elf.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_ELF_H
  17. #define __ASM_ELF_H
  18. #include <asm/hwcap.h>
  19. /*
  20. * ELF register definitions..
  21. */
  22. #include <asm/ptrace.h>
  23. #include <asm/user.h>
  24. /*
  25. * AArch64 static relocation types.
  26. */
  27. /* Miscellaneous. */
  28. #define R_ARM_NONE 0
  29. #define R_AARCH64_NONE 256
  30. /* Data. */
  31. #define R_AARCH64_ABS64 257
  32. #define R_AARCH64_ABS32 258
  33. #define R_AARCH64_ABS16 259
  34. #define R_AARCH64_PREL64 260
  35. #define R_AARCH64_PREL32 261
  36. #define R_AARCH64_PREL16 262
  37. /* Instructions. */
  38. #define R_AARCH64_MOVW_UABS_G0 263
  39. #define R_AARCH64_MOVW_UABS_G0_NC 264
  40. #define R_AARCH64_MOVW_UABS_G1 265
  41. #define R_AARCH64_MOVW_UABS_G1_NC 266
  42. #define R_AARCH64_MOVW_UABS_G2 267
  43. #define R_AARCH64_MOVW_UABS_G2_NC 268
  44. #define R_AARCH64_MOVW_UABS_G3 269
  45. #define R_AARCH64_MOVW_SABS_G0 270
  46. #define R_AARCH64_MOVW_SABS_G1 271
  47. #define R_AARCH64_MOVW_SABS_G2 272
  48. #define R_AARCH64_LD_PREL_LO19 273
  49. #define R_AARCH64_ADR_PREL_LO21 274
  50. #define R_AARCH64_ADR_PREL_PG_HI21 275
  51. #define R_AARCH64_ADR_PREL_PG_HI21_NC 276
  52. #define R_AARCH64_ADD_ABS_LO12_NC 277
  53. #define R_AARCH64_LDST8_ABS_LO12_NC 278
  54. #define R_AARCH64_TSTBR14 279
  55. #define R_AARCH64_CONDBR19 280
  56. #define R_AARCH64_JUMP26 282
  57. #define R_AARCH64_CALL26 283
  58. #define R_AARCH64_LDST16_ABS_LO12_NC 284
  59. #define R_AARCH64_LDST32_ABS_LO12_NC 285
  60. #define R_AARCH64_LDST64_ABS_LO12_NC 286
  61. #define R_AARCH64_LDST128_ABS_LO12_NC 299
  62. #define R_AARCH64_MOVW_PREL_G0 287
  63. #define R_AARCH64_MOVW_PREL_G0_NC 288
  64. #define R_AARCH64_MOVW_PREL_G1 289
  65. #define R_AARCH64_MOVW_PREL_G1_NC 290
  66. #define R_AARCH64_MOVW_PREL_G2 291
  67. #define R_AARCH64_MOVW_PREL_G2_NC 292
  68. #define R_AARCH64_MOVW_PREL_G3 293
  69. #define R_AARCH64_RELATIVE 1027
  70. /*
  71. * These are used to set parameters in the core dumps.
  72. */
  73. #define ELF_CLASS ELFCLASS64
  74. #ifdef __AARCH64EB__
  75. #define ELF_DATA ELFDATA2MSB
  76. #else
  77. #define ELF_DATA ELFDATA2LSB
  78. #endif
  79. #define ELF_ARCH EM_AARCH64
  80. /*
  81. * This yields a string that ld.so will use to load implementation
  82. * specific libraries for optimization. This is more specific in
  83. * intent than poking at uname or /proc/cpuinfo.
  84. */
  85. #define ELF_PLATFORM_SIZE 16
  86. #ifdef __AARCH64EB__
  87. #define ELF_PLATFORM ("aarch64_be")
  88. #else
  89. #define ELF_PLATFORM ("aarch64")
  90. #endif
  91. /*
  92. * This is used to ensure we don't load something for the wrong architecture.
  93. */
  94. #define elf_check_arch(x) ((x)->e_machine == EM_AARCH64)
  95. #define elf_read_implies_exec(ex,stk) (stk != EXSTACK_DISABLE_X)
  96. #define CORE_DUMP_USE_REGSET
  97. #define ELF_EXEC_PAGESIZE PAGE_SIZE
  98. /*
  99. * This is the base location for PIE (ET_DYN with INTERP) loads. On
  100. * 64-bit, this is above 4GB to leave the entire 32-bit address
  101. * space open for things that want to use the area for 32-bit pointers.
  102. */
  103. #define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3)
  104. #ifndef __ASSEMBLY__
  105. #include <linux/bug.h>
  106. #include <asm/processor.h> /* for signal_minsigstksz, used by ARCH_DLINFO */
  107. typedef unsigned long elf_greg_t;
  108. #define ELF_NGREG (sizeof(struct user_pt_regs) / sizeof(elf_greg_t))
  109. #define ELF_CORE_COPY_REGS(dest, regs) \
  110. *(struct user_pt_regs *)&(dest) = (regs)->user_regs;
  111. typedef elf_greg_t elf_gregset_t[ELF_NGREG];
  112. typedef struct user_fpsimd_state elf_fpregset_t;
  113. /*
  114. * When the program starts, a1 contains a pointer to a function to be
  115. * registered with atexit, as per the SVR4 ABI. A value of 0 means we have no
  116. * such handler.
  117. */
  118. #define ELF_PLAT_INIT(_r, load_addr) (_r)->regs[0] = 0
  119. #define SET_PERSONALITY(ex) \
  120. ({ \
  121. clear_thread_flag(TIF_32BIT); \
  122. current->personality &= ~READ_IMPLIES_EXEC; \
  123. })
  124. /* update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */
  125. #define ARCH_DLINFO \
  126. do { \
  127. NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  128. (elf_addr_t)current->mm->context.vdso); \
  129. \
  130. /* \
  131. * Should always be nonzero unless there's a kernel bug. \
  132. * If we haven't determined a sensible value to give to \
  133. * userspace, omit the entry: \
  134. */ \
  135. if (likely(signal_minsigstksz)) \
  136. NEW_AUX_ENT(AT_MINSIGSTKSZ, signal_minsigstksz); \
  137. else \
  138. NEW_AUX_ENT(AT_IGNORE, 0); \
  139. } while (0)
  140. #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
  141. struct linux_binprm;
  142. extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  143. int uses_interp);
  144. /* 1GB of VA */
  145. #ifdef CONFIG_COMPAT
  146. #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \
  147. 0x7ff >> (PAGE_SHIFT - 12) : \
  148. 0x3ffff >> (PAGE_SHIFT - 12))
  149. #else
  150. #define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12))
  151. #endif
  152. #ifdef __AARCH64EB__
  153. #define COMPAT_ELF_PLATFORM ("v8b")
  154. #else
  155. #define COMPAT_ELF_PLATFORM ("v8l")
  156. #endif
  157. #ifdef CONFIG_COMPAT
  158. /* PIE load location for compat arm. Must match ARM ELF_ET_DYN_BASE. */
  159. #define COMPAT_ELF_ET_DYN_BASE 0x000400000UL
  160. /* AArch32 registers. */
  161. #define COMPAT_ELF_NGREG 18
  162. typedef unsigned int compat_elf_greg_t;
  163. typedef compat_elf_greg_t compat_elf_gregset_t[COMPAT_ELF_NGREG];
  164. /* AArch32 EABI. */
  165. #define EF_ARM_EABI_MASK 0xff000000
  166. #define compat_elf_check_arch(x) (system_supports_32bit_el0() && \
  167. ((x)->e_machine == EM_ARM) && \
  168. ((x)->e_flags & EF_ARM_EABI_MASK))
  169. #define compat_start_thread compat_start_thread
  170. /*
  171. * Unlike the native SET_PERSONALITY macro, the compat version maintains
  172. * READ_IMPLIES_EXEC across an execve() since this is the behaviour on
  173. * arch/arm/.
  174. */
  175. #define COMPAT_SET_PERSONALITY(ex) \
  176. ({ \
  177. set_thread_flag(TIF_32BIT); \
  178. })
  179. #define COMPAT_ARCH_DLINFO
  180. extern int aarch32_setup_vectors_page(struct linux_binprm *bprm,
  181. int uses_interp);
  182. #define compat_arch_setup_additional_pages \
  183. aarch32_setup_vectors_page
  184. #endif /* CONFIG_COMPAT */
  185. #endif /* !__ASSEMBLY__ */
  186. #endif