Skip to content

Commit 1865f0e

Browse files
committed
[lld-link] Replace warn(...) with Warn(ctx)
1 parent 81c680a commit 1865f0e

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

lld/COFF/PDB.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ struct UnrelocatedFpoData {
183183
enum : uint32_t { kSymbolStreamMagicSize = 4 };
184184

185185
class DebugSHandler {
186+
COFFLinkerContext &ctx;
186187
PDBLinker &linker;
187188

188189
/// The object file whose .debug$S sections we're processing.
@@ -229,8 +230,8 @@ class DebugSHandler {
229230
const DebugSubsectionRecord &ss);
230231

231232
public:
232-
DebugSHandler(PDBLinker &linker, ObjFile &file)
233-
: linker(linker), file(file) {}
233+
DebugSHandler(COFFLinkerContext &ctx, PDBLinker &linker, ObjFile &file)
234+
: ctx(ctx), linker(linker), file(file) {}
234235

235236
void handleDebugS(SectionChunk *debugChunk);
236237

@@ -384,10 +385,11 @@ void PDBLinker::translateIdSymbols(MutableArrayRef<uint8_t> &recordData,
384385
}
385386
}
386387
if (newType == TypeIndex(SimpleTypeKind::NotTranslated)) {
387-
warn(formatv("procedure symbol record for `{0}` in {1} refers to PDB "
388-
"item index {2:X} which is not a valid function ID record",
389-
getSymbolName(CVSymbol(recordData)),
390-
source->file->getName(), ti->getIndex()));
388+
Warn(ctx) << formatv(
389+
"procedure symbol record for `{0}` in {1} refers to PDB "
390+
"item index {2:X} which is not a valid function ID record",
391+
getSymbolName(CVSymbol(recordData)), source->file->getName(),
392+
ti->getIndex());
391393
}
392394
*ti = newType;
393395
}
@@ -420,11 +422,12 @@ static void scopeStackOpen(SmallVectorImpl<uint32_t> &stack,
420422
}
421423

