On Thu, 31 Aug 2023 at 16:26, Christophe Lyon <christophe.l...@linaro.org> wrote: > > 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
I think this one probably just needs { dg-require-filesystem-ts "" } because there's no point testing that we can link to the std::filesystem definitions if some of those definitions are unusable on the target. // { dg-additional-options "-Wl,--gc-sections" { target gc_sections } } For the rest of them, does the attached patch help? If arm-eabi doesn't define _GLIBCXX_HAVE_READLINK then there's no point even trying to call filesystem::read_symlink. We can avoid a useless dependency on it by reusing the same preprocessor condition that filesystem::read_symlink uses. > 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? I'm undecided about this for now, but let's wait for HP's cris-elf testing anyway.
commit eea73ea3bdd44a8f7d8c0f54b15bfba9058f6ce8 Author: Jonathan Wakely <jwak...@redhat.com> Date: Thu Aug 31 18:31:32 2023 libstdc++: Avoid useless dependency on read_symlink from tzdb chrono::tzdb::current_zone uses filesystem::read_symlink, which creates a dependency on the fs_ops.o object in libstdc++.a, which then creates dependencies on several OS functions if --gc-sections isn't used. In the cases where that causes linker failures, we probably don't have readlink anyway, so the filesystem::read_symlink call will always fail. Repeat the preprocessor conditions for filesystem::read_symlink in the body of chrono::tzdb::current_zone so that we don't create the dependency on fs_ops.o if it's not even going to be able to read the symlink. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (tzdb::current_zone): Check configure macros for POSIX readlink before using filesystem::read_symlink. diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index 0fcbf6a4824..24044bb60f8 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -1635,6 +1635,9 @@ namespace std::chrono // TODO cache this function's result? #ifndef _AIX + // Repeat the preprocessor condition used by filesystem::read_symlink, + // to avoid a dependency on src/c++17/tzdb.o if it won't work anyway. +#if defined(_GLIBCXX_HAVE_READLINK) && defined(_GLIBCXX_HAVE_SYS_STAT_H) error_code ec; // This should be a symlink to e.g. /usr/share/zoneinfo/Europe/London auto path = filesystem::read_symlink("/etc/localtime", ec); @@ -1653,6 +1656,7 @@ namespace std::chrono return tz; } } +#endif // Otherwise, look for a file naming the time zone. string_view files[] { "/etc/timezone", // Debian derivates