[Mesa-dev] [PATCH] install: check for undefined symbols in shared libraries

Tapani Pälli tapani.palli at intel.com
Wed Aug 17 06:25:48 UTC 2016



On 08/16/2016 10:12 PM, Jan Ziak wrote:
> This patch ensures that shared libraries installed by Mesa do not contain
> any undefined symbols.
>
> The patch should help lowering the number of users experiencing undefined
> symbol errors with OpenGL apps.
>
> [http://google.sk/search?q=undefined+symbol:+_glapi_tls_Dispatch] 1250 results

There's some discussion in this bug if we should just autodetect this or 
maybe enable by default:

https://bugs.freedesktop.org/show_bug.cgi?id=72902


> The patched install process performs the checks necessary for eventual
> replacement of all RTLD_NOW with RTLD_LAZY in Mesa source code.
>
> It is out of Mesa's scope of responsibility to ensure that later modifications
> to non-Mesa libs such as libLLVM*.so do not break OpenGL apps.
>
> Signed-off-by: Jan Ziak (http://atom-symbol.net) <0xe2.0x9a.0x9b at gmail.com>
> ---
>  bin/dlopen-check.sh                   | 16 ++++++++++++++++
>  install-gallium-links.mk              |  4 ++++
>  install-lib-links.mk                  |  4 ++++
>  src/gallium/targets/dri/Makefile.am   |  5 ++++-
>  src/gallium/targets/va/Makefile.am    |  2 ++
>  src/gallium/targets/vdpau/Makefile.am |  2 ++
>  src/gallium/targets/xvmc/Makefile.am  |  2 ++
>  src/mesa/drivers/dri/Makefile.am      |  5 ++++-
>  8 files changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/bin/dlopen-check.sh b/bin/dlopen-check.sh
> new file mode 100755
> index 0000000..0a965ec
> --- /dev/null
> +++ b/bin/dlopen-check.sh
> @@ -0,0 +1,16 @@
> +#!/bin/bash
> +# Check shared libraries for undefined symbols
> +set -e
> +set -o pipefail
> +if [ $# == 0 ]; then
> +	echo "Usage: $0 SHARED-LIB..."
> +	exit 1
> +fi
> +UNDEFINED_SYMBOLS=$(ldd -d -r "$@" | { grep defined || true; })
> +if [ -n "$UNDEFINED_SYMBOLS" ]; then
> +	echo "$UNDEFINED_SYMBOLS" | sort | uniq | \
> +	while read -r LINE; do
> +		echo "error: $LINE"
> +	done
> +	exit 1
> +fi
> diff --git a/install-gallium-links.mk b/install-gallium-links.mk
> index ac5a499..5f6d696 100644
> --- a/install-gallium-links.mk
> +++ b/install-gallium-links.mk
> @@ -6,6 +6,10 @@ if HAVE_COMPAT_SYMLINKS
>  all-local : .install-gallium-links
>
>  .install-gallium-links : $(dri_LTLIBRARIES) $(egl_LTLIBRARIES) $(lib_LTLIBRARIES)
> +	if [ -n "$(shell find .libs -maxdepth 1 -name "*.so" -print -quit)" ]; then \
> +		LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +		$(top_srcdir)/bin/dlopen-check.sh .libs/*.so*; \
> +	fi
>  	$(AM_V_GEN)$(MKDIR_P) $(top_builddir)/$(LIB_DIR);	\
>  	link_dir=$(top_builddir)/$(LIB_DIR)/gallium;		\
>  	if test x$(egl_LTLIBRARIES) != x; then			\
> diff --git a/install-lib-links.mk b/install-lib-links.mk
> index 5fe9141..8de38cd 100644
> --- a/install-lib-links.mk
> +++ b/install-lib-links.mk
> @@ -6,6 +6,10 @@ if HAVE_COMPAT_SYMLINKS
>  all-local : .install-mesa-links
>
>  .install-mesa-links : $(lib_LTLIBRARIES)
> +	if [ -n "$(shell find .libs -maxdepth 1 -name "*.so" -print -quit)" ]; then \
> +		LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +		$(top_srcdir)/bin/dlopen-check.sh .libs/*.so*; \
> +	fi
>  	$(AM_V_GEN)$(MKDIR_P) $(top_builddir)/$(LIB_DIR);	\
>  	for f in $(join $(addsuffix .libs/,$(dir $(lib_LTLIBRARIES))),$(notdir $(lib_LTLIBRARIES:%.la=%.$(LIB_EXT)*))); do \
>  		if test -h .libs/$$f; then			\
> diff --git a/src/gallium/targets/dri/Makefile.am b/src/gallium/targets/dri/Makefile.am
> index 06ade45..86ac6ea 100644
> --- a/src/gallium/targets/dri/Makefile.am
> +++ b/src/gallium/targets/dri/Makefile.am
> @@ -136,7 +136,10 @@ endif
>
>  # hardlink each megadriver instance, but don't actually have
>  # gallium_dri.so in the set of final installed files.
> -install-data-hook:
> +install-data-hook: $(top_builddir)/$(LIB_DIR)/libGL.so
> +	LD_PRELOAD=$(top_builddir)/$(LIB_DIR)/libGL.so \
> +	LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +	$(top_srcdir)/bin/dlopen-check.sh $(DESTDIR)$(dridir)/gallium_dri.so
>  	for i in $(TARGET_DRIVERS); do                                  \
>  		ln -f $(DESTDIR)$(dridir)/gallium_dri.so                \
>  		      $(DESTDIR)$(dridir)/$${i}_dri.so;                 \
> diff --git a/src/gallium/targets/va/Makefile.am b/src/gallium/targets/va/Makefile.am
> index df825b7..b31bc2d 100644
> --- a/src/gallium/targets/va/Makefile.am
> +++ b/src/gallium/targets/va/Makefile.am
> @@ -70,6 +70,8 @@ endif
>  # hardlink each megadriver instance, but don't actually have
>  # gallium_drv_video.so in the set of final installed files.
>  install-data-hook:
> +	LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +	$(top_srcdir)/bin/dlopen-check.sh $(DESTDIR)$(vadir)/gallium_drv_video.so
>  	for i in $(TARGET_DRIVERS); do                                  \
>  		ln -f $(DESTDIR)$(vadir)/gallium_drv_video.so                \
>  		      $(DESTDIR)$(vadir)/$${i}_drv_video.so;                 \
> diff --git a/src/gallium/targets/vdpau/Makefile.am b/src/gallium/targets/vdpau/Makefile.am
> index d388f8b..ff70069 100644
> --- a/src/gallium/targets/vdpau/Makefile.am
> +++ b/src/gallium/targets/vdpau/Makefile.am
> @@ -106,6 +106,8 @@ endif
>  # hardlink each megadriver instance, but don't actually have
>  # libvdpau_gallium.so in the set of final installed files.
>  install-data-hook:
> +	LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +	$(top_srcdir)/bin/dlopen-check.sh $(DESTDIR)/$(vdpaudir)/libvdpau_gallium.$(LIB_EXT)
>  	$(AM_V_GEN)dest_dir=$(DESTDIR)/$(vdpaudir);			\
>  	for i in $(TARGET_DRIVERS); do					\
>  		j=libvdpau_gallium.$(LIB_EXT);				\
> diff --git a/src/gallium/targets/xvmc/Makefile.am b/src/gallium/targets/xvmc/Makefile.am
> index fdc5f4b..719c9c8 100644
> --- a/src/gallium/targets/xvmc/Makefile.am
> +++ b/src/gallium/targets/xvmc/Makefile.am
> @@ -68,6 +68,8 @@ endif
>  # hardlink each megadriver instance, but don't actually have
>  # libXvMCgallium.so in the set of final installed files.
>  install-data-hook:
> +	LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +	$(top_srcdir)/bin/dlopen-check.sh $(DESTDIR)/$(xvmcdir)/libXvMCgallium.$(LIB_EXT)
>  	$(AM_V_GEN)dest_dir=$(DESTDIR)/$(xvmcdir);			\
>  	for i in $(TARGET_DRIVERS); do					\
>  		j=libXvMCgallium.$(LIB_EXT);				\
> diff --git a/src/mesa/drivers/dri/Makefile.am b/src/mesa/drivers/dri/Makefile.am
> index 1c6dd08..411147a 100644
> --- a/src/mesa/drivers/dri/Makefile.am
> +++ b/src/mesa/drivers/dri/Makefile.am
> @@ -96,7 +96,10 @@ endif
>
>  # hardlink each megadriver instance, but don't actually have
>  # mesa_dri_drivers.so in the set of final installed files.
> -install-data-hook:
> +install-data-hook: $(top_builddir)/$(LIB_DIR)/libGL.so
> +	LD_PRELOAD=$(top_builddir)/$(LIB_DIR)/libGL.so \
> +	LD_LIBRARY_PATH=$(top_builddir)/$(LIB_DIR) \
> +	$(top_srcdir)/bin/dlopen-check.sh $(DESTDIR)$(dridir)/mesa_dri_drivers.so
>  	for i in $(MEGADRIVERS); do \
>  		ln -f $(DESTDIR)$(dridir)/mesa_dri_drivers.so \
>  		      $(DESTDIR)$(dridir)/$$i; \
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>


More information about the mesa-dev mailing list