Automatically disable assembly with MSAN.

MSAN is incompatible with hand-written assembly code. Previously we
required that OPENSSL_NO_ASM be set when building with MSAN, and the
CMake build would take care of this. However, with other build systems
it wasn't always so easy.

This change automatically disables assembly when the compiler is
configured for MSAN.

Change-Id: I6c219120f62d16b99bafc2efb02948ecbecaf87f
Reviewed-on: https://boringssl-review.googlesource.com/31724
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
Adam Langley 2018-09-07 11:20:23 -07:00 committed by CQ bot account: commit-bot@chromium.org
parent 967cd8219c
commit e77c27d734
8 changed files with 59 additions and 19 deletions

View File

@ -274,7 +274,7 @@ if(MSAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
set(OPENSSL_NO_ASM "1") set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer")
endif() endif()
if(ASAN) if(ASAN)
@ -284,7 +284,6 @@ if(ASAN)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope -fno-omit-frame-pointer")
set(OPENSSL_NO_ASM "1")
endif() endif()
if(CFI) if(CFI)

View File

@ -19,19 +19,6 @@
#include "internal.h" #include "internal.h"
#if defined(OPENSSL_MSAN) && !defined(OPENSSL_NO_ASM)
// MSan works by instrumenting memory accesses in the compiler. Accesses from
// uninstrumented code, such as assembly, are invisible to it. MSan will
// incorrectly report reads from assembly-initialized memory as uninitialized.
// If building BoringSSL with MSan, exclude assembly files from the build and
// define OPENSSL_NO_ASM.
//
// This is checked here rather than in a header because the consumer might not
// define OPENSSL_NO_ASM. It is only necessary for BoringSSL source files to be
// built with it.
#error "BoringSSL must be built with assembly disabled to use MSan."
#endif
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_STATIC_ARMCAP) && \ #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_STATIC_ARMCAP) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \ (defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) || \ defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64) || \

View File

@ -17,6 +17,12 @@
* domain licensed but the standard ISC license is included above to keep * domain licensed but the standard ISC license is included above to keep
* licensing simple. */ * licensing simple. */
#if defined(__has_feature)
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
#define OPENSSL_NO_ASM
#endif
#endif
#if !defined(OPENSSL_NO_ASM) && defined(__arm__) && !defined(__APPLE__) #if !defined(OPENSSL_NO_ASM) && defined(__arm__) && !defined(__APPLE__)
#if defined(BORINGSSL_PREFIX) #if defined(BORINGSSL_PREFIX)

View File

@ -130,6 +130,16 @@ sub expand_line {
return $line; return $line;
} }
print <<___;
#if defined(__has_feature)
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
#define OPENSSL_NO_ASM
#endif
#endif
#if !defined(OPENSSL_NO_ASM)
___
print "#if defined(__arm__)\n" if ($flavour eq "linux32"); print "#if defined(__arm__)\n" if ($flavour eq "linux32");
print "#if defined(__aarch64__)\n" if ($flavour eq "linux64"); print "#if defined(__aarch64__)\n" if ($flavour eq "linux64");
@ -184,5 +194,6 @@ while(my $line=<>) {
} }
print "#endif\n" if ($flavour eq "linux32" || $flavour eq "linux64"); print "#endif\n" if ($flavour eq "linux32" || $flavour eq "linux64");
print "#endif // !OPENSSL_NO_ASM";
close STDOUT; close STDOUT;

View File

@ -255,6 +255,16 @@ my $darn = sub {
" .long ".sprintf "0x%X",(31<<26)|($rt<<21)|($l<<16)|(755<<1); " .long ".sprintf "0x%X",(31<<26)|($rt<<21)|($l<<16)|(755<<1);
}; };
print <<___;
#if defined(__has_feature)
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)"
#define OPENSSL_NO_ASM"
#endif
#endif
#if !defined(OPENSSL_NO_ASM) && defined(__powerpc64__)
___
while($line=<>) { while($line=<>) {
$line =~ s|[#!;].*$||; # get rid of asm-style comments... $line =~ s|[#!;].*$||; # get rid of asm-style comments...
@ -296,4 +306,6 @@ while($line=<>) {
print "\n"; print "\n";
} }
print "#endif // !OPENSSL_NO_ASM && __powerpc64__";
close STDOUT; close STDOUT;

View File

@ -1139,10 +1139,21 @@ ___
OPTION DOTNAME OPTION DOTNAME
___ ___
} }
print STDOUT "#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM)\n" if ($gas);
print STDOUT "#if defined(BORINGSSL_PREFIX)\n" if ($gas); if ($gas) {
print STDOUT "#include <boringssl_prefix_symbols_asm.h>\n" if ($gas); print <<___;
print STDOUT "#endif\n" if ($gas); #if defined(__has_feature)
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
#define OPENSSL_NO_ASM
#endif
#endif
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM)
#if defined(BORINGSSL_PREFIX)
#include <boringssl_prefix_symbols_asm.h>
#endif
___
}
while(defined(my $line=<>)) { while(defined(my $line=<>)) {

View File

@ -1,3 +1,9 @@
#if defined(__has_feature)
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
#define OPENSSL_NO_ASM
#endif
#endif
#if defined(__arm__) && !defined(OPENSSL_NO_ASM) && !defined(__APPLE__) #if defined(__arm__) && !defined(OPENSSL_NO_ASM) && !defined(__APPLE__)
#if defined(BORINGSSL_PREFIX) #if defined(BORINGSSL_PREFIX)

View File

@ -231,9 +231,17 @@ extern "C" {
#endif #endif
#if __has_feature(memory_sanitizer) #if __has_feature(memory_sanitizer)
#define OPENSSL_MSAN #define OPENSSL_MSAN
#define OPENSSL_ASM_INCOMPATIBLE
#endif #endif
#endif #endif
#if defined(OPENSSL_ASM_INCOMPATIBLE)
#undef OPENSSL_ASM_INCOMPATIBLE
#if !defined(OPENSSL_NO_ASM)
#define OPENSSL_NO_ASM
#endif
#endif // OPENSSL_ASM_INCOMPATIBLE
// CRYPTO_THREADID is a dummy value. // CRYPTO_THREADID is a dummy value.
typedef int CRYPTO_THREADID; typedef int CRYPTO_THREADID;