Skip to content

Commit 7e33065

Browse files
committed
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 rust-lang/rust#37976
2 parents b06739d + a5bd4b5 commit 7e33065

File tree

12 files changed

+134
-41
lines changed

12 files changed

+134
-41
lines changed

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fn main() {
99
let aarch64 = target.contains("aarch64");
1010
let i686 = target.contains("i686");
1111
let x86_64 = target.contains("x86_64");
12+
let x32 = target.ends_with("gnux32");
1213
let windows = target.contains("windows");
1314
let mingw = target.contains("windows-gnu");
1415
let linux = target.contains("unknown-linux");
@@ -135,9 +136,10 @@ fn main() {
135136
cfg.header("sys/quota.h");
136137
}
137138

138-
if !musl {
139+
if !musl && !x32 {
139140
cfg.header("sys/sysctl.h");
140141
}
142+
141143
if !musl && !uclibc {
142144

143145
if !netbsd && !openbsd && !uclibc {

src/unix/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ s! {
3434
pub tv_usec: suseconds_t,
3535
}
3636

37+
// linux x32 compatibility
38+
// See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
3739
pub struct timespec {
3840
pub tv_sec: time_t,
39-
pub tv_nsec: c_long,
41+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
42+
pub tv_nsec: i64,
43+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
44+
pub tv_nsec: ::c_long,
4045
}
4146

4247
pub struct rlimit {

src/unix/notbsd/linux/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,30 @@ s! {
213213
__val: [::c_int; 2],
214214
}
215215

216+
// x32 compatibility
217+
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
216218
pub struct mq_attr {
219+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
220+
pub mq_flags: i64,
221+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
222+
pub mq_maxmsg: i64,
223+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
224+
pub mq_msgsize: i64,
225+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
226+
pub mq_curmsgs: i64,
227+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
228+
pad: [i64; 4],
229+
230+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
217231
pub mq_flags: ::c_long,
232+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
218233
pub mq_maxmsg: ::c_long,
234+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
219235
pub mq_msgsize: ::c_long,
236+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
220237
pub mq_curmsgs: ::c_long,
221-
pad: [::c_long; 4]
238+
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
239+
pad: [::c_long; 4],
222240
}
223241

224242
pub struct cpu_set_t {

src/unix/notbsd/linux/other/b32/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,17 @@ pub const PTRACE_SETFPREGS: ::c_uint = 15;
281281
pub const PTRACE_GETREGS: ::c_uint = 12;
282282
pub const PTRACE_SETREGS: ::c_uint = 13;
283283

284+
#[link(name = "util")]
285+
extern {
286+
pub fn sysctl(name: *mut ::c_int,
287+
namelen: ::c_int,
288+
oldp: *mut ::c_void,
289+
oldlenp: *mut ::size_t,
290+
newp: *mut ::c_void,
291+
newlen: ::size_t)
292+
-> ::c_int;
293+
}
294+
284295
cfg_if! {
285296
if #[cfg(target_arch = "x86")] {
286297
mod x86;

src/unix/notbsd/linux/other/b64/aarch64.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! AArch64-specific definitions for 64-bit linux-like values
22
3+
pub type c_long = i64;
4+
pub type c_ulong = u64;
35
pub type c_char = u8;
46
pub type wchar_t = u32;
57
pub type nlink_t = u32;
@@ -763,3 +765,14 @@ pub const SYS_pkey_mprotect: ::c_ulong = 288;
763765
pub const SYS_pkey_alloc: ::c_ulong = 289;
764766
pub const SYS_pkey_free: ::c_ulong = 290;
765767
pub const SYS_syscalls: ::c_ulong = 291;
768+
769+
#[link(name = "util")]
770+
extern {
771+
pub fn sysctl(name: *mut ::c_int,
772+
namelen: ::c_int,
773+
oldp: *mut ::c_void,
774+
oldlenp: *mut ::size_t,
775+
newp: *mut ::c_void,
776+
newlen: ::size_t)
777+
-> ::c_int;
778+
}

src/unix/notbsd/linux/other/b64/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! 64-bit specific definitions for linux-like values
22
3-
pub type c_long = i64;
4-
pub type c_ulong = u64;
53
pub type clock_t = i64;
64
pub type time_t = i64;
75
pub type ino_t = u64;
@@ -15,18 +13,18 @@ s! {
1513
}
1614

1715
pub struct sysinfo {
18-
pub uptime: ::c_long,
19-
pub loads: [::c_ulong; 3],
20-
pub totalram: ::c_ulong,
21-
pub freeram: ::c_ulong,
22-
pub sharedram: ::c_ulong,
23-
pub bufferram: ::c_ulong,
24-
pub totalswap: ::c_ulong,
25-
pub freeswap: ::c_ulong,
16+
pub uptime: i64,
17+
pub loads: [u64; 3],
18+
pub totalram: u64,
19+
pub freeram: u64,
20+
pub sharedram: u64,
21+
pub bufferram: u64,
22+
pub totalswap: u64,
23+
pub freeswap: u64,
2624
pub procs: ::c_ushort,
2725
pub pad: ::c_ushort,
28-
pub totalhigh: ::c_ulong,
29-
pub freehigh: ::c_ulong,
26+
pub totalhigh: u64,
27+
pub freehigh: u64,
3028
pub mem_unit: ::c_uint,
3129
pub _f: [::c_char; 0],
3230
}
@@ -64,6 +62,15 @@ cfg_if! {
6462
} else if #[cfg(any(target_arch = "x86_64"))] {
6563
mod x86_64;
6664
pub use self::x86_64::*;
65+
cfg_if! {
66+
if #[cfg(target_pointer_width = "32")] {
67+
mod x32;
68+
pub use self::x32::*;
69+
} else {
70+
mod not_x32;
71+
pub use self::not_x32::*;
72+
}
73+
}
6774
} else {
6875
// Unknown target_arch
6976
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pub type c_long = i64;
2+
pub type c_ulong = u64;
3+
4+
pub const SYS_uselib: ::c_long = 134;
5+
pub const SYS__sysctl: ::c_long = 156;
6+
pub const SYS_create_module: ::c_long = 174;
7+
pub const SYS_get_kernel_syms: ::c_long = 177;
8+
pub const SYS_query_module: ::c_long = 178;
9+
pub const SYS_nfsservctl: ::c_long = 180;
10+
pub const SYS_set_thread_area: ::c_long = 205;
11+
pub const SYS_get_thread_area: ::c_long = 211;
12+
pub const SYS_epoll_ctl_old: ::c_long = 214;
13+
pub const SYS_epoll_wait_old: ::c_long = 215;
14+
pub const SYS_vserver: ::c_long = 236;
15+
16+
#[link(name = "util")]
17+
extern {
18+
pub fn sysctl(name: *mut ::c_int,
19+
namelen: ::c_int,
20+
oldp: *mut ::c_void,
21+
oldlenp: *mut ::size_t,
22+
newp: *mut ::c_void,
23+
newlen: ::size_t)
24+
-> ::c_int;
25+
}

src/unix/notbsd/linux/other/b64/powerpc64.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! PowerPC64-specific definitions for 64-bit linux-like values
22
3+
pub type c_long = i64;
4+
pub type c_ulong = u64;
35
pub type c_char = u8;
46
pub type wchar_t = i32;
57
pub type nlink_t = u64;
@@ -842,3 +844,14 @@ pub const SYS_copy_file_range: ::c_ulong = 379;
842844
pub const SYS_preadv2: ::c_ulong = 380;
843845
pub const SYS_pwritev2: ::c_ulong = 381;
844846
pub const SYS_kexec_file_load: ::c_ulong = 382;
847+
848+
#[link(name = "util")]
849+
extern {
850+
pub fn sysctl(name: *mut ::c_int,
851+
namelen: ::c_int,
852+
oldp: *mut ::c_void,
853+
oldlenp: *mut ::size_t,
854+
newp: *mut ::c_void,
855+
newlen: ::size_t)
856+
-> ::c_int;
857+
}

src/unix/notbsd/linux/other/b64/sparc64.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! SPARC64-specific definitions for 64-bit linux-like values
22
3+
pub type c_long = i64;
4+
pub type c_ulong = u64;
35
pub type c_char = i8;
46
pub type wchar_t = i32;
57
pub type nlink_t = u32;
@@ -430,3 +432,14 @@ pub const TIOCOUTQ: ::c_ulong = 0x40047473;
430432
pub const TIOCGWINSZ: ::c_ulong = 0x40087468;
431433
pub const TIOCSWINSZ: ::c_ulong = 0x80087467;
432434
pub const FIONREAD: ::c_ulong = 0x4004667f;
435+
436+
#[link(name = "util")]
437+
extern {
438+
pub fn sysctl(name: *mut ::c_int,
439+
namelen: ::c_int,
440+
oldp: *mut ::c_void,
441+
oldlenp: *mut ::size_t,
442+
newp: *mut ::c_void,
443+
newlen: ::size_t)
444+
-> ::c_int;
445+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub type c_long = i32;
2+
pub type c_ulong = u32;

src/unix/notbsd/linux/other/b64/x86_64.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ s! {
2222
pub st_blksize: ::blksize_t,
2323
pub st_blocks: ::blkcnt_t,
2424
pub st_atime: ::time_t,
25-
pub st_atime_nsec: ::c_long,
25+
pub st_atime_nsec: i64,
2626
pub st_mtime: ::time_t,
27-
pub st_mtime_nsec: ::c_long,
27+
pub st_mtime_nsec: i64,
2828
pub st_ctime: ::time_t,
29-
pub st_ctime_nsec: ::c_long,
29+
pub st_ctime_nsec: i64,
3030
__unused: [::c_long; 3],
3131
}
3232

@@ -43,11 +43,11 @@ s! {
4343
pub st_blksize: ::blksize_t,
4444
pub st_blocks: ::blkcnt64_t,
4545
pub st_atime: ::time_t,
46-
pub st_atime_nsec: ::c_long,
46+
pub st_atime_nsec: i64,
4747
pub st_mtime: ::time_t,
48-
pub st_mtime_nsec: ::c_long,
48+
pub st_mtime_nsec: i64,
4949
pub st_ctime: ::time_t,
50-
pub st_ctime_nsec: ::c_long,
50+
pub st_ctime_nsec: i64,
5151
__reserved: [::c_long; 3],
5252
}
5353

@@ -742,7 +742,6 @@ pub const SYS_rt_sigsuspend: ::c_long = 130;
742742
pub const SYS_sigaltstack: ::c_long = 131;
743743
pub const SYS_utime: ::c_long = 132;
744744
pub const SYS_mknod: ::c_long = 133;
745-
pub const SYS_uselib: ::c_long = 134;
746745
pub const SYS_personality: ::c_long = 135;
747746
pub const SYS_ustat: ::c_long = 136;
748747
pub const SYS_statfs: ::c_long = 137;
@@ -764,7 +763,6 @@ pub const SYS_munlockall: ::c_long = 152;
764763
pub const SYS_vhangup: ::c_long = 153;
765764
pub const SYS_modify_ldt: ::c_long = 154;
766765
pub const SYS_pivot_root: ::c_long = 155;
767-
pub const SYS__sysctl: ::c_long = 156;
768766
pub const SYS_prctl: ::c_long = 157;
769767
pub const SYS_arch_prctl: ::c_long = 158;
770768
pub const SYS_adjtimex: ::c_long = 159;
@@ -782,13 +780,9 @@ pub const SYS_sethostname: ::c_long = 170;
782780
pub const SYS_setdomainname: ::c_long = 171;
783781
pub const SYS_iopl: ::c_long = 172;
784782
pub const SYS_ioperm: ::c_long = 173;
785-
pub const SYS_create_module: ::c_long = 174;
786783
pub const SYS_init_module: ::c_long = 175;
787784
pub const SYS_delete_module: ::c_long = 176;
788-
pub const SYS_get_kernel_syms: ::c_long = 177;
789-
pub const SYS_query_module: ::c_long = 178;
790785
pub const SYS_quotactl: ::c_long = 179;
791-
pub const SYS_nfsservctl: ::c_long = 180;
792786
pub const SYS_getpmsg: ::c_long = 181;
793787
pub const SYS_putpmsg: ::c_long = 182;
794788
pub const SYS_afs_syscall: ::c_long = 183;
@@ -813,17 +807,13 @@ pub const SYS_time: ::c_long = 201;
813807
pub const SYS_futex: ::c_long = 202;
814808
pub const SYS_sched_setaffinity: ::c_long = 203;
815809
pub const SYS_sched_getaffinity: ::c_long = 204;
816-
pub const SYS_set_thread_area: ::c_long = 205;
817810
pub const SYS_io_setup: ::c_long = 206;
818811
pub const SYS_io_destroy: ::c_long = 207;
819812
pub const SYS_io_getevents: ::c_long = 208;
820813
pub const SYS_io_submit: ::c_long = 209;
821814
pub const SYS_io_cancel: ::c_long = 210;
822-
pub const SYS_get_thread_area: ::c_long = 211;
823815
pub const SYS_lookup_dcookie: ::c_long = 212;
824816
pub const SYS_epoll_create: ::c_long = 213;
825-
pub const SYS_epoll_ctl_old: ::c_long = 214;
826-
pub const SYS_epoll_wait_old: ::c_long = 215;
827817
pub const SYS_remap_file_pages: ::c_long = 216;
828818
pub const SYS_getdents64: ::c_long = 217;
829819
pub const SYS_set_tid_address: ::c_long = 218;
@@ -844,7 +834,6 @@ pub const SYS_epoll_wait: ::c_long = 232;
844834
pub const SYS_epoll_ctl: ::c_long = 233;
845835
pub const SYS_tgkill: ::c_long = 234;
846836
pub const SYS_utimes: ::c_long = 235;
847-
pub const SYS_vserver: ::c_long = 236;
848837
pub const SYS_mbind: ::c_long = 237;
849838
pub const SYS_set_mempolicy: ::c_long = 238;
850839
pub const SYS_get_mempolicy: ::c_long = 239;

src/unix/notbsd/linux/other/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ s! {
4444

4545
#[cfg(any(target_arch = "aarch64",
4646
target_arch = "sparc64",
47-
target_pointer_width = "32"))]
47+
all(target_pointer_width = "32",
48+
not(target_arch = "x86_64"))))]
4849
pub ut_session: ::c_long,
4950
#[cfg(any(target_arch = "aarch64",
5051
target_arch = "sparc64",
@@ -53,7 +54,8 @@ s! {
5354

5455
#[cfg(not(any(target_arch = "aarch64",
5556
target_arch = "sparc64",
56-
target_pointer_width = "32")))]
57+
all(target_pointer_width = "32",
58+
not(target_arch = "x86_64")))))]
5759
pub ut_session: ::int32_t,
5860
#[cfg(not(any(target_arch = "aarch64",
5961
target_arch = "sparc64",
@@ -568,13 +570,6 @@ extern {
568570

569571
#[link(name = "util")]
570572
extern {
571-
pub fn sysctl(name: *mut ::c_int,
572-
namelen: ::c_int,
573-
oldp: *mut ::c_void,
574-
oldlenp: *mut ::size_t,
575-
newp: *mut ::c_void,
576-
newlen: ::size_t)
577-
-> ::c_int;
578573
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
579574
pub fn backtrace(buf: *mut *mut ::c_void,
580575
sz: ::c_int) -> ::c_int;

0 commit comments

Comments
 (0)