Skip to content

Commit

Permalink
Auto merge of #47052 - fschutt:master, r=estebank
Browse files Browse the repository at this point in the history
Improved error messages for linking failure

Partial fix for #46998

It's unnecessary to print the linker options if there is no linker installed in the first place. Currently, for libraries, the output is still printed, but that should be cleaned up in the future. If you don't have gcc or g++ installed, so that no linker is installed on the system, the output is now this:

```
$ ./rustc hello.rs
error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

error: aborting due to previous error
```

For libraries, the linker arguments are still printed, but they should be cleaned up in further commits.
  • Loading branch information
bors committed Jan 1, 2018
2 parents ad30f54 + 7c13fa3 commit 037bc65
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,25 @@ fn link_natively(sess: &Session,
info!("linker stdout:\n{}", escape_string(&prog.stdout));
},
Err(e) => {
sess.struct_err(&format!("could not exec the linker `{}`: {}", pname.display(), e))
.note(&format!("{:?}", &cmd))
.emit();
if sess.target.target.options.is_like_msvc && e.kind() == io::ErrorKind::NotFound {
let linker_not_found = e.kind() == io::ErrorKind::NotFound;

let mut linker_error = {
if linker_not_found {
sess.struct_err(&format!("linker `{}` not found", pname.display()))
} else {
sess.struct_err(&format!("could not exec the linker `{}`", pname.display()))
}
};

linker_error.note(&format!("{}", e));

if !linker_not_found {
linker_error.note(&format!("{:?}", &cmd));
}

linker_error.emit();

if sess.target.target.options.is_like_msvc && linker_not_found {
sess.note_without_error("the msvc targets depend on the msvc linker \
but `link.exe` was not found");
sess.note_without_error("please ensure that VS 2013 or VS 2015 was installed \
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-10755.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

// compile-flags: -C linker=llllll -Z linker-flavor=ld
// error-pattern: the linker `llllll`
// error-pattern: linker `llllll` not found

fn main() {
}

0 comments on commit 037bc65

Please sign in to comment.