[PATCH] D120137: [lld-macho] Deduplicate CFStrings during ICF

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 18 08:38:26 PST 2022


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`__cfstring` has embedded addends that foil ICF's hashing / equality
checks. (We can ignore embedded addends when doing ICF because the same
information gets recorded in our Reloc structs.) Therefore, in order to
dedup CFStrings, we create a mutable copy of the CFString and zero out
the embedded addends before performing any hashing / equality checks.

I anticipate this approach can be extended to other similar
statically-allocated struct sections in the future.

In addition, we previously treated all references with differing addends
as unequal. This is not true when the references are to literals:
different addends may point to the same literal in the output binary. In
particular, `__cfstring` has such references to `__cstring`. I've
adjusted ICF's `equalsConstant` logic accordingly, and I've added a few
more tests to make sure the addend-comparison code path is adequately
covered.

Fixes https://github.com/llvm/llvm-project/issues/51281.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120137

Files:
  lld/MachO/ICF.cpp
  lld/test/MachO/cfstring-dedup.s
  lld/test/MachO/icf.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120137.409947.patch
Type: text/x-patch
Size: 6346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220218/a29412cd/attachment.bin>


More information about the llvm-commits mailing list