A problem about dlsym with RTLD_DEFAULT

Yang Yingliang yangyingliang at huawei.com
Tue Oct 14 02:58:31 UTC 2014


On 2014/9/25 15:42, Joakim Tjernlund wrote:
> Yang Yingliang <yangyingliang at huawei.com> wrote on 2014/09/25 06:04:54:
>>
>> Hi,
>>
>> I encountered a problem, when I used dlsym with RTLD_DEFAULT.
>>
>> E.g.
>>
>> $ cat test.c 
>> #include <dlfcn.h>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>>    void *libaa = dlopen("./aa.so", RTLD_LAZY);
>>    void (*aaTest1)(void *);
>>
>>    if (libaa == NULL) {
>>       printf("dlopen failed\n");
>>       return 1;
>>    }
>>
>>    aaTest1 = dlsym(libaa, "aaTest1");
>>
>>    (*aaTest1)(libaa);
>>
>>    dlclose(libaa);
>>    return 0;
>> }
>>
>> $ cat aa.c
>> #define  _GNU_SOURCE
>> #include <dlfcn.h>
>> #include <stdio.h>
>>
>> int aaSymbol;
>>
>> void *aaTest1(void *libaa)
>> {
>>    printf("%p\n", dlsym(RTLD_DEFAULT, "aaSymbol"));
>>
>>    return NULL;
>> }
>>
>> Using uclibc:
>>
>> $ CC -o test test.c -ldl
>> $ CC -o aa.so aa.c -shared -fPIC -ldl
>> $ ./test
>> (nil)
>>
>>
>> Using glibc:
>>
>> $ CC -o test test.c -ldl
>> $ CC -o aa.so aa.c -shared -fPIC -ldl
>> $ ./test
>> 0x7ffcbbb4e030
>>
>> I cannot find the symbols of libaa.so in libaa with RTLD_DEFAULT,
>> but it can be found with using glibc.
>>
>> Is it a bug or just different from glibc ?
> 
> Both RTLD_DEFAULT and RTLD_NEXT behaviour feels like a bug, I just 
> guessing though
> 
> 
Hi,

Does other guys have more opinions ?

Thanks!




More information about the uClibc mailing list