[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174601619410.22196.10353886760773998736.tip-bot2@tip-bot2>
Date: Wed, 30 Apr 2025 12:29:54 -0000
From: "tip-bot2 for Rong Xu" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Rong Xu <xur@...gle.com>, "Peter Zijlstra (Intel)" <peterz@...radead.org>,
x86@...nel.org, linux-kernel@...r.kernel.org
Subject: [tip: objtool/core] objtool: Fix up st_info in COMDAT group section
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: 2cb291596e2c1837238bc322ae3545dacb99d584
Gitweb: https://git.kernel.org/tip/2cb291596e2c1837238bc322ae3545dacb99d584
Author: Rong Xu <xur@...gle.com>
AuthorDate: Fri, 25 Apr 2025 13:05:41 -07:00
Committer: Peter Zijlstra <peterz@...radead.org>
CommitterDate: Wed, 30 Apr 2025 13:58:34 +02:00
objtool: Fix up st_info in COMDAT group section
When __elf_create_symbol creates a local symbol, it relocates the first
global symbol upwards to make space. Subsequently, elf_update_symbol()
is called to refresh the symbol table section. However, this isn't
sufficient, as other sections might have the reference to the old
symbol index, for instance, the sh_info field of an SHT_GROUP section.
This patch updates the `sh_info` field when necessary. This field
serves as the key for the COMDAT group. An incorrect key would prevent
the linker's from deduplicating COMDAT symbols, leading to duplicate
definitions in the final link.
Signed-off-by: Rong Xu <xur@...gle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Link: https://lkml.kernel.org/r/20250425200541.113015-1-xur@google.com
---
tools/objtool/elf.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 727a3a4..8dffe68 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -573,6 +573,30 @@ err:
}
/*
+ * @sym's idx has changed. Update the sh_info in group sections.
+ */
+static void elf_update_group_sh_info(struct elf *elf, Elf32_Word symtab_idx,
+ Elf32_Word new_idx, Elf32_Word old_idx)
+{
+ struct section *sec;
+
+ list_for_each_entry(sec, &elf->sections, list) {
+ if (sec->sh.sh_type != SHT_GROUP)
+ continue;
+ if (sec->sh.sh_link == symtab_idx &&
+ sec->sh.sh_info == old_idx) {
+ sec->sh.sh_info = new_idx;
+ mark_sec_changed(elf, sec, true);
+ /*
+ * Each ELF group should have a unique symbol key.
+ * Return early on match.
+ */
+ return;
+ }
+ }
+}
+
+/*
* @sym's idx has changed. Update the relocs which reference it.
*/
static int elf_update_sym_relocs(struct elf *elf, struct symbol *sym)
@@ -745,7 +769,7 @@ __elf_create_symbol(struct elf *elf, struct symbol *sym)
/*
* Move the first global symbol, as per sh_info, into a new, higher
- * symbol index. This fees up a spot for a new local symbol.
+ * symbol index. This frees up a spot for a new local symbol.
*/
first_non_local = symtab->sh.sh_info;
old = find_symbol_by_index(elf, first_non_local);
@@ -763,6 +787,7 @@ __elf_create_symbol(struct elf *elf, struct symbol *sym)
if (elf_update_sym_relocs(elf, old))
return NULL;
+ elf_update_group_sh_info(elf, symtab->idx, new_idx, first_non_local);
new_idx = first_non_local;
}
Powered by blists - more mailing lists