Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4106421pxb; Mon, 8 Feb 2021 08:06:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWjy2WItTCOFp/vXATP86SRU/EEZfC/ptreVsiP7FRAm1jpGD91fSwzdCdliBbcOgjZFbn X-Received: by 2002:a50:d4d9:: with SMTP id e25mr17845725edj.183.1612800370378; Mon, 08 Feb 2021 08:06:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612800370; cv=none; d=google.com; s=arc-20160816; b=MfI3FcPPIDcWZ9ldBMtUpaVEv4i7DvhUa6jQ2/It+HHu4ty2tH6YHmPrdMZ3wQ7rI5 OG5bUDQrZQxZRdGMVSI2/ZY/Kosbhzudd47ZLMc/FvF18M9LuH5P2zKNkPVmqX4+TGcH k1d/a1MP5i5syXc9uPb83q28VZbc4lTxT+Zt7yrzlpI8abhrBEgBLm//Ov7G64mv2X5p 0LVgzBiv0+HrfscnOiLbZ5S5VeWRPb6OtO0xL2k1RjDQ3Bd5Jd2+rcXNicvIf98WKLR4 vf9xq70MUolKoLiGDtK7boLYuWrFELGMbFr+AnCCMDreyus3gMiAxHId8DjPR9Nzd4KO zUIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=F37Efn7H6EIrCiO0fXqpaL6GulpSOvOhFi/M1FNe9cw=; b=N7wdVD8tje9oEMDiJkjUrng3IZWBDHep7ReMG2WoyWpe2bpSq0J8YDg9ZlImBXl0+E +eymZpVTaaSC3GDnMCbb8qrEJy+InKrRr9iWRTnAdpfbziAig4/YCQwD/zkSPIqHQ77K cMjJD+tfBMvUQgGugNBIzsln9Si12sb3TTNg3qPCdMofZQsLV/Az6yTVO6ZBqoLjy/96 NRVCKKcryGGb6TETjU3Hfj3DpX2izbs+M6dROW+YFWzVEDd+usRCwqgQV4SydbzKLRX8 USggHDikpZBNtkcQzc5aVizCqp0oJdhQlsGYDY9Hto5HY+FKrZL3pEiVwi48GJa4bX5f 1EKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V4enW3kb; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 22si10709886ejc.181.2021.02.08.08.05.43; Mon, 08 Feb 2021 08:06:10 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=V4enW3kb; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230328AbhBHQD4 (ORCPT + 99 others); Mon, 8 Feb 2021 11:03:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:56628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbhBHPKS (ORCPT ); Mon, 8 Feb 2021 10:10:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BF47F64ECC; Mon, 8 Feb 2021 15:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612796832; bh=3rCQ7I9TwgVwgGUKfP/9UDumJyWLE6qOc5ewW1LSgEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V4enW3kb0R7rAzSpsl6j8bqHNemFV0w/50vMtnlMTeVzvSQFGIiioJ7wBJZxcQaqD iVA/fdVYpQWLSpm0ef4Dr6QbJXDQBn5CCm/sjMZBBSixN3V3Qe33hXLWs7IbUfLB8H 7a2SCWvu/MqtwFvm1sUBlqCt5I0kHeXbL4YLlJXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Golovin , Josh Poimboeuf , Borislav Petkov , Nathan Chancellor , Miroslav Benes , "Peter Zijlstra (Intel)" Subject: [PATCH 4.14 07/30] objtool: Support Clang non-section symbols in ORC generation Date: Mon, 8 Feb 2021 16:00:53 +0100 Message-Id: <20210208145805.550306003@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145805.239714726@linuxfoundation.org> References: <20210208145805.239714726@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josh Poimboeuf commit e81e0724432542af8d8c702c31e9d82f57b1ff31 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- tools/objtool/orc_gen.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -98,11 +98,6 @@ static int create_orc_entry(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)); @@ -115,8 +110,32 @@ static int create_orc_entry(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);