Skip to content

Commit 3bfc36c

Browse files
committed
Add the asmjs-unknown-emscripten triple. Add cfgs to libs.
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 updates libc to not link to -m and -rt since all emscripten runtime components are part of libc. Emscripten libc is musl. It disables stack protection.
1 parent 42c3ef8 commit 3bfc36c

File tree

25 files changed

+159
-18
lines changed

25 files changed

+159
-18
lines changed

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,12 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
12901290
putvar CFG_DISABLE_JEMALLOC
12911291
;;
12921292

1293+
*-emscripten)
1294+
step_msg "targeting emscripten, disabling jemalloc"
1295+
CFG_DISABLE_JEMALLOC=1
1296+
putvar CFG_DISABLE_JEMALLOC
1297+
;;
1298+
12931299
*)
12941300
;;
12951301
esac

mk/cfg/asmjs-unknown-emscripten.mk

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# asmjs-unknown-emscripten configuration
2+
CC_asmjs-unknown-emscripten=emcc
3+
CXX_asmjs-unknown-emscripten=em++
4+
CPP_asmjs-unknown-emscripten=$(CPP)
5+
AR_asmjs-unknown-emscripten=emar
6+
CFG_LIB_NAME_asmjs-unknown-emscripten=lib$(1).so
7+
CFG_STATIC_LIB_NAME_asmjs-unknown-emscripten=lib$(1).a
8+
CFG_LIB_GLOB_asmjs-unknown-emscripten=lib$(1)-*.so
9+
CFG_LIB_DSYM_GLOB_asmjs-unknown-emscripten=lib$(1)-*.dylib.dSYM
10+
CFG_JEMALLOC_CFLAGS_asmjs-unknown-emscripten := -m32 $(CFLAGS)
11+
# NB: The EMSCRIPTEN environment variable is set by the emscripten SDK.
12+
# This is only needed here to so the compiler-rt build can find unwind.h,
13+
# but the asmjs target *doesn't even link to compiler-rt*.
14+
CFG_GCCISH_CFLAGS_asmjs-unknown-emscripten := -Wall -Werror -g -fPIC -m32 $(CFLAGS) \
15+
-I$(EMSCRIPTEN)/system/lib/libcxxabi/include
16+
CFG_GCCISH_CXXFLAGS_asmjs-unknown-emscripten := -fno-rtti $(CXXFLAGS)
17+
CFG_GCCISH_LINK_FLAGS_asmjs-unknown-emscripten := -shared -fPIC -ldl -pthread -lrt -g -m32
18+
CFG_GCCISH_DEF_FLAG_asmjs-unknown-emscripten := -Wl,--export-dynamic,--dynamic-list=
19+
CFG_LLC_FLAGS_asmjs-unknown-emscripten :=
20+
CFG_INSTALL_NAME_asmjs-unknown-emscripten =
21+
CFG_EXE_SUFFIX_asmjs-unknown-emscripten =
22+
CFG_WINDOWSY_asmjs-unknown-emscripten :=
23+
CFG_UNIXY_asmjs-unknown-emscripten := 1
24+
CFG_LDPATH_asmjs-unknown-emscripten :=
25+
CFG_RUN_asmjs-unknown-emscripten=$(2)
26+
CFG_RUN_TARG_asmjs-unknown-emscripten=$(call CFG_RUN_asmjs-unknown-emscripten,,$(2))
27+
CFG_GNU_TRIPLE_asmjs-unknown-emscripten := asmjs-unknown-emscripten

mk/rt.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ $$(BACKTRACE_LIB_$(1)):
301301
touch $$@
302302
else
303303

304+
ifeq ($$(findstring emscripten,$(1)),emscripten)
305+
# FIXME: libbacktrace doesn't understand the emscripten triple
306+
$$(BACKTRACE_LIB_$(1)):
307+
touch $$@
308+
else
309+
304310
ifdef CFG_ENABLE_FAST_MAKE
305311
BACKTRACE_DEPS := $(S)/.gitmodules
306312
else
@@ -348,6 +354,7 @@ $$(BACKTRACE_LIB_$(1)): $$(BACKTRACE_BUILD_DIR_$(1))/Makefile $$(MKFILE_DEPS)
348354
INCDIR=$(S)src/libbacktrace
349355
$$(Q)cp $$(BACKTRACE_BUILD_DIR_$(1))/.libs/libbacktrace.a $$@
350356

357+
endif # endif for emscripten
351358
endif # endif for msvc
352359
endif # endif for ios
353360
endif # endif for darwin

src/jemalloc

Submodule jemalloc updated 102 files

