[lld] r301931 - Avoid empty .eh_frame sections.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 08:45:32 PDT 2017


Author: rafael
Date: Tue May  2 10:45:31 2017
New Revision: 301931

URL: http://llvm.org/viewvc/llvm-project?rev=301931&view=rev
Log:
Avoid empty .eh_frame sections.

Strip on OpenBSD does not correctly handle an empty .eh_frame section
and produces broken binaries in that case. Currently lld creates such
an empty .eh_frame section, despite the fact that the OpenBSD crtend.o
explicitly inserts a terminator. The Linux LSB "standard":

https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html#EHFRAME

explicitly says that

    The .eh_frame section shall contain 1 or more Call Frame Information (CFI) records.

This diff includes a test that specifically tests the issue I'm seeing
on OpenBSD.

Patch by Mark Kettenis!

Added:
    lld/trunk/test/ELF/Inputs/eh-frame-end.s
    lld/trunk/test/ELF/eh-frame-begin-end.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=301931&r1=301930&r2=301931&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue May  2 10:45:31 2017
@@ -541,6 +541,13 @@ template <class ELFT> void EhFrameSectio
       Off += alignTo(Fde->size(), Config->Wordsize);
     }
   }
+
+  // The LSB standard does not allow a .eh_frame section with zero
+  // Call Frame Information records. Therefore add a CIE record length
+  // 0 as a terminator if this .eh_frame section is empty.
+  if (Off == 0)
+    Off = 4;
+
   this->Size = Off;
 }
 

Added: lld/trunk/test/ELF/Inputs/eh-frame-end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/eh-frame-end.s?rev=301931&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/eh-frame-end.s (added)
+++ lld/trunk/test/ELF/Inputs/eh-frame-end.s Tue May  2 10:45:31 2017
@@ -0,0 +1,2 @@
+	.section ".eh_frame", "a", @progbits
+	.long 0

Added: lld/trunk/test/ELF/eh-frame-begin-end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/eh-frame-begin-end.s?rev=301931&view=auto
==============================================================================
--- lld/trunk/test/ELF/eh-frame-begin-end.s (added)
+++ lld/trunk/test/ELF/eh-frame-begin-end.s Tue May  2 10:45:31 2017
@@ -0,0 +1,17 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=amd64-unknown-openbsd %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=amd64-unknown-openbsd %p/Inputs/eh-frame-end.s -o %t2.o
+// RUN: ld.lld %t.o %t2.o -o %t
+// RUN: llvm-readobj -sections %t | FileCheck %s
+
+// CHECK:      Name: .eh_frame
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT:   SHF_ALLOC
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address: 0x200120
+// CHECK-NEXT: Offset: 0x120
+// CHECK-NEXT: Size: 4
+
+	.section ".eh_frame", "a", @progbits
+__EH_FRAME_BEGIN__:




More information about the llvm-commits mailing list