Skip to content

Commit c887363

Browse files
committed
Auto merge of #1975 - skrap:feature/move-uclibc-under-linux, r=<try>
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 bb8fe9a + 10693b4 commit c887363

File tree

27 files changed

+899
-3143
lines changed

27 files changed

+899
-3143
lines changed

ci/semver.sh

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ i686-unknown-freebsd \
3535
i686-unknown-linux-gnu \
3636
i686-unknown-linux-musl \
3737
i686-pc-windows-gnu \
38+
mipsel-unknown-linux-uclibc \
3839
x86_64-unknown-freebsd \
3940
x86_64-unknown-linux-gnu \
4041
x86_64-unknown-linux-musl \

libc-test/build.rs

+40-3
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,7 @@ fn test_linux(target: &str) {
22542254
let gnuabihf = target.contains("gnueabihf");
22552255
let x86_64_gnux32 = target.contains("gnux32") && x86_64;
22562256
let riscv64 = target.contains("riscv64");
2257+
let uclibc = target.contains("uclibc");
22572258

22582259
let mut cfg = ctest_cfg();
22592260
cfg.define("_GNU_SOURCE", None);
@@ -2363,7 +2364,8 @@ fn test_linux(target: &str) {
23632364
[!(x32 || musl || gnu)]: "sys/sysctl.h",
23642365
// <execinfo.h> is not supported by musl:
23652366
// https://www.openwall.com/lists/musl/2015/04/09/3
2366-
[!musl]: "execinfo.h",
2367+
// <execinfo.h> is not present on uclibc.
2368+
[!(musl || uclibc)]: "execinfo.h",
23672369
}
23682370

23692371
// Include linux headers at the end:
@@ -2405,16 +2407,18 @@ fn test_linux(target: &str) {
24052407
"linux/sockios.h",
24062408
"linux/vm_sockets.h",
24072409
"linux/wait.h",
2408-
"sys/auxv.h",
24092410
"sys/fanotify.h",
2411+
// <sys/auxv.h> is not present on uclibc
2412+
[!uclibc]: "sys/auxv.h",
24102413
}
24112414

24122415
// note: aio.h must be included before sys/mount.h
24132416
headers! {
24142417
cfg:
24152418
"sys/xattr.h",
24162419
"sys/sysinfo.h",
2417-
"aio.h",
2420+
// AIO is not supported by uclibc:
2421+
[!uclibc]: "aio.h",
24182422
}
24192423

24202424
cfg.type_name(move |ty, is_struct, is_union| {
@@ -2637,6 +2641,14 @@ fn test_linux(target: &str) {
26372641
| "CAN_RAW_FILTER_MAX"
26382642
| "CAN_NPROTO" => true,
26392643

2644+
"MS_RMT_MASK" if uclibc => true, // updated in glibc 2.22 and musl 1.1.13
2645+
2646+
// These are not defined in uclibc but will be passed through to the kernel
2647+
// so they will be supported if the kernel supports them. Otherwise the
2648+
// kernel will return runtime errors. Since they're required for tokio
2649+
// support, we except them from the tests here.
2650+
// See https://github.com/rust-lang/libc/pull/2019#issuecomment-754351482
2651+
"EPOLLEXCLUSIVE" | "EPOLLWAKEUP" if uclibc => true,
26402652
_ => false,
26412653
}
26422654
});
@@ -2681,6 +2693,31 @@ fn test_linux(target: &str) {
26812693
// FIXME: It now takes c_void instead of timezone since glibc 2.31.
26822694
"gettimeofday" if gnu => true,
26832695

2696+
// These are all implemented as static inline functions in uclibc, so
2697+
// they cannot be linked against.
2698+
// If implementations are required, they might need to be implemented
2699+
// in this crate.
2700+
"posix_spawnattr_init" if uclibc => true,
2701+
"posix_spawnattr_destroy" if uclibc => true,
2702+
"posix_spawnattr_getsigdefault" if uclibc => true,
2703+
"posix_spawnattr_setsigdefault" if uclibc => true,
2704+
"posix_spawnattr_getsigmask" if uclibc => true,
2705+
"posix_spawnattr_setsigmask" if uclibc => true,
2706+
"posix_spawnattr_getflags" if uclibc => true,
2707+
"posix_spawnattr_setflags" if uclibc => true,
2708+
"posix_spawnattr_getpgroup" if uclibc => true,
2709+
"posix_spawnattr_setpgroup" if uclibc => true,
2710+
"posix_spawnattr_getschedpolicy" if uclibc => true,
2711+
"posix_spawnattr_setschedpolicy" if uclibc => true,
2712+
"posix_spawnattr_getschedparam" if uclibc => true,
2713+
"posix_spawnattr_setschedparam" if uclibc => true,
2714+
"posix_spawn_file_actions_init" if uclibc => true,
2715+
"posix_spawn_file_actions_destroy" if uclibc => true,
2716+
2717+
// uclibc defines the flags type as a uint, but dependent crates
2718+
// assume it's a int instead.
2719+
"getnameinfo" if uclibc => true,
2720+
26842721
_ => false,
26852722
}
26862723
});

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

