Skip to content

Commit

Permalink
Require rust >= 1.26 and drop libc_int128 conditional
Browse files Browse the repository at this point in the history
[ resolve conflicts and add test skips that seem to be needed now -
  Trevor ]

(apply <rust-lang#4060> to `main`)
(cherry picked from commit 23a0d01)
  • Loading branch information
joshtriplett authored and tgross35 committed Nov 17, 2024
1 parent 30809c5 commit 60c9510
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 76 deletions.
12 changes: 8 additions & 4 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ fn test_apple(target: &str) {
// FIXME: Requires the macOS 14.4 SDK.
"os_sync_wake_by_address_flags_t" | "os_sync_wait_on_address_flags_t" => true,

// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

_ => false,
}
});
Expand Down Expand Up @@ -1798,12 +1801,13 @@ fn test_android(target: &str) {
// These are tested in the `linux_elf.rs` file.
"Elf64_Phdr" | "Elf32_Phdr" => true,

// FIXME: Somehow fails to test after removing cfg hacks:
"__uint128" => true,

// These are intended to be opaque
"posix_spawn_file_actions_t" => true,
"posix_spawnattr_t" => true,

// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

_ => false,
}
});
Expand Down Expand Up @@ -3659,7 +3663,7 @@ fn test_linux(target: &str) {
"priority_t" if musl => true,
"name_t" if musl => true,

// FIXME: Somehow fails to test after removing cfg hacks:
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

t => {
Expand Down
66 changes: 32 additions & 34 deletions src/fixed_width_ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type uint32_t = u32;
pub type uint64_t = u64;

cfg_if! {
if #[cfg(all(target_arch = "aarch64", not(any(target_os = "windows", target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos"))))] {
if #[cfg(all(target_arch = "aarch64", not(target_os = "windows")))] {
// This introduces partial support for FFI with __int128 and
// equivalent types on platforms where Rust's definition is validated
// to match the standard C ABI of that platform.
Expand Down Expand Up @@ -59,43 +59,41 @@ cfg_if! {
/// C __uint128_t (alternate name for [__uint128][])
pub type __uint128_t = u128;

macro_rules! static_assert_eq {
($a:expr, $b:expr) => {
const _: [(); $a] = [(); $b];
};
}
cfg_if! {
if #[cfg(libc_underscore_const_names)] {
macro_rules! static_assert_eq {
($a:expr, $b:expr) => {
const _: [(); $a] = [(); $b];
};
}

// NOTE: if you add more platforms to here, you may need to cfg
// these consts. They should always match the platform's values
// for `sizeof(__int128)` and `_Alignof(__int128)`.
const _SIZE_128: usize = 16;
const _ALIGN_128: usize = 16;
// NOTE: if you add more platforms to here, you may need to cfg
// these consts. They should always match the platform's values
// for `sizeof(__int128)` and `_Alignof(__int128)`.
const _SIZE_128: usize = 16;
const _ALIGN_128: usize = 16;

// Since Rust doesn't officially guarantee that these types
// have compatible ABIs, we const assert that these values have the
// known size/align of the target platform's libc. If rustc ever
// tries to regress things, it will cause a compilation error.
//
// This isn't a bullet-proof solution because e.g. it doesn't
// catch the fact that llvm and gcc disagree on how x64 __int128
// is actually *passed* on the stack (clang underaligns it for
// the same reason that rustc *never* properly aligns it).
// FIXME: temporarily disabled because of a ctest2 bug.
// static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);
// Since Rust doesn't officially guarantee that these types
// have compatible ABIs, we const assert that these values have the
// known size/align of the target platform's libc. If rustc ever
// tries to regress things, it will cause a compilation error.
//
// This isn't a bullet-proof solution because e.g. it doesn't
// catch the fact that llvm and gcc disagree on how x64 __int128
// is actually *passed* on the stack (clang underaligns it for
// the same reason that rustc *never* properly aligns it).
static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);
static_assert_eq!(core::mem::size_of::<__uint128>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);
static_assert_eq!(core::mem::size_of::<__int128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__int128_t>(), _ALIGN_128);

// static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
} else if #[cfg(all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos")))] {
/// /// C `__int128_t`
pub type __int128_t = i128;
/// /// C `__uint128_t`
pub type __uint128_t = u128;
static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
}
}
}
}
7 changes: 0 additions & 7 deletions src/unix/linux_like/android/b64/aarch64/int128.rs

This file was deleted.

9 changes: 6 additions & 3 deletions src/unix/linux_like/android/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ s! {
// auto-derive traits like Debug
__reserved: [[u64; 32]; 16],
}

pub struct user_fpsimd_struct {
pub vregs: [::__uint128_t; 32],
pub fpsr: u32,
pub fpcr: u32,
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -466,6 +472,3 @@ pub const PROT_MTE: ::c_int = 0x20;
// From NDK's asm/auxvec.h
pub const AT_SYSINFO_EHDR: ::c_ulong = 33;
pub const AT_VECTOR_SIZE_ARCH: ::c_ulong = 2;

mod int128;
pub use self::int128::*;
8 changes: 0 additions & 8 deletions src/unix/linux_like/linux/gnu/b64/aarch64/fallback.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/unix/linux_like/linux/gnu/b64/aarch64/int128.rs

This file was deleted.

9 changes: 6 additions & 3 deletions src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ s! {
__reserved: [[u64; 32]; 16],
}

pub struct user_fpsimd_struct {
pub vregs: [::__uint128_t; 32],
pub fpsr: ::c_uint,
pub fpcr: ::c_uint,
}

#[repr(align(8))]
pub struct clone_args {
pub flags: ::c_ulonglong,
Expand Down Expand Up @@ -964,6 +970,3 @@ cfg_if! {
pub use self::lp64::*;
}
}

mod int128;
pub use self::int128::*;
7 changes: 0 additions & 7 deletions src/unix/linux_like/linux/musl/b64/aarch64/int128.rs

This file was deleted.

9 changes: 6 additions & 3 deletions src/unix/linux_like/linux/musl/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ s! {
pub set_tid_size: ::c_ulonglong,
pub cgroup: ::c_ulonglong,
}

pub struct user_fpsimd_struct {
pub vregs: [::__uint128_t; 32],
pub fpsr: u32,
pub fpcr: u32,
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -686,6 +692,3 @@ pub const VMIN: usize = 6;
pub const IEXTEN: ::tcflag_t = 0x00008000;
pub const TOSTOP: ::tcflag_t = 0x00000100;
pub const FLUSHO: ::tcflag_t = 0x00001000;

mod int128;
pub use self::int128::*;

0 comments on commit 60c9510

Please sign in to comment.