[lld] r325045 - [WebAssembly] Cleanup methods for add synthetic symbols to symbtab. NFC.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 12:14:26 PST 2018
Author: sbc
Date: Tue Feb 13 12:14:26 2018
New Revision: 325045
URL: http://llvm.org/viewvc/llvm-project?rev=325045&view=rev
Log:
[WebAssembly] Cleanup methods for add synthetic symbols to symbtab. NFC.
These were duplicating (incorrectly) some of the logic for
handling conflicts, but since they are only ever added right
at the start we can assume no existing symbols.
Also rename these methods for clarity.
Differential Revision: https://reviews.llvm.org/D43252
Modified:
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SymbolTable.h
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=325045&r1=325044&r2=325045&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Tue Feb 13 12:14:26 2018
@@ -225,6 +225,11 @@ static StringRef getEntry(opt::InputArgL
return Arg->getValue();
}
+static Symbol* addUndefinedFunction(StringRef Name, const WasmSignature *Type) {
+ return Symtab->addUndefined(Name, Symbol::UndefinedFunctionKind, 0, nullptr,
+ Type);
+}
+
void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
WasmOptTable Parser;
opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));
@@ -292,19 +297,22 @@ void LinkerDriver::link(ArrayRef<const c
Symbol *EntrySym = nullptr;
if (!Config->Relocatable) {
- static WasmSignature Signature = {{}, WASM_TYPE_NORESULT};
+ static WasmSignature NullSignature = {{}, WASM_TYPE_NORESULT};
+
+ // Add synthetic symbols before any others
+ WasmSym::CallCtors = Symtab->addSyntheticFunction(
+ "__wasm_call_ctors", &NullSignature, WASM_SYMBOL_VISIBILITY_HIDDEN);
+ WasmSym::StackPointer = Symtab->addSyntheticGlobal("__stack_pointer");
+ WasmSym::HeapBase = Symtab->addSyntheticGlobal("__heap_base");
+ WasmSym::DsoHandle = Symtab->addSyntheticGlobal("__dso_handle");
+ WasmSym::DataEnd = Symtab->addSyntheticGlobal("__data_end");
+
if (!Config->Entry.empty())
- EntrySym = Symtab->addUndefinedFunction(Config->Entry, &Signature);
+ EntrySym = addUndefinedFunction(Config->Entry, &NullSignature);
// Handle the `--undefined <sym>` options.
for (auto* Arg : Args.filtered(OPT_undefined))
- Symtab->addUndefinedFunction(Arg->getValue(), nullptr);
- WasmSym::CallCtors = Symtab->addDefinedFunction(
- "__wasm_call_ctors", &Signature, WASM_SYMBOL_VISIBILITY_HIDDEN);
- WasmSym::StackPointer = Symtab->addDefinedGlobal("__stack_pointer");
- WasmSym::HeapBase = Symtab->addDefinedGlobal("__heap_base");
- WasmSym::DsoHandle = Symtab->addDefinedGlobal("__dso_handle");
- WasmSym::DataEnd = Symtab->addDefinedGlobal("__data_end");
+ addUndefinedFunction(Arg->getValue(), nullptr);
}
createFiles(Args);
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=325045&r1=325044&r2=325045&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Tue Feb 13 12:14:26 2018
@@ -127,38 +127,26 @@ static void checkSymbolTypes(const Symbo
return checkSymbolTypes(Existing, F, Kind, Sig);
}
-Symbol *SymbolTable::addDefinedFunction(StringRef Name,
- const WasmSignature *Type,
- uint32_t Flags) {
- DEBUG(dbgs() << "addDefinedFunction: " << Name << "\n");
+Symbol *SymbolTable::addSyntheticFunction(StringRef Name,
+ const WasmSignature *Type,
+ uint32_t Flags) {
+ DEBUG(dbgs() << "addSyntheticFunction: " << Name << "\n");
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
- if (WasInserted) {
- S->update(Symbol::DefinedFunctionKind, nullptr, Flags);
- 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);
- }
+ assert(WasInserted);
+ S->update(Symbol::DefinedFunctionKind, nullptr, Flags);
+ S->setFunctionType(Type);
return S;
}
-Symbol *SymbolTable::addDefinedGlobal(StringRef Name) {
- DEBUG(dbgs() << "addDefinedGlobal: " << Name << "\n");
+Symbol *SymbolTable::addSyntheticGlobal(StringRef Name) {
+ DEBUG(dbgs() << "addSyntheticGlobal: " << Name << "\n");
Symbol *S;
bool WasInserted;
std::tie(S, WasInserted) = insert(Name);
- if (WasInserted) {
- S->update(Symbol::DefinedGlobalKind);
- } else if (!S->isGlobal()) {
- error("symbol type mismatch: " + Name);
- } else {
- DEBUG(dbgs() << "resolving existing undefined global: " << Name << "\n");
- S->update(Symbol::DefinedGlobalKind);
- }
+ assert(WasInserted);
+ S->update(Symbol::DefinedGlobalKind);
return S;
}
Modified: lld/trunk/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.h?rev=325045&r1=325044&r2=325045&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.h (original)
+++ lld/trunk/wasm/SymbolTable.h Tue Feb 13 12:14:26 2018
@@ -55,12 +55,12 @@ public:
Symbol *addUndefined(StringRef Name, Symbol::Kind Kind, uint32_t Flags,
InputFile *F, const WasmSignature *Signature = nullptr);
Symbol *addUndefinedFunction(StringRef Name, const WasmSignature *Type);
- Symbol *addDefinedGlobal(StringRef Name);
- Symbol *addDefinedFunction(StringRef Name, const WasmSignature *Type,
- uint32_t Flags);
void addLazy(ArchiveFile *F, const Archive::Symbol *Sym);
bool addComdat(StringRef Name, ObjFile *);
+ Symbol *addSyntheticGlobal(StringRef Name);
+ Symbol *addSyntheticFunction(StringRef Name, const WasmSignature *Type,
+ uint32_t Flags);
private:
std::pair<Symbol *, bool> insert(StringRef Name);
More information about the llvm-commits
mailing list