Skip to content

Commit 8b844de

Browse files
committed
[lld-link] Replace fatal(...) with Fatal
1 parent 9a5946c commit 8b844de

File tree

7 files changed

+131
-109
lines changed

7 files changed

+131
-109
lines changed

lld/COFF/DebugTypes.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void TpiSource::remapRecord(MutableArrayRef<uint8_t> rec,
231231
for (const TiReference &ref : typeRefs) {
232232
unsigned byteSize = ref.Count * sizeof(TypeIndex);
233233
if (contents.size() < ref.Offset + byteSize)
234-
fatal("symbol record too short");
234+
Fatal(ctx) << "symbol record too short";
235235

236236
MutableArrayRef<TypeIndex> indices(
237237
reinterpret_cast<TypeIndex *>(contents.data() + ref.Offset), ref.Count);
@@ -320,8 +320,8 @@ Error TpiSource::mergeDebugT(TypeMerger *m) {
320320
std::optional<PCHMergerInfo> pchInfo;
321321
if (auto err = mergeTypeAndIdRecords(m->idTable, m->typeTable,
322322
indexMapStorage, types, pchInfo))
323-
fatal("codeview::mergeTypeAndIdRecords failed: " +
324-
toString(std::move(err)));
323+
Fatal(ctx) << "codeview::mergeTypeAndIdRecords failed: "
324+
<< toString(std::move(err));
325325
if (pchInfo) {
326326
file->pchSignature = pchInfo->PCHSignature;
327327
endPrecompIdx = pchInfo->EndPrecompIndex;
@@ -364,26 +364,30 @@ Error TypeServerSource::mergeDebugT(TypeMerger *m) {
364364
pdb::PDBFile &pdbFile = pdbInputFile->session->getPDBFile();
365365
Expected<pdb::TpiStream &> expectedTpi = pdbFile.getPDBTpiStream();
366366
if (auto e = expectedTpi.takeError())
367-
fatal("Type server does not have TPI stream: " + toString(std::move(e)));
367+
Fatal(ctx) << "Type server does not have TPI stream: "
368+
<< toString(std::move(e));
368369
pdb::TpiStream *maybeIpi = nullptr;
369370
if (pdbFile.hasPDBIpiStream()) {
370371
Expected<pdb::TpiStream &> expectedIpi = pdbFile.getPDBIpiStream();
371372
if (auto e = expectedIpi.takeError())
372-
fatal("Error getting type server IPI stream: " + toString(std::move(e)));
373+
Fatal(ctx) << "Error getting type server IPI stream: "
374+
<< toString(std::move(e));
373375
maybeIpi = &*expectedIpi;
374376
}
375377

376378
// Merge TPI first, because the IPI stream will reference type indices.
377379
if (auto err = mergeTypeRecords(m->typeTable, indexMapStorage,
378380
expectedTpi->typeArray()))
379-
fatal("codeview::mergeTypeRecords failed: " + toString(std::move(err)));
381+
Fatal(ctx) << "codeview::mergeTypeRecords failed: "
382+
<< toString(std::move(err));
380383
tpiMap = indexMapStorage;
381384

382385
// Merge IPI.
383386
if (maybeIpi) {
384387
if (auto err = mergeIdRecords(m->idTable, tpiMap, ipiSrc->indexMapStorage,
385388
maybeIpi->typeArray()))
386-
fatal("codeview::mergeIdRecords failed: " + toString(std::move(err)));
389+
Fatal(ctx) << "codeview::mergeIdRecords failed: "
390+
<< toString(std::move(err));
387391
ipiMap = ipiSrc->indexMapStorage;
388392
}
389393

@@ -572,8 +576,10 @@ void PrecompSource::registerMapping() {
572576
if (file->pchSignature && *file->pchSignature) {
573577
auto it = ctx.precompSourceMappings.emplace(*file->pchSignature, this);
574578
if (!it.second)
575-
fatal("a PCH object with the same signature has already been provided (" +
576-
toString(it.first->second->file) + " and " + toString(file) + ")");
579+
Fatal(ctx)
580+
<< "a PCH object with the same signature has already been provided ("
581+
<< toString(it.first->second->file) << " and " << toString(file)
582+
<< ")";
577583
registered = true;
578584
}
579585
}
@@ -756,7 +762,8 @@ void TypeServerSource::loadGHashes() {
756762
// Hash TPI stream.
757763
Expected<pdb::TpiStream &> expectedTpi = pdbFile.getPDBTpiStream();
758764
if (auto e = expectedTpi.takeError())
759-
fatal("Type server does not have TPI stream: " + toString(std::move(e)));
765+
Fatal(ctx) << "Type server does not have TPI stream: "
766+
<< toString(std::move(e));
760767
assignGHashesFromVector(
761768
GloballyHashedType::hashTypes(expectedTpi->typeArray()));
762769
isItemIndex.resize(ghashes.size());
@@ -766,7 +773,7 @@ void TypeServerSource::loadGHashes() {
766773
return;
767774
Expected<pdb::TpiStream &> expectedIpi = pdbFile.getPDBIpiStream();
768775
if (auto e = expectedIpi.takeError())
769-
fatal("error retrieving IPI stream: " + toString(std::move(e)));
776+
Fatal(ctx) << "error retrieving IPI stream: " << toString(std::move(e));
770777
ipiSrc->assignGHashesFromVector(
771778
GloballyHashedType::hashIds(expectedIpi->typeArray(), ghashes));
772779

lld/COFF/Driver.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
219219
make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
220220

221221
int memberIndex = 0;
222-
for (MemoryBufferRef m : getArchiveMembers(archive))
222+
for (MemoryBufferRef m : getArchiveMembers(ctx, archive))
223223
addArchiveBuffer(m, "<whole-archive>", filename, memberIndex++);
224224
return;
225225
}
@@ -1033,8 +1033,8 @@ void LinkerDriver::createImportLibrary(bool asLib) {
10331033
SmallString<128> tmpName;
10341034
if (std::error_code ec =
10351035
sys::fs::createUniqueFile(path + ".tmp-%%%%%%%%.lib", tmpName))
1036-
fatal("cannot create temporary file for import library " + path + ": " +
1037-
ec.message());
1036+
Fatal(ctx) << "cannot create temporary file for import library " << path
1037+
<< ": " << ec.message();
10381038

10391039
if (Error e = writeImportLibrary(libName, tmpName, exports,
10401040
ctx.config.machine, ctx.config.mingw)) {
@@ -1233,11 +1233,11 @@ static void readCallGraphsFromObjectFiles(COFFLinkerContext &ctx) {
12331233
uint32_t fromIndex, toIndex;
12341234
uint64_t count;
12351235
if (Error err = reader.readInteger(fromIndex))
1236-
fatal(toString(obj) + ": Expected 32-bit integer");
1236+
Fatal(ctx) << toString(obj) << ": Expected 32-bit integer";
12371237
if (Error err = reader.readInteger(toIndex))
1238-
fatal(toString(obj) + ": Expected 32-bit integer");
1238+
Fatal(ctx) << toString(obj) << ": Expected 32-bit integer";
12391239
if (Error err = reader.readInteger(count))
1240-
fatal(toString(obj) + ": Expected 64-bit integer");
1240+
Fatal(ctx) << toString(obj) << ": Expected 64-bit integer";
12411241
auto *fromSym = dyn_cast_or_null<Defined>(obj->getSymbol(fromIndex));
12421242
auto *toSym = dyn_cast_or_null<Defined>(obj->getSymbol(toIndex));
12431243
if (!fromSym || !toSym)
@@ -1279,9 +1279,11 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) {
12791279
const char *err = nullptr;
12801280
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
12811281
if (err)
1282-
fatal(toString(obj) + ": could not decode addrsig section: " + err);
1282+
Fatal(ctx) << toString(obj)
1283+
<< ": could not decode addrsig section: " << err;
12831284
if (symIndex >= syms.size())
1284-
fatal(toString(obj) + ": invalid symbol index in addrsig section");
1285+
Fatal(ctx) << toString(obj)
1286+
<< ": invalid symbol index in addrsig section";
12851287
markAddrsig(syms[symIndex]);
12861288
cur += size;
12871289
}
@@ -1574,7 +1576,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
15741576
(StringRef(argsArr[1]).equals_insensitive("/lib") ||
15751577
StringRef(argsArr[1]).equals_insensitive("-lib"))) {
15761578
if (llvm::libDriverMain(argsArr.slice(1)) != 0)
1577-
fatal("lib failed");
1579+
Fatal(ctx) << "lib failed";
15781580
return;
15791581
}
15801582

@@ -1676,7 +1678,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16761678
if (args.hasArg(OPT_deffile))
16771679
config->noEntry = true;
16781680
else
1679-
fatal("no input files");
1681+
Fatal(ctx) << "no input files";
16801682
}
16811683

16821684
// Construct search path list.
@@ -1887,7 +1889,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
18871889
if (auto *arg = args.getLastArg(OPT_machine)) {
18881890
config->machine = getMachineType(arg->getValue());
18891891
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN)
1890-
fatal(Twine("unknown /machine argument: ") + arg->getValue());
1892+
Fatal(ctx) << "unknown /machine argument: " << arg->getValue();
18911893
addWinSysRootLibSearchPaths();
18921894
}
18931895
}
@@ -1955,17 +1957,17 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
19551957
config->repro = false;
19561958
StringRef value(arg->getValue());
19571959
if (value.getAsInteger(0, config->timestamp))
1958-
fatal(Twine("invalid timestamp: ") + value +
1959-
". Expected 32-bit integer");
1960+
Fatal(ctx) << "invalid timestamp: " << value
1961+
<< ". Expected 32-bit integer";
19601962
}
19611963
} else {
19621964
config->repro = false;
19631965
if (std::optional<std::string> epoch =
19641966
Process::GetEnv("SOURCE_DATE_EPOCH")) {
19651967
StringRef value(*epoch);
19661968
if (value.getAsInteger(0, config->timestamp))
1967-
fatal(Twine("invalid SOURCE_DATE_EPOCH timestamp: ") + value +
1968-
". Expected 32-bit integer");
1969+
Fatal(ctx) << "invalid SOURCE_DATE_EPOCH timestamp: " << value
1970+
<< ". Expected 32-bit integer";
19691971
} else {
19701972
config->timestamp = time(nullptr);
19711973
}
@@ -2155,7 +2157,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
21552157

21562158
if (!config->manifestInput.empty() &&
21572159
config->manifest != Configuration::Embed) {
2158-
fatal("/manifestinput: requires /manifest:embed");
2160+
Fatal(ctx) << "/manifestinput: requires /manifest:embed";
21592161
}
21602162

21612163
// Handle /dwodir
@@ -2400,15 +2402,15 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24002402
llvm::TimeTraceScope timeScope("Infer subsystem");
24012403
config->subsystem = inferSubsystem();
24022404
if (config->subsystem == IMAGE_SUBSYSTEM_UNKNOWN)
2403-
fatal("subsystem must be defined");
2405+
Fatal(ctx) << "subsystem must be defined";
24042406
}
24052407

24062408
// Handle /entry and /dll
24072409
{
24082410
llvm::TimeTraceScope timeScope("Entry point");
24092411
if (auto *arg = args.getLastArg(OPT_entry)) {
24102412
if (!arg->getValue()[0])
2411-
fatal("missing entry point symbol name");
2413+
Fatal(ctx) << "missing entry point symbol name";
24122414
config->entry = addUndefined(mangle(arg->getValue()), true);
24132415
} else if (!config->entry && !config->noEntry) {
24142416
if (args.hasArg(OPT_dll)) {
@@ -2423,7 +2425,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
24232425
// infer that from user-defined entry name.
24242426
StringRef s = findDefaultEntry();
24252427
if (s.empty())
2426-
fatal("entry point must be defined");
2428+
Fatal(ctx) << "entry point must be defined";
24272429
config->entry = addUndefined(s, true);
24282430
Log(ctx) << "Entry name inferred: " << s;
24292431
}

0 commit comments

Comments
 (0)