Title: [275150] trunk
Revision
275150
Author
[email protected]
Date
2021-03-28 11:31:55 -0700 (Sun, 28 Mar 2021)

Log Message

Compile WebKit with UBSan
<https://webkit.org/b/176131>
<rdar://problem/34174018>

Reviewed by Alexey Proskuryakov.

.:

* Makefile.shared:
- Add support for "UBSAN=YES" argument to make.

Tools:

* Scripts/set-webkit-configuration:
- Add support for --[no-]ubsan command-line switch.
- Add warning when enabling ASan and TSan together.
(updateOrDeleteConfigurationFile):
- Extract common code for updating configuration files.

* Scripts/webkitdirs.pm:
(readSanitizerConfiguration): Add.
- Extract common code for reading sanitizer configuration files.
(determineASanIsEnabled):
(determineTSanIsEnabled):
(determineUBSanIsEnabled): Add.
- Make use of readSanitizerConfiguration().
(ubsanIsEnabled): Add.
(XcodeOptions):
- Add command-line switches for UBSan.
(generateBuildSystemFromCMakeProject): Ditto.

* sanitizer/ubsan.xcconfig: Add.
- Contains Xcode settings for enabling UBSan.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (275149 => 275150)


--- trunk/ChangeLog	2021-03-28 17:46:26 UTC (rev 275149)
+++ trunk/ChangeLog	2021-03-28 18:31:55 UTC (rev 275150)
@@ -1,3 +1,14 @@
+2021-03-28  David Kilzer  <[email protected]>
+
+        Compile WebKit with UBSan
+        <https://webkit.org/b/176131>
+        <rdar://problem/34174018>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Makefile.shared:
+        - Add support for "UBSAN=YES" argument to make.
+
 2021-03-27  Philippe Normand  <[email protected]>
 
         REGRESSION(r275111) [GLIB] Fix build with new derived sources and forwarding headers scheme

Modified: trunk/Makefile.shared (275149 => 275150)


--- trunk/Makefile.shared	2021-03-28 17:46:26 UTC (rev 275149)
+++ trunk/Makefile.shared	2021-03-28 18:31:55 UTC (rev 275150)
@@ -77,6 +77,14 @@
 endif
 endif
 
+ifeq ($(UBSAN),YES)
+UBSAN_OPTION=--ubsan
+else
+ifeq ($(UBSAN),NO)
+UBSAN_OPTION=--no-ubsan
+endif
+endif
+
 ifeq ($(WK_LTO_MODE),full)
 WK_LTO_OPTION=--lto-mode=full
 else ifeq ($(WK_LTO_MODE),thin)
@@ -93,7 +101,7 @@
 
 
 define set_webkit_configuration
-	$(SCRIPTS_PATH)/set-webkit-configuration $1 $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)
+	$(SCRIPTS_PATH)/set-webkit-configuration $1 $(ASAN_OPTION) $(TSAN_OPTION) $(UBSAN_OPTION) $(WK_LTO_OPTION)
 endef
 
 define invoke_xcode
@@ -107,7 +115,7 @@
 endef
 
 all:
-ifneq (,$(strip $(ASAN_OPTION) $(TSAN_OPTION) $(WK_LTO_OPTION)))
+ifneq (,$(strip $(ASAN_OPTION) $(TSAN_OPTION) $(UBSAN_OPTION) $(WK_LTO_OPTION)))
 	@$(call set_webkit_configuration,)
 endif
 	@$(call invoke_xcode,,GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_ADDITIONS) $$(inherited)')

Modified: trunk/Tools/ChangeLog (275149 => 275150)


--- trunk/Tools/ChangeLog	2021-03-28 17:46:26 UTC (rev 275149)
+++ trunk/Tools/ChangeLog	2021-03-28 18:31:55 UTC (rev 275150)
@@ -1,3 +1,32 @@
+2021-03-28  David Kilzer  <[email protected]>
+
+        Compile WebKit with UBSan
+        <https://webkit.org/b/176131>
+        <rdar://problem/34174018>
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Scripts/set-webkit-configuration:
+        - Add support for --[no-]ubsan command-line switch.
+        - Add warning when enabling ASan and TSan together.
+        (updateOrDeleteConfigurationFile):
+        - Extract common code for updating configuration files.
+
+        * Scripts/webkitdirs.pm:
+        (readSanitizerConfiguration): Add.
+        - Extract common code for reading sanitizer configuration files.
+        (determineASanIsEnabled):
+        (determineTSanIsEnabled):
+        (determineUBSanIsEnabled): Add.
+        - Make use of readSanitizerConfiguration().
+        (ubsanIsEnabled): Add.
+        (XcodeOptions):
+        - Add command-line switches for UBSan.
+        (generateBuildSystemFromCMakeProject): Ditto.
+
+        * sanitizer/ubsan.xcconfig: Add.
+        - Contains Xcode settings for enabling UBSan.
+
 2021-03-27  Kate Cheney  <[email protected]>
 
         PCM: Send report to both click source and attribution destination website

