about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-03-07 10:13:30 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-05-02 22:08:58 +0800
commitc59b70841c36277464b51161e3fcf12dfcb667e0 (patch)
treee8208c5c3dfd28964e5209da132bfd4f4a2d39e1 /compiler/rustc_codegen_ssa/src
parent6e23095adf9209614a45f7f75fea36dad7b92afb (diff)
downloadrust-c59b70841c36277464b51161e3fcf12dfcb667e0.tar.gz
rust-c59b70841c36277464b51161e3fcf12dfcb667e0.zip
Emit warning while outputs is not exe and prints linkage info
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs19
1 files changed, 19 insertions, 0 deletions
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.