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

Comment thread compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp Outdated
@PiJoules

PiJoules commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

cc @ilovepi

@erickt
erickt force-pushed the lto-module-summaries branch from 141d64a to 10ed1e0 Compare July 9, 2026 18:05
@rust-bors

This comment has been minimized.

@erickt
erickt force-pushed the lto-module-summaries branch from 10ed1e0 to 25ec857 Compare July 10, 2026 22:33
@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@erickt
erickt force-pushed the lto-module-summaries branch from 25ec857 to 162ba1c Compare July 17, 2026 18:53
@erickt

erickt commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

Comment thread compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp Outdated
@erickt

erickt commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rust-log-analyzer

This comment has been minimized.

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.

Finally, now that we're generating module summaries for `-Clto=fat`
without using ThinLTO, we need to update `rustc-metadata` to keep
around a temporary directory that contains the `.rmeta` for a little
longer before we deserialize it.
@erickt
erickt force-pushed the lto-module-summaries branch from dbe5531 to fe44964 Compare July 21, 2026 21:20
@erickt

erickt commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@bjorn3 - I think I did a force push and lost a comment from you. Does the latest version still have the concern you mentioned?

@cuviper

cuviper commented Jul 23, 2026

Copy link
Copy Markdown
Member

I assume they deleted their own comment, but do speak up if that's still relevant.

Otherwise, it looks good to me!

@bors r+

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fe44964 has been approved by cuviper

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2026
@bjorn3

bjorn3 commented Jul 23, 2026

Copy link
Copy Markdown
Member

I don't fully remember what my comment was, but I did indeed delete it when I realized I was thinking wrong. I don't have any objections to this PR.

jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
…iper

rustc_llvm: Emit module summaries when using -Clto=fat

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 rust-lang#158099, which also should fix up the tests with the gcc tools.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
…iper

rustc_llvm: Emit module summaries when using -Clto=fat

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 rust-lang#158099, which also should fix up the tests with the gcc tools.
@jhpratt

jhpratt commented Jul 24, 2026

Copy link
Copy Markdown
Member

@bors r- #159803 (comment)

---- [run-make] tests/run-make/fat-lto-module-summary stdout ----

error: rmake recipe failed to complete
status: exit status: 1
command: cd "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/fat-lto-module-summary/rmake_out" && env -u RUSTFLAGS -u __RUSTC_DEBUG_ASSERTIONS_ENABLED -u __STD_DEBUG_ASSERTIONS_ENABLED AR="arm-none-eabi-ar" BUILD_ROOT="/checkout/obj/build/x86_64-unknown-linux-gnu" CC="arm-none-eabi-gcc" CC_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -mthumb -march=armv6s-m -gz" CXX="arm-none-eabi-g++" CXX_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -mthumb -march=armv6s-m -gz" HOST_RUSTC_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/build/run_make_support/ca584b3561373ef1/out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" LD_LIB_PATH_ENVVAR="LD_LIBRARY_PATH" LLVM_BIN_DIR="/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/bin" LLVM_COMPONENTS="aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils abi aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgputargetmca amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cas cfguard cgdata codegen codegentypes core coroutines coverage csky cskyasmparser cskycodegen cskydesc cskydisassembler cskyinfo debuginfobtf debuginfocodeview debuginfodwarf debuginfodwarflowlevel debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dtlto dwarfcfichecker dwarflinker dwarflinkerclassic dwarflinkerparallel dwp engine executionengine extensions filecheck frontendatomic frontenddirective frontenddriver frontendhlsl frontendoffloading frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo hipstdpar instcombine instrumentation interfacestub interpreter ipo irprinter irreader jitlink libdriver lineeditor linker loongarch loongarchasmparser loongarchcodegen loongarchdesc loongarchdisassembler loongarchinfo lto m68k m68kasmparser m68kcodegen m68kdesc m68kdisassembler m68kinfo mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts objcopy object objectyaml option orcdebugging orcjit orcshared orctargetprocess passes plugins powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvtargetmca runtimedyld sandboxir scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support supportlsp symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target targetparser telemetry textapi textapibinaryreader transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86targetmca xray xtensa xtensaasmparser xtensacodegen xtensadesc xtensadisassembler xtensainfo" LLVM_FILECHECK="/checkout/obj/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" NODE="/usr/bin/node" PYTHON="/usr/bin/python3" RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUSTC_LINKER="arm-none-eabi-gcc" RUSTDOC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" SOURCE_ROOT="/checkout" TARGET="thumbv6m-none-eabi" TARGET_EXE_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/thumbv6m-none-eabi/lib" __BOOTSTRAP_JOBS="4" __RMAKE_VERBOSE_SUBPROCESS_OUTPUT="1" __STD_REMAP_DEBUGINFO_ENABLED="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/fat-lto-module-summary/rmake"
stdout: none
--- stderr -------------------------------
command failed at line 4
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/fat-lto-module-summary/rmake_out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/build/run_make_support/ca584b3561373ef1/out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make/fat-lto-module-summary/rmake_out" "foo.rs" "--crate-type" "lib" "-Clto=fat" "--emit=llvm-bc" "--target=thumbv6m-none-eabi"
output status: `exit status: 1`
=== STDOUT ===



=== STDERR ===
error[E0463]: can't find crate for `std`
  |
  = note: the `thumbv6m-none-eabi` target may not support the standard library
  = note: `std` is required by `<unknown>` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error: cannot resolve a prelude import

error: aborting due to 2 previous errors

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 24, 2026
@rust-bors

rust-bors Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159803), which was unapproved.

View changes since this unapproval

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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants