From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, "Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v2 4/8] objtool: introduce function elf_reloc_set_type
Date: Tue, 27 Dec 2022 16:01:00 +0000 [thread overview]
Message-ID: <20221216-objtool-memory-v2-4-17968f85a464@weissschuh.net> (raw)
In-Reply-To: <20221216-objtool-memory-v2-0-17968f85a464@weissschuh.net>
An upcoming patch needs to perform validation when setting reloc->type
so introduce a helper to contain this validation.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/objtool/check.c | 6 +++---
tools/objtool/elf.c | 11 ++++++++---
tools/objtool/include/objtool/elf.h | 2 ++
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 4350be739f4f..971ee6826de7 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -1355,7 +1355,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;
+ elf_reloc_set_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
@@ -1384,7 +1384,7 @@ static void annotate_call_site(struct objtool_file *file,
WARN_FUNC("Tail call to __fentry__ !?!?", insn->sec, insn->offset);
if (opts.mnop) {
if (reloc) {
- reloc->type = R_NONE;
+ elf_reloc_set_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
@@ -1863,7 +1863,7 @@ static int handle_jump_alt(struct objtool_file *file,
struct reloc *reloc = insn_reloc(file, orig_insn);
if (reloc) {
- reloc->type = R_NONE;
+ elf_reloc_set_type(reloc, R_NONE);
elf_write_reloc(file->elf, reloc);
}
elf_write_insn(file->elf, orig_insn->sec,
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 9c326efb8cd9..ee355beb0d82 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -555,7 +555,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offset,
reloc->sec = sec->reloc;
reloc->offset = offset;
- reloc->type = type;
+ elf_reloc_set_type(reloc, type);
reloc->sym = sym;
reloc->addend = addend;
@@ -872,7 +872,7 @@ static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc, unsig
WARN_ELF("gelf_getrel");
return -1;
}
- reloc->type = GELF_R_TYPE(reloc->rel.r_info);
+ elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rel.r_info));
reloc->addend = 0;
reloc->offset = reloc->rel.r_offset;
*symndx = GELF_R_SYM(reloc->rel.r_info);
@@ -885,7 +885,7 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi
WARN_ELF("gelf_getrela");
return -1;
}
- reloc->type = GELF_R_TYPE(reloc->rela.r_info);
+ elf_reloc_set_type(reloc, GELF_R_TYPE(reloc->rela.r_info));
reloc->addend = reloc->rela.r_addend;
reloc->offset = reloc->rela.r_offset;
*symndx = GELF_R_SYM(reloc->rela.r_info);
@@ -1471,3 +1471,8 @@ void elf_close(struct elf *elf)
free(elf->section_data);
free(elf);
}
+
+void elf_reloc_set_type(struct reloc *reloc, int type)
+{
+ reloc->type = type;
+}
diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
index 1c90f0ac0d53..33ec6cf72325 100644
--- a/tools/objtool/include/objtool/elf.h
+++ b/tools/objtool/include/objtool/elf.h
@@ -83,6 +83,8 @@ struct reloc {
bool jump_table_start;
};
+void elf_reloc_set_type(struct reloc *reloc, int type);
+
#define ELF_HASH_BITS 20
struct elf {
--
2.39.0
next prev parent reply other threads:[~2022-12-27 16:03 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-27 16:00 [PATCH v2 0/8] reduce maximum memory usage Thomas Weißschuh
2022-12-27 16:00 ` [PATCH v2 1/8] objtool: make struct entries[] static and const Thomas Weißschuh
2023-02-01 16:26 ` [tip: objtool/core] objtool: Make " tip-bot2 for Thomas Weißschuh
2023-02-04 10:17 ` tip-bot2 for Thomas Weißschuh
2022-12-27 16:00 ` [PATCH v2 2/8] objtool: make struct check_options static Thomas Weißschuh
2023-02-01 16:26 ` [tip: objtool/core] objtool: Make " tip-bot2 for Thomas Weißschuh
2023-02-04 10:17 ` tip-bot2 for Thomas Weißschuh
2022-12-27 16:00 ` [PATCH v2 3/8] objtool: allocate multiple structures with calloc() Thomas Weißschuh
2023-01-30 23:53 ` Josh Poimboeuf
2023-02-01 16:26 ` [tip: objtool/core] objtool: Allocate " tip-bot2 for Thomas Weißschuh
2023-02-04 10:17 ` tip-bot2 for Thomas Weißschuh
2022-12-27 16:01 ` Thomas Weißschuh [this message]
2022-12-27 16:01 ` [PATCH v2 5/8] objtool: reduce memory usage of struct reloc Thomas Weißschuh
2022-12-29 1:33 ` Rong Tao
2022-12-29 2:26 ` Thomas Weißschuh
2022-12-29 3:29 ` Rong Tao
2022-12-29 5:57 ` Thomas Weißschuh
2023-01-30 23:59 ` Josh Poimboeuf
2022-12-27 16:01 ` [PATCH v2 6/8] objtool: optimize layout of struct symbol Thomas Weißschuh
2023-02-01 16:26 ` [tip: objtool/core] objtool: Optimize " tip-bot2 for Thomas Weißschuh
2023-02-04 10:17 ` tip-bot2 for Thomas Weißschuh
2022-12-27 16:01 ` [PATCH v2 7/8] objtool: optimize layout of struct special_alt Thomas Weißschuh
2023-02-01 16:26 ` [tip: objtool/core] objtool: Optimize " tip-bot2 for Thomas Weißschuh
2023-02-04 10:17 ` tip-bot2 for Thomas Weißschuh
2022-12-27 16:01 ` [PATCH v2 8/8] objtool: explicitly cleanup resources on success Thomas Weißschuh
2023-01-31 0:02 ` Josh Poimboeuf
2023-01-29 21:43 ` [PATCH v2 0/8] objtool: reduce maximum memory usage Thomas Weißschuh
2023-01-31 0:03 ` Josh Poimboeuf
2023-01-31 3:54 ` Thomas Weißschuh
2023-01-31 17:27 ` Josh Poimboeuf
2023-02-07 17:30 ` Josh Poimboeuf
2023-02-01 12:51 ` David Laight
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=20221216-objtool-memory-v2-4-17968f85a464@weissschuh.net \
--to=linux@weissschuh.net \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.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®