Bug 17670 - internal error in symval_for_branch, at powerpc.cc:6755 during qt5 build
Summary: internal error in symval_for_branch, at powerpc.cc:6755 during qt5 build
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.25
Assignee: Alan Modra
URL: https://gcc.gnu.org/bugzilla/show_bug...
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-02 16:26 UTC by Markus Trippelsdorf
Modified: 2014-12-04 02:17 UTC (History)
2 users (show)

See Also:
Host: powerpc64-unknown-linux-gnu
Target: powerpc64-unknown-linux-gnu
Build: powerpc64-unknown-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2014-12-02 16:26:55 UTC
Trying to build qt5 on ppc64:

trippels@gcc2-power8 corelib % g++ -Wl,--no-undefined -Wl,-e,qt_core_boilerplate -shared -Wl,-soname,libQt5Core.so.5 -o libQt5Core.so.5.3.2 .obj/qabstractanimation.o .obj/qvariantanimation.o .obj/qpropertyanimation.o .obj/qanimationgroup.o .obj/qsequentialanimationgroup.o .obj/qparallelanimationgroup.o .obj/qpauseanimation.o .obj/qatomic_unix.o .obj/qglobal.o .obj/qglobalstatic.o .obj/qlibraryinfo.o .obj/qmalloc.o .obj/qnumeric.o .obj/qlogging.o .obj/qatomic.o .obj/qexception.o .obj/qresultstore.o .obj/qfutureinterface.o .obj/qfuturewatcher.o .obj/qmutex.o .obj/qreadwritelock.o .obj/qrunnable.o .obj/qmutexpool.o .obj/qsemaphore.o .obj/qthread.o .obj/qthreadpool.o .obj/qthreadstorage.o .obj/qthread_unix.o .obj/qwaitcondition_unix.o .obj/qarraydata.o .obj/qbitarray.o .obj/qbytearray.o .obj/qbytearraymatcher.o .obj/qcollator.o .obj/qcommandlineoption.o .obj/qcommandlineparser.o .obj/qcryptographichash.o .obj/qdatetime.o .obj/qdatetimeparser.o .obj/qeasingcurve.o .obj/qelapsedtimer.o .obj/qfreelist.o .obj/qhash.o .obj/qline.o .obj/qlinkedlist.o .obj/qlist.o .obj/qlocale.o .obj/qlocale_tools.o .obj/qpoint.o .obj/qmap.o .obj/qmargins.o .obj/qmessageauthenticationcode.o .obj/qcontiguouscache.o .obj/qrect.o .obj/qregexp.o .obj/qregularexpression.o .obj/qrefcount.o .obj/qshareddata.o .obj/qsharedpointer.o .obj/qsimd.o .obj/qsize.o .obj/qstring.o .obj/qstringbuilder.o .obj/qstringlist.o .obj/qtextboundaryfinder.o .obj/qtimeline.o .obj/qtimezone.o .obj/qtimezoneprivate.o .obj/qunicodetools.o .obj/qvector.o .obj/qvsnprintf.o .obj/qelapsedtimer_unix.o .obj/qlocale_unix.o .obj/qtimezoneprivate_tz.o .obj/qlocale_icu.o .obj/qcollator_icu.o .obj/qtimezoneprivate_icu.o .obj/harfbuzz-buffer.o .obj/harfbuzz-gdef.o .obj/harfbuzz-gsub.o .obj/harfbuzz-gpos.o .obj/harfbuzz-impl.o .obj/harfbuzz-open.o .obj/harfbuzz-stream.o .obj/harfbuzz-shaper-all.o .obj/qharfbuzz.o .obj/qabstractfileengine.o .obj/qbuffer.o .obj/qdatastream.o .obj/qdataurl.o .obj/qtldurl.o .obj/qdebug.o .obj/qdir.o .obj/qdiriterator.o .obj/qfile.o .obj/qfiledevice.o .obj/qfileinfo.o .obj/qipaddress.o .obj/qiodevice.o .obj/qlockfile.o .obj/qnoncontiguousbytedevice.o .obj/qprocess.o .obj/qtextstream.o .obj/qtemporarydir.o .obj/qtemporaryfile.o .obj/qresource.o .obj/qresource_iterator.o .obj/qsavefile.o .obj/qstandardpaths.o .obj/qurl.o .obj/qurlidna.o .obj/qurlquery.o .obj/qurlrecode.o .obj/qsettings.o .obj/qfsfileengine.o .obj/qfsfileengine_iterator.o .obj/qfilesystemwatcher.o .obj/qfilesystemwatcher_polling.o .obj/qfilesystementry.o .obj/qfilesystemengine.o .obj/qfileselector.o .obj/qloggingcategory.o .obj/qloggingregistry.o .obj/qfsfileengine_unix.o .obj/qfilesystemengine_unix.o .obj/qlockfile_unix.o .obj/qprocess_unix.o .obj/qfilesystemiterator_unix.o .obj/qstandardpaths_unix.o .obj/qfilesystemwatcher_inotify.o .obj/qabstractitemmodel.o .obj/qabstractproxymodel.o .obj/qitemselectionmodel.o .obj/qidentityproxymodel.o .obj/qsortfilterproxymodel.o .obj/qstringlistmodel.o .obj/qjson.o .obj/qjsondocument.o .obj/qjsonobject.o .obj/qjsonarray.o .obj/qjsonvalue.o .obj/qjsonwriter.o .obj/qjsonparser.o .obj/qpluginloader.o .obj/qfactoryloader.o .obj/quuid.o .obj/qlibrary.o .obj/qelfparser_p.o .obj/qmachparser.o .obj/qlibrary_unix.o .obj/qabstracteventdispatcher.o .obj/qabstractnativeeventfilter.o .obj/qbasictimer.o .obj/qeventloop.o .obj/qcoreapplication.o .obj/qcoreevent.o .obj/qmetaobject.o .obj/qmetatype.o .obj/qmetaobjectbuilder.o .obj/qmimedata.o .obj/qobject.o .obj/qobjectcleanuphandler.o .obj/qsignalmapper.o .obj/qsocketnotifier.o .obj/qtimer.o .obj/qtranslator.o .obj/qvariant.o .obj/qcoreglobaldata.o .obj/qsharedmemory.o .obj/qsystemsemaphore.o .obj/qpointer.o .obj/qmath.o .obj/qsystemerror.o .obj/qcore_unix.o .obj/qcrashhandler.o .obj/qeventdispatcher_unix.o .obj/qtimerinfo_unix.o .obj/qeventdispatcher_glib.o .obj/qsharedmemory_unix.o .obj/qsystemsemaphore_unix.o .obj/qisciicodec.o .obj/qlatincodec.o .obj/qtextcodec.o .obj/qtsciicodec.o .obj/qutfcodec.o .obj/qicucodec.o .obj/qstatemachine.o .obj/qabstractstate.o .obj/qstate.o .obj/qfinalstate.o .obj/qhistorystate.o .obj/qabstracttransition.o .obj/qsignaltransition.o .obj/qeventtransition.o .obj/qmimedatabase.o .obj/qmimetype.o .obj/qmimemagicrulematcher.o .obj/qmimetypeparser.o .obj/qmimemagicrule.o .obj/qmimeglobpattern.o .obj/qmimeprovider.o .obj/qxmlstream.o .obj/qxmlutils.o .obj/qstring_compat.o .obj/qrc_mimetypes.o .obj/moc_qabstractanimation_p.o .obj/moc_qnamespace.o .obj/moc_qthread.o .obj/moc_qthreadpool.o .obj/moc_qfuturewatcher.o .obj/moc_qeasingcurve.o .obj/moc_qlocale.o .obj/moc_qtimeline.o .obj/moc_qfile.o .obj/moc_qfiledevice.o .obj/moc_qiodevice.o .obj/moc_qnoncontiguousbytedevice_p.o .obj/moc_qtextstream_p.o .obj/moc_qtemporaryfile.o .obj/moc_qsavefile.o .obj/moc_qsettings.o .obj/moc_qfilesystemwatcher_p.o .obj/moc_qfilesystemwatcher_polling_p.o .obj/moc_qfilesystemwatcher_inotify_p.o .obj/moc_qabstractitemmodel.o .obj/moc_qstringlistmodel.o .obj/moc_qpluginloader.o .obj/moc_qlibrary.o .obj/moc_qfactoryloader_p.o .obj/moc_qabstracteventdispatcher.o .obj/moc_qeventloop.o .obj/moc_qcoreapplication.o .obj/moc_qcoreevent.o .obj/moc_qmimedata.o .obj/moc_qsocketnotifier.o .obj/moc_qtimer.o .obj/moc_qtranslator.o .obj/moc_qobjectcleanuphandler.o .obj/moc_qsharedmemory.o .obj/moc_qeventdispatcher_unix_p.o .obj/moc_qeventdispatcher_glib_p.o .obj/moc_qabstractstate.o .obj/moc_qstate.o .obj/moc_qfinalstate.o .obj/moc_qhistorystate.o .obj/moc_qabstracttransition.o .obj/moc_qsignaltransition.o .obj/moc_qeventtransition.o -lpthread -lz -licui18n -licuuc -licudata -lpcre16 -lm -ldl -lgthread-2.0 -pthread -lglib-2.0 -lrt
/home/trippels/bin/ld: internal error in symval_for_branch, at powerpc.cc:6755
collect2: error: ld returned 1 exit status
Comment 1 Cary Coutant 2014-12-02 17:50:09 UTC
Alan, can you take a look at this?
Comment 2 Markus Trippelsdorf 2014-12-02 18:05:37 UTC
Reduced using gcc trunk:

