diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -112,8 +112,7 @@ // This driver-specific context will be freed later by lldMain(). auto *ctx = new CommonLinkerContext; - ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput); - ctx->e.cleanupCallback = []() { + auto cleanup = []() { elf::ctx.reset(); symtab = SymbolTable(); @@ -128,6 +127,13 @@ SharedFile::vernauxNum = 0; }; + + // Clears leftovers from any previous invocation + cleanup(); + + ctx->e.initialize(stdoutOS, stderrOS, exitEarly, disableOutput); + ctx->e.cleanupCallback = cleanup; + ctx->e.logName = args::getFilenameWithoutExe(args[0]); ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use " "--error-limit=0 to see all errors)";