Skip to content

Commit 4bdba91

Browse files
committed
Better diagnostics for dlltool errors.
When dlltool fails, show the full command that was executed. In particular, llvm-dlltool is not very helpful, printing a generic usage message rather than what actually went wrong, so stdout and stderr aren't of much use when troubleshooting.
1 parent 4bd4e2e commit 4bdba91

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
22
33
codegen_llvm_dlltool_fail_import_library =
4-
Dlltool could not create import library: {$stdout}
4+
Dlltool could not create import library with {$dlltool_path} {$dlltool_args}:
5+
{$stdout}
56
{$stderr}
67
78
codegen_llvm_dynamic_linking_with_lto =

compiler/rustc_codegen_llvm/src/back/archive.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,24 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
198198
"arm" => ("arm", "--32"),
199199
_ => panic!("unsupported arch {}", sess.target.arch),
200200
};
201-
let result = std::process::Command::new(&dlltool)
202-
.args([
203-
"-d",
204-
def_file_path.to_str().unwrap(),
205-
"-D",
206-
lib_name,
207-
"-l",
208-
output_path.to_str().unwrap(),
209-
"-m",
210-
dlltool_target_arch,
211-
"-f",
212-
dlltool_target_bitness,
213-
"--no-leading-underscore",
214-
"--temp-prefix",
215-
temp_prefix.to_str().unwrap(),
216-
])
217-
.output();
218-
219-
match result {
201+
let mut dlltool_cmd = std::process::Command::new(&dlltool);
202+
dlltool_cmd.args([
203+
"-d",
204+
def_file_path.to_str().unwrap(),
205+
"-D",
206+
lib_name,
207+
"-l",
208+
output_path.to_str().unwrap(),
209+
"-m",
210+
dlltool_target_arch,
211+
"-f",
212+
dlltool_target_bitness,
213+
"--no-leading-underscore",
214+
"--temp-prefix",
215+
temp_prefix.to_str().unwrap(),
216+
]);
217+
218+
match dlltool_cmd.output() {
220219
Err(e) => {
221220
sess.emit_fatal(ErrorCallingDllTool {
222221
dlltool_path: dlltool.to_string_lossy(),
@@ -226,6 +225,12 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
226225
// dlltool returns '0' on failure, so check for error output instead.
227226
Ok(output) if !output.stderr.is_empty() => {
228227
sess.emit_fatal(DlltoolFailImportLibrary {
228+
dlltool_path: dlltool.to_string_lossy(),
229+
dlltool_args: dlltool_cmd
230+
.get_args()
231+
.map(|arg| arg.to_string_lossy())
232+
.collect::<Vec<_>>()
233+
.join(" "),
229234
stdout: String::from_utf8_lossy(&output.stdout),
230235
stderr: String::from_utf8_lossy(&output.stderr),
231236
})

compiler/rustc_codegen_llvm/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub(crate) struct ErrorCallingDllTool<'a> {
8181
#[derive(Diagnostic)]
8282
#[diag(codegen_llvm_dlltool_fail_import_library)]
8383
pub(crate) struct DlltoolFailImportLibrary<'a> {
84+
pub dlltool_path: Cow<'a, str>,
85+
pub dlltool_args: String,
8486
pub stdout: Cow<'a, str>,
8587
pub stderr: Cow<'a, str>,
8688
}

0 commit comments

Comments
 (0)