*** empty log message ***
[deliverable/binutils-gdb.git] / bfd / xcofflink.c
index 3a49918130b7e346346ff3aba31ce03eed40cb87..84b8e52ccaed995959c2dbb37affab071eedd1d7 100644 (file)
@@ -1,5 +1,5 @@
 /* POWER/PowerPC XCOFF linker support.
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
 
@@ -1239,7 +1239,7 @@ xcoff_link_add_symbols (abfd, info)
                {
                  (*_bfd_error_handler)
                    (_("%s: `%s' has line numbers but no enclosing section"),
-                    bfd_get_filename (abfd), name);
+                    bfd_archive_filename (abfd), name);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -1292,7 +1292,7 @@ xcoff_link_add_symbols (abfd, info)
        {
          (*_bfd_error_handler)
            (_("%s: class %d symbol `%s' has no aux entries"),
-            bfd_get_filename (abfd), sym.n_sclass, name);
+            bfd_archive_filename (abfd), sym.n_sclass, name);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
        }
@@ -1315,7 +1315,7 @@ xcoff_link_add_symbols (abfd, info)
        default:
          (*_bfd_error_handler)
            (_("%s: symbol `%s' has unrecognized csect type %d"),
-            bfd_get_filename (abfd), name, smtyp);
+            bfd_archive_filename (abfd), name, smtyp);
          bfd_set_error (bfd_error_bad_value);
          goto error_return;
 
@@ -1327,7 +1327,7 @@ xcoff_link_add_symbols (abfd, info)
            {
              (*_bfd_error_handler)
                (_("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
-                bfd_get_filename (abfd), name, sym.n_sclass, sym.n_scnum,
+                bfd_archive_filename (abfd), name, sym.n_sclass, sym.n_scnum,
                 aux.x_csect.x_scnlen.l);
              bfd_set_error (bfd_error_bad_value);
              goto error_return;
@@ -1363,7 +1363,7 @@ xcoff_link_add_symbols (abfd, info)
                {
                  (*_bfd_error_handler)
                    (_("%s: XMC_TC0 symbol `%s' is class %d scnlen %d"),
-                    bfd_get_filename (abfd), name, sym.n_sclass,
+                    bfd_archive_filename (abfd), name, sym.n_sclass,
                     aux.x_csect.x_scnlen.l);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
@@ -1515,7 +1515,7 @@ xcoff_link_add_symbols (abfd, info)
              {
                (*_bfd_error_handler)
                  (_("%s: csect `%s' not in enclosing section"),
-                  bfd_get_filename (abfd), name);
+                  bfd_archive_filename (abfd), name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
              }
@@ -1622,7 +1622,7 @@ xcoff_link_add_symbols (abfd, info)
              {
                (*_bfd_error_handler)
                  (_("%s: misplaced XTY_LD `%s'"),
-                  bfd_get_filename (abfd), name);
+                  bfd_archive_filename (abfd), name);
                bfd_set_error (bfd_error_bad_value);
                goto error_return;
              }
@@ -1946,7 +1946,7 @@ xcoff_link_add_symbols (abfd, info)
                {
                  (*_bfd_error_handler)
                    (_("%s: reloc %s:%d not in csect"),
-                    bfd_get_filename (abfd), o->name, i);
+                    bfd_archive_filename (abfd), o->name, i);
                  bfd_set_error (bfd_error_bad_value);
                  goto error_return;
                }
@@ -3219,6 +3219,41 @@ bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
   return false;
 }
 
+boolean 
+bfd_xcoff_link_generate_rtinit (abfd, init, fini)
+     bfd *abfd;
+     const char *init;
+     const char *fini;
+{
+  struct bfd_in_memory *bim;
+  
+  bim = ((struct bfd_in_memory *)
+        bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
+  if (bim == NULL)
+    return false;
+
+  bim->size = 0;
+  bim->buffer = 0;
+
+  abfd->link_next = 0;
+  abfd->format = bfd_object;
+  abfd->iostream = (PTR) bim;
+  abfd->flags = BFD_IN_MEMORY;
+  abfd->direction = write_direction;
+  abfd->where = 0;
+
+  if (false == bfd_xcoff_generate_rtinit (abfd, init, fini)) 
+    return false;
+
+  /* need to reset to unknown or it will not be read back in correctly */
+  abfd->format = bfd_unknown;
+  abfd->direction = read_direction;
+  abfd->where = 0;
+
+  return true;
+}
+
+
 /* Add a symbol to the .loader symbols, if necessary.  */
 
 static boolean
