Skip to content

Commit 987f824

Browse files
kyeongwoonbrson
kyeongwoon
authored andcommitted
Support ARM and Android
Conflicts: src/libcore/os.rs src/librustc/back/link.rs src/librustc/driver/driver.rs src/librustc/metadata/loader.rs src/librustc/middle/trans/base.rs
1 parent 27e6a0f commit 987f824

35 files changed

+599
-30
lines changed

Makefile.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ DRIVER_CRATE := $(S)src/driver/driver.rs
241241
######################################################################
242242

243243
# FIXME: x86-ism
244-
LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser jit mcjit \
244+
LLVM_COMPONENTS=x86 arm ipo bitreader bitwriter linker asmparser jit mcjit \
245245
interpreter
246246

247247
define DEF_LLVM_VARS

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ do
717717
then
718718
msg "configuring LLVM for $t"
719719

720-
LLVM_TARGETS="--enable-targets=x86,x86_64"
720+
LLVM_TARGETS="--enable-targets=x86,x86_64,arm"
721721
LLVM_BUILD="--build=$t"
722722
LLVM_HOST="--host=$t"
723723
LLVM_TARGET="--target=$t"

src/libcore/cleanup.rs

+3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ struct AllocHeader { priv opaque: () }
4040
struct MemoryRegion { priv opaque: () }
4141

4242
#[cfg(target_arch="x86")]
43+
#[cfg(target_arch="arm")]
4344
struct Registers {
4445
data: [u32 * 16]
4546
}
4647

