Skip to content

Commit d4080d1

Browse files
committed
Auto merge of #1975 - skrap:feature/move-uclibc-under-linux, r=JohnTitor
Move uclibc under linux This is a first cut at moving uclibc under linux, alongside `musl` and `gnu`. All tests pass on a vexpress a9 running in qemu. I am working on testing the other tier 3 uclibc targets: `mips-unknown-linux-uclibc` and `mipsel-unknown-linux-uclibc`. ~Not having access to these platforms, I am working on getting them running in qemu, but it may take a bit.~ The style check doesn't pass. I would appreciate some direction here. Many of these constants are defined under 2-of-3 out of musl/glibc/uclibc, so I'm not sure whether I should transform: ```rust #[cfg(not(target_env = "uclibc"))] pub fn foo(); ``` into 2 separate declarations, one each in `musl/mod.rs` and `gnu/mod.rs` or use a `cfg_if` block for each one (which explodes 2 lines into 5). - [x] Help me choose which fix to use for the items defined in musl and gnu but not uclibc. It's my guess that exploding into the `cfg_if` block is better for long-term maintainability, but I'd really appreciate opinions from the maintainers.
2 parents db71a57 + 3378f0c commit d4080d1

File tree

26 files changed

+905
-3143
lines changed

26 files changed

+905
-3143
lines changed

libc-test/build.rs

