Skip to content

Commit 3b66f74

Browse files
zslaytonZack Slayton
authored andcommitted
---
yaml --- r: 108942 b: refs/heads/dist-snap c: 9e0cfa2 h: refs/heads/master v: v3
1 parent ebe31cb commit 3b66f74

File tree

13 files changed

+326
-244
lines changed

13 files changed

+326
-244
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 9f3ebd8fc50682d6e4ef549cb31e70171acdcd71
9+
refs/heads/dist-snap: 9e0cfa23e8b3d2d17302eefd9d728e63e7c6c108
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/front/feature_gate.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5353
("simd", Active),
5454
("default_type_params", Active),
5555
("quote", Active),
56-
("linkage", Active),
5756

5857
// These are used to test this portion of the compiler, they don't actually
5958
// mean anything
@@ -239,19 +238,6 @@ impl Visitor<()> for Context {
239238
}
240239
}
241240

242-
fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
243-
match i.node {
244-
ast::ForeignItemFn(..) | ast::ForeignItemStatic(..) => {
245-
if attr::contains_name(i.attrs.as_slice(), "linkage") {
246-
self.gate_feature("linkage", i.span,
247-
"the `linkage` attribute is experimental \
248-
and not portable across platforms")
249-
}
250-
}
251-
}
252-
visit::walk_foreign_item(self, i, ())
253-
}
254-
255241
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
256242
match t.node {
257243
ast::TyClosure(closure) if closure.onceness == ast::Once &&

branches/dist-snap/src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static other_attrs: &'static [&'static str] = &[
983983

984984
// fn-level
985985
"test", "bench", "should_fail", "ignore", "inline", "lang", "main", "start",
986-
"no_split_stack", "cold", "macro_registrar", "linkage",
986+
"no_split_stack", "cold", "macro_registrar",
987987

988988
// internal attribute: bypass privacy inside items
989989
"!resolve_unexported",

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
21072107
}
21082108

21092109
ast_map::NodeForeignItem(ni) => {
2110+
let ty = ty::node_id_to_type(ccx.tcx, ni.id);
21102111
foreign = true;
21112112

21122113
match ni.node {
@@ -2115,7 +2116,41 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
21152116
foreign::register_foreign_item_fn(ccx, abis, ni)
21162117
}
21172118
ast::ForeignItemStatic(..) => {
2118-
foreign::register_static(ccx, ni)
2119+
// Treat the crate map static specially in order to
2120+
// a weak-linkage-like functionality where it's
2121+
// dynamically resolved at runtime. If we're
2122+
// building a library, then we declare the static
2123+
// with weak linkage, but if we're building a
2124+
// library then we've already declared the crate map
2125+
// so use that instead.
2126+
if attr::contains_name(ni.attrs.as_slice(),
2127+
"crate_map") {
2128+
if ccx.sess.building_library.get() {
2129+
let s = "_rust_crate_map_toplevel";
2130+
let g = unsafe {
2131+
s.with_c_str(|buf| {
2132+
let ty = type_of(ccx, ty);
2133+
llvm::LLVMAddGlobal(ccx.llmod,
2134+
ty.to_ref(),
2135+
buf)
2136+
})
2137+
};
2138+
lib::llvm::SetLinkage(g,
2139+
lib::llvm::ExternalWeakLinkage);
2140+
g
2141+
} else {
2142+
ccx.crate_map
2143+
}
2144+
} else {
2145+
let ident = foreign::link_name(ni);
2146+
unsafe {
2147+
ident.get().with_c_str(|buf| {
2148+
let ty = type_of(ccx, ty);
2149+
llvm::LLVMAddGlobal(ccx.llmod,
2150+
ty.to_ref(), buf)
2151+
})
2152+
}
2153+
}
21192154
}
21202155
}
21212156
}

branches/dist-snap/src/librustc/middle/trans/foreign.rs

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use back::{link};
1313
use lib::llvm::llvm;
14-
use lib::llvm::{ValueRef, CallConv, StructRetAttribute, Linkage};
14+
use lib::llvm::{ValueRef, CallConv, StructRetAttribute};
1515
use lib;
1616
use middle::trans::base::push_ctxt;
1717
use middle::trans::base;
@@ -105,105 +105,6 @@ pub fn llvm_calling_convention(ccx: &CrateContext,
105105
})
106106
}
107107

