[Mesa-dev] [PATCH] Allow static libstdc++/libgcc linking if selected
Emil Velikov
emil.l.velikov at gmail.com
Sun Mar 15 09:46:31 PDT 2015
Hi Vivek,
>From a quick look it seems that your use-case (both build and
runtime-wise) is a bit narrow. Allow me to elaborate:
Most people build mesa once and then package the different modules
into separate packages.
As other (non-dri) components use the C++ linker (and thus the
modified postdeps_CXX) there is no easy way of building dri modules
with static libs without causing chaos elsewhere. Another nice example
is the GL VDPAU interop, for which we jump back and forth between the
dri module and vdpau driver (backend). Both of which link against
libstdc++/libgcc_s. So it might be worth dropping the "used only with
dri" references in the patch.
That aside did you find any information as to why libtool adds the
explicit links despite -static-libgcc -static-libstdc++ ?
On 14 March 2015 at 16:22, Vivek Das Mohapatra <vivek at collabora.com> wrote:
> Sttaically link gallium modules with libstdc++/libgcc/libgcc_eh
> if --enable-static-libstdc++ is passed to ./configure:
>
Perhaps add a bit more on the topic? Here is my take on it, but feel
free to use something else.
Add a new configure switch which allows us to build some modules with
static libgcc_s/libstdc++. Such modules include the dri, vdpau, va
backends and others.
Note that if using this alongside LLVM, one needs to link both of them
statically. Checkout ./configure --help for more information.
> ---
> configure.ac | 38
> +++++++++++++++++++++++++++++++++++++
> src/gallium/Automake.inc | 1 +
> src/gallium/targets/dri/Makefile.am | 1 +
> 3 files changed, 40 insertions(+)
>
> diff --git a/configure.ac b/configure.ac
> index 90c7737..f10ed66 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -705,6 +705,43 @@ AC_ARG_ENABLE([dri],
>
> [enable_dri="$enableval"],
> [enable_dri=yes])
>
> +AC_ARG_ENABLE([static-libstdc++],
> + [AS_HELP_STRING([--enable-static-libstdc++],
> + [Statically link libstdc++/libgcc @<:@default=disabled@:>@])],
> + [enable_static_libstdc__="$enableval"],
> + [enable_static_libstdc__=no])
> +
> +dnl Strip out unnecessary dynamic linking in of libstdc++ and libgcc_s for
> +dnl DRI modules: they cause problems when loaded by games linked against
> +dnl a steam runtime with a different libgcc or libstdc++ version:
Afaict the problem is not specific only to the Steam runtime. Other
binary games (iirc ported by Loki) and programs (suspecting Matlab)
did ship their own version of the libraries.
> +if test x$enable_static_libstdc__ != xno;
> +then
> + if test x$enable_dri != xno;
You will need to check if llvm is enabled, and if so error out when
static-llvm is not set. Otherwise things are quite likely to explode.
> + then
Please place this on the previous line, like the rest of the file.
> +AC_MSG_NOTICE([Cleanup libtool C++ postdeps: $postdeps_CXX
> (enable_dri=$enable_dri)])
> + tmppdcxx=;
> + for x in ${postdeps_CXX};
> + do
Ditto.
> + case $x in
> + -lstdc++) true; ;;
> + -lgcc_s) true; ;;
> + *) tmppdcxx=${tmppdcxx}${tmppdcxx:+ }$x; ;;
Please rework the statement to be consistent with the rest of configure.ac
-lstdc++|-lgcc_s)
;;
*)
tmppdcxx="${tmppdcxx} $x" # guessing that's what you meant above ?
;;
> + esac;
> + done;
> + postdeps_CXX="${tmppdcxx}";
> +AC_MSG_NOTICE([Cleaned libtool C++ postdeps: $postdeps_CXX])
Now sure what either of the two messages above brings us.
> + fi;
> + STATIC_STDCPP_LIBS="-l:libgcc.a -l:libgcc_eh.a -l:libstdc++.a";
> + STATIC_STDCPP_LDFLAGS="-static-libgcc -static-libstdc++ \
> + -l:libgcc.a -l:libstdc++.a \
Do we need this line considering the STATIC_STDCPP_LIBS above ?
> + -Wl,--exclude-libs -Wl,libgcc.a:libstdc++.a";
> +else
> + STATIC_STDCPP_LIBS="";
> + STATIC_STDCPP_LDFLAGS="";
Drop the trailing semicolons and optionally move the default STATIC*
assignment before the conditional.
> +fi
> +AC_SUBST([STATIC_STDCPP_LDFLAGS])
> +AC_SUBST([STATIC_STDCPP_LIBS])
> +
> case "$host_os" in
> linux*)
> dri3_default=yes
> @@ -2450,6 +2487,7 @@ echo " prefix: $prefix"
> echo " exec_prefix: $exec_prefix"
> echo " libdir: $libdir"
> echo " includedir: $includedir"
> +echo " postdeps_CXX: $postdeps_CXX"
>
Don't think we need this.
> dnl API info
> echo ""
> diff --git a/src/gallium/Automake.inc b/src/gallium/Automake.inc
> index 95aae50..3e13cc7 100644
> --- a/src/gallium/Automake.inc
> +++ b/src/gallium/Automake.inc
> @@ -46,6 +46,7 @@ GALLIUM_TARGET_CFLAGS = \
>
> GALLIUM_COMMON_LIB_DEPS = \
> -lm \
> + $(STATIC_STDCPP_LIBS) \
Don't the classic dri modules need this? Afaict you'll end up removing
the references (link) to the C++ runtime and libgcc_s and things won't
end up too well.
> $(CLOCK_LIB) \
> $(PTHREAD_LIBS) \
> $(DLOPEN_LIBS)
> diff --git a/src/gallium/targets/dri/Makefile.am
> b/src/gallium/targets/dri/Makefile.am
> index aaeb950..6bc5458 100644
> --- a/src/gallium/targets/dri/Makefile.am
> +++ b/src/gallium/targets/dri/Makefile.am
> @@ -27,6 +27,7 @@ gallium_dri_la_LDFLAGS = \
> -shrext .so \
> -module \
> -avoid-version \
> + $(STATIC_STDCPP_LDFLAGS) \
You might want to add this to the other gallium targets. Otherwise
they'll be left out in the cold.
Cheers,
Emil
More information about the mesa-dev
mailing list