[compiler-rt] r319575 - [ubsan] Re-commit: lit changes for lld testing, future lto testing.

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 1 11:36:29 PST 2017


Author: lebedevri
Date: Fri Dec  1 11:36:29 2017
New Revision: 319575

URL: http://llvm.org/viewvc/llvm-project?rev=319575&view=rev
Log:
[ubsan] Re-commit: lit changes for lld testing, future lto testing.

Summary:
As discussed in https://github.com/google/oss-fuzz/issues/933,
it would be really awesome to be able to use ThinLTO for fuzzing.
However, as @kcc has pointed out, it is currently undefined (untested)
whether the sanitizers actually function properly with LLD and/or LTO.

This patch is inspired by the cfi test, which already do test with LTO
(and/or LLD), since LTO is required for CFI to function.

I started with UBSan, because it's cmakelists / lit.* files appeared
to be the cleanest. This patch adds the infrastructure to easily add
LLD and/or LTO sub-variants of the existing lit test configurations.

Also, this patch adds the LLD flavor, that explicitly does use LLD to link.
The check-ubsan does pass on my machine. And to minimize the [initial]
potential buildbot breakage i have put some restrictions on this flavour.

Please review carefully, i have not worked with lit/sanitizer tests before.

The original attempt, r319525 was reverted in r319526 due
to the failures in compiler-rt standalone builds.

Reviewers: eugenis, vitalybuka

Reviewed By: eugenis

Subscribers: #sanitizers, pcc, kubamracek, mgorny, llvm-commits, mehdi_amini, inglorion, kcc

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

Modified:
    compiler-rt/trunk/test/asan/lit.cfg
    compiler-rt/trunk/test/cfi/lit.cfg
    compiler-rt/trunk/test/cfi/lit.site.cfg.in
    compiler-rt/trunk/test/lit.common.cfg
    compiler-rt/trunk/test/lit.common.configured.in
    compiler-rt/trunk/test/profile/Linux/lit.local.cfg
    compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
    compiler-rt/trunk/test/scudo/lit.cfg
    compiler-rt/trunk/test/tsan/lit.cfg
    compiler-rt/trunk/test/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/lit.common.cfg
    compiler-rt/trunk/test/ubsan/lit.site.cfg.in
    compiler-rt/trunk/test/ubsan_minimal/lit.common.cfg

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Fri Dec  1 11:36:29 2017
@@ -96,7 +96,7 @@ if platform.system() == 'Windows':
   config.available_features.add(win_runtime_feature)
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
 config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )

Modified: compiler-rt/trunk/test/cfi/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/lit.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/lit.cfg (original)
+++ compiler-rt/trunk/test/cfi/lit.cfg Fri Dec  1 11:36:29 2017
@@ -5,13 +5,16 @@ config.name = 'cfi' + config.name_suffix
 config.suffixes = ['.c', '.cpp', '.test']
 config.test_source_root = os.path.dirname(__file__)
 
-clang = ' '.join([config.compile_wrapper, config.clang, config.target_cflags])
-clangxx = ' '.join([config.compile_wrapper, config.clang, config.target_cflags] + config.cxx_mode_flags)
+def build_invocation(compile_flags):
+  return " " + " ".join([config.clang] + compile_flags) + " "
+
+clang = build_invocation([config.target_cflags])
+clangxx = build_invocation([config.target_cflags] + config.cxx_mode_flags)
 
 config.substitutions.append((r"%clang ", clang + ' '))
 config.substitutions.append((r"%clangxx ", clangxx + ' '))
 if config.lto_supported:
-  clang_cfi = ' '.join(config.lto_launch + [clang] + config.lto_flags + ['-fsanitize=cfi '])
+  clang_cfi = clang + '-fsanitize=cfi '
 
   if config.cfi_lit_test_mode == "Devirt":
     config.available_features.add('devirt')

Modified: compiler-rt/trunk/test/cfi/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/cfi/lit.site.cfg.in?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/cfi/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/cfi/lit.site.cfg.in Fri Dec  1 11:36:29 2017
@@ -5,6 +5,7 @@ config.cfi_lit_test_mode = "@CFI_LIT_TES
 config.target_arch = "@CFI_TEST_TARGET_ARCH@"
 config.target_cflags = "@CFI_TEST_TARGET_CFLAGS@"
 config.use_lld = @CFI_TEST_USE_LLD@
