Skip to content

Commit ed6c106

Browse files
committed
[ELF] Replace errorCount with errCount(ctx)
to reduce reliance on the global context.
1 parent c1ead03 commit ed6c106

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

lld/ELF/Driver.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
707707

708708
initLLVM();
709709
createFiles(args);
710-
if (errorCount())
710+
if (errCount(ctx))
711711
return;
712712

713713
inferMachineType();
714714
setConfigs(ctx, args);
715715
checkOptions(ctx);
716-
if (errorCount())
716+
if (errCount(ctx))
717717
return;
718718

719719
invokeELFT(link, args);
@@ -2082,7 +2082,7 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
20822082

20832083
if (defaultScript && !hasScript)
20842084
readLinkerScript(ctx, *defaultScript);
2085-
if (files.empty() && !hasInput && errorCount() == 0)
2085+
if (files.empty() && !hasInput && errCount(ctx) == 0)
20862086
ErrAlways(ctx) << "no input files";
20872087
}
20882088

@@ -2999,7 +2999,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
29992999
ctx.duplicates.clear();
30003000

30013001
// Return if there were name resolution errors.
3002-
if (errorCount())
3002+
if (errCount(ctx))
30033003
return;
30043004

30053005
// We want to declare linker script's symbols early,
@@ -3062,7 +3062,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
30623062
reportBackrefs(ctx);
30633063
writeArchiveStats(ctx);
30643064
writeWhyExtract(ctx);
3065-
if (errorCount())
3065+
if (errCount(ctx))
30663066
return;
30673067

30683068
// Bail out if normal linked output is skipped due to LTO.

