| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___CONFIGURATION_ABI_H |
| 11 | #define _LIBCPP___CONFIGURATION_ABI_H |
| 12 | |
| 13 | #include <__config_site> |
| 14 | #include <__configuration/compiler.h> |
| 15 | #include <__configuration/platform.h> |
| 16 | |
| 17 | #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER |
| 18 | # pragma GCC system_header |
| 19 | #endif |
| 20 | |
| 21 | // FIXME: ABI detection should be done via compiler builtin macros. This |
| 22 | // is just a placeholder until Clang implements such macros. For now assume |
| 23 | // that Windows compilers pretending to be MSVC++ target the Microsoft ABI, |
| 24 | // and allow the user to explicitly specify the ABI to handle cases where this |
| 25 | // heuristic falls short. |
| 26 | #if _LIBCPP_ABI_FORCE_ITANIUM && _LIBCPP_ABI_FORCE_MICROSOFT |
| 27 | # error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be true" |
| 28 | #elif _LIBCPP_ABI_FORCE_ITANIUM |
| 29 | # define _LIBCPP_ABI_ITANIUM |
| 30 | #elif _LIBCPP_ABI_FORCE_MICROSOFT |
| 31 | # define _LIBCPP_ABI_MICROSOFT |
| 32 | #else |
| 33 | // Windows uses the Microsoft ABI |
| 34 | # if defined(_WIN32) && defined(_MSC_VER) |
| 35 | # define _LIBCPP_ABI_MICROSOFT |
| 36 | |
| 37 | // 32-bit ARM uses the Itanium ABI with a few differences (array cookies, etc), |
| 38 | // and so does 64-bit ARM on Apple platforms. |
| 39 | # elif defined(__arm__) || (defined(__APPLE__) && defined(__aarch64__)) |
| 40 | # define _LIBCPP_ABI_ITANIUM_WITH_ARM_DIFFERENCES |
| 41 | |
| 42 | // Non-Apple 64-bit ARM uses the vanilla Itanium ABI |
| 43 | # elif defined(__aarch64__) |
| 44 | # define _LIBCPP_ABI_ITANIUM |
| 45 | |
| 46 | // We assume that other architectures also use the vanilla Itanium ABI too |
| 47 | # else |
| 48 | # define _LIBCPP_ABI_ITANIUM |
| 49 | # endif |
| 50 | #endif |
| 51 | |
| 52 | #if _LIBCPP_ABI_VERSION >= 2 |
| 53 | // TODO: Move the description of the remaining ABI flags to ABIGuarantees.rst or remove them. |
| 54 | |
| 55 | // Override the default return value of exception::what() for bad_function_call::what() |
| 56 | // with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). |
| 57 | // This is an ABI break on platforms that sign and authenticate vtable function pointers |
| 58 | // because it changes the mangling of the virtual function located in the vtable, which |
| 59 | // changes how it gets signed. |
| 60 | # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE |
| 61 | // According to the Standard, `bitset::operator[] const` returns bool |
| 62 | # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL |
| 63 | |
| 64 | // These flags are documented in ABIGuarantees.rst |
| 65 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 66 | # define _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE |
| 67 | # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI |
| 68 | # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI |
| 69 | # define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION |
| 70 | # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE |
| 71 | # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE |
| 72 | # define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE |
| 73 | # define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING |
| 74 | # define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE |
| 75 | # define _LIBCPP_ABI_NO_ITERATOR_BASES |
| 76 | # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT |
| 77 | # define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER |
| 78 | # define _LIBCPP_ABI_OPTIMIZED_FUNCTION |
| 79 | # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 80 | # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
| 81 | # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY |
| 82 | # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW |
| 83 | # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION |
| 84 | # define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR |
| 85 | |
| 86 | #elif _LIBCPP_ABI_VERSION == 1 |
| 87 | // Feature macros for disabling pre ABI v1 features. All of these options |
| 88 | // are deprecated. |
| 89 | # if defined(__FreeBSD__) |
| 90 | # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR |
| 91 | # endif |
| 92 | #endif |
| 93 | |
| 94 | // TODO(LLVM 22): Remove this check |
| 95 | #if defined(_LIBCPP_ABI_NO_ITERATOR_BASES) && !defined(_LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER) |
| 96 | # ifndef _LIBCPP_ONLY_NO_ITERATOR_BASES |
| 97 | # error "You probably want to define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER. This has been split out from" \ |
| 98 | " _LIBCPP_ABI_NO_ITERATOR_BASES to allow only removing the second iterator member, since they aren't really related." \ |
| 99 | "If you actually want this ABI configuration, please define _LIBCPP_ONLY_NO_ITERATOR_BASES instead." |
| 100 | # endif |
| 101 | #endif |
| 102 | |
| 103 | // We had some bugs where we use [[no_unique_address]] together with construct_at, |
| 104 | // which causes UB as the call on construct_at could write to overlapping subobjects |
| 105 | // |
| 106 | // https://llvm.org/PR70506 |
| 107 | // https://llvm.org/PR70494 |
| 108 | // |
| 109 | // To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. |
| 110 | // The macro below is used for all classes whose ABI have changed as part of fixing these bugs. |
| 111 | #define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) |
| 112 | |
| 113 | // [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work. |
| 114 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING) |
| 115 | # define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING |
| 116 | #endif |
| 117 | |
| 118 | // Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds. |
| 119 | // Note that limited bounds checking is also available outside of this ABI configuration, but only some categories |
| 120 | // of types can be checked. |
| 121 | // |
| 122 | // ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase. |
| 123 | // This also affects the representation of a few library types that use std::unique_ptr |
| 124 | // internally, such as the unordered containers. |
| 125 | // #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR |
| 126 | |
| 127 | #if defined(_LIBCPP_COMPILER_CLANG_BASED) |
| 128 | # if defined(__APPLE__) |
| 129 | # if defined(__i386__) || defined(__x86_64__) |
| 130 | // use old string layout on x86_64 and i386 |
| 131 | # elif defined(__arm__) |
| 132 | // use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs |
| 133 | # if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 |
| 134 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 135 | # endif |
| 136 | # else |
| 137 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 138 | # endif |
| 139 | # endif |
| 140 | #endif |
| 141 | |
| 142 | #endif // _LIBCPP___CONFIGURATION_ABI_H |
| 143 | |