RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
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: CLOSED ERRATA
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: 2021-09-17 14:30 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: 2020-04-28 16:45:36 UTC
Type: Bug
Target Upstream Version:
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-26611 0 None None None 2021-08-27 22:33:41 UTC
Red Hat Product Errata RHSA-2020:1797 0 None None None 2020-04-28 16:45:59 UTC
Sourceware 24819 0 P2 NEW ld -r fails to handle .init_array section in comdat group 2020-09-20 13:21:29 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

Comment 9 Miloš Prchlík 2020-03-16 13:29:13 UTC
Verified with binutils-2.30-73.el8.

[root@opicee-1 ~]# ./x
init1: 30
init2: 2
init3: 3
PASS
[root@opicee-1 ~]# ./y
init1: 30
init2: 2
init3: 3
PASS
[root@opicee-1 ~]#

Comment 11 errata-xmlrpc 2020-04-28 16:45:36 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2020:1797


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