Skip to content

Commit 64ff30a

Browse files
committed
Add link_section attribute for static and fn items
This allows for control over the section placement of static, static mut, and fn items. One caveat is that if a static and a static mut are placed in the same section, the static is declared first, and the static mut is assigned to, the generated program crashes. For example: #[link_section=".boot"] static foo : uint = 0xdeadbeef; #[link_section=".boot"] static mut bar : uint = 0xcafebabe; Declaring bar first would mark .bootdata as writable, preventing the crash when bar is written to.
1 parent 74f4bad commit 64ff30a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/librustc/middle/trans/base.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
24562456
let val = match item {
24572457
ast_map::node_item(i, pth) => {
24582458
let my_path = vec::append((*pth).clone(), [path_name(i.ident)]);
2459-
match i.node {
2459+
let v = match i.node {
24602460
ast::item_static(_, m, expr) => {
24612461
let typ = ty::node_id_to_type(ccx.tcx, i.id);
24622462
let s = mangle_exported_name(ccx, my_path, typ);
@@ -2488,7 +2488,16 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::node_id) -> ValueRef {
24882488
llfn
24892489
}
24902490
_ => fail!("get_item_val: weird result in table")
2491+
};
2492+
match (attr::first_attr_value_str_by_name(i.attrs, "link_section")) {
2493+
Some(sect) => unsafe {
2494+
do sect.as_c_str |buf| {
2495+
llvm::LLVMSetSection(v, buf);
2496+
}
2497+
},
2498+
None => ()
24912499
}
2500+
v
24922501
}
24932502
ast_map::node_trait_method(trait_method, _, pth) => {
24942503
debug!("get_item_val(): processing a node_trait_method");

0 commit comments

Comments
 (0)