diff --git a/0002-LoongArch-fix-symbol-lookup-error.patch b/0002-LoongArch-fix-symbol-lookup-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..8a4913d4f3546cdeb2a4556d1efc5ff152a098ce --- /dev/null +++ b/0002-LoongArch-fix-symbol-lookup-error.patch @@ -0,0 +1,211 @@ +diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def +index b20d12495..5245d750d 100644 +--- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.def ++++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.def +@@ -2,6 +2,8 @@ + #define LOONGARCH_FEATURE(NAME, KIND) + #endif + ++LOONGARCH_FEATURE("invalid", FK_INVALID) ++LOONGARCH_FEATURE("none", FK_NONE) + LOONGARCH_FEATURE("+64bit", FK_64BIT) + LOONGARCH_FEATURE("+f", FK_FP32) + LOONGARCH_FEATURE("+d", FK_FP64) +@@ -17,6 +19,7 @@ LOONGARCH_FEATURE("+ual", FK_UAL) + #define LOONGARCH_ARCH(NAME, KIND, FEATURES) + #endif + ++LOONGARCH_ARCH("invalid", AK_INVALID, FK_INVALID) + LOONGARCH_ARCH("loongarch64", AK_LOONGARCH64, FK_64BIT | FK_FP32 | FK_FP64 | FK_UAL) + LOONGARCH_ARCH("la464", AK_LA464, FK_64BIT | FK_FP32 | FK_FP64 | FK_LSX | FK_LASX | FK_UAL) + +diff --git a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h +index 028844187..ff325a76d 100644 +--- a/llvm/include/llvm/TargetParser/LoongArchTargetParser.h ++++ b/llvm/include/llvm/TargetParser/LoongArchTargetParser.h +@@ -23,6 +23,9 @@ class StringRef; + namespace LoongArch { + + enum FeatureKind : uint32_t { ++ FK_INVALID = 0, ++ FK_NONE = 1, ++ + // 64-bit ISA is available. + FK_64BIT = 1 << 1, + +@@ -64,14 +67,11 @@ struct ArchInfo { + uint32_t Features; + }; + +-bool isValidArchName(StringRef Arch); ++ArchKind parseArch(StringRef Arch); + bool getArchFeatures(StringRef Arch, std::vector &Features); +-bool isValidCPUName(StringRef TuneCPU); +-void fillValidCPUList(SmallVectorImpl &Values); +-StringRef getDefaultArch(bool Is64Bit); + + } // namespace LoongArch + + } // namespace llvm + +-#endif // LLVM_TARGETPARSER_LOONGARCHTARGETPARSER_H ++#endif // LLVM_SUPPORT_LOONGARCHTARGETPARSER_H +diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h +index 5ddb1d314..59513fa2f 100644 +--- a/llvm/include/llvm/TargetParser/Triple.h ++++ b/llvm/include/llvm/TargetParser/Triple.h +@@ -846,14 +846,10 @@ public: + : PointerWidth == 64; + } + +- /// Tests whether the target is 32-bit LoongArch. +- bool isLoongArch32() const { return getArch() == Triple::loongarch32; } +- +- /// Tests whether the target is 64-bit LoongArch. +- bool isLoongArch64() const { return getArch() == Triple::loongarch64; } +- + /// Tests whether the target is LoongArch (32- and 64-bit). +- bool isLoongArch() const { return isLoongArch32() || isLoongArch64(); } ++ bool isLoongArch() const { ++ return getArch() == Triple::loongarch32 || getArch() == Triple::loongarch64; ++ } + + /// Tests whether the target is MIPS 32-bit (little and big endian). + bool isMIPS32() const { +diff --git a/llvm/lib/Target/LoongArch/LoongArch.td b/llvm/lib/Target/LoongArch/LoongArch.td +index 3e9e8b251..7215cd16f 100644 +--- a/llvm/lib/Target/LoongArch/LoongArch.td ++++ b/llvm/lib/Target/LoongArch/LoongArch.td +@@ -135,11 +135,6 @@ include "LoongArchInstrInfo.td" + def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>; + def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL]>; + +-// Generic 64-bit processor with double-precision floating-point support. +-def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit, +- FeatureUAL, +- FeatureBasicD]>; +- + // Support generic for compatibility with other targets. The triple will be used + // to change to the appropriate la32/la64 version. + def : ProcessorModel<"generic", NoSchedModel, []>; +diff --git a/llvm/lib/TargetParser/LoongArchTargetParser.cpp b/llvm/lib/TargetParser/LoongArchTargetParser.cpp +index 772d24c5c..faa8c314f 100644 +--- a/llvm/lib/TargetParser/LoongArchTargetParser.cpp ++++ b/llvm/lib/TargetParser/LoongArchTargetParser.cpp +@@ -1,4 +1,4 @@ +-//===-- LoongArchTargetParser - Parser for LoongArch features --*- C++ -*-====// ++//==-- LoongArch64TargetParser - Parser for LoongArch64 features --*- C++ -*-=// + // + // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. + // See https://llvm.org/LICENSE.txt for license information. +@@ -27,11 +27,12 @@ const ArchInfo AllArchs[] = { + #include "llvm/TargetParser/LoongArchTargetParser.def" + }; + +-bool LoongArch::isValidArchName(StringRef Arch) { ++LoongArch::ArchKind LoongArch::parseArch(StringRef Arch) { + for (const auto A : AllArchs) + if (A.Name == Arch) +- return true; +- return false; ++ return A.Kind; ++ ++ return LoongArch::ArchKind::AK_INVALID; + } + + bool LoongArch::getArchFeatures(StringRef Arch, +@@ -39,22 +40,10 @@ bool LoongArch::getArchFeatures(StringRef Arch, + for (const auto A : AllArchs) { + if (A.Name == Arch) { + for (const auto F : AllFeatures) +- if ((A.Features & F.Kind) == F.Kind) ++ if ((A.Features & F.Kind) == F.Kind && F.Kind != FK_INVALID) + Features.push_back(F.Name); + return true; + } + } + return false; + } +- +-bool LoongArch::isValidCPUName(StringRef Name) { return isValidArchName(Name); } +- +-void LoongArch::fillValidCPUList(SmallVectorImpl &Values) { +- for (const auto A : AllArchs) +- Values.emplace_back(A.Name); +-} +- +-StringRef LoongArch::getDefaultArch(bool Is64Bit) { +- // TODO: use a real 32-bit arch name. +- return Is64Bit ? "loongarch64" : ""; +-} +diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +index 367a2bef2..599eeeabc 100644 +--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp ++++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +@@ -492,7 +492,7 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize, + bool IsMIPS64 = TargetTriple.isMIPS64(); + bool IsArmOrThumb = TargetTriple.isARM() || TargetTriple.isThumb(); + bool IsAArch64 = TargetTriple.getArch() == Triple::aarch64; +- bool IsLoongArch64 = TargetTriple.isLoongArch64(); ++ bool IsLoongArch64 = TargetTriple.getArch() == Triple::loongarch64; + bool IsRISCV64 = TargetTriple.getArch() == Triple::riscv64; + bool IsWindows = TargetTriple.isOSWindows(); + bool IsFuchsia = TargetTriple.isOSFuchsia(); +diff --git a/llvm/test/CodeGen/LoongArch/cpus-invalid.ll b/llvm/test/CodeGen/LoongArch/cpus-invalid.ll +deleted file mode 100644 +index b5435fb90..000000000 +--- a/llvm/test/CodeGen/LoongArch/cpus-invalid.ll ++++ /dev/null +@@ -1,7 +0,0 @@ +-; RUN: llc < %s --mtriple=loongarch64 --mattr=+64bit --mcpu=invalidcpu 2>&1 | FileCheck %s +- +-; CHECK: {{.*}} is not a recognized processor for this target +- +-define void @f() { +- ret void +-} +diff --git a/llvm/test/CodeGen/LoongArch/cpus.ll b/llvm/test/CodeGen/LoongArch/cpus.ll +deleted file mode 100644 +index 35945ae4d..000000000 +--- a/llvm/test/CodeGen/LoongArch/cpus.ll ++++ /dev/null +@@ -1,20 +0,0 @@ +-;; This tests that llc accepts all valid LoongArch CPUs. +-;; Note the 'generic' names have been tested in cpu-name-generic.ll. +- +-; RUN: llc < %s --mtriple=loongarch64 --mcpu=loongarch64 2>&1 | FileCheck %s +-; RUN: llc < %s --mtriple=loongarch64 --mcpu=la464 2>&1 | FileCheck %s +-; RUN: llc < %s --mtriple=loongarch64 2>&1 | FileCheck %s +- +-; CHECK-NOT: {{.*}} is not a recognized processor for this target +- +-define void @f() { +- ret void +-} +- +-define void @tune_cpu_loongarch64() "tune-cpu"="loongarch64" { +- ret void +-} +- +-define void @tune_cpu_la464() "tune-cpu"="la464" { +- ret void +-} +diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp +index b19699fc0..77de43a16 100644 +--- a/llvm/unittests/TargetParser/TripleTest.cpp ++++ b/llvm/unittests/TargetParser/TripleTest.cpp +@@ -1225,14 +1225,12 @@ TEST(TripleTest, BitWidthPredicates) { + EXPECT_TRUE(T.isArch32Bit()); + EXPECT_FALSE(T.isArch64Bit()); + EXPECT_TRUE(T.isLoongArch()); +- EXPECT_TRUE(T.isLoongArch32()); + + T.setArch(Triple::loongarch64); + EXPECT_FALSE(T.isArch16Bit()); + EXPECT_FALSE(T.isArch32Bit()); + EXPECT_TRUE(T.isArch64Bit()); + EXPECT_TRUE(T.isLoongArch()); +- EXPECT_TRUE(T.isLoongArch64()); + + T.setArch(Triple::dxil); + EXPECT_FALSE(T.isArch16Bit()); diff --git a/llvm.spec b/llvm.spec index d810e2f9e30bee42b602e7215da5edf275a47c66..6ba5cc9fabaea204aef6aaf2618e14690ff15bd8 100644 --- a/llvm.spec +++ b/llvm.spec @@ -1,4 +1,4 @@ -%define anolis_release 2 +%define anolis_release 3 %global toolchain clang @@ -65,6 +65,7 @@ Source4: https://github.com/llvm/llvm-project/releases/download/llvmorg-% Patch2: 0001-llvm-Add-install-targets-for-gtest.patch Patch3: 0001-backport-LoongArch-patches.patch +Patch4: 0002-LoongArch-fix-symbol-lookup-error.patch Patch201: 0201-third-party-Add-install-targets-for-gtest.patch BuildRequires: gcc gcc-c++ clang cmake ninja-build zlib-devel libffi-devel @@ -485,6 +486,10 @@ fi %endif %changelog +* Tue Oct 31 2023 Chen Li - 16.0.6-3 +- LoongArch: Fix symbol lookup error when compiling clang on aarch + and x86 + * Thu Aug 17 2023 Chen Li - 16.0.6-2 - Backport LoongArch patches from llvmorg-17.0.0-rc2