Modified: trunk/Tools/Scripts/set-webkit-configuration (275149 => 275150)


--- trunk/Tools/Scripts/set-webkit-configuration	2021-03-28 17:46:26 UTC (rev 275149)
+++ trunk/Tools/Scripts/set-webkit-configuration	2021-03-28 18:31:55 UTC (rev 275150)
@@ -1,6 +1,6 @@
 #!/usr/bin/env perl
 
-# Copyright (C) 2005-2020 Apple Inc.  All rights reserved.
+# Copyright (C) 2005-2021 Apple Inc.  All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -41,6 +41,7 @@
   --[no-]asan                        Enable or disable clang address sanitizer
   --[no-]coverage                    Enable or disable LLVM Source-based Code Coverage
   --[no-]tsan                        Enable or disable clang thread sanitizer
+  --[no-]ubsan                       Enable or disable clang undefined behavior sanitizer
   --force-optimization-level=<level> Optimization level: O3, O2, O1, O0, Os, Ofast, Og, or none
   --lto-mode=<mode>                  Set LTO mode: full, thin, or none
   --debug                            Set the default configuration to debug
@@ -56,6 +57,8 @@
 my $disableCoverage = checkForArgumentAndRemoveFromARGV("--no-coverage");
 my $enableTSAN = checkForArgumentAndRemoveFromARGV("--tsan");
 my $disableTSAN = checkForArgumentAndRemoveFromARGV("--no-tsan");
+my $enableUBSAN = checkForArgumentAndRemoveFromARGV("--ubsan");
+my $disableUBSAN = checkForArgumentAndRemoveFromARGV("--no-ubsan");
 my $ltoMode;
 if (!checkForArgumentAndRemoveFromARGVGettingValue("--lto-mode", \$ltoMode)) {
     $ltoMode="";
@@ -81,25 +84,28 @@
 system "mkdir", "-p", "$baseProductDir";
 
 if (checkForArgumentAndRemoveFromARGV("--reset")) {
-    unlink "$baseProductDir/Configuration";
-    unlink "$baseProductDir/Architecture";
-    unlink "$baseProductDir/ASan";
-    unlink "$baseProductDir/Coverage";
-    unlink File::Spec->catfile($baseProductDir, "TSan");
-    unlink "$baseProductDir/ForceOptimizationLevel";
-    unlink "$baseProductDir/LTO";
+    for my $fileName (qw(Architecture ASan Configuration Coverage ForceOptimizationLevel LTO TSan UBSan)) {
+        unlink File::Spec->catfile($baseProductDir, $fileName);
+    }
     exit 0;
 }
 
-if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$enableTSAN && !$disableTSAN && !$ltoMode && !$forceOptimizationLevel)
+if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$enableTSAN && !$disableTSAN && !$enableUBSAN && !$disableUBSAN && !$ltoMode && !$forceOptimizationLevel)
     || ($enableASAN && $disableASAN)
     || ($enableCoverage && $disableCoverage)
     || ($enableTSAN && $disableTSAN)
+    || ($enableUBSAN && $disableUBSAN)
     ) {
     print STDERR $usage;
     exit 1;
 }
 
+if ($enableASAN && $enableTSAN) {
+    print STDERR "ERROR: Address Sanitizer and Thread Sanitzer can't be enabled together.\n";
+    print STDERR $usage;
+    exit 1;
+}
+
 if ($ltoMode && $ltoMode ne "full" && $ltoMode ne "thin" && $ltoMode ne "none") {
     print STDERR $usage;
     exit 1;
@@ -118,56 +124,24 @@
     exit 1;
 }
 
