1 From cb87481ee89dbd6609e227afbf64900fb4e5c930 Mon Sep 17 00:00:00 2001
2 From: Nicholas Piggin <npiggin@gmail.com>
3 Date: Wed, 26 Jul 2017 22:46:27 +1000
4 Subject: kbuild: linker script do not match C names unless LD_DEAD_CODE_DATA_ELIMINATION is configured
6 From: Nicholas Piggin <npiggin@gmail.com>
8 commit cb87481ee89dbd6609e227afbf64900fb4e5c930 upstream.
10 The .data and .bss sections were modified in the generic linker script to
11 pull in sections named .data.<C identifier>, which are generated by gcc with
12 -ffunction-sections and -fdata-sections options.
14 The problem with this pattern is it can also match section names that Linux
15 defines explicitly, e.g., .data.unlikely. This can cause Linux sections to
16 get moved into the wrong place.
18 The way to avoid this is to use ".." separators for explicit section names
19 (the dot character is valid in a section name but not a C identifier).
20 However currently there are sections which don't follow this rule, so for
21 now just disable the wild card by default.
23 Example: http://marc.info/?l=linux-arm-kernel&m=150106824024221&w=2
25 Fixes: b67067f1176df ("kbuild: allow archs to select link dead code/data elimination")
26 Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
27 Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
28 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
31 include/asm-generic/vmlinux.lds.h | 38 ++++++++++++++++++++++++++------------
32 1 file changed, 26 insertions(+), 12 deletions(-)
34 --- a/include/asm-generic/vmlinux.lds.h
35 +++ b/include/asm-generic/vmlinux.lds.h
37 #define ALIGN_FUNCTION() . = ALIGN(8)
40 + * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which
41 + * generates .data.identifier sections, which need to be pulled in with
42 + * .data. We don't want to pull in .data..other sections, which Linux
43 + * has defined. Same for text and bss.
45 +#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
46 +#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
47 +#define DATA_MAIN .data .data.[0-9a-zA-Z_]*
48 +#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]*
50 +#define TEXT_MAIN .text
51 +#define DATA_MAIN .data
52 +#define BSS_MAIN .bss
56 * Align to a 32 byte boundary equal to the
57 * alignment gcc 4.5 uses for a struct
63 - * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections generates
64 - * .data.identifier which needs to be pulled in with .data, but don't want to
65 - * pull in .data..stuff which has its own requirements. Same for bss.
68 - *(.data .data.[0-9a-zA-Z_]*) \
71 *(.data..shared_aligned) /* percpu related */ \
74 VMLINUX_SYMBOL(__security_initcall_end) = .; \
77 -/* .text section. Map to function alignment to avoid address changes
79 + * .text section. Map to function alignment to avoid address changes
80 * during second ld run in second ld pass when generating System.map
81 - * LD_DEAD_CODE_DATA_ELIMINATION option enables -ffunction-sections generates
82 - * .text.identifier which needs to be pulled in with .text , but some
83 - * architectures define .text.foo which is not intended to be pulled in here.
84 - * Those enabling LD_DEAD_CODE_DATA_ELIMINATION must ensure they don't have
85 - * conflicting section names, and must pull in .text.[0-9a-zA-Z_]* */
87 + * TEXT_MAIN here will match .text.fixup and .text.unlikely if dead
88 + * code elimination is enabled, so these sections should be converted
89 + * to use ".." first.
93 - *(.text.hot .text .text.fixup .text.unlikely) \
94 + *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \
100 *(.bss..page_aligned) \
102 - *(.bss .bss.[0-9a-zA-Z_]*) \