Skip to content

Commit 36529a2

Browse files
committed
Revert "[ASan] Removed ASAN_SHADOW_SCALE."
This reverts commit e4800fc. Reviewed By: kstoimenov Differential Revision: https://reviews.llvm.org/D115286
1 parent e4800fc commit 36529a2

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ mark_as_advanced(COMPILER_RT_BUILD_ORC)
5252
option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
5353
mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
5454

55+
set(COMPILER_RT_ASAN_SHADOW_SCALE ""
56+
CACHE STRING "Override the shadow scale to be used in ASan runtime")
57+
58+
if (NOT COMPILER_RT_ASAN_SHADOW_SCALE STREQUAL "")
59+
# Check that the shadow scale value is valid.
60+
if (NOT (COMPILER_RT_ASAN_SHADOW_SCALE GREATER -1 AND
61+
COMPILER_RT_ASAN_SHADOW_SCALE LESS 8))
62+
message(FATAL_ERROR "
63+
Invalid ASan Shadow Scale '${COMPILER_RT_ASAN_SHADOW_SCALE}'.")
64+
endif()
65+
66+
set(COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG
67+
-mllvm -asan-mapping-scale=${COMPILER_RT_ASAN_SHADOW_SCALE})
68+
set(COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION
69+
ASAN_SHADOW_SCALE=${COMPILER_RT_ASAN_SHADOW_SCALE})
70+
set(COMPILER_RT_ASAN_SHADOW_SCALE_FLAG
71+
-D${COMPILER_RT_ASAN_SHADOW_SCALE_DEFINITION})
72+
endif()
73+
5574
if(FUCHSIA)
5675
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
5776
else()

compiler-rt/lib/asan/asan_mapping.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,15 @@
151151
// || `[0x30000000, 0x35ffffff]` || LowShadow ||
152152
// || `[0x00000000, 0x2fffffff]` || LowMem ||
153153

154-
#define SHADOW_SCALE 3
155-
154+
#if defined(ASAN_SHADOW_SCALE)
155+
static const u64 kDefaultShadowScale = ASAN_SHADOW_SCALE;
156+
#else
157+
static const u64 kDefaultShadowScale = 3;
158+
#endif
156159
static const u64 kDefaultShadowSentinel = ~(uptr)0;
157160

161+
#define SHADOW_SCALE kDefaultShadowScale
162+
158163
#if SANITIZER_FUCHSIA
159164
# define SHADOW_OFFSET_CONST (0)
160165
#elif SANITIZER_WORDSIZE == 32

compiler-rt/lib/asan/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(ASAN_UNITTEST_HEADERS
2323
set(ASAN_UNITTEST_COMMON_CFLAGS
2424
${COMPILER_RT_UNITTEST_CFLAGS}
2525
${COMPILER_RT_GTEST_CFLAGS}
26+
${COMPILER_RT_ASAN_SHADOW_SCALE_LLVM_FLAG}
2627
-I${COMPILER_RT_SOURCE_DIR}/include
2728
-I${COMPILER_RT_SOURCE_DIR}/lib
2829
-I${COMPILER_RT_SOURCE_DIR}/lib/asan
@@ -51,6 +52,7 @@ list(APPEND ASAN_UNITTEST_COMMON_LINK_FLAGS -g)
5152

5253
# Use -D instead of definitions to please custom compile command.
5354
list(APPEND ASAN_UNITTEST_COMMON_CFLAGS
55+
${COMPILER_RT_ASAN_SHADOW_SCALE_FLAG}
5456
-DASAN_HAS_IGNORELIST=1
5557
-DASAN_HAS_EXCEPTIONS=1
5658
-DASAN_UAR=0

compiler-rt/lib/asan/tests/asan_interface_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ TEST(AddressSanitizerInterface, DeathCallbackTest) {
160160
#define BAD_ACCESS(ptr, offset) \
161161
EXPECT_TRUE(__asan_address_is_poisoned(ptr + offset))
162162

163+
#if !defined(ASAN_SHADOW_SCALE) || ASAN_SHADOW_SCALE == 3
163164
static const char* kUseAfterPoisonErrorMessage = "use-after-poison";
164165

165166
TEST(AddressSanitizerInterface, SimplePoisonMemoryRegionTest) {
@@ -199,6 +200,7 @@ TEST(AddressSanitizerInterface, OverlappingPoisonMemoryRegionTest) {
199200
BAD_ACCESS(array, 96);
200201
free(array);
201202
}
203+
#endif // !defined(ASAN_SHADOW_SCALE) || ASAN_SHADOW_SCALE == 3
202204

203205
TEST(AddressSanitizerInterface, PushAndPopWithPoisoningTest) {
204206
// Vector of capacity 20

0 commit comments

Comments
 (0)