Introduces a build option that enables link time optmizations (LTO).
When enabled, GCC is doing code optimization also while linking.
Although the overall building time increases, more efficient
Unikraft images can be created.
Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
Config.uk | 8 ++++++++
Makefile.uk | 6 ++++++
2 files changed, 14 insertions(+)
diff --git a/Config.uk b/Config.uk
index eea961e..21cec9b 100644
--- a/Config.uk
+++ b/Config.uk
@@ -78,6 +78,14 @@ config OPTIMIZE_DEADELIM
comment "Hint: Enable dropping of unused code to further reduce target image
size"
depends on OPTIMIZE_SIZE && !OPTIMIZE_DEADELIM
+config OPTIMIZE_LTO
+ bool "Link time optimizations (LTO)"
+ default n
+ help
+ Enables GCC to do code optimizations during linking. This option
+ will increase overall building time but creates more efficient
+ Unikraft binaries.
+
config DEBUG_SYMBOLS
bool "Debugging information"
default n
diff --git a/Makefile.uk b/Makefile.uk
index c540ada..1964563 100644
--- a/Makefile.uk
+++ b/Makefile.uk
@@ -34,6 +34,12 @@ CFLAGS-$(OPTIMIZE_DEADELIM) += -fdata-sections
-ffunction-sections
CXXFLAGS-$(OPTIMIZE_DEADELIM) += -fdata-sections -ffunction-sections
LDFLAGS-$(OPTIMIZE_DEADELIM) += -Wl,--gc-sections
+# LTO requires the compiler flags to be handed over also for linking
+CFLAGS-$(OPTIMIZE_LTO) += -flto
+CXXFLAGS-$(OPTIMIZE_LTO) += -flto
+LIBLDFLAGS-$(OPTIMIZE_LTO) += $(CFLAGS) $(CFLAGS-y)
+LDFLAGS-$(OPTIMIZE_LTO) += $(CFLAGS) $(CFLAGS-y)
+
ifneq ($(DEBUG_SYMBOLS),y)
CFLAGS += -g0
CXXFLAGS += -g0