Skip to content

Commit 3b10e31

Browse files
hitmoonyushanwei
andauthored
[clang][LoongArch] Add FreeBSD targets (llvm#119191)
Add support for freebsd on loongarch Signed-off-by: xiaoqiang zhao <[email protected]> Co-authored-by: yu shan wei <[email protected]>
1 parent 7077896 commit 3b10e31

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
726726
case llvm::Triple::Linux:
727727
return std::make_unique<LinuxTargetInfo<LoongArch32TargetInfo>>(Triple,
728728
Opts);
729+
case llvm::Triple::FreeBSD:
730+
return std::make_unique<FreeBSDTargetInfo<LoongArch32TargetInfo>>(Triple,
731+
Opts);
729732
default:
730733
return std::make_unique<LoongArch32TargetInfo>(Triple, Opts);
731734
}
@@ -734,6 +737,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
734737
case llvm::Triple::Linux:
735738
return std::make_unique<LinuxTargetInfo<LoongArch64TargetInfo>>(Triple,
736739
Opts);
740+
case llvm::Triple::FreeBSD:
741+
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
742+
Opts);
737743
default:
738744
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
739745
}

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ class LLVM_LIBRARY_VISIBILITY FreeBSDTargetInfo : public OSTargetInfo<Target> {
231231
case llvm::Triple::riscv32:
232232
case llvm::Triple::riscv64:
233233
break;
234+
case llvm::Triple::loongarch32:
235+
case llvm::Triple::loongarch64:
236+
break;
234237
}
235238
}
236239
};

clang/lib/Driver/ToolChains/FreeBSD.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
213213
CmdArgs.push_back("-m");
214214
CmdArgs.push_back("elf64lriscv");
215215
break;
216+
case llvm::Triple::loongarch32:
217+
CmdArgs.push_back("-m");
218+
CmdArgs.push_back("elf32loongarch");
219+
break;
220+
case llvm::Triple::loongarch64:
221+
CmdArgs.push_back("-m");
222+
CmdArgs.push_back("elf64loongarch");
223+
break;
216224
default:
217225
break;
218226
}
@@ -223,6 +231,12 @@ void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
223231
CmdArgs.push_back("--no-relax");
224232
}
225233

234+
if (Triple.isLoongArch64()) {
235+
CmdArgs.push_back("-X");
236+
if (Args.hasArg(options::OPT_mno_relax))
237+
CmdArgs.push_back("--no-relax");
238+
}
239+
226240
if (Arg *A = Args.getLastArg(options::OPT_G)) {
227241
if (ToolChain.getTriple().isMIPS()) {
228242
StringRef v = A->getValue();

clang/test/Driver/freebsd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@
7777
// RUN: | FileCheck --check-prefix=CHECK-RV64I-LD %s
7878
// CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"
7979
//
80+
// Check that LoongArch passes the correct linker emulation.
81+
//
82+
// RUN: %clang --target=loongarch32-freebsd -### %s %s 2>&1 \
83+
// RUN: | FileCheck --check-prefix=CHECK-LA32-LD %s
84+
// CHECK-LA32-LD: ld{{.*}}" {{.*}} "-m" "elf32loongarch"
85+
// RUN: %clang --target=loongarch64-freebsd -### %s %s 2>&1 \
86+
// RUN: | FileCheck --check-prefix=CHECK-LA64-LD %s
87+
// CHECK-LA64-LD: ld{{.*}}" {{.*}} "-m" "elf64loongarch"
88+
//
89+
// Check options passed to the linker on LoongArch
90+
//
91+
// RUN: %clang --target=loongarch64-freebsd -mno-relax -### %s %s 2>&1 \
92+
// RUN: | FileCheck --check-prefix=CHECK-LA64-LD-OPTS %s
93+
// CHECK-LA64-LD-OPTS: ld{{.*}}" {{.*}} "-X" "--no-relax"
94+
//
8095
// Check that the new linker flags are passed to FreeBSD
8196
// RUN: %clang --target=x86_64-pc-freebsd10.0 -m32 %s \
8297
// RUN: --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \

0 commit comments

Comments
 (0)