Skip to content

Commit

Permalink
MinGW: use .def file instead of linker script
Browse files Browse the repository at this point in the history
This greatly improves compatibility with LLD which is not going to support linker scripts anytime soon
  • Loading branch information
mati865 committed Apr 10, 2020
1 parent af89eb5 commit 44e602f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ impl<'a> Linker for GccLinker<'a> {
return;
}

let is_windows = self.sess.target.target.options.is_like_windows;
let mut arg = OsString::new();
let path = tmpdir.join("list");
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });

debug!("EXPORTED SYMBOLS:");

Expand All @@ -460,6 +461,21 @@ impl<'a> Linker for GccLinker<'a> {
if let Err(e) = res {
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
}
} else if is_windows {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);

// .def file similar to MSVC one but without LIBRARY section
// because LD doesn't like when it's empty
writeln!(f, "EXPORTS")?;
for symbol in self.info.exports[&crate_type].iter() {
debug!(" _{}", symbol);
writeln!(f, " {}", symbol)?;
}
};
if let Err(e) = res {
self.sess.fatal(&format!("failed to write list.def file: {}", e));
}
} else {
// Write an LD version script
let res: io::Result<()> = try {
Expand Down Expand Up @@ -493,7 +509,10 @@ impl<'a> Linker for GccLinker<'a> {
if !self.is_ld {
arg.push("-Wl,")
}
arg.push("--version-script=");
// Both LD and LLD accept export list in *.def file form, there are no flags required
if !is_windows {
arg.push("--version-script=")
}
}

arg.push(&path);
Expand Down

0 comments on commit 44e602f

Please sign in to comment.