Skip to content

Commit c7caab2

Browse files
committed
[lld-link] Simplify some << toString
1 parent 983f88c commit c7caab2

File tree

3 files changed

+25
-34
lines changed

3 files changed

+25
-34
lines changed

lld/COFF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ void ObjFile::handleComdatSelection(
621621
// seems better though.
622622
// (This behavior matches ModuleLinker::getComdatResult().)
623623
if (selection != leaderSelection) {
624-
Log(ctx) << "conflicting comdat type for " << toString(ctx, *leader) << ": "
624+
Log(ctx) << "conflicting comdat type for " << leader << ": "
625625
<< (int)leaderSelection << " in " << leader->getFile() << " and "
626626
<< (int)selection << " in " << this;
627627
ctx.symtab.reportDuplicate(leader, this);

lld/COFF/SymbolTable.cpp

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ struct UndefinedDiag {
272272

273273
static void reportUndefinedSymbol(COFFLinkerContext &ctx,
274274
const UndefinedDiag &undefDiag) {
275-
std::string out;
276-
llvm::raw_string_ostream os(out);
277-
os << "undefined symbol: " << toString(ctx, *undefDiag.sym);
275+
auto diag = errorOrWarn(ctx);
276+
diag << "undefined symbol: " << undefDiag.sym;
278277

279278
const size_t maxUndefReferences = 3;
280279
size_t numDisplayedRefs = 0, numRefs = 0;
@@ -284,13 +283,11 @@ static void reportUndefinedSymbol(COFFLinkerContext &ctx,
284283

285284
numRefs += totalLocations;
286285
numDisplayedRefs += symbolLocations.size();
287-
for (const std::string &s : symbolLocations) {
288-
os << s;
289-
}
286+
for (const std::string &s : symbolLocations)
287+
diag << s;
290288
}
291289
if (numDisplayedRefs < numRefs)
292-
os << "\n>>> referenced " << numRefs - numDisplayedRefs << " more times";
293-
errorOrWarn(ctx) << out;
290+
diag << "\n>>> referenced " << numRefs - numDisplayedRefs << " more times";
294291
}
295292

296293
void SymbolTable::loadMinGWSymbols() {
@@ -422,12 +419,12 @@ static void reportProblemSymbols(
422419

423420
for (Symbol *b : ctx.config.gcroot) {
424421
if (undefs.count(b))
425-
errorOrWarn(ctx) << "<root>: undefined symbol: " << toString(ctx, *b);
422+
errorOrWarn(ctx) << "<root>: undefined symbol: " << b;
426423
if (localImports)
427424
if (Symbol *imp = localImports->lookup(b))
428-
Warn(ctx) << "<root>: locally defined symbol imported: "
429-
<< toString(ctx, *imp) << " (defined in "
430-
<< toString(imp->getFile()) << ") [LNK4217]";
425+
Warn(ctx) << "<root>: locally defined symbol imported: " << imp
426+
<< " (defined in " << toString(imp->getFile())
427+
<< ") [LNK4217]";
431428
}
432429

433430
std::vector<UndefinedDiag> undefDiags;
@@ -448,9 +445,8 @@ static void reportProblemSymbols(
448445
}
449446
if (localImports)
450447
if (Symbol *imp = localImports->lookup(sym))
451-
Warn(ctx) << file << ": locally defined symbol imported: "
452-
<< toString(ctx, *imp) << " (defined in " << imp->getFile()
453-
<< ") [LNK4217]";
448+
Warn(ctx) << file << ": locally defined symbol imported: " << imp
449+
<< " (defined in " << imp->getFile() << ") [LNK4217]";
454450
}
455451
};
456452

@@ -800,24 +796,19 @@ static std::string getSourceLocation(InputFile *file, SectionChunk *sc,
800796
void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
801797
SectionChunk *newSc,
802798
uint32_t newSectionOffset) {
803-
std::string msg;
804-
llvm::raw_string_ostream os(msg);
805-
os << "duplicate symbol: " << toString(ctx, *existing);
799+
COFFSyncStream diag(ctx, ctx.config.forceMultiple ? DiagLevel::Warn
800+
: DiagLevel::Err);
801+
diag << "duplicate symbol: " << existing;
806802

807803
DefinedRegular *d = dyn_cast<DefinedRegular>(existing);
808804
if (d && isa<ObjFile>(d->getFile())) {
809-
os << getSourceLocation(d->getFile(), d->getChunk(), d->getValue(),
810-
existing->getName());
805+
diag << getSourceLocation(d->getFile(), d->getChunk(), d->getValue(),
806+
existing->getName());
811807
} else {
812-
os << getSourceLocation(existing->getFile(), nullptr, 0, "");
808+
diag << getSourceLocation(existing->getFile(), nullptr, 0, "");
813809
}
814-
os << getSourceLocation(newFile, newSc, newSectionOffset,
815-
existing->getName());
816-
817-
if (ctx.config.forceMultiple)
818-
Warn(ctx) << msg;
819-
else
820-
Err(ctx) << msg;
810+
diag << getSourceLocation(newFile, newSc, newSectionOffset,
811+
existing->getName());
821812
}
822813

823814
Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) {

lld/COFF/Writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,12 +1256,12 @@ void Writer::createImportTables() {
12561256
ctx.config.dllOrder[dll] = ctx.config.dllOrder.size();
12571257

12581258
if (file->impSym && !isa<DefinedImportData>(file->impSym))
1259-
Fatal(ctx) << toString(ctx, *file->impSym) << " was replaced";
1259+
Fatal(ctx) << file->impSym << " was replaced";
12601260
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
12611261
if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
12621262
if (!file->thunkSym)
12631263
Fatal(ctx) << "cannot delay-load " << toString(file)
1264-
<< " due to import of data: " << toString(ctx, *impSym);
1264+
<< " due to import of data: " << impSym;
12651265
delayIdata.add(impSym);
12661266
} else {
12671267
idata.add(impSym);
@@ -1280,15 +1280,15 @@ void Writer::appendImportThunks() {
12801280

12811281
if (file->thunkSym) {
12821282
if (!isa<DefinedImportThunk>(file->thunkSym))
1283-
Fatal(ctx) << toString(ctx, *file->thunkSym) << " was replaced";
1283+
Fatal(ctx) << file->thunkSym << " was replaced";
12841284
auto *chunk = cast<DefinedImportThunk>(file->thunkSym)->getChunk();
12851285
if (chunk->live)
12861286
textSec->addChunk(chunk);
12871287
}
12881288

12891289
if (file->auxThunkSym) {
12901290
if (!isa<DefinedImportThunk>(file->auxThunkSym))
1291-
Fatal(ctx) << toString(ctx, *file->auxThunkSym) << " was replaced";
1291+
Fatal(ctx) << file->auxThunkSym << " was replaced";
12921292
auto *chunk = cast<DefinedImportThunk>(file->auxThunkSym)->getChunk();
12931293
if (chunk->live)
12941294
textSec->addChunk(chunk);
@@ -1334,7 +1334,7 @@ void Writer::createExportTable() {
13341334
// Warn on exported deleting destructor.
13351335
for (auto e : ctx.config.exports)
13361336
if (e.sym && e.sym->getName().starts_with("??_G"))
1337-
Warn(ctx) << "export of deleting dtor: " << toString(ctx, *e.sym);
1337+
Warn(ctx) << "export of deleting dtor: " << e.sym;
13381338
}
13391339

13401340
void Writer::removeUnusedSections() {

0 commit comments

Comments
 (0)