]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
make.sh: Add -flto to CFLAGS
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Feb 2021 11:26:57 +0000 (11:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 20 May 2021 10:40:39 +0000 (10:40 +0000)
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 <michael.tremer@ipfire.org>
lfs/Config
make.sh

index 7d98e303b43d61b4effb3ed5f653c2d2d17b357a..00d8eedb1c116f1429f37f4a48498c1c668b643d 100644 (file)
@@ -44,6 +44,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 78b93c409829a560fd81ff958f97fbf305dd07ef..98cfc591d23d2ae413d374ad2037321c1d0adf78 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -144,6 +144,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} ))
+
+       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
@@ -217,19 +231,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} ))
-
-       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}"
@@ -586,6 +589,7 @@ enterchroot() {
                CONFIG_ROOT="${CONFIG_ROOT}" \
                CFLAGS="${CFLAGS} ${HARDENING_CFLAGS}" \
                CXXFLAGS="${CXXFLAGS} ${HARDENING_CFLAGS}" \
+               CFLAGS_LTO="${CFLAGS_LTO}" \
                RUSTFLAGS="${RUSTFLAGS}" \
                BUILDTARGET="${BUILDTARGET}" \
                CROSSTARGET="${CROSSTARGET}" \