summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/OutputSections.cpp22
-rw-r--r--lld/ELF/OutputSections.h6
2 files changed, 10 insertions, 18 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 29afbf3d8ae..3d6a8c86ae5 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -713,12 +713,7 @@ template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
template <class ELFT>
EhFrameHeader<ELFT>::EhFrameHeader()
- : OutputSectionBase<ELFT>(".eh_frame_hdr", llvm::ELF::SHT_PROGBITS,
- SHF_ALLOC) {
- // It's a 4 bytes of header + pointer to the contents of the .eh_frame section
- // + the number of FDE pointers in the table.
- this->Header.sh_size = 12;
-}
+ : OutputSectionBase<ELFT>(".eh_frame_hdr", SHT_PROGBITS, SHF_ALLOC) {}
// .eh_frame_hdr contains a binary search table of pointers to FDEs.
// Each entry of the search table consists of two values,
@@ -751,18 +746,16 @@ template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) {
}
}
+template <class ELFT> void EhFrameHeader<ELFT>::finalize() {
+ // .eh_frame_hdr has a 12 bytes header followed by an array of FDEs.
+ this->Header.sh_size = 12 + Out<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> void EhFrameHeader<ELFT>::reserveFde() {
- // Each FDE entry is 8 bytes long:
- // The first four bytes are an offset to the initial PC value for the FDE. The
- // last four byte are an offset to the FDE data itself.
- this->Header.sh_size += 8;
-}
-
template <class ELFT>
OutputSection<ELFT>::OutputSection(StringRef Name, uint32_t Type, uintX_t Flags)
: OutputSectionBase<ELFT>(Name, Type, Flags) {
@@ -1108,8 +1101,7 @@ void EhOutputSection<ELFT>::addSectionAux(EHInputSection<ELFT> *Sec,
if (!isFdeLive(FdePiece, Sec, Rels))
continue;
Cie->FdePieces.push_back(&FdePiece);
- if (Out<ELFT>::EhFrameHdr)
- Out<ELFT>::EhFrameHdr->reserveFde();
+ NumFdes++;
}
}
diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h
index 8deba71ff1d..5cb18234d6b 100644
--- a/lld/ELF/OutputSections.h
+++ b/lld/ELF/OutputSections.h
@@ -349,6 +349,8 @@ public:
void addSection(InputSectionBase<ELFT> *S) override;
+ size_t NumFdes = 0;
+
private:
template <class RelTy>
void addSectionAux(EHInputSection<ELFT> *S, llvm::ArrayRef<RelTy> Rels);
@@ -538,11 +540,9 @@ class EhFrameHeader final : public OutputSectionBase<ELFT> {
public:
EhFrameHeader();
+ void finalize() override;
void writeTo(uint8_t *Buf) override;
-
void addFde(uint32_t Pc, uint32_t FdeVA);
- void add(EhOutputSection<ELFT> *Sec);
- void reserveFde();
private:
struct FdeData {
OpenPOWER on IntegriCloud