From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18581 invoked by alias); 28 May 2006 05:04:42 -0000 Received: (qmail 18534 invoked by uid 48); 28 May 2006 05:04:12 -0000 Date: Sun, 28 May 2006 05:04:00 -0000 Message-ID: <20060528050412.18533.qmail@sourceware.org> From: "satoru at 0xcc dot net" To: glibc-bugs@sources.redhat.com In-Reply-To: <20060522145631.2683.satoru@0xcc.net> References: <20060522145631.2683.satoru@0xcc.net> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/2683] dladdr() returns wrong symbol names in rare cases X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2006-05/txt/msg00164.txt.bz2 List-Id: ------- Additional Comments From satoru at 0xcc dot net 2006-05-28 05:04 ------- (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 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' -- What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED | http://sourceware.org/bugzilla/show_bug.cgi?id=2683 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.