LLD COFF not closing mmaps to input files?

I’ve got a patched LLD 5.0.0 like this:

diff --git a/deps/lld/COFF/Driver.cpp b/deps/lld/COFF/Driver.cpp
index 854c3e69…8bab1c11 100644
— a/deps/lld/COFF/Driver.cpp
+++ b/deps/lld/COFF/Driver.cpp
@@ -1030,7 +1030,7 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
if (!Args.hasArgNoClaim(OPT_INPUT)) {
fixupExports();
createImportLibrary(/AsLib=/true);

  • exit(0);
  • return;
    }

// Handle /delayload
@@ -1172,9 +1172,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {

// Write the result.
writeResult(&Symtab);

I believe this line is the culprit:

COFF/Driver.cpp:102:

make<std::unique_ptr>(std::move(MB)); // take ownership

Patch forthcoming.

I think you want to call freeArena() before returning from lld::coff::link.

Thanks Rui, your suggestion solved the problem perfectly.

diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 8bab1c11…0dabca6e 100644
— a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -61,6 +61,7 @@ bool link(ArrayRef<const char *> Args, raw_ostream &Diag) {
(ErrorOS == &llvm::errs() && Process::StandardErrHasColors());
Driver = make();
Driver->link(Args);

  • freeArena();
    return !ErrorCount;
    }

Could we get this patch upstream?

lld::coff::LinkerDriver::link is not expected to return, so the patch doesn’t make sense unless you have a local patch to make it return, but I’m fine with that change because it is harmless. Please go ahead.