Summary: | dladdr() returns wrong symbol names in rare cases | ||
---|---|---|---|
Product: | glibc | Reporter: | Satoru Takabayashi <satoru> |
Component: | libc | Assignee: | Ulrich Drepper <drepper.fsp> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | glibc-bugs |
Priority: | P2 | Flags: | fweimer:
security-
|
Version: | unspecified | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Last reconfirmed: |
Description
Satoru Takabayashi
2006-05-22 14:56:31 UTC
Correct patch, I applied it to CVS. (In reply to comment #1) > Correct patch, I applied it to CVS. Thank you for fixing the bug. I just realized that completly skipping undefined references could be a problem. Consider the following code. #include <stdio.h> int main() { printf("%p\n", &printf); return 0; } If I compile it without -fPIC on my machine (Debian GNU/Linux sarge on a x86_32 machine), &printf points to a memory address in PLT. % gcc test.c % ./a.out 0x8048288 % readelf -S a.out |grep " \.plt" [11] .plt PROGBITS 08048270 000270 000030 04 AX 0 0 4 The binary contains the undefined symbols for printf both in .dysym and .symtab sections and the values of the undefined symbols correspond to the memory address in PLT (0x8048288). % readelf --symbols a.out |grep printf 2: 08048288 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2) 99: 08048288 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0 Hence, to support dladdr(&printf, info) for non-pic binaries, probably we need to allow the condition something like this as well. (ELFW(ST_TYPE) (symtab->st_info) == STT_FUNC && symtab->st_shndx == SHN_UNDEF && match->l_addr + symtab->st_value == addr) On the other hand, if I compile the same code with -fPIC, &printf points to the printf definition in the map of glibc. There is no problem in this case for doing dladdr(&printf, info). % gcc -fPIC test.c % ./a.out 0x4006e8e0 % ldd a.out libc.so.6 => /lib/libc.so.6 (0x4001f000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) % readelf --symbols /lib/libc.so.6|grep " printf" 157: 0004f8e0 57 FUNC GLOBAL DEFAULT 11 printf@@GLIBC_2.0 % python >>> "%x" % (0x4001f000 + 0x0004f8e0) '4006e8e0' I adjusted the patch. |