Update the recorded CIE length when aligning.

We cannot just pad with 0s as that would be a terminator mark.

llvm-svn: 256392
This commit is contained in:
Rafael Espindola 2015-12-24 20:44:06 +00:00
parent 8a39ce8d32
commit 91bd48a33a
2 changed files with 71 additions and 7 deletions

View File

@ -1038,23 +1038,30 @@ void EHOutputSection<ELFT>::addSection(EHInputSection<ELFT> *S) {
return addSectionAux(S, Obj.rels(RelSec));
}
template <class ELFT>
static typename ELFFile<ELFT>::uintX_t writeAlignedCieOrFde(StringRef Data,
uint8_t *Buf) {
typedef typename ELFFile<ELFT>::uintX_t uintX_t;
const endianness E = ELFT::TargetEndianness;
uint64_t Len = RoundUpToAlignment(Data.size(), sizeof(uintX_t));
write32<E>(Buf, Len - 4);
memcpy(Buf + 4, Data.data() + 4, Data.size() - 4);
return Len;
}
template <class ELFT> void EHOutputSection<ELFT>::writeTo(uint8_t *Buf) {
const endianness E = ELFT::TargetEndianness;
size_t Offset = 0;
for (const Cie<ELFT> &C : Cies) {
size_t CieOffset = Offset;
StringRef CieData = C.data();
memcpy(Buf + Offset, CieData.data(), CieData.size());
uintX_t CIELen = writeAlignedCieOrFde<ELFT>(C.data(), Buf + Offset);
C.S->Offsets[C.Index].second = Offset;
Offset += RoundUpToAlignment(CieData.size(), sizeof(uintX_t));
Offset += CIELen;
for (const EHRegion<ELFT> &F : C.Fdes) {
StringRef FdeData = F.data();
uintX_t Len = RoundUpToAlignment(FdeData.size(), sizeof(uintX_t));
write32<E>(Buf + Offset, Len - 4); // Length
uintX_t Len = writeAlignedCieOrFde<ELFT>(F.data(), Buf + Offset);
write32<E>(Buf + Offset + 4, Offset + 4 - CieOffset); // Pointer
memcpy(Buf + Offset + 8, FdeData.data() + 8, FdeData.size() - 8);
F.S->Offsets[F.Index].second = Offset;
Offset += Len;
}

View File

@ -0,0 +1,57 @@
// REQUIRES: x86
.cfi_startproc
.cfi_personality 0x1b, bar
.cfi_endproc
.global bar
.hidden bar
bar:
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: llvm-readobj -s -section-data %t.o | FileCheck --check-prefix=OBJ %s
// Check the size of the CIE (0x18 + 4) an FDE (0x10 + 4)
// OBJ: Name: .eh_frame
// OBJ-NEXT: Type:
// OBJ-NEXT: Flags [
// OBJ-NEXT: SHF_ALLOC
// OBJ-NEXT: ]
// OBJ-NEXT: Address:
// OBJ-NEXT: Offset:
// OBJ-NEXT: Size:
// OBJ-NEXT: Link:
// OBJ-NEXT: Info:
// OBJ-NEXT: AddressAlignment:
// OBJ-NEXT: EntrySize:
// OBJ-NEXT: SectionData (
// OBJ-NEXT: 0000: 18000000 00000000 017A5052 00017810
// OBJ-NEXT: 0010: 061B0000 00001B0C 07089001 10000000
// OBJ-NEXT: 0020: 20000000 00000000 00000000 00000000
// OBJ-NEXT: )
// RUN: ld.lld %t.o -o %t -shared
// RUN: llvm-readobj -s -section-data %t | FileCheck %s
// Check that the size of the CIE was changed to (0x1C + 4) and the FDE one was
// changed to (0x14 + 4)
// CHECK: Name: .eh_frame
// CHECK-NEXT: Type:
// CHECK-NEXT: Flags
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size:
// CHECK-NEXT: Link:
// CHECK-NEXT: Info:
// CHECK-NEXT: AddressAlignment:
// CHECK-NEXT: EntrySize:
// CHECK-NEXT: SectionData (
// CHECK-NEXT: 0000: 1C000000 00000000 017A5052 00017810
// CHECK-NEXT: 0010: 061B260E 00001B0C 07089001 00000000
// CHECK-NEXT: 0020: 14000000 24000000 100E0000 00000000
// CHECK-NEXT: 0030: 00000000 00000000
// CHECK-NEXT: )