public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/49571] New: -flto -Wl,--as-needed drops needed libraries
@ 2011-06-28 23:31 b.r.longbons at gmail dot com
  2011-06-28 23:38 ` [Bug lto/49571] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: b.r.longbons at gmail dot com @ 2011-06-28 23:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49571

           Summary: -flto -Wl,--as-needed drops needed libraries
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: b.r.longbons@gmail.com


Created attachment 24624
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24624
Minimal testcase demonstrating the error

Description:
-flto does something funny that makes --as-needed drop more libraries than it
should. See the attached file

Context:
I originally encountered this bug in a big C++ project with -m32, but quickly
reduced it to the attached minimal testcase.
Only in the original project, I got this misleading error:
/usr/bin/ld: /tmp/ccPEhCnW.ltrans4.ltrans.o: undefined reference to symbol
'sqrt@@GLIBC_2.0'
/usr/bin/ld: note: 'sqrt@@GLIBC_2.0' is defined in DSO
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/../../../../../lib32/libm.so
so try adding it to the linker command line
despite -lm *being* explicitly on the command line (which is normally not
needed in C++? Is that standard behavior or is it relying on the indirect
linking thing that *usually* generates that error?)

but this was replaced in the minimal case by the more typical
ccp7SO9X.ltrans0.o:(.text+0x29): undefined reference to `sqrt'


Workaround:
Identify which libraries are *actually* needed and pass them after
-Wl,--no-as-needed.
This works for my particular case (I am building multiple binaries, only one of
which requires -lm) since libm would be loaded indirectly by libstdc++ anyway,
but could be problematic in the general case




System information 1:
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.6.0/work/gcc-4.6.0/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.0
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.0/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --without-ppl --without-cloog --enable-lto --disable-nls
--with-system-zlib --disable-werror --enable-secureplt --enable-multilib
--enable-libmudflap --disable-libssp --enable-libgomp --enable-cld
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.6.0/python
--enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.6.0 p1.2, pie-0.4.5'
Thread model: posix
gcc version 4.6.0 (Gentoo 4.6.0 p1.2, pie-0.4.5) 

System information 2:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.0-13'
--with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++,go --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-multiarch
--with-multiarch-defaults=x86_64-linux-gnu --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib/x86_64-linux-gnu
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib/x86_64-linux-gnu
--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-objc-gc
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.1 20110611 (prerelease) (Debian 4.6.0-13)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries
  2011-06-28 23:31 [Bug lto/49571] New: -flto -Wl,--as-needed drops needed libraries b.r.longbons at gmail dot com
@ 2011-06-28 23:38 ` pinskia at gcc dot gnu.org
  2011-06-29  9:42 ` [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries with GNU ld and linker plugin rguenth at gcc dot gnu.org
  2014-08-06 10:38 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-06-28 23:38 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49571

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-06-28 23:37:39 UTC ---
I think this only fails when the LTO plugin is enabled.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries with GNU ld and linker plugin
  2011-06-28 23:31 [Bug lto/49571] New: -flto -Wl,--as-needed drops needed libraries b.r.longbons at gmail dot com
  2011-06-28 23:38 ` [Bug lto/49571] " pinskia at gcc dot gnu.org
@ 2011-06-29  9:42 ` rguenth at gcc dot gnu.org
  2014-08-06 10:38 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-29  9:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49571

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011.06.29 09:42:15
                 CC|                            |davek at gcc dot gnu.org
            Summary|-flto -Wl,--as-needed drops |-flto -Wl,--as-needed drops
                   |needed libraries            |needed libraries with GNU
                   |                            |ld and linker plugin
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-29 09:42:15 UTC ---
It works for me when using gold 2.21.1, it doesn't work with
GNU ld from the same version.  So I suggest to file a binutils bug instead.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries with GNU ld and linker plugin
  2011-06-28 23:31 [Bug lto/49571] New: -flto -Wl,--as-needed drops needed libraries b.r.longbons at gmail dot com
  2011-06-28 23:38 ` [Bug lto/49571] " pinskia at gcc dot gnu.org
  2011-06-29  9:42 ` [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries with GNU ld and linker plugin rguenth at gcc dot gnu.org
@ 2014-08-06 10:38 ` amodra at gmail dot com
  2 siblings, 0 replies; 4+ messages in thread
From: amodra at gmail dot com @ 2014-08-06 10:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49571

Alan Modra <amodra at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |amodra at gmail dot com
         Resolution|---                         |WORKSFORME

--- Comment #3 from Alan Modra <amodra at gmail dot com> ---
Works with BFD ld too.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-08-06 10:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-28 23:31 [Bug lto/49571] New: -flto -Wl,--as-needed drops needed libraries b.r.longbons at gmail dot com
2011-06-28 23:38 ` [Bug lto/49571] " pinskia at gcc dot gnu.org
2011-06-29  9:42 ` [Bug lto/49571] -flto -Wl,--as-needed drops needed libraries with GNU ld and linker plugin rguenth at gcc dot gnu.org
2014-08-06 10:38 ` amodra at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).