Skip to content

Commit 1534f45

Browse files
committed
[lld-link] Replace warn(...) with Warn(ctx)
1 parent 52aff97 commit 1534f45

File tree

6 files changed

+79
-70
lines changed

6 files changed

+79
-70
lines changed

lld/COFF/DebugTypes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,8 @@ void TpiSource::mergeTypeRecord(TypeIndex curIndex, CVType ty) {
674674
funcIdToType.push_back({funcId, funcType});
675675
} else {
676676
StringRef fname = file ? file->getName() : "<unknown PDB>";
677-
warn("corrupt LF_[M]FUNC_ID record 0x" + utohexstr(curIndex.getIndex()) +
678-
" in " + fname);
677+
Warn(ctx) << "corrupt LF_[M]FUNC_ID record 0x"
678+
<< utohexstr(curIndex.getIndex()) << " in " << fname;
679679
}
680680
}
681681
}
@@ -836,7 +836,7 @@ void UseTypeServerSource::remapTpiWithGHashes(GHashState *g) {
836836

837837
void PrecompSource::loadGHashes() {
838838
if (getDebugH(file)) {
839-
warn("ignoring .debug$H section; pch with ghash is not implemented");
839+
Warn(ctx) << "ignoring .debug$H section; pch with ghash is not implemented";
840840
}
841841

842842
uint32_t ghashIdx = 0;
@@ -864,7 +864,7 @@ void PrecompSource::loadGHashes() {
864864
void UsePrecompSource::loadGHashes() {
865865
auto e = findPrecompMap(file, precompDependency);
866866
if (!e) {
867-
warn(toString(e.takeError()));
867+
Warn(ctx) << e.takeError();
868868
return;
869869
}
870870

lld/COFF/Driver.cpp

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ StringRef LinkerDriver::findDefaultEntry() {
809809
if (findUnderscoreMangle("wmain")) {
810810
if (!findUnderscoreMangle("main"))
811811
return mangle("wmainCRTStartup");
812-
warn("found both wmain and main; using latter");
812+
Warn(ctx) << "found both wmain and main; using latter";
813813
}
814814
return mangle("mainCRTStartup");
815815
}
@@ -828,9 +828,9 @@ WindowsSubsystem LinkerDriver::inferSubsystem() {
828828
bool haveWWinMain = findUnderscoreMangle("wWinMain");
829829
if (haveMain || haveWMain) {
830830
if (haveWinMain || haveWWinMain) {
831-
warn(std::string("found ") + (haveMain ? "main" : "wmain") + " and " +
832-
(haveWinMain ? "WinMain" : "wWinMain") +
833-
"; defaulting to /subsystem:console");
831+
Warn(ctx) << "found " << (haveMain ? "main" : "wmain") << " and "
832+
<< (haveWinMain ? "WinMain" : "wWinMain")
833+
<< "; defaulting to /subsystem:console";
834834
}
835835
return IMAGE_SUBSYSTEM_WINDOWS_CUI;
836836
}
@@ -910,7 +910,8 @@ static std::string createResponseFile(const opt::InputArgList &args,
910910
return std::string(data);
911911
}
912912

913-
static unsigned parseDebugTypes(const opt::InputArgList &args) {
913+
static unsigned parseDebugTypes(COFFLinkerContext &ctx,
914+
const opt::InputArgList &args) {
914915
unsigned debugTypes = static_cast<unsigned>(DebugType::None);
915916

916917
if (auto *a = args.getLastArg(OPT_debugtype)) {
@@ -925,7 +926,7 @@ static unsigned parseDebugTypes(const opt::InputArgList &args) {
925926
.Case("fixup", static_cast<unsigned>(DebugType::Fixup))
926927
.Default(0);
927928
if (v == 0) {
928-
warn("/debugtype: unknown option '" + type + "'");
929+
Warn(ctx) << "/debugtype: unknown option '" << type << "'";
929930
continue;
930931
}
931932
debugTypes |= v;
@@ -1162,7 +1163,8 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
11621163

11631164
if (set.count(s) == 0) {
11641165
if (ctx.config.warnMissingOrderSymbol)
1165-
warn("/order:" + arg + ": missing symbol: " + s + " [LNK4037]");
1166+
Warn(ctx) << "/order:" << arg << ": missing symbol: " << s
1167+
<< " [LNK4037]";
11661168
} else
11671169
ctx.config.order[s] = INT_MIN + ctx.config.order.size();
11681170
}
@@ -1189,7 +1191,7 @@ void LinkerDriver::parseCallGraphFile(StringRef path) {
11891191
Symbol *sym = map.lookup(name);
11901192
if (!sym) {
11911193
if (ctx.config.warnMissingOrderSymbol)
1192-
warn(path + ": no such symbol: " + name);
1194+
Warn(ctx) << path << ": no such symbol: " << name;
11931195
return nullptr;
11941196
}
11951197

@@ -1332,8 +1334,8 @@ void LinkerDriver::parsePDBAltPath() {
13321334
else if (var.equals_insensitive("%_ext%"))
13331335
buf.append(binaryExtension);
13341336
else {
1335-
warn("only %_PDB% and %_EXT% supported in /pdbaltpath:, keeping " + var +
1336-
" as literal");
1337+
Warn(ctx) << "only %_PDB% and %_EXT% supported in /pdbaltpath:, keeping "
1338+
<< var << " as literal";
13371339
buf.append(var);
13381340
}
13391341

@@ -1691,7 +1693,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16911693
addLibSearchPaths();
16921694
} else {
16931695
if (args.hasArg(OPT_vctoolsdir, OPT_winsysroot))
1694-
warn("ignoring /vctoolsdir or /winsysroot flags in MinGW mode");
1696+
Warn(ctx) << "ignoring /vctoolsdir or /winsysroot flags in MinGW mode";
16951697
}
16961698
}
16971699

@@ -1752,7 +1754,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
17521754
StringRef(str).split(vec, ',');
17531755
for (StringRef s : vec) {
17541756
if (s == "fastlink") {
1755-
warn("/debug:fastlink unsupported; using /debug:full");
1757+
Warn(ctx) << "/debug:fastlink unsupported; using /debug:full";
17561758
s = "full";
17571759
}
17581760
if (s == "none") {
@@ -1795,7 +1797,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
17951797
config->demangle = args.hasFlag(OPT_demangle, OPT_demangle_no, true);
17961798

17971799
// Handle /debugtype
1798-
config->debugTypes = parseDebugTypes(args);
1800+
config->debugTypes = parseDebugTypes(ctx, args);
17991801

18001802
// Handle /driver[:uponly|:wdm].
18011803
config->driverUponly = args.hasArg(OPT_driver_uponly) ||
@@ -1832,7 +1834,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18321834

18331835
// Handle /pdbstripped
18341836
if (args.hasArg(OPT_pdbstripped))
1835-
warn("ignoring /pdbstripped flag, it is not yet supported");
1837+
Warn(ctx) << "ignoring /pdbstripped flag, it is not yet supported";
18361838

18371839
// Handle /noentry
18381840
if (args.hasArg(OPT_noentry)) {
@@ -2114,7 +2116,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
21142116
if (!isPowerOf2_64(config->align))
21152117
error("/align: not a power of two: " + StringRef(arg->getValue()));
21162118
if (!args.hasArg(OPT_driver))
2117-
warn("/align specified without /driver; image may not run");
2119+
Warn(ctx) << "/align specified without /driver; image may not run";
21182120
}
21192121

21202122
// Handle /aligncomm
@@ -2199,27 +2201,29 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
21992201
OPT_lld_allow_duplicate_weak_no, config->mingw);
22002202

22012203
if (args.hasFlag(OPT_inferasanlibs, OPT_inferasanlibs_no, false))
2202-
warn("ignoring '/inferasanlibs', this flag is not supported");
2204+
Warn(ctx) << "ignoring '/inferasanlibs', this flag is not supported";
22032205

22042206
if (config->incremental && args.hasArg(OPT_profile)) {
2205-
warn("ignoring '/incremental' due to '/profile' specification");
2207+
Warn(ctx) << "ignoring '/incremental' due to '/profile' specification";
22062208
config->incremental = false;
22072209
}
22082210

22092211
if (config->incremental && args.hasArg(OPT_order)) {
2210-
warn("ignoring '/incremental' due to '/order' specification");
2212+
Warn(ctx) << "ignoring '/incremental' due to '/order' specification";
22112213
config->incremental = false;
22122214
}
22132215

22142216
if (config->incremental && config->doGC) {
2215-
warn("ignoring '/incremental' because REF is enabled; use '/opt:noref' to "
2216-
"disable");
2217+
Warn(ctx) << "ignoring '/incremental' because REF is enabled; use "
2218+
"'/opt:noref' to "
2219+
"disable";
22172220
config->incremental = false;
22182221
}
22192222

22202223
if (config->incremental && config->doICF != ICFLevel::None) {
2221-
warn("ignoring '/incremental' because ICF is enabled; use '/opt:noicf' to "
2222-
"disable");
2224+
Warn(ctx) << "ignoring '/incremental' because ICF is enabled; use "
2225+
"'/opt:noicf' to "
2226+
"disable";
22232227
config->incremental = false;
22242228
}
22252229

@@ -2285,7 +2289,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22852289
// We should have inferred a machine type by now from the input files, but if
22862290
// not we assume x64.
22872291
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN) {
2288-
warn("/machine is not specified. x64 is assumed");
2292+
Warn(ctx) << "/machine is not specified. x64 is assumed";
22892293
config->machine = AMD64;
22902294
addWinSysRootLibSearchPaths();
22912295
}
@@ -2460,8 +2464,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24602464
}
24612465

24622466
if (config->lldmapFile != "" && config->lldmapFile == config->mapFile) {
2463-
warn("/lldmap and /map have the same output file '" + config->mapFile +
2464-
"'.\n>>> ignoring /lldmap");
2467+
Warn(ctx) << "/lldmap and /map have the same output file '"
2468+
<< config->mapFile << "'.\n>>> ignoring /lldmap";
24652469
config->lldmapFile.clear();
24662470
}
24672471

@@ -2741,7 +2745,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27412745

27422746
Symbol *sym = ctx.symtab.find(name);
27432747
if (!sym) {
2744-
warn("/aligncomm symbol " + name + " not found");
2748+
Warn(ctx) << "/aligncomm symbol " << name << " not found";
27452749
continue;
27462750
}
27472751

lld/COFF/DriverUtils.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void LinkerDriver::parseMerge(StringRef s) {
172172
if (!inserted) {
173173
StringRef existing = pair.first->second;
174174
if (existing != to)
175-
warn(s + ": already merged into " + existing);
175+
Warn(ctx) << s << ": already merged into " << existing;
176176
}
177177
}
178178

@@ -741,12 +741,12 @@ void LinkerDriver::fixupExports() {
741741
continue;
742742
}
743743
if (existing->source == e.source) {
744-
warn(Twine("duplicate ") + exportSourceName(existing->source) +
745-
" option: " + e.name);
744+
Warn(ctx) << "duplicate " << exportSourceName(existing->source)
745+
<< " option: " << e.name;
746746
} else {
747-
warn("duplicate export: " + e.name +
748-
Twine(" first seen in " + exportSourceName(existing->source) +
749-
Twine(", now in " + exportSourceName(e.source))));
747+
Warn(ctx) << "duplicate export: " << e.name << " first seen in "
748+
<< exportSourceName(existing->source) << ", now in "
749+
<< exportSourceName(e.source);
750750
}
751751
}
752752
ctx.config.exports = std::move(v);
@@ -822,7 +822,7 @@ MemoryBufferRef LinkerDriver::convertResToCOFF(ArrayRef<MemoryBufferRef> mbs,
822822

823823
for (const auto &dupeDiag : duplicates)
824824
if (ctx.config.forceMultipleRes)
825-
warn(dupeDiag);
825+
Warn(ctx) << dupeDiag;
826826
else
827827
error(dupeDiag);
828828

@@ -945,14 +945,15 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
945945
for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) {
946946
std::string nearest;
947947
if (ctx.optTable.findNearest(arg->getAsString(args), nearest) > 1)
948-
warn("ignoring unknown argument '" + arg->getAsString(args) + "'");
948+
Warn(ctx) << "ignoring unknown argument '" << arg->getAsString(args)
949+
<< "'";
949950
else
950-
warn("ignoring unknown argument '" + arg->getAsString(args) +
951-
"', did you mean '" + nearest + "'");
951+
Warn(ctx) << "ignoring unknown argument '" << arg->getAsString(args)
952+
<< "', did you mean '" << nearest << "'";
952953
}
953954

954955
if (args.hasArg(OPT_lib))
955-
warn("ignoring /lib since it's not the first argument");
956+
Warn(ctx) << "ignoring /lib since it's not the first argument";
956957

957958
return args;
958959
}
@@ -994,7 +995,7 @@ ParsedDirectives ArgParser::parseDirectives(StringRef s) {
994995
if (missingCount)
995996
fatal(Twine(result.args.getArgString(missingIndex)) + ": missing argument");
996997
for (auto *arg : result.args.filtered(OPT_UNKNOWN))
997-
warn("ignoring unknown argument: " + arg->getAsString(result.args));
998+
Warn(ctx) << "ignoring unknown argument: " << arg->getAsString(result.args);
998999
return result;
9991000
}
10001001

lld/COFF/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void ObjFile::initializeECThunks() {
206206
case Arm64ECThunkType::GuestExit:
207207
break;
208208
default:
209-
warn("Ignoring unknown EC thunk type " + Twine(entry->type));
209+
Warn(ctx) << "Ignoring unknown EC thunk type " << entry->type;
210210
}
211211
}
212212
}

lld/COFF/SymbolTable.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ void SymbolTable::loadMinGWSymbols() {
327327
// If it's lazy or already defined, hook it up as weak alias.
328328
if (l->isLazy() || isa<Defined>(l)) {
329329
if (ctx.config.warnStdcallFixup)
330-
warn("Resolving " + origName + " by linking to " + newName);
330+
Warn(ctx) << "Resolving " << origName << " by linking to "
331+
<< newName;
331332
else
332333
log("Resolving " + origName + " by linking to " + newName);
333334
undef->setWeakAlias(l);
@@ -379,9 +380,9 @@ bool SymbolTable::handleMinGWAutomaticImport(Symbol *sym, StringRef name) {
379380
toString(cast<DefinedRegular>(imp)->file));
380381
impSize = sizeof(DefinedRegular);
381382
} else {
382-
warn("unable to automatically import " + name + " from " + imp->getName() +
383-
" from " + toString(cast<DefinedRegular>(imp)->file) +
384-
"; unexpected symbol type");
383+
Warn(ctx) << "unable to automatically import " << name << " from "
384+
<< imp->getName() << " from " << cast<DefinedRegular>(imp)->file
385+
<< "; unexpected symbol type";
385386
return false;
386387
}
387388
sym->replaceKeepingName(imp, impSize);
@@ -412,7 +413,7 @@ bool SymbolTable::handleMinGWAutomaticImport(Symbol *sym, StringRef name) {
412413
/// objFiles and bitcodeFiles (if not nullptr) are used to report where
413414
/// undefined symbols are referenced.
414415
static void reportProblemSymbols(
415-
const COFFLinkerContext &ctx, const SmallPtrSetImpl<Symbol *> &undefs,
416+
COFFLinkerContext &ctx, const SmallPtrSetImpl<Symbol *> &undefs,
416417
const DenseMap<Symbol *, Symbol *> *localImports, bool needBitcodeFiles) {
417418
// Return early if there is nothing to report (which should be
418419
// the common case).
@@ -425,8 +426,9 @@ static void reportProblemSymbols(
425426
ctx.config.forceUnresolved);
426427
if (localImports)
427428
if (Symbol *imp = localImports->lookup(b))
428-
warn("<root>: locally defined symbol imported: " + toString(ctx, *imp) +
429-
" (defined in " + toString(imp->getFile()) + ") [LNK4217]");
429+
Warn(ctx) << "<root>: locally defined symbol imported: "
430+
<< toString(ctx, *imp) << " (defined in "
431+
<< toString(imp->getFile()) << ") [LNK4217]";
430432
}
431433

432434
std::vector<UndefinedDiag> undefDiags;
@@ -447,9 +449,9 @@ static void reportProblemSymbols(
447449
}
448450
if (localImports)
449451
if (Symbol *imp = localImports->lookup(sym))
450-
warn(toString(file) +
451-
": locally defined symbol imported: " + toString(ctx, *imp) +
452-
" (defined in " + toString(imp->getFile()) + ") [LNK4217]");
452+
Warn(ctx) << file << ": locally defined symbol imported: "
453+
<< toString(ctx, *imp) << " (defined in " << imp->getFile()
454+
<< ") [LNK4217]";
453455
}
454456
};
455457

@@ -814,7 +816,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
814816
existing->getName());
815817

816818
if (ctx.config.forceMultiple)
817-
warn(msg);
819+
Warn(ctx) << msg;
818820
else
819821
error(msg);
820822
}

0 commit comments

Comments
 (0)