From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 0B8433857814 for ; Fri, 19 Nov 2021 15:56:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B8433857814 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-347-Dgd9OyEsOeiEDOzK6l60hg-1; Fri, 19 Nov 2021 10:56:53 -0500 X-MC-Unique: Dgd9OyEsOeiEDOzK6l60hg-1 Received: by mail-ed1-f70.google.com with SMTP id m12-20020a056402430c00b003e9f10bbb7dso1357168edc.18 for ; Fri, 19 Nov 2021 07:56:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Pfm2vZeIQXPjN0h5EUJvQbyC6MHs7ygwPOQu15fLsP0=; b=5Qvj/HKU/dHRybgvzHOxE5xGO2YTsivlHcR08sUYN6odDJlxTDAvKCXV2pY0h++dKv sYbTg2oy43MjMXhEHpfyrvtmfAlq598I5FpVZotoLw9DPDsXCTBsZsu3dgYH28AGfmZf 9oVYiUrv6gvhzdPBzT4MilIMKHH1hI8HQDn3YcpuzvGkyVfd1+r5DTOEEHEUxnGClPLe 8Tbn8LEGFkDmEHTsIshCu08UQohUphbynv4aov3yskUEWABjtwzMc7CUWDPapgiKeVFw 1xU3Exz0oXDKE1nwXPah/Q/QI8IKGGqk/gXhF3VU0XJnIxmxlG0OaWfC/WJxXXsLkDqc sMIA== X-Gm-Message-State: AOAM532qYgyzhSxl+hWkvpLtw7fNa6vv8Y7U1uA4xNCKn608Br+FiU8J bHcMrx76l4Ynbtd2DpkpKnny+QX+CHxSOPN+3Tn2L0X2M9FJAZ8HD9O0xipbniuln5UW5mTd6+T Jl2GXF4qDpyn8zfH0Ob2kMw== X-Received: by 2002:a05:6402:405:: with SMTP id q5mr25561704edv.62.1637337411900; Fri, 19 Nov 2021 07:56:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGYRbewVGs6v+ARPEi4x6Zz1WVHZGO8WRHQdLm1K5dFxbmx9rJTcy018M15LtW7wndKnLxgw== X-Received: by 2002:a05:6402:405:: with SMTP id q5mr25561663edv.62.1637337411666; Fri, 19 Nov 2021 07:56:51 -0800 (PST) Received: from localhost (host86-166-129-255.range86-166.btcentralplus.com. [86.166.129.255]) by smtp.gmail.com with ESMTPSA id ho17sm96997ejc.111.2021.11.19.07.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Nov 2021 07:56:51 -0800 (PST) Date: Fri, 19 Nov 2021 15:56:50 +0000 From: Andrew Burgess To: Tom de Vries Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] [gdb/build] Check if libsource-highlight is usable Message-ID: <20211119155650.GB2514@redhat.com> References: <20211119123423.8459-1-tdevries@suse.de> MIME-Version: 1.0 In-Reply-To: <20211119123423.8459-1-tdevries@suse.de> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 15:55:18 up 4:53, 1 X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Nov 2021 15:56:58 -0000 * Tom de Vries via Gdb-patches [2021-11-19 13:34:23 +0100]: > When building gdb with g++ 4.8.5, I ran into: > ... > ld: source-cache.o: in function `source_cache::ensure(symtab*)': > source-cache.c:207: undefined reference to \ > srchilite::SourceHighlight::SourceHighlight(std::string const&) > ... > > [ I configured gdb without explicit settings related to source-highlight, so > we're excercising the enable_source_highlight=auto scenario. ] > > The problem is that: > - the source-highlight library is build with system compiler > g++ 7.5.0 which uses the new libstdc++ library abi (see > https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html ) > - gdb is build using g++ 4.8.5 which uses the old abi. > > [ There's a compatibility macro _GLIBCXX_USE_CXX11_ABI, but that doesn't work > for this case. Instead, it enables the opposite case where the > source-highlight library is build with g++ 4.8.5 and gdb is build with > g++ 7.5.0. ] > > Fix this by checking whether the source-highlight library is usable during > configuration. > > In the enable_source_highlight=auto scenario, this allows the build to skip > the unusable library and finish successfully. > > In the enable_source_highlight=yes scenario, this allows the build to error > out earlier. I make no claims of being an autoconf expert, but this all looks reasonable to me. I had just one tiny nit.. > > Tested on x86_64-linux. > --- > gdb/configure | 158 ++++++++++++++++++++++++++++++++--------------- > gdb/configure.ac | 47 ++++++++++++-- > 2 files changed, 151 insertions(+), 54 deletions(-) > > diff --git a/gdb/configure b/gdb/configure > index 6e2dfb766c8..aaa622d9fcc 100755 > --- a/gdb/configure > +++ b/gdb/configure > @@ -2367,6 +2367,52 @@ $as_echo "$ac_res" >&6; } > > } # ac_fn_c_check_func > > +# ac_fn_cxx_try_link LINENO > +# ------------------------- > +# Try to link conftest.$ac_ext, and return whether this succeeded. > +ac_fn_cxx_try_link () > +{ > + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack > + rm -f conftest.$ac_objext conftest$ac_exeext > + if { { ac_try="$ac_link" > +case "(($ac_try" in > + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; > + *) ac_try_echo=$ac_try;; > +esac > +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" > +$as_echo "$ac_try_echo"; } >&5 > + (eval "$ac_link") 2>conftest.err > + ac_status=$? > + if test -s conftest.err; then > + grep -v '^ *+' conftest.err >conftest.er1 > + cat conftest.er1 >&5 > + mv -f conftest.er1 conftest.err > + fi > + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > + test $ac_status = 0; } && { > + test -z "$ac_cxx_werror_flag" || > + test ! -s conftest.err > + } && test -s conftest$ac_exeext && { > + test "$cross_compiling" = yes || > + test -x conftest$ac_exeext > + }; then : > + ac_retval=0 > +else > + $as_echo "$as_me: failed program was:" >&5 > +sed 's/^/| /' conftest.$ac_ext >&5 > + > + ac_retval=1 > +fi > + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information > + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would > + # interfere with the next link command; also delete a directory that is > + # left behind by Apple's compiler. We do this before executing the actions. > + rm -rf conftest.dSYM conftest_ipa8_conftest.oo > + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno > + as_fn_set_status $ac_retval > + > +} # ac_fn_cxx_try_link > + > # ac_fn_c_check_type LINENO TYPE VAR INCLUDES > # ------------------------------------------- > # Tests whether TYPE exists after having included INCLUDES, setting cache > @@ -2524,52 +2570,6 @@ $as_echo "$ac_res" >&6; } > > } # ac_fn_c_check_member > > -# ac_fn_cxx_try_link LINENO > -# ------------------------- > -# Try to link conftest.$ac_ext, and return whether this succeeded. > -ac_fn_cxx_try_link () > -{ > - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack > - rm -f conftest.$ac_objext conftest$ac_exeext > - if { { ac_try="$ac_link" > -case "(($ac_try" in > - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; > - *) ac_try_echo=$ac_try;; > -esac > -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" > -$as_echo "$ac_try_echo"; } >&5 > - (eval "$ac_link") 2>conftest.err > - ac_status=$? > - if test -s conftest.err; then > - grep -v '^ *+' conftest.err >conftest.er1 > - cat conftest.er1 >&5 > - mv -f conftest.er1 conftest.err > - fi > - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 > - test $ac_status = 0; } && { > - test -z "$ac_cxx_werror_flag" || > - test ! -s conftest.err > - } && test -s conftest$ac_exeext && { > - test "$cross_compiling" = yes || > - test -x conftest$ac_exeext > - }; then : > - ac_retval=0 > -else > - $as_echo "$as_me: failed program was:" >&5 > -sed 's/^/| /' conftest.$ac_ext >&5 > - > - ac_retval=1 > -fi > - # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information > - # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would > - # interfere with the next link command; also delete a directory that is > - # left behind by Apple's compiler. We do this before executing the actions. > - rm -rf conftest.dSYM conftest_ipa8_conftest.oo > - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno > - as_fn_set_status $ac_retval > - > -} # ac_fn_cxx_try_link > - > # ac_fn_cxx_check_func LINENO FUNC VAR > # ------------------------------------ > # Tests whether FUNC exists, setting the cache variable VAR accordingly > @@ -12103,13 +12103,73 @@ $as_echo "no - pkg-config not found" >&6; } > ;; > esac > > - SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight` > - SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight` > + srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight` > + srchigh_pkg_libs=`${pkg_config_prog_path} --libs source-highlight` > + > + # Now that we have found a source-highlight library, check if we can use > + # it. In particular, we're trying to detect the situation that the > + # library is using the new libstdc++ library abi ( see > + # https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html ) > + # while the compiler being used to compile gdb is using the old abi. > + # Such a situation will result in an undefined reference to > + # srchilite::SourceHighlight::SourceHighlight(std::string const&). > + # This situation can occur when f.i. using a source highlight library what's "f.i." ? did you mean "e.g." ? Otherwise, LGTM. Thanks, Andrew > + # compiled with g++ 7.5.0 while building gdb with g++ 4.8.5. > + ac_ext=cpp > +ac_cpp='$CXXCPP $CPPFLAGS' > +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' > +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' > +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu > + > + save_CFLAGS=$CFLAGS > + save_LDFLAGS=$LDFLAGS > + CFLAGS="$CFLAGS $srchigh_pkg_cflags" > + LDFLAGS="$LDFLAGS $srchigh_pkg_libs" > + cat confdefs.h - <<_ACEOF >conftest.$ac_ext > +/* end confdefs.h. */ > +#include > +int > +main () > +{ > +std::string outlang = "esc.outlang"; > + new srchilite::SourceHighlight (outlang); > + > + ; > + return 0; > +} > +_ACEOF > +if ac_fn_cxx_try_link "$LINENO"; then : > + have_usable_source_highlight=yes > +else > + have_usable_source_highlight=no > + > +fi > +rm -f core conftest.err conftest.$ac_objext \ > + conftest$ac_exeext conftest.$ac_ext > + CFLAGS="$SAVE_CFLAGS" > + LDFLAGS="$SAVE_LDFLAGS" > + ac_ext=c > +ac_cpp='$CPP $CPPFLAGS' > +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' > +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' > +ac_compiler_gnu=$ac_cv_c_compiler_gnu > + > + > + if test "${have_usable_source_highlight}" = "yes"; then > > $as_echo "#define HAVE_SOURCE_HIGHLIGHT 1" >>confdefs.h > > - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 > + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 > $as_echo "yes" >&6; } > + SRCHIGH_CFLAGS="$srchigh_pkg_cflags" > + SRCHIGH_LIBS="$srchigh_pkg_libs" > + else > + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 > +$as_echo "no" >&6; } > + if test "${enable_source_highlight}" = "yes"; then > + as_fn_error $? "source-highlight in your system could not be used" "$LINENO" 5 > + fi > + fi > else > { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 > $as_echo "no" >&6; } > diff --git a/gdb/configure.ac b/gdb/configure.ac > index d4cfb6a7624..e4fed3c575c 100644 > --- a/gdb/configure.ac > +++ b/gdb/configure.ac > @@ -1248,11 +1248,48 @@ either use --disable-source-highlight or dnl > ;; > esac > > - SRCHIGH_CFLAGS=`${pkg_config_prog_path} --cflags source-highlight` > - SRCHIGH_LIBS=`${pkg_config_prog_path} --libs source-highlight` > - AC_DEFINE([HAVE_SOURCE_HIGHLIGHT], 1, > - [Define to 1 if the source-highlight library is available]) > - AC_MSG_RESULT([yes]) > + srchigh_pkg_cflags=`${pkg_config_prog_path} --cflags source-highlight` > + srchigh_pkg_libs=`${pkg_config_prog_path} --libs source-highlight` > + > + # Now that we have found a source-highlight library, check if we can use > + # it. In particular, we're trying to detect the situation that the > + # library is using the new libstdc++ library abi ( see > + # https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html ) > + # while the compiler being used to compile gdb is using the old abi. > + # Such a situation will result in an undefined reference to > + # srchilite::SourceHighlight::SourceHighlight(std::string const&). > + # This situation can occur when f.i. using a source highlight library > + # compiled with g++ 7.5.0 while building gdb with g++ 4.8.5. > + AC_LANG_PUSH(C++) > + save_CFLAGS=$CFLAGS > + save_LDFLAGS=$LDFLAGS > + CFLAGS="$CFLAGS $srchigh_pkg_cflags" > + LDFLAGS="$LDFLAGS $srchigh_pkg_libs" > + AC_LINK_IFELSE( > + [AC_LANG_PROGRAM( > + [#include ], > + [std::string outlang = "esc.outlang"; > + new srchilite::SourceHighlight (outlang);] > + )], > + [have_usable_source_highlight=yes], > + [have_usable_source_highlight=no] > + ) > + CFLAGS="$SAVE_CFLAGS" > + LDFLAGS="$SAVE_LDFLAGS" > + AC_LANG_POP(C++) > + > + if test "${have_usable_source_highlight}" = "yes"; then > + AC_DEFINE([HAVE_SOURCE_HIGHLIGHT], 1, > + [Define to 1 if the source-highlight library is available]) > + AC_MSG_RESULT([yes]) > + SRCHIGH_CFLAGS="$srchigh_pkg_cflags" > + SRCHIGH_LIBS="$srchigh_pkg_libs" > + else > + AC_MSG_RESULT([no]) > + if test "${enable_source_highlight}" = "yes"; then > + AC_MSG_ERROR([source-highlight in your system could not be used]) > + fi > + fi > else > AC_MSG_RESULT([no]) > if test "${enable_source_highlight}" = "yes"; then > > base-commit: fd0ff19bf435b267caae6a1ae04e7b4a4ba64f5b > -- > 2.26.2 >