summaryrefslogtreecommitdiffstats
path: root/lld/ELF/OutputSections.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2016-04-11 16:40:08 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2016-04-11 16:40:08 +0000
commitc98de13871b3376ba7c25dd33ca49a9712e6542b (patch)
treea7ef1a02ee8161e843e74ec36bf47aa03cbf0f4c /lld/ELF/OutputSections.cpp
parent7cf73ec4c76e426b711326f51df811f640c75c33 (diff)
downloadbcm5719-llvm-c98de13871b3376ba7c25dd33ca49a9712e6542b.tar.gz
bcm5719-llvm-c98de13871b3376ba7c25dd33ca49a9712e6542b.zip
ELF: Set FDE count in .eh_frame_hdr correctly.
It is possible to have FDEs with duplicate PCs if ICF was able to merge functions with FDEs, or if the input files for some reason contained duplicate FDEs. We previously weren't handling this correctly when producing the contents of the .eh_frame_hdr section; we were dropping entries and leaving null entries at the end of the section, which confused consumers of unwind data, such as the backtrace() function. Fix the bug by setting the FDE count to the number of FDEs actually emitted into .eh_frame_hdr, rather than the number of FDEs in .eh_frame. Differential Revision: http://reviews.llvm.org/D18911 llvm-svn: 265957
Diffstat (limited to 'lld/ELF/OutputSections.cpp')
-rw-r--r--lld/ELF/OutputSections.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 753960447fa..89a9df0c44b 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -727,23 +727,25 @@ EhFrameHeader<ELFT>::getFdePc(uintX_t EhVA, const FdeData &F) {
template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) {
const endianness E = ELFT::TargetEndianness;
+ uintX_t EhVA = Sec->getVA();
+ uintX_t VA = this->getVA();
+
+ // InitialPC -> Offset in .eh_frame, sorted by InitialPC, and deduplicate PCs.
+ // FIXME: Deduplication leaves unneeded null bytes at the end of the section.
+ std::map<uintX_t, size_t> PcToOffset;
+ for (const FdeData &F : FdeList)
+ PcToOffset[getFdePc(EhVA, F)] = F.Off;
+
const uint8_t Header[] = {1, DW_EH_PE_pcrel | DW_EH_PE_sdata4,
DW_EH_PE_udata4,
DW_EH_PE_datarel | DW_EH_PE_sdata4};
memcpy(Buf, Header, sizeof(Header));
- uintX_t EhVA = Sec->getVA();
- uintX_t VA = this->getVA();
uintX_t EhOff = EhVA - VA - 4;
write32<E>(Buf + 4, EhOff);
- write32<E>(Buf + 8, this->FdeList.size());
+ write32<E>(Buf + 8, PcToOffset.size());
Buf += 12;
- // InitialPC -> Offset in .eh_frame, sorted by InitialPC.
- std::map<uintX_t, size_t> PcToOffset;
- for (const FdeData &F : FdeList)
- PcToOffset[getFdePc(EhVA, F)] = F.Off;
-
for (auto &I : PcToOffset) {
// The first four bytes are an offset to the initial PC value for the FDE.
write32<E>(Buf, I.first - VA);
OpenPOWER on IntegriCloud