[vlc-commits] [Git][videolan/vlc][master] 8 commits: contrib: separate CFLAGS/CXXFLAGS that should not be passed to CMake/meson

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Jun 10 09:08:08 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
555bab47 by Steve Lhomme at 2026-06-10T08:28:58+00:00
contrib: separate CFLAGS/CXXFLAGS that should not be passed to CMake/meson

- - - - -
35becbd5 by Steve Lhomme at 2026-06-10T08:28:58+00:00
configure: fix libssp.a detection when LTO is enabled

This is failing when LTO is used with llvm-mingw: https://github.com/mstorsjo/llvm-mingw/issues/275
Even though we use the LLVM ar and ranlib, Linking through the compiler doesn't do the proper trick.
So we have to do it ourselves.

- - - - -
d001058b by Steve Lhomme at 2026-06-10T08:28:58+00:00
contrib: add an option to enable Link Time Optimization

- - - - -
e598ce39 by Steve Lhomme at 2026-06-10T08:28:58+00:00
contrib: ffmpeg: enable Link Time Optimization using the official flag

- - - - -
3f4eb904 by Steve Lhomme at 2026-06-10T08:28:58+00:00
contrib: qt: enable Link Time Optimization with the official flag

And don't pass extra CFLAGS/CXXFLAGS that we wouldn't pass to CMake.

- - - - -
4562c673 by Steve Lhomme at 2026-06-10T08:28:58+00:00
package/win32: add -t option to enable Link Time Optimization

- - - - -
11e8dca1 by Steve Lhomme at 2026-06-10T08:28:58+00:00
package/win32: warn when Link Time Optimization is not used in Release mode

- - - - -
b4fff265 by Steve Lhomme at 2026-06-10T08:28:58+00:00
CI: enable LTO in windows LLVM nightlies

- - - - -


7 changed files:

- configure.ac
- contrib/bootstrap
- contrib/src/ffmpeg/rules.mak
- contrib/src/main.mak
- contrib/src/qt/rules.mak
- extras/ci/gitlab-ci.yml
- extras/package/win32/build.sh


Changes:

=====================================
configure.ac
=====================================
@@ -1602,7 +1602,12 @@ AS_IF([test "${enable_ssp}" != "no" -a "${enable_optimizations}" != "no"], [
         AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[char buf[100]; fgets(buf, sizeof(buf), stdin);]])],[
           ac_cv_ld_ssp="yes"
         ], [
-          ac_cv_ld_ssp="no"
+          LDFLAGS="${LDFLAGS} -Wl,--require-defined,__stack_chk_guard"
+          AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>]], [[char buf[100]; fgets(buf, sizeof(buf), stdin);]])],[
+            ac_cv_ld_ssp="yes"
+          ], [
+            ac_cv_ld_ssp="no"
+          ])
         ])
       ])
       AS_IF([test "${ac_cv_ld_ssp}" = "no"], [VLC_RESTORE_FLAGS])


=====================================
contrib/bootstrap
=====================================
@@ -35,6 +35,7 @@ usage()
 	echo "  --enable-ad-clauses configure to build packages with advertising clauses"
 	echo "                   (USE AT YOUR OWN LEGAL RISKS)"
 	echo "  --disable-optim  disable optimization in libraries"
+	echo "  --enable-lto     use Link Time Optimization"
 	echo "  --enable-pdb     generate debug information in PDB format"
 	echo "  --enable-bitcode generate bitcode information"
 }
@@ -82,6 +83,9 @@ do
 		--disable-optim)
 			WITH_OPTIMIZATION=
 			;;
+		--enable-lto)
+			ENABLE_LTO=1
+			;;
 		--enable-pdb)
 			ENABLE_PDB=1
 			;;
@@ -258,6 +262,7 @@ test -z "$GPL" || add_make_enabled "GPL"
 test -z "$GNUV3" || add_make_enabled "GNUV3"
 test -z "$AD_CLAUSES" || add_make_enabled "AD_CLAUSES"
 test -z "$WITH_OPTIMIZATION" || add_make_enabled "WITH_OPTIMIZATION"
+test -z "$ENABLE_LTO" || add_make_enabled "ENABLE_LTO"
 test -z "$ENABLE_PDB" || add_make_enabled "ENABLE_PDB"
 
 LN_S="ln -s"


=====================================
contrib/src/ffmpeg/rules.mak
=====================================
@@ -46,6 +46,9 @@ endif
 ifdef ENABLE_PDB
 FFMPEGCONF += --ln_s=false
 endif
+ifdef ENABLE_LTO
+FFMPEGCONF += --enable-lto
+endif
 
 DEPS_ffmpeg = zlib $(DEPS_zlib) gsm $(DEPS_gsm) openjpeg $(DEPS_openjpeg)
 


=====================================
contrib/src/main.mak
=====================================
@@ -363,6 +363,7 @@ endif
 
 # Add these flags after CMake consumed the CFLAGS/CXXFLAGS
 # CMake handles the optimization level with CMAKE_BUILD_TYPE
