[lld] 4639a9a - [lld-link] Replace log(...) with Log
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 4 09:04:46 PST 2024
Author: Fangrui Song
Date: 2024-12-04T09:04:40-08:00
New Revision: 4639a9a06387b7ae3b21255d2ac3545e6b183236
URL: https://github.com/llvm/llvm-project/commit/4639a9a06387b7ae3b21255d2ac3545e6b183236
DIFF: https://github.com/llvm/llvm-project/commit/4639a9a06387b7ae3b21255d2ac3545e6b183236.diff
LOG: [lld-link] Replace log(...) with Log
Added:
Modified:
lld/COFF/DebugTypes.cpp
lld/COFF/Driver.cpp
lld/COFF/ICF.cpp
lld/COFF/InputFiles.cpp
lld/COFF/PDB.cpp
lld/COFF/SymbolTable.cpp
lld/COFF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/COFF/DebugTypes.cpp b/lld/COFF/DebugTypes.cpp
index 08f61e0d446214..7cdea0b4516303 100644
--- a/lld/COFF/DebugTypes.cpp
+++ b/lld/COFF/DebugTypes.cpp
@@ -241,10 +241,10 @@ void TpiSource::remapRecord(MutableArrayRef<uint8_t> rec,
uint16_t kind =
reinterpret_cast<const RecordPrefix *>(rec.data())->RecordKind;
StringRef fname = file ? file->getName() : "<unknown PDB>";
- log("failed to remap type index in record of kind 0x" +
- utohexstr(kind) + " in " + fname + " with bad " +
- (ref.Kind == TiRefKind::IndexRef ? "item" : "type") +
- " index 0x" + utohexstr(ti.getIndex()));
+ Log(ctx) << "failed to remap type index in record of kind 0x"
+ << utohexstr(kind) << " in " << fname << " with bad "
+ << (ref.Kind == TiRefKind::IndexRef ? "item" : "type")
+ << " index 0x" << utohexstr(ti.getIndex());
}
ti = TypeIndex(SimpleTypeKind::NotTranslated);
continue;
@@ -1137,9 +1137,10 @@ void TypeMerger::mergeTypesWithGHash() {
entries.push_back(cell);
}
parallelSort(entries, std::less<GHashCell>());
- log(formatv("ghash table load factor: {0:p} (size {1} / capacity {2})\n",
- tableSize ? double(entries.size()) / tableSize : 0,
- entries.size(), tableSize));
+ Log(ctx) << formatv(
+ "ghash table load factor: {0:p} (size {1} / capacity {2})\n",
+ tableSize ? double(entries.size()) / tableSize : 0, entries.size(),
+ tableSize);
// Find out how many type and item indices there are.
auto mid = llvm::lower_bound(entries, GHashCell(true, 0, 0));
@@ -1148,8 +1149,8 @@ void TypeMerger::mergeTypesWithGHash() {
"midpoint is not midpoint");
uint32_t numTypes = std::distance(entries.begin(), mid);
uint32_t numItems = std::distance(mid, entries.end());
- log("Tpi record count: " + Twine(numTypes));
- log("Ipi record count: " + Twine(numItems));
+ Log(ctx) << "Tpi record count: " << Twine(numTypes);
+ Log(ctx) << "Ipi record count: " << Twine(numItems);
// Make a list of the "unique" type records to merge for each tpi source. Type
// merging will skip indices not on this list. Store the destination PDB type
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 11e13f20c80428..19e035d72dba19 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -779,7 +779,7 @@ StringRef LinkerDriver::mangleMaybe(Symbol *s) {
// If we find a similar mangled symbol, make this an alias to it and return
// its name.
- log(unmangled->getName() + " aliased to " + mangled->getName());
+ Log(ctx) << unmangled->getName() << " aliased to " << mangled->getName();
unmangled->setWeakAlias(ctx.symtab.addUndefined(mangled->getName()));
return mangled->getName();
}
@@ -2419,7 +2419,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (s.empty())
fatal("entry point must be defined");
config->entry = addUndefined(s, true);
- log("Entry name inferred: " + s);
+ Log(ctx) << "Entry name inferred: " << s;
}
}
}
diff --git a/lld/COFF/ICF.cpp b/lld/COFF/ICF.cpp
index 3140d094ae0f0f..796d3a4108ba48 100644
--- a/lld/COFF/ICF.cpp
+++ b/lld/COFF/ICF.cpp
@@ -314,16 +314,16 @@ void ICF::run() {
[&](size_t begin, size_t end) { segregate(begin, end, false); });
} while (repeat);
- log("ICF needed " + Twine(cnt) + " iterations");
+ Log(ctx) << "ICF needed " << Twine(cnt) << " iterations";
// Merge sections in the same classes.
forEachClass([&](size_t begin, size_t end) {
if (end - begin == 1)
return;
- log("Selected " + chunks[begin]->getDebugName());
+ Log(ctx) << "Selected " << chunks[begin]->getDebugName();
for (size_t i = begin + 1; i < end; ++i) {
- log(" Removed " + chunks[i]->getDebugName());
+ Log(ctx) << " Removed " << chunks[i]->getDebugName();
chunks[begin]->replace(chunks[i]);
}
});
diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp
index 65def1f509a4d9..dd309f70fd13a9 100644
--- a/lld/COFF/InputFiles.cpp
+++ b/lld/COFF/InputFiles.cpp
@@ -518,8 +518,8 @@ void ObjFile::initializeSymbols() {
}
if (sparseChunks[sym.getSectionNumber()] == pendingComdat) {
StringRef name = check(coffObj->getSymbolName(sym));
- log("comdat section " + name +
- " without leader and unassociated, discarding");
+ Log(ctx) << "comdat section " << name
+ << " without leader and unassociated, discarding";
continue;
}
symbols[i] = createRegular(sym);
@@ -620,10 +620,9 @@ void ObjFile::handleComdatSelection(
// seems better though.
// (This behavior matches ModuleLinker::getComdatResult().)
if (selection != leaderSelection) {
- log(("conflicting comdat type for " + toString(ctx, *leader) + ": " +
- Twine((int)leaderSelection) + " in " + toString(leader->getFile()) +
- " and " + Twine((int)selection) + " in " + toString(this))
- .str());
+ Log(ctx) << "conflicting comdat type for " << toString(ctx, *leader) << ": "
+ << (int)leaderSelection << " in " << leader->getFile() << " and "
+ << (int)selection << " in " << this;
ctx.symtab.reportDuplicate(leader, this);
return;
}
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index b4b10ef8913f0e..cc4221768fbb07 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -569,7 +569,8 @@ void PDBLinker::writeSymbolRecord(SectionChunk *debugChunk,
// Re-map all the type index references.
TpiSource *source = debugChunk->file->debugTypesObj;
if (!source->remapTypesInSymbolRecord(recordBytes)) {
- log("ignoring unknown symbol record with kind 0x" + utohexstr(sym.kind()));
+ Log(ctx) << "ignoring unknown symbol record with kind 0x"
+ << utohexstr(sym.kind());
replaceWithSkipRecord(recordBytes);
}
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 9f41421722286c..92001ed8c79472 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -54,7 +54,7 @@ static bool compatibleMachineType(COFFLinkerContext &ctx, MachineTypes mt) {
}
void SymbolTable::addFile(InputFile *file) {
- log("Reading " + toString(file));
+ Log(ctx) << "Reading " << toString(file);
if (file->lazy) {
if (auto *f = dyn_cast<BitcodeFile>(file))
f->parseLazy();
@@ -320,8 +320,8 @@ void SymbolTable::loadMinGWSymbols() {
if (newName != origName && (l = find(newName)) != nullptr) {
// If we found a symbol and it is lazy; load it.
if (l->isLazy() && !l->pendingArchiveLoad) {
- log("Loading lazy " + l->getName() + " from " +
- l->getFile()->getName() + " for stdcall fixup");
+ Log(ctx) << "Loading lazy " << l->getName() << " from "
+ << l->getFile()->getName() << " for stdcall fixup";
forceLazy(l);
}
// If it's lazy or already defined, hook it up as weak alias.
@@ -330,7 +330,8 @@ void SymbolTable::loadMinGWSymbols() {
Warn(ctx) << "Resolving " << origName << " by linking to "
<< newName;
else
- log("Resolving " + origName + " by linking to " + newName);
+ Log(ctx) << "Resolving " << origName << " by linking to "
+ << newName;
undef->setWeakAlias(l);
continue;
}
@@ -346,8 +347,8 @@ void SymbolTable::loadMinGWSymbols() {
if (!l || l->pendingArchiveLoad || !l->isLazy())
continue;
- log("Loading lazy " + l->getName() + " from " + l->getFile()->getName() +
- " for automatic import");
+ Log(ctx) << "Loading lazy " << l->getName() << " from "
+ << l->getFile()->getName() << " for automatic import";
forceLazy(l);
}
}
@@ -372,12 +373,12 @@ bool SymbolTable::handleMinGWAutomaticImport(Symbol *sym, StringRef name) {
// reference itself to point at the IAT entry.
size_t impSize = 0;
if (isa<DefinedImportData>(imp)) {
- log("Automatically importing " + name + " from " +
- cast<DefinedImportData>(imp)->getDLLName());
+ Log(ctx) << "Automatically importing " << name << " from "
+ << cast<DefinedImportData>(imp)->getDLLName();
impSize = sizeof(DefinedImportData);
} else if (isa<DefinedRegular>(imp)) {
- log("Automatically importing " + name + " from " +
- toString(cast<DefinedRegular>(imp)->file));
+ Log(ctx) << "Automatically importing " << name << " from "
+ << toString(cast<DefinedRegular>(imp)->file);
impSize = sizeof(DefinedRegular);
} else {
Warn(ctx) << "unable to automatically import " << name << " from "
@@ -398,7 +399,7 @@ bool SymbolTable::handleMinGWAutomaticImport(Symbol *sym, StringRef name) {
if (refptr && refptr->getChunk()->getSize() == ctx.config.wordsize) {
SectionChunk *sc = dyn_cast_or_null<SectionChunk>(refptr->getChunk());
if (sc && sc->getRelocs().size() == 1 && *sc->symbols().begin() == sym) {
- log("Replacing .refptr." + name + " with " + imp->getName());
+ Log(ctx) << "Replacing .refptr." << name << " with " << imp->getName();
refptr->getChunk()->live = false;
refptr->replaceKeepingName(imp, impSize);
}
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 34f4839396df12..f30077ee184946 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -670,8 +670,9 @@ void Writer::finalizeAddresses() {
}
if (rangesOk) {
if (pass > 0)
- log("Added " + Twine(numChunks - origNumChunks) + " thunks with " +
- "margin " + Twine(margin) + " in " + Twine(pass) + " passes");
+ Log(ctx) << "Added " << Twine(numChunks - origNumChunks)
+ << " thunks with " << "margin " << Twine(margin) << " in "
+ << Twine(pass) << " passes";
return;
}
@@ -1116,7 +1117,7 @@ void Writer::createSections() {
// special case for all architectures.
outChars = data | r;
- log("Processing section " + pSec->name + " -> " + name);
+ Log(ctx) << "Processing section " << pSec->name << " -> " << name;
sortCRTSectionChunks(pSec->chunks);
}
@@ -2221,7 +2222,8 @@ void Writer::createRuntimePseudoRelocs() {
}
if (!rels.empty()) {
- log("Writing " + Twine(rels.size()) + " runtime pseudo relocations");
+ Log(ctx) << "Writing " << Twine(rels.size())
+ << " runtime pseudo relocations";
const char *symbolName = "_pei386_runtime_relocator";
Symbol *relocator = ctx.symtab.findUnderscore(symbolName);
if (!relocator)
@@ -2496,8 +2498,8 @@ void Writer::sortCRTSectionChunks(std::vector<Chunk *> &chunks) {
if (ctx.config.verbose) {
for (auto &c : chunks) {
auto sc = dyn_cast<SectionChunk>(c);
- log(" " + sc->file->mb.getBufferIdentifier().str() +
- ", SectionID: " + Twine(sc->getSectionNumber()));
+ Log(ctx) << " " << sc->file->mb.getBufferIdentifier().str()
+ << ", SectionID: " << Twine(sc->getSectionNumber());
}
}
}
More information about the llvm-commits
mailing list