diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h --- a/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_interface_internal.h @@ -33,11 +33,17 @@ SANITIZER_INTERFACE_ATTRIBUTE const char *__sanitizer_get_report_path(); + // common_interface_defs.h may be already included in unit tests, + // which include googletest headers, which may transitively include + // sanitizer interface headers. Avoid defining this struct second time + // in such case, or it will lead to typedef redefinition error. +#ifndef SANITIZER_COMMON_INTERFACE_DEFS_H typedef struct { int coverage_sandboxed; __sanitizer::sptr coverage_fd; unsigned int coverage_max_block_size; } __sanitizer_sandbox_arguments; +#endif // Notify the tools that the sandbox is going to be turned on. SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cpp @@ -11,17 +11,25 @@ //===----------------------------------------------------------------------===// #include +// This ensures that including both internal sanitizer_common headers +// and the interface headers does not lead to compilation failures. +// Both may be included in unit tests, where googletest transitively +// pulls in sanitizer interface headers. +// The headers are specifically included using relative paths, +// because a compiler may use a different mismatching version +// of sanitizer headers. +#include "../../../include/sanitizer/asan_interface.h" +#include "../../../include/sanitizer/msan_interface.h" +#include "../../../include/sanitizer/tsan_interface.h" +#include "gtest/gtest.h" #include "sanitizer_common/sanitizer_allocator_internal.h" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_file.h" #include "sanitizer_common/sanitizer_flags.h" #include "sanitizer_common/sanitizer_libc.h" #include "sanitizer_common/sanitizer_platform.h" - #include "sanitizer_pthread_wrappers.h" -#include "gtest/gtest.h" - namespace __sanitizer { static bool IsSorted(const uptr *array, uptr n) {