This is the mail archive of the binutils@sourceware.org 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: How to use bits_per_byte (~OCTETS_PER_BYTE) of bfd_arch_info_type in binutils port?


On Mon, Aug 10, 2009 at 02:04:03AM +0200, Martin Walter wrote:
> Hello,
> 
> >> I know about these architectures, but mine uses ELF so I did not dig
> >> too much into them. I am not that much into the binutils and it does
> >> not seem like this can be fixed easily. Have you got some more details
> >> on where these missing conversions could reside?
> >
> > Apart from saying they are likely in elflink.c, no. ?I found the
> > errors on bfd_set_section_contents calls by inspection when responding
> > to your email.
> 
> I have yet failed to find the relevant hotspots in the code. Some
> changes give improvements in one place, but create a total mess in the
> object file in other places. I am doing the Binutils port for a
> practical work at University and I am afraid not to have the required
> insight into the BFD to fix this on my own. Is there a possibility to
> request a fix by a maintainer directly?

I don't have time spare to do this at the moment, sorry.  I started
looking just at occurrences of output_offset (which is an address),
and found rather a lot of places that assume octet/byte == 1.

eg.
	p = sort + o->output_offset / ext_size * sort_elt;
and
      offset += sections[n]->size;

besides the calls to bfd_set_section_contents, which ought to be fixed
by the following patch.  I'm loathe to apply this patch to the
official sources until we have a contributed port that needs it,
because bfd_octets_per_bytes is not exactly a cheap function.  A
proper fix would involve adding an opb_shift or somesuch to the bfd
struct, and using that.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.351
diff -u -p -r1.351 elflink.c
--- bfd/elflink.c	10 Aug 2009 06:14:04 -0000	1.351
+++ bfd/elflink.c	10 Aug 2009 11:56:30 -0000
@@ -9696,15 +9696,16 @@ elf_link_input_bfd (struct elf_final_lin
 	  }
 	  break;
 	default:
-	  {
-	    if (! (o->flags & SEC_EXCLUDE)
-		&& ! (o->output_section->flags & SEC_NEVER_LOAD)
-		&& ! bfd_set_section_contents (output_bfd, o->output_section,
-					       contents,
-					       (file_ptr) o->output_offset,
-					       o->size))
-	      return FALSE;
-	  }
+	  if (!(o->flags & SEC_EXCLUDE)
+	      && !(o->output_section->flags & SEC_NEVER_LOAD))
+	    {
+	      file_ptr loc;
+
+	      loc = o->output_offset * bfd_octets_per_byte (output_bfd);
+	      if (!bfd_set_section_contents (output_bfd, o->output_section,
+					     contents, loc, o->size))
+		return FALSE;
+	    }
 	  break;
 	}
     }
@@ -9803,6 +9804,7 @@ elf_reloc_link_order (bfd *output_bfd,
       bfd_byte *buf;
       bfd_boolean ok;
       const char *sym_name;
+      file_ptr loc;
 
       size = bfd_get_reloc_size (howto);
       buf = bfd_zmalloc (size);
@@ -9833,8 +9835,9 @@ elf_reloc_link_order (bfd *output_bfd,
 	    }
 	  break;
 	}
+      loc = link_order->offset * bfd_octets_per_byte (output_bfd);
       ok = bfd_set_section_contents (output_bfd, output_section, buf,
-				     link_order->offset, size);
+				     loc, size);
       free (buf);
       if (! ok)
 	return FALSE;
@@ -10999,10 +11002,11 @@ bfd_elf_final_link (bfd *abfd, struct bf
 	       != SHT_STRTAB)
 	      || strcmp (bfd_get_section_name (abfd, o), ".dynstr") != 0)
 	    {
+	      file_ptr loc;
+
+	      loc = o->output_offset * bfd_octets_per_byte (abfd);
 	      if (! bfd_set_section_contents (abfd, o->output_section,
-					      o->contents,
-					      (file_ptr) o->output_offset,
-					      o->size))
+					      o->contents, loc, o->size))
 		goto error_return;
 	    }
 	  else

-- 
Alan Modra
Australia Development Lab, IBM


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