src/liballoc_system/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ extern crate libc;
2929
target_arch = "arm",
3030
target_arch = "mips",
3131
target_arch = "mipsel",
32-
target_arch = "powerpc")))]
32+
target_arch = "powerpc",
33+
target_arch = "asmjs")))]
3334
const MIN_ALIGN: usize = 8;
3435
#[cfg(all(any(target_arch = "x86_64",
3536
target_arch = "aarch64")))]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use super::{Target, TargetOptions};
12+
13+
pub fn target() -> Target {
14+
let opts = TargetOptions {
15+
linker: "emcc".to_string(),
16+
ar: "emar".to_string(),
17+
18+
dynamic_linking: false,
19+
executables: true,
20+
exe_suffix: ".js".to_string(),
21+
no_compiler_rt: true,
22+
linker_is_gnu: true,
23+
allow_asm: false,
24+
archive_format: "gnu".to_string(),
25+
.. Default::default()
26+
};
27+
Target {
28+
llvm_target: "asmjs-unknown-emscripten".to_string(),
29+
target_endian: "little".to_string(),
30+
target_pointer_width: "32".to_string(),
31+
target_os: "emscripten".to_string(),
32+
target_env: "".to_string(),
33+
target_vendor: "unknown".to_string(),
34+
arch: "asmjs".to_string(),
35+
options: opts,
36+
}
37+
}

src/librustc_back/target/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ impl Target {
448448
x86_64_pc_windows_msvc,
449449
i686_pc_windows_msvc,
450450

451-
le32_unknown_nacl
451+
le32_unknown_nacl,
452+
asmjs_unknown_emscripten
452453
);
453454

454455

src/librustc_trans/trans/cabi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use trans::cabi_arm;
2020
use trans::cabi_aarch64;
2121
use trans::cabi_powerpc;
2222
use trans::cabi_mips;
23+
use trans::cabi_asmjs;
2324
use trans::type_::Type;
2425

2526
#[derive(Clone, Copy, PartialEq)]
@@ -127,6 +128,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
127128
},
128129
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
129130
"powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
131+
"asmjs" => cabi_asmjs::compute_abi_info(ccx, atys, rty, ret_def),
130132
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)
131133
),
132134
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use trans::cabi::FnType;
12+
use trans::cabi_arm;
13+
use trans::context::CrateContext;
14+
use trans::type_::Type;
15+
16+
pub fn compute_abi_info(ccx: &CrateContext,
17+
atys: &[Type],
18+
rty: Type,
19+
ret_def: bool) -> FnType {
20+
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def,
21+
cabi_arm::Flavor::General)
22+
}

src/librustc_trans/trans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mod builder;
2828
mod cabi;
2929
mod cabi_aarch64;
3030
mod cabi_arm;
31+
mod cabi_asmjs;
3132
mod cabi_mips;
3233
mod cabi_powerpc;
3334
mod cabi_x86;

src/libstd/dynamic_lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ mod tests {
183183
target_os = "dragonfly",
184184
target_os = "bitrig",
185185
target_os = "netbsd",
186-
target_os = "openbsd"))]
186+
target_os = "openbsd",
187+
target_os = "emscripten"))]
187188
mod dl {
188189
use prelude::v1::*;
189190

src/libstd/env.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,17 @@ mod os {
832832
pub const EXE_EXTENSION: &'static str = "pexe";
833833
}
834834

835+
#[cfg(target_os = "emscripten")]
836+
mod os {
837+
pub const FAMILY: &'static str = "unix";
838+
pub const OS: &'static str = "emscripten";
839+
pub const DLL_PREFIX: &'static str = "lib";
840+
pub const DLL_SUFFIX: &'static str = ".so";
841+
pub const DLL_EXTENSION: &'static str = "so";
842+
pub const EXE_SUFFIX: &'static str = ".js";
843+
pub const EXE_EXTENSION: &'static str = "js";
844+
}
845+
835846
#[cfg(target_arch = "x86")]
836847
mod arch {
837848
pub const ARCH: &'static str = "x86";
@@ -872,6 +883,11 @@ mod arch {
872883
pub const ARCH: &'static str = "le32";
873884
}
874885

886+
#[cfg(target_arch = "asmjs")]
887+
mod arch {
888+
pub const ARCH: &'static str = "asmjs";
889+
}
890+
875891
#[cfg(test)]
876892
mod tests {
877893
use prelude::v1::*;

src/libstd/os/linux/raw.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
2626
#[cfg(any(target_arch = "x86",
2727
target_arch = "le32",
2828
target_arch = "powerpc",
29-
target_arch = "arm"))]
29+
target_arch = "arm",
30+
target_arch = "asmjs"))]
3031
mod arch {
3132
use super::{dev_t, mode_t};
3233
use os::raw::{c_long, c_short};

src/libstd/os/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ pub use sys::ext as windows;
3131
#[cfg(target_os = "netbsd")] pub mod netbsd;
3232
#[cfg(target_os = "openbsd")] pub mod openbsd;
3333

34+
// Emscripten is just like linux
35+
#[cfg(target_os = "emscripten")]
36+
#[path = "linux/mod.rs"]
37+
pub mod emscripten;
38+
3439
pub mod raw;

src/libstd/sys/common/args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
3838
target_os = "dragonfly",
3939
target_os = "bitrig",
4040
target_os = "netbsd",
41-
target_os = "openbsd"))]
41+
target_os = "openbsd",
42+
target_os = "emscripten"))]
4243
mod imp {
4344
use prelude::v1::*;
4445

src/libstd/sys/common/libunwind.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pub const unwinder_private_data_size: usize = 2;
8686
#[cfg(target_arch = "powerpc")]
8787
pub const unwinder_private_data_size: usize = 2;
8888

89+
#[cfg(target_arch = "asmjs")]
90+
// FIXME: Copied from arm. Need to confirm.
91+
pub const unwinder_private_data_size: usize = 20;
92+
8993
#[repr(C)]
9094
pub struct _Unwind_Exception {
9195
pub exception_class: _Unwind_Exception_Class,

src/libstd/sys/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod unwind;
4545
pub mod util;
4646
pub mod wtf8;
4747

48-
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))),
48+
#[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "emscripten"))),
4949
all(windows, target_env = "gnu")))]
5050
pub mod gnu;
5151

