Skip to content

Commit cb996a1

Browse files
committed
Support for wasm32-wali-linux-musl target in clang, lld, and libcxx
1 parent 917f022 commit cb996a1

File tree

8 files changed

+55
-14
lines changed

8 files changed

+55
-14
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
687687
}
688688
case llvm::Triple::wasm32:
689689
if (Triple.getSubArch() != llvm::Triple::NoSubArch ||
690-
Triple.getVendor() != llvm::Triple::UnknownVendor ||
690+
(!Triple.isWALI() &&
691+
Triple.getVendor() != llvm::Triple::UnknownVendor) ||
691692
!Triple.isOSBinFormatWasm())
692693
return nullptr;
693694
switch (os) {
@@ -697,6 +698,10 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
697698
case llvm::Triple::Emscripten:
698699
return std::make_unique<EmscriptenTargetInfo<WebAssembly32TargetInfo>>(
699700
Triple, Opts);
701+
// WALI OS target
702+
case llvm::Triple::Linux:
703+
return std::make_unique<WALITargetInfo<WebAssembly32TargetInfo>>(Triple,
704+
Opts);
700705
case llvm::Triple::UnknownOS:
701706
return std::make_unique<WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>>(
702707
Triple, Opts);

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,23 @@ class LLVM_LIBRARY_VISIBILITY WASITargetInfo
936936
using WebAssemblyOSTargetInfo<Target>::WebAssemblyOSTargetInfo;
937937
};
938938

939+
// WALI target
940+
template <typename Target>
941+
class LLVM_LIBRARY_VISIBILITY WALITargetInfo
942+
: public WebAssemblyOSTargetInfo<Target> {
943+
void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
944+
MacroBuilder &Builder) const final {
945+
WebAssemblyOSTargetInfo<Target>::getOSDefines(Opts, Triple, Builder);
946+
// Linux defines; list based off of gcc output
947+
DefineStd(Builder, "unix", Opts);
948+
DefineStd(Builder, "linux", Opts);
949+
Builder.defineMacro("__wali__");
950+
}
951+
952+
public:
953+
using WebAssemblyOSTargetInfo<Target>::WebAssemblyOSTargetInfo;
954+
};
955+
939956
// Emscripten target
940957
template <typename Target>
941958
class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo

clang/lib/Basic/Targets/WebAssembly.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,20 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
8888
LongDoubleWidth = LongDoubleAlign = 128;
8989
LongDoubleFormat = &llvm::APFloat::IEEEquad();
9090
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
91-
// size_t being unsigned long for both wasm32 and wasm64 makes mangled names
92-
// more consistent between the two.
93-
SizeType = UnsignedLong;
94-
PtrDiffType = SignedLong;
95-
IntPtrType = SignedLong;
9691
HasUnalignedAccess = true;
92+
if (T.isWALI()) {
93+
// WALI ABI requires 64-bit longs on both wasm32 and wasm64
94+
LongAlign = LongWidth = 64;
95+
SizeType = UnsignedInt;
96+
PtrDiffType = SignedInt;
97+
IntPtrType = SignedInt;
98+
} else {
99+
// size_t being unsigned long for both wasm32 and wasm64 makes mangled
100+
// names more consistent between the two.
101+
SizeType = UnsignedLong;
102+
PtrDiffType = SignedLong;
103+
IntPtrType = SignedLong;
104+
}
97105
}
98106

99107
StringRef getABI() const override;

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6833,6 +6833,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
68336833
TC = std::make_unique<toolchains::VEToolChain>(*this, Target, Args);
68346834
else if (Target.isOHOSFamily())
68356835
TC = std::make_unique<toolchains::OHOS>(*this, Target, Args);
6836+
else if (Target.isWALI())
6837+
TC = std::make_unique<toolchains::WebAssembly>(*this, Target, Args);
68366838
else
68376839
TC = std::make_unique<toolchains::Linux>(*this, Target, Args);
68386840
break;

libunwind/src/UnwindRegistersRestore.S

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
10+
911
#include "assembly.h"
1012

1113
#define FROM_0_TO_15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
@@ -20,8 +22,6 @@
2022
.text
2123
#endif
2224

23-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
24-
2525
#if defined(__i386__)
2626
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
2727
#
@@ -1250,7 +1250,6 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
12501250

12511251
#endif
12521252

1253-
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
1254-
12551253
NO_EXEC_STACK_DIRECTIVE
12561254

1255+
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */

libunwind/src/UnwindRegistersSave.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
10+
911
#include "assembly.h"
1012

1113
#define FROM_0_TO_15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
@@ -20,8 +22,6 @@
2022
.text
2123
#endif
2224

23-
#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__)
24-
2525
#if defined(__i386__)
2626

2727
#
@@ -1232,6 +1232,6 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
12321232
WEAK_ALIAS(__unw_getcontext, unw_getcontext)
12331233
#endif
12341234

1235-
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */
1236-
12371235
NO_EXEC_STACK_DIRECTIVE
1236+
1237+
#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__wasm__) */

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class Triple {
199199
SUSE,
200200
OpenEmbedded,
201201
Intel,
202+
WALI,
202203
Meta,
203204
LastVendorType = Meta
204205
};
@@ -795,6 +796,12 @@ class Triple {
795796
return getObjectFormat() == Triple::DXContainer;
796797
}
797798

799+
/// Tests whether the target uses WALI Wasm
800+
bool isWALI() const {
801+
return getArch() == Triple::wasm32 && getVendor() == Triple::WALI &&
802+
getOS() == Triple::Linux;
803+
}
804+
798805
/// Tests whether the target is the PS4 platform.
799806
bool isPS4() const {
800807
return getArch() == Triple::x86_64 &&

llvm/lib/TargetParser/Triple.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ StringRef Triple::getVendorTypeName(VendorType Kind) {
277277
case PC: return "pc";
278278
case SCEI: return "scei";
279279
case SUSE: return "suse";
280+
case WALI:
281+
return "wali";
280282
case Meta:
281283
return "meta";
282284
}
@@ -681,6 +683,7 @@ static Triple::VendorType parseVendor(StringRef VendorName) {
681683
.Case("suse", Triple::SUSE)
682684
.Case("oe", Triple::OpenEmbedded)
683685
.Case("intel", Triple::Intel)
686+
.Case("wali", Triple::WALI)
684687
.Case("meta", Triple::Meta)
685688
.Default(Triple::UnknownVendor);
686689
}

0 commit comments

Comments
 (0)