Skip to content

Commit 983f88c

Browse files
committed
[lld-link] Use COFFSyncStream
Add a operator<< overload for Symbol *.
1 parent fb2cbc0 commit 983f88c

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27452745

27462746
// Handle /output-def (MinGW specific).
27472747
if (auto *arg = args.getLastArg(OPT_output_def))
2748-
writeDefFile(arg->getValue(), config->exports);
2748+
writeDefFile(ctx, arg->getValue(), config->exports);
27492749

27502750
// Set extra alignment for .comm symbols
27512751
for (auto pair : config->alignComm) {

lld/COFF/DriverUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,12 @@ static void handleColorDiagnostics(COFFLinkerContext &ctx,
885885
}
886886
}
887887

888-
static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
888+
static cl::TokenizerCallback getQuotingStyle(COFFLinkerContext &ctx,
889+
opt::InputArgList &args) {
889890
if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {
890891
StringRef s = arg->getValue();
891892
if (s != "windows" && s != "posix")
892-
error("invalid response file quoting: " + s);
893+
Err(ctx) << "invalid response file quoting: " << s;
893894
if (s == "windows")
894895
return cl::TokenizeWindowsCommandLine;
895896
return cl::TokenizeGNUCommandLine;
@@ -919,7 +920,7 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
919920
argv.data() + argv.size());
920921
if (!args.hasArg(OPT_lldignoreenv))
921922
addLINK(expandedArgv);
922-
cl::ExpandResponseFiles(saver(), getQuotingStyle(args), expandedArgv);
923+
cl::ExpandResponseFiles(saver(), getQuotingStyle(ctx, args), expandedArgv);
923924
args = ctx.optTable.ParseArgs(ArrayRef(expandedArgv).drop_front(),
924925
missingIndex, missingCount);
925926

lld/COFF/MinGW.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ bool AutoExporter::shouldExport(Defined *sym) const {
170170
return !excludeObjects.count(fileName);
171171
}
172172

173-
void lld::coff::writeDefFile(StringRef name,
173+
void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,
174174
const std::vector<Export> &exports) {
175175
llvm::TimeTraceScope timeScope("Write .def file");
176176
std::error_code ec;
177177
raw_fd_ostream os(name, ec, sys::fs::OF_None);
178178
if (ec)
179-
fatal("cannot open " + name + ": " + ec.message());
179+
Fatal(ctx) << "cannot open " << name << ": " << ec.message();
180180

181181
os << "EXPORTS\n";
182182
for (const Export &e : exports) {

lld/COFF/MinGW.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class AutoExporter {
4545
COFFLinkerContext &ctx;
4646
};
4747

48-
void writeDefFile(StringRef name, const std::vector<Export> &exports);
48+
void writeDefFile(COFFLinkerContext &, StringRef name,
49+
const std::vector<Export> &exports);
4950

5051
// The -wrap option is a feature to rename symbols so that you can write
5152
// wrappers for existing functions. If you pass `-wrap:foo`, all

lld/COFF/PDB.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,14 +1725,13 @@ void PDBLinker::commit(codeview::GUID *guid) {
17251725
// the user can see the output of /time and /summary, which is very helpful
17261726
// when trying to figure out why a PDB file is too large.
17271727
if (Error e = builder.commit(ctx.config.pdbPath, guid)) {
1728-
e = handleErrors(std::move(e),
1729-
[](const llvm::msf::MSFError &me) {
1730-
error(me.message());
1731-
if (me.isPageOverflow())
1732-
error("try setting a larger /pdbpagesize");
1733-
});
1728+
e = handleErrors(std::move(e), [&](const llvm::msf::MSFError &me) {
1729+
Err(ctx) << me.message();
1730+
if (me.isPageOverflow())
1731+
Err(ctx) << "try setting a larger /pdbpagesize";
1732+
});
17341733
checkError(std::move(e));
1735-
error("failed to write PDB file " + Twine(ctx.config.pdbPath));
1734+
Err(ctx) << "failed to write PDB file " << Twine(ctx.config.pdbPath);
17361735
}
17371736
}
17381737

lld/COFF/SymbolTable.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ void SymbolTable::addFile(InputFile *file) {
102102
ctx.driver.parseDirectives(file);
103103
}
104104

105-
static void errorOrWarn(const Twine &s, bool forceUnresolved) {
106-
if (forceUnresolved)
107-
warn(s);
108-
else
109-
error(s);
105+
static COFFSyncStream errorOrWarn(COFFLinkerContext &ctx) {
106+
return {ctx, ctx.config.forceUnresolved ? DiagLevel::Warn : DiagLevel::Err};
110107
}
111108

112109
// Causes the file associated with a lazy symbol to be linked in.
@@ -273,7 +270,7 @@ struct UndefinedDiag {
273270
std::vector<File> files;
274271
};
275272

276-
static void reportUndefinedSymbol(const COFFLinkerContext &ctx,
273+
static void reportUndefinedSymbol(COFFLinkerContext &ctx,
277274
const UndefinedDiag &undefDiag) {
278275
std::string out;
279276
llvm::raw_string_ostream os(out);
@@ -293,7 +290,7 @@ static void reportUndefinedSymbol(const COFFLinkerContext &ctx,
293290
}
294291
if (numDisplayedRefs < numRefs)
295292
os << "\n>>> referenced " << numRefs - numDisplayedRefs << " more times";
296-
errorOrWarn(out, ctx.config.forceUnresolved);
293+
errorOrWarn(ctx) << out;
297294
}
298295

299296
void SymbolTable::loadMinGWSymbols() {
@@ -425,8 +422,7 @@ static void reportProblemSymbols(
425422

426423
for (Symbol *b : ctx.config.gcroot) {
427424
if (undefs.count(b))
428-
errorOrWarn("<root>: undefined symbol: " + toString(ctx, *b),
429-
ctx.config.forceUnresolved);
425+
errorOrWarn(ctx) << "<root>: undefined symbol: " << toString(ctx, *b);
430426
if (localImports)
431427
if (Symbol *imp = localImports->lookup(b))
432428
Warn(ctx) << "<root>: locally defined symbol imported: "

lld/COFF/Symbols.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ coff::operator<<(const COFFSyncStream &s,
6060
return s;
6161
}
6262

63+
const COFFSyncStream &coff::operator<<(const COFFSyncStream &s, Symbol *sym) {
64+
return s << maybeDemangleSymbol(s.ctx, sym->getName());
65+
}
66+
6367
namespace coff {
6468

6569
void Symbol::computeName() {

lld/COFF/Symbols.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ class ArchiveFile;
3333
class COFFLinkerContext;
3434
class InputFile;
3535
class ObjFile;
36+
class Symbol;
3637
class SymbolTable;
3738

3839
const COFFSyncStream &operator<<(const COFFSyncStream &,
3940
const llvm::object::Archive::Symbol *);
41+
const COFFSyncStream &operator<<(const COFFSyncStream &, Symbol *);
4042

4143
// The base class for real symbol classes.
4244
class Symbol {

0 commit comments

Comments
 (0)