1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */ 28c2c3df3SCatalin Marinas/* 38c2c3df3SCatalin Marinas * ld script to make ARM Linux kernel 48c2c3df3SCatalin Marinas * taken from the i386 version by Russell King 58c2c3df3SCatalin Marinas * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> 68c2c3df3SCatalin Marinas */ 78c2c3df3SCatalin Marinas 819f6bc32SKees Cook#define RO_EXCEPTION_TABLE_ALIGN 8 92883352bSKees Cook#define RUNTIME_DISCARD_EXIT 1019f6bc32SKees Cook 118c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h> 1298fb7548SArd Biesheuvel#include <asm/cache.h> 13ce492a16SDavid Brazdil#include <asm/hyp_image.h> 1487d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h> 158c2c3df3SCatalin Marinas#include <asm/memory.h> 168c2c3df3SCatalin Marinas#include <asm/page.h> 178c2c3df3SCatalin Marinas 18a2c1d73bSMark Rutland#include "image.h" 19a2c1d73bSMark Rutland 208c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64) 21af885f40SGeoff LevandENTRY(_text) 228c2c3df3SCatalin Marinas 238c2c3df3SCatalin Marinasjiffies = jiffies_64; 248c2c3df3SCatalin Marinas 25e9ee186bSJames Morse 263471ee06SDavid Brazdil#ifdef CONFIG_KVM 27e9ee186bSJames Morse#define HYPERVISOR_EXTABLE \ 28e9ee186bSJames Morse . = ALIGN(SZ_8); \ 29e9ee186bSJames Morse __start___kvm_ex_table = .; \ 30e9ee186bSJames Morse *(__kvm_ex_table) \ 31e9ee186bSJames Morse __stop___kvm_ex_table = .; 3230c95391SDavid Brazdil 332d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS \ 3416174eeaSDavid Brazdil HYP_SECTION_NAME(.rodata) : { \ 3516174eeaSDavid Brazdil __hyp_rodata_start = .; \ 362d7bf218SDavid Brazdil *(HYP_SECTION_NAME(.data..ro_after_init)) \ 3716174eeaSDavid Brazdil *(HYP_SECTION_NAME(.rodata)) \ 3816174eeaSDavid Brazdil __hyp_rodata_end = .; \ 392d7bf218SDavid Brazdil } 402d7bf218SDavid Brazdil 4130c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION \ 4230c95391SDavid Brazdil . = ALIGN(PAGE_SIZE); \ 4330c95391SDavid Brazdil HYP_SECTION_NAME(.data..percpu) : { \ 4430c95391SDavid Brazdil *(HYP_SECTION_NAME(.data..percpu)) \ 4530c95391SDavid Brazdil } 46*8c49b5d4SDavid Brazdil 47*8c49b5d4SDavid Brazdil#define HYPERVISOR_RELOC_SECTION \ 48*8c49b5d4SDavid Brazdil .hyp.reloc : ALIGN(4) { \ 49*8c49b5d4SDavid Brazdil __hyp_reloc_begin = .; \ 50*8c49b5d4SDavid Brazdil *(.hyp.reloc) \ 51*8c49b5d4SDavid Brazdil __hyp_reloc_end = .; \ 52*8c49b5d4SDavid Brazdil } 53*8c49b5d4SDavid Brazdil 543471ee06SDavid Brazdil#else /* CONFIG_KVM */ 553471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE 562d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS 5730c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION 58*8c49b5d4SDavid Brazdil#define HYPERVISOR_RELOC_SECTION 593471ee06SDavid Brazdil#endif 60e9ee186bSJames Morse 612240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 622240bbb6SMarc Zyngier /* \ 6306f75a1fSArd Biesheuvel * Align to 4 KB so that \ 6406f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 6506f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 6606f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 6706f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 6806f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 692240bbb6SMarc Zyngier */ \ 7006f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 715c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 722240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 735c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 745c636aa0SMasahiro Yamada __hyp_text_start = .; \ 752240bbb6SMarc Zyngier *(.hyp.text) \ 76e9ee186bSJames Morse HYPERVISOR_EXTABLE \ 775c636aa0SMasahiro Yamada __hyp_text_end = .; 782240bbb6SMarc Zyngier 795dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 805dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 815c636aa0SMasahiro Yamada __idmap_text_start = .; \ 825dfe9d7dSArd Biesheuvel *(.idmap.text) \ 835c636aa0SMasahiro Yamada __idmap_text_end = .; 845dfe9d7dSArd Biesheuvel 8582869ac5SJames Morse#ifdef CONFIG_HIBERNATION 8682869ac5SJames Morse#define HIBERNATE_TEXT \ 8782869ac5SJames Morse . = ALIGN(SZ_4K); \ 885c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 8982869ac5SJames Morse *(.hibernate_exit.text) \ 905c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 9182869ac5SJames Morse#else 9282869ac5SJames Morse#define HIBERNATE_TEXT 9382869ac5SJames Morse#endif 9482869ac5SJames Morse 95c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 96c7b9adafSWill Deacon#define TRAMP_TEXT \ 97c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 985c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 99c7b9adafSWill Deacon *(.entry.tramp.text) \ 100c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 1015c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 102c7b9adafSWill Deacon#else 103c7b9adafSWill Deacon#define TRAMP_TEXT 104c7b9adafSWill Deacon#endif 105c7b9adafSWill Deacon 106a352ea3eSArd Biesheuvel/* 107a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 108348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 109348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 110a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 111a352ea3eSArd Biesheuvel * boundary should be sufficient. 112a352ea3eSArd Biesheuvel */ 113a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 114a352ea3eSArd Biesheuvel 115a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 116a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 117a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 118a352ea3eSArd Biesheuvel#else 119a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 120a352ea3eSArd Biesheuvel#endif 121a352ea3eSArd Biesheuvel 1228c2c3df3SCatalin MarinasSECTIONS 1238c2c3df3SCatalin Marinas{ 1248c2c3df3SCatalin Marinas /* 1258c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 1268c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 1278c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 1288c2c3df3SCatalin Marinas * order of matching. 1298c2c3df3SCatalin Marinas */ 1302883352bSKees Cook DISCARDS 1318c2c3df3SCatalin Marinas /DISCARD/ : { 1321e48ef7fSArd Biesheuvel *(.interp .dynamic) 1333bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 1348c2c3df3SCatalin Marinas } 1358c2c3df3SCatalin Marinas 136120dc60dSArd Biesheuvel . = KIMAGE_VADDR; 1378c2c3df3SCatalin Marinas 1388c2c3df3SCatalin Marinas .head.text : { 1398c2c3df3SCatalin Marinas _text = .; 1408c2c3df3SCatalin Marinas HEAD_TEXT 1418c2c3df3SCatalin Marinas } 142e2a073ddSArd Biesheuvel .text : ALIGN(SEGMENT_ALIGN) { /* Real text segment */ 1438c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1448c2c3df3SCatalin Marinas IRQENTRY_TEXT 145be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 146888b3c87SPratyush Anand ENTRY_TEXT 1478c2c3df3SCatalin Marinas TEXT_TEXT 1488c2c3df3SCatalin Marinas SCHED_TEXT 1496727ad9eSChris Metcalf CPUIDLE_TEXT 1508c2c3df3SCatalin Marinas LOCK_TEXT 1512dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1522240bbb6SMarc Zyngier HYPERVISOR_TEXT 1535dfe9d7dSArd Biesheuvel IDMAP_TEXT 15482869ac5SJames Morse HIBERNATE_TEXT 155c7b9adafSWill Deacon TRAMP_TEXT 1568c2c3df3SCatalin Marinas *(.fixup) 1578c2c3df3SCatalin Marinas *(.gnu.warning) 1588c2c3df3SCatalin Marinas . = ALIGN(16); 1598c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1608c2c3df3SCatalin Marinas } 1618c2c3df3SCatalin Marinas 162be288182SKees Cook /* 163be288182SKees Cook * Make sure that the .got.plt is either completely empty or it 164be288182SKees Cook * contains only the lazy dispatch entries. 165be288182SKees Cook */ 166be288182SKees Cook .got.plt : { *(.got.plt) } 167be288182SKees Cook ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 168be288182SKees Cook "Unexpected GOT/PLT entries detected!") 169be288182SKees Cook 17097740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1719fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1729fdc14c5SArd Biesheuvel 17319f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 17419f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1758c2c3df3SCatalin Marinas 1768eb7e28dSJun Yao idmap_pg_dir = .; 1778eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1789d2d75edSGavin Shan idmap_pg_end = .; 1798eb7e28dSJun Yao 1808eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1818eb7e28dSJun Yao tramp_pg_dir = .; 1828eb7e28dSJun Yao . += PAGE_SIZE; 1838eb7e28dSJun Yao#endif 1848eb7e28dSJun Yao 185833be850SMark Rutland reserved_pg_dir = .; 186833be850SMark Rutland . += PAGE_SIZE; 187833be850SMark Rutland 1888eb7e28dSJun Yao swapper_pg_dir = .; 1898eb7e28dSJun Yao . += PAGE_SIZE; 1908eb7e28dSJun Yao 19197740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1928c2c3df3SCatalin Marinas __init_begin = .; 1932ebe088bSArd Biesheuvel __inittext_begin = .; 1948c2c3df3SCatalin Marinas 1958c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 196ca2ef4ffSMark Rutland 197ca2ef4ffSMark Rutland __exittext_begin = .; 1988c2c3df3SCatalin Marinas .exit.text : { 1991eae811dSArd Biesheuvel EXIT_TEXT 2008c2c3df3SCatalin Marinas } 201ca2ef4ffSMark Rutland __exittext_end = .; 202da141706SLaura Abbott 2032ebe088bSArd Biesheuvel . = ALIGN(4); 2042ebe088bSArd Biesheuvel .altinstructions : { 2052ebe088bSArd Biesheuvel __alt_instructions = .; 2062ebe088bSArd Biesheuvel *(.altinstructions) 2072ebe088bSArd Biesheuvel __alt_instructions_end = .; 2082ebe088bSArd Biesheuvel } 2092ebe088bSArd Biesheuvel 21076085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2112ebe088bSArd Biesheuvel __inittext_end = .; 2122ebe088bSArd Biesheuvel __initdata_begin = .; 2132ebe088bSArd Biesheuvel 2148c2c3df3SCatalin Marinas .init.data : { 2158c2c3df3SCatalin Marinas INIT_DATA 2168c2c3df3SCatalin Marinas INIT_SETUP(16) 2178c2c3df3SCatalin Marinas INIT_CALLS 2188c2c3df3SCatalin Marinas CON_INITCALL 2198c2c3df3SCatalin Marinas INIT_RAM_FS 220ba4259a6SCatalin Marinas *(.init.altinstructions .init.bss) /* from the EFI stub */ 2218c2c3df3SCatalin Marinas } 2228c2c3df3SCatalin Marinas .exit.data : { 2231eae811dSArd Biesheuvel EXIT_DATA 2248c2c3df3SCatalin Marinas } 2258c2c3df3SCatalin Marinas 22698fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 22730c95391SDavid Brazdil HYPERVISOR_PERCPU_SECTION 2288c2c3df3SCatalin Marinas 229*8c49b5d4SDavid Brazdil HYPERVISOR_RELOC_SECTION 230*8c49b5d4SDavid Brazdil 2313bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 2321e48ef7fSArd Biesheuvel *(.rela .rela*) 2331e48ef7fSArd Biesheuvel } 234e039ee4eSAndre Przywara 2353bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 2363bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 2370cd3defeSArd Biesheuvel 2385cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2395cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2405cf896fbSPeter Collingbourne *(.relr.dyn) 2415cf896fbSPeter Collingbourne } 2425cf896fbSPeter Collingbourne 2435cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2445cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2455cf896fbSPeter Collingbourne#endif 2465cf896fbSPeter Collingbourne 24797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2482ebe088bSArd Biesheuvel __initdata_end = .; 2499aa4ec15SMark Rutland __init_end = .; 2509aa4ec15SMark Rutland 2513c620626SMark Salter _data = .; 2528c2c3df3SCatalin Marinas _sdata = .; 253c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 254b6113038SJames Morse 2552d7bf218SDavid Brazdil HYPERVISOR_DATA_SECTIONS 2562d7bf218SDavid Brazdil 257b6113038SJames Morse /* 258b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 259b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 260b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 261b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 262b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 263b6113038SJames Morse * interfere with adjacent data. 264b6113038SJames Morse */ 265b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 266b6113038SJames Morse __mmuoff_data_start = .; 267b6113038SJames Morse *(.mmuoff.data.write) 268b6113038SJames Morse } 269b6113038SJames Morse . = ALIGN(SZ_2K); 270b6113038SJames Morse .mmuoff.data.read : { 271b6113038SJames Morse *(.mmuoff.data.read) 272b6113038SJames Morse __mmuoff_data_end = .; 273b6113038SJames Morse } 274b6113038SJames Morse 275a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 276cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2778c2c3df3SCatalin Marinas _edata = .; 2788c2c3df3SCatalin Marinas 2798c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 280bd00cd5fSMark Rutland 281bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2822b5548b6SJun Yao init_pg_dir = .; 2832b5548b6SJun Yao . += INIT_DIR_SIZE; 2842b5548b6SJun Yao init_pg_end = .; 2852b5548b6SJun Yao 28676085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 287cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2888c2c3df3SCatalin Marinas _end = .; 2898c2c3df3SCatalin Marinas 2908c2c3df3SCatalin Marinas STABS_DEBUG 291578d7f0fSKees Cook DWARF_DEBUG 292c604abc3SKees Cook ELF_DETAILS 293a2c1d73bSMark Rutland 294a2c1d73bSMark Rutland HEAD_SYMBOLS 295be288182SKees Cook 296be288182SKees Cook /* 297be288182SKees Cook * Sections that should stay zero sized, which is safer to 298be288182SKees Cook * explicitly check instead of blindly discarding. 299be288182SKees Cook */ 300be288182SKees Cook .plt : { 3015f692a81SArd Biesheuvel *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) 302be288182SKees Cook } 303be288182SKees Cook ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 304be288182SKees Cook 305be288182SKees Cook .data.rel.ro : { *(.data.rel.ro) } 306be288182SKees Cook ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 3078c2c3df3SCatalin Marinas} 3082240bbb6SMarc Zyngier 30990776dd1SKees Cook#include "image-vars.h" 31090776dd1SKees Cook 3112240bbb6SMarc Zyngier/* 3125dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 31306f75a1fSArd Biesheuvel * and should not cross a page boundary. 3142240bbb6SMarc Zyngier */ 31506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 31606f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 3175dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 3185dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 31982869ac5SJames Morse#ifdef CONFIG_HIBERNATION 32082869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 32182869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 32282869ac5SJames Morse#endif 3236c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 3246c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 3256c27c408SWill Deacon "Entry trampoline text too big") 3266c27c408SWill Deacon#endif 327da57a369SMark Rutland/* 328da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 329da57a369SMark Rutland */ 330120dc60dSArd BiesheuvelASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") 331