ld crash generating map file for c++11 auto return type inference

Bug #1608898 reported by Greg Whiteley
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
binutils (Ubuntu)
Fix Released
Undecided
Unassigned
Xenial
New
Undecided
Unassigned

Bug Description

I'm getting a crash in ld while linking C++-11 auto return type code. ld starts madly allocating memory until your memory and swap are filled, then seg-faults. Use ulimit to avoid swap thrashing while reproducing:

$ ulimit -v 2147483648 # 2GB
$ g++ -Wall -ggdb -O0 --std=c++11 -Werror -Wl,-Map=_timing.map _timing_ld_crash_map.cpp -o _timing
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.

I've reduced the input source which is attached as _timing_ld_crash_map.cpp.

The following changes (on their own) make the problem "go away":

1. remove -Wl,-Map=...map from the command-line
2. stepping up to -O1 or higher. -Og fails must like -O0.
3. Making `runTest` `static`

It seems likely the compiler is emitting a symbol or symbols causing binutils to choke during mapfile generation. Its possible the compiler could be partly at fault, but clearly ld shouldn't max out the memory.

Wrapping the body (not the #includes) in #pragma optimisation for -O3 doesn't fix things so likely the std library symbols in <vector> are part of the problem.

$ lsb_release -rd
Description: Ubuntu 16.04 LTS
Release: 16.04

$ apt-cache policy binutils gcc g++
binutils:
  Installed: 2.26.1-1ubuntu1~16.04.1
  Candidate: 2.26.1-1ubuntu1~16.04.1
  Version table:
 *** 2.26.1-1ubuntu1~16.04.1 500
        500 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     2.26-8ubuntu2 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
gcc:
  Installed: 4:5.3.1-1ubuntu1
  Candidate: 4:5.3.1-1ubuntu1
  Version table:
 *** 4:5.3.1-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
g++:
  Installed: 4:5.3.1-1ubuntu1
  Candidate: 4:5.3.1-1ubuntu1
  Version table:
 *** 4:5.3.1-1ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status

Revision history for this message
Greg Whiteley (greg-whiteley) wrote :
Revision history for this message
Greg Whiteley (greg-whiteley) wrote :

Does not reproduce on 14.04, with binutils-2.24-5ubuntu14.1, g++/gcc-4:4.8.2-1ubuntu6

Revision history for this message
Matthias Klose (doko) wrote :

this seems to work in yakkety. in xenial I get a segfault, but i can't see the memory hog.

Changed in binutils (Ubuntu):
status: New → Fix Released
Revision history for this message
Greg Whiteley (greg-whiteley) wrote :

OK - the memory hog was the original error I had with our original (sadly proprietary) source code - before I added ulimit and stripped it down to the smallest possible code. In both cases the error was a seg-fault so I didn't notice when or if the memory hog went away.

I'll see what I can do to get the original code released in case there is a second bug.

What compiler/linker version is used in yakkety?

Also - I can't seem to install binutils-dbgsym package - does this exist?

Revision history for this message
Matthias Klose (doko) wrote :

$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.27
$ gcc --version
gcc (Ubuntu 6.1.1-11ubuntu12) 6.1.1 20160805

see https://wiki.ubuntu.com/Debug%20Symbol%20Packages for the debug packages.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.