vmlinux.lds.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * ld script to make ARM Linux kernel
  3. * taken from the i386 version by Russell King
  4. * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  5. */
  6. #include <asm-generic/vmlinux.lds.h>
  7. #include <asm/cache.h>
  8. #include <asm/kernel-pgtable.h>
  9. #include <asm/thread_info.h>
  10. #include <asm/memory.h>
  11. #include <asm/page.h>
  12. #include <asm/pgtable.h>
  13. #include "image.h"
  14. /* .exit.text needed in case of alternative patching */
  15. #define ARM_EXIT_KEEP(x) x
  16. #define ARM_EXIT_DISCARD(x)
  17. OUTPUT_ARCH(aarch64)
  18. ENTRY(_text)
  19. jiffies = jiffies_64;
  20. #define HYPERVISOR_TEXT \
  21. /* \
  22. * Align to 4 KB so that \
  23. * a) the HYP vector table is at its minimum \
  24. * alignment of 2048 bytes \
  25. * b) the HYP init code will not cross a page \
  26. * boundary if its size does not exceed \
  27. * 4 KB (see related ASSERT() below) \
  28. */ \
  29. . = ALIGN(SZ_4K); \
  30. VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \
  31. *(.hyp.idmap.text) \
  32. VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \
  33. VMLINUX_SYMBOL(__hyp_text_start) = .; \
  34. *(.hyp.text) \
  35. VMLINUX_SYMBOL(__hyp_text_end) = .;
  36. #define IDMAP_TEXT \
  37. . = ALIGN(SZ_4K); \
  38. VMLINUX_SYMBOL(__idmap_text_start) = .; \
  39. *(.idmap.text) \
  40. VMLINUX_SYMBOL(__idmap_text_end) = .;
  41. #ifdef CONFIG_HIBERNATION
  42. #define HIBERNATE_TEXT \
  43. . = ALIGN(SZ_4K); \
  44. VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\
  45. *(.hibernate_exit.text) \
  46. VMLINUX_SYMBOL(__hibernate_exit_text_end) = .;
  47. #else
  48. #define HIBERNATE_TEXT
  49. #endif
  50. /*
  51. * The size of the PE/COFF section that covers the kernel image, which
  52. * runs from stext to _edata, must be a round multiple of the PE/COFF
  53. * FileAlignment, which we set to its minimum value of 0x200. 'stext'
  54. * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
  55. * boundary should be sufficient.
  56. */
  57. PECOFF_FILE_ALIGNMENT = 0x200;
  58. #ifdef CONFIG_EFI
  59. #define PECOFF_EDATA_PADDING \
  60. .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
  61. #else
  62. #define PECOFF_EDATA_PADDING
  63. #endif
  64. #if defined(CONFIG_DEBUG_ALIGN_RODATA)
  65. /*
  66. * 4 KB granule: 1 level 2 entry
  67. * 16 KB granule: 128 level 3 entries, with contiguous bit
  68. * 64 KB granule: 32 level 3 entries, with contiguous bit
  69. */
  70. #define SEGMENT_ALIGN SZ_2M
  71. #else
  72. /*
  73. * 4 KB granule: 16 level 3 entries, with contiguous bit
  74. * 16 KB granule: 4 level 3 entries, without contiguous bit
  75. * 64 KB granule: 1 level 3 entry
  76. */
  77. #define SEGMENT_ALIGN SZ_64K
  78. #endif
  79. SECTIONS
  80. {
  81. /*
  82. * XXX: The linker does not define how output sections are
  83. * assigned to input sections when there are multiple statements
  84. * matching the same input section name. There is no documented
  85. * order of matching.
  86. */
  87. /DISCARD/ : {
  88. ARM_EXIT_DISCARD(EXIT_TEXT)
  89. ARM_EXIT_DISCARD(EXIT_DATA)
  90. EXIT_CALL
  91. *(.discard)
  92. *(.discard.*)
  93. *(.interp .dynamic)
  94. *(.dynsym .dynstr .hash)
  95. }
  96. . = KIMAGE_VADDR + TEXT_OFFSET;
  97. .head.text : {
  98. _text = .;
  99. HEAD_TEXT
  100. }
  101. .text : { /* Real text segment */
  102. _stext = .; /* Text and read-only data */
  103. __exception_text_start = .;
  104. *(.exception.text)
  105. __exception_text_end = .;
  106. IRQENTRY_TEXT
  107. SOFTIRQENTRY_TEXT
  108. ENTRY_TEXT
  109. TEXT_TEXT
  110. SCHED_TEXT
  111. CPUIDLE_TEXT
  112. LOCK_TEXT
  113. KPROBES_TEXT
  114. HYPERVISOR_TEXT
  115. IDMAP_TEXT
  116. HIBERNATE_TEXT
  117. *(.fixup)
  118. *(.gnu.warning)
  119. . = ALIGN(16);
  120. *(.got) /* Global offset table */
  121. }
  122. . = ALIGN(SEGMENT_ALIGN);
  123. _etext = .; /* End of text section */
  124. RO_DATA(PAGE_SIZE) /* everything from this point to */
  125. EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
  126. NOTES
  127. . = ALIGN(SEGMENT_ALIGN);
  128. __init_begin = .;
  129. INIT_TEXT_SECTION(8)
  130. .exit.text : {
  131. ARM_EXIT_KEEP(EXIT_TEXT)
  132. }
  133. .init.data : {
  134. INIT_DATA
  135. INIT_SETUP(16)
  136. INIT_CALLS
  137. CON_INITCALL
  138. SECURITY_INITCALL
  139. INIT_RAM_FS
  140. *(.init.rodata.* .init.bss) /* from the EFI stub */
  141. }
  142. .exit.data : {
  143. ARM_EXIT_KEEP(EXIT_DATA)
  144. }
  145. PERCPU_SECTION(L1_CACHE_BYTES)
  146. . = ALIGN(4);
  147. .altinstructions : {
  148. __alt_instructions = .;
  149. *(.altinstructions)
  150. __alt_instructions_end = .;
  151. }
  152. .altinstr_replacement : {
  153. *(.altinstr_replacement)
  154. }
  155. .rela : ALIGN(8) {
  156. *(.rela .rela*)
  157. }
  158. __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
  159. __rela_size = SIZEOF(.rela);
  160. . = ALIGN(SEGMENT_ALIGN);
  161. __init_end = .;
  162. _data = .;
  163. _sdata = .;
  164. RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
  165. /*
  166. * Data written with the MMU off but read with the MMU on requires
  167. * cache lines to be invalidated, discarding up to a Cache Writeback
  168. * Granule (CWG) of data from the cache. Keep the section that
  169. * requires this type of maintenance to be in its own Cache Writeback
  170. * Granule (CWG) area so the cache maintenance operations don't
  171. * interfere with adjacent data.
  172. */
  173. .mmuoff.data.write : ALIGN(SZ_2K) {
  174. __mmuoff_data_start = .;
  175. *(.mmuoff.data.write)
  176. }
  177. . = ALIGN(SZ_2K);
  178. .mmuoff.data.read : {
  179. *(.mmuoff.data.read)
  180. __mmuoff_data_end = .;
  181. }
  182. PECOFF_EDATA_PADDING
  183. _edata = .;
  184. BSS_SECTION(0, 0, 0)
  185. . = ALIGN(PAGE_SIZE);
  186. idmap_pg_dir = .;
  187. . += IDMAP_DIR_SIZE;
  188. swapper_pg_dir = .;
  189. . += SWAPPER_DIR_SIZE;
  190. #ifdef CONFIG_ARM64_SW_TTBR0_PAN
  191. reserved_ttbr0 = .;
  192. . += RESERVED_TTBR0_SIZE;
  193. #endif
  194. _end = .;
  195. STABS_DEBUG
  196. HEAD_SYMBOLS
  197. }
  198. /*
  199. * The HYP init code and ID map text can't be longer than a page each,
  200. * and should not cross a page boundary.
  201. */
  202. ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  203. "HYP init code too big or misaligned")
  204. ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  205. "ID map text too big or misaligned")
  206. #ifdef CONFIG_HIBERNATION
  207. ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
  208. <= SZ_4K, "Hibernate exit text too big or misaligned")
  209. #endif
  210. /*
  211. * If padding is applied before .head.text, virt<->phys conversions will fail.
  212. */
  213. ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")