Skip to content

[CtxProf] emit fatal usage error when flatten-prethinlink runs without guid metadata#194383

Merged
boomanaiden154 merged 3 commits into
llvm:mainfrom
pektezol:194185
Jun 17, 2026
Merged

[CtxProf] emit fatal usage error when flatten-prethinlink runs without guid metadata#194383
boomanaiden154 merged 3 commits into
llvm:mainfrom
pektezol:194185

Conversation

@pektezol

@pektezol pektezol commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

ctx-prof-flatten-prethinlink can call AssignGUIDPass::getGUID() on defined functions even when the GUID metadata is missing. In that case, LLVM currently asserts on missing !guid metadata.

Replace the assertion with reportFatalUsageError() so the pass fails with a clear user-facing error, and add a regression test for invoking only ctx-prof-flatten-prethinlink.

Fixes #194185

@github-actions

Copy link
Copy Markdown

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Apr 27, 2026
@llvmbot

llvmbot commented Apr 27, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-llvm-analysis

Author: Arda Serdar Pektezol (pektezol)

Changes

Fixes #194185

ctx-prof-flatten-prethinlink can call AssignGUIDPass::getGUID() on defined functions even when the GUID metadata is missing. In that case, LLVM currently asserts on missing !guid metadata.

Replace the assertion with reportFatalUsageError() so the pass fails with a clear user-facing error, and add a regression test for invoking only ctx-prof-flatten-prethinlink.

@boomanaiden154 sorry for the ping, accidentally closed the previous one (#194186). I updated the error message.


Full diff: https://github.com/llvm/llvm-project/pull/194383.diff

2 Files Affected:

  • (modified) llvm/lib/Analysis/CtxProfAnalysis.cpp (+3-1)
  • (added) llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll (+7)
diff --git a/llvm/lib/Analysis/CtxProfAnalysis.cpp b/llvm/lib/Analysis/CtxProfAnalysis.cpp
index c4abec02e765a..f0255e303d062 100644
--- a/llvm/lib/Analysis/CtxProfAnalysis.cpp
+++ b/llvm/lib/Analysis/CtxProfAnalysis.cpp
@@ -441,7 +441,9 @@ GlobalValue::GUID AssignGUIDPass::getGUID(const Function &F) {
     return F.getGUID();
   }
   auto *MD = F.getMetadata(GUIDMetadataName);
-  assert(MD && "guid not found for defined function");
+  if (!MD)
+    reportFatalUsageError(
+        "this pass requires the GUID metadata to be available.");
   return cast<ConstantInt>(cast<ConstantAsMetadata>(MD->getOperand(0))
                                ->getValue()
                                ->stripPointerCasts())
diff --git a/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll b/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll
new file mode 100644
index 0000000000000..e234273bd7cc9
--- /dev/null
+++ b/llvm/test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll
@@ -0,0 +1,7 @@
+; RUN: not opt -passes='ctx-prof-flatten-prethinlink' %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: LLVM ERROR: this pass requires the GUID metadata to be available.
+
+define void @test() {
+  ret void
+}

Comment thread llvm/lib/Analysis/CtxProfAnalysis.cpp Outdated
@pektezol
pektezol requested a review from boomanaiden154 June 17, 2026 18:53
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 175893 tests passed
  • 3506 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/NVPTX/global-ordering.ll
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc < /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/NVPTX/global-ordering.ll -mtriple=nvptx -mcpu=sm_20 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/NVPTX/global-ordering.ll --check-prefix=PTX32
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=nvptx -mcpu=sm_20
# .---command stderr------------
# | LLVM ERROR: initialized packed aggregate with pointers 'sadd' requires at least PTX ISA version 7.1
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mtriple=nvptx -mcpu=sm_20
# |  #0 0x000000000864a138 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:881:13
# |  #1 0x00000000086470a1 llvm::sys::RunSignalHandlers() /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:109:18
# |  #2 0x000000000864af51 SignalHandler(int, siginfo_t*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38
# |  #3 0x000079bdc3357330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x000079bdc33b0b2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x000079bdc335727e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x000079bdc333a8ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00000000085a67c5 llvm::report_fatal_error(llvm::Twine const&, bool) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/ErrorHandling.cpp:137:5
# |  #8 0x00000000060b5522 (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc+0x60b5522)
# |  #9 0x00000000060b0645 llvm::NVPTXAsmPrinter::emitGlobals(llvm::Module const&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:767:33
# | #10 0x00000000060b5782 llvm::NVPTXAsmPrinter::doFinalization(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp:827:20
# | #11 0x0000000007881e9a llvm::FPPassManager::doFinalization(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1488:13
# | #12 0x000000000787b892 runOnModule /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:41
# | #13 0x000000000787b892 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:533:44
# | #14 0x000000000508d078 compileModule(char**, llvm::SmallVectorImpl<llvm::PassPlugin>&, llvm::LLVMContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:882:17
# | #15 0x0000000005089fc3 main /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:460:13
# | #16 0x000079bdc333c1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #17 0x000079bdc333c28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #18 0x0000000005089165 _start (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc+0x5089165)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/NVPTX/global-ordering.ll --check-prefix=PTX32
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/NVPTX/global-ordering.ll --check-prefix=PTX32
# `-----------------------------
# error: command failed with exit status: 2

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 135961 tests passed
  • 3455 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/NVPTX/global-ordering.ll
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
c:\_work\llvm-project\llvm-project\build\bin\llc.exe < C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\NVPTX\global-ordering.ll -mtriple=nvptx -mcpu=sm_20 | c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\NVPTX\global-ordering.ll --check-prefix=PTX32
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\llc.exe' -mtriple=nvptx -mcpu=sm_20
# .---command stderr------------
# | LLVM ERROR: initialized packed aggregate with pointers 'sadd' requires at least PTX ISA version 7.1
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: c:\\_work\\llvm-project\\llvm-project\\build\\bin\\llc.exe -mtriple=nvptx -mcpu=sm_20
# | Exception Code: 0xC000001D
# |  #0 0x00007ff6ddaa13d6 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x2d313d6)
# |  #1 0x00007ffefc7bbb04 (C:\Windows\System32\ucrtbase.dll+0x7bb04)
# |  #2 0x00007ffefc7bcad1 (C:\Windows\System32\ucrtbase.dll+0x7cad1)
# |  #3 0x00007ff6db4c66da (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x7566da)
# |  #4 0x00007ff6db06d915 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x2fd915)
# |  #5 0x00007ff6db067de7 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x2f7de7)
# |  #6 0x00007ff6db06dbd0 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x2fdbd0)
# |  #7 0x00007ff6db28f681 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x51f681)
# |  #8 0x00007ff6db288691 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x518691)
# |  #9 0x00007ff6dad752af (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x52af)
# | #10 0x00007ff6df682920 (c:\_work\llvm-project\llvm-project\build\bin\llc.exe+0x4912920)
# | #11 0x00007fff056d4cb0 (C:\Windows\System32\KERNEL32.DLL+0x14cb0)
# | #12 0x00007fff12bbedcb (C:\Windows\SYSTEM32\ntdll.dll+0x7edcb)
# `-----------------------------
# error: command failed with exit status: 0xc000001d
# executed command: 'c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe' 'C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\NVPTX\global-ordering.ll' --check-prefix=PTX32
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  c:\_work\llvm-project\llvm-project\build\bin\filecheck.exe C:\_work\llvm-project\llvm-project\llvm\test\CodeGen\NVPTX\global-ordering.ll --check-prefix=PTX32
# `-----------------------------
# error: command failed with exit status: 2

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

@boomanaiden154 boomanaiden154 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@boomanaiden154
boomanaiden154 merged commit cddebef into llvm:main Jun 17, 2026
8 of 11 checks passed
@github-actions

Copy link
Copy Markdown

@pektezol Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

nasherm pushed a commit to nasherm/llvm-project that referenced this pull request Jun 18, 2026
…t guid metadata (llvm#194383)

`ctx-prof-flatten-prethinlink` can call `AssignGUIDPass::getGUID()` on
defined functions even when the GUID metadata is missing. In that case,
LLVM currently asserts on missing `!guid` metadata.

Replace the assertion with `reportFatalUsageError()` so the pass fails
with a clear user-facing error, and add a regression test for invoking
only `ctx-prof-flatten-prethinlink`.

Fixes llvm#194185
mtrofin added a commit that referenced this pull request Jul 7, 2026
This reverts #201194, thus relanding @orodley's PR #184065 (and
#200323):

> This allows us to keep GUIDs consistent across compilation phases
which may change the name or linkage type.
> See
https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801

The CFI issues that triggered the original revert are fixed by #201370,
together with the addressing of the TODOs in `LowerTypeTests.cpp` left
in the latter. The [graphite
diff](https://app.graphite.com/github/pr/llvm/llvm-project/201849/Reland-%23184065)
between this change's V1 and V2 shows what's been added:

- the `TODO`s from #201370 are done
- in LowerTypeTests.cpp, passing `!guid` when creating a new declaration
and when converting a definition to a declaration.
- `llvm/test/Transforms/LowerTypeTests/export-icall.ll` tests also the
above def->decl conversion
- removed
`test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll`
introduced in #194383 (this was between the revert and this PR), as now
the general expectation is that GUID assignment happens appropriately
and all passes use `getGUID`, so there's no reason for `CtxProfAnalysis`
to do something different.

Currently, we reassign GUIDs when CFI promotes internal linkage symbols,
which is counter to the goal of the RFC. This is addressed in PR
#203171. The reason for this split fix can be explained on
`compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c`. Here, a module
with the exact same source path is compiled twice, under different
conditional compilation, to produce 2 objects. Each object defines an
internal linkage symbol with the same name (this is
`install_trap_loop_detection` from
`compiler-rt/test/cfi/trap_loop_signal_handler.inc` which is
`-include`\-d by both - see how `%clang_cfi` is defined). The ThinLTO
GUID of this symbol will be the same. Its name won't be - because CFI
promotes it and renames it using a hash that is based on the IR Module
content (rather than the source path). During thinlink,
`LTO::addThinLTO`will mark each of the 2 exported symbols as prevailing
in their corresponding modules. But that is done by associating their
GUID to the module. So whichever comes last wins. The other symbol will
be marked available externally and its body DCEd later in backend. But
each module will refer to its copy of `install_trap_loop_detection`, and
so we end up with a linker error.

As mentioned, the fix is in PR #203171, and this relanding PR just
maintains the existing ThinLTO behavior by rewriting the GUIDs. Since we
haven't yet leveraged the GUID mechanics for e.g. simplifying PGO, this
aspect of this change is essentially NFC.

Co-authored-by: Owen Rodley <[email protected]>
gandhi56 pushed a commit that referenced this pull request Jul 9, 2026
This reverts #201194, thus relanding @orodley's PR #184065 (and
#200323):

> This allows us to keep GUIDs consistent across compilation phases
which may change the name or linkage type.
> See
https://discourse.llvm.org/t/rfc-keep-globalvalue-guids-stable/84801

The CFI issues that triggered the original revert are fixed by #201370,
together with the addressing of the TODOs in `LowerTypeTests.cpp` left
in the latter. The [graphite
diff](https://app.graphite.com/github/pr/llvm/llvm-project/201849/Reland-%23184065)
between this change's V1 and V2 shows what's been added:

- the `TODO`s from #201370 are done
- in LowerTypeTests.cpp, passing `!guid` when creating a new declaration
and when converting a definition to a declaration.
- `llvm/test/Transforms/LowerTypeTests/export-icall.ll` tests also the
above def->decl conversion
- removed
`test/Analysis/CtxProfAnalysis/flatten-prethinlink-requires-guid-metadata.ll`
introduced in #194383 (this was between the revert and this PR), as now
the general expectation is that GUID assignment happens appropriately
and all passes use `getGUID`, so there's no reason for `CtxProfAnalysis`
to do something different.

Currently, we reassign GUIDs when CFI promotes internal linkage symbols,
which is counter to the goal of the RFC. This is addressed in PR
#203171. The reason for this split fix can be explained on
`compiler-rt/test/cfi/icall/wrong-signature-mixed-lto.c`. Here, a module
with the exact same source path is compiled twice, under different
conditional compilation, to produce 2 objects. Each object defines an
internal linkage symbol with the same name (this is
`install_trap_loop_detection` from
`compiler-rt/test/cfi/trap_loop_signal_handler.inc` which is
`-include`\-d by both - see how `%clang_cfi` is defined). The ThinLTO
GUID of this symbol will be the same. Its name won't be - because CFI
promotes it and renames it using a hash that is based on the IR Module
content (rather than the source path). During thinlink,
`LTO::addThinLTO`will mark each of the 2 exported symbols as prevailing
in their corresponding modules. But that is done by associating their
GUID to the module. So whichever comes last wins. The other symbol will
be marked available externally and its body DCEd later in backend. But
each module will refer to its copy of `install_trap_loop_detection`, and
so we end up with a linker error.

As mentioned, the fix is in PR #203171, and this relanding PR just
maintains the existing ThinLTO behavior by rewriting the GUIDs. Since we
haven't yet leveraged the GUID mechanics for e.g. simplifying PGO, this
aspect of this change is essentially NFC.

Co-authored-by: Owen Rodley <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[opt] crash for ctx-prof-flatten-prethinlink pass without GUID metadata

3 participants