]> git.lizzy.rs Git - rust.git/commitdiff
Stabilize -Z print-link-args as --print link-args
authorJosh Triplett <josh@joshtriplett.org>
Mon, 6 Dec 2021 22:09:24 +0000 (14:09 -0800)
committerJosh Triplett <josh@joshtriplett.org>
Sun, 9 Jan 2022 21:22:50 +0000 (13:22 -0800)
We have stable options for adding linker arguments; we should have a
stable option to help debug linker arguments.

12 files changed:
compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_driver/src/lib.rs
compiler/rustc_interface/src/tests.rs
compiler/rustc_session/src/config.rs
compiler/rustc_session/src/options.rs
src/test/run-make-fulldeps/codegen-options-parsing/Makefile
src/test/run-make-fulldeps/interdependent-c-libraries/Makefile
src/test/run-make-fulldeps/link-arg/Makefile
src/test/run-make-fulldeps/metadata-flag-frobs-symbols/Makefile
src/test/run-make-fulldeps/no-builtins-lto/Makefile
src/test/run-make-fulldeps/redundant-libs/Makefile
src/test/run-make-fulldeps/static-nobundle/Makefile

index 638b2a7b5a9f24b1ad4dc7fb2901373a15d41e45..5397547670931021702c9aa4e164a197b53ec0fe 100644 (file)
@@ -722,7 +722,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
         cmd.env_remove(k);
     }
 
-    if sess.opts.debugging_opts.print_link_args {
+    if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
         println!("{:?}", &cmd);
     }
 
index 6ff94341142fda67563b9f412857a987ab1256f3..19f4c22d4bba3f47f01054835dd52eb3f4c95cab 100644 (file)
@@ -652,9 +652,9 @@ fn print_crate_info(
         temps_dir: &Option<PathBuf>,
     ) -> Compilation {
         use rustc_session::config::PrintRequest::*;
-        // PrintRequest::NativeStaticLibs is special - printed during linking
+        // NativeStaticLibs and LinkArgs are special - printed during linking
         // (empty iterator returns true)
-        if sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs) {
+        if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
             return Compilation::Continue;
         }
 
@@ -745,7 +745,8 @@ fn print_crate_info(
                     codegen_backend.print(*req, sess);
                 }
                 // Any output here interferes with Cargo's parsing of other printed output
-                PrintRequest::NativeStaticLibs => {}
+                NativeStaticLibs => {}
+                LinkArgs => {}
             }
         }
         Compilation::Stop
index c651feaaa66f62cf5b0d1718ce6eb193bc5833d0..760187f04151caca92597e2462fc090e80b375b3 100644 (file)
@@ -675,7 +675,6 @@ macro_rules! untracked {
     // `pre_link_arg` is omitted because it just forwards to `pre_link_args`.
     untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
     untracked!(profile_closures, true);
-    untracked!(print_link_args, true);
     untracked!(print_llvm_passes, true);
     untracked!(print_mono_items, Some(String::from("abc")));
     untracked!(print_type_sizes, true);
index 87e8e57611765ab053b69a42c4e4f0339a1bc7eb..ec32201c263170578976973e6c6e23947b9978b5 100644 (file)
@@ -534,6 +534,7 @@ pub enum PrintRequest {
     TargetSpec,
     NativeStaticLibs,
     StackProtectorStrategies,
+    LinkArgs,
 }
 
 #[derive(Copy, Clone)]
@@ -1115,7 +1116,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
             "Compiler information to print on stdout",
             "[crate-name|file-names|sysroot|target-libdir|cfg|target-list|\
              target-cpus|target-features|relocation-models|code-models|\
-             tls-models|target-spec-json|native-static-libs|stack-protector-strategies]",
+             tls-models|target-spec-json|native-static-libs|stack-protector-strategies\
+             link-args]",
         ),
         opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
         opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
@@ -1547,6 +1549,7 @@ fn collect_print_requests(
                 );
             }
         }
+        "link-args" => PrintRequest::LinkArgs,
         req => early_error(error_format, &format!("unknown print request `{}`", req)),
     }));
 
index bd7b1639613eb7963a776fcb38b2e779cf95cb74..7114b11703140b2f3fc2c002490a5cc3d99a86e2 100644 (file)
@@ -1294,8 +1294,6 @@ mod parse {
         See #77382 and #74551."),
     print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
         "make rustc print the total optimization fuel used by a crate"),
-    print_link_args: bool = (false, parse_bool, [UNTRACKED],
-        "print the arguments passed to the linker (default: no)"),
     print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
         "print the LLVM optimization passes being run (default: no)"),
     print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
