[clang] [Clang][LoongArch] Generate _mcount instead of mcount (PR #65657)

Nathan Chancellor via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 12:07:09 PDT 2023


https://github.com/nathanchance created https://github.com/llvm/llvm-project/pull/65657:

When building the LoongArch Linux kernel without `CONFIG_DYNAMIC_FTRACE`, the build fails to link because the mcount symbol is `mcount`, not `_mcount` like GCC generates and the kernel expects:

```
ld.lld: error: undefined symbol: mcount
>>> referenced by version.c
>>>               init/version.o:(early_hostname) in archive vmlinux.a
>>> referenced by do_mounts.c
>>>               init/do_mounts.o:(rootfs_init_fs_context) in archive vmlinux.a
>>> referenced by main.c
>>>               init/main.o:(__traceiter_initcall_level) in archive vmlinux.a
>>> referenced 97011 more times
>>> did you mean: _mcount
>>> defined in: vmlinux.a(arch/loongarch/kernel/mcount.o)
```

Set `MCountName` in `LoongArchTargetInfo` to `_mcount`, which resolves the build failure.


>From a359527254c6b6be9f988a4fc65a7b6d307f4514 Mon Sep 17 00:00:00 2001
From: Nathan Chancellor <nathan at kernel.org>
Date: Thu, 7 Sep 2023 11:59:05 -0700
Subject: [PATCH] [Clang][LoongArch] Generate _mcount instead of mcount

When building the LoongArch Linux kernel without CONFIG_DYNAMIC_FTRACE,
the build fails to link because the mcount symbol is "mcount", not
"_mcount" like GCC generates and the kernel expects:

  ld.lld: error: undefined symbol: mcount
  >>> referenced by version.c
  >>>               init/version.o:(early_hostname) in archive vmlinux.a
  >>> referenced by do_mounts.c
  >>>               init/do_mounts.o:(rootfs_init_fs_context) in archive vmlinux.a
  >>> referenced by main.c
  >>>               init/main.o:(__traceiter_initcall_level) in archive vmlinux.a
  >>> referenced 97011 more times
  >>> did you mean: _mcount
  >>> defined in: vmlinux.a(arch/loongarch/kernel/mcount.o)

Set MCountName in LoongArchTargetInfo to "_mcount", which resolves the build
failure.
---
 clang/lib/Basic/Targets/LoongArch.h | 1 +
 clang/test/CodeGen/mcount.c         | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/clang/lib/Basic/Targets/LoongArch.h b/clang/lib/Basic/Targets/LoongArch.h
index 34143f462a24722..ba7fb78ab94cd23 100644
--- a/clang/lib/Basic/Targets/LoongArch.h
+++ b/clang/lib/Basic/Targets/LoongArch.h
@@ -36,6 +36,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
     LongDoubleWidth = 128;
     LongDoubleAlign = 128;
     LongDoubleFormat = &llvm::APFloat::IEEEquad();
+    MCountName = "_mcount";
     SuitableAlign = 128;
     WCharType = SignedInt;
     WIntType = UnsignedInt;
diff --git a/clang/test/CodeGen/mcount.c b/clang/test/CodeGen/mcount.c
index 8f994ab4e75443a..bdd609c1dfc5826 100644
--- a/clang/test/CodeGen/mcount.c
+++ b/clang/test/CodeGen/mcount.c
@@ -7,6 +7,8 @@
 // RUN: %clang_cc1 -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple loongarch32 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
+// RUN: %clang_cc1 -pg -triple loongarch64 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mips-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
 // RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s



More information about the cfe-commits mailing list