CFI: Fix LTO for #![no_builtins] crates with CFI#156024
CFI: Fix LTO for #![no_builtins] crates with CFI#156024rcvalle wants to merge 1 commit intorust-lang:mainfrom
#![no_builtins] crates with CFI#156024Conversation
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
58c916f to
02987f4
Compare
This comment has been minimized.
This comment has been minimized.
| // | ||
| // Therefore, with `-Clinker-plugin-lto` and `-Zsanitizer=cfi`, a | ||
| // `#![no_builtins]` crate must still use rustc's `EmitObj::Bitcode` | ||
| // path (and emit LLVM bitcode in the `.o` for linker-based LTO). |
There was a problem hiding this comment.
The reason we don't use LTO for compiler-builtins is that doing so breaks the weak linkage that compiler-builtins uses. We use a legacy interface for implementing LTO that treats weak and strong symbols identically. We tried to make compiler-builtins participate in LTO before in #113923, but this resulted in the regression #118609.
In any case just emitting bitcode is not enough. You also need to updated ignored_for_lto:
rust/compiler/rustc_codegen_ssa/src/back/link.rs
Lines 1406 to 1422 in 0469a92
There was a problem hiding this comment.
This change only makes it participate on LTO when using both -Clinker-plugin-lto (not rustc LTO) and -Zsanitizer=cfi, which expects a clang or ld.lld linker already and thus doesn't cause the regressions listed on #146133, with the regression tests added by @dianqk now passing. However, I see that the regressions you mention are different ones. Are there any regression tests for them I can verify?
There was a problem hiding this comment.
Cargo uses -Clinker-plugin-lto when compiling rlib crates even when not doing linker plugin LTO to skip unnecessary codegen for them.
There was a problem hiding this comment.
I'm a bit confused about what is the issue you're referring to. ignored_for_lto is for rustc LTO (not proper LTO). The #142284 issue is when using both -Clinker-plugin-lto (proper LTO) and -Zsanitizer=cfi, where LTO is deferred to the linker; the fix needed was to ensure those crates emit LLVM bitcode so proper LTO can run the LowerTypeTests pass and lower llvm.type.test intrinsics and related metadata. (Note the issue #142284 doesn't happen with rust LTO: #142284 (comment) because these are properly lowered already.) Would you mind providing more details? Maybe a regression test or a reproducer?
There was a problem hiding this comment.
I was thinking wrong in my earlier comments. I however did just remember that you tried to land pretty much the same PR previously as #145368, which then had to be reverted in #146133 due to regressions. Has anything changed since then to fix those regressions even when compiling compiler-builtins with LTO enabled?
02987f4 to
49f46f9
Compare
This comment has been minimized.
This comment has been minimized.
49f46f9 to
1a3cf09
Compare
This comment has been minimized.
This comment has been minimized.
1a3cf09 to
c338aae
Compare
Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's `EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for linker-based LTO).
c338aae to
6650fd5
Compare
|
r? bjorn3 (since you're already reviewing this, and know way more about this than I do) |
Fixes LTO for
#![no_builtins]crates with CFI enabled by using rustc'sEmitObj::Bitcodepath (and emitting LLVM bitcode in the.ofor linker-based LTO).In addition to adding a specific regression test for #142284, it also adds a test that verifies that the examples in rust-cfi-examples build with
-Zbuild-stdto prevent other future regressions.