index 39e9a9bdd6b684493da1400d21413eb55fb59423..f1410b69b3fceafe49a87bbab3a602b00610c3f0 100644 (file)
@@ -24,8 +24,8 @@ all:
        $(RUSTC) -C lto dummy.rs
 
        # Should not link dead code...
-       $(RUSTC) -Z print-link-args dummy.rs 2>&1 | \
+       $(RUSTC) --print link-args dummy.rs 2>&1 | \
                $(CGREP) -e '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF'
        # ... unless you specifically ask to keep it
-       $(RUSTC) -Z print-link-args -C link-dead-code dummy.rs 2>&1 | \
+       $(RUSTC) --print link-args -C link-dead-code dummy.rs 2>&1 | \
                $(CGREP) -ve '--gc-sections|-z[^ ]* [^ ]*<ignore>|-dead_strip|/OPT:REF'
index 1268022e37b744294eb2772f96333598109f9e33..0a50859cdaa4dd670423cb6cefcec9e546e38843 100644 (file)
@@ -11,4 +11,4 @@
 all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar)
        $(RUSTC) foo.rs
        $(RUSTC) bar.rs
-       $(RUSTC) main.rs -Z print-link-args
+       $(RUSTC) main.rs --print link-args
index d7c9fd2711285b14e2f4c28edc2954b955cd93d0..0360ede762551a673873abba499d6293992e2df0 100644 (file)
@@ -1,5 +1,5 @@
 -include ../tools.mk
-RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" -Z print-link-args
+RUSTC_FLAGS = -C link-arg="-lfoo" -C link-arg="-lbar" --print link-args
 
 all:
        $(RUSTC) $(RUSTC_FLAGS) empty.rs | $(CGREP) lfoo lbar
index 09e6ae0bbf7cd01f578084b768dd967d7f02d505..3ffbba9444bc2ea338d31e8e31c184c99f7980d2 100644 (file)
@@ -6,5 +6,5 @@ all:
        $(RUSTC) bar.rs \
                --extern foo1=$(TMPDIR)/libfoo-a.rlib \
                --extern foo2=$(TMPDIR)/libfoo-b.rlib \
-               -Z print-link-args
+               --print link-args
        $(call RUN,bar)
index b9688f16c646465d82d216f8b42579c1cf2220da..2e41be39d5d00851348915f5ebfa2e2a200f5ed3 100644 (file)
@@ -6,4 +6,4 @@ all:
        # Build an executable that depends on that crate using LTO. The no_builtins crate doesn't
        # participate in LTO, so its rlib must be explicitly linked into the final binary. Verify this by
        # grepping the linker arguments.
-       $(RUSTC) main.rs -C lto -Z print-link-args | $(CGREP) 'libno_builtins.rlib'
+       $(RUSTC) main.rs -C lto --print link-args | $(CGREP) 'libno_builtins.rlib'
index 8468d102bec8312a276df6de130368ef4d492891..e09841fb42e1876ae337328568d6994a20ac0e33 100644 (file)
@@ -16,7 +16,7 @@ RUSTC_FLAGS = \
     -l foo \
     -l static=baz \
     -l foo \
-    -Z print-link-args
+    --print link-args
 
 all: $(call DYLIB,foo) $(call STATICLIB,bar) $(call STATICLIB,baz)
        $(RUSTC) $(RUSTC_FLAGS) main.rs
index abc32d4423b05a8ffb01d12977c78592a8ffd394..8f78c401a11415fe9b4665d9117187b77734adb3 100644 (file)
@@ -13,9 +13,9 @@ all: $(call NATIVE_STATICLIB,aaa)
        nm $(TMPDIR)/libbbb.rlib | $(CGREP) -e "U _*native_func"
 
        # Check that aaa gets linked (either as `-l aaa` or `aaa.lib`) when building ccc.
-       $(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib -Z print-link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib'
+       $(RUSTC) ccc.rs -C prefer-dynamic --crate-type=dylib --print link-args | $(CGREP) -e '-l[" ]*aaa|aaa\.lib'
 
        # Check that aaa does NOT get linked when building ddd.
-       $(RUSTC) ddd.rs -Z print-link-args | $(CGREP) -ve '-l[" ]*aaa|aaa\.lib'
+       $(RUSTC) ddd.rs --print link-args | $(CGREP) -ve '-l[" ]*aaa|aaa\.lib'
 
        $(call RUN,ddd)