[WebAssembly] Support for new target wasm32-linux-muslwali (#162581)
Add toolchain support for 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)
This commit is contained in:
parent
a4a0a4b9b1
commit
7e7c923b58
@ -704,6 +704,10 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
|
||||
case llvm::Triple::Emscripten:
|
||||
return std::make_unique<EmscriptenTargetInfo<WebAssembly32TargetInfo>>(
|
||||
Triple, Opts);
|
||||
|
||||
case llvm::Triple::Linux:
|
||||
return std::make_unique<WALITargetInfo<WebAssembly32TargetInfo>>(Triple,
|
||||
Opts);
|
||||
case llvm::Triple::UnknownOS:
|
||||
return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>>(
|
||||
Triple, Opts);
|
||||
|
||||
@ -948,6 +948,23 @@ public:
|
||||
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
|
||||
|
||||
@ -88,12 +88,23 @@ public:
|
||||
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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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__) */
|
||||
|
||||
@ -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__) */
|
||||
|
||||
@ -277,6 +277,7 @@ public:
|
||||
MuslF32,
|
||||
MuslSF,
|
||||
MuslX32,
|
||||
MuslWALI,
|
||||
LLVM,
|
||||
|
||||
MSVC,
|
||||
@ -798,6 +799,12 @@ public:
|
||||
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 @@ public:
|
||||
getEnvironment() == Triple::MuslF32 ||
|
||||
getEnvironment() == Triple::MuslSF ||
|
||||
getEnvironment() == Triple::MuslX32 ||
|
||||
getEnvironment() == Triple::MuslWALI ||
|
||||
getEnvironment() == Triple::OpenHOS || isOSLiteOS();
|
||||
}
|
||||
|
||||
|
||||
@ -375,6 +375,8 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
|
||||
case MuslSF:
|
||||
return "muslsf";
|
||||
case MuslX32: return "muslx32";
|
||||
case MuslWALI:
|
||||
return "muslwali";
|
||||
case Simulator: return "simulator";
|
||||
case Pixel: return "pixel";
|
||||
case Vertex: return "vertex";
|
||||
@ -767,6 +769,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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user