Skip to content

Commit 25c4953

Browse files
committed
x86/core: implement LD_DEAD_CODE_DATA_ELIMINATION
With its special sections like .cfi_sites, .altinstr_replacement etc. protected by the linker keyword KEEP(), x86 builds and works with LD DCE just fine. DCE still gives some benefit even when CONFIG_LTO=y. Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
1 parent 855baa2 commit 25c4953

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ config X86
235235
select HAVE_KRETPROBES
236236
select HAVE_RETHOOK
237237
select HAVE_KVM
238+
select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
238239
select HAVE_LIVEPATCH if X86_64
239240
select HAVE_MIXED_BREAKPOINTS_REGS
240241
select HAVE_MOD_ARCH_SPECIFIC

arch/x86/kernel/vmlinux.lds.S

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SECTIONS
135135
SOFTIRQENTRY_TEXT
136136
#ifdef CONFIG_RETPOLINE
137137
__indirect_thunk_start = .;
138-
*(.text.__x86.*)
138+
KEEP(*(.text.__x86.*))
139139
__indirect_thunk_end = .;
140140
#endif
141141
STATIC_CALL_TEXT
@@ -239,22 +239,22 @@ SECTIONS
239239
* See static_cpu_has() for an example.
240240
*/
241241
.altinstr_aux : AT(ADDR(.altinstr_aux) - LOAD_OFFSET) {
242-
*(.altinstr_aux)
242+
KEEP(*(.altinstr_aux))
243243
}
244244

245245
INIT_DATA_SECTION(16)
246246

247247
.x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
248248
__x86_cpu_dev_start = .;
249-
*(.x86_cpu_dev.init)
249+
KEEP(*(.x86_cpu_dev.init))
250250
__x86_cpu_dev_end = .;
251251
}
252252

253253
#ifdef CONFIG_X86_INTEL_MID
254254
.x86_intel_mid_dev.init : AT(ADDR(.x86_intel_mid_dev.init) - \
255255
LOAD_OFFSET) {
256256
__x86_intel_mid_dev_start = .;
257-
*(.x86_intel_mid_dev.init)
257+
KEEP(*(.x86_intel_mid_dev.init))
258258
__x86_intel_mid_dev_end = .;
259259
}
260260
#endif
@@ -268,7 +268,7 @@ SECTIONS
268268
. = ALIGN(8);
269269
.parainstructions : AT(ADDR(.parainstructions) - LOAD_OFFSET) {
270270
__parainstructions = .;
271-
*(.parainstructions)
271+
KEEP(*(.parainstructions))
272272
__parainstructions_end = .;
273273
}
274274

@@ -281,21 +281,21 @@ SECTIONS
281281
. = ALIGN(8);
282282
.retpoline_sites : AT(ADDR(.retpoline_sites) - LOAD_OFFSET) {
283283
__retpoline_sites = .;
284-
*(.retpoline_sites)
284+
KEEP(*(.retpoline_sites))
285285
__retpoline_sites_end = .;
286286
}
287287

288288
. = ALIGN(8);
289289
.return_sites : AT(ADDR(.return_sites) - LOAD_OFFSET) {
290290
__return_sites = .;
291-
*(.return_sites)
291+
KEEP(*(.return_sites))
292292
__return_sites_end = .;
293293
}
294294

295295
. = ALIGN(8);
296296
.call_sites : AT(ADDR(.call_sites) - LOAD_OFFSET) {
297297
__call_sites = .;
298-
*(.call_sites)
298+
KEEP(*(.call_sites))
299299
__call_sites_end = .;
300300
}
301301
#endif
@@ -304,7 +304,7 @@ SECTIONS
304304
. = ALIGN(8);
305305
.ibt_endbr_seal : AT(ADDR(.ibt_endbr_seal) - LOAD_OFFSET) {
306306
__ibt_endbr_seal = .;
307-
*(.ibt_endbr_seal)
307+
KEEP(*(.ibt_endbr_seal))
308308
__ibt_endbr_seal_end = .;
309309
}
310310
#endif
@@ -313,7 +313,7 @@ SECTIONS
313313
. = ALIGN(8);
314314
.cfi_sites : AT(ADDR(.cfi_sites) - LOAD_OFFSET) {
315315
__cfi_sites = .;
316-
*(.cfi_sites)
316+
KEEP(*(.cfi_sites))
317317
__cfi_sites_end = .;
318318
}
319319
#endif
@@ -326,7 +326,7 @@ SECTIONS
326326
. = ALIGN(8);
327327
.altinstructions : AT(ADDR(.altinstructions) - LOAD_OFFSET) {
328328
__alt_instructions = .;
329-
*(.altinstructions)
329+
KEEP(*(.altinstructions))
330330
__alt_instructions_end = .;
331331
}
332332

@@ -336,13 +336,13 @@ SECTIONS
336336
* get the address and the length of them to patch the kernel safely.
337337
*/
338338
.altinstr_replacement : AT(ADDR(.altinstr_replacement) - LOAD_OFFSET) {
339-
*(.altinstr_replacement)
339+
KEEP(*(.altinstr_replacement))
340340
}
341341

342342
. = ALIGN(8);
343343
.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
344344
__apicdrivers = .;
345-
*(.apicdrivers);
345+
KEEP(*(.apicdrivers))
346346
__apicdrivers_end = .;
347347
}
348348

@@ -377,7 +377,7 @@ SECTIONS
377377
. = ALIGN(PAGE_SIZE);
378378
.smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
379379
__smp_locks = .;
380-
*(.smp_locks)
380+
KEEP(*(.smp_locks))
381381
. = ALIGN(PAGE_SIZE);
382382
__smp_locks_end = .;
383383
}
@@ -412,7 +412,7 @@ SECTIONS
412412
.brk : AT(ADDR(.brk) - LOAD_OFFSET) {
413413
__brk_base = .;
414414
. += 64 * 1024; /* 64k alignment slop space */
415-
*(.bss..brk) /* areas brk users have reserved */
415+
KEEP(*(.bss..brk)) /* areas brk users have reserved */
416416
__brk_limit = .;
417417
}
418418

@@ -438,7 +438,7 @@ SECTIONS
438438
. = ALIGN(HPAGE_SIZE);
439439
.init.scratch : AT(ADDR(.init.scratch) - LOAD_OFFSET) {
440440
__init_scratch_begin = .;
441-
*(.init.scratch)
441+
KEEP(*(.init.scratch))
442442
. = ALIGN(HPAGE_SIZE);
443443
__init_scratch_end = .;
444444
}

0 commit comments

Comments
 (0)