[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 17:16:39 PDT 2026
https://github.com/peter941221 created https://github.com/llvm/llvm-project/pull/203806
Fixes #203761
`BPOrderer::computeOrder` called `takeError()` on the `InstrProfReader::create(...)` result and then still accessed the same `Expected` with `get()`. When `--irpgo-profile` points at a missing file, that turns a normal profile-open failure into an assertion instead of a regular linker error.
Handle the `Expected` directly, report the file error through `lld::error`, and return without building a startup order. Add an ELF regression test for the missing-profile case.
Validation:
- `build-lld/bin/llvm-lit -sv -j1 lld/test/ELF/bp-section-orderer-missing-profile.s`
- `clang++ -O2 -fuse-ld=lld -Wl,--irpgo-profile=non_existent_file.profdata,--bp-startup-sort=function main.cpp`
>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] [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
More information about the llvm-commits
mailing list