root-project / cling

The cling C++ interpreter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Out of memory at linking stage

xsbee opened this issue · comments

commented
  • Checked for duplicates

Describe the bug

Building cling runs out of memory at the linking stage.

Expected behavior

Cling to be successfully built.

To Reproduce

  1. Clone cling repo.
  2. Run ./cpt.py --check-requirements && ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/

Setup

  1. Cling version: master branch
  2. Operating System: Linux

Additional context

[100%] Linking CXX executable ../../../../bin/cling

out of memory allocating 239168 bytes after a total of 18446698046162099904 bytes
collect2: error: ld returned 1 exit status
make[3]: *** [tools/cling/tools/driver/CMakeFiles/cling.dir/build.make:293: bin/cling] Error 1
make[3]: *** Deleting file 'bin/cling'
make[2]: *** [CMakeFiles/Makefile2:68152: tools/cling/tools/driver/CMakeFiles/cling.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:68159: tools/cling/tools/driver/CMakeFiles/cling.dir/rule] Error 2
make: *** [Makefile:14606: cling] Error 2
subprocess.CalledProcessError: Command 'make -j 2 cling' returned non-zero exit status 2
commented

@xsbee that's because cling does static linking against LLVM/Clang. IIRC the resulting release binary is over 100MB, and debug version is close to half a gig. 🤯

It's been a long time since I've tried that, so my numbers might be off a bit, but you get the point.

The "propah" way to do this would be to use dynamic linking against libclang and libLLVM, which is what I've done. If you are on Ubuntu 20.04 or 22.04 (23.04 coming soon), you try these packages:

https://launchpad.net/~ppa-verse/+archive/ubuntu/xeus-cling

Right, we're very hesitant to use dynamic linking because these days, the world pulls in their own set of llvm libraries, all with slightly different versions and often (like with cling...) with slight patches. We have seen graphics drivers and cling cause clashes in llvm symbols - linking statically with all symbols hidden is the solution. Get more RAM! ;-)

commented

these days, the world pulls in their own set of llvm libraries

The world has gone crazy. In more than one aspect. They should either use the system libraries, or if they need patches like cling, they should put them in the right place so they don't interfere with the system libs.

Get more RAM!

This is not the right answer and it's not always possible. Eg, I've tried building static cling on Ubuntu's launchpad for my .deb packages, and it kept failing due to insufficient RAM.

Well it's hard. LLVM has no stable API, which makes it virtually impossible to find the right LLVM version installed. And patches cannot be moved elsewhere, they really change LLVM itself...

commented

@Axel-Naumann not sure about that. Large distros like Debian and Ubuntu usually provide several stable versions. Eg, I'm on Ubuntu 22.04 and they provide LLVM-11 through LLVM-15.

But again, if you need a custom version, just stick the libs with your package (eg, /usr/libexec/cling) and not into /usr/lib.

People like to throw more RAM, disk space and CPU clocks at every problem. The result is: it takes the same amount of time on average to open a file or launch a program, as it did 20 years ago, despite the fact that current computers are million times faster than they were 20 years ago. 😞

I agree, but I don't know how to solve this. C++ isn't C++98 anymore, a C++ compiler is a monster these days, and cling is witnessing this. We try to upstream everything to be able to reuse unchanged LLVM / clang libraries - but we are not there yet. Until then you'll have to throw RAM at cling in debug mode.

Let me know if there's something concrete for us to fix!

commented

Let me know if there's something concrete for us to fix!

@Axel-Naumann you can find all the patches you need here: https://github.com/dimitry-ishenko-cpp/llvm-clang-9
and here: https://github.com/dimitry-ishenko-cpp/cling-packaging

There are instructions on how to build Debian packages as well.

Does that fix the memory usage of the linking step?

If not, could you post this at the appropriate bug or create a new one, please?

Thanks a LOT for sharing these links! I'll try to integrate them in August (sorry, long vacation and full work calendar in July...)

commented

@Axel-Naumann those links are basically what I use to create .deb packages with patched version of LLVM/Clang 9 and cling, which is dynamically linked against it.

Does that fix the memory usage of the linking step?

Absolutely. The size of my cling binary is 1.7M and libcling.so.9 is 1.6M.

commented

@Axel-Naumann if you need my help when you are back, feel free to holler