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