Skip to content

Commit 84712ea

Browse files
xur-llvmmasahir0y
authored andcommitted
AutoFDO: Enable -ffunction-sections for the AutoFDO build
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]>
1 parent 9a92584 commit 84712ea

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
@@ -95,18 +95,25 @@
9595
* With LTO_CLANG, the linker also splits sections by default, so we need
9696
* these macros to combine the sections during the final link.
9797
*
98+
* With AUTOFDO_CLANG, by default, the linker splits text sections and
99+
* regroups functions into subsections.
100+
*
98101
* RODATA_MAIN is not used because existing code already defines .rodata.x
99102
* sections to be brought in with rodata.
100103
*/
101-
#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG)
104+
#if defined(CONFIG_LD_DEAD_CODE_DATA_ELIMINATION) || defined(CONFIG_LTO_CLANG) || \
105+
defined(CONFIG_AUTOFDO_CLANG)
102106
#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)
103111
#define DATA_MAIN .data .data.[0-9a-zA-Z_]* .data..L* .data..compoundliteral* .data.$__unnamed_* .data.$L*
104112
#define SDATA_MAIN .sdata .sdata.[0-9a-zA-Z_]*
105113
#define RODATA_MAIN .rodata .rodata.[0-9a-zA-Z_]* .rodata..L*
106114
#define BSS_MAIN .bss .bss.[0-9a-zA-Z_]* .bss..L* .bss..compoundliteral*
107115
#define SBSS_MAIN .sbss .sbss.[0-9a-zA-Z_]*
108116
#else
109-
#define TEXT_MAIN .text
110117
#define DATA_MAIN .data
111118
#define SDATA_MAIN .sdata
112119
#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)