From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org, jpoimboe@redhat.com, jgross@suse.com, mbenes@suse.com
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org
Subject: [PATCH v2 09/14] objtool: Extract elf_strtab_concat()
Date: Thu, 18 Mar 2021 18:11:12 +0100 [thread overview]
Message-ID: <20210318171919.948282703@infradead.org> (raw)
In-Reply-To: 20210318171103.577093939@infradead.org
Create a common helper to append strings to a strtab.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
tools/objtool/elf.c | 73 +++++++++++++++++++++++++++++-----------------------
1 file changed, 42 insertions(+), 31 deletions(-)
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -676,13 +676,51 @@ struct elf *elf_open_read(const char *na
return NULL;
}
+static int elf_strtab_concat(struct elf *elf, char *name, const char *strtab_name)
+{
+ struct section *strtab = NULL;
+ Elf_Data *data;
+ Elf_Scn *s;
+ int len;
+
+ if (strtab_name)
+ strtab = find_section_by_name(elf, strtab_name);
+ if (!strtab)
+ strtab = find_section_by_name(elf, ".strtab");
+ if (!strtab) {
+ WARN("can't find %s or .strtab section", strtab_name);
+ return -1;
+ }
+
+ s = elf_getscn(elf->elf, strtab->idx);
+ if (!s) {
+ WARN_ELF("elf_getscn");
+ return -1;
+ }
+
+ data = elf_newdata(s);
+ if (!data) {
+ WARN_ELF("elf_newdata");
+ return -1;
+ }
+
+ data->d_buf = name;
+ data->d_size = strlen(name) + 1;;
+ data->d_align = 1;
+
+ len = strtab->len;
+ strtab->len += data->d_size;
+ strtab->changed = true;
+
+ return len;
+}
+
struct section *elf_create_section(struct elf *elf, const char *name,
unsigned int sh_flags, size_t entsize, int nr)
{
- struct section *sec, *shstrtab;
+ struct section *sec;
size_t size = entsize * nr;
Elf_Scn *s;
- Elf_Data *data;
sec = malloc(sizeof(*sec));
if (!sec) {
@@ -739,36 +777,9 @@ struct section *elf_create_section(struc
sec->sh.sh_addralign = 1;
sec->sh.sh_flags = SHF_ALLOC | sh_flags;
-
- /* Add section name to .shstrtab (or .strtab for Clang) */
- shstrtab = find_section_by_name(elf, ".shstrtab");
- if (!shstrtab)
- shstrtab = find_section_by_name(elf, ".strtab");
- if (!shstrtab) {
- WARN("can't find .shstrtab or .strtab section");
- return NULL;
- }
-
- s = elf_getscn(elf->elf, shstrtab->idx);
- if (!s) {
- WARN_ELF("elf_getscn");
+ sec->sh.sh_name = elf_strtab_concat(elf, sec->name, ".shstrtab");
+ if (sec->sh.sh_name == -1)
return NULL;
- }
-
- data = elf_newdata(s);
- if (!data) {
- WARN_ELF("elf_newdata");
- return NULL;
- }
-
- data->d_buf = sec->name;
- data->d_size = strlen(name) + 1;
- data->d_align = 1;
-
- sec->sh.sh_name = shstrtab->len;
-
- shstrtab->len += strlen(name) + 1;
- shstrtab->changed = true;
list_add_tail(&sec->list, &elf->sections);
elf_hash_add(elf->section_hash, &sec->hash, sec->idx);
next prev parent reply other threads:[~2021-03-18 17:25 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-18 17:11 [PATCH v2 00/14] x86,objtool: Optimize !RETPOLINE Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 01/14] x86: Add insn_decode_kernel() Peter Zijlstra
2021-03-19 10:40 ` Borislav Petkov
2021-03-18 17:11 ` [PATCH v2 02/14] x86/alternatives: Optimize optimize_nops() Peter Zijlstra
2021-03-21 12:06 ` Borislav Petkov
2021-03-22 8:17 ` Peter Zijlstra
2021-03-22 11:07 ` Borislav Petkov
2021-03-18 17:11 ` [PATCH v2 03/14] x86/retpoline: Simplify retpolines Peter Zijlstra
2021-03-19 17:18 ` David Laight
2021-03-22 9:32 ` Peter Zijlstra
2021-03-22 15:41 ` David Laight
2021-03-18 17:11 ` [PATCH v2 04/14] objtool: Correctly handle retpoline thunk calls Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 05/14] objtool: Per arch retpoline naming Peter Zijlstra
2021-03-19 2:38 ` Josh Poimboeuf
2021-03-19 9:07 ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 06/14] objtool: Fix static_call list generation Peter Zijlstra
2021-03-22 12:44 ` Miroslav Benes
2021-03-18 17:11 ` [PATCH v2 07/14] objtool: Rework rebuild_reloc logic Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 08/14] objtool: Add elf_create_reloc() helper Peter Zijlstra
2021-03-19 1:42 ` Josh Poimboeuf
2021-03-19 9:47 ` Peter Zijlstra
2021-03-19 15:12 ` Josh Poimboeuf
2021-03-19 15:24 ` Peter Zijlstra
2021-03-19 15:37 ` Josh Poimboeuf
2021-03-18 17:11 ` Peter Zijlstra [this message]
2021-03-19 2:10 ` [PATCH v2 09/14] objtool: Extract elf_strtab_concat() Josh Poimboeuf
2021-03-19 9:52 ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 10/14] objtool: Extract elf_symbol_add() Peter Zijlstra
2021-03-19 2:14 ` Josh Poimboeuf
2021-03-19 9:54 ` Peter Zijlstra
2021-03-19 15:04 ` Josh Poimboeuf
2021-03-18 17:11 ` [PATCH v2 11/14] objtool: Add elf_create_undef_symbol() Peter Zijlstra
2021-03-19 2:29 ` Josh Poimboeuf
2021-03-19 7:56 ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 12/14] objtool: Allow archs to rewrite retpolines Peter Zijlstra
2021-03-19 2:54 ` Josh Poimboeuf
2021-03-19 11:21 ` Peter Zijlstra
2021-03-19 13:28 ` Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 13/14] objtool: Skip magical retpoline .altinstr_replacement Peter Zijlstra
2021-03-18 17:11 ` [PATCH v2 14/14] objtool,x86: Rewrite retpoline thunk calls Peter Zijlstra
2021-03-19 3:29 ` Josh Poimboeuf
2021-03-19 8:06 ` Peter Zijlstra
2021-03-19 15:30 ` Josh Poimboeuf
2021-03-19 15:56 ` Peter Zijlstra
2021-03-19 22:52 ` 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=20210318171919.948282703@infradead.org \
--to=peterz@infradead.org \
--cc=jgross@suse.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.com \
--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;
as well as URLs for NNTP newsgroup(s).