Bug 44668

Summary: backtrace_symbols() reports wrong function names
Product: [Retired] Red Hat Linux Reporter: Martin Strassburger <martin.strassburger>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Aaron Brown <abrown>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: fweimer
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-06-15 08:14:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Martin Strassburger 2001-06-15 08:14:34 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.4.2-2 i686)

Description of problem:
In our software product the function backtrace_symbols() is used in signal
handlers to find out where some error raised.
In glibc 2.2.2 the output of backtrace_symbols() and backtrace_symbols_fd()
seems to be broken.

How reproducible:
Always

Steps to Reproduce:
1. compile the following coding and execute it
#include <execinfo.h>
void showStack()
{
  void * array [1024];
  backtrace_symbols_fd(array, 
		       backtrace(array, sizeof(array)/sizeof(array[0])),
		       1);
}

void b()
{
  showStack();
}

void a()
{
  b();
}

int main()
{
  a();
  return 0;
}

2. The output looks like this:
./a.out(backtrace_symbols_fd+0x133)[0x80484df]
./a.out(backtrace_symbols_fd+0x157)[0x8048503]
./a.out(backtrace_symbols_fd+0x167)[0x8048513]
./a.out(backtrace_symbols_fd+0x177)[0x8048523]
/lib/i686/libc.so.6(__libc_start_main+0x93)[0x40041177]
./a.out(backtrace_symbols_fd+0x35)[0x80483e1]

3. The output should look like this:
./a.out(showStack+0x??)[0x80484df]
./a.out(b+0x??)[0x8048503]
./a.out(a+0x??)[0x8048513]
./a.out(main+0x??)[0x8048523]
/lib/i686/libc.so.6(__libc_start_main+0x93)[0x40041177]

It's really a pity not to get the function names because it makes debugging
of large programs much easier.

Comment 1 Jakub Jelinek 2001-06-15 10:35:49 UTC
backtrace_symbols does not use debugging info nor symbol table, that's
what debuggers are for.
backtrace_symbols uses information from the dynamic symbol table, so if
a function is not in dynamic symbol table, it cannot show up in the backtrace
listing. Unless you play with symbol versioning or symbol visibility, all
non-static functions make it into the dynamic symbol table for shared libraries,
for binaries you have to request that explicitely.
-Wl,--export-dynamic will do the job (tested on your example).