diff options
Diffstat (limited to 'lld/wasm/Symbols.cpp')
-rw-r--r-- | lld/wasm/Symbols.cpp | 302 |
1 files changed, 151 insertions, 151 deletions
diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp index 941f500732b..61868f37577 100644 --- a/lld/wasm/Symbols.cpp +++ b/lld/wasm/Symbols.cpp @@ -24,16 +24,16 @@ using namespace llvm::wasm; using namespace lld; using namespace lld::wasm; -DefinedFunction *WasmSym::CallCtors; -DefinedFunction *WasmSym::InitMemory; -DefinedFunction *WasmSym::ApplyRelocs; -DefinedData *WasmSym::DsoHandle; -DefinedData *WasmSym::DataEnd; -DefinedData *WasmSym::GlobalBase; -DefinedData *WasmSym::HeapBase; -GlobalSymbol *WasmSym::StackPointer; -UndefinedGlobal *WasmSym::TableBase; -UndefinedGlobal *WasmSym::MemoryBase; +DefinedFunction *WasmSym::callCtors; +DefinedFunction *WasmSym::initMemory; +DefinedFunction *WasmSym::applyRelocs; +DefinedData *WasmSym::dsoHandle; +DefinedData *WasmSym::dataEnd; +DefinedData *WasmSym::globalBase; +DefinedData *WasmSym::heapBase; +GlobalSymbol *WasmSym::stackPointer; +UndefinedGlobal *WasmSym::tableBase; +UndefinedGlobal *WasmSym::memoryBase; WasmSymbolType Symbol::getWasmType() const { if (isa<FunctionSymbol>(this)) @@ -50,248 +50,248 @@ WasmSymbolType Symbol::getWasmType() const { } const WasmSignature *Symbol::getSignature() const { - if (auto* F = dyn_cast<FunctionSymbol>(this)) - return F->Signature; - if (auto *L = dyn_cast<LazySymbol>(this)) - return L->Signature; + if (auto* f = dyn_cast<FunctionSymbol>(this)) + return f->signature; + if (auto *l = dyn_cast<LazySymbol>(this)) + return l->signature; return nullptr; } InputChunk *Symbol::getChunk() const { - if (auto *F = dyn_cast<DefinedFunction>(this)) - return F->Function; - if (auto *D = dyn_cast<DefinedData>(this)) - return D->Segment; + if (auto *f = dyn_cast<DefinedFunction>(this)) + return f->function; + if (auto *d = dyn_cast<DefinedData>(this)) + return d->segment; return nullptr; } bool Symbol::isDiscarded() const { - if (InputChunk *C = getChunk()) - return C->Discarded; + if (InputChunk *c = getChunk()) + return c->discarded; return false; } bool Symbol::isLive() const { - if (auto *G = dyn_cast<DefinedGlobal>(this)) - return G->Global->Live; - if (auto *E = dyn_cast<DefinedEvent>(this)) - return E->Event->Live; - if (InputChunk *C = getChunk()) - return C->Live; - return Referenced; + if (auto *g = dyn_cast<DefinedGlobal>(this)) + return g->global->live; + if (auto *e = dyn_cast<DefinedEvent>(this)) + return e->event->live; + if (InputChunk *c = getChunk()) + return c->live; + return referenced; } void Symbol::markLive() { assert(!isDiscarded()); - if (auto *G = dyn_cast<DefinedGlobal>(this)) - G->Global->Live = true; - if (auto *E = dyn_cast<DefinedEvent>(this)) - E->Event->Live = true; - if (InputChunk *C = getChunk()) - C->Live = true; - Referenced = true; + if (auto *g = dyn_cast<DefinedGlobal>(this)) + g->global->live = true; + if (auto *e = dyn_cast<DefinedEvent>(this)) + e->event->live = true; + if (InputChunk *c = getChunk()) + c->live = true; + referenced = true; } uint32_t Symbol::getOutputSymbolIndex() const { - assert(OutputSymbolIndex != INVALID_INDEX); - return OutputSymbolIndex; + assert(outputSymbolIndex != INVALID_INDEX); + return outputSymbolIndex; } -void Symbol::setOutputSymbolIndex(uint32_t Index) { - LLVM_DEBUG(dbgs() << "setOutputSymbolIndex " << Name << " -> " << Index +void Symbol::setOutputSymbolIndex(uint32_t index) { + LLVM_DEBUG(dbgs() << "setOutputSymbolIndex " << name << " -> " << index << "\n"); - assert(OutputSymbolIndex == INVALID_INDEX); - OutputSymbolIndex = Index; + assert(outputSymbolIndex == INVALID_INDEX); + outputSymbolIndex = index; } -void Symbol::setGOTIndex(uint32_t Index) { - LLVM_DEBUG(dbgs() << "setGOTIndex " << Name << " -> " << Index << "\n"); - assert(GOTIndex == INVALID_INDEX); +void Symbol::setGOTIndex(uint32_t index) { + LLVM_DEBUG(dbgs() << "setGOTIndex " << name << " -> " << index << "\n"); + assert(gotIndex == INVALID_INDEX); // Any symbol that is assigned a GOT entry must be exported othewise the // dynamic linker won't be able create the entry that contains it. - ForceExport = true; - GOTIndex = Index; + forceExport = true; + gotIndex = index; } bool Symbol::isWeak() const { - return (Flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK; + return (flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK; } bool Symbol::isLocal() const { - return (Flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_LOCAL; + return (flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_LOCAL; } bool Symbol::isHidden() const { - return (Flags & WASM_SYMBOL_VISIBILITY_MASK) == WASM_SYMBOL_VISIBILITY_HIDDEN; + return (flags & WASM_SYMBOL_VISIBILITY_MASK) == WASM_SYMBOL_VISIBILITY_HIDDEN; } -void Symbol::setHidden(bool IsHidden) { - LLVM_DEBUG(dbgs() << "setHidden: " << Name << " -> " << IsHidden << "\n"); - Flags &= ~WASM_SYMBOL_VISIBILITY_MASK; - if (IsHidden) - Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN; +void Symbol::setHidden(bool isHidden) { + LLVM_DEBUG(dbgs() << "setHidden: " << name << " -> " << isHidden << "\n"); + flags &= ~WASM_SYMBOL_VISIBILITY_MASK; + if (isHidden) + flags |= WASM_SYMBOL_VISIBILITY_HIDDEN; else - Flags |= WASM_SYMBOL_VISIBILITY_DEFAULT; + flags |= WASM_SYMBOL_VISIBILITY_DEFAULT; } bool Symbol::isExported() const { if (!isDefined() || isLocal()) return false; - if (ForceExport || Config->ExportAll) + if (forceExport || config->exportAll) return true; - if (Config->ExportDynamic && !isHidden()) + if (config->exportDynamic && !isHidden()) return true; - return Flags & WASM_SYMBOL_EXPORTED; + return flags & WASM_SYMBOL_EXPORTED; } uint32_t FunctionSymbol::getFunctionIndex() const { - if (auto *F = dyn_cast<DefinedFunction>(this)) - return F->Function->getFunctionIndex(); - assert(FunctionIndex != INVALID_INDEX); - return FunctionIndex; + if (auto *f = dyn_cast<DefinedFunction>(this)) + return f->function->getFunctionIndex(); + assert(functionIndex != INVALID_INDEX); + return functionIndex; } -void FunctionSymbol::setFunctionIndex(uint32_t Index) { - LLVM_DEBUG(dbgs() << "setFunctionIndex " << Name << " -> " << Index << "\n"); - assert(FunctionIndex == INVALID_INDEX); - FunctionIndex = Index; +void FunctionSymbol::setFunctionIndex(uint32_t index) { + LLVM_DEBUG(dbgs() << "setFunctionIndex " << name << " -> " << index << "\n"); + assert(functionIndex == INVALID_INDEX); + functionIndex = index; } bool FunctionSymbol::hasFunctionIndex() const { - if (auto *F = dyn_cast<DefinedFunction>(this)) - return F->Function->hasFunctionIndex(); - return FunctionIndex != INVALID_INDEX; + if (auto *f = dyn_cast<DefinedFunction>(this)) + return f->function->hasFunctionIndex(); + return functionIndex != INVALID_INDEX; } uint32_t FunctionSymbol::getTableIndex() const { - if (auto *F = dyn_cast<DefinedFunction>(this)) - return F->Function->getTableIndex(); - assert(TableIndex != INVALID_INDEX); - return TableIndex; + if (auto *f = dyn_cast<DefinedFunction>(this)) + return f->function->getTableIndex(); + assert(tableIndex != INVALID_INDEX); + return tableIndex; } bool FunctionSymbol::hasTableIndex() const { - if (auto *F = dyn_cast<DefinedFunction>(this)) - return F->Function->hasTableIndex(); - return TableIndex != INVALID_INDEX; + if (auto *f = dyn_cast<DefinedFunction>(this)) + return f->function->hasTableIndex(); + return tableIndex != INVALID_INDEX; } -void FunctionSymbol::setTableIndex(uint32_t Index) { +void FunctionSymbol::setTableIndex(uint32_t index) { // For imports, we set the table index here on the Symbol; for defined // functions we set the index on the InputFunction so that we don't export // the same thing twice (keeps the table size down). - if (auto *F = dyn_cast<DefinedFunction>(this)) { - F->Function->setTableIndex(Index); + if (auto *f = dyn_cast<DefinedFunction>(this)) { + f->function->setTableIndex(index); return; } - LLVM_DEBUG(dbgs() << "setTableIndex " << Name << " -> " << Index << "\n"); - assert(TableIndex == INVALID_INDEX); - TableIndex = Index; + LLVM_DEBUG(dbgs() << "setTableIndex " << name << " -> " << index << "\n"); + assert(tableIndex == INVALID_INDEX); + tableIndex = index; } -DefinedFunction::DefinedFunction(StringRef Name, uint32_t Flags, InputFile *F, - InputFunction *Function) - : FunctionSymbol(Name, DefinedFunctionKind, Flags, F, - Function ? &Function->Signature : nullptr), - Function(Function) {} +DefinedFunction::DefinedFunction(StringRef name, uint32_t flags, InputFile *f, + InputFunction *function) + : FunctionSymbol(name, DefinedFunctionKind, flags, f, + function ? &function->signature : nullptr), + function(function) {} uint32_t DefinedData::getVirtualAddress() const { LLVM_DEBUG(dbgs() << "getVirtualAddress: " << getName() << "\n"); - if (Segment) - return Segment->OutputSeg->StartVA + Segment->OutputSegmentOffset + Offset; - return Offset; + if (segment) + return segment->outputSeg->startVA + segment->outputSegmentOffset + offset; + return offset; } -void DefinedData::setVirtualAddress(uint32_t Value) { - LLVM_DEBUG(dbgs() << "setVirtualAddress " << Name << " -> " << Value << "\n"); - assert(!Segment); - Offset = Value; +void DefinedData::setVirtualAddress(uint32_t value) { + LLVM_DEBUG(dbgs() << "setVirtualAddress " << name << " -> " << value << "\n"); + assert(!segment); + offset = value; } uint32_t DefinedData::getOutputSegmentOffset() const { LLVM_DEBUG(dbgs() << "getOutputSegmentOffset: " << getName() << "\n"); - return Segment->OutputSegmentOffset + Offset; + return segment->outputSegmentOffset + offset; } uint32_t DefinedData::getOutputSegmentIndex() const { LLVM_DEBUG(dbgs() << "getOutputSegmentIndex: " << getName() << "\n"); - return Segment->OutputSeg->Index; + return segment->outputSeg->index; } uint32_t GlobalSymbol::getGlobalIndex() const { - if (auto *F = dyn_cast<DefinedGlobal>(this)) - return F->Global->getGlobalIndex(); - assert(GlobalIndex != INVALID_INDEX); - return GlobalIndex; + if (auto *f = dyn_cast<DefinedGlobal>(this)) + return f->global->getGlobalIndex(); + assert(globalIndex != INVALID_INDEX); + return globalIndex; } -void GlobalSymbol::setGlobalIndex(uint32_t Index) { - LLVM_DEBUG(dbgs() << "setGlobalIndex " << Name << " -> " << Index << "\n"); - assert(GlobalIndex == INVALID_INDEX); - GlobalIndex = Index; +void GlobalSymbol::setGlobalIndex(uint32_t index) { + LLVM_DEBUG(dbgs() << "setGlobalIndex " << name << " -> " << index << "\n"); + assert(globalIndex == INVALID_INDEX); + globalIndex = index; } bool GlobalSymbol::hasGlobalIndex() const { - if (auto *F = dyn_cast<DefinedGlobal>(this)) - return F->Global->hasGlobalIndex(); - return GlobalIndex != INVALID_INDEX; + if (auto *f = dyn_cast<DefinedGlobal>(this)) + return f->global->hasGlobalIndex(); + return globalIndex != INVALID_INDEX; } -DefinedGlobal::DefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File, - InputGlobal *Global) - : GlobalSymbol(Name, DefinedGlobalKind, Flags, File, - Global ? &Global->getType() : nullptr), - Global(Global) {} +DefinedGlobal::DefinedGlobal(StringRef name, uint32_t flags, InputFile *file, + InputGlobal *global) + : GlobalSymbol(name, DefinedGlobalKind, flags, file, + global ? &global->getType() : nullptr), + global(global) {} uint32_t EventSymbol::getEventIndex() const { - if (auto *F = dyn_cast<DefinedEvent>(this)) - return F->Event->getEventIndex(); - assert(EventIndex != INVALID_INDEX); - return EventIndex; + if (auto *f = dyn_cast<DefinedEvent>(this)) + return f->event->getEventIndex(); + assert(eventIndex != INVALID_INDEX); + return eventIndex; } -void EventSymbol::setEventIndex(uint32_t Index) { - LLVM_DEBUG(dbgs() << "setEventIndex " << Name << " -> " << Index << "\n"); - assert(EventIndex == INVALID_INDEX); - EventIndex = Index; +void EventSymbol::setEventIndex(uint32_t index) { + LLVM_DEBUG(dbgs() << "setEventIndex " << name << " -> " << index << "\n"); + assert(eventIndex == INVALID_INDEX); + eventIndex = index; } bool EventSymbol::hasEventIndex() const { - if (auto *F = dyn_cast<DefinedEvent>(this)) - return F->Event->hasEventIndex(); - return EventIndex != INVALID_INDEX; + if (auto *f = dyn_cast<DefinedEvent>(this)) + return f->event->hasEventIndex(); + return eventIndex != INVALID_INDEX; } -DefinedEvent::DefinedEvent(StringRef Name, uint32_t Flags, InputFile *File, - InputEvent *Event) - : EventSymbol(Name, DefinedEventKind, Flags, File, - Event ? &Event->getType() : nullptr, - Event ? &Event->Signature : nullptr), - Event(Event) {} +DefinedEvent::DefinedEvent(StringRef name, uint32_t flags, InputFile *file, + InputEvent *event) + : EventSymbol(name, DefinedEventKind, flags, file, + event ? &event->getType() : nullptr, + event ? &event->signature : nullptr), + event(event) {} const OutputSectionSymbol *SectionSymbol::getOutputSectionSymbol() const { - assert(Section->OutputSec && Section->OutputSec->SectionSym); - return Section->OutputSec->SectionSym; + assert(section->outputSec && section->outputSec->sectionSym); + return section->outputSec->sectionSym; } -void LazySymbol::fetch() { cast<ArchiveFile>(File)->addMember(&ArchiveSymbol); } +void LazySymbol::fetch() { cast<ArchiveFile>(file)->addMember(&archiveSymbol); } -std::string lld::toString(const wasm::Symbol &Sym) { - return lld::maybeDemangleSymbol(Sym.getName()); +std::string lld::toString(const wasm::Symbol &sym) { + return lld::maybeDemangleSymbol(sym.getName()); } -std::string lld::maybeDemangleSymbol(StringRef Name) { - if (Config->Demangle) - if (Optional<std::string> S = demangleItanium(Name)) - return *S; - return Name; +std::string lld::maybeDemangleSymbol(StringRef name) { + if (config->demangle) + if (Optional<std::string> s = demangleItanium(name)) + return *s; + return name; } -std::string lld::toString(wasm::Symbol::Kind Kind) { - switch (Kind) { +std::string lld::toString(wasm::Symbol::Kind kind) { + switch (kind) { case wasm::Symbol::DefinedFunctionKind: return "DefinedFunction"; case wasm::Symbol::DefinedDataKind: @@ -317,24 +317,24 @@ std::string lld::toString(wasm::Symbol::Kind Kind) { } -void lld::wasm::printTraceSymbolUndefined(StringRef Name, const InputFile* File) { - message(toString(File) + ": reference to " + Name); +void lld::wasm::printTraceSymbolUndefined(StringRef name, const InputFile* file) { + message(toString(file) + ": reference to " + name); } // Print out a log message for --trace-symbol. -void lld::wasm::printTraceSymbol(Symbol *Sym) { +void lld::wasm::printTraceSymbol(Symbol *sym) { // Undefined symbols are traced via printTraceSymbolUndefined - if (Sym->isUndefined()) + if (sym->isUndefined()) return; - std::string S; - if (Sym->isLazy()) - S = ": lazy definition of "; + std::string s; + if (sym->isLazy()) + s = ": lazy definition of "; else - S = ": definition of "; + s = ": definition of "; - message(toString(Sym->getFile()) + S + Sym->getName()); + message(toString(sym->getFile()) + s + sym->getName()); } -const char *lld::wasm::DefaultModule = "env"; -const char *lld::wasm::FunctionTableName = "__indirect_function_table"; +const char *lld::wasm::defaultModule = "env"; +const char *lld::wasm::functionTableName = "__indirect_function_table"; |