[x264-devel] configure: Add link-time optimization support

Henrik Gramner git at videolan.org
Mon Jun 13 23:44:54 CEST 2016


x264 | branch: master | Henrik Gramner <henrik at gramner.com> | Sun Apr 24 14:10:22 2016 +0200| [92515e8ff73491ef8a44c85e0bee265ba5791070] | committer: Henrik Gramner

configure: Add link-time optimization support

Enabled by using the --enable-lto configuration option.

May give a slight performance improvement in some cases, but it can
also reduce performance in other cases (largely compiler-dependant)
so don't enable it by default. It also makes compilation (and linking
in particular) a fair bit slower.

Note that some older versions of GNU binutils will incorrectly warn
about "memset used with constant zero length parameter" when linking
using LTO. This is due to a bug in binutils and can safely be ignored.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=92515e8ff73491ef8a44c85e0bee265ba5791070
---

 configure |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index dcf7765..ab6ca2f 100755
--- a/configure
+++ b/configure
@@ -35,6 +35,7 @@ Configuration options:
 
 Advanced options:
   --disable-asm            disable platform-specific assembly optimizations
+  --enable-lto             enable link-time optimization
   --enable-debug           add -g
   --enable-gprof           add -pg
   --enable-strip           add -s
@@ -346,6 +347,7 @@ thread="auto"
 swscale="auto"
 asm="auto"
 interlaced="yes"
+lto="no"
 debug="no"
 gprof="no"
 strip="no"
@@ -452,6 +454,9 @@ for opt do
         --disable-swscale)
             swscale="no"
             ;;
+        --enable-lto)
+            lto="auto"
+            ;;
         --enable-debug)
             debug="yes"
             ;;
@@ -503,11 +508,21 @@ done
 [ "$cli" = "no" -a "$shared" = "no" -a "$static" = "no" ] && die "Nothing to build. Enable cli, shared or static."
 
 CC="${CC-${cross_prefix}gcc}"
-AR="${AR-${cross_prefix}ar}"
-RANLIB="${RANLIB-${cross_prefix}ranlib}"
 STRIP="${STRIP-${cross_prefix}strip}"
 INSTALL="${INSTALL-install}"
 
+# ar and ranlib doesn't load the LTO plugin by default, prefer the gcc-prefixed wrappers which does.
+if ${cross_prefix}gcc-ar --version >/dev/null 2>&1; then
+    AR="${AR-${cross_prefix}gcc-ar}"
+else
+    AR="${AR-${cross_prefix}ar}"
+fi
+if ${cross_prefix}gcc-ranlib --version >/dev/null 2>&1; then
+    RANLIB="${RANLIB-${cross_prefix}gcc-ranlib}"
+else
+    RANLIB="${RANLIB-${cross_prefix}ranlib}"
+fi
+
 if [ "x$host" = x ]; then
     host=`${SRCPATH}/config.guess`
 fi
@@ -1177,7 +1192,13 @@ if [ "$debug" = "yes" ]; then
     RCFLAGS="$RCFLAGS -DDEBUG"
 else
     CFLAGS="-O3 -ffast-math $CFLAGS"
+    if [ "$lto" = "auto" ] && [ $compiler = GNU ] && cc_check "" "-flto" ; then
+        lto="yes"
+        CFLAGS="$CFLAGS -flto"
+        LDFLAGS="$LDFLAGS -O3 -flto"
+    fi
 fi
+[ "$lto" = "auto" ] && lto="no"
 
 if cc_check '' -fno-tree-vectorize ; then
     CFLAGS="$CFLAGS -fno-tree-vectorize"
@@ -1462,6 +1483,7 @@ gpl:           $gpl
 thread:        $thread
 opencl:        $opencl
 filters:       $filters
+lto:           $lto
 debug:         $debug
 gprof:         $gprof
 strip:         $strip



More information about the x264-devel mailing list