@@ -2416,11 +2416,6 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24162416 unsafe {
24172417 llvm:: LLVMPositionBuilderAtEnd ( bld, llbb) ;
24182418
2419- let crate_map = ccx. crate_map ;
2420- let opaque_crate_map = do "crate_map" . with_c_str |buf| {
2421- llvm:: LLVMBuildPointerCast ( bld, crate_map, Type :: i8p ( ) . to_ref ( ) , buf)
2422- } ;
2423-
24242419 let ( start_fn, args) = if use_start_lang_item {
24252420 let start_def_id = match ccx. tcx . lang_items . require ( StartFnLangItem ) {
24262421 Ok ( id) => id,
@@ -2443,8 +2438,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24432438 C_null ( Type :: opaque_box ( ccx) . ptr_to ( ) ) ,
24442439 opaque_rust_main,
24452440 llvm:: LLVMGetParam ( llfn, 0 ) ,
2446- llvm:: LLVMGetParam ( llfn, 1 ) ,
2447- opaque_crate_map
2441+ llvm:: LLVMGetParam ( llfn, 1 )
24482442 ]
24492443 } ;
24502444 ( start_fn, args)
@@ -2453,8 +2447,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
24532447 let args = ~[
24542448 C_null ( Type :: opaque_box ( ccx) . ptr_to ( ) ) ,
24552449 llvm:: LLVMGetParam ( llfn, 0 as c_uint ) ,
2456- llvm:: LLVMGetParam ( llfn, 1 as c_uint ) ,
2457- opaque_crate_map
2450+ llvm:: LLVMGetParam ( llfn, 1 as c_uint )
24582451 ] ;
24592452
24602453 ( rust_main, args)
@@ -2635,13 +2628,16 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
26352628 }
26362629 ast:: foreign_item_static( * ) => {
26372630 let ident = foreign:: link_name ( ccx, ni) ;
2638- let g = do ident . with_c_str |buf| {
2639- unsafe {
2631+ unsafe {
2632+ let g = do ident . with_c_str |buf| {
26402633 let ty = type_of ( ccx, ty) ;
26412634 llvm:: LLVMAddGlobal ( ccx. llmod , ty. to_ref ( ) , buf)
2635+ } ;
2636+ if attr:: contains_name ( ni. attrs , "weak_linkage" ) {
2637+ lib:: llvm:: SetLinkage ( g, lib:: llvm:: ExternalWeakLinkage ) ;
26422638 }
2643- } ;
2644- g
2639+ g
2640+ }
26452641 }
26462642 }
26472643 }
@@ -2959,7 +2955,14 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
29592955 llvm:: LLVMAddGlobal ( llmod, maptype. to_ref ( ) , buf)
29602956 }
29612957 } ;
2962- lib:: llvm:: SetLinkage ( map, lib:: llvm:: ExternalLinkage ) ;
2958+ // On windows we'd like to export the toplevel cratemap
2959+ // such that we can find it from libstd.
2960+ if targ_cfg. os == session:: OsWin32 && "toplevel" == mapname {
2961+ lib:: llvm:: SetLinkage ( map, lib:: llvm:: DLLExportLinkage ) ;
2962+ } else {
2963+ lib:: llvm:: SetLinkage ( map, lib:: llvm:: ExternalLinkage ) ;
2964+ }
2965+
29632966 return map;
29642967}
29652968
@@ -3114,6 +3117,26 @@ pub fn trans_crate(sess: session::Session,
31143117
31153118 decl_gc_metadata ( ccx, llmod_id) ;
31163119 fill_crate_map ( ccx, ccx. crate_map ) ;
3120+
3121+ // NOTE win32: wart with exporting crate_map symbol
3122+ // We set the crate map (_rust_crate_map_toplevel) to use dll_export
3123+ // linkage but that ends up causing the linker to look for a
3124+ // __rust_crate_map_toplevel symbol (extra underscore) which it will
3125+ // subsequently fail to find. So to mitigate that we just introduce
3126+ // an alias from the symbol it expects to the one that actually exists.
3127+ if ccx. sess . targ_cfg . os == session:: OsWin32 &&
3128+ !* ccx. sess . building_library {
3129+
3130+ let maptype = val_ty ( ccx. crate_map ) . to_ref ( ) ;
3131+
3132+ do "__rust_crate_map_toplevel" . with_c_str |buf| {
3133+ unsafe {
3134+ llvm:: LLVMAddAlias ( ccx. llmod , maptype,
3135+ ccx. crate_map , buf) ;
3136+ }
3137+ }
3138+ }
3139+
31173140 glue:: emit_tydescs ( ccx) ;
31183141 write_abi_version ( ccx) ;
31193142 if ccx. sess . opts . debuginfo {
0 commit comments