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: phdrs for orphans


On Mon, Dec 09, 2002 at 11:48:11PM +1030, Alan Modra wrote:
> Hmm, but why is the output statement re-ordering done by place_orphan
> not doing this for us automatically?  Huh, looks like place_orphan is
> re-ordering the wrong list!  I'll revisit this tomorrow..

I re-ordered both the output section statement, and the general
list as it seems both lists may be traversed after placing orphans.

I'd appreciate a critical review of this patch as it's very easy to
get the list handling wrong..  I think some renaming of fields might
be a good idea too.

	* emultempl/elf32.em (struct orphan_save): Add os_tail field.
	(gld${EMULATION_NAME}_place_orphan): Re-order output_section_statement
	list too.

Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.86
diff -u -p -r1.86 elf32.em
--- ld/emultempl/elf32.em	4 Dec 2002 23:56:14 -0000	1.86
+++ ld/emultempl/elf32.em	10 Dec 2002 03:15:24 -0000
@@ -1071,6 +1071,7 @@ struct orphan_save {
   lang_output_section_statement_type *os;
   asection **section;
   lang_statement_union_type **stmt;
+  lang_statement_union_type **os_tail;
 };
 
 static bfd_boolean
@@ -1093,6 +1094,7 @@ gld${EMULATION_NAME}_place_orphan (file,
   const char *secname;
   const char *ps = NULL;
   lang_output_section_statement_type *os;
+  lang_statement_union_type **os_tail;
   etree_type *load_base;
   int isdyn = 0;
 
@@ -1242,6 +1244,7 @@ gld${EMULATION_NAME}_place_orphan (file,
 			     exp_nameop (ADDR, secname));
     }
 
+  os_tail = lang_output_section_statement.tail;
   os = lang_enter_output_section_statement (secname, address, 0,
 					    (bfd_vma) 0,
 					    (etree_type *) NULL,
@@ -1321,11 +1324,15 @@ gld${EMULATION_NAME}_place_orphan (file,
 	 read/write section before or amongst the read-only ones.  */
       if (add.head != NULL)
 	{
+	  lang_statement_union_type *newly_added_os;
+
 	  if (place->stmt == NULL)
 	    {
 	      /* Put the new statement list right at the head.  */
 	      *add.tail = place->os->header.next;
 	      place->os->header.next = add.head;
+
+	      place->os_tail = &place->os->next;
 	    }
 	  else
 	    {
@@ -1341,6 +1348,21 @@ gld${EMULATION_NAME}_place_orphan (file,
 
 	  /* Save the end of this list.  */
 	  place->stmt = add.tail;
+
+	  /* Do the same for the list of output statements.  */
+	  newly_added_os = *os_tail;
+	  *os_tail = NULL;
+	  newly_added_os->output_section_statement.next = *place->os_tail;
+	  *place->os_tail = newly_added_os;
+	  place->os_tail = &newly_added_os->output_section_statement.next;
+
+	  /* Fixing the global list pointer here is a little different.
+	     We added to the list in lang_enter_output_section_statement,
+	     trimmed off the new output_section_statment above when
+	     assigning *os_tail = NULL, but possibly added it back in
+	     the same place when assigning *place->os_tail.  */
+	  if (*os_tail == NULL)
+	    lang_output_section_statement.tail = os_tail;
 	}
     }
 

-- 
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]