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