Skip to content

Conversation

nathanchance
Copy link
Member

@nathanchance nathanchance commented Sep 2, 2025

GCC defines these macros for both userspace and kernel address sanitizers:

$ gcc -E -dM -fsanitize=address -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_ADDRESS__ 1
$ gcc -E -dM -fsanitize=kernel-address -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_ADDRESS__ 1
$ gcc -E -dM -fsanitize=hwaddress -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_HWADDRESS__ 1
$ gcc -E -dM -fsanitize=kernel-hwaddress -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_HWADDRESS__ 1

PR #153888 added these same defines for clang but only for the userspace address sanitizers:

$ clang -E -dM -fsanitize=address -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_ADDRESS__ 1
$ clang -E -dM -fsanitize=kernel-address -x c /dev/null &| string match -er SANITIZE
$ clang -E -dM -fsanitize=hwaddress -x c /dev/null &| string match -er SANITIZE
#define __SANITIZE_HWADDRESS__ 1
$ clang -E -dM -fsanitize=kernel-hwaddress -x c /dev/null &| string match -er SANITIZE

Match GCC's behavior so that the Linux kernel can eventually drop its own internal defines.

GCC defines these macros for both userspace and kernel address
sanitizers:

  $ gcc -E -dM -fsanitize=address -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_ADDRESS__ 1
  $ gcc -E -dM -fsanitize=kernel-address -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_ADDRESS__ 1
  $ gcc -E -dM -fsanitize=hwaddress -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_HWADDRESS__ 1
  $ gcc -E -dM -fsanitize=kernel-hwaddress -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_HWADDRESS__ 1

PR llvm#153888 added these same defines for clang but only for the userspace
address sanitizers:

  $ clang -E -dM -fsanitize=address -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_ADDRESS__ 1
  $ clang -E -dM -fsanitize=kernel-address -x c /dev/null &| string match -er SANITIZE
  $ clang -E -dM -fsanitize=hwaddress -x c /dev/null &| string match -er SANITIZE
  #define __SANITIZE_HWADDRESS__ 1
  $ clang -E -dM -fsanitize=kernel-hwaddress -x c /dev/null &| string match -er SANITIZE

Match GCC's behavior so that the Linux kernel can eventually drop its
own internal defines.
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants