image.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Linker script macros to generate Image header fields.
  3. *
  4. * Copyright (C) 2014 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __ASM_IMAGE_H
  19. #define __ASM_IMAGE_H
  20. #ifndef LINKER_SCRIPT
  21. #error This file should only be included in vmlinux.lds.S
  22. #endif
  23. /*
  24. * There aren't any ELF relocations we can use to endian-swap values known only
  25. * at link time (e.g. the subtraction of two symbol addresses), so we must get
  26. * the linker to endian-swap certain values before emitting them.
  27. *
  28. * Note that, in order for this to work when building the ELF64 PIE executable
  29. * (for KASLR), these values should not be referenced via R_AARCH64_ABS64
  30. * relocations, since these are fixed up at runtime rather than at build time
  31. * when PIE is in effect. So we need to split them up in 32-bit high and low
  32. * words.
  33. */
  34. #ifdef CONFIG_CPU_BIG_ENDIAN
  35. #define DATA_LE32(data) \
  36. ((((data) & 0x000000ff) << 24) | \
  37. (((data) & 0x0000ff00) << 8) | \
  38. (((data) & 0x00ff0000) >> 8) | \
  39. (((data) & 0xff000000) >> 24))
  40. #else
  41. #define DATA_LE32(data) ((data) & 0xffffffff)
  42. #endif
  43. #define DEFINE_IMAGE_LE64(sym, data) \
  44. sym##_lo32 = DATA_LE32((data) & 0xffffffff); \
  45. sym##_hi32 = DATA_LE32((data) >> 32)
  46. #ifdef CONFIG_CPU_BIG_ENDIAN
  47. #define __HEAD_FLAG_BE 1
  48. #else
  49. #define __HEAD_FLAG_BE 0
  50. #endif
  51. #define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
  52. #define __HEAD_FLAG_PHYS_BASE 1
  53. #define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \
  54. (__HEAD_FLAG_PAGE_SIZE << 1) | \
  55. (__HEAD_FLAG_PHYS_BASE << 3))
  56. /*
  57. * These will output as part of the Image header, which should be little-endian
  58. * regardless of the endianness of the kernel. While constant values could be
  59. * endian swapped in head.S, all are done here for consistency.
  60. */
  61. #define HEAD_SYMBOLS \
  62. DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \
  63. DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET); \
  64. DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
  65. #ifdef CONFIG_EFI
  66. /*
  67. * Use ABSOLUTE() to avoid ld.lld treating this as a relative symbol:
  68. * https://github.com/ClangBuiltLinux/linux/issues/561
  69. */
  70. __efistub_stext_offset = ABSOLUTE(stext - _text);
  71. /*
  72. * The EFI stub has its own symbol namespace prefixed by __efistub_, to
  73. * isolate it from the kernel proper. The following symbols are legally
  74. * accessed by the stub, so provide some aliases to make them accessible.
  75. * Only include data symbols here, or text symbols of functions that are
  76. * guaranteed to be safe when executed at another offset than they were
  77. * linked at. The routines below are all implemented in assembler in a
  78. * position independent manner
  79. */
  80. __efistub_memcmp = __pi_memcmp;
  81. __efistub_memchr = __pi_memchr;
  82. __efistub_memcpy = __pi_memcpy;
  83. __efistub_memmove = __pi_memmove;
  84. __efistub_memset = __pi_memset;
  85. __efistub_strlen = __pi_strlen;
  86. __efistub_strnlen = __pi_strnlen;
  87. __efistub_strcmp = __pi_strcmp;
  88. __efistub_strncmp = __pi_strncmp;
  89. __efistub___flush_dcache_area = __pi___flush_dcache_area;
  90. #ifdef CONFIG_KASAN
  91. __efistub___memcpy = __pi_memcpy;
  92. __efistub___memmove = __pi_memmove;
  93. __efistub___memset = __pi_memset;
  94. #endif
  95. __efistub__text = _text;
  96. __efistub__end = _end;
  97. __efistub__edata = _edata;
  98. __efistub_screen_info = screen_info;
  99. #endif
  100. #endif /* __ASM_IMAGE_H */