Skip to content

Commit

Permalink
Rollup merge of rust-lang#63965 - loganwendholt:linker-script-fix, r=…
Browse files Browse the repository at this point in the history
…michaelwoerister

Prevent syntax error in LD linker version script

As discussed in rust-lang#63925, there is an edge case in which an invalid LD version script is generated when building a `cdylib` with no exported symbols. This PR makes a slight modification to the  LD version script generation by first checking to see if any symbols need to be exported. If not, the `global` section of the linker script is simply omitted, and the syntax error is averted.
  • Loading branch information
Centril committed Aug 29, 2019
2 parents f0e2895 + 42bd6fa commit 1c4a9a9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,13 @@ impl<'a> Linker for GccLinker<'a> {
// Write an LD version script
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
writeln!(f, "{{\n global:")?;
for sym in self.info.exports[&crate_type].iter() {
debug!(" {};", sym);
writeln!(f, " {};", sym)?;
writeln!(f, "{{")?;
if !self.info.exports[&crate_type].is_empty() {
writeln!(f, " global:")?;
for sym in self.info.exports[&crate_type].iter() {
debug!(" {};", sym);
writeln!(f, " {};", sym)?;
}
}
writeln!(f, "\n local:\n *;\n}};")?;
};
Expand Down

0 comments on commit 1c4a9a9

Please sign in to comment.