From ef1ae536062efb3fba8e9389da934689a0c608e3 Mon Sep 17 00:00:00 2001 From: X512 Date: Sat, 29 May 2021 16:20:38 +0900 Subject: [PATCH] gcc11: Enable frame pointers by default for Haiku * fno-omit-frame-pointer is enabled by default on all architectures * This provides easier/faster backtraces at the cost of lower performance (Fedora benchmarks show between no difference and 10% depending on the scenario, with most things being around 2%) * 32-bit x86 is not changed, because it has very few registes compared to other architectures, the performance cost would be even worse there (Fedora backed out the change on 32bit x86 as well) On ARM and RISV-V, unwinding without a frame pointer is difficult (on ARM this is due to the architecture defining mainly the link register as a way to chaun functions, there is no fixed stack structure, on RISC-V I don't know what the situation is but I expect there is something similar). So on these architectures, the frame pointer should always be enabled. On PPC, there is an hardware register doing pretty much the frame pointer role, and that can't be disabled. On other architectures (m68k and x86_64), it is mostly a matter of balance between the performance cost and the ease of getting backtraces (for example for realtime profiling). This can now easily be tweaked per architecture as needed, with frame pointers being enabled by default (a reasonable choice for someone starting a new architecture, ease of debugging is more important than performance then). Note that code that enables -fomit-frame-pointer explicitly can still do that if needed, so the bad cases where the performance cost is very high can be handled in this way. Source for Fedora benchmarks: https://pagure.io/fesco/issue/2817#comment-826636 Change-Id: Iea9b8fec51adb192052f55cc49a8c1d922e27aa4 Reviewed-on: https://review.haiku-os.org/c/buildtools/+/4368 Reviewed-by: X512 X512 Reviewed-by: David Karoly Reviewed-by: Fredrik Holmqvist Reviewed-by: Alex von Gluck IV --- gcc/gcc/config/haiku.h | 12 +++++++++--- gcc/gcc/config/i386/haiku.h | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gcc/gcc/config/haiku.h b/gcc/gcc/config/haiku.h index 37adf4081d..88adc25772 100644 --- a/gcc/gcc/config/haiku.h +++ b/gcc/gcc/config/haiku.h @@ -44,11 +44,17 @@ Boston, MA 02111-1307, USA. */ /* Haiku uses lots of multichars, so don't warn about them unless the user explicitly asks for the warnings with -Wmultichar. Note that - CC1_SPEC is used for both cc1 and cc1plus. */ -#undef CC1_SPEC -#define CC1_SPEC \ + CC1_SPEC is used for both cc1 and cc1plus. + + HAIKU_CC1_SPEC is common options for all architectures. The frame pointer is also enabled + for all architectures, except for 32-bit i386, because that one has a very limited number of + registers, and the performance impact is too high. */ +#define HAIKU_CC1_SPEC \ "%{fpic|fPIC|fpie|fPIE|fno-pic|fno-PIC|fno-pie|fno-PIE:;:-fPIC} \ %{!Wmultichar: -Wno-multichar} %(cc1_cpu) %{profile:-p}" +#undef CC1_SPEC +#define CC1_SPEC \ + HAIKU_CC1_SPEC " %{!fomit-frame-pointer: -fno-omit-frame-pointer}" #undef CC1PLUS_SPEC #define CC1PLUS_SPEC "%{!Wctor-dtor-privacy:-Wno-ctor-dtor-privacy}" diff --git a/gcc/gcc/config/i386/haiku.h b/gcc/gcc/config/i386/haiku.h index 3379e19f54..4d43c6bbfa 100644 --- a/gcc/gcc/config/i386/haiku.h +++ b/gcc/gcc/config/i386/haiku.h @@ -75,3 +75,8 @@ Boston, MA 02111-1307, USA. */ if ((MAX_SKIP)==0) fprintf ((FILE), "\t.p2align %d\n", (LOG)); \ else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP)) #endif + +/* On 32-bit i386, because there are so few registers, keep the frame pointer disabled by default. + * Other architectures have it always enabled for Haiku */ +#undef CC1_SPEC +#define CC1_SPEC HAIKU_CC1_SPEC