root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.54k stars 1.24k forks source link

Segmentation fault when building with the mold linker #15473

Open jmcarcell opened 2 months ago

jmcarcell commented 2 months ago

Check duplicate issues.

Description

When using the mold linker there is a segmentation fault when running rootcling, like here

[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

I haven't tried with lld to see if it also doesn't build. This is certainly not very important, but I'm reporting here in case someone else finds this. EDIT: lld works fine for me.

Reproducer

# Install mold and have it available in PATH, for example in /usr/bin
export LDFLAGS="-fuse-ld=mold"
# from the root source
mkdir builddir
cd builddir
cmake .. DCMAKE_CXX_STANDARD=20 -Dminimal=ON -G Ninja
ninja

ROOT version

master, any recent one also doesn't work

Installation method

Build from source

Operating system

Linux (Arch)

Additional context

I'm compiling with GCC 13 and 14

dpiparo commented 2 months ago

Hi @jmcarcell , how is the linker related to the command that fails for you? That is the invocation of rootcling, the generator of dictionaries. Could you confirm that the problem is there also if you do not export the LDFLAGS env variable?

jmcarcell commented 2 months ago

I have no idea why that's happening but it's definitely that because building with LDFLAGS empty (so using /usr/bin/ld) works fine. I just checked and using lld works fine, I'll add to the issue.

jmcarcell commented 1 month ago

I reported this to mold in https://github.com/rui314/mold/issues/1270 and was able to compile by using a different linker for libCling.so. However, many of the tests fail (with segmentation faults) so I think it's best not to allow compiling with mold at all.

guitargeek commented 1 month ago

Closed by #15689 and it's backport to 6.32.

vgvassilev commented 1 month ago

We should apply the suggested fix in the bugreport submitted to the mold linker.

silverweed commented 3 weeks ago

I just tried to build master with mold 2.32.0 (released last week) and it worked fine. Also, for some reason the CMakeLists check didn't prevent me from using mold as a linker, so I think it's defective. We should either remove it or fix it, and if we fix it we want to check for the mold version, since there's no point in disallowing mold >= 2.32.

Here is my cmake cmdline:

cmake -Ddev=on -Dtesting=on -Dccache=on -Droot7=on -Dbuiltin_davix=off  -During=on -DCMAKE_BUILD_TYPE=debug -Dtmva=on -Droofit=on  -Dbuiltin_pcre=off -Dbuiltin_zstd=on -Dbuiltin_lz4=off -Dbuiltin_lzma=off -Dbuiltin_xxhash=off -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=mold' -DCMAKE_SHARED_LINKER_FLAGS='-fuse-ld=mold' -DCMAKE_MODULE_LINKER_FLAGS='-fuse-ld=mold' -DCMAKE_EXPORT_COMPILE_COMMANDS=on  -G Ninja ../../root

I then built with

mold -run cmake --build . -j32

I verified that mold was indeed called instead of the default linker by doing watch -n 0.5 pgrep mold and watch -n 0.5 pgrep lld: the first one showed some output several times during compilation, the second didn't.