Changeset 267130 in webkit


Ignore:
Timestamp:
Sep 15, 2020 7:53:36 PM (4 years ago)
Author:
ddkilzer@apple.com
Message:

WebKit should support building with clang ThreadSanitizer enabled
<https://webkit.org/b/216318>
<rdar://problem/31615729>

Reviewed by Darin Adler.

This patch doesn't attempt to resolve every potential false
positive, but makes it easy to build WebKit with TSan enabled.

.:

  • Makefile.shared:
  • Update to work with make [args] TSAN=YES.

Source/WTF:

  • WTF.xcodeproj/project.pbxproj:
  • wtf/CMakeLists.txt:
  • Add ThreadSanitizerSupport.h to the project.
  • wtf/Compiler.h:
  • Define TSAN_ENABLED and SUPPRESS_TSAN macros.
  • wtf/Locker.h:

(WTF::Locker::~Locker):
(WTF::Locker::unlockEarly):
(WTF::Locker::operator=):
(WTF::Locker::lock):

  • Instrument lock/unlock methods for ThreadSanitizer.
  • wtf/ThreadSanitizerSupport.h: Add.

(AnnotateHappensBefore):
(AnnotateHappensAfter):

  • Declare TSan runtime functions needed to annotate WTF::Locker.

(TSAN_ANNOTATE_HAPPENS_BEFORE):
(TSAN_ANNOTATE_HAPPENS_AFTER):

  • Define macros used to call TSan runtime functions if TSan is enabled.

Tools:

  • Scripts/set-webkit-configuration:
  • Add support for --[no-]tsan switches.
  • Scripts/webkitdirs.pm:

(determineTSanIsEnabled):
(tsanIsEnabled):
(XcodeOptions):
(generateBuildSystemFromCMakeProject):

  • Add support for building with TSan enabled.
  • asan/asan.xcconfig: Rename to sanitizer/asan.xcconfig.
  • sanitizer/asan.xcconfig: Rename from asan/asan.xcconfig.
  • Extract common variables to sanitizer.xcconfig.
  • sanitizer/sanitizer.xcconfig: Add.
  • Extract common variables from asan.xcconfig.
  • sanitizer/tsan.xcconfig: Add.
  • Add support for TSan.
