Skip to content

Commit cd13f4d

Browse files
committed
auto merge of #10997 : cadencemarseille/rust/issue-10755-ICE-for-missing-linker, r=alexcrichton
Trap the io_error condition so that a more informative error message is displayed when the linker program cannot be started, such as when the name of the linker binary is accidentally mistyped. closes #10755
2 parents 9a8f791 + f24787d commit cd13f4d

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/librustc/back/link.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use std::os::consts::{macos, freebsd, linux, android, win32};
3333
use std::ptr;
3434
use std::run;
3535
use std::str;
36+
use std::io;
3637
use std::io::fs;
3738
use extra::tempfile::TempDir;
3839
use syntax::abi;
@@ -97,6 +98,7 @@ pub mod write {
9798
use util::common::time;
9899

99100
use std::c_str::ToCStr;
101+
use std::io;
100102
use std::libc::{c_uint, c_int};
101103
use std::path::Path;
102104
use std::run;
@@ -310,7 +312,11 @@ pub mod write {
310312
assembly.as_str().unwrap().to_owned()];
311313

312314
debug!("{} '{}'", cc, args.connect("' '"));
313-
match run::process_output(cc, args) {
315+
let opt_prog = {
316+
let _guard = io::ignore_io_error();
317+
run::process_output(cc, args)
318+
};
319+
match opt_prog {
314320
Some(prog) => {
315321
if !prog.status.success() {
316322
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
@@ -320,7 +326,7 @@ pub mod write {
320326
}
321327
},
322328
None => {
323-
sess.err(format!("could not exec `{}`", cc));
329+
sess.err(format!("could not exec the linker `{}`", cc));
324330
sess.abort_if_errors();
325331
}
326332
}
@@ -952,8 +958,11 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
952958

953959
// Invoke the system linker
954960
debug!("{} {}", cc_prog, cc_args.connect(" "));
955-
let opt_prog = time(sess.time_passes(), "running linker", (), |()|
956-
run::process_output(cc_prog, cc_args));
961+
let opt_prog = {
962+
let _guard = io::ignore_io_error();
963+
time(sess.time_passes(), "running linker", (), |()|
964+
run::process_output(cc_prog, cc_args))
965+
};
957966

958967
match opt_prog {
959968
Some(prog) => {
@@ -965,7 +974,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
965974
}
966975
},
967976
None => {
968-
sess.err(format!("could not exec `{}`", cc_prog));
977+
sess.err(format!("could not exec the linker `{}`", cc_prog));
969978
sess.abort_if_errors();
970979
}
971980
}

src/test/compile-fail/issue-10755.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: --linker=llllll
12+
// error-pattern: the linker `llllll`
13+
14+
fn main() {
15+
}

0 commit comments

Comments
 (0)