aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Piggin <npiggin@gmail.com>2017-07-26 08:46:27 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-08-09 11:57:42 -0400
commitcb87481ee89dbd6609e227afbf64900fb4e5c930 (patch)
treed8aa0cf8801b143f6f67eb9f83ca66fb940056b2
parentaae4e7a8bc44722fe70d58920a36916b1043195e (diff)
kbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is configured
The .data and .bss sections were modified in the generic linker script to pull in sections named .data.<C identifier>, which are generated by gcc with -ffunction-sections and -fdata-sections options. The problem with this pattern is it can also match section names that Linux defines explicitly, e.g., .data.unlikely. This can cause Linux sections to get moved into the wrong place. The way to avoid this is to use ".." separators for explicit section names (the dot character is valid in a section name but not a C identifier). However currently there are sections which don't follow this rule, so for now just disable the wild card by default. Example: http://marc.info/?l=linux-arm-kernel&m=150106824024221&w=2 Cc: <stable@vger.kernel.org> # 4.9 Fixes: b67067f1176df ("kbuild: allow archs to select link dead code/data elimination") Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
-rw-r--r--include/asm-generic/vmlinux.lds.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index da0be9a8d1de..9623d78f8494 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -60,6 +60,22 @@
60#define ALIGN_FUNCTION() . = ALIGN(8) 60#define ALIGN_FUNCTION() . = ALIGN(8)
61 61
62/* 62/*
63 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
64 * generates .data.identifier sections, which need to be pulled in with
65 * .data. We don't want to pull in .data..other sections, which Linux
66 * has defined. Same for text and bss.
67 */
68#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
69#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
70#define DATA_MAIN .data .data.[0-9a-zA-Z_]*
71#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
72#else
73#define TEXT_MAIN .text
74#define DATA_MAIN .data
75#define BSS_MAIN .bss
76#endif
77
78/*
63 * Align to a 32 byte boundary equal to the 79 * Align to a 32 byte boundary equal to the
64 * alignment gcc 4.5 uses for a struct 80 * alignment gcc 4.5 uses for a struct
65 */ 81 */
@@ -198,12 +214,9 @@
198 214
199/* 215/*
200 * .data section 216 * .data section
201 * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections generates
202 * .data.identifier which needs to be pulled in with .data, but don't want to
203 * pull in .data..stuff which has its own requirements. Same for bss.
204 */ 217 */
205#define DATA_DATA \ 218#define DATA_DATA \
206 *(.data .data.[0-9a-zA-Z_]*) \ 219 *(DATA_MAIN) \
207 *(.ref.data) \ 220 *(.ref.data) \
208 *(.data..shared_aligned) /* percpu related */ \ 221 *(.data..shared_aligned) /* percpu related */ \
209 MEM_KEEP(init.data) \ 222 MEM_KEEP(init.data) \
@@ -434,16 +447,17 @@
434 VMLINUX_SYMBOL(__security_initcall_end) = .; \ 447 VMLINUX_SYMBOL(__security_initcall_end) = .; \
435 } 448 }
436 449
437/* .text section. Map to function alignment to avoid address changes 450/*
451 * .text section. Map to function alignment to avoid address changes
438 * during second ld run in second ld pass when generating System.map 452 * during second ld run in second ld pass when generating System.map
439 * LD_DEAD_CODE_DATA_ELIMINATION option enables -ffunction-sections generates 453 *
440 * .text.identifier which needs to be pulled in with .text , but some 454 * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
441 * architectures define .text.foo which is not intended to be pulled in here. 455 * code elimination is enabled, so these sections should be converted
442 * Those enabling LD_DEAD_CODE_DATA_ELIMINATION must ensure they don't have 456 * to use ".." first.
443 * conflicting section names, and must pull in .text.[0-9a-zA-Z_]* */ 457 */
444#define TEXT_TEXT \ 458#define TEXT_TEXT \
445 ALIGN_FUNCTION(); \ 459 ALIGN_FUNCTION(); \
446 *(.text.hot .text .text.fixup .text.unlikely) \ 460 *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \
447 *(.ref.text) \ 461 *(.ref.text) \
448 MEM_KEEP(init.text) \ 462 MEM_KEEP(init.text) \
449 MEM_KEEP(exit.text) \ 463 MEM_KEEP(exit.text) \
@@ -613,7 +627,7 @@
613 BSS_FIRST_SECTIONS \ 627 BSS_FIRST_SECTIONS \
614 *(.bss..page_aligned) \ 628 *(.bss..page_aligned) \
615 *(.dynbss) \ 629 *(.dynbss) \
616 *(.bss .bss.[0-9a-zA-Z_]*) \ 630 *(BSS_MAIN) \
617 *(COMMON) \ 631 *(COMMON) \
618 } 632 }
619 633