mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 06:56:44 +00:00

Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are replaced with the more appropriate `#if SANITIZER_GLIBC` (the headers are glibc extensions, not specific to Linux (i.e. if we ever support GNU/kFreeBSD or Hurd, the guards may automatically work)). Several `#if SANITIZER_LINUX && !SANITIZER_ANDROID` guards are refined with `#if SANITIZER_GLIBC` (the definitions are available on Linux glibc, but may not be available on other libc (e.g. musl) implementations). This patch makes `ninja asan cfi msan stats tsan ubsan xray` build on a musl based Linux distribution (apk install musl-libintl) Notes about disabled interceptors for musl: * `SANITIZER_INTERCEPT_GLOB`: musl does not implement `GLOB_ALTDIRFUNC` (GNU extension) * Some ioctl structs and functions operating on them. * `SANITIZER_INTERCEPT___PRINTF_CHK`: `_FORTIFY_SOURCE` functions are GNU extension * `SANITIZER_INTERCEPT___STRNDUP`: `dlsym(RTLD_NEXT, "__strndup")` errors so a diagnostic is formed. The diagnostic uses `write` which hasn't been intercepted => SIGSEGV * `SANITIZER_INTERCEPT_*64`: the `_LARGEFILE64_SOURCE` functions are glibc specific. musl does something like `#define pread64 pread` * Disabled `msg_iovlen msg_controllen cmsg_len` checks: musl is conforming while many implementations (Linux/FreeBSD/NetBSD/Solaris) are non-conforming. Since we pick the glibc definition, exclude the checks for musl (incompatible sizes but compatible offsets) Pass through LIBCXX_HAS_MUSL_LIBC to make check-msan/check-tsan able to build libc++ (https://bugs.llvm.org/show_bug.cgi?id=48618). Many sanitizer features are available now. ``` % ninja check-asan (known issues: * ASAN_OPTIONS=fast_unwind_on_malloc=0 odr-violations hangs ) ... Testing Time: 53.69s Unsupported : 185 Passed : 512 Expectedly Failed: 1 Failed : 12 % ninja check-ubsan check-ubsan-minimal check-memprof # all passed % ninja check-cfi ( all cross-dso/) ... Testing Time: 8.68s Unsupported : 264 Passed : 80 Expectedly Failed: 8 Failed : 32 % ninja check-lsan (With GetTls (D93972), 10 failures) Testing Time: 4.09s Unsupported: 7 Passed : 65 Failed : 22 % ninja check-msan (Many are due to functions not marked unsupported.) Testing Time: 23.09s Unsupported : 6 Passed : 764 Expectedly Failed: 2 Failed : 58 % ninja check-tsan Testing Time: 23.21s Unsupported : 86 Passed : 295 Expectedly Failed: 1 Failed : 25 ``` Used `ASAN_OPTIONS=verbosity=2` to verify there is no unneeded interceptor. Partly based on Jari Ronkainen's https://reviews.llvm.org/D63785#1921014 Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D93848
54 lines
2.2 KiB
C++
54 lines
2.2 KiB
C++
//===-- interception_linux.h ------------------------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
//
|
|
// Linux-specific interception methods.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
|
SANITIZER_SOLARIS
|
|
|
|
#if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
|
|
# error "interception_linux.h should be included from interception library only"
|
|
#endif
|
|
|
|
#ifndef INTERCEPTION_LINUX_H
|
|
#define INTERCEPTION_LINUX_H
|
|
|
|
namespace __interception {
|
|
bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
|
|
uptr wrapper);
|
|
bool InterceptFunction(const char *name, const char *ver, uptr *ptr_to_real,
|
|
uptr func, uptr wrapper);
|
|
} // namespace __interception
|
|
|
|
#define INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func) \
|
|
::__interception::InterceptFunction( \
|
|
#func, \
|
|
(::__interception::uptr *) & REAL(func), \
|
|
(::__interception::uptr) & (func), \
|
|
(::__interception::uptr) & WRAP(func))
|
|
|
|
// dlvsym is a GNU extension supported by some other platforms.
|
|
#if SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
|
|
#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
|
|
::__interception::InterceptFunction( \
|
|
#func, symver, \
|
|
(::__interception::uptr *) & REAL(func), \
|
|
(::__interception::uptr) & (func), \
|
|
(::__interception::uptr) & WRAP(func))
|
|
#else
|
|
#define INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver) \
|
|
INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
|
|
#endif // SANITIZER_GLIBC || SANITIZER_FREEBSD || SANITIZER_NETBSD
|
|
|
|
#endif // INTERCEPTION_LINUX_H
|
|
#endif // SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD ||
|
|
// SANITIZER_SOLARIS
|