+# CMake handles LTO flags with INTERPROCEDURAL_OPTIMIZATION
 HOSTVARS_CMAKE := \
 	CPPFLAGS="$(CPPFLAGS)" \
 	CFLAGS="$(CFLAGS)" \
@@ -374,22 +375,27 @@ HOSTVARS_CMAKE := \
 # and cause the check if symbols have underscore prefix to
 # incorrectly report they have not, even if they have.
 ifndef WITH_OPTIMIZATION
-CFLAGS := $(CFLAGS) -g -O0
-CXXFLAGS := $(CXXFLAGS) -g -O0
+AUTOTOOLS_CFLAGS := $(AUTOTOOLS_CFLAGS) -g -O0
+AUTOTOOLS_CXXFLAGS := $(AUTOTOOLS_CXXFLAGS) -g -O0
 else
-CFLAGS := $(CFLAGS) -g -O2
-CXXFLAGS := $(CXXFLAGS) -g -O2
+AUTOTOOLS_CFLAGS := $(AUTOTOOLS_CFLAGS) -g -O2
+AUTOTOOLS_CXXFLAGS := $(AUTOTOOLS_CXXFLAGS) -g -O2
+endif
+
+ifdef ENABLE_LTO
+AUTOTOOLS_CFLAGS := $(AUTOTOOLS_CFLAGS) -flto
+AUTOTOOLS_CXXFLAGS := $(AUTOTOOLS_CXXFLAGS) -flto
 endif
 
 HOSTVARS := $(HOSTTOOLS) \
 	CPPFLAGS="$(CPPFLAGS)" \
-	CFLAGS="$(CFLAGS)" \
-	CXXFLAGS="$(CXXFLAGS)" \
+	CFLAGS="$(CFLAGS) $(AUTOTOOLS_CFLAGS)" \
+	CXXFLAGS="$(CXXFLAGS) $(AUTOTOOLS_CXXFLAGS)" \
 	LDFLAGS="$(LDFLAGS)"
 HOSTVARS_PIC := $(HOSTTOOLS) \
 	CPPFLAGS="$(CPPFLAGS) $(PIC)" \
-	CFLAGS="$(CFLAGS) $(PIC)" \
-	CXXFLAGS="$(CXXFLAGS) $(PIC)" \
+	CFLAGS="$(CFLAGS) $(AUTOTOOLS_CFLAGS) $(PIC)" \
+	CXXFLAGS="$(CXXFLAGS) $(AUTOTOOLS_CXXFLAGS) $(PIC)" \
 	LDFLAGS="$(LDFLAGS)"
 
 BUILDCOMMONCONF := --disable-dependency-tracking
@@ -518,6 +524,9 @@ CMAKE += -DCMAKE_BUILD_TYPE=Debug
 else
 CMAKE += -DCMAKE_BUILD_TYPE=RelWithDebInfo
 endif
+ifdef ENABLE_LTO
+CMAKE += -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_POLICY_DEFAULT_CMP0069:STRING=NEW
+endif
 ifdef HAVE_WIN32
 CMAKE += -DCMAKE_DEBUG_POSTFIX:STRING=
 endif
@@ -536,6 +545,9 @@ MESONFLAGS += --buildtype debug
 else
 MESONFLAGS += --buildtype debugoptimized
 endif
+ifdef ENABLE_LTO
+MESONFLAGS += -Db_lto=true
+endif
 ifdef HAVE_BITCODE_ENABLED
 MESONFLAGS += -Db_bitcode=true
 endif


=====================================
contrib/src/qt/rules.mak
=====================================
@@ -105,6 +105,10 @@ QTBASE_COMMON_CONFIG += -DFEATURE_stack_clash_protection=OFF
 endif
 endif
 
+ifdef ENABLE_LTO
+QTBASE_CONFIG += -DFEATURE_ltcg=ON
+endif
+
 QTBASE_CONFIG += $(QTBASE_COMMON_CONFIG) \
     -DFEATURE_gif=OFF \
 	-DFEATURE_harfbuzz=ON -DFEATURE_system_harfbuzz=ON -DFEATURE_jpeg=ON -DFEATURE_system_jpeg=ON \


=====================================
extras/ci/gitlab-ci.yml
=====================================
@@ -220,7 +220,7 @@ nightly-win32-llvm:
         name: $VLC_WIN_LLVM_MSVCRT_IMAGE
     variables:
         <<: *variables-win32
-        LIBVLC_EXTRA_BUILD_FLAGS: -D /
+        LIBVLC_EXTRA_BUILD_FLAGS: -D / -t
 
 nightly-win64:
     extends: .nightly-win-common
@@ -234,7 +234,7 @@ nightly-win64-llvm:
         name: $VLC_WIN_LLVM_MSVCRT_IMAGE
     variables:
         <<: *variables-win64
-        LIBVLC_EXTRA_BUILD_FLAGS: -D /
+        LIBVLC_EXTRA_BUILD_FLAGS: -D / -t
 
 nightly-win64-llvm-meson:
     extends: .nightly-win-common
