From 3e7543a16ec6450b8fe0c3d50bc341b5f143cc54 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Dec 2016 08:23:33 -0700 Subject: WIP: Cross-compilation for Redox target --- src/liballoc_system/lib.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/liballoc_system') diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index a4fabb5a2c9..487e8e8e6ec 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -19,6 +19,7 @@ issue = "27783")] #![feature(allocator)] #![feature(staged_api)] +#![cfg_attr(target_os = "redox", feature(libc))] #![cfg_attr(unix, feature(libc))] // The minimum alignment guaranteed by the architecture. This value is used to @@ -71,7 +72,49 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { imp::usable_size(size, align) } -#[cfg(unix)] +#[cfg(target_os = "redox")] +mod imp { + extern crate libc; + + use core::cmp; + use core::ptr; + use MIN_ALIGN; + + pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { + libc::malloc(size as libc::size_t) as *mut u8 + } + + pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { + if align <= MIN_ALIGN { + libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 + } else { + let new_ptr = allocate(size, align); + if !new_ptr.is_null() { + ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); + deallocate(ptr, old_size, align); + } + new_ptr + } + } + + pub unsafe fn reallocate_inplace(_ptr: *mut u8, + old_size: usize, + _size: usize, + _align: usize) + -> usize { + old_size + } + + pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { + libc::free(ptr as *mut libc::c_void) + } + + pub fn usable_size(size: usize, _align: usize) -> usize { + size + } +} + +#[cfg(any(unix))] mod imp { extern crate libc; -- cgit 1.4.1-3-g733a5 From 2ca1f0b3b30208695529e227cda6ba0ad8a5ec60 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 18:09:19 -0700 Subject: Switch back to alloc_system --- src/liballoc_system/lib.rs | 51 +++------------------------------- src/librustc_back/target/redox_base.rs | 4 +-- 2 files changed, 6 insertions(+), 49 deletions(-) (limited to 'src/liballoc_system') diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 487e8e8e6ec..4daa6cbb846 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -19,8 +19,7 @@ issue = "27783")] #![feature(allocator)] #![feature(staged_api)] -#![cfg_attr(target_os = "redox", feature(libc))] -#![cfg_attr(unix, feature(libc))] +#![cfg_attr(any(unix, target_os = "redox"), feature(libc))] // The minimum alignment guaranteed by the architecture. This value is used to // add fast paths for low alignment values. In practice, the alignment is a @@ -72,49 +71,7 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { imp::usable_size(size, align) } -#[cfg(target_os = "redox")] -mod imp { - extern crate libc; - - use core::cmp; - use core::ptr; - use MIN_ALIGN; - - pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size as libc::size_t) as *mut u8 - } - - pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { - if align <= MIN_ALIGN { - libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 - } else { - let new_ptr = allocate(size, align); - if !new_ptr.is_null() { - ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); - deallocate(ptr, old_size, align); - } - new_ptr - } - } - - pub unsafe fn reallocate_inplace(_ptr: *mut u8, - old_size: usize, - _size: usize, - _align: usize) - -> usize { - old_size - } - - pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { - libc::free(ptr as *mut libc::c_void) - } - - pub fn usable_size(size: usize, _align: usize) -> usize { - size - } -} - -#[cfg(any(unix))] +#[cfg(any(unix, target_os = "redox"))] mod imp { extern crate libc; @@ -130,7 +87,7 @@ mod imp { } } - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "redox"))] unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { // On android we currently target API level 9 which unfortunately // doesn't have the `posix_memalign` API used below. Instead we use @@ -152,7 +109,7 @@ mod imp { libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8 } - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "redox")))] unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { let mut out = ptr::null_mut(); let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t); diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index fc4c68276b6..a04ec81e973 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, - lib_allocation_crate: "ralloc".to_string(), - exe_allocation_crate: "ralloc".to_string(), + lib_allocation_crate: "alloc_system".to_string(), + exe_allocation_crate: "alloc_system".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() -- cgit 1.4.1-3-g733a5