From nobody Tue Dec 2 02:19:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E1B43242A4 for ; Thu, 20 Nov 2025 20:52:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763671952; cv=none; b=FVbMz6dp3NYGkc70E2iXY30UV6+llXrk1aXBGzBN/+bvAFkKGVf8F5a1gvKwGOOJ4ERsM1jnAuy58k+jFuj14VF1qjwofOuuP3rVHcxSK2b6Va2f/t/o3/h8rJh0vzoutanLh9Jxm3ATrkWEeB6nuu4Iu2xgeRXRw0JrfQe8Xk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763671952; c=relaxed/simple; bh=8GNjVMtK9NJAT4U3TdvqgZ/kDsLlD1r/0G46aAc1HSM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n9kErX+7iaCaUo49fkjU4k9BIxK4n8rYb2Gu2XvNF3vwaAe+BsBPzgBebpggppGuiJTgxFaH4hSLAt6CFiAKokxkKx4PSxJ+bNCa9Dm40KGYv1rFwF1sRS0tpmOynHvW+dpZhi8MplJ88jlBzTafeS9FaI6O0O2eWIymeR9k8/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=izqgExvl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="izqgExvl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 795F5C116C6; Thu, 20 Nov 2025 20:52:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763671951; bh=8GNjVMtK9NJAT4U3TdvqgZ/kDsLlD1r/0G46aAc1HSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=izqgExvlZDC9mfDtrdEijEa++D1WcG3lCJglmw+s6JMecMNY8nzmg5zqutk/JpgnN d4iuXCfJZA030mU8GRoe6D02npKZaYhYg8rhTvFBbDqISpuUvjha01u9eRhc2BfE4K Ei4P2hNnQhUKfQWCiEIaCYYvaqQQXziu1JcL4ejWrSMzt7msuSNj8jkcIWHGq6kX3m R/MSRMUm+oqrTXQ355ZBvar3F5PRkrlorXr3Ny9aXrqN9bMcWONNwo7aS4qVwuIBH2 SqEQqM26Wrz9TsDlW+wVZ4QgQTzCKhwSf0mXxqRLBYTmGVSBEYYY88MbmC2F5fRG7u MAsgQxS60XJ3A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Rong Xu , Han Shen , Sriraman Tallam , Krzysztof Pszeniczny Subject: [PATCH 2/6] objtool: Fix .cold function detection for duplicate symbols Date: Thu, 20 Nov 2025 12:52:16 -0800 Message-ID: <82c7b52e40efa75dd10e1c550cc75c1ce10ac2c9.1763671318.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The objtool .cold child/parent correlation is done in two phases: first in elf_add_symbol() and later in add_jump_destinations(). The first phase is rather crude and can pick the wrong parent if there are duplicates with the same name. The second phase usually fixes that, but only if the parent has a direct jump to the child. It does *not* work if the only branch from the parent to the child is an alternative or jump table entry. Make the first phase more robust by looking for the parent in the same STT_FILE as the child. Fixes the following objtool warnings in an AutoFDO build with a large CLANG_AUTOFDO_PROFILE profile: vmlinux.o: warning: objtool: rdev_add_key() falls through to next functio= n rdev_add_key.cold() vmlinux.o: warning: objtool: rdev_set_default_key() falls through to next= function rdev_set_default_key.cold() Fixes: 13810435b9a7 ("objtool: Support GCC 8's cold subfunctions") Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 28 ++++++++++++++++++++++++++-- tools/objtool/include/objtool/elf.h | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 7895f65aca2a..fffca31d47ed 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -288,6 +288,23 @@ struct symbol *find_symbol_by_name(const struct elf *e= lf, const char *name) return NULL; } =20 +/* Find local symbol with matching STT_FILE */ +static struct symbol *find_local_symbol_by_file_and_name(const struct elf = *elf, + struct symbol *file, + const char *name) +{ + struct symbol *sym; + + elf_hash_for_each_possible(symbol_name, sym, name_hash, str_hash(name)) { + if (sym->bind =3D=3D STB_LOCAL && sym->file =3D=3D file && + !strcmp(sym->name, name)) { + return sym; + } + } + + return NULL; +} + struct symbol *find_global_symbol_by_name(const struct elf *elf, const cha= r *name) { struct symbol *sym; @@ -524,7 +541,7 @@ static int elf_add_symbol(struct elf *elf, struct symbo= l *sym) static int read_symbols(struct elf *elf) { struct section *symtab, *symtab_shndx, *sec; - struct symbol *sym, *pfunc; + struct symbol *sym, *pfunc, *file =3D NULL; int symbols_nr, i; char *coldstr; Elf_Data *shndx_data =3D NULL; @@ -597,6 +614,11 @@ static int read_symbols(struct elf *elf) =20 if (elf_add_symbol(elf, sym)) return -1; + + if (sym->type =3D=3D STT_FILE) + file =3D sym; + else if (sym->bind =3D=3D STB_LOCAL) + sym->file =3D file; } =20 if (opts.stats) { @@ -626,7 +648,9 @@ static int read_symbols(struct elf *elf) return -1; } =20 - pfunc =3D find_symbol_by_name(elf, pname); + pfunc =3D find_local_symbol_by_file_and_name(elf, sym->file, pname); + if (!pfunc) + pfunc =3D find_global_symbol_by_name(elf, pname); free(pname); =20 if (!pfunc) { diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 21d8b825fd8f..e12c516bd320 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -69,7 +69,7 @@ struct symbol { unsigned int idx, len; unsigned long offset; unsigned long __subtree_last; - struct symbol *pfunc, *cfunc, *alias; + struct symbol *pfunc, *cfunc, *alias, *file; unsigned char bind, type; u8 uaccess_safe : 1; u8 static_call_tramp : 1; --=20 2.51.1