public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-3660] libstdc++: Use GLIBCXX_CHECK_LINKER_FEATURES for cross-builds (PR111238)
@ 2023-09-04 20:44 Christophe Lyon
  0 siblings, 0 replies; only message in thread
From: Christophe Lyon @ 2023-09-04 20:44 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:56d0592db19b69e3cc217fabe5c2f8be3a75a8cf

commit r14-3660-g56d0592db19b69e3cc217fabe5c2f8be3a75a8cf
Author: Christophe Lyon <christophe.lyon@linaro.org>
Date:   Thu Aug 31 13:50:16 2023 +0000

    libstdc++: Use GLIBCXX_CHECK_LINKER_FEATURES for cross-builds (PR111238)
    
    As discussed in PR104167 (comments #8 and below), and PR111238, using
    -Wl,-gc-sections in the libstdc++ testsuite for arm-eabi
    (cross-toolchain) avoids link failures for a few tests:
    
    27_io/filesystem/path/108636.cc
    std/time/clock/gps/1.cc
    std/time/clock/gps/io.cc
    std/time/clock/tai/1.cc
    std/time/clock/tai/io.cc
    std/time/clock/utc/1.cc
    std/time/clock/utc/io.cc
    std/time/clock/utc/leap_second_info.cc
    std/time/exceptions.cc
    std/time/format.cc
    std/time/time_zone/get_info_local.cc
    std/time/time_zone/get_info_sys.cc
    std/time/tzdb/1.cc
    std/time/tzdb/leap_seconds.cc
    std/time/tzdb_list/1.cc
    std/time/zoned_time/1.cc
    std/time/zoned_time/custom.cc
    std/time/zoned_time/io.cc
    std/time/zoned_traits.cc
    
    This patch achieves this by calling GLIBCXX_CHECK_LINKER_FEATURES in
    cross-build cases, like we already do for native builds. We keep not
    doing so in Canadian-cross builds.
    
    However, this would hide the fact that libstdc++ somehow forces the
    user to use -Wl,-gc-sections to avoid undefined references to chdir,
    mkdir, chmod, pathconf, ... so maybe it's better to keep the status
    quo and not apply this patch?
    
    2023-08-31  Christophe Lyon  <christophe.lyon@linaro.org>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/111238
            * configure: Regenerate.
            * configure.ac: Call GLIBCXX_CHECK_LINKER_FEATURES in cross,
            non-Canadian builds.

Diff:
---
 libstdc++-v3/configure    | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 libstdc++-v3/configure.ac |   4 ++
 2 files changed, 158 insertions(+)

diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index db1932300c01..830c25fe8b13 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -29823,6 +29823,160 @@ else
     CANADIAN=yes
   else
     CANADIAN=no
+  fi
+
+  if test $CANADIAN = no; then
+
+  # If we're not using GNU ld, then there's no point in even trying these
+  # tests.  Check for that first.  We should have already tested for gld
+  # by now (in libtool), but require it now just to be safe...
+  test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
+  test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
+
+
+
+  # The name set by libtool depends on the version of libtool.  Shame on us
+  # for depending on an impl detail, but c'est la vie.  Older versions used
+  # ac_cv_prog_gnu_ld, but now it's lt_cv_prog_gnu_ld, and is copied back on
+  # top of with_gnu_ld (which is also set by --with-gnu-ld, so that actually
+  # makes sense).  We'll test with_gnu_ld everywhere else, so if that isn't
+  # set (hence we're using an older libtool), then set it.
+  if test x${with_gnu_ld+set} != xset; then
+    if test x${ac_cv_prog_gnu_ld+set} != xset; then
+      # We got through "ac_require(ac_prog_ld)" and still not set?  Huh?
+      with_gnu_ld=no
+    else
+      with_gnu_ld=$ac_cv_prog_gnu_ld
+    fi
+  fi
+
+  # Start by getting the version number.  I think the libtool test already
+  # does some of this, but throws away the result.
+  glibcxx_ld_is_gold=no
+  glibcxx_ld_is_mold=no
+  if test x"$with_gnu_ld" = x"yes"; then
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld version" >&5
+$as_echo_n "checking for ld version... " >&6; }
+
+    if $LD --version 2>/dev/null | grep 'GNU gold' >/dev/null 2>&1; then
+      glibcxx_ld_is_gold=yes
+    elif $LD --version 2>/dev/null | grep 'mold' >/dev/null 2>&1; then
+      glibcxx_ld_is_mold=yes
+    fi
+    ldver=`$LD --version 2>/dev/null |
+	   sed -e 's/[. ][0-9]\{8\}$//;s/.* \([^ ]\{1,\}\)$/\1/; q'`
+
+    glibcxx_gnu_ld_version=`echo $ldver | \
+	   $AWK -F. '{ if (NF<3) $3=0; print ($1*100+$2)*100+$3 }'`
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_gnu_ld_version" >&5
+$as_echo "$glibcxx_gnu_ld_version" >&6; }
+  fi
+
+  # Set --gc-sections.
+  glibcxx_have_gc_sections=no
+  if test "$glibcxx_ld_is_gold" = "yes" || test "$glibcxx_ld_is_mold" = "yes" ; then
+    if $LD --help 2>/dev/null | grep gc-sections >/dev/null 2>&1; then
+      glibcxx_have_gc_sections=yes
+    fi
+  else
+    glibcxx_gcsections_min_ld=21602
+    if test x"$with_gnu_ld" = x"yes" &&
+	test $glibcxx_gnu_ld_version -gt $glibcxx_gcsections_min_ld ; then
+      glibcxx_have_gc_sections=yes
+    fi
+  fi
+  if test "$glibcxx_have_gc_sections" = "yes"; then
+    # Sufficiently young GNU ld it is!  Joy and bunny rabbits!
+    # NB: This flag only works reliably after 2.16.1. Configure tests
+    # for this are difficult, so hard wire a value that should work.
+
+    ac_test_CFLAGS="${CFLAGS+set}"
+    ac_save_CFLAGS="$CFLAGS"
+    CFLAGS='-Wl,--gc-sections'
+
+    # Check for -Wl,--gc-sections
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld that supports -Wl,--gc-sections" >&5
+$as_echo_n "checking for ld that supports -Wl,--gc-sections... " >&6; }
+    if test x$gcc_no_link = xyes; then
+  as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5
+fi
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+ int one(void) { return 1; }
+     int two(void) { return 2; }
+
+int
+main ()
+{
+ two();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_gcsections=yes
+else
+  ac_gcsections=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+    if test "$ac_gcsections" = "yes"; then
+      rm -f conftest.c
+      touch conftest.c
+      if $CC -c conftest.c; then
+	if $LD --gc-sections -o conftest conftest.o 2>&1 | \
+	   grep "Warning: gc-sections option ignored" > /dev/null; then
+	  ac_gcsections=no
+	fi
+      fi
+      rm -f conftest.c conftest.o conftest
+    fi
+    if test "$ac_gcsections" = "yes"; then
+      SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
+    fi
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_gcsections" >&5
+$as_echo "$ac_gcsections" >&6; }
+
+    if test "$ac_test_CFLAGS" = set; then
+      CFLAGS="$ac_save_CFLAGS"
+    else
+      # this is the suspicious part
+      CFLAGS=''
+    fi
+  fi
+
+  # Set -z,relro.
+  # Note this is only for shared objects.
+  ac_ld_relro=no
+  if test x"$with_gnu_ld" = x"yes"; then
+    # cygwin and mingw uses PE, which has no ELF relro support,
+    # multi target ld may confuse configure machinery
+    case "$host" in
+    *-*-cygwin*)
+     ;;
+    *-*-mingw*)
+     ;;
+    *)
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld that supports -Wl,-z,relro" >&5
+$as_echo_n "checking for ld that supports -Wl,-z,relro... " >&6; }
+      cxx_z_relo=`$LD -v --help 2>/dev/null | grep "z relro"`
+      if test -n "$cxx_z_relo"; then
+        OPT_LDFLAGS="-Wl,-z,relro"
+        ac_ld_relro=yes
+      fi
+      { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ld_relro" >&5
+$as_echo "$ac_ld_relro" >&6; }
+    esac
+  fi
+
+  # Set linker optimization flags.
+  if test x"$with_gnu_ld" = x"yes"; then
+    OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
+  fi
+
+
+
+
   fi
 
   # Construct crosses by hand, eliminating bits that need ld...
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index fc0f25220277..494723534358 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -325,6 +325,10 @@ else
     CANADIAN=no
   fi
 
+  if test $CANADIAN = no; then
+    GLIBCXX_CHECK_LINKER_FEATURES
+  fi
+
   # Construct crosses by hand, eliminating bits that need ld...
   # GLIBCXX_CHECK_MATH_SUPPORT

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-04 20:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-04 20:44 [gcc r14-3660] libstdc++: Use GLIBCXX_CHECK_LINKER_FEATURES for cross-builds (PR111238) Christophe Lyon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).