<p dir="ltr">Lgtm.</p>
<div class="gmail_quote">On Apr 9, 2016 15:25, "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 updated this revision to Diff 53146.<br>
pcc added a comment.<br>
<br>
Set FDE count in .eh_frame_hdr correctly instead<br>
<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,27 @@<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 01000000 600e0000<br>
+#                                     ^ FDE count<br>
+# CHECK-NEXT: 101b0 e8ffffff 00000000 00000000<br>
+#                   ^ 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>
@@ -733,23 +733,25 @@<br>
 template <class ELFT> void EhFrameHeader<ELFT>::writeTo(uint8_t *Buf) {<br>
   const endianness E = ELFT::TargetEndianness;<br>
<br>
+  uintX_t EhVA = Sec->getVA();<br>
+  uintX_t VA = this->getVA();<br>
+<br>
+  // InitialPC -> Offset in .eh_frame, sorted by InitialPC, and deduplicate PCs.<br>
+  // FIXME: Deduplication leaves unneeded null bytes at the end of the section.<br>
+  std::map<uintX_t, size_t> PcToOffset;<br>
+  for (const FdeData &F : FdeList)<br>
+    PcToOffset[getFdePc(EhVA, F)] = F.Off;<br>
+<br>
   const uint8_t Header[] = {1, DW_EH_PE_pcrel | DW_EH_PE_sdata4,<br>
                             DW_EH_PE_udata4,<br>
                             DW_EH_PE_datarel | DW_EH_PE_sdata4};<br>
   memcpy(Buf, Header, sizeof(Header));<br>
<br>
-  uintX_t EhVA = Sec->getVA();<br>
-  uintX_t VA = this->getVA();<br>
   uintX_t EhOff = EhVA - VA - 4;<br>
   write32<E>(Buf + 4, EhOff);<br>
-  write32<E>(Buf + 8, this->FdeList.size());<br>
+  write32<E>(Buf + 8, PcToOffset.size());<br>
   Buf += 12;<br>
<br>
-  // InitialPC -> Offset in .eh_frame, sorted by InitialPC.<br>
-  std::map<uintX_t, size_t> PcToOffset;<br>
-  for (const FdeData &F : FdeList)<br>
-    PcToOffset[getFdePc(EhVA, F)] = F.Off;<br>
-<br>
   for (auto &I : PcToOffset) {<br>
     // The first four bytes are an offset to the initial PC value for the FDE.<br>
     write32<E>(Buf, I.first - VA);<br>
<br>
<br>
</blockquote></div>