Skip to content

Commit 2bd8075

Browse files
committed
Continue tightening holes in reachability
* Don't flag any address_insignificant statics as reachable because the whole point of the address_insignificant optimization is that the static is not reachable. Additionally, there's no need for it to be reachable because LLVM optimizes it away. * Be sure to not leak external node ids into our reachable set, this can spuriously cause local items to be considered reachable if the node ids just happen to line up
1 parent 18084be commit 2bd8075

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

src/librustc/middle/reachable.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,44 @@ impl Visitor<()> for MarkSymbolVisitor {
128128
};
129129

130130
let def_id = def_id_of_def(def);
131-
if ReachableContext::
132-
def_id_represents_local_inlined_item(self.tcx, def_id) {
133-
self.worklist.push(def_id.node)
131+
if is_local(def_id) {
132+
if ReachableContext::
133+
def_id_represents_local_inlined_item(self.tcx, def_id) {
134+
self.worklist.push(def_id.node)
135+
} else {
136+
match def {
137+
// If this path leads to a static, then we may have
138+
// to do some work to figure out whether the static
139+
// is indeed reachable (address_insignificant
140+
// statics are *never* reachable).
141+
ast::DefStatic(..) => {
142+
self.worklist.push(def_id.node);
143+
}
144+
145+
// If this wasn't a static, then this destination is
146+
// surely reachable.
147+
_ => {
148+
self.reachable_symbols.insert(def_id.node);
149+
}
150+
}
134151
}
135-
self.reachable_symbols.insert(def_id.node);
152+
}
136153
}
137154
ast::ExprMethodCall(..) => {
138155
match self.method_map.find(&expr.id) {
139156
Some(&typeck::method_map_entry {
140157
origin: typeck::method_static(def_id),
141158
..
142159
}) => {
143-
if ReachableContext::
144-
def_id_represents_local_inlined_item(
145-
self.tcx,
146-
def_id) {
147-
self.worklist.push(def_id.node)
148-
}
149-
self.reachable_symbols.insert(def_id.node);
160+
if is_local(def_id) {
161+
if ReachableContext::
162+
def_id_represents_local_inlined_item(
163+
self.tcx,
164+
def_id) {
165+
self.worklist.push(def_id.node)
166+
}
167+
self.reachable_symbols.insert(def_id.node);
168+
}
150169
}
151170
Some(_) => {}
152171
None => {
@@ -310,10 +329,19 @@ impl ReachableContext {
310329
}
311330
}
312331

332+
// Statics with insignificant addresses are not reachable
333+
// because they're inlined specially into all other crates.
334+
ast::item_static(..) => {
335+
if attr::contains_name(item.attrs,
336+
"address_insignificant") {
337+
self.reachable_symbols.remove(&search_item);
338+
}
339+
}
340+
313341
// These are normal, nothing reachable about these
314342
// inherently and their children are already in the
315343
// worklist, as determined by the privacy pass
316-
ast::item_static(..) | ast::item_ty(..) |
344+
ast::item_ty(..) |
317345
ast::item_mod(..) | ast::item_foreign_mod(..) |
318346
ast::item_impl(..) | ast::item_trait(..) |
319347
ast::item_struct(..) | ast::item_enum(..) => {}

src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,9 +2521,12 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25212521
// requested
25222522
if attr::contains_name(i.attrs,
25232523
"address_insignificant"){
2524+
if ccx.reachable.contains(&id) {
2525+
ccx.sess.span_bug(i.span,
2526+
"insignificant static is \
2527+
reachable");
2528+
}
25242529
lib::llvm::SetUnnamedAddr(g, true);
2525-
lib::llvm::SetLinkage(g,
2526-
lib::llvm::InternalLinkage);
25272530

25282531
// This is a curious case where we must make
25292532
// all of these statics inlineable. If a

0 commit comments

Comments
 (0)