Skip to content

Commit 77aa3e5

Browse files
committed
Auto merge of #1519 - gnzlbg:max_align_t, r=gnzlbg
Implement max_align_t Implement `max_align_t` for windows and unix targets. WIP: at this stage I just want to see what breaks.
2 parents 2f5ed5d + 974f550 commit 77aa3e5

File tree

43 files changed

+262
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+262
-24
lines changed

ci/azure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
TARGET: x86_64-unknown-linux-gnu
2626

2727
- job: DockerLinuxTier2
28-
dependsOn: DockerLinuxTier1
28+
#dependsOn: DockerLinuxTier1
2929
pool:
3030
vmImage: ubuntu-16.04
3131
steps:

libc-test/build.rs

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ fn do_ctest() {
3131
}
3232
}
3333

34+
fn ctest_cfg() -> ctest::TestGenerator {
35+
let mut cfg = ctest::TestGenerator::new();
36+
let libc_cfgs = [
37+
"libc_priv_mod_use",
38+
"libc_union",
39+
"libc_const_size_of",
40+
"libc_align",
41+
"libc_core_cvoid",
42+
"libc_packedN",
43+
"libc_thread_local",
44+
];
45+
for f in &libc_cfgs {
46+
cfg.cfg(f, None);
47+
}
48+
cfg
49+
}
50+
3451
fn main() {
3552
do_cc();
3653
do_ctest();
@@ -59,8 +76,9 @@ macro_rules! headers {
5976
fn test_apple(target: &str) {
6077
assert!(target.contains("apple"));
6178
let x86_64 = target.contains("x86_64");
79+
let i686 = target.contains("i686");
6280

63-
let mut cfg = ctest::TestGenerator::new();
81+
let mut cfg = ctest_cfg();
6482
cfg.flag("-Wno-deprecated-declarations");
6583
cfg.define("__APPLE_USE_RFC_3542", None);
6684

@@ -225,13 +243,18 @@ fn test_apple(target: &str) {
225243
}
226244
});
227245

246+
cfg.skip_roundtrip(move |s| match s {
247+
// FIXME: this type has the wrong ABI
248+
"max_align_t" if i686 => true,
249+
_ => false,
250+
});
228251
cfg.generate("../src/lib.rs", "main.rs");
229252
}
230253

