public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
@ 2022-09-04  7:20 markmigm at gmail dot com
  2022-09-04 16:38 ` [Bug c++/106825] " markmigm at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: markmigm at gmail dot com @ 2022-09-04  7:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

            Bug ID: 106825
           Summary: header unit <memory> based std::shared_ptr<...>(...)
                    use gets: undefined reference to
                    `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M
                    _release()', aarch64 example
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: markmigm at gmail dot com
  Target Milestone: ---

In, for example, aarch64 Fedora 36, with its g++ 12.2.1 related
toolchain, the program:

// c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC
-xc++-system-header memory
// c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC
-omodule_shared_ptr_failure module_shared_ptr_failure.cpp

import <memory>;

struct base{int v=0;};

int main()
{
        return std::shared_ptr<base>(new base{})->v;
}

gets the following failure for the shown command sequence:

# c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC -xc++-system-header
memory

# c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC
-omodule_shared_ptr_failure module_shared_ptr_failure.cpp
/usr/bin/ld: /tmp/ccm2DaSN.o: in function
`std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count()':
module_shared_ptr_failure.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED2Ev[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EED5Ev]+0x24):
undefined reference to
`std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()'
collect2: error: ld returned 1 exit status

The -fPIC use is not required to see the problem.

For reference:

# c++ -v
Using built-in specs.
COLLECT_GCC=c++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/12/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-12.2.1-20220819/obj-aarch64-redhat-linux/isl-install
--enable-gnu-indirect-function --build=aarch64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.1 20220819 (Red Hat 12.2.1-1) (GCC)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/106825] header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
  2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
@ 2022-09-04 16:38 ` markmigm at gmail dot com
  2022-09-04 17:14 ` markmigm at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: markmigm at gmail dot com @ 2022-09-04 16:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

--- Comment #1 from Mark Millard <markmigm at gmail dot com> ---
(In reply to Mark Millard from comment #0)

FYI: I also see this on FreeBSD via the lang/gcc12 port (that,
in my installed context, is at 12.2.0), using the default library:
libstdc++ .

I do not see any failure on FreeBSD when I use -stdlib=libc++ on the two
command lines:

# g++12 -std=c++20 -stdlib=libc++ -pedantic -Wall -Wextra -fmodules-ts -fPIC
-xc++-system-header memory
# g++12 -std=c++20 -stdlib=libc++ -pedantic -Wall -Wextra -fmodules-ts -fPIC
-omodule_shared_ptr_failure module_shared_ptr_failure.cpp
#

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/106825] header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
  2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
  2022-09-04 16:38 ` [Bug c++/106825] " markmigm at gmail dot com
@ 2022-09-04 17:14 ` markmigm at gmail dot com
  2022-09-04 17:43 ` markmigm at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: markmigm at gmail dot com @ 2022-09-04 17:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

--- Comment #2 from Mark Millard <markmigm at gmail dot com> ---
An tiny example that avoids all involvement of libstdc++ is (showing
g++12 from FreeBSD in the comments, instead of c++ for fedora
--but both contexts fail):

# more module_template_specialization_failure.cppm
// g++12 -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -xc++-system-header
memory
// g++12 -std=c++20 -fmodules-ts -g -fPIC -xc++ -c
module_template_specialization_failure.cppm

export module module_template_specialization_intf;

export template<int c> int test();
export template<>      int test<0>() { return -1; };
export template<>      int test<1>() { return -2; };

# more module_template_specialization_failure.cpp
// g++12 -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -xc++-system-header
memory
// g++12 -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC -c              
   -xc++ module_template_specialization_failure.cppm
// g++12 -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC
-omain_using_plugin       module_template_specialization_failure.cpp

import module_template_specialization_intf;

int main()
{
        return test<0>()-test<1>();
}

The sequence and result is:

# c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -xc++-system-header
memory
# c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC -c -xc++
module_template_specialization_failure.cppm
# c++ -std=c++20 -pedantic -Wall -Wextra -fmodules-ts -fPIC -omain_using_plugin
module_template_specialization_failure.cpp
/usr/bin/ld: /tmp/ccmyKNjk.o: in function `main':
module_template_specialization_failure.cpp:(.text+0xc): undefined reference to
`_ZW35module_template_specialization_intf4testILi0EEiv'
/usr/bin/ld: module_template_specialization_failure.cpp:(.text+0x14): undefined
reference to `_ZW35module_template_specialization_intf4testILi1EEiv'
/usr/bin/ld: /tmp/ccmyKNjk.o: in function
`_GLOBAL__sub_I_module_template_specialization_failure.cpp':
module_template_specialization_failure.cpp:(.text+0x30): undefined reference to
`_ZGIW35module_template_specialization_intf'
collect2: error: ld returned 1 exit status

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/106825] header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
  2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
  2022-09-04 16:38 ` [Bug c++/106825] " markmigm at gmail dot com
  2022-09-04 17:14 ` markmigm at gmail dot com
