LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 19031 - Small testcase uses extreme amount of memory if compiled with -g and -mrelocation-model static
Summary: Small testcase uses extreme amount of memory if compiled with -g and -mreloca...
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: 3.4
Hardware: PC All
: P release blocker
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-03 15:05 PST by Dimitry Andric
Modified: 2014-11-12 13:55 PST (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments
Small testcase using way too much memory for its size (2.15 KB, application/octet-stream)
2014-03-03 15:05 PST, Dimitry Andric
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric 2014-03-03 15:05:24 PST
Created attachment 12180 [details]
Small testcase using way too much memory for its size

A post on the FreeBSD toolchain mailing list showed a clang crash due to OOM:
http://lists.freebsd.org/pipermail/freebsd-toolchain/2014-February/001125.html

the log of the build is here (crash is at the end):
http://beefy2.isc.freebsd.org/bulk/head-amd64-default/2014-02-28_01h43m56s/logs/arx-libertatis-1.0.3_2.log

The OP notes an RSS of 15GB.  I did some creduce'ing on his sample files, using clang trunk r202496, and ended up with the attached sample program, just ~100 lines of code.  If you compile this with just -O2, it is very fast to compile, and uses little memory:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelocation-model static -O2 too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        0.04 real         0.02 user         0.00 sys
     19020  maximum resident set size
     42992  average shared memory size
       101  average unshared data size
       298  average unshared stack size
      1057  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        20  messages sent
         0  messages received
         0  signals received
        22  voluntary context switches
         0  involuntary context switches

if you add -g, though, it suddenly balloons to ~2.5 GiB!  E.g.:

$ time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -mrelocation-model static -O2 -g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        7.87 real         4.26 user         3.53 sys
   2661660  maximum resident set size
     32178  average shared memory size
        75  average unshared data size
       255  average unshared stack size
   1069959  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        27  messages sent
         0  messages received
         0  signals received
        30  voluntary context switches
       167  involuntary context switches

I know generating debug information always uses more memory, but this is a little bit ridiculous. :-)

Also interesting is that removing the -mrelocation-model static helps:

$ /usr/bin/time -l clang -cc1 -triple x86_64-unknown-freebsd11.0 -emit-obj -O2 -g too-much-mem.cpp
too-much-mem.cpp:40:1: warning: inline namespaces are a C++11 feature
inline namespace __1 {
^
1 warning generated.
        0.07 real         0.01 user         0.03 sys
     19476  maximum resident set size
     19346  average shared memory size
        45  average unshared data size
       153  average unshared stack size
      1156  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
        36  messages sent
         0  messages received
         0  signals received
        38  voluntary context switches
         0  involuntary context switches

So this seems to be some sort of bad interaction between the static relocation model and debug information generation?

When building the original testcase from the mailing list, this is all even worse, and it blows up my testing VM before it can compile, having used up at least 8GB resident set size.  Similarly to the minimized testcase, removing -mrelocation-model static allows it to compile, within about 3.5 seconds, and just 91 MiB of RSS.

I can also reproduce these results on Linux, btw, so it is not specifically FreeBSD-related.
Comment 1 Eric Christopher 2014-03-03 15:24:11 PST
It's a problem with resolving all of the dbg_value instructions I believe.
Comment 2 Dmitry Marakasov 2014-04-24 18:58:05 PDT
I'd allow myself to rise its priority. This bug affects much software and will probably block FreeBSD 11 may its release happen soon enough.
Comment 3 Dimitry Andric 2014-11-12 13:55:55 PST
Fixed by r221709, similar to bug 20893.