trippels@gcc2-power8 corelib % cat qmimeglobpattern.ii
class G;
class A
{
public:
  A (G);
};
class B
{
public:
  int m_fn1 ();
};
class QString;
struct C
{
  B ref;
};
template <typename> class QList
{
  C d;
public:
  ~QList ();
  void m_fn2 ();
  void m_fn3 ();
};
class G : public QList<QString>
{
};
struct D
{
  void m_fn4 (const QString &&);
  G m_matchingMimeTypes;
};
class F
{
  G m_fn5 (const QString &) const;
};
template <typename T> QList<T>::~QList ()
{
  if (d.ref.m_fn1 ())
    m_fn3 ();
}
template <typename T>
void
QList<T>::m_fn2 ()
{
  QList ();
}
void
D::m_fn4 (const QString &&)
{
  m_matchingMimeTypes.m_fn2 ();
}
G
F::m_fn5 (const QString &) const
{
  G a;
  for (A b (a);;)
    ;
}

trippels@gcc2-power8 corelib % cat qmimeprovider.ii
class A
{
public:
  int m_fn1 ();
};
class QString
{
public:
  static QString m_fn2 (char *);
};
struct B
{
  A ref;
};
template <typename> class QList
{
  B d;
public:
  ~QList ();
  class const_iterator
  {
  };
  const_iterator m_fn3 ();
  void m_fn4 ();
};
class C
{
  QList<QString> c;
  QList<QString>::const_iterator i;
public:
  C (QList<QString>) : i (c.m_fn3 ()) {}
};
class D
{
public:
  enum StandardLocation
  {
    GenericDataLocation
  };
  static QList<QString> m_fn5 (StandardLocation, QString);
};
QList<QString> a = D::m_fn5 (D::GenericDataLocation, QString::m_fn2 (""));
template <typename T> QList<T>::~QList ()
{
  if (d.ref.m_fn1 ())
    m_fn4 ();
}
void
fn1 ()
{
  C b (a);
}

trippels@gcc2-power8 corelib % g++ -shared -w -O3 -fvisibility=hidden -std=c++0x qmimeglobpattern.ii qmimeprovider.ii
/home/trippels/bin/ld: internal error in symval_for_branch, at powerpc.cc:6755
Comment 3 Alan Modra 2014-12-03 04:32:28 UTC
I don't know enough C++ to say anything authoritive about the testcase but it seems to me that either the testcase is invalid or mainline g++ is broken, probably the latter.

The reason I say that is that qmimeglobpattern.o contains this group
COMDAT group section [    1] `.group' [_ZN5QListI7QStringED5Ev] contains 1 sections:
   [Index]    Name
   [   11]   .text._ZN5QListI7QStringED2Ev
defining the function _ZN5QListI7QStringED2Ev

and qmimeprovider.o this group
COMDAT group section [    1] `.group' [_ZN5QListI7QStringED5Ev] contains 2 sections:
   [Index]    Name
   [    8]   .text._ZN5QListI7QStringED2Ev
   [   12]   .gcc_except_table._ZN5QListI7QStringED2Ev
defining _ZN5QListI7QStringED1Ev and _ZN5QListI7QStringED2Ev

Since these are comdat groups, the first one is kept and the second dropped, resulting in _ZN5QListI7QStringED1Ev being undefined.  The sym is weak so that in itself doesn't cause a link failure, but does result in runtime failure even on x86_64.  I can simply change the assertion to a condition in powerpc.cc which will result in exactly the same runtime failure on powerpc..  Now it happens that _ZN5QListI7QStringED1Ev and _ZN5QListI7QStringED2Ev are aliases in the second group, but I don't think ld has any business trying to map symbols across to the kept section.
Comment 4 Markus Trippelsdorf 2014-12-03 07:57:53 UTC
Moved to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64163
Comment 5 Andrew Pinski 2014-12-03 08:14:15 UTC
Reopening since the linker should not crash on code which violates C++ ODR.
Comment 6 cvs-commit@gcc.gnu.org 2014-12-03 23:14:21 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  1611bc4afb0f08f0aff64ec355b8d68e9f4f0a73 (commit)
      from  858339f2b7aafe199c1cd07fc8d4a7c8130aa285 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1611bc4afb0f08f0aff64ec355b8d68e9f4f0a73

