@@ -272,9 +272,8 @@ struct UndefinedDiag {
272272
273273static 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
296293void 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,
800796void 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
823814Symbol *SymbolTable::addAbsolute (StringRef n, COFFSymbolRef sym) {
0 commit comments