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

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.

Differential Revision: https://reviews.llvm.org/D114195
This commit is contained in:
Nico Weber 2021-11-18 16:59:21 -05:00
parent 4f9a5c2a14
commit bc20bcb39e
2 changed files with 12 additions and 3 deletions

View File

@ -114,7 +114,8 @@ static bool equalsConstant(const ConcatInputSection *ia,
if (sa->kind() != sb->kind())
return false;
if (!isa<Defined>(sa)) {
assert(isa<DylibSymbol>(sa));
// ICF runs before Undefineds are reported.
assert(isa<DylibSymbol>(sa) || isa<Undefined>(sa));
return sa == sb;
}
const auto *da = cast<Defined>(sa);
@ -275,7 +276,7 @@ void ICF::run() {
} else {
hash += defined->value;
}
} else if (!isa<Undefined>(sym))
} else if (!isa<Undefined>(sym)) // ICF runs before Undefined diags.
llvm_unreachable("foldIdenticalSections symbol kind");
}
}

View File

@ -20,9 +20,17 @@ _foo:
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