aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/objtool/include
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@kernel.org>2023-05-30 10:20:56 -0700
committerJosh Poimboeuf <jpoimboe@kernel.org>2023-06-07 10:03:15 -0700
commit53257a977a69b5eabbaafb64dcd767d2a4fef2b3 (patch)
tree330e0fa0f2417613b8199d23c5853dbd53654864 /tools/objtool/include
parentobjtool: Improve reloc naming (diff)
downloadwireguard-linux-53257a977a69b5eabbaafb64dcd767d2a4fef2b3.tar.xz
wireguard-linux-53257a977a69b5eabbaafb64dcd767d2a4fef2b3.zip
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.h13
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) \