From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Miroslav Benes <mbenes@suse.cz>
Subject: [PATCH 15/22] objtool: Get rid of reloc->type
Date: Tue, 30 May 2023 10:21:07 -0700 [thread overview]
Message-ID: <d1c1f8da31e4f052a2478aea585fcf355cacc53a.1685464332.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1685464332.git.jpoimboe@kernel.org>
Get the type from the embedded GElf_Rel[a] struct.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/arch/x86/decode.c | 2 +-
tools/objtool/arch/x86/special.c | 4 ++--
tools/objtool/check.c | 11 ++++++-----
tools/objtool/elf.c | 6 ++----
tools/objtool/include/objtool/elf.h | 11 ++++++++++-
5 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index 9ef024fd648c..ffb12e83b238 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -84,7 +84,7 @@ bool arch_pc_relative_reloc(struct reloc *reloc)
* All relocation types where P (the address of the target)
* is included in the computation.
*/
- switch (reloc->type) {
+ switch (reloc_type(reloc)) {
case R_X86_64_PC8:
case R_X86_64_PC16:
case R_X86_64_PC32:
diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c
index 7c97b7391279..1a54a249cb50 100644
--- a/tools/objtool/arch/x86/special.c
+++ b/tools/objtool/arch/x86/special.c
@@ -108,7 +108,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
table_offset = text_reloc->addend;
table_sec = text_reloc->sym->sec;
- if (text_reloc->type == R_X86_64_PC32)
+ if (reloc_type(text_reloc) == R_X86_64_PC32)
table_offset += 4;
/*
@@ -138,7 +138,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
* indicates a rare GCC quirk/bug which can leave dead
* code behind.
*/
- if (text_reloc->type == R_X86_64_PC32)
+ if (reloc_type(text_reloc) == R_X86_64_PC32)
file->ignore_unreachables = true;
return rodata_reloc;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 440c326121d4..1d794d15bc53 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -957,7 +957,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
if (!reloc)
return -1;
- reloc->type = addr_size == 8 ? R_ABS64 : R_ABS32;
+ set_reloc_type(reloc, addr_size == 8 ? R_ABS64 : R_ABS32);
idx++;
}
@@ -1353,7 +1353,7 @@ static void annotate_call_site(struct objtool_file *file,
*/
if (opts.hack_noinstr && insn->sec->noinstr && sym->profiling_func) {
if (reloc) {
- reloc->type = R_NONE;
+ set_reloc_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
@@ -1382,7 +1382,7 @@ static void annotate_call_site(struct objtool_file *file,
WARN_INSN(insn, "tail call to __fentry__ !?!?");
if (opts.mnop) {
if (reloc) {
- reloc->type = R_NONE;
+ set_reloc_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
@@ -1864,7 +1864,7 @@ static int handle_jump_alt(struct objtool_file *file,
struct reloc *reloc = insn_reloc(file, orig_insn);
if (reloc) {
- reloc->type = R_NONE;
+ set_reloc_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
elf_write_insn(file->elf, orig_insn->sec,
@@ -4268,7 +4268,8 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn
continue;
off = reloc->sym->offset;
- if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)
+ if (reloc_type(reloc) == R_X86_64_PC32 ||
+ reloc_type(reloc) == R_X86_64_PLT32)
off += arch_dest_reloc_offset(reloc->addend);
else
off += reloc->addend;
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 2b45460225d1..be9d24dcdf56 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -541,6 +541,7 @@ static int elf_update_sym_relocs(struct elf *elf, struct symbol *sym)
struct reloc *reloc;
list_for_each_entry(reloc, &sym->reloc_list, sym_reloc_entry) {
+ reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc_type(reloc));
if (elf_write_reloc(elf, reloc))
return -1;
}
@@ -831,11 +832,11 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec,
}
reloc->sec = rsec;
- reloc->type = type;
reloc->sym = sym;
reloc->addend = addend;
reloc->rel.r_offset = offset;
+ reloc->rel.r_info = GELF_R_INFO(sym->idx, type);
if (elf_write_reloc(elf, reloc))
return NULL;
@@ -910,7 +911,6 @@ static int read_reloc(struct section *rsec, int i, struct reloc *reloc)
return -1;
}
- reloc->type = GELF_R_TYPE(reloc->rel.r_info);
reloc->addend = rela ? reloc->rela.r_addend : 0;
return 0;
@@ -1231,8 +1231,6 @@ int elf_write_reloc(struct elf *elf, struct reloc *reloc)
struct section *rsec = reloc->sec;
int ret;
- reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type);
-
if (rsec->sh.sh_type == SHT_RELA) {
reloc->rela.r_addend = reloc->addend;
ret = gelf_update_rela(rsec->data, reloc_idx(reloc), &reloc->rela);
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index 2070860a099e..41d2149f8bb8 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -76,7 +76,6 @@ struct reloc {
struct symbol *sym;
struct list_head sym_reloc_entry;
s64 addend;
- unsigned int type;
bool jump_table_start;
};
@@ -208,6 +207,16 @@ static inline unsigned long reloc_offset(struct reloc *reloc)
return reloc->rel.r_offset;
}
+static inline unsigned int reloc_type(struct reloc *reloc)
+{
+ return GELF_R_TYPE(reloc->rel.r_info);
+}
+
+static inline void set_reloc_type(struct reloc *reloc, int type)
+{
+ reloc->rel.r_info = GELF_R_INFO(GELF_R_SYM(reloc->rel.r_info), type);
+}
+
#define for_each_sec(file, sec) \
list_for_each_entry(sec, &file->elf->sections, list)
--
2.40.1
next prev parent reply other threads:[~2023-05-30 17:22 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 17:20 [PATCH 00/22] objtool: Reduce memory usage with CONFIG_DEBUG_INFO Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 01/22] objtool: Tidy elf.h Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 02/22] objtool: Remove flags argument from elf_create_section() Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 03/22] objtool: Improve reloc naming Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 04/22] objtool: Consolidate rel/rela handling Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 05/22] objtool: Fix reloc_hash size Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 06/22] objtool: Add mark_sec_changed() Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:20 ` [PATCH 07/22] objtool: Add elf_create_section_pair() Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 08/22] objtool: Keep GElf_Rel[a] structs synced Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 09/22] objtool: Don't free memory in elf_close() Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 10/22] objtool: Add for_each_reloc() Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 11/22] objtool: Allocate relocs in advance for new rela sections Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 12/22] objtool: Get rid of reloc->list Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 13/22] objtool: Get rid of reloc->idx Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 14/22] objtool: Get rid of reloc->offset Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` Josh Poimboeuf [this message]
2023-06-09 7:47 ` [tip: objtool/core] objtool: Get rid of reloc->type tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 16/22] objtool: Get rid of reloc->addend Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 17/22] objtool: Get rid of reloc->jump_table_start Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 18/22] objtool: Shrink reloc->sym_reloc_entry Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 19/22] objtool: Shrink elf hash nodes Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 20/22] objtool: Get rid of reloc->rel[a] Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 21/22] objtool: Free insns when done Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
2023-05-30 17:21 ` [PATCH 22/22] objtool: Skip reading DWARF section data Josh Poimboeuf
2023-06-09 7:47 ` [tip: objtool/core] " tip-bot2 for Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d1c1f8da31e4f052a2478aea585fcf355cacc53a.1685464332.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®