[clang] [libunwind] [llvm] Support for new target `wasm32-linux-muslwali` (PR #162581)
Arjun Ramesh via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 8 18:58:06 PDT 2025
https://github.com/arjunr2 created https://github.com/llvm/llvm-project/pull/162581
This new PR is just #156087 reflecting the changes to the naming of the [WALI](https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html) target as per its corresponding [RFC](https://discourse.llvm.org/t/rfc-new-wasm-linux-target-support/88203)
All added tests have been updated to reflect the same as well.
>From 467006e41c06211befcc00c8ea15432c37979fbf Mon Sep 17 00:00:00 2001
From: Arjun Ramesh <arjunr2 at andrew.cmu.edu>
Date: Sat, 30 Aug 2025 01:01:02 -0400
Subject: [PATCH] Support for new target `wasm32-linux-muslwali` in
clang/libunwind
---
clang/lib/Basic/Targets.cpp | 30 +++++++++++++------------
clang/lib/Basic/Targets/OSTargets.h | 17 ++++++++++++++
clang/lib/Basic/Targets/WebAssembly.h | 21 ++++++++++++-----
clang/lib/Driver/Driver.cpp | 2 ++
clang/test/Driver/wasm-toolchain.c | 7 ++++++
clang/test/Driver/wasm-toolchain.cpp | 25 +++++++++++++++++++++
libunwind/src/UnwindRegistersRestore.S | 7 ++++--
libunwind/src/UnwindRegistersSave.S | 8 +++++--
llvm/include/llvm/TargetParser/Triple.h | 8 +++++++
llvm/lib/TargetParser/Triple.cpp | 1 +
10 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index d9aafc6c75d3b..3afa04c812749 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -453,8 +453,7 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
return std::make_unique<FuchsiaTargetInfo<RISCV64TargetInfo>>(Triple,
Opts);
case llvm::Triple::Haiku:
- return std::make_unique<HaikuTargetInfo<RISCV64TargetInfo>>(Triple,
- Opts);
+ return std::make_unique<HaikuTargetInfo<RISCV64TargetInfo>>(Triple, Opts);
case llvm::Triple::Linux:
switch (Triple.getEnvironment()) {
default:
@@ -698,17 +697,21 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
!Triple.isOSBinFormatWasm())
return nullptr;
switch (os) {
- case llvm::Triple::WASI:
+ case llvm::Triple::WASI:
return std::make_unique<WASITargetInfo<WebAssembly32TargetInfo>>(Triple,
Opts);
- case llvm::Triple::Emscripten:
+ case llvm::Triple::Emscripten:
return std::make_unique<EmscriptenTargetInfo<WebAssembly32TargetInfo>>(
Triple, Opts);
- case llvm::Triple::UnknownOS:
+
+ case llvm::Triple::Linux:
+ return std::make_unique<WALITargetInfo<WebAssembly32TargetInfo>>(Triple,
+ Opts);
+ case llvm::Triple::UnknownOS:
return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>>(
Triple, Opts);
- default:
- return nullptr;
+ default:
+ return nullptr;
}
case llvm::Triple::wasm64:
if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
@@ -716,17 +719,17 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
!Triple.isOSBinFormatWasm())
return nullptr;
switch (os) {
- case llvm::Triple::WASI:
+ case llvm::Triple::WASI:
return std::make_unique<WASITargetInfo<WebAssembly64TargetInfo>>(Triple,
Opts);
- case llvm::Triple::Emscripten:
+ case llvm::Triple::Emscripten:
return std::make_unique<EmscriptenTargetInfo<WebAssembly64TargetInfo>>(
Triple, Opts);
- case llvm::Triple::UnknownOS:
+ case llvm::Triple::UnknownOS:
return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>>(
Triple, Opts);
- default:
- return nullptr;
+ default:
+ return nullptr;
}
case llvm::Triple::dxil:
@@ -806,8 +809,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
}
// Check the TuneCPU name if specified.
- if (!Opts->TuneCPU.empty() &&
- !Target->isValidTuneCPUName(Opts->TuneCPU)) {
+ if (!Opts->TuneCPU.empty() && !Target->isValidTuneCPUName(Opts->TuneCPU)) {
Diags.Report(diag::err_target_unknown_cpu) << Opts->TuneCPU;
SmallVector<StringRef, 32> ValidList;
Target->fillValidTuneCPUList(ValidList);
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 6c49a09ab27f5..bd6ffcf3173ab 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -948,6 +948,23 @@ class LLVM_LIBRARY_VISIBILITY WASITargetInfo
using WebAssemblyOSTargetInfo<Target>::WebAssemblyOSTargetInfo;
};
+// WALI target
+template <typename Target>
+class LLVM_LIBRARY_VISIBILITY WALITargetInfo
+ : public WebAssemblyOSTargetInfo<Target> {
+ void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+ MacroBuilder &Builder) const final {
+ WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
+ // Linux defines; list based off of gcc output
+ DefineStd(Builder, "unix", Opts);
+ DefineStd(Builder, "linux", Opts);
+ Builder.defineMacro("__wali__");
+ }
+
+public:
+ using WebAssemblyOSTargetInfo<Target>::WebAssemblyOSTargetInfo;
+};
+
// Emscripten target
template <typename Target>
class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
diff --git a/clang/lib/Basic/Targets/WebAssembly.h b/clang/lib/Basic/Targets/WebAssembly.h
index eba74229dfc14..4de6ce6bb5a21 100644
--- a/clang/lib/Basic/Targets/WebAssembly.h
+++ b/clang/lib/Basic/Targets/WebAssembly.h
@@ -88,12 +88,23 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
LongDoubleWidth = LongDoubleAlign = 128;
LongDoubleFormat = &llvm::APFloat::IEEEquad();
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
- // size_t being unsigned long for both wasm32 and wasm64 makes mangled names
- // more consistent between the two.
- SizeType = UnsignedLong;
- PtrDiffType = SignedLong;
- IntPtrType = SignedLong;
HasUnalignedAccess = true;
+ if (T.isWALI()) {
+ // The WALI ABI is documented here:
+ // https://doc.rust-lang.org/rustc/platform-support/wasm32-wali-linux.html
+ // Currently, this ABI only applies to wasm32 targets and notably requires
+ // 64-bit longs
+ LongAlign = LongWidth = 64;
+ SizeType = UnsignedInt;
+ PtrDiffType = SignedInt;
+ IntPtrType = SignedInt;
+ } else {
+ // size_t being unsigned long for both wasm32 and wasm64 makes mangled
+ // names more consistent between the two.
+ SizeType = UnsignedLong;
+ PtrDiffType = SignedLong;
+ IntPtrType = SignedLong;
+ }
}
StringRef getABI() const override;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 85a1335785542..40ea513e85427 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6836,6 +6836,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
TC = std::make_unique<toolchains::VEToolChain>(*this, Target, Args);
else if (Target.isOHOSFamily())
TC = std::make_unique<toolchains::OHOS>(*this, Target, Args);
+ else if (Target.isWALI())
+ TC = std::make_unique<toolchains::WebAssembly>(*this, Target, Args);
else
TC = std::make_unique<toolchains::Linux>(*this, Target, Args);
break;
diff --git a/clang/test/Driver/wasm-toolchain.c b/clang/test/Driver/wasm-toolchain.c
index 91803fe6bc1f2..29a94aeec77a9 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -296,3 +296,10 @@
// RUN: | FileCheck -check-prefix=LINK_WASIP2_USE_WASMLD %s
// LINK_WASIP2_USE_WASMLD: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
// LINK_WASIP2_USE_WASMLD: wasm-ld{{.*}}" "-m" "wasm32" {{.*}} "[[temp]]" {{.*}}
+
+// Basic `wasm32-linux-muslwali` compile-link test.
+
+// RUN: %clang -### --target=wasm32-linux-muslwali --sysroot=/foo %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LINK_WALI_BASIC %s
+// LINK_WALI_BASIC: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_WALI_BASIC: wasm-ld{{.*}}" "-L/foo/lib/wasm32-linux-muslwali" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins.a" "-o" "a.out"
diff --git a/clang/test/Driver/wasm-toolchain.cpp b/clang/test/Driver/wasm-toolchain.cpp
index ba1c55b33edca..d7ff76cedfd10 100644
--- a/clang/test/Driver/wasm-toolchain.cpp
+++ b/clang/test/Driver/wasm-toolchain.cpp
@@ -86,3 +86,28 @@
// COMPILE_STDCXX: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
// COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-wasi"
// COMPILE_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include"
+
+// RUN: %clangxx -### --target=wasm32-linux-muslwali --stdlib=libc++ %s 2>&1 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libcxx_tree/usr \
+// RUN: | FileCheck -check-prefix=COMPILE_WALI %s
+// COMPILE_WALI: "-cc1"
+// COMPILE_WALI: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
+// COMPILE_WALI: "-isysroot" "[[SYSROOT:[^"]+]]"
+// COMPILE_WALI: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-linux-muslwali/c++/v1"
+// COMPILE_WALI: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/v1"
+// COMPILE_WALI: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// COMPILE_WALI: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-linux-muslwali"
+// COMPILE_WALI: "-internal-isystem" "[[SYSROOT:[^"]+]]/include"
+
+// RUN: %clangxx -### --target=wasm32-linux-muslwali --stdlib=libstdc++ %s 2>&1 \
+// RUN: --sysroot=%S/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr \
+// RUN: | FileCheck -check-prefix=COMPILE_WALI_STDCXX %s
+// COMPILE_WALI_STDCXX: "-cc1"
+// COMPILE_WALI_STDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
+// COMPILE_WALI_STDCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8/wasm32-linux-muslwali"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/c++/4.8/backward"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|\\\\)}}include"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include/wasm32-linux-muslwali"
+// COMPILE_WALI_STDCXX: "-internal-isystem" "[[SYSROOT:[^"]+]]/include"
diff --git a/libunwind/src/UnwindRegistersRestore.S b/libunwind/src/UnwindRegistersRestore.S
index 1bcd205be260d..1077d80bc90de 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#if !defined(__wasm__)
+
#include "assembly.h"
#define FROM_0_TO_15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
@@ -20,7 +22,7 @@
.text
#endif
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__)
#if defined(__i386__)
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
@@ -1253,7 +1255,8 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
#endif
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
NO_EXEC_STACK_DIRECTIVE
+#endif /* !defined(__wasm__) */
diff --git a/libunwind/src/UnwindRegistersSave.S b/libunwind/src/UnwindRegistersSave.S
index 5139a551ad245..8bf99ebd942fa 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#if !defined(__wasm__)
+
#include "assembly.h"
#define FROM_0_TO_15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
@@ -20,7 +22,7 @@
.text
#endif
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__)
#if defined(__i386__)
@@ -1232,6 +1234,8 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
WEAK_ALIAS(__unw_getcontext, unw_getcontext)
#endif
-#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
+#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
NO_EXEC_STACK_DIRECTIVE
+
+#endif /* !defined(__wasm__) */
diff --git a/llvm/include/llvm/TargetParser/Triple.h b/llvm/include/llvm/TargetParser/Triple.h
index ed2e01ccb1e26..110c86bd09051 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -277,6 +277,7 @@ class Triple {
MuslF32,
MuslSF,
MuslX32,
+ MuslWALI,
LLVM,
MSVC,
@@ -798,6 +799,12 @@ class Triple {
return getObjectFormat() == Triple::DXContainer;
}
+ /// Tests whether the target uses WALI Wasm
+ bool isWALI() const {
+ return getArch() == Triple::wasm32 &&
+ isOSLinux() && getEnvironment() == Triple::MuslWALI;
+ }
+
/// Tests whether the target is the PS4 platform.
bool isPS4() const {
return getArch() == Triple::x86_64 &&
@@ -840,6 +847,7 @@ class Triple {
getEnvironment() == Triple::MuslF32 ||
getEnvironment() == Triple::MuslSF ||
getEnvironment() == Triple::MuslX32 ||
+ getEnvironment() == Triple::MuslWALI ||
getEnvironment() == Triple::OpenHOS || isOSLiteOS();
}
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index ac3626db46ea9..d9f420eccc6f7 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -767,6 +767,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
.StartsWith("muslf32", Triple::MuslF32)
.StartsWith("muslsf", Triple::MuslSF)
.StartsWith("muslx32", Triple::MuslX32)
+ .StartsWith("muslwali", Triple::MuslWALI)
.StartsWith("musl", Triple::Musl)
.StartsWith("msvc", Triple::MSVC)
.StartsWith("itanium", Triple::Itanium)
More information about the llvm-commits
mailing list