Re: [PATCH v4 14/22] objtool: Reuse string references
Song Liu <[email protected]>
| Newsgroups | org.kernel.vger.live-patching,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <CAPhsuW6JgV1a7jMxQ0bknOpQ7WQNSqYbAHWss18GCrzGZ79OcQ@mail.gmail.com> |
On Sat, Aug 8, 2026 at 4:18 PM Josh Poimboeuf <[email protected]> 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 <[email protected]> Acked-by: Song Liu <[email protected]> With one nitpick below: > --- > 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 [...]