Fix @pltoff linker segfault for non-shared link.
[deliverable/binutils-gdb.git] / bfd / simple.c
index 9044c28b38da13430f78be91a75fa3e28948fd0e..5039911dcfdf1356793a6df6a83bdfcc33019ea3 100644 (file)
@@ -1,5 +1,5 @@
 /* simple.c -- BFD simple client routines
-   Copyright 2002, 2003
+   Copyright 2002, 2003, 2004
    Free Software Foundation, Inc.
    Contributed by MontaVista Software, Inc.
 
@@ -140,42 +140,21 @@ bfd_simple_get_relocated_section_contents (bfd *abfd,
   bfd_byte *contents, *data;
   int storage_needed;
   void *saved_offsets;
-  bfd_boolean saved_reloc_done = sec->reloc_done;
-
-#undef RETURN
-#define RETURN(x)                              \
-  do                                           \
-    {                                          \
-      sec->reloc_done = saved_reloc_done;      \
-      return (x);                              \
-    }                                          \
-  while (0)
-
-  /* Foul hack to prevent bfd_section_size aborts.  The reloc_done flag
-     only controls that macro (and the related size macros), selecting
-     between _raw_size and _cooked_size.  We may be called with relocation
-     done or not, so we need to save the done-flag and mark the section as
-     not relocated.
-
-     Debug sections won't change size while we're only relocating.  There
-     may be trouble here someday if it tries to run relaxation
-     unexpectedly, so make sure.  */
-  BFD_ASSERT (sec->_raw_size == sec->_cooked_size);
-  sec->reloc_done = 0;
 
   if (! (sec->flags & SEC_RELOC))
     {
-      bfd_size_type size = bfd_section_size (abfd, sec);
+      bfd_size_type amt = sec->rawsize > sec->size ? sec->rawsize : sec->size;
+      bfd_size_type size = sec->rawsize ? sec->rawsize : sec->size;
 
       if (outbuf == NULL)
-       contents = bfd_malloc (size);
+       contents = bfd_malloc (amt);
       else
        contents = outbuf;
 
       if (contents)
        bfd_get_section_contents (abfd, sec, contents, 0, size);
 
-      RETURN (contents);
+      return contents;
     }
 
   /* In order to use bfd_get_relocated_section_contents, we need
@@ -197,21 +176,21 @@ bfd_simple_get_relocated_section_contents (bfd *abfd,
   link_order.next = NULL;
   link_order.type = bfd_indirect_link_order;
   link_order.offset = 0;
-  link_order.size = bfd_section_size (abfd, sec);
+  link_order.size = sec->size;
   link_order.u.indirect.section = sec;
 
   data = NULL;
   if (outbuf == NULL)
     {
-      data = bfd_malloc (bfd_section_size (abfd, sec));
+      data = bfd_malloc (sec->size);
       if (data == NULL)
-       RETURN (NULL);
+       return NULL;
       outbuf = data;
     }
 
   /* The sections in ABFD may already have output sections and offsets set.
      Because this function is primarily for debug sections, and GCC uses the
-     knowledge that debug sections will generally have VMA 0 when emiting
+     knowledge that debug sections will generally have VMA 0 when emitting
      relocations between DWARF-2 sections (which are supposed to be
      section-relative offsets anyway), we need to reset the output offsets
      to zero.  We also need to arrange for section->output_section->vma plus
@@ -224,7 +203,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd,
     {
       if (data)
        free (data);
-      RETURN (NULL);
+      return NULL;
     }
   bfd_map_over_sections (abfd, simple_save_output_info, saved_offsets);
 
@@ -265,7 +244,7 @@ bfd_simple_get_relocated_section_contents (bfd *abfd,
   bfd_map_over_sections (abfd, simple_restore_output_info, saved_offsets);
   free (saved_offsets);
 
-  bfd_link_hash_table_free (abfd, link_info.hash);
+  _bfd_generic_link_hash_table_free (link_info.hash);
 
-  RETURN (contents);
+  return contents;
 }
This page took 0.024766 seconds and 4 git commands to generate.