]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR 12320 ld --as-needed links libgcc_s.so.1 unnecessarily on Solaris
authorAlan Modra <amodra@gmail.com>
Sat, 21 Feb 2026 00:26:43 +0000 (10:56 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 21 Feb 2026 00:26:43 +0000 (10:56 +1030)
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.

12 files changed:
bfd/Makefile.am
bfd/Makefile.in
bfd/configure
bfd/configure.ac
bfd/elf-solaris2.c [new file with mode: 0644]
bfd/elf-solaris2.h [new file with mode: 0644]
bfd/elf32-i386.c
bfd/elf32-sparc.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/po/SRC-POTFILES.in
ld/emultempl/solaris2.em

index 056f0eee3dac9c1a398c52e786126a463961d4a8..e4df05441eb7add7bae926c6796654778853b5f0 100644 (file)
@@ -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 \
index 82041970a61049a8582bf438ad1b543574d1db51..14512cf61fb37c586b5f4c13ec9f54cb3af1348f 100644 (file)
@@ -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@
index 654a10dd84c5faf46b3df5cd6ce071fd120488e1..0312b36e3c1da4941efc81b502eabbed7a1e5b61 100755 (executable)
@@ -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
     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" ;;
index f86c9eae754a7ee50bfca9dab6208ca3634ad3b5..f1477bca81b0dbbb454a29ad3009b6d099db838e 100644 (file)
@@ -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 (file)
index 0000000..84c4608
--- /dev/null
@@ -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 (file)
index 0000000..0c7b189
--- /dev/null
@@ -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;
+}
index c2b3c7dd16530fdd64579dd60bef3121760ff85d..8c7d7a74021aa84557704381552af301cc3a271f 100644 (file)
@@ -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"
 
index b61b4bb9fb79c94c4749252a748e26917a3c6cd3..ad18e734d180c270a68876c9719055ef8000ea1b 100644 (file)
@@ -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,
index c73f2934edfaade7c96cdef25e35ca4d8e693939..bb83ccdf20eb304fd661c16556800c1dd1159ab8 100644 (file)
@@ -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
index 55102f833657c9ab16ca5b920303d5f5a2661873..9ce487ca05e99b5474e3d7806e1787fae92808c0 100644 (file)
@@ -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.  */
 
index bb77914cf059282b86dff7b9227e3bc35e75c2bf..406329247646ba524d22a677b164393ac98834c7 100644 (file)
@@ -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
index 680b7bba87a88db25abdbc1e9d303bbcc8ce474e..0b0be93d4b97b454364c0fbe25263bf5d387b6d9 100644 (file)
@@ -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