This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: strip, Linux's backtrace_symbols API, and GCC optimizations levels
- From: Ian Lance Taylor <iant at google dot com>
- To: bgoodr3 <bgoodr at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Sat, 02 May 2009 16:43:23 -0700
- Subject: Re: strip, Linux's backtrace_symbols API, and GCC optimizations levels
- References: <23348886.post@talk.nabble.com>
bgoodr3 <bgoodr@gmail.com> writes:
> 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?
It depends on what is missing. backtrace_symbols will never show calls
for which the callee has been inlined. However, it should normally be
able to show non-inlined calls regardless of the optimization level, as
long as you compile C++ or compile with the -fexceptions or
-funwind-tables option. That said, backtrace_symbols will not work
reliably if called from a signal handler.
> 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
gcc defines the preprocessor symbol __OPTIMIZE__ when doing an
optimizing compilation.
Ian