[binutils-gdb] Solaris emulation check
Alan Modra
amodra@sourceware.org
Sat Feb 21 00:28:10 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=533664fefb62f806bbb27a04f0d9385627950324
commit 533664fefb62f806bbb27a04f0d9385627950324
Author: Alan Modra <amodra@gmail.com>
Date: Sat Feb 21 10:56:33 2026 +1030
Solaris emulation check
elf_solaris2_before_allocation can be called when ld output is non-ELF,
but also when ld output is ELF but not Solaris. Split out from the
pr12320 fix due to the indentation change.
PR 12320
PR 33177
* emultempl/solaris2.em (elf_solaris_before_allocation): Wrap
everything done here in a more rigorous output hash table check.
Diff:
---
ld/emultempl/solaris2.em | 179 ++++++++++++++++++++++++-----------------------
1 file changed, 91 insertions(+), 88 deletions(-)
diff --git a/ld/emultempl/solaris2.em b/ld/emultempl/solaris2.em
index 671f72a0a3c..680b7bba87a 100644
--- a/ld/emultempl/solaris2.em
+++ b/ld/emultempl/solaris2.em
@@ -44,100 +44,103 @@ fragment <<EOF
static void
elf_solaris2_before_allocation (void)
{
- /* 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[] = {
- "_START_",
- "_END_",
- NULL
- };
- const char **sym;
-
- /* Do this for both executables and shared objects. */
- if (!bfd_link_relocatable (&link_info)
- && is_elf_hash_table (link_info.hash))
+ if (is_elf_hash_table (link_info.hash)
+ && elf_hash_table (&link_info)->target_os == is_solaris)
{
- for (sym = global_syms; *sym != NULL; sym++)
+ /* 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[] = {
+ "_START_",
+ "_END_",
+ NULL
+ };
+ const char **sym;
+
+ /* Do this for both executables and shared objects. */
+ if (!bfd_link_relocatable (&link_info))
{
- 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)
- continue;
-
- /* Undo the hiding done by _bfd_elf_define_linkage_sym. */
- h->forced_local = 0;
- h->other &= ~STV_HIDDEN;
-
- /* Emit it into the .dynamic section, too. */
- bfd_elf_link_record_dynamic_symbol (&link_info, h);
+ for (sym = 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)
+ continue;
+
+ /* Undo the hiding done by _bfd_elf_define_linkage_sym. */
+ h->forced_local = 0;
+ h->other &= ~STV_HIDDEN;
+
+ /* Emit it into the .dynamic section, too. */
+ bfd_elf_link_record_dynamic_symbol (&link_info, h);
+ }
+
+ for (sym = local_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)
+ continue;
+
+ /* Turn it local. */
+ h->forced_local = 1;
+ /* Type should be STT_OBJECT, not STT_NOTYPE. */
+ h->type = STT_OBJECT;
+ }
}
- for (sym = local_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)
- continue;
-
- /* Turn it local. */
- h->forced_local = 1;
- /* Type should be STT_OBJECT, not STT_NOTYPE. */
- h->type = STT_OBJECT;
- }
- }
-
- /* Only do this if emitting a shared object and versioning is in place. */
- if (bfd_link_dll (&link_info)
- && ((link_info.version_info != NULL
- && link_info.version_info->name[0] != '\0')
- || link_info.create_default_symver))
- {
- struct bfd_elf_version_expr *globals = NULL, *locals = NULL;
- struct bfd_elf_version_tree *basever;
- const char *soname;
-
- for (sym = global_syms; *sym != NULL; sym++)
+ /* Only do this if emitting a shared object and versioning is in place. */
+ if (bfd_link_dll (&link_info)
+ && ((link_info.version_info != NULL
+ && link_info.version_info->name[0] != '\0')
+ || link_info.create_default_symver))
{
- /* Create a version pattern for this symbol. Some of them start
- off as local, others as global, so try both. */
- globals = lang_new_vers_pattern (globals, *sym, NULL, true);
-
- /* Treat basever symbols as if from a linker script to
- appease --no-undefined-version. */
- globals->script = 1;
-
- locals = lang_new_vers_pattern (locals, *sym, NULL, true);
+ struct bfd_elf_version_expr *globals = NULL, *locals = NULL;
+ struct bfd_elf_version_tree *basever;
+ const char *soname;
+
+ for (sym = 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. */
+ globals = lang_new_vers_pattern (globals, *sym, NULL, true);
+
+ /* Treat basever symbols as if from a linker script to
+ appease --no-undefined-version. */
+ globals->script = 1;
+
+ locals = lang_new_vers_pattern (locals, *sym, NULL, true);
+ }
+
+ /* New version node for those symbols. */
+ basever = lang_new_vers_node (globals, locals);
+
+ /* The version name matches what bfd_elf_size_dynamic_sections uses
+ for the base version. */
+ soname = bfd_elf_get_dt_soname (link_info.output_bfd);
+ if (soname == NULL)
+ soname = lbasename (bfd_get_filename (link_info.output_bfd));
+
+ /* Register the node. */
+ lang_register_vers_node (soname, basever, NULL);
+ /* Enforce base version. The encoded vd_ndx is vernum + 1. */
+ basever->vernum = 0;
}
-
- /* New version node for those symbols. */
- basever = lang_new_vers_node (globals, locals);
-
- /* The version name matches what bfd_elf_size_dynamic_sections uses
- for the base version. */
- soname = bfd_elf_get_dt_soname (link_info.output_bfd);
- if (soname == NULL)
- soname = lbasename (bfd_get_filename (link_info.output_bfd));
-
- /* Register the node. */
- lang_register_vers_node (soname, basever, NULL);
- /* Enforce base version. The encoded vd_ndx is vernum + 1. */
- basever->vernum = 0;
}
${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation} ();
More information about the Binutils-cvs
mailing list