[lld] bc20bcb - [lld/mac] Crash even less on undefined symbols with --icf=all
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 19 06:23:44 PST 2021
Author: Nico Weber
Date: 2021-11-19T09:23:19-05:00
New Revision: bc20bcb39e02e7b593fe0f50fe47959b635f5e56
URL: https://github.com/llvm/llvm-project/commit/bc20bcb39e02e7b593fe0f50fe47959b635f5e56
DIFF: https://github.com/llvm/llvm-project/commit/bc20bcb39e02e7b593fe0f50fe47959b635f5e56.diff
LOG: [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
Added:
Modified:
lld/MachO/ICF.cpp
lld/test/MachO/invalid/undefined-symbol.s
Removed:
################################################################################
diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp
index 8802f292a9c85..f9dea4b861ac3 100644
--- a/lld/MachO/ICF.cpp
+++ b/lld/MachO/ICF.cpp
@@ -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");
}
}
diff --git a/lld/test/MachO/invalid/undefined-symbol.s b/lld/test/MachO/invalid/undefined-symbol.s
index deb543a31462f..97a300494b277 100644
--- a/lld/test/MachO/invalid/undefined-symbol.s
+++ b/lld/test/MachO/invalid/undefined-symbol.s
@@ -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
More information about the llvm-commits
mailing list