From nobody Sun Feb 8 09:11:36 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 922CB1D61B4; Tue, 3 Sep 2024 04:00:40 +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=1725336040; cv=none; b=BdQoZ71+yIJBGSym/wr5nlSCfDu2r0/WT66cFL/Ln7akF8uvPwup1GjvTZ+O7GQggI0WWwn0b7/C26nD2rSjc0GWOutILe5pkpa9Xnp1+f3L+QRrlrkdAfKFcZjQ/ZfuDkHJ36HzYfPKeyDC2tTIVnjQm1CSwXO+24cek+OrpjQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725336040; c=relaxed/simple; bh=K51ZKKek6YNwqc2KmzuJq5BxCeSmLBBJ3r1dJblKcf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=umhWJP0CqX7W0jOMetjdd9j5hzbXepOc0Qjzd5vf3dL/i9rNU9OD2H/CJYGHjvixAi/p/2Srd3ExzTpZyLv4h4wp/Z6Jj59inae+6jqG/1Q6svJhAx/ADp6ZxjrWhRSU1i0ZY9aEGhRwGfmPp8H5CL4hJ6tWBl98VM7287tUzJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D580FoCP; 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="D580FoCP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 194F4C4CEC7; Tue, 3 Sep 2024 04:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725336040; bh=K51ZKKek6YNwqc2KmzuJq5BxCeSmLBBJ3r1dJblKcf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D580FoCP7B1SrYC6jLwS/tc6+JhsvVMSsPDF9QUluKX/ENwtHXVIERXvCuUEASrsk tOk496q0Q3YpG17t4wD1I8pHxAmIhL1LaPEUsN0SjDeDXwIhg9k+T8vjUI7fc96dZI XEo9+Ds4UeEBd1WJPDfgnXW9kpLdSb1cKmLR2mipGF3+/FthrA+bd+nqMibdrIEzyB YzoOEYiUjRIlCcwYHLXhXS/usqNHwvoLYqSo7DXFFhKVaPs75/CcnR8diEab2vKqxv QspsXpCQ+gbHqCudddoIe0xbKjTGQ4GlhIOgAuc/roiBMPcZgkCdCPe2YJRu7iNEtH dfSuQWpZ0cTrw== 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 22/31] objtool: Make find_symbol_containing() less arbitrary Date: Mon, 2 Sep 2024 21:00:05 -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" In the rare case of overlapping symbols, find_symbol_containing() just returns the first one it finds. Make it less arbitrary by returning the smallest symbol with size > 0. Eventually we should consider making such overlapping symbols illegal. Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 7f89b0a99886..49528e7835aa 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -195,14 +195,29 @@ struct symbol *find_func_by_offset(struct section *se= c, unsigned long offset) struct symbol *find_symbol_containing(const struct section *sec, unsigned = long offset) { struct rb_root_cached *tree =3D (struct rb_root_cached *)&sec->symbol_tre= e; - struct symbol *iter; + struct symbol *sym =3D NULL, *tmp; =20 - __sym_for_each(iter, tree, offset, offset) { - if (iter->type !=3D STT_SECTION) - return iter; + __sym_for_each(tmp, tree, offset, offset) { + if (tmp->len) { + if (!sym) { + sym =3D tmp; + continue; + } + + if (sym->offset !=3D tmp->offset || sym->len !=3D tmp->len) { + /* + * In the rare case of overlapping symbols, + * pick the smaller one. + * + * TODO: outlaw overlapping symbols + */ + if (tmp->len < sym->len) + sym =3D tmp; + } + } } =20 - return NULL; + return sym; } =20 /* --=20 2.45.2