浏览代码

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>
Ramin Moussavi 2 月之前
父节点
当前提交
87b354252a
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      include/features.h

+ 5 - 2
include/features.h

@@ -340,9 +340,12 @@
 # define __USE_LARGEFILE64	1
 #endif
 
-#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
-# define __USE_FILE_OFFSET64	1
+#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64
+# error "_FILE_OFFSET_BITS != 64 is not supported by uClibc-ng"
 #endif
+#undef  _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS	64
+#define __USE_FILE_OFFSET64	1
 
 #if defined _BSD_SOURCE || defined _SVID_SOURCE
 # define __USE_MISC	1