aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-01-09 23:43:14 +0000
committerSam Clegg <sbc@chromium.org>2018-01-09 23:43:14 +0000
commitea7caceedcc8d872bc31c141515ef2e3749ef659 (patch)
tree7499d1e4ee969bda41210ab8d2e5d7c339c07b44 /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
parent29f5f987f1b76b5c43310b2062c9f447667a4f80 (diff)
downloadllvm-ea7caceedcc8d872bc31c141515ef2e3749ef659.zip
llvm-ea7caceedcc8d872bc31c141515ef2e3749ef659.tar.gz
llvm-ea7caceedcc8d872bc31c141515ef2e3749ef659.tar.bz2
[WebAssembly] Add COMDAT support
This adds COMDAT support to the Wasm object-file format. Spec: https://github.com/WebAssembly/tool-conventions/pull/31 Corresponding LLD change: https://bugs.llvm.org/show_bug.cgi?id=35533, and D40845 Patch by Nicholas Wilson Differential Revision: https://reviews.llvm.org/D40844 llvm-svn: 322135
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 24d4baa..bdc4bc0 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1254,15 +1254,17 @@ void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal(
// Wasm
//===----------------------------------------------------------------------===//
-static void checkWasmComdat(const GlobalValue *GV) {
+static const Comdat *getWasmComdat(const GlobalValue *GV) {
const Comdat *C = GV->getComdat();
if (!C)
- return;
+ return nullptr;
- // TODO(sbc): At some point we may need COMDAT support but currently
- // they are not supported.
- report_fatal_error("WebAssembly doesn't support COMDATs, '" + C->getName() +
- "' cannot be lowered.");
+ if (C->getSelectionKind() != Comdat::Any)
+ report_fatal_error("WebAssembly COMDATs only support "
+ "SelectionKind::Any, '" + C->getName() + "' cannot be "
+ "lowered.");
+
+ return C;
}
static SectionKind getWasmKindForNamedSection(StringRef Name, SectionKind K) {
@@ -1278,16 +1280,25 @@ static SectionKind getWasmKindForNamedSection(StringRef Name, SectionKind K) {
MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
StringRef Name = GO->getSection();
- checkWasmComdat(GO);
+
Kind = getWasmKindForNamedSection(Name, Kind);
- return getContext().getWasmSection(Name, Kind);
+
+ StringRef Group = "";
+ if (const Comdat *C = getWasmComdat(GO)) {
+ Group = C->getName();
+ }
+
+ return getContext().getWasmSection(Name, Kind, Group,
+ MCContext::GenericSectionID);
}
static MCSectionWasm *selectWasmSectionForGlobal(
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID) {
StringRef Group = "";
- checkWasmComdat(GO);
+ if (const Comdat *C = getWasmComdat(GO)) {
+ Group = C->getName();
+ }
bool UniqueSectionNames = TM.getUniqueSectionNames();
SmallString<128> Name = getSectionPrefixForGlobal(Kind);