Created attachment 214530 [details] Patch to build cad/openvsp with GCC cad/openvsp doesn't build with clang anymore due to bug #230888. It builds with GCC but it then segfaults with the following backtrace: Program received signal SIGSEGV, Segmentation fault. 0x0000000802efba18 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1 (gdb) bt #0 0x0000000802efba18 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1 #1 0x0000000801a273e6 in __dynamic_cast () from /usr/local/lib/gcc9/libstdc++.so.6 #2 0x0000000801aa9e8e in bool std::has_facet<std::ctype<char> >(std::locale const&) () from /usr/local/lib/gcc9/libstdc++.so.6 #3 0x0000000801a9bbd4 in std::basic_ios<char, std::char_traits<char> >::_M_cache_locale(std::locale const&) () from /usr/local/lib/gcc9/libstdc++.so.6 #4 0x0000000801a9c070 in std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*) () from /usr/local/lib/gcc9/libstdc++.so.6 #5 0x0000000801a3b463 in std::ios_base::Init::Init() () from /usr/local/lib/gcc9/libstdc++.so.6 #6 0x000000000049f60d in ?? () #7 0x000000080194846e in ?? () from /libexec/ld-elf.so.1 #8 0x00007fffffffc828 in ?? () #9 0x0000000801975800 in ?? () #10 0x0000000000000000 in ?? () How to reproduce: 1 - Apply attached patch: cd /usr/ports && patch -p0 < cad_openvsp_gcc_build.svndiff 2 - Build & install port: cd /usr/ports/cad/openvsp && make install 3 - Launch program: /usr/local/bin/vsp Segmentation fault (core dumped)
Seems closely related to bug #236344
It's difficult to extract the minimal case. The vsp executable requires quite a few libraries both from system and in its own distribution: /usr/local/bin/g++9 -O2 -pipe -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -lgcc -lstdc++ -Wl,-rpath=/usr/local/lib/gcc9 -isystem /usr/local/include -fPIC -std=c++11 -fPIC -O3 -DNDEBUG -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 CMakeFiles/vsp.dir/common.cpp.o CMakeFiles/vsp.dir/main.cpp.o -o vsp -Wl,-rpath,/usr/local/lib: ../geom_api/libgui_interface_g.a ../gui_and_draw/libgui_and_draw.a ../geom_core/libgeom_core.a ../geom_api/libgeom_api_g.a ../cfd_mesh/libcfd_mesh.a ../external/triangle/libtriangle.a ../fltk_screens/libscreens.a ../xmlvsp/libxmlvsp.a ../external/sixseries/libsixseries.a ../util/libutil.a ../external/tritri/libtritri.a ../external/clipper/libclipper.a ../external/angelscript/sdk/angelscript/lib/libAngelscript.a ../external/cartesian/libcartesian.a ../external/wavedragEL/libwavedragEL.a ../external/Pinocchio/Pinocchio/libpinocchio.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/CPPTEST-prefix/lib/libcpptest.a -L/usr/local/lib -lxml2 -lpthread -llzma -lz -L/usr/lib -lm /usr/local/lib/libfltk_images.so /usr/local/lib/libfltk_forms.so /usr/local/lib/libfltk_gl.so /usr/local/lib/libGL.so /usr/local/lib/libfltk.so /usr/local/lib/libSM.so /usr/local/lib/libICE.so /usr/local/lib/libX11.so /usr/local/lib/libXext.so -lm /usr/local/lib/libGL.so /usr/local/lib/libGLU.so /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/CMINPACK-prefix/lib/libcminpack.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libsdai_ap203.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libstepeditor.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libstepcore.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libstepdai.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libsteputils.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/../sc-install/lib/libbase.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/LIBIGES-prefix/lib/libiges_static.a ../vsp_graphic/libvsp_graphic.a /usr/local/lib/libGLEW.so ../external/glfont2/libglfont2.a ../external/stb/libstb_image.a /wrkdirs/usr/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/EXPRPARSE-prefix/lib/libexprparse.a /usr/local/lib/libGL.so /usr/local/lib/libGLU.so
(In reply to Fernando Apesteguía from comment #0) In your patch I see: CXXFLAGS+= -lgcc -lstdc++ CPPFLAGS+= -lgcc -lstdc++ that's never going to work of course, you are mixing two C++ libraries. Either compile everything (and that really means everything :) with libstdc++, or make gcc use libc++'s headers and libraries.
I tried with the following diff instead: Index: Makefile =================================================================== --- Makefile (revision 535286) +++ Makefile (working copy) @@ -13,7 +13,7 @@ LICENSE_NAME= NASA Open Source Agreement version 1 LICENSE_FILE= ${WRKSRC}/LICENSE LICENSE_PERMS= dist-mirror dist-sell pkg-mirror pkg-sell auto-accept -BROKEN= fails to link +#BROKEN= fails to link BROKEN_aarch64= fails to compile: invokes x86 asm LIB_DEPENDS= libdrm.so:graphics/libdrm \ @@ -27,7 +27,7 @@ BUILD_DEPENDS= ${LOCALBASE}/lib/libopenNURBS.a:gra ${LOCALBASE}/include/glm/glm.hpp:math/glm \ ${LOCALBASE}/libdata/pkgconfig/pthread-stubs.pc:devel/libpthread-stubs -USES= compiler:c++11-lang cmake:noninja localbase\ +USES= compiler:gcc-c++11-lib compiler:openmp cmake:noninja localbase\ gl gnome jpeg xorg USE_GITHUB= yes GH_PROJECT= OpenVSP @@ -57,7 +57,7 @@ USE_GNOME= libxml2 # See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=230888 .if ${OPSYS} == FreeBSD .if (${OSVERSION} < 1200000 || ${OSVERSION} >=1300000) -BROKEN= undefined reference to __atomic_load +#BROKEN= undefined reference to __atomic_load .endif .endif but it errors out pretty quickly with a gcc error: [ 18%] Building CXX object src/cldai/CMakeFiles/stepdai-static.dir/sdaiBinary.cc.o In file included from /usr/include/c++/v1/__tree:15, from /usr/include/c++/v1/map:479, from /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/sdaiApplication_instance.cc:13: /usr/include/c++/v1/memory: In instantiation of 'constexpr std::__1::__compressed_pair_elem<_Tp, _Idx, _CanBeEmptyBase>::__compressed_pair_elem(_Up&&) [with _Up = long int; <template-parameter-2-2> = void; _Tp = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*; int _Idx = 0; bool _CanBeEmptyBase = false]': /usr/include/c++/v1/memory:2289:72: required from 'constexpr std::__1::__compressed_pair<_T1, _T2>::__compressed_pair(_U1&&, _U2&&) [with _U1 = long int; _U2 = std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >; _T1 = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*; _T2 = std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >]' /usr/include/c++/v1/vector:455:41: required from 'std::__1::__vector_base<_Tp, _Allocator>::__vector_base(std::__1::__vector_base<_Tp, _Allocator>::allocator_type&&) [with _Tp = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >; _Allocator = std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >; std::__1::__vector_base<_Tp, _Allocator>::allocator_type = std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >]' /usr/include/c++/v1/vector:1249:82: required from 'std::__1::vector<_Tp, _Alloc>::vector(const std::__1::vector<_Tp, _Alloc>&) [with _Tp = std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >; _Allocator = std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >]' /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/dictSchema.h:66:16: required from here /usr/include/c++/v1/memory:2204:42: error: invalid conversion from 'long int' to 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*' [-fpermissive] 2204 | : __value_(_VSTD::forward<_Up>(__u)) | ^ | | | long int /usr/include/c++/v1/memory: In instantiation of 'constexpr std::__1::__compressed_pair_elem<_Tp, _Idx, _CanBeEmptyBase>::__compressed_pair_elem(_Up&&) [with _Up = long int; <template-parameter-2-2> = void; _Tp = recursiveEntDescripIterator::queue_pair**; int _Idx = 0; bool _CanBeEmptyBase = false]': /usr/include/c++/v1/memory:2289:72: required from 'constexpr std::__1::__compressed_pair<_T1, _T2>::__compressed_pair(_U1&&, _U2&&) [with _U1 = long int; _U2 = std::__1::allocator<recursiveEntDescripIterator::queue_pair*>&; _T1 = recursiveEntDescripIterator::queue_pair**; _T2 = std::__1::allocator<recursiveEntDescripIterator::queue_pair*>&]' /usr/include/c++/v1/__split_buffer:316:30: required from 'std::__1::__split_buffer<_Tp, _Allocator>::__split_buffer(std::__1::__split_buffer<_Tp, _Allocator>::size_type, std::__1::__split_buffer<_Tp, _Allocator>::size_type, std::__1::__split_buffer<_Tp, _Allocator>::__alloc_rr&) [with _Tp = recursiveEntDescripIterator::queue_pair*; _Allocator = std::__1::allocator<recursiveEntDescripIterator::queue_pair*>&; std::__1::__split_buffer<_Tp, _Allocator>::size_type = long unsigned int; std::__1::__split_buffer<_Tp, _Allocator>::__alloc_rr = std::__1::allocator<recursiveEntDescripIterator::queue_pair*>]' /usr/include/c++/v1/deque:2596:13: required from 'void std::__1::deque<_Tp, _Allocator>::__add_back_capacity() [with _Tp = recursiveEntDescripIterator::queue_pair; _Allocator = std::__1::allocator<recursiveEntDescripIterator::queue_pair>]' /usr/include/c++/v1/deque:1928:9: required from 'void std::__1::deque<_Tp, _Allocator>::push_back(const value_type&) [with _Tp = recursiveEntDescripIterator::queue_pair; _Allocator = std::__1::allocator<recursiveEntDescripIterator::queue_pair>; std::__1::deque<_Tp, _Allocator>::value_type = recursiveEntDescripIterator::queue_pair]' /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/SubSuperIterators.h:30:34: required from here /usr/include/c++/v1/memory:2204:42: error: invalid conversion from 'long int' to 'recursiveEntDescripIterator::queue_pair**' [-fpermissive] [ 19%] Building CXX object src/clutils/CMakeFiles/steputils.dir/dirobj.cc.o /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/sdaiApplication_instance.cc: In function 'SDAI_Application_instance* ReadEntityRef(std::__1::istream&, ErrorDescriptor*, const char*, InstMgrBase*, int)': /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/sdaiApplication_instance.cc:680:33: warning: this statement may fall through [-Wimplicit-fallthrough=] 680 | err->GreaterSeverity( SEVERITY_WARNING ); | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ /wrkdirs/share/dim/ports/cad/openvsp/work/.build/Libraries-prefix/src/Libraries-build/STEPCODE-prefix/src/STEPCODE/src/clstepcore/sdaiApplication_instance.cc:682:9: note: here 682 | case '#': { | ^~~~ As gcc's error messages are very hard to read, and clang does not produce these particular errors, it will be interesting to debug :)
Removing the CPPFLAGS and still having USE_GCC= 9+ builds but segfaults with identical backtrace: Program received signal SIGSEGV, Segmentation fault. 0x0000000802efba18 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1 (gdb) bt #0 0x0000000802efba18 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1 #1 0x000000080234f3e6 in __dynamic_cast () from /usr/local/lib/gcc9/libstdc++.so.6 #2 0x00000008023d1e8e in bool std::has_facet<std::ctype<char> >(std::locale const&) () from /usr/local/lib/gcc9/libstdc++.so.6 #3 0x00000008023c3bd4 in std::basic_ios<char, std::char_traits<char> >::_M_cache_locale(std::locale const&) () from /usr/local/lib/gcc9/libstdc++.so.6 #4 0x00000008023c4070 in std::basic_ios<char, std::char_traits<char> >::init(std::basic_streambuf<char, std::char_traits<char> >*) () from /usr/local/lib/gcc9/libstdc++.so.6 #5 0x0000000802363463 in std::ios_base::Init::Init() () from /usr/local/lib/gcc9/libstdc++.so.6 #6 0x000000000049f60d in ?? () #7 0x000000080194846e in ?? () from /libexec/ld-elf.so.1 #8 0x00007fffffffc818 in ?? () #9 0x0000000801975800 in ?? () #10 0x0000000000000000 in ?? () The executable is linked against both libstdc++ and libc++ fernape@beastie:~/FreeBSD-repos/ports/head/cad/openvsp$ ldd /usr/local/bin/vsp | grep '\+\+' libstdc++.so.6 => /usr/local/lib/gcc9/libstdc++.so.6 (0x8022ab000) libc++.so.1 => /usr/lib/libc++.so.1 (0x802e0f000)
(In reply to Dimitry Andric from comment #4) Hmm: -USES= compiler:c++11-lang cmake:noninja localbase\ +USES= compiler:gcc-c++11-lib compiler:openmp cmake:noninja localbase\ gl gnome jpeg xorg vs. . . . /sdaiApplication_instance.cc:13: /usr/include/c++/v1/memory: In instantiation of . . . Looks like a FreeBSD libc++ header is in use for an intended gcc libstdc++ library use?
(In reply to Mark Millard from comment #6) Yes, that is precisely the point, you want to use libc++ headers and libraries. You can use g++ as a compiler, but you should *not* use libstdc++ with it. That is, unless you can ensure 100% that no C++ code compiled for libc++ and libstdc++ ever mix. Which definitely is not the case for this port...
(In reply to Dimitry Andric from comment #7) .if ${_COMPILER_ARGS:Mfeatures} .if defined(_CXXINTERNAL_${_CXX_hash}) _CXXINTERNAL= ${_CXXINTERNAL_${_CXX_hash}} .else _CXXINTERNAL!= ${CXX} -\#\#\# /dev/null 2>&1 _CXXINTERNAL_${_CXX_hash}= ${_CXXINTERNAL} PORTS_ENV_VARS+= _CXXINTERNAL_${_CXX_hash} .endif .if ${_CXXINTERNAL:M\"-lc++\"} COMPILER_FEATURES= libc++ .else COMPILER_FEATURES= libstdc++ .endif When I the command with -### for g++9 I find a: "-lstdc++" and no instance of -lc++. So I get COMPILER_FEATURES being libstdc++ . Then later I see: .if ${_COMPILER_ARGS:Mgcc-c++11-lib} USE_GCC= yes CHOSEN_COMPILER_TYPE= gcc .if ${COMPILER_FEATURES:Mlibc++} CXXFLAGS+= -nostdinc++ -isystem /usr/include/c++/v1 LDFLAGS+= -L${WRKDIR} _USES_configure+= 200:gcc-libc++-configure gcc-libc++-configure: @${LN} -fs /usr/lib/libc++.so ${WRKDIR}/libstdc++.so .endif .endif which would not set the likes of -nostdinc++ and related material. Have I missed something?
(In reply to Mark Millard from comment #8) I've never made a FreeBSD port force a gcc to be libc++ based but I have done such in Makefiles of my own software on FreeBSD. I used (extracted examples): CXX= g++9 -v -std=c++17 -Wno-psabi -nostdinc -nostdinc++ -I/usr/include/c++/v1 -I/usr/include and for use in linking: LDCXX= -nodefaultlibs -lc++ -lcxxrt -lthr -lm -lc -lgcc_s This gives a hint at the options I'd expect to be in use (other than -v and -std=...). When I looked around it did not appear to me that the FreeBSD ports infrastructure was set up to deal with g++*'s using libc++ --only with clang++ dealing with either libc++ or libstdc++ .
(In reply to Dimitry Andric from comment #3) I would add that LDFLAGS (or some other linker variable) is the appropriate variable for libraries. CPPFLAGS is entirely inappropriate - this is for preprocessor flags. CFLAGS and CXXFLAGS are the standard variables for C and C++ compilation. Also, isn't libgcc just a symlink to libcompiler_rt?