diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -114,7 +114,8 @@ if (sa->kind() != sb->kind()) return false; if (!isa(sa)) { - assert(isa(sa)); + // ICF runs before Undefineds are reported. + assert(isa(sa) || isa(sa)); return sa == sb; } const auto *da = cast(sa); @@ -275,7 +276,7 @@ } else { hash += defined->value; } - } else if (!isa(sym)) + } else if (!isa(sym)) // ICF runs before Undefined diags. llvm_unreachable("foldIdenticalSections symbol kind"); } } diff --git a/lld/test/MachO/invalid/undefined-symbol.s b/lld/test/MachO/invalid/undefined-symbol.s --- a/lld/test/MachO/invalid/undefined-symbol.s +++ b/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