GCC uses two linker mapfiles for Solaris ld: clearcap.map and
libgcc-unwind.map.  Currently, both the original v1 mapfile syntax and
the new v2 one are supported, distinguished with configure checks.
However, the v2 mapfile syntax was already introduced in Solaris 11.0,
so with only Solaris 11.4 supported the checks are no longer necessary.

Besides, when doing non-bootstrap builds where the build compiler's
configured linker and the stage1 compiler differ (ld -> gld), the build
compiler was probed for mapfile syntax support, which breaks the stage1
compiler.

Now, the mapfiles are used unconditionally if the freshly built compiler
uses Solaris ld.

Bootstrapped without regressions on i386-pc-solaris2.11 and
sparc-sun-solaris2.11 with ld and gld, and x86_64-pc-linux-gnu.

Committed to trunk.

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2026-06-25  Rainer Orth  <[email protected]>

        gcc:
        * configure.ac (gcc_cv_ld_clearcap): Remove.
        Link clearcap.map to config/sol2-clearcap.map with Solaris ld.

        * configure: Regenerate.
        * config.in: Likewise.
        * config/sol2-clearcap.map: Remove.
        * config/sol2-clearcapv2.map: Rename to sol2-clearcap.map.
        * config/t-sol2 (install-clearcap-map): Install source file
        directly.
        * config/sol2.h (LINK_CLEARCAP_SPEC): Guard with HAVE_SOLARIS_LD.

        libgcc:
        * configure.ac (solaris_ld_v2_maps): Remove.
        * configure: Regenerate.
        * Makefile.in (solaris_ld_v2_maps): Remove.
        * config/t-slibgcc-sld (libgcc-unwind.map): Remove
        solaris_ld_v2_maps handling.

# HG changeset patch
# Parent  c9664d6689e057ba0d8fdb6f4a22659c5294672e
Hardcode Solaris v2 mapfile syntax with Solaris ld

diff --git a/gcc/config.in b/gcc/config.in
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1738,13 +1738,6 @@
 #endif
 
 
-/* Define if the linker supports clearing hardware capabilities via mapfile.
-   */
-#ifndef USED_FOR_TARGET
-#undef HAVE_LD_CLEARCAP
-#endif
-
-
 /* Define to the level of your linker's compressed debug section support. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_LD_COMPRESS_DEBUG
diff --git a/gcc/config/sol2-clearcap.map b/gcc/config/sol2-clearcap.map
--- a/gcc/config/sol2-clearcap.map
+++ b/gcc/config/sol2-clearcap.map
@@ -1,2 +1,7 @@
 # Clear all hardware capabilities emitted by Sun as.
-hwcap_1 = V0x0 OVERRIDE;
+#
+# Uses mapfile v2 syntax which is the only way to clear AT_SUN_CAP_HW2 flags.
+$mapfile_version 2
+CAPABILITY {
+  HW = ;
+};
diff --git a/gcc/config/sol2-clearcapv2.map b/gcc/config/sol2-clearcapv2.map
deleted file mode 100644
--- a/gcc/config/sol2-clearcapv2.map
+++ /dev/null
@@ -1,7 +0,0 @@
-# Clear all hardware capabilities emitted by Sun as.
-#
-# Uses mapfile v2 syntax which is the only way to clear AT_SUN_CAP_HW2 flags.
-$mapfile_version 2
-CAPABILITY {
-  HW = ;
-};
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -348,7 +348,7 @@ along with GCC; see the file COPYING3.  
 
 /* Clear hardware capabilities, either explicitly or with OpenMP:
    #pragma openmp declare simd creates clones for SSE2, AVX, and AVX2.  */
-#ifdef HAVE_LD_CLEARCAP
+#if HAVE_SOLARIS_LD
 #define LINK_CLEARCAP_SPEC " %{mclear-hwcap|fopenmp*:-M %sclearcap.map}"
 #else
 #define LINK_CLEARCAP_SPEC ""
diff --git a/gcc/config/t-sol2 b/gcc/config/t-sol2
--- a/gcc/config/t-sol2
+++ b/gcc/config/t-sol2
@@ -50,5 +50,5 @@ sol2.o: $(srcdir)/config/sol2.cc gt-sol2
 install: install-clearcap-map
 
 # Ignore failures: file only exists if linker supports it.
