[lld] [lld][MachO] Add N_COLD_FUNC support (PR #183909)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 18:59:08 PST 2026


================
@@ -1007,13 +1007,23 @@ static void sortSegmentsAndSections() {
         osec->align = tlvAlign;
       }
 
-      if (!isecPriorities.empty()) {
-        if (auto *merged = dyn_cast<ConcatOutputSection>(osec)) {
-          llvm::stable_sort(
-              merged->inputs, [&](InputSection *a, InputSection *b) {
-                return isecPriorities.lookup(a) < isecPriorities.lookup(b);
-              });
-        }
+      if (auto *merged = dyn_cast<ConcatOutputSection>(osec)) {
----------------
nocchijiang wrote:

Apple's ld64 performs parallelized sorting across most sections, whereas ld64.lld currently handles these sequentially, only sorting `ConcatOutputSection`s while allowing all of them to be reordered via priority/order files. While adopting a parallel sort in ld64.lld would alleviate this overhead, I believe that optimization is out of scope for this PR.

If you are concerned that this specific overhead is too high, I can limit the partition to only run on `TextOutputSection`. This would skip the logic for all non-executable sections where `isCold` isn't utilized yet. Let me know if you'd like me to add that check, or if you're comfortable proceeding with the current implementation.

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


More information about the llvm-commits mailing list