From nobody Sun Feb 8 09:32:14 2026 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 3F2231D6DD4; Tue, 3 Sep 2024 04:00:43 +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=1725336043; cv=none; b=fGN2/kUwTwugriaGHbZ1BjbmX40N52UoL0G05dGMGeU+H4CeTxZ4BO2GhyCcIloXmQoRQmO9ghwe81DsV02JgNTFL5zVKU9qcePyB/EfUfz+1Kl/hUZXlktDEefQxhFa8S8L+DFYCcb6yBKiNABqdLKx6qFXu3kew4DR9GCdBbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725336043; c=relaxed/simple; bh=MTklontumUzZpdX06cPRFX4LLGHwOyI3SJ4gnMlG+5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqwzY9xM7rafhHguzCaXBP4toq0YjqJaiP9uEZLx/o3peBda8mLwJQt8IOsbJO8F81+PANKNq2T7xDkStt8DonOwe1dkns65Hgie/R8TDUYEJiesyAFB0a76Y6dsb9kEZqdwFigcbVb4MsWY9BrJ3QLr108WENgbXRpvCUZ7HFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rAdGF1dJ; 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="rAdGF1dJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B95CAC4CED0; Tue, 3 Sep 2024 04:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725336043; bh=MTklontumUzZpdX06cPRFX4LLGHwOyI3SJ4gnMlG+5A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rAdGF1dJMDPP8zNlF+p8n1XV4xPxBRGG/Bv+Jb2iJvdB2xHaW56BCDxCYbIi7wPkB Zpdso/ZPTLOygEdTCJ0rYCQLE3bsbIj1G/V+e9CKbRgmH6OTf6gArRvo2pIKeRsfst +sLQyLP3qW6Wfm7ueZsVuLtwCDYSz8ykT/ZZ0r2Mm7qQ9joroZ3bnmuTUg+b1cUCb1 pQmObfe8HyBxpZisGhJYtpgRWE+21KPuEZe9elZpOpfdCJ8dbHGDeoK8ui1lWd5Uly O78nrLS+ktGnjWK2S6oIZRSfBC9r8s3o0S+Ck5O9hdoruGb/wNStbZKK1j9Yh6ei6q VvXfGR1o+DDqw== From: Josh Poimboeuf To: live-patching@vger.kernel.org Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Miroslav Benes , Petr Mladek , Joe Lawrence , Jiri Kosina , Peter Zijlstra , Marcos Paulo de Souza , Song Liu Subject: [RFC 27/31] objtool: Fix weak symbol detection Date: Mon, 2 Sep 2024 21:00:10 -0700 Message-ID: X-Mailer: git-send-email 2.45.2 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" find_symbol_hole_containing() fails to find a symbol hole (aka stripped weak symbol) if its section has no symbols before the hole. This breaks weak symbol detection if -ffunction-sections is enabled. Fix it by allowing the interval tree to contain section symbols, which are always at offset zero for a given section. Fixes a bunch of (-ffunction-sections) warnings like: vmlinux.o: warning: objtool: .text.__x64_sys_io_setup+0x10: unreachable i= nstruction vmlinux.o: warning: objtool: .text.__x64_sys_io_setup+0x14: unreachable i= nstruction vmlinux.o: warning: objtool: .text.__x64_sys_io_setup+0x19: unreachable i= nstruction vmlinux.o: warning: objtool: .text.__x64_sys_io_setup+0x20: unreachable i= nstruction Fixes: 4adb23686795 ("objtool: Ignore extra-symbol code") Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 471df0336aa7..3109277804cc 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -110,7 +110,7 @@ struct symbol_hole { }; =20 /* - * Find !section symbol where @offset is after it. + * Find the last symbol before @offset. */ static int symbol_hole_by_offset(const void *key, const struct rb_node *no= de) { @@ -121,8 +121,7 @@ static int symbol_hole_by_offset(const void *key, const= struct rb_node *node) return -1; =20 if (sh->offset >=3D s->offset + s->len) { - if (s->type !=3D STT_SECTION) - sh->sym =3D s; + sh->sym =3D s; return 1; } =20 @@ -416,7 +415,8 @@ static void elf_add_symbol(struct elf *elf, struct symb= ol *sym) sym->len =3D sym->sym.st_size; =20 __sym_for_each(s, &sym->sec->symbol_tree, sym->offset, sym->offset) { - if (s->offset =3D=3D sym->offset && s->type =3D=3D sym->type) + if (s->type =3D=3D sym->type && s->offset =3D=3D sym->offset && + s->len =3D=3D sym->len) s->alias =3D sym; } =20 @@ -433,9 +433,13 @@ static void elf_add_symbol(struct elf *elf, struct sym= bol *sym) /* * Don't store empty STT_NOTYPE symbols in the rbtree. They * can exist within a function, confusing the sorting. + * + * TODO: is this still true? */ - if (!sym->len) +#if 0 + if (sym->type =3D=3D STT_NOTYPE && !sym->len) __sym_remove(sym, &sym->sec->symbol_tree); +#endif } =20 static void read_symbols(struct elf *elf) --=20 2.45.2