Skip to content

[clang][LoongArch] Add FreeBSD targets #119191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm of two minds about adding loongarch32 triples. It's harmless and parallels riscv, but the chances of a new 32-bit port being importing into the FreeBSD are close to zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brooksdavis Thanks!
after have reading Future of 32-bit platform support in FreeBSD , I think It's reasonable to exclude 32 bit from LoongArch support.
I also hope to hear some comments/suggestions from @emaste

Copy link
Contributor

Choose a reason for hiding this comment

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

@brooksdavis 32-bit RISC-V support was removed for FreeBSD. I just noticed this addition and think it should be removed.

case llvm::Triple::loongarch64:
break;
}
}
};
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/Driver/ToolChains/FreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions clang/test/Driver/freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Loading