Skip to content

Commit 9138c4a

Browse files
xur-llvmWangYuli
authored andcommitted
AutoFDO: Enable -ffunction-sections for the AutoFDO build
[ Upstream commit 0847420 ] Enable -ffunction-sections by default for the AutoFDO build. With -ffunction-sections, the compiler places each function in its own section named .text.function_name instead of placing all functions in the .text section. In the AutoFDO build, this allows the linker to utilize profile information to reorganize functions for improved utilization of iCache and iTLB. Co-developed-by: Han Shen <[email protected]> Signed-off-by: Han Shen <[email protected]> Signed-off-by: Rong Xu <[email protected]> Suggested-by: Sriraman Tallam <[email protected]> Tested-by: Yonghong Song <[email protected]> Tested-by: Yabin Cui <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]> [ Backport from v6.13 ] Signed-off-by: WangYuli <[email protected]>
1 parent a1a4aa7 commit 9138c4a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/asm-generic/vmlinux.lds.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,25 @@
9393
* With LTO_CLANG, the linker also splits sections by default, so we need
9494
* these macros to combine the sections during the final link.
9595
*
96+
* With AUTOFDO_CLANG, by default, the linker splits text sections and
97+
* regroups functions into subsections.
98+
*
9699
* RODATA_MAIN is not used because existing code already defines .rodata.x
97100
* sections to be brought in with rodata.
98101
*/
99-
#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
102+
#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) || \
103+
defined(CONFIG_AUTOFDO_CLANG)
100104
#define TEXT_MAIN .text .text.[0-9a-zA-Z_]*
105+
#else
106+
#define TEXT_MAIN .text
107+
#endif
108+
#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
101109
#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*
102110
#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
103111
#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
104112
#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*
105113
#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
106114
#else
107-
#define TEXT_MAIN .text
108115
#define DATA_MAIN .data
109116
#define SDATA_MAIN .sdata
110117
#define RODATA_MAIN .rodata

scripts/Makefile.autofdo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ifndef CONFIG_DEBUG_INFO
99
endif
1010

1111
ifdef CLANG_AUTOFDO_PROFILE
12-
CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE)
12+
CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections
1313
endif
1414

1515
ifdef CONFIG_LTO_CLANG_THIN

0 commit comments

Comments
 (0)