Skip to content

Commit f8bae3a

Browse files
committed
[ELF] Replace warn(...) with Warn
1 parent 09c2c5e commit f8bae3a

16 files changed

+114
-100
lines changed

lld/ELF/ARMErrataFix.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ static ScanResult scanCortexA8Errata657417(InputSection *isec, uint64_t &off,
300300
scanRes.off = branchOff;
301301
scanRes.instr = instr2;
302302
} else {
303-
warn(toString(isec->file) +
304-
": skipping cortex-a8 657417 erratum sequence, section " +
305-
isec->name + " is too large to patch");
303+
Warn(ctx) << isec->file
304+
<< ": skipping cortex-a8 657417 erratum sequence, section "
305+
<< isec->name << " is too large to patch";
306306
}
307307
}
308308
}

lld/ELF/Arch/ARM.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,19 @@ static void stateChangeWarning(Ctx &ctx, uint8_t *loc, RelType relt,
504504
if (s.isSection()) {
505505
// Section symbols must be defined and in a section. Users cannot change
506506
// the type. Use the section name as getName() returns an empty string.
507-
warn(place.loc + "branch and link relocation: " + toString(relt) +
508-
" to STT_SECTION symbol " + cast<Defined>(s).section->name +
509-
" ; interworking not performed" + hint);
507+
Warn(ctx) << place.loc << "branch and link relocation: " << relt
508+
<< " to STT_SECTION symbol " << cast<Defined>(s).section->name
509+
<< " ; interworking not performed" << hint;
510510
} else {
511511
// Warn with hint on how to alter the symbol type.
512-
warn(getErrorLoc(ctx, loc) + "branch and link relocation: " +
513-
toString(relt) + " to non STT_FUNC symbol: " + s.getName() +
514-
" interworking not performed; consider using directive '.type " +
515-
s.getName() +
516-
", %function' to give symbol type STT_FUNC if interworking between "
517-
"ARM and Thumb is required" +
518-
hint);
512+
Warn(ctx)
513+
<< getErrorLoc(ctx, loc) << "branch and link relocation: " << relt
514+
<< " to non STT_FUNC symbol: " << s.getName()
515+
<< " interworking not performed; consider using directive '.type "
516+
<< s.getName()
517+
<< ", %function' to give symbol type STT_FUNC if interworking between "
518+
"ARM and Thumb is required"
519+
<< hint;
519520
}
520521
}
521522

@@ -1236,9 +1237,9 @@ template <class ELFT> void ObjFile<ELFT>::importCmseSymbols() {
12361237
}
12371238

12381239
if (eSym.st_size != ACLESESYM_SIZE) {
1239-
warn("CMSE symbol '" + sym->getName() + "' in import library '" +
1240-
toString(this) + "' does not have correct size of " +
1241-
Twine(ACLESESYM_SIZE) + " bytes");
1240+
Warn(ctx) << "CMSE symbol '" << sym->getName() << "' in import library '"
1241+
<< this << "' does not have correct size of "
1242+
<< Twine(ACLESESYM_SIZE) << " bytes";
12421243
}
12431244

12441245
ctx.symtab->cmseImportLib[sym->getName()] = sym;
@@ -1360,16 +1361,17 @@ ArmCmseSGSection::ArmCmseSGSection(Ctx &ctx)
13601361
cast<Defined>(entryFunc.sym));
13611362
for (auto &[_, sym] : ctx.symtab->cmseImportLib) {
13621363
if (!ctx.symtab->inCMSEOutImpLib.count(sym->getName()))
1363-
warn("entry function '" + sym->getName() +
1364-
"' from CMSE import library is not present in secure application");
1364+
Warn(ctx)
1365+
<< "entry function '" << sym->getName()
1366+
<< "' from CMSE import library is not present in secure application";
13651367
}
13661368

13671369
if (!ctx.symtab->cmseImportLib.empty() && ctx.arg.cmseOutputLib.empty()) {
13681370
for (auto &[_, entryFunc] : ctx.symtab->cmseSymMap) {
13691371
Symbol *sym = entryFunc.sym;
13701372
if (!ctx.symtab->inCMSEOutImpLib.count(sym->getName()))
1371-
warn("new entry function '" + sym->getName() +
1372-
"' introduced but no output import library specified");
1373+
Warn(ctx) << "new entry function '" << sym->getName()
1374+
<< "' introduced but no output import library specified";
13731375
}
13741376
}
13751377
}

