From 425af8dc5915c8a8185ef3ea270da495b8dab4af Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Mon, 16 Mar 2026 23:11:10 +0100 Subject: [PATCH 1/2] Makefile: add link-time optimization support Add flags for enabling link-time optmization during compilation by calling "make LTO=yes". I cannot find a definition of LDFLAGS, so just chuck it into GDAL_FLAGS which should be used for the binaries that does heavy computation. I don't have any performance comparisons, but compiling with LTO makes the binary noticeably smaller, before: $ ls -l `which force-l2ps` -rwxr-xr-x 1 root root 2668408 Mar 16 22:02 /usr/local/bin/force/force-l2ps and after: $ ls -l `which force-l2ps` -rwxr-xr-x 1 root root 1986848 Mar 16 22:14 /usr/local/bin/force/force-l2ps Reducing the binary size is likely to improve the instruction cache hit rate even if we pessimistically assume that LTO didn't manage to make any other optimization. --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 09b948f9..3674f8b6 100755 --- a/Makefile +++ b/Makefile @@ -27,10 +27,15 @@ # Installation directory INSTALLDIR=/usr/local/bin +# Link time optimization flags. +ifeq ($(LTO),yes) + FLAGS_LTO = -flto +endif + # Libraries GDAL_INCLUDES = $(shell gdal-config --cflags) GDAL_LIBS = $(shell gdal-config --libs) -GDAL_FLAGS = -Wl,-rpath=/usr/lib +GDAL_FLAGS = $(FLAGS_LTO) -Wl,-rpath=/usr/lib GSL_INCLUDES = $(shell gsl-config --cflags) GSL_LIBS = $(shell gsl-config --libs) @@ -57,7 +62,7 @@ RSTATS_LIBS = $(shell R CMD config --ldflags | sed 's/ /\n/g' | grep '\-L') -lR ### Compiler # Compilation Flags -CFLAGS=-O3 -Wall -fopenmp +CFLAGS=-O3 -Wall $(FLAGS_LTO) -fopenmp #CFLAGS=-g -Wall -fopenmp GCC=gcc $(CFLAGS) From 1813a99141152686fbfef77b729f9db33ee6ea68 Mon Sep 17 00:00:00 2001 From: "Peter A. Jonsson" Date: Mon, 16 Mar 2026 23:13:42 +0100 Subject: [PATCH 2/2] Dockerfile: enable link-time optimization --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9e67ae6f..1de00dd3 100755 --- a/Dockerfile +++ b/Dockerfile @@ -75,7 +75,7 @@ COPY --link --chown=1000:1000 . . # Build, install, check FORCE RUN echo "building FORCE" && \ ./debug.sh $debug && \ - make -j$(nproc) $build + make LTO=yes -j$(nproc) $build FROM internal_base AS force