Skip to content

[libc] Clean up sanitizer macros #98402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions libc/src/__support/macros/sanitizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,11 @@

#include "src/__support/macros/config.h" //LIBC_HAS_FEATURE

//-----------------------------------------------------------------------------
// Properties to check the presence or absence or sanitizers
//-----------------------------------------------------------------------------

// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
// a compiler instrumentation module and a run-time library. The
// MEMORY_SANITIZER macro is deprecated but we will continue to honor it for
// now.
#ifdef LIBC_HAVE_MEMORY_SANITIZER
#error "LIBC_HAVE_MEMORY_SANITIZER cannot be directly set."
#elif defined(MEMORY_SANITIZER) || defined(__SANITIZE_MEMORY__) || \
(LIBC_HAS_FEATURE(memory_sanitizer) && !defined(__native_client__))
#define LIBC_HAVE_MEMORY_SANITIZER
#endif

// AddressSanitizer (ASan) is a fast memory error detector. The
// ADDRESS_SANITIZER macro is deprecated but we will continue to honor it for
// now.
#ifdef LIBC_HAVE_ADDRESS_SANITIZER
#error "LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set."
#elif defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__) || \
LIBC_HAS_FEATURE(address_sanitizer)
#define LIBC_HAVE_ADDRESS_SANITIZER
#endif

// HWAddressSanitizer (HWASan) is a fast, low memory overhead error detector.
#ifdef LIBC_HAVE_HWADDRESS_SANITIZER
#error "LIBC_HAVE_HWADDRESS_SANITIZER cannot be directly set."
#elif LIBC_HAS_FEATURE(hwaddress_sanitizer)
#define LIBC_HAVE_HWADDRESS_SANITIZER
#endif

//-----------------------------------------------------------------------------
// Functions to unpoison memory
//-----------------------------------------------------------------------------

#if defined(LIBC_HAVE_MEMORY_SANITIZER)
#if LIBC_HAS_FEATURE(memory_sanitizer)
// Only perform MSAN unpoison in non-constexpr context.
#include <sanitizer/msan_interface.h>
#define MSAN_UNPOISON(addr, size) \
Expand All @@ -59,7 +27,7 @@
#define MSAN_UNPOISON(ptr, size)
#endif

#ifdef LIBC_HAVE_ADDRESS_SANITIZER
#if LIBC_HAS_FEATURE(address_sanitizer)
#include <sanitizer/asan_interface.h>
#define ASAN_POISON_MEMORY_REGION(addr, size) \
__asan_poison_memory_region((addr), (size))
Expand Down
Loading