libsanitizer: features.h: hard-wire _FILE_OFFSET_BITS=64 to match library's 64-bit off_t/ino_t
libsanitizer's __sanitizer_dirent struct layout check fails to build
against uClibc-ng's stock headers on 32-bit targets:
CHECK_SIZE_AND_OFFSET(dirent, d_ino)
static_assert failed: "sizeof(((struct dirent *) 0)->d_ino) == 8",
actually 4
The cause is an ABI mismatch entirely inside uClibc-ng: the library is
built unconditionally with 64-bit off_t / ino_t / dirent / time_t
internals (UCLIBC_HAS_LFS is hard-coded y since the 2016 cleanup,
commit 74ca8d6f5d2e -- "remove UCLIBC_HAS_LFS"), but <sys/types.h>
still defaults to 32-bit off_t / ino_t on 32-bit targets unless the
user explicitly sets -D_FILE_OFFSET_BITS=64. Programs that don't know
about this hidden requirement get headers and library disagreeing.
libsanitizer's static-asserts catch it; most other consumers silently
mis-link.
Fix: in features.h, hard-wire _FILE_OFFSET_BITS=64 to match what the
library was built with. This matches what musl libc does -- musl
exposes only the 64-bit ABI in its headers, no 32-bit opt-in, because
the library itself only ships 64-bit internals. Same situation here.
To prevent the silent-mis-link case from sneaking back in via user
code that sets -D_FILE_OFFSET_BITS=32, this version of the patch
turns that into a loud compile-time error rather than a silent
override. Existing builds that pass -D_FILE_OFFSET_BITS=64 explicitly
(most distro builds) are unaffected.
Side benefits:
- <dirent> / off_t / ino_t are 64-bit consistently across all TUs
- Y2038-clean on 32-bit targets (64-bit time_t requires 64-bit
off_t -- see musl time64 release notes)
- libsanitizer's __sanitizer_dirent layout check passes out of box
Companion patch:
- <fts.h> ships an unconditional
#ifdef __USE_FILE_OFFSET64
# error "<fts.h> cannot be used with -D_FILE_OFFSET_BITS==64"
#endif
that becomes unconditionally wrong with this patch. Removed in
the 2/2 follow-up (also triggered by libsanitizer indirectly --
elfutils-0.193, used by heaptrack, includes <fts.h> while
LFS-on).
Signed-off-by: Ramin Moussavi <ramin.moussavi@yacoub.de>