Bug 1730906 - ld -r fails to handle .init_array section in comdat group
Summary: ld -r fails to handle .init_array section in comdat group
Keywords:
Status: ON_QA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: binutils
Version: 8.2
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Nick Clifton
QA Contact: Miloš Prchlík
URL:
Whiteboard:
Depends On:
Blocks: 1746913 1755139
TreeView+ depends on / blocked
 
Reported: 2019-07-17 20:25 UTC by H.J. Lu
Modified: 2020-02-02 14:55 UTC (History)
4 users (show)

Fixed In Version: binutils-2.30-59.el8
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:


Attachments (Terms of Use)
Proposed patch (954 bytes, patch)
2019-07-22 13:21 UTC, Nick Clifton
no flags Details | Diff


Links
System ID Priority Status Summary Last Updated
Sourceware 24819 None None None 2019-07-22 12:23:41 UTC

Description H.J. Lu 2019-07-17 20:25:41 UTC
[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.

A patch is posted at

https://sourceware.org/ml/binutils/2019-07/msg00169.html

Comment 1 Nick Clifton 2019-07-22 13:21:31 UTC
Created attachment 1592601 [details]
Proposed patch

Hi H.J.

  Thanks for raising this bug, and providing a patch.

  I have updated Fedora rawhide (binutils-2.32-18), and this attachment
  is the patch for RHEL-8.2 once that opens.

Cheers
  Nick

Comment 7 Nick Clifton 2019-10-28 14:06:55 UTC
Fixed in binutils-2.30-59.el8


Note You need to log in before you can comment on or make changes to this bug.