auto P = CieMap.insert(std::make_pair(CieInfo, Cies.size()));
if (P.second) {
Cies.push_back(C);
- this->Header.sh_size += Length;
+ this->Header.sh_size += RoundUpToAlignment(Length, sizeof(uintX_t));
}
OffsetToIndex[Offset] = P.first->second;
} else {
if (I == OffsetToIndex.end())
error("Invalid CIE reference");
Cies[I->second].Fdes.push_back(EHRegion<ELFT>(S, Index));
- this->Header.sh_size += Length;
+ this->Header.sh_size += RoundUpToAlignment(Length, sizeof(uintX_t));
}
}
StringRef CieData = C.data();
memcpy(Buf + Offset, CieData.data(), CieData.size());
C.S->Offsets[C.Index].second = Offset;
- Offset += CieData.size();
+ Offset += RoundUpToAlignment(CieData.size(), sizeof(uintX_t));
for (const EHRegion<ELFT> &F : C.Fdes) {
StringRef FdeData = F.data();
- memcpy(Buf + Offset, FdeData.data(), 4); // Length
+ uintX_t Len = RoundUpToAlignment(FdeData.size(), sizeof(uintX_t));
+ write32<E>(Buf + Offset, Len - 4); // Length
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 += FdeData.size();
+ Offset += Len;
}
}
// CHECK-NEXT: ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset:
-// CHECK-NEXT: Size:
+// CHECK-NEXT: Size: 96
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 8
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: SectionData (
-// CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001 |
-// CHECK-NEXT: 0010: 1B0C0708 90010000 10000000 1C000000 |
-// CHECK-NEXT: 0020: 180E0000 01000000 00000000 10000000 |
-// CHECK-NEXT: 0030: 30000000 060E0000 02000000 00000000 |
-// CHECK-NEXT: 0040: 10000000 44000000 F10D0000 01000000 |
-// CHECK-NEXT: 0050: 00000000 |
+// CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001 |
+// CHECK-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000 |
+// CHECK-NEXT: 0020: 180E0000 01000000 00000000 00000000 |
+// CHECK-NEXT: 0030: 14000000 34000000 020E0000 02000000 |
+// CHECK-NEXT: 0040: 00000000 00000000 14000000 4C000000 |
+// CHECK-NEXT: 0050: E90D0000 01000000 00000000 00000000 |
// CHECK-NEXT: )
// CHECK: Name: foo