Currently, our `safe` ICF mode only merges non-address-significant code, leaving duplicate address-significant functions in the output. This patch introduces `safe_thunks` ICF mode, which keeps a single master copy of each function and replaces address-significant duplicates with thunks that branch to the master copy. Currently `--icf=safe_thunks` is only supported for `arm64` architectures. **Perf stats for a large binary:** | ICF Option | Total Size | __text Size | __unwind_info | % total | |-------------------|------------|-------------|---------------------|---------------------------| | `--icf=none` | 91.738 MB | 55.220 MB | 1.424 MB | 0% | | `--icf=safe` | 85.042 MB | 49.572 MB | 1.168 MB | 7.30% | | `--icf=safe_thunks` | 84.650 MB | 49.219 MB | 1.143 MB | 7.72% | | `--icf=all` | 82.060 MB | 48.726 MB | 1.111 MB | 10.55% | So overall we can expect a `~0.45%` binary size reduction for a typical large binary compared to the `--icf=safe` option. **Runtime:** Linking the above binary took ~10 seconds. Comparing the link performance of --icf=safe_thunks vs --icf=safe, a ~2% slowdown was observed.
10 KiB
10 KiB