From 9e1e4d5e56491cca755a14ba306fca0264a8bdf1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 26 Feb 2021 11:26:57 +0000 Subject: [PATCH] make.sh: Add -flto to CFLAGS This will compile the whole distribition with LTO. GCC will generate some intermediate representation of the code which will be compiled into binary at linking stage, after an optimizer has removed any unneeded symbols and the inliner has had a chance to inline functions across source files. Signed-off-by: Michael Tremer --- lfs/Config | 3 +++ make.sh | 30 +++++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/lfs/Config b/lfs/Config index 524ba35c0d..1e06b40116 100644 --- a/lfs/Config +++ b/lfs/Config @@ -42,6 +42,9 @@ PARALLELISM = $(shell echo $$( \ fi) \ ) +# Enable LTO +CFLAGS += $(CFLAGS_LTO) + MAKETUNING = -j$(PARALLELISM) ifeq "$(BUILD_ARCH)" "aarch64" diff --git a/make.sh b/make.sh index 5d48e5e068..f75e592c3a 100755 --- a/make.sh +++ b/make.sh @@ -136,6 +136,20 @@ system_memory() { configure_build() { local build_arch="${1}" + # Determine parallelism + # We assume that each process consumes about + # 128MB of memory. Therefore we find out how + # many processes fit into memory. + local mem_max=$(( ${SYSTEM_MEMORY} / 128 )) + local cpu_max=$(( ${SYSTEM_PROCESSORS} + 1 )) + + local parallelism + if [ ${mem_max} -lt ${cpu_max} ]; then + parallelism=${mem_max} + else + parallelism=${cpu_max} + fi + if [ "${build_arch}" = "default" ]; then build_arch="$(configure_build_guess)" fi @@ -202,19 +216,8 @@ configure_build() { CFLAGS="-O2 -pipe -Wall -fexceptions -fPIC ${CFLAGS_ARCH}" CXXFLAGS="${CFLAGS}" - # Determine parallelism - # We assume that each process consumes about - # 128MB of memory. Therefore we find out how - # many processes fit into memory. - local mem_max=$(( ${SYSTEM_MEMORY} / 128 )) - local cpu_max=$(( ${SYSTEM_PROCESSORS} + 1 )) - - local parallelism - if [ ${mem_max} -lt ${cpu_max} ]; then - parallelism=${mem_max} - else - parallelism=${cpu_max} - fi + # Enable LTO + CFLAGS_LTO="-flto=${parallelism} -ffat-lto-objects" # Use this as default PARALLELISM DEFAULT_PARALLELISM="${parallelism}" @@ -568,6 +571,7 @@ enterchroot() { CONFIG_ROOT="${CONFIG_ROOT}" \ CFLAGS="${CFLAGS} ${HARDENING_CFLAGS}" \ CXXFLAGS="${CXXFLAGS} ${HARDENING_CFLAGS}" \ + CFLAGS_LTO="${CFLAGS_LTO}" \ RUSTFLAGS="${RUSTFLAGS}" \ BUILDTARGET="${BUILDTARGET}" \ CROSSTARGET="${CROSSTARGET}" \ -- 2.39.5