Bug 13066 - LTO linker fails GCC LTO tests
Summary: LTO linker fails GCC LTO tests
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on: 12762
Blocks:
  Show dependency treegraph
 
Reported: 2011-08-08 16:44 UTC by H.J. Lu
Modified: 2011-08-10 06:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A workaround (817 bytes, patch)
2011-08-08 19:39 UTC, H.J. Lu
Details | Diff
A patch (843 bytes, patch)
2011-08-09 00:38 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2011-08-08 16:44:20 UTC
With 20110808 bfd linker and GCC trunk, I got

[hjl@gnu-6 gcc]$ cat /export/gnu/import/git/gcc/gcc/testsuite/g++.dg/torture/pr40389.C
/* { dg-do run } */

template <typename V> struct S
{
  V *f, *l;
  __attribute__ ((noinline)) S (void) { f = 0, l = 0; }
  void foo (V *x)
  {
    if (x->p != 0)
      x->p->n = x->n;
    else
      f = x->n;
    if (x->n != 0)
      x->n->p = x->p;
    else
      l = x->p;
  }
  __attribute__ ((noinline)) void bar (V *x)
  {
    x->n = 0;
    x->p = l;
    if (l != 0)
      l->n = x;
    else
      f = x;
    l = x;
  }
};

struct H;

struct A
{
  S <H> k;
};

struct H
{
  A *a;
  H *p, *n;
  __attribute__ ((noinline)) H (void) { p = 0, n = 0, a = 0; }
  __attribute__ ((noinline)) H (A *b) : a (b)
  {
    p = 0;
    n = 0;
    if (a != 0)
      a->k.bar (this);
  }
  __attribute__ ((noinline)) H (const H &h) : a (h.a)
  {
    p = 0;
    n = 0;
    if (a != 0)
      a->k.bar (this);
  }
  ~H (void) { if (a != 0) a->k.foo (this); }
  H &operator= (const H &o)
  {
    if (a != 0 || &o == this)
      __builtin_abort ();
    a = o.a;
    if (a != 0)
      a->k.bar (this);
    return *this;
  }
};

__attribute__ ((noinline))
H baz (void)
{
  return H (new A);
}

H g;

int
main (void)
{
  g = baz ();
  if (g.a->k.f != &g)
    __builtin_abort ();
  return 0;
}

[hjl@gnu-6 gcc]$ /usr/gcc-4.7.0-x32/bin/g++  -O2 -flto /export/gnu/import/git/gcc/gcc/testsuite/g++.dg/torture/pr40389.C
collect2: error: ld terminated with signal 6 [Aborted], core dumped
ld: /export/gnu/import/git/gcc-x32/lto-plugin/lto-plugin.c:360: dump_symtab: Assertion `resolution != LDPR_UNKNOWN' failed.
[hjl@gnu-6 gcc]$
Comment 1 H.J. Lu 2011-08-08 17:05:39 UTC
It may be caused by

http://lists.gnu.org/archive/html/bug-binutils/2011-08/msg00035.html
Comment 2 H.J. Lu 2011-08-08 19:15:00 UTC
(In reply to comment #1)
> It may be caused by
> 
> http://lists.gnu.org/archive/html/bug-binutils/2011-08/msg00035.html

This change is wrong since 2 symbols may have the same comdat key.
Comment 3 H.J. Lu 2011-08-08 19:39:34 UTC
Created attachment 5883 [details]
A workaround
Comment 4 H.J. Lu 2011-08-09 00:38:22 UTC
Created attachment 5886 [details]
A patch

This patch is better.
Comment 5 cvs-commit@gcc.gnu.org 2011-08-09 09:27:38 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2011-08-09 09:27:34

Modified files:
	ld             : ChangeLog plugin.c 

Log message:
	PR ld/13066
	PR ld/12762
	* plugin.c (add_symbols): Revert 2011-08-05.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2362&r2=1.2363
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/plugin.c.diff?cvsroot=src&r1=1.37&r2=1.38
Comment 6 Alan Modra 2011-08-09 13:29:55 UTC
Reverted offending patch
Comment 7 Alan Modra 2011-08-10 05:59:11 UTC
HJ, does this testcase pass if linked with gold?
Comment 8 H.J. Lu 2011-08-10 06:11:41 UTC
(In reply to comment #7)
> HJ, does this testcase pass if linked with gold?

Yes.