Skip to content

Add new cfg gnu_file_offset_bits64 corresponding to _FILE_OFFSET_BITS=64 #4345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
afa5c65
ci: Use $PWD instead of $(pwd) in run-docker
snogge Dec 11, 2024
84a04a1
ci: Add matrix env variables to the environment
snogge Mar 14, 2025
f10e8e4
ci: Always upload successfully created artifacts
snogge Mar 14, 2025
a184436
gnu: build settings for _FILE_OFFSET_BITS=64
snogge Mar 14, 2025
874e399
gnu: Set up the CI for _FILE_OFFSET_BITS=64
snogge Mar 14, 2025
f44fdc1
gnu: Handle basic file types for 32bit with _FILE_OFFSET_BITS=64
snogge Dec 16, 2024
862ba8a
gnu: Update F_GETLK for gnu_file_offset_bits64
snogge Mar 20, 2023
6ed2bc8
gnu: Update F_SETLK and F_SETLKW for gnu_file_offset_bits64
snogge Mar 20, 2023
5c5c364
gnu: Set RLIM_INFINITY for mips with gnu_file_offset_bits64
snogge Mar 11, 2025
2b4fafb
gnu: Use _FILE_OFFSET_BITS=64 versions of glibc symbols
snogge Nov 21, 2024
0c6d56c
gnu powerpc: Use a separate stat struct for powerpc
snogge Mar 18, 2025
e134959
gnu sparc: Use a separate stat struct for 32bit powerpc
snogge Mar 20, 2025
5a5abc2
gnu: Adapt struct stat for gnu_file_offset_bits64
snogge Dec 19, 2024
96e81e7
gnu: Adapt stat64 for gnu_file_offset_bits64
snogge Mar 18, 2025
169d50b
gnu: Correct the struct stat64 padding for 32bit mips
snogge Mar 20, 2025
22ac02c
gnu: Correct struct stat64 for sparc
snogge Mar 20, 2025
131efe9
gnu: Add the __f_unused field to struct statvfs for sparc
snogge Mar 17, 2025
c1e4812
gnu: Add missing f_flags field to struct statfs for sparc
snogge Mar 18, 2025
872642a
gnu: Add proper structs for fpos_t and fpos64_t
snogge Nov 21, 2024
7ba56f2
gnu: Update struct aiocb for gnu_file_offset_bits64
snogge Mar 20, 2023
4a7c9a9
gnu: Adapt struct flock on mips for gnu_file_offset_bits64
snogge Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ jobs:
- target: i686-unknown-linux-gnu
docker: true
os: ubuntu-24.04
- target: i686-unknown-linux-gnu
docker: true
os: ubuntu-24.04
artifact-tag: offset-bits64
env:
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
- target: x86_64-unknown-linux-gnu
docker: true
os: ubuntu-24.04
Expand Down Expand Up @@ -107,6 +113,13 @@ jobs:
with:
key: ${{ matrix.target }}

- name: Add matrix env variables to the environment
if: matrix.env
run: |
echo '${{ toJson(matrix.env) }}' |
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
shell: bash

- name: Run natively
if: "!matrix.docker"
run: ./ci/run.sh ${{ matrix.target }}
Expand All @@ -115,11 +128,13 @@ jobs:
run: ./ci/run-docker.sh ${{ matrix.target }}

- name: Create CI artifacts
id: create_artifacts
if: always()
run: ./ci/create-artifacts.py
- uses: actions/upload-artifact@v4
if: always() && steps.create_artifacts.outcome == 'success'
with:
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
path: ${{ env.ARCHIVE_PATH }}
retention-days: 5

Expand All @@ -139,15 +154,11 @@ jobs:
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
- arm-linux-androideabi
- arm-unknown-linux-gnueabihf
- arm-unknown-linux-musleabihf
- i686-linux-android
- i686-unknown-linux-musl
- loongarch64-unknown-linux-gnu
- loongarch64-unknown-linux-musl
# FIXME(ppc): SIGILL running tests, see
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
# - powerpc-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- riscv64gc-unknown-linux-gnu
Expand All @@ -162,6 +173,19 @@ jobs:
# FIXME: It seems some items in `src/unix/mod.rs`
# aren't defined on redox actually.
# - x86_64-unknown-redox
include:
- target: arm-unknown-linux-gnueabihf
- target: arm-unknown-linux-gnueabihf
env:
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
artifact-tag: offset-bits64
# FIXME(ppc): SIGILL running tests, see
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
# - target: powerpc-unknown-linux-gnu
# - target: powerpc-unknown-linux-gnu
# env:
# RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
# artifact-tag: offset-bits64
timeout-minutes: 25
env:
TARGET: ${{ matrix.target }}
Expand All @@ -173,15 +197,24 @@ jobs:
with:
key: ${{ matrix.target }}

