Skip to content

Commit

Permalink
[sanitizer_common] Heed __ndbl_ prefix for 32-bit Linux/sparc64 inter… (
Browse files Browse the repository at this point in the history
llvm#109106)

…ceptors

When ASan testing is enabled on SPARC as per PR llvm#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`.
  • Loading branch information
rorth authored and xgupta committed Oct 4, 2024
1 parent e2e2943 commit f14d43c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f14d43c

Please sign in to comment.