Skip to content

Commit

Permalink
Recognise clang -fsanitize options and translate them
Browse files Browse the repository at this point in the history
Because we depend on knowing if clang's address, memory or undefinedbehavior
sanitizers are enabled, we make an extra effort to detect them among the
C flags, and adjust the %disabled values accordingly.

Reviewed-by: Bernd Edlinger <[email protected]>
(Merged from openssl#8778)
  • Loading branch information
levitte committed Apr 24, 2019
1 parent 0109e03 commit bacc308
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions Configure
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,27 @@ unless ($disabled{threads}) {
}
}

# Find out if clang's sanitizers have been enabled with -fsanitize
# flags and ensure that the corresponding %disabled elements area
# removed to reflect that the sanitizers are indeed enabled.
my %detected_sanitizers = ();
foreach (grep /^-fsanitize=/, @{$config{CFLAGS} || []}) {
(my $checks = $_) =~ s/^-fsanitize=//;
foreach (split /,/, $checks) {
my $d = { address => 'asan',
undefined => 'ubsan',
memory => 'msan' } -> {$_};
next unless defined $d;

$detected_sanitizers{$d} = 1;
if (defined $disabled{$d}) {
die "***** Conflict between disabling $d and enabling $_ sanitizer"
if $disabled{$d} ne "default";
delete $disabled{$d};
}
}
}

# If threads still aren't disabled, add a C macro to ensure the source
# code knows about it. Any other flag is taken care of by the configs.
unless($disabled{threads}) {
Expand Down Expand Up @@ -1367,20 +1388,20 @@ if ($disabled{"dynamic-engine"}) {
$config{dynamic_engines} = 1;
}

unless ($disabled{asan}) {
unless ($disabled{asan} || defined $detected_sanitizers{asan}) {
push @{$config{cflags}}, "-fsanitize=address";
push @{$config{cxxflags}}, "-fsanitize=address" if $config{CXX};
}

unless ($disabled{ubsan}) {
unless ($disabled{ubsan} || defined $detected_sanitizers{ubsan}) {
# -DPEDANTIC or -fnosanitize=alignment may also be required on some
# platforms.
push @{$config{cflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all";
push @{$config{cxxflags}}, "-fsanitize=undefined", "-fno-sanitize-recover=all"
if $config{CXX};
}

unless ($disabled{msan}) {
unless ($disabled{msan} || defined $detected_sanitizers{msan}) {
push @{$config{cflags}}, "-fsanitize=memory";
push @{$config{cxxflags}}, "-fsanitize=memory" if $config{CXX};
}
Expand Down

0 comments on commit bacc308

Please sign in to comment.