Skip to content

rustc_llvm: Emit module summaries when using -Clto=fat#158099

Open
PiJoules wants to merge 1 commit into
rust-lang:mainfrom
PiJoules:lto-module-summaries
Open

rustc_llvm: Emit module summaries when using -Clto=fat#158099
PiJoules wants to merge 1 commit into
rust-lang:mainfrom
PiJoules:lto-module-summaries

Conversation

@PiJoules

Copy link
Copy Markdown
Contributor

Currently, module summaries are only emitted with thin lto. If we would link full/fat lto'd rust code against lto'd c++ code built with CFI (or WPD), those passes would fail during the link step because the participating rust modules are missing module summaries. Rust code does not know at compile-time if it would be participating in some special link which may require module summaries, so this PR ensures module summaries are unconditionally emitted for full/fat lto, just like with thin lto.

The WriteBitcodeToFile function just invokes the normal BitcodeWriterPass under the hood, but doesn't provide a way to set the argument for emitting module summaries. So this patch just adds the pass directly and sets that argument.

Currently, module summaries are only emitted with thin lto. If we would
link full/fat lto'd rust code against lto'd c++ code built with CFI (or
WPD), those passes would fail during the link step because the
participating rust modules are missing module summaries. Rust code does
not know at compile-time if it would be participating in some special
link which may require module summaries, so this PR ensures module
summaries are unconditionally emitted for full/fat lto, just like with
thin lto.

The WriteBitcodeToFile function just invokes the normal
BitcodeWriterPass under the hood, but doesn't provide a way to set the
argument for emitting module summaries. So this patch just adds the pass
directly and sets that argument.
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

r? @cuviper

rustbot has assigned @cuviper.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @cuviper

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 18, 2026
@PiJoules

Copy link
Copy Markdown
Contributor Author

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job tidy failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
All checks passed!
checking python file formatting
29 files already formatted
checking C++ file formatting
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:929:77: error: code should be clang-formatted [-Wclang-format-violations]
      // Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
                                                                            ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:929:87: error: code should be clang-formatted [-Wclang-format-violations]
      // Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
                                                                                      ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:930:7: error: code should be clang-formatted [-Wclang-format-violations]
      // metadata is defined and explicitly set to zero. Otherwise, the thin LTO block
      ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:930:68: error: code should be clang-formatted [-Wclang-format-violations]
---
                                                                                      ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:931:7: error: code should be clang-formatted [-Wclang-format-violations]
      // ID will be emitted.
      ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:932:19: error: code should be clang-formatted [-Wclang-format-violations]
      auto *Zero = ConstantInt::get(Type::getInt32Ty(TheModule->getContext()), 0);
                  ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:934:51: error: code should be clang-formatted [-Wclang-format-violations]
      MPM.addPass(BitcodeWriterPass(ThinLTODataOS, /*ShouldPreserveUseListOrder=*/false,
                                                  ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1470:79: error: code should be clang-formatted [-Wclang-format-violations]
        // Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
                                                                              ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1470:89: error: code should be clang-formatted [-Wclang-format-violations]
        // Note the bitcode writer will only emit the full LTO block ID if the "ThinLTO"
                                                                                        ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1471:9: error: code should be clang-formatted [-Wclang-format-violations]
        // metadata is defined and explicitly set to zero. Otherwise, the thin LTO block
        ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1471:70: error: code should be clang-formatted [-Wclang-format-violations]
---
                                                                                        ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1472:9: error: code should be clang-formatted [-Wclang-format-violations]
        // ID will be emitted.
        ^
/checkout/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp:1473:21: error: code should be clang-formatted [-Wclang-format-violations]
        auto *Zero = ConstantInt::get(Type::getInt32Ty(unwrap(M)->getContext()), 0);
                    ^

clang-format linting failed! Printing diff suggestions:
rerun tidy with `--extra-checks=cpp:fmt --bless` to reformat C++ code
tidy [extra_checks:cpp_fmt]: checks with external tool 'clang-format' failed
tidy [extra_checks:cpp_fmt]: FAIL
spellchecking files
building external tool typos from package typos-cli@1.38.1
finished building tool typos
yarn install v1.22.22
warning package.json: No license field
---
info: ✓ ES-Check passed! All files are ES10 compatible.
typechecking javascript files
tidy: The following check failed: extra_checks:cpp_fmt
Bootstrap failed while executing `test src/tools/tidy tidyselftest --extra-checks=py,cpp,js,spellcheck`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools-bin/rust-tidy --root-path=/checkout --cargo-path=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo --output-dir=/checkout/obj/build --concurrency=4 --npm-path=/node/bin/yarn --ci=true --extra-checks=py,cpp,js,spellcheck` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:1624:23
Executed at: src/bootstrap/src/core/build_steps/test.rs:1511:29

--- BACKTRACE vvv
   0: <bootstrap::utils::exec::DeferredCommand>::finish_process
             at /checkout/src/bootstrap/src/utils/exec.rs:939:17
   1: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
             at /checkout/src/bootstrap/src/utils/exec.rs:831:21
   2: <bootstrap::utils::exec::ExecutionContext>::run
             at /checkout/src/bootstrap/src/utils/exec.rs:741:45
   3: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
             at /checkout/src/bootstrap/src/utils/exec.rs:339:27
   4: <bootstrap::core::build_steps::test::Tidy as bootstrap::core::builder::Step>::run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:1511:29
   5: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::Tidy>
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1596:36
   6: <bootstrap::core::build_steps::test::Tidy as bootstrap::core::builder::Step>::make_run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:1433:21
   7: <bootstrap::core::builder::StepDescription>::maybe_run
             at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
   8: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
             at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:232:18
   9: <bootstrap::core::builder::Builder>::run_step_descriptions
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1139:9
  10: <bootstrap::core::builder::Builder>::execute_cli
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1118:14
  11: <bootstrap::Build>::build
             at /checkout/src/bootstrap/src/lib.rs:803:25
  12: bootstrap::main
             at /checkout/src/bootstrap/src/bin/main.rs:130:11
  13: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/ops/function.rs:250:5
  14: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/sys/backtrace.rs:166:18
  15: std::rt::lang_start::<()>::{closure#0}
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/rt.rs:206:18
  16: <&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe as core::ops::function::FnOnce<()>>::call_once
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/ops/function.rs:287:21
  17: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:581:40
  18: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe>
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:544:19
  19: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panic.rs:359:14
  20: std::rt::lang_start_internal::{closure#0}
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/rt.rs:175:24
  21: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:581:40
---
  28: __libc_start_main
  29: _start


Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:02:32
  local time: Thu Jun 18 18:44:34 UTC 2026
  network time: Thu, 18 Jun 2026 18:44:34 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants