Skip to content
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
case llvm::Triple::OpenBSD:
return std::make_unique<OpenBSDTargetInfo<LoongArch64TargetInfo>>(Triple,
Opts);
default:
return std::make_unique<LoongArch64TargetInfo>(Triple, Opts);
}
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
case llvm::Triple::sparcv9:
this->MCountName = "_mcount";
break;
case llvm::Triple::loongarch64:
case llvm::Triple::riscv64:
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also make sure this is sorted, loongarch64 before riscv64.

}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/OpenBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (Nopie || Profiling)
CmdArgs.push_back("-nopie");

if (Triple.isRISCV64()) {
if (Triple.isLoongArch64() || Triple.isRISCV64()) {
CmdArgs.push_back("-X");
if (Args.hasArg(options::OPT_mno_relax))
CmdArgs.push_back("--no-relax");
Expand Down
5 changes: 4 additions & 1 deletion clang/test/Driver/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@
// UNWIND-TABLES: "-funwind-tables=2"
// NO-UNWIND-TABLES-NOT: "-funwind-tables=2"

// Check that the -X and --no-relax flags are passed to the linker on riscv64
// Check that the -X and --no-relax flags are passed to the linker
// RUN: %clang --target=loongarch64-unknown-openbsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck --check-prefix=LA64-FLAGS %s
// RUN: %clang --target=riscv64-unknown-openbsd -mno-relax -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
// LA64-FLAGS: "-X" "--no-relax"
// RISCV64-FLAGS: "-X" "--no-relax"

// Check passing LTO flags to the linker
Expand Down