Skip to content

Commit c44534e

Browse files
authoredAug 22, 2016
Auto merge of #35821 - nbaksalyar:solaris-trans-fix, r=alexcrichton
Fix linker on Solaris/Illumos This patch provides a fix for the `GnuLinker::export_symbols` function that currently relies on a `--retain-symbols-file` option which is not supported by the Solaris & Illumos linker. Instead, a [version script](https://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html) is used on this platform to achieve the same goal. Here's an example of a similar approach in LLVM's CMake script: https://github.com/llvm-mirror/llvm/blob/master/cmake/modules/AddLLVM.cmake#L88-L94. Perhaps other platforms like OpenBSD could benefit from this as well. /cc @semarie
2 parents 42584d3 + c08b7b9 commit c44534e

File tree

1 file changed

+39
-19
lines changed

1 file changed

+39
-19
lines changed
 

‎src/librustc_trans/back/linker.rs

+39-19
Original file line numberDiff line numberDiff line change
@@ -247,29 +247,49 @@ impl<'a> Linker for GnuLinker<'a> {
247247
return
248248
}
249249

250+
let mut arg = OsString::new();
250251
let path = tmpdir.join("list");
251-
let prefix = if self.sess.target.target.options.is_like_osx {
252-
"_"
253-
} else {
254-
""
255-
};
256-
let res = (|| -> io::Result<()> {
257-
let mut f = BufWriter::new(File::create(&path)?);
258-
for sym in &self.info.cdylib_exports {
259-
writeln!(f, "{}{}", prefix, sym)?;
252+
253+
if self.sess.target.target.options.is_like_solaris {
254+
let res = (|| -> io::Result<()> {
255+
let mut f = BufWriter::new(File::create(&path)?);
256+
writeln!(f, "{{\n global:")?;
257+
for sym in &self.info.cdylib_exports {
258+
writeln!(f, " {};", sym)?;
259+
}
260+
writeln!(f, "\n local:\n *;\n}};")?;
261+
Ok(())
262+
})();
263+
if let Err(e) = res {
264+
self.sess.fatal(&format!("failed to write version script: {}", e));
260265
}
261-
Ok(())
262-
})();
263-
if let Err(e) = res {
264-
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
265-
}
266-
let mut arg = OsString::new();
267-
if self.sess.target.target.options.is_like_osx {
268-
arg.push("-Wl,-exported_symbols_list,");
266+
267+
arg.push("-Wl,-M,");
268+
arg.push(&path);
269269
} else {
270-
arg.push("-Wl,--retain-symbols-file=");
270+
let prefix = if self.sess.target.target.options.is_like_osx {
271+
"_"
272+
} else {
273+
""
274+
};
275+
let res = (|| -> io::Result<()> {
276+
let mut f = BufWriter::new(File::create(&path)?);
277+
for sym in &self.info.cdylib_exports {
278+
writeln!(f, "{}{}", prefix, sym)?;
279+
}
280+
Ok(())
281+
})();
282+
if let Err(e) = res {
283+
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
284+
}
285+
if self.sess.target.target.options.is_like_osx {
286+
arg.push("-Wl,-exported_symbols_list,");
287+
} else {
288+
arg.push("-Wl,--retain-symbols-file=");
289+
}
290+
arg.push(&path);
271291
}
272-
arg.push(&path);
292+
273293
self.cmd.arg(arg);
274294
}
275295
}

0 commit comments

Comments
 (0)
Please sign in to comment.