bfd_link_order vs. asection

Alan Modra amodra@bigpond.net.au
Tue Dec 27 03:08:00 GMT 2005


Some time ago, I looked at moving the "offset" and "size" fields of
struct bfd_link_order out of the common part and into the "data" and
"reloc" union fields.  The idea was to free up space in "indirect",
so that I could stash some pointers there for use by the linker.  I
never finished the linker patch, so won't commit the change to
bfd_link_order.  This part just changes some places that can use fields
duplicated in the section struct.

	* coff-h8300.c (h8300_reloc16_extra_cases): Use input section
	"output_offset" instead of link order "offset".
	* coff-h8500.c (extra_case): Likewise.
	* coff-w65.c (w65_reloc16_extra_cases): Likewise.
	* coff-z80.c (extra_case): Likewise.
	* coff-z8k.c (extra_case): Likewise.
	* linker.c (default_indirect_link_order): Likewise, "size" too.
	* ecoff.c (ecoff_indirect_link_order): Likewise.

Index: bfd/coff-h8300.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-h8300.c,v
retrieving revision 1.36
diff -u -p -r1.36 coff-h8300.c
--- bfd/coff-h8300.c	4 May 2005 15:53:02 -0000	1.36
+++ bfd/coff-h8300.c	24 Dec 2005 12:27:51 -0000
@@ -671,7 +671,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       /* Get the address of the target of this branch.  */
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma);
 
@@ -703,7 +703,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
       /* Get the address of the instruction (not the reloc).  */
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma + 1);
 
@@ -817,7 +817,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
       /* Get the address of the next instruction.  */
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma + 1);
 
@@ -864,7 +864,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
       /* Get the address of the instruction (not the reloc).  */
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma - 1);
 
@@ -925,7 +925,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
       /* Get the address of the instruction (not the reloc).  */
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma + 2);
 
