From c59b70841c36277464b51161e3fcf12dfcb667e0 Mon Sep 17 00:00:00 2001 From: xizheyin Date: Fri, 7 Mar 2025 10:13:30 +0800 Subject: Emit warning while outputs is not exe and prints linkage info Signed-off-by: xizheyin --- compiler/rustc_codegen_ssa/src/back/link.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (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 323538969d7..ffa888a17d0 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) { } } +fn check_link_info_print_request(sess: &Session, crate_type: CrateType) { + let print_native_static_libs = + sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs); + if print_native_static_libs { + if crate_type != CrateType::Staticlib { + sess.dcx() + .warn(format!("cannot output linkage information without staticlib crate-type")); + sess.dcx() + .note(format!("consider `--crate-type staticlib` to print linkage information")); + } else if !sess.opts.output_types.should_link() { + sess.dcx().warn(format!( + "skipping link step due to conflict: cannot output linkage information without emitting link" + )); + } + } +} + /// Performs the linkage portion of the compilation phase. This will generate all /// of the requested outputs for this compilation session. pub fn link_binary( @@ -178,6 +195,8 @@ pub fn link_binary( tempfiles_for_stdout_output.push(out_filename); } } + + check_link_info_print_request(sess, crate_type); } // Remove the temporary object file and metadata if we aren't saving temps. -- cgit 1.4.1-3-g733a5 From 98bb597c05c32365abbd6898f278b097352774ed Mon Sep 17 00:00:00 2001 From: xizheyin Date: Fri, 2 May 2025 22:37:33 +0800 Subject: Update compiler/rustc_codegen_ssa/src/back/link.rs Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> --- 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 ffa888a17d0..28c7b5b2745 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -79,7 +79,7 @@ fn check_link_info_print_request(sess: &Session, crate_type: CrateType) { .note(format!("consider `--crate-type staticlib` to print linkage information")); } else if !sess.opts.output_types.should_link() { sess.dcx().warn(format!( - "skipping link step due to conflict: cannot output linkage information without emitting link" + "cannot output linkage information when --emit link is not passed" )); } } -- cgit 1.4.1-3-g733a5 From 72a9219e82c157041bfc8dfd378c9cb2b09c0650 Mon Sep 17 00:00:00 2001 From: xizheyin Date: Fri, 2 May 2025 22:56:27 +0800 Subject: check all crate-type to find staticlib Signed-off-by: xizheyin --- compiler/rustc_codegen_ssa/src/back/link.rs | 12 ++++++------ .../emit-warning-while-exe-and-print-link-info.rs | 2 +- .../emit-warning-while-exe-and-print-link-info.stderr | 2 +- 3 files changed, 8 insertions(+), 8 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 28c7b5b2745..1e9d9338b13 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -68,19 +68,19 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) { } } -fn check_link_info_print_request(sess: &Session, crate_type: CrateType) { +fn check_link_info_print_request(sess: &Session, crate_types: &[CrateType]) { let print_native_static_libs = sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs); + let has_staticlib = crate_types.iter().any(|ct| *ct == CrateType::Staticlib); if print_native_static_libs { - if crate_type != CrateType::Staticlib { + if !has_staticlib { sess.dcx() .warn(format!("cannot output linkage information without staticlib crate-type")); sess.dcx() .note(format!("consider `--crate-type staticlib` to print linkage information")); } else if !sess.opts.output_types.should_link() { - sess.dcx().warn(format!( - "cannot output linkage information when --emit link is not passed" - )); + sess.dcx() + .warn(format!("cannot output linkage information when --emit link is not passed")); } } } @@ -196,7 +196,7 @@ pub fn link_binary( } } - check_link_info_print_request(sess, crate_type); + check_link_info_print_request(sess, &codegen_results.crate_info.crate_types); } // Remove the temporary object file and metadata if we aren't saving temps. diff --git a/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.rs b/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.rs index 48f5475c884..3e9ca457a9c 100644 --- a/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.rs +++ b/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.rs @@ -1,3 +1,3 @@ //@ compile-flags: --print native-static-libs --crate-type staticlib --emit metadata //@ check-pass -//~? WARN skipping link step due to conflict: cannot output linkage information without emitting link +//~? WARN cannot output linkage information when --emit link is not passed diff --git a/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.stderr b/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.stderr index 0b46d2f6848..b32e1437d6b 100644 --- a/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.stderr +++ b/tests/ui/print-request/emit-warning-while-exe-and-print-link-info.stderr @@ -1,4 +1,4 @@ -warning: skipping link step due to conflict: cannot output linkage information without emitting link +warning: cannot output linkage information when --emit link is not passed warning: 1 warning emitted -- cgit 1.4.1-3-g733a5 From f66787a08d57dc1296619b314d2be596085bfeef Mon Sep 17 00:00:00 2001 From: xizheyin Date: Fri, 2 May 2025 23:14:18 +0800 Subject: Update compiler/rustc_codegen_ssa/src/back/link.rs Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com> Signed-off-by: xizheyin --- compiler/rustc_codegen_ssa/src/back/link.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 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 1e9d9338b13..62c389ec791 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -195,10 +195,10 @@ pub fn link_binary( tempfiles_for_stdout_output.push(out_filename); } } - - check_link_info_print_request(sess, &codegen_results.crate_info.crate_types); } + check_link_info_print_request(sess, &codegen_results.crate_info.crate_types); + // Remove the temporary object file and metadata if we aren't saving temps. sess.time("link_binary_remove_temps", || { // If the user requests that temporaries are saved, don't delete any. -- cgit 1.4.1-3-g733a5