422424
// To close a scope, update the record that opened the scope.
423-
static void scopeStackClose(SmallVectorImpl<uint32_t> &stack,
425+
static void scopeStackClose(COFFLinkerContext &ctx,
426+
SmallVectorImpl<uint32_t> &stack,
424427
std::vector<uint8_t> &storage,
425428
uint32_t storageBaseOffset, ObjFile *file) {
426429
if (stack.empty()) {
427-
warn("symbol scopes are not balanced in " + file->getName());
430+
Warn(ctx) << "symbol scopes are not balanced in " << file->getName();
428431
return;
429432
}
430433

@@ -594,7 +597,7 @@ void PDBLinker::analyzeSymbolSubsection(
594597
cantFail(symData.readBytes(0, symData.getLength(), symsBuffer));
595598

596599
if (symsBuffer.empty())
597-
warn("empty symbols subsection in " + file->getName());
600+
Warn(ctx) << "empty symbols subsection in " << file->getName();
598601

599602
Error ec = forEachCodeViewRecord<CVSymbol>(
600603
symsBuffer, [&](CVSymbol sym) -> llvm::Error {
@@ -635,7 +638,7 @@ void PDBLinker::analyzeSymbolSubsection(
635638
// any partial records, undo that. For globals, we just keep what we have and
636639
// continue.
637640
if (ec) {
638-
warn("corrupt symbol records in " + file->getName());
641+
Warn(ctx) << "corrupt symbol records in " << file->getName();
639642
moduleSymOffset = moduleSymStart;
640643
consumeError(std::move(ec));
641644
}
@@ -678,7 +681,7 @@ Error PDBLinker::writeAllModuleSymbolRecords(ObjFile *file,
678681
if (symbolOpensScope(sym.kind()))
679682
scopeStackOpen(scopes, storage);
680683
else if (symbolEndsScope(sym.kind()))
681-
scopeStackClose(scopes, storage, moduleSymStart, file);
684+
scopeStackClose(ctx, scopes, storage, moduleSymStart, file);
682685

683686
// Copy, relocate, and rewrite each module symbol.
684687
if (symbolGoesInModuleStream(sym, scopes.size())) {
@@ -740,12 +743,12 @@ static pdb::SectionContrib createSectionContrib(COFFLinkerContext &ctx,
740743
}
741744

742745
static uint32_t
743-
translateStringTableIndex(uint32_t objIndex,
746+
translateStringTableIndex(COFFLinkerContext &ctx, uint32_t objIndex,
744747
const DebugStringTableSubsectionRef &objStrTable,
745748
DebugStringTableSubsection &pdbStrTable) {
746749
auto expectedString = objStrTable.getString(objIndex);
747750
if (!expectedString) {
748-
warn("Invalid string table reference");
751+
Warn(ctx) << "Invalid string table reference";
749752
consumeError(expectedString.takeError());
750753
return 0;
751754
}
@@ -820,8 +823,9 @@ void DebugSHandler::handleDebugS(SectionChunk *debugChunk) {
820823
break;
821824

822825
default:
823-
warn("ignoring unknown debug$S subsection kind 0x" +
824-
utohexstr(uint32_t(ss.kind())) + " in file " + toString(&file));
826+
Warn(ctx) << "ignoring unknown debug$S subsection kind 0x"
827+
<< utohexstr(uint32_t(ss.kind())) << " in file "
828+
<< toString(&file);
825829
break;
826830
}
827831
}
@@ -934,8 +938,9 @@ void DebugSHandler::finish() {
934938
"string table subsection");
935939

936940
if (!stringTableFixups.empty())
937-
warn("No StringTable subsection was encountered, but there are string "
938-
"table references");
941+
Warn(ctx)
942+
<< "No StringTable subsection was encountered, but there are string "
943+
"table references";
939944
return;
940945
}
941946

@@ -967,17 +972,17 @@ void DebugSHandler::finish() {
967972
exitOnErr(fds.initialize(reader));
968973
for (codeview::FrameData fd : fds) {
969974
fd.RvaStart += rvaStart;
970-
fd.FrameFunc =
971-
translateStringTableIndex(fd.FrameFunc, cvStrTab, linker.pdbStrTab);
975+
fd.FrameFunc = translateStringTableIndex(ctx, fd.FrameFunc, cvStrTab,
976+
linker.pdbStrTab);
972977
dbiBuilder.addNewFpoData(fd);
973978
}
974979
}
975980

976981
// Translate the fixups and pass them off to the module builder so they will
977982
// be applied during writing.
978983
for (StringTableFixup &ref : stringTableFixups) {
979-
ref.StrTabOffset =
980-
translateStringTableIndex(ref.StrTabOffset, cvStrTab, linker.pdbStrTab);
984+
ref.StrTabOffset = translateStringTableIndex(ctx, ref.StrTabOffset,
985+
cvStrTab, linker.pdbStrTab);
981986
}
982987
file.moduleDBI->setStringTableFixups(std::move(stringTableFixups));
983988

@@ -1032,7 +1037,7 @@ void PDBLinker::addDebugSymbols(TpiSource *source) {
10321037
ScopedTimer t(ctx.symbolMergingTimer);
10331038
ExitOnError exitOnErr;
10341039
pdb::DbiStreamBuilder &dbiBuilder = builder.getDbiBuilder();
1035-
DebugSHandler dsh(*this, *source->file);
1040+
DebugSHandler dsh(ctx, *this, *source->file);
10361041
// Now do all live .debug$S and .debug$F sections.
10371042
for (SectionChunk *debugChunk : source->file->getDebugChunks()) {
10381043
if (!debugChunk->live || debugChunk->getSize() == 0)
@@ -1326,7 +1331,7 @@ void PDBLinker::addNatvisFiles() {
13261331
ErrorOr<std::unique_ptr<MemoryBuffer>> dataOrErr =
13271332
MemoryBuffer::getFile(file);
13281333
if (!dataOrErr) {
1329-
warn("Cannot open input file: " + file);
1334+
Warn(ctx) << "Cannot open input file: " << file;
13301335
continue;
13311336
}
13321337
std::unique_ptr<MemoryBuffer> data = std::move(*dataOrErr);
@@ -1348,7 +1353,7 @@ void PDBLinker::addNamedStreams() {
13481353
ErrorOr<std::unique_ptr<MemoryBuffer>> dataOrErr =
13491354
MemoryBuffer::getFile(file);
13501355
if (!dataOrErr) {
1351-
warn("Cannot open input file: " + file);
1356+
Warn(ctx) << "Cannot open input file: " << file;
13521357
continue;
13531358
}
13541359
std::unique_ptr<MemoryBuffer> data = std::move(*dataOrErr);

lld/COFF/Writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
26862686

26872687
#define RETURN_IF_NOT_CONTAINS(field) \
26882688
if (loadConfigSize < offsetof(T, field) + sizeof(T::field)) { \
2689-
warn("'_load_config_used' structure too small to include " #field); \
2689+
Warn(ctx) << "'_load_config_used' structure too small to include " #field; \
26902690
return; \
26912691
}
26922692

@@ -2696,12 +2696,12 @@ template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
26962696
#define CHECK_VA(field, sym) \
26972697
if (auto *s = dyn_cast<DefinedSynthetic>(ctx.symtab.findUnderscore(sym))) \
26982698
if (loadConfig->field != ctx.config.imageBase + s->getRVA()) \
2699-
warn(#field " not set correctly in '_load_config_used'");
2699+
Warn(ctx) << #field " not set correctly in '_load_config_used'";
27002700

27012701
#define CHECK_ABSOLUTE(field, sym) \
27022702
if (auto *s = dyn_cast<DefinedAbsolute>(ctx.symtab.findUnderscore(sym))) \
27032703
if (loadConfig->field != s->getVA()) \
2704-
warn(#field " not set correctly in '_load_config_used'");
2704+
Warn(ctx) << #field " not set correctly in '_load_config_used'";
27052705

27062706
if (ctx.config.dependentLoadFlags) {
27072707
RETURN_IF_NOT_CONTAINS(DependentLoadFlags)
@@ -2715,8 +2715,8 @@ template <typename T> void Writer::prepareLoadConfig(T *loadConfig) {
27152715
ctx.dynamicRelocs->getRVA() - relocSec->getRVA();
27162716
}
27172717
else {
2718-
warn("'_load_config_used' structure too small to include dynamic "
2719-
"relocations");
2718+
Warn(ctx) << "'_load_config_used' structure too small to include dynamic "
2719+
"relocations";
27202720
}
27212721
}
27222722

0 commit comments

Comments
 (0)