llvm::LLVMAddGlobal(llmod, maptype.to_ref(), buf)
}
};
- lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
+ // On windows we'd like to export the toplevel cratemap
+ // such that we can find it from libstd.
+ if targ_cfg.os == session::OsWin32 && "toplevel" == mapname {
+ lib::llvm::SetLinkage(map, lib::llvm::DLLExportLinkage);
+ } else {
+ lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
+ }
+
return map;
}
decl_gc_metadata(ccx, llmod_id);
fill_crate_map(ccx, ccx.crate_map);
+
+ // NOTE win32: wart with exporting crate_map symbol
+ // We set the crate map (_rust_crate_map_toplevel) to use dll_export
+ // linkage but that ends up causing the linker to look for a
+ // __rust_crate_map_toplevel symbol (extra underscore) which it will
+ // subsequently fail to find. So to mitigate that we just introduce
+ // an alias from the symbol it expects to the one that actually exists.
+ if ccx.sess.targ_cfg.os == session::OsWin32 &&
+ !*ccx.sess.building_library {
+
+ let maptype = val_ty(ccx.crate_map).to_ref();
+
+ do "__rust_crate_map_toplevel".with_c_str |buf| {
+ unsafe {
+ llvm::LLVMAddAlias(ccx.llmod, maptype,
+ ccx.crate_map, buf);
+ }
+ }
+ }
+
glue::emit_tydescs(ccx);
write_abi_version(ccx);
if ccx.sess.opts.debuginfo {
#[link_args = "-undefined dynamic_lookup"]
extern {}
+#[cfg(not(stage0), not(windows))]
extern {
- #[cfg(not(stage0))]
#[weak_linkage]
#[link_name = "_rust_crate_map_toplevel"]
static CRATE_MAP: CrateMap;
children: [*CrateMap, ..1]
}
-#[cfg(not(stage0))]
+#[cfg(not(stage0), not(windows))]
pub fn get_crate_map() -> *CrateMap {
&'static CRATE_MAP as *CrateMap
}
+#[cfg(not(stage0), windows)]
+#[fixed_stack_segment]
+#[inline(never)]
+pub fn get_crate_map() -> *CrateMap {
+ use c_str::ToCStr;
+ use unstable::dynamic_lib::dl;
+
+ let sym = unsafe {
+ let module = dl::open_internal();
+ let sym = do "__rust_crate_map_toplevel".with_c_str |buf| {
+ dl::symbol(module, buf)
+ };
+ dl::close(module);
+ sym
+ };
+
+ sym as *CrateMap
+}
+
unsafe fn version(crate_map: *CrateMap) -> i32 {
match (*crate_map).version {
1 => return 1,