Commit 6d6d1161 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

build: add CONFIG_LTO to enable link-time optimization



Change-Id: I9546d715b8d2ca3ebf46183bdbaa58e8aa921d95
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 6a8cd333
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23,3 +23,4 @@ CONFIG.local
.project
.cproject
.settings
mk/cc.mk
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ CONFIG_DEBUG?=n
# Treat warnings as errors (fail the build on any warning).
CONFIG_WERROR?=n

# Build with link-time optimization.
CONFIG_LTO?=n

# Build with code coverage instrumentation.
CONFIG_COVERAGE?=n

+8 −2
Original line number Diff line number Diff line
@@ -38,17 +38,23 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y += lib test examples app

.PHONY: all clean $(DIRS-y) config.h CONFIG.local
.PHONY: all clean $(DIRS-y) config.h CONFIG.local mk/cc.mk

all: $(DIRS-y)
clean: $(DIRS-y)
	$(Q)rm -f mk/cc.mk
	$(Q)rm -f config.h

app: lib
test: lib
examples: lib

$(DIRS-y): config.h
$(DIRS-y): mk/cc.mk config.h

mk/cc.mk:
	$(Q)scripts/detect_cc.sh --cc=$(CC) --cxx=$(CXX) --lto=$(CONFIG_LTO) > $@.tmp; \
	cmp -s $@.tmp $@ || mv $@.tmp $@ ; \
	rm -f $@.tmp

config.h: CONFIG CONFIG.local scripts/genconfig.py
	$(Q)python scripts/genconfig.py $(MAKEFLAGS) > $@.tmp; \
+10 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ function usage()
	echo " --enable-asan             Enable address sanitizer"
	echo " --enable-ubsan            Enable undefined behavior sanitizer"
	echo " --enable-coverage         Enable code coverage tracking"
	echo " --enable-lto              Enable link-time optimization"
	echo " --with-env=path           Use an alternate environment implementation"
	echo ""
	echo "Specifying Dependencies:"
@@ -67,6 +68,12 @@ for i in "$@"; do
		--disable-coverage)
			CONFIG_COVERAGE=n
			;;
		--enable-lto)
			CONFIG_LTO=y
			;;
		--disable-lto)
			CONFIG_LTO=n
			;;
		--enable-werror)
			CONFIG_WERROR=y
			;;
@@ -139,6 +146,9 @@ fi
if [ -n "$CONFIG_COVERAGE" ]; then
	echo "CONFIG_COVERAGE?=$CONFIG_COVERAGE" >> CONFIG.local
fi
if [ -n "$CONFIG_LTO" ]; then
	echo "CONFIG_LTO?=$CONFIG_LTO" >> CONFIG.local
fi
if [ -n "$CONFIG_ASAN" ]; then
	echo "CONFIG_ASAN?=$CONFIG_ASAN" >> CONFIG.local
fi
+8 −1
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@
-include $(SPDK_ROOT_DIR)/CONFIG.local
include $(SPDK_ROOT_DIR)/CONFIG

-include $(SPDK_ROOT_DIR)/mk/cc.mk

C_OPT ?= -fno-omit-frame-pointer
ifneq ($(V),1)
Q ?= @
@@ -54,6 +56,11 @@ ifeq ($(CONFIG_WERROR), y)
COMMON_CFLAGS += -Werror
endif

ifeq ($(CONFIG_LTO),y)
COMMON_CFLAGS += -flto
LDFLAGS += -flto
endif

COMMON_CFLAGS += -Wformat -Wformat-security

COMMON_CFLAGS += -D_GNU_SOURCE
@@ -149,7 +156,7 @@ LINK_CXX=\
LIB_C=\
	$(Q)echo "  LIB $(notdir $@)"; \
	rm -f $@; \
	ar crDs $@ $(OBJS)
	$(CCAR) crDs $@ $(OBJS)

# Clean up generated files listed as arguments plus a default list
CLEAN_C=\
Loading