231254
fn test_openbsd(target: &str) {
232255
assert!(target.contains("openbsd"));
233256

234-
let mut cfg = ctest::TestGenerator::new();
257+
let mut cfg = ctest_cfg();
235258
cfg.flag("-Wno-deprecated-declarations");
236259

237260
headers! { cfg:
@@ -371,7 +394,7 @@ fn test_windows(target: &str) {
371394
assert!(target.contains("windows"));
372395
let gnu = target.contains("gnu");
373396

374-
let mut cfg = ctest::TestGenerator::new();
397+
let mut cfg = ctest_cfg();
375398
cfg.define("_WIN32_WINNT", Some("0x8000"));
376399

377400
headers! { cfg:
@@ -474,7 +497,7 @@ fn test_windows(target: &str) {
474497
fn test_redox(target: &str) {
475498
assert!(target.contains("redox"));
476499

477-
let mut cfg = ctest::TestGenerator::new();
500+
let mut cfg = ctest_cfg();
478501
cfg.flag("-Wno-deprecated-declarations");
479502

480503
headers! {
@@ -540,7 +563,7 @@ fn test_redox(target: &str) {
540563
fn test_cloudabi(target: &str) {
541564
assert!(target.contains("cloudabi"));
542565

543-
let mut cfg = ctest::TestGenerator::new();
566+
let mut cfg = ctest_cfg();
544567
cfg.flag("-Wno-deprecated-declarations");
545568

546569
headers! {
@@ -611,7 +634,7 @@ fn test_cloudabi(target: &str) {
611634
fn test_solaris(target: &str) {
612635
assert!(target.contains("solaris"));
613636

614-
let mut cfg = ctest::TestGenerator::new();
637+
let mut cfg = ctest_cfg();
615638
cfg.flag("-Wno-deprecated-declarations");
616639

617640
cfg.define("_XOPEN_SOURCE", Some("700"));
@@ -722,7 +745,7 @@ fn test_solaris(target: &str) {
722745
fn test_netbsd(target: &str) {
723746
assert!(target.contains("netbsd"));
724747
let rumprun = target.contains("rumprun");
725-
let mut cfg = ctest::TestGenerator::new();
748+
let mut cfg = ctest_cfg();
726749

727750
cfg.flag("-Wno-deprecated-declarations");
728751
cfg.define("_NETBSD_SOURCE", Some("1"));
@@ -922,7 +945,7 @@ fn test_netbsd(target: &str) {
922945

923946
fn test_dragonflybsd(target: &str) {
924947
assert!(target.contains("dragonfly"));
925-
let mut cfg = ctest::TestGenerator::new();
948+
let mut cfg = ctest_cfg();
926949
cfg.flag("-Wno-deprecated-declarations");
927950

928951
headers! {
@@ -1127,7 +1150,7 @@ fn test_dragonflybsd(target: &str) {
11271150
fn test_wasi(target: &str) {
11281151
assert!(target.contains("wasi"));
11291152

1130-
let mut cfg = ctest::TestGenerator::new();
1153+
let mut cfg = ctest_cfg();
11311154
cfg.define("_GNU_SOURCE", None);
11321155

11331156
headers! { cfg:
@@ -1204,7 +1227,7 @@ fn test_android(target: &str) {
12041227
};
12051228
let x86 = target.contains("i686") || target.contains("x86_64");
12061229

1207-
let mut cfg = ctest::TestGenerator::new();
1230+
let mut cfg = ctest_cfg();
12081231
cfg.define("_GNU_SOURCE", None);
12091232

12101233
headers! { cfg:
@@ -1429,7 +1452,7 @@ fn test_android(target: &str) {
14291452

14301453
fn test_freebsd(target: &str) {
14311454
assert!(target.contains("freebsd"));
1432-
let mut cfg = ctest::TestGenerator::new();
1455+
let mut cfg = ctest_cfg();
14331456

14341457
let freebsd_ver = which_freebsd();
14351458

@@ -1631,7 +1654,7 @@ fn test_freebsd(target: &str) {
16311654
fn test_emscripten(target: &str) {
16321655
assert!(target.contains("emscripten"));
16331656

1634-
let mut cfg = ctest::TestGenerator::new();
1657+
let mut cfg = ctest_cfg();
16351658
cfg.define("_GNU_SOURCE", None); // FIXME: ??
16361659

16371660
headers! { cfg:
@@ -1852,17 +1875,19 @@ fn test_linux(target: &str) {
18521875
}
18531876

18541877
let arm = target.contains("arm");
1855-
let x86_64 = target.contains("x86_64");
1856-
let x86_32 = target.contains("i686");
1857-
let x32 = target.contains("x32");
1878+
let i686 = target.contains("i686");
18581879
let mips = target.contains("mips");
18591880
let mips32 = mips && !target.contains("64");
1860-
let mips64 = mips && target.contains("64");
18611881
let mips32_musl = mips32 && musl;
1862-
let sparc64 = target.contains("sparc64");
1882+
let mips64 = mips && target.contains("64");
1883+
let ppc64 = target.contains("powerpc64");
18631884
let s390x = target.contains("s390x");
1885+
let sparc64 = target.contains("sparc64");
1886+
let x32 = target.contains("x32");
1887+
let x86_32 = target.contains("i686");
1888+
let x86_64 = target.contains("x86_64");
18641889

1865-
let mut cfg = ctest::TestGenerator::new();
1890+
let mut cfg = ctest_cfg();
18661891
cfg.define("_GNU_SOURCE", None);
18671892
// This macro re-deifnes fscanf,scanf,sscanf to link to the symbols that are
18681893
// deprecated since glibc >= 2.29. This allows Rust binaries to link against
@@ -2286,6 +2311,9 @@ fn test_linux(target: &str) {
22862311
true
22872312
}
22882313

2314+
// FIXME: the call ABI of max_align_t is incorrect on these platforms:
2315+
"max_align_t" if i686 || mips64 || ppc64 => true,
2316+
22892317
_ => false,
22902318
});
22912319

@@ -2305,7 +2333,7 @@ fn test_linux_like_apis(target: &str) {
23052333

23062334
if linux || android || emscripten {
23072335
// test strerror_r from the `string.h` header
2308-
let mut cfg = ctest::TestGenerator::new();
2336+
let mut cfg = ctest_cfg();
23092337
cfg.skip_type(|_| true).skip_static(|_| true);
23102338

23112339
headers! { cfg: "string.h" }
@@ -2321,7 +2349,7 @@ fn test_linux_like_apis(target: &str) {
23212349
if linux || android || emscripten {
23222350
// test fcntl - see:
23232351
// http://man7.org/linux/man-pages/man2/fcntl.2.html
2324-
let mut cfg = ctest::TestGenerator::new();
2352+
let mut cfg = ctest_cfg();
23252353

23262354
if musl {
23272355
cfg.header("fcntl.h");
@@ -2351,7 +2379,7 @@ fn test_linux_like_apis(target: &str) {
23512379

23522380
if linux || android {
23532381
// test termios
2354-
let mut cfg = ctest::TestGenerator::new();
2382+
let mut cfg = ctest_cfg();
23552383
cfg.header("asm/termbits.h");
23562384
cfg.skip_type(|_| true)
23572385
.skip_static(|_| true)
@@ -2368,7 +2396,7 @@ fn test_linux_like_apis(target: &str) {
23682396

23692397
if linux || android {
23702398
// test IPV6_ constants:
2371-
let mut cfg = ctest::TestGenerator::new();
2399+
let mut cfg = ctest_cfg();
23722400
headers! {
23732401
cfg:
23742402
"linux/in6.h"
@@ -2399,7 +2427,7 @@ fn test_linux_like_apis(target: &str) {
23992427
// These types have a field called `p_type`, but including
24002428
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
24012429
// making the tests for these fails when both are included.
2402-
let mut cfg = ctest::TestGenerator::new();
2430+
let mut cfg = ctest_cfg();
24032431
cfg.header("elf.h");
24042432
cfg.skip_fn(|_| true)
24052433
.skip_static(|_| true)

src/unix/bsd/apple/b32/align.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 2]);

src/unix/bsd/apple/b32.rs renamed to src/unix/bsd/apple/b32/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,10 @@ extern "C" {
106106
options: ::c_ulong,
107107
) -> ::c_int;
108108
}
109+
110+
cfg_if! {
111+
if #[cfg(libc_align)] {
112+
mod align;
113+
pub use self::align::*;
114+
}
115+
}

src/unix/bsd/apple/b64/align.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 2]);

src/unix/bsd/apple/b64.rs renamed to src/unix/bsd/apple/b64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ extern "C" {
111111
options: ::c_uint,
112112
) -> ::c_int;
113113
}
114+
115+
cfg_if! {
116+
if #[cfg(libc_align)] {
117+
mod align;
118+
pub use self::align::*;
119+
}
120+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 4]);

src/unix/bsd/freebsdlike/freebsd/x86_64.rs renamed to src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ cfg_if! {
1515
}
1616
}
1717
pub const MAP_32BIT: ::c_int = 0x00080000;
18+
19+
cfg_if! {
20+
if #[cfg(libc_align)] {
21+
mod align;
22+
pub use self::align::*;
23+
}
24+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(8))]
3+
pub struct max_align_t([f64; 2]);

src/unix/linux_like/android/b32/x86.rs renamed to src/unix/linux_like/android/b32/x86/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,10 @@ pub const CS: ::c_int = 13;
413413
pub const EFL: ::c_int = 14;
414414
pub const UESP: ::c_int = 15;
415415
pub const SS: ::c_int = 16;
416+
417+
cfg_if! {
418+
if #[cfg(libc_align)] {
419+
mod align;
420+
pub use self::align::*;
421+
}
422+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f32; 8]);

src/unix/linux_like/android/b64/aarch64.rs renamed to src/unix/linux_like/android/b64/aarch64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,10 @@ pub const SYS_pkey_mprotect: ::c_long = 288;
323323
pub const SYS_pkey_alloc: ::c_long = 289;
324324
pub const SYS_pkey_free: ::c_long = 290;
325325
pub const SYS_syscalls: ::c_long = 292;
326+
327+
cfg_if! {
328+
if #[cfg(libc_align)] {
329+
mod align;
330+
pub use self::align::*;
331+
}
332+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 4]);

src/unix/linux_like/android/b64/x86_64.rs renamed to src/unix/linux_like/android/b64/x86_64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,10 @@ pub const DS: ::c_int = 23;
418418
pub const ES: ::c_int = 24;
419419
pub const FS: ::c_int = 25;
420420
pub const GS: ::c_int = 26;
421+
422+
cfg_if! {
423+
if #[cfg(libc_align)] {
424+
mod align;
425+
pub use self::align::*;
426+
}
427+
}

src/unix/linux_like/emscripten/align.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
macro_rules! expand_align {
22
() => {
3+
#[derive(Copy, Clone, Debug, PartialEq)]
4+
#[repr(C, align(8))]
5+
pub struct max_align_t([f64; 2]);
6+
37
s! {
48
#[repr(align(4))]
59
pub struct pthread_mutex_t {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(8))]
3+
pub struct max_align_t([i64; 2]);

src/unix/linux_like/linux/gnu/b32/arm.rs renamed to src/unix/linux_like/linux/gnu/b32/arm/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,3 +859,10 @@ pub const SYS_pkey_mprotect: ::c_long = 394;
859859
pub const SYS_pkey_alloc: ::c_long = 395;
860860
pub const SYS_pkey_free: ::c_long = 396;
861861
pub const SYS_statx: ::c_long = 397;
862+
863+
cfg_if! {
864+
if #[cfg(libc_align)] {
865+
mod align;
866+
pub use self::align::*;
867+
}
868+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(8))]
3+
pub struct max_align_t([f32; 4]);

src/unix/linux_like/linux/gnu/b32/mips.rs renamed to src/unix/linux_like/linux/gnu/b32/mips/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,3 +891,10 @@ pub const TIOCM_RNG: ::c_int = 0x200;
891891
pub const TIOCM_DSR: ::c_int = 0x400;
892892

893893
pub const EHWPOISON: ::c_int = 168;
894+
895+
cfg_if! {
896+
if #[cfg(libc_align)] {
897+
mod align;
898+
pub use self::align::*;
899+
}
900+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 6]);

src/unix/linux_like/linux/gnu/b32/x86.rs renamed to src/unix/linux_like/linux/gnu/b32/x86/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,10 @@ extern "C" {
11471147
ucp: *const ucontext_t,
11481148
) -> ::c_int;
11491149
}
1150+
1151+
cfg_if! {
1152+
if #[cfg(libc_align)] {
1153+
mod align;
1154+
pub use self::align::*;
1155+
}
1156+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f32; 8]);

src/unix/linux_like/linux/gnu/b64/aarch64.rs renamed to src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,10 @@ extern "C" {
936936
newlen: ::size_t,
937937
) -> ::c_int;
938938
}
939+
940+
cfg_if! {
941+
if #[cfg(libc_align)] {
942+
mod align;
943+
pub use self::align::*;
944+
}
945+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#[derive(Copy, Clone, Debug, PartialEq)]
2+
#[repr(C, align(16))]
3+
pub struct max_align_t([f64; 4]);

0 commit comments

Comments
 (0)