[lld] ed6c106 - [ELF] Replace errorCount with errCount(ctx)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 09:06:07 PST 2024
Author: Fangrui Song
Date: 2024-11-07T09:06:01-08:00
New Revision: ed6c106e6a9e4855f9bf328674be3d3c6ceb9586
URL: https://github.com/llvm/llvm-project/commit/ed6c106e6a9e4855f9bf328674be3d3c6ceb9586
DIFF: https://github.com/llvm/llvm-project/commit/ed6c106e6a9e4855f9bf328674be3d3c6ceb9586.diff
LOG: [ELF] Replace errorCount with errCount(ctx)
to reduce reliance on the global context.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/ScriptLexer.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/Writer.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 711000dcd4be12..f5125f9ba4b3a3 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -707,13 +707,13 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
initLLVM();
createFiles(args);
- if (errorCount())
+ if (errCount(ctx))
return;
inferMachineType();
setConfigs(ctx, args);
checkOptions(ctx);
- if (errorCount())
+ if (errCount(ctx))
return;
invokeELFT(link, args);
@@ -2082,7 +2082,7 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
if (defaultScript && !hasScript)
readLinkerScript(ctx, *defaultScript);
- if (files.empty() && !hasInput && errorCount() == 0)
+ if (files.empty() && !hasInput && errCount(ctx) == 0)
ErrAlways(ctx) << "no input files";
}
@@ -2999,7 +2999,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
ctx.duplicates.clear();
// Return if there were name resolution errors.
- if (errorCount())
+ if (errCount(ctx))
return;
// We want to declare linker script's symbols early,
@@ -3062,7 +3062,7 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
reportBackrefs(ctx);
writeArchiveStats(ctx);
writeWhyExtract(ctx);
- if (errorCount())
+ if (errCount(ctx))
return;
// Bail out if normal linked output is skipped due to LTO.
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp
index a89db24e27d039..ae5ad7cae949d9 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -80,7 +80,7 @@ std::string ScriptLexer::getCurrentLocation() {
// We don't want to record cascading errors. Keep only the first one.
void ScriptLexer::setError(const Twine &msg) {
- if (errorCount())
+ if (errCount(ctx))
return;
std::string s = (getCurrentLocation() + ": " + msg).str();
@@ -196,7 +196,7 @@ StringRef ScriptLexer::skipSpace(StringRef s) {
}
// Used to determine whether to stop parsing. Treat errors like EOF.
-bool ScriptLexer::atEOF() { return eof || errorCount(); }
+bool ScriptLexer::atEOF() { return eof || errCount(ctx); }
StringRef ScriptLexer::next() {
prevTok = peek();
@@ -228,7 +228,7 @@ bool ScriptLexer::consume(StringRef tok) {
void ScriptLexer::skip() { (void)next(); }
void ScriptLexer::expect(StringRef expect) {
- if (errorCount())
+ if (errCount(ctx))
return;
StringRef tok = next();
if (tok != expect) {
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 85b45f6198ea59..d8adc56cf7d9a0 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -287,7 +287,7 @@ void ScriptParser::readLinkerScript() {
}
void ScriptParser::readDefsym() {
- if (errorCount())
+ if (errCount(ctx))
return;
inExpr = true;
StringRef name = readName();
@@ -516,7 +516,7 @@ void ScriptParser::readPhdrs() {
cmd.name = tok;
cmd.type = readPhdrType();
- while (!errorCount() && !consume(";")) {
+ while (!errCount(ctx) && !consume(";")) {
if (consume("FILEHDR"))
cmd.hasFilehdr = true;
else if (consume("PHDRS"))
@@ -575,7 +575,7 @@ SmallVector<SectionCommand *, 0> ScriptParser::readOverlay() {
SmallVector<SectionCommand *, 0> v;
OutputSection *prev = nullptr;
- while (!errorCount() && !consume("}")) {
+ while (!errCount(ctx) && !consume("}")) {
// VA is the same for all sections. The LMAs are consecutive in memory
// starting from the base load address specified.
OutputDesc *osd = readOverlaySectionDescription();
@@ -766,7 +766,7 @@ SortSectionPolicy ScriptParser::readSortKind() {
// any file but a.o, and section .baz in any file but b.o.
SmallVector<SectionPattern, 0> ScriptParser::readInputSectionsList() {
SmallVector<SectionPattern, 0> ret;
- while (!errorCount() && peek() != ")") {
+ while (!errCount(ctx) && peek() != ")") {
StringMatcher excludeFilePat;
if (consume("EXCLUDE_FILE")) {
expect("(");
@@ -775,7 +775,7 @@ SmallVector<SectionPattern, 0> ScriptParser::readInputSectionsList() {
StringMatcher SectionMatcher;
// Break if the next token is ), EXCLUDE_FILE, or SORT*.
- while (!errorCount() && peekSortKind() == SortSectionPolicy::Default) {
+ while (!errCount(ctx) && peekSortKind() == SortSectionPolicy::Default) {
StringRef s = peek();
if (s == ")" || s == "EXCLUDE_FILE")
break;
@@ -1297,7 +1297,7 @@ Expr ScriptParser::combine(StringRef op, Expr l, Expr r) {
// This is a part of the operator-precedence parser. This function
// assumes that the remaining token stream starts with an operator.
Expr ScriptParser::readExpr1(Expr lhs, int minPrec) {
- while (!atEOF() && !errorCount()) {
+ while (!atEOF() && !errCount(ctx)) {
// Read an operator and an expression.
StringRef op1 = peek();
if (precedence(op1) < minPrec)
@@ -1429,7 +1429,7 @@ std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
uint64_t withFlags = 0;
uint64_t withoutFlags = 0;
expect("(");
- while (!errorCount()) {
+ while (!errCount(ctx)) {
StringRef tok = readName();
bool without = tok.consume_front("!");
if (std::optional<uint64_t> flag = parseFlag(tok)) {
@@ -1684,7 +1684,7 @@ Expr ScriptParser::readParenExpr() {
SmallVector<StringRef, 0> ScriptParser::readOutputSectionPhdrs() {
SmallVector<StringRef, 0> phdrs;
- while (!errorCount() && peek().starts_with(":")) {
+ while (!errCount(ctx) && peek().starts_with(":")) {
StringRef tok = next();
phdrs.push_back((tok.size() == 1) ? readName() : tok.substr(1));
}
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0a53137c3ea4c8..4a200841c1aacc 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -348,14 +348,14 @@ template <class ELFT> void Writer<ELFT>::run() {
checkSections();
// It does not make sense try to open the file if we have error already.
- if (errorCount())
+ if (errCount(ctx))
return;
{
llvm::TimeTraceScope timeScope("Write output file");
// Write the result down to a file.
openFile();
- if (errorCount())
+ if (errCount(ctx))
return;
if (!ctx.arg.oFormatBinary) {
@@ -370,7 +370,7 @@ template <class ELFT> void Writer<ELFT>::run() {
// Backfill .note.gnu.build-id section content. This is done at last
// because the content is usually a hash value of the entire output file.
writeBuildId();
- if (errorCount())
+ if (errCount(ctx))
return;
if (auto e = buffer->commit())
@@ -1421,7 +1421,7 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
scriptSections.push_back(&isec);
sections.push_back(isec);
}
- if (hasLinkOrder && errorCount() == 0) {
+ if (hasLinkOrder && errCount(ctx) == 0) {
llvm::stable_sort(sections, compareByFilePosition);
for (int i = 0, n = sections.size(); i != n; ++i)
*scriptSections[i] = sections[i];
@@ -2061,7 +2061,7 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
finalizeAddressDependentContent();
// All information needed for OutputSection part of Map file is available.
- if (errorCount())
+ if (errCount(ctx))
return;
{
More information about the llvm-commits
mailing list