vmlinux.lds.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /*
  2. * Helper macros to support writing architecture specific
  3. * linker scripts.
  4. *
  5. * A minimal linker scripts has following content:
  6. * [This is a sample, architectures may have special requiriements]
  7. *
  8. * OUTPUT_FORMAT(...)
  9. * OUTPUT_ARCH(...)
  10. * ENTRY(...)
  11. * SECTIONS
  12. * {
  13. * . = START;
  14. * __init_begin = .;
  15. * HEAD_TEXT_SECTION
  16. * INIT_TEXT_SECTION(PAGE_SIZE)
  17. * INIT_DATA_SECTION(...)
  18. * PERCPU_SECTION(CACHELINE_SIZE)
  19. * __init_end = .;
  20. *
  21. * _stext = .;
  22. * TEXT_SECTION = 0
  23. * _etext = .;
  24. *
  25. * _sdata = .;
  26. * RO_DATA_SECTION(PAGE_SIZE)
  27. * RW_DATA_SECTION(...)
  28. * _edata = .;
  29. *
  30. * EXCEPTION_TABLE(...)
  31. * NOTES
  32. *
  33. * BSS_SECTION(0, 0, 0)
  34. * _end = .;
  35. *
  36. * STABS_DEBUG
  37. * DWARF_DEBUG
  38. *
  39. * DISCARDS // must be the last
  40. * }
  41. *
  42. * [__init_begin, __init_end] is the init section that may be freed after init
  43. * // __init_begin and __init_end should be page aligned, so that we can
  44. * // free the whole .init memory
  45. * [_stext, _etext] is the text section
  46. * [_sdata, _edata] is the data section
  47. *
  48. * Some of the included output section have their own set of constants.
  49. * Examples are: [__initramfs_start, __initramfs_end] for initramfs and
  50. * [__nosave_begin, __nosave_end] for the nosave data
  51. */
  52. #ifndef LOAD_OFFSET
  53. #define LOAD_OFFSET 0
  54. #endif
  55. #include <linux/export.h>
  56. /* Align . to a 8 byte boundary equals to maximum function alignment. */
  57. #define ALIGN_FUNCTION() . = ALIGN(8)
  58. /*
  59. * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
  60. * generates .data.identifier sections, which need to be pulled in with
  61. * .data. We don't want to pull in .data..other sections, which Linux
  62. * has defined. Same for text and bss.
  63. */
  64. #ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
  65. #define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
  66. #define DATA_MAIN .data .data.[0-9a-zA-Z_]*
  67. #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
  68. #else
  69. #define TEXT_MAIN .text
  70. #define DATA_MAIN .data
  71. #define BSS_MAIN .bss
  72. #endif
  73. /*
  74. * Align to a 32 byte boundary equal to the
  75. * alignment gcc 4.5 uses for a struct
  76. */
  77. #define STRUCT_ALIGNMENT 32
  78. #define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
  79. /* The actual configuration determine if the init/exit sections
  80. * are handled as text/data or they can be discarded (which
  81. * often happens at runtime)
  82. */
  83. #ifdef CONFIG_HOTPLUG_CPU
  84. #define CPU_KEEP(sec) *(.cpu##sec)
  85. #define CPU_DISCARD(sec)
  86. #else
  87. #define CPU_KEEP(sec)
  88. #define CPU_DISCARD(sec) *(.cpu##sec)
  89. #endif
  90. #if defined(CONFIG_MEMORY_HOTPLUG)
  91. #define MEM_KEEP(sec) *(.mem##sec)
  92. #define MEM_DISCARD(sec)
  93. #else
  94. #define MEM_KEEP(sec)
  95. #define MEM_DISCARD(sec) *(.mem##sec)
  96. #endif
  97. #ifdef CONFIG_FTRACE_MCOUNT_RECORD
  98. #define MCOUNT_REC() . = ALIGN(8); \
  99. VMLINUX_SYMBOL(__start_mcount_loc) = .; \
  100. *(__mcount_loc) \
  101. VMLINUX_SYMBOL(__stop_mcount_loc) = .;
  102. #else
  103. #define MCOUNT_REC()
  104. #endif
  105. #ifdef CONFIG_TRACE_BRANCH_PROFILING
  106. #define LIKELY_PROFILE() VMLINUX_SYMBOL(__start_annotated_branch_profile) = .; \
  107. *(_ftrace_annotated_branch) \
  108. VMLINUX_SYMBOL(__stop_annotated_branch_profile) = .;
  109. #else
  110. #define LIKELY_PROFILE()
  111. #endif
  112. #ifdef CONFIG_PROFILE_ALL_BRANCHES
  113. #define BRANCH_PROFILE() VMLINUX_SYMBOL(__start_branch_profile) = .; \
  114. *(_ftrace_branch) \
  115. VMLINUX_SYMBOL(__stop_branch_profile) = .;
  116. #else
  117. #define BRANCH_PROFILE()
  118. #endif
  119. #ifdef CONFIG_KPROBES
  120. #define KPROBE_BLACKLIST() . = ALIGN(8); \
  121. VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \
  122. KEEP(*(_kprobe_blacklist)) \
  123. VMLINUX_SYMBOL(__stop_kprobe_blacklist) = .;
  124. #else
  125. #define KPROBE_BLACKLIST()
  126. #endif
  127. #ifdef CONFIG_EVENT_TRACING
  128. #define FTRACE_EVENTS() . = ALIGN(8); \
  129. VMLINUX_SYMBOL(__start_ftrace_events) = .; \
  130. KEEP(*(_ftrace_events)) \
  131. VMLINUX_SYMBOL(__stop_ftrace_events) = .; \
  132. VMLINUX_SYMBOL(__start_ftrace_eval_maps) = .; \
  133. KEEP(*(_ftrace_eval_map)) \
  134. VMLINUX_SYMBOL(__stop_ftrace_eval_maps) = .;
  135. #else
  136. #define FTRACE_EVENTS()
  137. #endif
  138. #ifdef CONFIG_TRACING
  139. #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .; \
  140. KEEP(*(__trace_printk_fmt)) /* Trace_printk fmt' pointer */ \
  141. VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
  142. #define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .; \
  143. KEEP(*(__tracepoint_str)) /* Trace_printk fmt' pointer */ \
  144. VMLINUX_SYMBOL(__stop___tracepoint_str) = .;
  145. #else
  146. #define TRACE_PRINTKS()
  147. #define TRACEPOINT_STR()
  148. #endif
  149. #ifdef CONFIG_FTRACE_SYSCALLS
  150. #define TRACE_SYSCALLS() . = ALIGN(8); \
  151. VMLINUX_SYMBOL(__start_syscalls_metadata) = .; \
  152. KEEP(*(__syscalls_metadata)) \
  153. VMLINUX_SYMBOL(__stop_syscalls_metadata) = .;
  154. #else
  155. #define TRACE_SYSCALLS()
  156. #endif
  157. #ifdef CONFIG_SERIAL_EARLYCON
  158. #define EARLYCON_TABLE() STRUCT_ALIGN(); \
  159. VMLINUX_SYMBOL(__earlycon_table) = .; \
  160. KEEP(*(__earlycon_table)) \
  161. VMLINUX_SYMBOL(__earlycon_table_end) = .;
  162. #else
  163. #define EARLYCON_TABLE()
  164. #endif
  165. #define ___OF_TABLE(cfg, name) _OF_TABLE_##cfg(name)
  166. #define __OF_TABLE(cfg, name) ___OF_TABLE(cfg, name)
  167. #define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
  168. #define _OF_TABLE_0(name)
  169. #define _OF_TABLE_1(name) \
  170. . = ALIGN(8); \
  171. VMLINUX_SYMBOL(__##name##_of_table) = .; \
  172. KEEP(*(__##name##_of_table)) \
  173. KEEP(*(__##name##_of_table_end))
  174. #define TIMER_OF_TABLES() OF_TABLE(CONFIG_TIMER_OF, timer)
  175. #define IRQCHIP_OF_MATCH_TABLE() OF_TABLE(CONFIG_IRQCHIP, irqchip)
  176. #define CLK_OF_TABLES() OF_TABLE(CONFIG_COMMON_CLK, clk)
  177. #define IOMMU_OF_TABLES() OF_TABLE(CONFIG_OF_IOMMU, iommu)
  178. #define RESERVEDMEM_OF_TABLES() OF_TABLE(CONFIG_OF_RESERVED_MEM, reservedmem)
  179. #define CPU_METHOD_OF_TABLES() OF_TABLE(CONFIG_SMP, cpu_method)
  180. #define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
  181. #ifdef CONFIG_ACPI
  182. #define ACPI_PROBE_TABLE(name) \
  183. . = ALIGN(8); \
  184. VMLINUX_SYMBOL(__##name##_acpi_probe_table) = .; \
  185. KEEP(*(__##name##_acpi_probe_table)) \
  186. VMLINUX_SYMBOL(__##name##_acpi_probe_table_end) = .;
  187. #else
  188. #define ACPI_PROBE_TABLE(name)
  189. #endif
  190. #define KERNEL_DTB() \
  191. STRUCT_ALIGN(); \
  192. VMLINUX_SYMBOL(__dtb_start) = .; \
  193. KEEP(*(.dtb.init.rodata)) \
  194. VMLINUX_SYMBOL(__dtb_end) = .;
  195. /*
  196. * .data section
  197. */
  198. #define DATA_DATA \
  199. *(.xiptext) \
  200. *(DATA_MAIN) \
  201. *(.ref.data) \
  202. *(.data..shared_aligned) /* percpu related */ \
  203. MEM_KEEP(init.data) \
  204. MEM_KEEP(exit.data) \
  205. *(.data.unlikely) \
  206. VMLINUX_SYMBOL(__start_once) = .; \
  207. *(.data.once) \
  208. VMLINUX_SYMBOL(__end_once) = .; \
  209. STRUCT_ALIGN(); \
  210. *(__tracepoints) \
  211. /* implement dynamic printk debug */ \
  212. . = ALIGN(8); \
  213. VMLINUX_SYMBOL(__start___jump_table) = .; \
  214. KEEP(*(__jump_table)) \
  215. VMLINUX_SYMBOL(__stop___jump_table) = .; \
  216. . = ALIGN(8); \
  217. VMLINUX_SYMBOL(__start___verbose) = .; \
  218. KEEP(*(__verbose)) \
  219. VMLINUX_SYMBOL(__stop___verbose) = .; \
  220. LIKELY_PROFILE() \
  221. BRANCH_PROFILE() \
  222. TRACE_PRINTKS() \
  223. TRACEPOINT_STR()
  224. /*
  225. * Data section helpers
  226. */
  227. #define NOSAVE_DATA \
  228. . = ALIGN(PAGE_SIZE); \
  229. VMLINUX_SYMBOL(__nosave_begin) = .; \
  230. *(.data..nosave) \
  231. . = ALIGN(PAGE_SIZE); \
  232. VMLINUX_SYMBOL(__nosave_end) = .;
  233. #define PAGE_ALIGNED_DATA(page_align) \
  234. . = ALIGN(page_align); \
  235. *(.data..page_aligned)
  236. #define READ_MOSTLY_DATA(align) \
  237. . = ALIGN(align); \
  238. *(.data..read_mostly) \
  239. . = ALIGN(align);
  240. #define CACHELINE_ALIGNED_DATA(align) \
  241. . = ALIGN(align); \
  242. *(.data..cacheline_aligned)
  243. #define INIT_TASK_DATA(align) \
  244. . = ALIGN(align); \
  245. VMLINUX_SYMBOL(__start_init_task) = .; \
  246. VMLINUX_SYMBOL(init_thread_union) = .; \
  247. VMLINUX_SYMBOL(init_stack) = .; \
  248. *(.data..init_task) \
  249. *(.data..init_thread_info) \
  250. . = VMLINUX_SYMBOL(__start_init_task) + THREAD_SIZE; \
  251. VMLINUX_SYMBOL(__end_init_task) = .;
  252. /*
  253. * Allow architectures to handle ro_after_init data on their
  254. * own by defining an empty RO_AFTER_INIT_DATA.
  255. */
  256. #ifndef RO_AFTER_INIT_DATA
  257. #define RO_AFTER_INIT_DATA \
  258. VMLINUX_SYMBOL(__start_ro_after_init) = .; \
  259. *(.data..ro_after_init) \
  260. VMLINUX_SYMBOL(__end_ro_after_init) = .;
  261. #endif
  262. /*
  263. * Read only Data
  264. */
  265. #define RO_DATA_SECTION(align) \
  266. . = ALIGN((align)); \
  267. .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
  268. VMLINUX_SYMBOL(__start_rodata) = .; \
  269. *(.rodata) *(.rodata.*) \
  270. RO_AFTER_INIT_DATA /* Read only after init */ \
  271. KEEP(*(__vermagic)) /* Kernel version magic */ \
  272. . = ALIGN(8); \
  273. VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
  274. KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \
  275. VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .; \
  276. *(__tracepoints_strings)/* Tracepoints: strings */ \
  277. } \
  278. \
  279. .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
  280. *(.rodata1) \
  281. } \
  282. \
  283. /* PCI quirks */ \
  284. .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
  285. VMLINUX_SYMBOL(__start_pci_fixups_early) = .; \
  286. KEEP(*(.pci_fixup_early)) \
  287. VMLINUX_SYMBOL(__end_pci_fixups_early) = .; \
  288. VMLINUX_SYMBOL(__start_pci_fixups_header) = .; \
  289. KEEP(*(.pci_fixup_header)) \
  290. VMLINUX_SYMBOL(__end_pci_fixups_header) = .; \
  291. VMLINUX_SYMBOL(__start_pci_fixups_final) = .; \
  292. KEEP(*(.pci_fixup_final)) \
  293. VMLINUX_SYMBOL(__end_pci_fixups_final) = .; \
  294. VMLINUX_SYMBOL(__start_pci_fixups_enable) = .; \
  295. KEEP(*(.pci_fixup_enable)) \
  296. VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \
  297. VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \
  298. KEEP(*(.pci_fixup_resume)) \
  299. VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \
  300. VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \
  301. KEEP(*(.pci_fixup_resume_early)) \
  302. VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \
  303. VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \
  304. KEEP(*(.pci_fixup_suspend)) \
  305. VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \
  306. VMLINUX_SYMBOL(__start_pci_fixups_suspend_late) = .; \
  307. KEEP(*(.pci_fixup_suspend_late)) \
  308. VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .; \
  309. } \
  310. \
  311. /* Built-in firmware blobs */ \
  312. .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \
  313. VMLINUX_SYMBOL(__start_builtin_fw) = .; \
  314. KEEP(*(.builtin_fw)) \
  315. VMLINUX_SYMBOL(__end_builtin_fw) = .; \
  316. } \
  317. \
  318. TRACEDATA \
  319. \
  320. /* Kernel symbol table: Normal symbols */ \
  321. __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
  322. VMLINUX_SYMBOL(__start___ksymtab) = .; \
  323. KEEP(*(SORT(___ksymtab+*))) \
  324. VMLINUX_SYMBOL(__stop___ksymtab) = .; \
  325. } \
  326. \
  327. /* Kernel symbol table: GPL-only symbols */ \
  328. __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
  329. VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
  330. KEEP(*(SORT(___ksymtab_gpl+*))) \
  331. VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
  332. } \
  333. \
  334. /* Kernel symbol table: Normal unused symbols */ \
  335. __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
  336. VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
  337. KEEP(*(SORT(___ksymtab_unused+*))) \
  338. VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
  339. } \
  340. \
  341. /* Kernel symbol table: GPL-only unused symbols */ \
  342. __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
  343. VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
  344. KEEP(*(SORT(___ksymtab_unused_gpl+*))) \
  345. VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
  346. } \
  347. \
  348. /* Kernel symbol table: GPL-future-only symbols */ \
  349. __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
  350. VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
  351. KEEP(*(SORT(___ksymtab_gpl_future+*))) \
  352. VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
  353. } \
  354. \
  355. /* Kernel symbol table: Normal symbols */ \
  356. __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
  357. VMLINUX_SYMBOL(__start___kcrctab) = .; \
  358. KEEP(*(SORT(___kcrctab+*))) \
  359. VMLINUX_SYMBOL(__stop___kcrctab) = .; \
  360. } \
  361. \
  362. /* Kernel symbol table: GPL-only symbols */ \
  363. __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
  364. VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \
  365. KEEP(*(SORT(___kcrctab_gpl+*))) \
  366. VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
  367. } \
  368. \
  369. /* Kernel symbol table: Normal unused symbols */ \
  370. __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
  371. VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \
  372. KEEP(*(SORT(___kcrctab_unused+*))) \
  373. VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \
  374. } \
  375. \
  376. /* Kernel symbol table: GPL-only unused symbols */ \
  377. __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
  378. VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \
  379. KEEP(*(SORT(___kcrctab_unused_gpl+*))) \
  380. VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \
  381. } \
  382. \
  383. /* Kernel symbol table: GPL-future-only symbols */ \
  384. __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
  385. VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
  386. KEEP(*(SORT(___kcrctab_gpl_future+*))) \
  387. VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
  388. } \
  389. \
  390. /* Kernel symbol table: strings */ \
  391. __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
  392. *(__ksymtab_strings) \
  393. } \
  394. \
  395. /* __*init sections */ \
  396. __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
  397. *(.ref.rodata) \
  398. MEM_KEEP(init.rodata) \
  399. MEM_KEEP(exit.rodata) \
  400. } \
  401. \
  402. /* Built-in module parameters. */ \
  403. __param : AT(ADDR(__param) - LOAD_OFFSET) { \
  404. VMLINUX_SYMBOL(__start___param) = .; \
  405. KEEP(*(__param)) \
  406. VMLINUX_SYMBOL(__stop___param) = .; \
  407. } \
  408. \
  409. /* Built-in module versions. */ \
  410. __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \
  411. VMLINUX_SYMBOL(__start___modver) = .; \
  412. KEEP(*(__modver)) \
  413. VMLINUX_SYMBOL(__stop___modver) = .; \
  414. . = ALIGN((align)); \
  415. VMLINUX_SYMBOL(__end_rodata) = .; \
  416. } \
  417. . = ALIGN((align));
  418. /* RODATA & RO_DATA provided for backward compatibility.
  419. * All archs are supposed to use RO_DATA() */
  420. #define RODATA RO_DATA_SECTION(4096)
  421. #define RO_DATA(align) RO_DATA_SECTION(align)
  422. #define SECURITY_INIT \
  423. .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
  424. VMLINUX_SYMBOL(__security_initcall_start) = .; \
  425. KEEP(*(.security_initcall.init)) \
  426. VMLINUX_SYMBOL(__security_initcall_end) = .; \
  427. }
  428. /*
  429. * .text section. Map to function alignment to avoid address changes
  430. * during second ld run in second ld pass when generating System.map
  431. *
  432. * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
  433. * code elimination is enabled, so these sections should be converted
  434. * to use ".." first.
  435. */
  436. #define TEXT_TEXT \
  437. ALIGN_FUNCTION(); \
  438. *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \
  439. *(.text..refcount) \
  440. *(.ref.text) \
  441. MEM_KEEP(init.text) \
  442. MEM_KEEP(exit.text) \
  443. /* sched.text is aling to function alignment to secure we have same
  444. * address even at second ld pass when generating System.map */
  445. #define SCHED_TEXT \
  446. ALIGN_FUNCTION(); \
  447. VMLINUX_SYMBOL(__sched_text_start) = .; \
  448. *(.sched.text) \
  449. VMLINUX_SYMBOL(__sched_text_end) = .;
  450. /* spinlock.text is aling to function alignment to secure we have same
  451. * address even at second ld pass when generating System.map */
  452. #define LOCK_TEXT \
  453. ALIGN_FUNCTION(); \
  454. VMLINUX_SYMBOL(__lock_text_start) = .; \
  455. *(.spinlock.text) \
  456. VMLINUX_SYMBOL(__lock_text_end) = .;
  457. #define CPUIDLE_TEXT \
  458. ALIGN_FUNCTION(); \
  459. VMLINUX_SYMBOL(__cpuidle_text_start) = .; \
  460. *(.cpuidle.text) \
  461. VMLINUX_SYMBOL(__cpuidle_text_end) = .;
  462. #define KPROBES_TEXT \
  463. ALIGN_FUNCTION(); \
  464. VMLINUX_SYMBOL(__kprobes_text_start) = .; \
  465. *(.kprobes.text) \
  466. VMLINUX_SYMBOL(__kprobes_text_end) = .;
  467. #define ENTRY_TEXT \
  468. ALIGN_FUNCTION(); \
  469. VMLINUX_SYMBOL(__entry_text_start) = .; \
  470. *(.entry.text) \
  471. VMLINUX_SYMBOL(__entry_text_end) = .;
  472. #define IRQENTRY_TEXT \
  473. ALIGN_FUNCTION(); \
  474. VMLINUX_SYMBOL(__irqentry_text_start) = .; \
  475. *(.irqentry.text) \
  476. VMLINUX_SYMBOL(__irqentry_text_end) = .;
  477. #define SOFTIRQENTRY_TEXT \
  478. ALIGN_FUNCTION(); \
  479. VMLINUX_SYMBOL(__softirqentry_text_start) = .; \
  480. *(.softirqentry.text) \
  481. VMLINUX_SYMBOL(__softirqentry_text_end) = .;
  482. /* Section used for early init (in .S files) */
  483. #define HEAD_TEXT *(.head.text)
  484. #define HEAD_TEXT_SECTION \
  485. .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \
  486. HEAD_TEXT \
  487. }
  488. /*
  489. * Exception table
  490. */
  491. #define EXCEPTION_TABLE(align) \
  492. . = ALIGN(align); \
  493. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \
  494. VMLINUX_SYMBOL(__start___ex_table) = .; \
  495. KEEP(*(__ex_table)) \
  496. VMLINUX_SYMBOL(__stop___ex_table) = .; \
  497. }
  498. /*
  499. * Init task
  500. */
  501. #define INIT_TASK_DATA_SECTION(align) \
  502. . = ALIGN(align); \
  503. .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \
  504. INIT_TASK_DATA(align) \
  505. }
  506. #ifdef CONFIG_CONSTRUCTORS
  507. #define KERNEL_CTORS() . = ALIGN(8); \
  508. VMLINUX_SYMBOL(__ctors_start) = .; \
  509. KEEP(*(.ctors)) \
  510. KEEP(*(SORT(.init_array.*))) \
  511. KEEP(*(.init_array)) \
  512. VMLINUX_SYMBOL(__ctors_end) = .;
  513. #else
  514. #define KERNEL_CTORS()
  515. #endif
  516. /* init and exit section handling */
  517. #define INIT_DATA \
  518. KEEP(*(SORT(___kentry+*))) \
  519. *(.init.data) \
  520. MEM_DISCARD(init.data) \
  521. KERNEL_CTORS() \
  522. MCOUNT_REC() \
  523. *(.init.rodata) \
  524. FTRACE_EVENTS() \
  525. TRACE_SYSCALLS() \
  526. KPROBE_BLACKLIST() \
  527. MEM_DISCARD(init.rodata) \
  528. CLK_OF_TABLES() \
  529. RESERVEDMEM_OF_TABLES() \
  530. TIMER_OF_TABLES() \
  531. IOMMU_OF_TABLES() \
  532. CPU_METHOD_OF_TABLES() \
  533. CPUIDLE_METHOD_OF_TABLES() \
  534. KERNEL_DTB() \
  535. IRQCHIP_OF_MATCH_TABLE() \
  536. ACPI_PROBE_TABLE(irqchip) \
  537. ACPI_PROBE_TABLE(timer) \
  538. ACPI_PROBE_TABLE(iort) \
  539. EARLYCON_TABLE()
  540. #define INIT_TEXT \
  541. *(.init.text) \
  542. *(.text.startup) \
  543. MEM_DISCARD(init.text)
  544. #define EXIT_DATA \
  545. *(.exit.data) \
  546. *(.fini_array) \
  547. *(.dtors) \
  548. MEM_DISCARD(exit.data) \
  549. MEM_DISCARD(exit.rodata)
  550. #define EXIT_TEXT \
  551. *(.exit.text) \
  552. *(.text.exit) \
  553. MEM_DISCARD(exit.text)
  554. #define EXIT_CALL \
  555. *(.exitcall.exit)
  556. /*
  557. * bss (Block Started by Symbol) - uninitialized data
  558. * zeroed during startup
  559. */
  560. #define SBSS(sbss_align) \
  561. . = ALIGN(sbss_align); \
  562. .sbss : AT(ADDR(.sbss) - LOAD_OFFSET) { \
  563. *(.dynsbss) \
  564. *(.sbss) \
  565. *(.scommon) \
  566. }
  567. /*
  568. * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
  569. * sections to the front of bss.
  570. */
  571. #ifndef BSS_FIRST_SECTIONS
  572. #define BSS_FIRST_SECTIONS
  573. #endif
  574. #define BSS(bss_align) \
  575. . = ALIGN(bss_align); \
  576. .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
  577. BSS_FIRST_SECTIONS \
  578. *(.bss..page_aligned) \
  579. *(.dynbss) \
  580. *(BSS_MAIN) \
  581. *(COMMON) \
  582. }
  583. /*
  584. * DWARF debug sections.
  585. * Symbols in the DWARF debugging sections are relative to
  586. * the beginning of the section so we begin them at 0.
  587. */
  588. #define DWARF_DEBUG \
  589. /* DWARF 1 */ \
  590. .debug 0 : { *(.debug) } \
  591. .line 0 : { *(.line) } \
  592. /* GNU DWARF 1 extensions */ \
  593. .debug_srcinfo 0 : { *(.debug_srcinfo) } \
  594. .debug_sfnames 0 : { *(.debug_sfnames) } \
  595. /* DWARF 1.1 and DWARF 2 */ \
  596. .debug_aranges 0 : { *(.debug_aranges) } \
  597. .debug_pubnames 0 : { *(.debug_pubnames) } \
  598. /* DWARF 2 */ \
  599. .debug_info 0 : { *(.debug_info \
  600. .gnu.linkonce.wi.*) } \
  601. .debug_abbrev 0 : { *(.debug_abbrev) } \
  602. .debug_line 0 : { *(.debug_line) } \
  603. .debug_frame 0 : { *(.debug_frame) } \
  604. .debug_str 0 : { *(.debug_str) } \
  605. .debug_loc 0 : { *(.debug_loc) } \
  606. .debug_macinfo 0 : { *(.debug_macinfo) } \
  607. .debug_pubtypes 0 : { *(.debug_pubtypes) } \
  608. /* DWARF 3 */ \
  609. .debug_ranges 0 : { *(.debug_ranges) } \
  610. /* SGI/MIPS DWARF 2 extensions */ \
  611. .debug_weaknames 0 : { *(.debug_weaknames) } \
  612. .debug_funcnames 0 : { *(.debug_funcnames) } \
  613. .debug_typenames 0 : { *(.debug_typenames) } \
  614. .debug_varnames 0 : { *(.debug_varnames) } \
  615. /* GNU DWARF 2 extensions */ \
  616. .debug_gnu_pubnames 0 : { *(.debug_gnu_pubnames) } \
  617. .debug_gnu_pubtypes 0 : { *(.debug_gnu_pubtypes) } \
  618. /* DWARF 4 */ \
  619. .debug_types 0 : { *(.debug_types) } \
  620. /* DWARF 5 */ \
  621. .debug_macro 0 : { *(.debug_macro) } \
  622. .debug_addr 0 : { *(.debug_addr) }
  623. /* Stabs debugging sections. */
  624. #define STABS_DEBUG \
  625. .stab 0 : { *(.stab) } \
  626. .stabstr 0 : { *(.stabstr) } \
  627. .stab.excl 0 : { *(.stab.excl) } \
  628. .stab.exclstr 0 : { *(.stab.exclstr) } \
  629. .stab.index 0 : { *(.stab.index) } \
  630. .stab.indexstr 0 : { *(.stab.indexstr) } \
  631. .comment 0 : { *(.comment) }
  632. #ifdef CONFIG_GENERIC_BUG
  633. #define BUG_TABLE \
  634. . = ALIGN(8); \
  635. __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
  636. VMLINUX_SYMBOL(__start___bug_table) = .; \
  637. KEEP(*(__bug_table)) \
  638. VMLINUX_SYMBOL(__stop___bug_table) = .; \
  639. }
  640. #else
  641. #define BUG_TABLE
  642. #endif
  643. #ifdef CONFIG_UNWINDER_ORC
  644. #define ORC_UNWIND_TABLE \
  645. . = ALIGN(4); \
  646. .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) { \
  647. VMLINUX_SYMBOL(__start_orc_unwind_ip) = .; \
  648. KEEP(*(.orc_unwind_ip)) \
  649. VMLINUX_SYMBOL(__stop_orc_unwind_ip) = .; \
  650. } \
  651. . = ALIGN(6); \
  652. .orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \
  653. VMLINUX_SYMBOL(__start_orc_unwind) = .; \
  654. KEEP(*(.orc_unwind)) \
  655. VMLINUX_SYMBOL(__stop_orc_unwind) = .; \
  656. } \
  657. . = ALIGN(4); \
  658. .orc_lookup : AT(ADDR(.orc_lookup) - LOAD_OFFSET) { \
  659. VMLINUX_SYMBOL(orc_lookup) = .; \
  660. . += (((SIZEOF(.text) + LOOKUP_BLOCK_SIZE - 1) / \
  661. LOOKUP_BLOCK_SIZE) + 1) * 4; \
  662. VMLINUX_SYMBOL(orc_lookup_end) = .; \
  663. }
  664. #else
  665. #define ORC_UNWIND_TABLE
  666. #endif
  667. #ifdef CONFIG_PM_TRACE
  668. #define TRACEDATA \
  669. . = ALIGN(4); \
  670. .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \
  671. VMLINUX_SYMBOL(__tracedata_start) = .; \
  672. KEEP(*(.tracedata)) \
  673. VMLINUX_SYMBOL(__tracedata_end) = .; \
  674. }
  675. #else
  676. #define TRACEDATA
  677. #endif
  678. #define NOTES \
  679. .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
  680. VMLINUX_SYMBOL(__start_notes) = .; \
  681. *(.note.*) \
  682. VMLINUX_SYMBOL(__stop_notes) = .; \
  683. }
  684. #define INIT_SETUP(initsetup_align) \
  685. . = ALIGN(initsetup_align); \
  686. VMLINUX_SYMBOL(__setup_start) = .; \
  687. KEEP(*(.init.setup)) \
  688. VMLINUX_SYMBOL(__setup_end) = .;
  689. #define INIT_CALLS_LEVEL(level) \
  690. VMLINUX_SYMBOL(__initcall##level##_start) = .; \
  691. KEEP(*(.initcall##level##.init)) \
  692. KEEP(*(.initcall##level##s.init)) \
  693. #define INIT_CALLS \
  694. VMLINUX_SYMBOL(__initcall_start) = .; \
  695. KEEP(*(.initcallearly.init)) \
  696. INIT_CALLS_LEVEL(0) \
  697. INIT_CALLS_LEVEL(1) \
  698. INIT_CALLS_LEVEL(2) \
  699. INIT_CALLS_LEVEL(3) \
  700. INIT_CALLS_LEVEL(4) \
  701. INIT_CALLS_LEVEL(5) \
  702. INIT_CALLS_LEVEL(rootfs) \
  703. INIT_CALLS_LEVEL(6) \
  704. INIT_CALLS_LEVEL(7) \
  705. VMLINUX_SYMBOL(__initcall_end) = .;
  706. #define CON_INITCALL \
  707. VMLINUX_SYMBOL(__con_initcall_start) = .; \
  708. KEEP(*(.con_initcall.init)) \
  709. VMLINUX_SYMBOL(__con_initcall_end) = .;
  710. #define SECURITY_INITCALL \
  711. VMLINUX_SYMBOL(__security_initcall_start) = .; \
  712. KEEP(*(.security_initcall.init)) \
  713. VMLINUX_SYMBOL(__security_initcall_end) = .;
  714. #ifdef CONFIG_BLK_DEV_INITRD
  715. #define INIT_RAM_FS \
  716. . = ALIGN(4); \
  717. VMLINUX_SYMBOL(__initramfs_start) = .; \
  718. KEEP(*(.init.ramfs)) \
  719. . = ALIGN(8); \
  720. KEEP(*(.init.ramfs.info))
  721. #else
  722. #define INIT_RAM_FS
  723. #endif
  724. /*
  725. * Memory encryption operates on a page basis. Since we need to clear
  726. * the memory encryption mask for this section, it needs to be aligned
  727. * on a page boundary and be a page-size multiple in length.
  728. *
  729. * Note: We use a separate section so that only this section gets
  730. * decrypted to avoid exposing more than we wish.
  731. */
  732. #ifdef CONFIG_AMD_MEM_ENCRYPT
  733. #define PERCPU_DECRYPTED_SECTION \
  734. . = ALIGN(PAGE_SIZE); \
  735. *(.data..percpu..decrypted) \
  736. . = ALIGN(PAGE_SIZE);
  737. #else
  738. #define PERCPU_DECRYPTED_SECTION
  739. #endif
  740. /*
  741. * Default discarded sections.
  742. *
  743. * Some archs want to discard exit text/data at runtime rather than
  744. * link time due to cross-section references such as alt instructions,
  745. * bug table, eh_frame, etc. DISCARDS must be the last of output
  746. * section definitions so that such archs put those in earlier section
  747. * definitions.
  748. */
  749. #define DISCARDS \
  750. /DISCARD/ : { \
  751. EXIT_TEXT \
  752. EXIT_DATA \
  753. EXIT_CALL \
  754. *(.discard) \
  755. *(.discard.*) \
  756. }
  757. /**
  758. * PERCPU_INPUT - the percpu input sections
  759. * @cacheline: cacheline size
  760. *
  761. * The core percpu section names and core symbols which do not rely
  762. * directly upon load addresses.
  763. *
  764. * @cacheline is used to align subsections to avoid false cacheline
  765. * sharing between subsections for different purposes.
  766. */
  767. #define PERCPU_INPUT(cacheline) \
  768. VMLINUX_SYMBOL(__per_cpu_start) = .; \
  769. *(.data..percpu..first) \
  770. . = ALIGN(PAGE_SIZE); \
  771. *(.data..percpu..page_aligned) \
  772. . = ALIGN(cacheline); \
  773. *(.data..percpu..read_mostly) \
  774. . = ALIGN(cacheline); \
  775. *(.data..percpu) \
  776. *(.data..percpu..shared_aligned) \
  777. PERCPU_DECRYPTED_SECTION \
  778. VMLINUX_SYMBOL(__per_cpu_end) = .;
  779. /**
  780. * PERCPU_VADDR - define output section for percpu area
  781. * @cacheline: cacheline size
  782. * @vaddr: explicit base address (optional)
  783. * @phdr: destination PHDR (optional)
  784. *
  785. * Macro which expands to output section for percpu area.
  786. *
  787. * @cacheline is used to align subsections to avoid false cacheline
  788. * sharing between subsections for different purposes.
  789. *
  790. * If @vaddr is not blank, it specifies explicit base address and all
  791. * percpu symbols will be offset from the given address. If blank,
  792. * @vaddr always equals @laddr + LOAD_OFFSET.
  793. *
  794. * @phdr defines the output PHDR to use if not blank. Be warned that
  795. * output PHDR is sticky. If @phdr is specified, the next output
  796. * section in the linker script will go there too. @phdr should have
  797. * a leading colon.
  798. *
  799. * Note that this macros defines __per_cpu_load as an absolute symbol.
  800. * If there is no need to put the percpu section at a predetermined
  801. * address, use PERCPU_SECTION.
  802. */
  803. #define PERCPU_VADDR(cacheline, vaddr, phdr) \
  804. VMLINUX_SYMBOL(__per_cpu_load) = .; \
  805. .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
  806. - LOAD_OFFSET) { \
  807. PERCPU_INPUT(cacheline) \
  808. } phdr \
  809. . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
  810. /**
  811. * PERCPU_SECTION - define output section for percpu area, simple version
  812. * @cacheline: cacheline size
  813. *
  814. * Align to PAGE_SIZE and outputs output section for percpu area. This
  815. * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
  816. * __per_cpu_start will be identical.
  817. *
  818. * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
  819. * except that __per_cpu_load is defined as a relative symbol against
  820. * .data..percpu which is required for relocatable x86_32 configuration.
  821. */
  822. #define PERCPU_SECTION(cacheline) \
  823. . = ALIGN(PAGE_SIZE); \
  824. .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
  825. VMLINUX_SYMBOL(__per_cpu_load) = .; \
  826. PERCPU_INPUT(cacheline) \
  827. }
  828. /*
  829. * Definition of the high level *_SECTION macros
  830. * They will fit only a subset of the architectures
  831. */
  832. /*
  833. * Writeable data.
  834. * All sections are combined in a single .data section.
  835. * The sections following CONSTRUCTORS are arranged so their
  836. * typical alignment matches.
  837. * A cacheline is typical/always less than a PAGE_SIZE so
  838. * the sections that has this restriction (or similar)
  839. * is located before the ones requiring PAGE_SIZE alignment.
  840. * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
  841. * matches the requirement of PAGE_ALIGNED_DATA.
  842. *
  843. * use 0 as page_align if page_aligned data is not used */
  844. #define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
  845. . = ALIGN(PAGE_SIZE); \
  846. .data : AT(ADDR(.data) - LOAD_OFFSET) { \
  847. INIT_TASK_DATA(inittask) \
  848. NOSAVE_DATA \
  849. PAGE_ALIGNED_DATA(pagealigned) \
  850. CACHELINE_ALIGNED_DATA(cacheline) \
  851. READ_MOSTLY_DATA(cacheline) \
  852. DATA_DATA \
  853. CONSTRUCTORS \
  854. } \
  855. BUG_TABLE \
  856. #define INIT_TEXT_SECTION(inittext_align) \
  857. . = ALIGN(inittext_align); \
  858. .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \
  859. VMLINUX_SYMBOL(_sinittext) = .; \
  860. INIT_TEXT \
  861. VMLINUX_SYMBOL(_einittext) = .; \
  862. }
  863. #define INIT_DATA_SECTION(initsetup_align) \
  864. .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \
  865. INIT_DATA \
  866. INIT_SETUP(initsetup_align) \
  867. INIT_CALLS \
  868. CON_INITCALL \
  869. SECURITY_INITCALL \
  870. INIT_RAM_FS \
  871. }
  872. #define BSS_SECTION(sbss_align, bss_align, stop_align) \
  873. . = ALIGN(sbss_align); \
  874. VMLINUX_SYMBOL(__bss_start) = .; \
  875. SBSS(sbss_align) \
  876. BSS(bss_align) \
  877. . = ALIGN(stop_align); \
  878. VMLINUX_SYMBOL(__bss_stop) = .;