Skip to content

Commit 44e602f

Browse files
committed
MinGW: use .def file instead of linker script
This greatly improves compatibility with LLD which is not going to support linker scripts anytime soon
1 parent af89eb5 commit 44e602f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

Diff for: src/librustc_codegen_ssa/back/linker.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,9 @@ impl<'a> Linker for GccLinker<'a> {
443443
return;
444444
}
445445

446+
let is_windows = self.sess.target.target.options.is_like_windows;
446447
let mut arg = OsString::new();
447-
let path = tmpdir.join("list");
448+
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });
448449

449450
debug!("EXPORTED SYMBOLS:");
450451

@@ -460,6 +461,21 @@ impl<'a> Linker for GccLinker<'a> {
460461
if let Err(e) = res {
461462
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
462463
}
464+
} else if is_windows {
465+
let res: io::Result<()> = try {
466+
let mut f = BufWriter::new(File::create(&path)?);
467+
468+
// .def file similar to MSVC one but without LIBRARY section
469+
// because LD doesn't like when it's empty
470+
writeln!(f, "EXPORTS")?;
471+
for symbol in self.info.exports[&crate_type].iter() {
472+
debug!(" _{}", symbol);
473+
writeln!(f, " {}", symbol)?;
474+
}
475+
};
476+
if let Err(e) = res {
477+
self.sess.fatal(&format!("failed to write list.def file: {}", e));
478+
}
463479
} else {
464480
// Write an LD version script
465481
let res: io::Result<()> = try {
@@ -493,7 +509,10 @@ impl<'a> Linker for GccLinker<'a> {
493509
if !self.is_ld {
494510
arg.push("-Wl,")
495511
}
496-
arg.push("--version-script=");
512+
// Both LD and LLD accept export list in *.def file form, there are no flags required
513+
if !is_windows {
514+
arg.push("--version-script=")
515+
}
497516
}
498517

499518
arg.push(&path);

0 commit comments

Comments
 (0)