Skip to content

Commit 1a54496

Browse files
authored
Merge pull request #4345 from snogge/gnu-file-offset-64
Add new cfg gnu_file_offset_bits64 corresponding to _FILE_OFFSET_BITS=64
2 parents 978edec + 4a7c9a9 commit 1a54496

File tree

16 files changed

+360
-41
lines changed

16 files changed

+360
-41
lines changed

.github/workflows/ci.yaml

+39-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ jobs:
7676
- target: i686-unknown-linux-gnu
7777
docker: true
7878
os: ubuntu-24.04
79+
- target: i686-unknown-linux-gnu
80+
docker: true
81+
os: ubuntu-24.04
82+
artifact-tag: offset-bits64
83+
env:
84+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
7985
- target: x86_64-unknown-linux-gnu
8086
docker: true
8187
os: ubuntu-24.04
@@ -107,6 +113,13 @@ jobs:
107113
with:
108114
key: ${{ matrix.target }}
109115

116+
- name: Add matrix env variables to the environment
117+
if: matrix.env
118+
run: |
119+
echo '${{ toJson(matrix.env) }}' |
120+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
121+
shell: bash
122+
110123
- name: Run natively
111124
if: "!matrix.docker"
112125
run: ./ci/run.sh ${{ matrix.target }}
@@ -115,11 +128,13 @@ jobs:
115128
run: ./ci/run-docker.sh ${{ matrix.target }}
116129

117130
- name: Create CI artifacts
131+
id: create_artifacts
118132
if: always()
119133
run: ./ci/create-artifacts.py
120134
- uses: actions/upload-artifact@v4
135+
if: always() && steps.create_artifacts.outcome == 'success'
121136
with:
122-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
137+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
123138
path: ${{ env.ARCHIVE_PATH }}
124139
retention-days: 5
125140

@@ -139,15 +154,11 @@ jobs:
139154
- aarch64-unknown-linux-gnu
140155
- aarch64-unknown-linux-musl
141156
- arm-linux-androideabi
142-
- arm-unknown-linux-gnueabihf
143157
- arm-unknown-linux-musleabihf
144158
- i686-linux-android
145159
- i686-unknown-linux-musl
146160
- loongarch64-unknown-linux-gnu
147161
- loongarch64-unknown-linux-musl
148-
# FIXME(ppc): SIGILL running tests, see
149-
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
150-
# - powerpc-unknown-linux-gnu
151162
- powerpc64-unknown-linux-gnu
152163
- powerpc64le-unknown-linux-gnu
153164
- riscv64gc-unknown-linux-gnu
@@ -162,6 +173,19 @@ jobs:
162173
# FIXME: It seems some items in `src/unix/mod.rs`
163174
# aren't defined on redox actually.
164175
# - x86_64-unknown-redox
176+
include:
177+
- target: arm-unknown-linux-gnueabihf
178+
- target: arm-unknown-linux-gnueabihf
179+
env:
180+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
181+
artifact-tag: offset-bits64
182+
# FIXME(ppc): SIGILL running tests, see
183+
# https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713
184+
# - target: powerpc-unknown-linux-gnu
185+
# - target: powerpc-unknown-linux-gnu
186+
# env:
187+
# RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS: 64
188+
# artifact-tag: offset-bits64
165189
timeout-minutes: 25
166190
env:
167191
TARGET: ${{ matrix.target }}
@@ -173,15 +197,24 @@ jobs:
173197
with:
174198
key: ${{ matrix.target }}
175199

200+
- name: Add matrix env variables to the environment
201+
if: matrix.env
202+
run: |
203+
echo '${{ toJson(matrix.env) }}' |
204+
jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV
205+
shell: bash
206+
176207
- name: Execute run-docker.sh
177208
run: ./ci/run-docker.sh ${{ matrix.target }}
178209

179210
- name: Create CI artifacts
211+
id: create_artifacts
180212
if: always()
181213
run: ./ci/create-artifacts.py
182214
- uses: actions/upload-artifact@v4
215+
if: always() && steps.create_artifacts.outcome == 'success'
183216
with:
184-
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}
217+
name: ${{ env.ARCHIVE_NAME }}-${{ matrix.target }}${{ matrix.artifact-tag && format('-{0}', matrix.artifact-tag) }}
185218
path: ${{ env.ARCHIVE_PATH }}
186219
retention-days: 5
187220

