diff options
author | Josh Poimboeuf <jpoimboe@kernel.org> | 2023-05-30 20:20:56 +0300 |
---|---|---|
committer | Josh Poimboeuf <jpoimboe@kernel.org> | 2023-06-07 20:03:15 +0300 |
commit | 53257a977a69b5eabbaafb64dcd767d2a4fef2b3 (patch) | |
tree | 330e0fa0f2417613b8199d23c5853dbd53654864 /tools/objtool/include | |
parent | a5bd623653231bce8657978e9d2c2ebfaf19e297 (diff) | |
download | linux-53257a977a69b5eabbaafb64dcd767d2a4fef2b3.tar.xz |
objtool: Consolidate rel/rela handling
The GElf_Rel[a] structs have more similarities than differences. It's
safe to hard-code the assumptions about their shared fields as they will
never change. Consolidate their handling where possible, getting rid of
duplicated code.
Also, at least for now we only ever create rela sections, so simplify
the relocation creation code to be rela-only.
Link: https://lore.kernel.org/r/dcabf6df400ca500ea929f1e4284f5e5ec0b27c8.1685464332.git.jpoimboe@kernel.org
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Diffstat (limited to 'tools/objtool/include')
-rw-r--r-- | tools/objtool/include/objtool/elf.h | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index a4e43a69f922..6f82f2515d6b 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -12,6 +12,7 @@ #include <linux/hashtable.h> #include <linux/rbtree.h> #include <linux/jhash.h> +#include <arch/elf.h> #ifdef LIBELF_USE_DEPRECATED # define elf_getshdrnum elf_getshnum @@ -147,12 +148,14 @@ static inline bool has_multiple_files(struct elf *elf) return elf->num_files > 1; } -static inline int elf_class_addrsize(struct elf *elf) +static inline size_t elf_addr_size(struct elf *elf) { - if (elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32) - return sizeof(u32); - else - return sizeof(u64); + return elf->ehdr.e_ident[EI_CLASS] == ELFCLASS32 ? 4 : 8; +} + +static inline size_t elf_rela_size(struct elf *elf) +{ + return elf_addr_size(elf) == 4 ? sizeof(Elf32_Rela) : sizeof(Elf64_Rela); } #define for_each_sec(file, sec) \ |