Author: hitmoon
Date: 2024-12-13T10:34:53+08:00
New Revision: 3b10e31d3a4a1c660c82287d3b9f6515f37a32ca

URL: 
https://github.com/llvm/llvm-project/commit/3b10e31d3a4a1c660c82287d3b9f6515f37a32ca
DIFF: 
https://github.com/llvm/llvm-project/commit/3b10e31d3a4a1c660c82287d3b9f6515f37a32ca.diff

LOG: [clang][LoongArch] Add FreeBSD targets (#119191)

Add support for freebsd on loongarch

Signed-off-by: xiaoqiang zhao <zxq_yx_...@163.com>
Co-authored-by: yu shan wei <mp...@vip.163.com>

Added: 
    

Modified: 
    clang/lib/Basic/Targets.cpp
    clang/lib/Basic/Targets/OSTargets.h
    clang/lib/Driver/ToolChains/FreeBSD.cpp
    clang/test/Driver/freebsd.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 0021d33c45d7c9..706a391023b3a3 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -726,6 +726,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const 
llvm::Triple &Triple,
     case llvm::Triple::Linux:
         return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
                                                                         Opts);
+    case llvm::Triple::FreeBSD:
+      return std::make_unique<FreeBSDTargetInfo<LoongArch32TargetInfo>>(Triple,
+                                                                        Opts);
     default:
         return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
     }
@@ -734,6 +737,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const 
llvm::Triple &Triple,
     case llvm::Triple::Linux:
         return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
                                                                         Opts);
+    case llvm::Triple::FreeBSD:
+      return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
+                                                                        Opts);
     default:
         return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
     }

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index c0351f26e9bee6..cd9b3760ca5874 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -231,6 +231,9 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public 
OSTargetInfo<Target> {
     case llvm::Triple::riscv32:
     case llvm::Triple::riscv64:
       break;
+    case llvm::Triple::loongarch32:
+    case llvm::Triple::loongarch64:
+      break;
     }
   }
 };

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index c78f4e26a2f107..678efefb1afce8 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -213,6 +213,14 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
     CmdArgs.push_back("-m");
     CmdArgs.push_back("elf64lriscv");
     break;
+  case llvm::Triple::loongarch32:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf32loongarch");
+    break;
+  case llvm::Triple::loongarch64:
+    CmdArgs.push_back("-m");
+    CmdArgs.push_back("elf64loongarch");
+    break;
   default:
     break;
   }
@@ -223,6 +231,12 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
       CmdArgs.push_back("--no-relax");
   }
 
+  if (Triple.isLoongArch64()) {
+    CmdArgs.push_back("-X");
+    if (Args.hasArg(options::OPT_mno_relax))
+      CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
     if (ToolChain.getTriple().isMIPS()) {
       StringRef v = A->getValue();

diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 10fe155fee8744..a0787bab4feb8f 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -77,6 +77,21 @@
 // RUN:   | FileCheck --check-prefix=CHECK-RV64I-LD %s
 // CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"
 //
+// Check that LoongArch passes the correct linker emulation.
+//
+// RUN: %clang --target=loongarch32-freebsd -### %s %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LA32-LD %s
+// CHECK-LA32-LD: ld{{.*}}" {{.*}} "-m" "elf32loongarch"
+// RUN: %clang --target=loongarch64-freebsd -### %s %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD %s
+// CHECK-LA64-LD: ld{{.*}}" {{.*}} "-m" "elf64loongarch"
+//
+// Check options passed to the linker on LoongArch
+//
+// RUN: %clang --target=loongarch64-freebsd -mno-relax -### %s %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-LA64-LD-OPTS %s
+// CHECK-LA64-LD-OPTS: ld{{.*}}" {{.*}} "-X" "--no-relax"
+//
 // Check that the new linker flags are passed to FreeBSD
 // RUN: %clang --target=x86_64-pc-freebsd10.0 -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to