[compiler-rt] [sanitizer_common] Heed __ndbl_ prefix for 32-bit Linux/sparc64 inter… (PR #109106)
Rainer Orth via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 02:18:07 PDT 2024
https://github.com/rorth created https://github.com/llvm/llvm-project/pull/109106
…ceptors
When ASan testing is enabled on SPARC as per PR #107405, a couple of tests `FAIL` on Linux/sparc64:
```
AddressSanitizer-sparc-linux :: TestCases/printf-2.c
AddressSanitizer-sparc-linux :: TestCases/printf-3.c
AddressSanitizer-sparc-linux :: TestCases/printf-4.c
AddressSanitizer-sparc-linux :: TestCases/printf-5.c
SanitizerCommon-asan-sparc-Linux :: Linux/unexpected_format_specifier_test.cpp
```
It turns out the interceptors aren't used since on Linux/sparc64 `double` and `long double` are the same, and a couple of `stdio` functions are prefixed with `__nldbl_` (no long double) accordingly.
This patch handles this.
Tested on `sparc64-unknown-linux-gnu`.
>From d4eb6c66e4702616e0193011b51a7dc5e667d296 Mon Sep 17 00:00:00 2001
From: Rainer Orth <ro at gcc.gnu.org>
Date: Wed, 18 Sep 2024 11:16:54 +0200
Subject: [PATCH] [sanitizer_common] Heed __ndbl_ prefix for 32-bit
Linux/sparc64 interceptors
When ASan testing is enabled on SPARC as per PR #107405, a couple of tests
`FAIL` on Linux/sparc64:
```
AddressSanitizer-sparc-linux :: TestCases/printf-2.c
AddressSanitizer-sparc-linux :: TestCases/printf-3.c
AddressSanitizer-sparc-linux :: TestCases/printf-4.c
AddressSanitizer-sparc-linux :: TestCases/printf-5.c
SanitizerCommon-asan-sparc-Linux :: Linux/unexpected_format_specifier_test.cpp
```
It turns out the interceptors aren't used since on Linux/sparc64 `double`
and `long double` are the same, and a couple of `stdio` functions are
prefixed with `__nldbl_` (no long double) accordingly.
This patch handles this.
Tested on `sparc64-unknown-linux-gnu`.
---
.../sanitizer_common_interceptors.inc | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index e09a4a8ae25fd8..bf5bb43018efc4 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -127,6 +127,39 @@ extern const short *_toupper_tab_;
extern const short *_tolower_tab_;
#endif
+#if SANITIZER_LINUX && SANITIZER_SPARC32
+// On 32-bit Linux/sparc64, double and long double are identical and glibc
+// uses a __nldbl_ (no long double) prefix for various stdio functions.
+# define __isoc23_fscanf __nldbl___isoc23_fscanf
+# define __isoc23_scanf __nldbl___isoc23_scanf
+# define __isoc23_sscanf __nldbl___isoc23_sscanf
+# define __isoc23_vfscanf __nldbl___isoc23_vfscanf
+# define __isoc23_vscanf __nldbl___isoc23_vscanf
+# define __isoc23_vsscanf __nldbl___isoc23_vsscanf
+# define __isoc99_fscanf __nldbl___isoc99_fscanf
+# define __isoc99_scanf __nldbl___isoc99_scanf
+# define __isoc99_sscanf __nldbl___isoc99_sscanf
+# define __isoc99_vfscanf __nldbl___isoc99_vfscanf
+# define __isoc99_vscanf __nldbl___isoc99_vscanf
+# define __isoc99_vsscanf __nldbl___isoc99_vsscanf
+# define asprintf __nldbl_asprintf
+# define fprintf __nldbl_fprintf
+# define fscanf __nldbl_fscanf
+# define printf __nldbl_printf
+# define scanf __nldbl_scanf
+# define snprintf __nldbl_snprintf
+# define sprintf __nldbl_sprintf
+# define sscanf __nldbl_sscanf
+# define vasprintf __nldbl_vasprintf
+# define vfprintf __nldbl_vfprintf
+# define vfscanf __nldbl_vfscanf
+# define vprintf __nldbl_vprintf
+# define vscanf __nldbl_vscanf
+# define vsnprintf __nldbl_vsnprintf
+# define vsprintf __nldbl_vsprintf
+# define vsscanf __nldbl_vsscanf
+#endif
+
#if SANITIZER_MUSL && \
(defined(__i386__) || defined(__arm__) || SANITIZER_MIPS32 || SANITIZER_PPC32)
// musl 1.2.0 on existing 32-bit architectures uses new symbol names for the
More information about the llvm-commits
mailing list