[COFF] clean up global resources after completion
authorRui Ueyama <ruiu@google.com>
Thu, 26 Jul 2018 17:11:24 +0000 (17:11 +0000)
committerRui Ueyama <ruiu@google.com>
Thu, 26 Jul 2018 17:11:24 +0000 (17:11 +0000)
Patch by Andrew Kelley.

Previously, running lld::coff::link() twice in the same process would
access stale pointers because of these global variables not being reset.
After this patch, lld::coff::link() can be called any number of times,
just like its ELF and MACH-O counterparts.

Differential Revision: https://reviews.llvm.org/D49856

llvm-svn: 338042

lld/COFF/Driver.cpp

index 2f7afaa..eefdb48 100644 (file)
@@ -75,6 +75,9 @@ bool link(ArrayRef<const char *> Args, bool CanExitEarly, raw_ostream &Diag) {
     exitLld(errorCount() ? 1 : 0);
 
   freeArena();
+  ObjFile::Instances.clear();
+  ImportFile::Instances.clear();
+  BitcodeFile::Instances.clear();
   return !errorCount();
 }