public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au>
To: Ian Lance Taylor <iant@google.com>,
	binutils@sourceware.org, 	Andrew Stubbs <ams@codesourcery.com>
Subject: Re: [patch] stop objcopy breaking group sections
Date: Sun, 28 Sep 2008 13:29:00 -0000	[thread overview]
Message-ID: <20080928132839.GI3740@bubble.grove.modra.org> (raw)
In-Reply-To: <20080927014418.GH3740@bubble.grove.modra.org>

On Sat, Sep 27, 2008 at 11:14:19AM +0930, Alan Modra wrote:
> Preferably not by scanning the symbols, but by setting up elf_group_id
> in bfd_section_from_shdr when reading the input file.

Actually, not there because the bfd symbols aren't available at that
point.  Instead, objcopy needs to set elf_group_id after it has read
the bfd symbols.

The bfd part of this patch also keeps the original SHT_GROUP section
name.

bfd/
	* elf.c (_bfd_elf_init_private_section_data): Tweak union copy.
	(bfd_section_from_shdr): Don't change SHT_GROUP section name.
	* elflink.c (section_signature): New function.
	(_bfd_elf_section_already_linked): Use it.
binutils/
	* objcopy.c (setup_section): Set elf_group_id.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.462
diff -u -p -r1.462 elf.c
--- bfd/elf.c	8 Aug 2008 08:00:14 -0000	1.462
+++ bfd/elf.c	28 Sep 2008 12:25:27 -0000
@@ -1863,14 +1863,8 @@ bfd_section_from_shdr (bfd *abfd, unsign
       return TRUE;
 
     case SHT_GROUP:
-      /* We need a BFD section for objcopy and relocatable linking,
-	 and it's handy to have the signature available as the section
-	 name.  */
       if (! IS_VALID_GROUP_SECTION_HEADER (hdr))
 	return FALSE;
-      name = group_signature (abfd, hdr);
-      if (name == NULL)
-	return FALSE;
       if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
 	return FALSE;
       if (hdr->contents != NULL)
@@ -6019,7 +6013,7 @@ _bfd_elf_init_private_section_data (bfd 
 	  if (elf_section_flags (isec) & SHF_GROUP)
 	    elf_section_flags (osec) |= SHF_GROUP;
 	  elf_next_in_group (osec) = elf_next_in_group (isec);
-	  elf_group_name (osec) = elf_group_name (isec);
+	  elf_section_data (osec)->group = elf_section_data (isec)->group;
 	}
     }
 
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.310
diff -u -p -r1.310 elflink.c
--- bfd/elflink.c	16 Sep 2008 14:09:34 -0000	1.310
+++ bfd/elflink.c	28 Sep 2008 12:25:33 -0000
@@ -11997,8 +11997,21 @@ bfd_elf_discard_info (bfd *output_bfd, s
   return ret;
 }
 
+/* For a SHT_GROUP section, return the group signature.  For other
+   sections, return the normal section name.  */
+
+static const char *
+section_signature (asection *sec)
+{
+  if ((sec->flags & SEC_GROUP) != 0
+      && elf_next_in_group (sec) != NULL
+      && elf_group_name (elf_next_in_group (sec)) != NULL)
+    return elf_group_name (elf_next_in_group (sec));
+  return sec->name;
+}
+
 void
-_bfd_elf_section_already_linked (bfd *abfd, struct bfd_section *sec,
+_bfd_elf_section_already_linked (bfd *abfd, asection *sec,
 				 struct bfd_link_info *info)
 {
   flagword flags;
@@ -12038,7 +12051,7 @@ _bfd_elf_section_already_linked (bfd *ab
      causes trouble for MIPS ELF, which relies on link once semantics
      to handle the .reginfo section correctly.  */
 
-  name = bfd_get_section_name (abfd, sec);
+  name = section_signature (sec);
 
   if (CONST_STRNEQ (name, ".gnu.linkonce.")
       && (p = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
@@ -12053,7 +12066,7 @@ _bfd_elf_section_already_linked (bfd *ab
       /* We may have 2 different types of sections on the list: group
 	 sections and linkonce sections.  Match like sections.  */
       if ((flags & SEC_GROUP) == (l->sec->flags & SEC_GROUP)
-	  && strcmp (name, l->sec->name) == 0
+	  && strcmp (name, section_signature (l->sec)) == 0
 	  && bfd_coff_get_comdat_section (l->sec->owner, l->sec) == NULL)
 	{
 	  /* The section has already been linked.  See if we should
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.123
diff -u -p -r1.123 objcopy.c
--- binutils/objcopy.c	6 Aug 2008 00:42:17 -0000	1.123
+++ binutils/objcopy.c	28 Sep 2008 12:35:20 -0000
@@ -2344,6 +2344,18 @@ setup_section (bfd *ibfd, sec_ptr isecti
   if (extract_symbol)
     return;
 
+  if ((isection->flags & SEC_GROUP) != 0)
+    {
+      asymbol *gsym = group_signature (isection);
+
+      if (gsym != NULL)
+	{
+	  gsym->flags |= BSF_KEEP;
+	  if (ibfd->xvec->flavour == bfd_target_elf_flavour)
+	    elf_group_id (isection) = gsym;
+	}
+    }
+
   /* Allow the BFD backend to copy any private data it understands
      from the input section to the output section.  */
   if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
@@ -2351,13 +2363,6 @@ setup_section (bfd *ibfd, sec_ptr isecti
       err = _("failed to copy private data");
       goto loser;
     }
-  else if ((isection->flags & SEC_GROUP) != 0)
-    {
-      asymbol *gsym = group_signature (isection);
-
-      if (gsym != NULL)
-	gsym->flags |= BSF_KEEP;
-    }
 
   /* All went well.  */
   return;


-- 
Alan Modra
Australia Development Lab, IBM

  reply	other threads:[~2008-09-28 13:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-24 15:12 Andrew Stubbs
2008-09-25  4:48 ` Alan Modra
2008-09-25  9:21   ` Andrew Stubbs
2008-09-25 10:39     ` Alan Modra
2008-09-25 12:10       ` Andrew Stubbs
2008-09-25 12:22       ` Daniel Jacobowitz
2008-09-25 23:06         ` Alan Modra
2008-09-26  0:53           ` Daniel Jacobowitz
2008-09-26 14:53             ` Ian Lance Taylor
2008-09-27  1:45               ` Alan Modra
2008-09-28 13:29                 ` Alan Modra [this message]
2008-10-01 21:52                   ` H.J. Lu
2008-10-01 23:12                     ` H.J. Lu
2008-10-02  1:08                       ` 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=20080928132839.GI3740@bubble.grove.modra.org \
    --to=amodra@bigpond.net.au \
    --cc=ams@codesourcery.com \
    --cc=binutils@sourceware.org \
    --cc=iant@google.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).