@ 2022-09-04 17:43 ` markmigm at gmail dot com
  2022-09-04 18:41 ` markmigm at gmail dot com
  2022-10-12 19:13 ` [Bug c++/106825] [modules] " ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: markmigm at gmail dot com @ 2022-09-04 17:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

--- Comment #3 from Mark Millard <markmigm at gmail dot com> ---
(In reply to Mark Millard from comment #2)
. . .
> export module module_template_specialization_intf;
> 
> export template<int c> int test();
> export template<>      int test<0>() { return -1; };
> export template<>      int test<1>() { return -2; };
. . .

In case it is unclear: libstdc++ is using such specializations
that lead to the libstdc++ tied instances of such failures that
was the basis for my original submittal.

Technically libstdc++ could avoid such specializations as an
implementation technique and avoid the problem for code using
libstdc++ .

If that happened, the tiny test would still not be covered and
would become a separate issue.

I'll also report that the tiny test also fails for clang++15
(from FreeBSD's devel/llvm15 port) but libc++ does not have
the problem for the original example I submitted here. So,
apparently, libc++ avoids use of template specializations
in its implementation of the specific original example.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/106825] header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
  2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
                   ` (2 preceding siblings ...)
  2022-09-04 17:43 ` markmigm at gmail dot com
@ 2022-09-04 18:41 ` markmigm at gmail dot com
  2022-10-12 19:13 ` [Bug c++/106825] [modules] " ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: markmigm at gmail dot com @ 2022-09-04 18:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

--- Comment #4 from Mark Millard <markmigm at gmail dot com> ---
(In reply to Mark Millard from comment #3)
. . .
> I'll also report that the tiny test also fails for clang++15
> (from FreeBSD's devel/llvm15 port)
. . .

Not true: I figured out that, for how the clang++15 command lines
work in this area, I was missing a step (and a resulting file).
With the step and file reference added the tiny example compiles
and links just fine.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/106825] [modules] header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example
  2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
                   ` (3 preceding siblings ...)
  2022-09-04 18:41 ` markmigm at gmail dot com
@ 2022-10-12 19:13 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-10-12 19:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106825

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
   Target Milestone|---                         |13.0
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
dup of the recently fixed PR104433 I think

*** This bug has been marked as a duplicate of bug 104433 ***

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-12 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-04  7:20 [Bug c++/106825] New: header unit <memory> based std::shared_ptr<...>(...) use gets: undefined reference to `std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()', aarch64 example markmigm at gmail dot com
2022-09-04 16:38 ` [Bug c++/106825] " markmigm at gmail dot com
2022-09-04 17:14 ` markmigm at gmail dot com
2022-09-04 17:43 ` markmigm at gmail dot com
2022-09-04 18:41 ` markmigm at gmail dot com
2022-10-12 19:13 ` [Bug c++/106825] [modules] " ppalka at gcc dot gnu.org

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).