[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-commits
Subject:    [PATCH] D112878: [MachO] Properly reset global state
From:       Shoaib Meenai via Phabricator via llvm-commits <llvm-commits () lists ! llvm ! org>
Date:       2021-10-31 23:15:40
Message-ID: o16Sv-pNRQWJcldGpYd5kg () ismtpd0221p1mdw1 ! sendgrid ! net
[Download RAW message or body]

This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f6d720f1f48: [MachO] Properly reset global state (autho=
red by smeenai).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112878/new/

https://reviews.llvm.org/D112878

Files:
  lld/MachO/Driver.cpp
  lld/MachO/Driver.h
  lld/MachO/DriverUtils.cpp
  lld/MachO/InputFiles.h
  lld/MachO/OutputSegment.cpp
  lld/MachO/OutputSegment.h
  lld/MachO/Writer.cpp
  lld/MachO/Writer.h


["D112878.383692.patch" (D112878.383692.patch)]

Index: lld/MachO/Writer.h
===================================================================
--- lld/MachO/Writer.h
+++ lld/MachO/Writer.h
@@ -26,6 +26,7 @@
 };
 
 template <class LP> void writeResult();
+void resetWriter();
 
 void createSyntheticSections();
 
Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -343,6 +343,7 @@
   }
 
   static uint32_t getInstanceCount() { return instanceCount; }
+  static void resetInstanceCount() { instanceCount = 0; }
 
 private:
   LoadCommandType type;
@@ -1153,6 +1154,8 @@
 
 template <class LP> void macho::writeResult() { Writer().run<LP>(); }
 
+void macho::resetWriter() { LCDylib::resetInstanceCount(); }
+
 void macho::createSyntheticSections() {
   in.header = make<MachHeaderSection>();
   if (config->dedupLiterals) {
Index: lld/MachO/OutputSegment.h
===================================================================
--- lld/MachO/OutputSegment.h
+++ lld/MachO/OutputSegment.h
@@ -68,6 +68,7 @@
 extern std::vector<OutputSegment *> outputSegments;
 
 void sortOutputSegments();
+void resetOutputSegments();
 
 OutputSegment *getOrCreateOutputSegment(StringRef name);
 
Index: lld/MachO/OutputSegment.cpp
===================================================================
--- lld/MachO/OutputSegment.cpp
+++ lld/MachO/OutputSegment.cpp
@@ -161,6 +161,11 @@
 static DenseMap<StringRef, OutputSegment *> nameToOutputSegment;
 std::vector<OutputSegment *> macho::outputSegments;
 
+void macho::resetOutputSegments() {
+  outputSegments.clear();
+  nameToOutputSegment.clear();
+}
+
 static StringRef maybeRenameSegment(StringRef name) {
   auto newName = config->segmentRenameMap.find(name);
   if (newName != config->segmentRenameMap.end())
Index: lld/MachO/InputFiles.h
===================================================================
--- lld/MachO/InputFiles.h
+++ lld/MachO/InputFiles.h
@@ -69,6 +69,7 @@
   virtual ~InputFile() = default;
   Kind kind() const { return fileKind; }
   StringRef getName() const { return name; }
+  static void resetIdCount() { idCount = 0; }
 
   MemoryBufferRef mb;
 
Index: lld/MachO/DriverUtils.cpp
===================================================================
--- lld/MachO/DriverUtils.cpp
+++ lld/MachO/DriverUtils.cpp
@@ -246,6 +246,8 @@
   return newFile;
 }
 
+void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
+
 Optional<StringRef>
 macho::findPathCombination(const Twine &name,
                            const std::vector<StringRef> &roots,
Index: lld/MachO/Driver.h
===================================================================
--- lld/MachO/Driver.h
+++ lld/MachO/Driver.h
@@ -56,6 +56,7 @@
 
 DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
                      bool isBundleLoader = false);
+void resetLoadedDylibs();
 
 // Search for all possible combinations of `{root}/{name}.{extension}`.
 // If \p extensions are not specified, then just search for `{root}/{name}`.
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -1068,7 +1068,25 @@
   lld::stdoutOS = &stdoutOS;
   lld::stderrOS = &stderrOS;
 
-  errorHandler().cleanupCallback = []() { freeArena(); };
+  errorHandler().cleanupCallback = []() {
+    freeArena();
+
+    concatOutputSections.clear();
+    inputFiles.clear();
+    inputSections.clear();
+    loadedArchives.clear();
+    syntheticSections.clear();
+    thunkMap.clear();
+
+    firstTLVDataSection = nullptr;
+    tar = nullptr;
+    memset(&in, 0, sizeof(in));
+
+    resetLoadedDylibs();
+    resetOutputSegments();
+    resetWriter();
+    InputFile::resetIdCount();
+  };
 
   errorHandler().logName = args::getFilenameWithoutExe(argsArr[0]);
   stderrOS.enable_colors(stderrOS.has_colors());
@@ -1392,6 +1410,8 @@
         reexportHandler(arg, extensions);
     }
 
+    cl::ResetAllOptionOccurrences();
+
     // Parse LTO options.
     if (const Arg *arg = args.getLastArg(OPT_mcpu))
       parseClangOption(saver.save("-mcpu=" + StringRef(arg->getValue())),
@@ -1476,5 +1496,7 @@
   if (canExitEarly)
     exitLld(errorCount() ? 1 : 0);
 
-  return !errorCount();
+  bool ret = errorCount() == 0;
+  errorHandler().reset();
+  return ret;
 }

[Attachment #4 (text/plain)]

_______________________________________________
llvm-commits mailing list
llvm-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic