[lld] 983f88c - [lld-link] Use COFFSyncStream
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 5 20:41:42 PST 2024
Author: Fangrui Song
Date: 2024-12-05T20:41:37-08:00
New Revision: 983f88c1ec9cee51cf0fb4e6a0f00074a7cf1b60
URL: https://github.com/llvm/llvm-project/commit/983f88c1ec9cee51cf0fb4e6a0f00074a7cf1b60
DIFF: https://github.com/llvm/llvm-project/commit/983f88c1ec9cee51cf0fb4e6a0f00074a7cf1b60.diff
LOG: [lld-link] Use COFFSyncStream
Add a operator<< overload for Symbol *.
Added:
Modified:
lld/COFF/Driver.cpp
lld/COFF/DriverUtils.cpp
lld/COFF/MinGW.cpp
lld/COFF/MinGW.h
lld/COFF/PDB.cpp
lld/COFF/SymbolTable.cpp
lld/COFF/Symbols.cpp
lld/COFF/Symbols.h
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index c1bf89ec0a5366..714de67e88b065 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -2745,7 +2745,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// Handle /output-def (MinGW specific).
if (auto *arg = args.getLastArg(OPT_output_def))
- writeDefFile(arg->getValue(), config->exports);
+ writeDefFile(ctx, arg->getValue(), config->exports);
// Set extra alignment for .comm symbols
for (auto pair : config->alignComm) {
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 44c8349079cc5e..c1b3272a1f49ea 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -885,11 +885,12 @@ static void handleColorDiagnostics(COFFLinkerContext &ctx,
}
}
-static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
+static cl::TokenizerCallback getQuotingStyle(COFFLinkerContext &ctx,
+ opt::InputArgList &args) {
if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {
StringRef s = arg->getValue();
if (s != "windows" && s != "posix")
- error("invalid response file quoting: " + s);
+ Err(ctx) << "invalid response file quoting: " << s;
if (s == "windows")
return cl::TokenizeWindowsCommandLine;
return cl::TokenizeGNUCommandLine;
@@ -919,7 +920,7 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
argv.data() + argv.size());
if (!args.hasArg(OPT_lldignoreenv))
addLINK(expandedArgv);
- cl::ExpandResponseFiles(saver(), getQuotingStyle(args), expandedArgv);
+ cl::ExpandResponseFiles(saver(), getQuotingStyle(ctx, args), expandedArgv);
args = ctx.optTable.ParseArgs(ArrayRef(expandedArgv).drop_front(),
missingIndex, missingCount);
diff --git a/lld/COFF/MinGW.cpp b/lld/COFF/MinGW.cpp
index 29c01da9e28f6d..76f5a0a7500b9d 100644
--- a/lld/COFF/MinGW.cpp
+++ b/lld/COFF/MinGW.cpp
@@ -170,13 +170,13 @@ bool AutoExporter::shouldExport(Defined *sym) const {
return !excludeObjects.count(fileName);
}
-void lld::coff::writeDefFile(StringRef name,
+void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,
const std::vector<Export> &exports) {
llvm::TimeTraceScope timeScope("Write .def file");
std::error_code ec;
raw_fd_ostream os(name, ec, sys::fs::OF_None);
if (ec)
- fatal("cannot open " + name + ": " + ec.message());
+ Fatal(ctx) << "cannot open " << name << ": " << ec.message();
os << "EXPORTS\n";
for (const Export &e : exports) {
diff --git a/lld/COFF/MinGW.h b/lld/COFF/MinGW.h
index aa5e53278ca4bf..ffa500b234777b 100644
--- a/lld/COFF/MinGW.h
+++ b/lld/COFF/MinGW.h
@@ -45,7 +45,8 @@ class AutoExporter {
COFFLinkerContext &ctx;
};
-void writeDefFile(StringRef name, const std::vector<Export> &exports);
+void writeDefFile(COFFLinkerContext &, StringRef name,
+ const std::vector<Export> &exports);
// The -wrap option is a feature to rename symbols so that you can write
// wrappers for existing functions. If you pass `-wrap:foo`, all
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp
index cc4221768fbb07..4382dd677ff59a 100644
--- a/lld/COFF/PDB.cpp
+++ b/lld/COFF/PDB.cpp
@@ -1725,14 +1725,13 @@ void PDBLinker::commit(codeview::GUID *guid) {
// the user can see the output of /time and /summary, which is very helpful
// when trying to figure out why a PDB file is too large.
if (Error e = builder.commit(ctx.config.pdbPath, guid)) {
- e = handleErrors(std::move(e),
- [](const llvm::msf::MSFError &me) {
- error(me.message());
- if (me.isPageOverflow())
- error("try setting a larger /pdbpagesize");
- });
+ e = handleErrors(std::move(e), [&](const llvm::msf::MSFError &me) {
+ Err(ctx) << me.message();
+ if (me.isPageOverflow())
+ Err(ctx) << "try setting a larger /pdbpagesize";
+ });
checkError(std::move(e));
- error("failed to write PDB file " + Twine(ctx.config.pdbPath));
+ Err(ctx) << "failed to write PDB file " << Twine(ctx.config.pdbPath);
}
}
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 89a8d694d03152..524e674615d89e 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -102,11 +102,8 @@ void SymbolTable::addFile(InputFile *file) {
ctx.driver.parseDirectives(file);
}
-static void errorOrWarn(const Twine &s, bool forceUnresolved) {
- if (forceUnresolved)
- warn(s);
- else
- error(s);
+static COFFSyncStream errorOrWarn(COFFLinkerContext &ctx) {
+ return {ctx, ctx.config.forceUnresolved ? DiagLevel::Warn : DiagLevel::Err};
}
// Causes the file associated with a lazy symbol to be linked in.
@@ -273,7 +270,7 @@ struct UndefinedDiag {
std::vector<File> files;
};
-static void reportUndefinedSymbol(const COFFLinkerContext &ctx,
+static void reportUndefinedSymbol(COFFLinkerContext &ctx,
const UndefinedDiag &undefDiag) {
std::string out;
llvm::raw_string_ostream os(out);
@@ -293,7 +290,7 @@ static void reportUndefinedSymbol(const COFFLinkerContext &ctx,
}
if (numDisplayedRefs < numRefs)
os << "\n>>> referenced " << numRefs - numDisplayedRefs << " more times";
- errorOrWarn(out, ctx.config.forceUnresolved);
+ errorOrWarn(ctx) << out;
}
void SymbolTable::loadMinGWSymbols() {
@@ -425,8 +422,7 @@ static void reportProblemSymbols(
for (Symbol *b : ctx.config.gcroot) {
if (undefs.count(b))
- errorOrWarn("<root>: undefined symbol: " + toString(ctx, *b),
- ctx.config.forceUnresolved);
+ errorOrWarn(ctx) << "<root>: undefined symbol: " << toString(ctx, *b);
if (localImports)
if (Symbol *imp = localImports->lookup(b))
Warn(ctx) << "<root>: locally defined symbol imported: "
diff --git a/lld/COFF/Symbols.cpp b/lld/COFF/Symbols.cpp
index 383f62afd8e1d3..7de2c3829d1b0d 100644
--- a/lld/COFF/Symbols.cpp
+++ b/lld/COFF/Symbols.cpp
@@ -60,6 +60,10 @@ coff::operator<<(const COFFSyncStream &s,
return s;
}
+const COFFSyncStream &coff::operator<<(const COFFSyncStream &s, Symbol *sym) {
+ return s << maybeDemangleSymbol(s.ctx, sym->getName());
+}
+
namespace coff {
void Symbol::computeName() {
diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index 6fabed9fc8f2b3..3b367a38c889f4 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -33,10 +33,12 @@ class ArchiveFile;
class COFFLinkerContext;
class InputFile;
class ObjFile;
+class Symbol;
class SymbolTable;
const COFFSyncStream &operator<<(const COFFSyncStream &,
const llvm::object::Archive::Symbol *);
+const COFFSyncStream &operator<<(const COFFSyncStream &, Symbol *);
// The base class for real symbol classes.
class Symbol {
More information about the llvm-commits
mailing list