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