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/* zig patch: instead of including __config_site, zig adds -D flags when compiling */
 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// In LLVM 20, we've changed to take these ABI breaks unconditionally. These flags only exist in case someone is running
 65// into the static_asserts we added to catch the ABI break and don't care that it is one.
 66// TODO(LLVM 22): Remove these flags
 67#  define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
 68#  define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
 69#  define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
 70#  define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
 71
 72// These flags are documented in ABIGuarantees.rst
 73#  define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 74#  define _LIBCPP_ABI_DO_NOT_EXPORT_BASIC_STRING_COMMON
 75#  define _LIBCPP_ABI_DO_NOT_EXPORT_VECTOR_BASE_COMMON
 76#  define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
 77#  define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
 78#  define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
 79#  define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
 80#  define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 81#  define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
 82#  define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
 83#  define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
 84#  define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
 85#  define _LIBCPP_ABI_NO_ITERATOR_BASES
 86#  define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
 87#  define _LIBCPP_ABI_OPTIMIZED_FUNCTION
 88#  define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
 89#  define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
 90#  define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
 91#  define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
 92#  define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
 93
 94#elif _LIBCPP_ABI_VERSION == 1
 95#  if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
 96// Enable compiling copies of now inline methods into the dylib to support
 97// applications compiled against older libraries. This is unnecessary with
 98// COFF dllexport semantics, since dllexport forces a non-inline definition
 99// of inline functions to be emitted anyway. Our own non-inline copy would
100// conflict with the dllexport-emitted copy, so we disable it. For XCOFF,
101// the linker will take issue with the symbols in the shared object if the
102// weak inline methods get visibility (such as from -fvisibility-inlines-hidden),
103// so disable it.
104#    define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
105#  endif
106// Feature macros for disabling pre ABI v1 features. All of these options
107// are deprecated.
108#  if defined(__FreeBSD__)
109#    define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
110#  endif
111#endif
112
113// We had some bugs where we use [[no_unique_address]] together with construct_at,
114// which causes UB as the call on construct_at could write to overlapping subobjects
115//
116// https://github.com/llvm/llvm-project/issues/70506
117// https://github.com/llvm/llvm-project/issues/70494
118//
119// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions.
120// The macro below is used for all classes whose ABI have changed as part of fixing these bugs.
121#define _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS __attribute__((__abi_tag__("llvm18_nua")))
122
123// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work.
124#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING)
125#  define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
126#endif
127
128// Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds.
129// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories
130// of types can be checked.
131//
132// ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase.
133//             This also affects the representation of a few library types that use std::unique_ptr
134//             internally, such as the unordered containers.
135// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
136
137#if defined(_LIBCPP_COMPILER_CLANG_BASED)
138#  if defined(__APPLE__)
139#    if defined(__i386__) || defined(__x86_64__)
140// use old string layout on x86_64 and i386
141#    elif defined(__arm__)
142// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
143#      if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
144#        define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
145#      endif
146#    else
147#      define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
148#    endif
149#  endif
150#endif
151
152#endif // _LIBCPP___CONFIGURATION_ABI_H