From dc1956e2efed951b9cfaa64109956707859c0573 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 15 Apr 2018 14:45:26 +0200 Subject: [PATCH 1/3] fix undefined behavior due to incorrect packing on macosx --- libc-test/build.rs | 3 --- src/unix/bsd/apple/mod.rs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 0f4efdca638f1..9805ef0e2166c 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -416,9 +416,6 @@ fn main() { // which is absent in glibc, has to be defined. "__timeval" if linux => true, - // The alignment of this is 4 on 64-bit OSX... - "kevent" | "shmid_ds" if apple && x86_64 => true, - // This is actually a union, not a struct "sigval" => true, diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 9cd5db654708d..00110e13e25b7 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -245,7 +245,7 @@ s! { pub f_reserved: [::uint32_t; 8], } - // FIXME: this should have align 4 but it's got align 8 on 64-bit + #[repr(packed(4))] pub struct kevent { pub ident: ::uintptr_t, pub filter: ::int16_t, @@ -524,7 +524,7 @@ s! { pub _key: ::key_t, } - // FIXME: this should have align 4 but it's got align 8 on 64-bit + #[repr(packed(4))] pub struct shmid_ds { pub shm_perm: ipc_perm, pub shm_segsz: ::size_t, From dfee17f1ff58db3f9b682554bd479de4363efac6 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 15 Apr 2018 14:50:00 +0200 Subject: [PATCH 2/3] fix this for stdbuild only --- libc-test/build.rs | 5 +++++ src/lib.rs | 2 +- src/unix/bsd/apple/mod.rs | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 9805ef0e2166c..74a0b4b101a7e 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -416,6 +416,11 @@ fn main() { // which is absent in glibc, has to be defined. "__timeval" if linux => true, + // Fixed on stdbuild with repr(packed(4)) + // Once repr_packed stabilizes we can fix this unconditionally + // and remove this check. + "kevent" | "shmid_ds" if apple && x86_64 => true, + // This is actually a union, not a struct "sigval" => true, diff --git a/src/lib.rs b/src/lib.rs index 2555480665185..877e87dc76b25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,7 +87,7 @@ // Attributes needed when building as part of the standard library #![cfg_attr(feature = "stdbuild", feature(no_std, staged_api, custom_attribute, cfg_target_vendor))] -#![cfg_attr(feature = "stdbuild", feature(link_cfg))] +#![cfg_attr(feature = "stdbuild", feature(link_cfg, repr_packed))] #![cfg_attr(feature = "stdbuild", no_std)] #![cfg_attr(feature = "stdbuild", staged_api)] #![cfg_attr(feature = "stdbuild", allow(warnings))] diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 00110e13e25b7..8fb1a1251dc59 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -245,7 +245,7 @@ s! { pub f_reserved: [::uint32_t; 8], } - #[repr(packed(4))] + #[cfg_attr(feature = "stdbuild", repr(packed(4)))] pub struct kevent { pub ident: ::uintptr_t, pub filter: ::int16_t, @@ -524,7 +524,7 @@ s! { pub _key: ::key_t, } - #[repr(packed(4))] + #[cfg_attr(feature = "stdbuild", repr(packed(4)))] pub struct shmid_ds { pub shm_perm: ipc_perm, pub shm_segsz: ::size_t, From 77837a0f335d09578bcdddf20deae65f04be0c8e Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 17 Apr 2018 00:30:50 +0200 Subject: [PATCH 3/3] bump compat Rust version from 1.0.0 to 1.13.0 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6acf0a80641ba..dc2cdab903e91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,9 @@ env: secure: "e2/3QjgRN9atOuSHp22TrYG7QVKcYUWY48Hi9b60w+r1+BhPkTseIJLte7WefRhdXtqpjjUJTooKDhnurFOeHaCT+nmBgiv+FPU893sBl4bhesY4m0vgUJVbNZcs6lTImYekWVb+aqjGdgV/XAgCw7c3kPmrZV0MzGDWL64Xaps=" matrix: include: - # 1.0.0 compat + # 1.13.0 compat - env: TARGET=x86_64-unknown-linux-gnu NO_ADD=1 - rust: 1.0.0 + rust: 1.13.0 script: rm -f Cargo.lock && cargo build install: