[compiler-rt] c17ac84 - [GWP-ASan] Migrate lit tests from old Scudo -> Standalone.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Fri May 14 10:42:05 PDT 2021


Author: Mitch Phillips
Date: 2021-05-14T10:41:48-07:00
New Revision: c17ac8432e62efcbbcaa5519739b403275c553ff

URL: https://github.com/llvm/llvm-project/commit/c17ac8432e62efcbbcaa5519739b403275c553ff
DIFF: https://github.com/llvm/llvm-project/commit/c17ac8432e62efcbbcaa5519739b403275c553ff.diff

LOG: [GWP-ASan] Migrate lit tests from old Scudo -> Standalone.

This removes one of the last dependencies on old Scudo, and should allow
us to delete the old Scudo soon.

Reviewed By: vitalybuka, cryptoad

Differential Revision: https://reviews.llvm.org/D102349

Added: 
    

Modified: 
    compiler-rt/lib/scudo/CMakeLists.txt
    compiler-rt/lib/scudo/standalone/CMakeLists.txt
    compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
    compiler-rt/test/gwp_asan/CMakeLists.txt
    compiler-rt/test/gwp_asan/backtrace.c
    compiler-rt/test/gwp_asan/lit.cfg.py
    compiler-rt/test/gwp_asan/repeated_alloc.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/CMakeLists.txt b/compiler-rt/lib/scudo/CMakeLists.txt
index c50ea0233faee..e580d6d1408bd 100644
--- a/compiler-rt/lib/scudo/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/CMakeLists.txt
@@ -34,12 +34,9 @@ set(SCUDO_MINIMAL_OBJECT_LIBS
   RTInterception)
 
 if (COMPILER_RT_HAS_GWP_ASAN)
-  # Currently, Scudo uses the GwpAsan flag parser. This backs onto the flag
-  # parsing mechanism of sanitizer_common. Once Scudo has its own flag parsing,
-  # and parses GwpAsan options, you can remove this dependency.
-  list(APPEND SCUDO_MINIMAL_OBJECT_LIBS RTGwpAsan RTGwpAsanOptionsParser
-                                        RTGwpAsanBacktraceLibc
-                                        RTGwpAsanSegvHandler)
+  list(APPEND SCUDO_MINIMAL_OBJECT_LIBS
+       RTGwpAsan RTGwpAsanOptionsParser RTGwpAsanBacktraceLibc
+       RTGwpAsanSegvHandler)
   list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
 endif()
 

diff  --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
index 1dbe8c76ff687..572ad078423f5 100644
--- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -1,7 +1,4 @@
 add_compiler_rt_component(scudo_standalone)
-if (COMPILER_RT_HAS_GWP_ASAN)
-  add_dependencies(scudo_standalone gwp_asan)
-endif()
 
 include_directories(../.. include)
 
@@ -25,13 +22,6 @@ append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS)
 # FIXME: find cleaner way to agree with GWPAsan flags
 append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS)
 
-if (COMPILER_RT_HAS_GWP_ASAN)
-  append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
-                SCUDO_CFLAGS)
-  append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG
-                -mno-omit-leaf-frame-pointer SCUDO_CFLAGS)
-endif() # COMPILER_RT_HAS_GWP_ASAN
-
 if(COMPILER_RT_DEBUG)
   list(APPEND SCUDO_CFLAGS -O0)
 else()
@@ -126,9 +116,13 @@ set(SCUDO_SOURCES_CXX_WRAPPERS
 set(SCUDO_OBJECT_LIBS)
 
 if (COMPILER_RT_HAS_GWP_ASAN)
+  add_dependencies(scudo_standalone gwp_asan)
   list(APPEND SCUDO_OBJECT_LIBS
-       RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler)
-  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
+       RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler
+       RTGwpAsanOptionsParser)
+
+  list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer
+                           -mno-omit-leaf-frame-pointer)
 endif()
 
 set(SCUDO_LINK_LIBS)
@@ -168,7 +162,6 @@ if(COMPILER_RT_HAS_SCUDO_STANDALONE)
     SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
     ADDITIONAL_HEADERS ${SCUDO_HEADERS}
     CFLAGS ${SCUDO_CFLAGS}