+41-3
Original file line numberDiff line numberDiff line change
@@ -2267,6 +2267,7 @@ fn test_linux(target: &str) {
22672267
let gnuabihf = target.contains("gnueabihf");
22682268
let x86_64_gnux32 = target.contains("gnux32") && x86_64;
22692269
let riscv64 = target.contains("riscv64");
2270+
let uclibc = target.contains("uclibc");
22702271

22712272
let mut cfg = ctest_cfg();
22722273
cfg.define("_GNU_SOURCE", None);
@@ -2377,7 +2378,8 @@ fn test_linux(target: &str) {
23772378
[!(x32 || musl || gnu)]: "sys/sysctl.h",
23782379
// <execinfo.h> is not supported by musl:
23792380
// https://www.openwall.com/lists/musl/2015/04/09/3
2380-
[!musl]: "execinfo.h",
2381+
// <execinfo.h> is not present on uclibc.
2382+
[!(musl || uclibc)]: "execinfo.h",
23812383
}
23822384

23832385
// Include linux headers at the end:
@@ -2419,16 +2421,18 @@ fn test_linux(target: &str) {
24192421
"linux/sockios.h",
24202422
"linux/vm_sockets.h",
24212423
"linux/wait.h",
2422-
"sys/auxv.h",
24232424
"sys/fanotify.h",
2425+
// <sys/auxv.h> is not present on uclibc
2426+
[!uclibc]: "sys/auxv.h",
24242427
}
24252428

24262429
// note: aio.h must be included before sys/mount.h
24272430
headers! {
24282431
cfg:
24292432
"sys/xattr.h",
24302433
"sys/sysinfo.h",
2431-
"aio.h",
2434+
// AIO is not supported by uclibc:
2435+
[!uclibc]: "aio.h",
24322436
}
24332437

24342438
cfg.type_name(move |ty, is_struct, is_union| {
@@ -2651,6 +2655,15 @@ fn test_linux(target: &str) {
26512655
| "CAN_RAW_FILTER_MAX"
26522656
| "CAN_NPROTO" => true,
26532657

2658+
"MS_RMT_MASK" if uclibc => true, // updated in glibc 2.22 and musl 1.1.13
2659+
2660+
// These are not defined in uclibc but will be passed through to the kernel
2661+
// so they will be supported if the kernel supports them. Otherwise the
2662+
// kernel will return runtime errors. Since they're required for tokio
2663+
// support, we except them from the tests here.
2664+
// See https://github.com/rust-lang/libc/pull/2019#issuecomment-754351482
2665+
"EPOLLEXCLUSIVE" | "EPOLLWAKEUP" if uclibc => true,
2666+
26542667
// FIXME: Requires recent kernel headers (5.8):
26552668
"STATX_MNT_ID" => true,
26562669

@@ -2698,6 +2711,31 @@ fn test_linux(target: &str) {
26982711
// FIXME: It now takes c_void instead of timezone since glibc 2.31.
26992712
"gettimeofday" if gnu => true,
27002713

2714+
// These are all implemented as static inline functions in uclibc, so
2715+
// they cannot be linked against.
2716+
// If implementations are required, they might need to be implemented
2717+
// in this crate.
2718+
"posix_spawnattr_init" if uclibc => true,
2719+
"posix_spawnattr_destroy" if uclibc => true,
2720+
"posix_spawnattr_getsigdefault" if uclibc => true,
2721+
"posix_spawnattr_setsigdefault" if uclibc => true,
2722+
"posix_spawnattr_getsigmask" if uclibc => true,
2723+
"posix_spawnattr_setsigmask" if uclibc => true,
2724+
"posix_spawnattr_getflags" if uclibc => true,
2725+
"posix_spawnattr_setflags" if uclibc => true,
2726+
"posix_spawnattr_getpgroup" if uclibc => true,
2727+
"posix_spawnattr_setpgroup" if uclibc => true,
2728+
"posix_spawnattr_getschedpolicy" if uclibc => true,
2729+
"posix_spawnattr_setschedpolicy" if uclibc => true,
2730+
"posix_spawnattr_getschedparam" if uclibc => true,
2731+
"posix_spawnattr_setschedparam" if uclibc => true,
2732+
"posix_spawn_file_actions_init" if uclibc => true,
2733+
"posix_spawn_file_actions_destroy" if uclibc => true,
2734+
2735+
// uclibc defines the flags type as a uint, but dependent crates
2736+
// assume it's a int instead.
2737+
"getnameinfo" if uclibc => true,
2738+
27012739
_ => false,
27022740
}
27032741
});

src/unix/linux_like/linux/gnu/mod.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ s! {
287287
__re_nsub: ::size_t,
288288
__bitfield: u8,
289289
}
290+
291+
pub struct Elf64_Chdr {
292+
pub ch_type: ::Elf64_Word,
293+
pub ch_reserved: ::Elf64_Word,
294+
pub ch_size: ::Elf64_Xword,
295+
pub ch_addralign: ::Elf64_Xword,
296+
}
297+
298+
pub struct Elf32_Chdr {
299+
pub ch_type: ::Elf32_Word,
300+
pub ch_size: ::Elf32_Word,
301+
pub ch_addralign: ::Elf32_Word,
302+
}
290303
}
291304

292305
impl siginfo_t {
@@ -620,6 +633,22 @@ pub const TCP_FASTOPEN: ::c_int = 23;
620633
pub const TCP_TIMESTAMP: ::c_int = 24;
621634
pub const TCP_FASTOPEN_CONNECT: ::c_int = 30;
622635

636+
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
637+
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
638+
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
639+
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
640+
641+
pub const AF_IB: ::c_int = 27;
642+
pub const AF_MPLS: ::c_int = 28;
643+
pub const AF_NFC: ::c_int = 39;
644+
pub const AF_VSOCK: ::c_int = 40;
645+
pub const AF_XDP: ::c_int = 44;
646+
pub const PF_IB: ::c_int = AF_IB;
647+
pub const PF_MPLS: ::c_int = AF_MPLS;
648+
pub const PF_NFC: ::c_int = AF_NFC;
649+
pub const PF_VSOCK: ::c_int = AF_VSOCK;
650+
pub const PF_XDP: ::c_int = AF_XDP;
651+
623652
/* DCCP socket options */
624653
pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1;
625654
pub const DCCP_SOCKOPT_SERVICE: ::c_int = 2;
@@ -646,6 +675,7 @@ pub const SIGEV_THREAD_ID: ::c_int = 4;
646675
pub const BUFSIZ: ::c_uint = 8192;
647676
pub const TMP_MAX: ::c_uint = 238328;
648677
pub const FOPEN_MAX: ::c_uint = 16;
678+
pub const FILENAME_MAX: ::c_uint = 4096;
649679
pub const POSIX_MADV_DONTNEED: ::c_int = 4;
650680
pub const _SC_EQUIV_CLASS_MAX: ::c_int = 41;
651681
pub const _SC_CHARCLASS_NAME_MAX: ::c_int = 45;
@@ -857,11 +887,6 @@ pub const PTRACE_INTERRUPT: ::c_uint = 0x4207;
857887
pub const PTRACE_LISTEN: ::c_uint = 0x4208;
858888
pub const PTRACE_PEEKSIGINFO: ::c_uint = 0x4209;
859889

860-
pub const EPOLLWAKEUP: ::c_int = 0x20000000;
861-
862-
pub const SEEK_DATA: ::c_int = 3;
863-
pub const SEEK_HOLE: ::c_int = 4;
864-
865890
// linux/fs.h
866891

867892
// Flags for preadv2/pwritev2

0 commit comments

Comments
 (0)