[PATCH] D28935: ELF: Fix ICF crash on absolute symbol relocations.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 19 21:09:15 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL292578: ELF: Fix ICF crash on absolute symbol relocations. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D28935?vs=85094&id=85095#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28935

Files:
  lld/trunk/ELF/ICF.cpp
  lld/trunk/test/ELF/Inputs/icf-absolute.s
  lld/trunk/test/ELF/icf-absolute.s


Index: lld/trunk/test/ELF/Inputs/icf-absolute.s
===================================================================
--- lld/trunk/test/ELF/Inputs/icf-absolute.s
+++ lld/trunk/test/ELF/Inputs/icf-absolute.s
@@ -0,0 +1,3 @@
+.globl a1, a2
+a1 = 1
+a2 = 1
Index: lld/trunk/test/ELF/icf-absolute.s
===================================================================
--- lld/trunk/test/ELF/icf-absolute.s
+++ lld/trunk/test/ELF/icf-absolute.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/icf-absolute.s -o %t2
+# RUN: ld.lld %t %t2 -o %t3 --icf=all --verbose | FileCheck %s
+
+# CHECK: selected .text.f1
+# CHECK:   removed .text.f2
+
+.globl _start, f1, f2
+_start:
+  ret
+
+.section .text.f1, "ax"
+f1:
+  .byte a1
+
+.section .text.f2, "ax"
+f2:
+  .byte a2
Index: lld/trunk/ELF/ICF.cpp
===================================================================
--- lld/trunk/ELF/ICF.cpp
+++ lld/trunk/ELF/ICF.cpp
@@ -245,14 +245,18 @@
     if (&SA == &SB)
       return true;
 
-    // Or, the two sections must be in the same equivalence class.
     auto *DA = dyn_cast<DefinedRegular<ELFT>>(&SA);
     auto *DB = dyn_cast<DefinedRegular<ELFT>>(&SB);
     if (!DA || !DB)
       return false;
     if (DA->Value != DB->Value)
       return false;
 
+    // Either both symbols must be absolute...
+    if (!DA->Section || !DB->Section)
+      return !DA->Section && !DB->Section;
+
+    // Or the two sections must be in the same equivalence class.
     auto *X = dyn_cast<InputSection<ELFT>>(DA->Section);
     auto *Y = dyn_cast<InputSection<ELFT>>(DB->Section);
     if (!X || !Y)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28935.85095.patch
Type: text/x-patch
Size: 1706 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170120/359952b6/attachment.bin>


More information about the llvm-commits mailing list