On 08-02-19 18:25, Thomas Schwinge wrote:
> Hi Tom!
> 
> On Fri, 8 Feb 2019 10:41:47 +0100, Tom de Vries <tdevr...@suse.de> wrote:
>> The backtrace functions backtrace_full, backtrace_print and backtrace_simple
>> walk the call stack, but make sure to skip the first entry, in order to skip
>> over the functions themselves, and start the backtrace at the caller of the
>> functions.
>>
>> When compiling with -flto, the functions may be inlined, causing them to skip
>> over the caller instead.
> 
> So, when recently working on the OpenACC Profiling Interface
> implementation in libgomp, where I'm using libbacktrace to figure out the
> caller of certain libgomp functions, I recently wondered about the very
> same issue, that we reliably have to skip a few initial frames.
> 
> So, "noinline" is how to do that reliably...  ;-/ That might be
> non-obvious for the casual reader, so they might not understand...
> 
>> Fix this by declaring the functions with __attribute__((noinline)).
> 
> ... this alone.
> 
> I'd suggest to have a common "#define LIBBACKTRACE_NOINLINE [...]" (or
> similar), together with the explanatory comment given above, and use that
> at the respective definition (or declaration?) sites.  Can that go into
> the public libbacktrace "*.h" file, so that it can also be used
> elsewhere, as described above?
> 
> If you agree, want me to prepare a patch?

Hi Thomas,

I suppose adding an explanatory comment at the places where I added
"__attribute__((noinline))" could be an improvement.

But to me, this is just an implementation detail of the library, and I
would avoid changing the public header file.

Thanks,
- Tom

Reply via email to