Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp248655pxb; Thu, 30 Sep 2021 05:22:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo/Exk+PmdCLRJFwkqgPwklQIqCUAG12M4VL3IODpYn6Ez1ueP8QOPUG6DJiy8j0jDy037 X-Received: by 2002:a17:90b:1d10:: with SMTP id on16mr12591900pjb.220.1633004566954; Thu, 30 Sep 2021 05:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633004566; cv=none; d=google.com; s=arc-20160816; b=rsT7nEyl6iFRgbAYG5OPm7dP+GS0nHGco9FVPrWR55YgzP4xIojbkqxmbYvniiJ9h1 xTDxcOl1YQXG/DN1btSfcsoA1LMnCBaOmiMCcW6NNsjNIRwFeTNyQ/JORqlCDRIVAfJ9 k9WU3Fg8ji09uVGVKGhi0nYRY0Xnqr13tno/U60LpLvl1lUhVVuzwDbS/BmIYuLcXhTx FmaZbTsMQ/iehe4KK4JNd6utnSDbg8cfcJ+PJ5lKPqcI+dCYd7jhJYvxYn9n8nN4tFt1 EBCph0VWoahYJaduT9OsJmWmJtPsoAOUQHEKRGZPU9oim2U7c5rDC9/wdaw9wgIBcfcK SDrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=UZS7L5sdXa7FYPEbrMCpL9TsId2dqB5wF+AhnZfv+AQ=; b=mlPQ0jRVbLHO6u8SXTZqWwNElptTYLYRmPvzbejJKtk3t9KrokjTIB7mlV3R8cZh6I UHI8V+vuYmW4N9wpMN+48BUUix7+qR+8jy1NCTUQXc9+QZsfkypd9ovSjRGTsYYMBglP sLZZi5OOKDWU+o7xuL+XNsA8uI26wRtVLDN1KxH/Sa8puchFdVnmxivbePIuqRfY5mkb lcnbQzRcKHCw8h0XzqvXRMkJ+ctSjJEvA5ajotOPZONhkHO0GFrJnBUSb6qzsXEW9WN3 NID/931cOXyHxjPneC5WW+frkc0qMi0Kcyaeh6RQpv7lWbdXiTyZmqwCvf07dlrwvJ6n K/Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wRTVDJD5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a10si3331001pgq.310.2021.09.30.05.22.33; Thu, 30 Sep 2021 05:22:46 -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=@infradead.org header.s=casper.20170209 header.b=wRTVDJD5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350109AbhI3KqU (ORCPT + 99 others); Thu, 30 Sep 2021 06:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350082AbhI3KqQ (ORCPT ); Thu, 30 Sep 2021 06:46:16 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 305B9C06176A for ; Thu, 30 Sep 2021 03:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=UZS7L5sdXa7FYPEbrMCpL9TsId2dqB5wF+AhnZfv+AQ=; b=wRTVDJD5p9+9D9AfPRjqBaKl3j /+a8yHnVg78mPC4HF5ik9BHozkqFsKmnNVVr863F6wdt8fSgyHcFG7DxCw8kvo/MOhaaqSTMV9Odm mLZWE0mB3U604vxl7BDBTru+N+om1iUyXrTcjgjtCogxzWE7jbgV/KH2n0jtI2wLu/JXfW2Zzjwsx /2B3EJQHq5ZJN/y/9UF6ByZXXU6E4ny7PVZE1vpTjT/Qz6abHIYQNRZe13rw/6zRiBNDlNCjqr1nC qLMFvM8q1eV2Jm/k+a9oAPkB26jnbJNhMx0gZkdDhsDvMPIUe/J0Y6FXEUUu0RbYVFzuVDOSJnI2K 64xyEwTw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVtWy-00CkwW-RC; Thu, 30 Sep 2021 10:43:26 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 9D82E300252; Thu, 30 Sep 2021 12:43:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CC3902C8F7853; Thu, 30 Sep 2021 12:43:10 +0200 (CEST) Date: Thu, 30 Sep 2021 12:43:10 +0200 From: Peter Zijlstra To: Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, x86@kernel.org, sfr@canb.auug.org.au, mbenes@suse.cz Subject: [PATCH] objtool: Teach get_alt_entry() about more relocation types Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) --- tools/objtool/special.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -58,6 +58,24 @@ void __weak arch_handle_alternative(unsi { } +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 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 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)