Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp245759pxj; Thu, 20 May 2021 08:29:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwp3kr6bW23H/lUWMcd/8f0hSTt0wLnEo0xicUPcdF7hqKHTYqkM/0siWCYoYeqPt10Vewz X-Received: by 2002:a92:360e:: with SMTP id d14mr5705423ila.106.1621524592523; Thu, 20 May 2021 08:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621524592; cv=none; d=google.com; s=arc-20160816; b=EPN3XafYth3Pxr42KaUnZSGQXnDqVfxo8Xq8uIqqR6+B/xbB6tyvXNNT+RoJf/pWzT aVC9UJRuhwJbamgwGfd5NvaxrK4DwiAcfsplslDWhjuA8anygw820uk7Cc0WAXFjN5g/ q4ptAsN0g58Z+3GOc29hElfj0bvX14sKknC5ZgjGzvIm8p2OMrxs1/70ByA8xGKZ2myB JzHa3Nwx3YED0uF0Nx1JqgPeAtua46y/YDVdfaZBc0S1gXLW+DvhfDuWqeyw2gG9o0jA VqMKO+7zizqPWp1SxdoWbS3TwD9QOQZQnCgkC1fJUUijxR9msT6TPI/7AMTv9JMOpgkh Ep+A== 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=c3Rz12KFrPD7fATdVI1uem7SlWpad+uHlidYJCvoTME=; b=sG500mKdLIJhGqgiruQ+5UdeaVgHIbWfvom4pcoQYQofYTM7wHk+PyY4eyJvyuYX/0 ukaimt/0e06OdyTR1cIi+wTZmYG4VPuTqMTfKK6trHTqgJMQkealb4xmwmJJfRKBZjiT wYU/DUJ2ZvWCOW0OY6WF+AyE9APLSEkyzKvXoatoDqK5BJEskfxo2yO62aAjAIeRUNBG IvYG2tng2xM4gL5+BiFW3Bms9K5jmiw08GDTfW+2yYVvpBSelW+//B8V48Jlp2EMuoVh NpS6lqXn5gLoO9U3FkPQOxiGHkLqHIK3wQmesUXn7W6b14+aVCHHACaQ4eAr9mFo7iAK 1dug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ILXGLSWE; 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 d25si2296277jam.64.2021.05.20.08.29.38; Thu, 20 May 2021 08:29:52 -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=ILXGLSWE; 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 S233009AbhETJhB (ORCPT + 99 others); Thu, 20 May 2021 05:37:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:33340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232930AbhETJeb (ORCPT ); Thu, 20 May 2021 05:34:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2376B613AC; Thu, 20 May 2021 09:29:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621502953; bh=5DhxySL7063pAgKvp/yiw/t12YXnyXZ+n2NwaHkUb9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ILXGLSWEFj4xAY/ee0SGBgshAwTDI3oAJgqjVskamMYG9a+Unjb3nc9D/RchBZTzd deAW394hdwiVFlC6Hu3tCJmRUFSvIXFDjcpcQ+Z8p8TW2/XoM4smReToZg40MOCsgS BB999H3xuYLnjL3j9it2bGZcKffob7YQ5T0flrws= 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 5.4 20/37] riscv: Workaround mcount name prior to clang-13 Date: Thu, 20 May 2021 11:22:41 +0200 Message-Id: <20210520092052.944408167@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092052.265851579@linuxfoundation.org> References: <20210520092052.265851579@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 8a5593ff9ff3..6d462681c9c0 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) @@ -78,7 +78,7 @@ ENDPROC(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 @@ -124,6 +124,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 857d5b70b1a9..4f84657f55c2 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