Skip to content

Commit cc2b09b

Browse files
authored
[Clang][LoongArch] Generate _mcount instead of mcount (#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.
1 parent c5624dc commit cc2b09b

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

clang/lib/Basic/Targets/LoongArch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
3636
LongDoubleWidth = 128;
3737
LongDoubleAlign = 128;
3838
LongDoubleFormat = &llvm::APFloat::IEEEquad();
39+
MCountName = "_mcount";
3940
SuitableAlign = 128;
4041
WCharType = SignedInt;
4142
WIntType = UnsignedInt;

clang/test/CodeGen/mcount.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// RUN: %clang_cc1 -pg -triple x86_64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
88
// RUN: %clang_cc1 -pg -triple arm-netbsd-eabi -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
99
// RUN: %clang_cc1 -pg -triple aarch64-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
10+
// RUN: %clang_cc1 -pg -triple loongarch32 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
11+
// RUN: %clang_cc1 -pg -triple loongarch64 -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
1012
// RUN: %clang_cc1 -pg -triple mips-netbsd -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-DOUBLE-PREFIXED,NO-MCOUNT1 %s
1113
// RUN: %clang_cc1 -pg -triple mips-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s
1214
// RUN: %clang_cc1 -pg -triple mipsel-unknown-gnu-linux -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK-PREFIXED,NO-MCOUNT1 %s

0 commit comments

Comments
 (0)