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 <linux/sizes.h> 11 12#include <asm-generic/vmlinux.lds.h> 13#include <asm/cache.h> 14#include <asm/thread_info.h> 15#include <asm/memory.h> 16#include <asm/page.h> 17 18#include "vmlinux.lds.h" 19 20OUTPUT_ARCH(arm) 21ENTRY(stext) 22 23#ifndef __ARMEB__ 24jiffies = jiffies_64; 25#else 26jiffies = jiffies_64 + 4; 27#endif 28 29SECTIONS 30{ 31 /* 32 * XXX: The linker does not define how output sections are 33 * assigned to input sections when there are multiple statements 34 * matching the same input section name. There is no documented 35 * order of matching. 36 * 37 * unwind exit sections must be discarded before the rest of the 38 * unwind sections get included. 39 */ 40 /DISCARD/ : { 41 *(.ARM.exidx.exit.text) 42 *(.ARM.extab.exit.text) 43 ARM_CPU_DISCARD(*(.ARM.exidx.cpuexit.text)) 44 ARM_CPU_DISCARD(*(.ARM.extab.cpuexit.text)) 45 ARM_EXIT_DISCARD(EXIT_TEXT) 46 ARM_EXIT_DISCARD(EXIT_DATA) 47 EXIT_CALL 48#ifndef CONFIG_MMU 49 *(.text.fixup) 50 *(__ex_table) 51#endif 52 *(.alt.smp.init) 53 *(.discard) 54 *(.discard.*) 55 } 56 57 . = XIP_VIRT_ADDR(CONFIG_XIP_PHYS_ADDR); 58 _xiprom = .; /* XIP ROM area to be mapped */ 59 60 .head.text : { 61 _text = .; 62 HEAD_TEXT 63 } 64 65 .text : { /* Real text segment */ 66 _stext = .; /* Text and read-only data */ 67 IDMAP_TEXT 68 __entry_text_start = .; 69 *(.entry.text) 70 __entry_text_end = .; 71 IRQENTRY_TEXT 72 SOFTIRQENTRY_TEXT 73 TEXT_TEXT 74 SCHED_TEXT 75 CPUIDLE_TEXT 76 LOCK_TEXT 77 HYPERVISOR_TEXT 78 KPROBES_TEXT 79 *(.gnu.warning) 80 *(.glue_7) 81 *(.glue_7t) 82 . = ALIGN(4); 83 *(.got) /* Global offset table */ 84 ARM_CPU_KEEP(PROC_INFO) 85 } 86 87 RO_DATA(PAGE_SIZE) 88 89 . = ALIGN(4); 90 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { 91 __start___ex_table = .; 92#ifdef CONFIG_MMU 93 *(__ex_table) 94#endif 95 __stop___ex_table = .; 96 } 97 98#ifdef CONFIG_ARM_UNWIND 99 /* 100 * Stack unwinding tables 101 */ 102 . = ALIGN(8); 103 .ARM.unwind_idx : { 104 __start_unwind_idx = .; 105 *(.ARM.exidx*) 106 __stop_unwind_idx = .; 107 } 108 .ARM.unwind_tab : { 109 __start_unwind_tab = .; 110 *(.ARM.extab*) 111 __stop_unwind_tab = .; 112 } 113#endif 114 115 NOTES 116 117 _etext = .; /* End of text and rodata section */ 118 119 /* 120 * The vectors and stubs are relocatable code, and the 121 * only thing that matters is their relative offsets 122 */ 123 __vectors_start = .; 124 .vectors 0xffff0000 : AT(__vectors_start) { 125 *(.vectors) 126 } 127 . = __vectors_start + SIZEOF(.vectors); 128 __vectors_end = .; 129 130 __stubs_start = .; 131 .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { 132 *(.stubs) 133 } 134 . = __stubs_start + SIZEOF(.stubs); 135 __stubs_end = .; 136 137 PROVIDE(vector_fiq_offset = vector_fiq - ADDR(.vectors)); 138 139 INIT_TEXT_SECTION(8) 140 .exit.text : { 141 ARM_EXIT_KEEP(EXIT_TEXT) 142 } 143 .init.proc.info : { 144 ARM_CPU_DISCARD(PROC_INFO) 145 } 146 .init.arch.info : { 147 __arch_info_begin = .; 148 *(.arch.info.init) 149 __arch_info_end = .; 150 } 151 .init.tagtable : { 152 __tagtable_begin = .; 153 *(.taglist.init) 154 __tagtable_end = .; 155 } 156 .init.rodata : { 157 INIT_SETUP(16) 158 INIT_CALLS 159 CON_INITCALL 160 SECURITY_INITCALL 161 INIT_RAM_FS 162 } 163 164#ifdef CONFIG_ARM_MPU 165 . = ALIGN(SZ_128K); 166#endif 167 _exiprom = .; /* End of XIP ROM area */ 168 169/* 170 * From this point, stuff is considered writable and will be copied to RAM 171 */ 172 __data_loc = ALIGN(4); /* location in file */ 173 . = PAGE_OFFSET + TEXT_OFFSET; /* location in memory */ 174#undef LOAD_OFFSET 175#define LOAD_OFFSET (PAGE_OFFSET + TEXT_OFFSET - __data_loc) 176 177 . = ALIGN(THREAD_SIZE); 178 _sdata = .; 179 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) 180 .data.ro_after_init : AT(ADDR(.data.ro_after_init) - LOAD_OFFSET) { 181 *(.data..ro_after_init) 182 } 183 _edata = .; 184 185 . = ALIGN(PAGE_SIZE); 186 __init_begin = .; 187 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { 188 INIT_DATA 189 } 190 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { 191 ARM_EXIT_KEEP(EXIT_DATA) 192 } 193#ifdef CONFIG_SMP 194 PERCPU_SECTION(L1_CACHE_BYTES) 195#endif 196 197 /* 198 * End of copied data. We need a dummy section to get its LMA. 199 * Also located before final ALIGN() as trailing padding is not stored 200 * in the resulting binary file and useless to copy. 201 */ 202 .data.endmark : AT(ADDR(.data.endmark) - LOAD_OFFSET) { } 203 _edata_loc = LOADADDR(.data.endmark); 204 205 . = ALIGN(PAGE_SIZE); 206 __init_end = .; 207 208#ifdef CONFIG_HAVE_TCM 209 /* 210 * We align everything to a page boundary so we can 211 * free it after init has commenced and TCM contents have 212 * been copied to its destination. 213 */ 214 .tcm_start : { 215 . = ALIGN(PAGE_SIZE); 216 __tcm_start = .; 217 __itcm_start = .; 218 } 219 220 /* 221 * Link these to the ITCM RAM 222 * Put VMA to the TCM address and LMA to the common RAM 223 * and we'll upload the contents from RAM to TCM and free 224 * the used RAM after that. 225 */ 226 .text_itcm ITCM_OFFSET : AT(__itcm_start) 227 { 228 __sitcm_text = .; 229 *(.tcm.text) 230 *(.tcm.rodata) 231 . = ALIGN(4); 232 __eitcm_text = .; 233 } 234 235 /* 236 * Reset the dot pointer, this is needed to create the 237 * relative __dtcm_start below (to be used as extern in code). 238 */ 239 . = ADDR(.tcm_start) + SIZEOF(.tcm_start) + SIZEOF(.text_itcm); 240 241 .dtcm_start : { 242 __dtcm_start = .; 243 } 244 245 /* TODO: add remainder of ITCM as well, that can be used for data! */ 246 .data_dtcm DTCM_OFFSET : AT(__dtcm_start) 247 { 248 . = ALIGN(4); 249 __sdtcm_data = .; 250 *(.tcm.data) 251 . = ALIGN(4); 252 __edtcm_data = .; 253 } 254 255 /* Reset the dot pointer or the linker gets confused */ 256 . = ADDR(.dtcm_start) + SIZEOF(.data_dtcm); 257 258 /* End marker for freeing TCM copy in linked object */ 259 .tcm_end : AT(ADDR(.dtcm_start) + SIZEOF(.data_dtcm)){ 260 . = ALIGN(PAGE_SIZE); 261 __tcm_end = .; 262 } 263#endif 264 265 BSS_SECTION(0, 0, 8) 266 _end = .; 267 268 STABS_DEBUG 269} 270 271/* 272 * These must never be empty 273 * If you have to comment these two assert statements out, your 274 * binutils is too old (for other reasons as well) 275 */ 276ASSERT((__proc_info_end - __proc_info_begin), "missing CPU support") 277ASSERT((__arch_info_end - __arch_info_begin), "no machine record defined") 278 279/* 280 * The HYP init code can't be more than a page long, 281 * and should not cross a page boundary. 282 * The above comment applies as well. 283 */ 284ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & PAGE_MASK) <= PAGE_SIZE, 285 "HYP init code too big or misaligned") 286 287#ifdef CONFIG_XIP_DEFLATED_DATA 288/* 289 * The .bss is used as a stack area for __inflate_kernel_data() whose stack 290 * frame is 9568 bytes. Make sure it has extra room left. 291 */ 292ASSERT((_end - __bss_start) >= 12288, ".bss too small for CONFIG_XIP_DEFLATED_DATA") 293#endif 294 295#ifdef CONFIG_ARM_MPU 296/* 297 * Due to PMSAv7 restriction on base address and size we have to 298 * enforce minimal alignment restrictions. It was seen that weaker 299 * alignment restriction on _xiprom will likely force XIP address 300 * space spawns multiple MPU regions thus it is likely we run in 301 * situation when we are reprogramming MPU region we run on with 302 * something which doesn't cover reprogramming code itself, so as soon 303 * as we update MPU settings we'd immediately try to execute straight 304 * from background region which is XN. 305 * It seem that alignment in 1M should suit most users. 306 * _exiprom is aligned as 1/8 of 1M so can be covered by subregion 307 * disable 308 */ 309ASSERT(!(_xiprom & (SZ_1M - 1)), "XIP start address may cause MPU programming issues") 310ASSERT(!(_exiprom & (SZ_128K - 1)), "XIP end address may cause MPU programming issues") 311#endif 312