@@ -3623,7 +3658,7 @@ _bfd_xcoff_bfd_final_link (abfd, info)
          int indx;
          asection **op;
          file_ptr sofar;
-
+         
          /* Insert .pad sections before every section which has
              contents and is loaded, if it is preceded by some other
              section which has contents and is loaded.  */
@@ -3639,20 +3674,27 @@ _bfd_xcoff_bfd_final_link (abfd, info)
                    saw_contents = true;
                  else
                    {
-                     asection *n, *hold;
-
-                     hold = *op;
-                     *op = NULL;
+                     asection *n, **st;
+                     
+                     /* Create a pad section and place it before the section
+                        that needs padding.  This requires unlinking and 
+                        relinking the bfd's section list.  */
+                     
+                     st = abfd->section_tail;
                      n = bfd_make_section_anyway (abfd, ".pad");
-                     BFD_ASSERT (*op == n);
-                     n->next = hold;
                      n->flags = SEC_HAS_CONTENTS;
-                     n->alignment_power = 0;
+                     n->alignment_power = 0; 
+
+                     BFD_ASSERT (*st == n);
+                     bfd_section_list_remove (abfd, st);
+                     bfd_section_list_insert (abfd, op, n);
+
+                     op = &n->next;
                      saw_contents = false;
                    }
                }
            }
-
+         
          /* Reset the section indices after inserting the new
              sections.  */
          indx = 0;
@@ -3923,17 +3965,6 @@ _bfd_xcoff_bfd_final_link (abfd, info)
        goto error_return;
     }
 
-  /* init-fini */
-  if (info->init_function || info->fini_function)
-    {
-      struct xcoff_link_hash_entry *hrtinit;
-
-      hrtinit = xcoff_link_hash_lookup (xcoff_hash_table (info),
-                                       "__rtinit",
-                                       false, false, true);
-    }
-
-
   /* Write out all the global symbols which do not come from XCOFF
      input files.  */
   xcoff_link_hash_traverse (xcoff_hash_table (info),
@@ -5259,7 +5290,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
                        {
                          (*_bfd_error_handler)
                            (_("%s: loader reloc in unrecognized section `%s'"),
-                            bfd_get_filename (input_bfd),
+                            bfd_archive_filename (input_bfd),
                             sec->name);
                          bfd_set_error (bfd_error_nonrepresentable_section);
                          return false;
@@ -5281,7 +5312,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
                        {
                          (*_bfd_error_handler)
                            (_("%s: `%s' in loader reloc but not loader sym"),
-                            bfd_get_filename (input_bfd),
+                            bfd_archive_filename (input_bfd),
                             h->root.root.string);
                          bfd_set_error (bfd_error_bad_value);
                          return false;
@@ -5296,7 +5327,7 @@ xcoff_link_input_bfd (finfo, input_bfd)
                    {
                      (*_bfd_error_handler)
                        (_("%s: loader reloc in read-only section %s"),
-                        bfd_get_filename (input_bfd),
+                        bfd_archive_filename (input_bfd),
                         bfd_get_section_name (finfo->output_bfd,
                                               o->output_section));
                      bfd_set_error (bfd_error_invalid_operation);
This page took 0.027223 seconds and 4 git commands to generate.