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); \ 375c636aa0SMasahiro Yamada __hyp_idmap_text_start = .; \ 382240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 395c636aa0SMasahiro Yamada __hyp_idmap_text_end = .; \ 405c636aa0SMasahiro Yamada __hyp_text_start = .; \ 412240bbb6SMarc Zyngier *(.hyp.text) \ 425c636aa0SMasahiro Yamada __hyp_text_end = .; 432240bbb6SMarc Zyngier 445dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 455dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 465c636aa0SMasahiro Yamada __idmap_text_start = .; \ 475dfe9d7dSArd Biesheuvel *(.idmap.text) \ 485c636aa0SMasahiro Yamada __idmap_text_end = .; 495dfe9d7dSArd Biesheuvel 5082869ac5SJames Morse#ifdef CONFIG_HIBERNATION 5182869ac5SJames Morse#define HIBERNATE_TEXT \ 5282869ac5SJames Morse . = ALIGN(SZ_4K); \ 535c636aa0SMasahiro Yamada __hibernate_exit_text_start = .; \ 5482869ac5SJames Morse *(.hibernate_exit.text) \ 555c636aa0SMasahiro 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); \ 635c636aa0SMasahiro Yamada __entry_tramp_text_start = .; \ 64c7b9adafSWill Deacon *(.entry.tramp.text) \ 65c7b9adafSWill Deacon . = ALIGN(PAGE_SIZE); \ 665c636aa0SMasahiro 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 141*8eb7e28dSJun Yao . = ALIGN(PAGE_SIZE); 142*8eb7e28dSJun Yao idmap_pg_dir = .; 143*8eb7e28dSJun Yao . += IDMAP_DIR_SIZE; 144*8eb7e28dSJun Yao 145*8eb7e28dSJun Yao#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 146*8eb7e28dSJun Yao tramp_pg_dir = .; 147*8eb7e28dSJun Yao . += PAGE_SIZE; 148*8eb7e28dSJun Yao#endif 149*8eb7e28dSJun Yao 150*8eb7e28dSJun Yao#ifdef CONFIG_ARM64_SW_TTBR0_PAN 151*8eb7e28dSJun Yao reserved_ttbr0 = .; 152*8eb7e28dSJun Yao . += RESERVED_TTBR0_SIZE; 153*8eb7e28dSJun Yao#endif 154*8eb7e28dSJun Yao swapper_pg_dir = .; 155*8eb7e28dSJun Yao . += PAGE_SIZE; 156*8eb7e28dSJun Yao swapper_pg_end = .; 157*8eb7e28dSJun Yao 15897740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1598c2c3df3SCatalin Marinas __init_begin = .; 1602ebe088bSArd Biesheuvel __inittext_begin = .; 1618c2c3df3SCatalin Marinas 1628c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 1638c2c3df3SCatalin Marinas .exit.text : { 1648c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_TEXT) 1658c2c3df3SCatalin Marinas } 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 .altinstr_replacement : { 1742ebe088bSArd Biesheuvel *(.altinstr_replacement) 1752ebe088bSArd Biesheuvel } 1762ebe088bSArd Biesheuvel 1772ebe088bSArd Biesheuvel . = ALIGN(PAGE_SIZE); 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 SECURITY_INITCALL 1878c2c3df3SCatalin Marinas INIT_RAM_FS 1881ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1898c2c3df3SCatalin Marinas } 1908c2c3df3SCatalin Marinas .exit.data : { 1918c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_DATA) 1928c2c3df3SCatalin Marinas } 1938c2c3df3SCatalin Marinas 19498fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1958c2c3df3SCatalin Marinas 1961e48ef7fSArd Biesheuvel .rela : ALIGN(8) { 1971e48ef7fSArd Biesheuvel *(.rela .rela*) 1981e48ef7fSArd Biesheuvel } 199e039ee4eSAndre Przywara 200d6732fc4SArd Biesheuvel __rela_offset = ABSOLUTE(ADDR(.rela) - KIMAGE_VADDR); 2010cd3defeSArd Biesheuvel __rela_size = SIZEOF(.rela); 2020cd3defeSArd Biesheuvel 20397740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 2042ebe088bSArd Biesheuvel __initdata_end = .; 2059aa4ec15SMark Rutland __init_end = .; 2069aa4ec15SMark Rutland 2073c620626SMark Salter _data = .; 2088c2c3df3SCatalin Marinas _sdata = .; 209e3067861SMark Rutland RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN) 210b6113038SJames Morse 211b6113038SJames Morse /* 212b6113038SJames Morse * Data written with the MMU off but read with the MMU on requires 213b6113038SJames Morse * cache lines to be invalidated, discarding up to a Cache Writeback 214b6113038SJames Morse * Granule (CWG) of data from the cache. Keep the section that 215b6113038SJames Morse * requires this type of maintenance to be in its own Cache Writeback 216b6113038SJames Morse * Granule (CWG) area so the cache maintenance operations don't 217b6113038SJames Morse * interfere with adjacent data. 218b6113038SJames Morse */ 219b6113038SJames Morse .mmuoff.data.write : ALIGN(SZ_2K) { 220b6113038SJames Morse __mmuoff_data_start = .; 221b6113038SJames Morse *(.mmuoff.data.write) 222b6113038SJames Morse } 223b6113038SJames Morse . = ALIGN(SZ_2K); 224b6113038SJames Morse .mmuoff.data.read : { 225b6113038SJames Morse *(.mmuoff.data.read) 226b6113038SJames Morse __mmuoff_data_end = .; 227b6113038SJames Morse } 228b6113038SJames Morse 229a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 230cad27ef2SArd Biesheuvel __pecoff_data_rawsize = ABSOLUTE(. - __initdata_begin); 2318c2c3df3SCatalin Marinas _edata = .; 2328c2c3df3SCatalin Marinas 2338c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 234bd00cd5fSMark Rutland 235bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 2362b5548b6SJun Yao init_pg_dir = .; 2372b5548b6SJun Yao . += INIT_DIR_SIZE; 2382b5548b6SJun Yao init_pg_end = .; 2392b5548b6SJun Yao 240cad27ef2SArd Biesheuvel __pecoff_data_size = ABSOLUTE(. - __initdata_begin); 2418c2c3df3SCatalin Marinas _end = .; 2428c2c3df3SCatalin Marinas 2438c2c3df3SCatalin Marinas STABS_DEBUG 244a2c1d73bSMark Rutland 245a2c1d73bSMark Rutland HEAD_SYMBOLS 2468c2c3df3SCatalin Marinas} 2472240bbb6SMarc Zyngier 2482240bbb6SMarc Zyngier/* 2495dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 25006f75a1fSArd Biesheuvel * and should not cross a page boundary. 2512240bbb6SMarc Zyngier */ 25206f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 25306f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2545dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2555dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 25682869ac5SJames Morse#ifdef CONFIG_HIBERNATION 25782869ac5SJames MorseASSERT(__hibernate_exit_text_end - (__hibernate_exit_text_start & ~(SZ_4K - 1)) 25882869ac5SJames Morse <= SZ_4K, "Hibernate exit text too big or misaligned") 25982869ac5SJames Morse#endif 2606c27c408SWill Deacon#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 2616c27c408SWill DeaconASSERT((__entry_tramp_text_end - __entry_tramp_text_start) == PAGE_SIZE, 2626c27c408SWill Deacon "Entry trampoline text too big") 2636c27c408SWill Deacon#endif 264da57a369SMark Rutland/* 265da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 266da57a369SMark Rutland */ 267ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 268