1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * ld script to make ARM Linux kernel 4 * taken from the i386 version by Russell King 5 * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> 6 */ 7 8#define RO_EXCEPTION_TABLE_ALIGN 8 9#define RUNTIME_DISCARD_EXIT 10 11#include <asm-generic/vmlinux.lds.h> 12#include <asm/cache.h> 13#include <asm/hyp_image.h> 14#include <asm/kernel-pgtable.h> 15#include <asm/memory.h> 16#include <asm/page.h> 17 18#include "image.h" 19 20OUTPUT_ARCH(aarch64) 21ENTRY(_text) 22 23jiffies = jiffies_64; 24 25 26#ifdef CONFIG_KVM 27#define HYPERVISOR_EXTABLE \ 28 . = ALIGN(SZ_8); \ 29 __start___kvm_ex_table = .; \ 30 *(__kvm_ex_table) \ 31 __stop___kvm_ex_table = .; 32 33#define HYPERVISOR_PERCPU_SECTION \ 34 . = ALIGN(PAGE_SIZE); \ 35 HYP_SECTION_NAME(.data..percpu) : { \ 36 *(HYP_SECTION_NAME(.data..percpu)) \ 37 } 38#else /* CONFIG_KVM */ 39#define HYPERVISOR_EXTABLE 40#define HYPERVISOR_PERCPU_SECTION 41#endif 42 43#define HYPERVISOR_TEXT \ 44 /* \ 45 * Align to 4 KB so that \ 46 * a) the HYP vector table is at its minimum \ 47 * alignment of 2048 bytes \ 48 * b) the HYP init code will not cross a page \ 49 * boundary if its size does not exceed \ 50 * 4 KB (see related ASSERT() below) \ 51 */ \ 52 . = ALIGN(SZ_4K); \ 53 __hyp_idmap_text_start = .; \ 54 *(.hyp.idmap.text) \ 55 __hyp_idmap_text_end = .; \ 56 __hyp_text_start = .; \ 57 *(.hyp.text) \ 58 HYPERVISOR_EXTABLE \ 59 __hyp_text_end = .; 60 61#define IDMAP_TEXT \ 62 . = ALIGN(SZ_4K); \ 63 __idmap_text_start = .; \ 64 *(.idmap.text) \ 65 __idmap_text_end = .; 66 67#ifdef CONFIG_HIBERNATION 68#define HIBERNATE_TEXT \ 69 . = ALIGN(SZ_4K); \ 70 __hibernate_exit_text_start = .; \ 71 *(.hibernate_exit.text) \ 72 __hibernate_exit_text_end = .; 73#else 74#define HIBERNATE_TEXT 75#endif 76 77#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 78#define TRAMP_TEXT \ 79 . = ALIGN(PAGE_SIZE); \ 80 __entry_tramp_text_start = .; \ 81 *(.entry.tramp.text) \ 82 . = ALIGN(PAGE_SIZE); \ 83 __entry_tramp_text_end = .; 84#else 85#define TRAMP_TEXT 86#endif 87 88/* 89 * The size of the PE/COFF section that covers the kernel image, which 90 * runs from _stext to _edata, must be a round multiple of the PE/COFF 91 * FileAlignment, which we set to its minimum value of 0x200. '_stext' 92 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 93 * boundary should be sufficient. 94 */ 95PECOFF_FILE_ALIGNMENT = 0x200; 96 97#ifdef CONFIG_EFI 98#define PECOFF_EDATA_PADDING \ 99 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 100#else 101#define PECOFF_EDATA_PADDING 102#endif 103 104SECTIONS 105{ 106 /* 107 * XXX: The linker does not define how output sections are 108 * assigned to input sections when there are multiple statements 109 * matching the same input section name. There is no documented 110 * order of matching. 111 */ 112 DISCARDS 113 /DISCARD/ : { 114 *(.interp .dynamic) 115 *(.dynsym .dynstr .hash .gnu.hash) 116 } 117 118 . = KIMAGE_VADDR; 119 120 .head.text : { 121 _text = .; 122 HEAD_TEXT 123 } 124 .text : { /* Real text segment */ 125 _stext = .; /* Text and read-only data */ 126 IRQENTRY_TEXT 127 SOFTIRQENTRY_TEXT 128 ENTRY_TEXT 129 TEXT_TEXT 130 SCHED_TEXT 131 CPUIDLE_TEXT 132 LOCK_TEXT 133 KPROBES_TEXT 134 HYPERVISOR_TEXT 135 IDMAP_TEXT 136 HIBERNATE_TEXT 137 TRAMP_TEXT 138 *(.fixup) 139 *(.gnu.warning) 140 . = ALIGN(16); 141 *(.got) /* Global offset table */ 142 } 143 144 /* 145 * Make sure that the .got.plt is either completely empty or it 146 * contains only the lazy dispatch entries. 147 */ 148 .got.plt : { *(.got.plt) } 149 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 150 "Unexpected GOT/PLT entries detected!") 151 152 . = ALIGN(SEGMENT_ALIGN); 153 _etext = .; /* End of text section */ 154 155 /* everything from this point to __init_begin will be marked RO NX */ 156 RO_DATA(PAGE_SIZE) 157 158 idmap_pg_dir = .; 159 . += IDMAP_DIR_SIZE; 160 idmap_pg_end = .; 161 162#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 163 tramp_pg_dir = .; 164 . += PAGE_SIZE; 165#endif 166 167 reserved_pg_dir = .; 168 . += PAGE_SIZE; 169 170 swapper_pg_dir = .; 171 . += PAGE_SIZE; 172 173 . = ALIGN(SEGMENT_ALIGN); 174 __init_begin = .; 175 __inittext_begin = .; 176 177 INIT_TEXT_SECTION(8) 178 179 __exittext_begin = .; 180 .exit.text : { 181 EXIT_TEXT 182 } 183 __exittext_end = .; 184 185 . = ALIGN(4); 186 .altinstructions : { 187 __alt_instructions = .; 188 *(.altinstructions) 189 __alt_instructions_end = .; 190 } 191 192 . = ALIGN(SEGMENT_ALIGN); 193 __inittext_end = .; 194 __initdata_begin = .; 195 196 .init.data : { 197 INIT_DATA 198 INIT_SETUP(16) 199 INIT_CALLS 200 CON_INITCALL 201 INIT_RAM_FS 202 *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ 203 } 204 .exit.data : { 205 EXIT_DATA 206 } 207 208 PERCPU_SECTION(L1_CACHE_BYTES) 209 HYPERVISOR_PERCPU_SECTION 210 211 .rela.dyn : ALIGN(8) { 212 *(.rela .rela*) 213 } 214 215 __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 216 __rela_size = SIZEOF(.rela.dyn); 217 218#ifdef CONFIG_RELR 219 .relr.dyn : ALIGN(8) { 220 *(.relr.dyn) 221 } 222 223 __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 224 __relr_size = SIZEOF(.relr.dyn); 225#endif 226 227 . = ALIGN(SEGMENT_ALIGN); 228 __initdata_end = .; 229 __init_end = .; 230 231 _data = .; 232 _sdata = .; 233 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 234 235 /* 236 * Data written with the MMU off but read with the MMU on requires 237 * cache lines to be invalidated, discarding up to a Cache Writeback 238 * Granule (CWG) of data from the cache. Keep the section that 239 * requires this type of maintenance to be in its own Cache Writeback 240 * Granule (CWG) area so the cache maintenance operations don't 241 * interfere with adjacent data. 242 */ 243 .mmuoff.data.write : ALIGN(SZ_2K) { 244 __mmuoff_data_start = .; 245 *(.mmuoff.data.write) 246 } 247 . = ALIGN(SZ_2K); 248 .mmuoff.data.read : { 249 *(.mmuoff.data.read) 250 __mmuoff_data_end = .; 251 } 252 253 PECOFF_EDATA_PADDING 254 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 255 _edata = .; 256 257 BSS_SECTION(0, 0, 0) 258 259 . = ALIGN(PAGE_SIZE); 260 init_pg_dir = .; 261 . += INIT_DIR_SIZE; 262 init_pg_end = .; 263 264 . = ALIGN(SEGMENT_ALIGN); 265 __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 266 _end = .; 267 268 STABS_DEBUG 269 DWARF_DEBUG 270 ELF_DETAILS 271 272 HEAD_SYMBOLS 273 274 /* 275 * Sections that should stay zero sized, which is safer to 276 * explicitly check instead of blindly discarding. 277 */ 278 .plt : { 279 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) 280 } 281 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 282 283 .data.rel.ro : { *(.data.rel.ro) } 284 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 285} 286 287#include "image-vars.h" 288 289/* 290 * The HYP init code and ID map text can't be longer than a page each, 291 * and should not cross a page boundary. 292 */ 293ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 294 "HYP init code too big or misaligned") 295ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 296 "ID map text too big or misaligned") 297#ifdef CONFIG_HIBERNATION 298ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 299 <= SZ_4K, "Hibernate exit text too big or misaligned") 300#endif 301#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 302ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE, 303 "Entry trampoline text too big") 304#endif 305/* 306 * If padding is applied before .head.text, virt<->phys conversions will fail. 307 */ 308ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") 309