Index: tools/lld/ELF/OutputSections.cpp =================================================================== --- tools/lld/ELF/OutputSections.cpp +++ tools/lld/ELF/OutputSections.cpp @@ -410,7 +410,14 @@ Off += alignTo(Fde->size(), sizeof(uintX_t)); } } - this->Size = Off; + + // Add a CIE record of length 0 as a terminator. While the relevant + // standards don't explicitly require such a terminator, ld.bfd and + // ld.gold always seem to add one and some unwiders rely on its + // presence. It also prevents us from generating a .eh_frame section + // with zero Call Frame Information records, which isn't allowed by + // the LSB standard. + this->Size = Off + 4; } template static uint64_t readFdeAddr(uint8_t *Buf, int Size) { Index: tools/lld/test/ELF/eh-frame-hdr.s =================================================================== --- tools/lld/test/ELF/eh-frame-hdr.s +++ tools/lld/test/ELF/eh-frame-hdr.s @@ -84,7 +84,7 @@ // HDR-NEXT: ] // HDR-NEXT: Address: 0x200180 // HDR-NEXT: Offset: 0x180 -// HDR-NEXT: Size: 96 +// HDR-NEXT: Size: 100 // HDR-NEXT: Link: 0 // HDR-NEXT: Info: 0 // HDR-NEXT: AddressAlignment: 8 @@ -96,6 +96,7 @@ // HDR-NEXT: 0030: 14000000 34000000 490E0000 01000000 // HDR-NEXT: 0040: 00000000 00000000 14000000 4C000000 // HDR-NEXT: 0050: 320E0000 01000000 00000000 00000000 +// HDR-NEXT: 0060: 00000000 // HDR-NEXT: ) // CIE: 14000000 00000000 017A5200 01781001 1B0C0708 90010000 // FDE(1): 14000000 1C000000 600E0000 01000000 00000000 00000000 Index: tools/lld/test/ELF/eh-frame-merge.s =================================================================== --- tools/lld/test/ELF/eh-frame-merge.s +++ tools/lld/test/ELF/eh-frame-merge.s @@ -27,7 +27,7 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: // CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 96 +// CHECK-NEXT: Size: 100 // CHECK-NEXT: Link: 0 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 8 @@ -39,6 +39,7 @@ // CHECK-NEXT: 0030: 14000000 34000000 D20D0000 02000000 | // CHECK-NEXT: 0040: 00000000 00000000 14000000 4C000000 | // CHECK-NEXT: 0050: B90D0000 01000000 00000000 00000000 | +// CHECK-NEXT: 0060: 00000000 | // CHECK-NEXT: ) // CHECK: Name: foo Index: tools/lld/test/ELF/ehframe-relocation.s =================================================================== --- tools/lld/test/ELF/ehframe-relocation.s +++ tools/lld/test/ELF/ehframe-relocation.s @@ -12,7 +12,7 @@ // CHECK-NEXT: ] // CHECK-NEXT: Address: 0x200120 // CHECK-NEXT: Offset: -// CHECK-NEXT: Size: 48 +// CHECK-NEXT: Size: 52 // CHECK-NOT: .eh_frame // 0x200120 = 2097440 Index: tools/lld/test/ELF/invalid-fde-rel.s =================================================================== --- tools/lld/test/ELF/invalid-fde-rel.s +++ tools/lld/test/ELF/invalid-fde-rel.s @@ -33,4 +33,4 @@ .long 0x0 .long 0x0 -// CHECK: 1 .eh_frame 00000018 +// CHECK: 1 .eh_frame 0000001c Index: tools/lld/test/ELF/linkerscript/eh-frame-hdr.s =================================================================== --- tools/lld/test/ELF/linkerscript/eh-frame-hdr.s +++ tools/lld/test/ELF/linkerscript/eh-frame-hdr.s @@ -7,7 +7,7 @@ # RUN: ld.lld -o %t1 --eh-frame-hdr --script %t.script %t # RUN: llvm-objdump -s -section=".eh_frame_hdr" %t1 | FileCheck %s -# CHECK: 011b033b 14000000 01000000 49000000 +# CHECK: 011b033b 14000000 01000000 4d000000 # CHECK-NEXT: 30000000 .global _start Index: tools/lld/test/ELF/linkerscript/symbols-synthetic.s =================================================================== --- tools/lld/test/ELF/linkerscript/symbols-synthetic.s +++ tools/lld/test/ELF/linkerscript/symbols-synthetic.s @@ -60,7 +60,7 @@ # SIMPLE: 0000000000000128 .foo 00000000 .hidden _end_sec # SIMPLE-NEXT: 0000000000000120 .foo 00000000 _begin_sec # SIMPLE-NEXT: 0000000000000128 *ABS* 00000000 _end_sec_abs -# SIMPLE-NEXT: 0000000000001048 .text 00000000 _start +# SIMPLE-NEXT: 000000000000104c .text 00000000 _start # SIMPLE-NEXT: 0000000000000120 .foo 00000000 begin_foo # SIMPLE-NEXT: 0000000000000128 .foo 00000000 end_foo # SIMPLE-NEXT: 0000000000000008 *ABS* 00000000 size_foo_1 Index: tools/lld/test/ELF/map-file.s =================================================================== --- tools/lld/test/ELF/map-file.s +++ tools/lld/test/ELF/map-file.s @@ -27,7 +27,7 @@ .comm common,4,16 // CHECK: Address Size Align Out In File Symbol -// CHECK-NEXT: 0000000000200158 0000000000000030 8 .eh_frame +// CHECK-NEXT: 0000000000200158 0000000000000034 8 .eh_frame // CHECK-NEXT: 0000000000201000 0000000000000015 4 .text // CHECK-NEXT: 0000000000201000 000000000000000e 4 .text // CHECK-NEXT: 0000000000201000 000000000000000e 4 {{.*}}{{/|\\}}map-file.s.tmp1.o Index: tools/lld/test/ELF/relocatable-eh-frame.s =================================================================== --- tools/lld/test/ELF/relocatable-eh-frame.s +++ tools/lld/test/ELF/relocatable-eh-frame.s @@ -5,7 +5,7 @@ # RUN: ld.lld %t -o %t.so -shared # RUN: llvm-objdump -h %t.so | FileCheck --check-prefix=DSO %s -# DSO: .eh_frame 00000030 +# DSO: .eh_frame 00000034 # CHECK: Relocations [ # CHECK-NEXT: Section ({{.*}}) .rela.eh_frame {