[vlc-commits] [Git][videolan/vlc][3.0.x] 7 commits: buildsystem: enable dead code stripping at link time
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sun Oct 4 07:23:32 UTC 2026
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
09ceeee7 by Brandon Li at 2026-10-04T06:58:56+00:00
buildsystem: enable dead code stripping at link time
(cherry picked from commit e367fe5c26b18dcd789a73061ec79680889b831c) (edited)
edited:
- VLC 3 doesn't have meson
- VLC 3 doesn't have sam3
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>
- - - - -
fef772a1 by Steve Lhomme at 2026-10-04T06:58:56+00:00
configure: enable split sections + dead section stripping by default
You can use --disable-split-sections to turn it of for all VLC code.
- - - - -
8c342d89 by Steve Lhomme at 2026-10-04T06:58:56+00:00
contrib: add --enable-sections option
To turn on -fdata-sections -ffunction-sections compiler flags.
- - - - -
e5eb3183 by Steve Lhomme at 2026-10-04T06:58:56+00:00
contrib: gmp: disable fdata-sections/ffunction-sections in Windows builds
It fails to link with some "foo" code.
It may be a Windows-only problem so only remove the flags on Windows.
- - - - -
083095b7 by Steve Lhomme at 2026-10-04T06:58:56+00:00
package/win32: add -fdata-sections -ffunction-sections to contribs
When combined with -gc-sections in the linker it can significantly reduce the
size of binaries.
- - - - -
4341222c by Steve Lhomme at 2026-10-04T06:58:56+00:00
package/macosx: add -fdata-sections -ffunction-sections to contribs
When combined with -gc-sections in the linker it can significantly reduce the
size of binaries.
- - - - -
8c32e9f0 by Steve Lhomme at 2026-10-04T06:58:56+00:00
package/snap: add -fdata-sections -ffunction-sections to contribs
When combined with -gc-sections in the linker it can significantly reduce the
size of binaries.
- - - - -
8 changed files:
- configure.ac
- contrib/bootstrap
- contrib/src/gmp/rules.mak
- contrib/src/main.mak
- extras/package/macosx/build.sh
- extras/package/snap/snapcraft.yaml
- extras/package/win32/build.sh
- modules/video_filter/Makefile.am
Changes:
=====================================
configure.ac
=====================================
@@ -385,6 +385,48 @@ case "${host_os}" in
;;
esac
+dnl
+dnl Drops unused symbols.
+dnl ELF linkers use --gc-sections, while Mach-O uses -dead_strip.
+dnl
+AC_MSG_CHECKING([for linker dead-code stripping flag])
+GC_SECTIONS_LDFLAGS=""
+VLC_SAVE_FLAGS
+AX_APPEND_FLAG([-Wl,--gc-sections], [LDFLAGS])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+ [GC_SECTIONS_LDFLAGS="-Wl,--gc-sections"], [])
+VLC_RESTORE_FLAGS
+AS_IF([test -z "${GC_SECTIONS_LDFLAGS}"], [
+ VLC_SAVE_FLAGS
+ AX_APPEND_FLAG([-Wl,-dead_strip], [LDFLAGS])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+ [GC_SECTIONS_LDFLAGS="-Wl,-dead_strip"], [])
+ VLC_RESTORE_FLAGS
+])
+AS_IF([test -n "${GC_SECTIONS_LDFLAGS}"],
+ [AC_MSG_RESULT([${GC_SECTIONS_LDFLAGS}])],
+ [AC_MSG_RESULT([none])])
+AC_SUBST([GC_SECTIONS_LDFLAGS])
+
+AC_ARG_ENABLE([split-sections],
+ AS_HELP_STRING([--split-sections],
+ [Split compiled sections and remove unused ones (default enabled)]))
+AS_IF([test "${enable_split_sections}" != "no" ], [
+ AS_IF([test -z "${GC_SECTIONS_LDFLAGS}"], [
+ AS_IF([test -n "${enable_split_sections}"], [
+ AC_MSG_ERROR([Split sections enabled but not supported by linker!])
+ ],[
+ AC_MSG_WARN([Split sections enabled but not supported by linker.])
+ ])
+ ],[
+ AX_APPEND_FLAG([${GC_SECTIONS_LDFLAGS}], [LDFLAGS])
+ AX_CHECK_COMPILE_FLAG([-fdata-sections -ffunction-sections], [
+ AX_APPEND_FLAG([-fdata-sections -ffunction-sections], [CFLAGS])
+ AX_APPEND_FLAG([-fdata-sections -ffunction-sections], [CXXFLAGS])
+ ])
+ ])
+])
+
dnl WinRT
AC_ARG_ENABLE(winstore_app,
AS_HELP_STRING([--enable-winstore-app],
=====================================
contrib/bootstrap
=====================================
@@ -37,6 +37,7 @@ usage()
echo " --disable-optim disable optimization in libraries"
echo " --enable-pdb generate debug information in PDB format"
echo " --enable-bitcode generate bitcode information"
+ echo " --enable-sections enable section splitting with compiler"
}
BUILD=
@@ -53,6 +54,7 @@ AD_CLAUSES=
WITH_OPTIMIZATION="1"
ENABLE_PDB=
ENABLE_BITCODE=
+ENABLE_SECTION_SPLIT=
while test -n "$1"
do
@@ -88,6 +90,9 @@ do
--enable-bitcode)
ENABLE_BITCODE=1
;;
+ --enable-sections)
+ ENABLE_SECTION_SPLIT=1
+ ;;
--enable-small)
ENABLE_SMALL=1
;;
@@ -271,6 +276,7 @@ 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_PDB" || add_make_enabled "ENABLE_PDB"
+test -z "$ENABLE_SECTION_SPLIT" || add_make_enabled "ENABLE_SECTION_SPLIT"
if [ "`uname -o 2>/dev/null`" = "Msys" ]; then
add_make "CMAKE_GENERATOR := MSYS Makefiles"
=====================================
contrib/src/gmp/rules.mak
=====================================
@@ -14,7 +14,12 @@ GMP_CONF += --disable-assembly
endif
endif
# gmp requires C99 and is _not_ forward-compatible with C23.
+ifdef HAVE_WIN32
+# disable sections splitting as it fails to link with "foo"
+GMP_CONF += CFLAGS="$(CFLAGS_NO_SECTIONS) -std=gnu99"
+else
GMP_CONF += CFLAGS="$(CFLAGS) -std=gnu99"
+endif
ifdef HAVE_WIN32
ifeq ($(ARCH),arm)
=====================================
contrib/src/main.mak
=====================================
@@ -345,6 +345,16 @@ CFLAGS := $(CFLAGS) -fembed-bitcode
CXXFLAGS := $(CXXFLAGS) -fembed-bitcode
endif
+# opt-out flags when --enable-sections is used
+CFLAGS_NO_SECTIONS := $(CFLAGS)
+CXXFLAGS_NO_SECTIONS := $(CXXFLAGS)
+
+ifdef ENABLE_SECTION_SPLIT
+CFLAGS := $(CFLAGS) -fdata-sections -ffunction-sections
+CXXFLAGS := $(CXXFLAGS) -fdata-sections -ffunction-sections
+endif
+
+
# Add these flags after CMake consumed the CFLAGS/CXXFLAGS
# CMake handles the optimization level with CMAKE_BUILD_TYPE
HOSTVARS_CMAKE := \
@@ -359,17 +369,23 @@ HOSTVARS_CMAKE := \
# incorrectly report they have not, even if they have.
ifndef WITH_OPTIMIZATION
CFLAGS := $(CFLAGS) -g -O0
+CFLAGS_NO_SECTIONS := $(CFLAGS_NO_SECTIONS) -g -O0
CXXFLAGS := $(CXXFLAGS) -g -O0
+CXXFLAGS_NO_SECTIONS := $(CXXFLAGS_NO_SECTIONS) -g -O0
else
CFLAGS := $(CFLAGS) -g -O2
+CFLAGS_NO_SECTIONS := $(CFLAGS_NO_SECTIONS) -g -O2
CXXFLAGS := $(CXXFLAGS) -g -O2
+CXXFLAGS_NO_SECTIONS := $(CXXFLAGS_NO_SECTIONS) -g -O2
endif
ifdef ENABLE_PDB
ifdef HAVE_CLANG
ifneq ($(findstring $(ARCH),i686 x86_64),)
CFLAGS := $(CFLAGS) -gcodeview
+CFLAGS_NO_SECTIONS := $(CFLAGS_NO_SECTIONS) -gcodeview
CXXFLAGS := $(CXXFLAGS) -gcodeview
+CXXFLAGS_NO_SECTIONS := $(CXXFLAGS_NO_SECTIONS) -gcodeview
endif
endif
endif
=====================================
extras/package/macosx/build.sh
=====================================
@@ -254,7 +254,7 @@ export EXTRA_LDFLAGS="-Wl,-syslibroot,$SDKROOT -mmacosx-version-min=$MINIMAL_OSX
# xcodebuild only allows to set a build-in sdk, not a custom one. Therefore use the default included SDK here
export XCODE_FLAGS="MACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -sdk macosx WARNING_CFLAGS=-Werror=partial-availability"
-CONTRIBFLAGS=
+CONTRIBFLAGS="--enable-sections"
if [ "$PACKAGETYPE" = "u" ]; then
# release package should have sparkle, breakpad, growl
CONTRIBFLAGS="$CONTRIBFLAGS --enable-sparkle --enable-breakpad --enable-growl"
=====================================
extras/package/snap/snapcraft.yaml
=====================================
@@ -89,6 +89,7 @@ parts:
cd contrib && mkdir linux && cd linux
../bootstrap \
--host=${CRAFT_ARCH_TRIPLET_BUILD_FOR} \
+ --enable-sections \
--enable-libdsm \
--enable-dvdcss
if [ -v VLC_PREBUILT_CONTRIBS_URL ]; then
=====================================
extras/package/win32/build.sh
=====================================
@@ -351,6 +351,8 @@ if [ -n "$DISABLEGUI" ]; then
CONTRIBFLAGS="$CONTRIBFLAGS --disable-qt --disable-qtsvg --disable-qtdeclarative --disable-qtgraphicaleffects --disable-qtquickcontrols2"
fi
+CONTRIBFLAGS="$CONTRIBFLAGS --enable-sections"
+
if [ "$COMPILING_WITH_CLANG" -gt 0 ]; then
# avoid using gcc-ar with the clang toolchain, if both are installed
VLC_AR="$TRIPLET-ar"
=====================================
modules/video_filter/Makefile.am
=====================================
@@ -154,7 +154,7 @@ video_filter_LTLIBRARIES += libdeinterlace_plugin.la
libopencv_wrapper_plugin_la_SOURCES = video_filter/opencv_wrapper.c
libopencv_wrapper_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(OPENCV_CFLAGS)
libopencv_wrapper_plugin_la_LIBADD = $(OPENCV_LIBS)
-libopencv_wrapper_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(video_filterdir)'
+libopencv_wrapper_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(GC_SECTIONS_LDFLAGS) -rpath '$(video_filterdir)'
video_filter_LTLIBRARIES += $(LTLIBopencv_wrapper)
EXTRA_LTLIBRARIES += libopencv_wrapper_plugin.la
@@ -172,6 +172,6 @@ video_filter_LTLIBRARIES += libblend_plugin.la
libopencv_example_plugin_la_SOURCES = video_filter/opencv_example.cpp video_filter/filter_event_info.h
libopencv_example_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(OPENCV_CFLAGS)
libopencv_example_plugin_la_LIBADD = $(OPENCV_LIBS)
-libopencv_example_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(video_filterdir)'
+libopencv_example_plugin_la_LDFLAGS = $(AM_LDFLAGS) $(GC_SECTIONS_LDFLAGS) -rpath '$(video_filterdir)'
video_filter_LTLIBRARIES += $(LTLIBopencv_example)
EXTRA_LTLIBRARIES += libopencv_example_plugin.la
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4061984debf2bb2c9808bdf25b4230569a0f91d5...8c32e9f0aa85c606f8837f05b7709223c9ccfcbc
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/4061984debf2bb2c9808bdf25b4230569a0f91d5...8c32e9f0aa85c606f8837f05b7709223c9ccfcbc
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