rui314 / mold

Mold: A Modern Linker 🦠
MIT License
13.69k stars 448 forks source link

Segmentation fault when compiling ROOT #1270

Closed jmcarcell closed 1 month ago

jmcarcell commented 1 month ago

When compiling ROOT, I get a segmentation fault only when using mold, ld, lld and gold all work fine, with GCC 13, 14 and Clang 16 and 17. Originally reported in https://github.com/root-project/root/issues/15473 Steps to reproduce:

git clone https://github.com/root-project/root
# Install mold and have it available in PATH, for example in /usr/bin
export LDFLAGS="-fuse-ld=mold"
cd root
mkdir builddir
cd builddir
cmake .. DCMAKE_CXX_STANDARD=20 -Dminimal=ON -G Ninja
ninja

And after waiting some time, errors like this one will appear:

[7643/9449] Generating G__RHTTP.cxx, ../../lib/RHTTP.pcm
FAILED: net/http/G__RHTTP.cxx lib/RHTTP.pcm /root/builddir/net/http/G__RHTTP.cxx /root/builddir/lib/RHTTP.pcm
cd /root/builddir/net/http && /usr/bin/cmake -E env LD_LIBRARY_PATH=/root/builddir/lib:/usr/local/lib: ROOTIGNOREPREFIX=1 /root/builddir/bin/rootcling -rootbuild -v2 -f G__RHTTP.cxx -cxxmodule -s /root/builddir/lib/libRHTTP.so -m RIO.pcm -m Thread.pcm -excludePath /root -excludePath /root/builddir/ginclude -excludePath /root/builddir/externals -excludePath /root/builddir/builtins -DUSE_WEBSOCKET -DUSE_X_DOM_SOCKET -DNO_SSL -DHTTP_WITHOUT_FASTCGI -compilerI/usr/include/c++/14.1.1 -compilerI/usr/include/c++/14.1.1/x86_64-pc-linux-gnu -compilerI/usr/include/c++/14.1.1/backward -compilerI/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/include -compilerI/usr/local/include -compilerI/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/include-fixed -compilerI/usr/include -compilerI/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/include -compilerI/usr/local/include -compilerI/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/include-fixed -compilerI/usr/include -I/root/builddir/include -I/usr/include -I/root/net/http/inc -I/root/core/unix/../clib/res -I/root/core/unix/inc -I/usr/include -I/root/core/zstd/inc -I/root/core/lz4/inc -I/root/core/lzma/inc -I/root/core/zip/inc -I/root/core/thread/inc -I/root/core/textinput/src -I/root/core/textinput/inc -I/root/core/rint/inc -I/root/core/meta/inc -I/root/core/gui/inc -I/root/core/foundation/res -I/root/core/foundation/v7/inc -I/root/core/foundation/inc -I/root/core/cont/inc -I/root/core/clingutils/res -I/root/core/clingutils/inc -I/root/core/clib/inc -I/root/core/base/v7/inc -I/root/core/base/inc -I/root/builddir/ginclude -I/root/io/io/v7/inc -I/root/io/io/inc -I/root/core/clib/res THttpCallArg.h THttpEngine.h THttpServer.h THttpWSHandler.h TRootSniffer.h TRootSnifferStore.h /root/net/http/inc/LinkDef.h
Segmentation fault

The issue seems to be the libCling.so library since I was able to compile fine by changing the linker used only for this target. The command above fails because rootcling is linked to libCling.so. The corresponding target is added in the CMakeLists.txt here: https://github.com/root-project/root/blob/master/core/metacling/src/CMakeLists.txt#L112. Cling is built on top of a patched version of LLVM 16 that can be found here: https://github.com/root-project/llvm-project.

rui314 commented 1 month ago

Thank you for your report. I can reproduce the issue, and I think I found the cause of it. I'll submit a fix shortly.

rui314 commented 1 month ago

The above commit should fix the issue. ROOT passes both -z defs and --undefined=ignore-in-object-files to the linker, which triggered the bug. In this case, -z defs is redundant, as --undefined=ignore-in-object-files appears after that and override -z defs. If you remove -z defs from the build file, ROOT could be built with the current version of mold.

jmcarcell commented 1 month ago

Thanks for the fix @rui314 I had a look and tried removing -z defs in the only place I could find it but I still got the same error (here). Alternatively I can just wait for the next version.

rui314 commented 1 month ago

Yeah, it's been a month since the last release, and there are a few important bug fixes since then, so it may be a good idea to make another maintenance release.