+30-5
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ s! {
285285
__re_nsub: ::size_t,
286286
__bitfield: u8,
287287
}
288+
289+
pub struct Elf64_Chdr {
290+
pub ch_type: ::Elf64_Word,
291+
pub ch_reserved: ::Elf64_Word,
292+
pub ch_size: ::Elf64_Xword,
293+
pub ch_addralign: ::Elf64_Xword,
294+
}
295+
296+
pub struct Elf32_Chdr {
297+
pub ch_type: ::Elf32_Word,
298+
pub ch_size: ::Elf32_Word,
299+
pub ch_addralign: ::Elf32_Word,
300+
}
288301
}
289302

290303
impl siginfo_t {
@@ -618,6 +631,22 @@ pub const TCP_FASTOPEN: ::c_int = 23;
618631
pub const TCP_TIMESTAMP: ::c_int = 24;
619632
pub const TCP_FASTOPEN_CONNECT: ::c_int = 30;
620633

634+
pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
635+
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
636+
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
637+
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;
638+
639+
pub const AF_IB: ::c_int = 27;
640+
pub const AF_MPLS: ::c_int = 28;
641+
pub const AF_NFC: ::c_int = 39;
642+
pub const AF_VSOCK: ::c_int = 40;
643+
pub const AF_XDP: ::c_int = 44;
644+
pub const PF_IB: ::c_int = AF_IB;
645+
pub const PF_MPLS: ::c_int = AF_MPLS;
646+
pub const PF_NFC: ::c_int = AF_NFC;
647+
pub const PF_VSOCK: ::c_int = AF_VSOCK;
648+
pub const PF_XDP: ::c_int = AF_XDP;
649+
621650
/* DCCP socket options */
622651
pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1;
623652
pub const DCCP_SOCKOPT_SERVICE: ::c_int = 2;
@@ -644,6 +673,7 @@ pub const SIGEV_THREAD_ID: ::c_int = 4;
644673
pub const BUFSIZ: ::c_uint = 8192;
645674
pub const TMP_MAX: ::c_uint = 238328;
646675
pub const FOPEN_MAX: ::c_uint = 16;
676+
pub const FILENAME_MAX: ::c_uint = 4096;
647677
pub const POSIX_MADV_DONTNEED: ::c_int = 4;
648678
pub const _SC_EQUIV_CLASS_MAX: ::c_int = 41;
649679
pub const _SC_CHARCLASS_NAME_MAX: ::c_int = 45;
@@ -855,11 +885,6 @@ pub const PTRACE_INTERRUPT: ::c_uint = 0x4207;
855885
pub const PTRACE_LISTEN: ::c_uint = 0x4208;
856886
pub const PTRACE_PEEKSIGINFO: ::c_uint = 0x4209;
857887

858-
pub const EPOLLWAKEUP: ::c_int = 0x20000000;
859-
860-
pub const SEEK_DATA: ::c_int = 3;
861-
pub const SEEK_HOLE: ::c_int = 4;
862-
863888
// linux/rtnetlink.h
864889
pub const TCA_PAD: ::c_ushort = 9;
865890
pub const TCA_DUMP_INVISIBLE: ::c_ushort = 10;

0 commit comments

Comments
 (0)