| 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 | |
| 17 | // The asm hack only works with GCC and Clang. |
| 18 | # if !defined(_WIN32) && !defined(_AIX) && !defined(__APPLE__) |
| 19 | |
| 20 | # if defined(__hexagon__) |
| 21 | |
| 22 | # define SANITIZER_REDEFINE_BUILTIN_ASM(name) \ |
| 23 | asm(".set " #name ", __sanitizer_internal_" #name) |
| 24 | |
| 25 | # else |
| 26 | |
| 27 | # define SANITIZER_REDEFINE_BUILTIN_ASM(name) \ |
| 28 | asm(#name " = __sanitizer_internal_" #name) |
| 29 | |
| 30 | # endif |
| 31 | |
| 32 | SANITIZER_REDEFINE_BUILTIN_ASM(memcpy); |
| 33 | SANITIZER_REDEFINE_BUILTIN_ASM(memmove); |
| 34 | SANITIZER_REDEFINE_BUILTIN_ASM(memset); |
| 35 | |
| 36 | # undef SANITIZER_REDEFINE_BUILTIN_ASM |
| 37 | |
| 38 | # if defined(__cplusplus) && \ |
| 39 | !defined(SANITIZER_COMMON_REDEFINE_BUILTINS_IN_STD) |
| 40 | |
| 41 | // The builtins should not be redefined in source files that make use of C++ |
| 42 | // standard libraries, in particular where C++STL headers with inline functions |
| 43 | // are used. The redefinition in such cases would lead to ODR violations. |
| 44 | // |
| 45 | // Try to break the build in common cases where builtins shouldn't be redefined. |
| 46 | namespace std { |
| 47 | class Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file { |
| 48 | Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file( |
| 49 | const Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file&) = delete; |
| 50 | Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file& operator=( |
| 51 | const Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file&) = delete; |
| 52 | }; |
| 53 | using array = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 54 | using atomic = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 55 | using function = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 56 | using map = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 57 | using set = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 58 | using shared_ptr = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 59 | using string = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 60 | using unique_ptr = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 61 | using unordered_map = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 62 | using unordered_set = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 63 | using vector = Define_SANITIZER_COMMON_NO_REDEFINE_BUILTINS_in_cpp_file; |
| 64 | } // namespace std |
| 65 | |
| 66 | # endif // __cpluplus |
| 67 | # endif // !_WIN32 |
| 68 | |
| 69 | # endif // SANITIZER_REDEFINE_BUILTINS_H |
| 70 | #endif // SANITIZER_COMMON_NO_REDEFINE_BUILTINS |
| 71 |