Thread (37 messages) flat view 37 messages, 2 authors, 27d ago

Re: [PATCH v4 14/22] objtool: Reuse string references

From: Song Liu <song@kernel.org>
Date: 2026-08-11 23:53:13
Also in: live-patching, lkml

On Sat, Aug 8, 2026 at 4:18 PM Josh Poimboeuf [off-list ref] wrote:
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 addresses in the ADRP+ADD pair would corrupt
the memory access.  Avoid that by detecting and reusing duplicates when
cloning string relocs.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Acked-by: Song Liu <song@kernel.org>

With one nitpick below:
quoted hunk ↗ jump to hunk
---
 tools/objtool/elf.c                 | 29 +++++++++++++++++++++++------
 tools/objtool/include/objtool/elf.h |  3 ++-
 tools/objtool/klp-diff.c            |  4 +++-
 3 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 8bf225d70d918..3bb04d6155a8b 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1379,9 +1379,27 @@ struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name)
        return elf;
 }

-unsigned int elf_add_string(struct elf *elf, struct section *strtab, const char *str)
+int elf_find_string(struct elf *elf, struct section *strtab, const char *str)
 {
elf_find_string() returns -1 for error and positive number for addend.
It is a good idea to add some comments for this behavior.

Thanks,
Song

[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help