Statically link librustrt to libstd

This commit alters the build process of the compiler to build a static
librustrt.a instead of a dynamic version. This means that we can stop
distributing librustrt as well as default linking against it in the compiler.

This also means that if you attempt to build rust code without libstd, it will
no longer work if there are any landing pads in play. The reason for this is
that LLVM and rustc will emit calls to the various upcalls in librustrt used to
manage exception handling. In theory we could split librustrt into librustrt and
librustupcall. We would then distribute librustupcall and link to it for all
programs using landing pads, but I would rather see just one librustrt artifact
and simplify the build process.

The major benefit of doing this is that building a static rust library for use
in embedded situations all of a sudden just became a whole lot more feasible.

Closes #3361
This commit is contained in:
Alex Crichton 2013-11-16 02:02:07 -08:00
parent e338a4154b
commit 9fbba7b2ee
36 changed files with 46 additions and 75 deletions

View File

@ -222,7 +222,7 @@ GENERATED :=
define DEF_LIBS
CFG_RUNTIME_$(1) :=$(call CFG_LIB_NAME_$(1),rustrt)
CFG_RUNTIME_$(1) :=$(call CFG_STATIC_LIB_NAME_$(1),rustrt)
CFG_RUSTLLVM_$(1) :=$(call CFG_LIB_NAME_$(1),rustllvm)
CFG_STDLIB_$(1) :=$(call CFG_LIB_NAME_$(1),std)
CFG_EXTRALIB_$(1) :=$(call CFG_LIB_NAME_$(1),extra)

View File

@ -88,7 +88,6 @@ install-target-$(1)-host-$(2): LIB_SOURCE_DIR=$$(TL$(1)$(2))
install-target-$(1)-host-$(2): LIB_DESTIN_DIR=$$(PTL$(1)$(2))
install-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
$$(Q)$$(call MK_INSTALL_DIR,$$(PTL$(1)$(2)))
$$(Q)$$(call INSTALL_LIB,$$(CFG_RUNTIME_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(STDLIB_GLOB_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(EXTRALIB_GLOB_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(LIBRUSTUV_GLOB_$(1)))
@ -101,7 +100,6 @@ install-target-$(1)-host-$(2): LIB_SOURCE_DIR=$$(TL$(1)$(2))
install-target-$(1)-host-$(2): LIB_DESTIN_DIR=$$(PTL$(1)$(2))
install-target-$(1)-host-$(2): $$(CSREQ$$(ISTAGE)_T_$(1)_H_$(2))
$$(Q)$$(call MK_INSTALL_DIR,$$(PTL$(1)$(2)))
$$(Q)$$(call INSTALL_LIB,$$(CFG_RUNTIME_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(CFG_RUSTLLVM_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(STDLIB_GLOB_$(1)))
$$(Q)$$(call INSTALL_LIB,$$(EXTRALIB_GLOB_$(1)))
@ -153,7 +151,6 @@ install-host: $(CSREQ$(ISTAGE)_T_$(CFG_BUILD_)_H_$(CFG_BUILD_))
$(Q)$(call INSTALL_LIB,$(LIBSYNTAX_GLOB_$(CFG_BUILD)))
$(Q)$(call INSTALL_LIB,$(LIBRUSTPKG_GLOB_$(CFG_BUILD)))
$(Q)$(call INSTALL_LIB,$(LIBRUSTDOC_GLOB_$(CFG_BUILD)))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME_$(CFG_BUILD)))
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM_$(CFG_BUILD)))
$(Q)$(call INSTALL,$(S)/man,$(CFG_MANDIR)/man1,rustc.1)
$(Q)$(call INSTALL,$(S)/man,$(CFG_MANDIR)/man1,rustdoc.1)
@ -170,7 +167,6 @@ uninstall:
$(Q)rm -f $(PHB)/rustpkg$(X_$(CFG_BUILD))
$(Q)rm -f $(PHB)/rustdoc$(X_$(CFG_BUILD))
$(Q)rm -f $(PHL)/$(CFG_RUSTLLVM_$(CFG_BUILD))
$(Q)rm -f $(PHL)/$(CFG_RUNTIME_$(CFG_BUILD))
$(Q)for i in \
$(call HOST_LIB_FROM_HL_GLOB,$(STDLIB_GLOB_$(CFG_BUILD))) \
$(call HOST_LIB_FROM_HL_GLOB,$(STDLIB_RGLOB_$(CFG_BUILD))) \
@ -238,7 +234,6 @@ endif
define INSTALL_RUNTIME_TARGET_N
install-runtime-target-$(1)-host-$(2): $$(TSREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
$(Q)$(call ADB_SHELL,mkdir,$(CFG_RUNTIME_PUSH_DIR))
$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(CFG_RUNTIME_$(1)),$(CFG_RUNTIME_PUSH_DIR))
$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(STDLIB_GLOB_$(1)),$(CFG_RUNTIME_PUSH_DIR))
$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(EXTRALIB_GLOB_$(1)),$(CFG_RUNTIME_PUSH_DIR))
$(Q)$(call ADB_PUSH,$$(TL$(1)$(2))/$$(LIBRUSTUV_GLOB_$(1)),$(CFG_RUNTIME_PUSH_DIR))
@ -247,7 +242,6 @@ endef
define INSTALL_RUNTIME_TARGET_CLEANUP_N
install-runtime-target-$(1)-cleanup:
$(Q)$(call ADB,remount)
$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(CFG_RUNTIME_$(1)))
$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(STDLIB_GLOB_$(1)))
$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(EXTRALIB_GLOB_$(1)))
$(Q)$(call ADB_SHELL,rm,$(CFG_RUNTIME_PUSH_DIR)/$(LIBRUSTUV_GLOB_$(1)))

