[lld] r323025 - [WebAssembly] Remove special handling of entry point export.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 19 17:44:45 PST 2018
Author: sbc
Date: Fri Jan 19 17:44:45 2018
New Revision: 323025
URL: http://llvm.org/viewvc/llvm-project?rev=323025&view=rev
Log:
[WebAssembly] Remove special handling of entry point export.
Its much easier to export it via setHidden(false), now that
that is a thing.
As a side effect the start function is not longer always exports first
(becuase its being exported just like all the other function).
Differential Revision: https://reviews.llvm.org/D42321
Modified:
lld/trunk/test/wasm/alias.ll
lld/trunk/test/wasm/call-indirect.ll
lld/trunk/test/wasm/entry.ll
lld/trunk/test/wasm/export.ll
lld/trunk/test/wasm/stack-pointer.ll
lld/trunk/test/wasm/visibility-hidden.ll
lld/trunk/test/wasm/weak-alias-overide.ll
lld/trunk/test/wasm/weak-undefined.ll
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/Symbols.cpp
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/test/wasm/alias.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/alias.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/alias.ll (original)
+++ lld/trunk/test/wasm/alias.ll Fri Jan 19 17:44:45 2018
@@ -53,10 +53,10 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: - Name: start_alias
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: start_alias
+; CHECK-NEXT: - Name: _start
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: __heap_base
Modified: lld/trunk/test/wasm/call-indirect.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/call-indirect.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/call-indirect.ll (original)
+++ lld/trunk/test/wasm/call-indirect.ll Fri Jan 19 17:44:45 2018
@@ -82,9 +82,6 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: bar
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
@@ -94,6 +91,9 @@ define void @call_ptr(i64 (i64)* %arg) {
; CHECK-NEXT: - Name: foo
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 3
; CHECK-NEXT: - Name: call_ptr
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 4
Modified: lld/trunk/test/wasm/entry.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/entry.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/entry.ll (original)
+++ lld/trunk/test/wasm/entry.ll Fri Jan 19 17:44:45 2018
@@ -1,19 +1,34 @@
; RUN: llc -filetype=obj -mtriple=wasm32-unknown-unknown-wasm %s -o %t.o
-; RUN: lld -flavor wasm -e entry -o %t.wasm %t.o
-; RUN: obj2yaml %t.wasm | FileCheck %s
-; RUN: lld -flavor wasm --entry=entry -o %t.wasm %t.o
-; RUN: obj2yaml %t.wasm | FileCheck %s
-define void @entry() local_unnamed_addr #0 {
+define hidden void @entry() local_unnamed_addr #0 {
entry:
ret void
}
-; CHECK: - Type: EXPORT
-; CHECK: Exports:
-; CHECK: - Name: memory
-; CHECK: Kind: MEMORY
-; CHECK: Index: 0
-; CHECK: - Name: entry
-; CHECK: Kind: FUNCTION
-; CHECK: Index: 0
+; RUN: lld -flavor wasm -e entry -o %t1.wasm %t.o
+; RUN: obj2yaml %t1.wasm | FileCheck %s
+; RUN: lld -flavor wasm --entry=entry -o %t2.wasm %t.o
+; RUN: obj2yaml %t2.wasm | FileCheck %s
+
+; CHECK: - Type: EXPORT
+; CHECK-NEXT: Exports:
+; CHECK-NEXT: - Name: memory
+; CHECK-NEXT: Kind: MEMORY
+; CHECK-NEXT: Index: 0
+; CHECK-NEXT: - Name: entry
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 0
+
+; The __wasm_call_ctors is somewhat special. Make sure we can use it
+; as the entry point if we choose
+; RUN: lld -flavor wasm --entry=__wasm_call_ctors -o %t3.wasm %t.o
+; RUN: obj2yaml %t3.wasm | FileCheck %s -check-prefix=CHECK-CTOR
+
+; CHECK-CTOR: - Type: EXPORT
+; CHECK-CTOR-NEXT: Exports:
+; CHECK-CTOR-NEXT: - Name: memory
+; CHECK-CTOR-NEXT: Kind: MEMORY
+; CHECK-CTOR-NEXT: Index: 0
+; CHECK-CTOR-NEXT: - Name: __wasm_call_ctors
+; CHECK-CTOR-NEXT: Kind: FUNCTION
+; CHECK-CTOR-NEXT: Index: 1
Modified: lld/trunk/test/wasm/export.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/export.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/export.ll (original)
+++ lld/trunk/test/wasm/export.ll Fri Jan 19 17:44:45 2018
@@ -20,12 +20,12 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: hidden_function
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: __heap_base
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 1
Modified: lld/trunk/test/wasm/stack-pointer.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/stack-pointer.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/stack-pointer.ll (original)
+++ lld/trunk/test/wasm/stack-pointer.ll Fri Jan 19 17:44:45 2018
@@ -52,12 +52,12 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: __wasm_call_ctors
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: __stack_pointer
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 0
Modified: lld/trunk/test/wasm/visibility-hidden.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/visibility-hidden.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/visibility-hidden.ll (original)
+++ lld/trunk/test/wasm/visibility-hidden.ll Fri Jan 19 17:44:45 2018
@@ -34,12 +34,12 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: objectDefault
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: archiveDefault
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 4
Modified: lld/trunk/test/wasm/weak-alias-overide.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/weak-alias-overide.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/weak-alias-overide.ll (original)
+++ lld/trunk/test/wasm/weak-alias-overide.ll Fri Jan 19 17:44:45 2018
@@ -60,12 +60,12 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: alias_fn
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 1
; CHECK-NEXT: - Name: direct_fn
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 2
Modified: lld/trunk/test/wasm/weak-undefined.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/weak-undefined.ll?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/test/wasm/weak-undefined.ll (original)
+++ lld/trunk/test/wasm/weak-undefined.ll Fri Jan 19 17:44:45 2018
@@ -67,15 +67,15 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
-; CHECK-NEXT: - Name: _start
-; CHECK-NEXT: Kind: FUNCTION
-; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: get_address_of_foo
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: get_address_of_global_var
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
+; CHECK-NEXT: - Name: _start
+; CHECK-NEXT: Kind: FUNCTION
+; CHECK-NEXT: Index: 2
; CHECK-NEXT: - Name: __heap_base
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 1
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Fri Jan 19 17:44:45 2018
@@ -282,10 +282,11 @@ void LinkerDriver::link(ArrayRef<const c
if (Config->Relocatable && Args.hasArg(OPT_undefined))
error("undefined symbols specified for relocatable output file");
+ Symbol *EntrySym = nullptr;
if (!Config->Relocatable) {
static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
if (!Config->Entry.empty())
- Symtab->addUndefinedFunction(Config->Entry, &Signature);
+ EntrySym = Symtab->addUndefinedFunction(Config->Entry, &Signature);
// Handle the `--undefined <sym>` options.
for (auto* Arg : Args.filtered(OPT_undefined))
@@ -341,6 +342,9 @@ void LinkerDriver::link(ArrayRef<const c
Sym->setHidden(false);
}
+ if (EntrySym)
+ EntrySym->setHidden(false);
+
if (errorCount())
return;
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Fri Jan 19 17:44:45 2018
@@ -131,6 +131,9 @@ Symbol *SymbolTable::addDefinedFunction(
S->setFunctionType(Type);
} else if (!S->isFunction()) {
error("symbol type mismatch: " + Name);
+ } else if (!S->isDefined()) {
+ DEBUG(dbgs() << "resolving existing undefined function: " << Name << "\n");
+ S->update(Symbol::DefinedFunctionKind, nullptr, Flags);
}
return S;
}
@@ -140,10 +143,14 @@ Symbol *SymbolTable::addDefinedGlobal(St
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
- if (WasInserted)
+ if (WasInserted) {
S->update(Symbol::DefinedGlobalKind);
- else if (!S->isGlobal())
+ } else if (!S->isGlobal()) {
error("symbol type mismatch: " + Name);
+ } else {
+ DEBUG(dbgs() << "resolving existing undefined global: " << Name << "\n");
+ S->update(Symbol::DefinedGlobalKind);
+ }
return S;
}
Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Fri Jan 19 17:44:45 2018
@@ -98,6 +98,7 @@ bool Symbol::isHidden() const {
}
void Symbol::setHidden(bool IsHidden) {
+ DEBUG(dbgs() << "setHidden: " << Name << " -> " << IsHidden << "\n");
Flags &= ~WASM_SYMBOL_VISIBILITY_MASK;
if (IsHidden)
Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN;
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=323025&r1=323024&r2=323025&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Fri Jan 19 17:44:45 2018
@@ -617,8 +617,6 @@ void Writer::calculateImports() {
}
void Writer::calculateExports() {
- Symbol *EntrySym = Symtab->find(Config->Entry);
- bool ExportEntry = !Config->Relocatable && EntrySym && EntrySym->isDefined();
bool ExportHidden = Config->EmitRelocs;
StringSet<> UsedNames;
auto BudgeLocalName = [&](const Symbol *Sym) {
@@ -640,11 +638,7 @@ void Writer::calculateExports() {
}
};
- if (ExportEntry)
- ExportedSymbols.emplace_back(WasmExportEntry{EntrySym, EntrySym->getName()});
-
- if (Config->CtorSymbol && ExportHidden &&
- !(ExportEntry && Config->CtorSymbol == EntrySym))
+ if (Config->CtorSymbol && (!Config->CtorSymbol->isHidden() || ExportHidden))
ExportedSymbols.emplace_back(
WasmExportEntry{Config->CtorSymbol, Config->CtorSymbol->getName()});
@@ -659,8 +653,6 @@ void Writer::calculateExports() {
if ((Sym->isHidden() || Sym->isLocal()) && !ExportHidden)
continue;
- if (ExportEntry && Sym == EntrySym)
- continue;
ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)});
}
}
More information about the llvm-commits
mailing list