1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 ARM Ltd.
11 * ELF register definitions..
13 #include <asm/ptrace.h>
17 * AArch64 static relocation types.
22 #define R_AARCH64_NONE 256
25 #define R_AARCH64_ABS64 257
26 #define R_AARCH64_ABS32 258
27 #define R_AARCH64_ABS16 259
28 #define R_AARCH64_PREL64 260
29 #define R_AARCH64_PREL32 261
30 #define R_AARCH64_PREL16 262
33 #define R_AARCH64_MOVW_UABS_G0 263
34 #define R_AARCH64_MOVW_UABS_G0_NC 264
35 #define R_AARCH64_MOVW_UABS_G1 265
36 #define R_AARCH64_MOVW_UABS_G1_NC 266
37 #define R_AARCH64_MOVW_UABS_G2 267
38 #define R_AARCH64_MOVW_UABS_G2_NC 268
39 #define R_AARCH64_MOVW_UABS_G3 269
41 #define R_AARCH64_MOVW_SABS_G0 270
42 #define R_AARCH64_MOVW_SABS_G1 271
43 #define R_AARCH64_MOVW_SABS_G2 272
45 #define R_AARCH64_LD_PREL_LO19 273
46 #define R_AARCH64_ADR_PREL_LO21 274
47 #define R_AARCH64_ADR_PREL_PG_HI21 275
48 #define R_AARCH64_ADR_PREL_PG_HI21_NC 276
49 #define R_AARCH64_ADD_ABS_LO12_NC 277
50 #define R_AARCH64_LDST8_ABS_LO12_NC 278
52 #define R_AARCH64_TSTBR14 279
53 #define R_AARCH64_CONDBR19 280
54 #define R_AARCH64_JUMP26 282
55 #define R_AARCH64_CALL26 283
56 #define R_AARCH64_LDST16_ABS_LO12_NC 284
57 #define R_AARCH64_LDST32_ABS_LO12_NC 285
58 #define R_AARCH64_LDST64_ABS_LO12_NC 286
59 #define R_AARCH64_LDST128_ABS_LO12_NC 299
61 #define R_AARCH64_MOVW_PREL_G0 287
62 #define R_AARCH64_MOVW_PREL_G0_NC 288
63 #define R_AARCH64_MOVW_PREL_G1 289
64 #define R_AARCH64_MOVW_PREL_G1_NC 290
65 #define R_AARCH64_MOVW_PREL_G2 291
66 #define R_AARCH64_MOVW_PREL_G2_NC 292
67 #define R_AARCH64_MOVW_PREL_G3 293
69 #define R_AARCH64_RELATIVE 1027
72 * These are used to set parameters in the core dumps.
74 #define ELF_CLASS ELFCLASS64
76 #define ELF_DATA ELFDATA2MSB
78 #define ELF_DATA ELFDATA2LSB
80 #define ELF_ARCH EM_AARCH64
83 * This yields a string that ld.so will use to load implementation
84 * specific libraries for optimization. This is more specific in
85 * intent than poking at uname or /proc/cpuinfo.
87 #define ELF_PLATFORM_SIZE 16
89 #define ELF_PLATFORM ("aarch64_be")
91 #define ELF_PLATFORM ("aarch64")
95 * This is used to ensure we don't load something for the wrong architecture.
97 #define elf_check_arch(x) ((x)->e_machine == EM_AARCH64)
100 * An executable for which elf_read_implies_exec() returns TRUE will
101 * have the READ_IMPLIES_EXEC personality flag set automatically.
103 * The decision process for determining the results are:
105 * CPU*: | arm32 | arm64 |
107 * ---------------------|------------|------------|
108 * missing PT_GNU_STACK | exec-all | exec-all |
109 * PT_GNU_STACK == RWX | exec-stack | exec-stack |
110 * PT_GNU_STACK == RW | exec-none | exec-none |
112 * exec-all : all PROT_READ user mappings are executable, except when
113 * backed by files on a noexec-filesystem.
114 * exec-none : only PROT_EXEC user mappings are executable.
115 * exec-stack: only the stack and PROT_EXEC user mappings are executable.
117 * *all arm64 CPUs support NX, so there is no "lacks NX" column.
120 #define elf_read_implies_exec(ex, stk) (stk == EXSTACK_DEFAULT)
122 #define CORE_DUMP_USE_REGSET
123 #define ELF_EXEC_PAGESIZE PAGE_SIZE
126 * This is the base location for PIE (ET_DYN with INTERP) loads. On
127 * 64-bit, this is above 4GB to leave the entire 32-bit address
128 * space open for things that want to use the area for 32-bit pointers.
130 #ifdef CONFIG_ARM64_FORCE_52BIT
131 #define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3)
133 #define ELF_ET_DYN_BASE (2 * DEFAULT_MAP_WINDOW_64 / 3)
134 #endif /* CONFIG_ARM64_FORCE_52BIT */
138 #include <linux/bug.h>
139 #include <asm/processor.h> /* for signal_minsigstksz, used by ARCH_DLINFO */
141 typedef unsigned long elf_greg_t;
143 #define ELF_NGREG (sizeof(struct user_pt_regs) / sizeof(elf_greg_t))
144 #define ELF_CORE_COPY_REGS(dest, regs) \
145 *(struct user_pt_regs *)&(dest) = (regs)->user_regs;
147 typedef elf_greg_t elf_gregset_t[ELF_NGREG];
148 typedef struct user_fpsimd_state elf_fpregset_t;
151 * When the program starts, a1 contains a pointer to a function to be
152 * registered with atexit, as per the SVR4 ABI. A value of 0 means we have no
155 #define ELF_PLAT_INIT(_r, load_addr) (_r)->regs[0] = 0
157 #define SET_PERSONALITY(ex) \
159 clear_thread_flag(TIF_32BIT); \
160 current->personality &= ~READ_IMPLIES_EXEC; \
163 /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
164 #define ARCH_DLINFO \
166 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
167 (elf_addr_t)current->mm->context.vdso); \
170 * Should always be nonzero unless there's a kernel bug. \
171 * If we haven't determined a sensible value to give to \
172 * userspace, omit the entry: \
174 if (likely(signal_minsigstksz)) \
175 NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \
177 NEW_AUX_ENT(AT_IGNORE, 0); \
180 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
182 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
187 #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
188 0x7ff >> (PAGE_SHIFT - 12) : \
189 0x3ffff >> (PAGE_SHIFT - 12))
191 #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
195 #define COMPAT_ELF_PLATFORM ("v8b")
197 #define COMPAT_ELF_PLATFORM ("v8l")
202 /* PIE load location for compat arm. Must match ARM ELF_ET_DYN_BASE. */
203 #define COMPAT_ELF_ET_DYN_BASE 0x000400000UL
205 /* AArch32 registers. */
206 #define COMPAT_ELF_NGREG 18
207 typedef unsigned int compat_elf_greg_t;
208 typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
211 #define EF_ARM_EABI_MASK 0xff000000
212 #define compat_elf_check_arch(x) (system_supports_32bit_el0() && \
213 ((x)->e_machine == EM_ARM) && \
214 ((x)->e_flags & EF_ARM_EABI_MASK))
216 #define compat_start_thread compat_start_thread
218 * Unlike the native SET_PERSONALITY macro, the compat version maintains
219 * READ_IMPLIES_EXEC across an execve() since this is the behaviour on
222 #define COMPAT_SET_PERSONALITY(ex) \
224 set_thread_flag(TIF_32BIT); \
226 #ifdef CONFIG_COMPAT_VDSO
227 #define COMPAT_ARCH_DLINFO \
230 * Note that we use Elf64_Off instead of elf_addr_t because \
231 * elf_addr_t in compat is defined as Elf32_Addr and casting \
232 * current->mm->context.vdso to it triggers a cast warning of \
233 * cast from pointer to integer of different size. \
235 NEW_AUX_ENT(AT_SYSINFO_EHDR, \
236 (Elf64_Off)current->mm->context.vdso); \
239 #define COMPAT_ARCH_DLINFO
241 extern int aarch32_setup_additional_pages(struct linux_binprm *bprm,
243 #define compat_arch_setup_additional_pages \
244 aarch32_setup_additional_pages
246 #endif /* CONFIG_COMPAT */
248 #endif /* !__ASSEMBLY__ */