blob: 98073332e2d05b62c12be5c9f4172ddcc3363736 [file] [log] [blame]
Catalin Marinas8c2c3df2012-04-20 14:45:54 +01001/*
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 Abbottda141702015-01-21 17:36:06 -080011#include <asm/pgtable.h>
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010012
Mark Rutlanda2c1d732014-06-24 16:51:36 +010013#include "image.h"
14
Will Deacon07c802b2014-11-25 15:26:13 +000015/* .exit.text needed in case of alternative patching */
16#define ARM_EXIT_KEEP(x) x
17#define ARM_EXIT_DISCARD(x)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010018
19OUTPUT_ARCH(aarch64)
Geoff Levandaf885f42014-05-16 18:26:01 +010020ENTRY(_text)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010021
22jiffies = jiffies_64;
23
Marc Zyngier2240bbb2012-12-07 18:40:43 +000024#define HYPERVISOR_TEXT \
25 /* \
Ard Biesheuvel06f75a12015-03-19 16:42:26 +000026 * 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 Zyngier2240bbb2012-12-07 18:40:43 +000032 */ \
Ard Biesheuvel06f75a12015-03-19 16:42:26 +000033 . = ALIGN(SZ_4K); \
Marc Zyngier2240bbb2012-12-07 18:40:43 +000034 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 Biesheuvel5dfe9d72015-06-01 13:40:33 +020041#define IDMAP_TEXT \
42 . = ALIGN(SZ_4K); \
43 VMLINUX_SYMBOL(__idmap_text_start) = .; \
44 *(.idmap.text) \
45 VMLINUX_SYMBOL(__idmap_text_end) = .;
46
Ard Biesheuvela352ea32014-10-10 18:42:55 +020047/*
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 */
54PECOFF_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 Abbottda141702015-01-21 17:36:06 -080063#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 Marinas8c2c3df2012-04-20 14:45:54 +010071SECTIONS
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 Abbottda141702015-01-21 17:36:06 -080093 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010094 .text : { /* Real text segment */
95 _stext = .; /* Text and read-only data */
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010096 __exception_text_start = .;
97 *(.exception.text)
98 __exception_text_end = .;
99 IRQENTRY_TEXT
100 TEXT_TEXT
101 SCHED_TEXT
102 LOCK_TEXT
Marc Zyngier2240bbb2012-12-07 18:40:43 +0000103 HYPERVISOR_TEXT
Ard Biesheuvel5dfe9d72015-06-01 13:40:33 +0200104 IDMAP_TEXT
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100105 *(.fixup)
106 *(.gnu.warning)
107 . = ALIGN(16);
108 *(.got) /* Global offset table */
109 }
110
Laura Abbottda141702015-01-21 17:36:06 -0800111 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100112 RO_DATA(PAGE_SIZE)
Will Deaconadace892013-05-08 17:29:24 +0100113 EXCEPTION_TABLE(8)
Mark Salterc80b7ee2013-08-23 16:16:42 +0100114 NOTES
Laura Abbottda141702015-01-21 17:36:06 -0800115 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100116 _etext = .; /* End of text and rodata section */
117
Laura Abbottda141702015-01-21 17:36:06 -0800118 ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100119 __init_begin = .;
120
121 INIT_TEXT_SECTION(8)
122 .exit.text : {
123 ARM_EXIT_KEEP(EXIT_TEXT)
124 }
Laura Abbottda141702015-01-21 17:36:06 -0800125
126 ALIGN_DEBUG_RO_MIN(16)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100127 .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 Wang562c85c2014-09-26 03:30:59 +0100141 . = ALIGN(PAGE_SIZE);
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100142 __init_end = .;
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100143
Andre Przywarae039ee42014-11-14 15:54:08 +0000144 . = 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 Salter3c620622013-11-04 16:38:47 +0000155 _data = .;
Mark Salter3c620622013-11-04 16:38:47 +0000156 _sdata = .;
157 RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
Ard Biesheuvela352ea32014-10-10 18:42:55 +0200158 PECOFF_EDATA_PADDING
Mark Salter3c620622013-11-04 16:38:47 +0000159 _edata = .;
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100160
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100161 BSS_SECTION(0, 0, 0)
Mark Rutlandbd00cd5f2014-06-24 16:51:35 +0100162
163 . = ALIGN(PAGE_SIZE);
164 idmap_pg_dir = .;
165 . += IDMAP_DIR_SIZE;
166 swapper_pg_dir = .;
167 . += SWAPPER_DIR_SIZE;
168
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100169 _end = .;
170
171 STABS_DEBUG
Mark Rutlanda2c1d732014-06-24 16:51:36 +0100172
173 HEAD_SYMBOLS
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100174}
Marc Zyngier2240bbb2012-12-07 18:40:43 +0000175
176/*
Ard Biesheuvel5dfe9d72015-06-01 13:40:33 +0200177 * The HYP init code and ID map text can't be longer than a page each,
Ard Biesheuvel06f75a12015-03-19 16:42:26 +0000178 * and should not cross a page boundary.
Marc Zyngier2240bbb2012-12-07 18:40:43 +0000179 */
Ard Biesheuvel06f75a12015-03-19 16:42:26 +0000180ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
181 "HYP init code too big or misaligned")
Ard Biesheuvel5dfe9d72015-06-01 13:40:33 +0200182ASSERT(__idmap_text_end - (__idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
183 "ID map text too big or misaligned")
Mark Rutlandda57a362014-06-24 16:51:37 +0100184
185/*
186 * If padding is applied before .head.text, virt<->phys conversions will fail.
187 */
188ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")