src/libstd/sys/unix/backtrace/printing/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
pub use self::imp::print;
1212

13-
#[cfg(any(target_os = "macos", target_os = "ios"))]
13+
#[cfg(any(target_os = "macos", target_os = "ios",
14+
target_os = "emscripten"))]
1415
#[path = "dladdr.rs"]
1516
mod imp;
1617

17-
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
18+
#[cfg(not(any(target_os = "macos", target_os = "ios",
19+
target_os = "emscripten")))]
1820
#[path = "gnu.rs"]
1921
mod imp;

src/libstd/sys/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ops::Neg;
2626
#[cfg(target_os = "nacl")] pub use os::nacl as platform;
2727
#[cfg(target_os = "netbsd")] pub use os::netbsd as platform;
2828
#[cfg(target_os = "openbsd")] pub use os::openbsd as platform;
29+
#[cfg(target_os = "emscripten")] pub use os::emscripten as platform;
2930

3031
pub mod backtrace;
3132
pub mod condvar;

src/libstd/sys/unix/os.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ static ENV_LOCK: StaticMutex = StaticMutex::new();
3838
/// Returns the platform-specific value of errno
3939
pub fn errno() -> i32 {
4040
extern {
41-
#[cfg_attr(any(target_os = "linux"), link_name = "__errno_location")]
41+
#[cfg_attr(any(target_os = "linux", target_os = "emscripten"),
42+
link_name = "__errno_location")]
4243
#[cfg_attr(any(target_os = "bitrig",
4344
target_os = "netbsd",
4445
target_os = "openbsd",
@@ -234,7 +235,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
234235
}
235236
}
236237

237-
#[cfg(any(target_os = "linux", target_os = "android"))]
238+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
238239
pub fn current_exe() -> io::Result<PathBuf> {
239240
::fs::read_link("/proc/self/exe")
240241
}
@@ -359,7 +360,8 @@ pub fn args() -> Args {
359360
target_os = "bitrig",
360361
target_os = "netbsd",
361362
target_os = "openbsd",
362-
target_os = "nacl"))]
363+
target_os = "nacl",
364+
target_os = "emscripten"))]
363365
pub fn args() -> Args {
364366
use sys_common;
365367
let bytes = sys_common::args::clone().unwrap_or(Vec::new());

src/libstd/sys/unix/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn os2c(s: &OsStr) -> CString {
9393
pub struct ExitStatus(c_int);
9494

9595
#[cfg(any(target_os = "linux", target_os = "android",
96-
target_os = "nacl"))]
96+
target_os = "nacl", target_os = "emscripten"))]
9797
mod status_imp {
9898
pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 }
9999
pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff }

src/libstd/sys/unix/thread.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ impl Thread {
8484
debug_assert_eq!(ret, 0);
8585
}
8686

87-
#[cfg(any(target_os = "linux", target_os = "android"))]
87+
#[cfg(any(target_os = "linux",
88+
target_os = "android",
89+
target_os = "emscripten"))]
8890
pub fn set_name(name: &str) {
8991
const PR_SET_NAME: libc::c_int = 15;
9092
let cname = CString::new(name).unwrap_or_else(|_| {

src/libtest/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,14 +1135,16 @@ impl MetricMap {
11351135
/// elimination.
11361136
///
11371137
/// This function is a no-op, and does not even read from `dummy`.
1138-
#[cfg(not(all(target_os = "nacl", target_arch = "le32")))]
1138+
#[cfg(not(any(all(target_os = "nacl", target_arch = "le32"),
1139+
target_arch = "asmjs")))]
11391140
pub fn black_box<T>(dummy: T) -> T {
11401141
// we need to "use" the argument in some way LLVM can't
11411142
// introspect.
11421143
unsafe {asm!("" : : "r"(&dummy))}
11431144
dummy
11441145
}
1145-
#[cfg(all(target_os = "nacl", target_arch = "le32"))]
1146+
#[cfg(any(all(target_os = "nacl", target_arch = "le32"),
1147+
target_arch = "asmjs"))]
11461148
#[inline(never)]
11471149
pub fn black_box<T>(dummy: T) -> T { dummy }
11481150

src/llvm

Submodule llvm updated 6028 files

0 commit comments

Comments
 (0)