[Bug 694751] New: backtrace() function of glibc on x86_64 does not work properly when called from a dynamic library.
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
https://bugzilla.novell.com/show_bug.cgi?id=694751 https://bugzilla.novell.com/show_bug.cgi?id=694751#c0 Summary: backtrace() function of glibc on x86_64 does not work properly when called from a dynamic library. Classification: openSUSE Product: openSUSE 11.3 Version: Final Platform: x86-64 OS/Version: openSUSE 11.3 Status: NEW Severity: Major Priority: P5 - None Component: Other AssignedTo: bnc-team-screening@forge.provo.novell.com ReportedBy: gil@cs.technion.ac.il QAContact: qa@suse.de Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 This happens with x86_64 (executables) and does not happen with i386. This fact suggests that the fault is in architecture specific code (like nptl/sysdeps/x86_64/pthreaddef.h) or in code that does not work well for x86_64. The The GNU C Library bug reporting instructions request to report bugs to vendors as they may change the shipped glibc code. I encountered this on OpenSUSE 11.3 x86_64 using 64bit code and glibc 2.11.2 that came with the distribution. More details appear below in shell output contained in the reproduction instructions. This bug hinders code debugging/development. Reproducible: Always Steps to Reproduce: I demonstrate this using a function that prints the return value of backtrace(). The returned value is different when the object file containing the function is linkeed into the executable and when it is included in a dynamic library linked to the executable. I included additional output like versions of gcc, ld, glibc, kernel.
cat main.c #include <stdio.h>
extern void print_stack_size(); int main() { print_stack_size(); return 0; }
cat bt.c #include <stdio.h> #include <stdlib.h> #include <execinfo.h>
gcc -Wall -g -c main.c gcc -Wall -g -fpic -c bt.c ld -shared -g -o libbt.so bt.o gcc -g -o exec1 main.o bt.o gcc -g -o exec2 main.o -L. -lbt setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:`pwd` ./exec1
./exec2
file *.o *.so exec? bt.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
void print_stack_size() { void* stack[20]; printf("trace returned %d frames\n", backtrace(stack, 20)); } trace returned 4 frames trace returned 1 frames main.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped libbt.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped exec1: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped exec2: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped
ldd exec1 linux-vdso.so.1 => (0x00007fffb59fa000) libc.so.6 => /lib64/libc.so.6 (0x00007f100c7b1000) /lib64/ld-linux-x86-64.so.2 (0x00007f100cb11000) ldd exec2 linux-vdso.so.1 => (0x00007fffee546000) libbt.so => /home/gili/testbacktrace/libbt.so (0x00007f1d3c225000) libc.so.6 => /lib64/libc.so.6 (0x00007f1d3bec5000) /lib64/ld-linux-x86-64.so.2 (0x00007f1d3c427000) cat /proc/version Linux version 2.6.34.7-0.7-xen (geeko@buildhost) (gcc version 4.5.0 20100604 [gcc-4_5-branch revision 160292] (SUSE Linux) ) #1 SMP 2010-12-13 11:13:53 +0100 cat /etc/issue Welcome to openSUSE 11.3 "Teal" - Kernel \r (\l).
strings /lib64/libc.so.6 | grep -i version argp_program_version versionsort versionsort64 argp_program_version_hook gnu_get_libc_version RPC: Incompatible versions of RPC RPC: Program/version mismatch <malloc version="1"> Print program version (PROGRAM ERROR) No version known!? %s: %s; low version = %lu, high version = %lu GNU C Library stable release version 2.11.2 (20100531), by Roland McGrath et al. Compiled by GNU CC version 4.5.0 20100604 [gcc-4_5-branch revision 160292]. crypt add-on version 2.1 by Michael Glad and others strings /lib64/libc.so.6 | grep -i version|tail -3 GNU C Library stable release version 2.11.2 (20100531), by Roland McGrath et al. Compiled by GNU CC version 4.5.0 20100604 [gcc-4_5-branch revision 160292]. crypt add-on version 2.1 by Michael Glad and others gcc --version gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292] Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ld --version GNU ld (GNU Binutils; openSUSE 11.3) 2.20.0.20100122-6 Copyright 2009 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
gcc -Wall -g -c -m32 main.c gcc -Wall -g -c -m32 bt.c ld -shared -melf_i386 -g -o libbt.so bt.o gcc -g -m32 -o exec1 main.o bt.o gcc -g -m32 -o exec2 main.o -L. -lbt ./exec1
./exec2
A demonstration that this does not happen when building a 32 bit executable on the same host: trace returned 3 frames trace returned 3 frames Actual Results: As shown, backtrace() returns only one stack frame when called from a 64 bit dynamic library. Expected Results: backtrace() should return all the stack frames (call addresses) like it does when called from the main program. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
https://bugzilla.novell.com/show_bug.cgi?id=694751 https://bugzilla.novell.com/show_bug.cgi?id=694751#c zj jia <zjjia@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|bnc-team-screening@forge.pr |matz@novell.com |ovo.novell.com | -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
![](https://seccdn.libravatar.org/avatar/3035b38ff33cf86f480bb169b8500b80.jpg?s=120&d=mm&r=g)
https://bugzilla.novell.com/show_bug.cgi?id=694751 https://bugzilla.novell.com/show_bug.cgi?id=694751#c3 Michael Matz <matz@novell.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID Severity|Major |Normal --- Comment #3 from Michael Matz <matz@novell.com> 2011-07-21 15:46:44 UTC --- You linked your shared library incorrectly. In particular you're using ld directly, which is not going to work. One symptom of "not working" is exactly that unwinding through shared library borders doesn't work. In this particular case adding --eh-frame-hdr would have been enough, but there are other reasons why you shouldn't use ld directly to create shared libraries. Please always use the appropriate driver (gcc or g++):
gcc -shared -g -o libbt.so bt.o
Then the testcases will work. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug.
participants (1)
-
bugzilla_noreply@novell.com