Skip to content

Commit e85d1d6

Browse files
committed
kbuild: test dead code/data elimination support in Kconfig
This config option should be enabled only when both the compiler and the linker support necessary flags. Add proper dependencies to Kconfig. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent f6f57a4 commit e85d1d6

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

‎Makefile‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
790790
endif
791791

792792
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
793-
KBUILD_CFLAGS_KERNEL += $(call cc-option,-ffunction-sections,)
794-
KBUILD_CFLAGS_KERNEL += $(call cc-option,-fdata-sections,)
793+
KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
794+
LDFLAGS_vmlinux += --gc-sections
795795
endif
796796

797797
# arch Makefile may override CC so keep this after arch Makefile is included
@@ -857,10 +857,6 @@ LDFLAGS_BUILD_ID := $(call ld-option, --build-id)
857857
KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
858858
LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
859859

860-
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
861-
LDFLAGS_vmlinux += $(call ld-option, --gc-sections,)
862-
endif
863-
864860
ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
865861
LDFLAGS_vmlinux += $(call ld-option, -X,)
866862
endif

‎init/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ config LD_DEAD_CODE_DATA_ELIMINATION
10851085
bool "Dead code and data elimination (EXPERIMENTAL)"
10861086
depends on HAVE_LD_DEAD_CODE_DATA_ELIMINATION
10871087
depends on EXPERT
1088+
depends on $(cc-option,-ffunction-sections -fdata-sections)
1089+
depends on $(ld-option,--gc-sections)
10881090
help
10891091
Enable this if you want to do dead code and data elimination with
10901092
the linker by compiling with -ffunction-sections -fdata-sections,

0 commit comments

Comments
 (0)