How much memory clang llvm needs for debug compiling?

Hi,

$cd llvm-build
$../llvm/configure --enable-targets=x86

make[4]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang/tools/libclang'
make[4]: ÕýÔÚ½øÈëĿ¼ `/home/nancy/work/build-llvm/tools/clang/tools/c-index-test'
llvm[4]: Linking Debug+Asserts executable c-index-test
llvm[4]: ======= Finished Linking Debug+Asserts Executable c-index-test
make[4]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang/tools/c-index-test'
make[4]: ÕýÔÚ½øÈëĿ¼ `/home/nancy/work/build-llvm/tools/clang/tools/c-arcmt-test'
llvm[4]: Linking Debug+Asserts executable c-arcmt-test
llvm[4]: ======= Finished Linking Debug+Asserts Executable c-arcmt-test
make[4]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang/tools/c-arcmt-test'
make[4]: ÕýÔÚ½øÈëĿ¼ `/home/nancy/work/build-llvm/tools/clang/tools/driver'
llvm[4]: Linking Debug+Asserts executable clang
/usr/bin/ld: ×îÖÕÁ¬½Óʧ°Ü: ÄÚ´æºÄ¾¡ ( in english : Memory exhausted)
collect2: error: ld returned 1 exit status
make[4]: *** [/home/nancy/work/build-llvm/Debug+Asserts/bin/clang] ´íÎó 1
make[4]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang/tools/driver'
make[3]: *** [driver/.makeall] ´íÎó 2
make[3]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang/tools'
make[2]: *** [all] ´íÎó 1
make[2]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools/clang'
make[1]: *** [clang/.makeall] ´íÎó 2
make[1]:ÕýÔÚÀ뿪Ŀ¼ `/home/nancy/work/build-llvm/tools'
make: *** [all] ´íÎó 1

What should I do to make debug enabled compiling successful? Anyone
can tell me a tiny configuration which can save memory? I only have 3G
RAM, Ubuntu kylin.

I have a 7 years old computer with 1 GB RAM and I was able to build clang in debug mode. I created a swap file of 4 GB I think, and I’ve stopped using the computer at all, just grab some tea and wait.

This link shows you how you can create a swap file:
http://askubuntu.com/questions/178712/how-to-increase-swap-space

At least for me it worked well.

Hi,

What should I do to make debug enabled compiling successful? Anyone
can tell me a tiny configuration which can save memory? I only have 3G
RAM, Ubuntu kylin.

3GB is probably going to be painful no matter what you do, but there
are a few things to try.

First, you could switch to ld.gold instead of ld.bfd. It uses much
less memory when linking. It can also be helpful to reduce the
parallelism of the build so that only one thing is linking at any one
time.

Finally, you can build clang with the debug info in separate files.
This needs a newer gdb & gcc/clang to work properly, but 14.04 should
be fine. This made a massive difference to me, so I'm really keen on
the idea. I think for autoconf you need ".../configure
--enable-split-dwarf" to use this.

Good luck!

Tim.

Hi,

Just a question: are you doing the actual build on a 32-bit x86 machine (not
a 64-bit x86-64 machine)? This seems to be sensible, but I've rarely had
problems doing a debug build on x86 within 2GB of memory (after ensuring
only one link at once); it's always been the x86-64 builds that are tricky
under low memory.

Regards,
Dave

Also, here the problem is ld. Switching to gold may help to resolve the problem.

Debug information is pretty large, especially for the link step. If
you have a recent gdb you can use the split dwarf configure option
which should reduce the memory requirements of the link quite
significantly (nearly back to no debug information).

-eric

First, you could switch to ld.gold instead of ld.bfd. It uses much

$ln -s `which gold` /usr/local/bin/ld

the idea. I think for autoconf you need ".../configure
--enable-split-dwarf" to use this.

$.../configure --enable-targets=x86 --enable-split-dwarf
$ make -j2
$ sudo make install

It works for me. Thanks a lot!

I want to use emacs+gdb to trace the code work flow.
M-x gdb
Run like gdb --annotate=3 clang
(gdb) set args test.c
(gdb) b main
(gdb) b /home/nancy/work/llvm/tools/clang/lib/Lex/Lexer.cpp:57
(gdb) r
It block at llvm/tools/clang/tools/driver/driver.cpp main() fucntion.
(gdb) c
program exit normally
why? why it not call Lexer.cpp:InitLexer()? And I really can't find
any entry point to clang/lib/*.cpp files within help of SourceInsight
code view start from llvm/tools/clang/tools/driver/driver.cpp main()
function.

What's wrong with me?

Yes, I'm sure it is X86. Thinkpad T61. Maybe you had tried the older
version. Latest version do not work. The problem solved. Thank you all
the same!

Oh, Another way to make it work. Thank you :slight_smile:

You need to use the -cc1 option that clang is being reinvoked with,
use the -v option on your original command line to take a look at it.

Also, if you're just doing development you don't need to install the
binary. The clang in build/Debug+Asserts/bin/clang will work just
fine.

-eric

Hi, eric

   Thank you for your -v advice

$clang -v test.c
....

Selected GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Candidate multilib: .;@m32
Selected multilib: .;@m32
"/usr/local/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj
-mrelax-all -disable-free -main-file-name test.c -mrelocation-model
static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -fuse-init-array -target-cpu pentium4
-target-linker-version 2.24 -v -resource-dir
/usr/local/bin/../lib/clang/3.5.0 -internal-isystem /usr/local/include
-internal-isystem /usr/local/bin/../lib/clang/3.5.0/include
-internal-externc-isystem /usr/include/i386-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem
/usr/include -fdebug-compilation-dir /home/nancy/work/test
-ferror-limit 19 -fmessage-length 80 -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -o /tmp/test-85913a.o -x c test.c

clang -cc1 version 3.5.0 based upon LLVM 3.5.0svn default target
i386-pc-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/local/bin/../lib/clang/3.5.0/include
/usr/include/i386-linux-gnu
/usr/include
End of search list.
......

I use
"-cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name test.c -mrelocation-model static -mdisable-fp-elim
-fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array
-target-cpu pentium4 -target-linker-version 2.24 -v -resource-dir
/usr/local/bin/../lib/clang/3.5.0 -internal-isystem /usr/local/include
-internal-isystem /usr/local/bin/../lib/clang/3.5.0/include
-internal-externc-isystem /usr/include/i386-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem
/usr/include -fdebug-compilation-dir /home/nancy/work/test
-ferror-limit 19 -fmessage-length 80 -mstackrealign -fobjc-runtime=gcc
-fdiagnostics-show-option -o /tmp/test-85913a.o -x c
/home/nancy/work/test/test.c"

as (gdb)set args parameters and setup those breakpoins and run, it
still normally exist without stopping at breakpoint I set in
Lexer.cpp.

Could you please tell me the specific steps?

Hi Nancy,

Have you tried setting follow-fork-mode to the child process?

https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

Best regards,
Gabor Ballabas

Hi Gabor,
   Thank you very much for your information! I learn how to use GDB
debug Multiple Interior/Threads today.
   It works!

Hi Eric,
   So sorry for the wrong feedback I gave yesterday. It also works!
Maybe because some wrong emacs enviroment setting or ....Today I try
again, this way is more directly and efficient!
Thank you very much !!!