vmlinux.lds.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  51. #define TRAMP_TEXT \
  52. . = ALIGN(PAGE_SIZE); \
  53. VMLINUX_SYMBOL(__entry_tramp_text_start) = .; \
  54. *(.entry.tramp.text) \
  55. . = ALIGN(PAGE_SIZE); \
  56. VMLINUX_SYMBOL(__entry_tramp_text_end) = .;
  57. #else
  58. #define TRAMP_TEXT
  59. #endif
  60. /*
  61. * The size of the PE/COFF section that covers the kernel image, which
  62. * runs from stext to _edata, must be a round multiple of the PE/COFF
  63. * FileAlignment, which we set to its minimum value of 0x200. 'stext'
  64. * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
  65. * boundary should be sufficient.
  66. */
  67. PECOFF_FILE_ALIGNMENT = 0x200;
  68. #ifdef CONFIG_EFI
  69. #define PECOFF_EDATA_PADDING \
  70. .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
  71. #else
  72. #define PECOFF_EDATA_PADDING
  73. #endif
  74. #if defined(CONFIG_DEBUG_ALIGN_RODATA)
  75. /*
  76. * 4 KB granule: 1 level 2 entry
  77. * 16 KB granule: 128 level 3 entries, with contiguous bit
  78. * 64 KB granule: 32 level 3 entries, with contiguous bit
  79. */
  80. #define SEGMENT_ALIGN SZ_2M
  81. #else
  82. /*
  83. * 4 KB granule: 16 level 3 entries, with contiguous bit
  84. * 16 KB granule: 4 level 3 entries, without contiguous bit
  85. * 64 KB granule: 1 level 3 entry
  86. */
  87. #define SEGMENT_ALIGN SZ_64K
  88. #endif
  89. SECTIONS
  90. {
  91. /*
  92. * XXX: The linker does not define how output sections are
  93. * assigned to input sections when there are multiple statements
  94. * matching the same input section name. There is no documented
  95. * order of matching.
  96. */
  97. /DISCARD/ : {
  98. ARM_EXIT_DISCARD(EXIT_TEXT)
  99. ARM_EXIT_DISCARD(EXIT_DATA)
  100. EXIT_CALL
  101. *(.discard)
  102. *(.discard.*)
  103. *(.interp .dynamic)
  104. *(.dynsym .dynstr .hash)
  105. }
  106. . = KIMAGE_VADDR + TEXT_OFFSET;
  107. .head.text : {
  108. _text = .;
  109. HEAD_TEXT
  110. }
  111. .text : { /* Real text segment */
  112. _stext = .; /* Text and read-only data */
  113. __exception_text_start = .;
  114. *(.exception.text)
  115. __exception_text_end = .;
  116. IRQENTRY_TEXT
  117. SOFTIRQENTRY_TEXT
  118. ENTRY_TEXT
  119. TEXT_TEXT
  120. SCHED_TEXT
  121. CPUIDLE_TEXT
  122. LOCK_TEXT
  123. KPROBES_TEXT
  124. HYPERVISOR_TEXT
  125. IDMAP_TEXT
  126. HIBERNATE_TEXT
  127. TRAMP_TEXT
  128. *(.fixup)
  129. *(.gnu.warning)
  130. . = ALIGN(16);
  131. *(.got) /* Global offset table */
  132. }
  133. . = ALIGN(SEGMENT_ALIGN);
  134. _etext = .; /* End of text section */
  135. RO_DATA(PAGE_SIZE) /* everything from this point to */
  136. EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */
  137. NOTES
  138. . = ALIGN(SEGMENT_ALIGN);
  139. __init_begin = .;
  140. INIT_TEXT_SECTION(8)
  141. .exit.text : {
  142. ARM_EXIT_KEEP(EXIT_TEXT)
  143. }
  144. .init.data : {
  145. INIT_DATA
  146. INIT_SETUP(16)
  147. INIT_CALLS
  148. CON_INITCALL
  149. SECURITY_INITCALL
  150. INIT_RAM_FS
  151. *(.init.rodata.* .init.bss) /* from the EFI stub */
  152. }
  153. .exit.data : {
  154. ARM_EXIT_KEEP(EXIT_DATA)
  155. }
  156. PERCPU_SECTION(L1_CACHE_BYTES)
  157. . = ALIGN(4);
  158. .altinstructions : {
  159. __alt_instructions = .;
  160. *(.altinstructions)
  161. __alt_instructions_end = .;
  162. }
  163. .altinstr_replacement : {
  164. *(.altinstr_replacement)
  165. }
  166. .rela : ALIGN(8) {
  167. *(.rela .rela*)
  168. }
  169. __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
  170. __rela_size = SIZEOF(.rela);
  171. . = ALIGN(SEGMENT_ALIGN);
  172. __init_end = .;
  173. _data = .;
  174. _sdata = .;
  175. RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
  176. /*
  177. * Data written with the MMU off but read with the MMU on requires
  178. * cache lines to be invalidated, discarding up to a Cache Writeback
  179. * Granule (CWG) of data from the cache. Keep the section that
  180. * requires this type of maintenance to be in its own Cache Writeback
  181. * Granule (CWG) area so the cache maintenance operations don't
  182. * interfere with adjacent data.
  183. */
  184. .mmuoff.data.write : ALIGN(SZ_2K) {
  185. __mmuoff_data_start = .;
  186. *(.mmuoff.data.write)
  187. }
  188. . = ALIGN(SZ_2K);
  189. .mmuoff.data.read : {
  190. *(.mmuoff.data.read)
  191. __mmuoff_data_end = .;
  192. }
  193. PECOFF_EDATA_PADDING
  194. _edata = .;
  195. BSS_SECTION(0, 0, 0)
  196. . = ALIGN(PAGE_SIZE);
  197. idmap_pg_dir = .;
  198. . += IDMAP_DIR_SIZE;
  199. swapper_pg_dir = .;
  200. . += SWAPPER_DIR_SIZE;
  201. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  202. tramp_pg_dir = .;
  203. . += PAGE_SIZE;
  204. #endif
  205. _end = .;
  206. STABS_DEBUG
  207. HEAD_SYMBOLS
  208. }
  209. /*
  210. * The HYP init code and ID map text can't be longer than a page each,
  211. * and should not cross a page boundary.
  212. */
  213. ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  214. "HYP init code too big or misaligned")
  215. ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
  216. "ID map text too big or misaligned")
  217. #ifdef CONFIG_HIBERNATION
  218. ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
  219. <= SZ_4K, "Hibernate exit text too big or misaligned")
  220. #endif
  221. #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
  222. ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE,
  223. "Entry trampoline text too big")
  224. #endif
  225. /*
  226. * If padding is applied before .head.text, virt<->phys conversions will fail.
  227. */
  228. ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")