diff options
| author | George Rimar <grimar@accesssoftek.com> | 2016-01-02 16:55:01 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2016-01-02 16:55:01 +0000 |
| commit | 147747ab0bbd90dc6c6928da393ff4ebdd5701c6 (patch) | |
| tree | 2e8ca1fed55bcc20d4e98e58c7e67299eb0f1d1f | |
| parent | d425dd13ad8d82802e40d5a05be15f7f847d45cf (diff) | |
| download | bcm5719-llvm-147747ab0bbd90dc6c6928da393ff4ebdd5701c6.tar.gz bcm5719-llvm-147747ab0bbd90dc6c6928da393ff4ebdd5701c6.zip | |
Revert or r256638. I`ve lost a little piece of code when resolved conflicts right before commit. Sorry about that.
Test did not catch this either, so I`ll improve it and recommit later.
Original commit message:
[ELF] - Optimize .eh_frame section: remove CIE if all FDEs referencing it were removed.
This patch performs little optimization for eh_frame section.
If all FDE`s that referenced CIE are removed then CIE is also removed from output.
That can happen for example when dropping FDEs that point to dropped sections. Testcase showing that is included.
The same optimization was added to ld about 14 years ago: https://sourceware.org/ml/binutils/2001-12/msg00144.html, gold does not do that it seems.
Differential revision: http://reviews.llvm.org/D15564
llvm-svn: 256693
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 20 | ||||
| -rw-r--r-- | lld/test/ELF/eh-frame-opt.s | 39 |
2 files changed, 8 insertions, 51 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 6d2605ab5cc..8bdc2b0e5c4 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -947,8 +947,7 @@ void EHOutputSection<ELFT>::addSectionAux( auto RelI = Rels.begin(); auto RelE = Rels.end(); - // Maps offset to Index/Length pair. - DenseMap<unsigned, std::pair<unsigned, uint32_t>> OffsetToData; + DenseMap<unsigned, unsigned> OffsetToIndex; while (!D.empty()) { unsigned Index = S->Offsets.size(); S->Offsets.push_back(std::make_pair(Offset, -1)); @@ -975,24 +974,21 @@ void EHOutputSection<ELFT>::addSectionAux( std::pair<StringRef, StringRef> CieInfo(Entry, Personality); auto P = CieMap.insert(std::make_pair(CieInfo, Cies.size())); - if (P.second) + if (P.second) { Cies.push_back(C); - OffsetToData[Offset] = std::make_pair(P.first->second, Length); + this->Header.sh_size += RoundUpToAlignment(Length, sizeof(uintX_t)); + } + OffsetToIndex[Offset] = P.first->second; } else { if (!HasReloc) error("FDE doesn't reference another section"); InputSectionBase<ELFT> *Target = S->getRelocTarget(*RelI); if (Target != &InputSection<ELFT>::Discarded && Target->isLive()) { uint32_t CieOffset = Offset + 4 - ID; - auto I = OffsetToData.find(CieOffset); - if (I == OffsetToData.end()) + auto I = OffsetToIndex.find(CieOffset); + if (I == OffsetToIndex.end()) error("Invalid CIE reference"); - std::pair<unsigned, uint32_t> &IndLen = I->second; - Cie<ELFT> &Cie = Cies[IndLen.first]; - if (Cie.Fdes.empty()) - this->Header.sh_size += - RoundUpToAlignment(IndLen.second, sizeof(uintX_t)); - Cie.Fdes.push_back(EHRegion<ELFT>(S, Index)); + Cies[I->second].Fdes.push_back(EHRegion<ELFT>(S, Index)); this->Header.sh_size += RoundUpToAlignment(Length, sizeof(uintX_t)); } } diff --git a/lld/test/ELF/eh-frame-opt.s b/lld/test/ELF/eh-frame-opt.s deleted file mode 100644 index 25ad99a07c4..00000000000 --- a/lld/test/ELF/eh-frame-opt.s +++ /dev/null @@ -1,39 +0,0 @@ -// REQUIRES: x86 -// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o -// RUN: ld.lld --gc-sections %t.o -o %t -// RUN: llvm-readobj -s -section-data %t | FileCheck %s - -// Here we check that if all FDEs referencing a CIE -// were removed, CIE is also removed. -// CHECK: Section { -// CHECK: Index: -// CHECK: Name: .eh_frame -// CHECK-NEXT: Type: SHT_X86_64_UNWIND -// CHECK-NEXT: Flags [ -// CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: ] -// CHECK-NEXT: Address: 0x10120 -// CHECK-NEXT: Offset: 0x120 -// CHECK-NEXT: Size: 0 -// CHECK-NEXT: Link: 0 -// CHECK-NEXT: Info: 0 -// CHECK-NEXT: AddressAlignment: 8 -// CHECK-NEXT: EntrySize: 0 -// CHECK-NEXT: SectionData ( -// CHECK-NEXT: ) -// CHECK-NEXT: } - -.section foo,"ax",@progbits -.cfi_startproc - nop -.cfi_endproc - -.section bar,"ax",@progbits -.cfi_startproc - nop - nop -.cfi_endproc - -.text -.globl _start; -_start: |

