Skip to content

Commit 2cea79d

Browse files
authored
Merge branch 'main' into vb-sc/clang-dependent-lookup-fix
2 parents 11c24e5 + 9664ce6 commit 2cea79d

File tree

10 files changed

+60
-65
lines changed

10 files changed

+60
-65
lines changed

lld/COFF/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
15821582
StringRef s = arg->getValue();
15831583
if (s.getAsInteger(10, n))
15841584
error(arg->getSpelling() + " number expected, but got " + s);
1585-
errorHandler().errorLimit = n;
1585+
ctx.e.errorLimit = n;
15861586
}
15871587

15881588
config->vfs = getVFS(args);
@@ -1696,7 +1696,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
16961696
// Handle /verbose
16971697
if (args.hasArg(OPT_verbose))
16981698
config->verbose = true;
1699-
errorHandler().verbose = config->verbose;
1699+
ctx.e.verbose = config->verbose;
17001700

17011701
// Handle /force or /force:unresolved
17021702
if (args.hasArg(OPT_force, OPT_force_unresolved))

lld/COFF/DriverUtils.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,21 +858,22 @@ COFFOptTable::COFFOptTable() : GenericOptTable(infoTable, true) {}
858858

859859
// Set color diagnostics according to --color-diagnostics={auto,always,never}
860860
// or --no-color-diagnostics flags.
861-
static void handleColorDiagnostics(opt::InputArgList &args) {
861+
static void handleColorDiagnostics(COFFLinkerContext &ctx,
862+
opt::InputArgList &args) {
862863
auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
863864
OPT_no_color_diagnostics);
864865
if (!arg)
865866
return;
866867
if (arg->getOption().getID() == OPT_color_diagnostics) {
867-
lld::errs().enable_colors(true);
868+
ctx.e.errs().enable_colors(true);
868869
} else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
869-
lld::errs().enable_colors(false);
870+
ctx.e.errs().enable_colors(false);
870871
} else {
871872
StringRef s = arg->getValue();
872873
if (s == "always")
873-
lld::errs().enable_colors(true);
874+
ctx.e.errs().enable_colors(true);
874875
else if (s == "never")
875-
lld::errs().enable_colors(false);
876+
ctx.e.errs().enable_colors(false);
876877
else if (s != "auto")
877878
error("unknown option: --color-diagnostics=" + s);
878879
}
@@ -934,12 +935,12 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
934935
}
935936

936937
// Handle /WX early since it converts missing argument warnings to errors.
937-
errorHandler().fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);
938+
ctx.e.fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);
938939

939940
if (missingCount)
940941
fatal(Twine(args.getArgString(missingIndex)) + ": missing argument");
941942

942-
handleColorDiagnostics(args);
943+
handleColorDiagnostics(ctx, args);
943944

