1 1.1 christos /* tc-aarch64.h -- Header file for tc-aarch64.c. 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 GAS. 6 1.1 christos 7 1.1 christos GAS 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 GAS 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 christos #ifndef TC_AARCH64 22 1.1 christos #define TC_AARCH64 1 23 1.1 christos 24 1.1 christos #include "opcode/aarch64.h" 25 1.1 christos 26 1.1 christos #ifndef TARGET_BYTES_BIG_ENDIAN 27 1.1 christos #define TARGET_BYTES_BIG_ENDIAN 0 28 1.1 christos #endif 29 1.1 christos 30 1.1 christos #define WORKING_DOT_WORD 31 1.1 christos 32 1.1 christos #define TARGET_ARCH bfd_arch_aarch64 33 1.1 christos 34 1.1 christos #define DIFF_EXPR_OK 35 1.1 christos 36 1.1 christos /* Permit // comments. */ 37 1.1 christos #define DOUBLESLASH_LINE_COMMENTS 38 1.1 christos 39 1.1 christos #ifdef LITTLE_ENDIAN 40 1.1 christos #undef LITTLE_ENDIAN 41 1.1 christos #endif 42 1.1 christos 43 1.1 christos #ifdef BIG_ENDIAN 44 1.1 christos #undef BIG_ENDIAN 45 1.1 christos #endif 46 1.1 christos 47 1.1 christos #define LITTLE_ENDIAN 1234 48 1.1 christos #define BIG_ENDIAN 4321 49 1.1 christos 50 1.1 christos #define SWAP_32(n) \ 51 1.1 christos ((((n) & 0xff) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) \ 52 1.1 christos | (((n) >> 24) & 0xff)) 53 1.1 christos 54 1.1 christos struct fix; 55 1.1 christos 56 1.1 christos struct aarch64_fix 57 1.1 christos { 58 1.1 christos struct aarch64_inst *inst; 59 1.1 christos enum aarch64_opnd opnd; 60 1.1 christos }; 61 1.1 christos 62 1.1.1.7 christos #ifdef OBJ_ELF 63 1.1 christos # define AARCH64_BI_ENDIAN 64 1.1 christos # define TARGET_FORMAT elf64_aarch64_target_format () 65 1.1.1.7 christos #elif defined (OBJ_COFF) 66 1.1.1.7 christos # define TARGET_FORMAT coff_aarch64_target_format () 67 1.1 christos #endif 68 1.1 christos 69 1.1 christos #define TC_FORCE_RELOCATION(FIX) aarch64_force_relocation (FIX) 70 1.1 christos 71 1.1 christos /* Currently there is no machine specific frags generated. */ 72 1.1 christos #define md_convert_frag(b,s,f) as_fatal ("aarch64 convert_frag called\n") 73 1.1 christos 74 1.1 christos #define md_cleanup() aarch64_cleanup () 75 1.1 christos 76 1.1 christos #define md_start_line_hook() aarch64_start_line_hook () 77 1.1 christos 78 1.1 christos #define tc_frob_label(S) aarch64_frob_label (S) 79 1.1 christos 80 1.1 christos /* We also need to mark assembler created symbols: */ 81 1.1 christos #define tc_frob_fake_label(S) aarch64_frob_label (S) 82 1.1 christos 83 1.1.1.5 christos #define tc_frob_section(S) aarch64_frob_section (S) 84 1.1.1.5 christos 85 1.1.1.5 christos /* The key used to sign a function's return address. */ 86 1.1.1.5 christos enum pointer_auth_key { 87 1.1.1.5 christos AARCH64_PAUTH_KEY_A, 88 1.1.1.5 christos AARCH64_PAUTH_KEY_B 89 1.1.1.5 christos }; 90 1.1.1.5 christos 91 1.1.1.5 christos /* The extra fields required by AArch64 in fde_entry and cie_entry. Currently 92 1.1.1.5 christos only used to store the key used to sign the frame's return address. */ 93 1.1.1.8 christos #define tc_fde_entry_extras enum pointer_auth_key pauth_key; \ 94 1.1.1.8 christos bool memtag_frame_p; 95 1.1.1.8 christos #define tc_cie_entry_extras enum pointer_auth_key pauth_key; \ 96 1.1.1.8 christos bool memtag_frame_p; 97 1.1.1.5 christos 98 1.1.1.5 christos /* The extra initialisation steps needed by AArch64 in alloc_fde_entry. 99 1.1.1.5 christos Currently only used to initialise the key used to sign the return 100 1.1.1.5 christos address. */ 101 1.1.1.8 christos #define tc_fde_entry_init_extra(fde) \ 102 1.1.1.8 christos do \ 103 1.1.1.8 christos { \ 104 1.1.1.8 christos fde->pauth_key = AARCH64_PAUTH_KEY_A; \ 105 1.1.1.8 christos fde->memtag_frame_p = false; \ 106 1.1.1.8 christos } \ 107 1.1.1.8 christos while (0) 108 1.1.1.5 christos 109 1.1.1.5 christos /* Extra checks required by AArch64 when outputting the current cie_entry. 110 1.1.1.5 christos Currently only used to output a 'B' if the return address is signed with the 111 1.1.1.5 christos B key. */ 112 1.1.1.5 christos #define tc_output_cie_extra(cie) \ 113 1.1.1.5 christos do \ 114 1.1.1.5 christos { \ 115 1.1.1.5 christos if (cie->pauth_key == AARCH64_PAUTH_KEY_B) \ 116 1.1.1.5 christos out_one ('B'); \ 117 1.1.1.8 christos if (cie->memtag_frame_p) \ 118 1.1.1.8 christos out_one ('G'); \ 119 1.1.1.5 christos } \ 120 1.1.1.5 christos while (0) 121 1.1.1.5 christos 122 1.1.1.5 christos /* Extra equivalence checks required by AArch64 when selecting the correct cie 123 1.1.1.8 christos for some fde. Currently used to check for equivalence between - keys used 124 1.1.1.8 christos to sign the return address, and if stack locations have MTE tagging 125 1.1.1.8 christos enabled. */ 126 1.1.1.8 christos #define tc_cie_fde_equivalent_extra(cie, fde) \ 127 1.1.1.8 christos ((cie->pauth_key == fde->pauth_key) \ 128 1.1.1.8 christos && (cie->memtag_frame_p == fde->memtag_frame_p)) 129 1.1.1.5 christos 130 1.1.1.5 christos /* The extra initialisation steps needed by AArch64 in select_cie_for_fde. 131 1.1.1.5 christos Currently only used to initialise the key used to sign the return 132 1.1.1.5 christos address. */ 133 1.1.1.8 christos #define tc_cie_entry_init_extra(cie, fde) \ 134 1.1.1.8 christos do \ 135 1.1.1.8 christos { \ 136 1.1.1.8 christos cie->pauth_key = fde->pauth_key; \ 137 1.1.1.8 christos cie->memtag_frame_p = fde->memtag_frame_p; \ 138 1.1.1.8 christos } \ 139 1.1.1.8 christos while (0) 140 1.1.1.5 christos 141 1.1 christos #define TC_FIX_TYPE struct aarch64_fix 142 1.1 christos #define TC_INIT_FIX_DATA(FIX) { (FIX)->tc_fix_data.inst = NULL; \ 143 1.1 christos (FIX)->tc_fix_data.opnd = AARCH64_OPND_NIL; } 144 1.1 christos 145 1.1 christos #define TC_SYMFIELD_TYPE unsigned int 146 1.1 christos #define AARCH64_GET_FLAG(s) (*symbol_get_tc (s)) 147 1.1 christos 148 1.1 christos void aarch64_copy_symbol_attributes (symbolS *, symbolS *); 149 1.1 christos #ifndef TC_COPY_SYMBOL_ATTRIBUTES 150 1.1 christos #define TC_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \ 151 1.1 christos (aarch64_copy_symbol_attributes (DEST, SRC)) 152 1.1 christos #endif 153 1.1 christos 154 1.1.1.5 christos #ifdef OBJ_ELF 155 1.1.1.8 christos /* Don't copy st_other. 156 1.1.1.8 christos This is needed so AArch64 specific st_other values can be independently 157 1.1.1.8 christos specified for an IFUNC resolver (that is called by the dynamic linker) 158 1.1.1.8 christos and the symbol it resolves (aliased to the resolver). In particular, 159 1.1.1.8 christos if a function symbol has special st_other value set via directives, 160 1.1.1.8 christos then attaching an IFUNC resolver to that symbol should not override 161 1.1.1.8 christos the st_other setting. Requiring the directive on the IFUNC resolver 162 1.1.1.8 christos symbol would be unexpected and problematic in C code, where the two 163 1.1.1.8 christos symbols appear as two independent function declarations. */ 164 1.1.1.5 christos #define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \ 165 1.1.1.8 christos elf_copy_symbol_size (DEST, SRC) 166 1.1.1.5 christos #endif 167 1.1.1.5 christos 168 1.1.1.2 christos #define TC_START_LABEL(STR, NUL_CHAR, NEXT_CHAR) \ 169 1.1.1.2 christos (NEXT_CHAR == ':' || (NEXT_CHAR == '/' && aarch64_data_in_code ())) 170 1.1 christos #define tc_canonicalize_symbol_name(str) aarch64_canonicalize_symbol_name (str); 171 1.1 christos #define obj_adjust_symtab() aarch64_adjust_symtab () 172 1.1 christos 173 1.1 christos #define LISTING_HEADER "AARCH64 GAS " 174 1.1 christos 175 1.1 christos #define LOCAL_LABEL(name) (name[0] == '.' && name[1] == 'L') 176 1.1 christos #define LOCAL_LABELS_FB 1 177 1.1 christos 178 1.1 christos /* This expression evaluates to true if the relocation is for a local 179 1.1 christos object for which we still want to do the relocation at runtime. 180 1.1 christos False if we are willing to perform this relocation while building 181 1.1 christos the .o file. GOTOFF does not need to be checked here because it is 182 1.1 christos not pcrel. I am not sure if some of the others are ever used with 183 1.1 christos pcrel, but it is easier to be safe than sorry. */ 184 1.1 christos 185 1.1 christos #define TC_FORCE_RELOCATION_LOCAL(FIX) \ 186 1.1.1.4 christos (GENERIC_FORCE_RELOCATION_LOCAL (FIX) \ 187 1.1 christos || (FIX)->fx_r_type == BFD_RELOC_64 \ 188 1.1.1.4 christos || (FIX)->fx_r_type == BFD_RELOC_32) 189 1.1 christos 190 1.1.1.2 christos #define TC_CONS_FIX_NEW(f,w,s,e,r) cons_fix_new_aarch64 ((f), (w), (s), (e)) 191 1.1 christos 192 1.1 christos /* For frags in code sections we need to record whether they contain 193 1.1 christos code or data. */ 194 1.1 christos struct aarch64_frag_type 195 1.1 christos { 196 1.1 christos int recorded; 197 1.1.1.7 christos #if defined OBJ_ELF || defined OBJ_COFF 198 1.1 christos /* If there is a mapping symbol at offset 0 in this frag, 199 1.1 christos it will be saved in FIRST_MAP. If there are any mapping 200 1.1 christos symbols in this frag, the last one will be saved in 201 1.1 christos LAST_MAP. */ 202 1.1 christos symbolS *first_map, *last_map; 203 1.1 christos #endif 204 1.1 christos }; 205 1.1 christos 206 1.1 christos #define TC_FRAG_TYPE struct aarch64_frag_type 207 1.1.1.5 christos #define TC_FRAG_INIT(fragp, max_bytes) aarch64_init_frag (fragp, max_bytes) 208 1.1.1.8 christos #define HANDLE_ALIGN(sec, fragp) aarch64_handle_align (fragp) 209 1.1.1.8 christos /* Max space for a rs_align_code fragment is 3 unaligned bytes 210 1.1.1.8 christos (fr_fix) plus 4 bytes to contain the repeating NOP (fr_var). */ 211 1.1.1.8 christos #define MAX_MEM_FOR_RS_ALIGN_CODE(p2align, max) (3 + 4) 212 1.1 christos 213 1.1 christos #define md_do_align(N, FILL, LEN, MAX, LABEL) \ 214 1.1 christos if (FILL == NULL && (N) != 0 && ! need_pass_2 && subseg_text_p (now_seg)) \ 215 1.1 christos { \ 216 1.1.1.2 christos frag_align_code (N, MAX); \ 217 1.1 christos goto LABEL; \ 218 1.1 christos } 219 1.1 christos 220 1.1.1.7 christos /* COFF sub section alignment calculated using the write.c implementation. */ 221 1.1.1.7 christos #ifndef OBJ_COFF 222 1.1.1.2 christos #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 223 1.1.1.7 christos #endif 224 1.1.1.2 christos 225 1.1.1.2 christos #define DWARF2_LINE_MIN_INSN_LENGTH 4 226 1.1 christos 227 1.1 christos /* The lr register is r30. */ 228 1.1 christos #define DWARF2_DEFAULT_RETURN_COLUMN 30 229 1.1 christos 230 1.1 christos /* Registers are generally saved at negative offsets to the CFA. */ 231 1.1.1.2 christos #define DWARF2_CIE_DATA_ALIGNMENT (-8) 232 1.1.1.2 christos 233 1.1.1.2 christos extern int aarch64_dwarf2_addr_size (void); 234 1.1.1.2 christos #define DWARF2_ADDR_SIZE(bfd) aarch64_dwarf2_addr_size () 235 1.1 christos 236 1.1.1.7 christos #if defined OBJ_ELF || defined OBJ_COFF 237 1.1 christos #ifdef OBJ_ELF 238 1.1 christos # define obj_frob_symbol(sym, punt) aarch64elf_frob_symbol ((sym), & (punt)) 239 1.1.1.7 christos #endif 240 1.1 christos 241 1.1 christos # define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_" 242 1.1 christos # define TC_SEGMENT_INFO_TYPE struct aarch64_segment_info_type 243 1.1 christos 244 1.1 christos /* This is not really an alignment operation, but it's something we 245 1.1 christos need to do at the same time: whenever we are figuring out the 246 1.1 christos alignment for data, we should check whether a $d symbol is 247 1.1 christos necessary. */ 248 1.1 christos # define md_cons_align(nbytes) mapping_state (MAP_DATA) 249 1.1 christos 250 1.1 christos enum mstate 251 1.1 christos { 252 1.1 christos MAP_UNDEFINED = 0, /* Must be zero, for seginfo in new sections. */ 253 1.1 christos MAP_DATA, 254 1.1 christos MAP_INSN, 255 1.1 christos }; 256 1.1 christos 257 1.1 christos void mapping_state (enum mstate); 258 1.1 christos 259 1.1 christos struct aarch64_segment_info_type 260 1.1 christos { 261 1.1.1.6 christos const char *last_file; 262 1.1.1.6 christos unsigned last_line; 263 1.1 christos enum mstate mapstate; 264 1.1 christos unsigned int marked_pr_dependency; 265 1.1.1.5 christos aarch64_instr_sequence insn_sequence; 266 1.1 christos }; 267 1.1 christos 268 1.1 christos /* We want .cfi_* pseudo-ops for generating unwind info. */ 269 1.1 christos #define TARGET_USE_CFIPOP 1 270 1.1 christos 271 1.1 christos /* CFI hooks. */ 272 1.1 christos #define tc_regname_to_dw2regnum tc_aarch64_regname_to_dw2regnum 273 1.1 christos #define tc_cfi_frame_initial_instructions tc_aarch64_frame_initial_instructions 274 1.1 christos 275 1.1.1.4 christos extern void aarch64_after_parse_args (void); 276 1.1.1.4 christos #define md_after_parse_args() aarch64_after_parse_args () 277 1.1.1.4 christos 278 1.1 christos # define EXTERN_FORCE_RELOC 1 279 1.1.1.9 christos # define tc_fix_adjustable(FIX) aarch64_fix_adjustable (FIX) 280 1.1.1.7 christos 281 1.1 christos /* Values passed to md_apply_fix don't include the symbol value. */ 282 1.1 christos # define MD_APPLY_SYM_VALUE(FIX) 0 283 1.1 christos 284 1.1.1.7 christos #else /* Neither OBJ_ELF nor OBJ_COFF. */ 285 1.1.1.7 christos 286 1.1.1.7 christos #define GLOBAL_OFFSET_TABLE_NAME "__GLOBAL_OFFSET_TABLE_" 287 1.1.1.7 christos 288 1.1.1.7 christos #endif /* OBJ_ELF || OBJ_COFF. */ 289 1.1.1.7 christos 290 1.1.1.7 christos #ifdef OBJ_ELF 291 1.1.1.7 christos 292 1.1.1.8 christos #define TARGET_USE_GINSN 1 293 1.1.1.8 christos /* Allow GAS to synthesize DWARF CFI for hand-written asm. 294 1.1.1.8 christos PS: TARGET_USE_CFIPOP is a pre-condition. */ 295 1.1.1.8 christos #define TARGET_USE_SCFI 1 296 1.1.1.8 christos /* Identify the maximum DWARF register number of all the registers being 297 1.1.1.8 christos tracked for SCFI. This is the last DWARF register number of the set 298 1.1.1.8 christos of SP, FP, and all callee-saved registers. For Aarch64, this means 79 299 1.1.1.8 christos because FP/Advanced SIMD v8-v15 are also callee-saved registers. */ 300 1.1.1.8 christos # define SCFI_MAX_REG_ID 79 301 1.1.1.8 christos /* Identify the DWARF register number of the frame-pointer register. */ 302 1.1.1.8 christos # define REG_FP 29 303 1.1.1.8 christos /* Identify the DWARF register number of the link register. */ 304 1.1.1.8 christos # define REG_LR 30 305 1.1.1.8 christos /* Identify the DWARF register number of the stack-pointer register. */ 306 1.1.1.8 christos # define REG_SP 31 307 1.1.1.8 christos 308 1.1.1.8 christos #define SCFI_INIT_CFA_OFFSET 0 309 1.1.1.8 christos 310 1.1.1.8 christos #define SCFI_CALLEE_SAVED_REG_P(dw2reg) aarch64_scfi_callee_saved_p (dw2reg) 311 1.1.1.8 christos extern bool aarch64_scfi_callee_saved_p (uint32_t dw2reg_num); 312 1.1.1.8 christos 313 1.1.1.7 christos /* Whether SFrame stack trace info is supported. */ 314 1.1.1.7 christos extern bool aarch64_support_sframe_p (void); 315 1.1.1.7 christos #define support_sframe_p aarch64_support_sframe_p 316 1.1.1.7 christos 317 1.1.1.8 christos /* The stack pointer DWARF register number for SFrame CFA tracking. */ 318 1.1.1.7 christos extern unsigned int aarch64_sframe_cfa_sp_reg; 319 1.1.1.7 christos #define SFRAME_CFA_SP_REG aarch64_sframe_cfa_sp_reg 320 1.1.1.7 christos 321 1.1.1.8 christos /* The frame pointer DWARF register number for SFrame CFA and FP tracking. */ 322 1.1.1.7 christos extern unsigned int aarch64_sframe_cfa_fp_reg; 323 1.1.1.7 christos #define SFRAME_CFA_FP_REG aarch64_sframe_cfa_fp_reg 324 1.1.1.7 christos 325 1.1.1.8 christos /* The return address DWARF register number for SFrame RA tracking. */ 326 1.1.1.7 christos extern unsigned int aarch64_sframe_cfa_ra_reg; 327 1.1.1.7 christos #define SFRAME_CFA_RA_REG aarch64_sframe_cfa_ra_reg 328 1.1.1.7 christos 329 1.1.1.8 christos /* Whether SFrame return address tracking is needed. */ 330 1.1.1.9 christos #define sframe_ra_tracking_p() true 331 1.1.1.7 christos 332 1.1.1.8 christos /* The fixed offset from CFA for SFrame to recover the return address. 333 1.1.1.8 christos (useful only when SFrame RA tracking is not needed). */ 334 1.1.1.7 christos extern offsetT aarch64_sframe_cfa_ra_offset (void); 335 1.1.1.7 christos #define sframe_cfa_ra_offset aarch64_sframe_cfa_ra_offset 336 1.1.1.7 christos 337 1.1.1.8 christos /* The abi/arch identifier for SFrame. */ 338 1.1.1.7 christos unsigned char aarch64_sframe_get_abi_arch (void); 339 1.1.1.7 christos #define sframe_get_abi_arch aarch64_sframe_get_abi_arch 340 1.1.1.7 christos 341 1.1.1.9 christos /* Whether SFrame FDE of type SFRAME_FDE_TYPE_FLEX be generated. */ 342 1.1.1.9 christos #define sframe_support_flex_fde_p() false 343 1.1.1.9 christos 344 1.1.1.7 christos #endif /* OBJ_ELF */ 345 1.1 christos 346 1.1 christos #define MD_PCREL_FROM_SECTION(F,S) md_pcrel_from_section(F,S) 347 1.1 christos 348 1.1 christos extern void aarch64_frag_align_code (int, int); 349 1.1 christos extern const char * elf64_aarch64_target_format (void); 350 1.1.1.7 christos extern const char * coff_aarch64_target_format (void); 351 1.1 christos extern int aarch64_force_relocation (struct fix *); 352 1.1 christos extern void aarch64_cleanup (void); 353 1.1 christos extern void aarch64_start_line_hook (void); 354 1.1 christos extern void aarch64_frob_label (symbolS *); 355 1.1.1.5 christos extern void aarch64_frob_section (asection *sec); 356 1.1 christos extern int aarch64_data_in_code (void); 357 1.1 christos extern char * aarch64_canonicalize_symbol_name (char *); 358 1.1 christos extern void aarch64_adjust_symtab (void); 359 1.1 christos extern void aarch64elf_frob_symbol (symbolS *, int *); 360 1.1 christos extern void cons_fix_new_aarch64 (fragS *, int, int, expressionS *); 361 1.1 christos extern void aarch64_init_frag (struct frag *, int); 362 1.1 christos extern void aarch64_handle_align (struct frag *); 363 1.1 christos extern int tc_aarch64_regname_to_dw2regnum (char *regname); 364 1.1 christos extern void tc_aarch64_frame_initial_instructions (void); 365 1.1.1.9 christos extern bool aarch64_fix_adjustable (struct fix *); 366 1.1 christos 367 1.1 christos #ifdef TE_PE 368 1.1 christos 369 1.1 christos #define O_secrel O_md1 370 1.1 christos 371 1.1 christos #define TC_DWARF2_EMIT_OFFSET tc_pe_dwarf2_emit_offset 372 1.1 christos void tc_pe_dwarf2_emit_offset (symbolS *, unsigned int); 373 1.1 christos 374 1.1 christos #endif /* TE_PE */ 375 1.1 christos 376 1.1.1.9 christos #ifdef OBJ_ELF 377 1.1.1.9 christos /* The target supports Object Attributes v2. */ 378 1.1.1.9 christos #define TC_OBJ_ATTR_v2 1 379 1.1.1.9 christos #endif /* OBJ_ELF */ 380 1.1.1.9 christos 381 1.1 christos #endif /* TC_AARCH64 */ 382