Bug 6931 - COMDAT group is broken
Summary: COMDAT group is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.20
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-01 19:17 UTC by H.J. Lu
Modified: 2008-10-04 07:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2008-10-02 14:42:55


Attachments
Testcases (353 bytes, patch)
2008-10-02 01:09 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2008-10-01 19:17:38 UTC
This patch:

http://sourceware.org/ml/binutils/2008-09/msg00214.html

may have caused:

[hjl@gnu-31 tmp]$ cat foo.c
extern int foo;
int *
foo1 ()
{
  return &foo;
}
[hjl@gnu-31 tmp]$ cat bar.c
extern int bar;
int *
bar1 ()
{
  return &bar;
}
[hjl@gnu-31 tmp]$ gcc -fPIC -c bar.c foo.c
[hjl@gnu-31 tmp]$ ld -r -o libbar.o bar.o
[hjl@gnu-31 tmp]$ ld -shared libbar.o foo.o
foo.o: In function `__i686.get_pc_thunk.cx':
foo.c:(.text.__i686.get_pc_thunk.cx[__i686.get_pc_thunk.cx]+0x0): multiple
definition of `__i686.get_pc_thunk.cx'
libbar.o:(.text.__i686.get_pc_thunk.cx[.group]+0x0): first defined here
[hjl@gnu-31 tmp]$
Comment 1 H.J. Lu 2008-10-01 19:18:22 UTC
It happens on Linux/ia32 with gcc 4.3.
Comment 2 H.J. Lu 2008-10-01 23:15:36 UTC
The bug is in bfd_elf_set_group_contents:

  symindx = 0; 
  if (elf_group_id (sec) != NULL)
    symindx = elf_group_id (sec)->udata.i;

  if (symindx == 0)
    {
      /* If called from the assembler, swap_out_syms will have set up
         elf_section_syms;  If called for "ld -r", use target_index.  */
      if (elf_section_syms (abfd) != NULL)
        symindx = elf_section_syms (abfd)[sec->index]->udata.i;
      else
        symindx = sec->target_index;
    }
  elf_section_data (sec)->this_hdr.sh_info = symindx;

"ld -r" is incorrect. We need to find the symbol index for
group signature which isn't the same as the section name.
Comment 3 H.J. Lu 2008-10-02 01:09:37 UTC
Created attachment 2974 [details]
Testcases

Those tests failed:

FAIL: ld-elf/group4
FAIL: ld-elf/group5
FAIL: ld-elf/group6
Comment 4 Alan Modra 2008-10-02 14:42:55 UTC
Testing a fix.  I know now why I hacked the group signature into the SEC_GROUP
name...
Comment 6 H.J. Lu 2008-10-03 15:16:06 UTC
It still isn't right:

bash-3.2$ cat
/export/gnu/src/binutils/binutils/binutils/testsuite/binutils-all/group.s
	.section .text.foo,"axG",%progbits,foo_group,comdat
	.global foo
foo:
	.word 0
	.section .data.foo,"awG",%progbits,foo_group,comdat
	.global bar
bar:
	.word 0
bash-3.2$ cat
/export/gnu/src/binutils/binutils/binutils/testsuite/binutils-all/group-2.s
	.section .text.foo,"axG",%progbits,.text.foo,comdat
	.global foo2
foo2:
	.word 0
	.section .data.bar,"awG",%progbits,.text.foo,comdat
	.global bar2
bar2:
	.word 0
bash-3.2$ gcc -c
/export/gnu/src/binutils/binutils/binutils/testsuite/binutils-all/group.s
/export/gnu/src/binutils/binutils/binutils/testsuite/binutils-all/group-2.s
bash-3.2$ ./ld-new -r group.o group-2.o
bash-3.2$ readelf -g group-2.o

COMDAT group section [    1] `.group' [.text.foo] contains 2 sections:
   [Index]    Name
   [    5]   .text.foo
   [    6]   .data.bar
bash-3.2$ readelf -g a.out 

COMDAT group section [    1] `foo_group' [foo_group] contains 2 sections:
   [Index]    Name
   [    4]   .text.foo
   [    7]   .data.foo

COMDAT group section [    2] `.group' [.text.foo.1] contains 2 sections:
   [Index]    Name
   [    5]   .text.foo.1
   [    8]   .data.bar
bash-3.2$ 

"ld -r" generates wrong group signature.