Skip to content

Commit

Permalink
Mark the metadata symbol as reachable to fix OSX not finding dylibs.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb authored and alexcrichton committed May 19, 2016
1 parent 07d373f commit 0d2c26c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 0d2c26c

Please sign in to comment.