1 /*===------ cet.h -Control-flow Enforcement Technology  feature ------------===
2  * Add x86 feature with IBT and/or SHSTK bits to ELF program property if they
3  * are enabled. Otherwise, contents in this header file are unused. This file
4  * is mainly design for assembly source code which want to enable CET.
5  *
6  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7  * See https://llvm.org/LICENSE.txt for license information.
8  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9  *
10  *===-----------------------------------------------------------------------===
11  */
12 #ifndef __CET_H
13 #define __CET_H
14 
15 #ifdef __ASSEMBLER__
16 
17 #ifndef __CET__
18 # define _CET_ENDBR
19 #endif
20 
21 #ifdef __CET__
22 
23 # ifdef __LP64__
24 #  if __CET__ & 0x1
25 #    define _CET_ENDBR endbr64
26 #  else
27 #    define _CET_ENDBR
28 #  endif
29 # else
30 #  if __CET__ & 0x1
31 #    define _CET_ENDBR endbr32
32 #  else
33 #    define _CET_ENDBR
34 #  endif
35 # endif
36 
37 
38 #  ifdef __LP64__
39 #   define __PROPERTY_ALIGN 3
40 #  else
41 #   define __PROPERTY_ALIGN 2
42 #  endif
43 
44 	.pushsection ".note.gnu.property", "a"
45 	.p2align __PROPERTY_ALIGN
46 	.long 1f - 0f		/* name length.  */
47 	.long 4f - 1f		/* data length.  */
48 	/* NT_GNU_PROPERTY_TYPE_0.   */
49 	.long 5			/* note type.  */
50 0:
51 	.asciz "GNU"		/* vendor name.  */
52 1:
53 	.p2align __PROPERTY_ALIGN
54 	/* GNU_PROPERTY_X86_FEATURE_1_AND.  */
55 	.long 0xc0000002	/* pr_type.  */
56 	.long 3f - 2f		/* pr_datasz.  */
57 2:
58 	/* GNU_PROPERTY_X86_FEATURE_1_XXX.  */
59 	.long __CET__
60 3:
61 	.p2align __PROPERTY_ALIGN
62 4:
63 	.popsection
64 #endif
65 #endif
66 #endif
67