Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 16 additions & 5 deletions clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/wasm-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
25 changes: 25 additions & 0 deletions clang/test/Driver/wasm-toolchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 5 additions & 2 deletions libunwind/src/UnwindRegistersRestore.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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__) */
8 changes: 6 additions & 2 deletions libunwind/src/UnwindRegistersSave.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +22,7 @@
.text
#endif

#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
#if !defined(__USING_SJLJ_EXCEPTIONS__)

#if defined(__i386__)

Expand Down Expand Up @@ -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__) */
8 changes: 8 additions & 0 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ class Triple {
MuslF32,
MuslSF,
MuslX32,
MuslWALI,
LLVM,

MSVC,
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -840,6 +847,7 @@ class Triple {
getEnvironment() == Triple::MuslF32 ||
getEnvironment() == Triple::MuslSF ||
getEnvironment() == Triple::MuslX32 ||
getEnvironment() == Triple::MuslWALI ||
getEnvironment() == Triple::OpenHOS || isOSLiteOS();
}

Expand Down
1 change: 1 addition & 0 deletions llvm/lib/TargetParser/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading