vmlinux.lds.h 28 KB

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