From 562c6b80192243b141d1ddd15d1827c860992147 Mon Sep 17 00:00:00 2001 From: Dan Liew Date: Tue, 18 Feb 2020 15:43:25 -0800 Subject: [PATCH] Add a `%darwin_min_target_with_tls_support` lit substitution. Summary: This substitution expands to the appropriate minimum deployment target flag where thread local storage (TLS) was first introduced on Darwin platforms. For all other platforms the substitution expands to an empty string. E.g. for macOS the substitution expands to `-mmacosx-version-min=10.12` This patch adds support for the substitution (and future substitutions) by doing a minor refactor and then uses the substitution in the relevant TSan tests. rdar://problem/59568956 Reviewers: yln, kubamracek, dvyukov, vitalybuka Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D74802 --- compiler-rt/test/lit.common.cfg.py | 39 ++++++++++++++++++++++++------------- compiler-rt/test/tsan/dtls.c | 5 +++-- compiler-rt/test/tsan/mutexset7.cpp | 3 ++- compiler-rt/test/tsan/tls_race.cpp | 4 +++- compiler-rt/test/tsan/tls_race2.cpp | 4 +++- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 6c4a6f5..3b1ea53 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -257,6 +257,15 @@ if config.gwp_asan: lit.util.usePlatformSdkOnDarwin(config, lit_config) +# Maps a lit substitution name for the minimum target OS flag +# to the macOS version that first contained the relevant feature. +darwin_min_deployment_target_substitutions = { + '%macos_min_target_10_11': '10.11', + # rdar://problem/22207160 + '%darwin_min_target_with_full_runtime_arc_support': '10.11', + '%darwin_min_target_with_tls_support': '10.12', +} + if config.host_os == 'Darwin': def get_apple_platform_version_aligned_with(macos_version, apple_platform): """ @@ -326,25 +335,29 @@ if config.host_os == 'Darwin': except: pass - min_os_aligned_with_osx_10_11 = get_apple_platform_version_aligned_with('10.11', config.apple_platform) - min_os_aligned_with_osx_10_11_flag = '' - if min_os_aligned_with_osx_10_11: - min_os_aligned_with_osx_10_11_flag = '{flag}={version}'.format( - flag=config.apple_platform_min_deployment_target_flag, - version=min_os_aligned_with_osx_10_11) - else: - lit_config.warning('Could not find a version of {} that corresponds with macOS 10.11'.format(config.apple_platform)) - config.substitutions.append( ("%macos_min_target_10_11", min_os_aligned_with_osx_10_11_flag) ) - # rdar://problem/22207160 - config.substitutions.append( ("%darwin_min_target_with_full_runtime_arc_support", min_os_aligned_with_osx_10_11_flag) ) + def get_apple_min_deploy_target_flag_aligned_with_osx(version): + min_os_aligned_with_osx_v = get_apple_platform_version_aligned_with(version, config.apple_platform) + min_os_aligned_with_osx_v_flag = '' + if min_os_aligned_with_osx_v: + min_os_aligned_with_osx_v_flag = '{flag}={version}'.format( + flag=config.apple_platform_min_deployment_target_flag, + version=min_os_aligned_with_osx_v) + else: + lit_config.warning('Could not find a version of {} that corresponds with macOS {}'.format( + config.apple_platform, + version)) + return min_os_aligned_with_osx_v_flag + + for substitution, osx_version in darwin_min_deployment_target_substitutions.items(): + config.substitutions.append( (substitution, get_apple_min_deploy_target_flag_aligned_with_osx(osx_version)) ) # 32-bit iOS simulator is deprecated and removed in latest Xcode. if config.apple_platform == "iossim": if config.target_arch == "i386": config.unsupported = True else: - config.substitutions.append( ("%macos_min_target_10_11", "") ) - config.substitutions.append( ("%darwin_min_target_with_full_runtime_arc_support", "") ) + for substitution in darwin_min_deployment_target_substitutions.keys(): + config.substitutions.append( (substitution, "") ) if config.android: env = os.environ.copy() diff --git a/compiler-rt/test/tsan/dtls.c b/compiler-rt/test/tsan/dtls.c index b00ca76..57c9da8 100644 --- a/compiler-rt/test/tsan/dtls.c +++ b/compiler-rt/test/tsan/dtls.c @@ -1,5 +1,6 @@ -// RUN: %clang_tsan %s -o %t -// RUN: %clang_tsan %s -DBUILD_SO -fPIC -o %t-so.so -shared +// RUN: %clang_tsan %darwin_min_target_with_tls_support %s -o %t +// RUN: %clang_tsan %darwin_min_target_with_tls_support %s -DBUILD_SO -fPIC -o \ +// RUN: %t-so.so -shared // RUN: %run %t 2>&1 | FileCheck %s // XFAIL: netbsd diff --git a/compiler-rt/test/tsan/mutexset7.cpp b/compiler-rt/test/tsan/mutexset7.cpp index d3a221d..d372965 100644 --- a/compiler-rt/test/tsan/mutexset7.cpp +++ b/compiler-rt/test/tsan/mutexset7.cpp @@ -1,4 +1,5 @@ -// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s +// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \ +// RUN: %deflake %run %t | FileCheck %s #include "test.h" int Global; diff --git a/compiler-rt/test/tsan/tls_race.cpp b/compiler-rt/test/tsan/tls_race.cpp index dd37ff0..5f5b6aa 100644 --- a/compiler-rt/test/tsan/tls_race.cpp +++ b/compiler-rt/test/tsan/tls_race.cpp @@ -1,4 +1,6 @@ -// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \ +// RUN: %deflake %run %t | \ +// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK #include "test.h" void *Thread(void *a) { diff --git a/compiler-rt/test/tsan/tls_race2.cpp b/compiler-rt/test/tsan/tls_race2.cpp index 5968e66..0e00831 100644 --- a/compiler-rt/test/tsan/tls_race2.cpp +++ b/compiler-rt/test/tsan/tls_race2.cpp @@ -1,4 +1,6 @@ -// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK +// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \ +// RUN: %deflake %run %t | \ +// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK #include "test.h" void *Thread2(void *a) { -- 2.7.4