]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129838: Don't redefine _Py_NO_SANITIZE_UNDEFINED (#129839)
authorCollin Funk <collin.funk1@gmail.com>
Thu, 20 Feb 2025 16:02:33 +0000 (08:02 -0800)
committerGitHub <noreply@github.com>
Thu, 20 Feb 2025 16:02:33 +0000 (17:02 +0100)
Newer GCC versions accept both __attribute__((no_sanitize("undefined")))
and __attribute__((no_sanitize_undefined)) so check that the macro is
not already defined.

Misc/NEWS.d/next/Build/2025-02-07-21-20-21.gh-issue-129838.fkuiEc.rst [new file with mode: 0644]
Modules/faulthandler.c

diff --git a/Misc/NEWS.d/next/Build/2025-02-07-21-20-21.gh-issue-129838.fkuiEc.rst b/Misc/NEWS.d/next/Build/2025-02-07-21-20-21.gh-issue-129838.fkuiEc.rst
new file mode 100644 (file)
index 0000000..9584602
--- /dev/null
@@ -0,0 +1,2 @@
+Don't redefine ``_Py_NO_SANITIZE_UNDEFINED`` when compiling with a recent
+GCC version and undefined sanitizer enabled.
index a15ced22677ab7a98e7ec9d52f6b4830ac21c659..4bfb63e66d2b62ec7c13a9367407611c22da0b4c 100644 (file)
 #define PUTS(fd, str) (void)_Py_write_noraise(fd, str, strlen(str))
 
 
-// clang uses __attribute__((no_sanitize("undefined")))
-// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
-#if defined(__has_feature)  // Clang
+// Clang and GCC 9.0+ use __attribute__((no_sanitize("undefined")))
+#if defined(__has_feature)
 #  if __has_feature(undefined_behavior_sanitizer)
 #    define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
 #  endif
 #endif
-#if defined(__GNUC__) \
+
+// GCC 4.9+ uses __attribute__((no_sanitize_undefined))
+#if !defined(_Py_NO_SANITIZE_UNDEFINED) && defined(__GNUC__) \
     && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9))
 #  define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
 #endif