[lld-macho] Fix ICF crash when comparing symbol relocs
authorJez Ng <jezng@fb.com>
Fri, 22 Apr 2022 19:34:54 +0000 (15:34 -0400)
committerJez Ng <jezng@fb.com>
Fri, 22 Apr 2022 19:36:53 +0000 (15:36 -0400)
commitc242e10c74d28d97a9e7f99f00a06a9a599be402
treeb258f298ec539b22e13eaadf0198ac0d0cd87d47
parente6382d23fcc8138d7dec4b23cb1b7f4e5cb4c335
[lld-macho] Fix ICF crash when comparing symbol relocs

Previously, when encountering a symbol reloc located in a literal section, we
would look up the contents of the literal at the `symbol value + addend` offset
within the literal section. However, it seems that this offset is not guaranteed
to be valid. Instead, we should use just the symbol value to retrieve the
literal's contents, and compare the addend values separately. ld64 seems to do
this.

Reviewed By: #lld-macho, thevinster

Differential Revision: https://reviews.llvm.org/D124223
lld/MachO/ICF.cpp
lld/test/MachO/icf-literals.s