@@ -242,7 +242,7 @@ nightly-win64-llvm-meson:
         name: $VLC_WIN_LLVM_MSVCRT_IMAGE
     variables:
         <<: *variables-win64
-        LIBVLC_EXTRA_BUILD_FLAGS: -D / -m
+        LIBVLC_EXTRA_BUILD_FLAGS: -D / -m -t
 
 nightly-win64-ucrt-llvm:
     extends: .nightly-win-common
@@ -252,7 +252,7 @@ nightly-win64-ucrt-llvm:
         <<: *variables-win64
         VLCARCH: win64-ucrt
         TRIPLET: $HOST_ARCH-ucrt-w64-mingw32
-        LIBVLC_EXTRA_BUILD_FLAGS: -D /
+        LIBVLC_EXTRA_BUILD_FLAGS: -D / -t
         UWP_EXTRA_BUILD_FLAGS: -u -x -S 0x0A000006
 
 nightly-win64-arm-llvm:
@@ -263,7 +263,7 @@ nightly-win64-arm-llvm:
         <<: *variables-win64-arm
         VLCARCH: winarm64-ucrt
         TRIPLET: $HOST_ARCH-ucrt-w64-mingw32
-        LIBVLC_EXTRA_BUILD_FLAGS: -D /
+        LIBVLC_EXTRA_BUILD_FLAGS: -D / -t
         UWP_EXTRA_BUILD_FLAGS: -u -x -S 0x0A000006
 
 #


=====================================
extras/package/win32/build.sh
=====================================
@@ -31,6 +31,7 @@ OPTIONS:
    -d            Create PDB files during the build
    -D <win_path> Create PDB files during the build, map the VLC sources to <win_path>
                  e.g.: -D c:/sources/vlc
+   -t            Link Time Optimization (LTO)
    -x            Add extra checks when compiling
    -S <sdkver>   Use maximum Windows API version (0x06010000 Windows 7 by default)
    -u            Use the Universal C Runtime (instead of msvcrt)
@@ -46,7 +47,7 @@ EOF
 }
 
 ARCH="x86_64"
-while getopts "hra:pcli:W:sb:dD:xS:uwzo:mg:" OPTION
+while getopts "hra:pcli:W:sb:dD:txS:uwzo:mg:" OPTION
 do
      case $OPTION in
          r)
@@ -84,6 +85,9 @@ do
              WITH_PDB="yes"
              PDB_MAP=$OPTARG
          ;;
+         t)
+             WITH_LTO="yes"
+         ;;
          x)
              EXTRA_CHECKS="yes"
          ;;
@@ -379,6 +383,9 @@ fi
 if [ -n "$DISABLEGUI" ]; then
     CONTRIBFLAGS="$CONTRIBFLAGS --disable-qt --disable-qtsvg --disable-qtdeclarative --disable-qtshadertools --disable-qtwayland"
 fi
+if [ -n "$WITH_LTO" ]; then
+    CONTRIBFLAGS="$CONTRIBFLAGS --enable-lto"
+fi
 
 if [ "$COMPILING_WITH_CLANG" -gt 0 ]; then
     # avoid using gcc-ar with the clang toolchain, if both are installed
@@ -481,6 +488,9 @@ if [ "$RELEASE" != "yes" ]; then
      CONFIGFLAGS="$CONFIGFLAGS --enable-debug"
      MCONFIGFLAGS="$MCONFIGFLAGS --buildtype debugoptimized"
 else
+    if [ -z "$WITH_LTO" ]; then
+        info "Warning: Link Time Optimization not used in Release mode (missing --enable-lto)"
+    fi
      CONFIGFLAGS="$CONFIGFLAGS --disable-debug"
      MCONFIGFLAGS="$MCONFIGFLAGS --buildtype release"
 fi
@@ -501,6 +511,11 @@ if [ -n "$EXTRA_CHECKS" ]; then
     CONFIGFLAGS="$CONFIGFLAGS --enable-extra-checks"
     MCONFIGFLAGS="$MCONFIGFLAGS -Dextra_checks=true"
 fi
+if [ -n "$WITH_LTO" ]; then
+    VLC_CFLAGS="$VLC_CFLAGS -flto"
+    VLC_CXXFLAGS="$VLC_CXXFLAGS -flto"
+    MCONFIGFLAGS="$MCONFIGFLAGS -Db_lto=true"
+fi
 if [ -n "$DISABLEGUI" ]; then
     CONFIGFLAGS="$CONFIGFLAGS --disable-qt --disable-skins2"
     MCONFIGFLAGS="$MCONFIGFLAGS -Dqt=disabled -Dskins2=disabled"



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/02220ef10c24166f3ebddacdb7fb3c6c96fcc155...b4fff265996f85b3745979bcbf1cba3915d03f67

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/02220ef10c24166f3ebddacdb7fb3c6c96fcc155...b4fff265996f85b3745979bcbf1cba3915d03f67
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list