[lld] [lld] Handle missing IRPGO profile without asserting (PR #203806)

Peter Chen J. via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 14 19:10:35 PDT 2026


https://github.com/peter941221 updated https://github.com/llvm/llvm-project/pull/203806

>From ad98abd77d21199c4594f84217dd817b58181ab6 Mon Sep 17 00:00:00 2001
From: peter941221 <peter941221 at gmail.com>
Date: Mon, 15 Jun 2026 08:12:33 +0800
Subject: [PATCH 1/2] [lld] Handle missing IRPGO profile without asserting

---
 lld/include/lld/Common/BPSectionOrdererBase.inc   | 7 +++++--
 lld/test/ELF/bp-section-orderer-missing-profile.s | 9 +++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 lld/test/ELF/bp-section-orderer-missing-profile.s

diff --git a/lld/include/lld/Common/BPSectionOrdererBase.inc b/lld/include/lld/Common/BPSectionOrdererBase.inc
index daac8785f8da7..087d0356db03d 100644
--- a/lld/include/lld/Common/BPSectionOrdererBase.inc
+++ b/lld/include/lld/Common/BPSectionOrdererBase.inc
@@ -177,9 +177,12 @@ auto BPOrderer<D>::computeOrder(
   if (!profilePath.empty()) {
     auto fs = vfs::getRealFileSystem();
     auto readerOrErr = InstrProfReader::create(profilePath, *fs);
-    lld::checkError(readerOrErr.takeError());
+    if (!readerOrErr) {
+      lld::error(toString(readerOrErr.takeError()));
+      return DenseMap<const Section *, int>();
+    }
 
-    reader = std::move(readerOrErr.get());
+    reader = std::move(*readerOrErr);
     for (auto &entry : *reader) {
       // Read all entries
       (void)entry;
diff --git a/lld/test/ELF/bp-section-orderer-missing-profile.s b/lld/test/ELF/bp-section-orderer-missing-profile.s
new file mode 100644
index 0000000000000..4712d12ae084f
--- /dev/null
+++ b/lld/test/ELF/bp-section-orderer-missing-profile.s
@@ -0,0 +1,9 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: not ld.lld %t.o --irpgo-profile=%t.missing.profdata --bp-startup-sort=function 2>&1 | FileCheck %s
+
+# CHECK: error: No such file or directory
+
+.globl _start
+_start:
+  ret

>From 1faf9631b4300fdf508bff95625ae03f5895525b Mon Sep 17 00:00:00 2001
From: peter941221 <peter941221 at gmail.com>
Date: Mon, 15 Jun 2026 10:10:00 +0800
Subject: [PATCH 2/2] [lld][MachO] Add missing-profile BP regression

---
 lld/test/MachO/bp-section-orderer-missing-profile.s | 10 ++++++++++
 1 file changed, 10 insertions(+)
 create mode 100644 lld/test/MachO/bp-section-orderer-missing-profile.s

diff --git a/lld/test/MachO/bp-section-orderer-missing-profile.s b/lld/test/MachO/bp-section-orderer-missing-profile.s
new file mode 100644
index 0000000000000..9bdec1e6e69a8
--- /dev/null
+++ b/lld/test/MachO/bp-section-orderer-missing-profile.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
+# RUN: not %lld -arch x86_64 -lSystem -e _main -o /dev/null %t.o --irpgo-profile=%t.missing.profdata --bp-startup-sort=function 2>&1 | FileCheck %s
+
+# CHECK: error: No such file or directory
+
+.text
+.globl _main
+_main:
+  ret



More information about the llvm-commits mailing list