diff options
author | Rui Ueyama <ruiu@google.com> | 2019-07-10 09:10:01 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2019-07-10 09:10:01 +0000 |
commit | 980a5a6e0d3362e826cf17eeff294caa5c854ea6 (patch) | |
tree | 2b142f62e18035ef65f96d816e9232e9d8e61b23 | |
parent | 2a8cc896d539471956d260742b5d78b0a8cc1e25 (diff) |
Make functions and member variables distinguishable even after the name style change. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@365605 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | COFF/Chunks.cpp | 2 | ||||
-rw-r--r-- | COFF/Chunks.h | 11 | ||||
-rw-r--r-- | COFF/Driver.cpp | 6 | ||||
-rw-r--r-- | COFF/InputFiles.cpp | 2 | ||||
-rw-r--r-- | COFF/SymbolTable.cpp | 2 | ||||
-rw-r--r-- | COFF/Symbols.h | 6 | ||||
-rw-r--r-- | COFF/Writer.cpp | 4 | ||||
-rw-r--r-- | wasm/InputChunks.h | 2 | ||||
-rw-r--r-- | wasm/OutputSections.cpp | 12 | ||||
-rw-r--r-- | wasm/OutputSections.h | 8 | ||||
-rw-r--r-- | wasm/SymbolTable.cpp | 38 | ||||
-rw-r--r-- | wasm/SyntheticSections.cpp | 15 | ||||
-rw-r--r-- | wasm/SyntheticSections.h | 12 | ||||
-rw-r--r-- | wasm/Writer.cpp | 21 |
14 files changed, 69 insertions, 72 deletions
diff --git a/COFF/Chunks.cpp b/COFF/Chunks.cpp index fbae6f9a2..4bad91d26 100644 --- a/COFF/Chunks.cpp +++ b/COFF/Chunks.cpp @@ -348,7 +348,7 @@ static void maybeReportRelocationToDiscarded(const SectionChunk *FromChunk, } void SectionChunk::writeTo(uint8_t *Buf) const { - if (!hasData()) + if (!HasData) return; // Copy section contents from source object file to output file. ArrayRef<uint8_t> A = getContents(); diff --git a/COFF/Chunks.h b/COFF/Chunks.h index 0df168be7..625a09245 100644 --- a/COFF/Chunks.h +++ b/COFF/Chunks.h @@ -90,11 +90,6 @@ public: assert(RVA == V && "RVA truncated"); } - // Returns true if this has non-zero data. BSS chunks return - // false. If false is returned, the space occupied by this chunk - // will be filled with zeros. - bool hasData() const { return HasData; } - // Returns readable/writable/executable bits. uint32_t getOutputCharacteristics() const; @@ -126,10 +121,14 @@ protected: const Kind ChunkKind; - // True if the section has data. Corresponds to the +public: + // Returns true if this has non-zero data. BSS chunks return + // false. If false is returned, the space occupied by this chunk + // will be filled with zeros. Corresponds to the // IMAGE_SCN_CNT_UNINITIALIZED_DATA section characteristic bit. uint8_t HasData : 1; +public: // The alignment of this chunk, stored in log2 form. The writer uses the // value. uint8_t P2Align : 7; diff --git a/COFF/Driver.cpp b/COFF/Driver.cpp index 6a95fafbb..24937abcb 100644 --- a/COFF/Driver.cpp +++ b/COFF/Driver.cpp @@ -210,7 +210,7 @@ void LinkerDriver::enqueuePath(StringRef Path, bool WholeArchive) { enqueueTask([=]() { auto MBOrErr = Future->get(); if (MBOrErr.second) { - std::string Error = + std::string Msg = "could not open '" + PathStr + "': " + MBOrErr.second.message(); // Check if the filename is a typo for an option flag. OptTable thinks // that all args that are not known options and that start with / are @@ -219,9 +219,9 @@ void LinkerDriver::enqueuePath(StringRef Path, bool WholeArchive) { // directory. std::string Nearest; if (COFFOptTable().findNearest(PathStr, Nearest) > 1) - error(Error); + error(Msg); else - error(Error + "; did you mean '" + Nearest + "'"); + error(Msg + "; did you mean '" + Nearest + "'"); } else Driver->addBuffer(std::move(MBOrErr.first), WholeArchive); }); diff --git a/COFF/InputFiles.cpp b/COFF/InputFiles.cpp index ebf6e4418..aac3b40c1 100644 --- a/COFF/InputFiles.cpp +++ b/COFF/InputFiles.cpp @@ -582,7 +582,7 @@ Optional<Symbol *> ObjFile::createDefined( } COMDATType Selection = (COMDATType)Def->Selection; - if (Leader->isCOMDAT()) + if (Leader->IsCOMDAT) handleComdatSelection(Sym, Selection, Prevailing, Leader); if (Prevailing) { diff --git a/COFF/SymbolTable.cpp b/COFF/SymbolTable.cpp index cbdce10b6..023b40167 100644 --- a/COFF/SymbolTable.cpp +++ b/COFF/SymbolTable.cpp @@ -458,7 +458,7 @@ SymbolTable::addComdat(InputFile *F, StringRef N, return {cast<DefinedRegular>(S), true}; } auto *ExistingSymbol = cast<DefinedRegular>(S); - if (!ExistingSymbol->isCOMDAT()) + if (!ExistingSymbol->IsCOMDAT) reportDuplicate(S, F); return {ExistingSymbol, false}; } diff --git a/COFF/Symbols.h b/COFF/Symbols.h index ee0c0e7b0..53e45a806 100644 --- a/COFF/Symbols.h +++ b/COFF/Symbols.h @@ -59,9 +59,6 @@ public: Kind kind() const { return static_cast<Kind>(SymbolKind); } - // Returns true if this is an external symbol. - bool isExternal() { return IsExternal; } - // Returns the symbol name. StringRef getName(); @@ -85,10 +82,10 @@ protected: const unsigned SymbolKind : 8; unsigned IsExternal : 1; +public: // This bit is used by the \c DefinedRegular subclass. unsigned IsCOMDAT : 1; -public: // This bit is used by Writer::createSymbolAndStringTable() to prevent // symbols from being written to the symbol table more than once. unsigned WrittenToSymtab : 1; @@ -172,7 +169,6 @@ public: } uint64_t getRVA() const { return (*Data)->getRVA() + Sym->Value; } - bool isCOMDAT() const { return IsCOMDAT; } SectionChunk *getChunk() const { return *Data; } uint32_t getValue() const { return Sym->Value; } diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp index 47e2c9aa4..64ed0a15f 100644 --- a/COFF/Writer.cpp +++ b/COFF/Writer.cpp @@ -1202,7 +1202,7 @@ void Writer::assignAddresses() { VirtualSize = alignTo(VirtualSize, C->getAlignment()); C->setRVA(RVA + VirtualSize); VirtualSize += C->getSize(); - if (C->hasData()) + if (C->HasData) RawSize = alignTo(VirtualSize, Config->FileAlign); } if (VirtualSize > UINT32_MAX) @@ -1377,7 +1377,7 @@ template <typename PEHeaderTy> void Writer::writeHeader() { SectionChunk *SC = B->getChunk(); assert(B->getRVA() >= SC->getRVA()); uint64_t OffsetInChunk = B->getRVA() - SC->getRVA(); - if (!SC->hasData() || OffsetInChunk + 4 > SC->getSize()) + if (!SC->HasData || OffsetInChunk + 4 > SC->getSize()) fatal("_load_config_used is malformed"); ArrayRef<uint8_t> SecContents = SC->getContents(); diff --git a/wasm/InputChunks.h b/wasm/InputChunks.h index ba2bb6f0e..b8e4c3273 100644 --- a/wasm/InputChunks.h +++ b/wasm/InputChunks.h @@ -53,7 +53,7 @@ public: StringRef getComdatName() const; virtual uint32_t getInputSectionOffset() const = 0; - size_t NumRelocations() const { return Relocations.size(); } + size_t getNumRelocations() const { return Relocations.size(); } void writeRelocations(llvm::raw_ostream &OS) const; ObjFile *File; diff --git a/wasm/OutputSections.cpp b/wasm/OutputSections.cpp index 77f727902..d5434b102 100644 --- a/wasm/OutputSections.cpp +++ b/wasm/OutputSections.cpp @@ -113,10 +113,10 @@ void CodeSection::writeTo(uint8_t *Buf) { Chunk->writeTo(Buf); } -uint32_t CodeSection::numRelocations() const { +uint32_t CodeSection::getNumRelocations() const { uint32_t Count = 0; for (const InputChunk *Func : Functions) - Count += Func->NumRelocations(); + Count += Func->getNumRelocations(); return Count; } @@ -190,11 +190,11 @@ void DataSection::writeTo(uint8_t *Buf) { } } -uint32_t DataSection::numRelocations() const { +uint32_t DataSection::getNumRelocations() const { uint32_t Count = 0; for (const OutputSegment *Seg : Segments) for (const InputChunk *InputSeg : Seg->InputSegments) - Count += InputSeg->NumRelocations(); + Count += InputSeg->getNumRelocations(); return Count; } @@ -237,10 +237,10 @@ void CustomSection::writeTo(uint8_t *Buf) { Section->writeTo(Buf); } -uint32_t CustomSection::numRelocations() const { +uint32_t CustomSection::getNumRelocations() const { uint32_t Count = 0; for (const InputSection *InputSect : InputSections) - Count += InputSect->NumRelocations(); + Count += InputSect->getNumRelocations(); return Count; } diff --git a/wasm/OutputSections.h b/wasm/OutputSections.h index feee5cf2d..3045ed7c5 100644 --- a/wasm/OutputSections.h +++ b/wasm/OutputSections.h @@ -42,7 +42,7 @@ public: virtual size_t getSize() const = 0; virtual void writeTo(uint8_t *Buf) = 0; virtual void finalizeContents() = 0; - virtual uint32_t numRelocations() const { return 0; } + virtual uint32_t getNumRelocations() const { return 0; } virtual void writeRelocations(raw_ostream &OS) const {} std::string Header; @@ -62,7 +62,7 @@ public: size_t getSize() const override { return Header.size() + BodySize; } void writeTo(uint8_t *Buf) override; - uint32_t numRelocations() const override; + uint32_t getNumRelocations() const override; void writeRelocations(raw_ostream &OS) const override; bool isNeeded() const override { return Functions.size() > 0; } void finalizeContents() override; @@ -80,7 +80,7 @@ public: size_t getSize() const override { return Header.size() + BodySize; } void writeTo(uint8_t *Buf) override; - uint32_t numRelocations() const override; + uint32_t getNumRelocations() const override; void writeRelocations(raw_ostream &OS) const override; bool isNeeded() const override { return Segments.size() > 0; } void finalizeContents() override; @@ -107,7 +107,7 @@ public: return Header.size() + NameData.size() + PayloadSize; } void writeTo(uint8_t *Buf) override; - uint32_t numRelocations() const override; + uint32_t getNumRelocations() const override; void writeRelocations(raw_ostream &OS) const override; void finalizeContents() override; diff --git a/wasm/SymbolTable.cpp b/wasm/SymbolTable.cpp index 1a391eff7..35ceed6d2 100644 --- a/wasm/SymbolTable.cpp +++ b/wasm/SymbolTable.cpp @@ -274,7 +274,7 @@ Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags, bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); - auto Replace = [&](Symbol* Sym) { + auto ReplaceSym = [&](Symbol *Sym) { // If the new defined function doesn't have signture (i.e. bitcode // functions) but the old symbol does, then preserve the old signature const WasmSignature *OldSig = S->getSignature(); @@ -284,7 +284,7 @@ Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags, }; if (WasInserted || S->isLazy()) { - Replace(S); + ReplaceSym(S); return S; } @@ -302,10 +302,10 @@ Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags, Symbol* Variant; if (getFunctionVariant(S, &Function->Signature, File, &Variant)) // New variant, always replace - Replace(Variant); + ReplaceSym(Variant); else if (shouldReplace(S, File, Flags)) // Variant already exists, replace it after checking shouldReplace - Replace(Variant); + ReplaceSym(Variant); // This variant we found take the place in the symbol table as the primary // variant. @@ -315,7 +315,7 @@ Symbol *SymbolTable::addDefinedFunction(StringRef Name, uint32_t Flags, // Existing function with matching signature. if (shouldReplace(S, File, Flags)) - Replace(S); + ReplaceSym(S); return S; } @@ -329,19 +329,19 @@ Symbol *SymbolTable::addDefinedData(StringRef Name, uint32_t Flags, bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); - auto Replace = [&]() { + auto ReplaceSym = [&]() { replaceSymbol<DefinedData>(S, Name, Flags, File, Segment, Address, Size); }; if (WasInserted || S->isLazy()) { - Replace(); + ReplaceSym(); return S; } checkDataType(S, File); if (shouldReplace(S, File, Flags)) - Replace(); + ReplaceSym(); return S; } @@ -353,19 +353,19 @@ Symbol *SymbolTable::addDefinedGlobal(StringRef Name, uint32_t Flags, bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); - auto Replace = [&]() { + auto ReplaceSym = [&]() { replaceSymbol<DefinedGlobal>(S, Name, Flags, File, Global); }; if (WasInserted || S->isLazy()) { - Replace(); + ReplaceSym(); return S; } checkGlobalType(S, File, &Global->getType()); if (shouldReplace(S, File, Flags)) - Replace(); + ReplaceSym(); return S; } @@ -377,19 +377,19 @@ Symbol *SymbolTable::addDefinedEvent(StringRef Name, uint32_t Flags, bool WasInserted; std::tie(S, WasInserted) = insert(Name, File); - auto Replace = [&]() { + auto ReplaceSym = [&]() { replaceSymbol<DefinedEvent>(S, Name, Flags, File, Event); }; if (WasInserted || S->isLazy()) { - Replace(); + ReplaceSym(); return S; } checkEventType(S, File, &Event->getType(), &Event->Signature); if (shouldReplace(S, File, Flags)) - Replace(); + ReplaceSym(); return S; } @@ -408,13 +408,13 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef ImportName, if (S->Traced) printTraceSymbolUndefined(Name, File); - auto Replace = [&]() { + auto ReplaceSym = [&]() { replaceSymbol<UndefinedFunction>(S, Name, ImportName, ImportModule, Flags, File, Sig, IsCalledDirectly); }; if (WasInserted) - Replace(); + ReplaceSym(); else if (auto *Lazy = dyn_cast<LazySymbol>(S)) Lazy->fetch(); else { @@ -427,7 +427,7 @@ Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef ImportName, ExistingFunction->Signature = Sig; if (IsCalledDirectly && !signatureMatches(ExistingFunction, Sig)) if (getFunctionVariant(S, Sig, File, &S)) - Replace(); + ReplaceSym(); } return S; @@ -623,13 +623,13 @@ void SymbolTable::handleWeakUndefines() { static void reportFunctionSignatureMismatch(StringRef SymName, FunctionSymbol *A, - FunctionSymbol *B, bool Error) { + FunctionSymbol *B, bool IsError) { std::string msg = ("function signature mismatch: " + SymName + "\n>>> defined as " + toString(*A->Signature) + " in " + toString(A->getFile()) + "\n>>> defined as " + toString(*B->Signature) + " in " + toString(B->getFile())) .str(); - if (Error) + if (IsError) error(msg); else warn(msg); diff --git a/wasm/SyntheticSections.cpp b/wasm/SyntheticSections.cpp index 2480ff2a0..8e8a0a13d 100644 --- a/wasm/SyntheticSections.cpp +++ b/wasm/SyntheticSections.cpp @@ -91,7 +91,7 @@ void TypeSection::writeBody() { writeSig(BodyOutputStream, *Sig); } -uint32_t ImportSection::numImports() const { +uint32_t ImportSection::getNumImports() const { assert(IsSealed); uint32_t NumImports = ImportedSymbols.size() + GOTSymbols.size(); if (Config->ImportMemory) @@ -123,7 +123,7 @@ void ImportSection::addImport(Symbol *Sym) { void ImportSection::writeBody() { raw_ostream &OS = BodyOutputStream; - writeUleb128(OS, numImports(), "import count"); + writeUleb128(OS, getNumImports(), "import count"); if (Config->ImportMemory) { WasmImport Import; @@ -205,7 +205,7 @@ void FunctionSection::addFunction(InputFunction *Func) { if (!Func->Live) return; uint32_t FunctionIndex = - Out.ImportSec->numImportedFunctions() + InputFunctions.size(); + Out.ImportSec->getNumImportedFunctions() + InputFunctions.size(); InputFunctions.emplace_back(Func); Func->setFunctionIndex(FunctionIndex); } @@ -254,7 +254,7 @@ void GlobalSection::addGlobal(InputGlobal *Global) { if (!Global->Live) return; uint32_t GlobalIndex = - Out.ImportSec->numImportedGlobals() + InputGlobals.size(); + Out.ImportSec->getNumImportedGlobals() + InputGlobals.size(); LLVM_DEBUG(dbgs() << "addGlobal: " << GlobalIndex << "\n"); Global->setGlobalIndex(GlobalIndex); Out.GlobalSec->InputGlobals.push_back(Global); @@ -273,7 +273,8 @@ void EventSection::writeBody() { void EventSection::addEvent(InputEvent *Event) { if (!Event->Live) return; - uint32_t EventIndex = Out.ImportSec->numImportedEvents() + InputEvents.size(); + uint32_t EventIndex = + Out.ImportSec->getNumImportedEvents() + InputEvents.size(); LLVM_DEBUG(dbgs() << "addEvent: " << EventIndex << "\n"); Event->setEventIndex(EventIndex); InputEvents.push_back(Event); @@ -460,7 +461,7 @@ void LinkingSection::addToSymtab(Symbol *Sym) { } unsigned NameSection::numNames() const { - unsigned NumNames = Out.ImportSec->numImportedFunctions(); + unsigned NumNames = Out.ImportSec->getNumImportedFunctions(); for (const InputFunction *F : Out.FunctionSec->InputFunctions) if (!F->getName().empty() || !F->getDebugName().empty()) ++NumNames; @@ -538,7 +539,7 @@ void TargetFeaturesSection::writeBody() { } void RelocSection::writeBody() { - uint32_t Count = Sec->numRelocations(); + uint32_t Count = Sec->getNumRelocations(); assert(Sec->SectionIndex != UINT32_MAX); writeUleb128(BodyOutputStream, Sec->SectionIndex, "reloc section"); writeUleb128(BodyOutputStream, Count, "reloc count"); diff --git a/wasm/SyntheticSections.h b/wasm/SyntheticSections.h index 9f5266188..c2a9c4b55 100644 --- a/wasm/SyntheticSections.h +++ b/wasm/SyntheticSections.h @@ -97,21 +97,21 @@ protected: class ImportSection : public SyntheticSection { public: ImportSection() : SyntheticSection(llvm::wasm::WASM_SEC_IMPORT) {} - bool isNeeded() const override { return numImports() > 0; } + bool isNeeded() const override { return getNumImports() > 0; } void writeBody() override; void addImport(Symbol *Sym); void addGOTEntry(Symbol *Sym); void seal() { IsSealed = true; } - uint32_t numImports() const; - uint32_t numImportedGlobals() const { + uint32_t getNumImports() const; + uint32_t getNumImportedGlobals() const { assert(IsSealed); return NumImportedGlobals; } - uint32_t numImportedFunctions() const { + uint32_t getNumImportedFunctions() const { assert(IsSealed); return NumImportedFunctions; } - uint32_t numImportedEvents() const { + uint32_t getNumImportedEvents() const { assert(IsSealed); return NumImportedEvents; } @@ -306,7 +306,7 @@ public: RelocSection(StringRef Name, OutputSection *Sec) : SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, Name), Sec(Sec) {} void writeBody() override; - bool isNeeded() const override { return Sec->numRelocations() > 0; }; + bool isNeeded() const override { return Sec->getNumRelocations() > 0; }; protected: OutputSection *Sec; diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp index cc8075aeb..5fabd976e 100644 --- a/wasm/Writer.cpp +++ b/wasm/Writer.cpp @@ -149,7 +149,7 @@ void Writer::createRelocSections() { OutputSection *Sec = OutputSections[I]; // Count the number of needed sections. - uint32_t Count = Sec->numRelocations(); + uint32_t Count = Sec->getNumRelocations(); if (!Count) continue; @@ -474,8 +474,8 @@ void Writer::calculateExports() { Out.ExportSec->Exports.push_back( WasmExport{FunctionTableName, WASM_EXTERNAL_TABLE, 0}); - unsigned FakeGlobalIndex = - Out.ImportSec->numImportedGlobals() + Out.GlobalSec->InputGlobals.size(); + unsigned FakeGlobalIndex = Out.ImportSec->getNumImportedGlobals() + + Out.GlobalSec->InputGlobals.size(); for (Symbol *Sym : Symtab->getSymbols()) { if (!Sym->isExported()) @@ -635,7 +635,7 @@ void Writer::createOutputSegments() { } } -static void CreateFunction(DefinedFunction *Func, StringRef BodyContent) { +static void createFunction(DefinedFunction *Func, StringRef BodyContent) { std::string FunctionBody; { raw_string_ostream OS(FunctionBody); @@ -679,7 +679,7 @@ void Writer::createInitMemoryFunction() { writeU8(OS, WASM_OPCODE_END, "END"); } - CreateFunction(WasmSym::InitMemory, BodyContent); + createFunction(WasmSym::InitMemory, BodyContent); } // For -shared (PIC) output, we create create a synthetic function which will @@ -699,7 +699,7 @@ void Writer::createApplyRelocationsFunction() { writeU8(OS, WASM_OPCODE_END, "END"); } - CreateFunction(WasmSym::ApplyRelocs, BodyContent); + createFunction(WasmSym::ApplyRelocs, BodyContent); } // Create synthetic "__wasm_call_ctors" function based on ctor functions @@ -734,7 +734,7 @@ void Writer::createCallCtorsFunction() { writeU8(OS, WASM_OPCODE_END, "END"); } - CreateFunction(WasmSym::CallCtors, BodyContent); + createFunction(WasmSym::CallCtors, BodyContent); } // Populate InitFunctions vector with init functions from all input objects. @@ -844,9 +844,10 @@ void Writer::run() { 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->getNumImportedFunctions())); + log("Global Imports : " + Twine(Out.ImportSec->getNumImportedGlobals())); + log("Event Imports : " + Twine(Out.ImportSec->getNumImportedEvents())); for (ObjFile *File : Symtab->ObjectFiles) File->dumpInfo(); } |