[lld-link] Use COFFSyncStream
Add a operator<< overload for Symbol *.
This commit is contained in:
parent
fb2cbc00e0
commit
983f88c1ec
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -45,7 +45,8 @@ private:
|
||||
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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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: "
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user