Make functions and member variables distinguishable even after the name style change. NFC.

llvm-svn: 365605
This commit is contained in:
Rui Ueyama 2019-07-10 09:10:01 +00:00
parent ed143c5d59
commit 7e296adec7
14 changed files with 69 additions and 72 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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);
});

View File

@ -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) {

View File

@ -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};
}

View File

@ -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; }

View File

@ -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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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");

View File

@ -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;

View File

@ -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();
}