Location:
trunk
Files:
5 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r267075 r267130  
     12020-09-15  David Kilzer  <ddkilzer@apple.com>
     2
     3        WebKit should support building with clang ThreadSanitizer enabled
     4        <https://webkit.org/b/216318>
     5        <rdar://problem/31615729>
     6
     7        Reviewed by Darin Adler.
     8
     9        This patch doesn't attempt to resolve every potential false
     10        positive, but makes it easy to build WebKit with TSan enabled.
     11
     12        * Makefile.shared:
     13        - Update to work with `make [args] TSAN=YES`.
     14
    1152020-09-14  Fujii Hironori  <Hironori.Fujii@sony.com>
    216
  • trunk/Makefile.shared

    r265602 r267130  
    7171endif
    7272
     73ifeq ($(TSAN),YES)
     74TSAN_OPTION=--tsan
     75else
     76ifeq ($(TSAN),NO)
     77TSAN_OPTION=--no-tsan
     78endif
     79endif
     80
    7381ifeq ($(WK_LTO_MODE),full)
    7482WK_LTO_OPTION=--lto-mode=full
     
    8593export PATH = $(shell getconf PATH)
    8694
    87 all: set_asan_configuration
     95all: set_sanitizer_configuration
    8896        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)' | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
    8997
    9098debug d development dev develop: force
    91         $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(WK_LTO_OPTION)
     99        $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)
    92100        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)' | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
    93101
    94102release r deployment dep deploy: force
    95         $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION) $(WK_LTO_OPTION)
     103        $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)
    96104        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)' | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
    97105
    98106release+assert ra: force
    99         $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION) $(WK_LTO_OPTION)
     107        $(SCRIPTS_PATH)/set-webkit-configuration --release $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)
    100108        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) ASSERT_ENABLED=1 $$(inherited)' | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
    101109
    102110testing t: force
    103         $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(WK_LTO_OPTION) --force-optimization-level=O3
     111        $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION) --force-optimization-level=O3
    104112        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)' | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
    105113
    106114analyze:
    107         $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(WK_LTO_OPTION)
     115        $(SCRIPTS_PATH)/set-webkit-configuration --debug $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)
    108116ifndef PATH_TO_SCAN_BUILD
    109117        ( $(SET_COLOR_DIAGNOSTICS_ARG); xcodebuild $(OTHER_OPTIONS) $(XCODE_OPTIONS) GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)' RUN_CLANG_STATIC_ANALYZER=YES | $(OUTPUT_FILTER) && exit $${PIPESTATUS[0]} )
     
    112120endif
    113121
    114 set_asan_configuration:
     122set_sanitizer_configuration:
    115123ifneq (,$(ASAN_OPTION))
    116124        $(SCRIPTS_PATH)/set-webkit-configuration $(ASAN_OPTION)
     125endif
     126ifneq (,$(TSAN_OPTION))
     127        $(SCRIPTS_PATH)/set-webkit-configuration $(TSAN_OPTION)
    117128endif
    118129
  • trunk/Source/WTF/ChangeLog

    r267116 r267130  
     12020-09-15  David Kilzer  <ddkilzer@apple.com>
     2
     3        WebKit should support building with clang ThreadSanitizer enabled
     4        <https://webkit.org/b/216318>
     5        <rdar://problem/31615729>
     6
     7        Reviewed by Darin Adler.
     8
     9        This patch doesn't attempt to resolve every potential false
     10        positive, but makes it easy to build WebKit with TSan enabled.
     11
     12        * WTF.xcodeproj/project.pbxproj:
     13        * wtf/CMakeLists.txt:
     14        - Add ThreadSanitizerSupport.h to the project.
     15
     16        * wtf/Compiler.h:
     17        - Define TSAN_ENABLED and SUPPRESS_TSAN macros.
     18
     19        * wtf/Locker.h:
     20        (WTF::Locker::~Locker):
     21        (WTF::Locker::unlockEarly):
     22        (WTF::Locker::operator=):
     23        (WTF::Locker::lock):
     24        - Instrument lock/unlock methods for ThreadSanitizer.
     25
     26        * wtf/ThreadSanitizerSupport.h: Add.
     27        (AnnotateHappensBefore):
     28        (AnnotateHappensAfter):
     29        - Declare TSan runtime functions needed to annotate WTF::Locker.
     30        (TSAN_ANNOTATE_HAPPENS_BEFORE):
     31        (TSAN_ANNOTATE_HAPPENS_AFTER):
     32        - Define macros used to call TSan runtime functions if TSan is
     33          enabled.
     34
    1352020-09-15  Myles C. Maxfield  <mmaxfield@apple.com>
    236
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r266573 r267130  
    374374                430B47871AAAAC1A001223DA /* StringCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringCommon.h; sourceTree = "<group>"; };
    375375                4427C5A921F6D6C300A612A4 /* ASCIICType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ASCIICType.cpp; sourceTree = "<group>"; };
     376                4468567225094FE8008CCA05 /* ThreadSanitizerSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadSanitizerSupport.h; sourceTree = "<group>"; };
    376377                46BA9EAB1F4CD61E009A2BBC /* CompletionHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompletionHandler.h; sourceTree = "<group>"; };
    377378                46BEB6E922FFDDD500269867 /* RefCounted.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RefCounted.cpp; sourceTree = "<group>"; };
     
    12701271                                5311BD591EA81A9600525281 /* ThreadMessage.h */,
    12711272                                A8A4733E151A825B004123FF /* ThreadSafeRefCounted.h */,
     1273                                4468567225094FE8008CCA05 /* ThreadSanitizerSupport.h */,
    12721274                                A8A4733F151A825B004123FF /* ThreadSpecific.h */,
    12731275                                0F66B2861DC97BAB004A1D3F /* TimeWithDynamicClockType.cpp */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r266573 r267130  
    261261    ThreadMessage.h
    262262    ThreadSafeRefCounted.h
     263    ThreadSanitizerSupport.h
    263264    ThreadSpecific.h
    264265    Threading.h
  • trunk/Source/WTF/wtf/Compiler.h

    r260027 r267130  
    157157#endif
    158158
     159/* TSAN_ENABLED and SUPPRESS_TSAN */
     160
     161#ifdef __SANITIZE_THREAD__
     162#define TSAN_ENABLED 1
     163#else
     164#define TSAN_ENABLED COMPILER_HAS_CLANG_FEATURE(thread_sanitizer)
     165#endif
     166
     167#if TSAN_ENABLED
     168#define SUPPRESS_TSAN __attribute__((no_sanitize_thread))
     169#else
     170#define SUPPRESS_TSAN
     171#endif
     172
    159173/* ==== Compiler-independent macros for various compiler features, in alphabetical order ==== */
    160174
  • trunk/Source/WTF/wtf/Locker.h

    r244352 r267130  
    11/*
    2  * Copyright (C) 2008-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3333#include <wtf/Compiler.h>
    3434#include <wtf/Noncopyable.h>
     35#include <wtf/ThreadSanitizerSupport.h>
    3536
    3637namespace WTF {
     
    6869    {
    6970        compilerFence();
    70         if (m_lockable)
     71        if (m_lockable) {
     72            TSAN_ANNOTATE_HAPPENS_BEFORE(m_lockable);
    7173            m_lockable->unlock();
     74        }
    7275    }
    7376   
     
    8689    void unlockEarly()
    8790    {
     91        TSAN_ANNOTATE_HAPPENS_BEFORE(m_lockable);
    8892        m_lockable->unlock();
    89         m_lockable = 0;
     93        m_lockable = nullptr;
    9094    }
    9195   
     
    100104    Locker& operator=(Locker&& other)
    101105    {
    102         if (m_lockable)
     106        if (m_lockable) {
     107            TSAN_ANNOTATE_HAPPENS_BEFORE(m_lockable);
    103108            m_lockable->unlock();
     109        }
    104110        m_lockable = other.m_lockable;
    105111        other.m_lockable = nullptr;
     
    110116    void lock()
    111117    {
    112         if (m_lockable)
     118        if (m_lockable) {
    113119            m_lockable->lock();
     120            TSAN_ANNOTATE_HAPPENS_AFTER(m_lockable);
     121        }
    114122        compilerFence();
    115123    }
  • trunk/Tools/ChangeLog

    r267123 r267130  
     12020-09-15  David Kilzer  <ddkilzer@apple.com>
     2
     3        WebKit should support building with clang ThreadSanitizer enabled
     4        <https://webkit.org/b/216318>
     5        <rdar://problem/31615729>
     6
     7        Reviewed by Darin Adler.
     8
     9        This patch doesn't attempt to resolve every potential false
     10        positive, but makes it easy to build WebKit with TSan enabled.
     11
     12        * Scripts/set-webkit-configuration:
     13        - Add support for --[no-]tsan switches.
     14        * Scripts/webkitdirs.pm:
     15        (determineTSanIsEnabled):
     16        (tsanIsEnabled):
     17        (XcodeOptions):
     18        (generateBuildSystemFromCMakeProject):
     19        - Add support for building with TSan enabled.
     20
     21        * asan/asan.xcconfig: Rename to sanitizer/asan.xcconfig.
     22        * sanitizer/asan.xcconfig: Rename from asan/asan.xcconfig.
     23        - Extract common variables to sanitizer.xcconfig.
     24        * sanitizer/sanitizer.xcconfig: Add.
     25        - Extract common variables from asan.xcconfig.
     26        * sanitizer/tsan.xcconfig: Add.
     27        - Add support for TSan.
     28
    1292020-09-15  Alex Christensen  <achristensen@webkit.org>
    230
  • trunk/Tools/Scripts/set-webkit-configuration

    r255160 r267130  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2005-2019 Apple Inc.  All rights reserved.
     3# Copyright (C) 2005-2020 Apple Inc.  All rights reserved.
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    2929use strict;
    3030use warnings;
     31use File::Spec;
    3132use FindBin;
    3233use lib $FindBin::Bin;
     
    4041  --[no-]asan                        Enable or disable clang address sanitizer
    4142  --[no-]coverage                    Enable or disable LLVM Source-based Code Coverage
     43  --[no-]tsan                        Enable or disable clang thread sanitizer
    4244  --force-optimization-level=<level> Optimization level: O3, O2, O1, O0, Os, Ofast, Og, or none
    4345  --lto-mode=<mode>                  Set LTO mode: full, thin, or none
     
    5355my $enableCoverage = checkForArgumentAndRemoveFromARGV("--coverage");
    5456my $disableCoverage = checkForArgumentAndRemoveFromARGV("--no-coverage");
     57my $enableTSAN = checkForArgumentAndRemoveFromARGV("--tsan");
     58my $disableTSAN = checkForArgumentAndRemoveFromARGV("--no-tsan");
    5559my $ltoMode;
    5660if (!checkForArgumentAndRemoveFromARGVGettingValue("--lto-mode", \$ltoMode)) {
     
    8185    unlink "$baseProductDir/Architecture";
    8286    unlink "$baseProductDir/ASan";
     87    unlink "$baseProductDir/Coverage";
     88    unlink File::Spec->catfile($baseProductDir, "TSan");
    8389    unlink "$baseProductDir/ForceOptimizationLevel";
    84     unlink "$baseProductDir/Coverage";
    8590    unlink "$baseProductDir/LTO";
    8691    exit 0;
    8792}
    8893
    89 if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$ltoMode && !$forceOptimizationLevel)
     94if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$enableTSAN && !$disableTSAN && !$ltoMode && !$forceOptimizationLevel)
    9095    || ($enableASAN && $disableASAN)
    91     || ($enableCoverage && $disableCoverage)) {
     96    || ($enableCoverage && $disableCoverage)
     97    || ($enableTSAN && $disableTSAN)
     98    ) {
    9299    print STDERR $usage;
    93100    exit 1;
     
    144151}
    145152
     153if ($enableTSAN) {
     154    open TSAN, ">", File::Spec->catfile($baseProductDir, "TSan") or die;
     155    print TSAN "YES";
     156    close TSAN;
     157} elsif ($disableTSAN) {
     158    unlink File::Spec->catfile($baseProductDir, "TSan");
     159}
     160
    146161if ($forceOptimizationLevel && $forceOptimizationLevel eq "none") {
    147162    unlink "$baseProductDir/ForceOptimizationLevel";
  • trunk/Tools/Scripts/webkitdirs.pm

    r265323 r267130  
    1 # Copyright (C) 2005-2019 Apple Inc. All rights reserved.
     1# Copyright (C) 2005-2020 Apple Inc. All rights reserved.
    22# Copyright (C) 2009 Google Inc. All rights reserved.
    33# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
     
    131131my %nativeArchitectureMap = ();
    132132my $asanIsEnabled;
     133my $tsanIsEnabled;
    133134my $forceOptimizationLevel;
    134135my $coverageIsEnabled;
     
    447448}
    448449
     450sub determineTSanIsEnabled
     451{
     452    return if defined $tsanIsEnabled;
     453    determineBaseProductDir();
     454
     455    $tsanIsEnabled = 0;
     456    my $tsanConfigurationValue;
     457
     458    if (open TSAN, "$baseProductDir/TSan") {
     459        $tsanConfigurationValue = <TSAN>;
     460        close TSAN;
     461        chomp $tsanConfigurationValue;
     462        $tsanIsEnabled = 1 if $tsanConfigurationValue eq "YES";
     463    }
     464}
     465
    449466sub determineForceOptimizationLevel
    450467{
     
    886903}
    887904
     905sub tsanIsEnabled()
     906{
     907    determineTSanIsEnabled();
     908    return $tsanIsEnabled;
     909}
     910
    888911sub forceOptimizationLevel()
    889912{
     
    940963    determineArchitecture();
    941964    determineASanIsEnabled();
     965    determineTSanIsEnabled();
    942966    determineForceOptimizationLevel();
    943967    determineCoverageIsEnabled();
     
    949973    push @options, "-ShowBuildOperationDuration=YES";
    950974    push @options, ("-configuration", $configuration);
    951     push @options, ("-xcconfig", sourceDir() . "/Tools/asan/asan.xcconfig", "ASAN_IGNORE=" . sourceDir() . "/Tools/asan/webkit-asan-ignore.txt") if $asanIsEnabled;
     975    if ($asanIsEnabled) {
     976        push @options, ("-xcconfig", File::Spec->catfile(sourceDir(), "Tools", "sanitizer", "asan.xcconfig"));
     977        my $asanIgnorePath = File::Spec->catfile(sourceDir(), "Tools", "sanitizer", "webkit-asan-ignore.txt");
     978        push @options, "ASAN_IGNORE=$asanIgnorePath" if -e $asanIgnorePath;
     979    } elsif ($tsanIsEnabled) {
     980        push @options, ("-xcconfig", File::Spec->catfile(sourceDir(), "Tools", "sanitizer", "tsan.xcconfig"));
     981    }
    952982    push @options, ("-xcconfig", sourceDir() . "/Tools/coverage/coverage.xcconfig") if $coverageIsEnabled;
    953983    push @options, ("GCC_OPTIMIZATION_LEVEL=$forceOptimizationLevel") if $forceOptimizationLevel;
     
    961991    appendToEnvironmentVariableList("WEBKIT_COVERAGE_BUILD", "1") if $coverageIsEnabled;
    962992
    963     die "cannot enable both ASAN and Coverage at this time\n" if $coverageIsEnabled && $asanIsEnabled;
     993    die "Cannot enable both ASAN and TSAN at the same time\n" if $asanIsEnabled && $tsanIsEnabled;
     994    die "Cannot enable both (ASAN or TSAN) and Coverage at this time\n" if $coverageIsEnabled && ($asanIsEnabled || $tsanIsEnabled);
    964995
    965996    if (willUseIOSDeviceSDK() || willUseWatchDeviceSDK() || willUseAppleTVDeviceSDK()) {
     
    24342465
    24352466    push @args, "-DENABLE_SANITIZERS=address" if asanIsEnabled();
     2467    push @args, "-DENABLE_SANITIZERS=thread" if tsanIsEnabled();
    24362468
    24372469    push @args, "-DLTO_MODE=$ltoMode" if ltoMode();
Note: See TracChangeset for help on using the changeset viewer.