[clang] 62ffbe0 - [Driver] Hook up NetBSD/riscv support (#67256)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 24 13:29:50 PDT 2023
Author: Brad Smith
Date: 2023-09-24T16:29:46-04:00
New Revision: 62ffbe0dcca9f394f9dbfda160e0f0a1e96948ae
URL: https://github.com/llvm/llvm-project/commit/62ffbe0dcca9f394f9dbfda160e0f0a1e96948ae
DIFF: https://github.com/llvm/llvm-project/commit/62ffbe0dcca9f394f9dbfda160e0f0a1e96948ae.diff
LOG: [Driver] Hook up NetBSD/riscv support (#67256)
Added:
Modified:
clang/lib/Basic/Targets.cpp
clang/lib/Driver/ToolChains/NetBSD.cpp
clang/test/Driver/netbsd.c
clang/test/Driver/netbsd.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 69576dbc458d9a1..35d1d0d2c45c530 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -429,11 +429,13 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<AMDGPUTargetInfo>(Triple, Opts);
case llvm::Triple::riscv32:
- // TODO: add cases for NetBSD, RTEMS once tested.
switch (os) {
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<RISCV32TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::NetBSD:
+ return std::make_unique<NetBSDTargetInfo<RISCV32TargetInfo>>(Triple,
+ Opts);
case llvm::Triple::Linux:
return std::make_unique<LinuxTargetInfo<RISCV32TargetInfo>>(Triple, Opts);
default:
@@ -441,11 +443,13 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
}
case llvm::Triple::riscv64:
- // TODO: add cases for NetBSD, RTEMS once tested.
switch (os) {
case llvm::Triple::FreeBSD:
return std::make_unique<FreeBSDTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);
+ case llvm::Triple::NetBSD:
+ return std::make_unique<NetBSDTargetInfo<RISCV64TargetInfo>>(Triple,
+ Opts);
case llvm::Triple::OpenBSD:
return std::make_unique<OpenBSDTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 88be6ea0d5e7883..0bd15434898828a 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -216,6 +216,16 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("elf64ppc");
break;
+ case llvm::Triple::riscv32:
+ CmdArgs.push_back("-m");
+ CmdArgs.push_back("elf32lriscv");
+ break;
+
+ case llvm::Triple::riscv64:
+ CmdArgs.push_back("-m");
+ CmdArgs.push_back("elf64lriscv");
+ break;
+
case llvm::Triple::sparc:
CmdArgs.push_back("-m");
CmdArgs.push_back("elf32_sparc");
@@ -230,6 +240,9 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
break;
}
+ if (Triple.isRISCV())
+ CmdArgs.push_back("-X");
+
if (Output.isFilename()) {
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
@@ -282,6 +295,8 @@ void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
case llvm::Triple::ppc:
case llvm::Triple::ppc64:
case llvm::Triple::ppc64le:
+ case llvm::Triple::riscv32:
+ case llvm::Triple::riscv64:
case llvm::Triple::sparc:
case llvm::Triple::sparcv9:
case llvm::Triple::x86:
@@ -418,6 +433,8 @@ ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const {
case llvm::Triple::ppc:
case llvm::Triple::ppc64:
case llvm::Triple::ppc64le:
+ case llvm::Triple::riscv32:
+ case llvm::Triple::riscv64:
case llvm::Triple::sparc:
case llvm::Triple::sparcv9:
case llvm::Triple::x86:
@@ -539,7 +556,9 @@ void NetBSD::addClangTargetOptions(const ArgList &DriverArgs,
getTriple().getArch() == llvm::Triple::aarch64 ||
getTriple().getArch() == llvm::Triple::aarch64_be ||
getTriple().getArch() == llvm::Triple::arm ||
- getTriple().getArch() == llvm::Triple::armeb;
+ getTriple().getArch() == llvm::Triple::armeb ||
+ getTriple().getArch() == llvm::Triple::riscv32 ||
+ getTriple().getArch() == llvm::Triple::riscv64;
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
options::OPT_fno_use_init_array, UseInitArrayDefault))
diff --git a/clang/test/Driver/netbsd.c b/clang/test/Driver/netbsd.c
index 67c048c6e91515f..760cba4ac4e0c9f 100644
--- a/clang/test/Driver/netbsd.c
+++ b/clang/test/Driver/netbsd.c
@@ -59,6 +59,12 @@
// RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi \
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=ARM-7 %s
+// RUN: %clang --target=riscv32-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV32 %s
+// RUN: %clang --target=riscv64-unknown-netbsd \
+// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV64 %s
// RUN: %clang --target=sparc-unknown-netbsd \
// RUN: -no-integrated-as --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=SPARC %s
@@ -99,6 +105,12 @@
// RUN: %clang --target=arm-unknown-netbsd7.0.0-eabi -static \
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=S-ARM-7 %s
+// RUN: %clang --target=riscv32-unknown-netbsd7.0.0 -static \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=S-RISCV32-7 %s
+// RUN: %clang --target=riscv64-unknown-netbsd7.0.0 -static \
+// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=S-RISCV64-7 %s
// RUN: %clang --target=sparc-unknown-netbsd7.0.0 -static \
// RUN: --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=S-SPARC-7 %s
@@ -264,6 +276,22 @@
// ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
// ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+// RISCV32: "-cc1" "-triple" "riscv32-unknown-netbsd"
+// RISCV32-NOT: "-fno-use-init-array"
+// RISCV32: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// RISCV32-SAME: "-m" "elf32lriscv" "-X"
+// RISCV32-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
+// RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
+// RISCV64: "-cc1" "-triple" "riscv64-unknown-netbsd"
+// RISCV64-NOT: "-fno-use-init-array"
+// RISCV64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// RISCV64-SAME: "-m" "elf64lriscv" "-X"
+// RISCV64-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
+// RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
// SPARC: "-cc1" "-triple" "sparc-unknown-netbsd"
// SPARC-NOT: "-fno-use-init-array"
// SPARC: as{{.*}}" "-32" "-Av8" "-o"
@@ -361,6 +389,20 @@
// S-ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
// S-ARM-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+// S-RISCV32-7: "-cc1" "-triple" "riscv32-unknown-netbsd7.0.0"
+// S-RISCV32-7: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
+// S-RISCV32-7-SAME: "-m" "elf32lriscv" "-X"
+// S-RISCV32-7-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// S-RISCV32-7-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
+// S-RISCV32-7-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
+// S-RISCV64-7: "-cc1" "-triple" "riscv64-unknown-netbsd7.0.0"
+// S-RISCV64-7: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
+// S-RISCV64-7-SAME: "-m" "elf64lriscv" "-X"
+// S-RISCV64-7-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// S-RISCV64-7-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc"
+// S-RISCV64-7-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
// S-SPARC-7: "-cc1" "-triple" "sparc-unknown-netbsd7.0.0"
// S-SPARC-7: "-fno-use-init-array"
// S-SPARC-7: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
diff --git a/clang/test/Driver/netbsd.cpp b/clang/test/Driver/netbsd.cpp
index ab24209b4577aa2..60640510a1bf560 100644
--- a/clang/test/Driver/netbsd.cpp
+++ b/clang/test/Driver/netbsd.cpp
@@ -19,6 +19,12 @@
// RUN: %clangxx --target=aarch64_be-unknown-netbsd7.0.0 \
// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=AARCH64_BE-7 %s
+// RUN: %clangxx --target=riscv32-unknown-netbsd \
+// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV32 %s
+// RUN: %clangxx --target=riscv64-unknown-netbsd \
+// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=RISCV64 %s
// RUN: %clangxx --target=sparc-unknown-netbsd \
// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=SPARC %s
@@ -59,6 +65,12 @@
// RUN: %clangxx --target=aarch64_be-unknown-netbsd7.0.0 -static \
// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=S-AARCH64_BE-7 %s
+// RUN: %clangxx --target=riscv32-unknown-netbsd -static \
+// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=S-RISCV32 %s
+// RUN: %clangxx --target=riscv64-unknown-netbsd -static \
+// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=S-RISCV64 %s
// RUN: %clangxx --target=sparc-unknown-netbsd -static \
// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=S-SPARC %s
@@ -124,6 +136,22 @@
// AARCH64_BE-7: "-lm" "-lc"
// AARCH64_BE-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+// RISCV32: "-cc1" "-triple" "riscv32-unknown-netbsd"
+// RISCV32: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// RISCV32-SAME: "-X"
+// RISCV32-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++"
+// RISCV32-SAME: "-lm" "-lc"
+// RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
+// RISCV64: "-cc1" "-triple" "riscv64-unknown-netbsd"
+// RISCV64: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
+// RISCV64-SAME: "-X"
+// RISCV64-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++"
+// RISCV64-SAME: "-lm" "-lc"
+// RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
// SPARC: "-cc1" "-triple" "sparc-unknown-netbsd"
// SPARC: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
// SPARC: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o"
@@ -214,6 +242,22 @@
// S-AARCH64_BE-7: "-lm" "-lc"
// S-AARCH64_BE-7: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+// S-RISCV32: "-cc1" "-triple" "riscv32-unknown-netbsd"
+// S-RISCV32: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
+// S-RISCV32-SAME: "-X"
+// S-RISCV32-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// S-RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++"
+// S-RISCV32-SAME: "-lm" "-lc"
+// S-RISCV32-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
+// S-RISCV64: "-cc1" "-triple" "riscv64-unknown-netbsd"
+// S-RISCV64: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
+// S-RISCV64-SAME: "-X"
+// S-RISCV64-SAME: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o" "{{.*}}/usr/lib{{/|\\\\}}crti.o"
+// S-RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtbegin.o" "{{.*}}.o" "-lc++"
+// S-RISCV64-SAME: "-lm" "-lc"
+// S-RISCV64-SAME: "{{.*}}/usr/lib{{/|\\\\}}crtend.o" "{{.*}}/usr/lib{{/|\\\\}}crtn.o"
+
// S-SPARC: "-cc1" "-triple" "sparc-unknown-netbsd"
// S-SPARC: ld{{.*}}" "--eh-frame-hdr" "-Bstatic"
// S-SPARC: "-o" "a.out" "{{.*}}/usr/lib{{/|\\\\}}crt0.o"
More information about the cfe-commits
mailing list