diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 772d92a4f85..d2128810a8b 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -451,8 +451,6 @@ cgoptions!( "don't run LLVM's SLP vectorization pass"), soft_float: bool = (false, parse_bool, "generate software floating point library calls"), - gen_crate_map: bool = (false, parse_bool, - "force generation of a toplevel crate map"), prefer_dynamic: bool = (false, parse_bool, "prefer dynamic linking to static linking"), no_integrated_as: bool = (false, parse_bool, diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 67c597f927a..2ba408bfa00 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -254,8 +254,6 @@ lets_do_this! { TyVisitorTraitLangItem, "ty_visitor", ty_visitor; OpaqueStructLangItem, "opaque", opaque; - EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory; - TypeIdLangItem, "type_id", type_id; EhPersonalityLangItem, "eh_personality", eh_personality_fn; diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 2ba8121b479..8c20cf39b49 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -980,7 +980,7 @@ static other_attrs: &'static [&'static str] = &[ "thread_local", // for statics "allow", "deny", "forbid", "warn", // lint options "deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability - "crate_map", "cfg", "doc", "export_name", "link_section", + "cfg", "doc", "export_name", "link_section", "no_mangle", "static_assert", "unsafe_no_drop_flag", "packed", "simd", "repr", "deriving", "unsafe_destructor", "link", "phase", "macro_export", "must_use", "automatically_derived", diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a00bcdd7037..b5e64972115 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -76,7 +76,7 @@ use std::c_str::ToCStr; use std::cell::{Cell, RefCell}; use std::libc::c_uint; use std::local_data; -use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic, OsWin32}; +use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic}; use syntax::ast_map::PathName; use syntax::ast_util::{local_def, is_local}; use syntax::attr::AttrMetaMethods; @@ -2316,65 +2316,6 @@ pub fn symname(name: &str, hash: &str, vers: &str) -> ~str { link::exported_name(ast_map::Values(path.iter()).chain(None), hash, vers) } -pub fn decl_crate_map(ccx: &mut CrateContext) { - let mut n_subcrates = 1; - while ccx.sess().cstore.have_crate_data(n_subcrates) { - n_subcrates += 1; - } - let is_top = !ccx.sess().building_library.get() || ccx.sess().opts.cg.gen_crate_map; - let sym_name = if is_top { - ~"_rust_crate_map_toplevel" - } else { - symname("_rust_crate_map_" + ccx.link_meta.crateid.name, - ccx.link_meta.crate_hash.as_str(), - ccx.link_meta.crateid.version_or_default()) - }; - - let maptype = Type::struct_(ccx, [ - Type::i32(ccx), // version - ccx.int_type.ptr_to(), // event loop factory - ], false); - let map = sym_name.with_c_str(|buf| { - unsafe { - llvm::LLVMAddGlobal(ccx.llmod, maptype.to_ref(), buf) - } - }); - lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage); - - // On windows we'd like to export the toplevel cratemap - // such that we can find it from libstd. - if ccx.sess().targ_cfg.os == OsWin32 && is_top { - unsafe { llvm::LLVMRustSetDLLExportStorageClass(map) } - } - - ccx.crate_map_name = sym_name; - ccx.crate_map = map; -} - -pub fn fill_crate_map(ccx: &CrateContext, map: ValueRef) { - let event_loop_factory = match ccx.tcx.lang_items.event_loop_factory() { - Some(did) => unsafe { - if is_local(did) { - llvm::LLVMConstPointerCast(get_item_val(ccx, did.node), - ccx.int_type.ptr_to().to_ref()) - } else { - let name = csearch::get_symbol(&ccx.sess().cstore, did); - let global = name.with_c_str(|buf| { - llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type.to_ref(), buf) - }); - global - } - }, - None => C_null(ccx.int_type.ptr_to()) - }; - unsafe { - llvm::LLVMSetInitializer(map, C_struct(ccx, - [C_i32(ccx, 2), - event_loop_factory, - ], false)); - } -} - pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::EncodeInlinedItem<'r>) -> encoder::EncodeParams<'r> { @@ -2467,26 +2408,6 @@ pub fn trans_crate(krate: ast::Crate, trans_mod(&ccx, &krate.module); } - fill_crate_map(&ccx, ccx.crate_map); - - // win32: wart with exporting crate_map symbol - // We set the crate map (_rust_crate_map_toplevel) to use dll_export - // linkage but that ends up causing the linker to look for a - // __rust_crate_map_toplevel symbol (extra underscore) which it will - // subsequently fail to find. So to mitigate that we just introduce - // an alias from the symbol it expects to the one that actually exists. - if ccx.sess().targ_cfg.os == OsWin32 && !ccx.sess().building_library.get() { - - let maptype = val_ty(ccx.crate_map).to_ref(); - - "__rust_crate_map_toplevel".with_c_str(|buf| { - unsafe { - llvm::LLVMAddAlias(ccx.llmod, maptype, - ccx.crate_map, buf); - } - }) - } - glue::emit_tydescs(&ccx); if ccx.sess().opts.debuginfo != NoDebugInfo { debuginfo::finalize(&ccx); @@ -2537,7 +2458,6 @@ pub fn trans_crate(krate: ast::Crate, // symbol. This symbol is required for use by the libmorestack library that // we link in, so we must ensure that this symbol is not internalized (if // defined in the crate). - reachable.push(ccx.crate_map_name.to_owned()); reachable.push(~"main"); reachable.push(~"rust_stack_exhausted"); reachable.push(~"rust_eh_personality"); // referenced from .eh_frame section on some platforms diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index c542556c48f..a8ff0760eaa 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -22,7 +22,6 @@ use middle::trans::base; use middle::trans::builder::Builder; use middle::trans::common::{C_i32, C_null}; use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats}; -use middle::trans::base::{decl_crate_map}; use middle::trans::debuginfo; use middle::trans::type_::Type; use middle::ty; @@ -105,8 +104,6 @@ pub struct CrateContext { int_type: Type, opaque_vec_type: Type, builder: BuilderRef_res, - crate_map: ValueRef, - crate_map_name: ~str, // Set when at least one function uses GC. Needed so that // decl_gc_metadata knows whether to link to the module metadata, which // is not emitted by LLVM's GC pass when no functions use GC. @@ -200,8 +197,6 @@ impl CrateContext { int_type: Type::from_ref(ptr::null()), opaque_vec_type: Type::from_ref(ptr::null()), builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)), - crate_map: ptr::null(), - crate_map_name: ~"", uses_gc: false, dbg_cx: dbg_cx, }; @@ -215,8 +210,6 @@ impl CrateContext { str_slice_ty.set_struct_body([Type::i8p(&ccx), ccx.int_type], false); ccx.tn.associate_type("str_slice", &str_slice_ty); - decl_crate_map(&mut ccx); - base::declare_intrinsics(&mut ccx); if ccx.sess().count_llvm_insns() { diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 3fd677b34d9..4aa272a63a3 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -134,28 +134,6 @@ pub fn register_static(ccx: &CrateContext, let ty = ty::node_id_to_type(ccx.tcx(), foreign_item.id); let llty = type_of::type_of(ccx, ty); - // Treat the crate map static specially in order to - // a weak-linkage-like functionality where it's - // dynamically resolved at runtime. If we're - // building a library, then we declare the static - // with weak linkage, but if we're building a - // library then we've already declared the crate map - // so use that instead. - if attr::contains_name(foreign_item.attrs.as_slice(), "crate_map") { - return if ccx.sess().building_library.get() { - let s = "_rust_crate_map_toplevel"; - let g = unsafe { - s.with_c_str(|buf| { - llvm::LLVMAddGlobal(ccx.llmod, llty.to_ref(), buf) - }) - }; - lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage); - g - } else { - ccx.crate_map - } - } - let ident = link_name(foreign_item); match attr::first_attr_value_str_by_name(foreign_item.attrs.as_slice(), "linkage") { diff --git a/src/libstd/rt/crate_map.rs b/src/libstd/rt/crate_map.rs deleted file mode 100644 index 98f4986b2c7..00000000000 --- a/src/libstd/rt/crate_map.rs +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use cast; -use option::{Some, None, Option}; -use ptr::RawPtr; -use rt::rtio::EventLoop; - -// Need to tell the linker on OS X to not barf on undefined symbols -// and instead look them up at runtime, which we need to resolve -// the crate_map properly. -#[cfg(target_os = "macos")] -#[link_args = "-Wl,-U,__rust_crate_map_toplevel"] -extern {} - -pub struct CrateMap<'a> { - version: i32, - event_loop_factory: Option ~EventLoop>, -} - -// When working on android, apparently weak symbols don't work so well for -// finding the crate map, and neither does dlopen + dlsym. This is mainly a -// problem when integrating a shared library with an existing application. -// Standalone binaries do not appear to have this problem. The reasons are a -// little mysterious, and more information can be found in #11731. -// -// For now we provide a way to tell libstd about the crate map manually that's -// checked before the normal weak symbol/dlopen paths. In theory this is useful -// on other platforms where our dlopen/weak linkage strategy mysteriously fails -// but the crate map can be specified manually. -static mut MANUALLY_PROVIDED_CRATE_MAP: *CrateMap<'static> = - 0 as *CrateMap<'static>; -#[no_mangle] -#[cfg(not(test))] -pub extern fn rust_set_crate_map(map: *CrateMap<'static>) { - unsafe { MANUALLY_PROVIDED_CRATE_MAP = map; } -} - -fn manual_crate_map() -> Option<&'static CrateMap<'static>> { - unsafe { - if MANUALLY_PROVIDED_CRATE_MAP.is_null() { - None - } else { - Some(cast::transmute(MANUALLY_PROVIDED_CRATE_MAP)) - } - } -} - -#[cfg(not(windows))] -pub fn get_crate_map() -> Option<&'static CrateMap<'static>> { - extern { - #[crate_map] - static CRATE_MAP: CrateMap<'static>; - } - - manual_crate_map().or_else(|| { - let ptr: (*CrateMap) = &'static CRATE_MAP; - if ptr.is_null() { - None - } else { - Some(&'static CRATE_MAP) - } - }) -} - -#[cfg(windows)] -pub fn get_crate_map() -> Option<&'static CrateMap<'static>> { - use c_str::ToCStr; - use unstable::dynamic_lib::dl; - - match manual_crate_map() { - Some(cm) => return Some(cm), - None => {} - } - - let sym = unsafe { - let module = dl::open_internal(); - let rust_crate_map_toplevel = if cfg!(target_arch = "x86") { - "__rust_crate_map_toplevel" - } else { - "_rust_crate_map_toplevel" - }; - let sym = rust_crate_map_toplevel.with_c_str(|buf| { - dl::symbol(module, buf) - }); - dl::close(module); - sym - }; - let ptr: (*CrateMap) = sym as *CrateMap; - if ptr.is_null() { - return None; - } else { - unsafe { - return Some(cast::transmute(sym)); - } - } -} diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 84e547619df..795281026a4 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -104,9 +104,6 @@ pub mod env; /// The local, managed heap pub mod local_heap; -/// Crate map -pub mod crate_map; - /// The runtime needs to be able to put a pointer into thread-local storage. mod local_ptr; diff --git a/src/test/run-make/bootstrap-from-c-with-green/Makefile b/src/test/run-make/bootstrap-from-c-with-green/Makefile index 2144a2ca574..43388fd9a6f 100644 --- a/src/test/run-make/bootstrap-from-c-with-green/Makefile +++ b/src/test/run-make/bootstrap-from-c-with-green/Makefile @@ -1,7 +1,7 @@ -include ../tools.mk all: - $(RUSTC) lib.rs -C gen-crate-map + $(RUSTC) lib.rs ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot) $(CC) main.c -o $(call RUN,main) -lboot $(call RUN,main) diff --git a/src/test/run-make/bootstrap-from-c-with-native/Makefile b/src/test/run-make/bootstrap-from-c-with-native/Makefile index 2144a2ca574..43388fd9a6f 100644 --- a/src/test/run-make/bootstrap-from-c-with-native/Makefile +++ b/src/test/run-make/bootstrap-from-c-with-native/Makefile @@ -1,7 +1,7 @@ -include ../tools.mk all: - $(RUSTC) lib.rs -C gen-crate-map + $(RUSTC) lib.rs ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot) $(CC) main.c -o $(call RUN,main) -lboot $(call RUN,main) diff --git a/src/test/run-make/c-link-to-rust-staticlib/Makefile b/src/test/run-make/c-link-to-rust-staticlib/Makefile index 6fa5369015b..134d15f37aa 100644 --- a/src/test/run-make/c-link-to-rust-staticlib/Makefile +++ b/src/test/run-make/c-link-to-rust-staticlib/Makefile @@ -5,7 +5,7 @@ ifneq ($(shell uname),Darwin) endif all: - $(RUSTC) foo.rs -C gen-crate-map + $(RUSTC) foo.rs ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo) $(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++ $(call RUN,bar) diff --git a/src/test/run-make/c-set-crate-map-manually/Makefile b/src/test/run-make/c-set-crate-map-manually/Makefile deleted file mode 100644 index 954f10d3edd..00000000000 --- a/src/test/run-make/c-set-crate-map-manually/Makefile +++ /dev/null @@ -1,7 +0,0 @@ --include ../tools.mk - -all: - $(RUSTC) lib.rs -C gen-crate-map - ln -nsf $(call DYLIB,boot-*) $(call DYLIB,boot) - $(CC) main.c -o $(call RUN,main) -lboot -Wl,-rpath,$(TMPDIR) - RUST_LOG=boot $(call RUN,main) diff --git a/src/test/run-make/c-set-crate-map-manually/lib.rs b/src/test/run-make/c-set-crate-map-manually/lib.rs deleted file mode 100644 index d5bada4a127..00000000000 --- a/src/test/run-make/c-set-crate-map-manually/lib.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[crate_id="boot#0.1"]; -#[crate_type="dylib"]; -#[no_uv]; -#[feature(phase)]; - -extern crate rustuv; -extern crate green; -#[phase(syntax, link)] extern crate log; - -use std::rt::crate_map::{CrateMap, rust_set_crate_map}; - -// pull in this symbol from libstd into this crate (for convenience) -#[no_mangle] -pub static set_crate_map: extern "C" fn(*CrateMap<'static>) = rust_set_crate_map; - -#[no_mangle] // this needs to get called from C -pub extern "C" fn foo(argc: int, argv: **u8) -> int { - green::start(argc, argv, proc() { - if log_enabled!(log::DEBUG) { return } - fail!() - }) -} diff --git a/src/test/run-make/c-set-crate-map-manually/main.c b/src/test/run-make/c-set-crate-map-manually/main.c deleted file mode 100644 index a69ec7d0c86..00000000000 --- a/src/test/run-make/c-set-crate-map-manually/main.c +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// this is the rust entry point that we're going to call. -int foo(int argc, char *argv[]); - -extern void (*set_crate_map)(void *map); -extern int _rust_crate_map_toplevel; - -int main(int argc, char *argv[]) { - set_crate_map(&_rust_crate_map_toplevel); - return foo(argc, argv); -} diff --git a/src/test/run-make/lto-smoke-c/Makefile b/src/test/run-make/lto-smoke-c/Makefile index af120c9baeb..6a703927736 100644 --- a/src/test/run-make/lto-smoke-c/Makefile +++ b/src/test/run-make/lto-smoke-c/Makefile @@ -5,7 +5,7 @@ ifneq ($(shell uname),Darwin) endif all: - $(RUSTC) foo.rs -C gen-crate-map -Z lto + $(RUSTC) foo.rs -Z lto ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo) $(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++ $(call RUN,bar)