[PATCH] Fix dladdr return value when cannot find symbol

Carmelo AMOROSO carmelo.amoroso at st.com
Wed Dec 12 20:04:20 UTC 2007


Carmelo AMOROSO wrote:
> Nickolai Zeldovich wrote:
>   
>>  On Dec 9, 2007 11:26 AM, Carmelo Amoroso <carmelo73 at gmail.com> wrote:
>>   
>>     
>>> Attached patch tries to fix it. The GNU_HASH part needs to be fixed accordingly.
>>>
>>> Any comments ?
>>>     
>>>       
>> I think that should work.  Minor point:
>>
>>   
>>     
>>> --- ldso/libdl/libdl.c  (revision 20633)
>>> +++ ldso/libdl/libdl.c  (working copy)
>>> @@ -723,8 +723,11 @@
>>>                 _dl_if_debug_print("Module \"%s\" at %p\n",
>>>                                    tpnt->libname, DL_LOADADDR_BASE(tpnt->loadaddr));
>>>
>>> -               if (DL_ADDR_IN_LOADADDR((ElfW(Addr)) __address, tpnt, pelf))
>>> +               if (DL_ADDR_IN_LOADADDR((ElfW(Addr)) __address, tpnt, pelf)) {
>>>                         pelf = tpnt;
>>> +                       /* Found, stop looping */
>>> +                       break;
>>> +               }
>>>         }
>>>
>>>         if (!pelf) {
>>>     
>>>       
>> I don't think this change is necessary or correct.  With this change,
>> the code can exit having found any shared library mapped at any lower
>> address.  Instead, you need to iterate over all loaded ELF files to
>> find the nearest shared library mapped at a lower address (see the
>> comment for DL_ADDR_IN_LOADADDR in dl-defs.h).
>>   
>> Nickolai.
>>   
>>     
> Yes, you're right. I'm doing some tests and I'll commit a comprehensive 
> patch.
> Thanks,
> Carmelo
>   
Hi,
while running more tests on this (indeed never used dladdr in the past), 
we have found that
the default implementation of DL_ADDR_IN_LOADADDR macro is broken for 
app_tpnt.
Infact, for *non* PIE executable (like the most of the cases) the 
app_tpnt->loadaddr is set to 0
being the difference between entry point from auxv and entry point from 
ELF program header.
So, according to the macro definition in dl-defs.h the comparison
tpnt->loadaddr < __address will be always true (also passing 0x1 as 
__address), and and the end of the loop
it will return the pelf pointing to app_tpnt.
I've seen that bfin and fvr use a own implementation of 
DL_ADDR_IN_LOADADDR macro... I'm wondering
if someone using these archs have experienced this kind of problems or not.

We'll go to fix it (and test for sh4), but I'm expecting to have a 
common better implementation.


Cheers,
Carmelo

>> _______________________________________________
>> uClibc mailing list
>> uClibc at uclibc.org
>> http://busybox.net/cgi-bin/mailman/listinfo/uclibc
>>
>>   
>>     
>
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://busybox.net/cgi-bin/mailman/listinfo/uclibc
>
>   




More information about the uClibc mailing list