[clang] [Driver] Handle mips*-*-none-elf triples (PR #196322)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 11 22:35:16 PDT 2026
https://github.com/mojyack updated https://github.com/llvm/llvm-project/pull/196322
>From ecec8f90efd68f5c746096eb353d82425673e176 Mon Sep 17 00:00:00 2001
From: mojyack <mojyack at gmail.com>
Date: Thu, 7 May 2026 22:54:07 +0900
Subject: [PATCH] [Driver] Mark mips*-*-none-elf triples as baremetal
Recognize MIPS bare-metal triples (mips{,el,64,64el}-*-none-elf) in the
BareMetal toolchain so clang invokes ld.lld directly instead of
delegating to $target-gcc.
---
clang/lib/Driver/ToolChains/BareMetal.cpp | 9 ++++-
clang/test/Driver/mips-toolchain.c | 40 +++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Driver/mips-toolchain.c
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 0a8e5d7f5b74a..d40e80bd944a9 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -55,6 +55,12 @@ static bool isX86BareMetal(const llvm::Triple &Triple) {
Triple.getEnvironmentName() == "elf";
}
+/// Is the triple mips{,el,64,64el}-*-none-elf?
+static bool isMIPSBareMetal(const llvm::Triple &Triple) {
+ return Triple.isMIPS() && Triple.getOS() == llvm::Triple::UnknownOS &&
+ Triple.getEnvironmentName() == "elf";
+}
+
static bool findRISCVMultilibs(const Driver &D,
const llvm::Triple &TargetTriple,
const ArgList &Args, DetectedMultilibs &Result) {
@@ -281,7 +287,8 @@ void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
bool BareMetal::handlesTarget(const llvm::Triple &Triple) {
return arm::isARMEABIBareMetal(Triple) ||
aarch64::isAArch64BareMetal(Triple) || isRISCVBareMetal(Triple) ||
- isPPCBareMetal(Triple) || isX86BareMetal(Triple);
+ isPPCBareMetal(Triple) || isX86BareMetal(Triple) ||
+ isMIPSBareMetal(Triple);
}
Tool *BareMetal::buildLinker() const {
diff --git a/clang/test/Driver/mips-toolchain.c b/clang/test/Driver/mips-toolchain.c
new file mode 100644
index 0000000000000..fc85f79c098a5
--- /dev/null
+++ b/clang/test/Driver/mips-toolchain.c
@@ -0,0 +1,40 @@
+// UNSUPPORTED: system-windows
+
+// Verify that mips*-*-none-elf triples are handled by the BareMetal toolchain,
+// i.e. clang drives ld.lld directly with the correct ELF emulation instead of
+// delegating to a $target-gcc.
+
+// RUN: %clang -### %s -fuse-ld=lld -B%S/Inputs/lld \
+// RUN: --target=mips-none-elf --sysroot= 2>&1 \
+// RUN: | FileCheck -check-prefix=MIPS-BAREMETAL %s
+// MIPS-BAREMETAL: "-cc1" "-triple" "mips-unknown-none-elf"
+// MIPS-BAREMETAL: "{{.*}}/Inputs/lld/ld.lld"
+// MIPS-BAREMETAL: "-Bstatic" "-m" "elf32btsmip"
+
+// RUN: %clang -### %s -fuse-ld=lld -B%S/Inputs/lld \
+// RUN: --target=mipsel-none-elf --sysroot= 2>&1 \
+// RUN: | FileCheck -check-prefix=MIPSEL-BAREMETAL %s
+// MIPSEL-BAREMETAL: "-cc1" "-triple" "mipsel-unknown-none-elf"
+// MIPSEL-BAREMETAL: "{{.*}}/Inputs/lld/ld.lld"
+// MIPSEL-BAREMETAL: "-Bstatic" "-m" "elf32ltsmip"
+
+// RUN: %clang -### %s -fuse-ld=lld -B%S/Inputs/lld \
+// RUN: --target=mips64-none-elf --sysroot= 2>&1 \
+// RUN: | FileCheck -check-prefix=MIPS64-BAREMETAL %s
+// MIPS64-BAREMETAL: "-cc1" "-triple" "mips64-unknown-none-elf"
+// MIPS64-BAREMETAL: "{{.*}}/Inputs/lld/ld.lld"
+// MIPS64-BAREMETAL: "-Bstatic" "-m" "elf64btsmip"
+
+// RUN: %clang -### %s -fuse-ld=lld -B%S/Inputs/lld \
+// RUN: --target=mips64el-none-elf --sysroot= 2>&1 \
+// RUN: | FileCheck -check-prefix=MIPS64EL-BAREMETAL %s
+// MIPS64EL-BAREMETAL: "-cc1" "-triple" "mips64el-unknown-none-elf"
+// MIPS64EL-BAREMETAL: "{{.*}}/Inputs/lld/ld.lld"
+// MIPS64EL-BAREMETAL: "-Bstatic" "-m" "elf64ltsmip"
+
+// RUN: %clang -### %s -fuse-ld=lld -B%S/Inputs/lld \
+// RUN: --target=mips64-none-elf -mabi=n32 --sysroot= 2>&1 \
+// RUN: | FileCheck -check-prefix=MIPS64-N32-BAREMETAL %s
+// MIPS64-N32-BAREMETAL: "-cc1" "-triple" "mips64-unknown-none-elf"
+// MIPS64-N32-BAREMETAL: "{{.*}}/Inputs/lld/ld.lld"
+// MIPS64-N32-BAREMETAL: "-Bstatic" "-m" "elf32btsmipn32"
More information about the cfe-commits
mailing list