1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* ld script to make s390 Linux kernel
3  * Written by Martin Schwidefsky (schwidefsky@de.ibm.com)
4  */
5 
6 #include <asm/thread_info.h>
7 #include <asm/page.h>
8 #include <asm/ftrace.lds.h>
9 
10 /*
11  * Put .bss..swapper_pg_dir as the first thing in .bss. This will
12  * make sure it has 16k alignment.
13  */
14 #define BSS_FIRST_SECTIONS *(.bss..swapper_pg_dir) \
15 			   *(.bss..invalid_pg_dir)
16 
17 #define RO_EXCEPTION_TABLE_ALIGN	16
18 
19 /* Handle ro_after_init data on our own. */
20 #define RO_AFTER_INIT_DATA
21 
22 #define RUNTIME_DISCARD_EXIT
23 
24 #define EMITS_PT_NOTE
25 
26 #include <asm-generic/vmlinux.lds.h>
27 #include <asm/vmlinux.lds.h>
28 
29 OUTPUT_FORMAT("elf64-s390", "elf64-s390", "elf64-s390")
30 OUTPUT_ARCH(s390:64-bit)
31 ENTRY(startup_continue)
32 jiffies = jiffies_64;
33 
34 PHDRS {
35 	text PT_LOAD FLAGS(5);	/* R_E */
36 	data PT_LOAD FLAGS(7);	/* RWE */
37 	note PT_NOTE FLAGS(0);	/* ___ */
38 }
39 
40 SECTIONS
41 {
42 	. = TEXT_OFFSET;
43 	.text : {
44 		_stext = .;		/* Start of text section */
45 		_text = .;		/* Text and read-only data */
46 		HEAD_TEXT
47 		TEXT_TEXT
48 		SCHED_TEXT
49 		LOCK_TEXT
50 		KPROBES_TEXT
51 		IRQENTRY_TEXT
52 		SOFTIRQENTRY_TEXT
53 		FTRACE_HOTPATCH_TRAMPOLINES_TEXT
54 		*(.text.*_indirect_*)
55 		*(.fixup)
56 		*(.gnu.warning)
57 		. = ALIGN(PAGE_SIZE);
58 		_etext = .;		/* End of text section */
59 	} :text = 0x0700
60 
61 	RO_DATA(PAGE_SIZE)
62 
63 	. = ALIGN(PAGE_SIZE);
64 	_sdata = .;		/* Start of data section */
65 
66 	. = ALIGN(PAGE_SIZE);
67 	__start_ro_after_init = .;
68 	.data..ro_after_init : {
69 		 *(.data..ro_after_init)
70 		JUMP_TABLE_DATA
71 	} :data
72 	. = ALIGN(PAGE_SIZE);
73 	__end_ro_after_init = .;
74 
75 	.data.rel.ro : {
76 		*(.data.rel.ro .data.rel.ro.*)
77 	}
78 	.got : {
79 		__got_start = .;
80 		*(.got)
81 		__got_end = .;
82 	}
83 
84 	RW_DATA(0x100, PAGE_SIZE, THREAD_SIZE)
85 	.data.rel : {
86 		*(.data.rel*)
87 	}
88 	BOOT_DATA_PRESERVED
89 
90 	. = ALIGN(8);
91 	.amode31.refs : {
92 		_start_amode31_refs = .;
93 		*(.amode31.refs)
94 		_end_amode31_refs = .;
95 	}
96 
97 	. = ALIGN(PAGE_SIZE);
98 	_edata = .;		/* End of data section */
99 
100 	/* will be freed after init */
101 	. = ALIGN(PAGE_SIZE);	/* Init code and data */
102 	__init_begin = .;
103 
104 	. = ALIGN(PAGE_SIZE);
105 	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
106 		_sinittext = .;
107 		INIT_TEXT
108 		. = ALIGN(PAGE_SIZE);
109 		_einittext = .;
110 	}
111 
112 	/*
113 	 * .exit.text is discarded at runtime, not link time,
114 	 * to deal with references from __bug_table
115 	*/
116 	.exit.text : {
117 		EXIT_TEXT
118 	}
119 
120 	.exit.data : {
121 		EXIT_DATA
122 	}
123 
124 	/*
125 	 * struct alt_inst entries. From the header (alternative.h):
126 	 * "Alternative instructions for different CPU types or capabilities"
127 	 * Think locking instructions on spinlocks.
128 	 * Note, that it is a part of __init region.
129 	 */
130 	. = ALIGN(8);
131 	.altinstructions : {
132 		__alt_instructions = .;
133 		*(.altinstructions)
134 		__alt_instructions_end = .;
135 	}
136 
137 	/*
138 	 * And here are the replacement instructions. The linker sticks
139 	 * them as binary blobs. The .altinstructions has enough data to
140 	 * get the address and the length of them to patch the kernel safely.
141 	 * Note, that it is a part of __init region.
142 	 */
143 	.altinstr_replacement : {
144 		*(.altinstr_replacement)
145 	}
146 
147 	/*
148 	 * Table with the patch locations to undo expolines
149 	*/
150 	. = ALIGN(4);
151 	.nospec_call_table : {
152 		__nospec_call_start = . ;
153 		*(.s390_indirect*)
154 		__nospec_call_end = . ;
155 	}
156 	.nospec_return_table : {
157 		__nospec_return_start = . ;
158 		*(.s390_return*)
159 		__nospec_return_end = . ;
160 	}
161 
162 	BOOT_DATA
163 
164 	/*
165 	 * .amode31 section for code, data, ex_table that need to stay
166 	 * below 2 GB, even when the kernel is relocated above 2 GB.
167 	 */
168 	. = ALIGN(PAGE_SIZE);
169 	_samode31 = .;
170 	.amode31.text : {
171 		_stext_amode31 = .;
172 		*(.amode31.text)
173 		*(.amode31.text.*_indirect_*)
174 		. = ALIGN(PAGE_SIZE);
175 		_etext_amode31 = .;
176 	}
177 	. = ALIGN(16);
178 	.amode31.ex_table : {
179 		_start_amode31_ex_table = .;
180 		KEEP(*(.amode31.ex_table))
181 		_stop_amode31_ex_table = .;
182 	}
183 	. = ALIGN(PAGE_SIZE);
184 	.amode31.data : {
185 		*(.amode31.data)
186 	}
187 	. = _samode31 + AMODE31_SIZE;
188 	_eamode31 = .;
189 
190 	/* early.c uses stsi, which requires page aligned data. */
191 	. = ALIGN(PAGE_SIZE);
192 	INIT_DATA_SECTION(0x100)
193 
194 	RUNTIME_CONST_VARIABLES
195 
196 	PERCPU_SECTION(0x100)
197 
198 	. = ALIGN(PAGE_SIZE);
199 	__init_end = .;		/* freed after init ends here */
200 
201 	BSS_SECTION(PAGE_SIZE, 4 * PAGE_SIZE, PAGE_SIZE)
202 
203 	. = ALIGN(PAGE_SIZE);
204 	_end = . ;
205 
206 	/*
207 	 * uncompressed image info used by the decompressor
208 	 * it should match struct vmlinux_info
209 	 */
210 	.vmlinux.info 0 (INFO) : {
211 		QUAD(startup_continue)				/* entry */
212 		QUAD(__bss_start - _stext)			/* image_size */
213 		QUAD(__bss_stop - __bss_start)			/* bss_size */
214 		QUAD(__boot_data_start)				/* bootdata_off */
215 		QUAD(__boot_data_end - __boot_data_start)	/* bootdata_size */
216 		QUAD(__boot_data_preserved_start)		/* bootdata_preserved_off */
217 		QUAD(__boot_data_preserved_end -
218 		     __boot_data_preserved_start)		/* bootdata_preserved_size */
219 		QUAD(__got_start)				/* got_start */
220 		QUAD(__got_end)					/* got_end */
221 		QUAD(_eamode31 - _samode31)			/* amode31_size */
222 		QUAD(init_mm)
223 		QUAD(swapper_pg_dir)
224 		QUAD(invalid_pg_dir)
225 		QUAD(__alt_instructions)
226 		QUAD(__alt_instructions_end)
227 #ifdef CONFIG_KASAN
228 		QUAD(kasan_early_shadow_page)
229 		QUAD(kasan_early_shadow_pte)
230 		QUAD(kasan_early_shadow_pmd)
231 		QUAD(kasan_early_shadow_pud)
232 		QUAD(kasan_early_shadow_p4d)
233 #endif
234 	} :NONE
235 
236 	/* Debugging sections.	*/
237 	STABS_DEBUG
238 	DWARF_DEBUG
239 	ELF_DETAILS
240 
241 	/*
242 	 * Make sure that the .got.plt is either completely empty or it
243 	 * contains only the three reserved double words.
244 	 */
245 	.got.plt : {
246 		*(.got.plt)
247 	}
248 	ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, "Unexpected GOT/PLT entries detected!")
249 
250 	/*
251 	 * Sections that should stay zero sized, which is safer to
252 	 * explicitly check instead of blindly discarding.
253 	 */
254 	.plt : {
255 		*(.plt) *(.plt.*) *(.iplt) *(.igot .igot.plt)
256 	}
257 	ASSERT(SIZEOF(.plt) == 0, "Unexpected run-time procedure linkages detected!")
258 	.rela.dyn : {
259 		*(.rela.*) *(.rela_*)
260 	}
261 	ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!")
262 
263 	/* Sections to be discarded */
264 	DISCARDS
265 	/DISCARD/ : {
266 		*(.eh_frame)
267 		*(.interp)
268 	}
269 }
270