Skip to content

Commit 384b998

Browse files
committed
Update contrib/libs/cxxsupp/builtins to 21.1.0
commit_hash:9a52feac5a98fb8e7217cb08905b10c5446f996b
1 parent 4077a5a commit 384b998

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+949
-307
lines changed

contrib/libs/cxxsupp/builtins/.yandex_meta/build.ym

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% extends '//builtin/bag.ym' %}
22

3-
{% block current_version %}20.1.8{% endblock %}
3+
{% block current_version %}21.1.0{% endblock %}
44

55
{% block current_url %}
66
https://github.com/llvm/llvm-project/releases/download/llvmorg-{{self.version().strip()}}/compiler-rt-{{self.version().strip()}}.src.tar.xz
@@ -117,7 +117,13 @@ def it_srcs():
117117
if n not in sset:
118118
yield x
119119

120-
yield from set(special) - {'x86_64/floatdixf.c', 'aarch64/sme-libc-routines.c'}
120+
yield from set(special) - {
121+
'x86_64/floatdixf.c',
122+
'aarch64/sme-libc-memcpy-memmove.c',
123+
'aarch64/sme-libc-memset-memchr.c',
124+
'aarch64/sme-libc-opt-memcpy-memmove.S',
125+
'aarch64/sme-libc-opt-memset-memchr.S',
126+
}
121127

