vmlinux.lds.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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. *(_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. *(_ftrace_events) \
  131. VMLINUX_SYMBOL(__stop_ftrace_events) = .; \
  132. VMLINUX_SYMBOL(__start_ftrace_enum_maps) = .; \
  133. *(_ftrace_enum_map) \
  134. VMLINUX_SYMBOL(__stop_ftrace_enum_maps) = .;
  135. #else
  136. #define FTRACE_EVENTS()
  137. #endif
  138. #ifdef CONFIG_TRACING
  139. #define TRACE_PRINTKS() VMLINUX_SYMBOL(__start___trace_bprintk_fmt) = .; \
  140. *(__trace_printk_fmt) /* Trace_printk fmt' pointer */ \
  141. VMLINUX_SYMBOL(__stop___trace_bprintk_fmt) = .;
  142. #define TRACEPOINT_STR() VMLINUX_SYMBOL(__start___tracepoint_str) = .; \
  143. *(__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. *(__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() . = ALIGN(8); \
  159. VMLINUX_SYMBOL(__earlycon_table) = .; \
  160. *(__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. *(__##name##_of_table) \
  173. *(__##name##_of_table_end)
  174. #define CLKSRC_OF_TABLES() OF_TABLE(CONFIG_CLKSRC_OF, clksrc)
  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. *(__##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. *(.dtb.init.rodata) \
  194. VMLINUX_SYMBOL(__dtb_end) = .;
  195. /*
  196. * .data section
  197. */
  198. #define DATA_DATA \
  199. *(DATA_MAIN) \
  200. *(.ref.data) \
  201. *(.data..shared_aligned) /* percpu related */ \
  202. MEM_KEEP(init.data) \
  203. MEM_KEEP(exit.data) \
  204. *(.data.unlikely) \
  205. STRUCT_ALIGN(); \
  206. *(__tracepoints) \
  207. /* implement dynamic printk debug */ \
  208. . = ALIGN(8); \
  209. VMLINUX_SYMBOL(__start___jump_table) = .; \
  210. *(__jump_table) \
  211. VMLINUX_SYMBOL(__stop___jump_table) = .; \
  212. . = ALIGN(8); \
  213. VMLINUX_SYMBOL(__start___verbose) = .; \
  214. *(__verbose) \
  215. VMLINUX_SYMBOL(__stop___verbose) = .; \
  216. LIKELY_PROFILE() \
  217. BRANCH_PROFILE() \
  218. TRACE_PRINTKS() \
  219. TRACEPOINT_STR()
  220. /*
  221. * Data section helpers
  222. */
  223. #define NOSAVE_DATA \
  224. . = ALIGN(PAGE_SIZE); \
  225. VMLINUX_SYMBOL(__nosave_begin) = .; \
  226. *(.data..nosave) \
  227. . = ALIGN(PAGE_SIZE); \
  228. VMLINUX_SYMBOL(__nosave_end) = .;
  229. #define PAGE_ALIGNED_DATA(page_align) \
  230. . = ALIGN(page_align); \
  231. *(.data..page_aligned)
  232. #define READ_MOSTLY_DATA(align) \
  233. . = ALIGN(align); \
  234. *(.data..read_mostly) \
  235. . = ALIGN(align);
  236. #define CACHELINE_ALIGNED_DATA(align) \
  237. . = ALIGN(align); \
  238. *(.data..cacheline_aligned)
  239. #define INIT_TASK_DATA(align) \
  240. . = ALIGN(align); \
  241. VMLINUX_SYMBOL(__start_init_task) = .; \
  242. *(.data..init_task) \
  243. VMLINUX_SYMBOL(__end_init_task) = .;
  244. /*
  245. * Allow architectures to handle ro_after_init data on their
  246. * own by defining an empty RO_AFTER_INIT_DATA.
  247. */
  248. #ifndef RO_AFTER_INIT_DATA
  249. #define RO_AFTER_INIT_DATA \
  250. __start_data_ro_after_init = .; \
  251. *(.data..ro_after_init) \
  252. __end_data_ro_after_init = .;
  253. #endif
  254. /*
  255. * Read only Data
  256. */
  257. #define RO_DATA_SECTION(align) \
  258. . = ALIGN((align)); \
  259. .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
  260. VMLINUX_SYMBOL(__start_rodata) = .; \
  261. *(.rodata) *(.rodata.*) \
  262. RO_AFTER_INIT_DATA /* Read only after init */ \
  263. *(__vermagic) /* Kernel version magic */ \
  264. . = ALIGN(8); \
  265. VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
  266. *(__tracepoints_ptrs) /* Tracepoints: pointer array */\
  267. VMLINUX_SYMBOL(__stop___tracepoints_ptrs) = .; \
  268. *(__tracepoints_strings)/* Tracepoints: strings */ \
  269. } \
  270. \
  271. .rodata1 : AT(ADDR(.rodata1) - LOAD_OFFSET) { \
  272. *(.rodata1) \
  273. } \
  274. \
  275. BUG_TABLE \
  276. \
  277. /* PCI quirks */ \
  278. .pci_fixup : AT(ADDR(.pci_fixup) - LOAD_OFFSET) { \
  279. VMLINUX_SYMBOL(__start_pci_fixups_early) = .; \
  280. *(.pci_fixup_early) \
  281. VMLINUX_SYMBOL(__end_pci_fixups_early) = .; \
  282. VMLINUX_SYMBOL(__start_pci_fixups_header) = .; \
  283. *(.pci_fixup_header) \
  284. VMLINUX_SYMBOL(__end_pci_fixups_header) = .; \
  285. VMLINUX_SYMBOL(__start_pci_fixups_final) = .; \
  286. *(.pci_fixup_final) \
  287. VMLINUX_SYMBOL(__end_pci_fixups_final) = .; \
  288. VMLINUX_SYMBOL(__start_pci_fixups_enable) = .; \
  289. *(.pci_fixup_enable) \
  290. VMLINUX_SYMBOL(__end_pci_fixups_enable) = .; \
  291. VMLINUX_SYMBOL(__start_pci_fixups_resume) = .; \
  292. *(.pci_fixup_resume) \
  293. VMLINUX_SYMBOL(__end_pci_fixups_resume) = .; \
  294. VMLINUX_SYMBOL(__start_pci_fixups_resume_early) = .; \
  295. *(.pci_fixup_resume_early) \
  296. VMLINUX_SYMBOL(__end_pci_fixups_resume_early) = .; \
  297. VMLINUX_SYMBOL(__start_pci_fixups_suspend) = .; \
  298. *(.pci_fixup_suspend) \
  299. VMLINUX_SYMBOL(__end_pci_fixups_suspend) = .; \
  300. VMLINUX_SYMBOL(__start_pci_fixups_suspend_late) = .; \
  301. *(.pci_fixup_suspend_late) \
  302. VMLINUX_SYMBOL(__end_pci_fixups_suspend_late) = .; \
  303. } \
  304. \
  305. /* Built-in firmware blobs */ \
  306. .builtin_fw : AT(ADDR(.builtin_fw) - LOAD_OFFSET) { \
  307. VMLINUX_SYMBOL(__start_builtin_fw) = .; \
  308. *(.builtin_fw) \
  309. VMLINUX_SYMBOL(__end_builtin_fw) = .; \
  310. } \
  311. \
  312. TRACEDATA \
  313. \
  314. /* Kernel symbol table: Normal symbols */ \
  315. __ksymtab : AT(ADDR(__ksymtab) - LOAD_OFFSET) { \
  316. VMLINUX_SYMBOL(__start___ksymtab) = .; \
  317. KEEP(*(SORT(___ksymtab+*))) \
  318. VMLINUX_SYMBOL(__stop___ksymtab) = .; \
  319. } \
  320. \
  321. /* Kernel symbol table: GPL-only symbols */ \
  322. __ksymtab_gpl : AT(ADDR(__ksymtab_gpl) - LOAD_OFFSET) { \
  323. VMLINUX_SYMBOL(__start___ksymtab_gpl) = .; \
  324. KEEP(*(SORT(___ksymtab_gpl+*))) \
  325. VMLINUX_SYMBOL(__stop___ksymtab_gpl) = .; \
  326. } \
  327. \
  328. /* Kernel symbol table: Normal unused symbols */ \
  329. __ksymtab_unused : AT(ADDR(__ksymtab_unused) - LOAD_OFFSET) { \
  330. VMLINUX_SYMBOL(__start___ksymtab_unused) = .; \
  331. KEEP(*(SORT(___ksymtab_unused+*))) \
  332. VMLINUX_SYMBOL(__stop___ksymtab_unused) = .; \
  333. } \
  334. \
  335. /* Kernel symbol table: GPL-only unused symbols */ \
  336. __ksymtab_unused_gpl : AT(ADDR(__ksymtab_unused_gpl) - LOAD_OFFSET) { \
  337. VMLINUX_SYMBOL(__start___ksymtab_unused_gpl) = .; \
  338. KEEP(*(SORT(___ksymtab_unused_gpl+*))) \
  339. VMLINUX_SYMBOL(__stop___ksymtab_unused_gpl) = .; \
  340. } \
  341. \
  342. /* Kernel symbol table: GPL-future-only symbols */ \
  343. __ksymtab_gpl_future : AT(ADDR(__ksymtab_gpl_future) - LOAD_OFFSET) { \
  344. VMLINUX_SYMBOL(__start___ksymtab_gpl_future) = .; \
  345. KEEP(*(SORT(___ksymtab_gpl_future+*))) \
  346. VMLINUX_SYMBOL(__stop___ksymtab_gpl_future) = .; \
  347. } \
  348. \
  349. /* Kernel symbol table: Normal symbols */ \
  350. __kcrctab : AT(ADDR(__kcrctab) - LOAD_OFFSET) { \
  351. VMLINUX_SYMBOL(__start___kcrctab) = .; \
  352. KEEP(*(SORT(___kcrctab+*))) \
  353. VMLINUX_SYMBOL(__stop___kcrctab) = .; \
  354. } \
  355. \
  356. /* Kernel symbol table: GPL-only symbols */ \
  357. __kcrctab_gpl : AT(ADDR(__kcrctab_gpl) - LOAD_OFFSET) { \
  358. VMLINUX_SYMBOL(__start___kcrctab_gpl) = .; \
  359. KEEP(*(SORT(___kcrctab_gpl+*))) \
  360. VMLINUX_SYMBOL(__stop___kcrctab_gpl) = .; \
  361. } \
  362. \
  363. /* Kernel symbol table: Normal unused symbols */ \
  364. __kcrctab_unused : AT(ADDR(__kcrctab_unused) - LOAD_OFFSET) { \
  365. VMLINUX_SYMBOL(__start___kcrctab_unused) = .; \
  366. KEEP(*(SORT(___kcrctab_unused+*))) \
  367. VMLINUX_SYMBOL(__stop___kcrctab_unused) = .; \
  368. } \
  369. \
  370. /* Kernel symbol table: GPL-only unused symbols */ \
  371. __kcrctab_unused_gpl : AT(ADDR(__kcrctab_unused_gpl) - LOAD_OFFSET) { \
  372. VMLINUX_SYMBOL(__start___kcrctab_unused_gpl) = .; \
  373. KEEP(*(SORT(___kcrctab_unused_gpl+*))) \
  374. VMLINUX_SYMBOL(__stop___kcrctab_unused_gpl) = .; \
  375. } \
  376. \
  377. /* Kernel symbol table: GPL-future-only symbols */ \
  378. __kcrctab_gpl_future : AT(ADDR(__kcrctab_gpl_future) - LOAD_OFFSET) { \
  379. VMLINUX_SYMBOL(__start___kcrctab_gpl_future) = .; \
  380. KEEP(*(SORT(___kcrctab_gpl_future+*))) \
  381. VMLINUX_SYMBOL(__stop___kcrctab_gpl_future) = .; \
  382. } \
  383. \
  384. /* Kernel symbol table: strings */ \
  385. __ksymtab_strings : AT(ADDR(__ksymtab_strings) - LOAD_OFFSET) { \
  386. KEEP(*(__ksymtab_strings)) \
  387. } \
  388. \
  389. /* __*init sections */ \
  390. __init_rodata : AT(ADDR(__init_rodata) - LOAD_OFFSET) { \
  391. *(.ref.rodata) \
  392. MEM_KEEP(init.rodata) \
  393. MEM_KEEP(exit.rodata) \
  394. } \
  395. \
  396. /* Built-in module parameters. */ \
  397. __param : AT(ADDR(__param) - LOAD_OFFSET) { \
  398. VMLINUX_SYMBOL(__start___param) = .; \
  399. *(__param) \
  400. VMLINUX_SYMBOL(__stop___param) = .; \
  401. } \
  402. \
  403. /* Built-in module versions. */ \
  404. __modver : AT(ADDR(__modver) - LOAD_OFFSET) { \
  405. VMLINUX_SYMBOL(__start___modver) = .; \
  406. *(__modver) \
  407. VMLINUX_SYMBOL(__stop___modver) = .; \
  408. . = ALIGN((align)); \
  409. VMLINUX_SYMBOL(__end_rodata) = .; \
  410. } \
  411. . = ALIGN((align));
  412. /* RODATA & RO_DATA provided for backward compatibility.
  413. * All archs are supposed to use RO_DATA() */
  414. #define RODATA RO_DATA_SECTION(4096)
  415. #define RO_DATA(align) RO_DATA_SECTION(align)
  416. #define SECURITY_INIT \
  417. .security_initcall.init : AT(ADDR(.security_initcall.init) - LOAD_OFFSET) { \
  418. VMLINUX_SYMBOL(__security_initcall_start) = .; \
  419. KEEP(*(.security_initcall.init)) \
  420. VMLINUX_SYMBOL(__security_initcall_end) = .; \
  421. }
  422. /*
  423. * .text section. Map to function alignment to avoid address changes
  424. * during second ld run in second ld pass when generating System.map
  425. *
  426. * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
  427. * code elimination is enabled, so these sections should be converted
  428. * to use ".." first.
  429. */
  430. #define TEXT_TEXT \
  431. ALIGN_FUNCTION(); \
  432. *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \
  433. *(.ref.text) \
  434. MEM_KEEP(init.text) \
  435. MEM_KEEP(exit.text) \
  436. /* sched.text is aling to function alignment to secure we have same
  437. * address even at second ld pass when generating System.map */
  438. #define SCHED_TEXT \
  439. ALIGN_FUNCTION(); \
  440. VMLINUX_SYMBOL(__sched_text_start) = .; \
  441. *(.sched.text) \
  442. VMLINUX_SYMBOL(__sched_text_end) = .;
  443. /* spinlock.text is aling to function alignment to secure we have same
  444. * address even at second ld pass when generating System.map */
  445. #define LOCK_TEXT \
  446. ALIGN_FUNCTION(); \
  447. VMLINUX_SYMBOL(__lock_text_start) = .; \
  448. *(.spinlock.text) \
  449. VMLINUX_SYMBOL(__lock_text_end) = .;
  450. #define CPUIDLE_TEXT \
  451. ALIGN_FUNCTION(); \
  452. VMLINUX_SYMBOL(__cpuidle_text_start) = .; \
  453. *(.cpuidle.text) \
  454. VMLINUX_SYMBOL(__cpuidle_text_end) = .;
  455. #define KPROBES_TEXT \
  456. ALIGN_FUNCTION(); \
  457. VMLINUX_SYMBOL(__kprobes_text_start) = .; \
  458. *(.kprobes.text) \
  459. VMLINUX_SYMBOL(__kprobes_text_end) = .;
  460. #define ENTRY_TEXT \
  461. ALIGN_FUNCTION(); \
  462. VMLINUX_SYMBOL(__entry_text_start) = .; \
  463. *(.entry.text) \
  464. VMLINUX_SYMBOL(__entry_text_end) = .;
  465. #if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
  466. #define IRQENTRY_TEXT \
  467. ALIGN_FUNCTION(); \
  468. VMLINUX_SYMBOL(__irqentry_text_start) = .; \
  469. *(.irqentry.text) \
  470. VMLINUX_SYMBOL(__irqentry_text_end) = .;
  471. #else
  472. #define IRQENTRY_TEXT
  473. #endif
  474. #if defined(CONFIG_FUNCTION_GRAPH_TRACER) || defined(CONFIG_KASAN)
  475. #define SOFTIRQENTRY_TEXT \
  476. ALIGN_FUNCTION(); \
  477. VMLINUX_SYMBOL(__softirqentry_text_start) = .; \
  478. *(.softirqentry.text) \
  479. VMLINUX_SYMBOL(__softirqentry_text_end) = .;
  480. #else
  481. #define SOFTIRQENTRY_TEXT
  482. #endif
  483. /* Section used for early init (in .S files) */
  484. #define HEAD_TEXT *(.head.text)
  485. #define HEAD_TEXT_SECTION \
  486. .head.text : AT(ADDR(.head.text) - LOAD_OFFSET) { \
  487. HEAD_TEXT \
  488. }
  489. /*
  490. * Exception table
  491. */
  492. #define EXCEPTION_TABLE(align) \
  493. . = ALIGN(align); \
  494. __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { \
  495. VMLINUX_SYMBOL(__start___ex_table) = .; \
  496. *(__ex_table) \
  497. VMLINUX_SYMBOL(__stop___ex_table) = .; \
  498. }
  499. /*
  500. * Init task
  501. */
  502. #define INIT_TASK_DATA_SECTION(align) \
  503. . = ALIGN(align); \
  504. .data..init_task : AT(ADDR(.data..init_task) - LOAD_OFFSET) { \
  505. INIT_TASK_DATA(align) \
  506. }
  507. #ifdef CONFIG_CONSTRUCTORS
  508. #define KERNEL_CTORS() . = ALIGN(8); \
  509. VMLINUX_SYMBOL(__ctors_start) = .; \
  510. *(.ctors) \
  511. *(SORT(.init_array.*)) \
  512. *(.init_array) \
  513. VMLINUX_SYMBOL(__ctors_end) = .;
  514. #else
  515. #define KERNEL_CTORS()
  516. #endif
  517. /* init and exit section handling */
  518. #define INIT_DATA \
  519. KEEP(*(SORT(___kentry+*))) \
  520. *(.init.data) \
  521. MEM_DISCARD(init.data) \
  522. KERNEL_CTORS() \
  523. MCOUNT_REC() \
  524. *(.init.rodata) \
  525. FTRACE_EVENTS() \
  526. TRACE_SYSCALLS() \
  527. KPROBE_BLACKLIST() \
  528. MEM_DISCARD(init.rodata) \
  529. CLK_OF_TABLES() \
  530. RESERVEDMEM_OF_TABLES() \
  531. CLKSRC_OF_TABLES() \
  532. IOMMU_OF_TABLES() \
  533. CPU_METHOD_OF_TABLES() \
  534. CPUIDLE_METHOD_OF_TABLES() \
  535. KERNEL_DTB() \
  536. IRQCHIP_OF_MATCH_TABLE() \
  537. ACPI_PROBE_TABLE(irqchip) \
  538. ACPI_PROBE_TABLE(clksrc) \
  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. *(.sbss) \
  564. *(.scommon) \
  565. }
  566. /*
  567. * Allow archectures to redefine BSS_FIRST_SECTIONS to add extra
  568. * sections to the front of bss.
  569. */
  570. #ifndef BSS_FIRST_SECTIONS
  571. #define BSS_FIRST_SECTIONS
  572. #endif
  573. #define BSS(bss_align) \
  574. . = ALIGN(bss_align); \
  575. .bss : AT(ADDR(.bss) - LOAD_OFFSET) { \
  576. BSS_FIRST_SECTIONS \
  577. *(.bss..page_aligned) \
  578. *(.dynbss) \
  579. *(BSS_MAIN) \
  580. *(COMMON) \
  581. }
  582. /*
  583. * DWARF debug sections.
  584. * Symbols in the DWARF debugging sections are relative to
  585. * the beginning of the section so we begin them at 0.
  586. */
  587. #define DWARF_DEBUG \
  588. /* DWARF 1 */ \
  589. .debug 0 : { *(.debug) } \
  590. .line 0 : { *(.line) } \
  591. /* GNU DWARF 1 extensions */ \
  592. .debug_srcinfo 0 : { *(.debug_srcinfo) } \
  593. .debug_sfnames 0 : { *(.debug_sfnames) } \
  594. /* DWARF 1.1 and DWARF 2 */ \
  595. .debug_aranges 0 : { *(.debug_aranges) } \
  596. .debug_pubnames 0 : { *(.debug_pubnames) } \
  597. /* DWARF 2 */ \
  598. .debug_info 0 : { *(.debug_info \
  599. .gnu.linkonce.wi.*) } \
  600. .debug_abbrev 0 : { *(.debug_abbrev) } \
  601. .debug_line 0 : { *(.debug_line) } \
  602. .debug_frame 0 : { *(.debug_frame) } \
  603. .debug_str 0 : { *(.debug_str) } \
  604. .debug_loc 0 : { *(.debug_loc) } \
  605. .debug_macinfo 0 : { *(.debug_macinfo) } \
  606. /* SGI/MIPS DWARF 2 extensions */ \
  607. .debug_weaknames 0 : { *(.debug_weaknames) } \
  608. .debug_funcnames 0 : { *(.debug_funcnames) } \
  609. .debug_typenames 0 : { *(.debug_typenames) } \
  610. .debug_varnames 0 : { *(.debug_varnames) } \
  611. /* Stabs debugging sections. */
  612. #define STABS_DEBUG \
  613. .stab 0 : { *(.stab) } \
  614. .stabstr 0 : { *(.stabstr) } \
  615. .stab.excl 0 : { *(.stab.excl) } \
  616. .stab.exclstr 0 : { *(.stab.exclstr) } \
  617. .stab.index 0 : { *(.stab.index) } \
  618. .stab.indexstr 0 : { *(.stab.indexstr) } \
  619. .comment 0 : { *(.comment) }
  620. #ifdef CONFIG_GENERIC_BUG
  621. #define BUG_TABLE \
  622. . = ALIGN(8); \
  623. __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
  624. VMLINUX_SYMBOL(__start___bug_table) = .; \
  625. *(__bug_table) \
  626. VMLINUX_SYMBOL(__stop___bug_table) = .; \
  627. }
  628. #else
  629. #define BUG_TABLE
  630. #endif
  631. #ifdef CONFIG_PM_TRACE
  632. #define TRACEDATA \
  633. . = ALIGN(4); \
  634. .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { \
  635. VMLINUX_SYMBOL(__tracedata_start) = .; \
  636. *(.tracedata) \
  637. VMLINUX_SYMBOL(__tracedata_end) = .; \
  638. }
  639. #else
  640. #define TRACEDATA
  641. #endif
  642. #define NOTES \
  643. .notes : AT(ADDR(.notes) - LOAD_OFFSET) { \
  644. VMLINUX_SYMBOL(__start_notes) = .; \
  645. *(.note.*) \
  646. VMLINUX_SYMBOL(__stop_notes) = .; \
  647. }
  648. #define INIT_SETUP(initsetup_align) \
  649. . = ALIGN(initsetup_align); \
  650. VMLINUX_SYMBOL(__setup_start) = .; \
  651. *(.init.setup) \
  652. VMLINUX_SYMBOL(__setup_end) = .;
  653. #define INIT_CALLS_LEVEL(level) \
  654. VMLINUX_SYMBOL(__initcall##level##_start) = .; \
  655. KEEP(*(.initcall##level##.init)) \
  656. KEEP(*(.initcall##level##s.init)) \
  657. #define INIT_CALLS \
  658. VMLINUX_SYMBOL(__initcall_start) = .; \
  659. KEEP(*(.initcallearly.init)) \
  660. INIT_CALLS_LEVEL(0) \
  661. INIT_CALLS_LEVEL(1) \
  662. INIT_CALLS_LEVEL(2) \
  663. INIT_CALLS_LEVEL(3) \
  664. INIT_CALLS_LEVEL(4) \
  665. INIT_CALLS_LEVEL(5) \
  666. INIT_CALLS_LEVEL(rootfs) \
  667. INIT_CALLS_LEVEL(6) \
  668. INIT_CALLS_LEVEL(7) \
  669. VMLINUX_SYMBOL(__initcall_end) = .;
  670. #define CON_INITCALL \
  671. VMLINUX_SYMBOL(__con_initcall_start) = .; \
  672. KEEP(*(.con_initcall.init)) \
  673. VMLINUX_SYMBOL(__con_initcall_end) = .;
  674. #define SECURITY_INITCALL \
  675. VMLINUX_SYMBOL(__security_initcall_start) = .; \
  676. KEEP(*(.security_initcall.init)) \
  677. VMLINUX_SYMBOL(__security_initcall_end) = .;
  678. #ifdef CONFIG_BLK_DEV_INITRD
  679. #define INIT_RAM_FS \
  680. . = ALIGN(4); \
  681. VMLINUX_SYMBOL(__initramfs_start) = .; \
  682. KEEP(*(.init.ramfs)) \
  683. . = ALIGN(8); \
  684. KEEP(*(.init.ramfs.info))
  685. #else
  686. #define INIT_RAM_FS
  687. #endif
  688. /*
  689. * Default discarded sections.
  690. *
  691. * Some archs want to discard exit text/data at runtime rather than
  692. * link time due to cross-section references such as alt instructions,
  693. * bug table, eh_frame, etc. DISCARDS must be the last of output
  694. * section definitions so that such archs put those in earlier section
  695. * definitions.
  696. */
  697. #define DISCARDS \
  698. /DISCARD/ : { \
  699. EXIT_TEXT \
  700. EXIT_DATA \
  701. EXIT_CALL \
  702. *(.discard) \
  703. *(.discard.*) \
  704. }
  705. /**
  706. * PERCPU_INPUT - the percpu input sections
  707. * @cacheline: cacheline size
  708. *
  709. * The core percpu section names and core symbols which do not rely
  710. * directly upon load addresses.
  711. *
  712. * @cacheline is used to align subsections to avoid false cacheline
  713. * sharing between subsections for different purposes.
  714. */
  715. #define PERCPU_INPUT(cacheline) \
  716. VMLINUX_SYMBOL(__per_cpu_start) = .; \
  717. VMLINUX_SYMBOL(__per_cpu_user_mapped_start) = .; \
  718. *(.data..percpu..first) \
  719. . = ALIGN(cacheline); \
  720. *(.data..percpu..user_mapped) \
  721. *(.data..percpu..user_mapped..shared_aligned) \
  722. . = ALIGN(PAGE_SIZE); \
  723. *(.data..percpu..user_mapped..page_aligned) \
  724. VMLINUX_SYMBOL(__per_cpu_user_mapped_end) = .; \
  725. . = ALIGN(PAGE_SIZE); \
  726. *(.data..percpu..page_aligned) \
  727. . = ALIGN(cacheline); \
  728. *(.data..percpu..read_mostly) \
  729. . = ALIGN(cacheline); \
  730. *(.data..percpu) \
  731. *(.data..percpu..shared_aligned) \
  732. VMLINUX_SYMBOL(__per_cpu_end) = .;
  733. /**
  734. * PERCPU_VADDR - define output section for percpu area
  735. * @cacheline: cacheline size
  736. * @vaddr: explicit base address (optional)
  737. * @phdr: destination PHDR (optional)
  738. *
  739. * Macro which expands to output section for percpu area.
  740. *
  741. * @cacheline is used to align subsections to avoid false cacheline
  742. * sharing between subsections for different purposes.
  743. *
  744. * If @vaddr is not blank, it specifies explicit base address and all
  745. * percpu symbols will be offset from the given address. If blank,
  746. * @vaddr always equals @laddr + LOAD_OFFSET.
  747. *
  748. * @phdr defines the output PHDR to use if not blank. Be warned that
  749. * output PHDR is sticky. If @phdr is specified, the next output
  750. * section in the linker script will go there too. @phdr should have
  751. * a leading colon.
  752. *
  753. * Note that this macros defines __per_cpu_load as an absolute symbol.
  754. * If there is no need to put the percpu section at a predetermined
  755. * address, use PERCPU_SECTION.
  756. */
  757. #define PERCPU_VADDR(cacheline, vaddr, phdr) \
  758. VMLINUX_SYMBOL(__per_cpu_load) = .; \
  759. .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
  760. - LOAD_OFFSET) { \
  761. PERCPU_INPUT(cacheline) \
  762. } phdr \
  763. . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
  764. /**
  765. * PERCPU_SECTION - define output section for percpu area, simple version
  766. * @cacheline: cacheline size
  767. *
  768. * Align to PAGE_SIZE and outputs output section for percpu area. This
  769. * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and
  770. * __per_cpu_start will be identical.
  771. *
  772. * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,)
  773. * except that __per_cpu_load is defined as a relative symbol against
  774. * .data..percpu which is required for relocatable x86_32 configuration.
  775. */
  776. #define PERCPU_SECTION(cacheline) \
  777. . = ALIGN(PAGE_SIZE); \
  778. .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \
  779. VMLINUX_SYMBOL(__per_cpu_load) = .; \
  780. PERCPU_INPUT(cacheline) \
  781. }
  782. /*
  783. * Definition of the high level *_SECTION macros
  784. * They will fit only a subset of the architectures
  785. */
  786. /*
  787. * Writeable data.
  788. * All sections are combined in a single .data section.
  789. * The sections following CONSTRUCTORS are arranged so their
  790. * typical alignment matches.
  791. * A cacheline is typical/always less than a PAGE_SIZE so
  792. * the sections that has this restriction (or similar)
  793. * is located before the ones requiring PAGE_SIZE alignment.
  794. * NOSAVE_DATA starts and ends with a PAGE_SIZE alignment which
  795. * matches the requirement of PAGE_ALIGNED_DATA.
  796. *
  797. * use 0 as page_align if page_aligned data is not used */
  798. #define RW_DATA_SECTION(cacheline, pagealigned, inittask) \
  799. . = ALIGN(PAGE_SIZE); \
  800. .data : AT(ADDR(.data) - LOAD_OFFSET) { \
  801. INIT_TASK_DATA(inittask) \
  802. NOSAVE_DATA \
  803. PAGE_ALIGNED_DATA(pagealigned) \
  804. CACHELINE_ALIGNED_DATA(cacheline) \
  805. READ_MOSTLY_DATA(cacheline) \
  806. DATA_DATA \
  807. CONSTRUCTORS \
  808. }
  809. #define INIT_TEXT_SECTION(inittext_align) \
  810. . = ALIGN(inittext_align); \
  811. .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) { \
  812. VMLINUX_SYMBOL(_sinittext) = .; \
  813. INIT_TEXT \
  814. VMLINUX_SYMBOL(_einittext) = .; \
  815. }
  816. #define INIT_DATA_SECTION(initsetup_align) \
  817. .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { \
  818. INIT_DATA \
  819. INIT_SETUP(initsetup_align) \
  820. INIT_CALLS \
  821. CON_INITCALL \
  822. SECURITY_INITCALL \
  823. INIT_RAM_FS \
  824. }
  825. #define BSS_SECTION(sbss_align, bss_align, stop_align) \
  826. . = ALIGN(sbss_align); \
  827. VMLINUX_SYMBOL(__bss_start) = .; \
  828. SBSS(sbss_align) \
  829. BSS(bss_align) \
  830. . = ALIGN(stop_align); \
  831. VMLINUX_SYMBOL(__bss_stop) = .;