[lld-link] Replace error(...) with Err

This commit is contained in:
Fangrui Song 2024-12-05 19:44:26 -08:00
parent f0b09dfd4c
commit 8d225f10ef
7 changed files with 104 additions and 92 deletions

View File

@ -49,7 +49,7 @@ struct Cluster {
class CallGraphSort {
public:
CallGraphSort(const COFFLinkerContext &ctx);
CallGraphSort(COFFLinkerContext &ctx);
DenseMap<const SectionChunk *, int> run();
@ -57,7 +57,7 @@ private:
std::vector<Cluster> clusters;
std::vector<const SectionChunk *> sections;
const COFFLinkerContext &ctx;
COFFLinkerContext &ctx;
};
// Maximum amount the combined cluster density can be worse than the original
@ -73,7 +73,7 @@ using SectionPair = std::pair<const SectionChunk *, const SectionChunk *>;
// Take the edge list in Config->CallGraphProfile, resolve symbol names to
// Symbols, and generate a graph between InputSections with the provided
// weights.
CallGraphSort::CallGraphSort(const COFFLinkerContext &ctx) : ctx(ctx) {
CallGraphSort::CallGraphSort(COFFLinkerContext &ctx) : ctx(ctx) {
const MapVector<SectionPair, uint64_t> &profile = ctx.config.callGraphProfile;
DenseMap<const SectionChunk *, int> secToCluster;
@ -211,7 +211,8 @@ DenseMap<const SectionChunk *, int> CallGraphSort::run() {
std::error_code ec;
raw_fd_ostream os(ctx.config.printSymbolOrder, ec, sys::fs::OF_None);
if (ec) {
error("cannot open " + ctx.config.printSymbolOrder + ": " + ec.message());
Err(ctx) << "cannot open " << ctx.config.printSymbolOrder << ": "
<< ec.message();
return orderMap;
}
// Print the symbols ordered by C3, in the order of increasing curOrder
@ -244,6 +245,6 @@ DenseMap<const SectionChunk *, int> CallGraphSort::run() {
// according to the C³ heuristic. All clusters are then sorted by a density
// metric to further improve locality.
DenseMap<const SectionChunk *, int>
coff::computeCallGraphProfileOrder(const COFFLinkerContext &ctx) {
coff::computeCallGraphProfileOrder(COFFLinkerContext &ctx) {
return CallGraphSort(ctx).run();
}

View File

@ -16,7 +16,7 @@ class SectionChunk;
class COFFLinkerContext;
llvm::DenseMap<const SectionChunk *, int>
computeCallGraphProfileOrder(const COFFLinkerContext &ctx);
computeCallGraphProfileOrder(COFFLinkerContext &ctx);
} // namespace lld::coff
#endif

View File

@ -101,8 +101,8 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
}
// Parse options of the form "old;new".
static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
unsigned id) {
static std::pair<StringRef, StringRef>
getOldNewOptions(COFFLinkerContext &ctx, opt::InputArgList &args, unsigned id) {
auto *arg = args.getLastArg(id);
if (!arg)
return {"", ""};
@ -110,14 +110,16 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
StringRef s = arg->getValue();
std::pair<StringRef, StringRef> ret = s.split(';');
if (ret.second.empty())
error(arg->getSpelling() + " expects 'old;new' format, but got " + s);
Err(ctx) << arg->getSpelling() << " expects 'old;new' format, but got "
<< s;
return ret;
}
// Parse options of the form "old;new[;extra]".
static std::tuple<StringRef, StringRef, StringRef>
getOldNewOptionsExtra(opt::InputArgList &args, unsigned id) {
auto [oldDir, second] = getOldNewOptions(args, id);
getOldNewOptionsExtra(COFFLinkerContext &ctx, opt::InputArgList &args,
unsigned id) {
auto [oldDir, second] = getOldNewOptions(ctx, args, id);
auto [newDir, extraDir] = second.split(';');
return {oldDir, newDir, extraDir};
}
@ -243,13 +245,14 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> mb,
break;
}
if (filename.ends_with_insensitive(".dll")) {
error(filename + ": bad file type. Did you specify a DLL instead of an "
"import library?");
Err(ctx) << filename
<< ": bad file type. Did you specify a DLL instead of an "
"import library?";
break;
}
[[fallthrough]];
default:
error(mbref.getBufferIdentifier() + ": unknown file type");
Err(ctx) << mbref.getBufferIdentifier() << ": unknown file type";
break;
}
}
@ -289,9 +292,9 @@ void LinkerDriver::enqueuePath(StringRef path, bool wholeArchive, bool lazy) {
// directory.
std::string nearest;
if (ctx.optTable.findNearest(pathStr, nearest) > 1)
error(msg);
Err(ctx) << msg;
else
error(msg + "; did you mean '" + nearest + "'");
Err(ctx) << msg << "; did you mean '" << nearest << "'";
} else
ctx.driver.addBuffer(std::move(mb), wholeArchive, lazy);
});
@ -315,11 +318,11 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef mb, StringRef symName,
obj =
make<BitcodeFile>(ctx, mb, parentName, offsetInArchive, /*lazy=*/false);
} else if (magic == file_magic::coff_cl_gl_object) {
error(mb.getBufferIdentifier() +
": is not a native COFF file. Recompile without /GL?");
Err(ctx) << mb.getBufferIdentifier()
<< ": is not a native COFF file. Recompile without /GL?";
return;
} else {
error("unknown file type: " + mb.getBufferIdentifier());
Err(ctx) << "unknown file type: " << mb.getBufferIdentifier();
return;
}
@ -485,8 +488,8 @@ void LinkerDriver::parseDirectives(InputFile *file) {
case OPT_inferasanlibs_no:
break;
default:
error(arg->getSpelling() + " is not allowed in .drectve (" +
toString(file) + ")");
Err(ctx) << arg->getSpelling() << " is not allowed in .drectve ("
<< toString(file) << ")";
}
}
}
@ -751,7 +754,7 @@ Symbol *LinkerDriver::addUndefined(StringRef name, bool aliasEC) {
void LinkerDriver::addUndefinedGlob(StringRef arg) {
Expected<GlobPattern> pat = GlobPattern::create(arg);
if (!pat) {
error("/includeglob: " + toString(pat.takeError()));
Err(ctx) << "/includeglob: " << toString(pat.takeError());
return;
}
@ -1133,7 +1136,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
// For some reason, the MSVC linker requires a filename to be
// preceded by "@".
if (!arg.starts_with("@")) {
error("malformed /order option: '@' missing");
Err(ctx) << "malformed /order option: '@' missing";
return;
}
@ -1206,7 +1209,7 @@ void LinkerDriver::parseCallGraphFile(StringRef path) {
uint64_t count;
if (fields.size() != 3 || !to_integer(fields[2], count)) {
error(path + ": parse error");
Err(ctx) << path << ": parse error";
return;
}
@ -1360,10 +1363,11 @@ void LinkerDriver::convertResources() {
if (!ctx.config.mingw &&
(resourceObjFiles.size() > 1 ||
(resourceObjFiles.size() == 1 && !resources.empty()))) {
error((!resources.empty() ? "internal .obj file created from .res files"
: toString(resourceObjFiles[1])) +
": more than one resource obj file not allowed, already got " +
toString(resourceObjFiles.front()));
Err(ctx) << (!resources.empty()
? "internal .obj file created from .res files"
: toString(resourceObjFiles[1]))
<< ": more than one resource obj file not allowed, already got "
<< resourceObjFiles.front();
return;
}
@ -1528,7 +1532,7 @@ std::optional<std::string> getReproduceFile(const opt::InputArgList &args) {
}
static std::unique_ptr<llvm::vfs::FileSystem>
getVFS(const opt::InputArgList &args) {
getVFS(COFFLinkerContext &ctx, const opt::InputArgList &args) {
using namespace llvm::vfs;
const opt::Arg *arg = args.getLastArg(OPT_vfsoverlay);
@ -1545,7 +1549,7 @@ getVFS(const opt::InputArgList &args) {
/*DiagHandler*/ nullptr, arg->getValue()))
return ret;
error("Invalid vfs overlay");
Err(ctx) << "Invalid vfs overlay";
return nullptr;
}
@ -1606,11 +1610,11 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
int n = 20;
StringRef s = arg->getValue();
if (s.getAsInteger(10, n))
error(arg->getSpelling() + " number expected, but got " + s);
Err(ctx) << arg->getSpelling() << " number expected, but got " << s;
ctx.e.errorLimit = n;
}
config->vfs = getVFS(args);
config->vfs = getVFS(ctx, args);
// Handle /help
if (args.hasArg(OPT_help)) {
@ -1624,8 +1628,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
StringRef v(arg->getValue());
unsigned threads = 0;
if (!llvm::to_integer(v, threads, 0) || threads == 0)
error(arg->getSpelling() + ": expected a positive integer, but got '" +
arg->getValue() + "'");
Err(ctx) << arg->getSpelling()
<< ": expected a positive integer, but got '" << arg->getValue()
<< "'";
parallel::strategy = hardware_concurrency(threads);
config->thinLTOJobs = v.str();
}
@ -1661,8 +1666,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (errOrWriter) {
tar = std::move(*errOrWriter);
} else {
error("/linkrepro: failed to open " + *path + ": " +
toString(errOrWriter.takeError()));
Err(ctx) << "/linkrepro: failed to open " << *path << ": "
<< toString(errOrWriter.takeError());
}
}
}
@ -1788,7 +1793,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
} else if (s == "nosymtab") {
config->writeSymtab = false;
} else {
error("/debug: unknown option: " + s);
Err(ctx) << "/debug: unknown option: " << s;
}
}
}
@ -1841,7 +1846,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (args.hasArg(OPT_dll))
config->noEntry = true;
else
error("/noentry must be specified with /dll");
Err(ctx) << "/noentry must be specified with /dll";
}
// Handle /dll
@ -1865,7 +1870,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (fixed) {
if (dynamicBaseArg &&
dynamicBaseArg->getOption().getID() == OPT_dynamicbase) {
error("/fixed must not be specified with /dynamicbase");
Err(ctx) << "/fixed must not be specified with /dynamicbase";
} else {
config->relocatable = false;
config->dynamicBase = false;
@ -1906,7 +1911,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (auto *arg = args.getLastArg(OPT_filealign)) {
parseNumbers(arg->getValue(), &config->fileAlign);
if (!isPowerOf2_64(config->fileAlign))
error("/filealign: not a power of two: " + Twine(config->fileAlign));
Err(ctx) << "/filealign: not a power of two: " << config->fileAlign;
}
// Handle /stack
@ -2013,21 +2018,22 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
ltoDebugPM = false;
} else if (s.consume_front("lldlto=")) {
if (s.getAsInteger(10, config->ltoo) || config->ltoo > 3)
error("/opt:lldlto: invalid optimization level: " + s);
Err(ctx) << "/opt:lldlto: invalid optimization level: " << s;
} else if (s.consume_front("lldltocgo=")) {
config->ltoCgo.emplace();
if (s.getAsInteger(10, *config->ltoCgo) || *config->ltoCgo > 3)
error("/opt:lldltocgo: invalid codegen optimization level: " + s);
Err(ctx) << "/opt:lldltocgo: invalid codegen optimization level: "
<< s;
} else if (s.consume_front("lldltojobs=")) {
if (!get_threadpool_strategy(s))
error("/opt:lldltojobs: invalid job count: " + s);
Err(ctx) << "/opt:lldltojobs: invalid job count: " << s;
config->thinLTOJobs = s.str();
} else if (s.consume_front("lldltopartitions=")) {
if (s.getAsInteger(10, config->ltoPartitions) ||
config->ltoPartitions == 0)
error("/opt:lldltopartitions: invalid partition count: " + s);
Err(ctx) << "/opt:lldltopartitions: invalid partition count: " << s;
} else if (s != "lbr" && s != "nolbr")
error("/opt: unknown option: " + s);
Err(ctx) << "/opt: unknown option: " << s;
}
}
@ -2049,7 +2055,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (llvm::is_contained(lldsaveTempsValues, s))
config->saveTempsArgs.insert(s);
else
error("unknown /lldsavetemps value: " + s);
Err(ctx) << "unknown /lldsavetemps value: " << s;
}
}
@ -2063,7 +2069,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
else if (s == "asm")
config->emit = EmitKind::ASM;
else
error("/lldemit: unknown option: " + s);
Err(ctx) << "/lldemit: unknown option: " << s;
}
// Handle /kill-at
@ -2114,7 +2120,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (auto *arg = args.getLastArg(OPT_align)) {
parseNumbers(arg->getValue(), &config->align);
if (!isPowerOf2_64(config->align))
error("/align: not a power of two: " + StringRef(arg->getValue()));
Err(ctx) << "/align: not a power of two: " << StringRef(arg->getValue());
if (!args.hasArg(OPT_driver))
Warn(ctx) << "/align specified without /driver; image may not run";
}
@ -2162,9 +2168,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
args.getLastArgValue(OPT_thinlto_index_only_arg);
std::tie(config->thinLTOPrefixReplaceOld, config->thinLTOPrefixReplaceNew,
config->thinLTOPrefixReplaceNativeObject) =
getOldNewOptionsExtra(args, OPT_thinlto_prefix_replace);
getOldNewOptionsExtra(ctx, args, OPT_thinlto_prefix_replace);
config->thinLTOObjectSuffixReplace =
getOldNewOptions(args, OPT_thinlto_object_suffix_replace);
getOldNewOptions(ctx, args, OPT_thinlto_object_suffix_replace);
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path);
config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);
config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);
@ -2258,12 +2264,12 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
switch (arg->getOption().getID()) {
case OPT_end_lib:
if (!inLib)
error("stray " + arg->getSpelling());
Err(ctx) << "stray " << arg->getSpelling();
inLib = false;
break;
case OPT_start_lib:
if (inLib)
error("nested " + arg->getSpelling());
Err(ctx) << "nested " << arg->getSpelling();
inLib = true;
break;
case OPT_wholearchive_file:
@ -2355,8 +2361,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (!config->dynamicBase &&
(config->machine == ARMNT || isAnyArm64(config->machine)))
error("/dynamicbase:no is not compatible with " +
machineToStr(config->machine));
Err(ctx) << "/dynamicbase:no is not compatible with "
<< machineToStr(config->machine);
// Handle /export
{
@ -2446,7 +2452,8 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// Fail early if an output file is not writable.
if (auto e = tryCreateFile(config->outputFile)) {
error("cannot open output file " + config->outputFile + ": " + e.message());
Err(ctx) << "cannot open output file " << config->outputFile << ": "
<< e.message();
return;
}
@ -2459,7 +2466,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (s == "exports")
config->mapInfo = true;
else
error("unknown option: /mapinfo:" + s);
Err(ctx) << "unknown option: /mapinfo:" << s;
}
}
@ -2774,7 +2781,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// functions.
if (auto *arg = args.getLastArg(OPT_order)) {
if (args.hasArg(OPT_call_graph_ordering_file))
error("/order and /call-graph-order-file may not be used together");
Err(ctx) << "/order and /call-graph-order-file may not be used together";
parseOrderFile(arg->getValue());
config->callGraphProfileSort = false;
}