-    OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
     PARENT_TARGET scudo_standalone)
 
   add_compiler_rt_runtime(clang_rt.scudo_standalone

diff  --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
index 1545c00378fbf..b84290f75d799 100644
--- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
+++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
@@ -23,7 +23,8 @@ if(ANDROID)
 endif()
 
 if (COMPILER_RT_HAS_GWP_ASAN)
-  list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS)
+  list(APPEND SCUDO_UNITTEST_CFLAGS -DGWP_ASAN_HOOKS -fno-omit-frame-pointer
+       -mno-omit-leaf-frame-pointer)
 endif()
 
 set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})

diff  --git a/compiler-rt/test/gwp_asan/CMakeLists.txt b/compiler-rt/test/gwp_asan/CMakeLists.txt
index de53ad5b7eed4..86260027426fe 100644
--- a/compiler-rt/test/gwp_asan/CMakeLists.txt
+++ b/compiler-rt/test/gwp_asan/CMakeLists.txt
@@ -7,7 +7,7 @@ set(GWP_ASAN_UNITTEST_DEPS)
 set(GWP_ASAN_TEST_DEPS
   ${SANITIZER_COMMON_LIT_TEST_DEPS}
   gwp_asan
-  scudo)
+  scudo_standalone)
 
 # Longstanding issues in the Android test runner means that compiler-rt unit
 # tests don't work on Android due to libc++ link-time issues. Looks like the
@@ -19,27 +19,23 @@ if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_GWP_ASAN AND NOT ANDROID)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/unit/lit.site.cfg.py.in
     ${CMAKE_CURRENT_BINARY_DIR}/unit/lit.site.cfg.py)
-  list(APPEND GWP_ASAN_TEST_DEPS ${GWP_ASAN_TEST_DEPS})
   list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/unit)
 endif()
 
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
-  )
+if (COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_SCUDO_STANDALONE AND COMPILER_RT_HAS_GWP_ASAN)
+  foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
+    set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
+    string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
+    get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_TEST_TARGET_CFLAGS)
+    string(TOUPPER ${arch} ARCH_UPPER_CASE)
+    set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
 
