Skip to content

Commit f3afa6f

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 7e51deb commit f3afa6f

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.
@@ -3563,18 +3565,26 @@ fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
35633565
}
35643566

35653567
fn test_linux(target: &str) {
3566-
assert!(target.contains("linux"));
3568+
assert!(target.contains("linux") || target.contains("l4re"));
3569+
3570+
// target_os
3571+
let linux = target.contains("linux");
3572+
let l4re = target.contains("l4re");
35673573

35683574
// target_env
35693575
let gnu = target.contains("gnu");
35703576
let musl = target.contains("musl") || target.contains("ohos");
35713577
let uclibc = target.contains("uclibc");
35723578

3573-
match (gnu, musl, uclibc) {
3574-
(true, false, false) => (),
3575-
(false, true, false) => (),
3576-
(false, false, true) => (),
3577-
(_, _, _) => panic!("linux target lib is gnu: {gnu}, musl: {musl}, uclibc: {uclibc}"),
3579+
match (linux, gnu, musl, uclibc) {
3580+
(true, true, false, false) => (),
3581+
(true, false, true, false) => (),
3582+
(true, false, false, true) => (),
3583+
(false, false, false, true) => (),
3584+
(_, _, _, _) => panic!(
3585+
"{} target lib is gnu: {gnu}, musl: {musl}, uclibc: {uclibc}",
3586+
if linux { "linux" } else { "l4re" }
3587+
),
35783588
}
35793589

35803590
let arm = target.contains("arm");
@@ -3608,6 +3618,9 @@ fn test_linux(target: &str) {
36083618
.define("__GLIBC_USE_DEPRECATED_SCANF", None);
36093619

36103620
config_gnu_bits(target, &mut cfg);
3621+
if l4re {
3622+
cfg.flag("-Wno-unused-function");
3623+
}
36113624

36123625
headers! { cfg:
36133626
"ctype.h",
@@ -3626,11 +3639,12 @@ fn test_linux(target: &str) {
36263639
"libgen.h",
36273640
"limits.h",
36283641
"link.h",
3629-
"linux/sysctl.h",
3642+
[uclibc]: "linux/if_ether.h",
3643+
[!l4re]: "linux/sysctl.h",
36303644
"locale.h",
36313645
"malloc.h",
36323646
"mntent.h",
3633-
"mqueue.h",
3647+
[!l4re]: "mqueue.h",
36343648
"net/ethernet.h",
36353649
"net/if.h",
36363650
"net/if_arp.h",
@@ -3640,6 +3654,7 @@ fn test_linux(target: &str) {
36403654
"netinet/ip.h",
36413655
"netinet/tcp.h",
36423656
"netinet/udp.h",
3657+
[l4re]: "netpacket/packet.h",
36433658
"poll.h",
36443659
"pthread.h",
36453660
"pty.h",
@@ -3650,43 +3665,44 @@ fn test_linux(target: &str) {
36503665
"semaphore.h",
36513666
"shadow.h",
36523667
"signal.h",
3653-
"spawn.h",
3654-
"stddef.h",
3668+
[!l4re]: "spawn.h",
3669+
[!l4re]: "stddef.h",
36553670
"stdint.h",
36563671
"stdio.h",
36573672
"stdlib.h",
36583673
"string.h",
3659-
"sys/epoll.h",
3660-
"sys/eventfd.h",
3674+
[l4re]: "sys/auxv.h",
3675+
[!l4re]: "sys/epoll.h",
3676+
[!l4re]: "sys/eventfd.h",
36613677
"sys/file.h",
3662-
"sys/fsuid.h",
3663-
"sys/klog.h",
3664-
"sys/inotify.h",
3678+
[!l4re]: "sys/fsuid.h",
3679+
[!l4re]: "sys/klog.h",
3680+
[!l4re]: "sys/inotify.h",
36653681
"sys/ioctl.h",
36663682
"sys/ipc.h",
36673683
"sys/mman.h",
36683684
"sys/mount.h",
3669-
"sys/msg.h",
3670-
"sys/personality.h",
3685+
[!l4re]: "sys/msg.h",
3686+
[!l4re]: "sys/personality.h",
36713687
"sys/prctl.h",
3672-
"sys/ptrace.h",
3673-
"sys/quota.h",
3674-
"sys/random.h",
3675-
"sys/reboot.h",
3688+
[!l4re]: "sys/ptrace.h",
3689+
[!l4re]: "sys/quota.h",
3690+
[!l4re]: "sys/random.h",
3691+
[!l4re]: "sys/reboot.h",
36763692
"sys/resource.h",
36773693
"sys/sem.h",
3678-
"sys/sendfile.h",
3694+
[!l4re]: "sys/sendfile.h",
36793695
"sys/shm.h",
3680-
"sys/signalfd.h",
3696+
[!l4re]: "sys/signalfd.h",
36813697
"sys/socket.h",
36823698
"sys/stat.h",
36833699
"sys/statvfs.h",
3684-
"sys/swap.h",
3700+
[!l4re]: "sys/swap.h",
36853701
"sys/syscall.h",
36863702
"sys/time.h",
3687-
"sys/timerfd.h",
3703+
[!l4re]: "sys/timerfd.h",
36883704
"sys/times.h",
3689-
"sys/timex.h",
3705+
[!l4re]: "sys/timex.h",
36903706
"sys/types.h",
36913707
"sys/uio.h",
36923708
"sys/un.h",
@@ -3708,12 +3724,12 @@ fn test_linux(target: &str) {
37083724
// ARM: https://bugzilla.redhat.com/show_bug.cgi?id=1116162
37093725
// Also unavailable on gnueabihf with glibc 2.30.
37103726
// https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=6b33f373c7b9199e00ba5fbafd94ac9bfb4337b1
3711-
[(x86_64 || x86_32 || arm) && !gnueabihf]: "sys/io.h",
3727+
[(x86_64 || x86_32 || arm) && !gnueabihf && !l4re]: "sys/io.h",
37123728
// `sys/reg.h` is only available on x86 and x86_64
3713-
[x86_64 || x86_32]: "sys/reg.h",
3729+
[(x86_64 || x86_32) && !l4re]: "sys/reg.h",
37143730
// sysctl system call is deprecated and not available on musl
37153731
// It is also unsupported in x32, deprecated since glibc 2.30:
3716-
[!(x32 || musl || gnu)]: "sys/sysctl.h",
3732+
[!(x32 || musl || gnu || l4re)]: "sys/sysctl.h",
37173733
// <execinfo.h> is not supported by musl:
37183734
// https://www.openwall.com/lists/musl/2015/04/09/3
37193735
// <execinfo.h> is not present on uclibc.
@@ -3723,11 +3739,11 @@ fn test_linux(target: &str) {
37233739
// Include linux headers at the end:
37243740
headers! {
37253741
cfg:
3726-
[loongarch64 || riscv64]: "asm/hwcap.h",
3727-
"asm/mman.h",
3742+
[(loongarch64 || riscv64) && !l4re]: "asm/hwcap.h",
3743+
[!l4re]: "asm/mman.h",
37283744
}
37293745

3730-
if !wasm32 {
3746+
if !wasm32 && !l4re {
37313747
headers! { cfg:
37323748
[gnu]: "linux/aio_abi.h",
37333749
"linux/can.h",
@@ -3745,7 +3761,6 @@ fn test_linux(target: &str) {
37453761
"linux/if.h",
37463762
"linux/if_addr.h",
37473763
"linux/if_alg.h",
3748-
"linux/if_ether.h",
37493764
"linux/if_packet.h",
37503765
"linux/if_tun.h",
37513766
"linux/if_xdp.h",
@@ -3792,7 +3807,6 @@ fn test_linux(target: &str) {
37923807
"linux/wait.h",
37933808
"linux/wireless.h",
37943809
"sys/fanotify.h",
3795-
// <sys/auxv.h> is not present on uclibc
37963810
[!uclibc]: "sys/auxv.h",
37973811
[gnu || musl]: "linux/close_range.h",
37983812
}
@@ -3801,7 +3815,7 @@ fn test_linux(target: &str) {
38013815
// note: aio.h must be included before sys/mount.h
38023816
headers! {
38033817
cfg:
3804-
"sys/xattr.h",
3818+
[!l4re]: "sys/xattr.h",
38053819
"sys/sysinfo.h",
38063820
// AIO is not supported by uclibc:
38073821
[!uclibc]: "aio.h",
@@ -3831,10 +3845,11 @@ fn test_linux(target: &str) {
38313845

38323846
cfg.rename_type(move |ty| {
38333847
match ty {
3834-
"Ioctl" if gnu => Some("unsigned long".to_string()),
3848+
"Ioctl" if gnu || uclibc => Some("unsigned long".to_string()),
38353849
"Ioctl" => Some("int".to_string()),
38363850
// LFS64 types have been removed in musl 1.2.4+
38373851
"off64_t" if musl => Some("off_t".to_string()),
3852+
"fsword_t" if uclibc => Some("__SWORD_TYPE".to_string()),
38383853
_ => None,
38393854
}
38403855
});
@@ -4090,6 +4105,13 @@ fn test_linux(target: &str) {
40904105

40914106
cfg.skip_const(move |constant| {
40924107
let name = constant.ident();
4108+
4109+
// L4Re requires a min stack size of 64k; that isn't defined in uClibc, but
4110+
// somewhere in the core libraries. uClibc wants 16k, but that's not enough.
4111+
if l4re && name == "PTHREAD_STACK_MIN" {
4112+
return true;
4113+
}
4114+
40934115
if !gnu {
40944116
// Skip definitions from the kernel on non-glibc Linux targets.
40954117
// They're libc-independent, so we only need to check them on one
@@ -4269,7 +4291,7 @@ fn test_linux(target: &str) {
42694291

42704292
// FIXME(musl): on musl the pthread types are defined a little differently
42714293
// - these constants are used by the glibc implementation.
4272-
n if musl && n.contains("__SIZEOF_PTHREAD") => true,
4294+
n if (musl || uclibc) && n.contains("__SIZEOF_PTHREAD") => true,
42734295

42744296
// FIXME(linux): It was extended to 4096 since glibc 2.31 (Linux 5.4).
42754297
// We should do so after a while.
@@ -4856,7 +4878,9 @@ fn test_linux(target: &str) {
48564878

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

4859-
test_linux_like_apis(target);
4881+
if !l4re {
4882+
test_linux_like_apis(target);
4883+
}
48604884
}
48614885

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

0 commit comments

Comments
 (0)