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 @@ -497,6 +497,7 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public OSTargetInfo<Target> {
this->MCountName = "_mcount";
break;
case llvm::Triple::riscv64:
case llvm::Triple::loongarch64:
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
6 changes: 6 additions & 0 deletions clang/lib/Driver/ToolChains/OpenBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ void openbsd::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");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

You can merge this check with the RISC-V check above this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also there is a space you added.

assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
if (Output.isFilename()) {
CmdArgs.push_back("-o");
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Driver/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
// CHECK-MIPS64-CPU: "-target-cpu" "mips3"
// CHECK-MIPS64EL-CPU: "-target-cpu" "mips3"

// Check that LoongArch passes the correct linker emulation.
//
// RUN: %clang --target=loongarch64-unknown-openbsd -### %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-unknown-openbsd -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 OpenBSD
// RUN: %clang --target=i686-pc-openbsd -r -### %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-LD-R %s
Expand Down