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 [216.145.221.124]) by sourceware.org (Postfix) with ESMTPS id 163F63858C33 for ; Thu, 2 Feb 2023 16:49:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 163F63858C33 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675356549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6n8jpQf6LB6XwCHpleR7S1QzK2WPrr6MtvehTdyMs8w=; b=RWgQ8j5hCtL2RkKCbBU5bsoMHfhTuT/1lRnRTpTaH+AppxHZFHyhIFpvmRGpdtecpI+P20 N3s22+vXeXV3C8rcoHk8YkzKSf6bZi9zVGhz5E6iy3cywiuvh4cWEXOaGXK3wCQ9FHZMFj xJG7kEY4zlrv1WPApGewPBeUFK1cuto= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-q84Z6ESgPNeDyQEIVfVz1Q-1; Thu, 02 Feb 2023 11:49:06 -0500 X-MC-Unique: q84Z6ESgPNeDyQEIVfVz1Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 02F2E185A794; Thu, 2 Feb 2023 16:49:06 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0EDD40398A0; Thu, 2 Feb 2023 16:49:05 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::filesystem errors with -fkeep-inline-functions [PR108636] Date: Thu, 2 Feb 2023 16:49:05 +0000 Message-Id: <20230202164905.2634961-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,URI_HEX autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested powerpc64le-linux. Pushed to trunk. The source code changes should be backported (the linker script changes aren't needed because those symbols aren't present on the branches). -- >8 -- With -fkeep-inline-functions there are linker errors when including . This happens because there are some filesystem::path constructors defined inline which call non-exported functions defined in the library. That's usually not a problem, because those constructors are only called by code that's also inside the library. But when the header is compiled with -fkeep-inline-functions those inline functions are emitted even though they aren't called. That then creates an undefined reference to the other library internsl. The fix is to just move the private constructors into the library where they are called. That way they are never even seen by users, and so not compiled even if -fkeep-inline-functions is used. On trunk there is a second problem, which is that the new equality operators for comparing directory iterators with default_sentinel use the shared_ptr::operator bool() conversion operator. The shared_ptr specializations used by directory iterators are explicitly instantiated in the library, but the bool conversion operators are not exported. This causes linker errors at -O0 or with -fkeep-inline-functions. That just requires the conversion operators to be exported. libstdc++-v3/ChangeLog: PR libstdc++/108636 * config/abi/pre/gnu.ver (GLIBCXX_3.4.31): Export shared_ptr conversion operators for directory iterator comparisons with std::default_sentinel_t. * include/bits/fs_path.h (path::path(string_view, _Type)) (path::_Cmpt::_Cmpt(string_view, _Type, size_t)): Move inline definitions to ... * src/c++17/fs_path.cc: ... here. * testsuite/27_io/filesystem/path/108636.cc: New test. --- libstdc++-v3/config/abi/pre/gnu.ver | 7 +++++++ libstdc++-v3/include/bits/fs_path.h | 10 ++-------- libstdc++-v3/src/c++17/fs_path.cc | 13 +++++++++++++ .../testsuite/27_io/filesystem/path/108636.cc | 8 ++++++++ 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 72716414ccb..34f23bcbce0 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -2504,6 +2504,13 @@ GLIBCXX_3.4.31 { _ZNSt6chrono9tzdb_list14const_iteratorppEi; _ZN9__gnu_cxx21zoneinfo_dir_overrideEv; + # __shared_ptr::operator bool() + _ZNKSt12__shared_ptrINSt10filesystem4_DirELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv; + _ZNKSt12__shared_ptrINSt10filesystem7__cxx114_DirELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv; + # __shared_ptr::operator bool() + _ZNKSt12__shared_ptrINSt10filesystem28recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv; + _ZNKSt12__shared_ptrINSt10filesystem7__cxx1128recursive_directory_iterator10_Dir_stackELN9__gnu_cxx12_Lock_policyE[012]EEcvbEv; + } GLIBCXX_3.4.30; # Symbols in the support library (libsupc++) have their own tag. diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 1cbfaaa5427..0d7bb10c1a0 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -596,12 +596,7 @@ namespace __detail _Multi = 0, _Root_name, _Root_dir, _Filename }; - path(basic_string_view __str, _Type __type) - : _M_pathname(__str) - { - __glibcxx_assert(__type != _Type::_Multi); - _M_cmpts.type(__type); - } + path(basic_string_view __str, _Type __type); enum class _Split { _Stem, _Extension }; @@ -851,8 +846,7 @@ namespace __detail struct path::_Cmpt : path { - _Cmpt(basic_string_view __s, _Type __t, size_t __pos) - : path(__s, __t), _M_pos(__pos) { } + _Cmpt(basic_string_view __s, _Type __t, size_t __pos); _Cmpt() : _M_pos(-1) { } diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc index 93149c4b415..aaea7d2725d 100644 --- a/libstdc++-v3/src/c++17/fs_path.cc +++ b/libstdc++-v3/src/c++17/fs_path.cc @@ -187,6 +187,19 @@ struct path::_Parser { return origin + c.str.data() - input.data(); } }; +inline +path::path(basic_string_view __str, _Type __type) +: _M_pathname(__str) +{ + __glibcxx_assert(__type != _Type::_Multi); + _M_cmpts.type(__type); +} + +inline +path::_Cmpt::_Cmpt(basic_string_view __s, _Type __t, size_t __pos) +: path(__s, __t), _M_pos(__pos) +{ } + struct path::_List::_Impl { using value_type = _Cmpt; diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc new file mode 100644 index 00000000000..d58de461090 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/108636.cc @@ -0,0 +1,8 @@ +// { dg-do link { target c++17 } } +// { dg-options "-fkeep-inline-functions" } + +#include +int main() +{ + // PR libstdc++/108636 - link failure with -fkeep-inline-functions +} -- 2.39.1