[aarch64] Fix misplaced synthetic plt syms

Michael Matz matz@suse.de
Thu Nov 13 17:35:46 GMT 2025


the placement of these symbols depends on knowing the
size of PLT entries.  Those differ depending on its security
type and if the file in question is an executable or shared lib.
To test the latter it's not enough to check the e_type: detecting
PIEs need to check DF_FLAGS_1 as well.  Conveniently there's
already a is_pie member in elf_tdata, it just isn't setup outside
of a linking setup.  So do that in get_plt_type and use it
in elfNN_aarch64_plt_sym_val.

bfd/
	PR binutils/33593
	elfnn-arch64.c (get_plt_type): Initialize tdatas is_pie.
	(elfNN_aarch64_plt_sym_val): Use it to detect PIEs.
---

Tested on many targets (including aarch64 of course).

 bfd/elfnn-aarch64.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 60bc946d196..1e4ec4780a1 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -10437,11 +10437,12 @@ get_plt_type (bfd *abfd)
 
       /* Let's check the processor specific dynamic array tags.  */
       bfd_vma tag = dyn.d_tag;
-      if (tag < DT_LOPROC || tag > DT_HIPROC)
-	continue;
-
       switch (tag)
 	{
+	case DT_FLAGS_1:
+	  elf_tdata (abfd)->is_pie = (dyn.d_un.d_val & DF_1_PIE) != 0;
+	  break;
+
 	case DT_AARCH64_BTI_PLT:
 	  ret |= PLT_BTI;
 	  break;
@@ -10484,14 +10485,16 @@ elfNN_aarch64_plt_sym_val (bfd_vma i, const asection *plt,
     = elf_aarch64_tdata (plt->owner)->sw_protections.plt_type;
   if (plt_type == PLT_BTI_PAC)
     {
-      if (elf_elfheader (plt->owner)->e_type == ET_EXEC)
+      if (elf_elfheader (plt->owner)->e_type == ET_EXEC
+	  || elf_tdata (plt->owner)->is_pie)
 	pltn_size = PLT_BTI_PAC_SMALL_ENTRY_SIZE;
       else
 	pltn_size = PLT_PAC_SMALL_ENTRY_SIZE;
     }
   else if (plt_type == PLT_BTI)
     {
-      if (elf_elfheader (plt->owner)->e_type == ET_EXEC)
+      if (elf_elfheader (plt->owner)->e_type == ET_EXEC
+	  || elf_tdata (plt->owner)->is_pie)
 	pltn_size = PLT_BTI_SMALL_ENTRY_SIZE;
     }
   else if (plt_type == PLT_PAC)
-- 
2.50.1


More information about the Binutils mailing list