}
uint32_t ImportSection::numImports() const {
+ assert(IsSealed);
uint32_t NumImports = ImportedSymbols.size() + GOTSymbols.size();
if (Config->ImportMemory)
++NumImports;
}
void ImportSection::addGOTEntry(Symbol *Sym) {
+ assert(!IsSealed);
if (Sym->hasGOTIndex())
return;
Sym->setGOTIndex(NumImportedGlobals++);
}
void ImportSection::addImport(Symbol *Sym) {
+ assert(!IsSealed);
ImportedSymbols.emplace_back(Sym);
if (auto *F = dyn_cast<FunctionSymbol>(Sym))
F->setFunctionIndex(NumImportedFunctions++);
if (!Func->Live)
return;
uint32_t FunctionIndex =
- Out.ImportSec->NumImportedFunctions + InputFunctions.size();
+ Out.ImportSec->numImportedFunctions() + InputFunctions.size();
InputFunctions.emplace_back(Func);
Func->setFunctionIndex(FunctionIndex);
}
if (!Global->Live)
return;
uint32_t GlobalIndex =
- Out.ImportSec->NumImportedGlobals + InputGlobals.size();
+ Out.ImportSec->numImportedGlobals() + InputGlobals.size();
LLVM_DEBUG(dbgs() << "addGlobal: " << GlobalIndex << "\n");
Global->setGlobalIndex(GlobalIndex);
Out.GlobalSec->InputGlobals.push_back(Global);
void EventSection::addEvent(InputEvent *Event) {
if (!Event->Live)
return;
- uint32_t EventIndex = Out.ImportSec->NumImportedEvents + InputEvents.size();
+ uint32_t EventIndex = Out.ImportSec->numImportedEvents() + InputEvents.size();
LLVM_DEBUG(dbgs() << "addEvent: " << EventIndex << "\n");
Event->setEventIndex(EventIndex);
InputEvents.push_back(Event);
}
unsigned NameSection::numNames() const {
- unsigned NumNames = Out.ImportSec->NumImportedFunctions;
+ unsigned NumNames = Out.ImportSec->numImportedFunctions();
for (const InputFunction *F : Out.FunctionSec->InputFunctions)
if (!F->getName().empty() || !F->getDebugName().empty())
++NumNames;
void writeBody() override;
void addImport(Symbol *Sym);
void addGOTEntry(Symbol *Sym);
+ void seal() { IsSealed = true; }
uint32_t numImports() const;
+ uint32_t numImportedGlobals() const {
+ assert(IsSealed);
+ return NumImportedGlobals;
+ }
+ uint32_t numImportedFunctions() const {
+ assert(IsSealed);
+ return NumImportedFunctions;
+ }
+ uint32_t numImportedEvents() const {
+ assert(IsSealed);
+ return NumImportedEvents;
+ }
- unsigned NumImportedGlobals = 0;
- unsigned NumImportedFunctions = 0;
- unsigned NumImportedEvents = 0;
std::vector<const Symbol *> ImportedSymbols;
protected:
+ bool IsSealed = false;
+ unsigned NumImportedGlobals = 0;
+ unsigned NumImportedFunctions = 0;
+ unsigned NumImportedEvents = 0;
std::vector<const Symbol *> GOTSymbols;
};
WasmExport{FunctionTableName, WASM_EXTERNAL_TABLE, 0});
unsigned FakeGlobalIndex =
- Out.ImportSec->NumImportedGlobals + Out.GlobalSec->InputGlobals.size();
+ Out.ImportSec->numImportedGlobals() + Out.GlobalSec->InputGlobals.size();
for (Symbol *Sym : Symtab->getSymbols()) {
if (!Sym->isExported())
}
void Writer::assignIndexes() {
- assert(Out.FunctionSec->InputFunctions.empty());
+ // Seal the import section, since other index spaces such as function and
+ // global are effected by the number of imports.
+ Out.ImportSec->seal();
for (InputFunction *Func : Symtab->SyntheticFunctions)
Out.FunctionSec->addFunction(Func);
Out.FunctionSec->addFunction(Func);
}
- scanRelocations();
-
for (InputGlobal *Global : Symtab->SyntheticGlobals)
Out.GlobalSec->addGlobal(Global);
populateTargetFeatures();
log("-- calculateImports");
calculateImports();
+ log("-- scanRelocations");
+ scanRelocations();
log("-- assignIndexes");
assignIndexes();
log("-- calculateInitFunctions");
log("Defined Functions: " + Twine(Out.FunctionSec->InputFunctions.size()));
log("Defined Globals : " + Twine(Out.GlobalSec->InputGlobals.size()));
log("Defined Events : " + Twine(Out.EventSec->InputEvents.size()));
- log("Function Imports : " + Twine(Out.ImportSec->NumImportedFunctions));
- log("Global Imports : " + Twine(Out.ImportSec->NumImportedGlobals));
- log("Event Imports : " + Twine(Out.ImportSec->NumImportedEvents));
+ log("Function Imports : " + Twine(Out.ImportSec->numImportedFunctions()));
+ log("Global Imports : " + Twine(Out.ImportSec->numImportedGlobals()));
+ log("Event Imports : " + Twine(Out.ImportSec->numImportedEvents()));
for (ObjFile *File : Symtab->ObjectFiles)
File->dumpInfo();
}