1/* SPDX-License-Identifier: GPL-2.0 */
2#ifdef CONFIG_PPC64
3#define PROVIDE32(x)	PROVIDE(__unused__##x)
4#else
5#define PROVIDE32(x)	PROVIDE(x)
6#endif
7
8#define BSS_FIRST_SECTIONS *(.bss.prominit)
9
10#include <asm/page.h>
11#include <asm-generic/vmlinux.lds.h>
12#include <asm/cache.h>
13#include <asm/thread_info.h>
14
15#if defined(CONFIG_STRICT_KERNEL_RWX) && !defined(CONFIG_PPC32)
16#define STRICT_ALIGN_SIZE	(1 << 24)
17#else
18#define STRICT_ALIGN_SIZE	PAGE_SIZE
19#endif
20
21ENTRY(_stext)
22
23PHDRS {
24	kernel PT_LOAD FLAGS(7); /* RWX */
25	notes PT_NOTE FLAGS(0);
26	dummy PT_NOTE FLAGS(0);
27
28	/* binutils < 2.18 has a bug that makes it misbehave when taking an
29	   ELF file with all segments at load address 0 as input.  This
30	   happens when running "strip" on vmlinux, because of the AT() magic
31	   in this linker script.  People using GCC >= 4.2 won't run into
32	   this problem, because the "build-id" support will put some data
33	   into the "notes" segment (at a non-zero load address).
34
35	   To work around this, we force some data into both the "dummy"
36	   segment and the kernel segment, so the dummy segment will get a
37	   non-zero load address.  It's not enough to always create the
38	   "notes" segment, since if nothing gets assigned to it, its load
39	   address will be zero.  */
40}
41
42#ifdef CONFIG_PPC64
43OUTPUT_ARCH(powerpc:common64)
44jiffies = jiffies_64;
45#else
46OUTPUT_ARCH(powerpc:common)
47jiffies = jiffies_64 + 4;
48#endif
49SECTIONS
50{
51	. = KERNELBASE;
52
53/*
54 * Text, read only data and other permanent read-only sections
55 */
56
57	_text = .;
58	_stext = .;
59
60	/*
61	 * Head text.
62	 * This needs to be in its own output section to avoid ld placing
63	 * branch trampoline stubs randomly throughout the fixed sections,
64	 * which it will do (even if the branch comes from another section)
65	 * in order to optimize stub generation.
66	 */
67	.head.text : AT(ADDR(.head.text) - LOAD_OFFSET) {
68#ifdef CONFIG_PPC64
69		KEEP(*(.head.text.first_256B));
70#ifdef CONFIG_PPC_BOOK3E
71#else
72		KEEP(*(.head.text.real_vectors));
73		*(.head.text.real_trampolines);
74		KEEP(*(.head.text.virt_vectors));
75		*(.head.text.virt_trampolines);
76# if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV)
77		KEEP(*(.head.data.fwnmi_page));
78# endif
79#endif
80#else /* !CONFIG_PPC64 */
81		HEAD_TEXT
82#endif
83	} :kernel
84
85	__head_end = .;
86
87#ifdef CONFIG_PPC64
88	/*
89	 * BLOCK(0) overrides the default output section alignment because
90	 * this needs to start right after .head.text in order for fixed
91	 * section placement to work.
92	 */
93	.text BLOCK(0) : AT(ADDR(.text) - LOAD_OFFSET) {
94#ifdef CONFIG_LD_HEAD_STUB_CATCH
95		KEEP(*(.linker_stub_catch));
96		. = . ;
97#endif
98
99#else
100	.text : AT(ADDR(.text) - LOAD_OFFSET) {
101		ALIGN_FUNCTION();
102#endif
103		/* careful! __ftr_alt_* sections need to be close to .text */
104		*(.text.hot TEXT_MAIN .text.fixup .text.unlikely .fixup __ftr_alt_* .ref.text);
105		SCHED_TEXT
106		CPUIDLE_TEXT
107		LOCK_TEXT
108		KPROBES_TEXT
109		IRQENTRY_TEXT
110		SOFTIRQENTRY_TEXT
111		/*
112		 * -Os builds call FP save/restore functions. The powerpc64
113		 * linker generates those on demand in the .sfpr section.
114		 * .sfpr gets placed at the beginning of a group of input
115		 * sections, which can break start-of-text offset if it is
116		 * included with the main text sections, so put it by itself.
117		 */
118		*(.sfpr);
119		MEM_KEEP(init.text)
120		MEM_KEEP(exit.text)
121
122#ifdef CONFIG_PPC32
123		*(.got1)
124		__got2_start = .;
125		*(.got2)
126		__got2_end = .;
127#endif /* CONFIG_PPC32 */
128
129	} :kernel
130
131	. = ALIGN(PAGE_SIZE);
132	_etext = .;
133	PROVIDE32 (etext = .);
134
135	/* Read-only data */
136	RO_DATA(PAGE_SIZE)
137
138#ifdef CONFIG_PPC64
139	. = ALIGN(8);
140	__stf_entry_barrier_fixup : AT(ADDR(__stf_entry_barrier_fixup) - LOAD_OFFSET) {
141		__start___stf_entry_barrier_fixup = .;
142		*(__stf_entry_barrier_fixup)
143		__stop___stf_entry_barrier_fixup = .;
144	}
145
146	. = ALIGN(8);
147	__stf_exit_barrier_fixup : AT(ADDR(__stf_exit_barrier_fixup) - LOAD_OFFSET) {
148		__start___stf_exit_barrier_fixup = .;
149		*(__stf_exit_barrier_fixup)
150		__stop___stf_exit_barrier_fixup = .;
151	}
152
153	. = ALIGN(8);
154	__rfi_flush_fixup : AT(ADDR(__rfi_flush_fixup) - LOAD_OFFSET) {
155		__start___rfi_flush_fixup = .;
156		*(__rfi_flush_fixup)
157		__stop___rfi_flush_fixup = .;
158	}
159#endif /* CONFIG_PPC64 */
160
161#ifdef CONFIG_PPC_BARRIER_NOSPEC
162	. = ALIGN(8);
163	__spec_barrier_fixup : AT(ADDR(__spec_barrier_fixup) - LOAD_OFFSET) {
164		__start___barrier_nospec_fixup = .;
165		*(__barrier_nospec_fixup)
166		__stop___barrier_nospec_fixup = .;
167	}
168#endif /* CONFIG_PPC_BARRIER_NOSPEC */
169
170	EXCEPTION_TABLE(0)
171
172	NOTES :kernel :notes
173
174	/* The dummy segment contents for the bug workaround mentioned above
175	   near PHDRS.  */
176	.dummy : AT(ADDR(.dummy) - LOAD_OFFSET) {
177		LONG(0)
178		LONG(0)
179		LONG(0)
180	} :kernel :dummy
181
182/*
183 * Init sections discarded at runtime
184 */
185	. = ALIGN(STRICT_ALIGN_SIZE);
186	__init_begin = .;
187	INIT_TEXT_SECTION(PAGE_SIZE) :kernel
188
189	/* .exit.text is discarded at runtime, not link time,
190	 * to deal with references from __bug_table
191	 */
192	.exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
193		EXIT_TEXT
194	}
195
196	.init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
197		INIT_DATA
198		__vtop_table_begin = .;
199		KEEP(*(.vtop_fixup));
200		__vtop_table_end = .;
201		__ptov_table_begin = .;
202		KEEP(*(.ptov_fixup));
203		__ptov_table_end = .;
204	}
205
206	.init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
207		INIT_SETUP(16)
208	}
209
210	.initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
211		INIT_CALLS
212	}
213
214	.con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
215		CON_INITCALL
216	}
217
218	SECURITY_INIT
219
220	. = ALIGN(8);
221	__ftr_fixup : AT(ADDR(__ftr_fixup) - LOAD_OFFSET) {
222		__start___ftr_fixup = .;
223		KEEP(*(__ftr_fixup))
224		__stop___ftr_fixup = .;
225	}
226	. = ALIGN(8);
227	__mmu_ftr_fixup : AT(ADDR(__mmu_ftr_fixup) - LOAD_OFFSET) {
228		__start___mmu_ftr_fixup = .;
229		KEEP(*(__mmu_ftr_fixup))
230		__stop___mmu_ftr_fixup = .;
231	}
232	. = ALIGN(8);
233	__lwsync_fixup : AT(ADDR(__lwsync_fixup) - LOAD_OFFSET) {
234		__start___lwsync_fixup = .;
235		KEEP(*(__lwsync_fixup))
236		__stop___lwsync_fixup = .;
237	}
238#ifdef CONFIG_PPC64
239	. = ALIGN(8);
240	__fw_ftr_fixup : AT(ADDR(__fw_ftr_fixup) - LOAD_OFFSET) {
241		__start___fw_ftr_fixup = .;
242		KEEP(*(__fw_ftr_fixup))
243		__stop___fw_ftr_fixup = .;
244	}
245#endif
246	.init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
247		INIT_RAM_FS
248	}
249
250	PERCPU_SECTION(L1_CACHE_BYTES)
251
252	. = ALIGN(8);
253	.machine.desc : AT(ADDR(.machine.desc) - LOAD_OFFSET) {
254		__machine_desc_start = . ;
255		KEEP(*(.machine.desc))
256		__machine_desc_end = . ;
257	}
258#ifdef CONFIG_RELOCATABLE
259	. = ALIGN(8);
260	.dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
261	{
262#ifdef CONFIG_PPC32
263		__dynamic_symtab = .;
264#endif
265		*(.dynsym)
266	}
267	.dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }
268	.dynamic : AT(ADDR(.dynamic) - LOAD_OFFSET)
269	{
270		__dynamic_start = .;
271		*(.dynamic)
272	}
273	.hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
274	.interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
275	.rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
276	{
277		__rela_dyn_start = .;
278		*(.rela*)
279	}
280#endif
281	/* .exit.data is discarded at runtime, not link time,
282	 * to deal with references from .exit.text
283	 */
284	.exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
285		EXIT_DATA
286	}
287
288	/* freed after init ends here */
289	. = ALIGN(PAGE_SIZE);
290	__init_end = .;
291
292/*
293 * And now the various read/write data
294 */
295
296	. = ALIGN(PAGE_SIZE);
297	_sdata = .;
298
299#ifdef CONFIG_PPC32
300	.data : AT(ADDR(.data) - LOAD_OFFSET) {
301		DATA_DATA
302		*(.data.rel*)
303		*(SDATA_MAIN)
304		*(.sdata2)
305		*(.got.plt) *(.got)
306		*(.plt)
307	}
308#else
309	.data : AT(ADDR(.data) - LOAD_OFFSET) {
310		DATA_DATA
311		*(.data.rel*)
312		*(.toc1)
313		*(.branch_lt)
314	}
315
316	.opd : AT(ADDR(.opd) - LOAD_OFFSET) {
317		__start_opd = .;
318		KEEP(*(.opd))
319		__end_opd = .;
320	}
321
322	. = ALIGN(256);
323	.got : AT(ADDR(.got) - LOAD_OFFSET) {
324		__toc_start = .;
325#ifndef CONFIG_RELOCATABLE
326		__prom_init_toc_start = .;
327		arch/powerpc/kernel/prom_init.o*(.toc .got)
328		__prom_init_toc_end = .;
329#endif
330		*(.got)
331		*(.toc)
332	}
333#endif
334
335	/* The initial task and kernel stack */
336	INIT_TASK_DATA_SECTION(THREAD_SIZE)
337
338	.data..page_aligned : AT(ADDR(.data..page_aligned) - LOAD_OFFSET) {
339		PAGE_ALIGNED_DATA(PAGE_SIZE)
340	}
341
342	.data..cacheline_aligned : AT(ADDR(.data..cacheline_aligned) - LOAD_OFFSET) {
343		CACHELINE_ALIGNED_DATA(L1_CACHE_BYTES)
344	}
345
346	.data..read_mostly : AT(ADDR(.data..read_mostly) - LOAD_OFFSET) {
347		READ_MOSTLY_DATA(L1_CACHE_BYTES)
348	}
349
350	. = ALIGN(PAGE_SIZE);
351	.data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
352		NOSAVE_DATA
353	}
354
355	BUG_TABLE
356
357	. = ALIGN(PAGE_SIZE);
358	_edata  =  .;
359	PROVIDE32 (edata = .);
360
361/*
362 * And finally the bss
363 */
364
365	BSS_SECTION(0, 0, 0)
366
367	. = ALIGN(PAGE_SIZE);
368	_end = . ;
369	PROVIDE32 (end = .);
370
371	STABS_DEBUG
372
373	DWARF_DEBUG
374
375	DISCARDS
376	/DISCARD/ : {
377		*(*.EMB.apuinfo)
378		*(.glink .iplt .plt .rela* .comment)
379		*(.gnu.version*)
380		*(.gnu.attributes)
381		*(.eh_frame)
382	}
383}
384