[PATCH] D21687: [ELF] - Remove CIE if all FDEs referencing it were removed (.eh_frame).

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 08:30:49 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

About 7 month ago we had a patch D15564 ("[ELF] - Optimize .eh_frame section: remove 
CIE if all FDEs referencing it were removed."). It was committed but then reverted.
I didn't commit a piece of code and testcase did not catxh this, I wanted to improve it before
recommit.
But nowadays this patch seems to be few lines trivial. And I think it is ok now.

http://reviews.llvm.org/D21687

Files:
  ELF/OutputSections.cpp
  test/ELF/eh-frame-opt.s

Index: test/ELF/eh-frame-opt.s
===================================================================
--- test/ELF/eh-frame-opt.s
+++ test/ELF/eh-frame-opt.s
@@ -0,0 +1,39 @@
+# 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_PROGBITS
+# 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", at progbits
+.cfi_startproc
+ nop
+.cfi_endproc
+
+.section .bar,"ax", at progbits
+.cfi_startproc
+ nop
+ nop
+.cfi_endproc
+
+.text
+.globl _start;
+_start:
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -1112,6 +1112,8 @@
 
   size_t Off = 0;
   for (CieRecord *Cie : Cies) {
+    if (Cie->FdePieces.empty())
+      continue;
     Cie->Piece->OutputOff = Off;
     Off += alignTo(Cie->Piece->size(), sizeof(uintX_t));
 
@@ -1159,6 +1161,8 @@
 template <class ELFT> void EhOutputSection<ELFT>::writeTo(uint8_t *Buf) {
   const endianness E = ELFT::TargetEndianness;
   for (CieRecord *Cie : Cies) {
+    if (Cie->FdePieces.empty())
+      continue;
     size_t CieOffset = Cie->Piece->OutputOff;
     writeCieFde<ELFT>(Buf + CieOffset, Cie->Piece->data());
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21687.61797.patch
Type: text/x-patch
Size: 1795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160624/7c260d48/attachment.bin>


More information about the llvm-commits mailing list