* emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Add
authorIan Lance Taylor <ian@airs.com>
Thu, 9 Nov 1995 18:11:03 +0000 (18:11 +0000)
committerIan Lance Taylor <ian@airs.com>
Thu, 9 Nov 1995 18:11:03 +0000 (18:11 +0000)
new local variable special_sections, and pass it to
size_dynamic_sections.  Look through the results, and move the
sections around in the mapping so that they are defined correctly.

ld/ChangeLog
ld/emultempl/aix.em

index a5fdcbf88b8d2d4ebb78dab20b1f3b79c8b8b811..56986e56e44302fb731f8ccc5538922ab7843ac0 100644 (file)
@@ -1,3 +1,10 @@
+Thu Nov  9 13:09:29 1995  Ian Lance Taylor  <ian@cygnus.com>
+
+       * emultempl/aix.em (gld${EMULATION_NAME}_before_allocation): Add
+       new local variable special_sections, and pass it to
+       size_dynamic_sections.  Look through the results, and move the
+       sections around in the mapping so that they are defined correctly.
+
 Wed Nov  8 11:40:59 1995  Ian Lance Taylor  <ian@cygnus.com>
 
        * ldemul.c (ldemul_default_target): Cast getenv return value.
index 971eeedf1beccc9ccbef876f1abc2e9cab55db45..54476977e4775e818470a1edb7dab95f76d8c129 100644 (file)
@@ -433,6 +433,8 @@ gld${EMULATION_NAME}_before_allocation ()
   struct filelist *fl;
   struct export_symbol_list *el;
   char *libpath;
+  asection *special_sections[6];
+  int i;
 
   /* Handle the import and export files, if any.  */
   for (fl = import_files; fl != NULL; fl = fl->next)
@@ -487,8 +489,113 @@ gld${EMULATION_NAME}_before_allocation ()
                                         maxstack, maxdata,
                                         gc ? true : false,
                                         modtype,
-                                        textro ? true : false))
+                                        textro ? true : false,
+                                        special_sections))
     einfo ("%P%F: failed to set dynamic section sizes: %E\n");
+
+  /* Look through the special sections, and put them in the right
+     place in the link ordering.  This is especially magic.  */
+  for (i = 0; i < 6; i++)
+    {
+      asection *sec;
+      lang_output_section_statement_type *os;
+      lang_statement_union_type **pls;
+      lang_input_section_type *is;
+      const char *oname;
+      boolean start;
+
+      sec = special_sections[i];
+      if (sec == NULL)
+       continue;
+
+      /* Remove this section from the list of the output section.
+         This assumes we know what the script looks like.  */
+      is = NULL;
+      os = lang_output_section_find (sec->output_section->name);
+      if (os == NULL)
+       einfo ("%P%F: can't find output section %s\n",
+              sec->output_section->name);
+      for (pls = &os->children.head; *pls != NULL; pls = &(*pls)->next)
+       {
+         if ((*pls)->header.type == lang_input_section_enum
+             && (*pls)->input_section.section == sec)
+           {
+             is = (lang_input_section_type *) *pls;
+             *pls = (*pls)->next;
+             break;
+           }
+         if ((*pls)->header.type == lang_wild_statement_enum)
+           {
+             lang_statement_union_type **pwls;
+
+             for (pwls = &(*pls)->wild_statement.children.head;
+                  *pwls != NULL;
+                  pwls = &(*pwls)->next)
+               {
+                 if ((*pwls)->header.type == lang_input_section_enum
+                     && (*pwls)->input_section.section == sec)
+                   {
+                     is = (lang_input_section_type *) *pwls;
+                     *pwls = (*pwls)->next;
+                     break;
+                   }
+               }
+             if (is != NULL)
+               break;
+           }
+       }       
+
+      if (is == NULL)
+       einfo ("%P%F: can't find %s in output section\n",
+              bfd_get_section_name (sec->owner, sec));
+
+      /* Now figure out where the section should go.  */
+      switch (i)
+       {
+       default: /* to avoid warnings */
+       case 0:
+         /* _text */
+         oname = ".text";
+         start = true;
+         break;
+       case 1:
+         /* _etext */
+         oname = ".text";
+         start = false;
+         break;
+       case 2:
+         /* _data */
+         oname = ".data";
+         start = true;
+         break;
+       case 3:
+         /* _edata */
+         oname = ".data";
+         start = false;
+         break;
+       case 4:
+       case 5:
+         /* _end and end */
+         oname = ".bss";
+         start = false;
+         break;
+       }
+
+      os = lang_output_section_find (oname);
+
+      if (start)
+       {
+         is->header.next = os->children.head;
+         os->children.head = (lang_statement_union_type *) is;
+       }
+      else
+       {
+         is->header.next = NULL;
+         lang_statement_append (&os->children,
+                                (lang_statement_union_type *) is,
+                                &is->header.next);
+       }
+    }
 }
 
 /* Read an import or export file.  For an import file, this is called