[lld] [lld-macho] Include ICF safe thunks in balanced partitioning (PR #212096)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 31 09:36:05 PDT 2026


================
@@ -0,0 +1,72 @@
+# REQUIRES: aarch64
+
+# RUN: rm -rf %t && split-file %s %t
+# RUN: llvm-mc -filetype=obj -triple=arm64-apple-darwin %t/input.s -o %t/input.o
+# RUN: llvm-profdata merge %t/profile.proftext -o %t/profile.profdata
+
+## The temporal profile names _hot_b, whose input section becomes a
+## linker-created ICF thunk. Balanced partitioning must order both that thunk
+## and the shared _hot_a body that it immediately branches to. _hot_c folds to
+## another thunk for the same body but is not profiled and must not be promoted.
+# RUN: %lld -arch arm64 -lSystem -e _main -o %t/out %t/input.o --icf=safe_thunks --irpgo-profile=%t/profile.profdata --bp-startup-sort=function --bp-compression-sort=none --verbose-bp-section-orderer 2>&1 | FileCheck %s --check-prefix=VERBOSE
+# VERBOSE: Ordered 2 sections (12 bytes) using balanced partitioning
+# VERBOSE: Functions for startup: 2 (12 bytes)
+
+# RUN: %lld -arch arm64 -lSystem -e _main -o - %t/input.o --icf=safe_thunks --irpgo-profile=%t/profile.profdata --bp-startup-sort=function --bp-compression-sort=none | llvm-nm --numeric-sort --format=just-symbols - | FileCheck %s --check-prefix=ORDER
+# ORDER: _hot_a
+# ORDER-NEXT: _hot_b
+# ORDER-NEXT: _main
+# ORDER-NEXT: _cold
+# ORDER-NEXT: _hot_c
----------------
ellishg wrote:

So my understanding is that when `_hot_a` and `_hot_b` are merged and need a thunk, we end up with a thunk for `_hot_a`, a thunk for `_hot_b`, and a body function that the two thunks branch to. That means we have three total functions we need to order. What are those symbol names? It seems like one of them might be `_hot_a.icf.thunk.target`

https://github.com/llvm/llvm-project/blob/b232d110b082c597ac518d37624d16aac3f71ab5/lld/MachO/ICF.cpp#L288-L289

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


More information about the llvm-commits mailing list