@@ -101,23 +101,25 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
101
101
}
102
102
103
103
// 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) {
106
106
auto *arg = args.getLastArg (id);
107
107
if (!arg)
108
108
return {" " , " " };
109
109
110
110
StringRef s = arg->getValue ();
111
111
std::pair<StringRef, StringRef> ret = s.split (' ;' );
112
112
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;
114
115
return ret;
115
116
}
116
117
117
118
// Parse options of the form "old;new[;extra]".
118
119
static 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);
121
123
auto [newDir, extraDir] = second.split (' ;' );
122
124
return {oldDir, newDir, extraDir};
123
125
}
@@ -243,13 +245,14 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
243
245
break ;
244
246
}
245
247
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?" ;
248
251
break ;
249
252
}
250
253
[[fallthrough]];
251
254
default :
252
- error ( mbref.getBufferIdentifier () + " : unknown file type" ) ;
255
+ Err (ctx) << mbref.getBufferIdentifier () << " : unknown file type" ;
253
256
break ;
254
257
}
255
258
}
@@ -289,9 +292,9 @@ void LinkerDriver::enqueuePath(StringRef path, bool wholeArchive, bool lazy) {
289
292
// directory.
290
293
std::string nearest;
291
294
if (ctx.optTable .findNearest (pathStr, nearest) > 1 )
292
- error (msg) ;
295
+ Err (ctx) << msg ;
293
296
else
294
- error ( msg + " ; did you mean '" + nearest + " '" ) ;
297
+ Err (ctx) << msg << " ; did you mean '" << nearest << " '" ;
295
298
} else
296
299
ctx.driver .addBuffer (std::move (mb), wholeArchive, lazy);
297
300
});
@@ -315,11 +318,11 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
315
318
obj =
316
319
make<BitcodeFile>(ctx, mb, parentName, offsetInArchive, /* lazy=*/ false );
317
320
} 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?" ;
320
323
return ;
321
324
} else {
322
- error ( " unknown file type: " + mb.getBufferIdentifier () );
325
+ Err (ctx) << " unknown file type: " << mb.getBufferIdentifier ();
323
326
return ;
324
327
}
325
328
@@ -485,8 +488,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
485
488
case OPT_inferasanlibs_no:
486
489
break ;
487
490
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) << " )" ;
490
493
}
491
494
}
492
495
}
@@ -751,7 +754,7 @@ Symbol *LinkerDriver::addUndefined(StringRef name, bool aliasEC) {
751
754
void LinkerDriver::addUndefinedGlob (StringRef arg) {
752
755
Expected<GlobPattern> pat = GlobPattern::create (arg);
753
756
if (!pat) {
754
- error ( " /includeglob: " + toString (pat.takeError () ));
757
+ Err (ctx) << " /includeglob: " << toString (pat.takeError ());
755
758
return ;
756
759
}
757
760
@@ -1133,7 +1136,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
1133
1136
// For some reason, the MSVC linker requires a filename to be
1134
1137
// preceded by "@".
1135
1138
if (!arg.starts_with (" @" )) {
1136
- error ( " malformed /order option: '@' missing" ) ;
1139
+ Err (ctx) << " malformed /order option: '@' missing" ;
1137
1140
return ;
1138
1141
}
1139
1142
@@ -1206,7 +1209,7 @@ void LinkerDriver::parseCallGraphFile(StringRef path) {
1206
1209
uint64_t count;
1207
1210
1208
1211
if (fields.size () != 3 || !to_integer (fields[2 ], count)) {
1209
- error ( path + " : parse error" ) ;
1212
+ Err (ctx) << path << " : parse error" ;
1210
1213
return ;
1211
1214
}
1212
1215
@@ -1360,10 +1363,11 @@ void LinkerDriver::convertResources() {
1360
1363
if (!ctx.config .mingw &&
1361
1364
(resourceObjFiles.size () > 1 ||
1362
1365
(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 ();
1367
1371
return ;
1368
1372
}
1369
1373
@@ -1528,7 +1532,7 @@ std::optional<std::string> getReproduceFile(const opt::InputArgList &args) {
1528
1532
}
1529
1533
1530
1534
static std::unique_ptr<llvm::vfs::FileSystem>
1531
- getVFS (const opt::InputArgList &args) {
1535
+ getVFS (COFFLinkerContext &ctx, const opt::InputArgList &args) {
1532
1536
using namespace llvm ::vfs;
1533
1537
1534
1538
const opt::Arg *arg = args.getLastArg (OPT_vfsoverlay);
@@ -1545,7 +1549,7 @@ getVFS(const opt::InputArgList &args) {
1545
1549
/* DiagHandler*/ nullptr , arg->getValue ()))
1546
1550
return ret;
1547
1551
1548
- error ( " Invalid vfs overlay" ) ;
1552
+ Err (ctx) << " Invalid vfs overlay" ;
1549
1553
return nullptr ;
1550
1554
}
1551
1555
@@ -1606,11 +1610,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1606
1610
int n = 20 ;
1607
1611
StringRef s = arg->getValue ();
1608
1612
if (s.getAsInteger (10 , n))
1609
- error ( arg->getSpelling () + " number expected, but got " + s) ;
1613
+ Err (ctx) << arg->getSpelling () << " number expected, but got " << s ;
1610
1614
ctx.e .errorLimit = n;
1611
1615
}
1612
1616
1613
- config->vfs = getVFS (args);
1617
+ config->vfs = getVFS (ctx, args);
1614
1618
1615
1619
// Handle /help
1616
1620
if (args.hasArg (OPT_help)) {
@@ -1624,8 +1628,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1624
1628
StringRef v (arg->getValue ());
1625
1629
unsigned threads = 0 ;
1626
1630
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
+ << " '" ;
1629
1634
parallel::strategy = hardware_concurrency (threads);
1630
1635
config->thinLTOJobs = v.str ();
1631
1636
}
@@ -1661,8 +1666,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1661
1666
if (errOrWriter) {
1662
1667
tar = std::move (*errOrWriter);
1663
1668
} else {
1664
- error ( " /linkrepro: failed to open " + *path + " : " +
1665
- toString (errOrWriter.takeError () ));
1669
+ Err (ctx) << " /linkrepro: failed to open " << *path << " : "
1670
+ << toString (errOrWriter.takeError ());
1666
1671
}
1667
1672
}
1668
1673
}
@@ -1788,7 +1793,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1788
1793
} else if (s == " nosymtab" ) {
1789
1794
config->writeSymtab = false ;
1790
1795
} else {
1791
- error ( " /debug: unknown option: " + s) ;
1796
+ Err (ctx) << " /debug: unknown option: " << s ;
1792
1797
}
1793
1798
}
1794
1799
}
@@ -1841,7 +1846,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1841
1846
if (args.hasArg (OPT_dll))
1842
1847
config->noEntry = true ;
1843
1848
else
1844
- error ( " /noentry must be specified with /dll" ) ;
1849
+ Err (ctx) << " /noentry must be specified with /dll" ;
1845
1850
}
1846
1851
1847
1852
// Handle /dll
@@ -1865,7 +1870,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1865
1870
if (fixed) {
1866
1871
if (dynamicBaseArg &&
1867
1872
dynamicBaseArg->getOption ().getID () == OPT_dynamicbase) {
1868
- error ( " /fixed must not be specified with /dynamicbase" ) ;
1873
+ Err (ctx) << " /fixed must not be specified with /dynamicbase" ;
1869
1874
} else {
1870
1875
config->relocatable = false ;
1871
1876
config->dynamicBase = false ;
@@ -1906,7 +1911,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
1906
1911
if (auto *arg = args.getLastArg (OPT_filealign)) {
1907
1912
parseNumbers (arg->getValue (), &config->fileAlign );
1908
1913
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 ;
1910
1915
}
1911
1916
1912
1917
// Handle /stack
@@ -2013,21 +2018,22 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2013
2018
ltoDebugPM = false ;
2014
2019
} else if (s.consume_front (" lldlto=" )) {
2015
2020
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 ;
2017
2022
} else if (s.consume_front (" lldltocgo=" )) {
2018
2023
config->ltoCgo .emplace ();
2019
2024
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;
2021
2027
} else if (s.consume_front (" lldltojobs=" )) {
2022
2028
if (!get_threadpool_strategy (s))
2023
- error ( " /opt:lldltojobs: invalid job count: " + s) ;
2029
+ Err (ctx) << " /opt:lldltojobs: invalid job count: " << s ;
2024
2030
config->thinLTOJobs = s.str ();
2025
2031
} else if (s.consume_front (" lldltopartitions=" )) {
2026
2032
if (s.getAsInteger (10 , config->ltoPartitions ) ||
2027
2033
config->ltoPartitions == 0 )
2028
- error ( " /opt:lldltopartitions: invalid partition count: " + s) ;
2034
+ Err (ctx) << " /opt:lldltopartitions: invalid partition count: " << s ;
2029
2035
} else if (s != " lbr" && s != " nolbr" )
2030
- error ( " /opt: unknown option: " + s) ;
2036
+ Err (ctx) << " /opt: unknown option: " << s ;
2031
2037
}
2032
2038
}
2033
2039
@@ -2049,7 +2055,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2049
2055
if (llvm::is_contained (lldsaveTempsValues, s))
2050
2056
config->saveTempsArgs .insert (s);
2051
2057
else
2052
- error ( " unknown /lldsavetemps value: " + s) ;
2058
+ Err (ctx) << " unknown /lldsavetemps value: " << s ;
2053
2059
}
2054
2060
}
2055
2061
@@ -2063,7 +2069,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2063
2069
else if (s == " asm" )
2064
2070
config->emit = EmitKind::ASM;
2065
2071
else
2066
- error ( " /lldemit: unknown option: " + s) ;
2072
+ Err (ctx) << " /lldemit: unknown option: " << s ;
2067
2073
}
2068
2074
2069
2075
// Handle /kill-at
@@ -2114,7 +2120,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2114
2120
if (auto *arg = args.getLastArg (OPT_align)) {
2115
2121
parseNumbers (arg->getValue (), &config->align );
2116
2122
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 ());
2118
2124
if (!args.hasArg (OPT_driver))
2119
2125
Warn (ctx) << " /align specified without /driver; image may not run" ;
2120
2126
}
@@ -2162,9 +2168,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2162
2168
args.getLastArgValue (OPT_thinlto_index_only_arg);
2163
2169
std::tie (config->thinLTOPrefixReplaceOld , config->thinLTOPrefixReplaceNew ,
2164
2170
config->thinLTOPrefixReplaceNativeObject ) =
2165
- getOldNewOptionsExtra (args, OPT_thinlto_prefix_replace);
2171
+ getOldNewOptionsExtra (ctx, args, OPT_thinlto_prefix_replace);
2166
2172
config->thinLTOObjectSuffixReplace =
2167
- getOldNewOptions (args, OPT_thinlto_object_suffix_replace);
2173
+ getOldNewOptions (ctx, args, OPT_thinlto_object_suffix_replace);
2168
2174
config->ltoObjPath = args.getLastArgValue (OPT_lto_obj_path);
2169
2175
config->ltoCSProfileGenerate = args.hasArg (OPT_lto_cs_profile_generate);
2170
2176
config->ltoCSProfileFile = args.getLastArgValue (OPT_lto_cs_profile_file);
@@ -2258,12 +2264,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2258
2264
switch (arg->getOption ().getID ()) {
2259
2265
case OPT_end_lib:
2260
2266
if (!inLib)
2261
- error ( " stray " + arg->getSpelling () );
2267
+ Err (ctx) << " stray " << arg->getSpelling ();
2262
2268
inLib = false ;
2263
2269
break ;
2264
2270
case OPT_start_lib:
2265
2271
if (inLib)
2266
- error ( " nested " + arg->getSpelling () );
2272
+ Err (ctx) << " nested " << arg->getSpelling ();
2267
2273
inLib = true ;
2268
2274
break ;
2269
2275
case OPT_wholearchive_file:
@@ -2355,8 +2361,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2355
2361
2356
2362
if (!config->dynamicBase &&
2357
2363
(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 );
2360
2366
2361
2367
// Handle /export
2362
2368
{
@@ -2446,7 +2452,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2446
2452
2447
2453
// Fail early if an output file is not writable.
2448
2454
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 ();
2450
2457
return ;
2451
2458
}
2452
2459
@@ -2459,7 +2466,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2459
2466
if (s == " exports" )
2460
2467
config->mapInfo = true ;
2461
2468
else
2462
- error ( " unknown option: /mapinfo:" + s) ;
2469
+ Err (ctx) << " unknown option: /mapinfo:" << s ;
2463
2470
}
2464
2471
}
2465
2472
@@ -2774,7 +2781,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2774
2781
// functions.
2775
2782
if (auto *arg = args.getLastArg (OPT_order)) {
2776
2783
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" ;
2778
2785
parseOrderFile (arg->getValue ());
2779
2786
config->callGraphProfileSort = false ;
2780
2787
}
0 commit comments