public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/53808] New: Undefined symbol when building a library with lto
@ 2012-06-29 18:20 rafael.espindola at gmail dot com
  2012-07-03 13:18 ` [Bug lto/53808] " hubicka at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: rafael.espindola at gmail dot com @ 2012-06-29 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53808
           Summary: Undefined symbol when building a library with lto
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rafael.espindola@gmail.com


The gcc lto plugin can drop a symbol that another translation unit has an
undefined reference to.

This might also be a bug in gcc (>= 4.6, with and without lto) producing an
undefined reference, the ABI is not very clear.

$ cat test.h
struct foo {
 virtual ~foo();
};
struct bar : public foo {
 virtual void zed();
};
$ cat def.cpp
#include "test.h"
void bar::zed() {
}
$ cat undef.cpp
#include "test.h"
void f() {
 foo *x(new bar);
 delete x;
}

Compile with:

$ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ -c undef.cpp -o undef.o -O3 -fPIC
$ nm undef.o | grep D0
                U _ZN3barD0Ev

$ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ -c def.cpp -o def.o -O3 -flto -fPIC
$ ~/gcc/build/gcc/xgcc -B ~/gcc/build/gcc/ def.o -o def.so -shared
-fuse-linker-plugin
$ readelf  -sDW def.so | grep bar
  12   7: 0000000000000931     5 OBJECT  WEAK   DEFAULT  13 _ZTS3bar
  11  10: 0000000000001ca0    40 OBJECT  WEAK   DEFAULT  24 _ZTV3bar
  13  14: 0000000000001cd0    24 OBJECT  WEAK   DEFAULT  24 _ZTI3bar
   8  15: 00000000000008b0    10 FUNC    GLOBAL DEFAULT  11 _ZN3bar3zedEv


Note that we have the vtable, but no the destructor.

$ g++ -shared -o foo.so undef.o def.so -Wl,-z,defs
undef.o:undef.cpp:function f(): error: undefined reference to 'bar::~bar()'


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

end of thread, other threads:[~2014-09-10 14:28 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-29 18:20 [Bug lto/53808] New: Undefined symbol when building a library with lto rafael.espindola at gmail dot com
2012-07-03 13:18 ` [Bug lto/53808] " hubicka at gcc dot gnu.org
2012-11-06 13:53 ` rafael.espindola at gmail dot com
2013-03-23  0:36 ` jason at gcc dot gnu.org
2013-03-23 21:40 ` hubicka at ucw dot cz
2013-09-04 12:26 ` rafael.espindola at gmail dot com
2014-02-25 17:47 ` jason at gcc dot gnu.org
2014-02-25 17:57 ` jason at gcc dot gnu.org
2014-02-25 18:55 ` jason at gcc dot gnu.org
2014-02-25 19:00 ` jason at gcc dot gnu.org
2014-02-26 21:33 ` jason at gcc dot gnu.org
2014-06-30 20:21 ` jason at gcc dot gnu.org
2014-07-22 14:03 ` rafael.espindola at gmail dot com
2014-07-30 17:28 ` jason at gcc dot gnu.org
2014-07-30 21:30 ` jason at gcc dot gnu.org
2014-08-19 17:30 ` jason at gcc dot gnu.org
2014-09-10 14:28 ` jason at gcc dot gnu.org

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).