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

            Bug ID: 59236
           Summary: Mixing -O0 and -O2 object causes link error because of
                    corrupted comadts
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rafael.espindola at gmail dot com
            Target: mingw

$ cat test1.cpp
#include "test.h"
struct zed : public foo {
  virtual ~zed();
};
zed::~zed() {}

$ cat test2.cpp
#include "test.h"
struct zed2 : public foo {
  virtual ~zed2();
};
zed2::~zed2() {}

$ cat test.h
class foo {
  virtual void bar() { __builtin_unreachable(); }
};

$ i686-w64-mingw32-g++ -fno-rtti -fno-exceptions -c test1.cpp
$ i686-w64-mingw32-g++ -fno-rtti -fno-exceptions -c test2.cpp -O2
$ i686-w64-mingw32-g++ -fno-rtti -fno-exceptions test1.o test2.o -o t.so
-shared

test2.o:test2.cpp:(.text$_ZN3foo3barEv+0x0): multiple definition of
`foo::bar()'
test1.o:test1.cpp:(.text$_ZN3foo3barEv[__ZN3foo3barEv]+0x0): first defined here
collect2: error: ld returned 1 exit status


The problem seems to be that test1.o has

  3 .text$_ZN3foo3barEv 0000000c  00000000  00000000  0000014c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD
(COMDAT __ZN3foo3barEv 4)

while test2.o has

  4 .text$_ZN3foo3barEv 00000000  00000000  00000000  00000000  2**4
                  ALLOC, LOAD, READONLY, CODE, LINK_ONCE_DISCARD

noticed that the comdat symbol is missing.

Reply via email to