Complement commit b932f770f70d ("x86_64 frame unwind info"), SVN r46374, <https://gcc.gnu.org/ml/gcc-patches/2001-10/msg00860.html>, and replace `-fexceptions -fnon-call-exceptions' with `-fasynchronous-unwind-tables' in LIB2_DIVMOD_FUNCS compilation flags so as to provide unwind tables for the affected functions while not pulling the unwinder proper, which is not required here.
Remove the ARM overrides accordingly, retaining the hook infrastructure however, and make the ARM test case a generic one. Beyond saving program space it fixes a RISC-V glibc build error due to unsatisfied `malloc' and `free' references from the unwinder causing link errors with `ld.so' where libgcc has been built at -O0. --- Hi, As discussed: <https://gcc.gnu.org/pipermail/gcc/2020-July/233120.html>. This has been regression-tested with all the GCC compiler testsuites with the `x86_64-linux' native configuration, which in particular means the moved ARM test case scored the UNSUPPORTED result. I have no access to a non-Linux configuration right now, so I cannot verify this test case, but in principle I expect it to work across the relevant targets (and the irrelevant ones can be excluded as they are discovered). OK to apply then? It may make sense to backport this fix too to the active release branches; please let me know if to do so. NB the original commit referred appears to contain more than just the corresponding mailing list posting; it looks like several patches were folded together before comitting, so this is as good as you can get. Maciej --- gcc/testsuite/gcc.dg/div64-unwinding.c | 25 +++++++++++++++++++++++++ gcc/testsuite/gcc.target/arm/div64-unwinding.c | 25 ------------------------- libgcc/Makefile.in | 2 +- libgcc/config/arm/t-bpabi | 5 ----- libgcc/config/arm/t-netbsd-eabi | 5 ----- 5 files changed, 26 insertions(+), 36 deletions(-) gcc-libgcc-divmod-asynchronous-unwind-tables.diff Index: gcc/gcc/testsuite/gcc.dg/div64-unwinding.c =================================================================== --- /dev/null +++ gcc/gcc/testsuite/gcc.dg/div64-unwinding.c @@ -0,0 +1,25 @@ +/* Performing a 64-bit division should not pull in the unwinder. */ + +/* { dg-do run { target { { ! *-*-linux* } && { ! *-*-uclinux* } } } } */ +/* { dg-skip-if "load causes weak symbol resolution" { vxworks_kernel } } */ +/* { dg-options "-O0" } */ + +#include <stdlib.h> + +long long +foo (long long c, long long d) +{ + return c/d; +} + +long long x = 0; +long long y = 1; + +extern int (*_Unwind_RaiseException) (void *) __attribute__((weak)); + +int main(void) +{ + if (&_Unwind_RaiseException != NULL) + abort ();; + return foo (x, y); +} Index: gcc/gcc/testsuite/gcc.target/arm/div64-unwinding.c =================================================================== --- gcc.orig/gcc/testsuite/gcc.target/arm/div64-unwinding.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Performing a 64-bit division should not pull in the unwinder. */ - -/* { dg-do run { target { { ! *-*-linux* } && { ! *-*-uclinux* } } } } */ -/* { dg-skip-if "load causes weak symbol resolution" { vxworks_kernel } } */ -/* { dg-options "-O0" } */ - -#include <stdlib.h> - -long long -foo (long long c, long long d) -{ - return c/d; -} - -long long x = 0; -long long y = 1; - -extern int (*_Unwind_RaiseException) (void *) __attribute__((weak)); - -int main(void) -{ - if (&_Unwind_RaiseException != NULL) - abort ();; - return foo (x, y); -} Index: gcc/libgcc/Makefile.in =================================================================== --- gcc.orig/libgcc/Makefile.in +++ gcc/libgcc/Makefile.in @@ -533,7 +533,7 @@ endif ifeq ($(LIB2_DIVMOD_EXCEPTION_FLAGS),) # Provide default flags for compiling divmod functions, if they haven't been # set already by a target-specific Makefile fragment. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions -fnon-call-exceptions +LIB2_DIVMOD_EXCEPTION_FLAGS := -fasynchronous-unwind-tables endif # Build LIB2_DIVMOD_FUNCS. Index: gcc/libgcc/config/arm/t-bpabi =================================================================== --- gcc.orig/libgcc/config/arm/t-bpabi +++ gcc/libgcc/config/arm/t-bpabi @@ -13,8 +13,3 @@ LIB2ADDEH = $(srcdir)/config/arm/unwind- # Add the BPABI names. SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver - -# On ARM, specifying -fnon-call-exceptions will needlessly pull in -# the unwinder in simple programs which use 64-bit division. Omitting -# the option is safe. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions Index: gcc/libgcc/config/arm/t-netbsd-eabi =================================================================== --- gcc.orig/libgcc/config/arm/t-netbsd-eabi +++ gcc/libgcc/config/arm/t-netbsd-eabi @@ -11,8 +11,3 @@ LIB2ADDEH = # Add the BPABI names. SHLIB_MAPFILES += $(srcdir)/config/arm/libgcc-bpabi.ver - -# On ARM, specifying -fnon-call-exceptions will needlessly pull in -# the unwinder in simple programs which use 64-bit division. Omitting -# the option is safe. -LIB2_DIVMOD_EXCEPTION_FLAGS := -fexceptions