On 06/08/2020 14:04, Maciej W. Rozycki via Gcc-patches wrote: > 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. > > gcc/ > * testsuite/gcc.target/arm/div64-unwinding.c: Rename to... > * testsuite/gcc.dg/div64-unwinding.c: ... this. > > libgcc/ > * Makefile.in [!LIB2_DIVMOD_EXCEPTION_FLAGS] > (LIB2_DIVMOD_EXCEPTION_FLAGS): Replace `-fexceptions > -fnon-call-exceptions' with `-fasynchronous-unwind-tables'. > * config/arm/t-bpabi (LIB2_DIVMOD_EXCEPTION_FLAGS): Remove > variable. > * config/arm/t-netbsd-eabi (LIB2_DIVMOD_EXCEPTION_FLAGS): > Likewise.
>From a quick glance, I'm not convinced this is right for Arm, since the Arm unwind format does not support anything other than call-based exceptions. How did you test it? R. > --- > Hi, > > I realised we still use handwritten ChangeLog entries (I got confused > with now different policies each of the various pieces of the GNU > toolchain has), so here's v2 of the change with a fix for that problem > being the only update. > > Also I have since run verification with the `riscv64-linux-gnu' target > and the ilp32d multilib as more representative for the change being made. > No problems were observed, although the now enabled test case scored: > > UNSUPPORTED: gcc.dg/div64-unwinding.c > > of course with the target failing the `! *-*-linux*' condition. > > Given that for the `riscv64-linux-gnu' target and the ilp32d multilib > glibc currently fails to link against libgcc.a built at -O0 I first ran > reference testing with target libraries built at -O2, but comparing that > to change-under-test -O2 results revealed another issue with GCC target > libraries built at -O0 causing link failures across testsuites, namely > libgcov.a referring atomic primitives where libatomic.a has not been > linked in. I haven't figured out yet if the issue is in libgcov, the > testsuite or the specs. Examples of failures: > > .../bin/riscv64-linux-gnu-ld: > .../gcc/testsuite/g++/../../lib32/ilp32d/libgcov.a(_gcov_indirect_call_profiler_v4.o): > in function `__gcov_topn_values_profiler_body': > .../libgcc/libgcov-profiler.c:116: undefined reference to > `__atomic_fetch_add_8' > .../bin/riscv64-linux-gnu-ld: .../libgcc/libgcov-profiler.c:129: undefined > reference to `__atomic_fetch_add_8' > .../bin/riscv64-linux-gnu-ld: .../libgcc/libgcov-profiler.c:150: undefined > reference to `__atomic_fetch_sub_8' > collect2: error: ld returned 1 exit status > compiler exited with status 1 > FAIL: g++.dg/other/pr55650.C -std=gnu++98 (test for excess errors) > > There were some odd Fortran failures too, with test cases failing to link, > making the results difficult to interpret. Therefore I decided to arrange > for a special build with first stage GCC built with its target libraries > at -O2, so that first stage glibc builds, and then second stage GCC built > with its target libraries at -O0 and second stage glibc omitted. That > removed the extra Fortran failures regardless of whether this change has > been applied or not, but we may consider looking overall into why a full > `riscv64-linux-gnu' build at -O0 has regressions against -O2 at least in > the ilp32d multilib. > > Meanwhile, OK to apply? > > Maciej > > Changes from v1: > > - ChangeLog entries added. > --- > 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 >