On Mon, 14 Apr 2025, Jakub Jelinek wrote: > Hi! > > Andi had a useful comment that even with the PR119727 workaround to > ignore differences in libbacktrace printed addresses, it is still better > to turn off ASLR when easily possible, e.g. in case some address leaks > in somewhere in the ICE message elsewhere, or to verify the ICE doesn't > depend on a particular library/binary load addresses. > > The following patch adds a configure check and uses personality syscall > to turn off randomization for further -freport-bug subprocesses. > > Bootstrapped/regtested on x86_64-linux and i686-linux, plus verified > -freport-bug in --enable-host-pie built gcc now prepares bitwise identical > /tmp/cc*.out dump (previously the libbacktrace addresses in it differed > between subsequent gcc ... -freport-bug invocations). > Ok for trunk?
LGTM. Richard. > 2025-04-14 Jakub Jelinek <ja...@redhat.com> > > PR driver/119727 > * configure.ac (HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE): New check. > * gcc.cc: Include sys/personality.h if > HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE is defined. > (try_generate_repro): Call > personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE) > if HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE is defined. > * config.in: Regenerate. > * configure: Regenerate. > > --- gcc/configure.ac.jj 2025-04-08 14:08:50.033298821 +0200 > +++ gcc/configure.ac 2025-04-12 17:00:45.773692708 +0200 > @@ -1781,6 +1781,21 @@ if test $ac_cv_have_decl_O_NONBLOCK = ye > [Define if O_NONBLOCK supported by fcntl.]) > fi > > +# Check if personality and ADDR_NO_RANDOMIZE are declared > +# in sys/personality.h > +AC_CACHE_CHECK(for personality ADDR_NO_RANDOMIZE, > + ac_cv_personality_addr_no_randomize, [ > +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ > +#include <sys/personality.h>]], [[ > +personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE);]])], > +[ac_cv_personality_addr_no_randomize=yes], > +[ac_cv_personality_addr_no_randomize=no])]) > +if test $ac_cv_personality_addr_no_randomize = yes; then > + AC_DEFINE(HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE, 1, > + [Define if personality and ADDR_NO_RANDOMIZE are declared in > +sys/personality.h.]) > +fi > + > > # C++ Modules would like some networking features to provide the mapping > # server. You can still use modules without them though. > --- gcc/gcc.cc.jj 2025-04-12 13:15:10.468668500 +0200 > +++ gcc/gcc.cc 2025-04-12 17:08:49.165065782 +0200 > @@ -30,6 +30,9 @@ compilation is specified by a string cal > #define INCLUDE_STRING > #include "config.h" > #include "system.h" > +#ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE > +#include <sys/personality.h> > +#endif > #include "coretypes.h" > #include "multilib.h" /* before tm.h */ > #include "tm.h" > @@ -8003,6 +8006,10 @@ try_generate_repro (const char **argv) > else > new_argv[out_arg] = "-o-"; > > +#ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE > + personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE); > +#endif > + > int status; > for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt) > { > --- gcc/config.in.jj 2025-04-08 14:08:48.883314831 +0200 > +++ gcc/config.in 2025-04-12 17:01:17.071263552 +0200 > @@ -2320,6 +2320,13 @@ > #endif > > > +/* Define if personality and ADDR_NO_RANDOMIZE are declared in > + sys/personality.h. */ > +#ifndef USED_FOR_TARGET > +#undef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE > +#endif > + > + > /* Define which stat syscall is able to handle 64bit indodes. */ > #ifndef USED_FOR_TARGET > #undef HOST_STAT_FOR_64BIT_INODES > --- gcc/configure.jj 2025-04-08 14:08:50.031298849 +0200 > +++ gcc/configure 2025-04-12 17:01:13.034318999 +0200 > @@ -12694,6 +12694,42 @@ $as_echo "#define HOST_HAS_O_NONBLOCK 1" > > fi > > +# Check if personality and ADDR_NO_RANDOMIZE are declared > +# in sys/personality.h > +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for personality > ADDR_NO_RANDOMIZE" >&5 > +$as_echo_n "checking for personality ADDR_NO_RANDOMIZE... " >&6; } > +if ${ac_cv_personality_addr_no_randomize+:} false; then : > + $as_echo_n "(cached) " >&6 > +else > + > +cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > + > +#include <sys/personality.h> > +int > +main () > +{ > + > +personality (personality (0xffffffffU) | ADDR_NO_RANDOMIZE); > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_cxx_try_compile "$LINENO"; then : > + ac_cv_personality_addr_no_randomize=yes > +else > + ac_cv_personality_addr_no_randomize=no > +fi > +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext > +fi > +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: > $ac_cv_personality_addr_no_randomize" >&5 > +$as_echo "$ac_cv_personality_addr_no_randomize" >&6; } > +if test $ac_cv_personality_addr_no_randomize = yes; then > + > +$as_echo "#define HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE 1" >>confdefs.h > + > +fi > + > > # C++ Modules would like some networking features to provide the mapping > # server. You can still use modules without them though. > @@ -21484,7 +21520,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 21487 "configure" > +#line 21523 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > @@ -21590,7 +21626,7 @@ else > lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 > lt_status=$lt_dlunknown > cat > conftest.$ac_ext <<_LT_EOF > -#line 21593 "configure" > +#line 21629 "configure" > #include "confdefs.h" > > #if HAVE_DLFCN_H > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)