[PATCH] D37739: [ELF] - ICF: handle SHF_LINK_ORDER sections properly.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 06:07:28 PDT 2017


grimar created this revision.
Herald added subscribers: kristof.beyls, emaste, aemerson.

ICF code currently handles SHF_LINK_ORDER section only for ARM.
Though it is possible (and testcase shows that) to use them in
other targets.

Testcase provided would crash before such change. Patch
adds verbose reporting when removing of SHF_LINK_ORDER sections
and also makes logic to work for all targets instead of only ARM.


https://reviews.llvm.org/D37739

Files:
  ELF/ICF.cpp
  test/ELF/icf-link-order.s


Index: test/ELF/icf-link-order.s
===================================================================
--- test/ELF/icf-link-order.s
+++ test/ELF/icf-link-order.s
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: ld.lld %t -o %t2 --icf=all --verbose | FileCheck %s
+# CHECK: selected .text.foo
+# CHECK:   removed .text.bar
+# CHECK:   removed .order_bar
+
+.section .text.foo, "ax"
+nop
+
+.section .text.bar, "ax"
+nop
+
+.section .order_foo,"ao", at progbits,.text.foo
+
+.section .order_bar,"ao", at progbits,.text.bar
Index: ELF/ICF.cpp
===================================================================
--- ELF/ICF.cpp
+++ ELF/ICF.cpp
@@ -429,14 +429,19 @@
     }
   });
 
-  // Mark ARM Exception Index table sections that refer to folded code
+  // Mark SHF_LINK_ORDER sections that refer to folded code
   // sections as not live. These sections have an implict dependency
   // via the link order dependency.
-  if (Config->EMachine == EM_ARM)
-    for (InputSectionBase *Sec : InputSections)
-      if (auto *S = dyn_cast<InputSection>(Sec))
-        if (S->Flags & SHF_LINK_ORDER)
-          S->Live = S->getLinkOrderDep()->Live;
+  for (InputSectionBase *Sec : InputSections) {
+    auto *S = dyn_cast<InputSection>(Sec);
+    if (!S || !S->Live)
+      continue;
+    InputSection *Dep = S->getLinkOrderDep();
+    if (Dep && !Dep->Live) {
+      log("  removed " + S->Name);
+      S->Live = false;
+    }
+  }
 }
 
 // ICF entry point function.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37739.114811.patch
Type: text/x-patch
Size: 1514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170912/be30f48a/attachment.bin>


More information about the llvm-commits mailing list