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
This commit is contained in:
commit
c44534ef5a
1 changed files with 40 additions and 20 deletions
|
@ -247,29 +247,49 @@ impl<'a> Linker for GnuLinker<'a> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = tmpdir.join("list");
|
|
||||||
let prefix = if self.sess.target.target.options.is_like_osx {
|
|
||||||
"_"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
let res = (|| -> io::Result<()> {
|
|
||||||
let mut f = BufWriter::new(File::create(&path)?);
|
|
||||||
for sym in &self.info.cdylib_exports {
|
|
||||||
writeln!(f, "{}{}", prefix, sym)?;
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})();
|
|
||||||
if let Err(e) = res {
|
|
||||||
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
|
|
||||||
}
|
|
||||||
let mut arg = OsString::new();
|
let mut arg = OsString::new();
|
||||||
if self.sess.target.target.options.is_like_osx {
|
let path = tmpdir.join("list");
|
||||||
arg.push("-Wl,-exported_symbols_list,");
|
|
||||||
|
if self.sess.target.target.options.is_like_solaris {
|
||||||
|
let res = (|| -> io::Result<()> {
|
||||||
|
let mut f = BufWriter::new(File::create(&path)?);
|
||||||
|
writeln!(f, "{{\n global:")?;
|
||||||
|
for sym in &self.info.cdylib_exports {
|
||||||
|
writeln!(f, " {};", sym)?;
|
||||||
|
}
|
||||||
|
writeln!(f, "\n local:\n *;\n}};")?;
|
||||||
|
Ok(())
|
||||||
|
})();
|
||||||
|
if let Err(e) = res {
|
||||||
|
self.sess.fatal(&format!("failed to write version script: {}", e));
|
||||||
|
}
|
||||||
|
|
||||||
|
arg.push("-Wl,-M,");
|
||||||
|
arg.push(&path);
|
||||||
} else {
|
} else {
|
||||||
arg.push("-Wl,--retain-symbols-file=");
|
let prefix = if self.sess.target.target.options.is_like_osx {
|
||||||
|
"_"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
let res = (|| -> io::Result<()> {
|
||||||
|
let mut f = BufWriter::new(File::create(&path)?);
|
||||||
|
for sym in &self.info.cdylib_exports {
|
||||||
|
writeln!(f, "{}{}", prefix, sym)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})();
|
||||||
|
if let Err(e) = res {
|
||||||
|
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
|
||||||
|
}
|
||||||
|
if self.sess.target.target.options.is_like_osx {
|
||||||
|
arg.push("-Wl,-exported_symbols_list,");
|
||||||
|
} else {
|
||||||
|
arg.push("-Wl,--retain-symbols-file=");
|
||||||
|
}
|
||||||
|
arg.push(&path);
|
||||||
}
|
}
|
||||||
arg.push(&path);
|
|
||||||
self.cmd.arg(arg);
|
self.cmd.arg(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue