1/* ELF program property for x86 ISA level.
2 Copyright (C) 2020 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
30/* ELF program property for x86 ISA level. */
31#ifdef INCLUDE_X86_ISA_LEVEL
32# if defined __x86_64__ || defined __FXSR__ || !defined _SOFT_FLOAT \
33 || defined __MMX__ || defined __SSE__ || defined __SSE2__
34# define ISA_BASELINE GNU_PROPERTY_X86_ISA_1_BASELINE
35# else
36# define ISA_BASELINE 0
37# endif
38
39# if defined __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 \
40 || (defined __x86_64__ && defined __LAHF_SAHF__) \
41 || defined __POPCNT__ || defined __SSE3__ \
42 || defined __SSSE3__ || defined __SSE4_1__ || defined __SSE4_2__
43# define ISA_V2 GNU_PROPERTY_X86_ISA_1_V2
44# else
45# define ISA_V2 0
46# endif
47
48# if defined __AVX__ || defined __AVX2__ || defined __F16C__ \
49 || defined __FMA__ || defined __LZCNT__ || defined __MOVBE__ \
50 || defined __XSAVE__
51# define ISA_V3 GNU_PROPERTY_X86_ISA_1_V3
52# else
53# define ISA_V3 0
54# endif
55
56# if defined __AVX512F__ || defined __AVX512BW__ || defined __AVX512CD__ \
57 || defined __AVX512DQ__ || defined __AVX512VL__
58# define ISA_V4 GNU_PROPERTY_X86_ISA_1_V4
59# else
60# define ISA_V4 0
61# endif
62
63# ifndef ISA_LEVEL
64# define ISA_LEVEL (ISA_BASELINE | ISA_V2 | ISA_V3 | ISA_V4)
65# endif
66
67# if ISA_LEVEL
68# ifdef __LP64__
69# define PROPERTY_ALIGN 3
70# else
71# define PROPERTY_ALIGN 2
72# endif
73
74# define note_stringify(arg) note_stringify_1(arg)
75# define note_stringify_1(arg) #arg
76
77asm(".pushsection \".note.gnu.property\",\"a\",@note\n"
78" .p2align " note_stringify (PROPERTY_ALIGN)
79 /* name length. */
80"\n .long 1f - 0f\n"
81 /* data length. */
82" .long 4f - 1f\n"
83 /* note type: NT_GNU_PROPERTY_TYPE_0. */
84" .long " note_stringify (NT_GNU_PROPERTY_TYPE_0)
85 /* vendor name. */
86"\n0: .asciz \"GNU\"\n"
87"1: .p2align " note_stringify (PROPERTY_ALIGN)
88 /* pr_type: GNU_PROPERTY_X86_ISA_1_NEEDED. */
89"\n .long " note_stringify (GNU_PROPERTY_X86_ISA_1_NEEDED)
90 /* pr_datasz. */
91"\n .long 3f - 2f\n"
92 /* GNU_PROPERTY_X86_ISA_1_V[234]. */
93"2:\n .long " note_stringify (ISA_LEVEL)
94"\n3:\n .p2align " note_stringify (PROPERTY_ALIGN)
95"\n4:\n .popsection");
96# endif /* ISA_LEVEL */
97#endif /* INCLUDE_X86_ISA_LEVEL */
98