108-
pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
109-
// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
110-
// applicable to variable declarations and may not really make sense for
111-
// Rust code in the first place but whitelist them anyway and trust that
112-
// the user knows what s/he's doing. Who knows, unanticipated use cases
113-
// may pop up in the future.
114-
//
115-
// ghost, dllimport, dllexport and linkonce_odr_autohide are not supported
116-
// and don't have to be, LLVM treats them as no-ops.
117-
match name {
118-
"appending" => Some(lib::llvm::AppendingLinkage),
119-
"available_externally" => Some(lib::llvm::AvailableExternallyLinkage),
120-
"common" => Some(lib::llvm::CommonLinkage),
121-
"extern_weak" => Some(lib::llvm::ExternalWeakLinkage),
122-
"external" => Some(lib::llvm::ExternalLinkage),
123-
"internal" => Some(lib::llvm::InternalLinkage),
124-
"linker_private" => Some(lib::llvm::LinkerPrivateLinkage),
125-
"linker_private_weak" => Some(lib::llvm::LinkerPrivateWeakLinkage),
126-
"linkonce" => Some(lib::llvm::LinkOnceAnyLinkage),
127-
"linkonce_odr" => Some(lib::llvm::LinkOnceODRLinkage),
128-
"private" => Some(lib::llvm::PrivateLinkage),
129-
"weak" => Some(lib::llvm::WeakAnyLinkage),
130-
"weak_odr" => Some(lib::llvm::WeakODRLinkage),
131-
_ => None,
132-
}
133-
}
134-
135-
pub fn register_static(ccx: @CrateContext,
136-
foreign_item: @ast::ForeignItem) -> ValueRef {
137-
let ty = ty::node_id_to_type(ccx.tcx, foreign_item.id);
138-
let llty = type_of::type_of(ccx, ty);
139-
140-
// Treat the crate map static specially in order to
141-
// a weak-linkage-like functionality where it's
142-
// dynamically resolved at runtime. If we're
143-
// building a library, then we declare the static
144-
// with weak linkage, but if we're building a
145-
// library then we've already declared the crate map
146-
// so use that instead.
147-
if attr::contains_name(foreign_item.attrs.as_slice(), "crate_map") {
148-
return if ccx.sess.building_library.get() {
149-
let s = "_rust_crate_map_toplevel";
150-
let g = unsafe {
151-
s.with_c_str(|buf| {
152-
llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf)
153-
})
154-
};
155-
lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage);
156-
g
157-
} else {
158-
ccx.crate_map
159-
}
160-
}
161-
162-
let ident = link_name(foreign_item);
163-
match attr::first_attr_value_str_by_name(foreign_item.attrs.as_slice(),
164-
"linkage") {
165-
// If this is a static with a linkage specified, then we need to handle
166-
// it a little specially. The typesystem prevents things like &T and
167-
// extern "C" fn() from being non-null, so we can't just declare a
168-
// static and call it a day. Some linkages (like weak) will make it such
169-
// that the static actually has a null value.
170-
Some(name) => {
171-
let linkage = match llvm_linkage_by_name(name.get()) {
172-
Some(linkage) => linkage,
173-
None => {
174-
ccx.sess.span_fatal(foreign_item.span,
175-
"invalid linkage specified");
176-
}
177-
};
178-
let llty2 = match ty::get(ty).sty {
179-
ty::ty_ptr(ref mt) => type_of::type_of(ccx, mt.ty),
180-
_ => {
181-
ccx.sess.span_fatal(foreign_item.span,
182-
"must have type `*T` or `*mut T`");
183-
}
184-
};
185-
unsafe {
186-
let g1 = ident.get().with_c_str(|buf| {
187-
llvm::LLVMAddGlobal(ccx.llmod, llty2.to_ref(), buf)
188-
});
189-
lib::llvm::SetLinkage(g1, linkage);
190-
191-
let real_name = "_rust_extern_with_linkage_" + ident.get();
192-
let g2 = real_name.with_c_str(|buf| {
193-
llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf)
194-
});
195-
lib::llvm::SetLinkage(g2, lib::llvm::InternalLinkage);
196-
llvm::LLVMSetInitializer(g2, g1);
197-
g2
198-
}
199-
}
200-
None => unsafe {
201-
ident.get().with_c_str(|buf| {
202-
llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf)
203-
})
204-
}
205-
}
206-
}
207108

208109
pub fn register_foreign_item_fn(ccx: @CrateContext, abis: AbiSet,
209110
foreign_item: @ast::ForeignItem) -> ValueRef {

0 commit comments

Comments
 (0)