Skip to content

Commit

Permalink
Make SK_NO_SANITIZE more compatible with GCC
Browse files Browse the repository at this point in the history
Folks using old versions of GCC noted SK_NO_SANITIZE didn't work
on old GCC versions. This was also noted in http://review.skia.org/668216
but the fix there is a bit clunky. Looking all uses of that macro,
we can just add guards to it depending on what attributes
are available.

For reference [1] is for a newer version that supports no_sanitize()
like clang does.

[1] https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gcc/Common-Function-Attributes.html

Change-Id: I860b7dd38426b8b169c04b86e1be2554f7b19289
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/924397
Commit-Queue: Kaylee Lubick <kjlubick@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
  • Loading branch information
kjlubick authored and SkCQ committed Nov 27, 2024
1 parent 8bece5d commit b8005bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
23 changes: 10 additions & 13 deletions include/private/base/SkAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,19 @@
* Used to ignore sanitizer warnings.
*/
#if !defined(SK_NO_SANITIZE)
# define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A))
#endif

/**
* Helper macro to define no_sanitize attributes only with clang.
*/
#if defined(__clang__) && defined(__has_attribute)
#if __has_attribute(no_sanitize)
#define SK_CLANG_NO_SANITIZE(A) SK_NO_SANITIZE(A)
#if defined(__has_attribute)
#if __has_attribute(no_sanitize)
// This should be for clang and versions of gcc >= 8.0
#define SK_NO_SANITIZE(A) SK_ATTRIBUTE(no_sanitize(A))
#else
// For compilers that don't support sanitization, just do nothing.
#define SK_NO_SANITIZE(A)
#endif
#else // no __has_attribute, e.g. MSVC
#define SK_NO_SANITIZE(A)
#endif
#endif

#if !defined(SK_CLANG_NO_SANITIZE)
#define SK_CLANG_NO_SANITIZE(A)
#endif

/**
* Annotates a class' non-trivial special functions as trivial for the purposes of calls.
* Allows a class with a non-trivial destructor to be __is_trivially_relocatable.
Expand Down
2 changes: 1 addition & 1 deletion include/private/base/SkTArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ template <typename T, bool MEM_MOVE = sk_is_trivially_relocatable_v<T>> class TA
// unpredictable location in memory. Of course, TArray won't actually use fItemArray in this
// way, and we don't want to construct a T before the user requests one. There's no real risk
// here, so disable CFI when doing these casts.
SK_CLANG_NO_SANITIZE("cfi")
SK_NO_SANITIZE("cfi")
static T* TCast(void* buffer) {
return (T*)buffer;
}
Expand Down

0 comments on commit b8005bb

Please sign in to comment.