Skip to content

Commit

Permalink
Auto merge of #812 - malbarbo:x32, r=alexcrichton
Browse files Browse the repository at this point in the history
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 rust-lang/rust#37976
  • Loading branch information
bors committed Oct 19, 2017
2 parents b06739d + a5bd4b5 commit 7e33065
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 41 deletions.
4 changes: 3 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 19 additions & 1 deletion src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/unix/notbsd/linux/other/b32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/unix/notbsd/linux/other/b64/aarch64.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
31 changes: 19 additions & 12 deletions src/unix/notbsd/linux/other/b64/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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],
}
Expand Down Expand Up @@ -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
}
Expand Down
25 changes: 25 additions & 0 deletions src/unix/notbsd/linux/other/b64/not_x32.rs
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions src/unix/notbsd/linux/other/b64/powerpc64.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
13 changes: 13 additions & 0 deletions src/unix/notbsd/linux/other/b64/sparc64.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/unix/notbsd/linux/other/b64/x32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub type c_long = i32;
pub type c_ulong = u32;
23 changes: 6 additions & 17 deletions src/unix/notbsd/linux/other/b64/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand All @@ -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],
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/unix/notbsd/linux/other/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7e33065

Please sign in to comment.