[PATCH] D40581: COFF: Simplify construction of safe SEH table. NFCI.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 28 14:39:44 PST 2017


pcc created this revision.

Instead of building intermediate sets of exception handlers for each
object file, just create one for the final output file.


https://reviews.llvm.org/D40581

Files:
  lld/COFF/InputFiles.cpp
  lld/COFF/InputFiles.h
  lld/COFF/Writer.cpp


Index: lld/COFF/Writer.cpp
===================================================================
--- lld/COFF/Writer.cpp
+++ lld/COFF/Writer.cpp
@@ -799,11 +799,10 @@
   for (ObjFile *File : ObjFile::Instances) {
     if (!File->SEHCompat)
       return;
-    for (Symbol *B : File->SEHandlers) {
-      // Make sure the handler is still live.
-      if (B->isLive())
-        Handlers.insert(cast<Defined>(B));
-    }
+    for (ulittle32_t I : File->SXData)
+      if (Symbol *B = File->getSymbol(I))
+        if (B->isLive())
+          Handlers.insert(cast<Defined>(B));
   }
 
   if (Handlers.empty())
Index: lld/COFF/InputFiles.h
===================================================================
--- lld/COFF/InputFiles.h
+++ lld/COFF/InputFiles.h
@@ -127,9 +127,9 @@
   // COFF-specific and x86-only.
   bool SEHCompat = false;
 
-  // The list of safe exception handlers listed in .sxdata section.
+  // The symbol table indexes of the safe exception handlers.
   // COFF-specific and x86-only.
-  std::set<Symbol *> SEHandlers;
+  ArrayRef<llvm::support::ulittle32_t> SXData;
 
   // Pointer to the PDB module descriptor builder. Various debug info records
   // will reference object files by "module index", which is here. Things like
@@ -140,7 +140,6 @@
 private:
   void initializeChunks();
   void initializeSymbols();
-  void initializeSEH();
 
   SectionChunk *
   readSection(uint32_t SectionNumber,
@@ -158,7 +157,6 @@
   Symbol *createUndefined(COFFSymbolRef Sym);
 
   std::unique_ptr<COFFObjectFile> COFFObj;
-  const coff_section *SXData = nullptr;
 
   // List of all chunks defined by this file. This includes both section
   // chunks and non-section chunks for common symbols.
Index: lld/COFF/InputFiles.cpp
===================================================================
--- lld/COFF/InputFiles.cpp
+++ lld/COFF/InputFiles.cpp
@@ -116,7 +116,6 @@
   // Read section and symbol tables.
   initializeChunks();
   initializeSymbols();
-  initializeSEH();
 }
 
 // We set SectionChunk pointers in the SparseChunks vector to this value
@@ -153,7 +152,12 @@
     fatal("getSectionName failed: #" + Twine(SectionNumber) + ": " +
           EC.message());
   if (Name == ".sxdata") {
-    SXData = Sec;
+    ArrayRef<uint8_t> Data;
+    COFFObj->getSectionContents(Sec, Data);
+    if (Data.size() % 4 != 0)
+      fatal(".sxdata must be an array of symbol table indices");
+    SXData = {reinterpret_cast<const ulittle32_t *>(Data.data()),
+              Data.size() / 4};
     return nullptr;
   }
   if (Name == ".drectve") {
@@ -370,20 +374,6 @@
   return createRegular(Sym);
 }
 
-void ObjFile::initializeSEH() {
-  if (!SEHCompat || !SXData)
-    return;
-  ArrayRef<uint8_t> A;
-  COFFObj->getSectionContents(SXData, A);
-  if (A.size() % 4 != 0)
-    fatal(".sxdata must be an array of symbol table indices");
-  auto *I = reinterpret_cast<const ulittle32_t *>(A.data());
-  auto *E = reinterpret_cast<const ulittle32_t *>(A.data() + A.size());
-  for (; I != E; ++I)
-    if (Symbols[*I])
-      SEHandlers.insert(Symbols[*I]);
-}
-
 MachineTypes ObjFile::getMachineType() {
   if (COFFObj)
     return static_cast<MachineTypes>(COFFObj->getMachine());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40581.124640.patch
Type: text/x-patch
Size: 3184 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171128/cddd0dcd/attachment.bin>


More information about the llvm-commits mailing list