# HG changeset patch # User tbell # Date 1352916808 28800 # Node ID 6213b3f9e08d4f96d147670c3ce71b390d05d5a5 # Parent 8e22b637770a22612f0ae0f4b68e78b192448aac 8001875: build-infra: We must be able to force static linking of stdc++ Summary: Ensure that we build with static linking when requested, or do not build at all Reviewed-by: ohair, tbell Contributed-by: erik.joelsson@oracle.com diff -r 8e22b637770a -r 6213b3f9e08d common/autoconf/generated-configure.sh --- a/common/autoconf/generated-configure.sh Wed Nov 14 10:05:49 2012 -0800 +++ b/common/autoconf/generated-configure.sh Wed Nov 14 10:13:28 2012 -0800 @@ -1035,7 +1035,7 @@ with_alsa_include with_alsa_lib with_zlib -enable_static_link_stdc++ +with_stdc++lib with_num_cores with_memory_size with_sjavac_server_java @@ -1712,9 +1712,6 @@ --disable-macosx-runtime-support disable the use of MacOSX Java runtime support framework [enabled] - --disable-static-link-stdc++ - disable static linking of the C++ runtime on Linux - [enabled] --enable-sjavac use sjavac to do fast incremental compiles [disabled] --disable-precompiled-headers @@ -1796,6 +1793,10 @@ --with-alsa-lib specify directory for the alsa library --with-zlib use zlib from build system or OpenJDK source (system, bundled) [bundled] + --with-stdc++lib=,, + force linking of the C++ runtime on Linux to either + static or dynamic, default is static with dynamic as + fallback --with-num-cores number of cores in the build system, e.g. --with-num-cores=8 [probed] --with-memory-size memory (in MB) available in the build system, e.g. @@ -3067,7 +3068,7 @@ #CUSTOM_AUTOCONF_INCLUDE # Do not change or remove the following line, it is needed for consistency checks: -DATE_WHEN_GENERATED=1352751880 +DATE_WHEN_GENERATED=1352916731 ############################################################################### # @@ -33006,12 +33007,19 @@ # statically link libstdc++ before C++ ABI is stablized on Linux unless # dynamic build is configured on command line. # -# Check whether --enable-static-link-stdc++ was given. -if test "${enable_static_link_stdc+++set}" = set; then - enableval=$enable_static_link_stdc++; -else - - enable_static_link_stdc__=yes + +# Check whether --with-stdc++lib was given. +if test "${with_stdc++lib+set}" = set; then + withval=$with_stdc++lib; + if test "x$with_stdc__lib" != xdynamic && test "x$with_stdc__lib" != xstatic \ + && test "x$with_stdc__lib" != xdefault; then + { { $as_echo "$as_me:$LINENO: error: Bad parameter value --with-stdc++lib=$with_stdc__lib!" >&5 +$as_echo "$as_me: error: Bad parameter value --with-stdc++lib=$with_stdc__lib!" >&2;} + { (exit 1); exit 1; }; } + fi + +else + with_stdc__lib=default fi @@ -33157,38 +33165,40 @@ { $as_echo "$as_me:$LINENO: result: $has_static_libstdcxx" >&5 $as_echo "$has_static_libstdcxx" >&6; } - if test "x$has_static_libcxx" = xno && test "x$has_dynamic_libcxx" = xno; then - { { $as_echo "$as_me:$LINENO: error: I cannot link to stdc++! Neither dynamically nor statically." >&5 -$as_echo "$as_me: error: I cannot link to stdc++! Neither dynamically nor statically." >&2;} - { (exit 1); exit 1; }; } - fi - - if test "x$enable_static_link_stdc__" = xyes && test "x$has_static_libstdcxx" = xno; then - { $as_echo "$as_me:$LINENO: Static linking of libstdc++ was not possible reverting to dynamic linking." >&5 -$as_echo "$as_me: Static linking of libstdc++ was not possible reverting to dynamic linking." >&6;} - enable_static_link_stdc__=no - fi - - if test "x$enable_static_link_stdc__" = xno && test "x$has_dynamic_libstdcxx" = xno; then - { $as_echo "$as_me:$LINENO: Dynamic linking of libstdc++ was not possible reverting to static linking." >&5 -$as_echo "$as_me: Dynamic linking of libstdc++ was not possible reverting to static linking." >&6;} - enable_static_link_stdc__=yes + if test "x$has_static_libstdcxx" = xno && test "x$has_dynamic_libstdcxx" = xno; then + { { $as_echo "$as_me:$LINENO: error: Cannot link to stdc++, neither dynamically nor statically!" >&5 +$as_echo "$as_me: error: Cannot link to stdc++, neither dynamically nor statically!" >&2;} + { (exit 1); exit 1; }; } + fi + + if test "x$with_stdc__lib" = xstatic && test "x$has_static_libstdcxx" = xno; then + { { $as_echo "$as_me:$LINENO: error: Static linking of libstdc++ was not possible!" >&5 +$as_echo "$as_me: error: Static linking of libstdc++ was not possible!" >&2;} + { (exit 1); exit 1; }; } + fi + + if test "x$with_stdc__lib" = xdynamic && test "x$has_dynamic_libstdcxx" = xno; then + { { $as_echo "$as_me:$LINENO: error: Dynamic linking of libstdc++ was not possible!" >&5 +$as_echo "$as_me: error: Dynamic linking of libstdc++ was not possible!" >&2;} + { (exit 1); exit 1; }; } fi { $as_echo "$as_me:$LINENO: checking how to link with libstdc++" >&5 $as_echo_n "checking how to link with libstdc++... " >&6; } - if test "x$enable_static_link_stdc__" = xyes; then + # If dynamic was requested, it's available since it would fail above otherwise. + # If dynamic wasn't requested, go with static unless it isn't available. + if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno; then + LIBCXX="$LIBCXX -lstdc++" + LDCXX="$CXX" + STATIC_CXX_SETTING="STATIC_CXX=false" + { $as_echo "$as_me:$LINENO: result: dynamic" >&5 +$as_echo "dynamic" >&6; } + else LIBCXX="$LIBCXX $STATIC_STDCXX_FLAGS" LDCXX="$CC" STATIC_CXX_SETTING="STATIC_CXX=true" { $as_echo "$as_me:$LINENO: result: static" >&5 $as_echo "static" >&6; } - else - LIBCXX="$LIBCXX -lstdc++" - LDCXX="$CXX" - STATIC_CXX_SETTING="STATIC_CXX=false" - { $as_echo "$as_me:$LINENO: result: dynamic" >&5 -$as_echo "dynamic" >&6; } fi fi diff -r 8e22b637770a -r 6213b3f9e08d common/autoconf/libraries.m4 --- a/common/autoconf/libraries.m4 Wed Nov 14 10:05:49 2012 -0800 +++ b/common/autoconf/libraries.m4 Wed Nov 14 10:13:28 2012 -0800 @@ -601,11 +601,16 @@ # statically link libstdc++ before C++ ABI is stablized on Linux unless # dynamic build is configured on command line. # -AC_ARG_ENABLE([static-link-stdc++], [AS_HELP_STRING([--disable-static-link-stdc++], - [disable static linking of the C++ runtime on Linux @<:@enabled@:>@])],, - [ - enable_static_link_stdc__=yes - ]) +AC_ARG_WITH([stdc++lib], [AS_HELP_STRING([--with-stdc++lib=,,], + [force linking of the C++ runtime on Linux to either static or dynamic, default is static with dynamic as fallback])], + [ + if test "x$with_stdc__lib" != xdynamic && test "x$with_stdc__lib" != xstatic \ + && test "x$with_stdc__lib" != xdefault; then + AC_MSG_ERROR([Bad parameter value --with-stdc++lib=$with_stdc__lib!]) + fi + ], + [with_stdc__lib=default] +) if test "x$OPENJDK_TARGET_OS" = xlinux; then # Test if -lstdc++ works. @@ -636,31 +641,31 @@ AC_LANG_POP(C++) AC_MSG_RESULT([$has_static_libstdcxx]) - if test "x$has_static_libcxx" = xno && test "x$has_dynamic_libcxx" = xno; then - AC_MSG_ERROR([I cannot link to stdc++! Neither dynamically nor statically.]) + if test "x$has_static_libstdcxx" = xno && test "x$has_dynamic_libstdcxx" = xno; then + AC_MSG_ERROR([Cannot link to stdc++, neither dynamically nor statically!]) fi - if test "x$enable_static_link_stdc__" = xyes && test "x$has_static_libstdcxx" = xno; then - AC_MSG_NOTICE([Static linking of libstdc++ was not possible reverting to dynamic linking.]) - enable_static_link_stdc__=no + if test "x$with_stdc__lib" = xstatic && test "x$has_static_libstdcxx" = xno; then + AC_MSG_ERROR([Static linking of libstdc++ was not possible!]) fi - if test "x$enable_static_link_stdc__" = xno && test "x$has_dynamic_libstdcxx" = xno; then - AC_MSG_NOTICE([Dynamic linking of libstdc++ was not possible reverting to static linking.]) - enable_static_link_stdc__=yes + if test "x$with_stdc__lib" = xdynamic && test "x$has_dynamic_libstdcxx" = xno; then + AC_MSG_ERROR([Dynamic linking of libstdc++ was not possible!]) fi AC_MSG_CHECKING([how to link with libstdc++]) - if test "x$enable_static_link_stdc__" = xyes; then + # If dynamic was requested, it's available since it would fail above otherwise. + # If dynamic wasn't requested, go with static unless it isn't available. + if test "x$with_stdc__lib" = xdynamic || test "x$has_static_libstdcxx" = xno; then + LIBCXX="$LIBCXX -lstdc++" + LDCXX="$CXX" + STATIC_CXX_SETTING="STATIC_CXX=false" + AC_MSG_RESULT([dynamic]) + else LIBCXX="$LIBCXX $STATIC_STDCXX_FLAGS" LDCXX="$CC" STATIC_CXX_SETTING="STATIC_CXX=true" AC_MSG_RESULT([static]) - else - LIBCXX="$LIBCXX -lstdc++" - LDCXX="$CXX" - STATIC_CXX_SETTING="STATIC_CXX=false" - AC_MSG_RESULT([dynamic]) fi fi AC_SUBST(STATIC_CXX_SETTING)