Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1344438pxb; Fri, 1 Oct 2021 08:42:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy14pTnz7yVm140JclU7dSorEapYapwG6Hfd8yGrF6Ts3MpnPjzo5gK1v1TfthUiwWHr0k0 X-Received: by 2002:a17:907:2090:: with SMTP id pv16mr7446388ejb.156.1633102953226; Fri, 01 Oct 2021 08:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633102953; cv=none; d=google.com; s=arc-20160816; b=qsXqt8JnTPGY/KZ2czPJ3ZKwntWNouJahNFlcPoTCqsjRrAi49MPnhuS1QBU6jgu6c i5xTLn+yZQXsBnfVj9piu0RREhDj3vwL5+LTG1W945B7DUTdFiNKRhLoWDUr4Nt5+3QN PWvSSdHRR934ip/pvHBgR/kltwOiOVH+HX1teGd+iHYJaynyMI2SWn+Ur52ehVIW2LgB bzNVx3IXYrD22aG0/x8eYICCM8T+g/L8DdZwoc1tpEcL4TIlbLhZt4l6ae2ciM82Q6+8 enG4fmBwOTFgZQZPgFB+jjXm7W7TSbA5IXJNSy/psAtvLWYDfsUieJXpbg2UMYRSJpca XKtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=2DoAPpnW6nze+QbMQRuvKt4Utwv1lG5GthgalZwKw+I=; b=oFCYeP/qF6ZLgs/meWvalmp0WF6jymjg3etVbsdvK4eiVTDN2UweUW1aHgYeLIGOWa dAxU2K5FkQZSBW0arPySxfRqAU05l1aZQqUwcLJVT/ozsf51jAvDeWLD70nZyf4bs7Ei 7YEXkWGlPGZiHW8CbXh4+6wCll1qI+7T/DAjVaFjDnEBnTb6cskCHpqqfHR7TYIGmrVg 2b4wRdT0NM7lhjWqo+ZquS8aZR8UmNlU2HDcavcUC4mZU6yuvSHE4f5tvehjMU3SfTP4 DQbQDcDiXltuc66/yLAXxCLRNAbTFUSSwj8jQQfGpL+rieQW+Hmp9EVIwfTBpAECN/Gr 31MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JtK0uIOt; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v8si6682567ejv.62.2021.10.01.08.42.07; Fri, 01 Oct 2021 08:42:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=JtK0uIOt; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354360AbhJAMMh (ORCPT + 99 others); Fri, 1 Oct 2021 08:12:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354322AbhJAMM3 (ORCPT ); Fri, 1 Oct 2021 08:12:29 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFF4BC06177B; Fri, 1 Oct 2021 05:10:45 -0700 (PDT) Date: Fri, 01 Oct 2021 12:10:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1633090244; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DoAPpnW6nze+QbMQRuvKt4Utwv1lG5GthgalZwKw+I=; b=JtK0uIOt9ObRc8H8dtH+piweNJ0IDIcAPOgQqbLTeNUfsQSRFg9NJtTUaLylE+wu0/d4P0 Efh2ZkyJjm2Cg30OG7Oz1CE3wZC4N9BXbCA/mhPfF7j4SQc7K5YBoJCQOodqrFUqTKOn9O FG84WtXAmubXiQsgeZ3NiFqnDTP6HPHtFZj2rXg0XqmLdHN5WJxWkxoR4Uy2AOrcgOX2ks iWXtFkuflDWjrxJECwT1mcAdEEpfMnyiz1SOa9xfDAWXBufL1bKQ4yI5AgliwRQsX3ea7J I3wgo6BPAfD8VbnLi3Rj3GoNE+211KZ6+zNI6Lp2Ad9l3hhL3AcXS4jEglY2mA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1633090244; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2DoAPpnW6nze+QbMQRuvKt4Utwv1lG5GthgalZwKw+I=; b=L99MPhdkY2hp/Yqv+bbfvsfYK5/ODfadrNoxDF9+u4VTvfOehtsDB2FBk5ZKeji7I1Zoz8 +HZpBCuJII8GxWCw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/urgent] objtool: Teach get_alt_entry() about more relocation types Cc: Stephen Rothwell , Borislav Petkov , "Peter Zijlstra (Intel)" , Josh Poimboeuf , Nathan Chancellor , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <163309024344.25758.12284143323900056369.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the objtool/urgent branch of tip: Commit-ID: 24ff652573754fe4c03213ebd26b17e86842feb3 Gitweb: https://git.kernel.org/tip/24ff652573754fe4c03213ebd26b17e86842feb3 Author: Peter Zijlstra AuthorDate: Thu, 30 Sep 2021 12:43:10 +02:00 Committer: Peter Zijlstra CommitterDate: Fri, 01 Oct 2021 13:57:47 +02:00 objtool: Teach get_alt_entry() about more relocation types Occasionally objtool encounters symbol (as opposed to section) relocations in .altinstructions. Typically they are the alternatives written by elf_add_alternative() as encountered on a noinstr validation run on vmlinux after having already ran objtool on the individual .o files. Basically this is the counterpart of commit 44f6a7c0755d ("objtool: Fix seg fault with Clang non-section symbols"), because when these new assemblers (binutils now also does this) strip the section symbols, elf_add_reloc_to_insn() is forced to emit symbol based relocations. As such, teach get_alt_entry() about different relocation types. Fixes: 9bc0bb50727c ("objtool/x86: Rewrite retpoline thunk calls") Reported-by: Stephen Rothwell Reported-by: Borislav Petkov Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Tested-by: Nathan Chancellor Link: https://lore.kernel.org/r/YVWUvknIEVNkPvnP@hirez.programming.kicks-ass.net --- tools/objtool/special.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tools/objtool/special.c b/tools/objtool/special.c index bc925cf..f58ecc5 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -58,6 +58,24 @@ void __weak arch_handle_alternative(unsigned short feature, struct special_alt * { } +static bool reloc2sec_off(struct reloc *reloc, struct section **sec, unsigned long *off) +{ + switch (reloc->sym->type) { + case STT_FUNC: + *sec = reloc->sym->sec; + *off = reloc->sym->offset + reloc->addend; + return true; + + case STT_SECTION: + *sec = reloc->sym->sec; + *off = reloc->addend; + return true; + + default: + return false; + } +} + static int get_alt_entry(struct elf *elf, struct special_entry *entry, struct section *sec, int idx, struct special_alt *alt) @@ -91,15 +109,12 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry, WARN_FUNC("can't find orig reloc", sec, offset + entry->orig); return -1; } - if (orig_reloc->sym->type != STT_SECTION) { - WARN_FUNC("don't know how to handle non-section reloc symbol %s", + if (!reloc2sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off)) { + WARN_FUNC("don't know how to handle reloc symbol type: %s", sec, offset + entry->orig, orig_reloc->sym->name); return -1; } - alt->orig_sec = orig_reloc->sym->sec; - alt->orig_off = orig_reloc->addend; - if (!entry->group || alt->new_len) { new_reloc = find_reloc_by_dest(elf, sec, offset + entry->new); if (!new_reloc) { @@ -116,8 +131,11 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry, if (arch_is_retpoline(new_reloc->sym)) return 1; - alt->new_sec = new_reloc->sym->sec; - alt->new_off = (unsigned int)new_reloc->addend; + if (!reloc2sec_off(new_reloc, &alt->new_sec, &alt->new_off)) { + WARN_FUNC("don't know how to handle reloc symbol type: %s", + sec, offset + entry->new, new_reloc->sym->name); + return -1; + } /* _ASM_EXTABLE_EX hack */ if (alt->new_off >= 0x7ffffff0)