build.rs

+23
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1313
"freebsd13",
1414
"freebsd14",
1515
"freebsd15",
16+
// Corresponds to `_FILE_OFFSET_BITS=64` in glibc
17+
"gnu_file_offset_bits64",
1618
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
1719
"libc_const_extern_fn",
1820
"libc_deny_warnings",
@@ -43,6 +45,10 @@ fn main() {
4345
let (rustc_minor_ver, _is_nightly) = rustc_minor_nightly();
4446
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
4547
let libc_ci = env::var("LIBC_CI").is_ok();
48+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
49+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
50+
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default();
51+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
4652

4753
// The ABI of libc used by std is backward compatible with FreeBSD 12.
4854
// The ABI of libc from crates.io is backward compatible with FreeBSD 12.
@@ -84,6 +90,23 @@ fn main() {
8490
if linux_time_bits64 {
8591
set_cfg("linux_time_bits64");
8692
}
93+
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS");
94+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
95+
Ok(val) if val == "64" => {
96+
if target_env == "gnu"
97+
&& target_os == "linux"
98+
&& target_ptr_width == "32"
99+
&& target_arch != "riscv32"
100+
&& target_arch != "x86_64"
101+
{
102+
set_cfg("gnu_file_offset_bits64");
103+
}
104+
}
105+
Ok(val) if val != "32" => {
106+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
107+
}
108+
_ => {}
109+
}
87110

88111
// On CI: deny all warnings
89112
if libc_ci {

ci/run-docker.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ run() {
4343
--user "$(id -u)":"$(id -g)" \
4444
--env LIBC_CI \
4545
--env LIBC_CI_ZBUILD_STD \
46+
--env RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS \
4647
--env CARGO_HOME=/cargo \
4748
--env CARGO_TARGET_DIR=/checkout/target \
4849
--volume "$CARGO_HOME":/cargo \
4950
--volume "$(rustc --print sysroot)":/rust:ro \
50-
--volume "$(pwd)":/checkout:ro \
51-
--volume "$(pwd)"/target:/checkout/target \
51+
--volume "$PWD":/checkout:ro \
52+
--volume "$PWD"/target:/checkout/target \
5253
$kvm \
5354
--init \
5455
--workdir /checkout \

ci/verify-build.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ test_target() {
7474
if [ "$os" = "linux" ]; then
7575
# Test with the equivalent of __USE_TIME_BITS64
7676
RUST_LIBC_UNSTABLE_LINUX_TIME_BITS64=1 $cmd
77+
case "$target" in
78+
# Test with the equivalent of __FILE_OFFSET_BITS=64
79+
arm*-gnu*|i*86*-gnu|powerpc-*-gnu*|mips*-gnu|sparc-*-gnu|thumb-*gnu*)
80+
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64 $cmd;;
81+
esac
7782
fi
7883

7984
# Test again without default features, i.e. without "std"
@@ -91,7 +96,7 @@ test_target() {
9196
stable-x86_64-*freebsd*) do_freebsd_checks=1 ;;
9297
nightly-i686*freebsd*) do_freebsd_checks=1 ;;
9398
esac
94-
99+
95100
if [ -n "${do_freebsd_checks:-}" ]; then
96101
for version in $freebsd_versions; do
97102
export RUST_LIBC_UNSTABLE_FREEBSD_VERSION="$version"
@@ -296,7 +301,7 @@ filter_and_run() {
296301
if [ "$target" = "wasm32-wasip2" ] && [ "$supports_wasi_pn" = "0" ]; then
297302
return
298303
fi
299-
304+
300305
test_target "$target" "$no_dist"
301306
some_tests_run=1
302307
fi

libc-test/build.rs

+28
Original file line numberDiff line numberDiff line change
@@ -3590,6 +3590,26 @@ fn test_vxworks(target: &str) {
35903590
cfg.generate(src_hotfix_dir().join("lib.rs"), "main.rs");
35913591
}
35923592

3593+
fn config_gnu_bits(target: &str, cfg: &mut ctest::TestGenerator) {
3594+
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS") {
3595+
Ok(val) if val == "64" => {
3596+
if target.contains("gnu")
3597+
&& target.contains("linux")
3598+
&& !target.ends_with("x32")
3599+
&& !target.contains("riscv32")
3600+
&& env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap() == "32"
3601+
{
3602+
cfg.define("_FILE_OFFSET_BITS", Some("64"));
3603+
cfg.cfg("gnu_file_offset_bits64", None);
3604+
}
3605+
}
3606+
Ok(val) if val != "32" => {
3607+
panic!("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS may only be set to '32' or '64'")
3608+
}
3609+
_ => {}
3610+
}
3611+
}
3612+
35933613
fn test_linux(target: &str) {
35943614
assert!(target.contains("linux"));
35953615

@@ -3633,6 +3653,8 @@ fn test_linux(target: &str) {
36333653
// glibc versions older than 2.29.
36343654
cfg.define("__GLIBC_USE_DEPRECATED_SCANF", None);
36353655

3656+
config_gnu_bits(target, &mut cfg);
3657+
36363658
headers! { cfg:
36373659
"ctype.h",
36383660
"dirent.h",
@@ -4794,6 +4816,7 @@ fn test_linux_like_apis(target: &str) {
47944816
if linux || android || emscripten {
47954817
// test strerror_r from the `string.h` header
47964818
let mut cfg = ctest_cfg();
4819+
config_gnu_bits(target, &mut cfg);
47974820
cfg.skip_type(|_| true).skip_static(|_| true);
47984821

47994822
headers! { cfg: "string.h" }
@@ -4810,6 +4833,7 @@ fn test_linux_like_apis(target: &str) {
48104833
// test fcntl - see:
48114834
// http://man7.org/linux/man-pages/man2/fcntl.2.html
48124835
let mut cfg = ctest_cfg();
4836+
config_gnu_bits(target, &mut cfg);
48134837

48144838
if musl {
48154839
cfg.header("fcntl.h");
@@ -4839,6 +4863,7 @@ fn test_linux_like_apis(target: &str) {
48394863
if (linux && !wali) || android {
48404864
// test termios
48414865
let mut cfg = ctest_cfg();
4866+
config_gnu_bits(target, &mut cfg);
48424867
cfg.header("asm/termbits.h");
48434868
cfg.header("linux/termios.h");
48444869
cfg.skip_type(|_| true)
@@ -4863,6 +4888,7 @@ fn test_linux_like_apis(target: &str) {
48634888
if linux || android {
48644889
// test IPV6_ constants:
48654890
let mut cfg = ctest_cfg();
4891+
config_gnu_bits(target, &mut cfg);
48664892
headers! {
48674893
cfg:
48684894
"linux/in6.h"
@@ -4894,6 +4920,7 @@ fn test_linux_like_apis(target: &str) {
48944920
// "resolve.h" defines a `p_type` macro that expands to `__p_type`
48954921
// making the tests for these fails when both are included.
48964922
let mut cfg = ctest_cfg();
4923+
config_gnu_bits(target, &mut cfg);
48974924
cfg.header("elf.h");
48984925
cfg.skip_fn(|_| true)
48994926
.skip_static(|_| true)
@@ -4913,6 +4940,7 @@ fn test_linux_like_apis(target: &str) {
49134940
if (linux && !wali) || android {
49144941
// Test `ARPHRD_CAN`.
49154942
let mut cfg = ctest_cfg();
4943+
config_gnu_bits(target, &mut cfg);
49164944
cfg.header("linux/if_arp.h");
49174945
cfg.skip_fn(|_| true)
49184946
.skip_static(|_| true)

src/unix/linux_like/linux/arch/mips/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,13 @@ cfg_if! {
379379
cfg_if! {
380380
if #[cfg(all(
381381
any(target_arch = "mips", target_arch = "mips32r6"),
382-
any(target_env = "uclibc", target_env = "gnu"),
383-
linux_time_bits64
382+
any(
383+
all(target_env = "uclibc", linux_time_bits64),
384+
all(
385+
target_env = "gnu",
386+
any(linux_time_bits64, gnu_file_offset_bits64)
387+
)
388+
)
384389
))] {
385390
pub const RLIM_INFINITY: crate::rlim_t = !0;
386391
} else if #[cfg(all(

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ s! {
6161
pub struct stat64 {
6262
pub st_dev: crate::dev_t,
6363
__pad1: c_uint,
64-
__st_ino: crate::ino_t,
64+
__st_ino: c_ulong,
6565
pub st_mode: crate::mode_t,
6666
pub st_nlink: crate::nlink_t,
6767
pub st_uid: crate::uid_t,
@@ -397,7 +397,13 @@ pub const MCL_ONFAULT: c_int = 0x0004;
397397
pub const POLLWRNORM: c_short = 0x100;
398398
pub const POLLWRBAND: c_short = 0x200;
399399

400-
pub const F_GETLK: c_int = 5;
400+
cfg_if! {
401+
if #[cfg(gnu_file_offset_bits64)] {
402+
pub const F_GETLK: c_int = 12;
403+
} else {
404+
pub const F_GETLK: c_int = 5;
405+
}
406+
}
401407
pub const F_GETOWN: c_int = 9;
402408
pub const F_SETOWN: c_int = 8;
403409

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

+25-3
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,36 @@ s! {
88
pub st_dev: c_ulong,
99

1010
st_pad1: [c_long; 3],
11+
1112
pub st_ino: crate::ino_t,
13+
1214
pub st_mode: crate::mode_t,
1315
pub st_nlink: crate::nlink_t,
1416
pub st_uid: crate::uid_t,
1517
pub st_gid: crate::gid_t,
18+
1619
pub st_rdev: c_ulong,
20+
21+
#[cfg(not(gnu_file_offset_bits64))]
1722
st_pad2: [c_long; 2],
23+
#[cfg(gnu_file_offset_bits64)]
24+
st_pad2: [c_long; 3],
25+
1826
pub st_size: off_t,
27+
28+
#[cfg(not(gnu_file_offset_bits64))]
1929
st_pad3: c_long,
30+
2031
pub st_atime: crate::time_t,
2132
pub st_atime_nsec: c_long,
2233
pub st_mtime: crate::time_t,
2334
pub st_mtime_nsec: c_long,
2435
pub st_ctime: crate::time_t,
2536
pub st_ctime_nsec: c_long,
37+
2638
pub st_blksize: crate::blksize_t,
39+
#[cfg(gnu_file_offset_bits64)]
40+
st_pad4: c_long,
2741
pub st_blocks: crate::blkcnt_t,
2842
st_pad5: [c_long; 14],
2943
}
@@ -37,7 +51,7 @@ s! {
3751
pub st_uid: crate::uid_t,
3852
pub st_gid: crate::gid_t,
3953
pub st_rdev: c_ulong,
40-
st_pad2: [c_long; 2],
54+
st_pad2: [c_long; 3],
4155
pub st_size: off64_t,
4256
pub st_atime: crate::time_t,
4357
pub st_atime_nsec: c_long,
@@ -176,9 +190,11 @@ s! {
176190
pub l_whence: c_short,
177191
pub l_start: off_t,
178192
pub l_len: off_t,
193+
#[cfg(not(gnu_file_offset_bits64))]
179194
pub l_sysid: c_long,
180195
pub l_pid: crate::pid_t,
181-
pad: [c_long; 4],
196+
#[cfg(not(gnu_file_offset_bits64))]
197+
__glibc_reserved0: [c_long; 4],
182198
}
183199
}
184200

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

746762
pub const EFD_NONBLOCK: c_int = 0x80;
747763

748-
pub const F_GETLK: c_int = 14;
764+
cfg_if! {
765+
if #[cfg(gnu_file_offset_bits64)] {
766+
pub const F_GETLK: c_int = 33;
767+
} else {
768+
pub const F_GETLK: c_int = 14;
769+
}
770+
}
749771
pub const F_GETOWN: c_int = 23;
750772
pub const F_SETOWN: c_int = 24;
751773

0 commit comments

Comments
 (0)