diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h index 6602dd8e562ed..8877fb7d6235a 100644 --- a/include/swift/IRGen/Linking.h +++ b/include/swift/IRGen/Linking.h @@ -1175,6 +1175,13 @@ class ApplyIRLinkage { if (Triple.isOSBinFormatELF()) return; + // Avoid to create GOT because wasm doesn't support + // dynamic linking yet + if (Triple.isOSBinFormatWasm()) { + GV->setDSOLocal(true); + return; + } + if (IRL.Linkage == llvm::GlobalValue::LinkOnceODRLinkage || IRL.Linkage == llvm::GlobalValue::WeakODRLinkage) if (Triple.supportsCOMDAT()) diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 4960656ddf169..a0769d12d82f3 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -2910,6 +2910,11 @@ IRGenModule::getAddrOfLLVMVariableOrGOTEquivalent(LinkEntity entity) { return {gotEquivalent, ConstantReference::Indirect}; }; + // Avoid to create GOT because wasm32 doesn't support + // dynamic linking yet + if (TargetInfo.OutputObjectFormat == llvm::Triple::Wasm) { + return direct(); + } // The integrated REPL incrementally adds new definitions, so always use // indirect references in this mode. if (IRGen.Opts.IntegratedREPL)