blob: a2c29865c3fe54e2d3c8c7ce1b956ba5ce5c0bf7 [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 Biesheuvela352ea32014-10-10 18:42:55 +020041/*
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 */
48PECOFF_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 Abbottda141702015-01-21 17:36:06 -080057#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 Marinas8c2c3df2012-04-20 14:45:54 +010065SECTIONS
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 Abbottda141702015-01-21 17:36:06 -080087 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010088 .text : { /* Real text segment */
89 _stext = .; /* Text and read-only data */
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010090 __exception_text_start = .;
91 *(.exception.text)
92 __exception_text_end = .;
93 IRQENTRY_TEXT
94 TEXT_TEXT
95 SCHED_TEXT
96 LOCK_TEXT
Marc Zyngier2240bbb2012-12-07 18:40:43 +000097 HYPERVISOR_TEXT
Catalin Marinas8c2c3df2012-04-20 14:45:54 +010098 *(.fixup)
99 *(.gnu.warning)
100 . = ALIGN(16);
101 *(.got) /* Global offset table */
102 }
103
Laura Abbottda141702015-01-21 17:36:06 -0800104 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100105 RO_DATA(PAGE_SIZE)
Will Deaconadace892013-05-08 17:29:24 +0100106 EXCEPTION_TABLE(8)
Mark Salterc80b7ee2013-08-23 16:16:42 +0100107 NOTES
Laura Abbottda141702015-01-21 17:36:06 -0800108 ALIGN_DEBUG_RO
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100109 _etext = .; /* End of text and rodata section */
110
Laura Abbottda141702015-01-21 17:36:06 -0800111 ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100112 __init_begin = .;
113
114 INIT_TEXT_SECTION(8)
115 .exit.text : {
116 ARM_EXIT_KEEP(EXIT_TEXT)
117 }
Laura Abbottda141702015-01-21 17:36:06 -0800118
119 ALIGN_DEBUG_RO_MIN(16)
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100120 .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 Wang562c85c2014-09-26 03:30:59 +0100134 . = ALIGN(PAGE_SIZE);
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100135 __init_end = .;
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100136
Andre Przywarae039ee42014-11-14 15:54:08 +0000137 . = 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 Salter3c620622013-11-04 16:38:47 +0000148 _data = .;
Mark Salter3c620622013-11-04 16:38:47 +0000149 _sdata = .;
150 RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
Ard Biesheuvela352ea32014-10-10 18:42:55 +0200151 PECOFF_EDATA_PADDING
Mark Salter3c620622013-11-04 16:38:47 +0000152 _edata = .;
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100153
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100154 BSS_SECTION(0, 0, 0)
Mark Rutlandbd00cd5f2014-06-24 16:51:35 +0100155
156 . = ALIGN(PAGE_SIZE);
157 idmap_pg_dir = .;
158 . += IDMAP_DIR_SIZE;
159 swapper_pg_dir = .;
160 . += SWAPPER_DIR_SIZE;
161
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100162 _end = .;
163
164 STABS_DEBUG
Mark Rutlanda2c1d732014-06-24 16:51:36 +0100165
166 HEAD_SYMBOLS
Catalin Marinas8c2c3df2012-04-20 14:45:54 +0100167}
Marc Zyngier2240bbb2012-12-07 18:40:43 +0000168
169/*
Ard Biesheuvel06f75a12015-03-19 16:42:26 +0000170 * The HYP init code can't be more than a page long,
171 * and should not cross a page boundary.
Marc Zyngier2240bbb2012-12-07 18:40:43 +0000172 */
Ard Biesheuvel06f75a12015-03-19 16:42:26 +0000173ASSERT(__hyp_idmap_text_end - (__hyp_idmap_text_start & ~(SZ_4K - 1)) <= SZ_4K,
174 "HYP init code too big or misaligned")
Mark Rutlandda57a362014-06-24 16:51:37 +0100175
176/*
177 * If padding is applied before .head.text, virt<->phys conversions will fail.
178 */
179ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")