+config.use_lto = True # CFI *requires* LTO.
 config.use_thinlto = @CFI_TEST_USE_THINLTO@
 
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")

Modified: compiler-rt/trunk/test/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.cfg (original)
+++ compiler-rt/trunk/test/lit.common.cfg Fri Dec  1 11:36:29 2017
@@ -324,3 +324,22 @@ if config.asan_shadow_scale:
   config.available_features.add("shadow-scale-%s" % config.asan_shadow_scale)
 else:
   config.available_features.add("shadow-scale-3")
+
+# Propagate the LLD/LTO into the clang config option, so nothing else is needed.
+run_wrapper = []
+target_cflags = [getattr(config, 'target_cflags', None)]
+extra_cflags = []
+
+if config.use_lto and config.lto_supported:
+  run_wrapper += config.lto_launch
+  extra_cflags += config.lto_flags
+elif config.use_lto and (not config.lto_supported):
+  config.unsupported = True
+
+if config.use_lld and config.has_lld and not config.use_lto:
+  extra_cflags += ["-fuse-ld=lld"]
+elif config.use_lld and (not config.has_lld):
+  config.unsupported = True
+
+config.clang = " " + " ".join(run_wrapper + [config.compile_wrapper, config.clang]) + " "
+config.target_cflags = " " + " ".join(target_cflags + extra_cflags) + " "

