Skip to content

Commit 7418775

Browse files
committed
Separate L4Re from Linux code, add aarch64 and enable tests
The L4Re code was previously attached to the Linux code which was not correct in many ways. This commit separates the L4Re code and enables the libc-tests and includes the fixes for the failing tests. Aarch64 is added as a second supported architecture (more to come).
1 parent 6370cba commit 7418775

File tree

16 files changed

+6945
-2731
lines changed

16 files changed

+6945
-2731
lines changed

libc-test/build.rs

Lines changed: 65 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn do_ctest() {
5353
t if t.contains("emscripten") => test_emscripten(t),
5454
t if t.contains("freebsd") => test_freebsd(t),
5555
t if t.contains("haiku") => test_haiku(t),
56+
t if t.contains("l4re") => test_linux(t),
5657
t if t.contains("linux") => test_linux(t),
5758
t if t.contains("netbsd") => test_netbsd(t),
5859
t if t.contains("openbsd") => test_openbsd(t),
@@ -94,9 +95,10 @@ fn do_semver() {
9495
// NOTE: Android doesn't include the unix file (or the Linux file) because
9596
// there are some many definitions missing it's actually easier just to
9697
// maintain a file for Android.
97-
// NOTE: AIX doesn't include the unix file because there are definitions
98-
// missing on AIX. It is easier to maintain a file for AIX.
99-
if family != os && !matches!(os.as_str(), "android" | "aix") {
98+
// NOTE: AIX and L4Re do not include the unix file because there are
99+
// definitions missing on these systems. It is easier to maintain separate
100+
// files for them.
101+
if family != os && !matches!(os.as_str(), "android" | "aix" | "l4re") {
100102
process_semver_file(&mut output, &mut semver_root, &family);
101103
}
102104
// We don't do semver for unknown targets.
@@ -3568,18 +3570,26 @@ fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
35683570
}
35693571

35703572
fn test_linux(target: &str) {
3571-
assert!(target.contains("linux"));
3573+
assert!(target.contains("linux") || target.contains("l4re"));
3574+
3575+
// target_os
3576+
let linux = target.contains("linux");
3577+
let l4re = target.contains("l4re");
35723578

35733579
// target_env
35743580
let gnu = target.contains("gnu");
35753581
let musl = target.contains("musl") || target.contains("ohos");
35763582
let uclibc = target.contains("uclibc");
35773583

3578-
match (gnu, musl, uclibc) {
3579-
(true, false, false) => (),
3580-
(false, true, false) => (),
3581-
(false, false, true) => (),
3582-
(_, _, _) => panic!("linux target lib is gnu: {gnu}, musl: {musl}, uclibc: {uclibc}"),
3584+
match (linux, gnu, musl, uclibc) {
3585+
(true, true, false, false) => (),
3586+
(true, false, true, false) => (),
3587+
(true, false, false, true) => (),
3588+
(false, false, false, true) => (),
3589+
(_, _, _, _) => panic!(
3590+
"{} target lib is gnu: {gnu}, musl: {musl}, uclibc: {uclibc}",
3591+
if linux { "linux" } else { "l4re" }
3592+
),
35833593
}
35843594

35853595
let arm = target.contains("arm");
@@ -3613,6 +3623,9 @@ fn test_linux(target: &str) {
36133623
.define("__GLIBC_USE_DEPRECATED_SCANF", None);
36143624

36153625
config_gnu_bits(target, &mut cfg);
3626+
if l4re {
3627+
cfg.flag("-Wno-unused-function");
3628+
}
36163629

36173630
headers! { cfg:
36183631
"ctype.h",
@@ -3631,11 +3644,12 @@ fn test_linux(target: &str) {
36313644
"libgen.h",
36323645
"limits.h",
36333646
"link.h",
3634-
"linux/sysctl.h",
3647+
[uclibc]: "linux/if_ether.h",
3648+
[!l4re]: "linux/sysctl.h",
36353649
"locale.h",
36363650
"malloc.h",
36373651
"mntent.h",
3638-
"mqueue.h",
3652+
[!l4re]: "mqueue.h",
36393653
"net/ethernet.h",
36403654
"net/if.h",
36413655
"net/if_arp.h",
@@ -3645,6 +3659,7 @@ fn test_linux(target: &str) {
36453659
"netinet/ip.h",
36463660
"netinet/tcp.h",
36473661
"netinet/udp.h",
3662+
[l4re]: "netpacket/packet.h",
36483663
"poll.h",
36493664
"pthread.h",
36503665
"pty.h",
@@ -3655,43 +3670,44 @@ fn test_linux(target: &str) {
36553670
"semaphore.h",
36563671
"shadow.h",
36573672
"signal.h",
3658-
"spawn.h",
3659-
"stddef.h",
3673+
[!l4re]: "spawn.h",
3674+
[!l4re]: "stddef.h",
36603675
"stdint.h",
36613676
"stdio.h",
36623677
"stdlib.h",
36633678
"string.h",
3664-
"sys/epoll.h",
3665-
"sys/eventfd.h",
3679+
[l4re]: "sys/auxv.h",
3680+
[!l4re]: "sys/epoll.h",
3681+
[!l4re]: "sys/eventfd.h",
36663682
"sys/file.h",
3667-
"sys/fsuid.h",
3668-
"sys/klog.h",
3669-
"sys/inotify.h",
3683+
[!l4re]: "sys/fsuid.h",
3684+
[!l4re]: "sys/klog.h",
3685+
[!l4re]: "sys/inotify.h",
36703686
"sys/ioctl.h",
36713687
"sys/ipc.h",
36723688
"sys/mman.h",
36733689
"sys/mount.h",
3674-
"sys/msg.h",
3675-
"sys/personality.h",
3690+
[!l4re]: "sys/msg.h",
3691+
[!l4re]: "sys/personality.h",
36763692
"sys/prctl.h",
3677-
"sys/ptrace.h",
3678-
"sys/quota.h",
3679-
"sys/random.h",
3680-
"sys/reboot.h",
3693+
[!l4re]: "sys/ptrace.h",
3694+
[!l4re]: "sys/quota.h",
3695+
[!l4re]: "sys/random.h",
3696+
[!l4re]: "sys/reboot.h",
36813697
"sys/resource.h",
36823698
"sys/sem.h",
3683-
"sys/sendfile.h",
3699+
[!l4re]: "sys/sendfile.h",
36843700
"sys/shm.h",
3685-
"sys/signalfd.h",
3701+
[!l4re]: "sys/signalfd.h",
36863702
"sys/socket.h",
36873703
"sys/stat.h",
36883704
"sys/statvfs.h",
3689-
"sys/swap.h",
3705+
[!l4re]: "sys/swap.h",
36903706
"sys/syscall.h",
36913707
"sys/time.h",
3692-
"sys/timerfd.h",
3708+
[!l4re]: "sys/timerfd.h",
36933709
"sys/times.h",
3694-
"sys/timex.h",
3710+
[!l4re]: "sys/timex.h",
36953711
"sys/types.h",
36963712
"sys/uio.h",
36973713
"sys/un.h",
@@ -3713,12 +3729,12 @@ fn test_linux(target: &str) {
37133729
// ARM: https://bugzilla.redhat.com/show_bug.cgi?id=1116162
37143730
// Also unavailable on gnueabihf with glibc 2.30.
37153731
// https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=6b33f373c7b9199e00ba5fbafd94ac9bfb4337b1
3716-
[(x86_64 || x86_32 || arm) && !gnueabihf]: "sys/io.h",
3732+
[(x86_64 || x86_32 || arm) && !gnueabihf && !l4re]: "sys/io.h",
37173733
// `sys/reg.h` is only available on x86 and x86_64
3718-
[x86_64 || x86_32]: "sys/reg.h",
3734+
[(x86_64 || x86_32) && !l4re]: "sys/reg.h",
37193735
// sysctl system call is deprecated and not available on musl
37203736
// It is also unsupported in x32, deprecated since glibc 2.30:
3721-
[!(x32 || musl || gnu)]: "sys/sysctl.h",
3737+
[!(x32 || musl || gnu || l4re)]: "sys/sysctl.h",
37223738
// <execinfo.h> is not supported by musl:
37233739
// https://www.openwall.com/lists/musl/2015/04/09/3
37243740
// <execinfo.h> is not present on uclibc.
@@ -3728,11 +3744,11 @@ fn test_linux(target: &str) {
37283744
// Include linux headers at the end:
37293745
headers! {
37303746
cfg:
3731-
[loongarch64 || riscv64]: "asm/hwcap.h",
3732-
"asm/mman.h",
3747+
[(loongarch64 || riscv64) && !l4re]: "asm/hwcap.h",
3748+
[!l4re]: "asm/mman.h",
37333749
}
37343750

3735-
if !wasm32 {
3751+
if !wasm32 && !l4re {
37363752
headers! { cfg:
37373753
[gnu]: "linux/aio_abi.h",
37383754
"linux/can.h",
@@ -3750,7 +3766,6 @@ fn test_linux(target: &str) {
37503766
"linux/if.h",
37513767
"linux/if_addr.h",
37523768
"linux/if_alg.h",
3753-
"linux/if_ether.h",
37543769
"linux/if_packet.h",
37553770
"linux/if_tun.h",
37563771
"linux/if_xdp.h",
@@ -3797,7 +3812,6 @@ fn test_linux(target: &str) {
37973812
"linux/wait.h",
37983813
"linux/wireless.h",
37993814
"sys/fanotify.h",
3800-
// <sys/auxv.h> is not present on uclibc
38013815
[!uclibc]: "sys/auxv.h",
38023816
[gnu || musl]: "linux/close_range.h",
38033817
}
@@ -3806,7 +3820,7 @@ fn test_linux(target: &str) {
38063820
// note: aio.h must be included before sys/mount.h
38073821
headers! {
38083822
cfg:
3809-
"sys/xattr.h",
3823+
[!l4re]: "sys/xattr.h",
38103824
"sys/sysinfo.h",
38113825
// AIO is not supported by uclibc:
38123826
[!uclibc]: "aio.h",
@@ -3836,10 +3850,11 @@ fn test_linux(target: &str) {
38363850

38373851
cfg.rename_type(move |ty| {
38383852
match ty {
3839-
"Ioctl" if gnu => Some("unsigned long".to_string()),
3853+
"Ioctl" if gnu || uclibc => Some("unsigned long".to_string()),
38403854
"Ioctl" => Some("int".to_string()),
38413855
// LFS64 types have been removed in musl 1.2.4+
38423856
"off64_t" if musl => Some("off_t".to_string()),
3857+
"fsword_t" if uclibc => Some("__SWORD_TYPE".to_string()),
38433858
_ => None,
38443859
}
38453860
});
@@ -4095,6 +4110,13 @@ fn test_linux(target: &str) {
40954110

40964111
cfg.skip_const(move |constant| {
40974112
let name = constant.ident();
4113+
4114+
// L4Re requires a min stack size of 64k; that isn't defined in uClibc, but
4115+
// somewhere in the core libraries. uClibc wants 16k, but that's not enough.
4116+
if l4re && name == "PTHREAD_STACK_MIN" {
4117+
return true;
4118+
}
4119+
40984120
if !gnu {
40994121
// Skip definitions from the kernel on non-glibc Linux targets.
41004122
// They're libc-independent, so we only need to check them on one
@@ -4274,7 +4296,7 @@ fn test_linux(target: &str) {
42744296

42754297
// FIXME(musl): on musl the pthread types are defined a little differently
42764298
// - these constants are used by the glibc implementation.
4277-
n if musl && n.contains("__SIZEOF_PTHREAD") => true,
4299+
n if (musl || uclibc) && n.contains("__SIZEOF_PTHREAD") => true,
42784300

42794301
// FIXME(linux): It was extended to 4096 since glibc 2.31 (Linux 5.4).
42804302
// We should do so after a while.
@@ -4861,7 +4883,9 @@ fn test_linux(target: &str) {
48614883

48624884
ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap();
48634885

4864-
test_linux_like_apis(target);
4886+
if !l4re {
4887+
test_linux_like_apis(target);
4888+
}
48654889
}
48664890

48674891
// This function tests APIs that are incompatible to test when other APIs

0 commit comments

Comments
 (0)