[llvm] r322309 - [WebAssemlby] MC: Don't write COMDAT symbols as global imports
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 12:35:17 PST 2018
Author: sbc
Date: Thu Jan 11 12:35:17 2018
New Revision: 322309
URL: http://llvm.org/viewvc/llvm-project?rev=322309&view=rev
Log:
[WebAssemlby] MC: Don't write COMDAT symbols as global imports
This was causing undefined references at link time in lld.
Differential Revision: https://reviews.llvm.org/D41959
Modified:
llvm/trunk/include/llvm/MC/MCSymbolWasm.h
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/WasmObjectWriter.cpp
llvm/trunk/test/MC/WebAssembly/comdat.ll
Modified: llvm/trunk/include/llvm/MC/MCSymbolWasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbolWasm.h?rev=322309&r1=322308&r2=322309&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolWasm.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolWasm.h Thu Jan 11 12:35:17 2018
@@ -19,6 +19,7 @@ private:
bool IsFunction = false;
bool IsWeak = false;
bool IsHidden = false;
+ bool IsComdat = false;
std::string ModuleName;
SmallVector<wasm::ValType, 1> Returns;
SmallVector<wasm::ValType, 4> Params;
@@ -49,6 +50,9 @@ public:
bool isHidden() const { return IsHidden; }
void setHidden(bool isHidden) { IsHidden = isHidden; }
+ bool isComdat() const { return IsComdat; }
+ void setComdat(bool isComdat) { IsComdat = isComdat; }
+
const StringRef getModuleName() const { return ModuleName; }
const SmallVector<wasm::ValType, 1> &getReturns() const {
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=322309&r1=322308&r2=322309&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Jan 11 12:35:17 2018
@@ -490,8 +490,10 @@ MCSectionWasm *MCContext::getWasmSection
const Twine &Group, unsigned UniqueID,
const char *BeginSymName) {
MCSymbolWasm *GroupSym = nullptr;
- if (!Group.isTriviallyEmpty() && !Group.str().empty())
+ if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
+ GroupSym->setComdat(true);
+ }
return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName);
}
Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=322309&r1=322308&r2=322309&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Thu Jan 11 12:35:17 2018
@@ -1122,7 +1122,8 @@ void WasmObjectWriter::writeObject(MCAss
continue;
// If the symbol is not defined in this translation unit, import it.
- if (!WS.isDefined(/*SetUsed=*/false) || WS.isVariable()) {
+ if ((!WS.isDefined(/*SetUsed=*/false) && !WS.isComdat()) ||
+ WS.isVariable()) {
WasmImport Import;
Import.ModuleName = WS.getModuleName();
Import.FieldName = WS.getName();
Modified: llvm/trunk/test/MC/WebAssembly/comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/comdat.ll?rev=322309&r1=322308&r2=322309&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/comdat.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/comdat.ll Thu Jan 11 12:35:17 2018
@@ -22,7 +22,41 @@ define linkonce_odr i32 @sharedFn() #1 c
ret i32 0
}
-; CHECK: - Type: EXPORT
+; CHECK: Sections:
+; CHECK-NEXT: - Type: TYPE
+; CHECK-NEXT: Signatures:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: ReturnType: I32
+; CHECK-NEXT: ParamTypes:
+; CHECK-NEXT: - Type: IMPORT
+; CHECK-NEXT: Imports:
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __linear_memory
+; CHECK-NEXT: Kind: MEMORY
+; CHECK-NEXT: Memory:
+; CHECK-NEXT: Initial: 0x00000001
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: __indirect_function_table
+; CHECK-NEXT: Kind: TABLE
+; CHECK-NEXT: Table:
+; CHECK-NEXT: ElemType: ANYFUNC
+; CHECK-NEXT: Limits:
+; CHECK-NEXT: Initial: 0x00000000
+; CHECK-NEXT: - Module: env
+; CHECK-NEXT: Field: funcImport
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: SigIndex: 0
+; CHECK-NEXT: - Type: FUNCTION
+; CHECK-NEXT: FunctionTypes: [ 0, 0, 0 ]
+; CHECK-NEXT: - Type: GLOBAL
+; CHECK-NEXT: Globals:
+; CHECK-NEXT: - Index: 0
+; CHECK-NEXT: Type: I32
+; CHECK-NEXT: Mutable: false
+; CHECK-NEXT: InitExpr:
+; CHECK-NEXT: Opcode: I32_CONST
+; CHECK-NEXT: Value: 0
+; CHECK-NEXT: - Type: EXPORT
; CHECK-NEXT: Exports:
; CHECK-NEXT: - Name: callImport
; CHECK-NEXT: Kind: FUNCTION
@@ -35,7 +69,7 @@ define linkonce_odr i32 @sharedFn() #1 c
; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: constantData
; CHECK-NEXT: Kind: GLOBAL
-; CHECK-NEXT: Index: 1
+; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Type: CODE
; CHECK-NEXT: Relocations:
; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB
More information about the llvm-commits
mailing list