lld/ELF/Arch/Mips.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,
8787
// (e.g. a table of function pointers). When we encounter this, ignore the
8888
// relocation and emit a warning instead.
8989
if (!s.isFunc() && s.type != STT_NOTYPE) {
90-
warn(getErrorLoc(ctx, loc) +
91-
"found R_MIPS_JALR relocation against non-function symbol " +
92-
toString(s) + ". This is invalid and most likely a compiler bug.");
90+
Warn(ctx) << getErrorLoc(ctx, loc)
91+
<< "found R_MIPS_JALR relocation against non-function symbol "
92+
<< &s << ". This is invalid and most likely a compiler bug.";
9393
return R_NONE;
9494
}
9595

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,11 @@ static uint32_t getPicFlags(ArrayRef<FileFlags> files) {
108108
for (const FileFlags &f : files.slice(1)) {
109109
bool isPic2 = f.flags & (EF_MIPS_PIC | EF_MIPS_CPIC);
110110
if (isPic && !isPic2)
111-
warn(toString(f.file) +
112-
": linking non-abicalls code with abicalls code " +
113-
toString(files[0].file));
111+
Warn(ctx) << f.file << ": linking non-abicalls code with abicalls code "
112+
<< files[0].file;
114113
if (!isPic && isPic2)
115-
warn(toString(f.file) +
116-
": linking abicalls code with non-abicalls code " +
117-
toString(files[0].file));
114+
Warn(ctx) << f.file << ": linking abicalls code with non-abicalls code "
115+
<< files[0].file;
118116
}
119117

120118
// Compute the result PIC/non-PIC flag.

lld/ELF/Arch/RISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ mergeAttributesSection(Ctx &ctx,
11891189
for (const InputSectionBase *sec : sections) {
11901190
RISCVAttributeParser parser;
11911191
if (Error e = parser.parse(sec->content(), llvm::endianness::little))
1192-
warn(toString(sec) + ": " + llvm::toString(std::move(e)));
1192+
Warn(ctx) << sec << ": " << llvm::toString(std::move(e));
11931193
for (const auto &tag : attributesTags) {
11941194
switch (RISCVAttrs::AttrType(tag.attr)) {
11951195
// Integer attributes.

lld/ELF/Driver.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args);
8686

8787
void elf::errorOrWarn(const Twine &msg) {
8888
if (ctx.arg.noinhibitExec)
89-
warn(msg);
89+
Warn(ctx) << msg;
9090
else
9191
ErrAlways(ctx) << msg;
9292
}
@@ -346,8 +346,9 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
346346
} else if (magic == file_magic::bitcode)
347347
files.push_back(make<BitcodeFile>(ctx, p.first, path, p.second, true));
348348
else
349-
warn(path + ": archive member '" + p.first.getBufferIdentifier() +
350-
"' is neither ET_REL nor LLVM bitcode");
349+
Warn(ctx) << path << ": archive member '"
350+
<< p.first.getBufferIdentifier()
351+
<< "' is neither ET_REL nor LLVM bitcode";
351352
}
352353
if (!saved.get())
353354
++nextGroupId;
@@ -627,7 +628,7 @@ static void checkZOptions(opt::InputArgList &args) {
627628
getZFlag(args, "rel", "rela", false);
628629
for (auto *arg : args.filtered(OPT_z))
629630
if (!arg->isClaimed())
630-
warn("unknown -z value: " + StringRef(arg->getValue()));
631+
Warn(ctx) << "unknown -z value: " << StringRef(arg->getValue());
631632
}
632633

633634
constexpr const char *saveTempsValues[] = {
@@ -838,11 +839,11 @@ static int getMemtagMode(Ctx &ctx, opt::InputArgList &args) {
838839
StringRef memtagModeArg = args.getLastArgValue(OPT_android_memtag_mode);
839840
if (memtagModeArg.empty()) {
840841
if (ctx.arg.androidMemtagStack)
841-
warn("--android-memtag-mode is unspecified, leaving "
842-
"--android-memtag-stack a no-op");
842+
Warn(ctx) << "--android-memtag-mode is unspecified, leaving "
843+
"--android-memtag-stack a no-op";
843844
else if (ctx.arg.androidMemtagHeap)
844-
warn("--android-memtag-mode is unspecified, leaving "
845-
"--android-memtag-heap a no-op");
845+
Warn(ctx) << "--android-memtag-mode is unspecified, leaving "
846+
"--android-memtag-heap a no-op";
846847
return ELF::NT_MEMTAG_LEVEL_NONE;
847848
}
848849

@@ -981,7 +982,7 @@ static void readCallGraph(Ctx &ctx, MemoryBufferRef mb) {
981982
Symbol *sym = map.lookup(name);
982983
if (!sym) {
983984
if (ctx.arg.warnSymbolOrdering)
984-
warn(mb.getBufferIdentifier() + ": no such symbol: " + name);
985+
Warn(ctx) << mb.getBufferIdentifier() << ": no such symbol: " << name;
985986
return nullptr;
986987
}
987988
maybeWarnUnorderableSymbol(ctx, sym);
@@ -1054,7 +1055,8 @@ processCallGraphRelocations(Ctx &ctx, SmallVector<uint32_t, 32> &symbolIndices,
10541055
}
10551056
}
10561057
if (symbolIndices.empty())
1057-
warn("SHT_LLVM_CALL_GRAPH_PROFILE exists, but relocation section doesn't");
1058+
Warn(ctx)
1059+
<< "SHT_LLVM_CALL_GRAPH_PROFILE exists, but relocation section doesn't";
10581060
return !symbolIndices.empty();
10591061
}
10601062

@@ -1210,7 +1212,8 @@ static SmallVector<StringRef, 0> getSymbolOrderingFile(Ctx &ctx,
12101212
SetVector<StringRef, SmallVector<StringRef, 0>> names;
12111213
for (StringRef s : args::getLines(mb))
12121214
if (!names.insert(s) && ctx.arg.warnSymbolOrdering)
1213-
warn(mb.getBufferIdentifier() + ": duplicate ordered symbol: " + s);
1215+
Warn(ctx) << mb.getBufferIdentifier()
1216+
<< ": duplicate ordered symbol: " << s;
12141217

12151218
return names.takeVector();
12161219
}
@@ -2118,7 +2121,8 @@ static uint64_t getMaxPageSize(Ctx &ctx, opt::InputArgList &args) {
21182121
}
21192122
if (ctx.arg.nmagic || ctx.arg.omagic) {
21202123
if (val != ctx.target->defaultMaxPageSize)
2121-
warn("-z max-page-size set, but paging disabled by omagic or nmagic");
2124+
Warn(ctx)
2125+
<< "-z max-page-size set, but paging disabled by omagic or nmagic";
21222126
return 1;
21232127
}
21242128
return val;
@@ -2135,7 +2139,8 @@ static uint64_t getCommonPageSize(Ctx &ctx, opt::InputArgList &args) {
21352139
}
21362140
if (ctx.arg.nmagic || ctx.arg.omagic) {
21372141
if (val != ctx.target->defaultCommonPageSize)
2138-
warn("-z common-page-size set, but paging disabled by omagic or nmagic");
2142+
Warn(ctx)
2143+
<< "-z common-page-size set, but paging disabled by omagic or nmagic";
21392144
return 1;
21402145
}
21412146
// commonPageSize can't be larger than maxPageSize.
@@ -2159,7 +2164,7 @@ static std::optional<uint64_t> getImageBase(Ctx &ctx, opt::InputArgList &args) {
21592164
return 0;
21602165
}
21612166
if ((v % ctx.arg.maxPageSize) != 0)
2162-
warn("--image-base: address isn't multiple of page size: " + s);
2167+
Warn(ctx) << "--image-base: address isn't multiple of page size: " << s;
21632168
return v;
21642169
}
21652170

@@ -2316,8 +2321,8 @@ static void reportBackrefs(Ctx &ctx) {
23162321
break;
23172322
}
23182323
if (!exclude)
2319-
warn("backward reference detected: " + sym.getName() + " in " +
2320-
toString(ref.second.first) + " refers to " + to);
2324+
Warn(ctx) << "backward reference detected: " << sym.getName() << " in "
2325+
<< ref.second.first << " refers to " << to;
23212326
}
23222327
}
23232328

