PR 12320 ld --as-needed links libgcc_s.so.1 unnecessarily on Solaris

Alan Modra amodra@gmail.com
Tue Feb 17 00:56:48 GMT 2026


The Solaris 2 ABI requires some global symbols to be present as
dynamic symbols.  These unfortunately interact with ld --as-needed.
See the comment above elf-solaris.c:elf_solaris2_add_symbol_hook,
a new function added by this patch to ignore those symbol in shared
libraries.

	PR 12320
	PR 33177
bfd/
	* elf-solaris2.c: New file.
	* elf-solaris2.h: New file.
	* elf32-i386.c (elf_backend_add_symbol_hook): Define for Solaris.
	* elf32-sparc.c (elf_backend_add_symbol_hook): Likewise.
	* elf64-sparc.c (elf64_sparc_solaris2_add_symbol_hook): New.
	(elf_backend_add_symbol_hook): Define for Solaris.
	* elf64-x86-64.c (elf_x86_64_solaris2_add_symbol_hook): New.
	(elf_backend_add_symbol_hook): Define for Solaris.
	* Makefile.am (BFD32_BACKENDS): Add elf-solaris2.lo.
	(BFD32_BACKENDS_CFILES): Add elf-solaris2.c.
	* configure.ac (elfxx_x86): Add elf-solaris2.lo.
	(elfxx_sparc): Define and use in all sparc_elf*_vec.
	* po/SRC-POTFILES.in: Regenerate.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
ld/
	* emultempl/solaris2.em (elf_solaris2_after_open): New function.
	(LDEMUL_AFTER_OPEN): Define.
	(elf_solaris_before_allocation): Delete global_syms, instead
	use elf_solaris2_global_syms.  Ignore globals that are still
	bfd_link_hash_new, ie. have not been defined by a script.

diff --git a/bfd/Makefile.am b/bfd/Makefile.am
index 056f0eee3da..e4df05441eb 100644
--- a/bfd/Makefile.am
+++ b/bfd/Makefile.am
@@ -291,6 +291,7 @@ BFD32_BACKENDS = \
 	elf-m10300.lo \
 	elf-properties.lo \
 	elf-sframe.lo \
+	elf-solaris2.lo \
 	elf-strtab.lo \
 	elf-vxworks.lo \
 	elf.lo \
@@ -425,6 +426,7 @@ BFD32_BACKENDS_CFILES = \
 	elf-m10300.c \
 	elf-properties.c \
 	elf-sframe.c \
+	elf-solaris2.c \
 	elf-strtab.c \
 	elf-vxworks.c \
 	elf.c \
diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index 82041970a61..14512cf61fb 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -760,6 +760,7 @@ BFD32_BACKENDS = \
 	elf-m10300.lo \
 	elf-properties.lo \
 	elf-sframe.lo \
+	elf-solaris2.lo \
 	elf-strtab.lo \
 	elf-vxworks.lo \
 	elf.lo \
@@ -894,6 +895,7 @@ BFD32_BACKENDS_CFILES = \
 	elf-m10300.c \
 	elf-properties.c \
 	elf-sframe.c \
+	elf-solaris2.c \
 	elf-strtab.c \
 	elf-vxworks.c \
 	elf.c \
@@ -1565,6 +1567,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-m10300.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-properties.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-sframe.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-solaris2.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-strtab.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf-vxworks.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf.Plo@am__quote@
diff --git a/bfd/configure b/bfd/configure
index 654a10dd84c..0312b36e3c1 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -15835,7 +15835,8 @@ coff="cofflink.lo $coffgen"
 ecoff="ecofflink.lo $coffgen"
 xcoff="xcofflink.lo $coffgen"
 
-elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-vxworks.lo"
+elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-solaris2.lo elf-vxworks.lo"
+elfxx_sparc="elfxx-sparc.lo elf-solaris2.lo elf-vxworks.lo $elf"
 for vec in $selvecs
 do
     target_size=32
