uint32_t MinorImageVersion = 0;
uint32_t MajorOSVersion = 6;
uint32_t MinorOSVersion = 0;
+ bool CanExitEarly = false;
bool DynamicBase = true;
bool AllowBind = true;
bool NxCompat = true;
StringSaver Saver{BAlloc};
std::vector<SpecificAllocBase *> SpecificAllocBase::Instances;
-bool link(ArrayRef<const char *> Args, raw_ostream &Diag) {
+bool link(ArrayRef<const char *> Args, bool CanExitEarly, raw_ostream &Diag) {
ErrorCount = 0;
ErrorOS = &Diag;
Config = make<Configuration>();
Config->Argv = {Args.begin(), Args.end()};
Config->ColorDiagnostics = ErrorOS->has_colors();
+ Config->CanExitEarly = CanExitEarly;
Symtab = make<SymbolTable>();
Driver = make<LinkerDriver>();
Driver->link(Args);
+
+ // Call exit() if we can to avoid calling destructors.
+ if (CanExitEarly)
+ exitLld(ErrorCount ? 1 : 0);
+
+ freeArena();
return !ErrorCount;
}
if (!Args.hasArg(OPT_INPUT)) {
fixupExports();
createImportLibrary(/*AsLib=*/true);
- exit(0);
+ return;
}
// Handle /delayload
// This is useful because MSVC link.exe can generate complete PDBs.
if (Args.hasArg(OPT_msvclto)) {
invokeMSVC(Args);
- exit(0);
+ return;
}
// Do LTO by compiling bitcode input files to a set of native COFF files then
// Write the result.
writeResult();
-
- if (ErrorCount)
- return;
-
- // Call exit to avoid calling destructors.
- exit(0);
}
} // namespace coff
uint64_t ErrorCount;
raw_ostream *ErrorOS;
-static LLVM_ATTRIBUTE_NORETURN void exitLld(int Val) {
+LLVM_ATTRIBUTE_NORETURN void exitLld(int Val) {
// Dealloc/destroy ManagedStatic variables before calling
// _exit(). In a non-LTO build, this is a nop. In an LTO
// build allows us to get the output of -time-passes.
print("error: ", raw_ostream::RED);
*ErrorOS << "too many errors emitted, stopping now"
<< " (use /ERRORLIMIT:0 to see all errors)\n";
- exitLld(1);
+ if (Config->CanExitEarly)
+ exitLld(1);
}
++ErrorCount;
LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
+LLVM_ATTRIBUTE_NORETURN void exitLld(int Val);
+
template <class T> T check(ErrorOr<T> V, const Twine &Prefix) {
if (auto EC = V.getError())
fatal(EC, Prefix);
std::vector<const char *> Vec;
for (const std::string &S : LinkArgs)
Vec.push_back(S.c_str());
- return coff::link(Vec);
+ return coff::link(Vec, true);
}
namespace lld {
namespace coff {
-bool link(llvm::ArrayRef<const char *> Args,
+bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly,
llvm::raw_ostream &Diag = llvm::errs());
}
return !mingw::link(Args);
return !elf::link(Args, true);
case WinLink:
- return !coff::link(Args);
+ return !coff::link(Args, true);
case Darwin:
return !mach_o::link(Args);
default: