Auto merge of #812 - malbarbo:x32, r=alexcrichton

Initial fixes for linux x32

Tested with a local build of rustc. The main test can be compiled but fails to execute (receives SIGTRAP, which I think in this case indicates memory violation, I will open an issue in the rustc repo).

This PR is important because it fixes the definition of `c_long` and `c_ulong`. Without these fixes, rustc crash with the error:

```
Cannot emit physreg copy instruction
UNREACHABLE executed at /checkout/src/llvm/lib/Target/X86/X86InstrInfo.cpp:5778!
```

Related https://github.com/rust-lang/rust/issues/37976
This commit is contained in:
bors 2017-10-19 16:40:53 +00:00
commit 7e33065ce4
12 changed files with 134 additions and 41 deletions

View File

@ -9,6 +9,7 @@ fn main() {
let aarch64 = target.contains("aarch64");
let i686 = target.contains("i686");
let x86_64 = target.contains("x86_64");
let x32 = target.ends_with("gnux32");
let windows = target.contains("windows");
let mingw = target.contains("windows-gnu");
let linux = target.contains("unknown-linux");
@ -135,9 +136,10 @@ fn main() {
cfg.header("sys/quota.h");
}
if !musl {
if !musl && !x32 {
cfg.header("sys/sysctl.h");
}
if !musl && !uclibc {
if !netbsd && !openbsd && !uclibc {

View File

@ -34,9 +34,14 @@ s! {
pub tv_usec: suseconds_t,
}
// linux x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
pub struct timespec {
pub tv_sec: time_t,
pub tv_nsec: c_long,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub tv_nsec: i64,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub tv_nsec: ::c_long,
}
pub struct rlimit {

View File

@ -213,12 +213,30 @@ s! {
__val: [::c_int; 2],
}
// x32 compatibility
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
pub struct mq_attr {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_flags: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_maxmsg: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_msgsize: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pub mq_curmsgs: i64,
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
pad: [i64; 4],
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_flags: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_maxmsg: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_msgsize: ::c_long,
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pub mq_curmsgs: ::c_long,
pad: [::c_long; 4]
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
pad: [::c_long; 4],
}
pub struct cpu_set_t {

View File

@ -281,6 +281,17 @@ pub const PTRACE_SETFPREGS: ::c_uint = 15;
pub const PTRACE_GETREGS: ::c_uint = 12;
pub const PTRACE_SETREGS: ::c_uint = 13;
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
}
cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;

View File

@ -1,5 +1,7 @@
//! AArch64-specific definitions for 64-bit linux-like values
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_char = u8;
pub type wchar_t = u32;
pub type nlink_t = u32;
@ -763,3 +765,14 @@ pub const SYS_pkey_mprotect: ::c_ulong = 288;
pub const SYS_pkey_alloc: ::c_ulong = 289;
pub const SYS_pkey_free: ::c_ulong = 290;
pub const SYS_syscalls: ::c_ulong = 291;
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
}

View File

@ -1,7 +1,5 @@
//! 64-bit specific definitions for linux-like values
pub type c_long = i64;
pub type c_ulong = u64;
pub type clock_t = i64;
pub type time_t = i64;
pub type ino_t = u64;
@ -15,18 +13,18 @@ s! {
}
pub struct sysinfo {
pub uptime: ::c_long,
pub loads: [::c_ulong; 3],
pub totalram: ::c_ulong,
pub freeram: ::c_ulong,
pub sharedram: ::c_ulong,
pub bufferram: ::c_ulong,
pub totalswap: ::c_ulong,
pub freeswap: ::c_ulong,
pub uptime: i64,
pub loads: [u64; 3],
pub totalram: u64,
pub freeram: u64,
pub sharedram: u64,
pub bufferram: u64,
pub totalswap: u64,
pub freeswap: u64,
pub procs: ::c_ushort,
pub pad: ::c_ushort,
pub totalhigh: ::c_ulong,
pub freehigh: ::c_ulong,
pub totalhigh: u64,
pub freehigh: u64,
pub mem_unit: ::c_uint,
pub _f: [::c_char; 0],
}
@ -64,6 +62,15 @@ cfg_if! {
} else if #[cfg(any(target_arch = "x86_64"))] {
mod x86_64;
pub use self::x86_64::*;
cfg_if! {
if #[cfg(target_pointer_width = "32")] {
mod x32;
pub use self::x32::*;
} else {
mod not_x32;
pub use self::not_x32::*;
}
}
} else {
// Unknown target_arch
}

View File

@ -0,0 +1,25 @@
pub type c_long = i64;
pub type c_ulong = u64;
pub const SYS_uselib: ::c_long = 134;
pub const SYS__sysctl: ::c_long = 156;
pub const SYS_create_module: ::c_long = 174;
pub const SYS_get_kernel_syms: ::c_long = 177;
pub const SYS_query_module: ::c_long = 178;
pub const SYS_nfsservctl: ::c_long = 180;
pub const SYS_set_thread_area: ::c_long = 205;
pub const SYS_get_thread_area: ::c_long = 211;
pub const SYS_epoll_ctl_old: ::c_long = 214;
pub const SYS_epoll_wait_old: ::c_long = 215;
pub const SYS_vserver: ::c_long = 236;
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
}

View File

@ -1,5 +1,7 @@
//! PowerPC64-specific definitions for 64-bit linux-like values
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_char = u8;
pub type wchar_t = i32;
pub type nlink_t = u64;
@ -842,3 +844,14 @@ pub const SYS_copy_file_range: ::c_ulong = 379;
pub const SYS_preadv2: ::c_ulong = 380;
pub const SYS_pwritev2: ::c_ulong = 381;
pub const SYS_kexec_file_load: ::c_ulong = 382;
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
}