-if ($configuration) {
-    open CONFIGURATION, ">", "$baseProductDir/Configuration" or die;
-    print CONFIGURATION $configuration;
-    close CONFIGURATION;
-}
-
-if ($architecture) {
-    if ($architecture ne "x86_64") {
-        open ARCHITECTURE, ">", "$baseProductDir/Architecture" or die;
-        print ARCHITECTURE $architecture;
-        close ARCHITECTURE;
+sub updateOrDeleteConfigurationFile($$)
+{
+    my ($fileName, $contents) = @_;
+    my $filePath = File::Spec->catfile($baseProductDir, $fileName);
+    if ($contents) {
+       open FILE, ">", $filePath or die;
+       print FILE $contents;
+       close FILE;
     } else {
-        unlink "$baseProductDir/Architecture";
+        unlink $filePath;
     }
 }
 
-if ($enableASAN) {
-    open ASAN, ">", "$baseProductDir/ASan" or die;
-    print ASAN "YES";
-    close ASAN;
-} elsif ($disableASAN) {
-    unlink "$baseProductDir/ASan";
-}
-
-if ($enableCoverage) {
-    open Coverage, ">", "$baseProductDir/Coverage" or die;
-    print Coverage "YES";
-    close Coverage;
-} elsif ($disableCoverage) {
-    unlink "$baseProductDir/Coverage";
-}
-
-if ($enableTSAN) {
-    open TSAN, ">", File::Spec->catfile($baseProductDir, "TSan") or die;
-    print TSAN "YES";
-    close TSAN;
-} elsif ($disableTSAN) {
-    unlink File::Spec->catfile($baseProductDir, "TSan");
-}
-
-if ($forceOptimizationLevel && $forceOptimizationLevel eq "none") {
-    unlink "$baseProductDir/ForceOptimizationLevel";
-} elsif ($forceOptimizationLevel) {
-    open ForceOptimizationLevel, ">", "$baseProductDir/ForceOptimizationLevel" or die;
-    print ForceOptimizationLevel substr($forceOptimizationLevel, 1) . "\n";
-    close ForceOptimizationLevel;
-}
-
-if ($ltoMode) {
-    open LTO, ">", "$baseProductDir/LTO" or die;
-    print LTO "$ltoMode";
-    close LTO;
-}
+updateOrDeleteConfigurationFile("Configuration", $configuration);
+updateOrDeleteConfigurationFile("Architecture", $architecture && $architecture ne "x86_64" ? $architecture : undef);
+updateOrDeleteConfigurationFile("ASan", $enableASAN ? "YES" : undef);
+updateOrDeleteConfigurationFile("Coverage", $enableCoverage ? "YES" : undef);
+updateOrDeleteConfigurationFile("TSan", $enableTSAN ? "YES" : undef);
+updateOrDeleteConfigurationFile("UBSan", $enableUBSAN ? "YES" : undef);
+updateOrDeleteConfigurationFile("ForceOptimizationLevel", (!$forceOptimizationLevel || $forceOptimizationLevel eq "none") ? undef : substr($forceOptimizationLevel, 1) . "\n");
+updateOrDeleteConfigurationFile("LTO", $ltoMode);

Modified: trunk/Tools/Scripts/webkitdirs.pm (275149 => 275150)


--- trunk/Tools/Scripts/webkitdirs.pm	2021-03-28 17:46:26 UTC (rev 275149)
+++ trunk/Tools/Scripts/webkitdirs.pm	2021-03-28 18:31:55 UTC (rev 275150)
@@ -1,4 +1,4 @@
-# Copyright (C) 2005-2020 Apple Inc. All rights reserved.
+# Copyright (C) 2005-2021 Apple Inc. All rights reserved.
 # Copyright (C) 2009 Google Inc. All rights reserved.
 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
 # Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
@@ -131,6 +131,7 @@
 my %nativeArchitectureMap = ();
 my $asanIsEnabled;
 my $tsanIsEnabled;
+my $ubsanIsEnabled;
 my $forceOptimizationLevel;
 my $coverageIsEnabled;
 my $ltoMode;
@@ -432,20 +433,25 @@
     $architecture = 'arm64' if $architecture =~ /aarch64/i;
 }
 
+sub readSanitizerConfiguration($)
+{
+    my ($fileName) = @_;
+
+    if (open FILE, File::Spec->catfile($baseProductDir, $fileName)) {
+        my $value = <FILE>;
+        close FILE;
+        chomp $value;
+        return ($value eq "YES");
+    }
+
+    return 0;
+}
+
 sub determineASanIsEnabled
 {
     return if defined $asanIsEnabled;
     determineBaseProductDir();
-
-    $asanIsEnabled = 0;
-    my $asanConfigurationValue;
-
-    if (open ASAN, "$baseProductDir/ASan") {
-        $asanConfigurationValue = <ASAN>;
-        close ASAN;
-        chomp $asanConfigurationValue;
-        $asanIsEnabled = 1 if $asanConfigurationValue eq "YES";
-    }
+    $asanIsEnabled = readSanitizerConfiguration("ASan");
 }
 
 sub determineTSanIsEnabled
@@ -452,16 +458,14 @@
 {
     return if defined $tsanIsEnabled;
     determineBaseProductDir();
+    $tsanIsEnabled = readSanitizerConfiguration("TSan");
+}
 
-    $tsanIsEnabled = 0;
-    my $tsanConfigurationValue;
-
-    if (open TSAN, "$baseProductDir/TSan") {
-        $tsanConfigurationValue = <TSAN>;
-        close TSAN;
-        chomp $tsanConfigurationValue;
-        $tsanIsEnabled = 1 if $tsanConfigurationValue eq "YES";
-    }
+sub determineUBSanIsEnabled
+{
+    return if defined $ubsanIsEnabled;
+    determineBaseProductDir();
+    $ubsanIsEnabled = readSanitizerConfiguration("UBSan");
 }
 
 sub determineForceOptimizationLevel
@@ -909,6 +913,12 @@
     return $tsanIsEnabled;
 }
 