944945
for (opt::Arg *arg : args.filtered(OPT_UNKNOWN)) {
945946
std::string nearest;

lld/COFF/Writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ struct ChunkRange {
205205
class Writer {
206206
public:
207207
Writer(COFFLinkerContext &c)
208-
: buffer(errorHandler().outputBuffer), delayIdata(c), edata(c), ctx(c) {}
208+
: buffer(c.e.outputBuffer), delayIdata(c), edata(c), ctx(c) {}
209209
void run();
210210

211211
private:
@@ -2461,7 +2461,7 @@ void Writer::sortExceptionTables() {
24612461
break;
24622462
default:
24632463
if (pdata.first)
2464-
lld::errs() << "warning: don't know how to handle .pdata.\n";
2464+
ctx.e.errs() << "warning: don't know how to handle .pdata\n";
24652465
break;
24662466
}
24672467
}

lld/Common/ErrorHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ void ErrorHandler::reportDiagnostic(StringRef location, Colors c,
215215
raw_svector_ostream os(buf);
216216
os << sep << location << ": ";
217217
if (!diagKind.empty()) {
218-
if (lld::errs().colors_enabled()) {
218+
if (errs().colors_enabled()) {
219219
os.enable_colors(true);
220220
os << c << diagKind << ": " << Colors::RESET;
221221
} else {
222222
os << diagKind << ": ";
223223
}
224224
}
225225
os << msg << '\n';
226-
lld::errs() << buf;
226+
errs() << buf;
227227
}
228228

229229
void ErrorHandler::log(const Twine &msg) {

lld/ELF/DriverUtils.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ static void handleColorDiagnostics(Ctx &ctx, opt::InputArgList &args) {
5858
return;
5959
StringRef s = arg->getValue();
6060
if (s == "always")
61-
lld::errs().enable_colors(true);
61+
ctx.errHandler->errs().enable_colors(true);
6262
else if (s == "never")
63-
lld::errs().enable_colors(false);
63+
ctx.errHandler->errs().enable_colors(false);
6464
else if (s != "auto")
6565
ErrAlways(ctx) << "unknown option: --color-diagnostics=" << s;
6666
}
@@ -139,16 +139,17 @@ opt::InputArgList ELFOptTable::parse(Ctx &ctx, ArrayRef<const char *> argv) {
139139
}
140140

141141
void elf::printHelp(Ctx &ctx) {
142+
auto &outs = ctx.errHandler->outs();
142143
ELFOptTable().printHelp(
143-
lld::outs(), (ctx.arg.progName + " [options] file...").str().c_str(),
144-
"lld", false /*ShowHidden*/, true /*ShowAllAliases*/);
145-
lld::outs() << "\n";
144+
outs, (ctx.arg.progName + " [options] file...").str().c_str(), "lld",
145+
false /*ShowHidden*/, true /*ShowAllAliases*/);
146+
outs << "\n";
146147

147148
// Scripts generated by Libtool versions up to 2021-10 expect /: supported
148149
// targets:.* elf/ in a message for the --help option. If it doesn't match,
149150
// the scripts assume that the linker doesn't support very basic features
150151
// such as shared libraries. Therefore, we need to print out at least "elf".
151-
lld::outs() << ctx.arg.progName << ": supported targets: elf\n";
152+
outs << ctx.arg.progName << ": supported targets: elf\n";
152153
}
153154

154155
static std::string rewritePath(StringRef s) {

lld/ELF/Relocations.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,44 +100,41 @@ static std::string getLocation(Ctx &ctx, InputSectionBase &s, const Symbol &sym,
100100
void elf::reportRangeError(Ctx &ctx, uint8_t *loc, const Relocation &rel,
101101
const Twine &v, int64_t min, uint64_t max) {
102102
ErrorPlace errPlace = getErrorPlace(ctx, loc);
103-
std::string hint;
103+
auto diag = Err(ctx);
104+
diag << errPlace.loc << "relocation " << rel.type
105+
<< " out of range: " << v.str() << " is not in [" << min << ", " << max
106+
<< ']';
107+
104108
if (rel.sym) {
105109
if (!rel.sym->isSection())
106-
hint = "; references '" + toStr(ctx, *rel.sym) + '\'';
110+
diag << "; references '" << rel.sym << '\'';
107111
else if (auto *d = dyn_cast<Defined>(rel.sym))
108-
hint = ("; references section '" + d->section->name + "'").str();
112+
diag << "; references section '" << d->section->name << "'";
109113

110114
if (ctx.arg.emachine == EM_X86_64 && rel.type == R_X86_64_PC32 &&
111115
rel.sym->getOutputSection() &&
112116
(rel.sym->getOutputSection()->flags & SHF_X86_64_LARGE)) {
113-
hint += "; R_X86_64_PC32 should not reference a section marked "
117+
diag << "; R_X86_64_PC32 should not reference a section marked "
114118
"SHF_X86_64_LARGE";
115119
}
116120
}
117121
if (!errPlace.srcLoc.empty())
118-
hint += "\n>>> referenced by " + errPlace.srcLoc;
122+
diag << "\n>>> referenced by " << errPlace.srcLoc;
119123
if (rel.sym && !rel.sym->isSection())
120-
hint += getDefinedLocation(ctx, *rel.sym);
124+
diag << getDefinedLocation(ctx, *rel.sym);
121125

122126
if (errPlace.isec && errPlace.isec->name.starts_with(".debug"))
123-
hint += "; consider recompiling with -fdebug-types-section to reduce size "
127+
diag << "; consider recompiling with -fdebug-types-section to reduce size "
124128
"of debug sections";
125-
126-
Err(ctx) << errPlace.loc << "relocation " << rel.type
127-
<< " out of range: " << v.str() << " is not in [" << Twine(min).str()
128-
<< ", " << Twine(max).str() << "]" << hint;
129129
}
130130

131131
void elf::reportRangeError(Ctx &ctx, uint8_t *loc, int64_t v, int n,
132132
const Symbol &sym, const Twine &msg) {
133-
ErrorPlace errPlace = getErrorPlace(ctx, loc);
134-
std::string hint;
133+
auto diag = Err(ctx);
134+
diag << getErrorPlace(ctx, loc).loc << msg << " is out of range: " << v
135+
<< " is not in [" << llvm::minIntN(n) << ", " << llvm::maxIntN(n) << "]";
135136
if (!sym.getName().empty())
136-
hint = "; references '" + toStr(ctx, sym) + '\'' +
137-
getDefinedLocation(ctx, sym);
138-
Err(ctx) << errPlace.loc << msg << " is out of range: " << Twine(v)
139-
<< " is not in [" << Twine(llvm::minIntN(n)) << ", "
140-
<< Twine(llvm::maxIntN(n)) << "]" << hint;
137+
diag << "; references '" << &sym << '\'' << getDefinedLocation(ctx, sym);
141138
}
142139

143140
// Build a bitmask with one bit set for each 64 subset of RelExpr.

lld/ELF/Symbols.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,15 +548,14 @@ void elf::reportDuplicate(Ctx &ctx, const Symbol &sym, const InputFile *newFile,
548548
std::string src2 = errSec->getSrcMsg(sym, errOffset);
549549
std::string obj2 = errSec->getObjMsg(errOffset);
550550

551-
std::string msg =
552-
"duplicate symbol: " + toStr(ctx, sym) + "\n>>> defined at ";
551+
auto diag = Err(ctx);
552+
diag << "duplicate symbol: " << &sym << "\n>>> defined at ";
553553
if (!src1.empty())
554-
msg += src1 + "\n>>> ";
555-
msg += obj1 + "\n>>> defined at ";
554+
diag << src1 << "\n>>> ";
555+
diag << obj1 << "\n>>> defined at ";
556556
if (!src2.empty())
557-
msg += src2 + "\n>>> ";
558-
msg += obj2;
559-
Err(ctx) << msg;
557+
diag << src2 << "\n>>> ";
558+
diag << obj2;
560559
}
561560

562561
void Symbol::checkDuplicate(Ctx &ctx, const Defined &other) const {

lld/ELF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ template <class ELFT> void Writer<ELFT>::run() {
342342

343343
// Handle --print-memory-usage option.
344344
if (ctx.arg.printMemoryUsage)
345-
ctx.script->printMemoryUsage(lld::outs());
345+
ctx.script->printMemoryUsage(ctx.errHandler->outs());
346346

347347
if (ctx.arg.checkSections)
348348
checkSections();

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ Error assembleToStream(const ExegesisTarget &ET,
272272
}
273273

274274
std::vector<unsigned> RegistersSetUp;
275+
RegistersSetUp.reserve(Key.RegisterInitialValues.size());
275276
for (const auto &InitValue : Key.RegisterInitialValues) {
276277
RegistersSetUp.push_back(InitValue.Register);
277278
}

llvm/unittests/ProfileData/InstrProfTest.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -677,29 +677,29 @@ TEST_F(InstrProfTest, test_memprof_merge) {
677677
Writer.addRecord({"func1", 0x1234, {42}}, Err);
678678

679679
InstrProfWriter Writer2;
680+
Writer2.setMemProfVersionRequested(memprof::Version3);
680681
ASSERT_THAT_ERROR(Writer2.mergeProfileKind(InstrProfKind::MemProf),
681682
Succeeded());
682683

683-
const IndexedMemProfRecord IndexedMR = makeRecord(
684-
/*AllocFrames=*/
685-
{
686-
{0, 1},
687-
{2, 3},
688-
},
689-
/*CallSiteFrames=*/{
690-
{4, 5},
691-
});
692-
693684
const FrameIdMapTy IdToFrameMap = getFrameMapping();
694685
for (const auto &I : IdToFrameMap) {
695-
Writer.addMemProfFrame(I.first, I.getSecond(), Err);
686+
Writer2.addMemProfFrame(I.first, I.getSecond(), Err);
696687
}
688+
689+
const auto CSIdToCallStackMap = getCallStackMapping();
690+
for (const auto &[CSId, CallStack] : CSIdToCallStackMap)
691+
Writer2.addMemProfCallStack(CSId, CallStack, Err);
692+
693+
const IndexedMemProfRecord IndexedMR = makeRecordV2(
694+
/*AllocFrames=*/{0x111, 0x222},
695+
/*CallSiteFrames=*/{}, makePartialMIB(), memprof::getHotColdSchema());
697696
Writer2.addMemProfRecord(/*Id=*/0x9999, IndexedMR);
698697

699698
ASSERT_THAT_ERROR(Writer.mergeProfileKind(Writer2.getProfileKind()),
700699
Succeeded());
701700
Writer.mergeRecordsFromWriter(std::move(Writer2), Err);
702701

702+
Writer.setMemProfVersionRequested(memprof::Version3);
703703
auto Profile = Writer.writeBuffer();
704704
readProfile(std::move(Profile));
705705

@@ -714,16 +714,12 @@ TEST_F(InstrProfTest, test_memprof_merge) {
714714

715715
std::optional<memprof::FrameId> LastUnmappedFrameId;
716716

717-
auto IdToFrameCallback = [&](const memprof::FrameId Id) {
718-
auto Iter = IdToFrameMap.find(Id);
719-
if (Iter == IdToFrameMap.end()) {
720-
LastUnmappedFrameId = Id;
721-
return memprof::Frame(0, 0, 0, false);
722-
}
723-
return Iter->second;
724-
};
717+
memprof::FrameIdConverter<decltype(IdToFrameMap)> FrameIdConv(IdToFrameMap);
718+
memprof::CallStackIdConverter<decltype(CSIdToCallStackMap)> CSIdConv(
719+
CSIdToCallStackMap, FrameIdConv);
725720

726-
const memprof::MemProfRecord WantRecord(IndexedMR, IdToFrameCallback);
721+
const ::llvm::memprof::MemProfRecord WantRecord =
722+
IndexedMR.toMemProfRecord(CSIdConv);
727723
ASSERT_EQ(LastUnmappedFrameId, std::nullopt)
728724
<< "could not map frame id: " << *LastUnmappedFrameId;
729725
EXPECT_THAT(WantRecord, EqualsRecord(Record));

0 commit comments

Comments
 (0)