From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Joe Lawrence <joe.lawrence@redhat.com>,
Song Liu <song@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel@lists.infradead.org,
Mark Rutland <mark.rutland@arm.com>,
Nathan Chancellor <nathan@kernel.org>,
Nicolas Schier <nsc@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH v2 10/12] objtool: Reuse consecutive string references
Date: Tue, 17 Mar 2026 15:51:10 -0700 [thread overview]
Message-ID: <4d211040356fe169b4236b3deea1cdff80e9babc.1773787568.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1773787568.git.jpoimboe@kernel.org>
For duplicate strings, elf_add_string() just blindly adds duplicates.
That can be a problem for arm64 which often uses two consecutive
instructions (and corresponding relocations) to put an address into a
register, like:
d8: 90000001 adrp x1, 0 <meminfo_proc_show> d8: R_AARCH64_ADR_PREL_PG_HI21 .rodata.meminfo_proc_show.str1.8
dc: 91000021 add x1, x1, #0x0 dc: R_AARCH64_ADD_ABS_LO12_NC .rodata.meminfo_proc_show.str1.8
Referencing two different string addresses in the adrp+add pair can
result in a corrupt string addresses. Detect such consecutive reuses
and force them to use the same string.
Acked-by: Song Liu <song@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/elf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index b911abe3a15e..5ccae2c937dc 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1374,6 +1374,8 @@ struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name)
unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char *str)
{
+ static unsigned int last_off;
+ static const char *last_str;
unsigned int offset;
if (!strtab)
@@ -1382,17 +1384,22 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char
ERROR("can't find .strtab section");
return -1;
}
-
if (!strtab->sh.sh_addralign) {
ERROR("'%s': invalid sh_addralign", strtab->name);
return -1;
}
+ if (last_str && !strcmp(last_str, str))
+ return last_off;
+
offset = ALIGN(sec_size(strtab), strtab->sh.sh_addralign);
if (!elf_add_data(elf, strtab, str, strlen(str) + 1))
return -1;
+ last_str = str;
+ last_off = offset;
+
return offset;
}
--
2.53.0
next prev parent reply other threads:[~2026-03-17 22:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 22:51 [PATCH v2 00/12] objtool/arm64: Port klp-build to arm64 Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 01/12] arm64: Annotate intra-function calls Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 02/12] arm64: head: Move boot header to .head.data Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 03/12] arm64: Fix EFI linking with -fdata-sections Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 04/12] crypto: arm64: Move data to .rodata Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 05/12] objtool: Extricate checksum calculation from validate_branch() Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 06/12] objtool: Allow setting --mnop without --mcount Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 07/12] kbuild: Only run objtool if there is at least one command Josh Poimboeuf
2026-03-18 19:54 ` Nicolas Schier
2026-03-19 0:49 ` Josh Poimboeuf
2026-03-30 18:49 ` Nicolas Schier
2026-03-17 22:51 ` [PATCH v2 08/12] objtool: Ignore jumps to the end of the function for non-CFG arches Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 09/12] objtool: Allow empty alternatives Josh Poimboeuf
2026-03-17 22:51 ` Josh Poimboeuf [this message]
2026-03-17 22:51 ` [PATCH v2 11/12] objtool: Introduce objtool for arm64 Josh Poimboeuf
2026-03-17 22:51 ` [PATCH v2 12/12] klp-build: Support cross-compilation Josh Poimboeuf
2026-03-19 4:13 ` [PATCH v2 00/12] objtool/arm64: Port klp-build to arm64 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=4d211040356fe169b4236b3deea1cdff80e9babc.1773787568.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=herbert@gondor.apana.org.au \
--cc=joe.lawrence@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=nathan@kernel.org \
--cc=nsc@kernel.org \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=will@kernel.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®