blob: 2739a62896ab4b2b01b47061116c6db5ab148478 [file] [log] [blame]
Tejun Heo405d9672009-06-24 15:13:38 +09001/*
2 * Common module linker script, always used when linking a module.
3 * Archs are free to supply their own linker scripts. ld will
4 * combine them automatically.
5 */
Ard Biesheuvel6ec9ba52022-10-27 17:59:06 +02006#ifdef CONFIG_UNWIND_TABLES
7#define DISCARD_EH_FRAME
8#else
9#define DISCARD_EH_FRAME *(.eh_frame)
10#endif
11
Sami Tolvanen28aad1c2021-04-08 11:28:29 -070012#ifdef CONFIG_CFI_CLANG
13# include <asm/page.h>
14# define ALIGN_CFI ALIGN(PAGE_SIZE)
Ard Biesheuvel6ec9ba52022-10-27 17:59:06 +020015# define SANITIZER_DISCARDS DISCARD_EH_FRAME
Sami Tolvanen28aad1c2021-04-08 11:28:29 -070016#else
17# define ALIGN_CFI
18# define SANITIZER_DISCARDS
19#endif
20
Tejun Heo405d9672009-06-24 15:13:38 +090021SECTIONS {
Josh Poimboeufe390f9a2017-03-01 12:04:44 -060022 /DISCARD/ : {
23 *(.discard)
24 *(.discard.*)
Sami Tolvanen28aad1c2021-04-08 11:28:29 -070025 SANITIZER_DISCARDS
Josh Poimboeufe390f9a2017-03-01 12:04:44 -060026 }
Alessio Igor Boganif02e8a62011-04-14 14:59:39 +020027
Rabin Vincent5d8591b2015-02-06 15:09:57 +103028 __ksymtab 0 : { *(SORT(___ksymtab+*)) }
29 __ksymtab_gpl 0 : { *(SORT(___ksymtab_gpl+*)) }
Rabin Vincent5d8591b2015-02-06 15:09:57 +103030 __kcrctab 0 : { *(SORT(___kcrctab+*)) }
31 __kcrctab_gpl 0 : { *(SORT(___kcrctab_gpl+*)) }
Andrey Ryabinin9ddf8252015-02-13 14:40:10 -080032
Reiner Huober4c5afb72021-07-06 15:02:52 +020033 .ctors 0 : ALIGN(8) { *(SORT(.ctors.*)) *(.ctors) }
David Daney5bd933f2017-03-07 17:31:08 -080034 .init_array 0 : ALIGN(8) { *(SORT(.init_array.*)) *(.init_array) }
David Daneyab426322017-03-01 14:04:53 -080035
Helge Deller9774b962022-07-08 11:44:54 +020036 .altinstructions 0 : ALIGN(8) { KEEP(*(.altinstructions)) }
37 __bug_table 0 : ALIGN(8) { KEEP(*(__bug_table)) }
David Daneyab426322017-03-01 14:04:53 -080038 __jump_table 0 : ALIGN(8) { KEEP(*(__jump_table)) }
Sami Tolvanendd277622020-12-11 10:46:22 -080039
40 __patchable_function_entries : { *(__patchable_function_entries) }
41
Eric Biggers6da26b82023-01-06 05:07:18 +000042#if IS_ENABLED(CONFIG_CRYPTO_FIPS140_MOD)
Eric Biggers57be8912023-01-06 05:07:15 +000043 /*
44 * The FIPS140 module incorporates copies of builtin code, which gets
45 * integrity checked at module load time, and registered in a way that
46 * ensures that the integrity checked versions supersede the builtin
47 * ones. These objects are compiled as builtin code, and so their init
48 * hooks will be exported from the binary in the same way as builtin
49 * initcalls are, i.e., annotated with a level that defines the order
50 * in which the hooks are expected to be invoked.
51 */
52#define INIT_CALLS_LEVEL(level) \
53 KEEP(*(.initcall##level##.init*)) \
54 KEEP(*(.initcall##level##s.init*))
55
56 .initcalls : {
57 *(.initcalls._start)
58 INIT_CALLS_LEVEL(0)
59 INIT_CALLS_LEVEL(1)
60 INIT_CALLS_LEVEL(2)
61 INIT_CALLS_LEVEL(3)
62 INIT_CALLS_LEVEL(4)
63 INIT_CALLS_LEVEL(5)
64 INIT_CALLS_LEVEL(rootfs)
65 INIT_CALLS_LEVEL(6)
66 INIT_CALLS_LEVEL(7)
67 *(.initcalls._end)
68 }
69#endif
70
Eric Biggersae4ca7a2023-01-06 05:07:20 +000071#if defined(CONFIG_LTO_CLANG) || IS_ENABLED(CONFIG_CRYPTO_FIPS140_MOD)
Sami Tolvanendd277622020-12-11 10:46:22 -080072 /*
73 * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and
74 * -ffunction-sections, which increases the size of the final module.
75 * Merge the split sections in the final binary.
76 */
77 .bss : {
78 *(.bss .bss.[0-9a-zA-Z_]*)
79 *(.bss..L*)
80 }
81
82 .data : {
83 *(.data .data.[0-9a-zA-Z_]*)
84 *(.data..L*)
85 }
86
87 .rodata : {
Ard Biesheuvel5651d742021-03-23 10:54:38 +010088 *(.rodata.._start)
Sami Tolvanendd277622020-12-11 10:46:22 -080089 *(.rodata .rodata.[0-9a-zA-Z_]*)
90 *(.rodata..L*)
Ard Biesheuvel5651d742021-03-23 10:54:38 +010091 *(.rodata.._end)
Sami Tolvanendd277622020-12-11 10:46:22 -080092 }
93
Sami Tolvanen28aad1c2021-04-08 11:28:29 -070094 /*
95 * With CONFIG_CFI_CLANG, we assume __cfi_check is at the beginning
96 * of the .text section, and is aligned to PAGE_SIZE.
97 */
98 .text : ALIGN_CFI {
Ard Biesheuvel5651d742021-03-23 10:54:38 +010099 *(.text.._start)
Sami Tolvanen28aad1c2021-04-08 11:28:29 -0700100 *(.text.__cfi_check)
101 *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*)
Ard Biesheuvel5651d742021-03-23 10:54:38 +0100102 *(.text.._end)
103 *(.text.._fips140_unchecked)
Sami Tolvanen28aad1c2021-04-08 11:28:29 -0700104 }
Sean Christopherson6a3193c2021-03-22 16:44:38 -0700105#endif
Tejun Heo405d9672009-06-24 15:13:38 +0900106}
Masahiro Yamada596b0472020-09-08 13:27:08 +0900107
108/* bring in arch-specific sections */
109#include <asm/module.lds.h>