Skip to content

Commit f7a2371

Browse files
committed
auto merge of #5614 : graydon/rust/static-linkage-bug, r=catamorphism
re bug that @nikomatsakis was hitting: when you define a `static` (old: `const`) containing a `&` or `&[]` expression, it will create temporaries (the underlying pointee) by creating a throwaway symbol for each temporary, each with _global_ linkage, and each named `"const"`. LLVM will helpfully rename multiple copies of this throwaway symbol to `"const1"` and `"const2"` and so forth in the _same_ library. But if you have _2 libraries_ -- say, libcore and librustc -- that both do this, the dynamic linker (at least on linux) will happily do horrible things like make the slice in one library point to the bytes of the vector from the other library. This is obviously a recipe for much hilarity and head-scratching. The solution is to change the linkage to something else, internal or (in the case of this patch) _private_. It will require a snapshot to integrate this into stage0 and thereby fix the problem / unblock patches that were hitting this in stage1.
2 parents d98a195 + 1163f69 commit f7a2371

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: src/librustc/middle/trans/consts.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
use core::prelude::*;
1212

1313
use back::abi;
14-
use lib::llvm::{llvm, ValueRef, TypeRef, Bool, True, False};
14+
use lib::llvm::{llvm, SetLinkage, InternalLinkage, PrivateLinkage,
15+
ValueRef, TypeRef, Bool, True, False};
1516
use metadata::csearch;
1617
use middle::const_eval;
1718
use middle::trans::adt;
@@ -104,6 +105,7 @@ fn const_addr_of(cx: @CrateContext, cv: ValueRef) -> ValueRef {
104105
};
105106
llvm::LLVMSetInitializer(gv, cv);
106107
llvm::LLVMSetGlobalConstant(gv, True);
108+
SetLinkage(gv, PrivateLinkage);
107109
gv
108110
}
109111
}
@@ -483,6 +485,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: @ast::expr) -> ValueRef {
483485
};
484486
llvm::LLVMSetInitializer(gv, cv);
485487
llvm::LLVMSetGlobalConstant(gv, True);
488+
SetLinkage(gv, PrivateLinkage);
486489
let p = const_ptrcast(cx, gv, llunitty);
487490
C_struct(~[p, sz])
488491
}

0 commit comments

Comments
 (0)