From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7814) id 9909E3858403; Fri, 19 Nov 2021 21:23:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9909E3858403 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Fangrui Song To: glibc-cvs@sourceware.org Subject: [glibc/google/grte/v5-2.27/master] elf: Support DT_RELR relative relocation format X-Act-Checkin: glibc X-Git-Author: Fangrui Song X-Git-Refname: refs/heads/google/grte/v5-2.27/master X-Git-Oldrev: c0a436544259c7aef8871c29731a48dc715039db X-Git-Newrev: d59cb9842ce708bd4fc057aaf143e4afab921197 Message-Id: <20211119212329.9909E3858403@sourceware.org> Date: Fri, 19 Nov 2021 21:23:29 +0000 (GMT) X-BeenThere: glibc-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Nov 2021 21:23:29 -0000 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d59cb9842ce708bd4fc057aaf143e4afab921197 commit d59cb9842ce708bd4fc057aaf143e4afab921197 Author: Fangrui Song Date: Fri Nov 19 13:21:57 2021 -0800 elf: Support DT_RELR relative relocation format Upstream patch: https://sourceware.org/pipermail/libc-alpha/2021-October/132029.html Bikeshedding: https://sourceware.org/pipermail/libc-alpha/2021-November/133009.html This commit removes configure.ac and test changes to avoid conflict when the upstream finally gets the feature. Diff: --- elf/dynamic-link.h | 28 ++++++++++++++++++++++++++++ elf/elf.h | 16 +++++++++++++--- elf/get-dynamic-info.h | 3 +++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index f576d787e3..5e72ddc972 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -253,6 +253,33 @@ elf_machine_lazy_rel (struct link_map *map, # define ELF_DYNAMIC_DO_RELA(map, lazy, skip_ifunc, boot_map) /* Nothing to do. */ # endif +# define ELF_DYNAMIC_DO_RELR(map) \ + do { \ + ElfW(Addr) l_addr = (map)->l_addr, *where = 0; \ + const ElfW(Relr) *r, *end; \ + if (!(map)->l_info[DT_RELR]) \ + break; \ + r = (const ElfW(Relr) *)D_PTR((map), l_info[DT_RELR]); \ + end = (const ElfW(Relr) *)((const char *)r + \ + (map)->l_info[DT_RELRSZ]->d_un.d_val); \ + for (; r < end; r++) \ + { \ + ElfW(Relr) entry = *r; \ + if ((entry & 1) == 0) \ + { \ + where = (ElfW(Addr) *)(l_addr + entry); \ + *where++ += l_addr; \ + } \ + else \ + { \ + for (long i = 0; (entry >>= 1) != 0; i++) \ + if ((entry & 1) != 0) \ + where[i] += l_addr; \ + where += CHAR_BIT * sizeof(ElfW(Relr)) - 1; \ + } \ + } \ + } while (0); + /* 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, boot_map) \ @@ -261,6 +288,7 @@ elf_machine_lazy_rel (struct link_map *map, (consider_profile)); \ ELF_DYNAMIC_DO_REL ((map), edr_lazy, skip_ifunc, boot_map); \ ELF_DYNAMIC_DO_RELA ((map), edr_lazy, skip_ifunc, boot_map); \ + ELF_DYNAMIC_DO_RELR ((map)); \ } while (0) #else /* NESTING */ # if ! ELF_MACHINE_NO_REL diff --git a/elf/elf.h b/elf/elf.h index 954f3266f7..9635285d9a 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -444,8 +444,9 @@ typedef struct #define SHT_FINI_ARRAY 15 /* Array of destructors */ #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_SYMTAB_SHNDX 18 /* Extended section indices */ +#define SHT_RELR 19 /* RELR relative relocations */ +#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. */ @@ -663,6 +664,11 @@ typedef struct Elf64_Sxword r_addend; /* Addend */ } Elf64_Rela; +/* RELR relocation table entry */ + +typedef Elf32_Word Elf32_Relr; +typedef Elf64_Xword Elf64_Relr; + /* How to extract and insert information held in the r_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) @@ -861,7 +867,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 /* Address of SYMTAB_SHNDX section */ +#define DT_RELRSZ 35 /* Total size of RELR relative relocations */ +#define DT_RELR 36 /* Address of RELR relative relocations */ +#define DT_RELRENT 37 /* Size of one RELR relative relocaction */ +#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 */ diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index f9c5b84d6a..631f794765 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -110,6 +110,7 @@ elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp) # if ! ELF_MACHINE_NO_REL ADJUST_DYN_INFO (DT_REL); # endif + ADJUST_DYN_INFO (DT_RELR); ADJUST_DYN_INFO (DT_JMPREL); ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM)); ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM @@ -137,6 +138,8 @@ 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 (info[DT_RELR] != NULL) + assert (info[DT_RELRENT]->d_un.d_val == sizeof (ElfW(Relr))); #ifdef RTLD_BOOTSTRAP /* Only the bind now flags are allowed. */ assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL