]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #9301 : luqmana/rust/ncm, r=brson
authorbors <bors@rust-lang.org>
Mon, 23 Sep 2013 22:46:05 +0000 (15:46 -0700)
committerbors <bors@rust-lang.org>
Mon, 23 Sep 2013 22:46:05 +0000 (15:46 -0700)
Get rid of the crate_map arg!

r? @brson

1  2 
src/librustc/middle/trans/base.rs
src/libstd/rt/mod.rs

index f7fcd8f908d714809109b70cdb803f127ace295a,4034d1ef8dd94370e514b9e4ff25e48052f1d7dc..441cc1bfae264cabff1b60ea61cf19edcfeecf26
@@@ -2388,12 -2388,38 +2388,12 @@@ pub fn create_entry_wrapper(ccx: @mut C
      let et = ccx.sess.entry_type.unwrap();
      match et {
          session::EntryMain => {
 -            let llfn = create_main(ccx, main_llfn);
 -            create_entry_fn(ccx, llfn, true);
 +            create_entry_fn(ccx, main_llfn, true);
          }
          session::EntryStart => create_entry_fn(ccx, main_llfn, false),
          session::EntryNone => {}    // Do nothing.
      }
  
 -    fn create_main(ccx: @mut CrateContext, main_llfn: ValueRef) -> ValueRef {
 -        let nt = ty::mk_nil();
 -        let llfty = type_of_rust_fn(ccx, [], nt);
 -        let llfdecl = decl_fn(ccx.llmod, "_rust_main",
 -                              lib::llvm::CCallConv, llfty);
 -
 -        let fcx = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
 -
 -        // the args vector built in create_entry_fn will need
 -        // be updated if this assertion starts to fail.
 -        assert!(!fcx.caller_expects_out_pointer);
 -
 -        let bcx = fcx.entry_bcx.unwrap();
 -        // Call main.
 -        let llenvarg = unsafe {
 -            let env_arg = fcx.env_arg_pos();
 -            llvm::LLVMGetParam(llfdecl, env_arg as c_uint)
 -        };
 -        let args = ~[llenvarg];
 -        Call(bcx, main_llfn, args, []);
 -
 -        finish_fn(fcx, bcx);
 -        return llfdecl;
 -    }
 -
      fn create_entry_fn(ccx: @mut CrateContext,
                         rust_main: ValueRef,
                         use_start_lang_item: bool) {
          unsafe {
              llvm::LLVMPositionBuilderAtEnd(bld, llbb);
  
-             let crate_map = ccx.crate_map;
-             let opaque_crate_map = do "crate_map".with_c_str |buf| {
-                 llvm::LLVMBuildPointerCast(bld, crate_map, Type::i8p().to_ref(), buf)
-             };
              let (start_fn, args) = if use_start_lang_item {
                  let start_def_id = match ccx.tcx.lang_items.require(StartFnLangItem) {
                      Ok(id) => id,
                          C_null(Type::opaque_box(ccx).ptr_to()),
                          opaque_rust_main,
                          llvm::LLVMGetParam(llfn, 0),
-                         llvm::LLVMGetParam(llfn, 1),
-                         opaque_crate_map
+                         llvm::LLVMGetParam(llfn, 1)
                       ]
                  };
                  (start_fn, args)
                  let args = ~[
                      C_null(Type::opaque_box(ccx).ptr_to()),
                      llvm::LLVMGetParam(llfn, 0 as c_uint),
-                     llvm::LLVMGetParam(llfn, 1 as c_uint),
-                     opaque_crate_map
+                     llvm::LLVMGetParam(llfn, 1 as c_uint)
                  ];
  
                  (rust_main, args)
@@@ -2635,13 -2654,16 +2628,16 @@@ pub fn get_item_val(ccx: @mut CrateCont
                          }
                          ast::foreign_item_static(*) => {
                              let ident = foreign::link_name(ccx, ni);
-                             let g = do ident.with_c_str |buf| {
-                                 unsafe {
+                             unsafe {
+                                 let g = do ident.with_c_str |buf| {
                                      let ty = type_of(ccx, ty);
                                      llvm::LLVMAddGlobal(ccx.llmod, ty.to_ref(), buf)
+                                 };
+                                 if attr::contains_name(ni.attrs, "weak_linkage") {
+                                     lib::llvm::SetLinkage(g, lib::llvm::ExternalWeakLinkage);
                                  }
-                             };
-                             g
+                                 g
+                             }
                          }
                      }
                  }
@@@ -2959,7 -2981,14 +2955,14 @@@ pub fn decl_crate_map(sess: session::Se
              llvm::LLVMAddGlobal(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 targ_cfg.os == session::OsWin32 && "toplevel" == mapname {
+         lib::llvm::SetLinkage(map, lib::llvm::DLLExportLinkage);
+     } else {
+         lib::llvm::SetLinkage(map, lib::llvm::ExternalLinkage);
+     }
      return map;
  }
  
@@@ -3114,6 -3143,26 +3117,26 @@@ pub fn trans_crate(sess: session::Sessi
  
      decl_gc_metadata(ccx, llmod_id);
      fill_crate_map(ccx, ccx.crate_map);
+     // NOTE 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 == session::OsWin32 &&
+        !*ccx.sess.building_library {
+         let maptype = val_ty(ccx.crate_map).to_ref();
+         do "__rust_crate_map_toplevel".with_c_str |buf| {
+             unsafe {
+                 llvm::LLVMAddAlias(ccx.llmod, maptype,
+                                    ccx.crate_map, buf);
+             }
+         }
+     }
      glue::emit_tydescs(ccx);
      write_abi_version(ccx);
      if ccx.sess.opts.debuginfo {
diff --combined src/libstd/rt/mod.rs
index df59e5538b40ad03ab193a409af9689157281316,1ad258c3edf6c461bcccf21ce43df58d6d43400e..85a379cab5a040b03a198a6bab6ec4b3cfa3e264
@@@ -54,8 -54,7 +54,8 @@@ Several modules in `core` are clients o
  
  */
  
 -#[doc(hidden)];
 +// XXX: this should not be here.
 +#[allow(missing_doc)];
  
  use cell::Cell;
  use clone::Clone;
@@@ -172,11 -171,11 +172,11 @@@ pub mod borrowck
  ///
  /// * `argc` & `argv` - The argument vector. On Unix this information is used
  ///   by os::args.
- /// * `crate_map` - Runtime information about the executing crate, mostly for logging
  ///
  /// # Return value
  ///
  /// The return value is used as the process return code. 0 on success, 101 on error.
+ #[cfg(stage0)]
  pub fn start(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
  
      init(argc, argv, crate_map);
  
      return exit_code;
  }
+ #[cfg(not(stage0))]
+ pub fn start(argc: int, argv: **u8, main: ~fn()) -> int {
+     init(argc, argv);
+     let exit_code = run(main);
+     cleanup();
+     return exit_code;
+ }
  
  /// Like `start` but creates an additional scheduler on the current thread,
  /// which in most cases will be the 'main' thread, and pins the main task to it.
  ///
  /// This is appropriate for running code that must execute on the main thread,
  /// such as the platform event loop and GUI.
+ #[cfg(stage0)]
  pub fn start_on_main_thread(argc: int, argv: **u8, crate_map: *u8, main: ~fn()) -> int {
      init(argc, argv, crate_map);
      let exit_code = run_on_main_thread(main);
  
      return exit_code;
  }
+ #[cfg(not(stage0))]
+ pub fn start_on_main_thread(argc: int, argv: **u8, main: ~fn()) -> int {
+     init(argc, argv);
+     let exit_code = run_on_main_thread(main);
+     cleanup();
+     return exit_code;
+ }
  
  /// One-time runtime initialization.
  ///
  /// Initializes global state, including frobbing
  /// the crate's logging flags, registering GC
  /// metadata, and storing the process arguments.
+ #[cfg(stage0)]
  pub fn init(argc: int, argv: **u8, crate_map: *u8) {
      // XXX: Derefing these pointers is not safe.
      // Need to propagate the unsafety to `start`.
          logging::init(crate_map);
      }
  }
+ #[cfg(not(stage0))]
+ pub fn init(argc: int, argv: **u8) {
+     // XXX: Derefing these pointers is not safe.
+     // Need to propagate the unsafety to `start`.
+     unsafe {
+         args::init(argc, argv);
+         env::init();
+         logging::init();
+     }
+ }
  
  /// One-time runtime cleanup.
  pub fn cleanup() {