|
|
147e83 |
# commit 122b66defdb9e4ded3ccc5c2b290f0520c6fa3cd
|
|
|
147e83 |
# Author: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
|
|
|
147e83 |
# Date: Wed Dec 4 06:52:40 2013 -0600
|
|
|
147e83 |
#
|
|
|
147e83 |
# PowerPC64 ELFv2 ABI 3/6: PLT local entry point optimization
|
|
|
147e83 |
#
|
|
|
147e83 |
# This is a follow-on to the previous patch to support the ELFv2 ABI in the
|
|
|
147e83 |
# dynamic loader, split off into its own patch since it is just an optional
|
|
|
147e83 |
# optimization.
|
|
|
147e83 |
#
|
|
|
147e83 |
# In the ELFv2 ABI, most functions define both a global and a local entry
|
|
|
147e83 |
# point; the local entry requires r2 to be already set up by the caller
|
|
|
147e83 |
# to point to the callee's TOC; while the global entry does not require
|
|
|
147e83 |
# the caller to know about the callee's TOC, but it needs to set up r12
|
|
|
147e83 |
# to the callee's entry point address.
|
|
|
147e83 |
#
|
|
|
147e83 |
# Now, when setting up a PLT slot, the dynamic linker will usually need
|
|
|
147e83 |
# to enter the target function's global entry point. However, if the
|
|
|
147e83 |
# linker can prove that the target function is in the same DSO as the
|
|
|
147e83 |
# PLT slot itself, and the whole DSO only uses a single TOC (which the
|
|
|
147e83 |
# linker will let ld.so know via a DT_PPC64_OPT entry), then it is
|
|
|
147e83 |
# possible to actually enter the local entry point address into the
|
|
|
147e83 |
# PLT slot, for a slight improvement in performance.
|
|
|
147e83 |
#
|
|
|
147e83 |
# Note that this uncovered a problem on the first call via _dl_runtime_resolve,
|
|
|
147e83 |
# because that routine neglected to restore the caller's TOC before calling
|
|
|
147e83 |
# the target function for the first time, since it assumed that function
|
|
|
147e83 |
# would always reload its own TOC anyway ...
|
|
|
147e83 |
#
|
|
|
147e83 |
diff -urN glibc-2.17-c758a686/elf/elf.h glibc-2.17-c758a686/elf/elf.h
|
|
|
147e83 |
--- glibc-2.17-c758a686/elf/elf.h 2014-05-29 14:08:44.000000000 -0500
|
|
|
147e83 |
+++ glibc-2.17-c758a686/elf/elf.h 2014-05-29 14:08:44.000000000 -0500
|
|
|
147e83 |
@@ -2273,8 +2273,19 @@
|
|
|
147e83 |
#define DT_PPC64_GLINK (DT_LOPROC + 0)
|
|
|
147e83 |
#define DT_PPC64_OPD (DT_LOPROC + 1)
|
|
|
147e83 |
#define DT_PPC64_OPDSZ (DT_LOPROC + 2)
|
|
|
147e83 |
+#define DT_PPC64_OPT (DT_LOPROC + 3)
|
|
|
147e83 |
#define DT_PPC64_NUM 3
|
|
|
147e83 |
|
|
|
147e83 |
+/* PowerPC64 specific values for the DT_PPC64_OPT Dyn entry. */
|
|
|
147e83 |
+#define PPC64_OPT_TLS 1
|
|
|
147e83 |
+#define PPC64_OPT_MULTI_TOC 2
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* PowerPC64 specific values for the Elf64_Sym st_other field. */
|
|
|
147e83 |
+#define STO_PPC64_LOCAL_BIT 5
|
|
|
147e83 |
+#define STO_PPC64_LOCAL_MASK (7 << STO_PPC64_LOCAL_BIT)
|
|
|
147e83 |
+#define PPC64_LOCAL_ENTRY_OFFSET(other) \
|
|
|
147e83 |
+ (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2)
|
|
|
147e83 |
+
|
|
|
147e83 |
|
|
|
147e83 |
/* ARM specific declarations */
|
|
|
147e83 |
|
|
|
147e83 |
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h
|
|
|
147e83 |
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h 2014-05-29 14:08:40.000000000 -0500
|
|
|
147e83 |
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-machine.h 2014-05-29 14:08:44.000000000 -0500
|
|
|
147e83 |
@@ -425,6 +425,42 @@
|
|
|
147e83 |
return lazy;
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
+#if _CALL_ELF == 2
|
|
|
147e83 |
+/* If the PLT entry whose reloc is 'reloc' resolves to a function in
|
|
|
147e83 |
+ the same object, return the target function's local entry point
|
|
|
147e83 |
+ offset if usable. */
|
|
|
147e83 |
+static inline Elf64_Addr __attribute__ ((always_inline))
|
|
|
147e83 |
+ppc64_local_entry_offset (struct link_map *map, lookup_t sym_map,
|
|
|
147e83 |
+ const Elf64_Rela *reloc)
|
|
|
147e83 |
+{
|
|
|
147e83 |
+ const Elf64_Sym *symtab;
|
|
|
147e83 |
+ const Elf64_Sym *sym;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* If the target function is in a different object, we cannot
|
|
|
147e83 |
+ use the local entry point. */
|
|
|
147e83 |
+ if (sym_map != map)
|
|
|
147e83 |
+ return 0;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* If the linker inserted multiple TOCs, we cannot use the
|
|
|
147e83 |
+ local entry point. */
|
|
|
147e83 |
+ if (map->l_info[DT_PPC64(OPT)]
|
|
|
147e83 |
+ && (map->l_info[DT_PPC64(OPT)]->d_un.d_val & PPC64_OPT_MULTI_TOC))
|
|
|
147e83 |
+ return 0;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Otherwise, we can use the local entry point. Retrieve its offset
|
|
|
147e83 |
+ from the symbol's ELF st_other field. */
|
|
|
147e83 |
+ symtab = (const void *) D_PTR (map, l_info[DT_SYMTAB]);
|
|
|
147e83 |
+ sym = &symtab[ELFW(R_SYM) (reloc->r_info)];
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* If the target function is an ifunc then the local entry offset is
|
|
|
147e83 |
+ for the resolver, not the final destination. */
|
|
|
147e83 |
+ if (__builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0))
|
|
|
147e83 |
+ return 0;
|
|
|
147e83 |
+
|
|
|
147e83 |
+ return PPC64_LOCAL_ENTRY_OFFSET (sym->st_other);
|
|
|
147e83 |
+}
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
+
|
|
|
147e83 |
/* Change the PLT entry whose reloc is 'reloc' to call the actual
|
|
|
147e83 |
routine. */
|
|
|
147e83 |
static inline Elf64_Addr __attribute__ ((always_inline))
|
|
|
147e83 |
@@ -471,6 +507,7 @@
|
|
|
147e83 |
PPC_DCBST (&plt->fd_func);
|
|
|
147e83 |
PPC_ISYNC;
|
|
|
147e83 |
#else
|
|
|
147e83 |
+ finaladdr += ppc64_local_entry_offset (map, sym_map, reloc);
|
|
|
147e83 |
*reloc_addr = finaladdr;
|
|
|
147e83 |
#endif
|
|
|
147e83 |
|
|
|
147e83 |
@@ -478,7 +515,9 @@
|
|
|
147e83 |
}
|
|
|
147e83 |
|
|
|
147e83 |
static inline void __attribute__ ((always_inline))
|
|
|
147e83 |
-elf_machine_plt_conflict (Elf64_Addr *reloc_addr, Elf64_Addr finaladdr)
|
|
|
147e83 |
+elf_machine_plt_conflict (struct link_map *map, lookup_t sym_map,
|
|
|
147e83 |
+ const Elf64_Rela *reloc,
|
|
|
147e83 |
+ Elf64_Addr *reloc_addr, Elf64_Addr finaladdr)
|
|
|
147e83 |
{
|
|
|
147e83 |
#if _CALL_ELF != 2
|
|
|
147e83 |
Elf64_FuncDesc *plt = (Elf64_FuncDesc *) reloc_addr;
|
|
|
147e83 |
@@ -492,6 +531,7 @@
|
|
|
147e83 |
PPC_DCBST (&plt->fd_toc);
|
|
|
147e83 |
PPC_SYNC;
|
|
|
147e83 |
#else
|
|
|
147e83 |
+ finaladdr += ppc64_local_entry_offset (map, sym_map, reloc);
|
|
|
147e83 |
*reloc_addr = finaladdr;
|
|
|
147e83 |
#endif
|
|
|
147e83 |
}
|
|
|
147e83 |
@@ -641,7 +681,7 @@
|
|
|
147e83 |
/* Fall thru */
|
|
|
147e83 |
case R_PPC64_JMP_SLOT:
|
|
|
147e83 |
#ifdef RESOLVE_CONFLICT_FIND_MAP
|
|
|
147e83 |
- elf_machine_plt_conflict (reloc_addr, value);
|
|
|
147e83 |
+ elf_machine_plt_conflict (map, sym_map, reloc, reloc_addr, value);
|
|
|
147e83 |
#else
|
|
|
147e83 |
elf_machine_fixup_plt (map, sym_map, reloc, reloc_addr, value);
|
|
|
147e83 |
#endif
|
|
|
147e83 |
diff -urN glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S
|
|
|
147e83 |
--- glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S 2014-05-29 14:08:40.000000000 -0500
|
|
|
147e83 |
+++ glibc-2.17-c758a686/sysdeps/powerpc/powerpc64/dl-trampoline.S 2014-05-29 14:08:44.000000000 -0500
|
|
|
147e83 |
@@ -74,6 +74,10 @@
|
|
|
147e83 |
/* Prepare for calling the function returned by fixup. */
|
|
|
147e83 |
PPC64_LOAD_FUNCPTR r3
|
|
|
147e83 |
ld r3,INT_PARMS+0(r1)
|
|
|
147e83 |
+#if _CALL_ELF == 2
|
|
|
147e83 |
+/* Restore the caller's TOC in case we jump to a local entry point. */
|
|
|
147e83 |
+ ld r2,FRAME_SIZE+40(r1)
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
/* Unwind the stack frame, and jump. */
|
|
|
147e83 |
addi r1,r1,FRAME_SIZE
|
|
|
147e83 |
bctr
|
|
|
147e83 |
@@ -321,6 +325,10 @@
|
|
|
147e83 |
/* Prepare for calling the function returned by fixup. */
|
|
|
147e83 |
PPC64_LOAD_FUNCPTR r3
|
|
|
147e83 |
ld r3,INT_PARMS+0(r1)
|
|
|
147e83 |
+#if _CALL_ELF == 2
|
|
|
147e83 |
+/* Restore the caller's TOC in case we jump to a local entry point. */
|
|
|
147e83 |
+ ld r2,FRAME_SIZE+40(r1)
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
/* Load the floating point registers. */
|
|
|
147e83 |
lfd fp1,FPR_PARMS+0(r1)
|
|
|
147e83 |
lfd fp2,FPR_PARMS+8(r1)
|