Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3795055pxf; Mon, 29 Mar 2021 11:36:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlD4WGWHwbfuPq2bosjqOidoU447UkhbHBm7f2J6eKs3YL1ELYuoDso1vieu7XyYG8L15J X-Received: by 2002:a17:906:1b42:: with SMTP id p2mr29729308ejg.236.1617042981926; Mon, 29 Mar 2021 11:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617042981; cv=none; d=google.com; s=arc-20160816; b=ZJOantVG3XJ4g0wLpWVp9/enL2Od8mCQVs3Byt1iA0qQekrfkwgrV6k+alvgSR3jGH nGXe2M7YgeFMD3a0N39pcy76/zKoDmpSwBNbPnHkhHjANFrUu9rJSonYWDDiYMchOBy/ RPkVqStIKOOw7frctUyx5oh5CiinEain836amL+m/wxw174/UPXt/2g6quc+k2+At/jc 7xMEZqNClfcyQ4J0sviOdymfNdMENhXyhmY1H+pFMKbajWHwvYOPPzbEYnJfqpLPRgA+ vAM92zUB5J+/7lzTB1Abke6VQ+3bVv/o7j05QmJYEFUInPzb6iTaCBg1Uue1bGL6rZb6 Htfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=yeNB5sEY4cPt05lVN+HkG1LRzxIjnMB5Dy/N7XWvZCE=; b=FyqGzS+h2K1idaySlxLiSyjxC08+AxUb9lh8m8t29nuEOzLds4wO9rYKNNKiD1jFuW N8S4cwC4GwOUzMgUSbXQ/FeyPtPB3NhbkrKaryIc6niGh+jcRXnqeSC8g5DWIxtAmor2 wJoRoNBo0TorjX3127TcgM/TFkyg5s1WfyMk1OR5CaIVsWIjBXIjvc37CiV7zzRvbK4h 1F1IKIrpodVkKOyuCbu1g8FERXXcDXoXLY4FUxMFEdgFPfMK+AzlWxcKavY3eDmxdjIO 52svSfXg13R9ntUBrd5buY+hxy0KyWg3k9WNZAU5UtMZsw+unN5fpKLQ6FAexo1ML2SY mWFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VGhHMfmT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si13750591edx.470.2021.03.29.11.35.59; Mon, 29 Mar 2021 11:36:21 -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=@google.com header.s=20161025 header.b=VGhHMfmT; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229711AbhC2Scx (ORCPT + 99 others); Mon, 29 Mar 2021 14:32:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbhC2Sc0 (ORCPT ); Mon, 29 Mar 2021 14:32:26 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D60A1C061756 for ; Mon, 29 Mar 2021 11:32:24 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id b83so19878050lfd.11 for ; Mon, 29 Mar 2021 11:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yeNB5sEY4cPt05lVN+HkG1LRzxIjnMB5Dy/N7XWvZCE=; b=VGhHMfmTPR07v1DfjHVVtzyLQnebdGInigQbMPBfwaYWt7mDv7tCcmrMKvooZ7qfPg 8sBmbelC6srradbru+Tn3QaZTcn1TPK3Za/wdwVFmyE3spGat6Ch/6BZLGj+leAqTLQ2 yFMaWb5ErXa78ZuA9OGsHv2AUuqQMT4aH/j+9wKm7pt3E3xJo7NkTSEB1tF4ITo9s1+7 g/GUR82HiGb+F480CL/zjgxBdmw10RnaycBZLGKoewnCjx/dND6HC2IKDkLIDOeNdE09 WeHsHDWAbIC/O8KeG8BI2alXNkfkn+31/Qh1a/tjD5BUPgC2OpWFA4x9dj2iz5Xo7J0B XlQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yeNB5sEY4cPt05lVN+HkG1LRzxIjnMB5Dy/N7XWvZCE=; b=K/HOOhbTH556SmZKyXGWVQIETAMOJtqFiuhrE7MJWGneMlWMFWCXagSB9n8a8vU6f8 OQp6Njjc8k5gYFXeAZk5nlejmg3DtvOyfAJNZK9ualTlhZv2Lf/LU30rG44+4IN9iBB1 KoduDjpTN7vD7Ei6IE5mvPRq4XSOtYaH7BzeMts5Zr+qfpqLUcrU/kyBpq8YoyLkps5Z W1C8hyWt/IWA1xjdF/2liaeWUBdjWyEJgCJibu4PKbpusODDofJlLXN+bUrbim1NoOtr jAHmAA7eN2Zm83kcigJDQOfAAeaI9aC5+i+8e6GmK1E6IsAurYq3XWkDobcyeqFOo51U zmPA== X-Gm-Message-State: AOAM530cxOtlxMDw1ZtOngfgpuMjplOBzThU+Iz7AGUCY3S/pKT8k3PU s8wBRCJWuuimvGDKCXXf2ie+T2Nu8P9qpKMfXpGoJw== X-Received: by 2002:a19:5055:: with SMTP id z21mr17019928lfj.297.1617042743134; Mon, 29 Mar 2021 11:32:23 -0700 (PDT) MIME-Version: 1.0 References: <20210325223807.2423265-1-nathan@kernel.org> <20210325223807.2423265-3-nathan@kernel.org> In-Reply-To: <20210325223807.2423265-3-nathan@kernel.org> From: Nick Desaulniers Date: Mon, 29 Mar 2021 11:32:12 -0700 Message-ID: Subject: Re: [PATCH 2/3] riscv: Workaround mcount name prior to clang-13 To: Nathan Chancellor Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, LKML , clang-built-linux , "# 3.4.x" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 3:38 PM Nathan Chancellor wrote: > > 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. > > Cc: stable@vger.kernel.org > Link: https://github.com/ClangBuiltLinux/linux/issues/1331 > Signed-off-by: Nathan Chancellor Thanks for keeping this alive on clang-10, and resolving it for future releases! Reviewed-by: Nick Desaulniers > --- > 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 845002cc2e57..04dad3380041 100644 > --- a/arch/riscv/include/asm/ftrace.h > +++ b/arch/riscv/include/asm/ftrace.h > @@ -13,9 +13,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; > @@ -36,7 +46,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 a36df04cfa09..7b83a1aaec98 100755 > --- a/scripts/recordmcount.pl > +++ b/scripts/recordmcount.pl > @@ -392,7 +392,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.31.0 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20210325223807.2423265-3-nathan%40kernel.org. -- Thanks, ~Nick Desaulniers