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 = .; 32e9ee186bSJames Morse 33*2d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS \ 34*2d7bf218SDavid Brazdil HYP_SECTION_NAME(.data..ro_after_init) : { \ 35*2d7bf218SDavid Brazdil __hyp_data_ro_after_init_start = .; \ 36*2d7bf218SDavid Brazdil *(HYP_SECTION_NAME(.data..ro_after_init)) \ 37*2d7bf218SDavid Brazdil __hyp_data_ro_after_init_end = .; \ 38*2d7bf218SDavid Brazdil } 39*2d7bf218SDavid Brazdil 4030c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION \ 4130c95391SDavid Brazdil . = ALIGN(PAGE_SIZE); \ 4230c95391SDavid Brazdil HYP_SECTION_NAME(.data..percpu) : { \ 4330c95391SDavid Brazdil *(HYP_SECTION_NAME(.data..percpu)) \ 4430c95391SDavid Brazdil } 453471ee06SDavid Brazdil#else /* CONFIG_KVM */ 463471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE 47*2d7bf218SDavid Brazdil#define HYPERVISOR_DATA_SECTIONS 4830c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION 493471ee06SDavid Brazdil#endif 508c2c3df3SCatalin Marinas 512240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 522240bbb6SMarc Zyngier /* \ 5306f75a1fSArd Biesheuvel * Align to 4 KB so that \ 5406f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 5506f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 5606f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 5706f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 5806f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 592240bbb6SMarc Zyngier */ \ 6006f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 615c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 622240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 635c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 645c636aa0SMasahiro Yamada __hyp_text_start = .; \ 652240bbb6SMarc Zyngier *(.hyp.text) \ 66e9ee186bSJames Morse HYPERVISOR_EXTABLE \ 675c636aa0SMasahiro Yamada __hyp_text_end = .; 682240bbb6SMarc Zyngier 695dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 705dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 715c636aa0SMasahiro Yamada __idmap_text_start = .; \ 725dfe9d7dSArd Biesheuvel *(.idmap.text) \ 735c636aa0SMasahiro Yamada __idmap_text_end = .; 745dfe9d7dSArd Biesheuvel 7582869ac5SJames Morse#ifdef CONFIG_HIBERNATION 7682869ac5SJames Morse#define HIBERNATE_TEXT \ 7782869ac5SJames Morse . = ALIGN(SZ_4K); \ 785c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 7982869ac5SJames Morse *(.hibernate_exit.text) \ 805c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 8182869ac5SJames Morse#else 8282869ac5SJames Morse#define HIBERNATE_TEXT 8382869ac5SJames Morse#endif 8482869ac5SJames Morse 85c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 86c7b9adafSWill Deacon#define TRAMP_TEXT \ 87c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 885c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 89c7b9adafSWill Deacon *(.entry.tramp.text) \ 90c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 915c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 92c7b9adafSWill Deacon#else 93c7b9adafSWill Deacon#define TRAMP_TEXT 94c7b9adafSWill Deacon#endif 95c7b9adafSWill Deacon 96a352ea3eSArd Biesheuvel/* 97a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 98348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 99348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 100a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 101a352ea3eSArd Biesheuvel * boundary should be sufficient. 102a352ea3eSArd Biesheuvel */ 103a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 104a352ea3eSArd Biesheuvel 105a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 106a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 107a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 108a352ea3eSArd Biesheuvel#else 109a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 110a352ea3eSArd Biesheuvel#endif 111a352ea3eSArd Biesheuvel 1128c2c3df3SCatalin MarinasSECTIONS 1138c2c3df3SCatalin Marinas{ 1148c2c3df3SCatalin Marinas /* 1158c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 1168c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 1178c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 1188c2c3df3SCatalin Marinas * order of matching. 1198c2c3df3SCatalin Marinas */ 1202883352bSKees Cook DISCARDS 1218c2c3df3SCatalin Marinas /DISCARD/ : { 1221e48ef7fSArd Biesheuvel *(.interp .dynamic) 1233bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 1248c2c3df3SCatalin Marinas } 1258c2c3df3SCatalin Marinas 126120dc60dSArd Biesheuvel . = KIMAGE_VADDR; 1278c2c3df3SCatalin Marinas 1288c2c3df3SCatalin Marinas .head.text : { 1298c2c3df3SCatalin Marinas _text = .; 1308c2c3df3SCatalin Marinas HEAD_TEXT 1318c2c3df3SCatalin Marinas } 1328c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1338c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1348c2c3df3SCatalin Marinas IRQENTRY_TEXT 135be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 136888b3c87SPratyush Anand ENTRY_TEXT 1378c2c3df3SCatalin Marinas TEXT_TEXT 1388c2c3df3SCatalin Marinas SCHED_TEXT 1396727ad9eSChris Metcalf CPUIDLE_TEXT 1408c2c3df3SCatalin Marinas LOCK_TEXT 1412dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1422240bbb6SMarc Zyngier HYPERVISOR_TEXT 1435dfe9d7dSArd Biesheuvel IDMAP_TEXT 14482869ac5SJames Morse HIBERNATE_TEXT 145c7b9adafSWill Deacon TRAMP_TEXT 1468c2c3df3SCatalin Marinas *(.fixup) 1478c2c3df3SCatalin Marinas *(.gnu.warning) 1488c2c3df3SCatalin Marinas . = ALIGN(16); 1498c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1508c2c3df3SCatalin Marinas } 1518c2c3df3SCatalin Marinas 152be288182SKees Cook /* 153be288182SKees Cook * Make sure that the .got.plt is either completely empty or it 154be288182SKees Cook * contains only the lazy dispatch entries. 155be288182SKees Cook */ 156be288182SKees Cook .got.plt : { *(.got.plt) } 157be288182SKees Cook ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 158be288182SKees Cook "Unexpected GOT/PLT entries detected!") 159be288182SKees Cook 16097740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1619fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1629fdc14c5SArd Biesheuvel 16319f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 16419f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1658c2c3df3SCatalin Marinas 1668eb7e28dSJun Yao idmap_pg_dir = .; 1678eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1689d2d75edSGavin Shan idmap_pg_end = .; 1698eb7e28dSJun Yao 1708eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1718eb7e28dSJun Yao tramp_pg_dir = .; 1728eb7e28dSJun Yao . += PAGE_SIZE; 1738eb7e28dSJun Yao#endif 1748eb7e28dSJun Yao 1758eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1768eb7e28dSJun Yao reserved_ttbr0 = .; 1778eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1788eb7e28dSJun Yao#endif 1798eb7e28dSJun Yao swapper_pg_dir = .; 1808eb7e28dSJun Yao . += PAGE_SIZE; 1818eb7e28dSJun Yao swapper_pg_end = .; 1828eb7e28dSJun Yao 18397740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1848c2c3df3SCatalin Marinas __init_begin = .; 1852ebe088bSArd Biesheuvel __inittext_begin = .; 1868c2c3df3SCatalin Marinas 1878c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 188ca2ef4ffSMark Rutland 189ca2ef4ffSMark Rutland __exittext_begin = .; 1908c2c3df3SCatalin Marinas .exit.text : { 1911eae811dSArd Biesheuvel EXIT_TEXT 1928c2c3df3SCatalin Marinas } 193ca2ef4ffSMark Rutland __exittext_end = .; 194da141706SLaura Abbott 1952ebe088bSArd Biesheuvel . = ALIGN(4); 1962ebe088bSArd Biesheuvel .altinstructions : { 1972ebe088bSArd Biesheuvel __alt_instructions = .; 1982ebe088bSArd Biesheuvel *(.altinstructions) 1992ebe088bSArd Biesheuvel __alt_instructions_end = .; 2002ebe088bSArd Biesheuvel } 2012ebe088bSArd Biesheuvel 20276085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2032ebe088bSArd Biesheuvel __inittext_end = .; 2042ebe088bSArd Biesheuvel __initdata_begin = .; 2052ebe088bSArd Biesheuvel 2068c2c3df3SCatalin Marinas .init.data : { 2078c2c3df3SCatalin Marinas INIT_DATA 2088c2c3df3SCatalin Marinas INIT_SETUP(16) 2098c2c3df3SCatalin Marinas INIT_CALLS 2108c2c3df3SCatalin Marinas CON_INITCALL 2118c2c3df3SCatalin Marinas INIT_RAM_FS 212e35123d8SWill Deacon *(.init.altinstructions .init.rodata.* .init.bss) /* from the EFI stub */ 2138c2c3df3SCatalin Marinas } 2148c2c3df3SCatalin Marinas .exit.data : { 2151eae811dSArd Biesheuvel EXIT_DATA 2168c2c3df3SCatalin Marinas } 2178c2c3df3SCatalin Marinas 21898fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 21930c95391SDavid Brazdil HYPERVISOR_PERCPU_SECTION 2208c2c3df3SCatalin Marinas 2213bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 2221e48ef7fSArd Biesheuvel *(.rela .rela*) 2231e48ef7fSArd Biesheuvel } 224e039ee4eSAndre Przywara 2253bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 2263bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 2270cd3defeSArd Biesheuvel 2285cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2295cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2305cf896fbSPeter Collingbourne *(.relr.dyn) 2315cf896fbSPeter Collingbourne } 2325cf896fbSPeter Collingbourne 2335cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2345cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2355cf896fbSPeter Collingbourne#endif 2365cf896fbSPeter Collingbourne 23797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2382ebe088bSArd Biesheuvel __initdata_end = .; 2399aa4ec15SMark Rutland __init_end = .; 2409aa4ec15SMark Rutland 2413c620626SMark Salter _data = .; 2428c2c3df3SCatalin Marinas _sdata = .; 243c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 244b6113038SJames Morse 245*2d7bf218SDavid Brazdil HYPERVISOR_DATA_SECTIONS 246*2d7bf218SDavid Brazdil 247b6113038SJames Morse /* 248b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 249b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 250b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 251b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 252b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 253b6113038SJames Morse * interfere with adjacent data. 254b6113038SJames Morse */ 255b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 256b6113038SJames Morse __mmuoff_data_start = .; 257b6113038SJames Morse *(.mmuoff.data.write) 258b6113038SJames Morse } 259b6113038SJames Morse . = ALIGN(SZ_2K); 260b6113038SJames Morse .mmuoff.data.read : { 261b6113038SJames Morse *(.mmuoff.data.read) 262b6113038SJames Morse __mmuoff_data_end = .; 263b6113038SJames Morse } 264b6113038SJames Morse 265a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 266cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2678c2c3df3SCatalin Marinas _edata = .; 2688c2c3df3SCatalin Marinas 2698c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 270bd00cd5fSMark Rutland 271bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2722b5548b6SJun Yao init_pg_dir = .; 2732b5548b6SJun Yao . += INIT_DIR_SIZE; 2742b5548b6SJun Yao init_pg_end = .; 2752b5548b6SJun Yao 27676085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 277cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2788c2c3df3SCatalin Marinas _end = .; 2798c2c3df3SCatalin Marinas 2808c2c3df3SCatalin Marinas STABS_DEBUG 281578d7f0fSKees Cook DWARF_DEBUG 282c604abc3SKees Cook ELF_DETAILS 283a2c1d73bSMark Rutland 284a2c1d73bSMark Rutland HEAD_SYMBOLS 285be288182SKees Cook 286be288182SKees Cook /* 287be288182SKees Cook * Sections that should stay zero sized, which is safer to 288be288182SKees Cook * explicitly check instead of blindly discarding. 289be288182SKees Cook */ 290be288182SKees Cook .plt : { 2915f692a81SArd Biesheuvel *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) 292be288182SKees Cook } 293be288182SKees Cook ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 294be288182SKees Cook 295be288182SKees Cook .data.rel.ro : { *(.data.rel.ro) } 296be288182SKees Cook ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 2978c2c3df3SCatalin Marinas} 2982240bbb6SMarc Zyngier 29990776dd1SKees Cook#include "image-vars.h" 30090776dd1SKees Cook 3012240bbb6SMarc Zyngier/* 3025dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 30306f75a1fSArd Biesheuvel * and should not cross a page boundary. 3042240bbb6SMarc Zyngier */ 30506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 30606f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 3075dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 3085dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 30982869ac5SJames Morse#ifdef CONFIG_HIBERNATION 31082869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 31182869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 31282869ac5SJames Morse#endif 3136c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 3146c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 3156c27c408SWill Deacon "Entry trampoline text too big") 3166c27c408SWill Deacon#endif 317da57a369SMark Rutland/* 318da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 319da57a369SMark Rutland */ 320120dc60dSArd BiesheuvelASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") 321