g++ fails to link when using the -flto switch

Bug #885927 reported by Lucas Clemente Vella
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
binutils (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Any C++ program I tried to build with GCC failed with undefined reference errors. As a test case, I have created a simple Hello World program:

$ cat hello.cpp
#include <iostream>

int main()
{
  std::cout << "Hello world!" << std::endl;
}

$ g++ -o hello hello.cpp -flto
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_GetDataRelBase@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_SetIP@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_RaiseException@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_GetLanguageSpecificData@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_GetRegionStart@GCC_3.0'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_dl_argv@GLIBC_PRIVATE'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_DeleteException@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_SetGR@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_Resume@GCC_3.0'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_GetIPInfo@GCC_4.2.0'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_rtld_global_ro@GLIBC_PRIVATE'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `__tls_get_addr@GLIBC_2.3'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_Resume_or_Rethrow@GCC_3.3'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `_rtld_global@GLIBC_PRIVATE'
/lib/x86_64-linux-gnu/libc.so.6: undefined reference to `__libc_enable_secure@GLIBC_PRIVATE'
/usr/lib/gcc/x86_64-linux-gnu/4.6.1/libstdc++.so: undefined reference to `_Unwind_GetTextRelBase@GCC_3.0'
collect2: ld returned 1 exit status

Every C++ program I tried to build with -flto failed at link stage. C programs compile without problems. A workaround is to add the -B/usr/lib/gold-ld/ switch to the command line:

$ g++ -B/usr/lib/gold-ld/ -flto -o hello hello.cpp
$ # Success

ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: binutils 2.21.53.20110810-0ubuntu4
ProcVersionSignature: Ubuntu 3.0.0-12.20-generic 3.0.4
Uname: Linux 3.0.0-12-generic x86_64
NonfreeKernelModules: fglrx
ApportVersion: 1.23-0ubuntu4
Architecture: amd64
Date: Thu Nov 3 21:43:56 2011
InstallationMedia: Ubuntu 11.04 "Natty Narwhal" - Release amd64 (20110427.1)
ProcEnviron:
 LANGUAGE=pt_BR:pt:en
 PATH=(custom, no user)
 LANG=pt_BR.UTF-8
 SHELL=/bin/bash
SourcePackage: binutils
UpgradeStatus: Upgraded to oneiric on 2011-10-15 (19 days ago)

Revision history for this message
Lucas Clemente Vella (lvella-gmail) wrote :
Ankit Saini (ankit28595)
Changed in binutils (Ubuntu):
status: New → Confirmed
Ankit Saini (ankit28595)
tags: removed: running-unity
Revision history for this message
Matthias Klose (doko) wrote :

fixed in -updates

Changed in binutils (Ubuntu):
status: Confirmed → Fix Released
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.