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#include <asm/hyp_image.h> 9#ifdef CONFIG_KVM 10#define HYPERVISOR_EXTABLE \ 11 . = ALIGN(SZ_8); \ 12 __start___kvm_ex_table = .; \ 13 *(__kvm_ex_table) \ 14 __stop___kvm_ex_table = .; 15 16#ifdef CONFIG_NVHE_EL2_TRACING 17#define HYPERVISOR_EVENT_IDS \ 18 . = ALIGN(SZ_8); \ 19 __hyp_event_ids_start = .; \ 20 *(HYP_SECTION_NAME(.event_ids)) \ 21 __hyp_event_ids_end = .; 22#else 23#define HYPERVISOR_EVENT_IDS 24#endif 25 26#define HYPERVISOR_RODATA_SECTIONS \ 27 HYP_SECTION_NAME(.rodata) : { \ 28 . = ALIGN(PAGE_SIZE); \ 29 __hyp_rodata_start = .; \ 30 *(HYP_SECTION_NAME(.data..ro_after_init)) \ 31 *(HYP_SECTION_NAME(.rodata)) \ 32 HYPERVISOR_EVENT_IDS \ 33 . = ALIGN(PAGE_SIZE); \ 34 __hyp_rodata_end = .; \ 35 } 36 37#define HYPERVISOR_DATA_SECTION \ 38 HYP_SECTION_NAME(.data) : { \ 39 . = ALIGN(PAGE_SIZE); \ 40 __hyp_data_start = .; \ 41 *(HYP_SECTION_NAME(.data)) \ 42 . = ALIGN(PAGE_SIZE); \ 43 __hyp_data_end = .; \ 44 } 45 46#define HYPERVISOR_PERCPU_SECTION \ 47 . = ALIGN(PAGE_SIZE); \ 48 HYP_SECTION_NAME(.data..percpu) : { \ 49 *(HYP_SECTION_NAME(.data..percpu)) \ 50 } 51 52#define HYPERVISOR_RELOC_SECTION \ 53 .hyp.reloc : ALIGN(4) { \ 54 __hyp_reloc_begin = .; \ 55 *(.hyp.reloc) \ 56 __hyp_reloc_end = .; \ 57 } 58 59#define BSS_FIRST_SECTIONS \ 60 __hyp_bss_start = .; \ 61 *(HYP_SECTION_NAME(.bss)) \ 62 . = ALIGN(PAGE_SIZE); \ 63 __hyp_bss_end = .; 64 65/* 66 * We require that __hyp_bss_start and __bss_start are aligned, and enforce it 67 * with an assertion. But the BSS_SECTION macro places an empty .sbss section 68 * between them, which can in some cases cause the linker to misalign them. To 69 * work around the issue, force a page alignment for __bss_start. 70 */ 71#define SBSS_ALIGN PAGE_SIZE 72#else /* CONFIG_KVM */ 73#define HYPERVISOR_EXTABLE 74#define HYPERVISOR_RODATA_SECTIONS 75#define HYPERVISOR_DATA_SECTION 76#define HYPERVISOR_PERCPU_SECTION 77#define HYPERVISOR_RELOC_SECTION 78#define SBSS_ALIGN 0 79#endif 80 81#define RO_EXCEPTION_TABLE_ALIGN 4 82#define RUNTIME_DISCARD_EXIT 83 84#include <asm-generic/vmlinux.lds.h> 85#include <asm/cache.h> 86#include <asm/kernel-pgtable.h> 87#include <asm/kexec.h> 88#include <asm/memory.h> 89#include <asm/page.h> 90 91#include "image.h" 92 93OUTPUT_ARCH(aarch64) 94ENTRY(_text) 95 96jiffies = jiffies_64; 97 98#define HYPERVISOR_TEXT \ 99 . = ALIGN(PAGE_SIZE); \ 100 __hyp_idmap_text_start = .; \ 101 *(.hyp.idmap.text) \ 102 __hyp_idmap_text_end = .; \ 103 __hyp_text_start = .; \ 104 *(.hyp.text) \ 105 HYPERVISOR_EXTABLE \ 106 . = ALIGN(PAGE_SIZE); \ 107 __hyp_text_end = .; 108 109#define IDMAP_TEXT \ 110 . = ALIGN(SZ_4K); \ 111 __idmap_text_start = .; \ 112 *(.idmap.text) \ 113 __idmap_text_end = .; 114 115#ifdef CONFIG_HIBERNATION 116#define HIBERNATE_TEXT \ 117 ALIGN_FUNCTION(); \ 118 __hibernate_exit_text_start = .; \ 119 *(.hibernate_exit.text) \ 120 __hibernate_exit_text_end = .; 121#else 122#define HIBERNATE_TEXT 123#endif 124 125#ifdef CONFIG_KEXEC_CORE 126#define KEXEC_TEXT \ 127 ALIGN_FUNCTION(); \ 128 __relocate_new_kernel_start = .; \ 129 *(.kexec_relocate.text) \ 130 __relocate_new_kernel_end = .; 131#else 132#define KEXEC_TEXT 133#endif 134 135#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 136#define TRAMP_TEXT \ 137 . = ALIGN(PAGE_SIZE); \ 138 __entry_tramp_text_start = .; \ 139 *(.entry.tramp.text) \ 140 . = ALIGN(PAGE_SIZE); \ 141 __entry_tramp_text_end = .; \ 142 *(.entry.tramp.rodata) 143#else 144#define TRAMP_TEXT 145#endif 146 147#ifdef CONFIG_UNWIND_TABLES 148#define UNWIND_DATA_SECTIONS \ 149 .eh_frame : { \ 150 __pi___eh_frame_start = .; \ 151 *(.eh_frame) \ 152 __pi___eh_frame_end = .; \ 153 } 154#else 155#define UNWIND_DATA_SECTIONS 156#endif 157 158/* 159 * The size of the PE/COFF section that covers the kernel image, which 160 * runs from _stext to _edata, must be a round multiple of the PE/COFF 161 * FileAlignment, which we set to its minimum value of 0x200. '_stext' 162 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 163 * boundary should be sufficient. 164 */ 165PECOFF_FILE_ALIGNMENT = 0x200; 166 167#ifdef CONFIG_EFI 168#define PECOFF_EDATA_PADDING \ 169 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 170#else 171#define PECOFF_EDATA_PADDING 172#endif 173 174SECTIONS 175{ 176 /* 177 * XXX: The linker does not define how output sections are 178 * assigned to input sections when there are multiple statements 179 * matching the same input section name. There is no documented 180 * order of matching. 181 */ 182 DISCARDS 183 /DISCARD/ : { 184 *(.interp .dynamic) 185 *(.dynsym .dynstr .hash .gnu.hash) 186 *(.ARM.attributes) 187 } 188 189 . = KIMAGE_VADDR; 190 191 .head.text : { 192 _text = .; 193 HEAD_TEXT 194 } 195 .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */ 196 _stext = .; /* Text and read-only data */ 197 IRQENTRY_TEXT 198 SOFTIRQENTRY_TEXT 199 ENTRY_TEXT 200 TEXT_TEXT 201 SCHED_TEXT 202 LOCK_TEXT 203 KPROBES_TEXT 204 HYPERVISOR_TEXT 205 STATIC_CALL_TEXT 206 *(.gnu.warning) 207 } 208 209 . = ALIGN(SEGMENT_ALIGN); 210 _etext = .; /* End of text section */ 211 212 /* everything from this point to __init_begin will be marked RO NX */ 213 RO_DATA(PAGE_SIZE) 214 215 HYPERVISOR_RODATA_SECTIONS 216 217#ifdef CONFIG_NVHE_EL2_TRACING 218 .rodata.hyp_string_fmts : { 219 __hyp_string_fmts_start = .; 220 *(_hyp_string_fmts) 221 __hyp_string_fmts_end = .; 222 } 223#endif 224 225 .got : { *(.got) } 226 /* 227 * Make sure that the .got.plt is either completely empty or it 228 * contains only the lazy dispatch entries. 229 */ 230 .got.plt : { *(.got.plt) } 231 ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 232 "Unexpected GOT/PLT entries detected!") 233 234 /* code sections that are never executed via the kernel mapping */ 235 .rodata.text : { 236 TRAMP_TEXT 237 HIBERNATE_TEXT 238 KEXEC_TEXT 239 IDMAP_TEXT 240 . = ALIGN(PAGE_SIZE); 241 } 242 243 idmap_pg_dir = .; 244 . += PAGE_SIZE; 245 246#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 247 tramp_pg_dir = .; 248 . += PAGE_SIZE; 249#endif 250 251 reserved_pg_dir = .; 252 . += PAGE_SIZE; 253 254 swapper_pg_dir = .; 255 . += PAGE_SIZE; 256 257 . = ALIGN(SEGMENT_ALIGN); 258 __init_begin = .; 259 __inittext_begin = .; 260 261 INIT_TEXT_SECTION(8) 262 263 __exittext_begin = .; 264 .exit.text : { 265 EXIT_TEXT 266 } 267 __exittext_end = .; 268 269 . = ALIGN(4); 270 .altinstructions : { 271 __alt_instructions = .; 272 *(.altinstructions) 273 __alt_instructions_end = .; 274 } 275 276 UNWIND_DATA_SECTIONS 277 278 . = ALIGN(SEGMENT_ALIGN); 279 __inittext_end = .; 280 __initdata_begin = .; 281 282 __pi_init_idmap_pg_dir = .; 283 . += INIT_IDMAP_DIR_SIZE; 284 __pi_init_idmap_pg_end = .; 285 286 .init.data : { 287 INIT_DATA 288 INIT_SETUP(16) 289 INIT_CALLS 290 CON_INITCALL 291 INIT_RAM_FS 292 *(.init.altinstructions .init.bss) /* from the EFI stub */ 293 } 294 .exit.data : { 295 EXIT_DATA 296 } 297 298 RUNTIME_CONST_VARIABLES 299 300 PERCPU_SECTION(L1_CACHE_BYTES) 301 HYPERVISOR_PERCPU_SECTION 302 303 HYPERVISOR_RELOC_SECTION 304 305 .rela.dyn : ALIGN(8) { 306 __pi_rela_start = .; 307 *(.rela .rela*) 308 __pi_rela_end = .; 309 } 310 311 .relr.dyn : ALIGN(8) { 312 __pi_relr_start = .; 313 *(.relr.dyn) 314 __pi_relr_end = .; 315 } 316 317 . = ALIGN(SEGMENT_ALIGN); 318 __initdata_end = .; 319 __init_end = .; 320 321 .data.rel.ro : { *(.data.rel.ro) } 322 ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 323 324 _data = .; 325 _sdata = .; 326 RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 327 328 HYPERVISOR_DATA_SECTION 329 330#ifdef CONFIG_NVHE_EL2_TRACING 331 .data.hyp_events : { 332 __hyp_events_start = .; 333 *(SORT(_hyp_events.*)) 334 __hyp_events_end = .; 335 } 336#endif 337 /* 338 * Data written with the MMU off but read with the MMU on requires 339 * cache lines to be invalidated, discarding up to a Cache Writeback 340 * Granule (CWG) of data from the cache. Keep the section that 341 * requires this type of maintenance to be in its own Cache Writeback 342 * Granule (CWG) area so the cache maintenance operations don't 343 * interfere with adjacent data. 344 */ 345 .mmuoff.data.write : ALIGN(SZ_2K) { 346 __mmuoff_data_start = .; 347 *(.mmuoff.data.write) 348 } 349 . = ALIGN(SZ_2K); 350 .mmuoff.data.read : { 351 *(.mmuoff.data.read) 352 __mmuoff_data_end = .; 353 } 354 355 PECOFF_EDATA_PADDING 356 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 357 _edata = .; 358 359 /* start of zero-init region */ 360 BSS_SECTION(SBSS_ALIGN, 0, PAGE_SIZE) 361 __pi___bss_start = __bss_start; 362 363 /* page table BSS starts here - preceding data/BSS is omitted from the linear map */ 364 .pgtbl : ALIGN(PAGE_SIZE) { 365 *(.bss..pgtbl) 366 } 367 ASSERT(ADDR(.pgtbl) == __bss_stop, ".pgtbl must follow BSS") 368 369 . = ALIGN(PAGE_SIZE); 370 __pi_init_pg_dir = .; 371 . += INIT_DIR_SIZE; 372 __pi_init_pg_end = .; 373 /* end of zero-init region */ 374 375 . += SZ_4K; /* stack for the early C runtime */ 376 early_init_stack = .; 377 378 . = ALIGN(SEGMENT_ALIGN); 379 __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 380 _end = .; 381 __pi__end = .; 382 383 STABS_DEBUG 384 DWARF_DEBUG 385 PROPELLER_DATA 386 MODINFO 387 ELF_DETAILS 388 389 HEAD_SYMBOLS 390 391 /* 392 * Sections that should stay zero sized, which is safer to 393 * explicitly check instead of blindly discarding. 394 */ 395 .plt : { 396 *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) 397 } 398 ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 399} 400 401#include "image-vars.h" 402 403/* 404 * The HYP init code and ID map text can't be longer than a page each. The 405 * former is page-aligned, but the latter may not be with 16K or 64K pages, so 406 * it should also not cross a page boundary. 407 */ 408ASSERT(__hyp_idmap_text_end - __hyp_idmap_text_start <= PAGE_SIZE, 409 "HYP init code too big") 410ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 411 "ID map text too big or misaligned") 412#ifdef CONFIG_HIBERNATION 413ASSERT(__hibernate_exit_text_end - __hibernate_exit_text_start <= SZ_4K, 414 "Hibernate exit text is bigger than 4 KiB") 415ASSERT(__hibernate_exit_text_start == swsusp_arch_suspend_exit, 416 "Hibernate exit text does not start with swsusp_arch_suspend_exit") 417#endif 418#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 419ASSERT((__entry_tramp_text_end - __entry_tramp_text_start) <= 3*PAGE_SIZE, 420 "Entry trampoline text too big") 421#endif 422#ifdef CONFIG_KVM 423ASSERT(__hyp_bss_start == __bss_start, "HYP and Host BSS are misaligned") 424#endif 425/* 426 * If padding is applied before .head.text, virt<->phys conversions will fail. 427 */ 428ASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") 429 430ASSERT(swapper_pg_dir - reserved_pg_dir == RESERVED_SWAPPER_OFFSET, 431 "RESERVED_SWAPPER_OFFSET is wrong!") 432 433#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 434ASSERT(swapper_pg_dir - tramp_pg_dir == TRAMP_SWAPPER_OFFSET, 435 "TRAMP_SWAPPER_OFFSET is wrong!") 436#endif 437 438#ifdef CONFIG_KEXEC_CORE 439/* kexec relocation code should fit into one KEXEC_CONTROL_PAGE_SIZE */ 440ASSERT(__relocate_new_kernel_end - __relocate_new_kernel_start <= SZ_4K, 441 "kexec relocation code is bigger than 4 KiB") 442ASSERT(KEXEC_CONTROL_PAGE_SIZE >= SZ_4K, "KEXEC_CONTROL_PAGE_SIZE is broken") 443ASSERT(__relocate_new_kernel_start == arm64_relocate_new_kernel, 444 "kexec control page does not start with arm64_relocate_new_kernel") 445#endif 446