PATCH: Include relocation section in section group

H. J. Lu hjl@lucon.org
Fri Jun 4 16:22:00 GMT 2004


We currently don't include relocation section in the section group
which the section it applies for is in. Also ld -r doesn't work on
input which includes relocation section in section group. This patch
changes them.

BTW, someone should double check if those targets which use the
second relocation section are OK.


H.J.
----
bfd/

2004-06-04  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (_bfd_elf_init_reloc_shdr): Set SHF_GROUP if needed.
	(bfd_elf_set_group_contents): Also include relocation sections.
	Remove zero-fill for ld -r.

gas/

2004-06-04  H.J. Lu  <hongjiu.lu@intel.com>

	* config/obj-elf.c (build_group_lists): Also count relocation
	sections.

--- binutils/bfd/elf.c.group	2004-06-04 06:21:39.563279600 -0700
+++ binutils/bfd/elf.c	2004-06-04 09:08:40.423440168 -0700
@@ -2385,7 +2385,10 @@ _bfd_elf_init_reloc_shdr (bfd *abfd,
 			 ? bed->s->sizeof_rela
 			 : bed->s->sizeof_rel);
   rel_hdr->sh_addralign = 1 << bed->s->log_file_align;
-  rel_hdr->sh_flags = 0;
+  if ((elf_section_flags (asect) & SHF_GROUP) != 0)
+    rel_hdr->sh_flags = SHF_GROUP;
+  else
+    rel_hdr->sh_flags = 0;
   rel_hdr->sh_addr = 0;
   rel_hdr->sh_size = 0;
   rel_hdr->sh_offset = 0;
@@ -2661,6 +2664,21 @@ bfd_elf_set_group_contents (bfd *abfd, a
       if (s != NULL)
 	idx = elf_section_data (s)->this_idx;
       H_PUT_32 (abfd, idx, loc);
+      if (s != NULL)
+	{
+	  if ((s->flags & SEC_RELOC) != 0)
+	    {
+	      loc -= 4;
+	      idx = elf_section_data (s)->rel_idx;
+	      H_PUT_32 (abfd, idx, loc);
+	    }
+	  if (elf_section_data (s)->rel_hdr2)
+	    {
+	      loc -= 4;
+	      idx = elf_section_data (s)->rel_idx2;
+	      H_PUT_32 (abfd, idx, loc);
+	    }
+	}
       elt = elf_next_in_group (elt);
       if (elt == first)
 	break;
@@ -2677,18 +2695,26 @@ bfd_elf_set_group_contents (bfd *abfd, a
 	  loc -= 4;
 	  H_PUT_32 (abfd,
 		    elf_section_data (elt->output_section)->this_idx, loc);
+	  if ((elt->output_section->flags & SEC_RELOC) != 0)
+	    {
+	      loc -= 4;
+	      H_PUT_32 (abfd,
+			elf_section_data (elt->output_section)->rel_idx,
+			loc);
+	    }
+	  if (elf_section_data (elt->output_section)->rel_hdr2)
+	    {
+	      loc -= 4;
+	      H_PUT_32 (abfd,
+			elf_section_data (elt->output_section)->rel_idx2,
+			loc);
+	    }
 	  elt = elf_next_in_group (elt);
 	  /* During a relocatable link, the lists are circular.  */
 	}
       while (elt != elf_next_in_group (l->u.indirect.section));
 
-  /* With ld -r, merging SHT_GROUP sections results in wasted space
-     due to allowing for the flag word on each input.  We may well
-     duplicate entries too.  */
-  while ((loc -= 4) > sec->contents)
-    H_PUT_32 (abfd, 0, loc);
-
-  if (loc != sec->contents)
+  if ((loc -= 4) != sec->contents)
     abort ();
 
   H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
--- binutils/gas/config/obj-elf.c.group	2004-05-03 09:00:46.000000000 -0700
+++ binutils/gas/config/obj-elf.c	2004-06-04 07:45:06.345596641 -0700
@@ -1842,7 +1842,7 @@ build_group_lists (bfd *abfd ATTRIBUTE_U
 	  elf_next_in_group (sec) = list->head[i];
 	  list->head[i] = sec;
 	  list->elt_count[i] += 1;
-	  return;
+	  goto rel;
 	}
     }
 
@@ -1859,6 +1859,12 @@ build_group_lists (bfd *abfd ATTRIBUTE_U
   list->head[i] = sec;
   list->elt_count[i] = 1;
   list->num_group += 1;
+
+rel:
+  if ((sec->flags & SEC_RELOC) != 0)
+    list->elt_count[i] += 1;
+  if (elf_section_data (sec)->rel_hdr2)
+    list->elt_count[i] += 1;
 }
 
 void



More information about the Binutils mailing list