Skip to content

Commit 133200a

Browse files
committed
libstd/librustc: Make the crate_map a weak symbol that libstd links against.
1 parent 9621156 commit 133200a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,17 +2652,18 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
26522652
let path = vec::append((*pth).clone(), [path_name(ni.ident)]);
26532653
foreign::register_foreign_item_fn(ccx, abis, &path, ni)
26542654
}
2655-
ast::foreign_item_static(*) if attr::contains_name(ni.attrs, "crate_map")
2656-
=> ccx.crate_map,
26572655
ast::foreign_item_static(*) => {
26582656
let ident = foreign::link_name(ccx, ni);
2659-
let g = do ident.with_c_str |buf| {
2660-
unsafe {
2657+
unsafe {
2658+
let g = do ident.with_c_str |buf| {
26612659
let ty = type_of(ccx, ty);
26622660
llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf)
2661+
};
2662+
if attr::contains_name(ni.attrs, "weak_linkage") {
2663+
lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage);
26632664
}
2664-
};
2665-
g
2665+
g
2666+
}
26662667
}
26672668
}
26682669
}

src/libstd/rt/crate_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use container::MutableSet;
1818

1919
extern {
2020
#[cfg(not(stage0))]
21-
#[crate_map]
21+
#[weak_linkage]
22+
#[link_name = "_rust_crate_map_toplevel"]
2223
static CRATE_MAP: CrateMap;
2324
}
2425

0 commit comments

Comments
 (0)