Skip to content

Commit

Permalink
Add a %darwin_min_target_with_tls_support lit substitution.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
delcypher committed Feb 19, 2020
1 parent d1d5180 commit 562c6b8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
39 changes: 26 additions & 13 deletions compiler-rt/test/lit.common.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@

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):
"""
Expand Down Expand Up @@ -326,25 +335,29 @@ def get_apple_platform_version_aligned_with(macos_version, apple_platform):
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()
Expand Down
5 changes: 3 additions & 2 deletions compiler-rt/test/tsan/dtls.c
Original file line number Diff line number Diff line change
@@ -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

Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/test/tsan/mutexset7.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/test/tsan/tls_race.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion compiler-rt/test/tsan/tls_race2.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit 562c6b8

Please sign in to comment.