galeb

Једноставна статичка дистрибуција заснована на musl-у
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

0040-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch (9288B)


      1 From: Drew DeVault <sir@cmpwn.com>
      2 From: Olsken (updated patches)
      3 Date: Sat, 21 Aug 2021 08:51:52 +0000
      4 Subject: [PATCH] configure: Add --enable-autolink-libatomic, use in
      5  LINK_GCC_C_SEQUENCE_SPEC [PR81358]
      6 
      7 This fixes issues with RISC-V.
      8 
      9 diff --git a/Makefile.in b/Makefile.in
     10 index 047be0255..765f6b89b 100644
     11 --- a/Makefile.in
     12 +++ b/Makefile.in
     13 @@ -221,6 +221,7 @@ HOST_EXPORTS = \
     14  	RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)"; export RANLIB_FOR_TARGET; \
     15  	READELF_FOR_TARGET="$(READELF_FOR_TARGET)"; export READELF_FOR_TARGET; \
     16  	TOPLEVEL_CONFIGURE_ARGUMENTS="$(TOPLEVEL_CONFIGURE_ARGUMENTS)"; export TOPLEVEL_CONFIGURE_ARGUMENTS; \
     17 +	TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS; \
     18  	HOST_LIBS="$(STAGE1_LIBS)"; export HOST_LIBS; \
     19  	GMPLIBS="$(HOST_GMPLIBS)"; export GMPLIBS; \
     20  	GMPINC="$(HOST_GMPINC)"; export GMPINC; \
     21 diff --git a/gcc/config.in b/gcc/config.in
     22 index 313c13c8e..d0287d4cc 100644
     23 --- a/gcc/config.in
     24 +++ b/gcc/config.in
     25 @@ -106,6 +106,12 @@
     26  #endif
     27  
     28  
     29 +/* Define if libatomic should always be linked. */
     30 +#ifndef USED_FOR_TARGET
     31 +#undef ENABLE_AUTOLINK_LIBATOMIC
     32 +#endif
     33 +
     34 +
     35  /* Define to 1 to specify that we are using the BID decimal floating point
     36     format instead of DPD */
     37  #ifndef USED_FOR_TARGET
     38 diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
     39 index e1a04e9fd..ef1ffa6d2 100644
     40 --- a/gcc/config/gnu-user.h
     41 +++ b/gcc/config/gnu-user.h
     42 @@ -109,8 +109,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     43  #define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
     44  #endif
     45  
     46 +#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC)
     47 +#  ifdef LD_AS_NEEDED_OPTION
     48 +#    define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
     49 +#  else
     50 +#    define LINK_LIBATOMIC_SPEC "-latomic"
     51 +#  endif
     52 +#elif !defined(LINK_LIBATOMIC_SPEC)
     53 +#  define LINK_LIBATOMIC_SPEC ""
     54 +#endif
     55 +
     56  #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \
     57 -  "%{static|static-pie:--start-group} %G %{!nolibc:%L} \
     58 +  "%{static|static-pie:--start-group} %G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L} \
     59     %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}"
     60  
     61  #undef LINK_GCC_C_SEQUENCE_SPEC
     62 diff --git a/gcc/configure b/gcc/configure
     63 index 9b28369e3..8afa1c84f 100755
     64 --- a/gcc/configure
     65 +++ b/gcc/configure
     66 @@ -978,6 +978,7 @@ with_changes_root_url
     67  enable_languages
     68  with_multilib_list
     69  with_multilib_generator
     70 +enable_autolink_libatomic
     71  with_zstd
     72  with_zstd_include
     73  with_zstd_lib
     74 @@ -1706,6 +1707,9 @@ Optional Features:
     75    --disable-shared        don't provide a shared libgcc
     76    --disable-gcov          don't provide libgcov and related host tools
     77    --enable-languages=LIST specify which front-ends to build
     78 +  --enable-autolink-libatomic
     79 +                          enable automatic linking of libatomic (ignored if
     80 +                          not built)
     81    --disable-rpath         do not hardcode runtime library paths
     82    --enable-sjlj-exceptions
     83                            arrange to use setjmp/longjmp exception handling
     84 @@ -8076,6 +8080,33 @@ else
     85  fi
     86  
     87  
     88 +# If libatomic is available, whether it should be linked automatically
     89 +# Check whether --enable-autolink-libatomic was given.
     90 +if test "${enable_autolink_libatomic+set}" = set; then :
     91 +  enableval=$enable_autolink_libatomic;
     92 +  case $enable_autolink_libatomic in
     93 +    yes | no) ;;
     94 +    *) as_fn_error $? "'$enable_autolink_libatomic' is an invalid value for
     95 +--enable-autolink-libatomic.  Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
     96 +  esac
     97 +
     98 +else
     99 +  enable_autolink_libatomic=''
    100 +fi
    101 +
    102 +
    103 +if test x$enable_autolink_libatomic = xyes; then
    104 +  if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then
    105 +
    106 +$as_echo "#define ENABLE_AUTOLINK_LIBATOMIC 1" >>confdefs.h
    107 +
    108 +  else
    109 +    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&5
    110 +$as_echo "$as_me: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&2;}
    111 +  fi
    112 +fi
    113 +
    114 +
    115  # -------------------------
    116  # Checks for other programs
    117  # -------------------------
    118 @@ -19392,7 +19423,7 @@ else
    119    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    120    lt_status=$lt_dlunknown
    121    cat > conftest.$ac_ext <<_LT_EOF
    122 -#line 19395 "configure"
    123 +#line 19426 "configure"
    124  #include "confdefs.h"
    125  
    126  #if HAVE_DLFCN_H
    127 @@ -19498,7 +19529,7 @@ else
    128    lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
    129    lt_status=$lt_dlunknown
    130    cat > conftest.$ac_ext <<_LT_EOF
    131 -#line 19501 "configure"
    132 +#line 19532 "configure"
    133  #include "confdefs.h"
    134  
    135  #if HAVE_DLFCN_H
    136 @@ -33588,4 +33619,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
    137  $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
    138  fi
    139  
    140 -
    141 diff --git a/gcc/configure.ac b/gcc/configure.ac
    142 index 162e08cbc..115ba8ac6 100644
    143 --- a/gcc/configure.ac
    144 +++ b/gcc/configure.ac
    145 @@ -1149,6 +1149,28 @@ AC_ARG_WITH(multilib-generator,
    146  :,
    147  with_multilib_generator=default)
    148  
    149 +# If libatomic is available, whether it should be linked automatically
    150 +AC_ARG_ENABLE(autolink-libatomic,
    151 +[AS_HELP_STRING([--enable-autolink-libatomic],
    152 +		[enable automatic linking of libatomic (ignored if not built)])],
    153 +[
    154 +  case $enable_autolink_libatomic in
    155 +    yes | no) ;;
    156 +    *) AC_MSG_ERROR(['$enable_autolink_libatomic' is an invalid value for
    157 +--enable-autolink-libatomic.  Valid choices are 'yes' and 'no'.]) ;;
    158 +  esac
    159 +], [enable_autolink_libatomic=''])
    160 +
    161 +if test x$enable_autolink_libatomic = xyes; then
    162 +  if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then
    163 +    AC_DEFINE(ENABLE_AUTOLINK_LIBATOMIC, 1,
    164 +	[Define if libatomic should always be linked.])
    165 +  else
    166 +    AC_MSG_WARN([libatomic is not build for this target, --enable-autolink-libatomic ignored])
    167 +  fi
    168 +fi
    169 +
    170 +
    171  # -------------------------
    172  # Checks for other programs
    173  # -------------------------
    174 @@ -7553,4 +7575,3 @@ done
    175  ], 
    176  [subdirs='$subdirs'])
    177  AC_OUTPUT
    178 -
    179 diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
    180 index 4c38244ae..4a544e6a4 100644
    181 --- a/gcc/doc/install.texi
    182 +++ b/gcc/doc/install.texi
    183 @@ -2213,6 +2213,14 @@ files, but these changed header paths may conflict with some compilation
    184  environments.  Enabled by default, and may be disabled using
    185  @option{--disable-canonical-system-headers}.
    186  
    187 +@item --enable-autolink-libatomic
    188 +@itemx --disable-autolink-libatomic
    189 +Tell GCC that it should automatically link libatomic; if supported by
    190 +the linker, the file is only linked as needed. This flag is ignored
    191 +when libatomic is not built. Note that this conigure flag is in particular
    192 +useful when building an offloading-target compiler; as for those, a
    193 +user had to specify @code{-foffload=target=-latomic} otherwise.
    194 +
    195  @item --with-glibc-version=@var{major}.@var{minor}
    196  Tell GCC that when the GNU C Library (glibc) is used on the target it
    197  will be version @var{major}.@var{minor} or later.  Normally this can
    198 diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
    199 index b370bc76b..acc782739 100644
    200 --- a/gcc/doc/tm.texi
    201 +++ b/gcc/doc/tm.texi
    202 @@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search.
    203  
    204  @defmac LINK_GCC_C_SEQUENCE_SPEC
    205  The sequence in which libgcc and libc are specified to the linker.
    206 -By default this is @code{%G %L %G}.
    207 +By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}.
    208 +@end defmac
    209 +
    210 +@defmac LINK_LIBATOMIC_SPEC
    211 +This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link
    212 +libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC}
    213 +is set.
    214  @end defmac
    215  
    216  @defmac POST_LINK_SPEC
    217 diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
    218 index 2974dae27..80e003a38 100644
    219 --- a/gcc/doc/tm.texi.in
    220 +++ b/gcc/doc/tm.texi.in
    221 @@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search.
    222  
    223  @defmac LINK_GCC_C_SEQUENCE_SPEC
    224  The sequence in which libgcc and libc are specified to the linker.
    225 -By default this is @code{%G %L %G}.
    226 +By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}.
    227 +@end defmac
    228 +
    229 +@defmac LINK_LIBATOMIC_SPEC
    230 +This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link
    231 +libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC}
    232 +is set.
    233  @end defmac
    234  
    235  @defmac POST_LINK_SPEC
    236 diff --git a/gcc/gcc.c b/gcc/gcc.c
    237 index d7f3ee55c..bc1bd1686 100644
    238 --- a/gcc/gcc.c
    239 +++ b/gcc/gcc.c
    240 @@ -980,13 +980,23 @@ proper position among the other output files.  */
    241  # define ASM_DEBUG_OPTION_SPEC ""
    242  #endif
    243  
    244 +#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC)
    245 +#  ifdef LD_AS_NEEDED_OPTION
    246 +#    define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
    247 +#  else
    248 +#    define LINK_LIBATOMIC_SPEC "-latomic"
    249 +#  endif
    250 +#elif !defined(LINK_LIBATOMIC_SPEC)
    251 +#  define LINK_LIBATOMIC_SPEC ""
    252 +#endif
    253 +
    254  /* Here is the spec for running the linker, after compiling all files.  */
    255  
    256  /* This is overridable by the target in case they need to specify the
    257     -lgcc and -lc order specially, yet not require them to override all
    258     of LINK_COMMAND_SPEC.  */
    259  #ifndef LINK_GCC_C_SEQUENCE_SPEC
    260 -#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}"
    261 +#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L %G}"
    262  #endif
    263  
    264  #ifdef ENABLE_DEFAULT_SSP