[compiler-rt] Do not introduce __sanitizer namespace globally

The definitions in sanitizer_common may conflict with definitions from system headers because:

The runtime includes the system headers after the project headers (as per LLVM coding guidelines).
lib/sanitizer_common/sanitizer_internal_defs.h pollutes the namespace of everything defined after it, which is all/most of the sanitizer .h and .cc files and the included system headers with: using namespace __sanitizer; // NOLINT
This patch solves the problem by introducing the namespace only within the sanitizer namespaces as proposed by Dmitry.

Differential Revision: https://reviews.llvm.org/D21947

llvm-svn: 281657
This commit is contained in:
Anna Zaks
2016-09-15 21:02:18 +00:00
parent 592bc45533
commit 691644f3ca
27 changed files with 78 additions and 21 deletions

View File

@@ -23,6 +23,8 @@
#include "asan_init_version.h"
using __sanitizer::uptr;
using __sanitizer::u64;
using __sanitizer::u32;
extern "C" {
// This function should be called at the very beginning of the process,

View File

@@ -26,6 +26,8 @@
#include <vector>
#include <limits>
using namespace __sanitizer;
// ATTENTION!
// Please don't call intercepted functions (including malloc() and friends)
// in this test. The static runtime library is linked explicitly (without

View File

@@ -30,6 +30,8 @@ typedef ElfW(Ehdr) Elf_Ehdr;
#include "ubsan/ubsan_handlers.h"
#endif
using namespace __sanitizer;
namespace __cfi {
#define kCfiShadowLimitsStorageSize 4096 // 1 page

View File

@@ -18,6 +18,9 @@
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "dfsan_platform.h"
using __sanitizer::uptr;
using __sanitizer::u16;
// Copy declarations from public sanitizer/dfsan_interface.h header here.
typedef u16 dfsan_label;

View File

@@ -16,6 +16,8 @@
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_common.h"
using namespace __sanitizer;
INTERCEPTOR(void *, mmap, void *addr, SIZE_T length, int prot, int flags,
int fd, OFF_T offset) {
void *res = REAL(mmap)(addr, length, prot, flags, fd, offset);

View File

@@ -17,6 +17,8 @@
#include "sanitizer_common/sanitizer_flag_parser.h"
#include "sanitizer_common/sanitizer_flags.h"
using namespace __sanitizer;
namespace __esan {
static const char EsanOptsEnv[] = "ESAN_OPTIONS";

View File

@@ -21,6 +21,9 @@
// This header should NOT include any other headers.
// All functions in this header are extern "C" and start with __esan_.
using __sanitizer::uptr;
using __sanitizer::u32;
extern "C" {
// This should be kept consistent with LLVM's EfficiencySanitizerOptions.

View File

@@ -92,8 +92,8 @@ typedef __sanitizer::OFF64_T OFF64_T;
// Just a pair of pointers.
struct interpose_substitution {
const uptr replacement;
const uptr original;
const __sanitizer::uptr replacement;
const __sanitizer::uptr original;
};
// For a function foo() create a global pair of pointers { wrap_foo, foo } in

View File

@@ -37,6 +37,16 @@ void __msan_warning();
SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))
void __msan_warning_noreturn();
using __sanitizer::uptr;
using __sanitizer::sptr;
using __sanitizer::uu64;
using __sanitizer::uu32;
using __sanitizer::uu16;
using __sanitizer::u64;
using __sanitizer::u32;
using __sanitizer::u16;
using __sanitizer::u8;
SANITIZER_INTERFACE_ATTRIBUTE
void __msan_maybe_warning_1(u8 s, u32 o);
SANITIZER_INTERFACE_ATTRIBUTE

View File

@@ -92,6 +92,8 @@ static __thread void *unsafe_stack_start = nullptr;
static __thread size_t unsafe_stack_size = 0;
static __thread size_t unsafe_stack_guard = 0;
using namespace __sanitizer;
static inline void *unsafe_stack_alloc(size_t size, size_t guard) {
CHECK_GE(size + guard, size);
void *addr = MmapOrDie(size + guard, "unsafe_stack_alloc");

View File

@@ -61,8 +61,8 @@ enum InternalAllocEnum {
} // namespace __sanitizer
inline void *operator new(__sanitizer::operator_new_size_type size,
InternalAllocEnum) {
return InternalAlloc(size);
__sanitizer::InternalAllocEnum) {
return __sanitizer::InternalAlloc(size);
}
#endif // SANITIZER_ALLOCATOR_INTERNAL_H

View File

@@ -834,6 +834,11 @@ void AvoidCVE_2016_2143();
INLINE void AvoidCVE_2016_2143() {}
#endif
struct StackDepotStats {
uptr n_uniq_ids;
uptr allocated;
};
} // namespace __sanitizer
inline void *operator new(__sanitizer::operator_new_size_type size,
@@ -841,9 +846,4 @@ inline void *operator new(__sanitizer::operator_new_size_type size,
return alloc.Allocate(size);
}
struct StackDepotStats {
uptr n_uniq_ids;
uptr allocated;
};
#endif // SANITIZER_COMMON_H

View File

@@ -171,7 +171,7 @@ void MaybeStartBackgroudThread() {
void NOINLINE
__sanitizer_sandbox_on_notify(__sanitizer_sandbox_arguments *args) {
PrepareForSandboxing(args);
if (sandboxing_callback)
sandboxing_callback();
__sanitizer::PrepareForSandboxing(args);
if (__sanitizer::sandboxing_callback)
__sanitizer::sandboxing_callback();
}

View File

@@ -47,6 +47,8 @@
#include "sanitizer_symbolizer.h"
#include "sanitizer_flags.h"
using namespace __sanitizer;
static const u64 kMagic64 = 0xC0BFFFFFFFFFFF64ULL;
static const u64 kMagic32 = 0xC0BFFFFFFFFFFF32ULL;
static const uptr kNumWordsForMagic = SANITIZER_WORDSIZE == 64 ? 1 : 2;

View File

@@ -328,6 +328,17 @@ inline void Trap() {
} // namespace __sanitizer
using namespace __sanitizer; // NOLINT
namespace __asan { using namespace __sanitizer; } // NOLINT
namespace __dsan { using namespace __sanitizer; } // NOLINT
namespace __dfsan { using namespace __sanitizer; } // NOLINT
namespace __esan { using namespace __sanitizer; } // NOLINT
namespace __lsan { using namespace __sanitizer; } // NOLINT
namespace __msan { using namespace __sanitizer; } // NOLINT
namespace __tsan { using namespace __sanitizer; } // NOLINT
namespace __scudo { using namespace __sanitizer; } // NOLINT
namespace __ubsan { using namespace __sanitizer; } // NOLINT
namespace __xray { using namespace __sanitizer; } // NOLINT
namespace __interception { using namespace __sanitizer; } // NOLINT
#endif // SANITIZER_DEFS_H

View File

@@ -39,17 +39,21 @@ char **GetEnviron();
} // namespace __sanitizer
extern "C" {
static char __crashreporter_info_buff__[kErrorMessageBufferSize] = {};
static char __crashreporter_info_buff__[__sanitizer::kErrorMessageBufferSize] =
{};
static const char *__crashreporter_info__ __attribute__((__used__)) =
&__crashreporter_info_buff__[0];
asm(".desc ___crashreporter_info__, 0x10");
} // extern "C"
namespace __sanitizer {
static BlockingMutex crashreporter_info_mutex(LINKER_INITIALIZED);
INLINE void CRAppendCrashLogMessage(const char *msg) {
BlockingMutexLock l(&crashreporter_info_mutex);
internal_strlcat(__crashreporter_info_buff__, msg,
sizeof(__crashreporter_info_buff__)); }
} // namespace __sanitizer
#endif // SANITIZER_MAC
#endif // SANITIZER_MAC_H

View File

@@ -55,6 +55,8 @@
#include <linux/perf_event.h>
#endif
using namespace __sanitizer;
namespace __sanitizer {
#if !SANITIZER_ANDROID
unsigned struct_statfs64_sz = sizeof(struct statfs64);

View File

@@ -937,6 +937,8 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr);
const int si_SEGV_ACCERR = SEGV_ACCERR;
} // namespace __sanitizer
using namespace __sanitizer;
COMPILER_CHECK(sizeof(__sanitizer_pthread_attr_t) >= sizeof(pthread_attr_t));
COMPILER_CHECK(sizeof(socklen_t) == sizeof(unsigned));

View File

@@ -85,9 +85,9 @@ void BufferedStackTrace::Unwind(u32 max_depth, uptr pc, uptr bp, void *context,
} // namespace __sanitizer
extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE
void __sanitizer_symbolize_pc(uptr pc, const char *fmt, char *out_buf,
uptr out_buf_size) {
void __sanitizer_symbolize_pc(__sanitizer::uptr pc,
const char *fmt, char *out_buf,
__sanitizer::uptr out_buf_size) {
if (!out_buf_size) return;
using namespace __sanitizer;
pc = StackTrace::GetPreviousInstructionPc(pc);

View File

@@ -79,10 +79,10 @@
// thread-local variables used by libc will be shared between the tracer task
// and the thread which spawned it.
COMPILER_CHECK(sizeof(SuspendedThreadID) == sizeof(pid_t));
namespace __sanitizer {
COMPILER_CHECK(sizeof(SuspendedThreadID) == sizeof(pid_t));
// Structure for passing arguments into the tracer thread.
struct TracerThreadArgument {
StopTheWorldCallback callback;

View File

@@ -25,6 +25,8 @@
#include <vector>
#include <set>
using namespace __sanitizer;
// Too slow for debug build
#if !SANITIZER_DEBUG

View File

@@ -25,6 +25,8 @@
# include "sanitizer_common/sanitizer_posix.h"
#endif
using namespace __sanitizer;
// A regression test for internal_memmove() implementation.
TEST(SanitizerCommon, InternalMemmoveRegression) {
char src[] = "Hello World";

View File

@@ -15,5 +15,5 @@
#include "sanitizer_common/sanitizer_libc.h"
extern "C" void _start() {
internal__exit(0);
__sanitizer::internal__exit(0);
}

View File

@@ -19,6 +19,6 @@ int main(int argc, char **argv) {
argv0 = argv[0];
testing::GTEST_FLAG(death_test_style) = "threadsafe";
testing::InitGoogleTest(&argc, argv);
SetCommonFlagsDefaults();
__sanitizer::SetCommonFlagsDefaults();
return RUN_ALL_TESTS();
}

View File

@@ -17,6 +17,7 @@
#define TSAN_INTERFACE_H
#include <sanitizer_common/sanitizer_internal_defs.h>
using __sanitizer::uptr;
// This header should NOT include any other headers.
// All functions in this header are extern "C" and start with __tsan_.

View File

@@ -73,6 +73,8 @@ public:
namespace abi = __cxxabiv1;
using namespace __sanitizer;
// We implement a simple two-level cache for type-checking results. For each
// (vptr,type) pair, a hash is computed. This hash is assumed to be globally
// unique; if it collides, we will get false negatives, but:

View File

@@ -27,6 +27,7 @@ extern const XRaySledEntry __start_xray_instr_map[] __attribute__((weak));
extern const XRaySledEntry __stop_xray_instr_map[] __attribute__((weak));
}
using namespace __sanitizer;
using namespace __xray;
// When set to 'true' this means the XRay runtime has been initialised. We use