This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: more section size fallout


And this one fixes major breakage of mmix.

bfd/
	* elf64-mmix.c (mmix_set_relaxable_size): Save original size in
	rawsize.
	(mmix_elf_perform_relocation): Adjust for above change.
	(mmix_elf_relocate_section): Likewise.
	(mmix_elf_relax_section): Likewise.  Use output_section->rawsize.
	(mmix_elf_get_section_contents): Delete.
	(bfd_elf64_get_section_contents): Delete.
	(mmix_elf_relocate_section): Zero stub area.
	* linker.c (default_indirect_link_order): Alloc max of section size
	and rawsize.
	* simple.c (bfd_simple_get_relocated_section_contents): Likewise.
	* section.c (bfd_malloc_and_get_section): Likewise.
	(struct bfd_section): Update rawsize comment.
	* bfd-in2.h: Regenerate.
ld/
	* ldlang.c (lang_reset_memory_regions): Save last relax pass section
	size in rawsize.

Index: bfd/elf64-mmix.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-mmix.c,v
retrieving revision 1.36
diff -u -p -r1.36 elf64-mmix.c
--- bfd/elf64-mmix.c	24 Jun 2004 04:46:22 -0000	1.36
+++ bfd/elf64-mmix.c	29 Jun 2004 12:51:23 -0000
@@ -991,10 +991,7 @@ mmix_elf_perform_relocation (isec, howto
 	goto pcrel_mmix_reloc_fits;
       else
 	{
-	  bfd_size_type size
-	    = (isec->size
-	       - (mmix_elf_section_data (isec)->pjs.n_pushj_relocs
-		  * MAX_PUSHJ_STUB_SIZE));
+	  bfd_size_type size = isec->rawsize ? isec->rawsize : isec->size;
 
 	  /* We have the bytes at the PUSHJ insn and need to get the
 	     position for the stub.  There's supposed to be room allocated
@@ -1343,16 +1338,20 @@ mmix_elf_relocate_section (output_bfd, i
   struct elf_link_hash_entry **sym_hashes;
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
-  bfd_size_type size
-    = (input_section->size
-       - (mmix_elf_section_data (input_section)->pjs.n_pushj_relocs
-	  * MAX_PUSHJ_STUB_SIZE));
+  bfd_size_type size;
   size_t pjsno = 0;
 
+  size = input_section->rawsize ? input_section->rawsize : input_section->size;
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
   relend = relocs + input_section->reloc_count;
 
+  /* Zero the stub area before we start.  */
+  if (input_section->rawsize != 0
+      && input_section->size > input_section->rawsize)
+    memset (contents + input_section->rawsize, 0,
+	    input_section->size - input_section->rawsize);
+
   for (rel = relocs; rel < relend; rel ++)
     {
       reloc_howto_type *howto;
@@ -2310,6 +2309,7 @@ mmix_set_relaxable_size (abfd, sec, ptr)
   if (mmix_elf_section_data (sec)->pjs.n_pushj_relocs == 0)
     return;
 
+  sec->rawsize = sec->size;
   sec->size += (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
 		* MAX_PUSHJ_STUB_SIZE);
 
@@ -2589,9 +2589,7 @@ mmix_elf_relax_section (abfd, sec, link_
   size_t pjsno = 0;
   bfd *bpo_greg_owner;
   Elf_Internal_Sym *isymbuf = NULL;
-  bfd_size_type size = (sec->size
-			- (mmix_elf_section_data (sec)->pjs.n_pushj_relocs
-			   * MAX_PUSHJ_STUB_SIZE));
+  bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
 
   mmix_elf_section_data (sec)->pjs.stubs_size_sum = 0;
 
@@ -2669,7 +2667,7 @@ mmix_elf_relax_section (abfd, sec, link_
 				      0,
 				      bfd_arch_bits_per_address (abfd),
 				      /* Output-stub location.  */
-				      sec->output_section->size
+				      sec->output_section->rawsize
 				      + (mmix_elf_section_data (sec
 							       ->output_section)
 					 ->pjs.stubs_size_sum)
@@ -2910,52 +2908,6 @@ mmix_elf_relax_section (abfd, sec, link_
     free (internal_relocs);
   return FALSE;
 }
-
-/* Because we set size to include the max size of pushj stubs,
-   i.e. larger than the actual section input size (see
-   mmix_set_relaxablesize), we have to take care of that when reading
-   the section.  */
-
-static bfd_boolean
-mmix_elf_get_section_contents (abfd, section, location, offset, count)
-     bfd *abfd;
-     sec_ptr section;
-     void *location;
-     file_ptr offset;
-     bfd_size_type count;
-{
-  bfd_size_type size = (section->size
-			- (mmix_elf_section_data (section)->pjs.n_pushj_relocs
-			   * MAX_PUSHJ_STUB_SIZE));
-
-  if (offset + count > section->size)
-    {
-      abort();
-      bfd_set_error (bfd_error_invalid_operation);
-      return FALSE;
-    }
-
-  /* Check bounds against the faked size.  */
-  if (offset + count > size)
-    {
-      /* Clear the part in the faked area.  */
-      memset (location + size - offset, 0, count - (size - offset));
-
-      /* If there's no initial part within the "real" contents, we're
-         done.  */
-      if ((bfd_size_type) offset >= size)
-	return TRUE;
-
-      /* Else adjust the count and fall through to call the generic
-         function.  */
-      count = size - offset;
-    }
-
-  return
-    _bfd_generic_get_section_contents (abfd, section, location, offset,
-				       count);
-}
-
 
 #define ELF_ARCH		bfd_arch_mmix
 #define ELF_MACHINE_CODE 	EM_MMIX
@@ -3004,6 +2956,5 @@ mmix_elf_get_section_contents (abfd, sec
 #define bfd_elf64_new_section_hook	mmix_elf_new_section_hook
 #define bfd_elf64_bfd_final_link	mmix_elf_final_link
 #define bfd_elf64_bfd_relax_section	mmix_elf_relax_section
-#define bfd_elf64_get_section_contents	mmix_elf_get_section_contents
 
 #include "elf64-target.h"
Index: bfd/linker.c
===================================================================
RCS file: /cvs/src/src/bfd/linker.c,v
retrieving revision 1.36
diff -u -p -r1.36 linker.c
--- bfd/linker.c	24 Jun 2004 04:46:24 -0000	1.36
+++ bfd/linker.c	29 Jun 2004 12:51:35 -0000
@@ -2756,7 +2756,9 @@ default_indirect_link_order (bfd *output
     }
 
   /* Get and relocate the section contents.  */
-  sec_size = input_section->size;
+  sec_size = (input_section->rawsize > input_section->size
+	      ? input_section->rawsize
+	      : input_section->size);
   contents = bfd_malloc (sec_size);
   if (contents == NULL && sec_size != 0)
     goto error_return;
Index: bfd/section.c
===================================================================
RCS file: /cvs/src/src/bfd/section.c,v
retrieving revision 1.73
diff -u -p -r1.73 section.c
--- bfd/section.c	24 Jun 2004 04:46:26 -0000	1.73
+++ bfd/section.c	29 Jun 2004 14:06:48 -0000
@@ -424,13 +424,14 @@ CODE_FRAGMENT
 .     size of <<.bss>>).  *}
 .  bfd_size_type size;
 .
-.  {* The original size on disk of the section, in octets.  This field
-.     is used by the linker relaxation code.  It is currently only set
-.     for sections where the linker relaxation scheme doesn't cache
-.     altered section and reloc contents (stabs, eh_frame, SEC_MERGE),
-.     and thus the original size needs to be kept to read the section
-.     multiple times.  If non-zero, rawsize will be used in address
-.     checks during relocation and to read section contents.  *}
+.  {* For input sections, the original size on disk of the section, in
+.     octets.  This field is used by the linker relaxation code.  It is
+.     currently only set for sections where the linker relaxation scheme
+.     doesn't cache altered section and reloc contents (stabs, eh_frame,
+.     SEC_MERGE, some coff relaxing targets), and thus the original size
+.     needs to be kept to read the section multiple times.
+.     For output sections, rawsize holds the section size calculated on
+.     a previous linker relaxation pass.  *}
 .  bfd_size_type rawsize;
 .
 .  {* If this section is going to be output, then this value is the
@@ -1379,7 +1380,7 @@ bfd_malloc_and_get_section (bfd *abfd, s
   if (sz == 0)
     return TRUE;
 
-  p = bfd_malloc (sz);
+  p = bfd_malloc (sec->rawsize > sec->size ? sec->rawsize : sec->size);
   if (p == NULL)
     return FALSE;
   *buf = p;
Index: bfd/simple.c
===================================================================
RCS file: /cvs/src/src/bfd/simple.c,v
retrieving revision 1.16
diff -u -p -r1.16 simple.c
--- bfd/simple.c	24 Jun 2004 04:46:26 -0000	1.16
+++ bfd/simple.c	29 Jun 2004 12:51:38 -0000
@@ -143,10 +143,11 @@ bfd_simple_get_relocated_section_content
 
   if (! (sec->flags & SEC_RELOC))
     {
+      bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
       bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
 
       if (outbuf == NULL)
-	contents = bfd_malloc (size);
+	contents = bfd_malloc (amt);
       else
 	contents = outbuf;
 
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.155
diff -u -p -r1.155 ldlang.c
--- ld/ldlang.c	24 Jun 2004 04:46:27 -0000	1.155
+++ ld/ldlang.c	29 Jun 2004 12:52:12 -0000
@@ -4235,7 +4235,11 @@ lang_reset_memory_regions (void)
     }
 
   for (o = output_bfd->sections; o != NULL; o = o->next)
-    o->size = 0;
+    {
+      /* Save the last size for possible use by bfd_relax_section.  */
+      o->rawsize = o->size;
+      o->size = 0;
+    }
 }
 
 /* Worker for lang_gc_sections_1.  */

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]