+sub ubsanIsEnabled()
+{
+    determineUBSanIsEnabled();
+    return $ubsanIsEnabled;
+}
+
 sub forceOptimizationLevel()
 {
     determineForceOptimizationLevel();
@@ -964,6 +974,7 @@
     determineArchitecture();
     determineASanIsEnabled();
     determineTSanIsEnabled();
+    determineUBSanIsEnabled();
     determineForceOptimizationLevel();
     determineCoverageIsEnabled();
     determineLTOMode();
@@ -980,6 +991,7 @@
     } elsif ($tsanIsEnabled) {
         push @options, ("-xcconfig", File::Spec->catfile(sourceDir(), "Tools", "sanitizer", "tsan.xcconfig"));
     }
+    push @options, ("-xcconfig", File::Spec->catfile(sourceDir(), "Tools", "sanitizer", "ubsan.xcconfig")) if $ubsanIsEnabled;
     push @options, ("-xcconfig", sourceDir() . "/Tools/coverage/coverage.xcconfig") if $coverageIsEnabled;
     push @options, ("GCC_OPTIMIZATION_LEVEL=$forceOptimizationLevel") if $forceOptimizationLevel;
     push @options, "WK_LTO_MODE=$ltoMode" if $ltoMode;
@@ -2470,6 +2482,7 @@
 
     push @args, "-DENABLE_SANITIZERS=address" if asanIsEnabled();
     push @args, "-DENABLE_SANITIZERS=thread" if tsanIsEnabled();
+    push @args, "-DENABLE_SANITIZERS=undefined" if ubsanIsEnabled();
 
     push @args, "-DLTO_MODE=$ltoMode" if ltoMode();
 

Added: trunk/Tools/sanitizer/ubsan.xcconfig (0 => 275150)


--- trunk/Tools/sanitizer/ubsan.xcconfig	                        (rev 0)
+++ trunk/Tools/sanitizer/ubsan.xcconfig	2021-03-28 18:31:55 UTC (rev 275150)
@@ -0,0 +1,13 @@
+#include "sanitizer.xcconfig"
+
+ENABLE_UNDEFINED_BEHAVIOR_SANITIZER = $(ENABLE_UNDEFINED_BEHAVIOR_SANITIZER_$(WK_UBSAN_DISALLOWED));
+ENABLE_UNDEFINED_BEHAVIOR_SANITIZER_ = YES;
+ENABLE_UNDEFINED_BEHAVIOR_SANITIZER_NO = YES;
+
+WK_ENABLE_SANITIZER = $(ENABLE_UNDEFINED_BEHAVIOR_SANITIZER);
+
+// FIXME: Tune list of UBSan checkers: <https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html>.
+// FIXME: UBSan checker -fsanitize=vptr is incompatible with GCC_ENABLE_CPP_RTTI=NO.
+// -fno-delete-null-pointer-checks: do not let the compiler remove nullptr checks that could otherwise be removed because they are considered undefined behavior.
+// -fno-optimize-sibling-calls: disable tail call elimination for more accurate crash stacks.
+WK_SANITIZER_OTHER_CFLAGS_YES = $(inherited) -fno-delete-null-pointer-checks -fno-optimize-sibling-calls -fno-sanitize=vptr;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to