Skip to content

Commit

Permalink
Add the asmjs-unknown-emscripten triple. Add cfgs to libs.
Browse files Browse the repository at this point in the history
Backtraces, and the compilation of libbacktrace for asmjs, are disabled.

This port doesn't use jemalloc so, like pnacl, it disables jemalloc *for all targets*
in the configure file.

It disables stack protection.
  • Loading branch information
brson committed Feb 6, 2016
1 parent 34af2de commit d6c0d85
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 19 deletions.
6 changes: 6 additions & 0 deletions configure
Expand Up @@ -1305,6 +1305,12 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
putvar CFG_DISABLE_JEMALLOC
;;

*-emscripten)
step_msg "targeting emscripten, disabling jemalloc"
CFG_DISABLE_JEMALLOC=1
putvar CFG_DISABLE_JEMALLOC
;;

*)
;;
esac
Expand Down
23 changes: 23 additions & 0 deletions mk/cfg/asmjs-unknown-emscripten.mk
@@ -0,0 +1,23 @@
# asmjs-unknown-emscripten configuration
CC_asmjs-unknown-emscripten=emcc
CXX_asmjs-unknown-emscripten=em++
CPP_asmjs-unknown-emscripten=$(CPP)
AR_asmjs-unknown-emscripten=emar
CFG_LIB_NAME_asmjs-unknown-emscripten=lib$(1).so
CFG_STATIC_LIB_NAME_asmjs-unknown-emscripten=lib$(1).a
CFG_LIB_GLOB_asmjs-unknown-emscripten=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_asmjs-unknown-emscripten=lib$(1)-*.dylib.dSYM
CFG_JEMALLOC_CFLAGS_asmjs-unknown-emscripten := -m32 $(CFLAGS)
CFG_GCCISH_CFLAGS_asmjs-unknown-emscripten := -Wall -Werror -g -fPIC -m32 $(CFLAGS)
CFG_GCCISH_CXXFLAGS_asmjs-unknown-emscripten := -fno-rtti $(CXXFLAGS)
CFG_GCCISH_LINK_FLAGS_asmjs-unknown-emscripten := -shared -fPIC -ldl -pthread -lrt -g -m32
CFG_GCCISH_DEF_FLAG_asmjs-unknown-emscripten := -Wl,--export-dynamic,--dynamic-list=
CFG_LLC_FLAGS_asmjs-unknown-emscripten :=
CFG_INSTALL_NAME_asmjs-unknown-emscripten =
CFG_EXE_SUFFIX_asmjs-unknown-emscripten =
CFG_WINDOWSY_asmjs-unknown-emscripten :=
CFG_UNIXY_asmjs-unknown-emscripten := 1
CFG_LDPATH_asmjs-unknown-emscripten :=
CFG_RUN_asmjs-unknown-emscripten=$(2)
CFG_RUN_TARG_asmjs-unknown-emscripten=$(call CFG_RUN_asmjs-unknown-emscripten,,$(2))
CFG_GNU_TRIPLE_asmjs-unknown-emscripten := asmjs-unknown-emscripten
19 changes: 19 additions & 0 deletions mk/rt.mk
Expand Up @@ -254,6 +254,15 @@ ifeq ($$(findstring freebsd,$(1)),freebsd)
COMPRT_CFLAGS_$(1) += -I/usr/include/c++/v1
endif

ifeq ($$(findstring emscripten,$(1)),emscripten)

# FIXME: emscripten doesn't use compiler-rt and can't build it without
# further hacks
$$(COMPRT_LIB_$(1)):
touch $$@

else

$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
@$$(call E, make: compiler-rt)
$$(Q)$$(MAKE) -C "$(S)src/compiler-rt" \
Expand All @@ -266,7 +275,10 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS)
TargetTriple=$(1) \
triple-builtins
$$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@

endif # if emscripten
endif

################################################################################
# libbacktrace
#
Expand Down Expand Up @@ -301,6 +313,12 @@ $$(BACKTRACE_LIB_$(1)):
touch $$@
else

ifeq ($$(findstring emscripten,$(1)),emscripten)
# FIXME: libbacktrace doesn't understand the emscripten triple
$$(BACKTRACE_LIB_$(1)):
touch $$@
else

ifdef CFG_ENABLE_FAST_MAKE
BACKTRACE_DEPS := $(S)/.gitmodules
else
Expand Down Expand Up @@ -348,6 +366,7 @@ $$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
INCDIR=$(S)src/libbacktrace
$$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@

