@@ -2416,11 +2416,6 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
2416
2416
unsafe {
2417
2417
llvm:: LLVMPositionBuilderAtEnd ( bld, llbb) ;
2418
2418
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
-
2424
2419
let ( start_fn, args) = if use_start_lang_item {
2425
2420
let start_def_id = match ccx. tcx . lang_items . require ( StartFnLangItem ) {
2426
2421
Ok ( id) => id,
@@ -2443,8 +2438,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
2443
2438
C_null ( Type :: opaque_box ( ccx) . ptr_to ( ) ) ,
2444
2439
opaque_rust_main,
2445
2440
llvm:: LLVMGetParam ( llfn, 0 ) ,
2446
- llvm:: LLVMGetParam ( llfn, 1 ) ,
2447
- opaque_crate_map
2441
+ llvm:: LLVMGetParam ( llfn, 1 )
2448
2442
]
2449
2443
} ;
2450
2444
( start_fn, args)
@@ -2453,8 +2447,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
2453
2447
let args = ~[
2454
2448
C_null ( Type :: opaque_box ( ccx) . ptr_to ( ) ) ,
2455
2449
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 )
2458
2451
] ;
2459
2452
2460
2453
( rust_main, args)
@@ -2635,13 +2628,16 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
2635
2628
}
2636
2629
ast:: foreign_item_static( * ) => {
2637
2630
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| {
2640
2633
let ty = type_of ( ccx, ty) ;
2641
2634
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 ) ;
2642
2638
}
2643
- } ;
2644
- g
2639
+ g
2640
+ }
2645
2641
}
2646
2642
}
2647
2643
}
@@ -2959,7 +2955,14 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta,
2959
2955
llvm:: LLVMAddGlobal ( llmod, maptype. to_ref ( ) , buf)
2960
2956
}
2961
2957
} ;
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
+
2963
2966
return map;
2964
2967
}
2965
2968
@@ -3114,6 +3117,26 @@ pub fn trans_crate(sess: session::Session,
3114
3117
3115
3118
decl_gc_metadata ( ccx, llmod_id) ;
3116
3119
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
+
3117
3140
glue:: emit_tydescs ( ccx) ;
3118
3141
write_abi_version ( ccx) ;
3119
3142
if ccx. sess . opts . debuginfo {
0 commit comments