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-generic/vmlinux.lds.h> 9#include <asm/cache.h> 10#include <asm/kernel-pgtable.h> 11#include <asm/thread_info.h> 12#include <asm/memory.h> 13#include <asm/page.h> 14#include <asm/pgtable.h> 15 16#include "image.h" 17 18/* .exit.text needed in case of alternative patching */ 19#define ARM_EXIT_KEEP(x) x 20#define ARM_EXIT_DISCARD(x) 21 22OUTPUT_ARCH(aarch64) 23ENTRY(_text) 24 25jiffies = jiffies_64; 26 27#define HYPERVISOR_TEXT \ 28 /* \ 29 * Align to 4 KB so that \ 30 * a) the HYP vector table is at its minimum \ 31 * alignment of 2048 bytes \ 32 * b) the HYP init code will not cross a page \ 33 * boundary if its size does not exceed \ 34 * 4 KB (see related ASSERT() below) \ 35 */ \ 36 . = ALIGN(SZ_4K); \ 37 VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ 38 *(.hyp.idmap.text) \ 39 VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \ 40 VMLINUX_SYMBOL(__hyp_text_start) = .; \ 41 *(.hyp.text) \ 42 VMLINUX_SYMBOL(__hyp_text_end) = .; 43 44#define IDMAP_TEXT \ 45 . = ALIGN(SZ_4K); \ 46 VMLINUX_SYMBOL(__idmap_text_start) = .; \ 47 *(.idmap.text) \ 48 VMLINUX_SYMBOL(__idmap_text_end) = .; 49 50#ifdef CONFIG_HIBERNATION 51#define HIBERNATE_TEXT \ 52 . = ALIGN(SZ_4K); \ 53 VMLINUX_SYMBOL(__hibernate_exit_text_start) = .;\ 54 *(.hibernate_exit.text) \ 55 VMLINUX_SYMBOL(__hibernate_exit_text_end) = .; 56#else 57#define HIBERNATE_TEXT 58#endif 59 60/* 61 * The size of the PE/COFF section that covers the kernel image, which 62 * runs from stext to _edata, must be a round multiple of the PE/COFF 63 * FileAlignment, which we set to its minimum value of 0x200. 'stext' 64 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 65 * boundary should be sufficient. 66 */ 67PECOFF_FILE_ALIGNMENT = 0x200; 68 69#ifdef CONFIG_EFI 70#define PECOFF_EDATA_PADDING \ 71 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 72#else 73#define PECOFF_EDATA_PADDING 74#endif 75 76SECTIONS 77{ 78 /* 79 * XXX: The linker does not define how output sections are 80 * assigned to input sections when there are multiple statements 81 * matching the same input section name. There is no documented 82 * order of matching. 83 */ 84 /DISCARD/ : { 85 ARM_EXIT_DISCARD(EXIT_TEXT) 86 ARM_EXIT_DISCARD(EXIT_DATA) 87 EXIT_CALL 88 *(.discard) 89 *(.discard.*) 90 *(.interp .dynamic) 91 *(.dynsym .dynstr .hash) 92 } 93 94 . = KIMAGE_VADDR + TEXT_OFFSET; 95 96 .head.text : { 97 _text = .; 98 HEAD_TEXT 99 } 100 .text : { /* Real text segment */ 101 _stext = .; /* Text and read-only data */ 102 __exception_text_start = .; 103 *(.exception.text) 104 __exception_text_end = .; 105 IRQENTRY_TEXT 106 SOFTIRQENTRY_TEXT 107 ENTRY_TEXT 108 TEXT_TEXT 109 SCHED_TEXT 110 CPUIDLE_TEXT 111 LOCK_TEXT 112 KPROBES_TEXT 113 HYPERVISOR_TEXT 114 IDMAP_TEXT 115 HIBERNATE_TEXT 116 *(.fixup) 117 *(.gnu.warning) 118 . = ALIGN(16); 119 *(.got) /* Global offset table */ 120 } 121 122 . = ALIGN(SEGMENT_ALIGN); 123 _etext = .; /* End of text section */ 124 125 RO_DATA(PAGE_SIZE) /* everything from this point to */ 126 EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */ 127 NOTES 128 129 . = ALIGN(SEGMENT_ALIGN); 130 __init_begin = .; 131 __inittext_begin = .; 132 133 INIT_TEXT_SECTION(8) 134 .exit.text : { 135 ARM_EXIT_KEEP(EXIT_TEXT) 136 } 137 138 . = ALIGN(4); 139 .altinstructions : { 140 __alt_instructions = .; 141 *(.altinstructions) 142 __alt_instructions_end = .; 143 } 144 .altinstr_replacement : { 145 *(.altinstr_replacement) 146 } 147 148 . = ALIGN(PAGE_SIZE); 149 __inittext_end = .; 150 __initdata_begin = .; 151 152 .init.data : { 153 INIT_DATA 154 INIT_SETUP(16) 155 INIT_CALLS 156 CON_INITCALL 157 SECURITY_INITCALL 158 INIT_RAM_FS 159 *(.init.rodata.* .init.bss) /* from the EFI stub */ 160 } 161 .exit.data : { 162 ARM_EXIT_KEEP(EXIT_DATA) 163 } 164 165 PERCPU_SECTION(L1_CACHE_BYTES) 166 167 .rela : ALIGN(8) { 168 *(.rela .rela*) 169 } 170 171 __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); 172 __rela_size = SIZEOF(.rela); 173 174 . = ALIGN(SEGMENT_ALIGN); 175 __initdata_end = .; 176 __init_end = .; 177 178 _data = .; 179 _sdata = .; 180 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 181 182 /* 183 * Data written with the MMU off but read with the MMU on requires 184 * cache lines to be invalidated, discarding up to a Cache Writeback 185 * Granule (CWG) of data from the cache. Keep the section that 186 * requires this type of maintenance to be in its own Cache Writeback 187 * Granule (CWG) area so the cache maintenance operations don't 188 * interfere with adjacent data. 189 */ 190 .mmuoff.data.write : ALIGN(SZ_2K) { 191 __mmuoff_data_start = .; 192 *(.mmuoff.data.write) 193 } 194 . = ALIGN(SZ_2K); 195 .mmuoff.data.read : { 196 *(.mmuoff.data.read) 197 __mmuoff_data_end = .; 198 } 199 200 PECOFF_EDATA_PADDING 201 __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 202 _edata = .; 203 204 BSS_SECTION(0, 0, 0) 205 206 . = ALIGN(PAGE_SIZE); 207 idmap_pg_dir = .; 208 . += IDMAP_DIR_SIZE; 209 swapper_pg_dir = .; 210 . += SWAPPER_DIR_SIZE; 211 212#ifdef CONFIG_ARM64_SW_TTBR0_PAN 213 reserved_ttbr0 = .; 214 . += RESERVED_TTBR0_SIZE; 215#endif 216 217 __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 218 _end = .; 219 220 STABS_DEBUG 221 222 HEAD_SYMBOLS 223} 224 225/* 226 * The HYP init code and ID map text can't be longer than a page each, 227 * and should not cross a page boundary. 228 */ 229ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 230 "HYP init code too big or misaligned") 231ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 232 "ID map text too big or misaligned") 233#ifdef CONFIG_HIBERNATION 234ASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 235 <= SZ_4K, "Hibernate exit text too big or misaligned") 236#endif 237 238/* 239 * If padding is applied before .head.text, virt<->phys conversions will fail. 240 */ 241ASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 242