[llvm] [ASan][ADT] Don't scribble with ASan (PR #79066)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 10:02:44 PST 2024
https://github.com/AdvenamTacet updated https://github.com/llvm/llvm-project/pull/79066
>From 21c85d98bb0f4eec47dc219a3dcf25e1d34be705 Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Mon, 22 Jan 2024 23:01:21 +0100
Subject: [PATCH 1/5] [ASan][ADT] Don't scribble with ASan
AddressSanitizer (ASAN) disables scribbling to prevent overwriting poisoned objects.
Needed by https://github.com/llvm/llvm-project/pull/79049
---
llvm/include/llvm/ADT/FunctionExtras.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 4cf1de488c7bde2..c58d0263b2efa07 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -317,8 +317,10 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// Clear the old callback and inline flag to get back to as-if-null.
RHS.CallbackAndInlineFlag = {};
-#ifndef NDEBUG
- // In debug builds, we also scribble across the rest of the storage.
+#if !defined(NDEBUG) && !(defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__))
+ // In debug builds without ASan, we also scribble across the rest of the storage.
+ // AddressSanitizer (ASAN) disables scribbling to prevent overwriting poisoned objects
+ // (e.g., annotated short strings).
memset(RHS.getInlineStorage(), 0xAD, InlineStorageSize);
#endif
}
>From 97c4c5909e553657e1fa2eea28e186ea75006f5d Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Mon, 22 Jan 2024 23:23:44 +0100
Subject: [PATCH 2/5] clang-format-fix
---
llvm/include/llvm/ADT/FunctionExtras.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index c58d0263b2efa07..bbba79f204e6020 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -317,10 +317,11 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// Clear the old callback and inline flag to get back to as-if-null.
RHS.CallbackAndInlineFlag = {};
-#if !defined(NDEBUG) && !(defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__))
- // In debug builds without ASan, we also scribble across the rest of the storage.
- // AddressSanitizer (ASAN) disables scribbling to prevent overwriting poisoned objects
- // (e.g., annotated short strings).
+#if !defined(NDEBUG) && \
+ !(defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__))
+ // In debug builds without ASan, we also scribble across the rest of the
+ // storage. AddressSanitizer (ASAN) disables scribbling to prevent
+ // overwriting poisoned objects (e.g., annotated short strings).
memset(RHS.getInlineStorage(), 0xAD, InlineStorageSize);
#endif
}
>From 4d19c7ea354a4c9d1ae9f2b37f9126e974d4947e Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Mon, 22 Jan 2024 23:39:47 +0100
Subject: [PATCH 3/5] Use LLVM_ADDRESS_SANITIZER_BUILD
---
llvm/include/llvm/ADT/FunctionExtras.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index bbba79f204e6020..fe07acf886722b7 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -317,8 +317,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// Clear the old callback and inline flag to get back to as-if-null.
RHS.CallbackAndInlineFlag = {};
-#if !defined(NDEBUG) && \
- !(defined(ADDRESS_SANITIZER) || defined(__SANITIZE_ADDRESS__))
+#if !defined(NDEBUG) && !defined(LLVM_ADDRESS_SANITIZER_BUILD)
// In debug builds without ASan, we also scribble across the rest of the
// storage. AddressSanitizer (ASAN) disables scribbling to prevent
// overwriting poisoned objects (e.g., annotated short strings).
>From 9072fbac7a7629add30697098e625110914cfcfd Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Tue, 23 Jan 2024 06:30:52 +0100
Subject: [PATCH 4/5] Fix based on code review
This commit:
- adds #include "llvm/Support/Compiler.h"
- fixes incorrect use of LLVM_ADDRESS_SANITIZER_BUILD
---
llvm/include/llvm/ADT/FunctionExtras.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index fe07acf886722b7..808f0cdba528698 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -35,6 +35,7 @@
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/STLForwardCompat.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemAlloc.h"
#include "llvm/Support/type_traits.h"
#include <cstring>
@@ -317,7 +318,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
// Clear the old callback and inline flag to get back to as-if-null.
RHS.CallbackAndInlineFlag = {};
-#if !defined(NDEBUG) && !defined(LLVM_ADDRESS_SANITIZER_BUILD)
+#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD
// In debug builds without ASan, we also scribble across the rest of the
// storage. AddressSanitizer (ASAN) disables scribbling to prevent
// overwriting poisoned objects (e.g., annotated short strings).
>From 9651e4bfd587f2312163c8458acbbdca96fb0d9d Mon Sep 17 00:00:00 2001
From: Advenam Tacet <advenam.tacet at trailofbits.com>
Date: Tue, 23 Jan 2024 18:59:27 +0100
Subject: [PATCH 5/5] Update comment text.
---
llvm/include/llvm/ADT/FunctionExtras.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 808f0cdba528698..c0bc30c7450fe4b 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -320,7 +320,7 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
#if !defined(NDEBUG) && !LLVM_ADDRESS_SANITIZER_BUILD
// In debug builds without ASan, we also scribble across the rest of the
- // storage. AddressSanitizer (ASAN) disables scribbling to prevent
+ // storage. Scribbling under AddressSanitizer (ASan) is disabled to prevent
// overwriting poisoned objects (e.g., annotated short strings).
memset(RHS.getInlineStorage(), 0xAD, InlineStorageSize);
#endif
More information about the llvm-commits
mailing list