From 24ca79c776340e9d03fc2f24e7acedba97634eb2 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 28 Nov 2017 22:50:53 +0000 Subject: [PATCH] COFF: Simplify construction of safe SEH table. NFCI. Instead of building intermediate sets of exception handlers for each object file, just create one for the final output file. Differential Revision: https://reviews.llvm.org/D40581 llvm-svn: 319244 --- lld/COFF/InputFiles.cpp | 22 ++++++---------------- lld/COFF/InputFiles.h | 6 ++---- lld/COFF/Writer.cpp | 9 ++++----- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp index 75beb746f30d..aa444ec44cb0 100644 --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -116,7 +116,6 @@ void ObjFile::parse() { // Read section and symbol tables. initializeChunks(); initializeSymbols(); - initializeSEH(); } // We set SectionChunk pointers in the SparseChunks vector to this value @@ -153,7 +152,12 @@ SectionChunk *ObjFile::readSection(uint32_t SectionNumber, fatal("getSectionName failed: #" + Twine(SectionNumber) + ": " + EC.message()); if (Name == ".sxdata") { - SXData = Sec; + ArrayRef Data; + COFFObj->getSectionContents(Sec, Data); + if (Data.size() % 4 != 0) + fatal(".sxdata must be an array of symbol table indices"); + SXData = {reinterpret_cast(Data.data()), + Data.size() / 4}; return nullptr; } if (Name == ".drectve") { @@ -370,20 +374,6 @@ Optional ObjFile::createDefined( return createRegular(Sym); } -void ObjFile::initializeSEH() { - if (!SEHCompat || !SXData) - return; - ArrayRef A; - COFFObj->getSectionContents(SXData, A); - if (A.size() % 4 != 0) - fatal(".sxdata must be an array of symbol table indices"); - auto *I = reinterpret_cast(A.data()); - auto *E = reinterpret_cast(A.data() + A.size()); - for (; I != E; ++I) - if (Symbols[*I]) - SEHandlers.insert(Symbols[*I]); -} - MachineTypes ObjFile::getMachineType() { if (COFFObj) return static_cast(COFFObj->getMachine()); diff --git a/lld/COFF/InputFiles.h b/lld/COFF/InputFiles.h index e4dee4c54ebb..10b0502e80b8 100644 --- a/lld/COFF/InputFiles.h +++ b/lld/COFF/InputFiles.h @@ -127,9 +127,9 @@ public: // 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 SEHandlers; + ArrayRef 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 @@ public: private: void initializeChunks(); void initializeSymbols(); - void initializeSEH(); SectionChunk * readSection(uint32_t SectionNumber, @@ -158,7 +157,6 @@ private: Symbol *createUndefined(COFFSymbolRef Sym); std::unique_ptr 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. diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index a676ed993aa2..1231cd48a5e5 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -799,11 +799,10 @@ void Writer::createSEHTable(OutputSection *RData) { 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(B)); - } + for (uint32_t I : File->SXData) + if (Symbol *B = File->getSymbol(I)) + if (B->isLive()) + Handlers.insert(cast(B)); } if (Handlers.empty())