Solaris emulation check

Alan Modra amodra@gmail.com
Tue Feb 17 00:55:22 GMT 2026
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.  diff -w shown here.

	PR 12320
	PR 33177
	* emultempl/solaris2.em (elf_solaris_before_allocation): Wrap
	everything done here in a more rigorous output hash table check.

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
@@ -43,6 +43,9 @@ fragment <<EOF
 
 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[] = {
@@ -64,8 +67,7 @@ elf_solaris2_before_allocation (void)
       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 (!bfd_link_relocatable (&link_info))
 	{
 	  for (sym = global_syms; *sym != NULL; sym++)
 	    {
@@ -139,6 +141,7 @@ elf_solaris2_before_allocation (void)
 	  /* Enforce base version.  The encoded vd_ndx is vernum + 1.  */
 	  basever->vernum = 0;
 	}
+    }
 
   ${LDEMUL_BEFORE_ALLOCATION-gld${EMULATION_NAME}_before_allocation} ();
 }

-- 
Alan Modra


More information about the Binutils mailing list