diff --git a/client/capture_context_mac_test.cc b/client/capture_context_mac_test.cc index 436ac5ad..1904b2b6 100644 --- a/client/capture_context_mac_test.cc +++ b/client/capture_context_mac_test.cc @@ -21,6 +21,7 @@ #include "build/build_config.h" #include "gtest/gtest.h" +#include "util/misc/address_sanitizer.h" #include "util/misc/implicit_cast.h" namespace crashpad { @@ -103,13 +104,14 @@ void TestCaptureContext() { // captured program counter should be slightly greater than or equal to the // reference program counter. uintptr_t pc = ProgramCounterFromContext(context_1); -#if !__has_feature(address_sanitizer) + +#if !defined(ADDRESS_SANITIZER) // AddressSanitizer can cause enough code bloat that the “nearby” check would // likely fail. const uintptr_t kReferencePC = reinterpret_cast(TestCaptureContext); EXPECT_LT(pc - kReferencePC, 64u); -#endif +#endif // !defined(ADDRESS_SANITIZER) // Declare sp and context_2 here because all local variables need to be // declared before computing the stack pointer reference value, so that the diff --git a/client/crashpad_info.cc b/client/crashpad_info.cc index e8a6a9ee..e517f7b1 100644 --- a/client/crashpad_info.cc +++ b/client/crashpad_info.cc @@ -14,6 +14,7 @@ #include "client/crashpad_info.h" +#include "util/misc/address_sanitizer.h" #include "util/stdlib/cxx.h" #if defined(OS_MACOSX) @@ -72,14 +73,14 @@ __attribute__(( #error Port #endif // !defined(OS_MACOSX) && !defined(OS_LINUX) && !defined(OS_ANDROID) -#if __has_feature(address_sanitizer) +#if defined(ADDRESS_SANITIZER) // AddressSanitizer would add a trailing red zone of at least 32 bytes, // which would be reflected in the size of the custom section. This confuses // MachOImageReader::GetCrashpadInfo(), which finds that the section’s size // disagrees with the structure’s size_ field. By specifying an alignment // greater than the red zone size, the red zone will be suppressed. aligned(64), -#endif // __has_feature(address_sanitizer) +#endif // defined(ADDRESS_SANITIZER) // The “used” attribute prevents the structure from being dead-stripped. used, diff --git a/util/misc/address_sanitizer.h b/util/misc/address_sanitizer.h new file mode 100644 index 00000000..75c72399 --- /dev/null +++ b/util/misc/address_sanitizer.h @@ -0,0 +1,28 @@ +// Copyright 2016 The Crashpad Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef CRASHPAD_UTIL_MISC_ADDRESS_SANITIZER_H_ +#define CRASHPAD_UTIL_MISC_ADDRESS_SANITIZER_H_ + +#include "base/compiler_specific.h" +#include "build/build_config.h" + +#if !defined(ADDRESS_SANITIZER) +#if HAS_FEATURE(address_sanitizer) || \ + (defined(COMPILER_GCC) && defined(__SANITIZE_ADDRESS__)) +#define ADDRESS_SANITIZER 1 +#endif +#endif // !defined(ADDRESS_SANITIZER) + +#endif // CRASHPAD_UTIL_MISC_ADDRESS_SANITIZER_H_ diff --git a/util/util.gyp b/util/util.gyp index 5768788a..418256d3 100644 --- a/util/util.gyp +++ b/util/util.gyp @@ -84,6 +84,7 @@ 'mach/task_for_pid.h', 'mach/task_memory.cc', 'mach/task_memory.h', + 'misc/address_sanitizer.h', 'misc/arraysize_unsafe.h', 'misc/clock.h', 'misc/clock_mac.cc',