bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/24819] New: ld -r fails to handle .init_array section in comdat


From: hjl.tools at gmail dot com
Subject: [Bug ld/24819] New: ld -r fails to handle .init_array section in comdat group
Date: Wed, 17 Jul 2019 18:07:20 +0000

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

            Bug ID: 24819
           Summary: ld -r fails to handle .init_array section in comdat
                    group
           Product: binutils
           Version: 2.33 (HEAD)
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: hjl.tools at gmail dot com
  Target Milestone: ---

[hjl@gnu-cfl-1 reloc-3]$ cat 1.s
        .text
        .section        .text.startup.foo1,"axG",@progbits,.group1,comdat
        .p2align 4,,15
        .type   foo1, @function
foo1:
.LFB0:
        .cfi_startproc
        movl    $30, init1(%rip)
        ret
        .cfi_endproc
.LFE0:
        .size   foo1, .-foo1
        .section        .init_array,"awG",@init_array,.group1,comdat
        .align 8
        .quad   foo1
[hjl@gnu-cfl-1 reloc-3]$ cat i.s
        .text
        .section        .text.startup.foo1,"axG",@progbits,.group1,comdat
        .p2align 4,,15
        .type   foo1, @function
foo1:
.LFB0:
        .cfi_startproc
        movl    $1, init1(%rip)
        ret
        .cfi_endproc
.LFE0:
        .size   foo1, .-foo1
        .section        .init_array,"awG",@init_array,.group1,comdat
        .align 8
        .quad   foo1
        .section        .text.startup.foo2,"axG",@progbits,.group2,comdat
        .p2align 4,,15
        .type   foo2, @function
foo2:
.LFB1:
        .cfi_startproc
        movl    $2, init2(%rip)
        ret
        .cfi_endproc
.LFE1:
        .size   foo2, .-foo2
        .section        .init_array,"awG",@init_array,.group2,comdat
        .align 8
        .quad   foo2
        .section        .text.startup.foo3,"ax",@progbits
        .p2align 4,,15
        .type   foo3, @function
foo3:
.LFB2:
        .cfi_startproc
        movl    $3, init3(%rip)
        ret
        .cfi_endproc
.LFE2:
        .size   foo3, .-foo3
        .section        .init_array
        .align 8
        .quad   foo3
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-1 reloc-3]$ cat m.c
#include <stdio.h>

int init1;
int init2;
int init3;

int
main (void)
{
  printf ("init1: %d\n", init1);
  printf ("init2: %d\n", init2);
  printf ("init3: %d\n", init3);
  if (init1 == 30 && init2 == 2 && init3 == 3)
    {
      printf ("PASS\n");
      return 0;
    }
  else
    {
      printf ("FAIL\n");
      return 1;
    }
}
[hjl@gnu-cfl-1 reloc-3]$ make
as  -o 1.o 1.s
as  -o i.o i.s
cc -O2    -c -o m.o m.c
cc -O2  -o x 1.o i.o m.o
./ld -r -o i-r.o i.o
cc -O2  -o y 1.o i-r.o m.o
./x
init1: 30
init2: 2
init3: 3
PASS
./y
init1: 30
init2: 2
init3: 0
FAIL
make: *** [Makefile:8: all] Error 1
[hjl@gnu-cfl-1 reloc-3]$ 

The problem is

[hjl@gnu-cfl-1 reloc-3]$ readelf -rW i-r.o
...
Relocation section '.rela.init_array' at offset 0x430 contains 2 entries:
    Offset             Info             Type               Symbol's Value 
Symbol's Name + Addend
0000000000000000  0000000f00000001 R_X86_64_64            0000000000000000 foo1
+ 0
0000000000000008  0000000700000001 R_X86_64_64            0000000000000000
.text.startup.foo3 + 0

where

        .section        .init_array
        .align 8
        .quad   foo3

is merged into

        .section        .init_array,"awG",@init_array,.group1,comdat
        .align 8
        .quad   foo1

When .group1 group in i-r.o is discarded, foo3 isn't called.

-- 
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]