Make Solaris global ABI symbols SHN_ABS

Alan Modra amodra@gmail.com
Tue Feb 17 00:58:04 GMT 2026


I have some reservations about making the global ABI symbols SHN_ABS,
but that's what the Solaris ABI says.  The problem with SHN_ABS
symbols holding addresses as is the case with all of these symbols, is
that in a shared libary or PIE those symbols must be relocated by the
base address of the library if they are used in dynamic relocations.
Which is wrong according to the ELF gABI:

SHN_ABS
    The symbol has an absolute value that will not change because of
    relocation.

For that reason GNU binutils has moved away from making _DYNAMIC,
_GLOBAL_OFFSET_TABLE_ and similar symbols SHN_ABS on a number of
targets.

	PR 33177
	* elf32-i386.c (elf_i386_finish_dynamic_symbol): Make Solaris ABI
	globals SHN_ABS.
	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Likewise.
	* elfxx-sparc.c (_bfd_sparc_elf_finish_dynamic_symbol): Likewise.

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 8c7d7a74021..aa0bec4a18c 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -4050,6 +4050,11 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
       _bfd_elf_append_rel (output_bfd, s, &rel);
     }
 
+  if (sym != NULL
+      && htab->elf.target_os == is_solaris
+      && is_solaris2_abi_global_sym (h->root.root.string))
+    sym->st_shndx = SHN_ABS;
+
   return true;
 }
 
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 9ce487ca05e..35c630e611e 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5561,6 +5561,11 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
       _bfd_elf_append_rela (output_bfd, s, &rela);
     }
 
+  if (sym != NULL
+      && htab->elf.target_os == is_solaris
+      && is_solaris2_abi_global_sym (h->root.root.string))
+    sym->st_shndx = SHN_ABS;
+
   return true;
 }
 
diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c
index d55dd04996f..e2b97dfd8d4 100644
--- a/bfd/elfxx-sparc.c
+++ b/bfd/elfxx-sparc.c
@@ -27,6 +27,7 @@
 #include "libbfd.h"
 #include "libiberty.h"
 #include "elf-bfd.h"
+#include "elf-solaris2.h"
 #include "elf/sparc.h"
 #include "opcode/sparc.h"
 #include "elfxx-sparc.h"
@@ -4470,7 +4471,9 @@ _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
   if (sym != NULL
       && (h == htab->elf.hdynamic
 	  || (htab->elf.target_os != is_vxworks
-	      && (h == htab->elf.hgot || h == htab->elf.hplt))))
+	      && (h == htab->elf.hgot || h == htab->elf.hplt))
+	  || (htab->elf.target_os == is_solaris
+	      && is_solaris2_abi_global_sym (h->root.root.string))))
     sym->st_shndx = SHN_ABS;
 
   return true;

-- 
Alan Modra


More information about the Binutils mailing list