From 1871856fc5f096e1b69a4c4989836d7a77f1ccc8 Mon Sep 17 00:00:00 2001 From: Zhuowei Zhang Date: Sat, 13 Apr 2019 17:41:32 -0700 Subject: [PATCH] [Swift+WASM] [IRGen] Disable COMDAT for reflection metadata LLVM's Wasm COMDAT code assumes each COMDAT will be in its own section. This works for C++ on Clang, since each COMDAT is emitted into its own .rodata. section, but not for Swift metadata, which are all placed in the same section. Disable COMDAT support when emitting reflection metadata. This matches the behaviour on ELF (where COMDATs are disabled) and MachO (which doesn't support COMDAT) This shouldn't affect existing platforms. --- include/swift/IRGen/Linking.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/swift/IRGen/Linking.h b/include/swift/IRGen/Linking.h index ca7024cd87d39..d721ac0d8515c 100644 --- a/include/swift/IRGen/Linking.h +++ b/include/swift/IRGen/Linking.h @@ -1095,6 +1095,14 @@ class ApplyIRLinkage { if (Triple.isOSBinFormatELF()) return; + // WebAssembly: disable COMDATs. + // LLVM's Wasm COMDAT code assumes each COMDAT will be in its own section. + // This works for C++ on Clang, since each COMDAT is emitted into its own + // .rodata. section, + // but not for Swift metadata, which are all placed in the same section. + if (Triple.isOSBinFormatWasm()) + return; + if (IRL.Linkage == llvm::GlobalValue::LinkOnceODRLinkage || IRL.Linkage == llvm::GlobalValue::WeakODRLinkage) if (Triple.supportsCOMDAT())