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 3330c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION \ 3430c95391SDavid Brazdil . = ALIGN(PAGE_SIZE); \ 3530c95391SDavid Brazdil HYP_SECTION_NAME(.data..percpu) : { \ 3630c95391SDavid Brazdil *(HYP_SECTION_NAME(.data..percpu)) \ 3730c95391SDavid Brazdil } 383471ee06SDavid Brazdil#else /* CONFIG_KVM */ 393471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE 4030c95391SDavid Brazdil#define HYPERVISOR_PERCPU_SECTION 413471ee06SDavid Brazdil#endif 428c2c3df3SCatalin Marinas 432240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 442240bbb6SMarc Zyngier /* \ 4506f75a1fSArd Biesheuvel * Align to 4 KB so that \ 4606f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 4706f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 4806f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 4906f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 5006f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 512240bbb6SMarc Zyngier */ \ 5206f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 535c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 542240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 555c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 565c636aa0SMasahiro Yamada __hyp_text_start = .; \ 572240bbb6SMarc Zyngier *(.hyp.text) \ 58e9ee186bSJames Morse HYPERVISOR_EXTABLE \ 595c636aa0SMasahiro Yamada __hyp_text_end = .; 602240bbb6SMarc Zyngier 615dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 625dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 635c636aa0SMasahiro Yamada __idmap_text_start = .; \ 645dfe9d7dSArd Biesheuvel *(.idmap.text) \ 655c636aa0SMasahiro Yamada __idmap_text_end = .; 665dfe9d7dSArd Biesheuvel 6782869ac5SJames Morse#ifdef CONFIG_HIBERNATION 6882869ac5SJames Morse#define HIBERNATE_TEXT \ 6982869ac5SJames Morse . = ALIGN(SZ_4K); \ 705c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 7182869ac5SJames Morse *(.hibernate_exit.text) \ 725c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 7382869ac5SJames Morse#else 7482869ac5SJames Morse#define HIBERNATE_TEXT 7582869ac5SJames Morse#endif 7682869ac5SJames Morse 77c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 78c7b9adafSWill Deacon#define TRAMP_TEXT \ 79c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 805c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 81c7b9adafSWill Deacon *(.entry.tramp.text) \ 82c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 835c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 84c7b9adafSWill Deacon#else 85c7b9adafSWill Deacon#define TRAMP_TEXT 86c7b9adafSWill Deacon#endif 87c7b9adafSWill Deacon 88a352ea3eSArd Biesheuvel/* 89a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 90348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 91348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 92a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 93a352ea3eSArd Biesheuvel * boundary should be sufficient. 94a352ea3eSArd Biesheuvel */ 95a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 96a352ea3eSArd Biesheuvel 97a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 98a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 99a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 100a352ea3eSArd Biesheuvel#else 101a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 102a352ea3eSArd Biesheuvel#endif 103a352ea3eSArd Biesheuvel 1048c2c3df3SCatalin MarinasSECTIONS 1058c2c3df3SCatalin Marinas{ 1068c2c3df3SCatalin Marinas /* 1078c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 1088c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 1098c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 1108c2c3df3SCatalin Marinas * order of matching. 1118c2c3df3SCatalin Marinas */ 1122883352bSKees Cook DISCARDS 1138c2c3df3SCatalin Marinas /DISCARD/ : { 1141e48ef7fSArd Biesheuvel *(.interp .dynamic) 1153bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 1168c2c3df3SCatalin Marinas } 1178c2c3df3SCatalin Marinas 118120dc60dSArd Biesheuvel . = KIMAGE_VADDR; 1198c2c3df3SCatalin Marinas 1208c2c3df3SCatalin Marinas .head.text : { 1218c2c3df3SCatalin Marinas _text = .; 1228c2c3df3SCatalin Marinas HEAD_TEXT 1238c2c3df3SCatalin Marinas } 1248c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1258c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1268c2c3df3SCatalin Marinas IRQENTRY_TEXT 127be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 128888b3c87SPratyush Anand ENTRY_TEXT 1298c2c3df3SCatalin Marinas TEXT_TEXT 1308c2c3df3SCatalin Marinas SCHED_TEXT 1316727ad9eSChris Metcalf CPUIDLE_TEXT 1328c2c3df3SCatalin Marinas LOCK_TEXT 1332dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1342240bbb6SMarc Zyngier HYPERVISOR_TEXT 1355dfe9d7dSArd Biesheuvel IDMAP_TEXT 13682869ac5SJames Morse HIBERNATE_TEXT 137c7b9adafSWill Deacon TRAMP_TEXT 1388c2c3df3SCatalin Marinas *(.fixup) 1398c2c3df3SCatalin Marinas *(.gnu.warning) 1408c2c3df3SCatalin Marinas . = ALIGN(16); 1418c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1428c2c3df3SCatalin Marinas } 1438c2c3df3SCatalin Marinas 144be288182SKees Cook /* 145be288182SKees Cook * Make sure that the .got.plt is either completely empty or it 146be288182SKees Cook * contains only the lazy dispatch entries. 147be288182SKees Cook */ 148be288182SKees Cook .got.plt : { *(.got.plt) } 149be288182SKees Cook ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 150be288182SKees Cook "Unexpected GOT/PLT entries detected!") 151be288182SKees Cook 15297740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1539fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1549fdc14c5SArd Biesheuvel 15519f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 15619f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1578c2c3df3SCatalin Marinas 1588eb7e28dSJun Yao idmap_pg_dir = .; 1598eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1609d2d75edSGavin Shan idmap_pg_end = .; 1618eb7e28dSJun Yao 1628eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1638eb7e28dSJun Yao tramp_pg_dir = .; 1648eb7e28dSJun Yao . += PAGE_SIZE; 1658eb7e28dSJun Yao#endif 1668eb7e28dSJun Yao 167*833be850SMark Rutland reserved_pg_dir = .; 168*833be850SMark Rutland . += PAGE_SIZE; 169*833be850SMark Rutland 1708eb7e28dSJun Yao swapper_pg_dir = .; 1718eb7e28dSJun Yao . += PAGE_SIZE; 1728eb7e28dSJun Yao 17397740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1748c2c3df3SCatalin Marinas __init_begin = .; 1752ebe088bSArd Biesheuvel __inittext_begin = .; 1768c2c3df3SCatalin Marinas 1778c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 178ca2ef4ffSMark Rutland 179ca2ef4ffSMark Rutland __exittext_begin = .; 1808c2c3df3SCatalin Marinas .exit.text : { 1811eae811dSArd Biesheuvel EXIT_TEXT 1828c2c3df3SCatalin Marinas } 183ca2ef4ffSMark Rutland __exittext_end = .; 184da141706SLaura Abbott 1852ebe088bSArd Biesheuvel . = ALIGN(4); 1862ebe088bSArd Biesheuvel .altinstructions : { 1872ebe088bSArd Biesheuvel __alt_instructions = .; 1882ebe088bSArd Biesheuvel *(.altinstructions) 1892ebe088bSArd Biesheuvel __alt_instructions_end = .; 1902ebe088bSArd Biesheuvel } 1912ebe088bSArd Biesheuvel 19276085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1932ebe088bSArd Biesheuvel __inittext_end = .; 1942ebe088bSArd Biesheuvel __initdata_begin = .; 1952ebe088bSArd Biesheuvel 1968c2c3df3SCatalin Marinas .init.data : { 1978c2c3df3SCatalin Marinas INIT_DATA 1988c2c3df3SCatalin Marinas INIT_SETUP(16) 1998c2c3df3SCatalin Marinas INIT_CALLS 2008c2c3df3SCatalin Marinas CON_INITCALL 2018c2c3df3SCatalin Marinas INIT_RAM_FS 2021ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 2038c2c3df3SCatalin Marinas } 2048c2c3df3SCatalin Marinas .exit.data : { 2051eae811dSArd Biesheuvel EXIT_DATA 2068c2c3df3SCatalin Marinas } 2078c2c3df3SCatalin Marinas 20898fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 20930c95391SDavid Brazdil HYPERVISOR_PERCPU_SECTION 2108c2c3df3SCatalin Marinas 2113bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 2121e48ef7fSArd Biesheuvel *(.rela .rela*) 2131e48ef7fSArd Biesheuvel } 214e039ee4eSAndre Przywara 2153bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 2163bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 2170cd3defeSArd Biesheuvel 2185cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2195cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2205cf896fbSPeter Collingbourne *(.relr.dyn) 2215cf896fbSPeter Collingbourne } 2225cf896fbSPeter Collingbourne 2235cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2245cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2255cf896fbSPeter Collingbourne#endif 2265cf896fbSPeter Collingbourne 22797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2282ebe088bSArd Biesheuvel __initdata_end = .; 2299aa4ec15SMark Rutland __init_end = .; 2309aa4ec15SMark Rutland 2313c620626SMark Salter _data = .; 2328c2c3df3SCatalin Marinas _sdata = .; 233c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 234b6113038SJames Morse 235b6113038SJames Morse /* 236b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 237b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 238b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 239b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 240b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 241b6113038SJames Morse * interfere with adjacent data. 242b6113038SJames Morse */ 243b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 244b6113038SJames Morse __mmuoff_data_start = .; 245b6113038SJames Morse *(.mmuoff.data.write) 246b6113038SJames Morse } 247b6113038SJames Morse . = ALIGN(SZ_2K); 248b6113038SJames Morse .mmuoff.data.read : { 249b6113038SJames Morse *(.mmuoff.data.read) 250b6113038SJames Morse __mmuoff_data_end = .; 251b6113038SJames Morse } 252b6113038SJames Morse 253a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 254cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2558c2c3df3SCatalin Marinas _edata = .; 2568c2c3df3SCatalin Marinas 2578c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 258bd00cd5fSMark Rutland 259bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2602b5548b6SJun Yao init_pg_dir = .; 2612b5548b6SJun Yao . += INIT_DIR_SIZE; 2622b5548b6SJun Yao init_pg_end = .; 2632b5548b6SJun Yao 26476085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 265cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2668c2c3df3SCatalin Marinas _end = .; 2678c2c3df3SCatalin Marinas 2688c2c3df3SCatalin Marinas STABS_DEBUG 269578d7f0fSKees Cook DWARF_DEBUG 270c604abc3SKees Cook ELF_DETAILS 271a2c1d73bSMark Rutland 272a2c1d73bSMark Rutland HEAD_SYMBOLS 273be288182SKees Cook 274be288182SKees Cook /* 275be288182SKees Cook * Sections that should stay zero sized, which is safer to 276be288182SKees Cook * explicitly check instead of blindly discarding. 277be288182SKees Cook */ 278be288182SKees Cook .plt : { 2795f692a81SArd Biesheuvel *(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt) 280be288182SKees Cook } 281be288182SKees Cook ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 282be288182SKees Cook 283be288182SKees Cook .data.rel.ro : { *(.data.rel.ro) } 284be288182SKees Cook ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 2858c2c3df3SCatalin Marinas} 2862240bbb6SMarc Zyngier 28790776dd1SKees Cook#include "image-vars.h" 28890776dd1SKees Cook 2892240bbb6SMarc Zyngier/* 2905dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 29106f75a1fSArd Biesheuvel * and should not cross a page boundary. 2922240bbb6SMarc Zyngier */ 29306f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 29406f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2955dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2965dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 29782869ac5SJames Morse#ifdef CONFIG_HIBERNATION 29882869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 29982869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 30082869ac5SJames Morse#endif 3016c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 3026c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 3036c27c408SWill Deacon "Entry trampoline text too big") 3046c27c408SWill Deacon#endif 305da57a369SMark Rutland/* 306da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 307da57a369SMark Rutland */ 308120dc60dSArd BiesheuvelASSERT(_text == KIMAGE_VADDR, "HEAD is misaligned") 309