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// According to the Standard, `bitset::operator[] const` returns bool
56# define _LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL
57
58// These flags are documented in ABIGuarantees.rst
59# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
60# define _LIBCPP_ABI_ATOMIC_WAIT_NATIVE_BY_SIZE
61# define _LIBCPP_ABI_ENABLE_SHARED_PTR_TRIVIAL_ABI
62# define _LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI
63# define _LIBCPP_ABI_FIX_CITYHASH_IMPLEMENTATION
64# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
65# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
66# define _LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE
67# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
68# define _LIBCPP_ABI_NO_FILESYSTEM_INLINE_NAMESPACE
69# define _LIBCPP_ABI_NO_ITERATOR_BASES
70# define _LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT
71# define _LIBCPP_ABI_NO_REVERSE_ITERATOR_SECOND_MEMBER
72# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
73# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
74# define _LIBCPP_ABI_VECTOR_LAYOUT_SIZE_BASED
75# define _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION
76# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_ARRAY
77# define _LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW
78# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
79# define _LIBCPP_ABI_TRIVIALLY_COPYABLE_BIT_ITERATOR
80# define _LIBCPP_ABI_USE_SMALL_DEQUE_BLOCK_SIZE
81# define _LIBCPP_ABI_VECTORIZED_MERSENNE_TWISTER_ENGINE
82
83#elif _LIBCPP_ABI_VERSION == 1
84// Feature macros for disabling pre ABI v1 features. All of these options
85// are deprecated.
86# if defined(__FreeBSD__)
87# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
88# endif
89#endif
90
91// We had some bugs where we use [[no_unique_address]] together with construct_at,
92// which causes UB as the call on construct_at could write to overlapping subobjects
93//
94// https://llvm.org/PR70506
95// https://llvm.org/PR70494
96//
97// To fix the bug we had to change the ABI of some classes to remove [[no_unique_address]] under certain conditions.
98// The macro below is used for all classes whose ABI have changed as part of fixing these bugs.
99#define _LIBCPP_LLVM18_NO_UNIQUE_ADDRESS_ABI_TAG __attribute__((__abi_tag__("llvm18_nua")))
100
101// [[msvc::no_unique_address]] seems to mostly affect empty classes, so the padding scheme for Itanium doesn't work.
102#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING)
103# define _LIBCPP_ABI_NO_COMPRESSED_PAIR_PADDING
104#endif
105
106// Tracks the bounds of the array owned by std::unique_ptr<T[]>, allowing it to trap when accessed out-of-bounds.
107// Note that limited bounds checking is also available outside of this ABI configuration, but only some categories
108// of types can be checked.
109//
110// ABI impact: This causes the layout of std::unique_ptr<T[]> to change and its size to increase.
111// This also affects the representation of a few library types that use std::unique_ptr
112// internally, such as the unordered containers.
113// #define _LIBCPP_ABI_BOUNDED_UNIQUE_PTR
114
115#if defined(_LIBCPP_COMPILER_CLANG_BASED)
116# if defined(__APPLE__)
117# if defined(__i386__) || defined(__x86_64__)
118// use old string layout on x86_64 and i386
119# elif defined(__arm__)
120// use old string layout on arm (which does not include aarch64/arm64), except on watch ABIs
121# if defined(__ARM_ARCH_7K__) && __ARM_ARCH_7K__ >= 2
122# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
123# endif
124# else
125# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
126# endif
127# endif
128#endif
129
130#endif // _LIBCPP___CONFIGURATION_ABI_H
131