From: xur@google.com
To: Josh Poimboeuf <jpoimboe@kernel.org>,
Peter Zijlstra <peterz@infradead.org>, Rong Xu <xur@google.com>
Cc: Han Shen <shenhan@google.com>,
Sriraman Tallam <tmsriram@google.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] objtool: fix up st_info in COMDAT group section
Date: Fri, 25 Apr 2025 13:05:41 -0700 [thread overview]
Message-ID: <20250425200541.113015-1-xur@google.com> (raw)
From: Rong Xu <xur@google.com>
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@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 727a3a4fd9d77..8dffe68d705c6 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -572,6 +572,30 @@ static int read_symbols(struct elf *elf)
return -1;
}
+/*
+ * @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.
*/
@@ -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;
}
--
2.49.0.850.g28803427d3-goog
next reply other threads:[~2025-04-25 20:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-25 20:05 xur [this message]
2025-04-30 12:29 ` [tip: objtool/core] objtool: Fix " tip-bot2 for Rong Xu
2025-05-07 23:22 ` Josh Poimboeuf
2025-05-08 0:11 ` [PATCH] objtool: Speed up SHT_GROUP reindexing Josh Poimboeuf
2025-05-08 0:11 ` Josh Poimboeuf
2025-05-08 15:27 ` Peter Zijlstra
2025-05-09 2:40 ` Rong Xu
2025-05-09 0:45 ` [tip: objtool/core] objtool: Fix up st_info in COMDAT group section Rong Xu
2025-05-09 3:22 ` 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=20250425200541.113015-1-xur@google.com \
--to=xur@google.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=shenhan@google.com \
--cc=tmsriram@google.com \
/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®