elf-m10300.lo \
elf-properties.lo \
elf-sframe.lo \
+ elf-solaris2.lo \
elf-strtab.lo \
elf-vxworks.lo \
elf.lo \
elf-m10300.c \
elf-properties.c \
elf-sframe.c \
+ elf-solaris2.c \
elf-strtab.c \
elf-vxworks.c \
elf.c \
elf-m10300.lo \
elf-properties.lo \
elf-sframe.lo \
+ elf-solaris2.lo \
elf-strtab.lo \
elf-vxworks.lo \
elf.lo \
elf-m10300.c \
elf-properties.c \
elf-sframe.c \
+ elf-solaris2.c \
elf-strtab.c \
elf-vxworks.c \
elf.c \
@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@
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" ;;
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" ;;
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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;
+}
#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. */
#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
#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. */
#undef elf_backend_want_plt_sym
#define elf_backend_want_plt_sym 0
+#undef elf_backend_add_symbol_hook
#include "elf32-target.h"
#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"
#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,
#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"
/* 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
#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,
#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
#include "dwarf2.h"
#include "libiberty.h"
#include "sframe.h"
+#include "elf-solaris2.h"
#include "opcode/i386.h"
/* 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
#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. */
#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. */
elf-properties.c
elf-s390.h
elf-sframe.c
+elf-solaris2.c
elf-strtab.c
elf-vxworks.c
elf-vxworks.h
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. */
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. */
EOF
+LDEMUL_AFTER_OPEN=elf_solaris2_after_open
LDEMUL_BEFORE_ALLOCATION=elf_solaris2_before_allocation