[PATCH] D114195: [lld/mac] Crash even less on undefined symbols with --icf=all

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 18 14:02:24 PST 2021


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added a project: lld-macho.
thakis requested review of this revision.

Follow-up to https://reviews.llvm.org/D112643. Even after that change, we were
still asserting if two separate functions that are eligible for ICF (same size,
same data, same number of relocs, same reloc types, ...) referred to
Undefineds. This fixes that oversight.


https://reviews.llvm.org/D114195

Files:
  lld/MachO/ICF.cpp
  lld/test/MachO/invalid/undefined-symbol.s


Index: lld/test/MachO/invalid/undefined-symbol.s
===================================================================
--- lld/test/MachO/invalid/undefined-symbol.s
+++ lld/test/MachO/invalid/undefined-symbol.s
@@ -20,9 +20,17 @@
   retq
 
 #--- main.s
-.globl _main
 .text
+
+_anotherref:
+  callq _foo
+  movq $0, %rax
+  retq
+
+.globl _main
 _main:
   callq _foo
   movq $0, %rax
   retq
+
+.subsections_via_symbols
Index: lld/MachO/ICF.cpp
===================================================================
--- lld/MachO/ICF.cpp
+++ lld/MachO/ICF.cpp
@@ -114,7 +114,7 @@
       if (sa->kind() != sb->kind())
         return false;
       if (!isa<Defined>(sa)) {
-        assert(isa<DylibSymbol>(sa));
+        assert(isa<DylibSymbol>(sa) || isa<Undefined>(sa));
         return sa == sb;
       }
       const auto *da = cast<Defined>(sa);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114195.388318.patch
Type: text/x-patch
Size: 845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211118/d13cb688/attachment.bin>


More information about the llvm-commits mailing list