cmajor-lang / cmajor

The Cmajor public repository
https://cmajor.dev
Other
522 stars 31 forks source link

Use after free errors while compiling with gcc 14.1.1 on Fedora 40 #75

Open ycollet opened 1 month ago

ycollet commented 1 month ago

I am trying to build cmajor for Fedora 40 and I've got a lot of "use after free" errors while compiling with gcc 14.1.1. Here is an example:

In member function ‘std::set<void*, std::less<void*>, std::allocator<void*> >::erase(void* const&)’,
    inlined from ‘GraphViz::GraphVizFree(void*)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/cmaj_GraphViz.cpp:72:23,
    inlined from ‘GraphViz::gvFreeRenderData(char*)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/./gvc/gvc.c:223:10,
    inlined from ‘convertDOTtoSVG(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)’ at /home/collette/rpmbuild/BUILD/cmajor/3rdParty/graphviz/cmaj_GraphViz.cpp:316:22:
/usr/include/c++/14/bits/stl_set.h:687:26: warning: pointer used after ‘free’ [-Wuse-after-free]
  687 |       { return _M_t.erase(__x); }
      |                ~~~~~~~~~~^~~~~

I added "-Wno-error=use-after-free" to the list of CXXFLAGS to workaround this problem.

cesaref commented 1 month ago

Thanks. It sounds like we need to add something to choc 'choc_DisableAllWarnings'. We have the strategy of trying to use external libraries as they are without 'fixing' them. Obviously we try and upstream changes, but for stuff like this the 'disable all warnings when compiling this unit' approach is pragmatic.

I'll look at getting a newer gcc build going and investigate this further.

ycollet commented 1 month ago

Thanks a lot for your quick answer. With my workaround, the build works. I will try the plugin soon.

ycollet commented 1 month ago

I try to package cmajor for Fedora. Some compilation flags are added to CMAKE_CXX_FLAGS:

-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
cesaref commented 1 month ago

Sorry, had a few other bits on but got around to trying this out. Can you try the latest release and see if i've resolved your warnings?