about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRamon de C Valle <rcvalle@users.noreply.github.com>2025-09-02 11:23:48 -0700
committerRamon de C Valle <rcvalle@users.noreply.github.com>2025-09-02 13:11:19 -0700
commit916b55e08217ca14dabec0169067ed8d6523bf6e (patch)
tree67e3465a42f1763bdc26eb053c9775d4bd097e9b
parentdb3fd4708c3916bbc59b81ff7d3f6e19d11820c7 (diff)
downloadrust-916b55e08217ca14dabec0169067ed8d6523bf6e.tar.gz
rust-916b55e08217ca14dabec0169067ed8d6523bf6e.zip
Revert "Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`"
This reverts commit cf8753e4f9c3597f04cd5d3aa261e4561d5378a6 and fixes the
regressions reported.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/write.rs13
-rw-r--r--tests/ui/sanitizer/cfi/no_builtins.rs22
2 files changed, 12 insertions, 23 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs
index 92582dcc399..8586615f7c7 100644
--- a/compiler/rustc_codegen_ssa/src/back/write.rs
+++ b/compiler/rustc_codegen_ssa/src/back/write.rs
@@ -138,12 +138,23 @@ impl ModuleConfig {
 
         let emit_obj = if !should_emit_obj {
             EmitObj::None
-        } else if sess.target.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled() {
+        } else if sess.target.obj_is_bitcode
+            || (sess.opts.cg.linker_plugin_lto.enabled() && !no_builtins)
+        {
             // This case is selected if the target uses objects as bitcode, or
             // if linker plugin LTO is enabled. In the linker plugin LTO case
             // the assumption is that the final link-step will read the bitcode
             // and convert it to object code. This may be done by either the
             // native linker or rustc itself.
+            //
+            // Note, however, that the linker-plugin-lto requested here is
+            // explicitly ignored for `#![no_builtins]` crates. These crates are
+            // specifically ignored by rustc's LTO passes and wouldn't work if
+            // loaded into the linker. These crates define symbols that LLVM
+            // lowers intrinsics to, and these symbol dependencies aren't known
+            // until after codegen. As a result any crate marked
+            // `#![no_builtins]` is assumed to not participate in LTO and
+            // instead goes on to generate object code.
             EmitObj::Bitcode
         } else if need_bitcode_in_object(tcx) {
             EmitObj::ObjectCode(BitcodeSection::Full)
diff --git a/tests/ui/sanitizer/cfi/no_builtins.rs b/tests/ui/sanitizer/cfi/no_builtins.rs
deleted file mode 100644
index 949057689ab..00000000000
--- a/tests/ui/sanitizer/cfi/no_builtins.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-// Verifies that `#![no_builtins]` crates can be built with linker-plugin-lto and CFI.
-// See Issue #142284
-//
-//@ needs-sanitizer-cfi
-//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static
-//@ compile-flags: --crate-type rlib
-//@ build-pass
-
-#![no_builtins]
-#![no_std]
-
-pub static FUNC: fn() = initializer;
-
-pub fn initializer() {
-    call(fma_with_fma);
-}
-
-pub fn call(fn_ptr: fn()) {
-    fn_ptr();
-}
-
-pub fn fma_with_fma() {}