-foreach(arch ${GWP_ASAN_SUPPORTED_ARCH})
-  set(GWP_ASAN_TEST_TARGET_ARCH ${arch})
-  string(TOLOWER "-${arch}" GWP_ASAN_TEST_CONFIG_SUFFIX)
-  get_test_cc_for_arch(${arch} GWP_ASAN_TEST_TARGET_CC GWP_ASAN_TEST_TARGET_CFLAGS)
-  string(TOUPPER ${arch} ARCH_UPPER_CASE)
-  set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config)
-
-  configure_lit_site_cfg(
-    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
-    ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
-  list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
-endforeach()
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+      ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py)
+    list(APPEND GWP_ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+  endforeach()
+endif()
 
 add_lit_testsuite(check-gwp_asan "Running the GWP-ASan tests"
   ${GWP_ASAN_TESTSUITES}

diff  --git a/compiler-rt/test/gwp_asan/backtrace.c b/compiler-rt/test/gwp_asan/backtrace.c
index 0ba32f85cbf97..9d9fc7db096be 100644
--- a/compiler-rt/test/gwp_asan/backtrace.c
+++ b/compiler-rt/test/gwp_asan/backtrace.c
@@ -1,7 +1,12 @@
 // REQUIRES: gwp_asan
-// RUN: %clang_gwp_asan %s -g -o %t
+// RUN: %clang_gwp_asan -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer %s -g -o %t
 // RUN: %expect_crash %t 2>&1 | FileCheck %s
 
+// Ensure we don't crash when using the unwinder when frame pointers are
+// disabled.
+// RUN: %clang_gwp_asan -fomit-frame-pointer -momit-leaf-frame-pointer %s -g -o %t
+// RUN: %expect_crash %t
+
 #include <stdlib.h>
 
 __attribute__((noinline)) void *allocate_mem() { return malloc(1); }

diff  --git a/compiler-rt/test/gwp_asan/lit.cfg.py b/compiler-rt/test/gwp_asan/lit.cfg.py
index a1b2551c2f9da..c806ae2d47271 100644
--- a/compiler-rt/test/gwp_asan/lit.cfg.py
+++ b/compiler-rt/test/gwp_asan/lit.cfg.py
@@ -14,31 +14,42 @@
 # C & CXX flags.
 c_flags = ([config.target_cflags])
 
-# Android doesn't want -lrt.
-if not config.android:
-  c_flags += ["-lrt"]
+cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++14"])
 
-cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
+libscudo_standalone = os.path.join(
+    config.compiler_rt_libdir,
+    "libclang_rt.scudo_standalone%s.a" % config.target_suffix)
+libscudo_standalone_cxx = os.path.join(
+    config.compiler_rt_libdir,
+    "libclang_rt.scudo_standalone_cxx%s.a" % config.target_suffix)
 
-gwp_asan_flags = ["-fsanitize=scudo", "-g", "-fno-omit-frame-pointer",
-                  "-mno-omit-leaf-frame-pointer"]
+scudo_link_flags = ["-pthread", "-Wl,--whole-archive", libscudo_standalone,
+                    "-Wl,--no-whole-archive"]
+scudo_link_cxx_flags = ["-Wl,--whole-archive", libscudo_standalone_cxx,
+                        "-Wl,--no-whole-archive"]
+
+# -rdynamic is necessary for online function symbolization.
+gwp_asan_flags = ["-rdynamic"] + scudo_link_flags
 
 def build_invocation(compile_flags):
   return " " + " ".join([config.clang] + compile_flags) + " "
 
 # Add substitutions.
 config.substitutions.append(("%clang ", build_invocation(c_flags)))
-config.substitutions.append(("%clang_gwp_asan ", build_invocation(c_flags + gwp_asan_flags)))
-config.substitutions.append(("%clangxx_gwp_asan ", build_invocation(cxx_flags + gwp_asan_flags)))
+config.substitutions.append(
+    ("%clang_gwp_asan ", build_invocation(c_flags + gwp_asan_flags)))
+config.substitutions.append((
+    "%clangxx_gwp_asan ",
+    build_invocation(cxx_flags + gwp_asan_flags + scudo_link_cxx_flags)))
 
 # Platform-specific default GWP_ASAN for lit tests. Ensure that GWP-ASan is
 # enabled and that it samples every allocation.
-default_gwp_asan_options = 'Enabled=1:SampleRate=1'
+default_gwp_asan_options = 'GWP_ASAN_Enabled=1:GWP_ASAN_SampleRate=1'
 
-config.environment['GWP_ASAN_OPTIONS'] = default_gwp_asan_options
+config.environment['SCUDO_OPTIONS'] = default_gwp_asan_options
 default_gwp_asan_options += ':'
-config.substitutions.append(('%env_gwp_asan_options=',
-                             'env GWP_ASAN_OPTIONS=' + default_gwp_asan_options))
+config.substitutions.append(('%env_scudo_options=',
+                             'env SCUDO_OPTIONS=' + default_gwp_asan_options))
 
 # GWP-ASan tests are currently supported on Linux only.
 if config.host_os not in ['Linux']:

diff  --git a/compiler-rt/test/gwp_asan/repeated_alloc.cpp b/compiler-rt/test/gwp_asan/repeated_alloc.cpp
index 2afad1bf3ab98..41d294c87f610 100644
--- a/compiler-rt/test/gwp_asan/repeated_alloc.cpp
+++ b/compiler-rt/test/gwp_asan/repeated_alloc.cpp
@@ -3,11 +3,11 @@
 // as expected and we didn't accidentally break the supporting allocator.
 
 // RUN: %clangxx_gwp_asan %s -o %t
-// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=1 %run %t
-// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=2 %run %t
-// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=11 %run %t
-// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=12 %run %t
-// RUN: %env_gwp_asan_options=MaxSimultaneousAllocations=13 %run %t
+// RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=1 %run %t
+// RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=2 %run %t
+// RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=11 %run %t
+// RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=12 %run %t
+// RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=13 %run %t
 
 #include <cstdlib>
 


        


More information about the llvm-commits mailing list