<p dir="ltr">How hard would it be to discard that part of the .eh_frame? Or at least not include it in the index (reduce fde_count).</p>
<p dir="ltr">If I understand it correctly with this patch we create an empty range in the binary search table, which is a bit odd.</p>
<div class="gmail_quote">On Apr 8, 2016 18:03, "Peter Collingbourne" <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">pcc created this revision.<br>
pcc added reviewers: ruiu, rafael.<br>
pcc added a subscriber: llvm-commits.<br>
<br>
It is possible to have FDEs with duplicate PCs if ICF was able to merge<br>
functions with FDEs, or if the input files for some reason contained duplicate<br>
FDEs.  We previously weren't handling this correctly when producing the<br>
contents of the .eh_frame_hdr section; we were dropping entries and leaving<br>
null entries at the end of the section, which confused consumers of unwind<br>
data, such as the backtrace() function.<br>
<br>
Fix the bug by collecting the FDEs into a std::multimap rather than a std::map.<br>
<br>
<a href="http://reviews.llvm.org/D18911" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18911</a><br>
<br>
Files:<br>
  ELF/OutputSections.cpp<br>
  test/ELF/eh-frame-hdr-icf.s<br>
<br>
Index: test/ELF/eh-frame-hdr-icf.s<br>
===================================================================<br>
--- /dev/null<br>
+++ test/ELF/eh-frame-hdr-icf.s<br>
@@ -0,0 +1,26 @@<br>
+# REQUIRES: x86<br>
+<br>
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
+# RUN: ld.lld %t -o %t2 --icf=all --eh-frame-hdr<br>
+# RUN: llvm-objdump -s %t2 | FileCheck %s<br>
+<br>
+# CHECK: Contents of section .eh_frame_hdr:<br>
+# CHECK-NEXT: 101a0 011b033b b4ffffff 02000000 600e0000<br>
+# CHECK-NEXT: 101b0 d0ffffff 600e0000 e8ffffff<br>
+#                   ^ FDE for f1      ^ FDE for f2<br>
+<br>
+.globl _start, f1, f2<br>
+_start:<br>
+  ret<br>
+<br>
+.section .text.f1, "ax"<br>
+f1:<br>
+  .cfi_startproc<br>
+  ret<br>
+  .cfi_endproc<br>
+<br>
+.section .text.f2, "ax"<br>
+f2:<br>
+  .cfi_startproc<br>
+  ret<br>
+  .cfi_endproc<br>
Index: ELF/OutputSections.cpp<br>
===================================================================<br>
--- ELF/OutputSections.cpp<br>
+++ ELF/OutputSections.cpp<br>
@@ -746,11 +746,13 @@<br>
   Buf += 12;<br>
<br>
   // InitialPC -> Offset in .eh_frame, sorted by InitialPC.<br>
-  std::map<uintX_t, size_t> PcToOffset;<br>
+  // We use a multimap in order to handle duplicate PCs, which can happen if ICF<br>
+  // was able to merge functions with FDEs.<br>
+  std::multimap<uintX_t, size_t> PcToOffsets;<br>
   for (const FdeData &F : FdeList)<br>
-    PcToOffset[getFdePc(EhVA, F)] = F.Off;<br>
+    PcToOffsets.insert({getFdePc(EhVA, F), F.Off});<br>
<br>
-  for (auto &I : PcToOffset) {<br>
+  for (auto &I : PcToOffsets) {<br>
     // The first four bytes are an offset to the initial PC value for the FDE.<br>
     write32<E>(Buf, I.first - VA);<br>
     // The last four bytes are an offset to the FDE data itself.<br>
<br>
<br>
</blockquote></div>