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> 12*ce492a16SDavid 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 25e9ee186bSJames Morse#define HYPERVISOR_EXTABLE \ 26e9ee186bSJames Morse . = ALIGN(SZ_8); \ 27e9ee186bSJames Morse __start___kvm_ex_table = .; \ 28e9ee186bSJames Morse *(__kvm_ex_table) \ 29e9ee186bSJames Morse __stop___kvm_ex_table = .; 30e9ee186bSJames Morse 312240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 322240bbb6SMarc Zyngier /* \ 3306f75a1fSArd Biesheuvel * Align to 4 KB so that \ 3406f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 3506f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 3606f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 3706f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3806f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 392240bbb6SMarc Zyngier */ \ 4006f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 415c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 422240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 435c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 445c636aa0SMasahiro Yamada __hyp_text_start = .; \ 452240bbb6SMarc Zyngier *(.hyp.text) \ 46e9ee186bSJames Morse HYPERVISOR_EXTABLE \ 475c636aa0SMasahiro Yamada __hyp_text_end = .; 482240bbb6SMarc Zyngier 495dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 505dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 515c636aa0SMasahiro Yamada __idmap_text_start = .; \ 525dfe9d7dSArd Biesheuvel *(.idmap.text) \ 535c636aa0SMasahiro Yamada __idmap_text_end = .; 545dfe9d7dSArd Biesheuvel 5582869ac5SJames Morse#ifdef CONFIG_HIBERNATION 5682869ac5SJames Morse#define HIBERNATE_TEXT \ 5782869ac5SJames Morse . = ALIGN(SZ_4K); \ 585c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5982869ac5SJames Morse *(.hibernate_exit.text) \ 605c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 6182869ac5SJames Morse#else 6282869ac5SJames Morse#define HIBERNATE_TEXT 6382869ac5SJames Morse#endif 6482869ac5SJames Morse 65c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 66c7b9adafSWill Deacon#define TRAMP_TEXT \ 67c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 685c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 69c7b9adafSWill Deacon *(.entry.tramp.text) \ 70c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 715c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 72c7b9adafSWill Deacon#else 73c7b9adafSWill Deacon#define TRAMP_TEXT 74c7b9adafSWill Deacon#endif 75c7b9adafSWill Deacon 76a352ea3eSArd Biesheuvel/* 77a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 78348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 79348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 80a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 81a352ea3eSArd Biesheuvel * boundary should be sufficient. 82a352ea3eSArd Biesheuvel */ 83a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 84a352ea3eSArd Biesheuvel 85a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 86a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 87a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 88a352ea3eSArd Biesheuvel#else 89a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 90a352ea3eSArd Biesheuvel#endif 91a352ea3eSArd Biesheuvel 928c2c3df3SCatalin MarinasSECTIONS 938c2c3df3SCatalin Marinas{ 948c2c3df3SCatalin Marinas /* 958c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 968c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 978c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 988c2c3df3SCatalin Marinas * order of matching. 998c2c3df3SCatalin Marinas */ 1008c2c3df3SCatalin Marinas /DISCARD/ : { 1018c2c3df3SCatalin Marinas EXIT_CALL 1028c2c3df3SCatalin Marinas *(.discard) 1038c2c3df3SCatalin Marinas *(.discard.*) 1041e48ef7fSArd Biesheuvel *(.interp .dynamic) 1053bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 1063bbd3db8SArd Biesheuvel *(.eh_frame) 1078c2c3df3SCatalin Marinas } 1088c2c3df3SCatalin Marinas 109ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 1108c2c3df3SCatalin Marinas 1118c2c3df3SCatalin Marinas .head.text : { 1128c2c3df3SCatalin Marinas _text = .; 1138c2c3df3SCatalin Marinas HEAD_TEXT 1148c2c3df3SCatalin Marinas } 1158c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1168c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1178c2c3df3SCatalin Marinas IRQENTRY_TEXT 118be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 119888b3c87SPratyush Anand ENTRY_TEXT 1208c2c3df3SCatalin Marinas TEXT_TEXT 1218c2c3df3SCatalin Marinas SCHED_TEXT 1226727ad9eSChris Metcalf CPUIDLE_TEXT 1238c2c3df3SCatalin Marinas LOCK_TEXT 1242dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1252240bbb6SMarc Zyngier HYPERVISOR_TEXT 1265dfe9d7dSArd Biesheuvel IDMAP_TEXT 12782869ac5SJames Morse HIBERNATE_TEXT 128c7b9adafSWill Deacon TRAMP_TEXT 1298c2c3df3SCatalin Marinas *(.fixup) 1308c2c3df3SCatalin Marinas *(.gnu.warning) 1318c2c3df3SCatalin Marinas . = ALIGN(16); 1328c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1338c2c3df3SCatalin Marinas } 1348c2c3df3SCatalin Marinas 13597740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1369fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1379fdc14c5SArd Biesheuvel 13819f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 13919f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1408c2c3df3SCatalin Marinas 1418eb7e28dSJun Yao idmap_pg_dir = .; 1428eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1439d2d75edSGavin Shan idmap_pg_end = .; 1448eb7e28dSJun Yao 1458eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1468eb7e28dSJun Yao tramp_pg_dir = .; 1478eb7e28dSJun Yao . += PAGE_SIZE; 1488eb7e28dSJun Yao#endif 1498eb7e28dSJun Yao 1508eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1518eb7e28dSJun Yao reserved_ttbr0 = .; 1528eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1538eb7e28dSJun Yao#endif 1548eb7e28dSJun Yao swapper_pg_dir = .; 1558eb7e28dSJun Yao . += PAGE_SIZE; 1568eb7e28dSJun Yao swapper_pg_end = .; 1578eb7e28dSJun Yao 15897740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1598c2c3df3SCatalin Marinas __init_begin = .; 1602ebe088bSArd Biesheuvel __inittext_begin = .; 1618c2c3df3SCatalin Marinas 1628c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 163ca2ef4ffSMark Rutland 164ca2ef4ffSMark Rutland __exittext_begin = .; 1658c2c3df3SCatalin Marinas .exit.text : { 1661eae811dSArd Biesheuvel EXIT_TEXT 1678c2c3df3SCatalin Marinas } 168ca2ef4ffSMark Rutland __exittext_end = .; 169da141706SLaura Abbott 1702ebe088bSArd Biesheuvel . = ALIGN(4); 1712ebe088bSArd Biesheuvel .altinstructions : { 1722ebe088bSArd Biesheuvel __alt_instructions = .; 1732ebe088bSArd Biesheuvel *(.altinstructions) 1742ebe088bSArd Biesheuvel __alt_instructions_end = .; 1752ebe088bSArd Biesheuvel } 1762ebe088bSArd Biesheuvel 17776085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1782ebe088bSArd Biesheuvel __inittext_end = .; 1792ebe088bSArd Biesheuvel __initdata_begin = .; 1802ebe088bSArd Biesheuvel 1818c2c3df3SCatalin Marinas .init.data : { 1828c2c3df3SCatalin Marinas INIT_DATA 1838c2c3df3SCatalin Marinas INIT_SETUP(16) 1848c2c3df3SCatalin Marinas INIT_CALLS 1858c2c3df3SCatalin Marinas CON_INITCALL 1868c2c3df3SCatalin Marinas INIT_RAM_FS 1871ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1888c2c3df3SCatalin Marinas } 1898c2c3df3SCatalin Marinas .exit.data : { 1901eae811dSArd Biesheuvel EXIT_DATA 1918c2c3df3SCatalin Marinas } 1928c2c3df3SCatalin Marinas 19398fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1948c2c3df3SCatalin Marinas 1953bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 1961e48ef7fSArd Biesheuvel *(.rela .rela*) 1971e48ef7fSArd Biesheuvel } 198e039ee4eSAndre Przywara 1993bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 2003bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 2010cd3defeSArd Biesheuvel 2025cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2035cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2045cf896fbSPeter Collingbourne *(.relr.dyn) 2055cf896fbSPeter Collingbourne } 2065cf896fbSPeter Collingbourne 2075cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2085cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2095cf896fbSPeter Collingbourne#endif 2105cf896fbSPeter Collingbourne 21197740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2122ebe088bSArd Biesheuvel __initdata_end = .; 2139aa4ec15SMark Rutland __init_end = .; 2149aa4ec15SMark Rutland 2153c620626SMark Salter _data = .; 2168c2c3df3SCatalin Marinas _sdata = .; 217c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 218b6113038SJames Morse 219b6113038SJames Morse /* 220b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 221b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 222b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 223b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 224b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 225b6113038SJames Morse * interfere with adjacent data. 226b6113038SJames Morse */ 227b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 228b6113038SJames Morse __mmuoff_data_start = .; 229b6113038SJames Morse *(.mmuoff.data.write) 230b6113038SJames Morse } 231b6113038SJames Morse . = ALIGN(SZ_2K); 232b6113038SJames Morse .mmuoff.data.read : { 233b6113038SJames Morse *(.mmuoff.data.read) 234b6113038SJames Morse __mmuoff_data_end = .; 235b6113038SJames Morse } 236b6113038SJames Morse 237a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 238cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2398c2c3df3SCatalin Marinas _edata = .; 2408c2c3df3SCatalin Marinas 2418c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 242bd00cd5fSMark Rutland 243bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2442b5548b6SJun Yao init_pg_dir = .; 2452b5548b6SJun Yao . += INIT_DIR_SIZE; 2462b5548b6SJun Yao init_pg_end = .; 2472b5548b6SJun Yao 24876085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 249cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2508c2c3df3SCatalin Marinas _end = .; 2518c2c3df3SCatalin Marinas 2528c2c3df3SCatalin Marinas STABS_DEBUG 253a2c1d73bSMark Rutland 254a2c1d73bSMark Rutland HEAD_SYMBOLS 2558c2c3df3SCatalin Marinas} 2562240bbb6SMarc Zyngier 25790776dd1SKees Cook#include "image-vars.h" 25890776dd1SKees Cook 2592240bbb6SMarc Zyngier/* 2605dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 26106f75a1fSArd Biesheuvel * and should not cross a page boundary. 2622240bbb6SMarc Zyngier */ 26306f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 26406f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2655dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2665dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 26782869ac5SJames Morse#ifdef CONFIG_HIBERNATION 26882869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 26982869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 27082869ac5SJames Morse#endif 2716c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2726c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2736c27c408SWill Deacon "Entry trampoline text too big") 2746c27c408SWill Deacon#endif 275da57a369SMark Rutland/* 276da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 277da57a369SMark Rutland */ 278ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 279