From c7f4f3ad75997c495de1ec91b6d714d1653412dd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 2 Oct 2018 13:49:51 -0700 Subject: wasm: Explicitly export all symbols with LLD This commit fixes an oddity on the wasm target where LTO can produce working executables but plain old optimizations doesn't. The compiler already knows what set of symbols it would like to export, but LLD only discovers this list transitively through symbol visibilities. LLD may not, however, always find all the symbols that we'd like to export. For example if you depend on an rlib with a `#[no_mangle]` symbol, then if you don't actually use anything from the rlib then the symbol won't appear in the final artifact! It will appear, however, with LTO. This commit attempts to rectify this situation by ensuring that all symbols rustc would otherwise preserve through LTO are also preserved through the linking process with LLD by default. --- src/librustc_codegen_llvm/back/linker.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/librustc_codegen_llvm') diff --git a/src/librustc_codegen_llvm/back/linker.rs b/src/librustc_codegen_llvm/back/linker.rs index c03180c02fe..e18c8b9dec4 100644 --- a/src/librustc_codegen_llvm/back/linker.rs +++ b/src/librustc_codegen_llvm/back/linker.rs @@ -89,6 +89,7 @@ impl LinkerInfo { Box::new(WasmLd { cmd, sess, + info: self }) as Box } } @@ -926,6 +927,7 @@ fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec { pub struct WasmLd<'a> { cmd: Command, sess: &'a Session, + info: &'a LinkerInfo, } impl<'a> Linker for WasmLd<'a> { @@ -1021,7 +1023,10 @@ impl<'a> Linker for WasmLd<'a> { fn build_dylib(&mut self, _out_filename: &Path) { } - fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType) { + fn export_symbols(&mut self, _tmpdir: &Path, crate_type: CrateType) { + for sym in self.info.exports[&crate_type].iter() { + self.cmd.arg("--export").arg(&sym); + } } fn subsystem(&mut self, _subsystem: &str) { -- cgit 1.4.1-3-g733a5