0035-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch (9499B)
1 From 573a66e4146c9a65d895af9081a4d3d49cfc9e7a Mon Sep 17 00:00:00 2001 2 From: Drew DeVault <sir@cmpwn.com> 3 Date: Wed, 9 Dec 2020 16:07:26 +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 Makefile.in | 1 + 10 gcc/config.in | 6 ++++++ 11 gcc/config/gnu-user.h | 12 +++++++++++- 12 gcc/configure | 32 ++++++++++++++++++++++++++++++-- 13 gcc/configure.ac | 22 +++++++++++++++++++++- 14 gcc/doc/install.texi | 8 ++++++++ 15 gcc/doc/tm.texi | 8 +++++++- 16 gcc/doc/tm.texi.in | 8 +++++++- 17 gcc/gcc.cc | 12 +++++++++++- 18 9 files changed, 102 insertions(+), 7 deletions(-) 19 20 diff --git a/Makefile.in b/Makefile.in 21 index b564ddbf792..a95c7407d16 100644 22 --- a/Makefile.in 23 +++ b/Makefile.in 24 @@ -232,6 +232,7 @@ HOST_EXPORTS = \ 25 RANLIB_FOR_TARGET="$(RANLIB_FOR_TARGET)"; export RANLIB_FOR_TARGET; \ 26 READELF_FOR_TARGET="$(READELF_FOR_TARGET)"; export READELF_FOR_TARGET; \ 27 TOPLEVEL_CONFIGURE_ARGUMENTS="$(TOPLEVEL_CONFIGURE_ARGUMENTS)"; export TOPLEVEL_CONFIGURE_ARGUMENTS; \ 28 + TARGET_CONFIGDIRS="$(TARGET_CONFIGDIRS)"; export TARGET_CONFIGDIRS; \ 29 HOST_LIBS="$(STAGE1_LIBS)"; export HOST_LIBS; \ 30 GMPLIBS="$(HOST_GMPLIBS)"; export GMPLIBS; \ 31 GMPINC="$(HOST_GMPINC)"; export GMPINC; \ 32 diff --git a/gcc/config.in b/gcc/config.in 33 index f0fbf123aa8..af84efc4f9e 100644 34 --- a/gcc/config.in 35 +++ b/gcc/config.in 36 @@ -118,6 +118,12 @@ 37 #endif 38 39 40 +/* Define if libatomic should always be linked. */ 41 +#ifndef USED_FOR_TARGET 42 +#undef ENABLE_AUTOLINK_LIBATOMIC 43 +#endif 44 + 45 + 46 /* Define to 1 to specify that we are using the BID decimal floating point 47 format instead of DPD */ 48 #ifndef USED_FOR_TARGET 49 diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h 50 index 8433e56c3e1..0347f10da8b 100644 51 --- a/gcc/config/gnu-user.h 52 +++ b/gcc/config/gnu-user.h 53 @@ -109,8 +109,18 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 54 #define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} " 55 #endif 56 57 +#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC) 58 +# ifdef LD_AS_NEEDED_OPTION 59 +# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION 60 +# else 61 +# define LINK_LIBATOMIC_SPEC "-latomic" 62 +# endif 63 +#elif !defined(LINK_LIBATOMIC_SPEC) 64 +# define LINK_LIBATOMIC_SPEC "" 65 +#endif 66 + 67 #define GNU_USER_TARGET_LINK_GCC_C_SEQUENCE_SPEC \ 68 - "%{static|static-pie:--start-group} %G %{!nolibc:%L} \ 69 + "%{static|static-pie:--start-group} %G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L} \ 70 %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}" 71 72 #undef LINK_GCC_C_SEQUENCE_SPEC 73 diff --git a/gcc/configure b/gcc/configure 74 index 2f6b3265a6c..6dc65bf4ccb 100755 75 --- a/gcc/configure 76 +++ b/gcc/configure 77 @@ -981,6 +981,7 @@ with_changes_root_url 78 enable_languages 79 with_multilib_list 80 with_multilib_generator 81 +enable_autolink_libatomic 82 with_zstd 83 with_zstd_include 84 with_zstd_lib 85 @@ -1710,6 +1711,9 @@ Optional Features: 86 --disable-shared don't provide a shared libgcc 87 --disable-gcov don't provide libgcov and related host tools 88 --enable-languages=LIST specify which front-ends to build 89 + --enable-autolink-libatomic 90 + enable automatic linking of libatomic (ignored if 91 + not built) 92 --disable-rpath do not hardcode runtime library paths 93 --enable-sjlj-exceptions 94 arrange to use setjmp/longjmp exception handling 95 @@ -8324,7 +8328,6 @@ else 96 fi 97 98 99 - 100 # Check whether --with-multilib-generator was given. 101 if test "${with_multilib_generator+set}" = set; then : 102 withval=$with_multilib_generator; : 103 @@ -8332,6 +8335,32 @@ else 104 with_multilib_generator=default 105 fi 106 107 +# If libatomic is available, whether it should be linked automatically 108 +# Check whether --enable-autolink-libatomic was given. 109 +if test "${enable_autolink_libatomic+set}" = set; then : 110 + enableval=$enable_autolink_libatomic; 111 + case $enable_autolink_libatomic in 112 + yes | no) ;; 113 + *) as_fn_error $? "'$enable_autolink_libatomic' is an invalid value for 114 +--enable-autolink-libatomic. Valid choices are 'yes' and 'no'." "$LINENO" 5 ;; 115 + esac 116 + 117 +else 118 + enable_autolink_libatomic='' 119 +fi 120 + 121 + 122 +if test x$enable_autolink_libatomic = xyes; then 123 + if echo " ${TARGET_CONFIGDIRS} " | grep " libatomic " > /dev/null 2>&1 ; then 124 + 125 +$as_echo "#define ENABLE_AUTOLINK_LIBATOMIC 1" >>confdefs.h 126 + 127 + else 128 + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&5 129 +$as_echo "$as_me: WARNING: libatomic is not build for this target, --enable-autolink-libatomic ignored" >&2;} 130 + fi 131 +fi 132 + 133 134 # ------------------------- 135 # Checks for other programs 136 @@ -34296,4 +34325,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 e683d3a7a5f..07c81c78336 100644 143 --- a/gcc/configure.ac 144 +++ b/gcc/configure.ac 145 @@ -1205,6 +1205,27 @@ 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 # Checks for other programs 172 # ------------------------- 173 @@ -7839,4 +7860,3 @@ done 174 ], 175 [subdirs='$subdirs']) 176 AC_OUTPUT 177 - 178 diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi 179 index 48408d842db..c90be0ee750 100644 180 --- a/gcc/doc/install.texi 181 +++ b/gcc/doc/install.texi 182 @@ -2295,6 +2295,14 @@ files, but these changed header paths may conflict with some compilation 183 environments. Enabled by default, and may be disabled using 184 @option{--disable-canonical-system-headers}. 185 186 +@item --enable-autolink-libatomic 187 +@itemx --disable-autolink-libatomic 188 +Tell GCC that it should automatically link libatomic; if supported by 189 +the linker, the file is only linked as needed. This flag is ignored 190 +when libatomic is not built. Note that this conigure flag is in particular 191 +useful when building an offloading-target compiler; as for those, a 192 +user had to specify @code{-foffload=target=-latomic} otherwise. 193 + 194 @item --with-glibc-version=@var{major}.@var{minor} 195 Tell GCC that when the GNU C Library (glibc) is used on the target it 196 will be version @var{major}.@var{minor} or later. Normally this can 197 diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi 198 index c5006afc00d..56b62c69ae8 100644 199 --- a/gcc/doc/tm.texi 200 +++ b/gcc/doc/tm.texi 201 @@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search. 202 203 @defmac LINK_GCC_C_SEQUENCE_SPEC 204 The sequence in which libgcc and libc are specified to the linker. 205 -By default this is @code{%G %L %G}. 206 +By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}. 207 +@end defmac 208 + 209 +@defmac LINK_LIBATOMIC_SPEC 210 +This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link 211 +libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC} 212 +is set. 213 @end defmac 214 215 @defmac POST_LINK_SPEC 216 diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in 217 index f869ddd5e5b..57c93f24ac3 100644 218 --- a/gcc/doc/tm.texi.in 219 +++ b/gcc/doc/tm.texi.in 220 @@ -381,7 +381,13 @@ the argument @option{-lgcc} to tell the linker to do the search. 221 222 @defmac LINK_GCC_C_SEQUENCE_SPEC 223 The sequence in which libgcc and libc are specified to the linker. 224 -By default this is @code{%G %L %G}. 225 +By default this is @code{%G LINK_LIBATOMIC_SPEC %L %G}. 226 +@end defmac 227 + 228 +@defmac LINK_LIBATOMIC_SPEC 229 +This macro is used in the default @code{LINK_GCC_C_SEQUENCE_SPEC} to link 230 +libatomic. By default, it is unset unless @code{ENABLE_AUTOLINK_LIBATOMIC} 231 +is set. 232 @end defmac 233 234 @defmac POST_LINK_SPEC 235 diff --git a/gcc/gcc.cc b/gcc/gcc.cc 236 index 735b2b1bba1..f10f3c91aa7 100644 237 --- a/gcc/gcc.cc 238 +++ b/gcc/gcc.cc 239 @@ -987,13 +987,23 @@ proper position among the other output files. */ 240 # define ASM_DEBUG_OPTION_SPEC "" 241 #endif 242 243 +#if !defined(LINK_LIBATOMIC_SPEC) && defined(ENABLE_AUTOLINK_LIBATOMIC) 244 +# ifdef LD_AS_NEEDED_OPTION 245 +# define LINK_LIBATOMIC_SPEC LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION 246 +# else 247 +# define LINK_LIBATOMIC_SPEC "-latomic" 248 +# endif 249 +#elif !defined(LINK_LIBATOMIC_SPEC) 250 +# define LINK_LIBATOMIC_SPEC "" 251 +#endif 252 + 253 /* Here is the spec for running the linker, after compiling all files. */ 254 255 /* This is overridable by the target in case they need to specify the 256 -lgcc and -lc order specially, yet not require them to override all 257 of LINK_COMMAND_SPEC. */ 258 #ifndef LINK_GCC_C_SEQUENCE_SPEC 259 -#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" 260 +#define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:" LINK_LIBATOMIC_SPEC " %L %G}" 261 #endif 262 263 #ifdef ENABLE_DEFAULT_SSP