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