Bug 269110 - lang/gcc12: std::for_each() SEGVs
Summary: lang/gcc12: std::for_each() SEGVs
Status: Closed DUPLICATE of bug 236344
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Lorenzo Salvadore
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-23 08:53 UTC by Yuri Victorovich
Modified: 2023-02-27 12:24 UTC (History)
2 users (show)

See Also:
salvadore: maintainer-feedback+


Attachments
testcase.cpp (445 bytes, text/plain)
2023-01-23 08:53 UTC, Yuri Victorovich
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2023-01-23 08:53:00 UTC
Created attachment 239651 [details]
testcase.cpp

The attached program compiles with:
> g++12 -g -std=c++20  testcase.cpp -ltbb

but the resulting executabls SEGVs.



FreeBSD 13.1 STABLE
Comment 1 Lorenzo Salvadore freebsd_committer freebsd_triage 2023-01-23 20:29:30 UTC
Bug confirmed, I can reproduce the issue. I will study the problem as soon as possible.
Comment 2 Lorenzo Salvadore freebsd_committer freebsd_triage 2023-02-20 00:13:44 UTC
If none of devel/onetbb and devel/tbb are installed, I can compile the test case successfully with

> g++12 -g -std=c++20  testcase.cpp

And the compiled binary runs without any segmentation fault.

On the other hand, if any of devel/onetbb and devel/tbb is installed, then -ltbb is necessary for a successful build and then the binary gets a segmentaion fault.

I CC the maintainer of devel/onetbb and devel/tbb, which might be able to help.
Comment 3 Ganael LAPLANCHE freebsd_committer freebsd_triage 2023-02-20 14:12:36 UTC
Hello,

Thanks Lorenzo. I am currently AFK, I'll see if I can help ASAP.

Cheers,

Ganaelk.
Comment 4 Ganael LAPLANCHE freebsd_committer freebsd_triage 2023-02-21 22:49:05 UTC
Hello,

First of all, Gcc detects the presence of Intel TBB headers, this is why -ltbb is needed to build your program when OneTbb port is installed, see:

/usr/local/lib/gcc12/include/c++/x86_64-portbld-freebsd13.1/bits/c++config.h:
 827 // For now this defaults to being based on the presence of Thread Building Blocks
 828 # ifndef _GLIBCXX_USE_TBB_PAR_BACKEND
 829 #  define _GLIBCXX_USE_TBB_PAR_BACKEND __has_include(<tbb/tbb.h>)
 830 # endif
 831 // This section will need some rework when a new (default) backend type is added
 832 # if _GLIBCXX_USE_TBB_PAR_BACKEND
 833 #  define _PSTL_PAR_BACKEND_TBB
 834 # else
 835 #  define _PSTL_PAR_BACKEND_SERIAL
 836 # endif

I could reproduce your problem and got a backtrace:

(gdb) bt
#0  0x000000080122cd48 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1
#1  0x00000008008a6263 in __dynamic_cast () from /usr/local/lib/gcc12/libstdc++.so.6
#2  0x0000000800932585 in bool std::has_facet<std::ctype<char> >(std::locale const&) () from /usr/local/lib/gcc12/libstdc++.so.6
#3  0x00000008009244e5 in std::basic_ios<char, std::char_traits<char> >::_M_cache_locale(std::locale const&) ()
   from /usr/local/lib/gcc12/libstdc++.so.6
#4  0x0000000800924641 in std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*) ()
   from /usr/local/lib/gcc12/libstdc++.so.6
#5  0x00000008008baad6 in std::ios_base::Init::Init() () from /usr/local/lib/gcc12/libstdc++.so.6
#6  0x0000000000403449 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
    at /usr/local/lib/gcc12/include/c++/iostream:74
#7  0x0000000000404087 in _GLOBAL__sub_I_main () at testcase.cpp:23
#8  0x00000008006160fd in ?? () from /libexec/ld-elf.so.1
#9  0x0000000000000000 in ?? ()

It seems to be related to PR#236344 and triggered when mixing libstdc++/libsupc++ from Gcc (frame #1) and libc++/libcxxrt from base (frame #0).

Re-building your test program that way :

$ g++12 -g -std=c++20 -lc++ -lcxxrt -ltbb testcase.cpp

seems to fix the problem.

Cheers,

Ganael.
Comment 5 Lorenzo Salvadore freebsd_committer freebsd_triage 2023-02-26 09:17:27 UTC
Thanks Ganael. Then I close this bug report as a duplicate of bug report #236344.

I will also track bug report #236344, in case I might be able to help.

*** This bug has been marked as a duplicate of bug 236344 ***
Comment 6 Mark Millard 2023-02-26 17:04:05 UTC
(In reply to Ganael LAPLANCHE from comment #4)

Another thing to try with g++12 instead of -lc++ -lcxxrt
is -stdlib=libc++ . That  should automatically deal with
those and possibly other related references tied to libc++
use. It is something that was enabled in some lang/gcc*
ports back in late 2022-Aug.
Comment 7 Ganael LAPLANCHE freebsd_committer freebsd_triage 2023-02-27 12:24:44 UTC
(In reply to Mark Millard from comment #6)

Thanks for the hint, Mark!