Modified: compiler-rt/trunk/test/lit.common.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.configured.in?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.configured.in (original)
+++ compiler-rt/trunk/test/lit.common.configured.in Fri Dec  1 11:36:29 2017
@@ -33,6 +33,7 @@ set_default("has_lld", @COMPILER_RT_HAS_
 set_default("can_symbolize", @CAN_SYMBOLIZE@)
 set_default("use_lld", False)
 set_default("use_thinlto", False)
+set_default("use_lto", config.use_thinlto)
 set_default("android", @ANDROID_PYBOOL@)
 config.available_features.add('target-is-%s' % config.target_arch)
 

Modified: compiler-rt/trunk/test/profile/Linux/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/Linux/lit.local.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/profile/Linux/lit.local.cfg (original)
+++ compiler-rt/trunk/test/profile/Linux/lit.local.cfg Fri Dec  1 11:36:29 2017
@@ -20,7 +20,9 @@ def is_gold_linker_available():
   if not '-plugin' in ld_out:
     return False
 
-  clang_cmd = subprocess.Popen([config.clang, '-fuse-ld=gold', '-xc', '-'],
+  # config.clang is not guaranteed to be just the executable!
+  clang_cmd = subprocess.Popen(" ".join([config.clang, '-fuse-ld=gold', '-xc', '-']),
+                               shell=True,
                                universal_newlines = True,
                                stdin = subprocess.PIPE,
                                stdout = subprocess.PIPE,

Modified: compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/lit.common.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/lit.common.cfg (original)
+++ compiler-rt/trunk/test/sanitizer_common/lit.common.cfg Fri Dec  1 11:36:29 2017
@@ -48,7 +48,7 @@ clang_cflags = config.debug_info_flags +
 clang_cxxflags = config.cxx_mode_flags + clang_cflags
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
 config.substitutions.append( ("%clangxx ", build_invocation(clang_cxxflags)) )

Modified: compiler-rt/trunk/test/scudo/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/lit.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/lit.cfg (original)
+++ compiler-rt/trunk/test/scudo/lit.cfg Fri Dec  1 11:36:29 2017
@@ -36,7 +36,7 @@ if not config.android:
 cxx_flags = (c_flags + config.cxx_mode_flags + ["-std=c++11"])
 
 def build_invocation(compile_flags):                                            
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "                   
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 # Add clang substitutions.
 config.substitutions.append(("%clang ", build_invocation(c_flags)))

Modified: compiler-rt/trunk/test/tsan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/lit.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/tsan/lit.cfg (original)
+++ compiler-rt/trunk/test/tsan/lit.cfg Fri Dec  1 11:36:29 2017
@@ -66,7 +66,7 @@ if config.has_libcxx and config.host_os
                           "-Wl,-rpath=%s" % libcxx_libdir]
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 config.substitutions.append( ("%clang_tsan ", build_invocation(clang_tsan_cflags)) )
 config.substitutions.append( ("%clangxx_tsan ", build_invocation(clang_tsan_cxxflags)) )

Modified: compiler-rt/trunk/test/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/CMakeLists.txt?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/ubsan/CMakeLists.txt Fri Dec  1 11:36:29 2017
@@ -3,9 +3,20 @@ set(UBSAN_LIT_TESTS_DIR ${CMAKE_CURRENT_
 set(UBSAN_TESTSUITES)
 set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 
-macro(add_ubsan_testsuite test_mode sanitizer arch)
+macro(add_ubsan_testsuite test_mode sanitizer arch lld thinlto)
   set(UBSAN_LIT_TEST_MODE "${test_mode}")
-  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE}-${arch})
+  set(CONFIG_NAME ${UBSAN_LIT_TEST_MODE})
+  if (${lld})
+    set(CONFIG_NAME ${CONFIG_NAME}-lld)
+    list(APPEND UBSAN_TEST_DEPS lld)
+  endif()
+  if (${thinlto})
+    set(CONFIG_NAME ${CONFIG_NAME}-thinlto)
+    list(APPEND UBSAN_TEST_DEPS LTO)
+  endif()
+  set(UBSAN_TEST_USE_LLD ${lld})
+  set(UBSAN_TEST_USE_THINLTO ${thinlto})
+  set(CONFIG_NAME ${CONFIG_NAME}-${arch})
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
     ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
@@ -15,6 +26,14 @@ macro(add_ubsan_testsuite test_mode sani
   endif()
 endmacro()
 
+macro(add_ubsan_testsuites test_mode sanitizer arch)
+  add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} False False)
+
+  if(COMPILER_RT_HAS_LLD AND arch STREQUAL "x86_64" AND NOT (APPLE OR WIN32))
+    add_ubsan_testsuite(${test_mode} ${sanitizer} ${arch} True False)
+  endif()
+endmacro()
+
 set(UBSAN_TEST_ARCH ${UBSAN_SUPPORTED_ARCH})
 if(APPLE)
   darwin_filter_host_archs(UBSAN_SUPPORTED_ARCH UBSAN_TEST_ARCH)
@@ -23,20 +42,20 @@ endif()
 foreach(arch ${UBSAN_TEST_ARCH})
   set(UBSAN_TEST_TARGET_ARCH ${arch})
   get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
-  add_ubsan_testsuite("Standalone" ubsan ${arch})
+  add_ubsan_testsuites("Standalone" ubsan ${arch})
 
   if(COMPILER_RT_HAS_ASAN AND ";${ASAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
     # TODO(wwchrome): Re-enable ubsan for asan win 64-bit when ready.
     # Disable ubsan with AddressSanitizer tests for Windows 64-bit.
     if(NOT OS_NAME MATCHES "Windows" OR CMAKE_SIZEOF_VOID_P EQUAL 4)
-      add_ubsan_testsuite("AddressSanitizer" asan ${arch})
+      add_ubsan_testsuites("AddressSanitizer" asan ${arch})
     endif()
   endif()
   if(COMPILER_RT_HAS_MSAN AND ";${MSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
-    add_ubsan_testsuite("MemorySanitizer" msan ${arch})
+    add_ubsan_testsuites("MemorySanitizer" msan ${arch})
   endif()
   if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
-    add_ubsan_testsuite("ThreadSanitizer" tsan ${arch})
+    add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
   endif()
 endforeach()
 
@@ -45,7 +64,7 @@ if(APPLE)
     set(UBSAN_TEST_TARGET_ARCH ${arch})
     get_test_cc_for_arch(${arch} UBSAN_TEST_TARGET_CC UBSAN_TEST_TARGET_CFLAGS)
     set(UBSAN_TEST_TARGET_CFLAGS "${UBSAN_TEST_TARGET_CFLAGS} -lc++abi")
-    add_ubsan_testsuite("StandaloneStatic" ubsan ${arch})
+    add_ubsan_testsuites("StandaloneStatic" ubsan ${arch})
   endforeach()
 endif()
 

Modified: compiler-rt/trunk/test/ubsan/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.common.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan/lit.common.cfg Fri Dec  1 11:36:29 2017
@@ -11,6 +11,9 @@ def get_required_attr(config, attr_name)
       "to lit.site.cfg " % attr_name)
   return attr_value
 
+# Setup config name.
+config.name = 'UBSan-' + config.name_suffix
+
 # Setup source root.
 config.test_source_root = os.path.dirname(__file__)
 
@@ -18,24 +21,19 @@ default_ubsan_opts = list(config.default
 # Choose between standalone and UBSan+ASan modes.
 ubsan_lit_test_mode = get_required_attr(config, 'ubsan_lit_test_mode')
 if ubsan_lit_test_mode == "Standalone":
-  config.name = 'UBSan-Standalone-' + config.target_arch
   config.available_features.add("ubsan-standalone")
   clang_ubsan_cflags = []
 elif ubsan_lit_test_mode == "StandaloneStatic":
-  config.name = 'UBSan-StandaloneStatic-' + config.target_arch
   config.available_features.add("ubsan-standalone-static")
   clang_ubsan_cflags = ['-static-libsan']
 elif ubsan_lit_test_mode == "AddressSanitizer":
-  config.name = 'UBSan-ASan-' + config.target_arch
   config.available_features.add("ubsan-asan")
   clang_ubsan_cflags = ["-fsanitize=address"]
   default_ubsan_opts += ['detect_leaks=0']
 elif ubsan_lit_test_mode == "MemorySanitizer":
-  config.name = 'UBSan-MSan-' + config.target_arch
   config.available_features.add("ubsan-msan")
   clang_ubsan_cflags = ["-fsanitize=memory"]
 elif ubsan_lit_test_mode == "ThreadSanitizer":
-  config.name = 'UBSan-TSan-' + config.target_arch
   config.available_features.add("ubsan-tsan")
   clang_ubsan_cflags = ["-fsanitize=thread"]
 else:
@@ -55,7 +53,7 @@ config.substitutions.append(('%env_ubsan
                              'env UBSAN_OPTIONS=' + default_ubsan_opts_str))
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 target_cflags = [get_required_attr(config, "target_cflags")]
 clang_ubsan_cflags += target_cflags

Modified: compiler-rt/trunk/test/ubsan/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/lit.site.cfg.in?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/ubsan/lit.site.cfg.in Fri Dec  1 11:36:29 2017
@@ -1,9 +1,12 @@
 @LIT_SITE_CFG_IN_HEADER@
 
 # Tool-specific config options.
+config.name_suffix = "@CONFIG_NAME@"
 config.ubsan_lit_test_mode = "@UBSAN_LIT_TEST_MODE@"
 config.target_cflags = "@UBSAN_TEST_TARGET_CFLAGS@"
 config.target_arch = "@UBSAN_TEST_TARGET_ARCH@"
+config.use_lld = @UBSAN_TEST_USE_LLD@
+config.use_thinlto = @UBSAN_TEST_USE_THINLTO@
 
 # Load common config for all compiler-rt lit tests.
 lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")

Modified: compiler-rt/trunk/test/ubsan_minimal/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan_minimal/lit.common.cfg?rev=319575&r1=319574&r2=319575&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan_minimal/lit.common.cfg (original)
+++ compiler-rt/trunk/test/ubsan_minimal/lit.common.cfg Fri Dec  1 11:36:29 2017
@@ -16,7 +16,7 @@ config.test_source_root = os.path.dirnam
 config.name = 'UBSan-Minimal-' + config.target_arch
 
 def build_invocation(compile_flags):
-  return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "
+  return " " + " ".join([config.clang] + compile_flags) + " "
 
 target_cflags = [get_required_attr(config, "target_cflags")]
 clang_ubsan_cflags = ["-fsanitize-minimal-runtime"] + target_cflags




More information about the llvm-commits mailing list