@@ -16055,12 +16056,12 @@ do
     sh_elf32_vxworks_le_vec)	 tb="$tb elf32-sh.lo elf-vxworks.lo elf32.lo $elf coff-sh.lo $coff" ;;
     sh_pe_le_vec)		 tb="$tb pe-sh.lo coff-sh.lo peigen.lo $coff" ;;
     sh_pei_le_vec)		 tb="$tb pei-sh.lo coff-sh.lo peigen.lo $coff" ;;
-    sparc_elf32_vec)		 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf32_sol2_vec)	 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf32_vxworks_vec)	 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf64_vec)		 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
-    sparc_elf64_fbsd_vec)	 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
-    sparc_elf64_sol2_vec)	 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
+    sparc_elf32_vec)		 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf32_sol2_vec)	 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf32_vxworks_vec)	 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf64_vec)		 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+    sparc_elf64_fbsd_vec)	 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+    sparc_elf64_sol2_vec)	 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
     spu_elf32_vec)		 tb="$tb elf32-spu.lo elf32.lo $elf" ;;
     sym_vec)			 tb="$tb xsym.lo" ;;
     tic30_coff_vec)		 tb="$tb coff-tic30.lo $coffgen" ;;
diff --git a/bfd/configure.ac b/bfd/configure.ac
index f86c9eae754..f1477bca81b 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -376,7 +376,8 @@ coff="cofflink.lo $coffgen"
 ecoff="ecofflink.lo $coffgen"
 xcoff="xcofflink.lo $coffgen"
 
-elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-vxworks.lo"
+elfxx_x86="elfxx-x86.lo elf-ifunc.lo elf-solaris2.lo elf-vxworks.lo"
+elfxx_sparc="elfxx-sparc.lo elf-solaris2.lo elf-vxworks.lo $elf"
 for vec in $selvecs
 do
     target_size=32
@@ -596,12 +597,12 @@ do
     sh_elf32_vxworks_le_vec)	 tb="$tb elf32-sh.lo elf-vxworks.lo elf32.lo $elf coff-sh.lo $coff" ;;
     sh_pe_le_vec)		 tb="$tb pe-sh.lo coff-sh.lo peigen.lo $coff" ;;
     sh_pei_le_vec)		 tb="$tb pei-sh.lo coff-sh.lo peigen.lo $coff" ;;
-    sparc_elf32_vec)		 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf32_sol2_vec)	 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf32_vxworks_vec)	 tb="$tb elf32-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf32.lo $elf" ;;
-    sparc_elf64_vec)		 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
-    sparc_elf64_fbsd_vec)	 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
-    sparc_elf64_sol2_vec)	 tb="$tb elf64-sparc.lo elfxx-sparc.lo elf-vxworks.lo elf64.lo $elf"; target_size=64 ;;
+    sparc_elf32_vec)		 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf32_sol2_vec)	 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf32_vxworks_vec)	 tb="$tb elf32-sparc.lo elf32.lo $elfxx_sparc" ;;
+    sparc_elf64_vec)		 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+    sparc_elf64_fbsd_vec)	 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
+    sparc_elf64_sol2_vec)	 tb="$tb elf64-sparc.lo elf64.lo $elfxx_sparc"; target_size=64 ;;
     spu_elf32_vec)		 tb="$tb elf32-spu.lo elf32.lo $elf" ;;
     sym_vec)			 tb="$tb xsym.lo" ;;
     tic30_coff_vec)		 tb="$tb coff-tic30.lo $coffgen" ;;
