[llvm] r318123 - [WebAssembly] Explicily disable comdat support for wasm output
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 13 16:49:16 PST 2017
Author: sbc
Date: Mon Nov 13 16:49:16 2017
New Revision: 318123
URL: http://llvm.org/viewvc/llvm-project?rev=318123&view=rev
Log:
[WebAssembly] Explicily disable comdat support for wasm output
For now at least. We clearly need some kind of comdat or
linkonce_odr support for wasm but currently COMDAT is not
supported.
Disable COMDAT support in the same way we do the Mach-O. This
also causes clang not to generated COMDATs.
Differential Revision: https://reviews.llvm.org/D39873
Added:
llvm/trunk/test/CodeGen/WebAssembly/comdat.ll
Modified:
llvm/trunk/include/llvm/ADT/Triple.h
llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Modified: llvm/trunk/include/llvm/ADT/Triple.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Triple.h?rev=318123&r1=318122&r2=318123&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Triple.h (original)
+++ llvm/trunk/include/llvm/ADT/Triple.h Mon Nov 13 16:49:16 2017
@@ -661,7 +661,9 @@ public:
}
/// Tests wether the target supports comdat
- bool supportsCOMDAT() const { return !isOSBinFormatMachO(); }
+ bool supportsCOMDAT() const {
+ return !isOSBinFormatMachO() && !isOSBinFormatWasm();
+ }
/// @}
/// @name Mutators
Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=318123&r1=318122&r2=318123&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Nov 13 16:49:16 2017
@@ -1825,10 +1825,10 @@ Expected<Value *> BitcodeReader::recordV
auto *GO = dyn_cast<GlobalObject>(V);
if (GO) {
if (GO->getComdat() == reinterpret_cast<Comdat *>(1)) {
- if (TT.isOSBinFormatMachO())
- GO->setComdat(nullptr);
- else
+ if (TT.supportsCOMDAT())
GO->setComdat(TheModule->getOrInsertComdat(V->getName()));
+ else
+ GO->setComdat(nullptr);
}
}
return V;
Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=318123&r1=318122&r2=318123&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Mon Nov 13 16:49:16 2017
@@ -1233,21 +1233,21 @@ void TargetLoweringObjectFileCOFF::emitL
// Wasm
//===----------------------------------------------------------------------===//
-static const Comdat *getWasmComdat(const GlobalValue *GV) {
+static void checkWasmComdat(const GlobalValue *GV) {
const Comdat *C = GV->getComdat();
if (!C)
- return nullptr;
+ return;
- if (C->getSelectionKind() != Comdat::Any)
- report_fatal_error("Wasm COMDATs only support SelectionKind::Any, '" +
- C->getName() + "' cannot be lowered.");
-
- return C;
+ // 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.");
}
MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
StringRef Name = GO->getSection();
+ checkWasmComdat(GO);
return getContext().getWasmSection(Name, SectionKind::getData());
}
@@ -1255,8 +1255,7 @@ static MCSectionWasm *selectWasmSectionF
MCContext &Ctx, const GlobalObject *GO, SectionKind Kind, Mangler &Mang,
const TargetMachine &TM, bool EmitUniqueSection, unsigned *NextUniqueID) {
StringRef Group = "";
- if (getWasmComdat(GO))
- llvm_unreachable("comdat not yet supported for wasm");
+ checkWasmComdat(GO);
bool UniqueSectionNames = TM.getUniqueSectionNames();
SmallString<128> Name = getSectionPrefixForGlobal(Kind);
Added: llvm/trunk/test/CodeGen/WebAssembly/comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/comdat.ll?rev=318123&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/comdat.ll (added)
+++ llvm/trunk/test/CodeGen/WebAssembly/comdat.ll Mon Nov 13 16:49:16 2017
@@ -0,0 +1,5 @@
+; RUN: not llc -mtriple wasm32-unknown-unknown-wasm %s 2>&1 | FileCheck %s
+
+$f = comdat any
+ at f = global i32 0, comdat
+; CHECK: LLVM ERROR: WebAssembly doesn't support COMDATs, 'f' cannot be lowered.
More information about the llvm-commits
mailing list