endif # endif for emscripten
endif # endif for msvc
endif # endif for ios
endif # endif for darwin
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc_system/lib.rs
Expand Up @@ -30,7 +30,8 @@ extern crate libc;
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "powerpc64")))]
target_arch = "powerpc64",
target_arch = "asmjs")))]
const MIN_ALIGN: usize = 8;
#[cfg(all(any(target_arch = "x86_64",
target_arch = "aarch64")))]
Expand Down
37 changes: 37 additions & 0 deletions src/librustc_back/target/asmjs_unknown_emscripten.rs
@@ -0,0 +1,37 @@
// Copyright 2015 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::{Target, TargetOptions};

pub fn target() -> Target {
let opts = TargetOptions {
linker: "emcc".to_string(),
ar: "emar".to_string(),

dynamic_linking: false,
executables: true,
exe_suffix: ".js".to_string(),
no_compiler_rt: true,
linker_is_gnu: true,
allow_asm: false,
archive_format: "gnu".to_string(),
.. Default::default()
};
Target {
llvm_target: "asmjs-unknown-emscripten".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "32".to_string(),
target_os: "emscripten".to_string(),
target_env: "".to_string(),
target_vendor: "unknown".to_string(),
arch: "asmjs".to_string(),
options: opts,
}
}
3 changes: 2 additions & 1 deletion src/librustc_back/target/mod.rs
Expand Up @@ -461,7 +461,8 @@ impl Target {
x86_64_pc_windows_msvc,
i686_pc_windows_msvc,

le32_unknown_nacl
le32_unknown_nacl,
asmjs_unknown_emscripten
);


Expand Down
2 changes: 2 additions & 0 deletions src/librustc_trans/trans/cabi.rs
Expand Up @@ -21,6 +21,7 @@ use trans::cabi_aarch64;
use trans::cabi_powerpc;
use trans::cabi_powerpc64;
use trans::cabi_mips;
use trans::cabi_asmjs;
use trans::type_::Type;

#[derive(Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -129,6 +130,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
"powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
"powerpc64" => cabi_powerpc64::compute_abi_info(ccx, atys, rty, ret_def),
"asmjs" => cabi_asmjs::compute_abi_info(ccx, atys, rty, ret_def),
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)
),
}
Expand Down
22 changes: 22 additions & 0 deletions src/librustc_trans/trans/cabi_asmjs.rs
@@ -0,0 +1,22 @@
// Copyright 2012-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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use trans::cabi::FnType;
use trans::cabi_arm;
use trans::context::CrateContext;
use trans::type_::Type;

pub fn compute_abi_info(ccx: &CrateContext,
atys: &[Type],
rty: Type,
ret_def: bool) -> FnType {
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def,
cabi_arm::Flavor::General)
}
1 change: 1 addition & 0 deletions src/librustc_trans/trans/mod.rs
Expand Up @@ -30,6 +30,7 @@ mod builder;
mod cabi;
mod cabi_aarch64;
mod cabi_arm;
mod cabi_asmjs;
mod cabi_mips;
mod cabi_powerpc;
mod cabi_powerpc64;
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/dynamic_lib.rs
Expand Up @@ -197,7 +197,8 @@ mod tests {
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
target_os = "solaris",
target_os = "emscripten"))]
mod dl {
use prelude::v1::*;

Expand Down
16 changes: 16 additions & 0 deletions src/libstd/env.rs
Expand Up @@ -844,6 +844,17 @@ mod os {
pub const EXE_EXTENSION: &'static str = "pexe";
}

#[cfg(target_os = "emscripten")]
mod os {
pub const FAMILY: &'static str = "unix";
pub const OS: &'static str = "emscripten";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const DLL_EXTENSION: &'static str = "so";
pub const EXE_SUFFIX: &'static str = ".js";
pub const EXE_EXTENSION: &'static str = "js";
}

#[cfg(target_arch = "x86")]
mod arch {
pub const ARCH: &'static str = "x86";
Expand Down Expand Up @@ -884,6 +895,11 @@ mod arch {
pub const ARCH: &'static str = "le32";
}

#[cfg(target_arch = "asmjs")]
mod arch {
pub const ARCH: &'static str = "asmjs";
}

#[cfg(test)]
mod tests {
use prelude::v1::*;
Expand Down
12 changes: 10 additions & 2 deletions src/libstd/os/linux/raw.rs
Expand Up @@ -26,15 +26,23 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
#[cfg(any(target_arch = "x86",
target_arch = "le32",
target_arch = "powerpc",
target_arch = "arm"))]
target_arch = "arm",
target_arch = "asmjs"))]
mod arch {
use super::{dev_t, mode_t};
use os::raw::{c_long, c_short};
use os::unix::raw::{gid_t, uid_t};

#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32;
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32;
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32;

#[stable(feature = "raw_ext", since = "1.1.0")]
#[cfg(not(any(target_env = "musl", target_arch = "asmjs")))]
pub type ino_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
#[cfg(any(target_env = "musl", target_arch = "asmjs"))]
pub type ino_t = u64;

#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32;
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/os/mod.rs
Expand Up @@ -32,4 +32,9 @@ pub use sys::ext as windows;
#[cfg(target_os = "openbsd")] pub mod openbsd;
#[cfg(target_os = "solaris")] pub mod solaris;

// Emscripten is just like linux
#[cfg(target_os = "emscripten")]
#[path = "linux/mod.rs"]
pub mod emscripten;

pub mod raw;
2 changes: 2 additions & 0 deletions src/libstd/os/raw.rs
Expand Up @@ -13,12 +13,14 @@
#![stable(feature = "raw_os", since = "1.1.0")]

#[cfg(any(target_os = "android",
target_os = "emscripten",
all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "powerpc64"))))]
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
#[cfg(not(any(target_os = "android",
target_os = "emscripten",
all(target_os = "linux", any(target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/sys/common/args.rs
Expand Up @@ -39,7 +39,8 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
target_os = "solaris",
target_os = "emscripten"))]
mod imp {
use prelude::v1::*;

Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/common/libunwind.rs
Expand Up @@ -86,6 +86,10 @@ pub const unwinder_private_data_size: usize = 2;
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(target_arch = "asmjs")]
// FIXME: Copied from arm. Need to confirm.
pub const unwinder_private_data_size: usize = 20;

