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> 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 242240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 252240bbb6SMarc Zyngier /* \ 2606f75a1fSArd Biesheuvel * Align to 4 KB so that \ 2706f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 2806f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 2906f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 3006f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3106f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 322240bbb6SMarc Zyngier */ \ 3306f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 345c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 352240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 365c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 375c636aa0SMasahiro Yamada __hyp_text_start = .; \ 382240bbb6SMarc Zyngier *(.hyp.text) \ 395c636aa0SMasahiro Yamada __hyp_text_end = .; 402240bbb6SMarc Zyngier 415dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 425dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 435c636aa0SMasahiro Yamada __idmap_text_start = .; \ 445dfe9d7dSArd Biesheuvel *(.idmap.text) \ 455c636aa0SMasahiro Yamada __idmap_text_end = .; 465dfe9d7dSArd Biesheuvel 4782869ac5SJames Morse#ifdef CONFIG_HIBERNATION 4882869ac5SJames Morse#define HIBERNATE_TEXT \ 4982869ac5SJames Morse . = ALIGN(SZ_4K); \ 505c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5182869ac5SJames Morse *(.hibernate_exit.text) \ 525c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 5382869ac5SJames Morse#else 5482869ac5SJames Morse#define HIBERNATE_TEXT 5582869ac5SJames Morse#endif 5682869ac5SJames Morse 57c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 58c7b9adafSWill Deacon#define TRAMP_TEXT \ 59c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 605c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 61c7b9adafSWill Deacon *(.entry.tramp.text) \ 62c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 635c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 64c7b9adafSWill Deacon#else 65c7b9adafSWill Deacon#define TRAMP_TEXT 66c7b9adafSWill Deacon#endif 67c7b9adafSWill Deacon 68a352ea3eSArd Biesheuvel/* 69a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 70348a625dSArd Biesheuvel * runs from _stext to _edata, must be a round multiple of the PE/COFF 71348a625dSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. '_stext' 72a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 73a352ea3eSArd Biesheuvel * boundary should be sufficient. 74a352ea3eSArd Biesheuvel */ 75a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 76a352ea3eSArd Biesheuvel 77a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 78a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 79a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 80a352ea3eSArd Biesheuvel#else 81a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 82a352ea3eSArd Biesheuvel#endif 83a352ea3eSArd Biesheuvel 848c2c3df3SCatalin MarinasSECTIONS 858c2c3df3SCatalin Marinas{ 868c2c3df3SCatalin Marinas /* 878c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 888c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 898c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 908c2c3df3SCatalin Marinas * order of matching. 918c2c3df3SCatalin Marinas */ 922883352bSKees Cook DISCARDS 938c2c3df3SCatalin Marinas /DISCARD/ : { 941e48ef7fSArd Biesheuvel *(.interp .dynamic) 953bbd3db8SArd Biesheuvel *(.dynsym .dynstr .hash .gnu.hash) 968c2c3df3SCatalin Marinas } 978c2c3df3SCatalin Marinas 98ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 998c2c3df3SCatalin Marinas 1008c2c3df3SCatalin Marinas .head.text : { 1018c2c3df3SCatalin Marinas _text = .; 1028c2c3df3SCatalin Marinas HEAD_TEXT 1038c2c3df3SCatalin Marinas } 1048c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1058c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1068c2c3df3SCatalin Marinas IRQENTRY_TEXT 107be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 108888b3c87SPratyush Anand ENTRY_TEXT 1098c2c3df3SCatalin Marinas TEXT_TEXT 1108c2c3df3SCatalin Marinas SCHED_TEXT 1116727ad9eSChris Metcalf CPUIDLE_TEXT 1128c2c3df3SCatalin Marinas LOCK_TEXT 1132dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1142240bbb6SMarc Zyngier HYPERVISOR_TEXT 1155dfe9d7dSArd Biesheuvel IDMAP_TEXT 11682869ac5SJames Morse HIBERNATE_TEXT 117c7b9adafSWill Deacon TRAMP_TEXT 1188c2c3df3SCatalin Marinas *(.fixup) 1198c2c3df3SCatalin Marinas *(.gnu.warning) 1208c2c3df3SCatalin Marinas . = ALIGN(16); 1218c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1228c2c3df3SCatalin Marinas } 1238c2c3df3SCatalin Marinas 124*be288182SKees Cook /* 125*be288182SKees Cook * Make sure that the .got.plt is either completely empty or it 126*be288182SKees Cook * contains only the lazy dispatch entries. 127*be288182SKees Cook */ 128*be288182SKees Cook .got.plt : { *(.got.plt) } 129*be288182SKees Cook ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, 130*be288182SKees Cook "Unexpected GOT/PLT entries detected!") 131*be288182SKees Cook 13297740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1339fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1349fdc14c5SArd Biesheuvel 13519f6bc32SKees Cook /* everything from this point to __init_begin will be marked RO NX */ 13619f6bc32SKees Cook RO_DATA(PAGE_SIZE) 1378c2c3df3SCatalin Marinas 1388eb7e28dSJun Yao idmap_pg_dir = .; 1398eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 1409d2d75edSGavin Shan idmap_pg_end = .; 1418eb7e28dSJun Yao 1428eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 1438eb7e28dSJun Yao tramp_pg_dir = .; 1448eb7e28dSJun Yao . += PAGE_SIZE; 1458eb7e28dSJun Yao#endif 1468eb7e28dSJun Yao 1478eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 1488eb7e28dSJun Yao reserved_ttbr0 = .; 1498eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 1508eb7e28dSJun Yao#endif 1518eb7e28dSJun Yao swapper_pg_dir = .; 1528eb7e28dSJun Yao . += PAGE_SIZE; 1538eb7e28dSJun Yao swapper_pg_end = .; 1548eb7e28dSJun Yao 15597740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1568c2c3df3SCatalin Marinas __init_begin = .; 1572ebe088bSArd Biesheuvel __inittext_begin = .; 1588c2c3df3SCatalin Marinas 1598c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 160ca2ef4ffSMark Rutland 161ca2ef4ffSMark Rutland __exittext_begin = .; 1628c2c3df3SCatalin Marinas .exit.text : { 1631eae811dSArd Biesheuvel EXIT_TEXT 1648c2c3df3SCatalin Marinas } 165ca2ef4ffSMark Rutland __exittext_end = .; 166da141706SLaura Abbott 1672ebe088bSArd Biesheuvel . = ALIGN(4); 1682ebe088bSArd Biesheuvel .altinstructions : { 1692ebe088bSArd Biesheuvel __alt_instructions = .; 1702ebe088bSArd Biesheuvel *(.altinstructions) 1712ebe088bSArd Biesheuvel __alt_instructions_end = .; 1722ebe088bSArd Biesheuvel } 1732ebe088bSArd Biesheuvel 17476085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1752ebe088bSArd Biesheuvel __inittext_end = .; 1762ebe088bSArd Biesheuvel __initdata_begin = .; 1772ebe088bSArd Biesheuvel 1788c2c3df3SCatalin Marinas .init.data : { 1798c2c3df3SCatalin Marinas INIT_DATA 1808c2c3df3SCatalin Marinas INIT_SETUP(16) 1818c2c3df3SCatalin Marinas INIT_CALLS 1828c2c3df3SCatalin Marinas CON_INITCALL 1838c2c3df3SCatalin Marinas INIT_RAM_FS 1841ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1858c2c3df3SCatalin Marinas } 1868c2c3df3SCatalin Marinas .exit.data : { 1871eae811dSArd Biesheuvel EXIT_DATA 1888c2c3df3SCatalin Marinas } 1898c2c3df3SCatalin Marinas 19098fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1918c2c3df3SCatalin Marinas 1923bbd3db8SArd Biesheuvel .rela.dyn : ALIGN(8) { 1931e48ef7fSArd Biesheuvel *(.rela .rela*) 1941e48ef7fSArd Biesheuvel } 195e039ee4eSAndre Przywara 1963bbd3db8SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela.dyn) - KIMAGE_VADDR); 1973bbd3db8SArd Biesheuvel __rela_size = SIZEOF(.rela.dyn); 1980cd3defeSArd Biesheuvel 1995cf896fbSPeter Collingbourne#ifdef CONFIG_RELR 2005cf896fbSPeter Collingbourne .relr.dyn : ALIGN(8) { 2015cf896fbSPeter Collingbourne *(.relr.dyn) 2025cf896fbSPeter Collingbourne } 2035cf896fbSPeter Collingbourne 2045cf896fbSPeter Collingbourne __relr_offset = ABSOLUTE(ADDR(.relr.dyn) - KIMAGE_VADDR); 2055cf896fbSPeter Collingbourne __relr_size = SIZEOF(.relr.dyn); 2065cf896fbSPeter Collingbourne#endif 2075cf896fbSPeter Collingbourne 20897740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2092ebe088bSArd Biesheuvel __initdata_end = .; 2109aa4ec15SMark Rutland __init_end = .; 2119aa4ec15SMark Rutland 2123c620626SMark Salter _data = .; 2138c2c3df3SCatalin Marinas _sdata = .; 214c9174047SKees Cook RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 215b6113038SJames Morse 216b6113038SJames Morse /* 217b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 218b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 219b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 220b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 221b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 222b6113038SJames Morse * interfere with adjacent data. 223b6113038SJames Morse */ 224b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 225b6113038SJames Morse __mmuoff_data_start = .; 226b6113038SJames Morse *(.mmuoff.data.write) 227b6113038SJames Morse } 228b6113038SJames Morse . = ALIGN(SZ_2K); 229b6113038SJames Morse .mmuoff.data.read : { 230b6113038SJames Morse *(.mmuoff.data.read) 231b6113038SJames Morse __mmuoff_data_end = .; 232b6113038SJames Morse } 233b6113038SJames Morse 234a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 235cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2368c2c3df3SCatalin Marinas _edata = .; 2378c2c3df3SCatalin Marinas 2388c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 239bd00cd5fSMark Rutland 240bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2412b5548b6SJun Yao init_pg_dir = .; 2422b5548b6SJun Yao . += INIT_DIR_SIZE; 2432b5548b6SJun Yao init_pg_end = .; 2442b5548b6SJun Yao 24576085affSArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 246cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2478c2c3df3SCatalin Marinas _end = .; 2488c2c3df3SCatalin Marinas 2498c2c3df3SCatalin Marinas STABS_DEBUG 250578d7f0fSKees Cook DWARF_DEBUG 251c604abc3SKees Cook ELF_DETAILS 252a2c1d73bSMark Rutland 253a2c1d73bSMark Rutland HEAD_SYMBOLS 254*be288182SKees Cook 255*be288182SKees Cook /* 256*be288182SKees Cook * Sections that should stay zero sized, which is safer to 257*be288182SKees Cook * explicitly check instead of blindly discarding. 258*be288182SKees Cook */ 259*be288182SKees Cook .plt : { 260*be288182SKees Cook *(.plt) *(.plt.*) *(.iplt) *(.igot) 261*be288182SKees Cook } 262*be288182SKees Cook ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!") 263*be288182SKees Cook 264*be288182SKees Cook .data.rel.ro : { *(.data.rel.ro) } 265*be288182SKees Cook ASSERT(SIZEOF(.data.rel.ro) == 0, "Unexpected RELRO detected!") 2668c2c3df3SCatalin Marinas} 2672240bbb6SMarc Zyngier 26890776dd1SKees Cook#include "image-vars.h" 26990776dd1SKees Cook 2702240bbb6SMarc Zyngier/* 2715dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 27206f75a1fSArd Biesheuvel * and should not cross a page boundary. 2732240bbb6SMarc Zyngier */ 27406f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 27506f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2765dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2775dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 27882869ac5SJames Morse#ifdef CONFIG_HIBERNATION 27982869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 28082869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 28182869ac5SJames Morse#endif 2826c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2836c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2846c27c408SWill Deacon "Entry trampoline text too big") 2856c27c408SWill Deacon#endif 286da57a369SMark Rutland/* 287da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 288da57a369SMark Rutland */ 289ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 290