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