@@ -2434,7 +2439,7 @@ static void findKeepUniqueSections(Ctx &ctx, opt::InputArgList &args) {
24342439
StringRef name = arg->getValue();
24352440
auto *d = dyn_cast_or_null<Defined>(ctx.symtab->find(name));
24362441
if (!d || !d->section) {
2437-
warn("could not find symbol " + name + " to keep unique");
2442+
Warn(ctx) << "could not find symbol " << name << " to keep unique";
24382443
continue;
24392444
}
24402445
d->section->keepUnique = true;
@@ -2749,7 +2754,7 @@ static void reportMissingFeature(StringRef config, const Twine &report) {
27492754
if (config == "error")
27502755
ErrAlways(ctx) << report;
27512756
else if (config == "warning")
2752-
warn(report);
2757+
Warn(ctx) << report;
27532758
}
27542759

27552760
static void checkAndReportMissingFeature(StringRef config, uint32_t features,
@@ -2820,13 +2825,15 @@ static void readSecurityNotes(Ctx &ctx) {
28202825
} else if (ctx.arg.zForceIbt &&
28212826
!(features & GNU_PROPERTY_X86_FEATURE_1_IBT)) {
28222827
if (ctx.arg.zCetReport == "none")
2823-
warn(toString(f) + ": -z force-ibt: file does not have "
2824-
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
2828+
Warn(ctx) << f
2829+
<< ": -z force-ibt: file does not have "
2830+
"GNU_PROPERTY_X86_FEATURE_1_IBT property";
28252831
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
28262832
}
28272833
if (ctx.arg.zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
2828-
warn(toString(f) + ": -z pac-plt: file does not have "
2829-
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property");
2834+
Warn(ctx) << f
2835+
<< ": -z pac-plt: file does not have "
2836+
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property";
28302837
features |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
28312838
}
28322839
ctx.arg.andFeatures &= features;

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ template <class ELFT> DWARFCache *ObjFile<ELFT>::getDwarf() {
482482
std::make_unique<LLDDwarfObj<ELFT>>(this), "",
483483
[&](Error err) { warn(getName() + ": " + toString(std::move(err))); },
484484
[&](Error warning) {
485-
warn(getName() + ": " + toString(std::move(warning)));
485+
Warn(ctx) << getName() << ": " << std::move(warning);
486486
}));
487487
});
488488

@@ -634,7 +634,7 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
634634
? llvm::endianness::little
635635
: llvm::endianness::big)) {
636636
InputSection isec(*this, sec, name);
637-
warn(toString(&isec) + ": " + llvm::toString(std::move(e)));
637+
Warn(ctx) << &isec << ": " << llvm::toString(std::move(e));
638638
} else {
639639
updateSupportedARMFeatures(ctx, attributes);
640640
updateARMVFPArgs(ctx, attributes, this);
@@ -802,12 +802,12 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats,
802802
if (sec.sh_link != 0)
803803
this->addrsigSec = &sec;
804804
else if (ctx.arg.icf == ICFLevel::Safe)
805-
warn(toString(this) +
806-
": --icf=safe conservatively ignores "
807-
"SHT_LLVM_ADDRSIG [index " +
808-
Twine(i) +
809-
"] with sh_link=0 "
810-
"(likely created using objcopy or ld -r)");
805+
Warn(ctx) << this
806+
<< ": --icf=safe conservatively ignores "
807+
"SHT_LLVM_ADDRSIG [index "
808+
<< Twine(i)
809+
<< "] with sh_link=0 "
810+
"(likely created using objcopy or ld -r)";
811811
}
812812
this->sections[i] = &InputSection::discarded;
813813
continue;

lld/ELF/InputSection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,9 @@ void InputSection::copyRelocations(Ctx &ctx, uint8_t *buf,
485485
sec->name != ".toc") {
486486
uint32_t secIdx = cast<Undefined>(sym).discardedSecIdx;
487487
Elf_Shdr_Impl<ELFT> sec = file->template getELFShdrs<ELFT>()[secIdx];
488-
warn("relocation refers to a discarded section: " +
489-
CHECK(file->getObj().getSectionName(sec), file) +
490-
"\n>>> referenced by " + getObjMsg(p->r_offset));
488+
Warn(ctx) << "relocation refers to a discarded section: "
489+
<< CHECK(file->getObj().getSectionName(sec), file)
490+
<< "\n>>> referenced by " << getObjMsg(p->r_offset);
491491
}
492492
p->setSymbolAndType(0, 0, false);
493493
continue;
@@ -661,9 +661,9 @@ static Relocation *getRISCVPCRelHi20(const InputSectionBase *loSec,
661661
"'");
662662

663663
if (addend != 0)
664-
warn(loSec->getLocation(loReloc.offset) +
665-
": non-zero addend in R_RISCV_PCREL_LO12 relocation to " +
666-
hiSec->getObjMsg(d->value) + " is ignored");
664+
Warn(ctx) << loSec->getLocation(loReloc.offset)
665+
<< ": non-zero addend in R_RISCV_PCREL_LO12 relocation to "
666+
<< hiSec->getObjMsg(d->value) << " is ignored";
667667

