Skip to content

Commit 3ccad75

Browse files
committed
rustc: Remove all crate map support
The crate map is no longer necessary now that logging and event loop factories have been moved out. Closes #11617 Closes #11731
1 parent b19261a commit 3ccad75

File tree

15 files changed

+6
-285
lines changed

15 files changed

+6
-285
lines changed

src/librustc/driver/session.rs

-2
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,6 @@ cgoptions!(
451451
"don't run LLVM's SLP vectorization pass"),
452452
soft_float: bool = (false, parse_bool,
453453
"generate software floating point library calls"),
454-
gen_crate_map: bool = (false, parse_bool,
455-
"force generation of a toplevel crate map"),
456454
prefer_dynamic: bool = (false, parse_bool,
457455
"prefer dynamic linking to static linking"),
458456
no_integrated_as: bool = (false, parse_bool,

src/librustc/middle/lang_items.rs

-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ lets_do_this! {
254254
TyVisitorTraitLangItem, "ty_visitor", ty_visitor;
255255
OpaqueStructLangItem, "opaque", opaque;
256256

257-
EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory;
258-
259257
TypeIdLangItem, "type_id", type_id;
260258

261259
EhPersonalityLangItem, "eh_personality", eh_personality_fn;

src/librustc/middle/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ static other_attrs: &'static [&'static str] = &[
980980
"thread_local", // for statics
981981
"allow", "deny", "forbid", "warn", // lint options
982982
"deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
983-
"crate_map", "cfg", "doc", "export_name", "link_section",
983+
"cfg", "doc", "export_name", "link_section",
984984
"no_mangle", "static_assert", "unsafe_no_drop_flag", "packed",
985985
"simd", "repr", "deriving", "unsafe_destructor", "link", "phase",
986986
"macro_export", "must_use", "automatically_derived",

src/librustc/middle/trans/base.rs

+1-81
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use std::c_str::ToCStr;
7676
use std::cell::{Cell, RefCell};
7777
use std::libc::c_uint;
7878
use std::local_data;
79-
use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic, OsWin32};
79+
use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic};
8080
use syntax::ast_map::PathName;
8181
use syntax::ast_util::{local_def, is_local};
8282
use syntax::attr::AttrMetaMethods;
@@ -2316,65 +2316,6 @@ pub fn symname(name: &str, hash: &str, vers: &str) -> ~str {
23162316
link::exported_name(ast_map::Values(path.iter()).chain(None), hash, vers)
23172317
}
23182318

2319-
pub fn decl_crate_map(ccx: &mut CrateContext) {
2320-
let mut n_subcrates = 1;
2321-
while ccx.sess().cstore.have_crate_data(n_subcrates) {
2322-
n_subcrates += 1;
2323-
}
2324-
let is_top = !ccx.sess().building_library.get() || ccx.sess().opts.cg.gen_crate_map;
2325-
let sym_name = if is_top {
2326-
~"_rust_crate_map_toplevel"
2327-
} else {
2328-
symname("_rust_crate_map_" + ccx.link_meta.crateid.name,
2329-
ccx.link_meta.crate_hash.as_str(),
2330-
ccx.link_meta.crateid.version_or_default())
2331-
};
2332-
2333-
let maptype = Type::struct_(ccx, [
2334-
Type::i32(ccx), // version
2335-
ccx.int_type.ptr_to(), // event loop factory
2336-
], false);
2337-
let map = sym_name.with_c_str(|buf| {
2338-
unsafe {
2339-
llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf)
2340-
}
2341-
});
2342-
lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
2343-
2344-
// On windows we'd like to export the toplevel cratemap
2345-
// such that we can find it from libstd.
2346-
if ccx.sess().targ_cfg.os == OsWin32 && is_top {
2347-
unsafe { llvm::LLVMRustSetDLLExportStorageClass(map) }
2348-
}
2349-
2350-
ccx.crate_map_name = sym_name;
2351-
ccx.crate_map = map;
2352-
}
2353-
2354-
pub fn fill_crate_map(ccx: &CrateContext, map: ValueRef) {
2355-
let event_loop_factory = match ccx.tcx.lang_items.event_loop_factory() {
2356-
Some(did) => unsafe {
2357-
if is_local(did) {
2358-
llvm::LLVMConstPointerCast(get_item_val(ccx, did.node),
2359-
ccx.int_type.ptr_to().to_ref())
2360-
} else {
2361-
let name = csearch::get_symbol(&ccx.sess().cstore, did);
2362-
let global = name.with_c_str(|buf| {
2363-
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf)
2364-
});
2365-
global
2366-
}
2367-
},
2368-
None => C_null(ccx.int_type.ptr_to())
2369-
};
2370-
unsafe {
2371-
llvm::LLVMSetInitializer(map, C_struct(ccx,
2372-
[C_i32(ccx, 2),
2373-
event_loop_factory,
2374-
], false));
2375-
}
2376-
}
2377-
23782319
pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::EncodeInlinedItem<'r>)
23792320
-> encoder::EncodeParams<'r> {
23802321

@@ -2467,26 +2408,6 @@ pub fn trans_crate(krate: ast::Crate,
24672408
trans_mod(&ccx, &krate.module);
24682409
}
24692410

2470-
fill_crate_map(&ccx, ccx.crate_map);
2471-
2472-
// win32: wart with exporting crate_map symbol
2473-
// We set the crate map (_rust_crate_map_toplevel) to use dll_export
2474-
// linkage but that ends up causing the linker to look for a
2475-
// __rust_crate_map_toplevel symbol (extra underscore) which it will
2476-
// subsequently fail to find. So to mitigate that we just introduce
2477-
// an alias from the symbol it expects to the one that actually exists.
2478-
if ccx.sess().targ_cfg.os == OsWin32 && !ccx.sess().building_library.get() {
2479-
2480-
let maptype = val_ty(ccx.crate_map).to_ref();
2481-
2482-
"__rust_crate_map_toplevel".with_c_str(|buf| {
2483-
unsafe {
2484-
llvm::LLVMAddAlias(ccx.llmod, maptype,
2485-
ccx.crate_map, buf);
2486-
}
2487-
})
2488-
}
2489-
24902411
glue::emit_tydescs(&ccx);
24912412
if ccx.sess().opts.debuginfo != NoDebugInfo {
24922413
debuginfo::finalize(&ccx);
@@ -2537,7 +2458,6 @@ pub fn trans_crate(krate: ast::Crate,
25372458
// symbol. This symbol is required for use by the libmorestack library that
25382459
// we link in, so we must ensure that this symbol is not internalized (if
25392460
// defined in the crate).
2540-
reachable.push(ccx.crate_map_name.to_owned());
25412461
reachable.push(~"main");
25422462
reachable.push(~"rust_stack_exhausted");
25432463
reachable.push(~"rust_eh_personality"); // referenced from .eh_frame section on some platforms

src/librustc/middle/trans/context.rs

-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use middle::trans::base;
2222
use middle::trans::builder::Builder;
2323
use middle::trans::common::{C_i32, C_null};
2424
use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats};
25-
use middle::trans::base::{decl_crate_map};
2625
use middle::trans::debuginfo;
2726
use middle::trans::type_::Type;
2827
use middle::ty;
@@ -105,8 +104,6 @@ pub struct CrateContext {
105104
int_type: Type,
106105
opaque_vec_type: Type,
107106
builder: BuilderRef_res,
108-
crate_map: ValueRef,
109-
crate_map_name: ~str,
110107
// Set when at least one function uses GC. Needed so that
111108
// decl_gc_metadata knows whether to link to the module metadata, which
112109
// is not emitted by LLVM's GC pass when no functions use GC.
@@ -200,8 +197,6 @@ impl CrateContext {
200197
int_type: Type::from_ref(ptr::null()),
201198
opaque_vec_type: Type::from_ref(ptr::null()),
202199
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
203-
crate_map: ptr::null(),
204-
crate_map_name: ~"",
205200
uses_gc: false,
206201
dbg_cx: dbg_cx,
207202
};
@@ -215,8 +210,6 @@ impl CrateContext {
215210
str_slice_ty.set_struct_body([Type::i8p(&ccx), ccx.int_type], false);
216211
ccx.tn.associate_type("str_slice", &str_slice_ty);
217212

218-
decl_crate_map(&mut ccx);
219-
220213
base::declare_intrinsics(&mut ccx);
221214

222215
if ccx.sess().count_llvm_insns() {

src/librustc/middle/trans/foreign.rs

-22
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,6 @@ pub fn register_static(ccx: &CrateContext,
134134
let ty = ty::node_id_to_type(ccx.tcx(), foreign_item.id);
135135
let llty = type_of::type_of(ccx, ty);
136136

137-
// Treat the crate map static specially in order to
138-
// a weak-linkage-like functionality where it's
139-
// dynamically resolved at runtime. If we're
140-
// building a library, then we declare the static
141-
// with weak linkage, but if we're building a
142-
// library then we've already declared the crate map
143-
// so use that instead.
144-
if attr::contains_name(foreign_item.attrs.as_slice(), "crate_map") {
145-
return if ccx.sess().building_library.get() {
146-
let s = "_rust_crate_map_toplevel";
147-
let g = unsafe {
148-
s.with_c_str(|buf| {
149-
llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf)
150-
})
151-
};
152-
lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage);
153-
g
154-
} else {
155-
ccx.crate_map
156-
}
157-
}
158-
159137
let ident = link_name(foreign_item);
160138
match attr::first_attr_value_str_by_name(foreign_item.attrs.as_slice(),
161139
"linkage") {

src/libstd/rt/crate_map.rs

-104
This file was deleted.

src/libstd/rt/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ pub mod env;
104104
/// The local, managed heap
105105
pub mod local_heap;
106106

107-
/// Crate map
108-
pub mod crate_map;
109-
110107
/// The runtime needs to be able to put a pointer into thread-local storage.
111108
mod local_ptr;
112109

src/test/run-make/bootstrap-from-c-with-green/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) lib.rs -C gen-crate-map
4+
$(RUSTC) lib.rs
55
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
66
$(CC) main.c -o $(call RUN,main) -lboot
77
$(call RUN,main)

src/test/run-make/bootstrap-from-c-with-native/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-include ../tools.mk
22

33
all:
4-
$(RUSTC) lib.rs -C gen-crate-map
4+
$(RUSTC) lib.rs
55
ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot)
66
$(CC) main.c -o $(call RUN,main) -lboot
77
$(call RUN,main)

src/test/run-make/c-link-to-rust-staticlib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ifneq ($(shell uname),Darwin)
55
endif
66

77
all:
8-
$(RUSTC) foo.rs -C gen-crate-map
8+
$(RUSTC) foo.rs
99
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
1010
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
1111
$(call RUN,bar)

src/test/run-make/c-set-crate-map-manually/Makefile

-7
This file was deleted.

src/test/run-make/c-set-crate-map-manually/lib.rs

-32
This file was deleted.

0 commit comments

Comments
 (0)