bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug admin/27303] New: gold/testsuite/initpri3. test fails on gold and l


From: slyfox at inbox dot ru
Subject: [Bug admin/27303] New: gold/testsuite/initpri3. test fails on gold and lld, passes on bfd. Which one is correct?
Date: Mon, 01 Feb 2021 07:27:36 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27303

            Bug ID: 27303
           Summary: gold/testsuite/initpri3. test fails on gold and lld,
                    passes on bfd. Which one is correct?
           Product: binutils
           Version: 2.36
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: admin
          Assignee: unassigned at sourceware dot org
          Reporter: slyfox at inbox dot ru
  Target Milestone: ---

The test fails as is on gold:

$ gcc-11.0.0 initpri3.c -o bug -fuse-ld=lld && ./bug
bug: initpri3.c:78: main: Assertion `i == 3' failed.
Aborted (core dumped)
$ gcc-11.0.0 initpri3.c -o bug -fuse-ld=gold && ./bug
bug: initpri3.c:40: ctor2: Assertion `i == 2' failed.
Aborted (core dumped)
$ gcc-11.0.0 initpri3.c -o bug -fuse-ld=bfd && ./bug

It looks like the difference here is how the array of `.ctors` is handled:

```
/* The .ctors section is run in reverse order, the .dtors section in
   run in forward order.  We give these arrays the "aligned" attribute
   because the x86_64 ABI would otherwise give them a 16-byte
   alignment, which may leave a hole in the section.  */

void (*ctors[]) (void)
  __attribute__ ((aligned (4), section (".ctors"))) = {
  ctor2,
  ctor1
};
```

The array is stored as one section:

```
        .section        .ctors,"aw"
        .align 8
        .type   ctors, @object
        .size   ctors, 16
ctors:
        .quad   ctor2
        .quad   ctor1
```

In both cases linker reordered the elements within the array:

$ gcc-11.0.0 initpri3.c -fuse-ld=gold -o ig -ggdb3
$ gcc-11.0.0 initpri3.c -fuse-ld=bfd -o ib -ggdb3

$ gdb --quiet ./ib
Reading symbols from ./ib...
(gdb) print ctors
$1 = {0x1139 <ctor1>, 0x117d <ctor2>}

$ gdb --quiet ./ig
Reading symbols from ./ig...
(gdb) print ctors
$1 = {0x689 <ctor1>, 0x6cd <ctor2>}

But not within __init_array_start:

$ gdb --quiet ./ib
Reading symbols from ./ib...
(gdb) start
Temporary breakpoint 1 at 0x124d: file initpri3.c, line 78.
Starting program: /tmp/z/ib

Temporary breakpoint 1, main () at initpri3.c:78
78        assert (i == 3);
(gdb) x/4a __init_array_start
0x555555557dc8: 0x555555555130  0x555555555139 <ctor1>
0x555555557dd8 <ctors+8>:       0x55555555517d <ctor2>  0x5555555550f0

gdb --quiet ./ig
Reading symbols from ./ig...
(gdb) start
Temporary breakpoint 1 at 0x79d: file initpri3.c, line 78.
Starting program: /tmp/z/ig
ig: initpri3.c:40: ctor2: Assertion `i == 2' failed.

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:49
49        return ret;
(gdb) x/4a __init_array_start
0x555555555db8: 0x555555554680  0x5555555546cd <ctor2>
0x555555555dc8 <ctors+8>:       0x555555554689 <ctor1>  0x3

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]