commit 1611bc4afb0f08f0aff64ec355b8d68e9f4f0a73
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Dec 3 16:17:23 2014 +1030

    powerpc gold, work around pr17670
    
    pr17670 is about an assert triggering on a branch to an undefined
    weak symbol, the symbol being undefined due to dropping its comdat
    group section.  (Well sort of.  The symbol is actually defined in
    an .opd section which isn't part of the group, but the code section
    the opd entry points at is dropped.)  So don't assert.
    Also, don't make long branch stubs to such symbols, and arrange to
    have target-reloc.h code warn when applying relocs that use the sym.
    
    	PR 17670
    	* symtab.cc (Symbol::set_undefined): Remove assertion.
    	* powerpc.cc (Target_powerpc::symval_for_branch): Don't assert
    	on symbols defined in discarded sections, instead return false.
    	Rearrange params, update all callers.
    	(Target_powerpc::Branch_info::make_stub): Don't make stubs for
    	branches to syms in discarded sections.
    	(Global_symbol_visitor_opd::operator()): Set discarded opd syms
    	undefined and flag as discarded.
    	(Target_powerpc::Relocate::relocate): Localize variable.

-----------------------------------------------------------------------

Summary of changes:
 gold/ChangeLog  |   13 +++++++++++++
 gold/powerpc.cc |   54 +++++++++++++++++++++++++++++++-----------------------
 gold/symtab.cc  |    1 -
 3 files changed, 44 insertions(+), 24 deletions(-)
Comment 7 cvs-commit@gcc.gnu.org 2014-12-04 02:10:29 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, binutils-2_25-branch has been updated
       via  feba93770920f91760d6390541221b75ba5c95f3 (commit)
      from  b6cc44453451b1ac6ca22d83875a6c3583ceec3d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=feba93770920f91760d6390541221b75ba5c95f3

commit feba93770920f91760d6390541221b75ba5c95f3
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Dec 3 16:17:23 2014 +1030

    powerpc gold, work around pr17670
    
    pr17670 is about an assert triggering on a branch to an undefined
    weak symbol, the symbol being undefined due to dropping its comdat
    group section.  (Well sort of.  The symbol is actually defined in
    an .opd section which isn't part of the group, but the code section
    the opd entry points at is dropped.)  So don't assert.
    Also, don't make long branch stubs to such symbols, and arrange to
    have target-reloc.h code warn when applying relocs that use the sym.
    
    	PR 17670
    	* symtab.cc (Symbol::set_undefined): Remove assertion.
    	* powerpc.cc (Target_powerpc::symval_for_branch): Don't assert
    	on symbols defined in discarded sections, instead return false.
    	Rearrange params, update all callers.
    	(Target_powerpc::Branch_info::make_stub): Don't make stubs for
    	branches to syms in discarded sections.
    	(Global_symbol_visitor_opd::operator()): Set discarded opd syms
    	undefined and flag as discarded.
    	(Target_powerpc::Relocate::relocate): Localize variable.

-----------------------------------------------------------------------

Summary of changes:
 gold/ChangeLog  |   13 +++++++++++++
 gold/powerpc.cc |   54 +++++++++++++++++++++++++++++++-----------------------
 gold/symtab.cc  |    1 -
 3 files changed, 44 insertions(+), 24 deletions(-)
Comment 8 Alan Modra 2014-12-04 02:17:20 UTC
fixed