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 919f6bc32SKees Cook 108c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h> 1198fb7548SArd Biesheuvel#include <asm/cache.h> 12ce492a16SDavid Brazdil#include <asm/hyp_image.h> 1387d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h> 148c2c3df3SCatalin Marinas#include <asm/memory.h> 158c2c3df3SCatalin Marinas#include <asm/page.h> 168c2c3df3SCatalin Marinas 17a2c1d73bSMark Rutland#include "image.h" 18a2c1d73bSMark Rutland 198c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64) 20af885f40SGeoff LevandENTRY(_text) 218c2c3df3SCatalin Marinas 228c2c3df3SCatalin Marinasjiffies = jiffies_64; 238c2c3df3SCatalin Marinas 24e9ee186bSJames Morse 25*3471ee06SDavid Brazdil#ifdef CONFIG_KVM 26e9ee186bSJames Morse#define HYPERVISOR_EXTABLE \ 27e9ee186bSJames Morse . = ALIGN(SZ_8); \ 28e9ee186bSJames Morse __start___kvm_ex_table = .; \ 29e9ee186bSJames Morse *(__kvm_ex_table) \ 30e9ee186bSJames Morse __stop___kvm_ex_table = .; 31*3471ee06SDavid Brazdil#else /* CONFIG_KVM */ 32*3471ee06SDavid Brazdil#define HYPERVISOR_EXTABLE 33*3471ee06SDavid Brazdil#endif 34e9ee186bSJames Morse 352240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 362240bbb6SMarc Zyngier /* \ 3706f75a1fSArd Biesheuvel * Align to 4 KB so that \ 3806f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 3906f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 4006f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 4106f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 4206f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 432240bbb6SMarc Zyngier */ \ 4406f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 455c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 462240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 475c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 485c636aa0SMasahiro Yamada __hyp_text_start = .; \ 492240bbb6SMarc Zyngier *(.hyp.text) \ 50e9ee186bSJames Morse HYPERVISOR_EXTABLE \ 515c636aa0SMasahiro Yamada __hyp_text_end = .; 522240bbb6SMarc Zyngier 535dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 545dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 555c636aa0SMasahiro Yamada __idmap_text_start = .; \ 565dfe9d7dSArd Biesheuvel *(.idmap.text) \ 575c636aa0SMasahiro Yamada __idmap_text_end = .; 585dfe9d7dSArd Biesheuvel 5982869ac5SJames Morse#ifdef CONFIG_HIBERNATION 6082869ac5SJames Morse#define HIBERNATE_TEXT \ 6182869ac5SJames Morse . = ALIGN(SZ_4K); \ 625c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 6382869ac5SJames Morse *(.hibernate_exit.text) \ 645c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 6582869ac5SJames Morse#else 6682869ac5SJames Morse#define HIBERNATE_TEXT 6782869ac5SJames Morse#endif 6882869ac5SJames Morse 69c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 70c7b9adafSWill Deacon#define TRAMP_TEXT \ 71c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 725c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 73c7b9adafSWill Deacon *(.entry.tramp.text) \ 74c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 755c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 76c7b9adafSWill Deacon#else 77c7b9adafSWill Deacon#define TRAMP_TEXT 78c7b9adafSWill Deacon#endif 79c7b9adafSWill Deacon 80a352ea3eSArd Biesheuvel/* 81a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 82348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 83348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 84a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 85a352ea3eSArd Biesheuvel * boundary should be sufficient. 86a352ea3eSArd Biesheuvel */ 87a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 88a352ea3eSArd Biesheuvel 89a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 90a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 91a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 92a352ea3eSArd Biesheuvel#else 93a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 94a352ea3eSArd Biesheuvel#endif 95a352ea3eSArd Biesheuvel 968c2c3df3SCatalin MarinasSECTIONS 978c2c3df3SCatalin Marinas{ 988c2c3df3SCatalin Marinas /* 998c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 1008c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 1018c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 1028c2c3df3SCatalin Marinas * order of matching. 1038c2c3df3SCatalin Marinas */ 1048c2c3df3SCatalin Marinas /DISCARD/ : { 1058c2c3df3SCatalin Marinas EXIT_CALL 1068c2c3df3SCatalin Marinas *(.discard) 1078c2c3df3SCatalin Marinas *(.discard.*) 1081e48ef7fSArd Biesheuvel *(.interp .dynamic) 1093bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 1103bbd3db8SArd Biesheuvel *(.eh_frame) 1118c2c3df3SCatalin Marinas } 1128c2c3df3SCatalin Marinas 113ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 1148c2c3df3SCatalin Marinas 1158c2c3df3SCatalin Marinas .head.text : { 1168c2c3df3SCatalin Marinas _text = .; 1178c2c3df3SCatalin Marinas HEAD_TEXT 1188c2c3df3SCatalin Marinas } 1198c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1208c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1218c2c3df3SCatalin Marinas IRQENTRY_TEXT 122be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 123888b3c87SPratyush Anand ENTRY_TEXT 1248c2c3df3SCatalin Marinas TEXT_TEXT 1258c2c3df3SCatalin Marinas SCHED_TEXT 1266727ad9eSChris Metcalf CPUIDLE_TEXT 1278c2c3df3SCatalin Marinas LOCK_TEXT 1282dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1292240bbb6SMarc Zyngier HYPERVISOR_TEXT 1305dfe9d7dSArd Biesheuvel IDMAP_TEXT 13182869ac5SJames Morse HIBERNATE_TEXT 132c7b9adafSWill Deacon TRAMP_TEXT 1338c2c3df3SCatalin Marinas *(.fixup) 1348c2c3df3SCatalin Marinas *(.gnu.warning) 1358c2c3df3SCatalin Marinas . = ALIGN(16); 1368c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1378c2c3df3SCatalin Marinas } 1388c2c3df3SCatalin Marinas 13997740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1409fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1419fdc14c5SArd Biesheuvel 14219f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 14319f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1448c2c3df3SCatalin Marinas 1458eb7e28dSJun Yao idmap_pg_dir = .; 1468eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1479d2d75edSGavin Shan idmap_pg_end = .; 1488eb7e28dSJun Yao 1498eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1508eb7e28dSJun Yao tramp_pg_dir = .; 1518eb7e28dSJun Yao . += PAGE_SIZE; 1528eb7e28dSJun Yao#endif 1538eb7e28dSJun Yao 1548eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1558eb7e28dSJun Yao reserved_ttbr0 = .; 1568eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1578eb7e28dSJun Yao#endif 1588eb7e28dSJun Yao swapper_pg_dir = .; 1598eb7e28dSJun Yao . += PAGE_SIZE; 1608eb7e28dSJun Yao swapper_pg_end = .; 1618eb7e28dSJun Yao 16297740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1638c2c3df3SCatalin Marinas __init_begin = .; 1642ebe088bSArd Biesheuvel __inittext_begin = .; 1658c2c3df3SCatalin Marinas 1668c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 167ca2ef4ffSMark Rutland 168ca2ef4ffSMark Rutland __exittext_begin = .; 1698c2c3df3SCatalin Marinas .exit.text : { 1701eae811dSArd Biesheuvel EXIT_TEXT 1718c2c3df3SCatalin Marinas } 172ca2ef4ffSMark Rutland __exittext_end = .; 173da141706SLaura Abbott 1742ebe088bSArd Biesheuvel . = ALIGN(4); 1752ebe088bSArd Biesheuvel .altinstructions : { 1762ebe088bSArd Biesheuvel __alt_instructions = .; 1772ebe088bSArd Biesheuvel *(.altinstructions) 1782ebe088bSArd Biesheuvel __alt_instructions_end = .; 1792ebe088bSArd Biesheuvel } 1802ebe088bSArd Biesheuvel 18176085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1822ebe088bSArd Biesheuvel __inittext_end = .; 1832ebe088bSArd Biesheuvel __initdata_begin = .; 1842ebe088bSArd Biesheuvel 1858c2c3df3SCatalin Marinas .init.data : { 1868c2c3df3SCatalin Marinas INIT_DATA 1878c2c3df3SCatalin Marinas INIT_SETUP(16) 1888c2c3df3SCatalin Marinas INIT_CALLS 1898c2c3df3SCatalin Marinas CON_INITCALL 1908c2c3df3SCatalin Marinas INIT_RAM_FS 1911ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1928c2c3df3SCatalin Marinas } 1938c2c3df3SCatalin Marinas .exit.data : { 1941eae811dSArd Biesheuvel EXIT_DATA 1958c2c3df3SCatalin Marinas } 1968c2c3df3SCatalin Marinas 19798fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1988c2c3df3SCatalin Marinas 1993bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 2001e48ef7fSArd Biesheuvel *(.rela .rela*) 2011e48ef7fSArd Biesheuvel } 202e039ee4eSAndre Przywara 2033bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 2043bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 2050cd3defeSArd Biesheuvel 2065cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2075cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2085cf896fbSPeter Collingbourne *(.relr.dyn) 2095cf896fbSPeter Collingbourne } 2105cf896fbSPeter Collingbourne 2115cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2125cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2135cf896fbSPeter Collingbourne#endif 2145cf896fbSPeter Collingbourne 21597740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2162ebe088bSArd Biesheuvel __initdata_end = .; 2179aa4ec15SMark Rutland __init_end = .; 2189aa4ec15SMark Rutland 2193c620626SMark Salter _data = .; 2208c2c3df3SCatalin Marinas _sdata = .; 221c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 222b6113038SJames Morse 223b6113038SJames Morse /* 224b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 225b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 226b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 227b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 228b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 229b6113038SJames Morse * interfere with adjacent data. 230b6113038SJames Morse */ 231b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 232b6113038SJames Morse __mmuoff_data_start = .; 233b6113038SJames Morse *(.mmuoff.data.write) 234b6113038SJames Morse } 235b6113038SJames Morse . = ALIGN(SZ_2K); 236b6113038SJames Morse .mmuoff.data.read : { 237b6113038SJames Morse *(.mmuoff.data.read) 238b6113038SJames Morse __mmuoff_data_end = .; 239b6113038SJames Morse } 240b6113038SJames Morse 241a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 242cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2438c2c3df3SCatalin Marinas _edata = .; 2448c2c3df3SCatalin Marinas 2458c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 246bd00cd5fSMark Rutland 247bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2482b5548b6SJun Yao init_pg_dir = .; 2492b5548b6SJun Yao . += INIT_DIR_SIZE; 2502b5548b6SJun Yao init_pg_end = .; 2512b5548b6SJun Yao 25276085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 253cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2548c2c3df3SCatalin Marinas _end = .; 2558c2c3df3SCatalin Marinas 2568c2c3df3SCatalin Marinas STABS_DEBUG 257a2c1d73bSMark Rutland 258a2c1d73bSMark Rutland HEAD_SYMBOLS 2598c2c3df3SCatalin Marinas} 2602240bbb6SMarc Zyngier 26190776dd1SKees Cook#include "image-vars.h" 26290776dd1SKees Cook 2632240bbb6SMarc Zyngier/* 2645dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 26506f75a1fSArd Biesheuvel * and should not cross a page boundary. 2662240bbb6SMarc Zyngier */ 26706f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 26806f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2695dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2705dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 27182869ac5SJames Morse#ifdef CONFIG_HIBERNATION 27282869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 27382869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 27482869ac5SJames Morse#endif 2756c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2766c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2776c27c408SWill Deacon "Entry trampoline text too big") 2786c27c408SWill Deacon#endif 279da57a369SMark Rutland/* 280da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 281da57a369SMark Rutland */ 282ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 283