Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp556367ybz; Wed, 15 Apr 2020 13:58:13 -0700 (PDT) X-Google-Smtp-Source: APiQypIM5uLPmK2fik7oTwp4ONwxzaw1icQVHe1I2W0wek1KMgMwFQHB75pEy2KKFVpD8qrNeCnR X-Received: by 2002:a50:c0ce:: with SMTP id r14mr13245011edf.298.1586984293067; Wed, 15 Apr 2020 13:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586984293; cv=none; d=google.com; s=arc-20160816; b=J/FrB0vuuag8AjbC1rwRg041Ld9yCt00ot049IkR3r1mKZOrPmwgleLwtQE3jr2UrA Jpp2bbokxVC8MzELeRCU9VjDw/sjH23MfTvJyZMsAygUPjF4l01q3iSnZdPIcUzL2AIi Ce5k8Mou38m33fzB5fRNc6NJjHT6rMIHk6R2WLX9vWPqGsMqdTnft1uTceM7YWJvx1n2 odK/UHPg1tDk/V6jHjioQXOs4JbazPszOI+DdaQJIEup3fJqkCdkx23EWrkiKgf8x+Zg ucvQvfJ1DT74ClUqi+YysNQN4FocaPnpl4g8GG9Gxk0SERVzZncgiVqOYihfjXuor6sq BuxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=2LKw8QhKCsnVNgwrHiaqk9rwY9/CqwoHedenbfTZ0tc=; b=m6cno/k4FUf7Y3hiVOhW0NV00AY1xRSarz6ekozPV6sqReZO9OUtcY4stDZBsYZdrT 2BpY+rX9zDrtw/Z1ZtYNfzy0rHhM8KHQ6UeE0jVwlwTbtuAhsgIe8F3/iMaJwYRiiFYf W2g41EiAvs1KnE9mHyTHJDgOUfGOjz2lHnEO6Znm1uMfP9ZBRgZohdjaKw2o+O8bLyRg hgUPR2NFkmvtuavjZ20gq1eu9FkBvf4Rt53tgDE/RMNuqMk9fJk1joOBoYv9hP/MBHdn 4HPr7/38urBLWVRtQOnZkWpvrwnp8DY6CFoYFWZpPqfrf3Q9VU/SawQSfLwz3ltxy0yg Q/Lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for 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 v5si8142339ejx.10.2020.04.15.13.57.49; Wed, 15 Apr 2020 13:58:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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; spf=pass (google.com: best guess record for 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 S2438729AbgDNK4U (ORCPT + 99 others); Tue, 14 Apr 2020 06:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S2438401AbgDNKeK (ORCPT ); Tue, 14 Apr 2020 06:34:10 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8277C061A41; Tue, 14 Apr 2020 03:34:10 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jOItH-0008Sj-8p; Tue, 14 Apr 2020 12:34:03 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id DECA71C0086; Tue, 14 Apr 2020 12:34:02 +0200 (CEST) Date: Tue, 14 Apr 2020 10:34:02 -0000 From: "tip-bot2 for Josh Poimboeuf" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] objtool: Support Clang non-section symbols in ORC generation Cc: Dmitry Golovin , Josh Poimboeuf , Borislav Petkov , Nathan Chancellor , Miroslav Benes , "Peter Zijlstra (Intel)" , x86 , LKML In-Reply-To: <9a9cae7fcf628843aabe5a086b1a3c5bf50f42e8.1585761021.git.jpoimboe@redhat.com> References: <9a9cae7fcf628843aabe5a086b1a3c5bf50f42e8.1585761021.git.jpoimboe@redhat.com> MIME-Version: 1.0 Message-ID: <158686044251.28353.5727217228270138782.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/urgent branch of tip: Commit-ID: e81e0724432542af8d8c702c31e9d82f57b1ff31 Gitweb: https://git.kernel.org/tip/e81e0724432542af8d8c702c31e9d82f57b1ff31 Author: Josh Poimboeuf AuthorDate: Wed, 01 Apr 2020 13:23:27 -05:00 Committer: Borislav Petkov CommitterDate: Tue, 14 Apr 2020 12:03:42 +02:00 objtool: Support Clang non-section symbols in ORC generation When compiling the kernel with AS=clang, objtool produces a lot of warnings: warning: objtool: missing symbol for section .text warning: objtool: missing symbol for section .init.text warning: objtool: missing symbol for section .ref.text It then fails to generate the ORC table. The problem is that objtool assumes text section symbols always exist. But the Clang assembler is aggressive about removing them. When generating relocations for the ORC table, objtool always tries to reference instructions by their section symbol offset. If the section symbol doesn't exist, it bails. Do a fallback: when a section symbol isn't available, reference a function symbol instead. Reported-by: Dmitry Golovin Signed-off-by: Josh Poimboeuf Signed-off-by: Borislav Petkov Tested-by: Nathan Chancellor Reviewed-by: Miroslav Benes Acked-by: Peter Zijlstra (Intel) Link: https://github.com/ClangBuiltLinux/linux/issues/669 Link: https://lkml.kernel.org/r/9a9cae7fcf628843aabe5a086b1a3c5bf50f42e8.1585761021.git.jpoimboe@redhat.com --- tools/objtool/orc_gen.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index 41e4a27..4c0dabd 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -88,11 +88,6 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti struct orc_entry *orc; struct rela *rela; - if (!insn_sec->sym) { - WARN("missing symbol for section %s", insn_sec->name); - return -1; - } - /* populate ORC data */ orc = (struct orc_entry *)u_sec->data->d_buf + idx; memcpy(orc, o, sizeof(*orc)); @@ -105,8 +100,32 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti } memset(rela, 0, sizeof(*rela)); - rela->sym = insn_sec->sym; - rela->addend = insn_off; + if (insn_sec->sym) { + rela->sym = insn_sec->sym; + rela->addend = insn_off; + } else { + /* + * The Clang assembler doesn't produce section symbols, so we + * have to reference the function symbol instead: + */ + rela->sym = find_symbol_containing(insn_sec, insn_off); + if (!rela->sym) { + /* + * Hack alert. This happens when we need to reference + * the NOP pad insn immediately after the function. + */ + rela->sym = find_symbol_containing(insn_sec, + insn_off - 1); + } + if (!rela->sym) { + WARN("missing symbol for insn at offset 0x%lx\n", + insn_off); + return -1; + } + + rela->addend = insn_off - rela->sym->offset; + } + rela->type = R_X86_64_PC32; rela->offset = idx * sizeof(int); rela->sec = ip_relasec;