-install-clearcap-map:
-	-$(INSTALL_DATA) clearcap.map $(DESTDIR)$(libdir)
+install-clearcap-map: $(srcdir)/config/sol2-clearcap.map
+	-$(INSTALL_DATA) $< $(DESTDIR)$(libdir)
diff --git a/gcc/configure b/gcc/configure
--- a/gcc/configure
+++ b/gcc/configure
@@ -33254,33 +33254,10 @@ $as_echo "#define USE_LD_AS_NEEDED_LDSCR
 
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker mapfile support for clearing hardware capabilities" >&5
-$as_echo_n "checking linker mapfile support for clearing hardware capabilities... " >&6; }
-saved_LDFLAGS="$LDFLAGS"
-for clearcap_map in sol2-clearcapv2.map sol2-clearcap.map; do
-  LDFLAGS="$saved_LDFLAGS -Wl,-M,${srcdir}/config/$clearcap_map"
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-int main(void) {return 0;}
-_ACEOF
-if ac_fn_cxx_try_link "$LINENO"; then :
-  gcc_cv_ld_clearcap=yes; break
-else
-  gcc_cv_ld_clearcap=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
-    conftest$ac_exeext conftest.$ac_ext
-done
-LDFLAGS="$saved_LDFLAGS"
-if test "x$gcc_cv_ld_clearcap" = xyes; then
-
-$as_echo "#define HAVE_LD_CLEARCAP 1" >>confdefs.h
-
-  ac_config_links="$ac_config_links clearcap.map:${srcdir}/config/$clearcap_map"
-
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_clearcap" >&5
-$as_echo "$gcc_cv_ld_clearcap" >&6; }
+if test x$ld_flavor = xsolaris; then
+  ac_config_links="$ac_config_links clearcap.map:${srcdir}/config/sol2-clearcap.map"
+
+fi
 
 case "$target" in
   powerpc*-*-*)
@@ -36069,7 +36046,7 @@ do
     "collect-ld") CONFIG_FILES="$CONFIG_FILES collect-ld:exec-tool.in" ;;
     "nm") CONFIG_FILES="$CONFIG_FILES nm:exec-tool.in" ;;
     "dsymutil") CONFIG_FILES="$CONFIG_FILES dsymutil:exec-tool.in" ;;
-    "clearcap.map") CONFIG_LINKS="$CONFIG_LINKS clearcap.map:${srcdir}/config/$clearcap_map" ;;
+    "clearcap.map") CONFIG_LINKS="$CONFIG_LINKS clearcap.map:${srcdir}/config/sol2-clearcap.map" ;;
     "$all_outputs") CONFIG_FILES="$CONFIG_FILES $all_outputs" ;;
     "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
 
diff --git a/gcc/configure.ac b/gcc/configure.ac
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -6597,20 +6597,9 @@ if test x"$gcc_cv_ld_use_as_needed_ldscr
 [Define if your linker supports AS_NEEDED in linker scripts.])
 fi
 
-AC_MSG_CHECKING(linker mapfile support for clearing hardware capabilities)
-saved_LDFLAGS="$LDFLAGS"
-for clearcap_map in sol2-clearcapv2.map sol2-clearcap.map; do
-  LDFLAGS="$saved_LDFLAGS -Wl,-M,${srcdir}/config/$clearcap_map"
-  AC_LINK_IFELSE([AC_LANG_SOURCE([int main(void) {return 0;}])],
-    [gcc_cv_ld_clearcap=yes; break], [gcc_cv_ld_clearcap=no])
-done
-LDFLAGS="$saved_LDFLAGS"
-if test "x$gcc_cv_ld_clearcap" = xyes; then
-  AC_DEFINE([HAVE_LD_CLEARCAP], 1,
-[Define if the linker supports clearing hardware capabilities via mapfile.])
-  AC_CONFIG_LINKS([clearcap.map:${srcdir}/config/$clearcap_map])
-fi
-AC_MSG_RESULT($gcc_cv_ld_clearcap)
+if test x$ld_flavor = xsolaris; then
+  AC_CONFIG_LINKS([clearcap.map:${srcdir}/config/sol2-clearcap.map])
+fi
 
 case "$target" in
   powerpc*-*-*)
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -44,7 +44,6 @@ enable_vtable_verify = @enable_vtable_ve
 enable_decimal_float = @enable_decimal_float@
 fixed_point = @fixed_point@
 with_aix_soname = @with_aix_soname@
