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> 1287d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h> 138c2c3df3SCatalin Marinas#include <asm/thread_info.h> 148c2c3df3SCatalin Marinas#include <asm/memory.h> 158c2c3df3SCatalin Marinas#include <asm/page.h> 16da141706SLaura Abbott#include <asm/pgtable.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 252240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 262240bbb6SMarc Zyngier /* \ 2706f75a1fSArd Biesheuvel * Align to 4 KB so that \ 2806f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 2906f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 3006f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 3106f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3206f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 332240bbb6SMarc Zyngier */ \ 3406f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 355c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 362240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 375c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 385c636aa0SMasahiro Yamada __hyp_text_start = .; \ 392240bbb6SMarc Zyngier *(.hyp.text) \ 405c636aa0SMasahiro Yamada __hyp_text_end = .; 412240bbb6SMarc Zyngier 425dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 435dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 445c636aa0SMasahiro Yamada __idmap_text_start = .; \ 455dfe9d7dSArd Biesheuvel *(.idmap.text) \ 465c636aa0SMasahiro Yamada __idmap_text_end = .; 475dfe9d7dSArd Biesheuvel 4882869ac5SJames Morse#ifdef CONFIG_HIBERNATION 4982869ac5SJames Morse#define HIBERNATE_TEXT \ 5082869ac5SJames Morse . = ALIGN(SZ_4K); \ 515c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5282869ac5SJames Morse *(.hibernate_exit.text) \ 535c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 5482869ac5SJames Morse#else 5582869ac5SJames Morse#define HIBERNATE_TEXT 5682869ac5SJames Morse#endif 5782869ac5SJames Morse 58c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 59c7b9adafSWill Deacon#define TRAMP_TEXT \ 60c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 615c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 62c7b9adafSWill Deacon *(.entry.tramp.text) \ 63c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 645c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 65c7b9adafSWill Deacon#else 66c7b9adafSWill Deacon#define TRAMP_TEXT 67c7b9adafSWill Deacon#endif 68c7b9adafSWill Deacon 69a352ea3eSArd Biesheuvel/* 70a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 71348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 72348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 73a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 74a352ea3eSArd Biesheuvel * boundary should be sufficient. 75a352ea3eSArd Biesheuvel */ 76a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 77a352ea3eSArd Biesheuvel 78a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 79a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 80a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 81a352ea3eSArd Biesheuvel#else 82a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 83a352ea3eSArd Biesheuvel#endif 84a352ea3eSArd Biesheuvel 858c2c3df3SCatalin MarinasSECTIONS 868c2c3df3SCatalin Marinas{ 878c2c3df3SCatalin Marinas /* 888c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 898c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 908c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 918c2c3df3SCatalin Marinas * order of matching. 928c2c3df3SCatalin Marinas */ 938c2c3df3SCatalin Marinas /DISCARD/ : { 948c2c3df3SCatalin Marinas EXIT_CALL 958c2c3df3SCatalin Marinas *(.discard) 968c2c3df3SCatalin Marinas *(.discard.*) 971e48ef7fSArd Biesheuvel *(.interp .dynamic) 983bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 993bbd3db8SArd Biesheuvel *(.eh_frame) 1008c2c3df3SCatalin Marinas } 1018c2c3df3SCatalin Marinas 102ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 1038c2c3df3SCatalin Marinas 1048c2c3df3SCatalin Marinas .head.text : { 1058c2c3df3SCatalin Marinas _text = .; 1068c2c3df3SCatalin Marinas HEAD_TEXT 1078c2c3df3SCatalin Marinas } 1088c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1098c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1108c2c3df3SCatalin Marinas IRQENTRY_TEXT 111be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 112888b3c87SPratyush Anand ENTRY_TEXT 1138c2c3df3SCatalin Marinas TEXT_TEXT 1148c2c3df3SCatalin Marinas SCHED_TEXT 1156727ad9eSChris Metcalf CPUIDLE_TEXT 1168c2c3df3SCatalin Marinas LOCK_TEXT 1172dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1182240bbb6SMarc Zyngier HYPERVISOR_TEXT 1195dfe9d7dSArd Biesheuvel IDMAP_TEXT 12082869ac5SJames Morse HIBERNATE_TEXT 121c7b9adafSWill Deacon TRAMP_TEXT 1228c2c3df3SCatalin Marinas *(.fixup) 1238c2c3df3SCatalin Marinas *(.gnu.warning) 1248c2c3df3SCatalin Marinas . = ALIGN(16); 1258c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1268c2c3df3SCatalin Marinas } 1278c2c3df3SCatalin Marinas 12897740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1299fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1309fdc14c5SArd Biesheuvel 13119f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 13219f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1338c2c3df3SCatalin Marinas 1348eb7e28dSJun Yao idmap_pg_dir = .; 1358eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 136*9d2d75edSGavin Shan idmap_pg_end = .; 1378eb7e28dSJun Yao 1388eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1398eb7e28dSJun Yao tramp_pg_dir = .; 1408eb7e28dSJun Yao . += PAGE_SIZE; 1418eb7e28dSJun Yao#endif 1428eb7e28dSJun Yao 1438eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1448eb7e28dSJun Yao reserved_ttbr0 = .; 1458eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1468eb7e28dSJun Yao#endif 1478eb7e28dSJun Yao swapper_pg_dir = .; 1488eb7e28dSJun Yao . += PAGE_SIZE; 1498eb7e28dSJun Yao swapper_pg_end = .; 1508eb7e28dSJun Yao 15197740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1528c2c3df3SCatalin Marinas __init_begin = .; 1532ebe088bSArd Biesheuvel __inittext_begin = .; 1548c2c3df3SCatalin Marinas 1558c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 156ca2ef4ffSMark Rutland 157ca2ef4ffSMark Rutland __exittext_begin = .; 1588c2c3df3SCatalin Marinas .exit.text : { 1591eae811dSArd Biesheuvel EXIT_TEXT 1608c2c3df3SCatalin Marinas } 161ca2ef4ffSMark Rutland __exittext_end = .; 162da141706SLaura Abbott 1632ebe088bSArd Biesheuvel . = ALIGN(4); 1642ebe088bSArd Biesheuvel .altinstructions : { 1652ebe088bSArd Biesheuvel __alt_instructions = .; 1662ebe088bSArd Biesheuvel *(.altinstructions) 1672ebe088bSArd Biesheuvel __alt_instructions_end = .; 1682ebe088bSArd Biesheuvel } 1692ebe088bSArd Biesheuvel .altinstr_replacement : { 1702ebe088bSArd Biesheuvel *(.altinstr_replacement) 1712ebe088bSArd Biesheuvel } 1722ebe088bSArd Biesheuvel 1732ebe088bSArd Biesheuvel . = ALIGN(PAGE_SIZE); 1742ebe088bSArd Biesheuvel __inittext_end = .; 1752ebe088bSArd Biesheuvel __initdata_begin = .; 1762ebe088bSArd Biesheuvel 1778c2c3df3SCatalin Marinas .init.data : { 1788c2c3df3SCatalin Marinas INIT_DATA 1798c2c3df3SCatalin Marinas INIT_SETUP(16) 1808c2c3df3SCatalin Marinas INIT_CALLS 1818c2c3df3SCatalin Marinas CON_INITCALL 1828c2c3df3SCatalin Marinas INIT_RAM_FS 1831ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1848c2c3df3SCatalin Marinas } 1858c2c3df3SCatalin Marinas .exit.data : { 1861eae811dSArd Biesheuvel EXIT_DATA 1878c2c3df3SCatalin Marinas } 1888c2c3df3SCatalin Marinas 18998fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1908c2c3df3SCatalin Marinas 1913bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 1921e48ef7fSArd Biesheuvel *(.rela .rela*) 1931e48ef7fSArd Biesheuvel } 194e039ee4eSAndre Przywara 1953bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 1963bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 1970cd3defeSArd Biesheuvel 1985cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 1995cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2005cf896fbSPeter Collingbourne *(.relr.dyn) 2015cf896fbSPeter Collingbourne } 2025cf896fbSPeter Collingbourne 2035cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2045cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2055cf896fbSPeter Collingbourne#endif 2065cf896fbSPeter Collingbourne 20797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2082ebe088bSArd Biesheuvel __initdata_end = .; 2099aa4ec15SMark Rutland __init_end = .; 2109aa4ec15SMark Rutland 2113c620626SMark Salter _data = .; 2128c2c3df3SCatalin Marinas _sdata = .; 213c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 214b6113038SJames Morse 215b6113038SJames Morse /* 216b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 217b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 218b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 219b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 220b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 221b6113038SJames Morse * interfere with adjacent data. 222b6113038SJames Morse */ 223b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 224b6113038SJames Morse __mmuoff_data_start = .; 225b6113038SJames Morse *(.mmuoff.data.write) 226b6113038SJames Morse } 227b6113038SJames Morse . = ALIGN(SZ_2K); 228b6113038SJames Morse .mmuoff.data.read : { 229b6113038SJames Morse *(.mmuoff.data.read) 230b6113038SJames Morse __mmuoff_data_end = .; 231b6113038SJames Morse } 232b6113038SJames Morse 233a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 234cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2358c2c3df3SCatalin Marinas _edata = .; 2368c2c3df3SCatalin Marinas 2378c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 238bd00cd5fSMark Rutland 239bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2402b5548b6SJun Yao init_pg_dir = .; 2412b5548b6SJun Yao . += INIT_DIR_SIZE; 2422b5548b6SJun Yao init_pg_end = .; 2432b5548b6SJun Yao 244cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2458c2c3df3SCatalin Marinas _end = .; 2468c2c3df3SCatalin Marinas 2478c2c3df3SCatalin Marinas STABS_DEBUG 248a2c1d73bSMark Rutland 249a2c1d73bSMark Rutland HEAD_SYMBOLS 2508c2c3df3SCatalin Marinas} 2512240bbb6SMarc Zyngier 25290776dd1SKees Cook#include "image-vars.h" 25390776dd1SKees Cook 2542240bbb6SMarc Zyngier/* 2555dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 25606f75a1fSArd Biesheuvel * and should not cross a page boundary. 2572240bbb6SMarc Zyngier */ 25806f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 25906f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2605dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2615dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 26282869ac5SJames Morse#ifdef CONFIG_HIBERNATION 26382869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 26482869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 26582869ac5SJames Morse#endif 2666c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2676c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2686c27c408SWill Deacon "Entry trampoline text too big") 2696c27c408SWill Deacon#endif 270da57a369SMark Rutland/* 271da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 272da57a369SMark Rutland */ 273ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 274