From 54f5a4ea4c859cf7f34f0d4955abc3a2f44bd0dc Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Sat, 22 Aug 2020 23:04:22 +0300 Subject: [PATCH] [LLD][COFF] Reset outputSections for successive runs The global variable outputSections in the COFF writer was not cleared between runs which caused successive calls to lld::coff::link to generate invalid binaries. These binaries when loaded would result in "invalid win32 applications" and/or "bad image" errors. Differential Revision: https://reviews.llvm.org/D86401 --- lld/COFF/Writer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 36ecdcd13512..82dff2e5bb62 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -601,6 +601,9 @@ void Writer::finalizeAddresses() { void Writer::run() { ScopedTimer t1(codeLayoutTimer); + // First, clear the output sections from previous runs + outputSections.clear(); + createImportTables(); createSections(); createMiscChunks();