mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
LLD patch: COFF: better behavior when using as a library
This applies de776439b61fb71c1256ad86238799c758c66048 from the LLVM git monorepo to the embedded LLD.
This commit is contained in:
parent
77b530b50a
commit
9ea23272fa
1
deps/lld/COFF/Config.h
vendored
1
deps/lld/COFF/Config.h
vendored
@ -157,6 +157,7 @@ struct Configuration {
|
||||
uint32_t MinorImageVersion = 0;
|
||||
uint32_t MajorOSVersion = 6;
|
||||
uint32_t MinorOSVersion = 0;
|
||||
bool CanExitEarly = false;
|
||||
bool DynamicBase = true;
|
||||
bool NxCompat = true;
|
||||
bool AllowIsolation = true;
|
||||
|
||||
16
deps/lld/COFF/Driver.cpp
vendored
16
deps/lld/COFF/Driver.cpp
vendored
@ -52,15 +52,22 @@ BumpPtrAllocator BAlloc;
|
||||
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 == &llvm::errs() && Process::StandardErrHasColors());
|
||||
Config->CanExitEarly = CanExitEarly;
|
||||
Driver = make<LinkerDriver>();
|
||||
Driver->link(Args);
|
||||
|
||||
// Call exit() if we can to avoid calling destructors.
|
||||
if (CanExitEarly)
|
||||
exitLld(ErrorCount ? 1 : 0);
|
||||
|
||||
freeArena();
|
||||
return !ErrorCount;
|
||||
}
|
||||
|
||||
@ -1030,7 +1037,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
||||
if (!Args.hasArgNoClaim(OPT_INPUT)) {
|
||||
fixupExports();
|
||||
createImportLibrary(/*AsLib=*/true);
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle /delayload
|
||||
@ -1122,7 +1129,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
||||
// 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
|
||||
@ -1172,9 +1179,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
|
||||
|
||||
// Write the result.
|
||||
writeResult(&Symtab);
|
||||
|
||||
// Call exit to avoid calling destructors.
|
||||
exit(0);
|
||||
}
|
||||
|
||||
} // namespace coff
|
||||
|
||||
5
deps/lld/COFF/Error.cpp
vendored
5
deps/lld/COFF/Error.cpp
vendored
@ -32,7 +32,7 @@ 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.
|
||||
@ -78,7 +78,8 @@ void error(const Twine &Msg) {
|
||||
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;
|
||||
|
||||
2
deps/lld/COFF/Error.h
vendored
2
deps/lld/COFF/Error.h
vendored
@ -27,6 +27,8 @@ LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
|
||||
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);
|
||||
|
||||
2
deps/lld/include/lld/Driver/Driver.h
vendored
2
deps/lld/include/lld/Driver/Driver.h
vendored
@ -15,7 +15,7 @@
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
||||
2
deps/lld/tools/lld/lld.cpp
vendored
2
deps/lld/tools/lld/lld.cpp
vendored
@ -103,7 +103,7 @@ int main(int Argc, const char **Argv) {
|
||||
case Gnu:
|
||||
return !elf::link(Args, true);
|
||||
case WinLink:
|
||||
return !coff::link(Args);
|
||||
return !coff::link(Args, true);
|
||||
case Darwin:
|
||||
return !mach_o::link(Args);
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user