From 82cc0eeec1a000b8f2b87a070ea807bdd41f44bf Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Tue, 26 Aug 2025 18:55:41 +0300 Subject: Ensure the coordinator thread terminates first --- compiler/rustc_codegen_ssa/src/back/write.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 9f22859ba81..0d766d2704b 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1957,10 +1957,10 @@ impl Drop for Coordinator { pub struct OngoingCodegen { pub backend: B, pub crate_info: CrateInfo, - pub codegen_worker_receive: Receiver, - pub shared_emitter_main: SharedEmitterMain, pub output_filenames: Arc, pub coordinator: Coordinator, + pub codegen_worker_receive: Receiver, + pub shared_emitter_main: SharedEmitterMain, } impl OngoingCodegen { -- cgit 1.4.1-3-g733a5 From dd07459096beddf523b86a7ef03e4703390a7319 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Tue, 26 Aug 2025 19:18:39 +0300 Subject: Comment on intentional field order --- compiler/rustc_codegen_ssa/src/back/write.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 0d766d2704b..8586615f7c7 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1958,6 +1958,9 @@ pub struct OngoingCodegen { pub backend: B, pub crate_info: CrateInfo, pub output_filenames: Arc, + // Field order below is intended to terminate the coordinator thread before two fields below + // drop and prematurely close channels used by coordinator thread. See `Coordinator`'s + // `Drop` implementation for more info. pub coordinator: Coordinator, pub codegen_worker_receive: Receiver, pub shared_emitter_main: SharedEmitterMain, -- cgit 1.4.1-3-g733a5 From cf8753e4f9c3597f04cd5d3aa261e4561d5378a6 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Tue, 10 Jun 2025 23:37:05 +0000 Subject: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins` Fix #142284 by ensuring that `#![no_builtins]` crates can still emit bitcode when proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto) is used. --- compiler/rustc_codegen_ssa/src/back/write.rs | 13 +------------ tests/ui/sanitizer/cfi/no_builtins.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 tests/ui/sanitizer/cfi/no_builtins.rs (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index aa29afb7f5b..f460c900c08 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -143,23 +143,12 @@ 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() && !no_builtins) - { + } else if sess.target.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled() { // 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 new file mode 100644 index 00000000000..949057689ab --- /dev/null +++ b/tests/ui/sanitizer/cfi/no_builtins.rs @@ -0,0 +1,22 @@ +// 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() {} -- cgit 1.4.1-3-g733a5