1 /* $NetBSD: elf_machdep.h,v 1.8 2025/11/28 19:12:58 jkoshy Exp $ */ 2 3 /*- 4 * Copyright (c) 2014 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Matt Thomas of 3am Software Foundry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _AARCH64_ELF_MACHDEP_H_ 33 #define _AARCH64_ELF_MACHDEP_H_ 34 35 #ifdef __aarch64__ 36 37 #if !defined(_SYS_ELFDEFINITIONS_H_) 38 /* 39 * Symbols that are part of the ELF psABI. 40 */ 41 42 /* Processor specific flags for the ELF header e_flags field. */ 43 #define EF_ARM_RELEXEC 0x00000001 44 #define EF_ARM_HASENTRY 0x00000002 45 #define EF_ARM_INTERWORK 0x00000004 /* GNU binutils 000413 */ 46 #define EF_ARM_SYMSARESORTED 0x00000004 /* ARM ELF A08 */ 47 #define EF_ARM_APCS_26 0x00000008 /* GNU binutils 000413 */ 48 #define EF_ARM_DYNSYMSUSESEGIDX 0x00000008 /* ARM ELF B01 */ 49 #define EF_ARM_APCS_FLOAT 0x00000010 /* GNU binutils 000413 */ 50 #define EF_ARM_MAPSYMSFIRST 0x00000010 /* ARM ELF B01 */ 51 #define EF_ARM_PIC 0x00000020 52 #define EF_ARM_ALIGN8 0x00000040 /* 8-bit structure alignment. */ 53 #define EF_ARM_NEW_ABI 0x00000080 54 #define EF_ARM_OLD_ABI 0x00000100 55 #define EF_ARM_SOFT_FLOAT 0x00000200 56 #define EF_ARM_BE8 0x00800000 57 #define EF_ARM_EABIMASK 0xff000000 58 #define EF_ARM_EABI_VER1 0x01000000 59 #define EF_ARM_EABI_VER2 0x02000000 60 #define EF_ARM_EABI_VER3 0x03000000 61 #define EF_ARM_EABI_VER4 0x04000000 62 #define EF_ARM_EABI_VER5 0x05000000 63 64 /* Processor specific relocation types */ 65 66 #define R_AARCH64_NONE 0 67 #define R_AARCH64_NONE2 256 68 69 #define R_AARCH64_ABS64 257 /* S + A */ 70 #define R_AARCH64_ABS32 258 /* S + A */ 71 #define R_AARCH64_ABS16 259 /* S + A */ 72 #define R_AARCH64_PREL64 260 /* S + A - P */ 73 #define R_AARCH64_PREL32 261 /* S + A - P */ 74 #define R_AARCH64_PREL16 262 /* S + A - P */ 75 #define R_AARCH64_MOVW_UABS_G0 263 /* S + A [bits 0..15] */ 76 #define R_AARCH64_MOVW_UABS_G0_NC 264 /* S + A [bits 0..15] */ 77 #define R_AARCH64_MOVW_UABS_G1 265 /* S + A [bits 16..31] */ 78 #define R_AARCH64_MOVW_UABS_G1_NC 266 /* S + A [bits 16..31] */ 79 #define R_AARCH64_MOVW_UABS_G2 267 /* S + A [bits 32..47] */ 80 #define R_AARCH64_MOVW_UABS_G2_NC 268 /* S + A [bits 32..47] */ 81 #define R_AARCH64_MOVW_UABS_G3 269 /* S + A [bits 48..63] */ 82 #define R_AARCH64_MOVW_SABS_G0 270 /* S + A [bits 0..15] */ 83 #define R_AARCH64_MOVW_SABS_G1 271 /* S + A [bits 16..31] */ 84 #define R_AARCH64_MOVW_SABS_G2 272 /* S + A [bits 32..47] */ 85 #define R_AARCH64_LD_PREL_LO19 273 /* S + A - P */ 86 #define R_AARCH64_ADR_PREL_LO21 274 /* S + A - P */ 87 #define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page(S + A) - Page(P) */ 88 #define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Page(S + A) - Page(P) */ 89 #define R_AARCH64_ADD_ABS_LO12_NC 277 /* S + A */ 90 #define R_AARCH64_LDST8_ABS_LO12_NC 278 /* S + A */ 91 #define R_AARCH_TSTBR14 279 /* S + A - P */ 92 #define R_AARCH_CONDBR19 281 /* S + A - P */ 93 #define R_AARCH_JUMP26 282 /* S + A - P */ 94 #define R_AARCH_CALL26 283 /* S + A - P */ 95 #define R_AARCH_LDST16_ABS_LO12_NC 284 /* S + A */ 96 #define R_AARCH_LDST32_ABS_LO12_NC 285 /* S + A */ 97 #define R_AARCH_LDST64_ABS_LO12_NC 286 /* S + A */ 98 #define R_AARCH64_MOVW_PREL_G0 287 /* S + A - P */ 99 #define R_AARCH64_MOVW_PREL_G0_NC 288 /* S + A - P */ 100 #define R_AARCH64_MOVW_PREL_G1 289 /* S + A - P */ 101 #define R_AARCH64_MOVW_PREL_G1_NC 290 /* S + A - P */ 102 #define R_AARCH64_MOVW_PREL_G2 291 /* S + A - P */ 103 #define R_AARCH64_MOVW_PREL_G2_NC 292 /* S + A - P */ 104 #define R_AARCH64_MOVW_PREL_G3 293 /* S + A - P */ 105 106 #define R_AARCH64_LDST128_ABS_LO12_NC 299 /* S + A */ 107 #define R_AARCH64_MOVW_GOTOFF_G0 300 /* G(GDAT(S + A)) - GOT */ 108 #define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* G(GDAT(S + A)) - GOT */ 109 #define R_AARCH64_MOVW_GOTOFF_G1 302 /* G(GDAT(S + A)) - GOT */ 110 #define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* G(GDAT(S + A)) - GOT */ 111 #define R_AARCH64_MOVW_GOTOFF_G2 304 /* G(GDAT(S + A)) - GOT */ 112 #define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* G(GDAT(S + A)) - GOT */ 113 #define R_AARCH64_MOVW_GOTOFF_G3 306 /* G(GDAT(S + A)) - GOT */ 114 #define R_AARCH64_GOTREL64 307 /* S + A - GOT */ 115 #define R_AARCH64_GOTREL32 308 /* S + A - GOT */ 116 #define R_AARCH64_GOT_LD_PREL19 309 /* G(GDAT(S + A)) - P */ 117 #define R_AARCH64_LD64_GOTOFF_LO15 310 /* G(GDAT(S + A)) - GOT */ 118 #define R_AARCH64_ADR_GOT_PAGE 311 /* Page(G(GDAT(S + A))) - Page(GOT) */ 119 #define R_AARCH64_LD64_GOT_LO12_NC 312 /* G(GDAT(S + A)) */ 120 #define R_AARCH64_LD64_GOTPAGE_LO15 313 /* G(GDAT(S + A)) - Page(GOT) */ 121 122 #define R_AARCH64_TLSGD_ADR_PREL21 512 /* G(GTLSIDX(S,A)) - P */ 123 #define R_AARCH64_TLSGD_ADR_PAGE21 513 /* Page(G(GTLSIDX(S,A))) - Page(P) */ 124 #define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* G(GTLSIDX(S,A)) */ 125 #define R_AARCH64_TLSGD_MOVW_G1 515 /* G(GTLSIDX(S,A)) - GOT */ 126 #define R_AARCH64_TLSGD_MOVW_G0_NV 516 /* G(GTLSIDX(S,A)) - GOT */ 127 #define R_AARCH64_TLSLD_ADR_PREL21 517 /* G(GLDM(S,A)) - P */ 128 #define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Page(G(GLDM(S))) - Page(P) */ 129 #define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* G(GLDM(S)) */ 130 #define R_AARCH64_TLSLD_MOVW_G1 520 /* G(GLDM(S)) - GOT */ 131 #define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* G(GLDM(S)) - GOT */ 132 #define R_AARCH64_TLSLD_LD_PREL21 522 /* G(GLDM(S)) - P */ 133 #define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* DTPREL(S+A) */ 134 #define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* DTPREL(S+A) */ 135 #define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* DTPREL(S+A) */ 136 #define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* DTPREL(S+A) */ 137 #define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* DTPREL(S+A) */ 138 #define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTPREL(S+A) */ 139 #define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTPREL(S+A) */ 140 #define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* DTPREL(S+A) */ 141 #define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTPREL(S+A) */ 142 #define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* DTPREL(S+A) */ 143 #define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTPREL(S+A) */ 144 #define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* DTPREL(S+A) */ 145 #define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTPREL(S+A) */ 146 #define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* DTPREL(S+A) */ 147 #define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTPREL(S+A) */ 148 #define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* DTPREL(S+A) */ 149 #define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* G(GTPREL(S+A)) - GOT */ 150 #define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* G(GTPREL(S+A)) - GOT */ 151 #define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page(G(GTPREL(S+A))) - Page(P) */ 152 #define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* G(GTPREL(S+A)) */ 153 #define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* G(GTPREL(S+A)) - P */ 154 #define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TPREL(S+A) */ 155 #define R_AARCH64_MOVW_TPREL_G1 545 /* TPREL(S+A) */ 156 #define R_AARCH64_MOVW_TPREL_G1_NC 546 /* TPREL(S+A) */ 157 #define R_AARCH64_MOVW_TPREL_G0 547 /* TPREL(S+A) */ 158 #define R_AARCH64_MOVW_TPREL_G0_NC 548 /* TPREL(S+A) */ 159 #define R_AARCH64_ADD_TPREL_HI12 549 /* TPREL(S+A) */ 160 #define R_AARCH64_ADD_TPREL_LO12 550 /* TPREL(S+A) */ 161 #define R_AARCH64_ADD_TPREL_LO12_NC 551 /* TPREL(S+A) */ 162 #define R_AARCH64_LDST8_TPREL_LO12 552 /* TPREL(S+A) */ 163 #define R_AARCH64_LDST8_TPREL_LO12_NC 553 /* TPREL(S+A) */ 164 #define R_AARCH64_LDST16_TPREL_LO12 554 /* TPREL(S+A) */ 165 #define R_AARCH64_LDST16_TPREL_LO12_NC 555 /* TPREL(S+A) */ 166 #define R_AARCH64_LDST32_TPREL_LO12 556 /* TPREL(S+A) */ 167 #define R_AARCH64_LDST32_TPREL_LO12_NC 557 /* TPREL(S+A) */ 168 #define R_AARCH64_LDST64_TPREL_LO12 558 /* TPREL(S+A) */ 169 #define R_AARCH64_LDST64_TPREL_LO12_NC 559 /* TPREL(S+A) */ 170 #define R_AARCH64_TLSDESC_LD_PREL19 560 /* G(GTLSDESC(S+A)) - P */ 171 #define R_AARCH64_TLSDESC_LD_PREL21 561 /* G(GTLSDESC(S+A)) - P */ 172 #define R_AARCH64_TLSDESC_LD_PAGE21 562 /* Page(G(GTLSDESC(S+A))) - Page(P) */ 173 #define R_AARCH64_TLSDESC_LD64_LO12 563 /* G(GTLSDESC(S+A)) */ 174 #define R_AARCH64_TLSDESC_ADD_LO12 564 /* G(GTLSDESC(S+A)) */ 175 #define R_AARCH64_TLSDESC_OFF_G1 565 /* G(GTLSDESC(S+A)) - GOT */ 176 #define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* G(GTLSDESC(S+A)) - GOT */ 177 #define R_AARCH64_TLSDESC_LDR 567 /* */ 178 #define R_AARCH64_TLSDESC_ADD 568 /* */ 179 #define R_AARCH64_TLSDESC_CALL 569 /* */ 180 #define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TPREL(S+A) */ 181 #define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* TPREL(S+A) */ 182 #define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTPREL(S+A) */ 183 #define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* DTPREL(S+A) */ 184 185 /* Dynamic Relocations */ 186 #define R_AARCH64_P32_COPY 180 187 #define R_AARCH64_P32_GLOB_DAT 181 /* S + A */ 188 #define R_AARCH64_P32_JUMP_SLOT 182 /* S + A */ 189 #define R_AARCH64_P32_RELATIVE 183 /* Delta(S) + A */ 190 #define R_AARCH64_P32_TLS_DTPREL 184 /* DTPREL(S+A) */ 191 #define R_AARCH64_P32_TLS_DTPMOD 185 /* LBM(S) */ 192 #define R_AARCH64_P32_TLS_TPREL 186 /* TPREL(S+A) */ 193 #define R_AARCH64_P32_TLSDESC 187 /* TLSDESC(S+A) */ 194 #define R_AARCH64_P32_IRELATIVE 188 /* Indirect(Delta(S) + A) */ 195 196 #define R_AARCH64_COPY 1024 197 #define R_AARCH64_GLOB_DAT 1025 /* S + A */ 198 #define R_AARCH64_JUMP_SLOT 1026 /* S + A */ 199 #define R_AARCH64_RELATIVE 1027 /* Delta(S) + A */ 200 #define R_AARCH64_TLS_DTPREL64 1028 /* DTPREL(S+A) */ 201 #define R_AARCH64_TLS_DTPMOD64 1029 /* LBM(S) */ 202 #define R_AARCH64_TLS_TPREL64 1030 /* TPREL(S+A) */ 203 #define R_AARCH64_TLSDESC 1031 /* TLSDESC(S+A) */ 204 #define R_AARCH64_IRELATIVE 1032 /* Indirect(Delta(S) + A) */ 205 206 /* Processor specific program header types */ 207 #define PT_AARCH64_ARCHEXT (PT_LOPROC + 0) 208 #define PT_AARCH64_UNWIND (PT_LOPROC + 1) 209 210 /* Processor specific section header flags */ 211 #define SHF_ENTRYSECT 0x10000000 212 #define SHF_COMDEF 0x80000000 213 214 #define SHT_AARCH64_ATTRIBUTES (SHT_LOPROC + 3) 215 216 #endif /* !defined(_SYS_ELFDEFINITIONS_H_) */ 217 218 /* 219 * Local symbols. 220 */ 221 222 #if defined(__AARCH64EB__) 223 #define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB 224 #define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB 225 #else 226 #define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB 227 #define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB 228 #endif 229 230 #define ELF32_MACHDEP_ID_CASES \ 231 case EM_ARM: \ 232 break; 233 234 #define ELF64_MACHDEP_ID_CASES \ 235 case EM_AARCH64: \ 236 break; 237 238 #define ELF64_MACHDEP_ID EM_AARCH64 239 #define ELF32_MACHDEP_ID EM_ARM 240 241 #define KERN_ELFSIZE 64 242 #define ARCH_ELFSIZE 64 /* MD native binary size */ 243 244 245 #define R_TYPE(name) R_AARCH64_ ## name 246 #define R_TLS_TYPE(name) R_AARCH64_ ## name ## 64 247 248 #ifdef _KERNEL 249 #ifdef ELFSIZE 250 #define ELF_MD_PROBE_FUNC ELFNAME2(aarch64_netbsd,probe) 251 #endif 252 253 struct exec_package; 254 255 int aarch64_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, 256 char *, vaddr_t *); 257 int aarch64_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, 258 char *, vaddr_t *); 259 #endif 260 261 #elif defined(__arm__) 262 263 #include <arm/elf_machdep.h> 264 265 #endif 266 267 #endif /* _AARCH64_ELF_MACHDEP_H_ */ 268