-solaris_ld_v2_maps = @solaris_ld_v2_maps@
 enable_execute_stack = @enable_execute_stack@
 unwind_header = @unwind_header@
 md_unwind_def_header = @md_unwind_def_header@
diff --git a/libgcc/config/t-slibgcc-sld b/libgcc/config/t-slibgcc-sld
--- a/libgcc/config/t-slibgcc-sld
+++ b/libgcc/config/t-slibgcc-sld
@@ -8,23 +8,13 @@ ifeq ($(enable_shared),yes)
 
 # Linker mapfile to enforce direct binding to libgcc_s unwinder
 # (PR target/59788).
-# Emit v2 mapfile syntax if possible, otherwise ld -z guidance complains
-# every time the mapfile is used.
 libgcc-unwind.map: libgcc-std.ver
-ifeq ($(solaris_ld_v2_maps),yes)
 	@(echo '$$mapfile_version 2';		\
 	echo "SYMBOL_SCOPE {";			\
 	for f in `grep _Unwind_ $< | sort`; do	\
 	  echo "	$$f { FLAGS = EXTERN DIRECT };"; \
 	done;					\
 	echo "};" ) > $@
-else
-	@(echo "{";				\
-	for f in `grep _Unwind_ $< | sort`; do	\
-	  echo "	$$f = EXTERN DIRECT;";	\
-	done;					\
-	echo "};" ) > $@
-endif
 
 # Copy libgcc-unwind.map to the place where gcc will look for it at build-time.
 install-libgcc-unwind-map-forbuild: libgcc-unwind.map
diff --git a/libgcc/configure b/libgcc/configure
--- a/libgcc/configure
+++ b/libgcc/configure
@@ -604,7 +604,6 @@ sfp_machine_header
 set_use_emutls
 set_have_cc_tls
 vis_hide
-solaris_ld_v2_maps
 real_host_noncanonical
 accel_dir_suffix
 use_tm_clone_registry
@@ -5403,26 +5402,6 @@ EOF
   ;;
 esac
 
-# Check if Solaris linker support v2 linker mapfile syntax.
-# Link with -nostartfiles -nodefaultlibs since neither are present while
-# building libgcc.
-case ${host} in
-*-*-solaris2*)
-  solaris_ld_v2_maps=no
-  echo 'int main(void) {return 0;}' > conftest.c
-  echo '$mapfile_version 2' > conftest.map
-  if { ac_try='${CC-cc} -nostartfiles -nodefaultlibs -Wl,-M,conftest.map -o conftest conftest.c 1>&5'
-  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
-  (eval $ac_try) 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; }; then
-      solaris_ld_v2_maps=yes
-  fi
-  ;;
-esac
-
-
 case ${host} in
 loongarch32*-*-*)
   tmake_file="${tmake_file} loongarch/t-crtstuff-la32"
diff --git a/libgcc/configure.ac b/libgcc/configure.ac
--- a/libgcc/configure.ac
+++ b/libgcc/configure.ac
@@ -529,21 +529,6 @@ EOF
   ;;
 esac
 
-# Check if Solaris linker support v2 linker mapfile syntax.
-# Link with -nostartfiles -nodefaultlibs since neither are present while
-# building libgcc.
-case ${host} in
-*-*-solaris2*)
-  solaris_ld_v2_maps=no
-  echo 'int main(void) {return 0;}' > conftest.c
-  echo '$mapfile_version 2' > conftest.map
-  if AC_TRY_COMMAND([${CC-cc} -nostartfiles -nodefaultlibs -Wl,-M,conftest.map -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD]); then
-      solaris_ld_v2_maps=yes
-  fi
-  ;;
-esac
-AC_SUBST(solaris_ld_v2_maps)
-
 case ${host} in
 loongarch32*-*-*)
   tmake_file="${tmake_file} loongarch/t-crtstuff-la32"

Reply via email to