Skip to content

Commit

Permalink
Auto merge of #1975 - skrap:feature/move-uclibc-under-linux, r=<try>
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 13, 2021
2 parents bb8fe9a + 10693b4 commit c887363
Show file tree
Hide file tree
Showing 27 changed files with 899 additions and 3,143 deletions.
1 change: 1 addition & 0 deletions ci/semver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ i686-unknown-freebsd \
i686-unknown-linux-gnu \
i686-unknown-linux-musl \
i686-pc-windows-gnu \
mipsel-unknown-linux-uclibc \
x86_64-unknown-freebsd \
x86_64-unknown-linux-gnu \
x86_64-unknown-linux-musl \
Expand Down
43 changes: 40 additions & 3 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,7 @@ fn test_linux(target: &str) {
let gnuabihf = target.contains("gnueabihf");
let x86_64_gnux32 = target.contains("gnux32") && x86_64;
let riscv64 = target.contains("riscv64");
let uclibc = target.contains("uclibc");

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

// Include linux headers at the end:
Expand Down Expand Up @@ -2405,16 +2407,18 @@ fn test_linux(target: &str) {
"linux/sockios.h",
"linux/vm_sockets.h",
"linux/wait.h",
"sys/auxv.h",
"sys/fanotify.h",
// <sys/auxv.h> is not present on uclibc
[!uclibc]: "sys/auxv.h",
}

// note: aio.h must be included before sys/mount.h
headers! {
cfg:
"sys/xattr.h",
"sys/sysinfo.h",
"aio.h",
// AIO is not supported by uclibc:
[!uclibc]: "aio.h",
}

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

"MS_RMT_MASK" if uclibc => true, // updated in glibc 2.22 and musl 1.1.13

// These are not defined in uclibc but will be passed through to the kernel
// so they will be supported if the kernel supports them. Otherwise the
// kernel will return runtime errors. Since they're required for tokio
// support, we except them from the tests here.
// See https://github.com/rust-lang/libc/pull/2019#issuecomment-754351482
"EPOLLEXCLUSIVE" | "EPOLLWAKEUP" if uclibc => true,
_ => false,
}
});
Expand Down Expand Up @@ -2681,6 +2693,31 @@ fn test_linux(target: &str) {
// FIXME: It now takes c_void instead of timezone since glibc 2.31.
"gettimeofday" if gnu => true,

// These are all implemented as static inline functions in uclibc, so
// they cannot be linked against.
// If implementations are required, they might need to be implemented
// in this crate.
"posix_spawnattr_init" if uclibc => true,
"posix_spawnattr_destroy" if uclibc => true,
"posix_spawnattr_getsigdefault" if uclibc => true,
"posix_spawnattr_setsigdefault" if uclibc => true,
"posix_spawnattr_getsigmask" if uclibc => true,
"posix_spawnattr_setsigmask" if uclibc => true,
"posix_spawnattr_getflags" if uclibc => true,
"posix_spawnattr_setflags" if uclibc => true,
"posix_spawnattr_getpgroup" if uclibc => true,
"posix_spawnattr_setpgroup" if uclibc => true,
"posix_spawnattr_getschedpolicy" if uclibc => true,
"posix_spawnattr_setschedpolicy" if uclibc => true,
"posix_spawnattr_getschedparam" if uclibc => true,
"posix_spawnattr_setschedparam" if uclibc => true,
"posix_spawn_file_actions_init" if uclibc => true,
"posix_spawn_file_actions_destroy" if uclibc => true,

// uclibc defines the flags type as a uint, but dependent crates
// assume it's a int instead.
"getnameinfo" if uclibc => true,

_ => false,
}
});
Expand Down
35 changes: 30 additions & 5 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ s! {
__re_nsub: ::size_t,
__bitfield: u8,
}

pub struct Elf64_Chdr {
pub ch_type: ::Elf64_Word,
pub ch_reserved: ::Elf64_Word,
pub ch_size: ::Elf64_Xword,
pub ch_addralign: ::Elf64_Xword,
}

pub struct Elf32_Chdr {
pub ch_type: ::Elf32_Word,
pub ch_size: ::Elf32_Word,
pub ch_addralign: ::Elf32_Word,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -618,6 +631,22 @@ pub const TCP_FASTOPEN: ::c_int = 23;
pub const TCP_TIMESTAMP: ::c_int = 24;
pub const TCP_FASTOPEN_CONNECT: ::c_int = 30;

pub const FAN_MARK_INODE: ::c_uint = 0x0000_0000;
pub const FAN_MARK_MOUNT: ::c_uint = 0x0000_0010;
// NOTE: FAN_MARK_FILESYSTEM requires Linux Kernel >= 4.20.0
pub const FAN_MARK_FILESYSTEM: ::c_uint = 0x0000_0100;

pub const AF_IB: ::c_int = 27;
pub const AF_MPLS: ::c_int = 28;
pub const AF_NFC: ::c_int = 39;
pub const AF_VSOCK: ::c_int = 40;
pub const AF_XDP: ::c_int = 44;
pub const PF_IB: ::c_int = AF_IB;
pub const PF_MPLS: ::c_int = AF_MPLS;
pub const PF_NFC: ::c_int = AF_NFC;
pub const PF_VSOCK: ::c_int = AF_VSOCK;
pub const PF_XDP: ::c_int = AF_XDP;

/* DCCP socket options */
pub const DCCP_SOCKOPT_PACKET_SIZE: ::c_int = 1;
pub const DCCP_SOCKOPT_SERVICE: ::c_int = 2;
Expand All @@ -644,6 +673,7 @@ pub const SIGEV_THREAD_ID: ::c_int = 4;
pub const BUFSIZ: ::c_uint = 8192;
pub const TMP_MAX: ::c_uint = 238328;
pub const FOPEN_MAX: ::c_uint = 16;
pub const FILENAME_MAX: ::c_uint = 4096;
pub const POSIX_MADV_DONTNEED: ::c_int = 4;
pub const _SC_EQUIV_CLASS_MAX: ::c_int = 41;
pub const _SC_CHARCLASS_NAME_MAX: ::c_int = 45;
Expand Down Expand Up @@ -855,11 +885,6 @@ pub const PTRACE_INTERRUPT: ::c_uint = 0x4207;
pub const PTRACE_LISTEN: ::c_uint = 0x4208;
pub const PTRACE_PEEKSIGINFO: ::c_uint = 0x4209;

pub const EPOLLWAKEUP: ::c_int = 0x20000000;

pub const SEEK_DATA: ::c_int = 3;
pub const SEEK_HOLE: ::c_int = 4;

// linux/rtnetlink.h
pub const TCA_PAD: ::c_ushort = 9;
pub const TCA_DUMP_INVISIBLE: ::c_ushort = 10;
Expand Down
Loading

0 comments on commit c887363

Please sign in to comment.