Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros

TEXT_MAIN, DATA_MAIN and friends are defined differently depending on
whether certain config options enable -ffunction-sections and/or
-fdata-sections.

There's no technical reason for that beyond voodoo coding. Keeping the
separate implementations adds unnecessary complexity, fragments the
logic, and increases the risk of subtle bugs.

Unify the macros by using the same input section patterns across all
configs.

This is a prerequisite for the upcoming livepatch klp-build tooling
which will manually enable -ffunction-sections and -fdata-sections via
KCFLAGS.

Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

+17 -35
+12 -28
include/asm-generic/vmlinux.lds.h
··· 87 87 #define ALIGN_FUNCTION() . = ALIGN(CONFIG_FUNCTION_ALIGNMENT) 88 88 89 89 /* 90 - * LD_DEAD_CODE_DATA_ELIMINATION option enables -fdata-sections, which 91 - * generates .data.identifier sections, which need to be pulled in with 92 - * .data. We don't want to pull in .data..other sections, which Linux 93 - * has defined. Same for text and bss. 90 + * Support -ffunction-sections by matching .text and .text.*, 91 + * but exclude '.text..*'. 94 92 * 95 - * With LTO_CLANG, the linker also splits sections by default, so we need 96 - * these macros to combine the sections during the final link. 97 - * 98 - * With AUTOFDO_CLANG and PROPELLER_CLANG, by default, the linker splits 99 - * text sections and regroups functions into subsections. 100 - * 101 - * RODATA_MAIN is not used because existing code already defines .rodata.x 102 - * sections to be brought in with rodata. 93 + * Special .text.* sections that are typically grouped separately, such as 94 + * .text.unlikely or .text.hot, must be matched explicitly before using 95 + * TEXT_MAIN. 103 96 */ 104 - #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) || \ 105 - defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG) 106 97 #define TEXT_MAIN .text .text.[0-9a-zA-Z_]* 107 - #else 108 - #define TEXT_MAIN .text 109 - #endif 110 - #if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) 98 + 99 + /* 100 + * Support -fdata-sections by matching .data, .data.*, and others, 101 + * but exclude '.data..*'. 102 + */ 111 103 #define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data.rel.* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L* 112 104 #define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]* 113 105 #define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L* 114 106 #define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral* 115 107 #define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]* 116 - #else 117 - #define DATA_MAIN .data .data.rel .data.rel.local 118 - #define SDATA_MAIN .sdata 119 - #define RODATA_MAIN .rodata 120 - #define BSS_MAIN .bss 121 - #define SBSS_MAIN .sbss 122 - #endif 123 108 124 109 /* 125 110 * GCC 4.5 and later have a 32 bytes section alignment for structures. ··· 566 581 * during second ld run in second ld pass when generating System.map 567 582 * 568 583 * TEXT_MAIN here will match symbols with a fixed pattern (for example, 569 - * .text.hot or .text.unlikely) if dead code elimination or 570 - * function-section is enabled. Match these symbols first before 571 - * TEXT_MAIN to ensure they are grouped together. 584 + * .text.hot or .text.unlikely). Match those before TEXT_MAIN to ensure 585 + * they get grouped together. 572 586 * 573 587 * Also placing .text.hot section at the beginning of a page, this 574 588 * would help the TLB performance.
+5 -7
scripts/module.lds.S
··· 38 38 __kcfi_traps : { KEEP(*(.kcfi_traps)) } 39 39 #endif 40 40 41 - #ifdef CONFIG_LTO_CLANG 42 - /* 43 - * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and 44 - * -ffunction-sections, which increases the size of the final module. 45 - * Merge the split sections in the final binary. 46 - */ 41 + .text : { 42 + *(.text .text.[0-9a-zA-Z_]*) 43 + } 44 + 47 45 .bss : { 48 46 *(.bss .bss.[0-9a-zA-Z_]*) 49 47 *(.bss..L*) ··· 56 58 *(.rodata .rodata.[0-9a-zA-Z_]*) 57 59 *(.rodata..L*) 58 60 } 59 - #endif 61 + 60 62 MOD_SEPARATE_CODETAG_SECTIONS() 61 63 } 62 64