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
5 changes: 5 additions & 0 deletions clang/lib/Driver/ToolChains/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ void cheerp::CheerpOptimizer::ConstructJob(Compilation &C, const JobAction &JA,
<< cheerpStrictLinkingEq->getAsString(Args) << cheerpStrictLinkingEq->getValue();
}
cheerpStrictLinkingEq->render(Args, CmdArgs);
} else if (triple.isCheerpOS() && !Args.hasArg(options::OPT_shared)) {
// Force strict-linking mode when generating executables for CheerpOS. Libraries are excluded for now.
// Strict-linking is required for feature detection in build systems.
// TODO: In the case of libraries, the right approach is to resolve imports from other libraries at compile time
CmdArgs.push_back("-cheerp-strict-linking=error");
}

if(Arg* cheerpLinearOutput = Args.getLastArg(options::OPT_cheerp_linear_output_EQ))
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/Cheerp/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ class TypeSupport
{
return ident.startswith("__imported_wasi_snapshot_preview1_");
}
static bool isCheerpOSFuncName(llvm::StringRef ident)
{
// NOTE: Currently we use a subset of WASI imports in CheerpOS mode, specifically
// to access arguments and the environment.
return isWasiFuncName(ident) || ident.startswith("__dl_") || ident.startswith("__syscall_");
}
static llvm::StringRef getWasiFuncName(llvm::StringRef ident)
{
ident.consume_front("__imported_wasi_snapshot_preview1_");
Expand Down
10 changes: 9 additions & 1 deletion llvm/lib/CheerpUtils/GlobalDepsAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,11 @@ void GlobalDepsAnalyzer::removeGlobalDestructors(llvm::Module& M)
int GlobalDepsAnalyzer::filterModule( const DenseSet<const Function*>& droppedMathBuiltins, Module & module )
{
std::vector< llvm::GlobalValue * > eraseQueue;

// Determine target mode for this module
Triple triple(module.getTargetTriple());
bool tripleIsWasi = triple.isCheerpWasi();
bool tripleIsCheerpOS = triple.isCheerpOS();

// Detach all the global variables, and put the unused ones in the eraseQueue
for ( Module::global_iterator it = module.global_begin(); it != module.global_end(); )
Expand Down Expand Up @@ -1663,7 +1668,10 @@ int GlobalDepsAnalyzer::filterModule( const DenseSet<const Function*>& droppedMa
}
else if(!droppedMathBuiltins.count(f) && f->getIntrinsicID()==0 &&
!TypeSupport::isClientFunc(f) && !TypeSupport::isClientConstructorName(f->getName()) &&
!TypeSupport::isWasiFuncName(f->getName()) &&
// Allow WASI imports if needed
!(tripleIsWasi && TypeSupport::isWasiFuncName(f->getName())) &&
// Allow CheerpOS imports if needed
!(tripleIsCheerpOS && TypeSupport::isCheerpOSFuncName(f->getName())) &&
// Special case "free" here, it might be used in genericjs code and lowered by the backend
f->getName() != "free" &&
// Special case "__memory_init", it will be populated just before the writer.
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/WebAssembly/CheerpWritePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ bool CheerpWritePass::runOnModule(Module& M)
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);

ModulePassManager MPM;
bool isWasmTarget = Triple(M.getTargetTriple()).isCheerpWasm();
Triple triple(M.getTargetTriple());
bool isWasmTarget = triple.isCheerpWasm();
cheerp::GlobalDepsAnalyzer::MATH_MODE mathMode;
if (NoNativeJavaScriptMath)
mathMode = cheerp::GlobalDepsAnalyzer::NO_BUILTINS;
Expand All @@ -210,7 +211,7 @@ bool CheerpWritePass::runOnModule(Module& M)
functionAddressMode == cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::Wasm &&
// NOTE: this is not actually required by the spec, but for now chrome
// doesn't like growing shared memory
(!WasmSharedMemory || WasmSharedModule);
((!WasmSharedMemory || triple.isCheerpWasmStandalone()) || WasmSharedModule);
bool hasAsmjsMem = functionAddressMode == cheerp::LinearMemoryHelperInitializer::FunctionAddressMode::AsmJS &&
(!SecondaryOutputFile.empty() || !SecondaryOutputPath.empty());

Expand Down
Loading