Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ int linkObjToBinaryGcc(llvm::StringRef outputPath,
// exception: invoke (ld-compatible) linker directly for WebAssembly targets
std::string tool;
std::unique_ptr<ArgsBuilder> argsBuilder;
if (global.params.targetTriple->isOSBinFormatWasm()) {
if (global.params.targetTriple->isOSBinFormatWasm() && !global.params.targetTriple->isOSWASI()) {
argsBuilder = std::make_unique<LdArgsBuilder>();
tool = getProgram("wasm-ld", &opts::linker);
} else {
Expand Down
18 changes: 18 additions & 0 deletions driver/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,26 @@ void registerPredefinedTargetVersions() {
break;
case llvm::Triple::WASI:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp1");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
#if LLVM_VERSION_MAJOR >= 22
case llvm::Triple::WASIp1:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp1");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
case llvm::Triple::WASIp2:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp2");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
case llvm::Triple::WASIp3:
VersionCondition::addPredefinedGlobalIdent("WASI");
VersionCondition::addPredefinedGlobalIdent("WASIp3");
VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI");
break;
#endif
case llvm::Triple::Emscripten:
VersionCondition::addPredefinedGlobalIdent("Emscripten");
// Emscripten uses musl and libc++, so mimic a musl Linux platform:
Expand Down
6 changes: 5 additions & 1 deletion gen/llvmhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ llvm::cl::opt<llvm::GlobalVariable::ThreadLocalMode> clThreadModel(
bool isTargetWindowsMSVC() {
return global.params.targetTriple->isWindowsMSVCEnvironment();
}
bool isTargetWasm() {
return global.params.targetTriple->isWasm();
}


/******************************************************************************
* Global context
Expand Down Expand Up @@ -289,7 +293,7 @@ void DtoCAssert(Module *M, Loc loc, LLValue *msg) {
args.push_back(file);
args.push_back(line);
args.push_back(msg);
} else if (triple.isOSSolaris() || triple.isMusl() ||
} else if (triple.isOSSolaris() || triple.isMusl() || triple.isOSWASI() ||
global.params.isUClibcEnvironment ||
triple.isGNUEnvironment()) {
const auto irFunc = gIR->func();
Expand Down
1 change: 1 addition & 0 deletions gen/llvmhelpers.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ import dmd.dtemplate;
extern (C++) void DtoSetFuncDeclIntrinsicName(TemplateInstance ti, TemplateDeclaration td, FuncDeclaration fd);

extern (C++) bool isTargetWindowsMSVC();
extern (C++) bool isTargetWasm();
4 changes: 2 additions & 2 deletions gen/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ static const char *getCAssertFunctionName() {
return "_assert";
} else if (triple.isOSSolaris()) {
return "__assert_c99";
} else if (triple.isMusl() || triple.isGNUEnvironment()) {
} else if (triple.isMusl() || triple.isGNUEnvironment() || triple.isOSWASI()) {
return "__assert_fail";
} else if (global.params.isNewlibEnvironment) {
return "__assert_func";
Expand All @@ -372,7 +372,7 @@ static std::vector<PotentiallyLazyType> getCAssertFunctionParamTypes() {
const auto uint = Type::tuns32;

if (triple.isOSDarwin() || triple.isOSFreeBSD() || triple.isOSSolaris() ||
triple.isMusl() || global.params.isUClibcEnvironment ||
triple.isMusl() || triple.isOSWASI() || global.params.isUClibcEnvironment ||
triple.isGNUEnvironment()) {
return {voidPtr, voidPtr, uint, voidPtr};
}
Expand Down
8 changes: 7 additions & 1 deletion tests/codegen/wasi.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// REQUIRES: target_WebAssembly, link_WebAssembly

// emit textual IR *and* compile & link
// RUN: %ldc -mtriple=wasm32-unknown-wasi -output-ll -output-o -of=%t.wasm %s
// RUN: %ldc -mtriple=wasm32-unknown-wasi --linker=lld -Xcc=-nostdlib -output-ll -output-o -of=%t.wasm %s
// RUN: FileCheck %s < %t.ll
//
// RUN: %ldc -mtriple=wasm32-unknown-wasip1 --linker=lld -Xcc=-nostdlib -output-ll -output-o -of=%t_p1.wasm %s
// RUN: FileCheck %s < %t_p1.ll
//
// RUN: %ldc -mtriple=wasm32-unknown-wasip2 --linker=lld -Xcc=-nostdlib -output-ll -output-o -of=%t_p2.wasm %s
// RUN: FileCheck %s < %t_p2.ll


// test predefined versions:
Expand Down
Loading