diff --git a/bfd/elf-solaris2.c b/bfd/elf-solaris2.c
new file mode 100644
index 00000000000..84c4608a941
--- /dev/null
+++ b/bfd/elf-solaris2.c
@@ -0,0 +1,61 @@
+/* Solaris2 link support for BFD.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This file is part of BFD, the Binary File Descriptor library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+#include "sysdep.h"
+#include "bfd.h"
+#include "elf-bfd.h"
+#include "elf-solaris2.h"
+
+/* Global symbols required by the Solaris 2 ABI.  */
+const char *const elf_solaris2_global_syms[] = {
+  "_DYNAMIC",
+  "_GLOBAL_OFFSET_TABLE_",
+  "_PROCEDURE_LINKAGE_TABLE_",
+  "_edata",
+  "_end",
+  "_etext",
+  NULL
+};
+
+/* Strip these symbols out of any dynamic library.  Their value in a
+   shared library can never be of use in the output executable or
+   shared library being produced by the linker.  They will of course
+   be defined relative to the current output, but in the case of a PDE
+   that happens for the first three symbols after loading the first
+   shared library.  The trouble with that is that if the first shared
+   library happens to be as-needed, references from crt*.o to those
+   symbols will always make the library seem to be needed.  */
+bool
+elf_solaris2_add_symbol_hook (bfd *abfd,
+			      struct bfd_link_info *info ATTRIBUTE_UNUSED,
+			      Elf_Internal_Sym *isym ATTRIBUTE_UNUSED,
+			      const char **name,
+			      flagword *flags ATTRIBUTE_UNUSED,
+			      asection **sec ATTRIBUTE_UNUSED,
+			      bfd_vma *value ATTRIBUTE_UNUSED)
+{
+  if ((bfd_get_file_flags (abfd) & DYNAMIC) == 0 || *name == NULL)
+    return true;
+
+  if (is_solaris2_abi_global_sym (*name))
+    *name = NULL;
+
+  return true;
+}
diff --git a/bfd/elf-solaris2.h b/bfd/elf-solaris2.h
new file mode 100644
index 00000000000..0c7b1897c8f
--- /dev/null
+++ b/bfd/elf-solaris2.h
@@ -0,0 +1,34 @@
+/* Solaris2 link support for BFD.
+   Copyright (C) 2026 Free Software Foundation, Inc.
+
+   This file is part of BFD, the Binary File Descriptor library.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+extern const char *const elf_solaris2_global_syms[];
+
+extern bool elf_solaris2_add_symbol_hook
+  (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, const char **,
+   flagword *, asection **, bfd_vma *) ATTRIBUTE_HIDDEN;
+
+static inline bool
+is_solaris2_abi_global_sym (const char *name)
+{
+  for (const char *const *sym = elf_solaris2_global_syms; *sym; ++sym)
+    if (strcmp (name, *sym) == 0)
+      return true;
+  return false;
+}
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index c2b3c7dd165..8c7d7a74021 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -21,6 +21,7 @@
 #include "elfxx-x86.h"
 #include "elf-vxworks.h"
 #include "dwarf2.h"
+#include "elf-solaris2.h"
 #include "opcode/i386.h"
 
 /* 386 uses REL relocations instead of RELA.  */
@@ -4646,8 +4647,6 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
 #undef	elf32_bed
 #define	elf32_bed				elf32_i386_fbsd_bed
 
-#undef elf_backend_add_symbol_hook
-
 #include "elf32-target.h"
 
 #undef elf_backend_init_file_header
@@ -4684,6 +4683,9 @@ elf_i386_fbsd_init_file_header (bfd *abfd, struct bfd_link_info *info)
 #undef  elf_backend_want_plt_sym
 #define elf_backend_want_plt_sym	1
 
+#undef	elf_backend_add_symbol_hook
+#define	elf_backend_add_symbol_hook	    elf_solaris2_add_symbol_hook
+
 #include "elf32-target.h"
 
 /* Intel MCU support.  */
@@ -4724,6 +4726,7 @@ elf32_iamcu_elf_object_p (bfd *abfd)
 
 #undef	elf_backend_want_plt_sym
 #define elf_backend_want_plt_sym	0
+#undef	elf_backend_add_symbol_hook
 
 #include "elf32-target.h"
 
diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c
index b61b4bb9fb7..ad18e734d18 100644
--- a/bfd/elf32-sparc.c
+++ b/bfd/elf32-sparc.c
@@ -23,6 +23,7 @@
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "elf-solaris2.h"
 #include "elf/sparc.h"
 #include "opcode/sparc.h"
 #include "elfxx-sparc.h"
@@ -295,6 +296,9 @@ elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
 #undef	elf_backend_static_tls_alignment
 #define elf_backend_static_tls_alignment	8
 
+#undef	elf_backend_add_symbol_hook
+#define	elf_backend_add_symbol_hook		elf_solaris2_add_symbol_hook
+
 static bool
 elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
 						 bfd *obfd ATTRIBUTE_UNUSED,
diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c
index c73f2934edf..bb83ccdf20e 100644
--- a/bfd/elf64-sparc.c
+++ b/bfd/elf64-sparc.c
@@ -23,6 +23,7 @@
 #include "bfd.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "elf-solaris2.h"
 #include "elf/sparc.h"
 #include "opcode/sparc.h"
 #include "elfxx-sparc.h"
@@ -1006,6 +1007,21 @@ static const struct elf_size_info elf64_sparc_size_info =
 
 /* Solaris 2.  */
 
+static bool
+elf64_sparc_solaris2_add_symbol_hook (bfd *abfd,
+				      struct bfd_link_info *info,
+				      Elf_Internal_Sym *sym,
+				      const char **namep,
+				      flagword *flagsp,
+				      asection **secp,
+				      bfd_vma *valp)
+{
+  return (elf64_sparc_add_symbol_hook (abfd, info, sym, namep,
+				       flagsp, secp, valp)
+	  && elf_solaris2_add_symbol_hook (abfd, info, sym, namep,
+					   flagsp, secp, valp));
+}
+
 #undef	TARGET_BIG_SYM
 #define	TARGET_BIG_SYM				sparc_elf64_sol2_vec
 #undef	TARGET_BIG_NAME
@@ -1025,6 +1041,9 @@ static const struct elf_size_info elf64_sparc_size_info =
 #undef  elf_backend_static_tls_alignment
 #define elf_backend_static_tls_alignment	16
 
+#undef	elf_backend_add_symbol_hook
+#define	elf_backend_add_symbol_hook	elf64_sparc_solaris2_add_symbol_hook
+
 static bool
 elf64_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
                                   bfd *obfd ATTRIBUTE_UNUSED,
@@ -1040,5 +1059,3 @@ elf64_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSE
 #define elf_backend_copy_special_section_fields elf64_sparc_copy_solaris_special_section_fields
 
 #include "elf64-target.h"
-
-#undef  elf_backend_copy_special_section_fields
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 55102f83365..9ce487ca05e 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -23,6 +23,7 @@
 #include "dwarf2.h"
 #include "libiberty.h"
 #include "sframe.h"
+#include "elf-solaris2.h"
 
 #include "opcode/i386.h"
 
@@ -6436,6 +6437,21 @@ elf_x86_64_special_sections[]=
 
 /* Solaris 2 support.  */
 
+static bool
+elf_x86_64_solaris2_add_symbol_hook (bfd *abfd,
+				     struct bfd_link_info *info,
+				     Elf_Internal_Sym *sym,
+				     const char **namep,
+				     flagword *flagsp,
+				     asection **secp,
+				     bfd_vma *valp)
+{
+  return (elf_x86_64_add_symbol_hook (abfd, info, sym, namep,
+				      flagsp, secp, valp)
+	  && elf_solaris2_add_symbol_hook (abfd, info, sym, namep,
+					   flagsp, secp, valp));
+}
+
 #undef  TARGET_LITTLE_SYM
 #define TARGET_LITTLE_SYM		    x86_64_elf64_sol2_vec
 #undef  TARGET_LITTLE_NAME
@@ -6466,6 +6482,9 @@ elf_x86_64_special_sections[]=
 #undef  elf_backend_want_plt_sym
 #define elf_backend_want_plt_sym	    1
 
+#undef	elf_backend_add_symbol_hook
+#define	elf_backend_add_symbol_hook	    elf_x86_64_solaris2_add_symbol_hook
+
 #include "elf64-target.h"
 
 /* Restore defaults.  */
@@ -6474,6 +6493,8 @@ elf_x86_64_special_sections[]=
 #undef	elf_backend_static_tls_alignment
 #undef	elf_backend_want_plt_sym
 #define elf_backend_want_plt_sym	0
+#undef	elf_backend_add_symbol_hook
+#define elf_backend_add_symbol_hook	elf_x86_64_add_symbol_hook
 
 /* 32bit x86-64 support.  */
 
diff --git a/bfd/po/SRC-POTFILES.in b/bfd/po/SRC-POTFILES.in
index bb77914cf05..40632924764 100644
--- a/bfd/po/SRC-POTFILES.in
+++ b/bfd/po/SRC-POTFILES.in
@@ -144,6 +144,7 @@ elf-m10300.c
 elf-properties.c
 elf-s390.h
 elf-sframe.c
+elf-solaris2.c
 elf-strtab.c
 elf-vxworks.c
 elf-vxworks.h
diff --git a/ld/emultempl/solaris2.em b/ld/emultempl/solaris2.em
index 680b7bba87a..0b0be93d4b9 100644
--- a/ld/emultempl/solaris2.em
+++ b/ld/emultempl/solaris2.em
@@ -41,42 +41,62 @@ fragment <<EOF
    Cf. Linker and Libraries Guide, Ch. 2, Link-Editor, Generating the Output
    File, p.63.  */
 
+#include "elf-solaris2.h"
+
+/* Set things up early so that global syms will be defined by PROVIDE
+   assignments in elf.sc.  The alternative to this is to modify elf.sc
+   for Solaris to not use PROVIDE for assignments to _etext, _edata,
+   and _end.  */
+static void
+elf_solaris2_after_open (void)
+{
+  if (is_elf_hash_table (link_info.hash)
+      && elf_hash_table (&link_info)->target_os == is_solaris
+      && !bfd_link_relocatable (&link_info))
+    {
+      const char *const *sym;
+
+      for (sym = elf_solaris2_global_syms; *sym != NULL; sym++)
+	{
+	  struct elf_link_hash_entry *h
+	    = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
+				    true, false, false);
+	  if (h)
+	    /* Otherwise elf_fix_symbol_flags sets ref_regular, which
+	       results in an abort when a script doesn't define the sym.  */
+	    h->non_elf = 0;
+	}
+    }
+  ${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open} ();
+}
+
 static void
 elf_solaris2_before_allocation (void)
 {
   if (is_elf_hash_table (link_info.hash)
       && elf_hash_table (&link_info)->target_os == is_solaris)
     {
-      /* Global symbols required by the Solaris 2 ABI.  */
-      static const char *global_syms[] = {
-	"_DYNAMIC",
-	"_GLOBAL_OFFSET_TABLE_",
-	"_PROCEDURE_LINKAGE_TABLE_",
-	"_edata",
-	"_end",
-	"_etext",
-	NULL
-      };
       /* Local symbols required by the Solaris 2 ABI.  Already emitted by
 	 emulparams/solaris2.sh.  */
-      static const char *local_syms[] = {
+      static const char *const local_syms[] = {
 	"_START_",
 	"_END_",
 	NULL
       };
-      const char **sym;
+      const char *const *sym;
 
       /* Do this for both executables and shared objects.  */
       if (!bfd_link_relocatable (&link_info))
 	{
-	  for (sym = global_syms; *sym != NULL; sym++)
+	  for (sym = elf_solaris2_global_syms; *sym != NULL; sym++)
 	    {
 	      struct elf_link_hash_entry *h;
 
 	      /* Lookup symbol.  */
 	      h = elf_link_hash_lookup (elf_hash_table (&link_info), *sym,
 					false, false, false);
-	      if (h == NULL)
+	      if (h == NULL
+		  || h->root.type == bfd_link_hash_new)
 		continue;
 
 	      /* Undo the hiding done by _bfd_elf_define_linkage_sym.  */
@@ -114,7 +134,7 @@ elf_solaris2_before_allocation (void)
 	  struct bfd_elf_version_tree *basever;
 	  const char *soname;
 
-	  for (sym = global_syms; *sym != NULL; sym++)
+	  for (sym = elf_solaris2_global_syms; *sym != NULL; sym++)
 	    {
 	      /* Create a version pattern for this symbol.  Some of them start
 		 off as local, others as global, so try both.  */
@@ -148,4 +168,5 @@ elf_solaris2_before_allocation (void)
 
 EOF
 
+LDEMUL_AFTER_OPEN=elf_solaris2_after_open
 LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation

-- 
Alan Modra


More information about the Binutils mailing list