benchtests: Add "workload" traces for powf128
[glibc.git] / sysdeps / x86 / dl-prop.h
blob89911e19e238ff64a080cf787a29e949da133718
1 /* Support for GNU properties. x86 version.
2 Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _DL_PROP_H
20 #define _DL_PROP_H
22 extern void _dl_cet_check (struct link_map *, const char *)
23 attribute_hidden;
24 extern void _dl_cet_open_check (struct link_map *)
25 attribute_hidden;
27 static inline void __attribute__ ((always_inline))
28 _rtld_main_check (struct link_map *m, const char *program)
30 #if CET_ENABLED
31 _dl_cet_check (m, program);
32 #endif
35 static inline void __attribute__ ((always_inline))
36 _dl_open_check (struct link_map *m)
38 #if CET_ENABLED
39 _dl_cet_open_check (m);
40 #endif
43 static inline void __attribute__ ((unused))
44 _dl_process_cet_property_note (struct link_map *l,
45 const ElfW(Nhdr) *note,
46 const ElfW(Addr) size,
47 const ElfW(Addr) align)
49 #if CET_ENABLED
50 /* Skip if we have seen a NT_GNU_PROPERTY_TYPE_0 note before. */
51 if (l->l_cet != lc_unknown)
52 return;
54 /* The NT_GNU_PROPERTY_TYPE_0 note must be aliged to 4 bytes in
55 32-bit objects and to 8 bytes in 64-bit objects. Skip notes
56 with incorrect alignment. */
57 if (align != (__ELF_NATIVE_CLASS / 8))
58 return;
60 const ElfW(Addr) start = (ElfW(Addr)) note;
62 unsigned int feature_1 = 0;
63 unsigned int last_type = 0;
65 while ((ElfW(Addr)) (note + 1) - start < size)
67 /* Find the NT_GNU_PROPERTY_TYPE_0 note. */
68 if (note->n_namesz == 4
69 && note->n_type == NT_GNU_PROPERTY_TYPE_0
70 && memcmp (note + 1, "GNU", 4) == 0)
72 /* Stop if we see more than one GNU property note which may
73 be generated by the older linker. */
74 if (l->l_cet != lc_unknown)
75 return;
77 /* Check CET status now. */
78 l->l_cet = lc_none;
80 /* Check for invalid property. */
81 if (note->n_descsz < 8
82 || (note->n_descsz % sizeof (ElfW(Addr))) != 0)
83 return;
85 /* Start and end of property array. */
86 unsigned char *ptr = (unsigned char *) (note + 1) + 4;
87 unsigned char *ptr_end = ptr + note->n_descsz;
91 unsigned int type = *(unsigned int *) ptr;
92 unsigned int datasz = *(unsigned int *) (ptr + 4);
94 /* Property type must be in ascending order. */
95 if (type < last_type)
96 return;
98 ptr += 8;
99 if ((ptr + datasz) > ptr_end)
100 return;
102 last_type = type;
104 if (type == GNU_PROPERTY_X86_FEATURE_1_AND)
106 /* The size of GNU_PROPERTY_X86_FEATURE_1_AND is 4
107 bytes. When seeing GNU_PROPERTY_X86_FEATURE_1_AND,
108 we stop the search regardless if its size is correct
109 or not. There is no point to continue if this note
110 is ill-formed. */
111 if (datasz != 4)
112 return;
114 feature_1 = *(unsigned int *) ptr;
116 /* Keep searching for the next GNU property note
117 generated by the older linker. */
118 break;
120 else if (type > GNU_PROPERTY_X86_FEATURE_1_AND)
122 /* Stop since property type is in ascending order. */
123 return;
126 /* Check the next property item. */
127 ptr += ALIGN_UP (datasz, sizeof (ElfW(Addr)));
129 while ((ptr_end - ptr) >= 8);
132 /* NB: Note sections like .note.ABI-tag and .note.gnu.build-id are
133 aligned to 4 bytes in 64-bit ELF objects. */
134 note = ((const void *) note
135 + ELF_NOTE_NEXT_OFFSET (note->n_namesz, note->n_descsz,
136 align));
139 /* We get here only if there is one or no GNU property note. */
140 if ((feature_1 & GNU_PROPERTY_X86_FEATURE_1_IBT))
141 l->l_cet |= lc_ibt;
142 if ((feature_1 & GNU_PROPERTY_X86_FEATURE_1_SHSTK))
143 l->l_cet |= lc_shstk;
144 #endif
147 static inline void __attribute__ ((unused))
148 _dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph)
150 const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr);
151 _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align);
154 static inline int __attribute__ ((always_inline))
155 _dl_process_gnu_property (struct link_map *l, uint32_t type, uint32_t datasz,
156 void *data)
158 return 0;
161 #endif /* _DL_PROP_H */