668668
// Relocations are sorted by offset, so we can use std::equal_range to do
669669
// binary search.
@@ -1125,7 +1125,7 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
11251125
// against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed in
11261126
// 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we need to
11271127
// keep this bug-compatible code for a while.
1128-
warn(msg);
1128+
Warn(ctx) << msg;
11291129
target.relocateNoSym(
11301130
bufLoc, type,
11311131
SignExtend64<bits>(sym.getVA(ctx, addend - offset - outSecOff)));

lld/ELF/LTO.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ static lto::Config createConfig(Ctx &ctx) {
7070
c.Options.BBSections = BasicBlockSection::All;
7171
} else if (ctx.arg.ltoBasicBlockSections == "labels") {
7272
c.Options.BBAddrMap = true;
73-
warn("'--lto-basic-block-sections=labels' is deprecated; Please use "
74-
"'--lto-basic-block-address-map' instead");
73+
Warn(ctx)
74+
<< "'--lto-basic-block-sections=labels' is deprecated; Please use "
75+
"'--lto-basic-block-address-map' instead";
7576
} else if (ctx.arg.ltoBasicBlockSections == "none") {
7677
c.Options.BBSections = BasicBlockSection::None;
7778
} else {

lld/ELF/LinkerScript.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ void LinkerScript::processSectionCommands() {
746746
OutputSection *osec = &osd->osec;
747747
if (process(osec) &&
748748
!map.try_emplace(CachedHashStringRef(osec->name), osd).second)
749-
warn("OVERWRITE_SECTIONS specifies duplicate " + osec->name);
749+
Warn(ctx) << "OVERWRITE_SECTIONS specifies duplicate " << osec->name;
750750
}
751751
for (SectionCommand *&base : sectionCommands) {
752752
if (auto *osd = dyn_cast<OutputDesc>(base)) {
@@ -1055,7 +1055,7 @@ void LinkerScript::diagnoseOrphanHandling() const {
10551055
if (ctx.arg.orphanHandling == OrphanHandlingPolicy::Error)
10561056
ErrAlways(ctx) << sec << " is being placed in '" << name << "'";
10571057
else
1058-
warn(toString(sec) + " is being placed in '" + name + "'");
1058+
Warn(ctx) << sec << " is being placed in '" << name << "'";
10591059
}
10601060
}
10611061

@@ -1084,8 +1084,9 @@ LinkerScript::findMemoryRegion(OutputSection *sec, MemoryRegion *hint) {
10841084
return ByteCommand::classof(comm);
10851085
});
10861086
if (!sec->memoryRegionName.empty() && hasInputOrByteCommand)
1087-
warn("ignoring memory region assignment for non-allocatable section '" +
1088-
sec->name + "'");
1087+
Warn(ctx)
1088+
<< "ignoring memory region assignment for non-allocatable section '"
1089+
<< sec->name << "'";
10891090
return {nullptr, nullptr};
10901091
}
10911092

0 commit comments

Comments
 (0)