Skip to content

Commit d8c14ad

Browse files
committed
Depend on glibc 2.17 and use getauxval unconditionally.
1 parent b188a58 commit d8c14ad

File tree

6 files changed

+32
-85
lines changed

6 files changed

+32
-85
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ oldest Linux version supported by:
160160
The specifics of this policy may change in the future, but we intend it to
161161
always reflect “very old” Linux versions.
162162

163+
## Minimum glibc Version
164+
165+
On glibc platforms, rustix requires at least glibc 2.17. This is at most the
166+
oldest glibc version supported by:
167+
- [any current Rust target]
168+
The specifics of this policy may change in the future, but we intend it to
169+
always reflect “very old” glibc versions.
170+
163171
[MSRV]: #minimum-supported-rust-version-msrv
164172
[Rust 1.63]: https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html
165173
[any current Rust target]: https://doc.rust-lang.org/nightly/rustc/platform-support.html

src/backend/libc/param/auxv.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ use crate::backend::c;
55
))]
66
use crate::ffi::CStr;
77

8-
// `getauxval` wasn't supported in glibc until 2.16.
9-
#[cfg(any(
10-
all(target_os = "android", target_pointer_width = "64"),
11-
target_os = "linux",
12-
))]
13-
weak!(fn getauxval(c::c_ulong) -> *mut c::c_void);
8+
extern "C" {
9+
fn getauxval(type_: c::c_ulong) -> *mut c::c_void;
10+
}
1411

1512
#[inline]
1613
pub(crate) fn page_size() -> usize {
@@ -29,14 +26,10 @@ pub(crate) fn clock_ticks_per_second() -> u64 {
2926
))]
3027
#[inline]
3128
pub(crate) fn linux_hwcap() -> (usize, usize) {
32-
if let Some(libc_getauxval) = getauxval.get() {
33-
unsafe {
34-
let hwcap = libc_getauxval(c::AT_HWCAP) as usize;
35-
let hwcap2 = libc_getauxval(c::AT_HWCAP2) as usize;
36-
(hwcap, hwcap2)
37-
}
38-
} else {
39-
(0, 0)
29+
unsafe {
30+
let hwcap = getauxval(c::AT_HWCAP) as usize;
31+
let hwcap2 = getauxval(c::AT_HWCAP2) as usize;
32+
(hwcap, hwcap2)
4033
}
4134
}
4235

@@ -61,9 +54,5 @@ pub(crate) fn linux_minsigstksz() -> usize {
6154
))]
6255
#[inline]
6356
pub(crate) fn linux_execfn() -> &'static CStr {
64-
if let Some(libc_getauxval) = getauxval.get() {
65-
unsafe { CStr::from_ptr(libc_getauxval(c::AT_EXECFN).cast()) }
66-
} else {
67-
cstr!("")
68-
}
57+
unsafe { CStr::from_ptr(getauxval(c::AT_EXECFN).cast()) }
6958
}

