]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Add annotype() helper
authorJosh Poimboeuf <jpoimboe@kernel.org>
Wed, 17 Sep 2025 16:03:52 +0000 (09:03 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 14 Oct 2025 21:46:49 +0000 (14:46 -0700)
... for reading annotation types.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
tools/objtool/arch/loongarch/orc.c
tools/objtool/arch/powerpc/decode.c
tools/objtool/arch/x86/decode.c
tools/objtool/arch/x86/orc.c
tools/objtool/check.c
tools/objtool/include/objtool/elf.h
tools/objtool/include/objtool/endianness.h
tools/objtool/orc_dump.c
tools/objtool/orc_gen.c
tools/objtool/special.c

index b58c5ff443c928b57974e790a29ca99400db03c2..ffd3a3c858ae7b9b11ae9904ee628f32ddba96c4 100644 (file)
@@ -5,7 +5,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
 {
index d4cb02120a6bd3cd56b9130f6e49196a5c8b72ab..3a9b748216edc9359d14c8da94ac0e5508681196 100644 (file)
@@ -7,7 +7,6 @@
 #include <objtool/arch.h>
 #include <objtool/warn.h>
 #include <objtool/builtin.h>
-#include <objtool/endianness.h>
 
 int arch_ftrace_match(const char *name)
 {
index 6bb46d9981533dad6ae17aa3143a70d4a4a5cf6b..b2c320f701f9492ef7f35b21089f278f7ab24dc4 100644 (file)
@@ -19,7 +19,6 @@
 #include <objtool/elf.h>
 #include <objtool/arch.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 #include <objtool/builtin.h>
 #include <arch/elf.h>
 
index 7176b9ec5b058728590f1ffec07fc55b90c989a1..735e150ca6b73da7292bcc7dfe28b0160cfe174d 100644 (file)
@@ -5,7 +5,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
 {
index 65a359cbf4ea8971583bde4d7f7f37adc6f00cc1..13ccfe0c7ebaf841038d5ca99cbadf4ebf74263c 100644 (file)
@@ -14,7 +14,6 @@
 #include <objtool/check.h>
 #include <objtool/special.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 #include <linux/objtool_types.h>
 #include <linux/hashtable.h>
@@ -2273,9 +2272,7 @@ static int read_annotate(struct objtool_file *file,
        }
 
        for_each_reloc(sec->rsec, reloc) {
-               type = *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * sec->sh.sh_entsize) + 4);
-               type = bswap_if_needed(file->elf, type);
-
+               type = annotype(file->elf, sec, reloc);
                offset = reloc->sym->offset + reloc_addend(reloc);
                insn = find_insn(file, reloc->sym->sec, offset);
 
index 9f135c262659e7ddb2179a140355d403caeb0ef3..814cfc0bbf16b0fcdec42b6a904c365d91239c31 100644 (file)
 #include <linux/hashtable.h>
 #include <linux/rbtree.h>
 #include <linux/jhash.h>
+
+#include <objtool/endianness.h>
 #include <arch/elf.h>
 
 #define SYM_NAME_LEN           512
 
+#define bswap_if_needed(elf, val) __bswap_if_needed(&elf->ehdr, val)
+
 #ifdef LIBELF_USE_DEPRECATED
 # define elf_getshdrnum    elf_getshnum
 # define elf_getshdrstrndx elf_getshstrndx
@@ -401,6 +405,15 @@ static inline void set_reloc_type(struct elf *elf, struct reloc *reloc, unsigned
        mark_sec_changed(elf, reloc->sec, true);
 }
 
+static inline unsigned int annotype(struct elf *elf, struct section *sec,
+                                   struct reloc *reloc)
+{
+       unsigned int type;
+
+       type = *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * 8) + 4);
+       return bswap_if_needed(elf, type);
+}
+
 #define RELOC_JUMP_TABLE_BIT 1UL
 
 /* Does reloc mark the beginning of a jump table? */
index 4d2aa9b0fe2fd5351691395d11b28270f7efc5df..aebcd2338668523f4f46019f9f331524cddd2345 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <linux/kernel.h>
 #include <endian.h>
-#include <objtool/elf.h>
 
 /*
  * Does a byte swap if target file endianness doesn't match the host, i.e. cross
  * To be used for multi-byte values conversion, which are read from / about
  * to be written to a target native endianness ELF file.
  */
-static inline bool need_bswap(struct elf *elf)
+static inline bool need_bswap(GElf_Ehdr *ehdr)
 {
        return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
-              (elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
+              (ehdr->e_ident[EI_DATA] == ELFDATA2LSB);
 }
 
-#define bswap_if_needed(elf, val)                                      \
+#define __bswap_if_needed(ehdr, val)                                   \
 ({                                                                     \
        __typeof__(val) __ret;                                          \
-       bool __need_bswap = need_bswap(elf);                            \
+       bool __need_bswap = need_bswap(ehdr);                           \
        switch (sizeof(val)) {                                          \
        case 8:                                                         \
                __ret = __need_bswap ? bswap_64(val) : (val); break;    \
index 1dd9fc18fe624200161b72aa8f3e8a3b01dfb4e3..5a979f52425ab032194c318ef13ea0e2f751daf3 100644 (file)
@@ -8,7 +8,6 @@
 #include <objtool/objtool.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int orc_dump(const char *filename)
 {
index 9d380abc2ed351209347c4b3684745bf0b6a8971..1045e1380ffde02dc4e3af0e3190ceeb2b9558b7 100644 (file)
@@ -12,7 +12,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 struct orc_list_entry {
        struct list_head list;
index fc2cf8dba1c03725e0575e70aa3d272ff6c3397f..e262af9171436a416e63cb972bd74d9fb23293b1 100644 (file)
@@ -15,7 +15,6 @@
 #include <objtool/builtin.h>
 #include <objtool/special.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 struct special_entry {
        const char *sec;