Bug 109719 - Truncated frame-pointer unwinding via Linux perf with g++
Summary: Truncated frame-pointer unwinding via Linux perf with g++
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-03 20:21 UTC by Christian Hergert
Modified: 2023-05-03 20:43 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-05-03 00:00:00


Attachments
First level of stack traces with clang++ (205 bytes, text/plain)
2023-05-03 20:31 UTC, Christian Hergert
Details
First level of stack traces with g++ (1.37 KB, text/plain)
2023-05-03 20:33 UTC, Christian Hergert
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Hergert 2023-05-03 20:21:45 UTC
On Fedora 38, frame-pointers are enabled by default. Caveats of course.

However, I noticed that clang++ is generating code that can unwind with frame-pointers just fine where as g++ is generating code that fails to unwind past a single frame for some projects.

Where I've noticed this is when profiling GTK/GNOME applications. Harfbuzz, which is C++ (no-rtti, no-exceptions, no-threadsafe-statics, and no stdlibc++), regularly results in stacktraces from Linux perf containing 2 frames. One of them looks corrupted, and the second to a Harfbuzz function.

When I recompile the project with clang++ instead (leaving the rest of the system still compiled with gcc) I get proper stacktraces from Linux perf showing how the Harfbuzz API was called (via GLib/GTK/Pango/etc).

Happy to provide more information and/or be remote hands/eyes.

Thanks!
Comment 1 Christian Hergert 2023-05-03 20:23:48 UTC
> When I recompile the project with clang++ instead 

I realize this was a bit vague, by "project" I mean Harfbuzz. Simply compiling Harfbuzz with clang++ made frame-pointer unwinding work by Linux perf.
Comment 2 Andrew Pinski 2023-05-03 20:28:16 UTC
>On Fedora 38, frame-pointers are enabled by default. Caveats of course.

HUH? omit frame pointer is on by default on x86_64.

What target is this on?

What exact command line is being used to compile the sources? If this on x86_64, you might still need -mno-omit-leaf-frame-pointer too.
Comment 3 Andrew Pinski 2023-05-03 20:29:12 UTC
Also on x86_64, frame pointers are not required by the ABI so this is not an ABI issue. Why instead are you not using the dwarf2 unwind tables that are generated by default too?
Comment 4 Christian Hergert 2023-05-03 20:31:26 UTC
Created attachment 54984 [details]
First level of stack traces with clang++

This shows a more proper first-level of stack frames within the program as harfbuzz API will show up in descendants properly.
Comment 5 Christian Hergert 2023-05-03 20:33:06 UTC
Created attachment 54985 [details]
First level of stack traces with g++

This shows stack traces when the only change was compiling harfbuzz with g++ instead of clang++.

Much of the unwinding done by the kernel becomes corrupted and shallow as you can see by lots of functions which have no business being called before `_start` or `__GI__clone3` are getting called.
Comment 6 Christian Hergert 2023-05-03 20:36:49 UTC
(In reply to Andrew Pinski from comment #2)
> HUH? omit frame pointer is on by default on x86_64.

Yes, Fedora 38 changed the default compiler flags to `-fno-omit-frame-pointer` so that the system can be profiled more reliably.

> What target is this on?

x86_64

> What exact command line is being used to compile the sources? If this on
> x86_64, you might still need -mno-omit-leaf-frame-pointer too.

No doubt, I have `-mno-omit-leaf-frame-pointer` too.
Comment 7 Christian Hergert 2023-05-03 20:38:16 UTC
(In reply to Andrew Pinski from comment #3)
> Also on x86_64, frame pointers are not required by the ABI so this is not an
> ABI issue. Why instead are you not using the dwarf2 unwind tables that are
> generated by default too?

Because the stack unwinding comes from the Linux kernel, which the default unwinder can only support frame-pointers. The DWARF unwinder was removed long ago.

Additionally, it can't use `.eh_frame_hdr` either.
Comment 8 Andrew Pinski 2023-05-03 20:39:05 UTC
(In reply to Christian Hergert from comment #6)
> (In reply to Andrew Pinski from comment #2)
> > HUH? omit frame pointer is on by default on x86_64.
> 
> Yes, Fedora 38 changed the default compiler flags to
> `-fno-omit-frame-pointer` so that the system can be profiled more reliably.

So you should report this to Fedora's team.

> 
> > What target is this on?
> 
> x86_64
> 
> > What exact command line is being used to compile the sources? If this on
> > x86_64, you might still need -mno-omit-leaf-frame-pointer too.
> 
> No doubt, I have `-mno-omit-leaf-frame-pointer` too.

I am suspecting the issue is inside the linux kernel ...

Anyways we need much more information here.
A sample simple program which shows that GCC is doing the wrong thing.
Maybe it is the linux frame pointer walker going wrong.
Comment 9 Christian Hergert 2023-05-03 20:43:27 UTC
Sure, no worries.