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/memory.h> 148c2c3df3SCatalin Marinas#include <asm/page.h> 158c2c3df3SCatalin Marinas 16a2c1d73bSMark Rutland#include "image.h" 17a2c1d73bSMark Rutland 188c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64) 19af885f40SGeoff LevandENTRY(_text) 208c2c3df3SCatalin Marinas 218c2c3df3SCatalin Marinasjiffies = jiffies_64; 228c2c3df3SCatalin Marinas 232240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 242240bbb6SMarc Zyngier /* \ 2506f75a1fSArd Biesheuvel * Align to 4 KB so that \ 2606f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 2706f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 2806f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 2906f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3006f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 312240bbb6SMarc Zyngier */ \ 3206f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 335c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 342240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 355c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 365c636aa0SMasahiro Yamada __hyp_text_start = .; \ 372240bbb6SMarc Zyngier *(.hyp.text) \ 385c636aa0SMasahiro Yamada __hyp_text_end = .; 392240bbb6SMarc Zyngier 405dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 415dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 425c636aa0SMasahiro Yamada __idmap_text_start = .; \ 435dfe9d7dSArd Biesheuvel *(.idmap.text) \ 445c636aa0SMasahiro Yamada __idmap_text_end = .; 455dfe9d7dSArd Biesheuvel 4682869ac5SJames Morse#ifdef CONFIG_HIBERNATION 4782869ac5SJames Morse#define HIBERNATE_TEXT \ 4882869ac5SJames Morse . = ALIGN(SZ_4K); \ 495c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5082869ac5SJames Morse *(.hibernate_exit.text) \ 515c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 5282869ac5SJames Morse#else 5382869ac5SJames Morse#define HIBERNATE_TEXT 5482869ac5SJames Morse#endif 5582869ac5SJames Morse 56c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 57c7b9adafSWill Deacon#define TRAMP_TEXT \ 58c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 595c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 60c7b9adafSWill Deacon *(.entry.tramp.text) \ 61c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 625c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 63c7b9adafSWill Deacon#else 64c7b9adafSWill Deacon#define TRAMP_TEXT 65c7b9adafSWill Deacon#endif 66c7b9adafSWill Deacon 67a352ea3eSArd Biesheuvel/* 68a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 69348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 70348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 71a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 72a352ea3eSArd Biesheuvel * boundary should be sufficient. 73a352ea3eSArd Biesheuvel */ 74a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 75a352ea3eSArd Biesheuvel 76a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 77a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 78a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 79a352ea3eSArd Biesheuvel#else 80a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 81a352ea3eSArd Biesheuvel#endif 82a352ea3eSArd Biesheuvel 838c2c3df3SCatalin MarinasSECTIONS 848c2c3df3SCatalin Marinas{ 858c2c3df3SCatalin Marinas /* 868c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 878c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 888c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 898c2c3df3SCatalin Marinas * order of matching. 908c2c3df3SCatalin Marinas */ 918c2c3df3SCatalin Marinas /DISCARD/ : { 928c2c3df3SCatalin Marinas EXIT_CALL 938c2c3df3SCatalin Marinas *(.discard) 948c2c3df3SCatalin Marinas *(.discard.*) 951e48ef7fSArd Biesheuvel *(.interp .dynamic) 963bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 973bbd3db8SArd Biesheuvel *(.eh_frame) 988c2c3df3SCatalin Marinas } 998c2c3df3SCatalin Marinas 100ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 1018c2c3df3SCatalin Marinas 1028c2c3df3SCatalin Marinas .head.text : { 1038c2c3df3SCatalin Marinas _text = .; 1048c2c3df3SCatalin Marinas HEAD_TEXT 1058c2c3df3SCatalin Marinas } 1068c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1078c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1088c2c3df3SCatalin Marinas IRQENTRY_TEXT 109be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 110888b3c87SPratyush Anand ENTRY_TEXT 1118c2c3df3SCatalin Marinas TEXT_TEXT 1128c2c3df3SCatalin Marinas SCHED_TEXT 1136727ad9eSChris Metcalf CPUIDLE_TEXT 1148c2c3df3SCatalin Marinas LOCK_TEXT 1152dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1162240bbb6SMarc Zyngier HYPERVISOR_TEXT 1175dfe9d7dSArd Biesheuvel IDMAP_TEXT 11882869ac5SJames Morse HIBERNATE_TEXT 119c7b9adafSWill Deacon TRAMP_TEXT 1208c2c3df3SCatalin Marinas *(.fixup) 1218c2c3df3SCatalin Marinas *(.gnu.warning) 1228c2c3df3SCatalin Marinas . = ALIGN(16); 1238c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1248c2c3df3SCatalin Marinas } 1258c2c3df3SCatalin Marinas 12697740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1279fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1289fdc14c5SArd Biesheuvel 12919f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 13019f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1318c2c3df3SCatalin Marinas 1328eb7e28dSJun Yao idmap_pg_dir = .; 1338eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1349d2d75edSGavin Shan idmap_pg_end = .; 1358eb7e28dSJun Yao 1368eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1378eb7e28dSJun Yao tramp_pg_dir = .; 1388eb7e28dSJun Yao . += PAGE_SIZE; 1398eb7e28dSJun Yao#endif 1408eb7e28dSJun Yao 1418eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1428eb7e28dSJun Yao reserved_ttbr0 = .; 1438eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1448eb7e28dSJun Yao#endif 1458eb7e28dSJun Yao swapper_pg_dir = .; 1468eb7e28dSJun Yao . += PAGE_SIZE; 1478eb7e28dSJun Yao swapper_pg_end = .; 1488eb7e28dSJun Yao 14997740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1508c2c3df3SCatalin Marinas __init_begin = .; 1512ebe088bSArd Biesheuvel __inittext_begin = .; 1528c2c3df3SCatalin Marinas 1538c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 154ca2ef4ffSMark Rutland 155ca2ef4ffSMark Rutland __exittext_begin = .; 1568c2c3df3SCatalin Marinas .exit.text : { 1571eae811dSArd Biesheuvel EXIT_TEXT 1588c2c3df3SCatalin Marinas } 159ca2ef4ffSMark Rutland __exittext_end = .; 160da141706SLaura Abbott 1612ebe088bSArd Biesheuvel . = ALIGN(4); 1622ebe088bSArd Biesheuvel .altinstructions : { 1632ebe088bSArd Biesheuvel __alt_instructions = .; 1642ebe088bSArd Biesheuvel *(.altinstructions) 1652ebe088bSArd Biesheuvel __alt_instructions_end = .; 1662ebe088bSArd Biesheuvel } 1672ebe088bSArd Biesheuvel 16876085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1692ebe088bSArd Biesheuvel __inittext_end = .; 1702ebe088bSArd Biesheuvel __initdata_begin = .; 1712ebe088bSArd Biesheuvel 1728c2c3df3SCatalin Marinas .init.data : { 1738c2c3df3SCatalin Marinas INIT_DATA 1748c2c3df3SCatalin Marinas INIT_SETUP(16) 1758c2c3df3SCatalin Marinas INIT_CALLS 1768c2c3df3SCatalin Marinas CON_INITCALL 1778c2c3df3SCatalin Marinas INIT_RAM_FS 1781ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1798c2c3df3SCatalin Marinas } 1808c2c3df3SCatalin Marinas .exit.data : { 1811eae811dSArd Biesheuvel EXIT_DATA 1828c2c3df3SCatalin Marinas } 1838c2c3df3SCatalin Marinas 18498fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1858c2c3df3SCatalin Marinas 1863bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 1871e48ef7fSArd Biesheuvel *(.rela .rela*) 1881e48ef7fSArd Biesheuvel } 189e039ee4eSAndre Przywara 1903bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 1913bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 1920cd3defeSArd Biesheuvel 1935cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 1945cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 1955cf896fbSPeter Collingbourne *(.relr.dyn) 1965cf896fbSPeter Collingbourne } 1975cf896fbSPeter Collingbourne 1985cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 1995cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2005cf896fbSPeter Collingbourne#endif 2015cf896fbSPeter Collingbourne 20297740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2032ebe088bSArd Biesheuvel __initdata_end = .; 2049aa4ec15SMark Rutland __init_end = .; 2059aa4ec15SMark Rutland 2063c620626SMark Salter _data = .; 2078c2c3df3SCatalin Marinas _sdata = .; 208c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 209b6113038SJames Morse 210b6113038SJames Morse /* 211b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 212b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 213b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 214b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 215b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 216b6113038SJames Morse * interfere with adjacent data. 217b6113038SJames Morse */ 218b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 219b6113038SJames Morse __mmuoff_data_start = .; 220b6113038SJames Morse *(.mmuoff.data.write) 221b6113038SJames Morse } 222b6113038SJames Morse . = ALIGN(SZ_2K); 223b6113038SJames Morse .mmuoff.data.read : { 224b6113038SJames Morse *(.mmuoff.data.read) 225b6113038SJames Morse __mmuoff_data_end = .; 226b6113038SJames Morse } 227b6113038SJames Morse 228a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 229cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2308c2c3df3SCatalin Marinas _edata = .; 2318c2c3df3SCatalin Marinas 2328c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 233bd00cd5fSMark Rutland 234bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2352b5548b6SJun Yao init_pg_dir = .; 2362b5548b6SJun Yao . += INIT_DIR_SIZE; 2372b5548b6SJun Yao init_pg_end = .; 2382b5548b6SJun Yao 23976085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 240cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2418c2c3df3SCatalin Marinas _end = .; 2428c2c3df3SCatalin Marinas 2438c2c3df3SCatalin Marinas STABS_DEBUG 244*c604abc3SKees Cook ELF_DETAILS 245a2c1d73bSMark Rutland 246a2c1d73bSMark Rutland HEAD_SYMBOLS 2478c2c3df3SCatalin Marinas} 2482240bbb6SMarc Zyngier 24990776dd1SKees Cook#include "image-vars.h" 25090776dd1SKees Cook 2512240bbb6SMarc Zyngier/* 2525dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 25306f75a1fSArd Biesheuvel * and should not cross a page boundary. 2542240bbb6SMarc Zyngier */ 25506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 25606f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2575dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2585dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 25982869ac5SJames Morse#ifdef CONFIG_HIBERNATION 26082869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 26182869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 26282869ac5SJames Morse#endif 2636c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2646c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2656c27c408SWill Deacon "Entry trampoline text too big") 2666c27c408SWill Deacon#endif 267da57a369SMark Rutland/* 268da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 269da57a369SMark Rutland */ 270ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 271