18c2c3df3SCatalin Marinas/* 28c2c3df3SCatalin Marinas * ld script to make ARM Linux kernel 38c2c3df3SCatalin Marinas * taken from the i386 version by Russell King 48c2c3df3SCatalin Marinas * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> 58c2c3df3SCatalin Marinas */ 68c2c3df3SCatalin Marinas 78c2c3df3SCatalin Marinas#include <asm-generic/vmlinux.lds.h> 898fb7548SArd Biesheuvel#include <asm/cache.h> 987d1587bSSuzuki K. Poulose#include <asm/kernel-pgtable.h> 108c2c3df3SCatalin Marinas#include <asm/thread_info.h> 118c2c3df3SCatalin Marinas#include <asm/memory.h> 128c2c3df3SCatalin Marinas#include <asm/page.h> 13da141706SLaura Abbott#include <asm/pgtable.h> 148c2c3df3SCatalin Marinas 15a2c1d73bSMark Rutland#include "image.h" 16a2c1d73bSMark Rutland 1707c802bdSWill Deacon/* .exit.text needed in case of alternative patching */ 1807c802bdSWill Deacon#define ARM_EXIT_KEEP(x) x 1907c802bdSWill Deacon#define ARM_EXIT_DISCARD(x) 208c2c3df3SCatalin Marinas 218c2c3df3SCatalin MarinasOUTPUT_ARCH(aarch64) 22af885f40SGeoff LevandENTRY(_text) 238c2c3df3SCatalin Marinas 248c2c3df3SCatalin Marinasjiffies = jiffies_64; 258c2c3df3SCatalin Marinas 262240bbb6SMarc Zyngier#define HYPERVISOR_TEXT \ 272240bbb6SMarc Zyngier /* \ 2806f75a1fSArd Biesheuvel * Align to 4 KB so that \ 2906f75a1fSArd Biesheuvel * a) the HYP vector table is at its minimum \ 3006f75a1fSArd Biesheuvel * alignment of 2048 bytes \ 3106f75a1fSArd Biesheuvel * b) the HYP init code will not cross a page \ 3206f75a1fSArd Biesheuvel * boundary if its size does not exceed \ 3306f75a1fSArd Biesheuvel * 4 KB (see related ASSERT() below) \ 342240bbb6SMarc Zyngier */ \ 3506f75a1fSArd Biesheuvel . = ALIGN(SZ_4K); \ 362240bbb6SMarc Zyngier VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ 372240bbb6SMarc Zyngier *(.hyp.idmap.text) \ 382240bbb6SMarc Zyngier VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \ 392240bbb6SMarc Zyngier VMLINUX_SYMBOL(__hyp_text_start) = .; \ 402240bbb6SMarc Zyngier *(.hyp.text) \ 412240bbb6SMarc Zyngier VMLINUX_SYMBOL(__hyp_text_end) = .; 422240bbb6SMarc Zyngier 435dfe9d7dSArd Biesheuvel#define IDMAP_TEXT \ 445dfe9d7dSArd Biesheuvel . = ALIGN(SZ_4K); \ 455dfe9d7dSArd Biesheuvel VMLINUX_SYMBOL(__idmap_text_start) = .; \ 465dfe9d7dSArd Biesheuvel *(.idmap.text) \ 475dfe9d7dSArd Biesheuvel VMLINUX_SYMBOL(__idmap_text_end) = .; 485dfe9d7dSArd Biesheuvel 49a352ea3eSArd Biesheuvel/* 50a352ea3eSArd Biesheuvel * The size of the PE/COFF section that covers the kernel image, which 51a352ea3eSArd Biesheuvel * runs from stext to _edata, must be a round multiple of the PE/COFF 52a352ea3eSArd Biesheuvel * FileAlignment, which we set to its minimum value of 0x200. 'stext' 53a352ea3eSArd Biesheuvel * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned 54a352ea3eSArd Biesheuvel * boundary should be sufficient. 55a352ea3eSArd Biesheuvel */ 56a352ea3eSArd BiesheuvelPECOFF_FILE_ALIGNMENT = 0x200; 57a352ea3eSArd Biesheuvel 58a352ea3eSArd Biesheuvel#ifdef CONFIG_EFI 59a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING \ 60a352ea3eSArd Biesheuvel .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } 61a352ea3eSArd Biesheuvel#else 62a352ea3eSArd Biesheuvel#define PECOFF_EDATA_PADDING 63a352ea3eSArd Biesheuvel#endif 64a352ea3eSArd Biesheuvel 65cb083816SMark Rutland#if defined(CONFIG_DEBUG_ALIGN_RODATA) 6697740051SArd Biesheuvel/* 6797740051SArd Biesheuvel * 4 KB granule: 1 level 2 entry 6897740051SArd Biesheuvel * 16 KB granule: 128 level 3 entries, with contiguous bit 6997740051SArd Biesheuvel * 64 KB granule: 32 level 3 entries, with contiguous bit 7097740051SArd Biesheuvel */ 7197740051SArd Biesheuvel#define SEGMENT_ALIGN SZ_2M 72da141706SLaura Abbott#else 7397740051SArd Biesheuvel/* 7497740051SArd Biesheuvel * 4 KB granule: 16 level 3 entries, with contiguous bit 7597740051SArd Biesheuvel * 16 KB granule: 4 level 3 entries, without contiguous bit 7697740051SArd Biesheuvel * 64 KB granule: 1 level 3 entry 7797740051SArd Biesheuvel */ 7897740051SArd Biesheuvel#define SEGMENT_ALIGN SZ_64K 79da141706SLaura Abbott#endif 80da141706SLaura Abbott 818c2c3df3SCatalin MarinasSECTIONS 828c2c3df3SCatalin Marinas{ 838c2c3df3SCatalin Marinas /* 848c2c3df3SCatalin Marinas * XXX: The linker does not define how output sections are 858c2c3df3SCatalin Marinas * assigned to input sections when there are multiple statements 868c2c3df3SCatalin Marinas * matching the same input section name. There is no documented 878c2c3df3SCatalin Marinas * order of matching. 888c2c3df3SCatalin Marinas */ 898c2c3df3SCatalin Marinas /DISCARD/ : { 908c2c3df3SCatalin Marinas ARM_EXIT_DISCARD(EXIT_TEXT) 918c2c3df3SCatalin Marinas ARM_EXIT_DISCARD(EXIT_DATA) 928c2c3df3SCatalin Marinas EXIT_CALL 938c2c3df3SCatalin Marinas *(.discard) 948c2c3df3SCatalin Marinas *(.discard.*) 951e48ef7fSArd Biesheuvel *(.interp .dynamic) 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 __exception_text_start = .; 1078c2c3df3SCatalin Marinas *(.exception.text) 1088c2c3df3SCatalin Marinas __exception_text_end = .; 1098c2c3df3SCatalin Marinas IRQENTRY_TEXT 110be7635e7SAlexander Potapenko SOFTIRQENTRY_TEXT 1118c2c3df3SCatalin Marinas TEXT_TEXT 1128c2c3df3SCatalin Marinas SCHED_TEXT 1138c2c3df3SCatalin Marinas LOCK_TEXT 1142240bbb6SMarc Zyngier HYPERVISOR_TEXT 1155dfe9d7dSArd Biesheuvel IDMAP_TEXT 1168c2c3df3SCatalin Marinas *(.fixup) 1178c2c3df3SCatalin Marinas *(.gnu.warning) 1188c2c3df3SCatalin Marinas . = ALIGN(16); 1198c2c3df3SCatalin Marinas *(.got) /* Global offset table */ 1208c2c3df3SCatalin Marinas } 1218c2c3df3SCatalin Marinas 12297740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1232f39b5f9SJeremy Linton RO_DATA(PAGE_SIZE) /* everything from this point to */ 1242f39b5f9SJeremy Linton EXCEPTION_TABLE(8) /* _etext will be marked RO NX */ 125c80b7ee8SMark Salter NOTES 1268c2c3df3SCatalin Marinas 12797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 128fca082bfSMark Rutland _etext = .; /* End of text and rodata section */ 1298c2c3df3SCatalin Marinas __init_begin = .; 1308c2c3df3SCatalin Marinas 1318c2c3df3SCatalin Marinas INIT_TEXT_SECTION(8) 1328c2c3df3SCatalin Marinas .exit.text : { 1338c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_TEXT) 1348c2c3df3SCatalin Marinas } 135da141706SLaura Abbott 1368c2c3df3SCatalin Marinas .init.data : { 1378c2c3df3SCatalin Marinas INIT_DATA 1388c2c3df3SCatalin Marinas INIT_SETUP(16) 1398c2c3df3SCatalin Marinas INIT_CALLS 1408c2c3df3SCatalin Marinas CON_INITCALL 1418c2c3df3SCatalin Marinas SECURITY_INITCALL 1428c2c3df3SCatalin Marinas INIT_RAM_FS 1431ce99bf4SArd Biesheuvel *(.init.rodata.* .init.bss) /* from the EFI stub */ 1448c2c3df3SCatalin Marinas } 1458c2c3df3SCatalin Marinas .exit.data : { 1468c2c3df3SCatalin Marinas ARM_EXIT_KEEP(EXIT_DATA) 1478c2c3df3SCatalin Marinas } 1488c2c3df3SCatalin Marinas 14998fb7548SArd Biesheuvel PERCPU_SECTION(L1_CACHE_BYTES) 1508c2c3df3SCatalin Marinas 151e039ee4eSAndre Przywara . = ALIGN(4); 152e039ee4eSAndre Przywara .altinstructions : { 153e039ee4eSAndre Przywara __alt_instructions = .; 154e039ee4eSAndre Przywara *(.altinstructions) 155e039ee4eSAndre Przywara __alt_instructions_end = .; 156e039ee4eSAndre Przywara } 157e039ee4eSAndre Przywara .altinstr_replacement : { 158e039ee4eSAndre Przywara *(.altinstr_replacement) 159e039ee4eSAndre Przywara } 1601e48ef7fSArd Biesheuvel .rela : ALIGN(8) { 1611e48ef7fSArd Biesheuvel *(.rela .rela*) 1621e48ef7fSArd Biesheuvel } 1631e48ef7fSArd Biesheuvel .dynsym : ALIGN(8) { 1641e48ef7fSArd Biesheuvel *(.dynsym) 1651e48ef7fSArd Biesheuvel } 1661e48ef7fSArd Biesheuvel .dynstr : { 1671e48ef7fSArd Biesheuvel *(.dynstr) 1681e48ef7fSArd Biesheuvel } 1691e48ef7fSArd Biesheuvel .hash : { 1701e48ef7fSArd Biesheuvel *(.hash) 1711e48ef7fSArd Biesheuvel } 172e039ee4eSAndre Przywara 173*0cd3defeSArd Biesheuvel __rela_offset = ADDR(.rela) - KIMAGE_VADDR; 174*0cd3defeSArd Biesheuvel __rela_size = SIZEOF(.rela); 175*0cd3defeSArd Biesheuvel __dynsym_offset = ADDR(.dynsym) - KIMAGE_VADDR; 176*0cd3defeSArd Biesheuvel 17797740051SArd Biesheuvel . = ALIGN(SEGMENT_ALIGN); 1789aa4ec15SMark Rutland __init_end = .; 1799aa4ec15SMark Rutland 1803c620626SMark Salter _data = .; 1818c2c3df3SCatalin Marinas _sdata = .; 18298fb7548SArd Biesheuvel RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) 183a352ea3eSArd Biesheuvel PECOFF_EDATA_PADDING 1848c2c3df3SCatalin Marinas _edata = .; 1858c2c3df3SCatalin Marinas 1868c2c3df3SCatalin Marinas BSS_SECTION(0, 0, 0) 187bd00cd5fSMark Rutland 188bd00cd5fSMark Rutland . = ALIGN(PAGE_SIZE); 189bd00cd5fSMark Rutland idmap_pg_dir = .; 190bd00cd5fSMark Rutland . += IDMAP_DIR_SIZE; 191bd00cd5fSMark Rutland swapper_pg_dir = .; 192bd00cd5fSMark Rutland . += SWAPPER_DIR_SIZE; 193bd00cd5fSMark Rutland 1948c2c3df3SCatalin Marinas _end = .; 1958c2c3df3SCatalin Marinas 1968c2c3df3SCatalin Marinas STABS_DEBUG 197a2c1d73bSMark Rutland 198a2c1d73bSMark Rutland HEAD_SYMBOLS 1998c2c3df3SCatalin Marinas} 2002240bbb6SMarc Zyngier 2012240bbb6SMarc Zyngier/* 2025dfe9d7dSArd Biesheuvel * The HYP init code and ID map text can't be longer than a page each, 20306f75a1fSArd Biesheuvel * and should not cross a page boundary. 2042240bbb6SMarc Zyngier */ 20506f75a1fSArd BiesheuvelASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 20606f75a1fSArd Biesheuvel "HYP init code too big or misaligned") 2075dfe9d7dSArd BiesheuvelASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, 2085dfe9d7dSArd Biesheuvel "ID map text too big or misaligned") 209da57a369SMark Rutland 210da57a369SMark Rutland/* 211da57a369SMark Rutland * If padding is applied before .head.text, virt<->phys conversions will fail. 212da57a369SMark Rutland */ 213ab893fb9SArd BiesheuvelASSERT(_text == (KIMAGE_VADDR + TEXT_OFFSET), "HEAD is misaligned") 214