From 0d2c26c261671f71002af13431fbd3c9720feff2 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Mon, 16 May 2016 20:05:43 +0300 Subject: [PATCH] Mark the metadata symbol as reachable to fix OSX not finding dylibs. --- src/librustc_trans/base.rs | 8 +++++--- src/librustc_trans/context.rs | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 21aba6fcb53d7..942975e971966 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -2508,9 +2508,7 @@ pub fn write_metadata<'a, 'tcx>(cx: &SharedCrateContext<'a, 'tcx>, let llmeta = C_bytes_in_context(cx.metadata_llcx(), &compressed[..]); let llconst = C_struct_in_context(cx.metadata_llcx(), &[llmeta], false); - let name = format!("rust_metadata_{}_{}", - cx.link_meta().crate_name, - cx.link_meta().crate_hash); + let name = cx.metadata_symbol_name(); let buf = CString::new(name).unwrap(); let llglobal = unsafe { llvm::LLVMAddGlobal(cx.metadata_llmod(), val_ty(llconst).to_ref(), buf.as_ptr()) @@ -2812,6 +2810,10 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, reachable_symbols.push("main".to_string()); } + if sess.crate_types.borrow().contains(&config::CrateTypeDylib) { + reachable_symbols.push(shared_ccx.metadata_symbol_name()); + } + // For the purposes of LTO or when creating a cdylib, we add to the // reachable set all of the upstream reachable extern fns. These functions // are all part of the public ABI of the final product, so we need to diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 60c6af84ebbb6..4d6c4cdcc6b07 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -503,6 +503,12 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { Substs::new(VecPerParamSpace::empty(), scheme.generics.regions.map(|_| ty::ReStatic))) } + + pub fn metadata_symbol_name(&self) -> String { + format!("rust_metadata_{}_{}", + self.link_meta().crate_name, + self.link_meta().crate_hash) + } } impl<'tcx> LocalCrateContext<'tcx> {