Skip to content

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

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

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

Conversation

@erickt

@erickt erickt commented Jul 9, 2026

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.

This is a rebase of @PiJoules's #158099, which also should fix up the tests with the gcc tools.

@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 Jul 9, 2026
@rustbot

rustbot commented Jul 9, 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

@PiJoules PiJoules 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.

Not a rust approver but LGTM from me with one nit

View changes since this review

/// "ThinLTO" metadata is defined and explicitly set to zero. Otherwise,
/// the thin LTO block ID will be emitted.
static void forceFullLTOSummary(Module *M) {
if (!M->getModuleFlag("ThinLTO")) {

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.

I suspect this can be an assert(!M->getModuleFlag("ThinLTO")) since this should never really be called if thinlto was used at all.

@PiJoules

PiJoules commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

cc @ilovepi

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.
@erickt erickt force-pushed the lto-module-summaries branch from 141d64a to 10ed1e0 Compare July 9, 2026 18:05
@rust-bors

rust-bors Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #159057) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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