lld/ELF/ScriptLexer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ std::string ScriptLexer::getCurrentLocation() {
8080

8181
// We don't want to record cascading errors. Keep only the first one.
8282
void ScriptLexer::setError(const Twine &msg) {
83-
if (errorCount())
83+
if (errCount(ctx))
8484
return;
8585

8686
std::string s = (getCurrentLocation() + ": " + msg).str();
@@ -196,7 +196,7 @@ StringRef ScriptLexer::skipSpace(StringRef s) {
196196
}
197197

198198
// Used to determine whether to stop parsing. Treat errors like EOF.
199-
bool ScriptLexer::atEOF() { return eof || errorCount(); }
199+
bool ScriptLexer::atEOF() { return eof || errCount(ctx); }
200200

201201
StringRef ScriptLexer::next() {
202202
prevTok = peek();
@@ -228,7 +228,7 @@ bool ScriptLexer::consume(StringRef tok) {
228228
void ScriptLexer::skip() { (void)next(); }
229229

230230
void ScriptLexer::expect(StringRef expect) {
231-
if (errorCount())
231+
if (errCount(ctx))
232232
return;
233233
StringRef tok = next();
234234
if (tok != expect) {

lld/ELF/ScriptParser.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void ScriptParser::readLinkerScript() {
287287
}
288288

289289
void ScriptParser::readDefsym() {
290-
if (errorCount())
290+
if (errCount(ctx))
291291
return;
292292
inExpr = true;
293293
StringRef name = readName();
@@ -516,7 +516,7 @@ void ScriptParser::readPhdrs() {
516516
cmd.name = tok;
517517
cmd.type = readPhdrType();
518518

519-
while (!errorCount() && !consume(";")) {
519+
while (!errCount(ctx) && !consume(";")) {
520520
if (consume("FILEHDR"))
521521
cmd.hasFilehdr = true;
522522
else if (consume("PHDRS"))
@@ -575,7 +575,7 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
575575

576576
SmallVector<SectionCommand *, 0> v;
577577
OutputSection *prev = nullptr;
578-
while (!errorCount() && !consume("}")) {
578+
while (!errCount(ctx) && !consume("}")) {
579579
// VA is the same for all sections. The LMAs are consecutive in memory
580580
// starting from the base load address specified.
581581
OutputDesc *osd = readOverlaySectionDescription();
@@ -766,7 +766,7 @@ SortSectionPolicy ScriptParser::readSortKind() {
766766
// any file but a.o, and section .baz in any file but b.o.
767767
SmallVector<SectionPattern, 0> ScriptParser::readInputSectionsList() {
768768
SmallVector<SectionPattern, 0> ret;
769-
while (!errorCount() && peek() != ")") {
769+
while (!errCount(ctx) && peek() != ")") {
770770
StringMatcher excludeFilePat;
771771
if (consume("EXCLUDE_FILE")) {
772772
expect("(");
@@ -775,7 +775,7 @@ SmallVector<SectionPattern, 0> ScriptParser::readInputSectionsList() {
775775

776776
StringMatcher SectionMatcher;
777777
// Break if the next token is ), EXCLUDE_FILE, or SORT*.
778-
while (!errorCount() && peekSortKind() == SortSectionPolicy::Default) {
778+
while (!errCount(ctx) && peekSortKind() == SortSectionPolicy::Default) {
779779
StringRef s = peek();
780780
if (s == ")" || s == "EXCLUDE_FILE")
781781
break;
@@ -1297,7 +1297,7 @@ Expr ScriptParser::combine(StringRef op, Expr l, Expr r) {
12971297
// This is a part of the operator-precedence parser. This function
12981298
// assumes that the remaining token stream starts with an operator.
12991299
Expr ScriptParser::readExpr1(Expr lhs, int minPrec) {
1300-
while (!atEOF() && !errorCount()) {
1300+
while (!atEOF() && !errCount(ctx)) {
13011301
// Read an operator and an expression.
13021302
StringRef op1 = peek();
13031303
if (precedence(op1) < minPrec)
@@ -1429,7 +1429,7 @@ std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
14291429
uint64_t withFlags = 0;
14301430
uint64_t withoutFlags = 0;
14311431
expect("(");
1432-
while (!errorCount()) {
1432+
while (!errCount(ctx)) {
14331433
StringRef tok = readName();
14341434
bool without = tok.consume_front("!");
14351435
if (std::optional<uint64_t> flag = parseFlag(tok)) {
@@ -1684,7 +1684,7 @@ Expr ScriptParser::readParenExpr() {
16841684

16851685
SmallVector<StringRef, 0> ScriptParser::readOutputSectionPhdrs() {
16861686
SmallVector<StringRef, 0> phdrs;
1687-
while (!errorCount() && peek().starts_with(":")) {
1687+
while (!errCount(ctx) && peek().starts_with(":")) {
16881688
StringRef tok = next();
16891689
phdrs.push_back((tok.size() == 1) ? readName() : tok.substr(1));
16901690
}

lld/ELF/Writer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,14 @@ template <class ELFT> void Writer<ELFT>::run() {
348348
checkSections();
349349

350350
// It does not make sense try to open the file if we have error already.
351-
if (errorCount())
351+
if (errCount(ctx))
352352
return;
353353

354354
{
355355
llvm::TimeTraceScope timeScope("Write output file");
356356
// Write the result down to a file.
357357
openFile();
358-
if (errorCount())
358+
if (errCount(ctx))
359359
return;
360360

361361
if (!ctx.arg.oFormatBinary) {
@@ -370,7 +370,7 @@ template <class ELFT> void Writer<ELFT>::run() {
370370
// Backfill .note.gnu.build-id section content. This is done at last
371371
// because the content is usually a hash value of the entire output file.
372372
writeBuildId();
373-
if (errorCount())
373+
if (errCount(ctx))
374374
return;
375375

376376
if (auto e = buffer->commit())
@@ -1421,7 +1421,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
14211421
scriptSections.push_back(&isec);
14221422
sections.push_back(isec);
14231423
}
1424-
if (hasLinkOrder && errorCount() == 0) {
1424+
if (hasLinkOrder && errCount(ctx) == 0) {
14251425
llvm::stable_sort(sections, compareByFilePosition);
14261426
for (int i = 0, n = sections.size(); i != n; ++i)
14271427
*scriptSections[i] = sections[i];
@@ -2061,7 +2061,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
20612061
finalizeAddressDependentContent();
20622062

20632063
// All information needed for OutputSection part of Map file is available.
2064-
if (errorCount())
2064+
if (errCount(ctx))
20652065
return;
20662066

20672067
{

0 commit comments

Comments
 (0)