This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strip, Linux's backtrace_symbols API, and GCC optimizations levels


I was intrigued to find that the Linux backtrace_symbols C function returns
strings that show function names, even when the executable and its shared
libraries are stripped with "strip --strip-all".  It is only when building
that application with GCC's -O2 optimization level (this is on 64-bit Linux,
RHEL5.3 kernel 2.6.18-128.el5, by the way) that many/most of the frames
disappear from backtrace_symbol's result.  The backtrace_symbols man page
does warn of this case, so I don't consider this to be a bug per se, just
want to know why that is the case for my edification.

Also, is there a way to have my cake and eat it too, which is to be able to
use -O2, but still have backtrace_symbols work like it would at lower
optimization levels?  I have tried adding -O2 along with
-fno-omit-frame-pointer, but backtrace_symbols still does not show all of
the stack trace.  If the answer is "no" (which is what I expect), then is
there some way (via special CPP macros defined by GCC) to detect an
optimization level inside the C code by way of a #ifdef check, so that I can
say something pseudo-coded like this:

#ifdef is_optimization_level >= 2
#  error Sorry charlie, this backtrace dumping code won't work like you
expect it to!
#endif
  static void backtrace_dump() { .... }

Thanks,
Brent

Reference material: 
1. backtrace_symbols man page: http://linux.die.net/man/3/backtrace_symbols
2. GCC's optimization section at
http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Optimize-Options.html states:
    -O also turns on -fomit-frame-pointer on machines where doing so does
not interfere with debugging.



-- 
View this message in context: http://www.nabble.com/strip%2C-Linux%27s-backtrace_symbols-API%2C-and-GCC-optimizations-levels-tp23348886p23348886.html
Sent from the Sourceware - binutils list mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]