@@ -272,9 +272,8 @@ struct UndefinedDiag {
272
272
273
273
static void reportUndefinedSymbol (COFFLinkerContext &ctx,
274
274
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 ;
278
277
279
278
const size_t maxUndefReferences = 3 ;
280
279
size_t numDisplayedRefs = 0 , numRefs = 0 ;
@@ -284,13 +283,11 @@ static void reportUndefinedSymbol(COFFLinkerContext &ctx,
284
283
285
284
numRefs += totalLocations;
286
285
numDisplayedRefs += symbolLocations.size ();
287
- for (const std::string &s : symbolLocations) {
288
- os << s;
289
- }
286
+ for (const std::string &s : symbolLocations)
287
+ diag << s;
290
288
}
291
289
if (numDisplayedRefs < numRefs)
292
- os << " \n >>> referenced " << numRefs - numDisplayedRefs << " more times" ;
293
- errorOrWarn (ctx) << out;
290
+ diag << " \n >>> referenced " << numRefs - numDisplayedRefs << " more times" ;
294
291
}
295
292
296
293
void SymbolTable::loadMinGWSymbols () {
@@ -422,12 +419,12 @@ static void reportProblemSymbols(
422
419
423
420
for (Symbol *b : ctx.config .gcroot ) {
424
421
if (undefs.count (b))
425
- errorOrWarn (ctx) << " <root>: undefined symbol: " << toString (ctx, *b) ;
422
+ errorOrWarn (ctx) << " <root>: undefined symbol: " << b ;
426
423
if (localImports)
427
424
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]" ;
431
428
}
432
429
433
430
std::vector<UndefinedDiag> undefDiags;
@@ -448,9 +445,8 @@ static void reportProblemSymbols(
448
445
}
449
446
if (localImports)
450
447
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]" ;
454
450
}
455
451
};
456
452
@@ -800,24 +796,19 @@ static std::string getSourceLocation(InputFile *file, SectionChunk *sc,
800
796
void SymbolTable::reportDuplicate (Symbol *existing, InputFile *newFile,
801
797
SectionChunk *newSc,
802
798
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;
806
802
807
803
DefinedRegular *d = dyn_cast<DefinedRegular>(existing);
808
804
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 ());
811
807
} else {
812
- os << getSourceLocation (existing->getFile (), nullptr , 0 , " " );
808
+ diag << getSourceLocation (existing->getFile (), nullptr , 0 , " " );
813
809
}
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 ());
821
812
}
822
813
823
814
Symbol *SymbolTable::addAbsolute (StringRef n, COFFSymbolRef sym) {
0 commit comments