[lld] r370010 - [lld][WebAssembly] Store table base in config rather than passing it around. NFC.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 21:19:35 PDT 2019
Author: sbc
Date: Mon Aug 26 21:19:34 2019
New Revision: 370010
URL: http://llvm.org/viewvc/llvm-project?rev=370010&view=rev
Log:
[lld][WebAssembly] Store table base in config rather than passing it around. NFC.
I've got another change that makes more use of this value in other
places.
Differential Revision: https://reviews.llvm.org/D66777
Modified:
lld/trunk/wasm/Config.h
lld/trunk/wasm/SyntheticSections.cpp
lld/trunk/wasm/SyntheticSections.h
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/wasm/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Config.h?rev=370010&r1=370009&r2=370010&view=diff
==============================================================================
--- lld/trunk/wasm/Config.h (original)
+++ lld/trunk/wasm/Config.h Mon Aug 26 21:19:34 2019
@@ -70,6 +70,12 @@ struct Configuration {
// True if we are creating position-independent code.
bool isPic;
+
+ // The table offset at which to place function addresses. We reserve zero
+ // for the null function pointer. This gets set to 1 for exectuables and 0
+ // for shared libraries (since they always added to a dynamic offset at
+ // runtime).
+ uint32_t tableBase = 0;
};
// The only instance of Configuration struct.
Modified: lld/trunk/wasm/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SyntheticSections.cpp?rev=370010&r1=370009&r2=370010&view=diff
==============================================================================
--- lld/trunk/wasm/SyntheticSections.cpp (original)
+++ lld/trunk/wasm/SyntheticSections.cpp Mon Aug 26 21:19:34 2019
@@ -143,7 +143,7 @@ void ImportSection::writeBody() {
}
if (config->importTable) {
- uint32_t tableSize = out.elemSec->elemOffset + out.elemSec->numEntries();
+ uint32_t tableSize = config->tableBase + out.elemSec->numEntries();
WasmImport import;
import.Module = defaultModule;
import.Field = functionTableName;
@@ -212,7 +212,7 @@ void FunctionSection::addFunction(InputF
}
void TableSection::writeBody() {
- uint32_t tableSize = out.elemSec->elemOffset + out.elemSec->numEntries();
+ uint32_t tableSize = config->tableBase + out.elemSec->numEntries();
raw_ostream &os = bodyOutputStream;
writeUleb128(os, 1, "table count");
@@ -313,7 +313,7 @@ void ExportSection::writeBody() {
void ElemSection::addEntry(FunctionSymbol *sym) {
if (sym->hasTableIndex())
return;
- sym->setTableIndex(elemOffset + indirectFunctions.size());
+ sym->setTableIndex(config->tableBase + indirectFunctions.size());
indirectFunctions.emplace_back(sym);
}
@@ -328,12 +328,12 @@ void ElemSection::writeBody() {
initExpr.Value.Global = WasmSym::tableBase->getGlobalIndex();
} else {
initExpr.Opcode = WASM_OPCODE_I32_CONST;
- initExpr.Value.Int32 = elemOffset;
+ initExpr.Value.Int32 = config->tableBase;
}
writeInitExpr(os, initExpr);
writeUleb128(os, indirectFunctions.size(), "elem count");
- uint32_t tableIndex = elemOffset;
+ uint32_t tableIndex = config->tableBase;
for (const FunctionSymbol *sym : indirectFunctions) {
assert(sym->getTableIndex() == tableIndex);
writeUleb128(os, sym->getFunctionIndex(), "function index");
Modified: lld/trunk/wasm/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SyntheticSections.h?rev=370010&r1=370009&r2=370010&view=diff
==============================================================================
--- lld/trunk/wasm/SyntheticSections.h (original)
+++ lld/trunk/wasm/SyntheticSections.h Mon Aug 26 21:19:34 2019
@@ -219,13 +219,12 @@ public:
class ElemSection : public SyntheticSection {
public:
- ElemSection(uint32_t offset)
- : SyntheticSection(llvm::wasm::WASM_SEC_ELEM), elemOffset(offset) {}
+ ElemSection()
+ : SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {}
bool isNeeded() const override { return indirectFunctions.size() > 0; };
void writeBody() override;
void addEntry(FunctionSymbol *sym);
uint32_t numEntries() const { return indirectFunctions.size(); }
- uint32_t elemOffset;
protected:
std::vector<const FunctionSymbol *> indirectFunctions;
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=370010&r1=370009&r2=370010&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Mon Aug 26 21:19:34 2019
@@ -87,7 +87,6 @@ private:
void writeSections();
uint64_t fileSize = 0;
- uint32_t tableBase = 0;
std::vector<WasmInitEntry> initFunctions;
llvm::StringMap<std::vector<InputSection *>> customSectionMapping;
@@ -852,7 +851,7 @@ void Writer::createSyntheticSections() {
out.globalSec = make<GlobalSection>();
out.eventSec = make<EventSection>();
out.exportSec = make<ExportSection>();
- out.elemSec = make<ElemSection>(tableBase);
+ out.elemSec = make<ElemSection>();
out.dataCountSec = make<DataCountSection>(segments.size());
out.linkingSec = make<LinkingSection>(initFunctions, segments);
out.nameSec = make<NameSection>();
@@ -867,9 +866,9 @@ void Writer::run() {
// For PIC code the table base is assigned dynamically by the loader.
// For non-PIC, we start at 1 so that accessing table index 0 always traps.
if (!config->isPic) {
- tableBase = 1;
+ config->tableBase = 1;
if (WasmSym::definedTableBase)
- WasmSym::definedTableBase->setVirtualAddress(tableBase);
+ WasmSym::definedTableBase->setVirtualAddress(config->tableBase);
}
log("-- createOutputSegments");
More information about the llvm-commits
mailing list