- name: Add matrix env variables to the environment
if: matrix.env
run: |
echo '${{ toJson(matrix.env) }}' |
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
shell: bash

- name: Execute run-docker.sh
run: ./ci/run-docker.sh ${{ matrix.target }}

- name: Create CI artifacts
id: create_artifacts
if: always()
run: ./ci/create-artifacts.py
- uses: actions/upload-artifact@v4
if: always() && steps.create_artifacts.outcome == 'success'
with:
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
path: ${{ env.ARCHIVE_PATH }}
retention-days: 5

Expand Down
23 changes: 23 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"freebsd13",
"freebsd14",
"freebsd15",
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
"gnu_file_offset_bits64",
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
"libc_const_extern_fn",
"libc_deny_warnings",
Expand Down Expand Up @@ -43,6 +45,10 @@ fn main() {
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let libc_ci = env::var("LIBC_CI").is_ok();
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();

// The ABI of libc used by std is backward compatible with FreeBSD 12.
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
Expand Down Expand Up @@ -84,6 +90,23 @@ fn main() {
if linux_time_bits64 {
set_cfg("linux_time_bits64");
}
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
Ok(val) if val == "64" => {
if target_env == "gnu"
&& target_os == "linux"
&& target_ptr_width == "32"
&& target_arch != "riscv32"
&& target_arch != "x86_64"
{
set_cfg("gnu_file_offset_bits64");
}
}
Ok(val) if val != "32" => {
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
}
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add something like Ok(val) if val != "32" => panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'),?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added that check for both build.rs and libc-test/build.rs.

}

// On CI: deny all warnings
if libc_ci {
Expand Down
5 changes: 3 additions & 2 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ run() {
--user "$(id -u)":"$(id -g)" \
--env LIBC_CI \
--env LIBC_CI_ZBUILD_STD \
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
--env CARGO_HOME=/cargo \
--env CARGO_TARGET_DIR=/checkout/target \
--volume "$CARGO_HOME":/cargo \
--volume "$(rustc --print sysroot)":/rust:ro \
--volume "$(pwd)":/checkout:ro \
--volume "$(pwd)"/target:/checkout/target \
--volume "$PWD":/checkout:ro \
--volume "$PWD"/target:/checkout/target \
$kvm \
--init \
--workdir /checkout \
Expand Down
9 changes: 7 additions & 2 deletions ci/verify-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ test_target() {
if [ "$os" = "linux" ]; then
# Test with the equivalent of __USE_TIME_BITS64
RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
case "$target" in
# Test with the equivalent of __FILE_OFFSET_BITS=64
arm*-gnu*|i*86*-gnu|powerpc-*-gnu*|mips*-gnu|sparc-*-gnu|thumb-*gnu*)
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd;;
esac
fi

# Test again without default features, i.e. without "std"
Expand All @@ -91,7 +96,7 @@ test_target() {
stable-x86_64-*freebsd*) do_freebsd_checks=1 ;;
nightly-i686*freebsd*) do_freebsd_checks=1 ;;
esac

if [ -n "${do_freebsd_checks:-}" ]; then
for version in $freebsd_versions; do
export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version"
Expand Down Expand Up @@ -296,7 +301,7 @@ filter_and_run() {
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
return
fi

test_target "$target" "$no_dist"
some_tests_run=1
fi
Expand Down
28 changes: 28 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3587,6 +3587,26 @@ fn test_vxworks(target: &str) {
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
}

fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
Ok(val) if val == "64" => {
if target.contains("gnu")
&& target.contains("linux")
&& !target.ends_with("x32")
&& !target.contains("riscv32")
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
{
cfg.define("_FILE_OFFSET_BITS", Some("64"));
cfg.cfg("gnu_file_offset_bits64", None);
}
}
Ok(val) if val != "32" => {
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
}
_ => {}
}
}

fn test_linux(target: &str) {
assert!(target.contains("linux"));

Expand Down Expand Up @@ -3630,6 +3650,8 @@ fn test_linux(target: &str) {
// glibc versions older than 2.29.
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);

config_gnu_bits(target, &mut cfg);

headers! { cfg:
"ctype.h",
"dirent.h",
Expand Down Expand Up @@ -4791,6 +4813,7 @@ fn test_linux_like_apis(target: &str) {
if linux || android || emscripten {
// test strerror_r from the `string.h` header
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.skip_type(|_| true).skip_static(|_| true);

headers! { cfg: "string.h" }
Expand All @@ -4807,6 +4830,7 @@ fn test_linux_like_apis(target: &str) {
// test fcntl - see:
// http://man7.org/linux/man-pages/man2/fcntl.2.html
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);

if musl {
cfg.header("fcntl.h");
Expand Down Expand Up @@ -4836,6 +4860,7 @@ fn test_linux_like_apis(target: &str) {
if (linux && !wali) || android {
// test termios
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("asm/termbits.h");
cfg.header("linux/termios.h");
cfg.skip_type(|_| true)
Expand All @@ -4860,6 +4885,7 @@ fn test_linux_like_apis(target: &str) {
if linux || android {
// test IPV6_ constants:
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
headers! {
cfg:
"linux/in6.h"
Expand Down Expand Up @@ -4891,6 +4917,7 @@ fn test_linux_like_apis(target: &str) {
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
// making the tests for these fails when both are included.
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("elf.h");
cfg.skip_fn(|_| true)
.skip_static(|_| true)
Expand All @@ -4910,6 +4937,7 @@ fn test_linux_like_apis(target: &str) {
if (linux && !wali) || android {
// Test `ARPHRD_CAN`.
let mut cfg = ctest_cfg();
config_gnu_bits(target, &mut cfg);
cfg.header("linux/if_arp.h");
cfg.skip_fn(|_| true)
.skip_static(|_| true)
Expand Down
9 changes: 7 additions & 2 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,13 @@ cfg_if! {
cfg_if! {
if #[cfg(all(
any(target_arch = "mips", target_arch = "mips32r6"),
any(target_env = "uclibc", target_env = "gnu"),
linux_time_bits64
any(
all(target_env = "uclibc", linux_time_bits64),
all(
target_env = "gnu",
any(linux_time_bits64, gnu_file_offset_bits64)
)
)
))] {
pub const RLIM_INFINITY: crate::rlim_t = !0;
} else if #[cfg(all(
Expand Down
10 changes: 8 additions & 2 deletions src/unix/linux_like/linux/gnu/b32/arm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ s! {
pub struct stat64 {
pub st_dev: crate::dev_t,
__pad1: c_uint,
__st_ino: crate::ino_t,
__st_ino: c_ulong,
pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
Expand Down Expand Up @@ -397,7 +397,13 @@ pub const MCL_ONFAULT: c_int = 0x0004;
pub const POLLWRNORM: c_short = 0x100;
pub const POLLWRBAND: c_short = 0x200;

pub const F_GETLK: c_int = 5;
cfg_if! {
if #[cfg(gnu_file_offset_bits64)] {
pub const F_GETLK: c_int = 12;
} else {
pub const F_GETLK: c_int = 5;
}
}
pub const F_GETOWN: c_int = 9;
pub const F_SETOWN: c_int = 8;

Expand Down
28 changes: 25 additions & 3 deletions src/unix/linux_like/linux/gnu/b32/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,36 @@ s! {
pub st_dev: c_ulong,

st_pad1: [c_long; 3],

pub st_ino: crate::ino_t,

pub st_mode: crate::mode_t,
pub st_nlink: crate::nlink_t,
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,

pub st_rdev: c_ulong,

#[cfg(not(gnu_file_offset_bits64))]
st_pad2: [c_long; 2],
#[cfg(gnu_file_offset_bits64)]
st_pad2: [c_long; 3],

pub st_size: off_t,

#[cfg(not(gnu_file_offset_bits64))]
st_pad3: c_long,

pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
pub st_mtime: crate::time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: crate::time_t,
pub st_ctime_nsec: c_long,

pub st_blksize: crate::blksize_t,
#[cfg(gnu_file_offset_bits64)]
st_pad4: c_long,
pub st_blocks: crate::blkcnt_t,
st_pad5: [c_long; 14],
}
Expand All @@ -37,7 +51,7 @@ s! {
pub st_uid: crate::uid_t,
pub st_gid: crate::gid_t,
pub st_rdev: c_ulong,
st_pad2: [c_long; 2],
st_pad2: [c_long; 3],
pub st_size: off64_t,
pub st_atime: crate::time_t,
pub st_atime_nsec: c_long,
Expand Down Expand Up @@ -176,9 +190,11 @@ s! {
pub l_whence: c_short,
pub l_start: off_t,
pub l_len: off_t,
#[cfg(not(gnu_file_offset_bits64))]
pub l_sysid: c_long,
pub l_pid: crate::pid_t,
pad: [c_long; 4],
#[cfg(not(gnu_file_offset_bits64))]
__glibc_reserved0: [c_long; 4],
}
}

Expand Down Expand Up @@ -745,7 +761,13 @@ pub const MAP_HUGETLB: c_int = 0x080000;

pub const EFD_NONBLOCK: c_int = 0x80;

pub const F_GETLK: c_int = 14;
cfg_if! {
if #[cfg(gnu_file_offset_bits64)] {
pub const F_GETLK: c_int = 33;
} else {
pub const F_GETLK: c_int = 14;
}
}
pub const F_GETOWN: c_int = 23;
pub const F_SETOWN: c_int = 24;

Expand Down
Loading
Loading