vmlinux.lds.h 27 KB

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