| 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 | # if defined(_WIN32) && defined(_MSC_VER) |
| 34 | # define _LIBCPP_ABI_MICROSOFT |
| 35 | # else |
| 36 | # define _LIBCPP_ABI_ITANIUM |
| 37 | # endif |
| 38 | #endif |
| 39 | |
| 40 | #if _LIBCPP_ABI_VERSION >= 2 |
| 41 | // TODO: Move the description of the remaining ABI flags to ABIGuarantees.rst or remove them. |
| 42 | |
| 43 | // Override the default return value of exception::what() for bad_function_call::what() |
| 44 | // with a string that is specific to bad_function_call (see http://wg21.link/LWG2233). |
| 45 | // This is an ABI break on platforms that sign and authenticate vtable function pointers |
| 46 | // because it changes the mangling of the virtual function located in the vtable, which |
| 47 | // changes how it gets signed. |
| 48 | # define _LIBCPP_ABI_BAD_FUNCTION_CALL_GOOD_WHAT_MESSAGE |
| 49 | // According to the Standard, `bitset::operator[] const` returns bool |
| 50 | # define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL |
| 51 | |
| 52 | // In LLVM 20, we've changed to take these ABI breaks unconditionally. These flags only exist in case someone is running |
| 53 | // into the static_asserts we added to catch the ABI break and don't care that it is one. |
| 54 | // TODO(LLVM 22): Remove these flags |
| 55 | # define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB |
| 56 | # define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB |
| 57 | # define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB |
| 58 | # define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB |
| 59 | |
| 60 | // These flags are documented in ABIGuarantees.rst |
| 61 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 62 | # define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON |
| 63 | # define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON |
| 64 | # define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10 |
| 65 | # define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI |
| 66 | # define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI |
| 67 | # define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION |
| 68 | # define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE |
| 69 | # define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE |
| 70 | # define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE |
| 71 | # define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING |
| 72 | # define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE |
| 73 | # define _LIBCPP_ABI_NO_ITERATOR_BASES |
| 74 | # define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT |
| 75 | # define _LIBCPP_ABI_OPTIMIZED_FUNCTION |
| 76 | # define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 77 | # define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
| 78 | # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY |
| 79 | # define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW |
| 80 | # define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION |
| 81 | |
| 82 | #elif _LIBCPP_ABI_VERSION == 1 |
| 83 | # if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF)) |
| 84 | // Enable compiling copies of now inline methods into the dylib to support |
| 85 | // applications compiled against older libraries. This is unnecessary with |
| 86 | // COFF dllexport semantics, since dllexport forces a non-inline definition |
| 87 | // of inline functions to be emitted anyway. Our own non-inline copy would |
| 88 | // conflict with the dllexport-emitted copy, so we disable it. For XCOFF, |
| 89 | // the linker will take issue with the symbols in the shared object if the |
| 90 | // weak inline methods get visibility (such as from -fvisibility-inlines-hidden), |
| 91 | // so disable it. |
| 92 | # define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS |
| 93 | # endif |
| 94 | // Feature macros for disabling pre ABI v1 features. All of these options |
| 95 | // are deprecated. |
| 96 | # if defined(__FreeBSD__) |
| 97 | # define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR |
| 98 | # endif |
| 99 | #endif |
| 100 | |
| 101 | // We had some bugs where we use [[no_unique_address]] together with construct_at, |
| 102 | // which causes UB as the call on construct_at could write to overlapping subobjects |
| 103 | // |
| 104 | // https://github.com/llvm/llvm-project/issues/70506 |
| 105 | // https://github.com/llvm/llvm-project/issues/70494 |
| 106 | // |
| 107 | // To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions. |
| 108 | // The macro below is used for all classes whose ABI have changed as part of fixing these bugs. |
| 109 | #define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua"))) |
| 110 | |
| 111 | // [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work. |
| 112 | #if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING) |
| 113 | # define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING |
| 114 | #endif |
| 115 | |
| 116 | // Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds. |
| 117 | // Note that limited bounds checking is also available outside of this ABI configuration, but only some categories |
| 118 | // of types can be checked. |
| 119 | // |
| 120 | // ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase. |
| 121 | // This also affects the representation of a few library types that use std::unique_ptr |
| 122 | // internally, such as the unordered containers. |
| 123 | // #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR |
| 124 | |
| 125 | #if defined(_LIBCPP_COMPILER_CLANG_BASED) |
| 126 | # if defined(__APPLE__) |
| 127 | # if defined(__i386__) || defined(__x86_64__) |
| 128 | // use old string layout on x86_64 and i386 |
| 129 | # elif defined(__arm__) |
| 130 | // use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs |
| 131 | # if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2 |
| 132 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 133 | # endif |
| 134 | # else |
| 135 | # define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 136 | # endif |
| 137 | # endif |
| 138 | #endif |
| 139 | |
| 140 | #endif // _LIBCPP___CONFIGURATION_ABI_H |
| 141 | |