Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGW: improve compatibility with LLD #70852

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
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);
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
Expand Down