11# !/usr/bin/env perl
22
3- # Copyright (C) 2005-2020 Apple Inc. All rights reserved.
3+ # Copyright (C) 2005-2021 Apple Inc. All rights reserved.
44#
55# Redistribution and use in source and binary forms, with or without
66# modification, are permitted provided that the following conditions
@@ -41,6 +41,7 @@ Usage: $programName [options]
4141 --[no-]asan Enable or disable clang address sanitizer
4242 --[no-]coverage Enable or disable LLVM Source-based Code Coverage
4343 --[no-]tsan Enable or disable clang thread sanitizer
44+ --[no-]ubsan Enable or disable clang undefined behavior sanitizer
4445 --force-optimization-level=<level> Optimization level: O3, O2, O1, O0, Os, Ofast, Og, or none
4546 --lto-mode=<mode> Set LTO mode: full, thin, or none
4647 --debug Set the default configuration to debug
@@ -56,6 +57,8 @@ my $enableCoverage = checkForArgumentAndRemoveFromARGV("--coverage");
5657my $disableCoverage = checkForArgumentAndRemoveFromARGV(" --no-coverage" );
5758my $enableTSAN = checkForArgumentAndRemoveFromARGV(" --tsan" );
5859my $disableTSAN = checkForArgumentAndRemoveFromARGV(" --no-tsan" );
60+ my $enableUBSAN = checkForArgumentAndRemoveFromARGV(" --ubsan" );
61+ my $disableUBSAN = checkForArgumentAndRemoveFromARGV(" --no-ubsan" );
5962my $ltoMode ;
6063if (!checkForArgumentAndRemoveFromARGVGettingValue(" --lto-mode" , \$ltoMode )) {
6164 $ltoMode =" " ;
@@ -81,25 +84,28 @@ my $baseProductDir = baseProductDir();
8184system " mkdir" , " -p" , " $baseProductDir " ;
8285
8386if (checkForArgumentAndRemoveFromARGV(" --reset" )) {
84- unlink " $baseProductDir /Configuration" ;
85- unlink " $baseProductDir /Architecture" ;
86- unlink " $baseProductDir /ASan" ;
87- unlink " $baseProductDir /Coverage" ;
88- unlink File::Spec-> catfile($baseProductDir , " TSan" );
89- unlink " $baseProductDir /ForceOptimizationLevel" ;
90- unlink " $baseProductDir /LTO" ;
87+ for my $fileName (qw( Architecture ASan Configuration Coverage ForceOptimizationLevel LTO TSan UBSan) ) {
88+ unlink File::Spec-> catfile($baseProductDir , $fileName );
89+ }
9190 exit 0;
9291}
9392
94- if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$enableTSAN && !$disableTSAN && !$ltoMode && !$forceOptimizationLevel )
93+ if ((!$configuration && !$architecture && !$enableASAN && !$disableASAN && !$enableCoverage && !$disableCoverage && !$enableTSAN && !$disableTSAN && !$enableUBSAN && ! $disableUBSAN && ! $ ltoMode && !$forceOptimizationLevel )
9594 || ($enableASAN && $disableASAN )
9695 || ($enableCoverage && $disableCoverage )
9796 || ($enableTSAN && $disableTSAN )
97+ || ($enableUBSAN && $disableUBSAN )
9898 ) {
9999 print STDERR $usage ;
100100 exit 1;
101101}
102102
103+ if ($enableASAN && $enableTSAN ) {
104+ print STDERR " ERROR: Address Sanitizer and Thread Sanitzer can't be enabled together.\n " ;
105+ print STDERR $usage ;
106+ exit 1;
107+ }
108+
103109if ($ltoMode && $ltoMode ne " full" && $ltoMode ne " thin" && $ltoMode ne " none" ) {
104110 print STDERR $usage ;
105111 exit 1;
@@ -118,56 +124,24 @@ if ($forceOptimizationLevel
118124 exit 1;
119125}
120126
121- if ($configuration ) {
122- open CONFIGURATION, " >" , " $baseProductDir /Configuration" or die ;
123- print CONFIGURATION $configuration ;
124- close CONFIGURATION;
125- }
126-
127- if ($architecture ) {
128- if ($architecture ne " x86_64" ) {
129- open ARCHITECTURE, " >" , " $baseProductDir /Architecture" or die ;
130- print ARCHITECTURE $architecture ;
131- close ARCHITECTURE;
127+ sub updateOrDeleteConfigurationFile ($$)
128+ {
129+ my ($fileName , $contents ) = @_ ;
130+ my $filePath = File::Spec-> catfile($baseProductDir , $fileName );
131+ if ($contents ) {
132+ open FILE, " >" , $filePath or die ;
133+ print FILE $contents ;
134+ close FILE;
132135 } else {
133- unlink " $baseProductDir /Architecture " ;
136+ unlink $filePath ;
134137 }
135138}
136139
137- if ($enableASAN ) {
138- open ASAN, " >" , " $baseProductDir /ASan" or die ;
139- print ASAN " YES" ;
140- close ASAN;
141- } elsif ($disableASAN ) {
142- unlink " $baseProductDir /ASan" ;
143- }
144-
145- if ($enableCoverage ) {
146- open Coverage, " >" , " $baseProductDir /Coverage" or die ;
147- print Coverage " YES" ;
148- close Coverage;
149- } elsif ($disableCoverage ) {
150- unlink " $baseProductDir /Coverage" ;
151- }
152-
153- if ($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-
161- if ($forceOptimizationLevel && $forceOptimizationLevel eq " none" ) {
162- unlink " $baseProductDir /ForceOptimizationLevel" ;
163- } elsif ($forceOptimizationLevel ) {
164- open ForceOptimizationLevel, " >" , " $baseProductDir /ForceOptimizationLevel" or die ;
165- print ForceOptimizationLevel substr ($forceOptimizationLevel , 1) . " \n " ;
166- close ForceOptimizationLevel;
167- }
168-
169- if ($ltoMode ) {
170- open LTO, " >" , " $baseProductDir /LTO" or die ;
171- print LTO " $ltoMode " ;
172- close LTO;
173- }
140+ updateOrDeleteConfigurationFile(" Configuration" , $configuration );
141+ updateOrDeleteConfigurationFile(" Architecture" , $architecture && $architecture ne " x86_64" ? $architecture : undef );
142+ updateOrDeleteConfigurationFile(" ASan" , $enableASAN ? " YES" : undef );
143+ updateOrDeleteConfigurationFile(" Coverage" , $enableCoverage ? " YES" : undef );
144+ updateOrDeleteConfigurationFile(" TSan" , $enableTSAN ? " YES" : undef );
145+ updateOrDeleteConfigurationFile(" UBSan" , $enableUBSAN ? " YES" : undef );
146+ updateOrDeleteConfigurationFile(" ForceOptimizationLevel" , (!$forceOptimizationLevel || $forceOptimizationLevel eq " none" ) ? undef : substr ($forceOptimizationLevel , 1) . " \n " );
147+ updateOrDeleteConfigurationFile(" LTO" , $ltoMode );
0 commit comments