@@ -1064,7 +1064,7 @@ h8300_reloc16_extra_cases (bfd *abfd, st
       /* Get the address of the target of this branch.  */
       value = bfd_coff_reloc16_get_value (reloc, link_info, input_section);
 
-      dot = (link_order->offset
+      dot = (input_section->output_offset
 	     + dst_address
 	     + link_order->u.indirect.section->output_section->vma) + 1;
 
Index: bfd/coff-h8500.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-h8500.c,v
retrieving revision 1.14
diff -u -p -r1.14 coff-h8500.c
--- bfd/coff-h8500.c	4 May 2005 15:53:02 -0000	1.14
+++ bfd/coff-h8500.c	24 Dec 2005 12:27:52 -0000
@@ -245,9 +245,9 @@ extra_case (in_abfd, link_info, link_ord
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = link_order->offset
-	  + *dst_ptr
-	    + link_order->u.indirect.section->output_section->vma;
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
+		       + input_section->output_section->vma);
 	int gap = dst - dot - 1; /* -1 since were in the odd byte of the
 				    word and the pc's been incremented.  */
 
@@ -269,9 +269,9 @@ extra_case (in_abfd, link_info, link_ord
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = link_order->offset
-	  + *dst_ptr
-	    + link_order->u.indirect.section->output_section->vma;
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
+		       + input_section->output_section->vma);
 	int gap = dst - dot - 1; /* -1 since were in the odd byte of the
 				    word and the pc's been incremented.  */
 
Index: bfd/coff-w65.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-w65.c,v
retrieving revision 1.15
diff -u -p -r1.15 coff-w65.c
--- bfd/coff-w65.c	4 May 2005 15:53:04 -0000	1.15
+++ bfd/coff-w65.c	24 Dec 2005 12:27:52 -0000
@@ -316,9 +316,9 @@ w65_reloc16_extra_cases (abfd, link_info
       {
 	int gap = bfd_coff_reloc16_get_value (reloc, link_info,
 					      input_section);
-	bfd_vma dot = link_order->offset
-	  + dst_address
-	    + link_order->u.indirect.section->output_section->vma;
+	bfd_vma dot = (dst_address
+		       + input_section->output_offset
+		       + input_section->output_section->vma);
 
 	gap -= dot + 1;
 	if (gap < -128 || gap > 127)
@@ -340,9 +340,9 @@ w65_reloc16_extra_cases (abfd, link_info
       {
 	bfd_vma gap = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = link_order->offset
-	  + dst_address
-	    + link_order->u.indirect.section->output_section->vma;
+	bfd_vma dot = (dst_address
+		       + input_section->output_offset
+		       + input_section->output_section->vma);
 
 	/* This wraps within the page, so ignore the relativeness, look at the
 	   high part.  */
Index: bfd/coff-z80.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-z80.c,v
retrieving revision 1.1
diff -u -p -r1.1 coff-z80.c
--- bfd/coff-z80.c	25 Oct 2005 17:40:09 -0000	1.1
+++ bfd/coff-z80.c	24 Dec 2005 12:27:52 -0000
@@ -200,8 +200,8 @@ extra_case (bfd *in_abfd,
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = (link_order->offset
-		       + *dst_ptr
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
 		       + input_section->output_section->vma);
 	int gap = dst - dot - 1;  /* -1, Since the offset is relative
 				     to the value of PC after reading
Index: bfd/coff-z8k.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-z8k.c,v
retrieving revision 1.20
diff -u -p -r1.20 coff-z8k.c
--- bfd/coff-z8k.c	26 Aug 2005 09:47:43 -0000	1.20
+++ bfd/coff-z8k.c	24 Dec 2005 12:27:52 -0000
@@ -230,8 +230,8 @@ extra_case (bfd *in_abfd,
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = (link_order->offset
-		       + *dst_ptr
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
 		       + input_section->output_section->vma);
 	int gap = dst - dot - 1;  /* -1, since we're in the odd byte of the
                                      word and the pc's been incremented.  */
@@ -258,8 +258,8 @@ extra_case (bfd *in_abfd,
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = (link_order->offset
-		       + *dst_ptr
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
 		       + input_section->output_section->vma);
 	int gap = dst - dot - 1;  /* -1, since we're in the odd byte of the
                                      word and the pc's been incremented.  */
@@ -289,8 +289,8 @@ extra_case (bfd *in_abfd,
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = (link_order->offset
-		       + *dst_ptr
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
 		       + input_section->output_section->vma);
 	int gap = dst - dot - 2;
 
@@ -318,8 +318,8 @@ extra_case (bfd *in_abfd,
       {
 	bfd_vma dst = bfd_coff_reloc16_get_value (reloc, link_info,
 						  input_section);
-	bfd_vma dot = (link_order->offset
-		       + *dst_ptr
+	bfd_vma dot = (*dst_ptr
+		       + input_section->output_offset
 		       + input_section->output_section->vma);
 	int gap = dst - dot - 2;
 
Index: bfd/ecoff.c
===================================================================
RCS file: /cvs/src/src/bfd/ecoff.c,v
retrieving revision 1.48
diff -u -p -r1.48 ecoff.c
--- bfd/ecoff.c	6 Jul 2005 10:35:41 -0000	1.48
+++ bfd/ecoff.c	24 Dec 2005 12:27:56 -0000
@@ -4002,11 +4002,10 @@ ecoff_indirect_link_order (bfd *output_b
 
   BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
 
-  if (link_order->size == 0)
-    return TRUE;
-
   input_section = link_order->u.indirect.section;
   input_bfd = input_section->owner;
+  if (input_section->size == 0)
+    return TRUE;
 
   BFD_ASSERT (input_section->output_section == output_section);
   BFD_ASSERT (input_section->output_offset == link_order->offset);
Index: bfd/linker.c
===================================================================
RCS file: /cvs/src/src/bfd/linker.c,v
retrieving revision 1.51
diff -u -p -r1.51 linker.c
--- bfd/linker.c	24 Oct 2005 11:24:31 -0000	1.51
+++ bfd/linker.c	24 Dec 2005 12:28:21 -0000
@@ -2717,11 +2717,10 @@ default_indirect_link_order (bfd *output
 
   BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
 
-  if (link_order->size == 0)
-    return TRUE;
-
   input_section = link_order->u.indirect.section;
   input_bfd = input_section->owner;
+  if (input_section->size == 0)
+    return TRUE;
 
   BFD_ASSERT (input_section->output_section == output_section);
   BFD_ASSERT (input_section->output_offset == link_order->offset);
@@ -2810,9 +2807,9 @@ default_indirect_link_order (bfd *output
     goto error_return;
 
   /* Output the section contents.  */
-  loc = link_order->offset * bfd_octets_per_byte (output_bfd);
+  loc = input_section->output_offset * bfd_octets_per_byte (output_bfd);
   if (! bfd_set_section_contents (output_bfd, output_section,
-				  new_contents, loc, link_order->size))
+				  new_contents, loc, input_section->size))
     goto error_return;
 
   if (contents != NULL)

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre



More information about the Binutils mailing list