#[repr(C)]
pub struct _Unwind_Exception {
pub exception_class: _Unwind_Exception_Class,
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/mod.rs
Expand Up @@ -45,7 +45,7 @@ pub mod unwind;
pub mod util;
pub mod wtf8;

#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))),
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
all(windows, target_env = "gnu")))]
pub mod gnu;

Expand Down
6 changes: 4 additions & 2 deletions src/libstd/sys/unix/backtrace/printing/mod.rs
Expand Up @@ -10,10 +10,12 @@

pub use self::imp::print;

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "emscripten"))]
#[path = "dladdr.rs"]
mod imp;

#[cfg(not(any(target_os = "macos", target_os = "ios")))]
#[cfg(not(any(target_os = "macos", target_os = "ios",
target_os = "emscripten")))]
#[path = "gnu.rs"]
mod imp;
6 changes: 4 additions & 2 deletions src/libstd/sys/unix/fs.rs
Expand Up @@ -293,7 +293,8 @@ impl DirEntry {
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "linux",
target_os = "solaris"))]
target_os = "solaris",
target_os = "emscripten"))]
pub fn ino(&self) -> raw::ino_t {
self.entry.d_ino
}
Expand Down Expand Up @@ -326,7 +327,8 @@ impl DirEntry {
}
}
#[cfg(any(target_os = "android",
target_os = "linux"))]
target_os = "linux",
target_os = "emscripten"))]
fn name_bytes(&self) -> &[u8] {
unsafe {
CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes()
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/mod.rs
Expand Up @@ -26,6 +26,7 @@ use ops::Neg;
#[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
#[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
#[cfg(target_os = "solaris")] pub use os::solaris as platform;
#[cfg(target_os = "emscripten")] pub use os::emscripten as platform;

pub mod backtrace;
pub mod condvar;
Expand Down
8 changes: 5 additions & 3 deletions src/libstd/sys/unix/os.rs
Expand Up @@ -38,7 +38,8 @@ static ENV_LOCK: StaticMutex = StaticMutex::new();
/// Returns the platform-specific value of errno
pub fn errno() -> i32 {
extern {
#[cfg_attr(any(target_os = "linux"), link_name = "__errno_location")]
#[cfg_attr(any(target_os = "linux", target_os = "emscripten"),
link_name = "__errno_location")]
#[cfg_attr(any(target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd",
Expand Down Expand Up @@ -235,7 +236,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
pub fn current_exe() -> io::Result<PathBuf> {
::fs::read_link("/proc/self/exe")
}
Expand Down Expand Up @@ -385,7 +386,8 @@ pub fn args() -> Args {
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris",
target_os = "nacl"))]
target_os = "nacl",
target_os = "emscripten"))]
pub fn args() -> Args {
use sys_common;
let bytes = sys_common::args::clone().unwrap_or(Vec::new());
Expand Down
3 changes: 2 additions & 1 deletion src/libstd/sys/unix/process.rs
Expand Up @@ -131,7 +131,8 @@ impl fmt::Debug for Command {
pub struct ExitStatus(c_int);

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "nacl", target_os = "solaris"))]
target_os = "nacl", target_os = "solaris",
target_os = "emscripten"))]
mod status_imp {
pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 }
pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff }
Expand Down

0 comments on commit d6c0d85

Please sign in to comment.