From 420c58fb119325325ec2f58f1686d7bcb63b51ad Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 27 Feb 2024 15:05:02 +0000 Subject: sess: stabilize relro-level Signed-off-by: David Wood --- compiler/rustc_codegen_ssa/src/back/link.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index e4a050dcfc9..5cc286e86eb 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2013,7 +2013,7 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained: /// Add options making relocation sections in the produced ELF files read-only /// and suppressing lazy binding. fn add_relro_args(cmd: &mut dyn Linker, sess: &Session) { - match sess.opts.unstable_opts.relro_level.unwrap_or(sess.target.relro_level) { + match sess.opts.cg.relro_level.unwrap_or(sess.target.relro_level) { RelroLevel::Full => cmd.full_relro(), RelroLevel::Partial => cmd.partial_relro(), RelroLevel::Off => cmd.no_relro(), -- cgit 1.4.1-3-g733a5 From dacfbfccc5da7c88e466af06be9468f2d10da03e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 9 Apr 2024 17:44:20 +0000 Subject: Update ar_archive_writer to 0.2.0 This adds a whole bunch of tests checking for any difference with llvm's archive writer. It also fixes two mistakes in the porting from C++ to Rust. The first one causes a divergence for Mach-O archives which may or may not be harmless. The second will definitively cause issues, but only applies to thin archives, which rustc currently doesn't create. --- Cargo.lock | 4 ++-- compiler/rustc_codegen_ssa/Cargo.toml | 2 +- compiler/rustc_codegen_ssa/src/back/archive.rs | 9 +-------- 3 files changed, 4 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/Cargo.lock b/Cargo.lock index b1bdaef81ff..d8044c67a47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -210,9 +210,9 @@ dependencies = [ [[package]] name = "ar_archive_writer" -version = "0.1.5" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9792d37ca5173d7e7f4fe453739a0671d0557915a030a383d6b866476bbc3e71" +checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a" dependencies = [ "object 0.32.2", ] diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index baf10622a6d..f347a7fb0bb 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] # tidy-alphabetical-start -ar_archive_writer = "0.1.5" +ar_archive_writer = "0.2.0" bitflags = "2.4.1" cc = "1.0.90" itertools = "0.12" diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index ef55682d541..d336973d2b9 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -285,14 +285,7 @@ impl<'a> ArArchiveBuilder<'a> { .tempfile_in(output.parent().unwrap_or_else(|| Path::new(""))) .map_err(|err| io_error_context("couldn't create a temp file", err))?; - write_archive_to_stream( - archive_tmpfile.as_file_mut(), - &entries, - true, - archive_kind, - true, - false, - )?; + write_archive_to_stream(archive_tmpfile.as_file_mut(), &entries, archive_kind, false)?; let any_entries = !entries.is_empty(); drop(entries); -- cgit 1.4.1-3-g733a5 From efbbfa24a5b309c713079486908c1754721548f9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 10 Apr 2024 15:02:04 +0200 Subject: visionOS: Fix logic for finding the SDK root The `sdk_name` is `xros`/`xrsimulator`, not `visionos`/`visionossimulator`. --- compiler/rustc_codegen_ssa/src/back/link.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index ac278de02af..cc3f18294ca 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3029,9 +3029,10 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result {} "watchsimulator" if sdkroot.contains("WatchOS.platform") || sdkroot.contains("MacOSX.platform") => {} - "visionos" - if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {} - "visionossimulator" + "xros" + if sdkroot.contains("XRSimulator.platform") + || sdkroot.contains("MacOSX.platform") => {} + "xrsimulator" if sdkroot.contains("XROS.platform") || sdkroot.contains("MacOSX.platform") => {} // Ignore `SDKROOT` if it's not a valid path. _ if !p.is_absolute() || p == Path::new("/") || !p.exists() => {} -- cgit 1.4.1-3-g733a5 From a03aeca99a1679e27d7439e6030fe759eb1f6f04 Mon Sep 17 00:00:00 2001 From: Michael Baikov Date: Tue, 16 Apr 2024 10:25:17 -0400 Subject: Allow workproducts without object files. This pull request partially reverts changes from e16c3b4a4421 Original motivation for this assert was described with "A WorkProduct without a saved file is useless" which was true at the time but now it is possible to have work products with other types of files (llvm-ir, asm, etc) and there are bugreports for this failure: For example: https://github.com/rust-lang/rust/issues/123695 Fixes https://github.com/rust-lang/rust/issues/123234 Now existing `assert` and `.unwrap_or_else` are unified into a single check that emits slightly more user friendly error message if an object files was meant to be produced but it's missing --- compiler/rustc_codegen_ssa/src/back/write.rs | 13 +++++------- tests/run-make/artifact-incr-cache-no-obj/lib.rs | 6 ++++++ tests/run-make/artifact-incr-cache-no-obj/rmake.rs | 23 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 tests/run-make/artifact-incr-cache-no-obj/lib.rs create mode 100644 tests/run-make/artifact-incr-cache-no-obj/rmake.rs (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index e7f692144ff..c4f062405bb 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -907,8 +907,6 @@ fn execute_copy_from_cache_work_item( module: CachedModuleCodegen, module_config: &ModuleConfig, ) -> WorkItemResult { - assert!(module_config.emit_obj != EmitObj::None); - let incr_comp_session_dir = cgcx.incr_comp_session_dir.as_ref().unwrap(); let load_from_incr_comp_dir = |output_path: PathBuf, saved_path: &str| { @@ -928,12 +926,6 @@ fn execute_copy_from_cache_work_item( } }; - let object = load_from_incr_comp_dir( - cgcx.output_filenames.temp_path(OutputType::Object, Some(&module.name)), - module.source.saved_files.get("o").unwrap_or_else(|| { - cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name }) - }), - ); let dwarf_object = module.source.saved_files.get("dwo").as_ref().and_then(|saved_dwarf_object_file| { let dwarf_obj_out = cgcx @@ -955,9 +947,14 @@ fn execute_copy_from_cache_work_item( } }; + let should_emit_obj = module_config.emit_obj != EmitObj::None; let assembly = load_from_incr_cache(module_config.emit_asm, OutputType::Assembly); let llvm_ir = load_from_incr_cache(module_config.emit_ir, OutputType::LlvmAssembly); let bytecode = load_from_incr_cache(module_config.emit_bc, OutputType::Bitcode); + let object = load_from_incr_cache(should_emit_obj, OutputType::Object); + if should_emit_obj && object.is_none() { + cgcx.create_dcx().emit_fatal(errors::NoSavedObjectFile { cgu_name: &module.name }) + } WorkItemResult::Finished(CompiledModule { name: module.name, diff --git a/tests/run-make/artifact-incr-cache-no-obj/lib.rs b/tests/run-make/artifact-incr-cache-no-obj/lib.rs new file mode 100644 index 00000000000..fa4048594e3 --- /dev/null +++ b/tests/run-make/artifact-incr-cache-no-obj/lib.rs @@ -0,0 +1,6 @@ +#![crate_name = "foo"] + +#[inline(never)] +pub fn add(a: u32, b: u32) -> u32 { + a + b +} diff --git a/tests/run-make/artifact-incr-cache-no-obj/rmake.rs b/tests/run-make/artifact-incr-cache-no-obj/rmake.rs new file mode 100644 index 00000000000..de55de2a1ee --- /dev/null +++ b/tests/run-make/artifact-incr-cache-no-obj/rmake.rs @@ -0,0 +1,23 @@ +// emitting an object file is not necessary if user didn't ask for one +// +// This test is similar to run-make/artifact-incr-cache but it doesn't +// require to emit an object file +// +// Fixes: rust-lang/rust#123234 + +extern crate run_make_support; + +use run_make_support::{rustc, tmp_dir}; + +fn main() { + let inc_dir = tmp_dir(); + + for _ in 0..=1 { + rustc() + .input("lib.rs") + .crate_type("lib") + .emit("asm,dep-info,link,mir,llvm-ir,llvm-bc") + .incremental(&inc_dir) + .run(); + } +} -- cgit 1.4.1-3-g733a5 From c021367de1897288f81e7f8bba23c2d2325e57f4 Mon Sep 17 00:00:00 2001 From: beetrees Date: Wed, 17 Apr 2024 03:10:09 +0100 Subject: Make the comments for `ReturnDest` variants doc comments --- compiler/rustc_codegen_ssa/src/mir/block.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 24f2c50e882..452398e6d82 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1861,12 +1861,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } enum ReturnDest<'tcx, V> { - // Do nothing; the return value is indirect or ignored. + /// Do nothing; the return value is indirect or ignored. Nothing, - // Store the return value to the pointer. + /// Store the return value to the pointer. Store(PlaceRef<'tcx, V>), - // Store an indirect return value to an operand local place. + /// Store an indirect return value to an operand local place. IndirectOperand(PlaceRef<'tcx, V>, mir::Local), - // Store a direct return value to an operand local place. + /// Store a direct return value to an operand local place. DirectOperand(mir::Local), } -- cgit 1.4.1-3-g733a5