[lld] r316730 - Make EhFrameHdr pull data from EhFrameSection. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 26 20:13:24 PDT 2017


Author: ruiu
Date: Thu Oct 26 20:13:24 2017
New Revision: 316730

URL: http://llvm.org/viewvc/llvm-project?rev=316730&view=rev
Log:
Make EhFrameHdr pull data from EhFrameSection. NFC.

Previously, EhFrameSection pushes data to EhFrameHdr by calling addFde
function. By making EhFrameHdr pull data from EhFrameSection, we can
eliminate a member from EhFrameHdr.

Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=316730&r1=316729&r2=316730&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Oct 26 20:13:24 2017
@@ -550,6 +550,26 @@ template <class ELFT> void EhFrameSectio
   this->Size = Off;
 }
 
+// Returns data for .eh_frame_hdr. .eh_frame_hdr is a binary search table
+// to get an FDE from an address to which FDE is applied. This function
+// returns a list of such pairs.
+template <class ELFT>
+std::vector<typename EhFrameSection<ELFT>::FdeData>
+EhFrameSection<ELFT>::getFdeData() const {
+  uint8_t *Buf = getParent()->Loc + OutSecOff;
+  std::vector<FdeData> Ret;
+
+  for (CieRecord *Rec : CieRecords) {
+    uint8_t Enc = getFdeEncoding<ELFT>(Rec->Cie);
+    for (EhSectionPiece *Fde : Rec->Fdes) {
+      uint32_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
+      uint32_t FdeVA = getParent()->Addr + Fde->OutputOff;
+      Ret.push_back({Pc, FdeVA});
+    }
+  }
+  return Ret;
+}
+
 static uint64_t readFdeAddr(uint8_t *Buf, int Size) {
   switch (Size) {
   case DW_EH_PE_udata2:
@@ -568,7 +588,7 @@ static uint64_t readFdeAddr(uint8_t *Buf
 // We need it to create .eh_frame_hdr section.
 template <class ELFT>
 uint64_t EhFrameSection<ELFT>::getFdePc(uint8_t *Buf, size_t FdeOff,
-                                        uint8_t Enc) {
+                                        uint8_t Enc) const {
   // The starting address to which this FDE applies is
   // stored at FDE + 8 byte.
   size_t Off = FdeOff + 8;
@@ -601,20 +621,6 @@ template <class ELFT> void EhFrameSectio
   // getOffset() takes care of discontiguous section pieces.
   for (EhInputSection *S : Sections)
     S->relocateAlloc(Buf, nullptr);
-
-  // Construct .eh_frame_hdr. .eh_frame_hdr is a binary search table
-  // to get a FDE from an address to which FDE is applied. So here
-  // we obtain two addresses and pass them to EhFrameHdr object.
-  if (In<ELFT>::EhFrameHdr) {
-    for (CieRecord *Rec : CieRecords) {
-      uint8_t Enc = getFdeEncoding<ELFT>(Rec->Cie);
-      for (EhSectionPiece *Fde : Rec->Fdes) {
-        uint64_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
-        uint64_t FdeVA = getParent()->Addr + Fde->OutputOff;
-        In<ELFT>::EhFrameHdr->addFde(Pc, FdeVA);
-      }
-    }
-  }
 }
 
 GotSection::GotSection()
@@ -1966,8 +1972,11 @@ EhFrameHeader<ELFT>::EhFrameHeader()
 // the starting PC from where FDEs covers, and the FDE's address.
 // It is sorted by PC.
 template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) {
+  typedef typename EhFrameSection<ELFT>::FdeData FdeData;
   const endianness E = ELFT::TargetEndianness;
 
+  std::vector<FdeData> Fdes = In<ELFT>::EhFrame->getFdeData();
+
   // Sort the FDE list by their PC and uniqueify. Usually there is only
   // one FDE for a PC (i.e. function), but if ICF merges two functions
   // into one, there can be more than one FDEs pointing to the address.
@@ -1997,11 +2006,6 @@ template <class ELFT> size_t EhFrameHead
   return 12 + In<ELFT>::EhFrame->NumFdes * 8;
 }
 
-template <class ELFT>
-void EhFrameHeader<ELFT>::addFde(uint32_t Pc, uint32_t FdeVA) {
-  Fdes.push_back({Pc, FdeVA});
-}
-
 template <class ELFT> bool EhFrameHeader<ELFT>::empty() const {
   return In<ELFT>::EhFrame->empty();
 }

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=316730&r1=316729&r2=316730&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Thu Oct 26 20:13:24 2017
@@ -76,9 +76,15 @@ public:
 
   void addSection(InputSectionBase *S);
 
+  std::vector<EhInputSection *> Sections;
   size_t NumFdes = 0;
 
-  std::vector<EhInputSection *> Sections;
+  struct FdeData {
+    uint32_t Pc;
+    uint32_t FdeVA;
+  };
+
+  std::vector<FdeData> getFdeData() const;
 
 private:
   uint64_t Size = 0;
@@ -91,7 +97,7 @@ private:
   template <class RelTy>
   bool isFdeLive(EhSectionPiece &Piece, ArrayRef<RelTy> Rels);
 
-  uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc);
+  uint64_t getFdePc(uint8_t *Buf, size_t Off, uint8_t Enc) const;
 
   std::vector<CieRecord *> CieRecords;
 
@@ -574,16 +580,7 @@ public:
   EhFrameHeader();
   void writeTo(uint8_t *Buf) override;
   size_t getSize() const override;
-  void addFde(uint32_t Pc, uint32_t FdeVA);
   bool empty() const override;
-
-private:
-  struct FdeData {
-    uint32_t Pc;
-    uint32_t FdeVA;
-  };
-
-  std::vector<FdeData> Fdes;
 };
 
 // For more information about .gnu.version and .gnu.version_r see:




More information about the llvm-commits mailing list