src/backend/linux_raw/param/auxv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub(crate) fn vsyscall() -> *const c::c_void {
224224

225225
if vsyscall.is_null() {
226226
#[cold]
227-
fn compute_vsyscall() -> *const c::c_void {
227+
fn compute_vsyscall() -> *mut c::c_void {
228228
init_auxv();
229229
VSYSCALL.load(Relaxed)
230230
}
@@ -253,7 +253,7 @@ static PHNUM: AtomicUsize = AtomicUsize::new(0);
253253
static ENTRY: AtomicUsize = AtomicUsize::new(0);
254254
#[cfg(feature = "runtime")]
255255
static RANDOM: AtomicPtr<[u8; 16]> = AtomicPtr::new(null_mut());
256-
#[cfg(feature = "x86")]
256+
#[cfg(target_arch = "x86")]
257257
static VSYSCALL: AtomicPtr<c::c_void> = AtomicPtr::new(null_mut());
258258

259259
const PR_GET_AUXV: c::c_int = 0x4155_5856;

src/backend/linux_raw/param/libc_auxv.rs

+3-47
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ use {
1717
core::sync::atomic::Ordering::Relaxed,
1818
};
1919

20-
// `getauxval` wasn't supported in glibc until 2.16. Also this lets us use
21-
// `*mut` as the return type to preserve strict provenance.
22-
#[cfg(not(feature = "runtime"))]
23-
weak!(fn getauxval(c::c_ulong) -> *mut c::c_void);
24-
25-
// With the "runtime" feature, go ahead and depend on `getauxval` existing so
26-
// that we never fail.
27-
#[cfg(feature = "runtime")]
2820
extern "C" {
2921
fn getauxval(type_: c::c_ulong) -> *mut c::c_void;
3022
}
@@ -99,18 +91,6 @@ pub(crate) fn clock_ticks_per_second() -> u64 {
9991
#[cfg(feature = "param")]
10092
#[inline]
10193
pub(crate) fn linux_hwcap() -> (usize, usize) {
102-
#[cfg(not(feature = "runtime"))]
103-
unsafe {
104-
if let Some(libc_getauxval) = getauxval.get() {
105-
let hwcap = libc_getauxval(AT_HWCAP) as usize;
106-
let hwcap2 = libc_getauxval(AT_HWCAP2) as usize;
107-
(hwcap, hwcap2)
108-
} else {
109-
(0, 0)
110-
}
111-
}
112-
113-
#[cfg(feature = "runtime")]
11494
unsafe {
11595
let hwcap = getauxval(AT_HWCAP) as usize;
11696
let hwcap2 = getauxval(AT_HWCAP2) as usize;
@@ -140,19 +120,7 @@ pub(crate) fn linux_minsigstksz() -> usize {
140120
#[cfg(feature = "param")]
141121
#[inline]
142122
pub(crate) fn linux_execfn() -> &'static CStr {
143-
#[cfg(not(feature = "runtime"))]
144-
unsafe {
145-
if let Some(libc_getauxval) = getauxval.get() {
146-
CStr::from_ptr(libc_getauxval(AT_EXECFN).cast())
147-
} else {
148-
cstr!("")
149-
}
150-
}
151-
152-
#[cfg(feature = "runtime")]
153-
unsafe {
154-
CStr::from_ptr(getauxval(AT_EXECFN).cast())
155-
}
123+
unsafe { CStr::from_ptr(getauxval(AT_EXECFN).cast()) }
156124
}
157125

158126
#[cfg(feature = "runtime")]
@@ -176,19 +144,7 @@ pub(crate) fn exe_phdrs() -> (*const c::c_void, usize, usize) {
176144
/// if we don't see it, this function returns a null pointer.
177145
#[inline]
178146
pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr {
179-
#[cfg(not(feature = "runtime"))]
180-
unsafe {
181-
if let Some(libc_getauxval) = getauxval.get() {
182-
libc_getauxval(AT_SYSINFO_EHDR) as *const Elf_Ehdr
183-
} else {
184-
null()
185-
}
186-
}
187-
188-
#[cfg(feature = "runtime")]
189-
unsafe {
190-
getauxval(AT_SYSINFO_EHDR) as *const Elf_Ehdr
191-
}
147+
unsafe { getauxval(AT_SYSINFO_EHDR) as *const Elf_Ehdr }
192148
}
193149

194150
#[cfg(feature = "runtime")]
@@ -214,7 +170,7 @@ pub(crate) fn vsyscall() -> *const c_void {
214170
if vsyscall.is_null() {
215171
#[cold]
216172
fn compute_vsyscall() -> *mut c_void {
217-
let vsyscall = unsafe { getauxval(AT_SYSINFO) } as *mut c_void;
173+
let vsyscall = unsafe { getauxval(AT_SYSINFO) as *mut c_void };
218174
VSYSCALL.store(vsyscall, Relaxed);
219175
vsyscall
220176
}

src/lib.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,9 @@ pub(crate) mod check_types;
157157
#[macro_use]
158158
pub(crate) mod bitcast;
159159

160-
// linux_raw: Weak symbols are used by the use-libc-auxv feature for
161-
// glibc 2.15 support.
162-
//
163-
// libc: Weak symbols are used to call various functions available in some
164-
// versions of libc and not others.
165-
#[cfg(any(
166-
all(linux_raw, feature = "use-libc-auxv"),
167-
all(libc, not(any(windows, target_os = "espidf", target_os = "wasi")))
168-
))]
160+
// Weak symbols are used to call various functions available in some versions
161+
// of libc and not others.
162+
#[cfg(all(libc, not(any(windows, target_os = "espidf", target_os = "wasi"))))]
169163
#[macro_use]
170164
mod weak;
171165

tests/param/auxv.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ fn test_clock_ticks_per_second() {
2727
))]
2828
#[test]
2929
fn test_linux_hwcap() {
30-
weak!(fn getauxval(libc::c_ulong) -> libc::c_ulong);
30+
extern "C" {
31+
fn getauxval(type_: c::c_ulong) -> *mut c::c_void;
32+
}
3133

32-
if let Some(libc_getauxval) = getauxval.get() {
33-
let (_hwcap, hwcap2) = linux_hwcap();
34+
let (_hwcap, hwcap2) = linux_hwcap();
3435

35-
// glibc seems to return a different value than `LD_SHOW_AUXV=1` reports.
36-
#[cfg(not(target_env = "gnu"))]
37-
assert_eq!(_hwcap, unsafe { libc_getauxval(libc::AT_HWCAP) } as usize);
36+
// glibc seems to return a different value than `LD_SHOW_AUXV=1` reports.
37+
#[cfg(not(target_env = "gnu"))]
38+
assert_eq!(_hwcap, unsafe { getauxval(libc::AT_HWCAP) } as usize);
3839

39-
assert_eq!(hwcap2, unsafe { libc_getauxval(libc::AT_HWCAP2) } as usize);
40-
}
40+
assert_eq!(hwcap2, unsafe { getauxval(libc::AT_HWCAP2) } as usize);
4141
}
4242

4343
#[cfg(any(

0 commit comments

Comments
 (0)