@@ -101,23 +101,25 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
101101}
102102
103103// Parse options of the form "old;new".
104- static std::pair<StringRef, StringRef> getOldNewOptions (opt::InputArgList &args,
105- unsigned id) {
104+ static std::pair<StringRef, StringRef>
105+ getOldNewOptions (COFFLinkerContext &ctx, opt::InputArgList &args, unsigned id) {
106106 auto *arg = args.getLastArg (id);
107107 if (!arg)
108108 return {" " , " " };
109109
110110 StringRef s = arg->getValue ();
111111 std::pair<StringRef, StringRef> ret = s.split (' ;' );
112112 if (ret.second .empty ())
113- error (arg->getSpelling () + " expects 'old;new' format, but got " + s);
113+ Err (ctx) << arg->getSpelling () << " expects 'old;new' format, but got "
114+ << s;
114115 return ret;
115116}
116117
117118// Parse options of the form "old;new[;extra]".
118119static std::tuple<StringRef, StringRef, StringRef>
119- getOldNewOptionsExtra (opt::InputArgList &args, unsigned id) {
120- auto [oldDir, second] = getOldNewOptions (args, id);
120+ getOldNewOptionsExtra (COFFLinkerContext &ctx, opt::InputArgList &args,
121+ unsigned id) {
122+ auto [oldDir, second] = getOldNewOptions (ctx, args, id);
121123 auto [newDir, extraDir] = second.split (' ;' );
122124 return {oldDir, newDir, extraDir};
123125}
@@ -243,13 +245,14 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
243245 break ;
244246 }
245247 if (filename.ends_with_insensitive (" .dll" )) {
246- error (filename + " : bad file type. Did you specify a DLL instead of an "
247- " import library?" );
248+ Err (ctx) << filename
249+ << " : bad file type. Did you specify a DLL instead of an "
250+ " import library?" ;
248251 break ;
249252 }
250253 [[fallthrough]];
251254 default :
252- error ( mbref.getBufferIdentifier () + " : unknown file type" ) ;
255+ Err (ctx) << mbref.getBufferIdentifier () << " : unknown file type" ;
253256 break ;
254257 }
255258}
@@ -289,9 +292,9 @@ void LinkerDriver::enqueuePath(StringRef path, bool wholeArchive, bool lazy) {
289292 // directory.
290293 std::string nearest;
291294 if (ctx.optTable .findNearest (pathStr, nearest) > 1 )
292- error (msg) ;
295+ Err (ctx) << msg ;
293296 else
294- error ( msg + " ; did you mean '" + nearest + " '" ) ;
297+ Err (ctx) << msg << " ; did you mean '" << nearest << " '" ;
295298 } else
296299 ctx.driver .addBuffer (std::move (mb), wholeArchive, lazy);
297300 });
@@ -315,11 +318,11 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
315318 obj =
316319 make<BitcodeFile>(ctx, mb, parentName, offsetInArchive, /* lazy=*/ false );
317320 } else if (magic == file_magic::coff_cl_gl_object) {
318- error ( mb.getBufferIdentifier () +
319- " : is not a native COFF file. Recompile without /GL?" ) ;
321+ Err (ctx) << mb.getBufferIdentifier ()
322+ << " : is not a native COFF file. Recompile without /GL?" ;
320323 return ;
321324 } else {
322- error ( " unknown file type: " + mb.getBufferIdentifier () );
325+ Err (ctx) << " unknown file type: " << mb.getBufferIdentifier ();
323326 return ;
324327 }
325328
@@ -485,8 +488,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
485488 case OPT_inferasanlibs_no:
486489 break ;
487490 default :
488- error ( arg->getSpelling () + " is not allowed in .drectve (" +
489- toString (file) + " )" ) ;
491+ Err (ctx) << arg->getSpelling () << " is not allowed in .drectve ("
492+ << toString (file) << " )" ;
490493 }
491494 }
492495}
@@ -751,7 +754,7 @@ Symbol *LinkerDriver::addUndefined(StringRef name, bool aliasEC) {
751754void LinkerDriver::addUndefinedGlob (StringRef arg) {
752755 Expected<GlobPattern> pat = GlobPattern::create (arg);
753756 if (!pat) {
754- error ( " /includeglob: " + toString (pat.takeError () ));
757+ Err (ctx) << " /includeglob: " << toString (pat.takeError ());
755758 return ;
756759 }
757760
@@ -1133,7 +1136,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
11331136 // For some reason, the MSVC linker requires a filename to be
11341137 // preceded by "@".
11351138 if (!arg.starts_with (" @" )) {
1136- error ( " malformed /order option: '@' missing" ) ;
1139+ Err (ctx) << " malformed /order option: '@' missing" ;
11371140 return ;
11381141 }
11391142
@@ -1206,7 +1209,7 @@ void LinkerDriver::parseCallGraphFile(StringRef path) {
12061209 uint64_t count;
12071210
12081211 if (fields.size () != 3 || !to_integer (fields[2 ], count)) {
1209- error ( path + " : parse error" ) ;
1212+ Err (ctx) << path << " : parse error" ;
12101213 return ;
12111214 }
12121215
@@ -1360,10 +1363,11 @@ void LinkerDriver::convertResources() {
13601363 if (!ctx.config .mingw &&
13611364 (resourceObjFiles.size () > 1 ||
13621365 (resourceObjFiles.size () == 1 && !resources.empty ()))) {
1363- error ((!resources.empty () ? " internal .obj file created from .res files"
1364- : toString (resourceObjFiles[1 ])) +
1365- " : more than one resource obj file not allowed, already got " +
1366- toString (resourceObjFiles.front ()));
1366+ Err (ctx) << (!resources.empty ()
1367+ ? " internal .obj file created from .res files"
1368+ : toString (resourceObjFiles[1 ]))
1369+ << " : more than one resource obj file not allowed, already got "
1370+ << resourceObjFiles.front ();
13671371 return ;
13681372 }
13691373
@@ -1528,7 +1532,7 @@ std::optional<std::string> getReproduceFile(const opt::InputArgList &args) {
15281532}
15291533
15301534static std::unique_ptr<llvm::vfs::FileSystem>
1531- getVFS (const opt::InputArgList &args) {
1535+ getVFS (COFFLinkerContext &ctx, const opt::InputArgList &args) {
15321536 using namespace llvm ::vfs;
15331537
15341538 const opt::Arg *arg = args.getLastArg (OPT_vfsoverlay);
@@ -1545,7 +1549,7 @@ getVFS(const opt::InputArgList &args) {
15451549 /* DiagHandler*/ nullptr , arg->getValue ()))
15461550 return ret;
15471551
1548- error ( " Invalid vfs overlay" ) ;
1552+ Err (ctx) << " Invalid vfs overlay" ;
15491553 return nullptr ;
15501554}
15511555
@@ -1606,11 +1610,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16061610 int n = 20 ;
16071611 StringRef s = arg->getValue ();
16081612 if (s.getAsInteger (10 , n))
1609- error ( arg->getSpelling () + " number expected, but got " + s) ;
1613+ Err (ctx) << arg->getSpelling () << " number expected, but got " << s ;
16101614 ctx.e .errorLimit = n;
16111615 }
16121616
1613- config->vfs = getVFS (args);
1617+ config->vfs = getVFS (ctx, args);
16141618
16151619 // Handle /help
16161620 if (args.hasArg (OPT_help)) {
@@ -1624,8 +1628,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16241628 StringRef v (arg->getValue ());
16251629 unsigned threads = 0 ;
16261630 if (!llvm::to_integer (v, threads, 0 ) || threads == 0 )
1627- error (arg->getSpelling () + " : expected a positive integer, but got '" +
1628- arg->getValue () + " '" );
1631+ Err (ctx) << arg->getSpelling ()
1632+ << " : expected a positive integer, but got '" << arg->getValue ()
1633+ << " '" ;
16291634 parallel::strategy = hardware_concurrency (threads);
16301635 config->thinLTOJobs = v.str ();
16311636 }
@@ -1661,8 +1666,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16611666 if (errOrWriter) {
16621667 tar = std::move (*errOrWriter);
16631668 } else {
1664- error ( " /linkrepro: failed to open " + *path + " : " +
1665- toString (errOrWriter.takeError () ));
1669+ Err (ctx) << " /linkrepro: failed to open " << *path << " : "
1670+ << toString (errOrWriter.takeError ());
16661671 }
16671672 }
16681673 }
@@ -1788,7 +1793,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
17881793 } else if (s == " nosymtab" ) {
17891794 config->writeSymtab = false ;
17901795 } else {
1791- error ( " /debug: unknown option: " + s) ;
1796+ Err (ctx) << " /debug: unknown option: " << s ;
17921797 }
17931798 }
17941799 }
@@ -1841,7 +1846,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18411846 if (args.hasArg (OPT_dll))
18421847 config->noEntry = true ;
18431848 else
1844- error ( " /noentry must be specified with /dll" ) ;
1849+ Err (ctx) << " /noentry must be specified with /dll" ;
18451850 }
18461851
18471852 // Handle /dll
@@ -1865,7 +1870,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18651870 if (fixed) {
18661871 if (dynamicBaseArg &&
18671872 dynamicBaseArg->getOption ().getID () == OPT_dynamicbase) {
1868- error ( " /fixed must not be specified with /dynamicbase" ) ;
1873+ Err (ctx) << " /fixed must not be specified with /dynamicbase" ;
18691874 } else {
18701875 config->relocatable = false ;
18711876 config->dynamicBase = false ;
@@ -1906,7 +1911,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
19061911 if (auto *arg = args.getLastArg (OPT_filealign)) {
19071912 parseNumbers (arg->getValue (), &config->fileAlign );
19081913 if (!isPowerOf2_64 (config->fileAlign ))
1909- error ( " /filealign: not a power of two: " + Twine ( config->fileAlign )) ;
1914+ Err (ctx) << " /filealign: not a power of two: " << config->fileAlign ;
19101915 }
19111916
19121917 // Handle /stack
@@ -2013,21 +2018,22 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20132018 ltoDebugPM = false ;
20142019 } else if (s.consume_front (" lldlto=" )) {
20152020 if (s.getAsInteger (10 , config->ltoo ) || config->ltoo > 3 )
2016- error ( " /opt:lldlto: invalid optimization level: " + s) ;
2021+ Err (ctx) << " /opt:lldlto: invalid optimization level: " << s ;
20172022 } else if (s.consume_front (" lldltocgo=" )) {
20182023 config->ltoCgo .emplace ();
20192024 if (s.getAsInteger (10 , *config->ltoCgo ) || *config->ltoCgo > 3 )
2020- error (" /opt:lldltocgo: invalid codegen optimization level: " + s);
2025+ Err (ctx) << " /opt:lldltocgo: invalid codegen optimization level: "
2026+ << s;
20212027 } else if (s.consume_front (" lldltojobs=" )) {
20222028 if (!get_threadpool_strategy (s))
2023- error ( " /opt:lldltojobs: invalid job count: " + s) ;
2029+ Err (ctx) << " /opt:lldltojobs: invalid job count: " << s ;
20242030 config->thinLTOJobs = s.str ();
20252031 } else if (s.consume_front (" lldltopartitions=" )) {
20262032 if (s.getAsInteger (10 , config->ltoPartitions ) ||
20272033 config->ltoPartitions == 0 )
2028- error ( " /opt:lldltopartitions: invalid partition count: " + s) ;
2034+ Err (ctx) << " /opt:lldltopartitions: invalid partition count: " << s ;
20292035 } else if (s != " lbr" && s != " nolbr" )
2030- error ( " /opt: unknown option: " + s) ;
2036+ Err (ctx) << " /opt: unknown option: " << s ;
20312037 }
20322038 }
20332039
@@ -2049,7 +2055,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20492055 if (llvm::is_contained (lldsaveTempsValues, s))
20502056 config->saveTempsArgs .insert (s);
20512057 else
2052- error ( " unknown /lldsavetemps value: " + s) ;
2058+ Err (ctx) << " unknown /lldsavetemps value: " << s ;
20532059 }
20542060 }
20552061
@@ -2063,7 +2069,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
20632069 else if (s == " asm" )
20642070 config->emit = EmitKind::ASM;
20652071 else
2066- error ( " /lldemit: unknown option: " + s) ;
2072+ Err (ctx) << " /lldemit: unknown option: " << s ;
20672073 }
20682074
20692075 // Handle /kill-at
@@ -2114,7 +2120,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
21142120 if (auto *arg = args.getLastArg (OPT_align)) {
21152121 parseNumbers (arg->getValue (), &config->align );
21162122 if (!isPowerOf2_64 (config->align ))
2117- error ( " /align: not a power of two: " + StringRef (arg->getValue () ));
2123+ Err (ctx) << " /align: not a power of two: " << StringRef (arg->getValue ());
21182124 if (!args.hasArg (OPT_driver))
21192125 Warn (ctx) << " /align specified without /driver; image may not run" ;
21202126 }
@@ -2162,9 +2168,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
21622168 args.getLastArgValue (OPT_thinlto_index_only_arg);
21632169 std::tie (config->thinLTOPrefixReplaceOld , config->thinLTOPrefixReplaceNew ,
21642170 config->thinLTOPrefixReplaceNativeObject ) =
2165- getOldNewOptionsExtra (args, OPT_thinlto_prefix_replace);
2171+ getOldNewOptionsExtra (ctx, args, OPT_thinlto_prefix_replace);
21662172 config->thinLTOObjectSuffixReplace =
2167- getOldNewOptions (args, OPT_thinlto_object_suffix_replace);
2173+ getOldNewOptions (ctx, args, OPT_thinlto_object_suffix_replace);
21682174 config->ltoObjPath = args.getLastArgValue (OPT_lto_obj_path);
21692175 config->ltoCSProfileGenerate = args.hasArg (OPT_lto_cs_profile_generate);
21702176 config->ltoCSProfileFile = args.getLastArgValue (OPT_lto_cs_profile_file);
@@ -2258,12 +2264,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22582264 switch (arg->getOption ().getID ()) {
22592265 case OPT_end_lib:
22602266 if (!inLib)
2261- error ( " stray " + arg->getSpelling () );
2267+ Err (ctx) << " stray " << arg->getSpelling ();
22622268 inLib = false ;
22632269 break ;
22642270 case OPT_start_lib:
22652271 if (inLib)
2266- error ( " nested " + arg->getSpelling () );
2272+ Err (ctx) << " nested " << arg->getSpelling ();
22672273 inLib = true ;
22682274 break ;
22692275 case OPT_wholearchive_file:
@@ -2355,8 +2361,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23552361
23562362 if (!config->dynamicBase &&
23572363 (config->machine == ARMNT || isAnyArm64 (config->machine )))
2358- error ( " /dynamicbase:no is not compatible with " +
2359- machineToStr (config->machine ) );
2364+ Err (ctx) << " /dynamicbase:no is not compatible with "
2365+ << machineToStr (config->machine );
23602366
23612367 // Handle /export
23622368 {
@@ -2446,7 +2452,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24462452
24472453 // Fail early if an output file is not writable.
24482454 if (auto e = tryCreateFile (config->outputFile )) {
2449- error (" cannot open output file " + config->outputFile + " : " + e.message ());
2455+ Err (ctx) << " cannot open output file " << config->outputFile << " : "
2456+ << e.message ();
24502457 return ;
24512458 }
24522459
@@ -2459,7 +2466,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24592466 if (s == " exports" )
24602467 config->mapInfo = true ;
24612468 else
2462- error ( " unknown option: /mapinfo:" + s) ;
2469+ Err (ctx) << " unknown option: /mapinfo:" << s ;
24632470 }
24642471 }
24652472
@@ -2774,7 +2781,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27742781 // functions.
27752782 if (auto *arg = args.getLastArg (OPT_order)) {
27762783 if (args.hasArg (OPT_call_graph_ordering_file))
2777- error ( " /order and /call-graph-order-file may not be used together" ) ;
2784+ Err (ctx) << " /order and /call-graph-order-file may not be used together" ;
27782785 parseOrderFile (arg->getValue ());
27792786 config->callGraphProfileSort = false ;
27802787 }
0 commit comments