authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-01 12:06:33-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-01 12:06:33-05:00
log9ea23272fac7f4580d29f7ee557108883f127a5d
tree5251b09dbe1149afaa70fc588e280bed97de232e
parent77b530b50aedd1cf9943e1d4fdd97a364fe9a921

LLD patch: COFF: better behavior when using as a library

This applies de776439b61fb71c1256ad86238799c758c66048 from the LLVM git monorepo to the embedded LLD.

6 files changed, 18 insertions(+), 10 deletions(-)

deps/lld/COFF/Config.h+1
......@@ -157,6 +157,7 @@ struct Configuration {
157157 uint32_t MinorImageVersion = 0;
158158 uint32_t MajorOSVersion = 6;
159159 uint32_t MinorOSVersion = 0;
160 bool CanExitEarly = false;
160161 bool DynamicBase = true;
161162 bool NxCompat = true;
162163 bool AllowIsolation = true;
deps/lld/COFF/Driver.cpp+10-6
......@@ -52,15 +52,22 @@ BumpPtrAllocator BAlloc;
5252StringSaver Saver{BAlloc};
5353std::vector<SpecificAllocBase *> SpecificAllocBase::Instances;
5454
55bool link(ArrayRef<const char *> Args, raw_ostream &Diag) {
55bool link(ArrayRef<const char *> Args, bool CanExitEarly, raw_ostream &Diag) {
5656 ErrorCount = 0;
5757 ErrorOS = &Diag;
5858 Config = make<Configuration>();
5959 Config->Argv = {Args.begin(), Args.end()};
6060 Config->ColorDiagnostics =
6161 (ErrorOS == &llvm::errs() && Process::StandardErrHasColors());
62 Config->CanExitEarly = CanExitEarly;
6263 Driver = make<LinkerDriver>();
6364 Driver->link(Args);
65
66 // Call exit() if we can to avoid calling destructors.
67 if (CanExitEarly)
68 exitLld(ErrorCount ? 1 : 0);
69
70 freeArena();
6471 return !ErrorCount;
6572}
6673
......@@ -1030,7 +1037,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
10301037 if (!Args.hasArgNoClaim(OPT_INPUT)) {
10311038 fixupExports();
10321039 createImportLibrary(/*AsLib=*/true);
1033 exit(0);
1040 return;
10341041 }
10351042
10361043 // Handle /delayload
......@@ -1122,7 +1129,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
11221129 // This is useful because MSVC link.exe can generate complete PDBs.
11231130 if (Args.hasArg(OPT_msvclto)) {
11241131 invokeMSVC(Args);
1125 exit(0);
1132 return;
11261133 }
11271134
11281135 // 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) {
11721179
11731180 // Write the result.
11741181 writeResult(&Symtab);
1175
1176 // Call exit to avoid calling destructors.
1177 exit(0);
11781182}
11791183
11801184} // namespace coff
deps/lld/COFF/Error.cpp+3-2
......@@ -32,7 +32,7 @@ namespace coff {
3232uint64_t ErrorCount;
3333raw_ostream *ErrorOS;
3434
35static LLVM_ATTRIBUTE_NORETURN void exitLld(int Val) {
35LLVM_ATTRIBUTE_NORETURN void exitLld(int Val) {
3636 // Dealloc/destroy ManagedStatic variables before calling
3737 // _exit(). In a non-LTO build, this is a nop. In an LTO
3838 // build allows us to get the output of -time-passes.
......@@ -78,7 +78,8 @@ void error(const Twine &Msg) {
7878 print("error: ", raw_ostream::RED);
7979 *ErrorOS << "too many errors emitted, stopping now"
8080 << " (use /ERRORLIMIT:0 to see all errors)\n";
81 exitLld(1);
81 if (Config->CanExitEarly)
82 exitLld(1);
8283 }
8384
8485 ++ErrorCount;
deps/lld/COFF/Error.h+2
......@@ -27,6 +27,8 @@ LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg);
2727LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix);
2828LLVM_ATTRIBUTE_NORETURN void fatal(llvm::Error &Err, const Twine &Prefix);
2929
30LLVM_ATTRIBUTE_NORETURN void exitLld(int Val);
31
3032template <class T> T check(ErrorOr<T> V, const Twine &Prefix) {
3133 if (auto EC = V.getError())
3234 fatal(EC, Prefix);
deps/lld/include/lld/Driver/Driver.h+1-1
......@@ -15,7 +15,7 @@
1515
1616namespace lld {
1717namespace coff {
18bool link(llvm::ArrayRef<const char *> Args,
18bool link(llvm::ArrayRef<const char *> Args, bool CanExitEarly,
1919 llvm::raw_ostream &Diag = llvm::errs());
2020}
2121
deps/lld/tools/lld/lld.cpp+1-1
......@@ -103,7 +103,7 @@ int main(int Argc, const char **Argv) {
103103 case Gnu:
104104 return !elf::link(Args, true);
105105 case WinLink:
106 return !coff::link(Args);
106 return !coff::link(Args, true);
107107 case Darwin:
108108 return !mach_o::link(Args);
109109 default: