elfxx-aarch64.h revision 1.1.1.9 1 1.1 christos /* AArch64-specific backend routines.
2 1.1.1.9 christos Copyright (C) 2009-2026 Free Software Foundation, Inc.
3 1.1 christos Contributed by ARM Ltd.
4 1.1 christos
5 1.1 christos This file is part of BFD, the Binary File Descriptor library.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program; see the file COPYING3. If not,
19 1.1 christos see <http://www.gnu.org/licenses/>. */
20 1.1 christos
21 1.1.1.5 christos extern void bfd_elf64_aarch64_init_maps
22 1.1.1.5 christos (bfd *);
23 1.1.1.5 christos
24 1.1.1.5 christos extern void bfd_elf32_aarch64_init_maps
25 1.1.1.5 christos (bfd *);
26 1.1.1.5 christos
27 1.1.1.5 christos /* Types of PLTs based on the level of security. This would be a
28 1.1.1.5 christos bit-mask to denote which of the combinations of security features
29 1.1.1.5 christos are enabled:
30 1.1.1.5 christos - No security feature PLTs
31 1.1.1.5 christos - PLTs with BTI instruction
32 1.1.1.5 christos - PLTs with PAC instruction
33 1.1.1.5 christos */
34 1.1.1.5 christos typedef enum
35 1.1.1.5 christos {
36 1.1.1.5 christos PLT_NORMAL = 0x0, /* Normal plts. */
37 1.1.1.8 christos PLT_BTI = 0x1, /* plts with BTI. */
38 1.1.1.5 christos PLT_PAC = 0x2, /* plts with pointer authentication. */
39 1.1.1.5 christos PLT_BTI_PAC = PLT_BTI | PLT_PAC
40 1.1.1.5 christos } aarch64_plt_type;
41 1.1.1.5 christos
42 1.1.1.8 christos /* Indicates whether the linker should generate warnings, errors, or nothing
43 1.1.1.8 christos when input objects are missing GNU feature property markings and the output
44 1.1.1.8 christos has the markings. */
45 1.1.1.5 christos typedef enum
46 1.1.1.5 christos {
47 1.1.1.8 christos MARKING_NONE = 0, /* Does not emit any warning/error messages. */
48 1.1.1.8 christos MARKING_WARN = 1, /* Emit warning when the input objects are missing GNU
49 1.1.1.8 christos feature property markings, and the output has the
50 1.1.1.8 christos markings. */
51 1.1.1.8 christos MARKING_ERROR = 2, /* Emit error when the input objects are missing GNU
52 1.1.1.8 christos feature property markings, and the output has the
53 1.1.1.8 christos markings. */
54 1.1.1.8 christos MARKING_UNSET = 3, /* The only purpose of this value is to simulate an
55 1.1.1.8 christos optional to detect when the value was not initialized
56 1.1.1.8 christos from the command line. */
57 1.1.1.8 christos } aarch64_feature_marking_report;
58 1.1.1.8 christos
59 1.1.1.8 christos /* To indicate whether GNU_PROPERTY_AARCH64_FEATURE_1_GCS bit is
60 1.1.1.8 christos enabled/disabled on the output when -z gcs linker
61 1.1.1.8 christos command line option is passed. */
62 1.1.1.8 christos typedef enum
63 1.1.1.8 christos {
64 1.1.1.8 christos GCS_NEVER = 0, /* gcs is disabled on output. */
65 1.1.1.8 christos GCS_IMPLICIT = 1, /* gcs is deduced from input object. */
66 1.1.1.8 christos GCS_ALWAYS = 2, /* gsc is enabled on output. */
67 1.1.1.8 christos } aarch64_gcs_type;
68 1.1.1.8 christos
69 1.1.1.8 christos /* A structure to encompass all information about software protections coming
70 1.1.1.8 christos from BTI, PAC and GCS related command line options. */
71 1.1.1.8 christos struct aarch64_protection_opts
72 1.1.1.5 christos {
73 1.1.1.8 christos /* PLT type to use depending on the selected software proctections. */
74 1.1.1.5 christos aarch64_plt_type plt_type;
75 1.1.1.8 christos
76 1.1.1.8 christos /* Report level for BTI issues. */
77 1.1.1.8 christos aarch64_feature_marking_report bti_report;
78 1.1.1.8 christos
79 1.1.1.8 christos /* Look-up mode for GCS property. */
80 1.1.1.8 christos aarch64_gcs_type gcs_type;
81 1.1.1.8 christos
82 1.1.1.8 christos /* Report level for GCS issues. */
83 1.1.1.8 christos aarch64_feature_marking_report gcs_report;
84 1.1.1.8 christos
85 1.1.1.8 christos /* Report level for GCS issues with dynamic inputs. */
86 1.1.1.8 christos aarch64_feature_marking_report gcs_report_dynamic;
87 1.1.1.8 christos };
88 1.1.1.8 christos typedef struct aarch64_protection_opts aarch64_protection_opts;
89 1.1.1.8 christos
90 1.1.1.8 christos struct elf_aarch64_local_symbol;
91 1.1.1.8 christos struct elf_aarch64_obj_tdata
92 1.1.1.8 christos {
93 1.1.1.8 christos struct elf_obj_tdata root;
94 1.1.1.8 christos
95 1.1.1.8 christos /* local symbol descriptors */
96 1.1.1.8 christos struct elf_aarch64_local_symbol *locals;
97 1.1.1.8 christos
98 1.1.1.8 christos /* Zero to warn when linking objects with incompatible enum sizes. */
99 1.1.1.8 christos int no_enum_size_warning;
100 1.1.1.8 christos
101 1.1.1.8 christos /* Zero to warn when linking objects with incompatible wchar_t sizes. */
102 1.1.1.8 christos int no_wchar_size_warning;
103 1.1.1.8 christos
104 1.1.1.8 christos /* All GNU_PROPERTY_AARCH64_FEATURE_1_AND properties. */
105 1.1.1.8 christos uint32_t gnu_property_aarch64_feature_1_and;
106 1.1.1.8 christos
107 1.1.1.8 christos /* Software protections options. */
108 1.1.1.8 christos struct aarch64_protection_opts sw_protections;
109 1.1.1.8 christos
110 1.1.1.9 christos /* The merge of object attributes already occured. */
111 1.1.1.9 christos bool oa_merge_done;
112 1.1.1.9 christos
113 1.1.1.8 christos /* Number of reported BTI issues. */
114 1.1.1.8 christos int n_bti_issues;
115 1.1.1.8 christos
116 1.1.1.8 christos /* Number of reported GCS issues for non-dynamic objects. */
117 1.1.1.8 christos int n_gcs_issues;
118 1.1.1.8 christos
119 1.1.1.8 christos /* Number of reported GCS issues for dynamic objects. */
120 1.1.1.8 christos int n_gcs_dynamic_issues;
121 1.1.1.8 christos };
122 1.1.1.8 christos
123 1.1.1.8 christos #define elf_aarch64_tdata(bfd) \
124 1.1.1.8 christos ((struct elf_aarch64_obj_tdata *) (bfd)->tdata.any)
125 1.1.1.5 christos
126 1.1.1.5 christos /* An enum to define what kind of erratum fixes we should apply. This gives the
127 1.1.1.5 christos user a bit more control over the sequences we generate. */
128 1.1.1.5 christos typedef enum
129 1.1.1.5 christos {
130 1.1.1.5 christos ERRAT_NONE = (1 << 0), /* No erratum workarounds allowed. */
131 1.1.1.5 christos ERRAT_ADR = (1 << 1), /* Erratum workarounds using ADR allowed. */
132 1.1.1.5 christos ERRAT_ADRP = (1 << 2), /* Erratum workarounds using ADRP are allowed. */
133 1.1.1.5 christos } erratum_84319_opts;
134 1.1.1.5 christos
135 1.1.1.8 christos /* An enum to define the various modes of MTE operation.
136 1.1.1.8 christos At this time, except AARCH64_MEMTAG_MODE_NONE, the enumerator constants are
137 1.1.1.8 christos the same as specified in the Memtag ABI Extension to ELF for the Arm 64-bit
138 1.1.1.8 christos Architecture (AArch64) document (the intent being that this keeps the
139 1.1.1.8 christos emission of the associated dynamic tag simple).*/
140 1.1.1.8 christos typedef enum
141 1.1.1.8 christos {
142 1.1.1.8 christos AARCH64_MEMTAG_MODE_SYNC = 0,
143 1.1.1.8 christos AARCH64_MEMTAG_MODE_ASYNC = 1,
144 1.1.1.8 christos AARCH64_MEMTAG_MODE_NONE = 2,
145 1.1.1.8 christos } aarch64_memtag_mode_type;
146 1.1.1.8 christos
147 1.1.1.8 christos /* A structure to encompass all information about memtag feature related
148 1.1.1.8 christos command line options. */
149 1.1.1.8 christos struct aarch64_memtag_opts
150 1.1.1.8 christos {
151 1.1.1.8 christos /* Mode of MTE operation. */
152 1.1.1.8 christos aarch64_memtag_mode_type memtag_mode;
153 1.1.1.8 christos
154 1.1.1.8 christos /* Whether stack accesses use MTE insns. */
155 1.1.1.8 christos unsigned int memtag_stack;
156 1.1.1.8 christos };
157 1.1.1.8 christos
158 1.1.1.8 christos typedef struct aarch64_memtag_opts aarch64_memtag_opts;
159 1.1.1.8 christos
160 1.1.1.5 christos extern void bfd_elf64_aarch64_set_options
161 1.1.1.5 christos (bfd *, struct bfd_link_info *, int, int, int, int, erratum_84319_opts, int,
162 1.1.1.8 christos const aarch64_protection_opts *, const aarch64_memtag_opts *);
163 1.1.1.5 christos
164 1.1.1.5 christos extern void bfd_elf32_aarch64_set_options
165 1.1.1.5 christos (bfd *, struct bfd_link_info *, int, int, int, int, erratum_84319_opts, int,
166 1.1.1.8 christos const aarch64_protection_opts *, const aarch64_memtag_opts *);
167 1.1.1.5 christos
168 1.1.1.5 christos /* AArch64 stub generation support for ELF64. Called from the linker. */
169 1.1.1.5 christos extern int elf64_aarch64_setup_section_lists
170 1.1.1.5 christos (bfd *, struct bfd_link_info *);
171 1.1.1.5 christos extern void elf64_aarch64_next_input_section
172 1.1.1.5 christos (struct bfd_link_info *, struct bfd_section *);
173 1.1.1.6 christos extern bool elf64_aarch64_size_stubs
174 1.1.1.5 christos (bfd *, bfd *, struct bfd_link_info *, bfd_signed_vma,
175 1.1.1.5 christos struct bfd_section * (*) (const char *, struct bfd_section *),
176 1.1.1.5 christos void (*) (void));
177 1.1.1.6 christos extern bool elf64_aarch64_build_stubs
178 1.1.1.5 christos (struct bfd_link_info *);
179 1.1.1.5 christos /* AArch64 stub generation support for ELF32. Called from the linker. */
180 1.1.1.5 christos extern int elf32_aarch64_setup_section_lists
181 1.1.1.5 christos (bfd *, struct bfd_link_info *);
182 1.1.1.5 christos extern void elf32_aarch64_next_input_section
183 1.1.1.5 christos (struct bfd_link_info *, struct bfd_section *);
184 1.1.1.6 christos extern bool elf32_aarch64_size_stubs
185 1.1.1.5 christos (bfd *, bfd *, struct bfd_link_info *, bfd_signed_vma,
186 1.1.1.5 christos struct bfd_section * (*) (const char *, struct bfd_section *),
187 1.1.1.5 christos void (*) (void));
188 1.1.1.6 christos extern bool elf32_aarch64_build_stubs
189 1.1.1.5 christos (struct bfd_link_info *);
190 1.1 christos
191 1.1.1.8 christos /* AArch64 relative relocation packing support for ELF64. */
192 1.1.1.8 christos extern bool elf64_aarch64_size_relative_relocs
193 1.1.1.9 christos (struct bfd_link_info *, bool *) ATTRIBUTE_HIDDEN;
194 1.1.1.8 christos extern bool elf64_aarch64_finish_relative_relocs
195 1.1.1.9 christos (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
196 1.1.1.8 christos /* AArch64 relative relocation packing support for ELF32. */
197 1.1.1.8 christos extern bool elf32_aarch64_size_relative_relocs
198 1.1.1.9 christos (struct bfd_link_info *, bool *) ATTRIBUTE_HIDDEN;
199 1.1.1.8 christos extern bool elf32_aarch64_finish_relative_relocs
200 1.1.1.9 christos (struct bfd_link_info *) ATTRIBUTE_HIDDEN;
201 1.1.1.8 christos
202 1.1 christos /* Take the PAGE component of an address or offset. */
203 1.1.1.3 christos #define PG(x) ((x) & ~ (bfd_vma) 0xfff)
204 1.1 christos #define PG_OFFSET(x) ((x) & (bfd_vma) 0xfff)
205 1.1 christos
206 1.1 christos #define AARCH64_ADR_OP 0x10000000
207 1.1 christos #define AARCH64_ADRP_OP 0x90000000
208 1.1 christos #define AARCH64_ADRP_OP_MASK 0x9F000000
209 1.1 christos
210 1.1 christos extern bfd_signed_vma
211 1.1.1.9 christos _bfd_aarch64_sign_extend (bfd_vma, int) ATTRIBUTE_HIDDEN;
212 1.1 christos
213 1.1 christos extern uint32_t
214 1.1.1.9 christos _bfd_aarch64_decode_adrp_imm (uint32_t) ATTRIBUTE_HIDDEN;
215 1.1 christos
216 1.1 christos extern uint32_t
217 1.1.1.9 christos _bfd_aarch64_reencode_adr_imm (uint32_t, uint32_t) ATTRIBUTE_HIDDEN;
218 1.1 christos
219 1.1 christos extern bfd_reloc_status_type
220 1.1 christos _bfd_aarch64_elf_put_addend (bfd *, bfd_byte *, bfd_reloc_code_real_type,
221 1.1.1.9 christos reloc_howto_type *, bfd_signed_vma)
222 1.1.1.9 christos ATTRIBUTE_HIDDEN;
223 1.1 christos
224 1.1 christos extern bfd_vma
225 1.1.1.5 christos _bfd_aarch64_elf_resolve_relocation (bfd *, bfd_reloc_code_real_type, bfd_vma,
226 1.1.1.9 christos bfd_vma, bfd_vma, bool) ATTRIBUTE_HIDDEN;
227 1.1 christos
228 1.1.1.6 christos extern bool
229 1.1.1.9 christos _bfd_aarch64_elf_grok_prstatus (bfd *, Elf_Internal_Note *) ATTRIBUTE_HIDDEN;
230 1.1 christos
231 1.1.1.6 christos extern bool
232 1.1.1.9 christos _bfd_aarch64_elf_grok_psinfo (bfd *, Elf_Internal_Note *) ATTRIBUTE_HIDDEN;
233 1.1 christos
234 1.1 christos extern char *
235 1.1.1.9 christos _bfd_aarch64_elf_write_core_note (bfd *, char *, int *, int, ...)
236 1.1.1.9 christos ATTRIBUTE_HIDDEN;
237 1.1 christos
238 1.1 christos #define elf_backend_grok_prstatus _bfd_aarch64_elf_grok_prstatus
239 1.1.1.3 christos #define elf_backend_grok_psinfo _bfd_aarch64_elf_grok_psinfo
240 1.1.1.3 christos #define elf_backend_write_core_note _bfd_aarch64_elf_write_core_note
241 1.1.1.5 christos
242 1.1.1.9 christos extern obj_attr_version_t
243 1.1.1.9 christos _bfd_aarch64_obj_attrs_version_dec (uint8_t) ATTRIBUTE_HIDDEN;
244 1.1.1.9 christos
245 1.1.1.9 christos extern uint8_t
246 1.1.1.9 christos _bfd_aarch64_obj_attrs_version_enc (obj_attr_version_t) ATTRIBUTE_HIDDEN;
247 1.1.1.9 christos
248 1.1.1.9 christos extern const known_subsection_v2_t aarch64_obj_attr_v2_known_subsections[2]
249 1.1.1.9 christos ATTRIBUTE_HIDDEN;
250 1.1.1.9 christos
251 1.1.1.9 christos extern bfd *
252 1.1.1.9 christos _bfd_aarch64_elf_link_setup_object_attributes (struct bfd_link_info *)
253 1.1.1.9 christos ATTRIBUTE_HIDDEN;
254 1.1.1.9 christos
255 1.1.1.9 christos extern void
256 1.1.1.9 christos _bfd_aarch64_oav2_record (obj_attr_subsection_v2_t *, Tag_Feature_Set, uint32_t)
257 1.1.1.9 christos ATTRIBUTE_HIDDEN;
258 1.1.1.9 christos
259 1.1.1.9 christos extern void
260 1.1.1.9 christos _bfd_aarch64_translate_gnu_props_to_obj_attrs
261 1.1.1.9 christos (const bfd *, const elf_property_list *) ATTRIBUTE_HIDDEN;
262 1.1.1.9 christos
263 1.1.1.9 christos extern void
264 1.1.1.9 christos _bfd_aarch64_translate_obj_attrs_to_gnu_props
265 1.1.1.9 christos (bfd *, const obj_attr_subsection_v2_t *) ATTRIBUTE_HIDDEN;
266 1.1.1.9 christos
267 1.1.1.9 christos extern bool
268 1.1.1.9 christos _bfd_aarch64_oav2_default_value (const struct bfd_link_info *,
269 1.1.1.9 christos const obj_attr_info_t *,
270 1.1.1.9 christos const obj_attr_subsection_v2_t *,
271 1.1.1.9 christos obj_attr_v2_t *) ATTRIBUTE_HIDDEN;
272 1.1.1.9 christos
273 1.1.1.9 christos extern obj_attr_v2_merge_result_t
274 1.1.1.9 christos _bfd_aarch64_oav2_attr_merge (const struct bfd_link_info *, const bfd *,
275 1.1.1.9 christos const obj_attr_subsection_v2_t *,
276 1.1.1.9 christos const obj_attr_v2_t *, const obj_attr_v2_t *,
277 1.1.1.9 christos const obj_attr_v2_t *) ATTRIBUTE_HIDDEN;
278 1.1.1.9 christos
279 1.1.1.5 christos extern bfd *
280 1.1.1.9 christos _bfd_aarch64_elf_link_setup_gnu_properties (struct bfd_link_info *)
281 1.1.1.9 christos ATTRIBUTE_HIDDEN;
282 1.1.1.5 christos
283 1.1.1.5 christos extern enum elf_property_kind
284 1.1.1.5 christos _bfd_aarch64_elf_parse_gnu_properties (bfd *, unsigned int,
285 1.1.1.9 christos bfd_byte *, unsigned int)
286 1.1.1.9 christos ATTRIBUTE_HIDDEN;
287 1.1.1.5 christos
288 1.1.1.6 christos extern bool
289 1.1.1.5 christos _bfd_aarch64_elf_merge_gnu_properties (struct bfd_link_info *, bfd *,
290 1.1.1.5 christos elf_property *, elf_property *,
291 1.1.1.9 christos uint32_t) ATTRIBUTE_HIDDEN;
292 1.1.1.5 christos
293 1.1.1.5 christos extern void
294 1.1.1.9 christos _bfd_aarch64_elf_check_bti_report (const struct bfd_link_info *, const bfd *)
295 1.1.1.9 christos ATTRIBUTE_HIDDEN;
296 1.1.1.8 christos
297 1.1.1.8 christos extern void
298 1.1.1.9 christos _bfd_aarch64_elf_check_gcs_report (const struct bfd_link_info *, const bfd *)
299 1.1.1.9 christos ATTRIBUTE_HIDDEN;
300 1.1.1.8 christos
301 1.1.1.8 christos extern void
302 1.1.1.5 christos _bfd_aarch64_elf_link_fixup_gnu_properties (struct bfd_link_info *,
303 1.1.1.9 christos elf_property_list **)
304 1.1.1.9 christos ATTRIBUTE_HIDDEN;
305 1.1.1.5 christos
306 1.1.1.5 christos #define elf_backend_parse_gnu_properties \
307 1.1.1.5 christos _bfd_aarch64_elf_parse_gnu_properties
308 1.1.1.5 christos
309 1.1.1.5 christos #define elf_backend_fixup_gnu_properties \
310 1.1.1.5 christos _bfd_aarch64_elf_link_fixup_gnu_properties
311