public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sources.redhat.com
Cc: amodra@bigpond.net.au
Subject: PATCH: PR ld/6931: COMDAT group is broken
Date: Thu, 02 Oct 2008 21:43:00 -0000	[thread overview]
Message-ID: <20081002214244.GA28256@lucon.org> (raw)

bfd_elf_set_group_contents needs to handle group signature properly for
ld -r. The sh_info field of group section has the symbol table index 
of group signature. We need to get the symbol table index of group
signature in output file. We start with the symbol table index for
group signature in input file. If it is a global symbol, we can get
its index from ELF symbol hash table. If it is a local symbol, we
have to first get the symbol table entry for group signature in
input file and then compute the symbol table index in output file.

OK to install?


H.J.
--
bfd/

2008-10-02  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/6931
	* elf.c (bfd_elf_set_group_contents): Properly get the symbol
	table index for group signature for ld -r.

ld/testsuite/

2008-10-02  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/6931
	* ld-elf/group4.d: New.
	* ld-elf/group5.d: Likewise.
	* ld-elf/group6.d: Likewise.

--- binutils/bfd/elf.c.grp	2008-10-02 13:52:45.000000000 -0700
+++ binutils/bfd/elf.c	2008-10-02 14:00:14.000000000 -0700
@@ -2715,11 +2715,73 @@ bfd_elf_set_group_contents (bfd *abfd, a
   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.  */
+	 elf_section_syms.  */
       if (elf_section_syms (abfd) != NULL)
 	symindx = elf_section_syms (abfd)[sec->index]->udata.i;
       else
-	symindx = sec->target_index;
+	{
+	  struct bfd_link_order *lo;
+	  asection *input;
+	  Elf_Internal_Shdr *symtab_hdr;
+
+	  /* Handle "ld -r".  */
+	  input = NULL;
+	  for (lo = sec->map_head.link_order; lo != NULL; lo = lo->next)
+	    if (lo->type == bfd_indirect_link_order)
+	      {
+		/* There should be only one input section.  */
+		BFD_ASSERT (input == NULL);
+
+		input = lo->u.indirect.section;
+		/* Get the symbol table index for group signature in
+		   input file.  */
+		symindx = elf_section_data(input)->this_hdr.sh_info;
+	      }
+
+	  BFD_ASSERT (input != NULL);
+
+	  symtab_hdr = &elf_symtab_hdr (input->owner);
+	  if (symindx < symtab_hdr->sh_info)
+	    {
+	      unsigned char esym[sizeof (Elf64_External_Sym)];
+	      Elf_External_Sym_Shndx eshndx;
+	      Elf_Internal_Sym isym;
+	      Elf_Internal_Shdr *elf_sect;
+	      int target_index;
+
+	      /* Get the symbol table entry for group signature in
+		 input file.  */
+	      if (bfd_elf_get_elf_syms (input->owner, symtab_hdr, 1, 
+					symindx, &isym, esym, &eshndx)
+		  == NULL)
+		abort ();
+
+	      /* Get the group signature section in input file.  */
+	      elf_sect = elf_elfsections (input->owner)[isym.st_shndx];
+
+	      /* Compute the symbol table index for group signature
+		 in output file.  */
+	      target_index
+		= elf_sect->bfd_section->output_section->target_index;
+	      if (ELF_ST_TYPE (isym.st_info) == STT_SECTION)
+		symindx = target_index;
+	      else
+		symindx += target_index;
+	    }
+	  else
+	    {
+	      struct elf_link_hash_entry **sym_hashes;
+	      struct elf_link_hash_entry *h;
+
+	      sym_hashes = elf_sym_hashes (input->owner);
+	      h = sym_hashes[symindx - symtab_hdr->sh_info];
+	      while (h->root.type == bfd_link_hash_indirect
+		     || h->root.type == bfd_link_hash_warning)
+		h = (struct elf_link_hash_entry *) h->root.u.i.link;
+	      symindx = h->indx;
+	    }
+	}
+      BFD_ASSERT (symindx != 0);
     }
   elf_section_data (sec)->this_hdr.sh_info = symindx;
 
--- binutils/ld/testsuite/ld-elf/group4.d.grp	2008-10-02 13:52:46.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/group4.d	2008-10-02 13:52:46.000000000 -0700
@@ -0,0 +1,16 @@
+#source: ../../../binutils/testsuite/binutils-all/group-2.s
+#ld: -r
+#readelf: -Sg --wide
+
+#...
+  \[[ 0-9]+\] .group[ \t]+GROUP[ \t]+.*
+#...
+  \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AXG[ \t]+.*
+#...
+  \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WAG[ \t]+.*
+#...
+COMDAT group section \[[ 0-9]+\] `.group' \[.text.foo\] contains 2 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.*
+   \[[ 0-9]+\]   .data.*
+#pass
--- binutils/ld/testsuite/ld-elf/group5.d.grp	2008-10-02 13:52:46.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/group5.d	2008-10-02 13:52:46.000000000 -0700
@@ -0,0 +1,16 @@
+#source: ../../../binutils/testsuite/binutils-all/group-3.s
+#ld: -r
+#readelf: -Sg --wide
+
+#...
+  \[[ 0-9]+\] .group[ \t]+GROUP[ \t]+.*
+#...
+  \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AXG[ \t]+.*
+#...
+  \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WAG[ \t]+.*
+#...
+COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains 2 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.*
+   \[[ 0-9]+\]   .data.*
+#pass
--- binutils/ld/testsuite/ld-elf/group6.d.grp	2008-10-02 13:52:46.000000000 -0700
+++ binutils/ld/testsuite/ld-elf/group6.d	2008-10-02 13:52:46.000000000 -0700
@@ -0,0 +1,16 @@
+#source: ../../../binutils/testsuite/binutils-all/group-4.s
+#ld: -r
+#readelf: -Sg --wide
+
+#...
+  \[[ 0-9]+\] .group[ \t]+GROUP[ \t]+.*
+#...
+  \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AXG[ \t]+.*
+#...
+  \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WAG[ \t]+.*
+#...
+COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains 2 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.*
+   \[[ 0-9]+\]   .data.*
+#pass

             reply	other threads:[~2008-10-02 21:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-02 21:43 H.J. Lu [this message]
2008-10-03  0:30 ` H.J. Lu
2008-10-03  9:47   ` Alan Modra
2008-10-03 13:03     ` Alan Modra
2008-10-03 15:11     ` H.J. Lu
2008-10-03 19:41     ` H.J. Lu
2008-10-04  6:14       ` Alan Modra
2008-10-04 14:56         ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081002214244.GA28256@lucon.org \
    --to=hongjiu.lu@intel.com \
    --cc=amodra@bigpond.net.au \
    --cc=binutils@sources.redhat.com \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).