Repository navigation
fix: support glibc < 2.30 - #6
Conversation
Without the fix, cargo test on rockylinux:8 (glibc 2.28) fails to link with "undefined reference to `gettid'"; with it, all tests pass. Both were checked locally in the rockylinux:8 image on aarch64.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
[Medium impact] The change affects thread-ID fields in logs for users of the formatter. The PR is not ready to merge because Apple builds still fail. Findings
SummaryThe PR replaces the direct Linux
Reviews (2) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
| pub(super) fn gettid() -> u64 { | ||
| let mut id: u64 = 0; | ||
| // SAFETY: id is stack-allocated and guaranteed to outlast the call. | ||
| let res = unsafe { libc::pthread_threadid_np(0, &mut id) }; |
There was a problem hiding this comment.
libc::pthread_threadid_np takes a pointer-typed pthread_t on Apple, but this call passes the integer 0. Rust does not convert that integer into a null pointer, so macOS builds fail with a type mismatch. Pass std::ptr::null_mut() instead.
| let res = unsafe { libc::pthread_threadid_np(0, &mut id) }; | |
| let res = unsafe { libc::pthread_threadid_np(std::ptr::null_mut(), &mut id) }; |
There was a problem hiding this comment.
Not true: on Apple, libc defines pthread_t = crate::uintptr_t (src/unix/bsd/mod.rs:8 in libc 0.2.191), so 0 is a usize and Test (macos-14) passes. std::ptr::null_mut() is what would fail to compile.
There was a problem hiding this comment.
You're right—my comment was incorrect. With the locked libc 0.2.191 binding, Apple’s pthread_t is uintptr_t (usize), so 0 is type-correct here, while std::ptr::null_mut() would fail to compile. The macOS CI pass is consistent with that. Please disregard my suggested change; the existing call is correct.
…old-glibc # Conflicts: # Cargo.lock # Cargo.toml
Mirrors
EmbarkStudios/tracing-logfmt#23and adds one commit that isn't upstream. FixesEmbarkStudios/tracing-logfmt#22: on glibc < 2.30 (RHEL 8) the crate fails to link because glibc doesn't exportgettidthere.gettidis now looked up once withdlsym, andsyscall(SYS_gettid)is used when it is missing.ci: test on rockylinux:8 ...is fork-only. It adds acargo test --all-featuresjob in a rockylinux:8 container (glibc 2.28). Run locally in that image, main fails withundefined reference to `gettid'and this branch passes all tests. Written by Claude; drop it or send it upstream as you prefer.Cargo.toml/Cargo.lock, since each adds a dependency. Merge it last, and main gets merged into this branch to resolve.cargo-deny stays red until #1 lands.