blob: 78a695e2ccc05dff1dbfa68054536dde8a179e26 [file] [log] [blame]
This patch adds experimental support for SHT_RELR sections, proposed
here: https://groups.google.com/forum/#!topic/generic-abi/bX460iggiKg
SHT_RELR sections are supported for arm, aarch64, and x86_64 targets.
To enable them, pass '--experimental-use-relr' flag to gold.
Definitions for the new ELF section type and dynamic array tags, as well
as the encoding used in the new section are all under discussion and are
subject to change. We plan to send the patch upstream after the gABI has
been updated to include the new definitions.
--- elf/do-rel.h
+++ elf/do-rel.h
@@ -26,6 +26,12 @@
# define elf_machine_rel_relative elf_machine_rela_relative
#endif
+#ifdef DO_RELR
+# define elf_dynamic_do_Rel elf_dynamic_do_Relr
+# define Rel Relr
+# define elf_machine_rel_relative elf_machine_relr_relative
+#endif
+
#ifndef DO_ELF_MACHINE_REL_RELATIVE
# define DO_ELF_MACHINE_REL_RELATIVE(map, l_addr, relative) \
elf_machine_rel_relative (l_addr, relative, \
@@ -46,12 +52,12 @@ elf_dynamic_do_Rel (struct link_map *map,
const ElfW(Rel) *r = (const void *) reladdr;
const ElfW(Rel) *end = (const void *) (reladdr + relsize);
ElfW(Addr) l_addr = map->l_addr;
-# if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP
+# if defined ELF_MACHINE_IRELATIVE && !defined RTLD_BOOTSTRAP && !defined DO_RELR
const ElfW(Rel) *r2 = NULL;
const ElfW(Rel) *end2 = NULL;
# endif
-#if (!defined DO_RELA || !defined ELF_MACHINE_PLT_REL) && !defined RTLD_BOOTSTRAP
+#if (!defined DO_RELA || !defined ELF_MACHINE_PLT_REL) && !defined RTLD_BOOTSTRAP && !defined DO_RELR
/* We never bind lazily during ld.so bootstrap. Unfortunately gcc is
not clever enough to see through all the function calls to realize
that. */
@@ -80,8 +86,10 @@ elf_dynamic_do_Rel (struct link_map *map,
else
#endif
{
+# if !defined DO_RELR
const ElfW(Sym) *const symtab =
(const void *) D_PTR (map, l_info[DT_SYMTAB]);
+# endif
const ElfW(Rel) *relative = r;
r += nrelative;
@@ -108,9 +116,36 @@ elf_dynamic_do_Rel (struct link_map *map,
if (l_addr != 0 || ! map->l_info[VALIDX(DT_GNU_PRELINKED)])
# endif
#endif
+
+#ifdef DO_RELR
+ {
+ ElfW(Addr) base = 0;
+ for (; relative < end; ++relative)
+ {
+ ElfW(Relr) entry = *relative;
+ if ((entry&1) == 0)
+ {
+ elf_machine_relr_relative (l_addr, (void *) (l_addr + entry));
+ base = entry + sizeof(ElfW(Addr));
+ continue;
+ }
+ ElfW(Addr) offset = base;
+ while (entry != 0)
+ {
+ entry >>= 1;
+ if ((entry&1) != 0)
+ elf_machine_relr_relative (l_addr, (void *) (l_addr + offset));
+ offset += sizeof(ElfW(Addr));
+ }
+ base += (8*sizeof(ElfW(Addr)) - 1) * sizeof(ElfW(Addr));
+ }
+ }
+#else
for (; relative < r; ++relative)
DO_ELF_MACHINE_REL_RELATIVE (map, l_addr, relative);
+#endif
+#if !defined DO_RELR
#ifdef RTLD_BOOTSTRAP
/* The dynamic linker always uses versioning. */
assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
@@ -180,6 +215,7 @@ elf_dynamic_do_Rel (struct link_map *map,
# endif
}
#endif
+#endif
}
}
@@ -189,3 +225,4 @@ elf_dynamic_do_Rel (struct link_map *map,
#undef elf_machine_rel_relative
#undef DO_ELF_MACHINE_REL_RELATIVE
#undef DO_RELA
+#undef DO_RELR
--- elf/dynamic-link.h
+++ elf/dynamic-link.h
@@ -76,6 +76,11 @@ auto inline void __attribute__((always_inline))
elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
void *const reloc_addr);
# endif
+# if ! ELF_MACHINE_NO_RELR
+auto inline void __attribute__((always_inline))
+elf_machine_relr_relative (ElfW(Addr) l_addr,
+ void *const reloc_addr);
+# endif
# if ELF_MACHINE_NO_RELA || defined ELF_MACHINE_PLT_REL
auto inline void __attribute__((always_inline))
elf_machine_lazy_rel (struct link_map *map,
@@ -190,6 +195,15 @@ elf_machine_lazy_rel (struct link_map *map,
# define ELF_DYNAMIC_DO_RELA(map, lazy, skip_ifunc) /* Nothing to do. */
# endif
+# if ! ELF_MACHINE_NO_RELR
+# define DO_RELR
+# include "do-rel.h"
+# define ELF_DYNAMIC_DO_RELR(map, lazy, skip_ifunc) \
+ _ELF_DYNAMIC_DO_RELOC (RELR, Relr, map, lazy, skip_ifunc, 1)
+# else
+# define ELF_DYNAMIC_DO_RELR(map, lazy, skip_ifunc) /* Nothing to do. */
+# endif
+
/* This can't just be an inline function because GCC is too dumb
to inline functions containing inlines themselves. */
# define ELF_DYNAMIC_RELOCATE(map, lazy, consider_profile, skip_ifunc) \
@@ -198,6 +212,7 @@ elf_machine_lazy_rel (struct link_map *map,
(consider_profile)); \
ELF_DYNAMIC_DO_REL ((map), edr_lazy, skip_ifunc); \
ELF_DYNAMIC_DO_RELA ((map), edr_lazy, skip_ifunc); \
+ ELF_DYNAMIC_DO_RELR ((map), edr_lazy, skip_ifunc); \
} while (0)
#endif
--- elf/elf.h
+++ elf/elf.h
@@ -334,7 +334,8 @@ typedef struct
#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
#define SHT_GROUP 17 /* Section group */
#define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */
-#define SHT_NUM 19 /* Number of defined types. */
+#define SHT_RELR 19 /* Relative relocation, only offsets */
+#define SHT_NUM 20 /* Number of defined types. */
#define SHT_LOOS 0x60000000 /* Start OS-specific. */
#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */
#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */
@@ -552,6 +553,12 @@ typedef struct
Elf64_Sxword r_addend; /* Addend */
} Elf64_Rela;
+/* Relocation table entry for relative (in section of type SHT_RELR). */
+
+typedef Elf32_Word Elf32_Relr; /* offset/bitmap for relative relocations */
+
+typedef Elf64_Xword Elf64_Relr; /* offset/bitmap for relative relocations */
+
/* How to extract and insert information held in the r_info field. */
#define ELF32_R_SYM(val) ((val) >> 8)
@@ -731,7 +738,11 @@ typedef struct
#define DT_ENCODING 32 /* Start of encoded range */
#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
-#define DT_NUM 34 /* Number used */
+#define DT_SYMTAB_SHNDX 34
+#define DT_RELRSZ 35
+#define DT_RELR 36
+#define DT_RELRENT 37
+#define DT_NUM 38 /* Number used */
#define DT_LOOS 0x6000000d /* Start of OS-specific */
#define DT_HIOS 0x6ffff000 /* End of OS-specific */
#define DT_LOPROC 0x70000000 /* Start of processor-specific */
@@ -783,6 +794,7 @@ typedef struct
GNU extension. */
#define DT_VERSYM 0x6ffffff0
+#define DT_RELRCOUNT 0x6ffffff8
#define DT_RELACOUNT 0x6ffffff9
#define DT_RELCOUNT 0x6ffffffa
--- elf/get-dynamic-info.h
+++ elf/get-dynamic-info.h
@@ -105,6 +105,9 @@ elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
# if ! ELF_MACHINE_NO_REL
ADJUST_DYN_INFO (DT_REL);
# endif
+# if ! ELF_MACHINE_NO_RELR
+ ADJUST_DYN_INFO (DT_RELR);
+#endif
ADJUST_DYN_INFO (DT_JMPREL);
ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
@@ -132,6 +135,10 @@ elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
if (info[DT_REL] != NULL)
assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
#endif
+#if ! ELF_MACHINE_NO_RELR
+ if (info[DT_RELR] != NULL)
+ assert (info[DT_RELRENT]->d_un.d_val == sizeof (ElfW(Relr)));
+# endif
#ifdef RTLD_BOOTSTRAP
/* Only the bind now flags are allowed. */
assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
--- sysdeps/aarch64/dl-machine.h
+++ sysdeps/aarch64/dl-machine.h
@@ -203,6 +203,7 @@ _dl_start_user: \n\
/* AArch64 uses RELA not REL */
#define ELF_MACHINE_NO_REL 1
#define ELF_MACHINE_NO_RELA 0
+#define ELF_MACHINE_NO_RELR 0
static inline ElfW(Addr)
elf_machine_fixup_plt (struct link_map *map, lookup_t t,
@@ -368,6 +369,15 @@ elf_machine_rela_relative (ElfW(Addr) l_addr,
inline void
__attribute__ ((always_inline))
+elf_machine_relr_relative (ElfW(Addr) l_addr,
+ void *const reloc_addr_arg)
+{
+ ElfW(Addr) *const reloc_addr = reloc_addr_arg;
+ *reloc_addr += l_addr;
+}
+
+inline void
+__attribute__ ((always_inline))
elf_machine_lazy_rel (struct link_map *map,
ElfW(Addr) l_addr,
const ElfW(Rela) *reloc,
--- sysdeps/arm/dl-machine.h
+++ sysdeps/arm/dl-machine.h
@@ -284,6 +284,7 @@ elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
Prelinked libraries may use Elf32_Rela though. */
#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
#define ELF_MACHINE_NO_REL 0
+#define ELF_MACHINE_NO_RELR 0
/* Names of the architecture-specific auditing callback functions. */
#define ARCH_LA_PLTENTER arm_gnu_pltenter
@@ -650,6 +651,15 @@ elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
*reloc_addr += l_addr;
}
+auto inline void
+__attribute ((always_inline))
+elf_machine_relr_relative (ElfW(Addr) l_addr,
+ void *const reloc_addr_arg)
+{
+ ElfW(Addr) *const reloc_addr = reloc_addr_arg;
+ *reloc_addr += l_addr;
+}
+
# ifndef RTLD_BOOTSTRAP
auto inline void
__attribute__ ((always_inline))
--- sysdeps/i386/dl-machine.h
+++ sysdeps/i386/dl-machine.h
@@ -267,6 +267,7 @@ elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
Prelinked libraries may use Elf32_Rela though. */
#define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
#define ELF_MACHINE_NO_REL 0
+#define ELF_MACHINE_NO_RELR 0
#ifdef RESOLVE_MAP
@@ -616,6 +616,15 @@
*reloc_addr += l_addr;
}
+auto inline void
+__attribute ((always_inline))
+elf_machine_relr_relative (ElfW(Addr) l_addr,
+ void *const reloc_addr_arg)
+{
+ ElfW(Addr) *const reloc_addr = reloc_addr_arg;
+ *reloc_addr += l_addr;
+}
+
# ifndef RTLD_BOOTSTRAP
auto inline void
__attribute__ ((always_inline))
--- sysdeps/x86_64/dl-machine.h
+++ sysdeps/x86_64/dl-machine.h
@@ -212,6 +212,7 @@ _dl_start_user:\n\
/* The x86-64 never uses Elf64_Rel/Elf32_Rel relocations. */
#define ELF_MACHINE_NO_REL 1
#define ELF_MACHINE_NO_RELA 0
+#define ELF_MACHINE_NO_RELR 0
/* We define an initialization function. This is called very early in
_dl_sysdep_start. */
@@ -521,6 +522,15 @@ elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
auto inline void
__attribute ((always_inline))
+elf_machine_relr_relative (ElfW(Addr) l_addr,
+ void *const reloc_addr_arg)
+{
+ ElfW(Addr) *const reloc_addr = reloc_addr_arg;
+ *reloc_addr += l_addr;
+}
+
+auto inline void
+__attribute ((always_inline))
elf_machine_lazy_rel (struct link_map *map,
ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
int skip_ifunc)