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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-11-20
                 CC|                            |hjl at gcc dot gnu.org,
                   |                            |hubicka at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org,
                   |                            |matz at gcc dot gnu.org,
                   |                            |schwab at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Hi.

Thanks for the report. I isolated the issue and it's related to how
constructors are called and hang in GCOV is just demonstration of the problem.

Please consider this:

$ cat foo.c
__attribute__ ((constructor)) static void
ctor2 ()
{
  static int c2 = 0;
  __builtin_printf ("ctor2 called\n");
  if (c2++ != 0)
    __builtin_abort ();
}

int
main (void)
{
}

$ cat bar.c
__attribute__((constructor))
static void ctor1() {
  static int c1 = 0;
  __builtin_printf ("ctor1 called\n");
  if (c1++ != 0)
    __builtin_abort ();
}

int main(void)
{
}

Then running:

$ gcc -g -I. -fPIC -c foo.c -o foo.o 
$ gcc -g -I. -c bar.c -o bar.o 
$ gcc -Wl,-L. -Wl,--export-dynamic -pie foo.o -o foo.so
$ gcc -Wl,-L. -l:foo.so -fPIC bar.o foo.so -o bar

$ ./bar
ctor2 called
ctor2 called
Aborted (core dumped)

Problem is that ctor1 is not called and we instead call ctor2 twice.
Note that clang compiler has the same problem.

To be honest I'm not shared libraries expert, but I'll CC some guys who can
help.

Reply via email to