View File

@ -1,5 +1,7 @@
//! SPARC64-specific definitions for 64-bit linux-like values
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_char = i8;
pub type wchar_t = i32;
pub type nlink_t = u32;
@ -430,3 +432,14 @@ pub const TIOCOUTQ: ::c_ulong = 0x40047473;
pub const TIOCGWINSZ: ::c_ulong = 0x40087468;
pub const TIOCSWINSZ: ::c_ulong = 0x80087467;
pub const FIONREAD: ::c_ulong = 0x4004667f;
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
}

View File

@ -0,0 +1,2 @@
pub type c_long = i32;
pub type c_ulong = u32;

View File

@ -22,11 +22,11 @@ s! {
pub st_blksize: ::blksize_t,
pub st_blocks: ::blkcnt_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_atime_nsec: i64,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_mtime_nsec: i64,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
pub st_ctime_nsec: i64,
__unused: [::c_long; 3],
}
@ -43,11 +43,11 @@ s! {
pub st_blksize: ::blksize_t,
pub st_blocks: ::blkcnt64_t,
pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,
pub st_atime_nsec: i64,
pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,
pub st_mtime_nsec: i64,
pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,
pub st_ctime_nsec: i64,
__reserved: [::c_long; 3],
}
@ -742,7 +742,6 @@ pub const SYS_rt_sigsuspend: ::c_long = 130;
pub const SYS_sigaltstack: ::c_long = 131;
pub const SYS_utime: ::c_long = 132;
pub const SYS_mknod: ::c_long = 133;
pub const SYS_uselib: ::c_long = 134;
pub const SYS_personality: ::c_long = 135;
pub const SYS_ustat: ::c_long = 136;
pub const SYS_statfs: ::c_long = 137;
@ -764,7 +763,6 @@ pub const SYS_munlockall: ::c_long = 152;
pub const SYS_vhangup: ::c_long = 153;
pub const SYS_modify_ldt: ::c_long = 154;
pub const SYS_pivot_root: ::c_long = 155;
pub const SYS__sysctl: ::c_long = 156;
pub const SYS_prctl: ::c_long = 157;
pub const SYS_arch_prctl: ::c_long = 158;
pub const SYS_adjtimex: ::c_long = 159;
@ -782,13 +780,9 @@ pub const SYS_sethostname: ::c_long = 170;
pub const SYS_setdomainname: ::c_long = 171;
pub const SYS_iopl: ::c_long = 172;
pub const SYS_ioperm: ::c_long = 173;
pub const SYS_create_module: ::c_long = 174;
pub const SYS_init_module: ::c_long = 175;
pub const SYS_delete_module: ::c_long = 176;
pub const SYS_get_kernel_syms: ::c_long = 177;
pub const SYS_query_module: ::c_long = 178;
pub const SYS_quotactl: ::c_long = 179;
pub const SYS_nfsservctl: ::c_long = 180;
pub const SYS_getpmsg: ::c_long = 181;
pub const SYS_putpmsg: ::c_long = 182;
pub const SYS_afs_syscall: ::c_long = 183;
@ -813,17 +807,13 @@ pub const SYS_time: ::c_long = 201;
pub const SYS_futex: ::c_long = 202;
pub const SYS_sched_setaffinity: ::c_long = 203;
pub const SYS_sched_getaffinity: ::c_long = 204;
pub const SYS_set_thread_area: ::c_long = 205;
pub const SYS_io_setup: ::c_long = 206;
pub const SYS_io_destroy: ::c_long = 207;
pub const SYS_io_getevents: ::c_long = 208;
pub const SYS_io_submit: ::c_long = 209;
pub const SYS_io_cancel: ::c_long = 210;
pub const SYS_get_thread_area: ::c_long = 211;
pub const SYS_lookup_dcookie: ::c_long = 212;
pub const SYS_epoll_create: ::c_long = 213;
pub const SYS_epoll_ctl_old: ::c_long = 214;
pub const SYS_epoll_wait_old: ::c_long = 215;
pub const SYS_remap_file_pages: ::c_long = 216;
pub const SYS_getdents64: ::c_long = 217;
pub const SYS_set_tid_address: ::c_long = 218;
@ -844,7 +834,6 @@ pub const SYS_epoll_wait: ::c_long = 232;
pub const SYS_epoll_ctl: ::c_long = 233;
pub const SYS_tgkill: ::c_long = 234;
pub const SYS_utimes: ::c_long = 235;
pub const SYS_vserver: ::c_long = 236;
pub const SYS_mbind: ::c_long = 237;
pub const SYS_set_mempolicy: ::c_long = 238;
pub const SYS_get_mempolicy: ::c_long = 239;

View File

@ -44,7 +44,8 @@ s! {
#[cfg(any(target_arch = "aarch64",
target_arch = "sparc64",
target_pointer_width = "32"))]
all(target_pointer_width = "32",
not(target_arch = "x86_64"))))]
pub ut_session: ::c_long,
#[cfg(any(target_arch = "aarch64",
target_arch = "sparc64",
@ -53,7 +54,8 @@ s! {
#[cfg(not(any(target_arch = "aarch64",
target_arch = "sparc64",
target_pointer_width = "32")))]
all(target_pointer_width = "32",
not(target_arch = "x86_64")))))]
pub ut_session: ::int32_t,
#[cfg(not(any(target_arch = "aarch64",
target_arch = "sparc64",
@ -568,13 +570,6 @@ extern {
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void,
sz: ::c_int) -> ::c_int;