GNU Linux-libre 4.9.337-gnu1
[releases.git] / arch / arm64 / kernel / vmlinux.lds.S
1 /*
2  * ld script to make ARM Linux kernel
3  * taken from the i386 version by Russell King
4  * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <asm-generic/vmlinux.lds.h>
8 #include <asm/cache.h>
9 #include <asm/kernel-pgtable.h>
10 #include <asm/thread_info.h>
11 #include <asm/memory.h>
12 #include <asm/page.h>
13 #include <asm/pgtable.h>
14
15 #include "image.h"
16
17 /* .exit.text needed in case of alternative patching */
18 #define ARM_EXIT_KEEP(x)        x
19 #define ARM_EXIT_DISCARD(x)
20
21 OUTPUT_ARCH(aarch64)
22 ENTRY(_text)
23
24 jiffies = jiffies_64;
25
26
27 #define HYPERVISOR_EXTABLE                                      \
28         . = ALIGN(SZ_8);                                        \
29         VMLINUX_SYMBOL(__start___kvm_ex_table) = .;             \
30         *(__kvm_ex_table)                                       \
31         VMLINUX_SYMBOL(__stop___kvm_ex_table) = .;
32
33 #define HYPERVISOR_TEXT                                 \
34         /*                                              \
35          * Align to 4 KB so that                        \
36          * a) the HYP vector table is at its minimum    \
37          *    alignment of 2048 bytes                   \
38          * b) the HYP init code will not cross a page   \
39          *    boundary if its size does not exceed      \
40          *    4 KB (see related ASSERT() below)         \
41          */                                             \
42         . = ALIGN(SZ_4K);                               \
43         VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;     \
44         *(.hyp.idmap.text)                              \
45         VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;       \
46         VMLINUX_SYMBOL(__hyp_text_start) = .;           \
47         *(.hyp.text)                                    \
48         HYPERVISOR_EXTABLE                              \
49         VMLINUX_SYMBOL(__hyp_text_end) = .;
50
51 #define IDMAP_TEXT                                      \
52         . = ALIGN(SZ_4K);                               \
53         VMLINUX_SYMBOL(__idmap_text_start) = .;         \
54         *(.idmap.text)                                  \
55         VMLINUX_SYMBOL(__idmap_text_end) = .;
56
57 #ifdef CONFIG_HIBERNATION
58 #define HIBERNATE_TEXT                                  \
59         . = ALIGN(SZ_4K);                               \
60         VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\
61         *(.hibernate_exit.text)                         \
62         VMLINUX_SYMBOL(__hibernate_exit_text_end) = .;
63 #else
64 #define HIBERNATE_TEXT
65 #endif
66
67 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
68 #define TRAMP_TEXT                                      \
69         . = ALIGN(PAGE_SIZE);                           \
70         VMLINUX_SYMBOL(__entry_tramp_text_start) = .;   \
71         *(.entry.tramp.text)                            \
72         . = ALIGN(PAGE_SIZE);                           \
73         VMLINUX_SYMBOL(__entry_tramp_text_end) = .;
74 #else
75 #define TRAMP_TEXT
76 #endif
77
78 /*
79  * The size of the PE/COFF section that covers the kernel image, which
80  * runs from stext to _edata, must be a round multiple of the PE/COFF
81  * FileAlignment, which we set to its minimum value of 0x200. 'stext'
82  * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
83  * boundary should be sufficient.
84  */
85 PECOFF_FILE_ALIGNMENT = 0x200;
86
87 #ifdef CONFIG_EFI
88 #define PECOFF_EDATA_PADDING    \
89         .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
90 #else
91 #define PECOFF_EDATA_PADDING
92 #endif
93
94 #if defined(CONFIG_DEBUG_ALIGN_RODATA)
95 /*
96  *  4 KB granule:   1 level 2 entry
97  * 16 KB granule: 128 level 3 entries, with contiguous bit
98  * 64 KB granule:  32 level 3 entries, with contiguous bit
99  */
100 #define SEGMENT_ALIGN                   SZ_2M
101 #else
102 /*
103  *  4 KB granule:  16 level 3 entries, with contiguous bit
104  * 16 KB granule:   4 level 3 entries, without contiguous bit
105  * 64 KB granule:   1 level 3 entry
106  */
107 #define SEGMENT_ALIGN                   SZ_64K
108 #endif
109
110 SECTIONS
111 {
112         /*
113          * XXX: The linker does not define how output sections are
114          * assigned to input sections when there are multiple statements
115          * matching the same input section name.  There is no documented
116          * order of matching.
117          */
118         /DISCARD/ : {
119                 ARM_EXIT_DISCARD(EXIT_TEXT)
120                 ARM_EXIT_DISCARD(EXIT_DATA)
121                 EXIT_CALL
122                 *(.discard)
123                 *(.discard.*)
124                 *(.interp .dynamic)
125                 *(.dynsym .dynstr .hash)
126         }
127
128         . = KIMAGE_VADDR + TEXT_OFFSET;
129
130         .head.text : {
131                 _text = .;
132                 HEAD_TEXT
133         }
134         .text : {                       /* Real text segment            */
135                 _stext = .;             /* Text and read-only data      */
136                         __exception_text_start = .;
137                         *(.exception.text)
138                         __exception_text_end = .;
139                         IRQENTRY_TEXT
140                         SOFTIRQENTRY_TEXT
141                         ENTRY_TEXT
142                         TEXT_TEXT
143                         SCHED_TEXT
144                         CPUIDLE_TEXT
145                         LOCK_TEXT
146                         KPROBES_TEXT
147                         HYPERVISOR_TEXT
148                         IDMAP_TEXT
149                         HIBERNATE_TEXT
150                         TRAMP_TEXT
151                         *(.fixup)
152                         *(.gnu.warning)
153                 . = ALIGN(16);
154                 *(.got)                 /* Global offset table          */
155         }
156
157         . = ALIGN(SEGMENT_ALIGN);
158         _etext = .;                     /* End of text section */
159
160         RO_DATA(PAGE_SIZE)              /* everything from this point to     */
161         EXCEPTION_TABLE(8)              /* __init_begin will be marked RO NX */
162         NOTES
163
164         . = ALIGN(SEGMENT_ALIGN);
165         __init_begin = .;
166
167         INIT_TEXT_SECTION(8)
168         .exit.text : {
169                 ARM_EXIT_KEEP(EXIT_TEXT)
170         }
171
172         .init.data : {
173                 INIT_DATA
174                 INIT_SETUP(16)
175                 INIT_CALLS
176                 CON_INITCALL
177                 SECURITY_INITCALL
178                 INIT_RAM_FS
179                 *(.init.rodata.* .init.bss)     /* from the EFI stub */
180         }
181         .exit.data : {
182                 ARM_EXIT_KEEP(EXIT_DATA)
183         }
184
185         PERCPU_SECTION(L1_CACHE_BYTES)
186
187         . = ALIGN(4);
188         .altinstructions : {
189                 __alt_instructions = .;
190                 *(.altinstructions)
191                 __alt_instructions_end = .;
192         }
193         .altinstr_replacement : {
194                 *(.altinstr_replacement)
195         }
196         .rela : ALIGN(8) {
197                 *(.rela .rela*)
198         }
199
200         __rela_offset   = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR);
201         __rela_size     = SIZEOF(.rela);
202
203         . = ALIGN(SEGMENT_ALIGN);
204         __init_end = .;
205
206         _data = .;
207         _sdata = .;
208         RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
209
210         /*
211          * Data written with the MMU off but read with the MMU on requires
212          * cache lines to be invalidated, discarding up to a Cache Writeback
213          * Granule (CWG) of data from the cache. Keep the section that
214          * requires this type of maintenance to be in its own Cache Writeback
215          * Granule (CWG) area so the cache maintenance operations don't
216          * interfere with adjacent data.
217          */
218         .mmuoff.data.write : ALIGN(SZ_2K) {
219                 __mmuoff_data_start = .;
220                 *(.mmuoff.data.write)
221         }
222         . = ALIGN(SZ_2K);
223         .mmuoff.data.read : {
224                 *(.mmuoff.data.read)
225                 __mmuoff_data_end = .;
226         }
227
228         PECOFF_EDATA_PADDING
229         _edata = .;
230
231         BSS_SECTION(0, 0, 0)
232
233         . = ALIGN(PAGE_SIZE);
234         idmap_pg_dir = .;
235         . += IDMAP_DIR_SIZE;
236         swapper_pg_dir = .;
237         . += SWAPPER_DIR_SIZE;
238
239 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
240         tramp_pg_dir = .;
241         . += PAGE_SIZE;
242 #endif
243
244         _end = .;
245
246         STABS_DEBUG
247
248         HEAD_SYMBOLS
249 }
250
251 /*
252  * The HYP init code and ID map text can't be longer than a page each,
253  * and should not cross a page boundary.
254  */
255 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
256         "HYP init code too big or misaligned")
257 ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
258         "ID map text too big or misaligned")
259 #ifdef CONFIG_HIBERNATION
260 ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1))
261         <= SZ_4K, "Hibernate exit text too big or misaligned")
262 #endif
263 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
264 ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE,
265         "Entry trampoline text too big")
266 #endif
267 /*
268  * If padding is applied before .head.text, virt<->phys conversions will fail.
269  */
270 ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned")