-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[clang][LoongArch] Add FreeBSD targets #119191
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: None (hitmoon) ChangesAdd support for freebsd on loongarch Full diff: https://github.com/llvm/llvm-project/pull/119191.diff 4 Files Affected:
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 0021d33c45d7c9..98d151cfe4312f 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 75f53e96ce28f6..a39d8526e958f3 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 3d744bc087f467..be44fc4fe1a84d 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..c99beade607343 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -77,6 +77,15 @@
// 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-LOONG32-LD %s
+// CHECK-LOONG32-LD: ld{{.*}}" {{.*}} "-m" "elf32loongarch"
+// RUN: %clang --target=loongarch64-freebsd -### %s %s 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-LOONG64-LD %s
+// CHECK-LOONG64-LD: ld{{.*}}" {{.*}} "-m" "elf64loongarch"
+//
// 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 \
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can FreeBSD be built with this PR?
✅ With the latest revision this PR passed the C/C++ code formatter. |
Yes, tested by building kernel-toolchain |
1f33d76
to
975aed8
Compare
LGTM from the LoongArch side. It would be better a FreeBSD expert could have a look. But if there is no obvious objections I'd like to merge and mention it in LLVM20's release notes. Thanks! @hitmoon Looking forward to hear more news about the FreeBSD-LoongArch porting progress. |
@SixWeining Thanks for the review ! |
Also a |
Not only clang, all of FreeBSD on LoongArch |
Co-authored-by: yu shan wei <[email protected]> Signed-off-by: xiaoqiang zhao <[email protected]>
975aed8
to
e59a6e3
Compare
clang tag added |
It's not about what can get built after the change, but what part of LLVM project this change applies to, which is Clang. Look at the diff -- all touched files reside in |
@@ -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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any experience with LoongArch, but this diff looks fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@hitmoon Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/11277 Here is the relevant piece of the build log for the reference
|
Add support for freebsd on loongarch