Skip to content

Commit 1c4a9a9

Browse files
authored
Rollup merge of #63965 - loganwendholt:linker-script-fix, r=michaelwoerister
Prevent syntax error in LD linker version script As discussed in #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.
2 parents f0e2895 + 42bd6fa commit 1c4a9a9

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,13 @@ impl<'a> Linker for GccLinker<'a> {
430430
// Write an LD version script
431431
let res: io::Result<()> = try {
432432
let mut f = BufWriter::new(File::create(&path)?);
433-
writeln!(f, "{{\n global:")?;
434-
for sym in self.info.exports[&crate_type].iter() {
435-
debug!(" {};", sym);
436-
writeln!(f, " {};", sym)?;
433+
writeln!(f, "{{")?;
434+
if !self.info.exports[&crate_type].is_empty() {
435+
writeln!(f, " global:")?;
436+
for sym in self.info.exports[&crate_type].iter() {
437+
debug!(" {};", sym);
438+
writeln!(f, " {};", sym)?;
439+
}
437440
}
438441
writeln!(f, "\n local:\n *;\n}};")?;
439442
};

0 commit comments

Comments
 (0)