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 88c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h> 998fb7548SArd Biesheuvel#include <asm/cache.h> 1087d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h> 118c2c3df3SCatalin Marinas#include <asm/thread_info.h> 128c2c3df3SCatalin Marinas#include <asm/memory.h> 138c2c3df3SCatalin Marinas#include <asm/page.h> 14da141706SLaura Abbott#include <asm/pgtable.h> 158c2c3df3SCatalin Marinas 16a2c1d73bSMark Rutland#include "image.h" 17a2c1d73bSMark Rutland 1807c802bdSWill Deacon/* .exit.text needed in case of alternative patching */ 1907c802bdSWill Deacon#define ARM_EXIT_KEEP(x) x 2007c802bdSWill Deacon#define ARM_EXIT_DISCARD(x) 218c2c3df3SCatalin Marinas 228c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64) 23af885f40SGeoff LevandENTRY(_text) 248c2c3df3SCatalin Marinas 258c2c3df3SCatalin Marinasjiffies = jiffies_64; 268c2c3df3SCatalin Marinas 272240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 282240bbb6SMarc Zyngier /* \ 2906f75a1fSArd Biesheuvel * Align to 4 KB so that \ 3006f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 3106f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 3206f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 3306f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3406f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 352240bbb6SMarc Zyngier */ \ 3606f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 37*5c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 382240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 39*5c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 40*5c636aa0SMasahiro Yamada __hyp_text_start = .; \ 412240bbb6SMarc Zyngier *(.hyp.text) \ 42*5c636aa0SMasahiro Yamada __hyp_text_end = .; 432240bbb6SMarc Zyngier 445dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 455dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 46*5c636aa0SMasahiro Yamada __idmap_text_start = .; \ 475dfe9d7dSArd Biesheuvel *(.idmap.text) \ 48*5c636aa0SMasahiro Yamada __idmap_text_end = .; 495dfe9d7dSArd Biesheuvel 5082869ac5SJames Morse#ifdef CONFIG_HIBERNATION 5182869ac5SJames Morse#define HIBERNATE_TEXT \ 5282869ac5SJames Morse . = ALIGN(SZ_4K); \ 53*5c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5482869ac5SJames Morse *(.hibernate_exit.text) \ 55*5c636aa0SMasahiro Yamada __hibernate_exit_text_end = .; 5682869ac5SJames Morse#else 5782869ac5SJames Morse#define HIBERNATE_TEXT 5882869ac5SJames Morse#endif 5982869ac5SJames Morse 60c7b9adafSWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 61c7b9adafSWill Deacon#define TRAMP_TEXT \ 62c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 63*5c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 64c7b9adafSWill Deacon *(.entry.tramp.text) \ 65c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 66*5c636aa0SMasahiro Yamada __entry_tramp_text_end = .; 67c7b9adafSWill Deacon#else 68c7b9adafSWill Deacon#define TRAMP_TEXT 69c7b9adafSWill Deacon#endif 70c7b9adafSWill Deacon 71a352ea3eSArd Biesheuvel/* 72a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 73a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF 74a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext' 75a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 76a352ea3eSArd Biesheuvel * boundary should be sufficient. 77a352ea3eSArd Biesheuvel */ 78a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 79a352ea3eSArd Biesheuvel 80a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 81a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 82a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 83a352ea3eSArd Biesheuvel#else 84a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 85a352ea3eSArd Biesheuvel#endif 86a352ea3eSArd Biesheuvel 878c2c3df3SCatalin MarinasSECTIONS 888c2c3df3SCatalin Marinas{ 898c2c3df3SCatalin Marinas /* 908c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 918c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 928c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 938c2c3df3SCatalin Marinas * order of matching. 948c2c3df3SCatalin Marinas */ 958c2c3df3SCatalin Marinas /DISCARD/ : { 968c2c3df3SCatalin Marinas ARM_EXIT_DISCARD(EXIT_TEXT) 978c2c3df3SCatalin Marinas ARM_EXIT_DISCARD(EXIT_DATA) 988c2c3df3SCatalin Marinas EXIT_CALL 998c2c3df3SCatalin Marinas *(.discard) 1008c2c3df3SCatalin Marinas *(.discard.*) 1011e48ef7fSArd Biesheuvel *(.interp .dynamic) 10208cc55b2SArd Biesheuvel *(.dynsym .dynstr .hash) 1038c2c3df3SCatalin Marinas } 1048c2c3df3SCatalin Marinas 105ab893fb9SArd Biesheuvel . = KIMAGE_VADDR + TEXT_OFFSET; 1068c2c3df3SCatalin Marinas 1078c2c3df3SCatalin Marinas .head.text : { 1088c2c3df3SCatalin Marinas _text = .; 1098c2c3df3SCatalin Marinas HEAD_TEXT 1108c2c3df3SCatalin Marinas } 1118c2c3df3SCatalin Marinas .text : { /* Real text segment */ 1128c2c3df3SCatalin Marinas _stext = .; /* Text and read-only data */ 1138c2c3df3SCatalin Marinas __exception_text_start = .; 1148c2c3df3SCatalin Marinas *(.exception.text) 1158c2c3df3SCatalin Marinas __exception_text_end = .; 1168c2c3df3SCatalin Marinas IRQENTRY_TEXT 117be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 118888b3c87SPratyush Anand ENTRY_TEXT 1198c2c3df3SCatalin Marinas TEXT_TEXT 1208c2c3df3SCatalin Marinas SCHED_TEXT 1216727ad9eSChris Metcalf CPUIDLE_TEXT 1228c2c3df3SCatalin Marinas LOCK_TEXT 1232dd0e8d2SSandeepa Prabhu KPROBES_TEXT 1242240bbb6SMarc Zyngier HYPERVISOR_TEXT 1255dfe9d7dSArd Biesheuvel IDMAP_TEXT 12682869ac5SJames Morse HIBERNATE_TEXT 127c7b9adafSWill Deacon TRAMP_TEXT 1288c2c3df3SCatalin Marinas *(.fixup) 1298c2c3df3SCatalin Marinas *(.gnu.warning) 1308c2c3df3SCatalin Marinas . = ALIGN(16); 1318c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1328c2c3df3SCatalin Marinas } 1338c2c3df3SCatalin Marinas 13497740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1359fdc14c5SArd Biesheuvel _etext = .; /* End of text section */ 1369fdc14c5SArd Biesheuvel 1372f39b5f9SJeremy Linton RO_DATA(PAGE_SIZE) /* everything from this point to */ 1389fdc14c5SArd Biesheuvel EXCEPTION_TABLE(8) /* __init_begin will be marked RO NX */ 139c80b7ee8SMark Salter NOTES 1408c2c3df3SCatalin Marinas 14197740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1428c2c3df3SCatalin Marinas __init_begin = .; 1432ebe088bSArd Biesheuvel __inittext_begin = .; 1448c2c3df3SCatalin Marinas 1458c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 1468c2c3df3SCatalin Marinas .exit.text : { 1478c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_TEXT) 1488c2c3df3SCatalin Marinas } 149da141706SLaura Abbott 1502ebe088bSArd Biesheuvel . = ALIGN(4); 1512ebe088bSArd Biesheuvel .altinstructions : { 1522ebe088bSArd Biesheuvel __alt_instructions = .; 1532ebe088bSArd Biesheuvel *(.altinstructions) 1542ebe088bSArd Biesheuvel __alt_instructions_end = .; 1552ebe088bSArd Biesheuvel } 1562ebe088bSArd Biesheuvel .altinstr_replacement : { 1572ebe088bSArd Biesheuvel *(.altinstr_replacement) 1582ebe088bSArd Biesheuvel } 1592ebe088bSArd Biesheuvel 1602ebe088bSArd Biesheuvel . = ALIGN(PAGE_SIZE); 1612ebe088bSArd Biesheuvel __inittext_end = .; 1622ebe088bSArd Biesheuvel __initdata_begin = .; 1632ebe088bSArd Biesheuvel 1648c2c3df3SCatalin Marinas .init.data : { 1658c2c3df3SCatalin Marinas INIT_DATA 1668c2c3df3SCatalin Marinas INIT_SETUP(16) 1678c2c3df3SCatalin Marinas INIT_CALLS 1688c2c3df3SCatalin Marinas CON_INITCALL 1698c2c3df3SCatalin Marinas SECURITY_INITCALL 1708c2c3df3SCatalin Marinas INIT_RAM_FS 1711ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1728c2c3df3SCatalin Marinas } 1738c2c3df3SCatalin Marinas .exit.data : { 1748c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_DATA) 1758c2c3df3SCatalin Marinas } 1768c2c3df3SCatalin Marinas 17798fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1788c2c3df3SCatalin Marinas 1791e48ef7fSArd Biesheuvel .rela : ALIGN(8) { 1801e48ef7fSArd Biesheuvel *(.rela .rela*) 1811e48ef7fSArd Biesheuvel } 182e039ee4eSAndre Przywara 183d6732fc4SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); 1840cd3defeSArd Biesheuvel __rela_size = SIZEOF(.rela); 1850cd3defeSArd Biesheuvel 18697740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1872ebe088bSArd Biesheuvel __initdata_end = .; 1889aa4ec15SMark Rutland __init_end = .; 1899aa4ec15SMark Rutland 1903c620626SMark Salter _data = .; 1918c2c3df3SCatalin Marinas _sdata = .; 192e3067861SMark Rutland RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 193b6113038SJames Morse 194b6113038SJames Morse /* 195b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 196b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 197b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 198b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 199b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 200b6113038SJames Morse * interfere with adjacent data. 201b6113038SJames Morse */ 202b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 203b6113038SJames Morse __mmuoff_data_start = .; 204b6113038SJames Morse *(.mmuoff.data.write) 205b6113038SJames Morse } 206b6113038SJames Morse . = ALIGN(SZ_2K); 207b6113038SJames Morse .mmuoff.data.read : { 208b6113038SJames Morse *(.mmuoff.data.read) 209b6113038SJames Morse __mmuoff_data_end = .; 210b6113038SJames Morse } 211b6113038SJames Morse 212a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 213cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2148c2c3df3SCatalin Marinas _edata = .; 2158c2c3df3SCatalin Marinas 2168c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 217bd00cd5fSMark Rutland 218bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 219bd00cd5fSMark Rutland idmap_pg_dir = .; 220bd00cd5fSMark Rutland . += IDMAP_DIR_SIZE; 2211e1b8c04SSteve Capper 2221e1b8c04SSteve Capper#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2231e1b8c04SSteve Capper tramp_pg_dir = .; 2241e1b8c04SSteve Capper . += PAGE_SIZE; 2251e1b8c04SSteve Capper#endif 2261e1b8c04SSteve Capper 2274b65a5dbSCatalin Marinas#ifdef CONFIG_ARM64_SW_TTBR0_PAN 2284b65a5dbSCatalin Marinas reserved_ttbr0 = .; 2294b65a5dbSCatalin Marinas . += RESERVED_TTBR0_SIZE; 2304b65a5dbSCatalin Marinas#endif 2319dfe4828SSteve Capper swapper_pg_dir = .; 2329dfe4828SSteve Capper . += SWAPPER_DIR_SIZE; 2330370b31eSSteve Capper swapper_pg_end = .; 2344b65a5dbSCatalin Marinas 235cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2368c2c3df3SCatalin Marinas _end = .; 2378c2c3df3SCatalin Marinas 2388c2c3df3SCatalin Marinas STABS_DEBUG 239a2c1d73bSMark Rutland 240a2c1d73bSMark Rutland HEAD_SYMBOLS 2418c2c3df3SCatalin Marinas} 2422240bbb6SMarc Zyngier 2432240bbb6SMarc Zyngier/* 2445dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 24506f75a1fSArd Biesheuvel * and should not cross a page boundary. 2462240bbb6SMarc Zyngier */ 24706f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 24806f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2495dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2505dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 25182869ac5SJames Morse#ifdef CONFIG_HIBERNATION 25282869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 25382869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 25482869ac5SJames Morse#endif 2556c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2566c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2576c27c408SWill Deacon "Entry trampoline text too big") 2586c27c408SWill Deacon#endif 259da57a369SMark Rutland/* 260da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 261da57a369SMark Rutland */ 262ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 263