[compiler-rt] [sanitizer] Undef _TIME_BITS along with _FILE_OFFSET_BITS (PR #99699)

Thomas Petazzoni via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 20 02:30:01 PDT 2024


https://github.com/tpetazzoni updated https://github.com/llvm/llvm-project/pull/99699

>From 920de81b808965543dcc07fa387dd810f99b74bd Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Date: Fri, 19 Jul 2024 22:22:55 +0200
Subject: [PATCH] [sanitizer] Undef _TIME_BITS along with _FILE_OFFSET_BITS

This change is identical to
26800a2c7e7996dc773b4e990dd5cca41c45e1a9 ("[sanitizer] Undef
_TIME_BITS along with _FILE_OFFSET_BITS on Linux"), but for
sanitizer_procmaps_solaris.cpp.

Indeed, even though sanitizer_procmaps_solaris.cpp is Solaris
specific, it also gets built on Linux platforms. It also includes
sanitizer_platform.h, which also ends up including features-time64.h,
causing a build failure on 32-bit Linux platforms on which 64-bit
time_t is enabled by setting _TIME_BITS=64.

To fix this, we do the same change: undefine _TIME_BITS, which anyway
will cause no harm as the rest of this file is inside a
SANITIZER_SOLARIS compile-time conditional.

Fixes:

In file included from /home/thomas/buildroot/buildroot/output/host/i686-buildroot-linux-gnu/sysroot/usr/include/features.h:394,
                 from ../../../../libsanitizer/sanitizer_common/sanitizer_platform.h:25,
                 from ../../../../libsanitizer/sanitizer_common/sanitizer_procmaps_solaris.cpp:14:
/home/thomas/buildroot/buildroot/output/host/i686-buildroot-linux-gnu/sysroot/usr/include/features-time64.h:26:5: error: #error "_TIME_BITS=64 is al
lowed only with _FILE_OFFSET_BITS=64"
   26 | #   error "_TIME_BITS=64 is allowed only with _FILE_OFFSET_BITS=64"
      |     ^~~~~

Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
---
 .../sanitizer_common/sanitizer_procmaps_solaris.cpp  | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
index eeb49e2afe34d..cc523f347131b 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_solaris.cpp
@@ -11,6 +11,18 @@
 
 // Before Solaris 11.4, <procfs.h> doesn't work in a largefile environment.
 #undef _FILE_OFFSET_BITS
+
+// Even though this is a Solaris-specific file, it gets built on all
+// platforms, including Linux ones. On such platforms, _TIME_BITS=64
+// might be passed to enable 64-bit time_t on 32-bit
+// architectures. However _TIME_BITS=64 requires _FILE_OFFSET_BITS=64,
+// but we undefine _FILE_OFFSET_BITS above, causing a failure as
+// sanitizer_platform.h below includes some system headers that are
+// unhappy with _TIME_BITS defined and _FILE_OFFSET_BITS
+// undefined. Therefore, apply the same consideration as in
+// sanitizer_platform_limits_posix.cpp, which consists in undefining
+// _TIME_BITS.
+#undef _TIME_BITS
 #include "sanitizer_platform.h"
 #if SANITIZER_SOLARIS
 #  include <fcntl.h>



More information about the llvm-commits mailing list