4748
#[cfg(target_arch="x86")]
49+
#[cfg(target_arch="arm")]
4850
struct Context {
4951
regs: Registers,
5052
next: *Context,
@@ -70,6 +72,7 @@ struct BoxedRegion {
7072
}
7173

7274
#[cfg(target_arch="x86")]
75+
#[cfg(target_arch="arm")]
7376
struct Task {
7477
// Public fields
7578
refcount: intptr_t, // 0

src/libcore/libc.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ pub mod types {
198198
// Standard types that are scalar but vary by OS and arch.
199199

200200
#[cfg(target_os = "linux")]
201+
#[cfg(target_os = "android")]
201202
pub mod os {
202203
pub mod common {
203204
pub mod posix01 {}
204205
}
205206

206207
#[cfg(target_arch = "x86")]
208+
#[cfg(target_arch = "arm")]
207209
pub mod arch {
208210
pub mod c95 {
209211
pub type c_char = i8;
@@ -797,6 +799,7 @@ pub mod consts {
797799

798800

799801
#[cfg(target_os = "linux")]
802+
#[cfg(target_os = "android")]
800803
pub mod os {
801804
pub mod c95 {
802805
pub const EXIT_FAILURE : int = 1;
@@ -1264,6 +1267,7 @@ pub mod funcs {
12641267

12651268

12661269
#[cfg(target_os = "linux")]
1270+
#[cfg(target_os = "android")]
12671271
#[cfg(target_os = "macos")]
12681272
#[cfg(target_os = "freebsd")]
12691273
pub mod posix88 {
@@ -1283,7 +1287,8 @@ pub mod funcs {
12831287

12841288
#[cfg(target_os = "linux")]
12851289
#[cfg(target_os = "freebsd")]
1286-
unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1290+
#[cfg(target_os = "android")]
1291+
unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
12871292

12881293
#[cfg(target_os = "macos")]
12891294
#[link_name = "fstat64"]
@@ -1294,6 +1299,7 @@ pub mod funcs {
12941299

12951300
#[cfg(target_os = "linux")]
12961301
#[cfg(target_os = "freebsd")]
1302+
#[cfg(target_os = "android")]
12971303
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
12981304

12991305
#[cfg(target_os = "macos")]
@@ -1382,6 +1388,7 @@ pub mod funcs {
13821388
}
13831389

13841390
#[cfg(target_os = "linux")]
1391+
#[cfg(target_os = "android")]
13851392
#[cfg(target_os = "macos")]
13861393
#[cfg(target_os = "freebsd")]
13871394
pub mod posix01 {
@@ -1394,6 +1401,7 @@ pub mod funcs {
13941401
pub extern mod stat_ {
13951402
#[cfg(target_os = "linux")]
13961403
#[cfg(target_os = "freebsd")]
1404+
#[cfg(target_os = "android")]
13971405
unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
13981406

13991407
#[cfg(target_os = "macos")]
@@ -1410,6 +1418,7 @@ pub mod funcs {
14101418
unsafe fn fsync(fd: c_int) -> c_int;
14111419

14121420
#[cfg(target_os = "linux")]
1421+
#[cfg(target_os = "android")]
14131422
unsafe fn fdatasync(fd: c_int) -> c_int;
14141423

14151424
unsafe fn setenv(name: *c_char, val: *c_char,
@@ -1442,6 +1451,7 @@ pub mod funcs {
14421451

14431452
#[cfg(target_os = "win32")]
14441453
#[cfg(target_os = "linux")]
1454+
#[cfg(target_os = "android")]
14451455
#[cfg(target_os = "macos")]
14461456
#[cfg(target_os = "freebsd")]
14471457
pub mod posix08 {
@@ -1473,6 +1483,7 @@ pub mod funcs {
14731483

14741484

14751485
#[cfg(target_os = "linux")]
1486+
#[cfg(target_os = "android")]
14761487
#[cfg(target_os = "win32")]
14771488
pub mod bsd44 {
14781489
}
@@ -1492,6 +1503,7 @@ pub mod funcs {
14921503
}
14931504

14941505
#[cfg(target_os = "linux")]
1506+
#[cfg(target_os = "android")]
14951507
pub mod extra {
14961508
}
14971509

src/libcore/os.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ pub fn fsync_fd(fd: c_int, _level: io::fsync::Level) -> c_int {
325325
}
326326

327327
#[cfg(target_os = "linux")]
328+
#[cfg(target_os = "android")]
328329
pub fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
329330
unsafe {
330331
use libc::funcs::posix01::unistd::*;
@@ -449,6 +450,7 @@ pub fn self_exe_path() -> Option<Path> {
449450
}
450451

451452
#[cfg(target_os = "linux")]
453+
#[cfg(target_os = "android")]
452454
fn load_self() -> Option<~str> {
453455
unsafe {
454456
use libc::funcs::posix01::unistd::readlink;
@@ -876,6 +878,7 @@ pub fn real_args() -> ~[~str] {
876878
}
877879

878880
#[cfg(target_os = "linux")]
881+
#[cfg(target_os = "android")]
879882
#[cfg(target_os = "freebsd")]
880883
pub fn real_args() -> ~[~str] {
881884
unsafe {
@@ -976,7 +979,6 @@ pub mod consts {
976979
pub const FAMILY: &str = "windows";
977980
}
978981

979-
980982
#[cfg(target_os = "macos")]
981983
use os::consts::macos::*;
982984

@@ -986,6 +988,9 @@ pub mod consts {
986988
#[cfg(target_os = "linux")]
987989
use os::consts::linux::*;
988990

991+
#[cfg(target_os = "android")]
992+
use os::consts::android::*;
993+
989994
#[cfg(target_os = "win32")]
990995
use os::consts::win32::*;
991996

@@ -1010,6 +1015,13 @@ pub mod consts {
10101015
pub const EXE_SUFFIX: &str = "";
10111016
}
10121017

1018+
pub mod android {
1019+
pub const SYSNAME: &str = "android";
1020+
pub const DLL_PREFIX: &str = "lib";
1021+
pub const DLL_SUFFIX: &str = ".so";
1022+
pub const EXE_SUFFIX: &str = "";
1023+
}
1024+
10131025
pub mod win32 {
10141026
pub const SYSNAME: &str = "win32";
10151027
pub const DLL_PREFIX: &str = "";

src/libcore/path.rs

+2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ pub pure fn Path(s: &str) -> Path {
8989
}
9090

9191
#[cfg(target_os = "linux")]
92+
#[cfg(target_os = "android")]
9293
mod stat {
9394
#[cfg(target_arch = "x86")]
95+
#[cfg(target_arch = "arm")]
9496
pub mod arch {
9597
use libc;
9698

src/libcore/run.rs

+2
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ pub fn waitpid(pid: pid_t) -> int {
405405
#[cfg(unix)]
406406
fn waitpid_os(pid: pid_t) -> int {
407407
#[cfg(target_os = "linux")]
408+
#[cfg(target_os = "android")]
408409
fn WIFEXITED(status: i32) -> bool {
409410
(status & 0xffi32) == 0i32
410411
}
@@ -416,6 +417,7 @@ pub fn waitpid(pid: pid_t) -> int {
416417
}
417418

418419
#[cfg(target_os = "linux")]
420+
#[cfg(target_os = "android")]
419421
fn WEXITSTATUS(status: i32) -> i32 {
420422
(status >> 8i32) & 0xffi32
421423
}

src/librustc/back/arm.rs

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2012 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 back::target_strs;
12+
use driver::session;
13+
use session::sess_os_to_meta_os;
14+
use metadata::loader::meta_section_name;
15+
16+
fn get_target_strs(target_os: session::os) -> target_strs::t {
17+
return {
18+
module_asm: ~"",
19+
20+
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
21+
22+
data_layout: match target_os {
23+
session::os_macos => {
24+
~"e-p:32:32:32" +
25+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
26+
~"-f32:32:32-f64:64:64" +
27+
~"-v64:64:64-v128:64:128" +
28+
~"-a0:0:64-n32"
29+
}
30+
31+
session::os_win32 => {
32+
~"e-p:32:32:32" +
33+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
34+
~"-f32:32:32-f64:64:64" +
35+
~"-v64:64:64-v128:64:128" +
36+
~"-a0:0:64-n32"
37+
}
38+
39+
session::os_linux => {
40+
~"e-p:32:32:32" +
41+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
42+
~"-f32:32:32-f64:64:64" +
43+
~"-v64:64:64-v128:64:128" +
44+
~"-a0:0:64-n32"
45+
}
46+
47+
session::os_android => {
48+
~"e-p:32:32:32" +
49+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
50+
~"-f32:32:32-f64:64:64" +
51+
~"-v64:64:64-v128:64:128" +
52+
~"-a0:0:64-n32"
53+
}
54+
55+
session::os_freebsd => {
56+
~"e-p:32:32:32" +
57+
~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
58+
~"-f32:32:32-f64:64:64" +
59+
~"-v64:64:64-v128:64:128" +
60+
~"-a0:0:64-n32"
61+
}
62+
},
63+
64+
target_triple: match target_os {
65+
session::os_macos => ~"arm-apple-darwin",
66+
session::os_win32 => ~"arm-pc-mingw32",
67+
session::os_linux => ~"arm-unknown-linux",
68+
session::os_android => ~"arm-unknown-android",
69+
session::os_freebsd => ~"arm-unknown-freebsd"
70+
},
71+
72+
cc_args: ~[~"-marm"]
73+
};
74+
}
75+
76+
77+
//
78+
// Local Variables:
79+
// mode: rust
80+
// fill-column: 78;
81+
// indent-tabs-mode: nil
82+
// c-basic-offset: 4
83+
// buffer-file-coding-system: utf-8-unix
84+
// End:
85+
//

src/librustc/back/link.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use core::cmp;
3030
use core::hash;
3131
use core::io::{Writer, WriterUtil};
3232
use core::libc::{c_int, c_uint, c_char};
33-
use core::os::consts::{macos, freebsd, linux, win32};
33+
use core::os::consts::{macos, freebsd, linux, android, win32};
3434
use core::os;
3535
use core::ptr;
3636
use core::run;
@@ -43,7 +43,7 @@ use syntax::ast_map::{path, path_mod, path_name};
4343
use syntax::attr;
4444
use syntax::print::pprust;
4545

46-
pub enum output_type {
46+
enum output_type {
4747
output_type_none,
4848
output_type_bitcode,
4949
output_type_assembly,
@@ -712,6 +712,7 @@ fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
712712
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
713713
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
714714
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
715+
session::os_android => (android::DLL_PREFIX, android::DLL_SUFFIX),
715716
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
716717
};
717718
return str::from_slice(dll_prefix) + libname +
@@ -758,7 +759,10 @@ fn link_binary(sess: Session,
758759
// For win32, there is no cc command,
759760
// so we add a condition to make it use gcc.
760761
let cc_prog: ~str =
761-
if sess.targ_cfg.os == session::os_win32 { ~"gcc" } else { ~"cc" };
762+
if sess.targ_cfg.os == session::os_android {
763+
~"arm-linux-androideabi-g++"
764+
} else if sess.targ_cfg.os == session::os_win32 { ~"gcc" }
765+
else { ~"cc" };
762766
// The invocations of cc share some flags across platforms
763767

764768
let mut cc_args =
@@ -831,6 +835,11 @@ fn link_binary(sess: Session,
831835
// have to be explicit about linking to it. See #2510
832836
cc_args.push(~"-lm");
833837
}
838+
else if sess.targ_cfg.os == session::os_android {
839+
cc_args.push_all(~[~"-ldl", ~"-llog", ~"-lsupc++",
840+
~"-lgnustl_shared"]);
841+
cc_args.push(~"-lm");
842+
}
834843

835844
if sess.targ_cfg.os == session::os_freebsd {
836845
cc_args.push_all(~[~"-pthread", ~"-lrt",
@@ -851,7 +860,9 @@ fn link_binary(sess: Session,
851860
}
852861

853862
// Stack growth requires statically linking a __morestack function
863+
if sess.targ_cfg.os != session::os_android {
854864
cc_args.push(~"-lmorestack");
865+
}
855866

856867
// FIXME (#2397): At some point we want to rpath our guesses as to where
857868
// extern libraries might live, based on the addl_lib_search_paths

src/librustc/back/rpath.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ fn get_rpath_relative_to_output(os: session::os,
130130

131131
// Mac doesn't appear to support $ORIGIN
132132
let prefix = match os {
133-
session::os_linux | session::os_freebsd => "$ORIGIN",
133+
session::os_android |session::os_linux | session::os_freebsd
134+
=> "$ORIGIN",
134135
session::os_macos => "@executable_path",
135136
session::os_win32 => util::unreachable()
136137
};
@@ -331,6 +332,7 @@ mod test {
331332

332333
#[test]
333334
#[cfg(target_os = "linux")]
335+
#[cfg(target_os = "andorid")]
334336
fn test_rpath_relative() {
335337
let o = session::os_linux;
336338
let res = get_rpath_relative_to_output(o,

0 commit comments

Comments
 (0)