1 /* ELF program property for x86 ISA level.
2    Copyright (C) 2020-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    In addition to the permissions in the GNU Lesser General Public
11    License, the Free Software Foundation gives you unlimited
12    permission to link the compiled version of this file with other
13    programs, and to distribute those programs without any restriction
14    coming from the use of this file.  (The Lesser General Public
15    License restrictions do apply in other respects; for example, they
16    cover modification of the file, and distribution when not linked
17    into another program.)
18 
19    The GNU C Library is distributed in the hope that it will be useful,
20    but WITHOUT ANY WARRANTY; without even the implied warranty of
21    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22    Lesser General Public License for more details.
23 
24    You should have received a copy of the GNU Lesser General Public
25    License along with the GNU C Library; if not, see
26    <https://www.gnu.org/licenses/>.  */
27 
28 #include <elf.h>
29 #include <sysdeps/x86/isa-level.h>
30 /* ELF program property for x86 ISA level.  */
31 #ifdef INCLUDE_X86_ISA_LEVEL
32 # if MINIMUM_X86_ISA_LEVEL >= 1
33 /* NB: ISAs, excluding MMX, in x86-64 ISA level baseline are used.  */
34 #  define ISA_BASELINE	GNU_PROPERTY_X86_ISA_1_BASELINE
35 # else
36 #  define ISA_BASELINE	0
37 # endif
38 
39 # if MINIMUM_X86_ISA_LEVEL >= 2
40 /* NB: ISAs in x86-64 ISA level v2 are used.  */
41 #  define ISA_V2	GNU_PROPERTY_X86_ISA_1_V2
42 # else
43 #  define ISA_V2	0
44 # endif
45 
46 # if MINIMUM_X86_ISA_LEVEL >= 3
47 /* NB: ISAs in x86-64 ISA level v3 are used.  */
48 #  define ISA_V3	GNU_PROPERTY_X86_ISA_1_V3
49 # else
50 #  define ISA_V3	0
51 # endif
52 
53 # if MINIMUM_X86_ISA_LEVEL >= 4
54 /* NB: ISAs in x86-64 ISA level v4 are used.  */
55 #  define ISA_V4	GNU_PROPERTY_X86_ISA_1_V4
56 # else
57 #  define ISA_V4	0
58 # endif
59 
60 # ifndef ISA_LEVEL
61 #  define ISA_LEVEL (ISA_BASELINE | ISA_V2 | ISA_V3 | ISA_V4)
62 # endif
63 
64 # if ISA_LEVEL
65 #  ifdef __LP64__
66 #   define PROPERTY_ALIGN 3
67 #  else
68 #   define PROPERTY_ALIGN 2
69 #  endif
70 
71 #  define note_stringify(arg) note_stringify_1(arg)
72 #  define note_stringify_1(arg) #arg
73 
74 asm(".pushsection \".note.gnu.property\",\"a\",@note\n"
75 "	.p2align " note_stringify (PROPERTY_ALIGN)
76 	/* name length.  */
77 "\n	.long 1f - 0f\n"
78 	/* data length.  */
79 "	.long 4f - 1f\n"
80 	/* note type: NT_GNU_PROPERTY_TYPE_0.  */
81 "	.long " note_stringify (NT_GNU_PROPERTY_TYPE_0)
82 	/* vendor name.  */
83 "\n0:	.asciz \"GNU\"\n"
84 "1:	.p2align " note_stringify (PROPERTY_ALIGN)
85 	/* pr_type: GNU_PROPERTY_X86_ISA_1_NEEDED.  */
86 "\n	.long " note_stringify (GNU_PROPERTY_X86_ISA_1_NEEDED)
87 	/* pr_datasz.  */
88 "\n	.long 3f - 2f\n"
89 	/* GNU_PROPERTY_X86_ISA_1_V[234].  */
90 "2:\n	 .long " note_stringify (ISA_LEVEL)
91 "\n3:\n	.p2align " note_stringify (PROPERTY_ALIGN)
92 "\n4:\n .popsection");
93 # endif /* ISA_LEVEL */
94 #endif /* INCLUDE_X86_ISA_LEVEL */
95