122128
print('\n'.join(sorted(list(it_srcs()))).strip())
123129
EOF
@@ -164,7 +170,12 @@ ls aarch64/*.c cpu_model/aarch64.*c aarch64/*.S > special
164170
python3 join.py common special aarch
165171
echo ')'
166172

167-
echo 'IF(NOT OS_DARWIN) SRCS(aarch64/sme-libc-routines.c) ENDIF()'
173+
echo 'IF(NOT OS_DARWIN)'
174+
echo ' SRCS('
175+
echo ' aarch64/sme-libc-opt-memcpy-memmove.S'
176+
echo ' aarch64/sme-libc-opt-memset-memchr.S'
177+
echo ' )'
178+
echo 'ENDIF()'
168179
echo 'ELSEIF (ARCH_X86_64)'
169180
echo 'SRCS('
170181
ls x86_64/*.c cpu_model/x86.*c x86_64/*.S > special

contrib/libs/cxxsupp/builtins/.yandex_meta/devtools.licenses.report

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ BELONGS ya.make
101101
Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0
102102
Files with this license:
103103
aarch64/chkstk.S [1:2]
104+
aarch64/emupac.cpp [3:4]
104105
aarch64/fp_mode.c [3:4]
105106
aarch64/sme-abi-assert.c [1:2]
106107
aarch64/sme-abi.S [1:2]
107-
aarch64/sme-libc-mem-routines.S [1:2]
108+
aarch64/sme-libc-memcpy-memmove.c [3:4]
109+
aarch64/sme-libc-memset-memchr.c [3:4]
110+
aarch64/sme-libc-opt-memcpy-memmove.S [3:4]
111+
aarch64/sme-libc-opt-memset-memchr.S [3:4]
108112
absvdi2.c [3:4]
109113
absvsi2.c [3:4]
110114
absvti2.c [3:4]
@@ -267,6 +271,7 @@ BELONGS ya.make
267271
eprintf.c [3:4]
268272
extendbfsf2.c [3:4]
269273
extenddftf2.c [3:4]
274+
extendhfdf2.c [3:4]
270275
extendhfsf2.c [3:4]
271276
extendhfxf2.c [3:4]
272277
extendsfdf2.c [3:4]
@@ -493,10 +498,14 @@ BELONGS ya.make
493498
Links : http://llvm.org/foundation/relicensing/LICENSE.txt, https://spdx.org/licenses/LLVM-exception
494499
Files with this license:
495500
aarch64/chkstk.S [1:2]
501+
aarch64/emupac.cpp [3:4]
496502
aarch64/fp_mode.c [3:4]
497503
aarch64/sme-abi-assert.c [1:2]
498504
aarch64/sme-abi.S [1:2]
499-
aarch64/sme-libc-mem-routines.S [1:2]
505+
aarch64/sme-libc-memcpy-memmove.c [3:4]
506+
aarch64/sme-libc-memset-memchr.c [3:4]
507+
aarch64/sme-libc-opt-memcpy-memmove.S [3:4]
508+
aarch64/sme-libc-opt-memset-memchr.S [3:4]
500509
absvdi2.c [3:4]
501510
absvsi2.c [3:4]
502511
absvti2.c [3:4]
@@ -659,6 +668,7 @@ BELONGS ya.make
659668
eprintf.c [3:4]
660669
extendbfsf2.c [3:4]
661670
extenddftf2.c [3:4]
671+
extendhfdf2.c [3:4]
662672
extendhfsf2.c [3:4]
663673
extendhfxf2.c [3:4]
664674
extendsfdf2.c [3:4]
@@ -943,10 +953,14 @@ BELONGS ya.make
943953
Links : http://www.apache.org/licenses/, http://www.apache.org/licenses/LICENSE-2.0, https://spdx.org/licenses/Apache-2.0
944954
Files with this license:
945955
aarch64/chkstk.S [3:3]
956+
aarch64/emupac.cpp [5:5]
946957
aarch64/fp_mode.c [5:5]
947958
aarch64/sme-abi-assert.c [3:3]
948959
aarch64/sme-abi.S [3:3]
949-
aarch64/sme-libc-mem-routines.S [3:3]
960+
aarch64/sme-libc-memcpy-memmove.c [5:5]
961+
aarch64/sme-libc-memset-memchr.c [5:5]
962+
aarch64/sme-libc-opt-memcpy-memmove.S [5:5]
963+
aarch64/sme-libc-opt-memset-memchr.S [5:5]
950964
absvdi2.c [5:5]
951965
absvsi2.c [5:5]
952966
absvti2.c [5:5]
@@ -1109,6 +1123,7 @@ BELONGS ya.make
11091123
eprintf.c [5:5]
11101124
extendbfsf2.c [5:5]
11111125
extenddftf2.c [5:5]
1126+
extendhfdf2.c [5:5]
11121127
extendhfsf2.c [5:5]
11131128
extendhfxf2.c [5:5]
11141129
extendsfdf2.c [5:5]
@@ -1335,10 +1350,14 @@ BELONGS ya.make
13351350
Links : http://llvm.org/foundation/relicensing/LICENSE.txt, https://spdx.org/licenses/LLVM-exception
13361351
Files with this license:
13371352
aarch64/chkstk.S [3:3]
1353+
aarch64/emupac.cpp [5:5]
13381354
aarch64/fp_mode.c [5:5]
13391355
aarch64/sme-abi-assert.c [3:3]
13401356
aarch64/sme-abi.S [3:3]
1341-
aarch64/sme-libc-mem-routines.S [3:3]
1357+
aarch64/sme-libc-memcpy-memmove.c [5:5]
1358+
aarch64/sme-libc-memset-memchr.c [5:5]
1359+
aarch64/sme-libc-opt-memcpy-memmove.S [5:5]
1360+
aarch64/sme-libc-opt-memset-memchr.S [5:5]
13421361
absvdi2.c [5:5]
13431362
absvsi2.c [5:5]
13441363
absvti2.c [5:5]
@@ -1501,6 +1520,7 @@ BELONGS ya.make
15011520
eprintf.c [5:5]
15021521
extendbfsf2.c [5:5]
15031522
extenddftf2.c [5:5]
1523+
extendhfdf2.c [5:5]
15041524
extendhfsf2.c [5:5]
15051525
extendhfxf2.c [5:5]
15061526
extendsfdf2.c [5:5]

contrib/libs/cxxsupp/builtins/README.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ switch32
272272
switch8
273273
switchu8
274274

275-
// This function generates a custom trampoline function with the specific
276-
// realFunc and localsPtr values.
277-
void __trampoline_setup(uint32_t* trampOnStack, int trampSizeAllocated,
278-
const void* realFunc, void* localsPtr);
279-
280275
// There is no C interface to the *_vfp_d8_d15_regs functions. There are
281276
// called in the prolog and epilog of Thumb1 functions. When the C++ ABI use
282277
// SJLJ for exceptions, each function with a catch clause or destructors needs

contrib/libs/cxxsupp/builtins/aarch64/chkstk.S

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515
// bl __chkstk
1616
// sub sp, sp, x15, lsl #4
1717

18-
#ifdef __aarch64__
18+
#if defined(__aarch64__) || defined(__arm64ec__)
19+
20+
#ifdef __arm64ec__
21+
#define CHKSTK_FUNC __chkstk_arm64ec
22+
#else
23+
#define CHKSTK_FUNC __chkstk
24+
#endif
1925

2026
#define PAGE_SIZE 4096
2127

2228
.p2align 2
23-
DEFINE_COMPILERRT_FUNCTION(__chkstk)
29+
DEFINE_COMPILERRT_FUNCTION(CHKSTK_FUNC)
2430
lsl x16, x15, #4
2531
mov x17, sp
2632
1:
@@ -30,6 +36,6 @@ DEFINE_COMPILERRT_FUNCTION(__chkstk)
3036
b.gt 1b
3137

3238
ret
33-
END_COMPILERRT_FUNCTION(__chkstk)
39+
END_COMPILERRT_FUNCTION(CHKSTK_FUNC)
3440

35-
#endif // __aarch64__
41+
#endif // defined(__aarch64__) || defined(__arm64ec__)
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
//===--- emupac.cpp - Emulated PAC implementation -------------------------===//
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+
// This file implements Emulated PAC using SipHash_1_3 as the IMPDEF hashing
10+
// scheme.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include <stdint.h>
15+
16+
#include "siphash/SipHash.h"
17+
18+
// EmuPAC implements runtime emulation of PAC instructions. If the current
19+
// CPU supports PAC, EmuPAC uses real PAC instructions. Otherwise, it uses the
20+
// emulation, which is effectively an implementation of PAC with an IMPDEF
21+
// hashing scheme based on SipHash_1_3.
22+
//
23+
// The purpose of the emulation is to allow programs to be built to be portable
24+
// to machines without PAC support, with some performance loss and increased
25+
// probability of false positives (due to not being able to portably determine
26+
// the VA size), while being functionally almost equivalent to running on a
27+
// machine with PAC support. One example of a use case is if PAC is used in
28+
// production as a security mitigation, but the testing environment is
29+
// heterogeneous (i.e. some machines lack PAC support). In this case we would
30+
// like the testing machines to be able to detect issues resulting
31+
// from the use of PAC instructions that would affect production by running
32+
// tests. This can be achieved by building test binaries with EmuPAC and
33+
// production binaries with real PAC.
34+
//
35+
// EmuPAC should not be used in production and is only intended for testing use
36+
// cases. This is not only because of the performance costs, which will exist
37+
// even on PAC-supporting machines because of the function call overhead for
38+
// each sign/auth operation, but because it provides weaker security compared to
39+
// real PAC: the key is constant and public, which means that we do not mix a
40+
// global secret.
41+
//
42+
// The emulation assumes that the VA size is at most 48 bits. The architecture
43+
// as of ARMv8.2, which was the last architecture version in which PAC was not
44+
// mandatory, permitted VA size up to 52 bits via ARMv8.2-LVA, but we are
45+
// unaware of an ARMv8.2 CPU that implemented ARMv8.2-LVA.
46+
47+
static const uint64_t max_va_size = 48;
48+
static const uint64_t pac_mask =
49+
((1ULL << 55) - 1) & ~((1ULL << max_va_size) - 1);
50+
static const uint64_t ttbr1_mask = 1ULL << 55;
51+
52+
// Determine whether PAC is supported without accessing memory. This utilizes
53+
// the XPACLRI instruction which will copy bit 55 of x30 into at least bit 54 if
54+
// PAC is supported and acts as a NOP if PAC is not supported.
55+
static bool pac_supported() {
56+
register uintptr_t x30 __asm__("x30") = 1ULL << 55;
57+
__asm__ __volatile__("xpaclri" : "+r"(x30));
58+
return x30 & (1ULL << 54);
59+
}
60+
61+
#ifdef __GCC_HAVE_DWARF2_CFI_ASM
62+
#define CFI_INST(inst) inst
63+
#else
64+
#define CFI_INST(inst)
65+
#endif
66+
67+
#ifdef __APPLE__
68+
#define ASM_SYMBOL(symbol) "_" #symbol
69+
#else
70+
#define ASM_SYMBOL(symbol) #symbol
71+
#endif
72+
73+
// This asm snippet is used to force the creation of a frame record when
74+
// calling the EmuPAC functions. This is important because the EmuPAC functions
75+
// may crash if an auth failure is detected and may be unwound past using a
76+
// frame pointer based unwinder.
77+
// clang-format off
78+
#define FRAME_POINTER_WRAP(sym) \
79+
CFI_INST(".cfi_startproc\n") \
80+
"stp x29, x30, [sp, #-16]!\n" \
81+
CFI_INST(".cfi_def_cfa_offset 16\n") \
82+
"mov x29, sp\n" \
83+
CFI_INST(".cfi_def_cfa w29, 16\n") \
84+
CFI_INST(".cfi_offset w30, -8\n") \
85+
CFI_INST(".cfi_offset w29, -16\n") \
86+
"bl " ASM_SYMBOL(sym) "\n" \
87+
CFI_INST(".cfi_def_cfa wsp, 16\n") \
88+
"ldp x29, x30, [sp], #16\n" \
89+
CFI_INST(".cfi_def_cfa_offset 0\n") \
90+
CFI_INST(".cfi_restore w30\n") \
91+
CFI_INST(".cfi_restore w29\n") \
92+
"ret\n" \
93+
CFI_INST(".cfi_endproc\n")
94+
// clang-format on
95+
96+
// Emulated DA key value.
97+
static const uint8_t emu_da_key[16] = {0xb5, 0xd4, 0xc9, 0xeb, 0x79, 0x10,
98+
0x4a, 0x79, 0x6f, 0xec, 0x8b, 0x1b,
99+
0x42, 0x87, 0x81, 0xd4};
100+
101+
extern "C" [[gnu::flatten]] uint64_t __emupac_pacda_impl(uint64_t ptr,
102+
uint64_t disc) {
103+
if (pac_supported()) {
104+
__asm__ __volatile__(".arch_extension pauth\npacda %0, %1"
105+
: "+r"(ptr)
106+
: "r"(disc));
107+
return ptr;
108+
}
109+
if (ptr & ttbr1_mask) {
110+
if ((ptr & pac_mask) != pac_mask) {
111+
return ptr | pac_mask;
112+
}
113+
} else {
114+
if (ptr & pac_mask) {
115+
return ptr & ~pac_mask;
116+
}
117+
}
118+
uint64_t hash;
119+
siphash<1, 3>(reinterpret_cast<uint8_t *>(&ptr), 8, emu_da_key,
120+
*reinterpret_cast<uint8_t (*)[8]>(&hash));
121+
return (ptr & ~pac_mask) | (hash & pac_mask);
122+
}
123+
124+
// clang-format off
125+
__asm__(
126+
".globl " ASM_SYMBOL(__emupac_pacda) "\n"
127+
ASM_SYMBOL(__emupac_pacda) ":\n"
128+
FRAME_POINTER_WRAP(__emupac_pacda_impl)
129+
);
130+
// clang-format on
131+
132+
extern "C" [[gnu::flatten]] uint64_t __emupac_autda_impl(uint64_t ptr,
133+
uint64_t disc) {
134+
if (pac_supported()) {
135+
__asm__ __volatile__(".arch_extension pauth\nautda %0, %1"
136+
: "+r"(ptr)
137+
: "r"(disc));
138+
return ptr;
139+
}
140+
uint64_t ptr_without_pac =
141+
(ptr & ttbr1_mask) ? (ptr | pac_mask) : (ptr & ~pac_mask);
142+
uint64_t hash;
143+
siphash<1, 3>(reinterpret_cast<uint8_t *>(&ptr_without_pac), 8, emu_da_key,
144+
*reinterpret_cast<uint8_t (*)[8]>(&hash));
145+
if (((ptr & ~pac_mask) | (hash & pac_mask)) != ptr) {
146+
__builtin_trap();
147+
}
148+
return ptr_without_pac;
149+
}
150+
151+
// clang-format off
152+
__asm__(
153+
".globl " ASM_SYMBOL(__emupac_autda) "\n"
154+
ASM_SYMBOL(__emupac_autda) ":\n"
155+
FRAME_POINTER_WRAP(__emupac_autda_impl)
156+
);
157+
// clang-format on

0 commit comments

Comments
 (0)