GNU Linux-libre 4.14.303-gnu1
[releases.git] / arch / arm / kernel / vmlinux.lds.S
1 /* SPDX-License-Identifier: GPL-2.0 */
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 #ifdef CONFIG_XIP_KERNEL
8 #include "vmlinux-xip.lds.S"
9 #else
10
11 #include <asm-generic/vmlinux.lds.h>
12 #include <asm/cache.h>
13 #include <asm/thread_info.h>
14 #include <asm/memory.h>
15 #include <asm/page.h>
16 #include <asm/pgtable.h>
17
18 /*
19  * ld.lld does not support NOCROSSREFS:
20  * https://github.com/ClangBuiltLinux/linux/issues/1609
21  */
22 #ifdef CONFIG_LD_IS_LLD
23 #define NOCROSSREFS
24 #endif
25
26 /* Set start/end symbol names to the LMA for the section */
27 #define ARM_LMA(sym, section)                                           \
28         sym##_start = LOADADDR(section);                                \
29         sym##_end = LOADADDR(section) + SIZEOF(section)
30
31 #define PROC_INFO                                                       \
32         . = ALIGN(4);                                                   \
33         VMLINUX_SYMBOL(__proc_info_begin) = .;                          \
34         *(.proc.info.init)                                              \
35         VMLINUX_SYMBOL(__proc_info_end) = .;
36
37 #define HYPERVISOR_TEXT                                                 \
38         VMLINUX_SYMBOL(__hyp_text_start) = .;                           \
39         *(.hyp.text)                                                    \
40         VMLINUX_SYMBOL(__hyp_text_end) = .;
41
42 #define IDMAP_TEXT                                                      \
43         ALIGN_FUNCTION();                                               \
44         VMLINUX_SYMBOL(__idmap_text_start) = .;                         \
45         *(.idmap.text)                                                  \
46         VMLINUX_SYMBOL(__idmap_text_end) = .;                           \
47         . = ALIGN(PAGE_SIZE);                                           \
48         VMLINUX_SYMBOL(__hyp_idmap_text_start) = .;                     \
49         *(.hyp.idmap.text)                                              \
50         VMLINUX_SYMBOL(__hyp_idmap_text_end) = .;
51
52 #ifdef CONFIG_HOTPLUG_CPU
53 #define ARM_CPU_DISCARD(x)
54 #define ARM_CPU_KEEP(x)         x
55 #else
56 #define ARM_CPU_DISCARD(x)      x
57 #define ARM_CPU_KEEP(x)
58 #endif
59
60 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
61         defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL)
62 #define ARM_EXIT_KEEP(x)        x
63 #define ARM_EXIT_DISCARD(x)
64 #else
65 #define ARM_EXIT_KEEP(x)
66 #define ARM_EXIT_DISCARD(x)     x
67 #endif
68
69 OUTPUT_ARCH(arm)
70 ENTRY(stext)
71
72 #ifndef __ARMEB__
73 jiffies = jiffies_64;
74 #else
75 jiffies = jiffies_64 + 4;
76 #endif
77
78 SECTIONS
79 {
80         /*
81          * XXX: The linker does not define how output sections are
82          * assigned to input sections when there are multiple statements
83          * matching the same input section name.  There is no documented
84          * order of matching.
85          *
86          * unwind exit sections must be discarded before the rest of the
87          * unwind sections get included.
88          */
89         /DISCARD/ : {
90                 *(.ARM.exidx.exit.text)
91                 *(.ARM.extab.exit.text)
92                 ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text))
93                 ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text))
94                 ARM_EXIT_DISCARD(EXIT_TEXT)
95                 ARM_EXIT_DISCARD(EXIT_DATA)
96                 EXIT_CALL
97 #ifndef CONFIG_MMU
98                 *(.text.fixup)
99                 *(__ex_table)
100 #endif
101 #ifndef CONFIG_SMP_ON_UP
102                 *(.alt.smp.init)
103 #endif
104                 *(.discard)
105                 *(.discard.*)
106         }
107
108         . = PAGE_OFFSET + TEXT_OFFSET;
109         .head.text : {
110                 _text = .;
111                 HEAD_TEXT
112         }
113
114 #ifdef CONFIG_STRICT_KERNEL_RWX
115         . = ALIGN(1<<SECTION_SHIFT);
116 #endif
117
118         .text : {                       /* Real text segment            */
119                 _stext = .;             /* Text and read-only data      */
120                         IDMAP_TEXT
121                         __exception_text_start = .;
122                         *(.exception.text)
123                         __exception_text_end = .;
124                         IRQENTRY_TEXT
125                         SOFTIRQENTRY_TEXT
126                         TEXT_TEXT
127                         SCHED_TEXT
128                         CPUIDLE_TEXT
129                         LOCK_TEXT
130                         HYPERVISOR_TEXT
131                         KPROBES_TEXT
132                         *(.gnu.warning)
133                         *(.glue_7)
134                         *(.glue_7t)
135                 . = ALIGN(4);
136                 *(.got)                 /* Global offset table          */
137                         ARM_CPU_KEEP(PROC_INFO)
138         }
139
140 #ifdef CONFIG_DEBUG_ALIGN_RODATA
141         . = ALIGN(1<<SECTION_SHIFT);
142 #endif
143         _etext = .;                     /* End of text section */
144
145         RO_DATA(PAGE_SIZE)
146
147         . = ALIGN(4);
148         __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
149                 __start___ex_table = .;
150 #ifdef CONFIG_MMU
151                 *(__ex_table)
152 #endif
153                 __stop___ex_table = .;
154         }
155
156 #ifdef CONFIG_ARM_UNWIND
157         /*
158          * Stack unwinding tables
159          */
160         . = ALIGN(8);
161         .ARM.unwind_idx : {
162                 __start_unwind_idx = .;
163                 *(.ARM.exidx*)
164                 __stop_unwind_idx = .;
165         }
166         .ARM.unwind_tab : {
167                 __start_unwind_tab = .;
168                 *(.ARM.extab*)
169                 __stop_unwind_tab = .;
170         }
171 #endif
172
173         NOTES
174
175 #ifdef CONFIG_STRICT_KERNEL_RWX
176         . = ALIGN(1<<SECTION_SHIFT);
177 #else
178         . = ALIGN(PAGE_SIZE);
179 #endif
180         __init_begin = .;
181
182         /*
183          * The vectors and stubs are relocatable code, and the
184          * only thing that matters is their relative offsets
185          */
186         __vectors_lma = .;
187         OVERLAY 0xffff0000 : NOCROSSREFS AT(__vectors_lma) {
188                 .vectors {
189                         *(.vectors)
190                 }
191                 .vectors.bhb.loop8 {
192                         *(.vectors.bhb.loop8)
193                 }
194                 .vectors.bhb.bpiall {
195                         *(.vectors.bhb.bpiall)
196                 }
197         }
198         ARM_LMA(__vectors, .vectors);
199         ARM_LMA(__vectors_bhb_loop8, .vectors.bhb.loop8);
200         ARM_LMA(__vectors_bhb_bpiall, .vectors.bhb.bpiall);
201         . = __vectors_lma + SIZEOF(.vectors) +
202                 SIZEOF(.vectors.bhb.loop8) +
203                 SIZEOF(.vectors.bhb.bpiall);
204
205         __stubs_lma = .;
206         .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_lma) {
207                 *(.stubs)
208         }
209         ARM_LMA(__stubs, .stubs);
210         . = __stubs_lma + SIZEOF(.stubs);
211
212         PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors));
213
214         INIT_TEXT_SECTION(8)
215         .exit.text : {
216                 ARM_EXIT_KEEP(EXIT_TEXT)
217         }
218         .init.proc.info : {
219                 ARM_CPU_DISCARD(PROC_INFO)
220         }
221         .init.arch.info : {
222                 __arch_info_begin = .;
223                 *(.arch.info.init)
224                 __arch_info_end = .;
225         }
226         .init.tagtable : {
227                 __tagtable_begin = .;
228                 *(.taglist.init)
229                 __tagtable_end = .;
230         }
231 #ifdef CONFIG_SMP_ON_UP
232         .init.smpalt : {
233                 __smpalt_begin = .;
234                 *(.alt.smp.init)
235                 __smpalt_end = .;
236         }
237 #endif
238         .init.pv_table : {
239                 __pv_table_begin = .;
240                 *(.pv_table)
241                 __pv_table_end = .;
242         }
243         .init.data : {
244                 INIT_DATA
245                 INIT_SETUP(16)
246                 INIT_CALLS
247                 CON_INITCALL
248                 SECURITY_INITCALL
249                 INIT_RAM_FS
250         }
251         .exit.data : {
252                 ARM_EXIT_KEEP(EXIT_DATA)
253         }
254
255 #ifdef CONFIG_SMP
256         PERCPU_SECTION(L1_CACHE_BYTES)
257 #endif
258
259 #ifdef CONFIG_STRICT_KERNEL_RWX
260         . = ALIGN(1<<SECTION_SHIFT);
261 #else
262         . = ALIGN(THREAD_SIZE);
263 #endif
264         __init_end = .;
265         __data_loc = .;
266
267         .data : AT(__data_loc) {
268                 _data = .;              /* address in memory */
269                 _sdata = .;
270
271                 /*
272                  * first, the init task union, aligned
273                  * to an 8192 byte boundary.
274                  */
275                 INIT_TASK_DATA(THREAD_SIZE)
276
277                 NOSAVE_DATA
278                 CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
279                 READ_MOSTLY_DATA(L1_CACHE_BYTES)
280
281                 /*
282                  * and the usual data section
283                  */
284                 DATA_DATA
285                 CONSTRUCTORS
286
287                 _edata = .;
288         }
289         _edata_loc = __data_loc + SIZEOF(.data);
290
291         BUG_TABLE
292
293 #ifdef CONFIG_HAVE_TCM
294         /*
295          * We align everything to a page boundary so we can
296          * free it after init has commenced and TCM contents have
297          * been copied to its destination.
298          */
299         .tcm_start : {
300                 . = ALIGN(PAGE_SIZE);
301                 __tcm_start = .;
302                 __itcm_start = .;
303         }
304
305         /*
306          * Link these to the ITCM RAM
307          * Put VMA to the TCM address and LMA to the common RAM
308          * and we'll upload the contents from RAM to TCM and free
309          * the used RAM after that.
310          */
311         .text_itcm ITCM_OFFSET : AT(__itcm_start)
312         {
313                 __sitcm_text = .;
314                 *(.tcm.text)
315                 *(.tcm.rodata)
316                 . = ALIGN(4);
317                 __eitcm_text = .;
318         }
319
320         /*
321          * Reset the dot pointer, this is needed to create the
322          * relative __dtcm_start below (to be used as extern in code).
323          */
324         . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm);
325
326         .dtcm_start : {
327                 __dtcm_start = .;
328         }
329
330         /* TODO: add remainder of ITCM as well, that can be used for data! */
331         .data_dtcm DTCM_OFFSET : AT(__dtcm_start)
332         {
333                 . = ALIGN(4);
334                 __sdtcm_data = .;
335                 *(.tcm.data)
336                 . = ALIGN(4);
337                 __edtcm_data = .;
338         }
339
340         /* Reset the dot pointer or the linker gets confused */
341         . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm);
342
343         /* End marker for freeing TCM copy in linked object */
344         .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){
345                 . = ALIGN(PAGE_SIZE);
346                 __tcm_end = .;
347         }
348 #endif
349
350         BSS_SECTION(0, 0, 0)
351         _end = .;
352
353         STABS_DEBUG
354 }
355
356 #ifdef CONFIG_STRICT_KERNEL_RWX
357 /*
358  * Without CONFIG_DEBUG_ALIGN_RODATA, __start_rodata_section_aligned will
359  * be the first section-aligned location after __start_rodata. Otherwise,
360  * it will be equal to __start_rodata.
361  */
362 __start_rodata_section_aligned = ALIGN(__start_rodata, 1 << SECTION_SHIFT);
363 #endif
364
365 /*
366  * These must never be empty
367  * If you have to comment these two assert statements out, your
368  * binutils is too old (for other reasons as well)
369  */
370 ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support")
371 ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined")
372
373 /*
374  * The HYP init code can't be more than a page long,
375  * and should not cross a page boundary.
376  * The above comment applies as well.
377  */
378 ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & PAGE_MASK) <= PAGE_SIZE,
379         "HYP init code too big or misaligned")
380
381 #endif /* CONFIG_XIP_KERNEL */