Skip to content

Commit 9ac4878

Browse files
committed
auto merge of #10749 : Blei/rust/fix-linker-args, r=alexcrichton
This is inspired by a mystifying linker failure when using `pkg-config` to generate the linker args: `pkg-config` produces output that ends in a space, thus resulting in an empty linker argument. Also added some updates to the concerning error messages that helped spotting this bug.
2 parents df41115 + 32688f8 commit 9ac4878

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/librustc/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ pub mod write {
362362
~"-o", object.as_str().unwrap().to_owned(),
363363
assembly.as_str().unwrap().to_owned()];
364364

365-
debug!("{} {}", cc, args.connect(" "));
365+
debug!("{} '{}'", cc, args.connect("' '"));
366366
let prog = run::process_output(cc, args);
367367

368368
if !prog.status.success() {
369369
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
370-
sess.note(format!("{} arguments: {}", cc, args.connect(" ")));
370+
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
371371
sess.note(str::from_utf8(prog.error + prog.output));
372372
sess.abort_if_errors();
373373
}
@@ -1061,7 +1061,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10611061
let mut cc_args = sess.targ_cfg.target_strs.cc_args.clone();
10621062
cc_args.push_all_move(link_args(sess, dylib, obj_filename, out_filename));
10631063
if (sess.opts.debugging_opts & session::print_link_args) != 0 {
1064-
println!("{} link args: {}", cc_prog, cc_args.connect(" "));
1064+
println!("{} link args: '{}'", cc_prog, cc_args.connect("' '"));
10651065
}
10661066

10671067
// May have not found libraries in the right formats.
@@ -1073,7 +1073,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10731073

10741074
if !prog.status.success() {
10751075
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
1076-
sess.note(format!("{} arguments: {}", cc_prog, cc_args.connect(" ")));
1076+
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
10771077
sess.note(str::from_utf8(prog.error + prog.output));
10781078
sess.abort_if_errors();
10791079
}

src/librustc/driver/driver.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,13 @@ pub fn build_session_options(binary: @str,
762762
let ar = matches.opt_str("ar");
763763
let linker = matches.opt_str("linker");
764764
let linker_args = matches.opt_strs("link-args").flat_map( |a| {
765-
a.split(' ').map(|arg| arg.to_owned()).collect()
765+
a.split(' ').filter_map(|arg| {
766+
if arg.is_empty() {
767+
None
768+
} else {
769+
Some(arg.to_owned())
770+
}
771+
}).collect()
766772
});
767773

768774
let cfg = parse_cfgspecs(matches.opt_strs("cfg"), demitter);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-include ../tools.mk
2+
# Notice the space in the end, this emulates the output of pkg-config
3+
RUSTC_FLAGS = --link-args "-lc "
4+
5+
all:
6+
$(RUSTC) $(RUSTC_FLAGS) empty.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() { }

0 commit comments

Comments
 (0)