vmlinux.lds.h 28 KB

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