From 0e95395d38b0b8a22140a7c636c554cdb4815fbc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Wed, 26 Feb 2020 05:58:24 +0000 Subject: [PATCH] [WASM] Avoid to emit GOT for WASM WebAssembly doesn't support dynamic linking, so GOT is not necessary now. LLVM produces virtual GOT when compiler want to use GOT, but it takes overhead on runtime. Discussion: https://forums.swift.org/t/wasm-support/16087/19 --- include/swift/IRGen/Linking.h | 7 +++++++ lib/IRGen/GenDecl.cpp | 5 +++++ 2 files changed, 12 insertions(+) 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)