[lld] [lld-macho][arm64] Enhance safe ICF with thunk-based deduplication (PR #106573)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 08:34:29 PDT 2024


================
@@ -335,9 +404,20 @@ void ICF::run() {
   forEachClass([&](size_t begin, size_t end) {
     if (end - begin < 2)
       return;
+    bool useSafeThunks = config->icfLevel == ICFLevel::safe_thunks;
+
+    // For ICF level safe_thunks, replace keepUnique function bodies with
+    // thunks. For all other ICF levles, directly merge the functions.
+    if (useSafeThunks)
+      applySafeThunksToRange(begin, end);
+
     ConcatInputSection *beginIsec = icfInputs[begin];
-    for (size_t i = begin + 1; i < end; ++i)
+    for (size_t i = begin + 1; i < end; ++i) {
+      // When using safe_thunks, keepUnique inputs are already handeled above
+      if (useSafeThunks && icfInputs[i]->keepUnique)
----------------
alx32 wrote:

We can't do:
```
if (icfInputs[i]->keepUnique) {
  assert(useSafeThunks);
```
Because `icfInputs[i]->keepUnique` can also happen for `--icf=safe`.

https://github.com/llvm/llvm-project/pull/106573


More information about the llvm-commits mailing list