Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ld script to make ARM Linux kernel |
| 3 | * taken from the i386 version by Russell King |
| 4 | * Written by Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
| 5 | */ |
| 6 | |
| 7 | #include <asm-generic/vmlinux.lds.h> |
| 8 | #include <asm/thread_info.h> |
| 9 | #include <asm/memory.h> |
| 10 | #include <asm/page.h> |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 11 | #include <asm/pgtable.h> |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 12 | |
Mark Rutland | a2c1d73 | 2014-06-24 16:51:36 +0100 | [diff] [blame] | 13 | #include "image.h" |
| 14 | |
Will Deacon | 07c802b | 2014-11-25 15:26:13 +0000 | [diff] [blame] | 15 | /* .exit.text needed in case of alternative patching */ |
| 16 | #define ARM_EXIT_KEEP(x) x |
| 17 | #define ARM_EXIT_DISCARD(x) |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 18 | |
| 19 | OUTPUT_ARCH(aarch64) |
Geoff Levand | af885f4 | 2014-05-16 18:26:01 +0100 | [diff] [blame] | 20 | ENTRY(_text) |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 21 | |
| 22 | jiffies = jiffies_64; |
| 23 | |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 24 | #define HYPERVISOR_TEXT \ |
| 25 | /* \ |
Ard Biesheuvel | 06f75a1 | 2015-03-19 16:42:26 +0000 | [diff] [blame] | 26 | * Align to 4 KB so that \ |
| 27 | * a) the HYP vector table is at its minimum \ |
| 28 | * alignment of 2048 bytes \ |
| 29 | * b) the HYP init code will not cross a page \ |
| 30 | * boundary if its size does not exceed \ |
| 31 | * 4 KB (see related ASSERT() below) \ |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 32 | */ \ |
Ard Biesheuvel | 06f75a1 | 2015-03-19 16:42:26 +0000 | [diff] [blame] | 33 | . = ALIGN(SZ_4K); \ |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 34 | VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ |
| 35 | *(.hyp.idmap.text) \ |
| 36 | VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; \ |
| 37 | VMLINUX_SYMBOL(__hyp_text_start) = .; \ |
| 38 | *(.hyp.text) \ |
| 39 | VMLINUX_SYMBOL(__hyp_text_end) = .; |
| 40 | |
Ard Biesheuvel | a352ea3 | 2014-10-10 18:42:55 +0200 | [diff] [blame] | 41 | /* |
| 42 | * The size of the PE/COFF section that covers the kernel image, which |
| 43 | * runs from stext to _edata, must be a round multiple of the PE/COFF |
| 44 | * FileAlignment, which we set to its minimum value of 0x200. 'stext' |
| 45 | * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned |
| 46 | * boundary should be sufficient. |
| 47 | */ |
| 48 | PECOFF_FILE_ALIGNMENT = 0x200; |
| 49 | |
| 50 | #ifdef CONFIG_EFI |
| 51 | #define PECOFF_EDATA_PADDING \ |
| 52 | .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); } |
| 53 | #else |
| 54 | #define PECOFF_EDATA_PADDING |
| 55 | #endif |
| 56 | |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 57 | #ifdef CONFIG_DEBUG_ALIGN_RODATA |
| 58 | #define ALIGN_DEBUG_RO . = ALIGN(1<<SECTION_SHIFT); |
| 59 | #define ALIGN_DEBUG_RO_MIN(min) ALIGN_DEBUG_RO |
| 60 | #else |
| 61 | #define ALIGN_DEBUG_RO |
| 62 | #define ALIGN_DEBUG_RO_MIN(min) . = ALIGN(min); |
| 63 | #endif |
| 64 | |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 65 | SECTIONS |
| 66 | { |
| 67 | /* |
| 68 | * XXX: The linker does not define how output sections are |
| 69 | * assigned to input sections when there are multiple statements |
| 70 | * matching the same input section name. There is no documented |
| 71 | * order of matching. |
| 72 | */ |
| 73 | /DISCARD/ : { |
| 74 | ARM_EXIT_DISCARD(EXIT_TEXT) |
| 75 | ARM_EXIT_DISCARD(EXIT_DATA) |
| 76 | EXIT_CALL |
| 77 | *(.discard) |
| 78 | *(.discard.*) |
| 79 | } |
| 80 | |
| 81 | . = PAGE_OFFSET + TEXT_OFFSET; |
| 82 | |
| 83 | .head.text : { |
| 84 | _text = .; |
| 85 | HEAD_TEXT |
| 86 | } |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 87 | ALIGN_DEBUG_RO |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 88 | .text : { /* Real text segment */ |
| 89 | _stext = .; /* Text and read-only data */ |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 90 | __exception_text_start = .; |
| 91 | *(.exception.text) |
| 92 | __exception_text_end = .; |
| 93 | IRQENTRY_TEXT |
| 94 | TEXT_TEXT |
| 95 | SCHED_TEXT |
| 96 | LOCK_TEXT |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 97 | HYPERVISOR_TEXT |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 98 | *(.fixup) |
| 99 | *(.gnu.warning) |
| 100 | . = ALIGN(16); |
| 101 | *(.got) /* Global offset table */ |
| 102 | } |
| 103 | |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 104 | ALIGN_DEBUG_RO |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 105 | RO_DATA(PAGE_SIZE) |
Will Deacon | adace89 | 2013-05-08 17:29:24 +0100 | [diff] [blame] | 106 | EXCEPTION_TABLE(8) |
Mark Salter | c80b7ee | 2013-08-23 16:16:42 +0100 | [diff] [blame] | 107 | NOTES |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 108 | ALIGN_DEBUG_RO |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 109 | _etext = .; /* End of text and rodata section */ |
| 110 | |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 111 | ALIGN_DEBUG_RO_MIN(PAGE_SIZE) |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 112 | __init_begin = .; |
| 113 | |
| 114 | INIT_TEXT_SECTION(8) |
| 115 | .exit.text : { |
| 116 | ARM_EXIT_KEEP(EXIT_TEXT) |
| 117 | } |
Laura Abbott | da14170 | 2015-01-21 17:36:06 -0800 | [diff] [blame] | 118 | |
| 119 | ALIGN_DEBUG_RO_MIN(16) |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 120 | .init.data : { |
| 121 | INIT_DATA |
| 122 | INIT_SETUP(16) |
| 123 | INIT_CALLS |
| 124 | CON_INITCALL |
| 125 | SECURITY_INITCALL |
| 126 | INIT_RAM_FS |
| 127 | } |
| 128 | .exit.data : { |
| 129 | ARM_EXIT_KEEP(EXIT_DATA) |
| 130 | } |
| 131 | |
| 132 | PERCPU_SECTION(64) |
| 133 | |
Yalin Wang | 562c85c | 2014-09-26 03:30:59 +0100 | [diff] [blame] | 134 | . = ALIGN(PAGE_SIZE); |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 135 | __init_end = .; |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 136 | |
Andre Przywara | e039ee4 | 2014-11-14 15:54:08 +0000 | [diff] [blame] | 137 | . = ALIGN(4); |
| 138 | .altinstructions : { |
| 139 | __alt_instructions = .; |
| 140 | *(.altinstructions) |
| 141 | __alt_instructions_end = .; |
| 142 | } |
| 143 | .altinstr_replacement : { |
| 144 | *(.altinstr_replacement) |
| 145 | } |
| 146 | |
| 147 | . = ALIGN(PAGE_SIZE); |
Mark Salter | 3c62062 | 2013-11-04 16:38:47 +0000 | [diff] [blame] | 148 | _data = .; |
Mark Salter | 3c62062 | 2013-11-04 16:38:47 +0000 | [diff] [blame] | 149 | _sdata = .; |
| 150 | RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) |
Ard Biesheuvel | a352ea3 | 2014-10-10 18:42:55 +0200 | [diff] [blame] | 151 | PECOFF_EDATA_PADDING |
Mark Salter | 3c62062 | 2013-11-04 16:38:47 +0000 | [diff] [blame] | 152 | _edata = .; |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 153 | |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 154 | BSS_SECTION(0, 0, 0) |
Mark Rutland | bd00cd5f | 2014-06-24 16:51:35 +0100 | [diff] [blame] | 155 | |
| 156 | . = ALIGN(PAGE_SIZE); |
| 157 | idmap_pg_dir = .; |
| 158 | . += IDMAP_DIR_SIZE; |
| 159 | swapper_pg_dir = .; |
| 160 | . += SWAPPER_DIR_SIZE; |
| 161 | |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 162 | _end = .; |
| 163 | |
| 164 | STABS_DEBUG |
Mark Rutland | a2c1d73 | 2014-06-24 16:51:36 +0100 | [diff] [blame] | 165 | |
| 166 | HEAD_SYMBOLS |
Catalin Marinas | 8c2c3df | 2012-04-20 14:45:54 +0100 | [diff] [blame] | 167 | } |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 168 | |
| 169 | /* |
Ard Biesheuvel | 06f75a1 | 2015-03-19 16:42:26 +0000 | [diff] [blame] | 170 | * The HYP init code can't be more than a page long, |
| 171 | * and should not cross a page boundary. |
Marc Zyngier | 2240bbb | 2012-12-07 18:40:43 +0000 | [diff] [blame] | 172 | */ |
Ard Biesheuvel | 06f75a1 | 2015-03-19 16:42:26 +0000 | [diff] [blame] | 173 | ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K, |
| 174 | "HYP init code too big or misaligned") |
Mark Rutland | da57a36 | 2014-06-24 16:51:37 +0100 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * If padding is applied before .head.text, virt<->phys conversions will fail. |
| 178 | */ |
| 179 | ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned") |