View File

@ -121,11 +121,9 @@ $$(RT_BUILD_DIR_$(1)_$(2))/arch/$$(HOST_$(1))/libmorestack.a: $$(MORESTACK_OBJS_
@$$(call E, link: $$@)
$$(Q)$(AR_$(1)) rcs $$@ $$^
$$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS) \
$$(RUNTIME_DEF_$(1)_$(2))
$$(RT_BUILD_DIR_$(1)_$(2))/$(CFG_RUNTIME_$(1)): $$(RUNTIME_OBJS_$(1)_$(2)) $$(MKFILE_DEPS)
@$$(call E, link: $$@)
$$(Q)$$(call CFG_LINK_CXX_$(1),$$@, $$(RUNTIME_OBJS_$(1)_$(2)) \
$$(CFG_LIBUV_LINK_FLAGS_$(1)),$$(RUNTIME_DEF_$(1)_$(2)),$$(CFG_RUNTIME_$(1)))
$$(Q)$(AR_$(1)) rcs $$@ $$(RUNTIME_OBJS_$(1)_$(2))
# These could go in rt.mk or rustllvm.mk, they're needed for both.

View File

@ -31,7 +31,6 @@ snapshot_files = {
"lib/librustc-*.so",
"lib/libsyntax-*.so",
"lib/librustuv-*.so",
"lib/librustrt.so",
"lib/librustllvm.so"],
"macos": ["bin/rustc",
"lib/libstd-*.dylib",
@ -39,7 +38,6 @@ snapshot_files = {
"lib/librustc-*.dylib",
"lib/libsyntax-*.dylib",
"lib/librustuv-*.dylib",
"lib/librustrt.dylib",
"lib/librustllvm.dylib"],
"winnt": ["bin/rustc.exe",
"bin/std-*.dll",
@ -47,7 +45,6 @@ snapshot_files = {
"bin/rustc-*.dll",
"bin/syntax-*.dll",
"bin/rustuv-*.dll",
"bin/rustrt.dll",
"bin/rustllvm.dll"],
"freebsd": ["bin/rustc",
"lib/libstd-*.so",
@ -55,7 +52,6 @@ snapshot_files = {
"lib/librustc-*.so",
"lib/libsyntax-*.so",
"lib/librustuv-*.so",
"lib/librustrt.so",
"lib/librustllvm.so"]
}

View File

@ -13,7 +13,7 @@
//! necessary for running libstd.
// All platforms need to link to rustrt
#[link(name = "rustrt")]
#[link(name = "rustrt", kind = "static")]
extern {}
// LLVM implements the `frem` instruction as a call to `fmod`, which lives in
@ -26,6 +26,7 @@ extern {}
#[link(name = "dl")]
#[link(name = "m")]
#[link(name = "pthread")]
#[link(name = "stdc++")]
extern {}
#[cfg(target_os = "android")]
@ -45,4 +46,9 @@ extern {}
#[cfg(target_os = "macos")]
#[link(name = "pthread")]
#[link(name = "stdc++")]
extern {}
#[cfg(stage0)]
#[link_args = "-lstdc++"]
extern {}

View File

@ -1,51 +0,0 @@
rust_dbg_abi_1
rust_dbg_abi_2
rust_dbg_static_mut
rust_dbg_static_mut_check_four
rust_get_time
rust_tzset
rust_gmtime
rust_localtime
rust_timegm
rust_mktime
rust_precise_time_ns
rust_list_dir_val
rust_list_dir_wfd_size
rust_list_dir_wfd_fp_buf
rust_unset_sigprocmask
rust_env_pairs
rust_win32_rand_acquire
rust_win32_rand_gen
rust_win32_rand_release
upcall_rust_personality
upcall_reset_stack_limit
rust_dbg_call
rust_dbg_do_nothing
tdefl_compress_mem_to_heap
tinfl_decompress_mem_to_heap
rust_swap_registers
rust_readdir
rust_opendir
rust_dbg_extern_identity_u32
rust_dbg_extern_identity_u64
rust_dbg_extern_identity_TwoU8s
rust_dbg_extern_identity_TwoU16s
rust_dbg_extern_identity_TwoU32s
rust_dbg_extern_identity_TwoU64s
rust_dbg_extern_identity_TwoDoubles
rust_dbg_extern_return_TwoU8s
rust_dbg_extern_return_TwoU16s
rust_dbg_extern_return_TwoU32s
rust_dbg_extern_return_TwoU64s
rust_dbg_extern_identity_double
rust_dbg_extern_identity_u8
rust_try
rust_begin_unwind
rust_valgrind_stack_register
rust_valgrind_stack_deregister
rust_running_on_valgrind
rust_get_num_cpus
rust_get_test_int
rust_pthread_mutex_t_size
rust_pthread_cond_t_size
rust_crit_section_size

View File

@ -8,14 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[link_name = "rustrt"];
#[link(name = "anonexternmod",
vers = "0.1")];
#[link(name = "anonexternmod", vers = "0.1")];
#[crate_type = "lib"];
use std::libc;
extern {
#[link(name = "rustrt")]
pub fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -18,6 +18,7 @@ use std::libc;
pub mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -13,6 +13,7 @@
pub mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -14,6 +14,9 @@ extern mod anonexternmod;
use anonexternmod::rust_get_test_int;
#[link(name = "rustrt")] // we have explicitly chosen to require this
extern {}
pub fn main() {
unsafe {
rust_get_test_int();

View File

@ -10,7 +10,7 @@
use std::libc;
#[link_name = "rustrt"]
#[link(name = "rustrt")]
extern {
fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -11,6 +11,7 @@
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -13,6 +13,7 @@ use std::libc;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -14,6 +14,7 @@ use std::task;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -13,6 +13,7 @@ use std::libc;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -18,6 +18,7 @@ use std::task;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -18,6 +18,7 @@ struct TwoU16s {
one: u16, two: u16
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_TwoU16s(v: TwoU16s) -> TwoU16s;
}

View File

@ -16,6 +16,7 @@ struct TwoU32s {
one: u32, two: u32
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_TwoU32s(v: TwoU32s) -> TwoU32s;
}

View File

@ -18,6 +18,7 @@ struct TwoU64s {
one: u64, two: u64
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_TwoU64s(v: TwoU64s) -> TwoU64s;
}

View File

@ -18,6 +18,7 @@ struct TwoU8s {
one: u8, two: u8
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_TwoU8s(v: TwoU8s) -> TwoU8s;
}

View File

@ -10,6 +10,7 @@
// Test a function that takes/returns a u8.
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_u8(v: u8) -> u8;
}

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_double(v: f64) -> f64;
}

View File

@ -10,6 +10,7 @@
// Test a function that takes/returns a u32.
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_u32(v: u32) -> u32;
}

View File

@ -10,6 +10,7 @@
// Test a call to a function that takes/returns a u64.
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_identity_u64(v: u64) -> u64;
}

View File

@ -12,6 +12,7 @@ struct TwoU16s {
one: u16, two: u16
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_return_TwoU16s() -> TwoU16s;
}

View File

@ -12,6 +12,7 @@ struct TwoU32s {
one: u32, two: u32
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_return_TwoU32s() -> TwoU32s;
}

View File

@ -14,6 +14,7 @@ struct TwoU64s {
one: u64, two: u64
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_return_TwoU64s() -> TwoU64s;
}

View File

@ -12,6 +12,7 @@ struct TwoU8s {
one: u8, two: u8
}
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_extern_return_TwoU8s() -> TwoU8s;
}

View File

@ -17,6 +17,7 @@ use std::task;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -14,6 +14,7 @@ use std::task;
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_call(cb: extern "C" fn (libc::uintptr_t) -> libc::uintptr_t,
data: libc::uintptr_t)

View File

@ -2,6 +2,7 @@ use std::cast;
use std::libc;
use std::unstable::run_in_bare_thread;
#[link(name = "rustrt")]
extern {
fn rust_dbg_call(cb: extern "C" fn(libc::uintptr_t),
data: libc::uintptr_t) -> libc::uintptr_t;

View File

@ -14,7 +14,7 @@
mod rustrt1 {
use std::libc;
#[link_name = "rustrt"]
#[link(name = "rustrt")]
extern {
pub fn rust_get_test_int() -> libc::intptr_t;
}
@ -23,7 +23,7 @@ mod rustrt1 {
mod rustrt2 {
use std::libc;
#[link_name = "rustrt"]
#[link(name = "rustrt")]
extern {
pub fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -13,6 +13,7 @@
mod rustrt {
use std::libc;
#[link(name = "rustrt")]
extern {
pub fn rust_get_test_int() -> libc::intptr_t;
}

View File

@ -17,6 +17,9 @@
extern mod foreign_lib;
#[link(name = "rustrt")] // we have explicitly chosen to require this
extern {}
pub fn main() {
unsafe {
let _foo = foreign_lib::rustrt::rust_get_test_int();

View File

@ -14,7 +14,7 @@
use std::libc;
#[nolink]
#[link(name = "rustrt")]
extern {
static mut rust_dbg_static_mut: libc::c_int;
pub fn rust_dbg_static_mut_check_four();

View File

@ -16,7 +16,7 @@ pub struct Floats { a: f64, b: u8, c: f64 }
mod rustrt {
use super::{Floats, Quad};
#[nolink]
#[link(name = "rustrt")]
extern {
pub fn rust_dbg_abi_1(q: Quad) -> Quad;
pub fn rust_dbg_abi_2(f: Floats) -> Floats;