Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp387706pxj; Thu, 20 May 2021 11:37:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpn1WXmprfD4p8Ewoa4GtNmfD4RO9r0vzfMoGyhij2sbJOjXBzer144Ix9e5Y7cN9g1KG5 X-Received: by 2002:a92:c607:: with SMTP id p7mr6817492ilm.97.1621535826404; Thu, 20 May 2021 11:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535826; cv=none; d=google.com; s=arc-20160816; b=VIjAQRYZSDXeoI8fHwD9lbrwpu8/BjkSP0rw7CLc0sMk/mH+LMOatvJ7fnRjFdIDB4 lPOL1N4owEuJdb4EKAD5A6IPpU60+FYGlR5IESsKP3sBSdpUoSmPu5DeyiTExuytX0GQ TixUWZCwHO+vEdLluj/mWJ36F4xFU6HOJBgQPLFZM7HfsZq1HaYuBpro+BxAERJOgykt Z2Dkh7aQMA+uY14o9jiVdlh0xnU4oUydcRwm5MAH0e1hFN94FqPnWTzsKc/v4783EKvD If7PUL/JgNECAGSVGugt0Hio0HWlrz6XtIUujGc5WwkfDeSYmeW5kS33CSJ3bhNf8DMG Di9g== 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=7kNYrkOWoj61b15q7zJ8fyJ5RvP9wYg4wrB+I5gonTU=; b=qtkvhlfYtBUJwksN9lxfGn9BvYLT+9rFOQCeLBnndp7PxgvJaIYXwGD686dRbUGzvV GVRTranoOH+Ik8zW7TmfhSJ51zemIFB/xbNaNkKRR6KQ0DMLC1Yf+GEtjsGqxzXkj9LX NlmNAC5Xlxjz3uIDwvVrV/MW522PM2UD+xaE/7CMDDA2SlELtbbVWFjPmhsi6yHagsRg zZ2Hw8gazVHzvDKEHeEnqUgX7BA4JC9z68hee/Z5wFDAaEy0e/Ftr98eLMVIx4iEa2Hx RH89YLDNb7izfiTg+EqVpB0JVEPWY9grSa+3UMYfz2MbSDy9CQRq+S/ER3yLCoNCtifm UJgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ZHO+2+MQ; 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 c15si2949537jag.124.2021.05.20.11.36.51; Thu, 20 May 2021 11:37:06 -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=@linuxfoundation.org header.s=korg header.b=ZHO+2+MQ; 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 S236590AbhETKYU (ORCPT + 99 others); Thu, 20 May 2021 06:24:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:46058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235934AbhETKNN (ORCPT ); Thu, 20 May 2021 06:13:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8643361442; Thu, 20 May 2021 09:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503854; bh=70A0GRAmaL/D6QBoBkf17V3ylGgPZk8LKx1hrUPXpVs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZHO+2+MQgTen4pRUVST6jFtEfYKzek1Pzyaon/Hn9XvEA8QTwiv+/8J3ucpGSqsn9 /DAlxfXfHKsYgLlibUTpQvAOtGs+GyH/ZkKvItbwQOMhvX6XHCYoyZ1jgvwGJKZV2p NHbEiXDZqWU4hmDW/pYj/ktqL0lZe9cskXtGlZXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Palmer Dabbelt , Sasha Levin Subject: [PATCH 4.19 410/425] riscv: Workaround mcount name prior to clang-13 Date: Thu, 20 May 2021 11:22:59 +0200 Message-Id: <20210520092144.881219546@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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: Nathan Chancellor [ Upstream commit 7ce04771503074a7de7f539cc43f5e1b385cb99b ] Prior to clang 13.0.0, the RISC-V name for the mcount symbol was "mcount", which differs from the GCC version of "_mcount", which results in the following errors: riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_level': main.c:(.text+0xe): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_start': main.c:(.text+0x4e): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `__traceiter_initcall_finish': main.c:(.text+0x92): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `.LBB32_28': main.c:(.text+0x30c): undefined reference to `mcount' riscv64-linux-gnu-ld: init/main.o: in function `free_initmem': main.c:(.text+0x54c): undefined reference to `mcount' This has been corrected in https://reviews.llvm.org/D98881 but the minimum supported clang version is 10.0.1. To avoid build errors and to gain a working function tracer, adjust the name of the mcount symbol for older versions of clang in mount.S and recordmcount.pl. Link: https://github.com/ClangBuiltLinux/linux/issues/1331 Signed-off-by: Nathan Chancellor Reviewed-by: Nick Desaulniers Signed-off-by: Palmer Dabbelt Signed-off-by: Sasha Levin --- arch/riscv/include/asm/ftrace.h | 14 ++++++++++++-- arch/riscv/kernel/mcount.S | 10 +++++----- scripts/recordmcount.pl | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/ftrace.h b/arch/riscv/include/asm/ftrace.h index 02fbc175142e..693c3839a7df 100644 --- a/arch/riscv/include/asm/ftrace.h +++ b/arch/riscv/include/asm/ftrace.h @@ -10,9 +10,19 @@ #endif #define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR +/* + * Clang prior to 13 had "mcount" instead of "_mcount": + * https://reviews.llvm.org/D98881 + */ +#if defined(CONFIG_CC_IS_GCC) || CONFIG_CLANG_VERSION >= 130000 +#define MCOUNT_NAME _mcount +#else +#define MCOUNT_NAME mcount +#endif + #define ARCH_SUPPORTS_FTRACE_OPS 1 #ifndef __ASSEMBLY__ -void _mcount(void); +void MCOUNT_NAME(void); static inline unsigned long ftrace_call_adjust(unsigned long addr) { return addr; @@ -33,7 +43,7 @@ struct dyn_arch_ftrace { * both auipc and jalr at the same time. */ -#define MCOUNT_ADDR ((unsigned long)_mcount) +#define MCOUNT_ADDR ((unsigned long)MCOUNT_NAME) #define JALR_SIGN_MASK (0x00000800) #define JALR_OFFSET_MASK (0x00000fff) #define AUIPC_OFFSET_MASK (0xfffff000) diff --git a/arch/riscv/kernel/mcount.S b/arch/riscv/kernel/mcount.S index 5721624886a1..fabddee90d1b 100644 --- a/arch/riscv/kernel/mcount.S +++ b/arch/riscv/kernel/mcount.S @@ -47,8 +47,8 @@ ENTRY(ftrace_stub) #ifdef CONFIG_DYNAMIC_FTRACE - .global _mcount - .set _mcount, ftrace_stub + .global MCOUNT_NAME + .set MCOUNT_NAME, ftrace_stub #endif ret ENDPROC(ftrace_stub) @@ -79,7 +79,7 @@ EXPORT_SYMBOL(return_to_handler) #endif #ifndef CONFIG_DYNAMIC_FTRACE -ENTRY(_mcount) +ENTRY(MCOUNT_NAME) la t4, ftrace_stub #ifdef CONFIG_FUNCTION_GRAPH_TRACER la t0, ftrace_graph_return @@ -125,6 +125,6 @@ do_trace: jalr t5 RESTORE_ABI_STATE ret -ENDPROC(_mcount) +ENDPROC(MCOUNT_NAME) #endif -EXPORT_SYMBOL(_mcount) +EXPORT_SYMBOL(MCOUNT_NAME) diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl index bc12e12e4b3a..657e69125a46 100755 --- a/scripts/recordmcount.pl +++ b/scripts/recordmcount.pl @@ -395,7 +395,7 @@ if ($arch eq "x86_64") { $mcount_regex = "^\\s*([0-9a-fA-F]+):.*\\s_mcount\$"; } elsif ($arch eq "riscv") { $function_regex = "^([0-9a-fA-F]+)\\s+<([^.0-9][0-9a-zA-Z_\\.]+)>:"; - $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL(_PLT)?\\s_mcount\$"; + $mcount_regex = "^\\s*([0-9a-fA-F]+):\\sR_RISCV_CALL(_PLT)?\\s_?mcount\$"; $type = ".quad"; $alignment = 2; } elsif ($arch eq "nds32") { -- 2.30.2