View File

@ -179,11 +179,11 @@ void LinkerDriver::parseMerge(StringRef s) {
void LinkerDriver::parsePDBPageSize(StringRef s) {
int v;
if (s.getAsInteger(0, v)) {
error("/pdbpagesize: invalid argument: " + s);
Err(ctx) << "/pdbpagesize: invalid argument: " << s;
return;
}
if (v != 4096 && v != 8192 && v != 16384 && v != 32768) {
error("/pdbpagesize: invalid argument: " + s);
Err(ctx) << "/pdbpagesize: invalid argument: " << s;
return;
}
@ -234,12 +234,12 @@ void LinkerDriver::parseSection(StringRef s) {
void LinkerDriver::parseAligncomm(StringRef s) {
auto [name, align] = s.split(',');
if (name.empty() || align.empty()) {
error("/aligncomm: invalid argument: " + s);
Err(ctx) << "/aligncomm: invalid argument: " << s;
return;
}
int v;
if (align.getAsInteger(0, v)) {
error("/aligncomm: invalid argument: " + s);
Err(ctx) << "/aligncomm: invalid argument: " << s;
return;
}
ctx.config.alignComm[std::string(name)] =
@ -252,7 +252,7 @@ void LinkerDriver::parseFunctionPadMin(llvm::opt::Arg *a) {
if (!arg.empty()) {
// Optional padding in bytes is given.
if (arg.getAsInteger(0, ctx.config.functionPadMin))
error("/functionpadmin: invalid argument: " + arg);
Err(ctx) << "/functionpadmin: invalid argument: " << arg;
return;
}
// No optional argument given.
@ -263,7 +263,7 @@ void LinkerDriver::parseFunctionPadMin(llvm::opt::Arg *a) {
} else if (ctx.config.machine == AMD64) {
ctx.config.functionPadMin = 6;
} else {
error("/functionpadmin: invalid argument for this machine: " + arg);
Err(ctx) << "/functionpadmin: invalid argument for this machine: " << arg;
}
}
@ -272,12 +272,12 @@ void LinkerDriver::parseDependentLoadFlags(llvm::opt::Arg *a) {
StringRef arg = a->getNumValues() ? a->getValue() : "";
if (!arg.empty()) {
if (arg.getAsInteger(0, ctx.config.dependentLoadFlags))
error("/dependentloadflag: invalid argument: " + arg);
Err(ctx) << "/dependentloadflag: invalid argument: " << arg;
return;
}
// MSVC linker reports error "no argument specified", although MSDN describes
// argument as optional.
error("/dependentloadflag: no argument specified");
Err(ctx) << "/dependentloadflag: no argument specified";
}
// Parses a string in the form of "EMBED[,=<integer>]|NO".
@ -334,12 +334,12 @@ void LinkerDriver::parseSwaprun(StringRef arg) {
else if (swaprun.equals_insensitive("net"))
ctx.config.swaprunNet = true;
else if (swaprun.empty())
error("/swaprun: missing argument");
Err(ctx) << "/swaprun: missing argument";
else
error("/swaprun: invalid argument: " + swaprun);
Err(ctx) << "/swaprun: invalid argument: " << swaprun;
// To catch trailing commas, e.g. `/spawrun:cd,`
if (newArg.empty() && arg.ends_with(","))
error("/swaprun: missing argument");
Err(ctx) << "/swaprun: missing argument";
arg = newArg;
} while (!arg.empty());
}
@ -614,7 +614,7 @@ Export LinkerDriver::parseExport(StringRef arg) {
if (!rest.empty() && !rest.contains(','))
e.exportAs = rest;
else
error("invalid EXPORTAS value: " + rest);
Err(ctx) << "invalid EXPORTAS value: " << rest;
break;
}
if (tok.starts_with("@")) {
@ -824,7 +824,7 @@ MemoryBufferRef LinkerDriver::convertResToCOFF(ArrayRef<MemoryBufferRef> mbs,
if (ctx.config.forceMultipleRes)
Warn(ctx) << dupeDiag;
else
error(dupeDiag);
Err(ctx) << dupeDiag;
Expected<std::unique_ptr<MemoryBuffer>> e =
llvm::object::writeWindowsResourceCOFF(ctx.config.machine, parser,
@ -875,7 +875,7 @@ static void handleColorDiagnostics(COFFLinkerContext &ctx,
else if (s == "never")
ctx.e.errs().enable_colors(false);
else if (s != "auto")
error("unknown option: --color-diagnostics=" + s);
Err(ctx) << "unknown option: --color-diagnostics=" << s;
}
}

View File

@ -187,7 +187,7 @@ struct ECMapEntry {
void ObjFile::initializeECThunks() {
for (SectionChunk *chunk : hybmpChunks) {
if (chunk->getContents().size() % sizeof(ECMapEntry)) {
error("Invalid .hybmp chunk size " + Twine(chunk->getContents().size()));
Err(ctx) << "Invalid .hybmp chunk size " << chunk->getContents().size();
continue;
}
@ -363,9 +363,9 @@ void ObjFile::readAssociativeDefinition(COFFSymbolRef sym,
const coff_section *parentSec = getSection(parentIndex);
if (Expected<StringRef> e = coffObj->getSectionName(parentSec))
parentName = *e;
error(toString(this) + ": associative comdat " + name + " (sec " +
Twine(sectionNumber) + ") has invalid reference to section " +
parentName + " (sec " + Twine(parentIndex) + ")");
Err(ctx) << toString(this) << ": associative comdat " << name << " (sec "
<< sectionNumber << ") has invalid reference to section "
<< parentName << " (sec " << parentIndex << ")";
};
if (parent == pendingComdat) {
@ -1325,12 +1325,12 @@ void DLLFile::parse() {
bin.release();
coffObj.reset(obj);
} else {
error(toString(this) + " is not a COFF file");
Err(ctx) << toString(this) << " is not a COFF file";
return;
}
if (!coffObj->getPE32Header() && !coffObj->getPE32PlusHeader()) {
error(toString(this) + " is not a PE-COFF executable");
Err(ctx) << toString(this) << " is not a PE-COFF executable";
return;
}

View File

@ -66,8 +66,9 @@ void SymbolTable::addFile(InputFile *file) {
ctx.objFileInstances.push_back(f);
} else if (auto *f = dyn_cast<BitcodeFile>(file)) {
if (ltoCompilationDone) {
error("LTO object file " + toString(file) + " linked in after "
"doing LTO compilation.");
Err(ctx) << "LTO object file " << toString(file)
<< " linked in after "
"doing LTO compilation.";
}
ctx.bitcodeFileInstances.push_back(f);
} else if (auto *f = dyn_cast<ImportFile>(file)) {
@ -81,13 +82,14 @@ void SymbolTable::addFile(InputFile *file) {
(ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN ||
(ctx.config.machineInferred &&
(ctx.config.machine == ARM64 || ctx.config.machine == AMD64)))) {
error(toString(file) + ": machine type arm64ec is ambiguous and cannot be "
"inferred, use /machine:arm64ec or /machine:arm64x");
Err(ctx) << toString(file)
<< ": machine type arm64ec is ambiguous and cannot be "
"inferred, use /machine:arm64ec or /machine:arm64x";
return;
}
if (!compatibleMachineType(ctx, mt)) {
error(toString(file) + ": machine type " + machineToStr(mt) +
" conflicts with " + machineToStr(ctx.config.machine));
Err(ctx) << toString(file) << ": machine type " << machineToStr(mt)
<< " conflicts with " << machineToStr(ctx.config.machine);
return;
}
if (ctx.config.machine == IMAGE_FILE_MACHINE_UNKNOWN &&
@ -624,7 +626,7 @@ void SymbolTable::initializeECThunks() {
// feasible, functions are required to be COMDAT symbols with no offset.
if (!from || !from->getChunk()->isCOMDAT() ||
cast<DefinedRegular>(from)->getValue()) {
error("non COMDAT symbol '" + from->getName() + "' in hybrid map");
Err(ctx) << "non COMDAT symbol '" << from->getName() << "' in hybrid map";
continue;
}
from->getChunk()->setEntryThunk(to);
@ -819,7 +821,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile,
if (ctx.config.forceMultiple)
Warn(ctx) << msg;
else
error(msg);
Err(ctx) << msg;
}
Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) {

View File

@ -1644,7 +1644,7 @@ void Writer::assignAddresses() {
rawSize = alignTo(virtualSize, config->fileAlign);
}
if (virtualSize > UINT32_MAX)
error("section larger than 4 GiB: " + sec->name);
Err(ctx) << "section larger than 4 GiB: " << sec->name;
sec->header.VirtualSize = virtualSize;
sec->header.SizeOfRawData = rawSize;
if (rawSize != 0)
@ -1896,7 +1896,8 @@ void Writer::createSEHTable() {
SymbolRVASet handlers;
for (ObjFile *file : ctx.objFileInstances) {
if (!file->hasSafeSEH())
error("/safeseh: " + file->getName() + " is not compatible with SEH");
Err(ctx) << "/safeseh: " << file->getName()
<< " is not compatible with SEH";
markSymbolsForRVATable(file, file->getSXDataChunks(), handlers);
}
@ -2238,8 +2239,8 @@ void Writer::createRuntimePseudoRelocs() {
// Not writing any pseudo relocs; if some were needed, error out and
// indicate what required them.
for (const RuntimePseudoReloc &rpr : rels)
error("automatic dllimport of " + rpr.sym->getName() + " in " +
toString(rpr.target->file) + " requires pseudo relocations");
Err(ctx) << "automatic dllimport of " << rpr.sym->getName() << " in "
<< toString(rpr.target->file) << " requires pseudo relocations";
return;
}
@ -2249,9 +2250,10 @@ void Writer::createRuntimePseudoRelocs() {
const char *symbolName = "_pei386_runtime_relocator";
Symbol *relocator = ctx.symtab.findUnderscore(symbolName);
if (!relocator)
error("output image has runtime pseudo relocations, but the function " +
Twine(symbolName) +
" is missing; it is needed for fixing the relocations at runtime");
Err(ctx)
<< "output image has runtime pseudo relocations, but the function "
<< symbolName
<< " is missing; it is needed for fixing the relocations at runtime";
}
PseudoRelocTableChunk *table = make<PseudoRelocTableChunk>(rels);