diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-05-16 20:05:43 +0300 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-05-19 15:32:03 -0700 |
| commit | 0d2c26c261671f71002af13431fbd3c9720feff2 (patch) | |
| tree | 29da516f1e9fe87e252d8dc47da6ea660f003226 | |
| parent | 07d373f3d6e616058864afd963f6f7bb518249a4 (diff) | |
| download | rust-0d2c26c261671f71002af13431fbd3c9720feff2.tar.gz rust-0d2c26c261671f71002af13431fbd3c9720feff2.zip | |
Mark the metadata symbol as reachable to fix OSX not finding dylibs.
| -rw-r--r-- | src/librustc_trans/base.rs | 8 | ||||
| -rw-r--r-- | 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 21aba6fcb53..942975e9719 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 60c6af84ebb..4d6c4cdcc6b 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> { |
