automake: ask the linker to do garbage collection
authorEmil Velikov <emil.l.velikov@gmail.com>
Tue, 11 Mar 2014 17:58:08 +0000 (17:58 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Mon, 31 Mar 2014 13:56:14 +0000 (14:56 +0100)
By doing GC the linker removes all the symbols that are not referenced
and/or used by the final library. This results in a saving of ~100K
up-to ~600K per (stripped) binary (classic vs gallium drivers).

If interested one can ask the compiler to print the sections that are
removed using -Wl,--print-gc-sections.

v2: Check if ld supports the flag before using it.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Matt Turner <mattst88@gmail.com> (v1)
20 files changed:
configure.ac
src/egl/main/Makefile.am
src/egl/wayland/wayland-egl/Makefile.am
src/gallium/Automake.inc
src/gallium/targets/egl-static/Makefile.am
src/gallium/targets/gbm/Makefile.am
src/gallium/targets/libgl-xlib/Makefile.am
src/gallium/targets/opencl/Makefile.am
src/gallium/targets/osmesa/Makefile.am
src/gallium/targets/pipe-loader/Makefile.am
src/gallium/targets/xa/Makefile.am
src/gbm/Makefile.am
src/glx/Makefile.am
src/mapi/es1api/Makefile.am
src/mapi/es2api/Makefile.am
src/mapi/shared-glapi/Makefile.am
src/mapi/vgapi/Makefile.am
src/mesa/drivers/dri/Makefile.am
src/mesa/drivers/osmesa/Makefile.am
src/mesa/drivers/x11/Makefile.am

index 3055de67a7e8b19a1d64df0ff8bf52549871e5b5..af1b0d1fa400c40f0e9c07b4c98ca76ba1211471 100644 (file)
@@ -315,6 +315,22 @@ if test "x$enable_debug" = xyes; then
     fi
 fi
 
+dnl
+dnl Check if linker supports garbage collection
+dnl
+save_LDFLAGS=$LDFLAGS
+LDFLAGS="$LDFLAGS -Wl,--gc-sections"
+AC_MSG_CHECKING([whether ld supports --gc-sections])
+AC_LINK_IFELSE(
+    [AC_LANG_SOURCE([static char UnusedFunc() { return 5; } int main() { return 0;}])],
+    [AC_MSG_RESULT([yes])
+        GC_SECTIONS="-Wl,--gc-sections";],
+    [AC_MSG_RESULT([no])
+        GC_SECTIONS="";])
+LDFLAGS=$save_LDFLAGS
+
+AC_SUBST([GC_SECTIONS])
+
 dnl
 dnl compatibility symlinks
 dnl
index 57c9ccd6abb029b080ae1121c2b21bd797f5fdce..e4c2539f73c6bb9422dcc9be56bc8f3ad6ef81e7 100644 (file)
@@ -77,6 +77,7 @@ libEGL_la_LDFLAGS = \
        -no-undefined \
        -version-number 1:0 \
        -Wl,-Bsymbolic \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 if HAVE_EGL_PLATFORM_X11
index 3c2673a648638049291746177a58d27321899eed..d3fe11769ecf5c0877f8356319d199e31e01f3cc 100644 (file)
@@ -11,6 +11,7 @@ libwayland_egl_la_SOURCES = wayland-egl.c
 libwayland_egl_la_LDFLAGS = \
        -no-undefined \
        -version-info 1 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 TESTS = wayland-egl-symbols-check
index 1151f916bef7f353e51719090cb07b84cbd0fcca..56f1433a0f8533e584ac65d5296d05fd303a50c2 100644 (file)
@@ -57,6 +57,7 @@ GALLIUM_DRI_LINKER_FLAGS = \
        -shared \
        -module \
        -avoid-version \
+       $(GC_SECTIONS) \
        -Wl,--version-script=$(DRI_VERSION_SCRIPT)
 
 GALLIUM_VDPAU_LINKER_FLAGS = \
@@ -65,6 +66,7 @@ GALLIUM_VDPAU_LINKER_FLAGS = \
        -no-undefined \
        -version-number $(VDPAU_MAJOR):$(VDPAU_MINOR) \
        -export-symbols-regex $(VDPAU_EXPORTS) \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 GALLIUM_XVMC_LINKER_FLAGS = \
@@ -73,6 +75,7 @@ GALLIUM_XVMC_LINKER_FLAGS = \
        -no-undefined \
        -version-number $(XVMC_MAJOR):$(XVMC_MINOR) \
        -export-symbols-regex '^XvMC' \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 GALLIUM_OMX_LINKER_FLAGS = \
@@ -80,6 +83,7 @@ GALLIUM_OMX_LINKER_FLAGS = \
        -module \
        -no-undefined \
        -export-symbols-regex $(EXPORTS) \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 GALLIUM_VDPAU_LIB_DEPS = \
index 55eb3baaa06574a35d4c70b499c3d91442fe2361..58ecf697ce945adfb479ad6816b8694061eac570 100644 (file)
@@ -48,6 +48,7 @@ AM_LDFLAGS = \
        -module \
        -no-undefined \
        -avoid-version \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined \
        -Wl,--version-script=$(top_srcdir)/src/gallium/targets/egl-static/egl.link
 
index c109ddbb463be68b80f5c2c87335d461906db5b5..22b4826391e14095cbf1647e9bf8891106ef8bb9 100644 (file)
@@ -70,6 +70,7 @@ gbm_gallium_drm_la_LDFLAGS = \
        -module \
        -no-undefined \
        -avoid-version \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 if HAVE_MESA_LLVM
index d7aec7b5b509181bbaa7e256186a1694d3324493..ef3d23ebcd9e5eb1142b035d66d578a4759dfc70 100644 (file)
@@ -47,6 +47,7 @@ libGL_la_SOURCES = xlib.c
 libGL_la_LDFLAGS = \
        -no-undefined \
        -version-number $(GL_MAJOR):$(GL_MINOR):$(GL_TINY) \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 libGL_la_LIBADD = \
index b401d10d7a784394d5867e2920baccc582446ef9..aae31ff33660995e4c5dc00caf2b136e9a78e5b6 100644 (file)
@@ -6,6 +6,7 @@ lib@OPENCL_LIBNAME@_la_LDFLAGS = \
        $(LLVM_LDFLAGS) \
        -no-undefined \
        -version-number 1:0 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 
index 651fc5d2b4548f1e2d7ddf38314933ebaf2e2baa..559135cc5fe86e505480e8e68585b3929f81fe55 100644 (file)
@@ -43,6 +43,7 @@ lib@OSMESA_LIB@_la_LDFLAGS = \
        -module \
        -no-undefined \
        -version-number @OSMESA_VERSION@ \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 
index 00823fe5bdde13573b72677e79c32991d07205e6..fa463addcc5f25337fae3077ad6945ce14f2546d 100644 (file)
@@ -49,6 +49,7 @@ AM_LDFLAGS = \
        -module \
        -no-undefined \
        -avoid-version \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined \
        -Wl,--version-script=$(top_srcdir)/src/gallium/targets/pipe-loader/pipe.link
 
index 214c51df883b8fdabf9eaa0a5bb38b03262b1dda..21f29cfa65e38ccd9d950111cb04bd75fd5a8eea 100644 (file)
@@ -67,6 +67,7 @@ endif
 libxatracker_la_LDFLAGS = \
        -no-undefined \
        -version-number $(XA_MAJOR):$(XA_MINOR):$(XA_TINY) \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 if HAVE_MESA_LLVM
index c71a974015baabad569cf093438c6e86039faedd..ea06ce1607d4b5ae814529bd02e85d8a1b39d6a4 100644 (file)
@@ -22,6 +22,7 @@ libgbm_la_SOURCES = \
 libgbm_la_LDFLAGS = \
        -no-undefined \
        -version-info 1:0 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 libgbm_la_LIBADD = \
index 0c99c0709d644354e2388404a7b0d00646d3b002..aa7666aa93cccb379a5150edaae85ca81e5e1da5 100644 (file)
@@ -112,6 +112,7 @@ GL_LDFLAGS = \
        -no-undefined \
        -version-number 1:2 \
        -Wl,-Bsymbolic \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 lib@GL_LIB@_la_SOURCES =
index b9581184a967472232a3f93dfe7b6adb2a6d254f..febb137eafa71210c617b7b2f6c237b12cb75f6e 100644 (file)
@@ -47,6 +47,7 @@ libGLESv1_CM_la_LIBADD = $(GLESv1_CM_LIB_DEPS)
 libGLESv1_CM_la_LDFLAGS = \
        -no-undefined \
        -version-number 1:1 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 if HAVE_SHARED_GLAPI
index 1fb6d7c960482eb6a112a8979151ebcab06a9fbf..e694a36e5d3fc782c71841a73e05922bde33f530 100644 (file)
@@ -51,6 +51,7 @@ libGLESv2_la_LIBADD = $(GLESv2_LIB_DEPS)
 libGLESv2_la_LDFLAGS = \
        -no-undefined \
        -version-number 2 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 if HAVE_SHARED_GLAPI
index 7e1068fdfec6b1001c25c75fdc768c191819fa0e..33a939a90f9d25df6abe439c91108873be600da8 100644 (file)
@@ -11,6 +11,7 @@ libglapi_la_SOURCES = $(MAPI_GLAPI_FILES)
 libglapi_la_LIBADD = $(PTHREAD_LIBS) $(SELINUX_LIBS)
 libglapi_la_LDFLAGS = \
        -no-undefined \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 include $(GLAPI)/gen/glapi_gen.mk
index f85addc7c3165b26c86f62ef25931727bcd889ae..f946b9bb6f95528281261c13020c8394d86d9734 100644 (file)
@@ -47,6 +47,7 @@ libOpenVG_la_LIBADD = $(VG_LIB_DEPS)
 libOpenVG_la_LDFLAGS = \
        -no-undefined \
        -version-number 1 \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 vgapi_tmp.h: $(srcdir)/vgapi.csv $(top_srcdir)/src/mapi/mapi_abi.py
index 17ac76be11f9e71cbf208cdc14aebeef4f7ada0c..f1fee122cb78bcee0872f4e6b92574e37cd032dc 100644 (file)
@@ -53,6 +53,7 @@ mesa_dri_drivers_la_SOURCES =
 mesa_dri_drivers_la_LDFLAGS = \
         -module -avoid-version -shared \
         -Wl,-Bsymbolic \
+        $(GC_SECTIONS) \
         $()
 mesa_dri_drivers_la_LIBADD = \
         ../../libmesa.la \
index cfab70216aca97a05823df031fb44fae0ea36642..b133fd679220669f1a14f5b71644793baea4f2c4 100644 (file)
@@ -39,6 +39,7 @@ lib@OSMESA_LIB@_la_LDFLAGS = \
        -module \
        -no-undefined \
        -version-number @OSMESA_VERSION@ \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 
index 4c63d59a57cf8910e271934c71b9111658629107..2b38ad31101d336f56a906793f17b0b6a88634ce 100644 (file)
@@ -64,6 +64,7 @@ lib@GL_LIB@_la_LIBADD = \
 lib@GL_LIB@_la_LDFLAGS = \
        -no-undefined \
        -version-number $(GL_MAJOR):$(GL_MINOR):$(GL_PATCH) \
+       $(GC_SECTIONS) \
        -Wl,--no-undefined
 
 include $(top_srcdir)/install-lib-links.mk