1). print function address directly:
printf("strerror=%p, strerror_r=%p\n", strerror, strerror_r);
strerror=0x8049ec0, strerror_r=0x8049e20
2). dlsym version:
rtldDefault= dlopen(0, RTLD_NOW | RTLD_GLOBAL);
dlsym(rtldDefault, "strerror_r"); ==> strerror_r=0xb76544e0
but
dlsym(rtldDefault, "strerror"); ==> strerror=0x8049ec0
3). others:
dlsym((void*)0, "strerror_r") ==> strerror_r=0xb76544e0
dlsym((void*)-1, "strerror_r") ==> strerror_r=0xb76544e0
How can I get strerror_r=0x8049e20 using dlsym()?
I have already print the address of strerror_r first, then call dlsym().
strerror_r=0xb76544e0 is wrong address, my call strerror_r with this address just do nothing.
If you look at the declaration of
strerror_rin/usr/include/string.h:Compiling a sample program with
gcc -save-tempsand default configuration, I get the following precompiled declaration:So it looks like the
strerror_rfunction is linked to the symbol__xpg_strerror_rinstead.Indeed, a check of the generated binary
objdump -t a.out | grep strerror:So, asking your question, just do
dlsym(rtldDefault, "__xpg_strerror_r").