File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
tests/run-make/rust-lld-by-default Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ // Test linking using `cc` with `rust-lld`, which is on by default on the x86_64-unknown-linux-gnu
2+ // target.
3+ // See https://github.com/rust-lang/compiler-team/issues/510 for more info
4+
5+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ // Ensure that rust-lld is used as the default linker on `x86_64-unknown-linux-gnu`, and that it can
2+ // also be turned off with a CLI flag.
3+
4+ //@ needs-rust-lld
5+ //@ only-x86_64-unknown-linux-gnu
6+
7+ extern crate run_make_support;
8+
9+ use run_make_support:: regex:: Regex ;
10+ use run_make_support:: rustc;
11+ use std:: process:: Output ;
12+
13+ fn main ( ) {
14+ // A regular compilation should use rust-lld by default. We'll check that by asking the linker
15+ // to display its version number with a link-arg.
16+ let output = rustc ( )
17+ . env ( "RUSTC_LOG" , "rustc_codegen_ssa::back::link=info" )
18+ . link_arg ( "-Wl,-v" )
19+ . input ( "main.rs" )
20+ . run ( ) ;
21+ assert ! (
22+ find_lld_version_in_logs( output) ,
23+ "the LLD version string should be present in the output logs"
24+ ) ;
25+
26+ // But it can still be disabled by turning the linker feature off.
27+ let output = rustc ( )
28+ . env ( "RUSTC_LOG" , "rustc_codegen_ssa::back::link=info" )
29+ . link_arg ( "-Wl,-v" )
30+ . arg ( "-Zlinker-features=-lld" )
31+ . input ( "main.rs" )
32+ . run ( ) ;
33+ assert ! (
34+ !find_lld_version_in_logs( output) ,
35+ "the LLD version string should not be present in the output logs"
36+ ) ;
37+ }
38+
39+ fn find_lld_version_in_logs ( output : Output ) -> bool {
40+ let lld_version_re = Regex :: new ( r"^LLD [0-9]+\.[0-9]+\.[0-9]+" ) . unwrap ( ) ;
41+ let stderr = std:: str:: from_utf8 ( & output. stderr ) . unwrap ( ) ;
42+ stderr. lines ( ) . any ( |line| lld_version_re. is_match ( line) )
43+ }
You can’t perform that action at this time.
0 commit comments