Skip to content

Commit f24787d

Browse files
Fix #10755 - ICE: --linker=
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
1 parent c87b9d3 commit f24787d

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
}
@@ -948,8 +954,11 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
948954

949955
// Invoke the system linker
950956
debug!("{} {}", cc_prog, cc_args.connect(" "));
951-
let opt_prog = time(sess.time_passes(), "running linker", (), |()|
952-
run::process_output(cc_prog, cc_args));
957+
let opt_prog = {
958+
let _guard = io::ignore_io_error();
959+
time(sess.time_passes(), "running linker", (), |()|
960+
run::process_output(cc_prog, cc_args))
961+
};
953962

954963
match opt_prog {
955964
Some(prog) => {
@@ -961,7 +970,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
961970
}
962971
},
963972
None => {
964-
sess.err(format!("could not exec `{}`", cc_prog));
973+
sess.err(format!("could not exec the linker `{}`", cc_prog));
965974
sess.abort_if_errors();
966975
}
967976
}

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)