sanitizer_redefine_builtins.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===-- sanitizer_redefine_builtins.h ---------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Redefine builtin functions to use internal versions. This is needed where
  10. // compiler optimizations end up producing unwanted libcalls!
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef SANITIZER_COMMON_NO_REDEFINE_BUILTINS
  14. # ifndef SANITIZER_REDEFINE_BUILTINS_H
  15. # define SANITIZER_REDEFINE_BUILTINS_H
  16. // The asm hack only works with GCC and Clang.
  17. # if !defined(_WIN32)
  18. asm("memcpy = __sanitizer_internal_memcpy");
  19. asm("memmove = __sanitizer_internal_memmove");
  20. asm("memset = __sanitizer_internal_memset");
  21. # if defined(__cplusplus) && \
  22. !defined(SANITIZER_COMMON_REDEFINE_BUILTINS_IN_STD)
  23. // The builtins should not be redefined in source files that make use of C++
  24. // standard libraries, in particular where C++STL headers with inline functions
  25. // are used. The redefinition in such cases would lead to ODR violations.
  26. //
  27. // Try to break the build in common cases where builtins shouldn't be redefined.
  28. namespace std {
  29. class Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file {
  30. Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file(
  31. const Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file&) = delete;
  32. Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file& operator=(
  33. const Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file&) = delete;
  34. };
  35. using array = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  36. using atomic = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  37. using function = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  38. using map = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  39. using set = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  40. using shared_ptr = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  41. using string = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  42. using unique_ptr = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  43. using unordered_map = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  44. using unordered_set = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  45. using vector = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file;
  46. } // namespace std
  47. # endif // __cpluplus
  48. # endif // !_WIN32
  49. # endif // SANITIZER_REDEFINE_BUILTINS_H
  50. #endif // SANITIZER_COMMON_NO_REDEFINE_BUILTINS