[PATCH 2/2] elf: Defer arch PLT IFUNC relocations in the two-phase relocation split

Adhemerval Zanella <[email protected]>
Newsgroups gmane.comp.lib.glibc.alpha
Message-ID <[email protected]>
The split introduced by commit 63b31c05a8a does not handle sparc
and (R_SPARC_JMP_IREL) powerpc64 (ELFv1, R_PPC64_JMP_IREL), which
are emited in some constructions.  Handle such cases on
elf_dynamic_is_Rel_irelative.

It fixes elf/tst-ifunc-fault-bindnow and elf/tst-ifunc-fault-lazy on
sparc64 (powerpc64 emits R_PPC64_IRELATIVE in both cases,
R_PPC64_JMP_IREL is emitted only when the ifunc is called, not just
referenced).

Checked with the elf tests on qemu sparc64 and powerpc64.
---
 elf/do-rel.h                           | 8 +++++++-
 sysdeps/powerpc/powerpc64/dl-machine.h | 1 +
 sysdeps/sparc/sparc32/dl-machine.h     | 1 +
 sysdeps/sparc/sparc64/dl-machine.h     | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/elf/do-rel.h b/elf/do-rel.h
index c7a8be368f0..77022447348 100644
--- a/elf/do-rel.h
+++ b/elf/do-rel.h
@@ -45,7 +45,13 @@ elf_dynamic_is_Rel_irelative (const ElfW(Rel) *reloc, const ElfW(Sym) *sym)
   return ((sym != NULL
 	   && ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC
 	   && sym->st_shndx != SHN_UNDEF)
-	  || r_type == ELF_MACHINE_IRELATIVE);
+	  || r_type == ELF_MACHINE_IRELATIVE
+# ifdef ELF_MACHINE_IRELATIVE_PLT
+	  /* Some ports resolve an IFUNC PLT slot for a local resolver with a
+	     dedicated reloc that carries no symboli.  */
+	  || r_type == ELF_MACHINE_IRELATIVE_PLT
+# endif
+	  );
 #else
   return false;
 #endif
diff --git a/sysdeps/powerpc/powerpc64/dl-machine.h b/sysdeps/powerpc/powerpc64/dl-machine.h
index 1f5d7a0170b..f1ce639843e 100644
--- a/sysdeps/powerpc/powerpc64/dl-machine.h
+++ b/sysdeps/powerpc/powerpc64/dl-machine.h
@@ -305,6 +305,7 @@ BODY_PREFIX "_dl_start_user:\n"						\
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
 #define ELF_MACHINE_JMP_SLOT	R_PPC64_JMP_SLOT
 #define ELF_MACHINE_IRELATIVE	R_PPC64_IRELATIVE
+#define ELF_MACHINE_IRELATIVE_PLT R_PPC64_JMP_IREL
 
 /* We define an initialization function to initialize HWCAP/HWCAP2 and
    platform data so it can be copied into the TCB later.  This is called
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index 3771339a04a..540e7d24e26 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -157,6 +157,7 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
 #define ELF_MACHINE_JMP_SLOT	R_SPARC_JMP_SLOT
 #define ELF_MACHINE_IRELATIVE	R_SPARC_IRELATIVE
+#define ELF_MACHINE_IRELATIVE_PLT R_SPARC_JMP_IREL
 
 /* Undo the sub %sp, 6*4, %sp; add %sp, 22*4, %o0 below to get at the
    value we want in __libc_stack_end.  */
diff --git a/sysdeps/sparc/sparc64/dl-machine.h b/sysdeps/sparc/sparc64/dl-machine.h
index 8a1a38d1701..0885f4dc913 100644
--- a/sysdeps/sparc/sparc64/dl-machine.h
+++ b/sysdeps/sparc/sparc64/dl-machine.h
@@ -120,6 +120,7 @@ elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc,
 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
 #define ELF_MACHINE_JMP_SLOT	R_SPARC_JMP_SLOT
 #define ELF_MACHINE_IRELATIVE	R_SPARC_IRELATIVE
+#define ELF_MACHINE_IRELATIVE_PLT R_SPARC_JMP_IREL
 
 /* Set up the loaded object described by L so its unrelocated PLT
    entries will jump to the on-demand fixup code in dl-runtime.c.  */
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.