Back to index

cell-binutils  2.17cvs20070401
Defines | Functions | Variables
coffcode.h File Reference
#include "coffswap.h"
#include "Your aouthdr magic number is not being set!"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define STRING_SIZE_SIZE   4
#define DOT_DEBUG   ".debug"
#define GNU_LINKONCE_WI   ".gnu.linkonce.wi."
#define STYP_XCOFF_DEBUG   STYP_INFO
#define STYP_DEBUG_INFO   STYP_INFO
#define get_index(symbol)   ((symbol)->udata.i)
#define coff_set_alignment_hook   ((void (*) (bfd *, asection *, void *)) bfd_void)
#define symname_in_debug_hook   (bfd_boolean (*) (bfd *, struct internal_syment *)) bfd_false
#define coff_pointerize_aux_hook   0
#define ALIGN_SECTIONS_IN_FILE
#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)
#define coff_rtype_to_howto   NULL
#define coff_reloc16_estimate   dummy_reloc16_estimate
#define coff_reloc16_extra_cases   dummy_reloc16_extra_cases
#define coff_bfd_link_hash_table_free   _bfd_generic_link_hash_table_free
#define coff_relocate_section   NULL
#define coff_bfd_link_hash_table_create   _bfd_generic_link_hash_table_create
#define coff_bfd_link_add_symbols   _bfd_generic_link_add_symbols
#define coff_bfd_final_link   _bfd_generic_final_link
#define coff_bfd_link_just_syms   _bfd_generic_link_just_syms
#define coff_bfd_link_split_section   _bfd_generic_link_split_section
#define coff_start_final_link   NULL
#define coff_adjust_symndx   NULL
#define coff_link_add_one_symbol   _bfd_generic_link_add_one_symbol
#define coff_SWAP_aux_in   coff_swap_aux_in
#define coff_SWAP_sym_in   coff_swap_sym_in
#define coff_SWAP_lineno_in   coff_swap_lineno_in
#define coff_SWAP_aux_out   coff_swap_aux_out
#define coff_SWAP_sym_out   coff_swap_sym_out
#define coff_SWAP_lineno_out   coff_swap_lineno_out
#define coff_SWAP_reloc_out   coff_swap_reloc_out
#define coff_SWAP_filehdr_out   coff_swap_filehdr_out
#define coff_SWAP_aouthdr_out   coff_swap_aouthdr_out
#define coff_SWAP_scnhdr_out   coff_swap_scnhdr_out
#define coff_SWAP_reloc_in   coff_swap_reloc_in
#define coff_SWAP_filehdr_in   coff_swap_filehdr_in
#define coff_SWAP_aouthdr_in   coff_swap_aouthdr_in
#define coff_SWAP_scnhdr_in   coff_swap_scnhdr_in
#define coff_close_and_cleanup   _bfd_generic_close_and_cleanup
#define coff_bfd_free_cached_info   _bfd_generic_bfd_free_cached_info
#define coff_get_section_contents   _bfd_generic_get_section_contents
#define coff_bfd_copy_private_symbol_data   _bfd_generic_bfd_copy_private_symbol_data
#define coff_bfd_copy_private_header_data   _bfd_generic_bfd_copy_private_header_data
#define coff_bfd_copy_private_section_data   _bfd_generic_bfd_copy_private_section_data
#define coff_bfd_copy_private_bfd_data   _bfd_generic_bfd_copy_private_bfd_data
#define coff_bfd_merge_private_bfd_data   _bfd_generic_bfd_merge_private_bfd_data
#define coff_bfd_set_private_flags   _bfd_generic_bfd_set_private_flags
#define coff_bfd_print_private_bfd_data   _bfd_generic_bfd_print_private_bfd_data
#define coff_bfd_is_local_label_name   _bfd_coff_is_local_label_name
#define coff_bfd_is_target_special_symbol   ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
#define coff_read_minisymbols   _bfd_generic_read_minisymbols
#define coff_minisymbol_to_symbol   _bfd_generic_minisymbol_to_symbol
#define coff_bfd_reloc_type_lookup   _bfd_norelocs_bfd_reloc_type_lookup
#define coff_bfd_reloc_name_lookup   _bfd_norelocs_bfd_reloc_name_lookup
#define coff_bfd_get_relocated_section_contents   bfd_generic_get_relocated_section_contents
#define coff_bfd_relax_section   bfd_generic_relax_section
#define coff_bfd_gc_sections   bfd_generic_gc_sections
#define coff_bfd_merge_sections   bfd_generic_merge_sections
#define coff_bfd_is_group_section   bfd_generic_is_group_section
#define coff_bfd_discard_group   bfd_generic_discard_group
#define coff_section_already_linked   _bfd_generic_section_already_linked
#define CREATE_BIG_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)
#define CREATE_BIGHDR_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)
#define CREATE_LITTLE_COFF_TARGET_VEC(VAR, NAME, EXTRA_O_FLAGS, EXTRA_S_FLAGS, UNDER, ALTERNATIVE, SWAP_TABLE)

Functions

static long sec_to_styp_flags (const char *, flagword)
static bfd_boolean styp_to_sec_flags (bfd *, void *, const char *, asection *, flagword *)
static bfd_boolean coff_bad_format_hook (bfd *, void *)
static void coff_set_custom_section_alignment (bfd *, asection *, const struct coff_section_alignment_entry *, const unsigned int)
static bfd_boolean coff_new_section_hook (bfd *, asection *)
static bfd_boolean coff_set_arch_mach_hook (bfd *, void *)
static bfd_boolean coff_write_relocs (bfd *, int)
static bfd_boolean coff_set_flags (bfd *, unsigned int *, unsigned short *)
static bfd_boolean coff_set_arch_mach (bfd *, enum bfd_architecture, unsigned long) ATTRIBUTE_UNUSED
static bfd_boolean coff_compute_section_file_positions (bfd *)
static bfd_boolean coff_write_object_contents (bfd *) ATTRIBUTE_UNUSED
static bfd_boolean coff_set_section_contents (bfd *, asection *, const void *, file_ptr, bfd_size_type)
static void * buy_and_read (bfd *, file_ptr, bfd_size_type)
static bfd_boolean coff_slurp_line_table (bfd *, asection *)
static bfd_boolean coff_slurp_symbol_table (bfd *)
static enum
coff_symbol_classification 
coff_classify_symbol (bfd *, struct internal_syment *)
static bfd_boolean coff_slurp_reloc_table (bfd *, asection *, asymbol **)
static long coff_canonicalize_reloc (bfd *, asection *, arelent **, asymbol **)
static void * coff_mkobject_hook (bfd *, void *, void *)
static bfd_boolean styp_to_sec_flags (bfd *abfd ATTRIBUTE_UNUSED, void *hdr, const char *name, asection *section ATTRIBUTE_UNUSED, flagword *flags_ptr)
static bfd_boolean coff_bad_format_hook (bfd *abfd ATTRIBUTE_UNUSED, void *filehdr)
static void coff_set_custom_section_alignment (bfd *abfd ATTRIBUTE_UNUSED, asection *section, const struct coff_section_alignment_entry *alignment_table, const unsigned int table_size)
static bfd_boolean coff_mkobject (bfd *abfd)
static void * coff_mkobject_hook (bfd *abfd, void *filehdr, void *aouthdr ATTRIBUTE_UNUSED)
static bfd_boolean coff_print_aux (bfd *abfd ATTRIBUTE_UNUSED, FILE *file ATTRIBUTE_UNUSED, combined_entry_type *table_base ATTRIBUTE_UNUSED, combined_entry_type *symbol ATTRIBUTE_UNUSED, combined_entry_type *aux ATTRIBUTE_UNUSED, unsigned int indaux ATTRIBUTE_UNUSED)
static bfd_boolean coff_set_flags (bfd *abfd, unsigned int *magicp ATTRIBUTE_UNUSED, unsigned short *flagsp ATTRIBUTE_UNUSED)
static bfd_boolean coff_set_section_contents (bfd *abfd, sec_ptr section, const void *location, file_ptr offset, bfd_size_type count)
static bfd_boolean coff_slurp_reloc_table (bfd *abfd, sec_ptr asect, asymbol **symbols)
static long coff_canonicalize_reloc (bfd *abfd, sec_ptr section, arelent **relptr, asymbol **symbols)
static int dummy_reloc16_estimate (bfd *abfd ATTRIBUTE_UNUSED, asection *input_section ATTRIBUTE_UNUSED, arelent *reloc ATTRIBUTE_UNUSED, unsigned int shrink ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
static void dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED, struct bfd_link_order *link_order ATTRIBUTE_UNUSED, arelent *reloc ATTRIBUTE_UNUSED, bfd_byte *data ATTRIBUTE_UNUSED, unsigned int *src_ptr ATTRIBUTE_UNUSED, unsigned int *dst_ptr ATTRIBUTE_UNUSED)
static bfd_boolean coff_link_output_has_begun (bfd *abfd, struct coff_final_link_info *info ATTRIBUTE_UNUSED)
static bfd_boolean coff_final_link_postscript (bfd *abfd ATTRIBUTE_UNUSED, struct coff_final_link_info *pfinfo ATTRIBUTE_UNUSED)

Variables

static struct coff_section_alignment_entry []
static const unsigned int coff_section_alignment_table_size
static const
bfd_coff_backend_data
bfd_coff_std_swap_table 
ATTRIBUTE_UNUSED

Define Documentation

Definition at line 2931 of file coffcode.h.

#define CALC_ADDEND (   abfd,
  ptr,
  reloc,
  cache_ptr 
)
Value:
{                                                             \
    coff_symbol_type *coffsym = NULL;                          \
                                                                \
    if (ptr && bfd_asymbol_bfd (ptr) != abfd)                   \
      coffsym = (obj_symbols (abfd)                             \
                 + (cache_ptr->sym_ptr_ptr - symbols));         \
    else if (ptr)                                               \
      coffsym = coff_symbol_from (abfd, ptr);                   \
    if (coffsym != NULL                                          \
        && coffsym->native->u.syment.n_scnum == 0)              \
      cache_ptr->addend = 0;                                    \
    else if (ptr && bfd_asymbol_bfd (ptr) == abfd               \
             && ptr->section != NULL)                            \
      cache_ptr->addend = - (ptr->section->vma + ptr->value);   \
    else                                                        \
      cache_ptr->addend = 0;                                    \
  }

Definition at line 4816 of file coffcode.h.

#define coff_adjust_symndx   NULL

Definition at line 5077 of file coffcode.h.

Definition at line 5300 of file coffcode.h.

Definition at line 5292 of file coffcode.h.

Definition at line 5296 of file coffcode.h.

Definition at line 5288 of file coffcode.h.

Definition at line 5362 of file coffcode.h.

Definition at line 5065 of file coffcode.h.

Definition at line 5280 of file coffcode.h.

Definition at line 5350 of file coffcode.h.

Definition at line 5341 of file coffcode.h.

Definition at line 5358 of file coffcode.h.

Definition at line 5316 of file coffcode.h.

Definition at line 5320 of file coffcode.h.

Definition at line 5063 of file coffcode.h.

Definition at line 5060 of file coffcode.h.

Definition at line 5038 of file coffcode.h.

Definition at line 5069 of file coffcode.h.

Definition at line 5070 of file coffcode.h.

Definition at line 5304 of file coffcode.h.

Definition at line 5354 of file coffcode.h.

Definition at line 5312 of file coffcode.h.

Definition at line 5346 of file coffcode.h.

Definition at line 5337 of file coffcode.h.

Definition at line 5334 of file coffcode.h.

Definition at line 5308 of file coffcode.h.

Definition at line 5276 of file coffcode.h.

Definition at line 5284 of file coffcode.h.

Definition at line 5081 of file coffcode.h.

Definition at line 5328 of file coffcode.h.

#define coff_pointerize_aux_hook   0

Definition at line 2339 of file coffcode.h.

Definition at line 5324 of file coffcode.h.

Definition at line 5003 of file coffcode.h.

Definition at line 5020 of file coffcode.h.

Definition at line 5058 of file coffcode.h.

#define coff_rtype_to_howto   NULL

Definition at line 4959 of file coffcode.h.

Definition at line 5366 of file coffcode.h.

#define coff_set_alignment_hook   ((void (*) (bfd *, asection *, void *)) bfd_void)

Definition at line 1742 of file coffcode.h.

Definition at line 5073 of file coffcode.h.

Definition at line 5141 of file coffcode.h.

Definition at line 5129 of file coffcode.h.

Definition at line 5105 of file coffcode.h.

Definition at line 5114 of file coffcode.h.

Definition at line 5138 of file coffcode.h.

Definition at line 5126 of file coffcode.h.

Definition at line 5111 of file coffcode.h.

Definition at line 5120 of file coffcode.h.

Definition at line 5135 of file coffcode.h.

Definition at line 5123 of file coffcode.h.

Definition at line 5144 of file coffcode.h.

Definition at line 5132 of file coffcode.h.

Definition at line 5108 of file coffcode.h.

Definition at line 5117 of file coffcode.h.

#define CREATE_BIG_COFF_TARGET_VEC (   VAR,
  NAME,
  EXTRA_O_FLAGS,
  EXTRA_S_FLAGS,
  UNDER,
  ALTERNATIVE,
  SWAP_TABLE 
)

Definition at line 5370 of file coffcode.h.

#define CREATE_BIGHDR_COFF_TARGET_VEC (   VAR,
  NAME,
  EXTRA_O_FLAGS,
  EXTRA_S_FLAGS,
  UNDER,
  ALTERNATIVE,
  SWAP_TABLE 
)

Definition at line 5420 of file coffcode.h.

#define CREATE_LITTLE_COFF_TARGET_VEC (   VAR,
  NAME,
  EXTRA_O_FLAGS,
  EXTRA_S_FLAGS,
  UNDER,
  ALTERNATIVE,
  SWAP_TABLE 
)

Definition at line 5470 of file coffcode.h.

#define DOT_DEBUG   ".debug"

Definition at line 309 of file coffcode.h.

#define get_index (   symbol)    ((symbol)->udata.i)

Definition at line 1141 of file coffcode.h.

#define GNU_LINKONCE_WI   ".gnu.linkonce.wi."

Definition at line 310 of file coffcode.h.

#define STRING_SIZE_SIZE   4

Definition at line 307 of file coffcode.h.

#define STYP_DEBUG_INFO   STYP_INFO

Definition at line 392 of file coffcode.h.

Definition at line 386 of file coffcode.h.

Definition at line 2275 of file coffcode.h.


Function Documentation

static void * buy_and_read ( bfd abfd,
file_ptr  where,
bfd_size_type  size 
) [static]

Definition at line 4220 of file coffcode.h.

{
  void * area = bfd_alloc (abfd, size);

  if (!area)
    return (NULL);
  if (bfd_seek (abfd, where, SEEK_SET) != 0
      || bfd_bread (area, size, abfd) != size)
    return (NULL);
  return (area);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean coff_bad_format_hook ( bfd ,
void *   
) [static]
static bfd_boolean coff_bad_format_hook ( bfd *abfd  ATTRIBUTE_UNUSED,
void *  filehdr 
) [static]

Definition at line 1431 of file coffcode.h.

{
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;

  if (BADMAG (*internal_f))
    return FALSE;

  /* If the optional header is NULL or not the correct size then
     quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
     and Intel 960 readwrite headers (I960WRMAGIC) is that the
     optional header is of a different size.

     But the mips keeps extra stuff in it's opthdr, so dont check
     when doing that.  */

#if defined(M88) || defined(I960)
  if (internal_f->f_opthdr != 0 && bfd_coff_aoutsz (abfd) != internal_f->f_opthdr)
    return FALSE;
#endif

  return TRUE;
}
static long coff_canonicalize_reloc ( bfd ,
asection ,
arelent **  ,
asymbol **   
) [static]
static long coff_canonicalize_reloc ( bfd abfd,
sec_ptr  section,
arelent **  relptr,
asymbol **  symbols 
) [static]

Definition at line 4967 of file coffcode.h.

{
  arelent *tblptr = section->relocation;
  unsigned int count = 0;

  if (section->flags & SEC_CONSTRUCTOR)
    {
      /* This section has relocs made up by us, they are not in the
        file, so take them out of their chain and place them into
        the data area provided.  */
      arelent_chain *chain = section->constructor_chain;

      for (count = 0; count < section->reloc_count; count++)
       {
         *relptr++ = &chain->relent;
         chain = chain->next;
       }
    }
  else
    {
      if (! coff_slurp_reloc_table (abfd, section, symbols))
       return -1;

      tblptr = section->relocation;

      for (; count++ < section->reloc_count;)
       *relptr++ = tblptr++;
    }
  *relptr = 0;
  return section->reloc_count;
}

Here is the call graph for this function:

static enum coff_symbol_classification coff_classify_symbol ( bfd abfd,
struct internal_syment syment 
) [static]

Definition at line 4698 of file coffcode.h.

{
  /* FIXME: This partially duplicates the switch in
     coff_slurp_symbol_table.  */
  switch (syment->n_sclass)
    {
    case C_EXT:
    case C_WEAKEXT:
#ifdef I960
    case C_LEAFEXT:
#endif
#ifdef ARM
    case C_THUMBEXT:
    case C_THUMBEXTFUNC:
#endif
#ifdef C_SYSTEM
    case C_SYSTEM:
#endif
#ifdef COFF_WITH_PE
    case C_NT_WEAK:
#endif
      if (syment->n_scnum == 0)
       {
         if (syment->n_value == 0)
           return COFF_SYMBOL_UNDEFINED;
         else
           return COFF_SYMBOL_COMMON;
       }
      return COFF_SYMBOL_GLOBAL;

    default:
      break;
    }

#ifdef COFF_WITH_PE
  if (syment->n_sclass == C_STAT)
    {
      if (syment->n_scnum == 0)
       /* The Microsoft compiler sometimes generates these if a
          small static function is inlined every time it is used.
          The function is discarded, but the symbol table entry
          remains.  */
       return COFF_SYMBOL_LOCAL;

#ifdef STRICT_PE_FORMAT
      /* This is correct for Microsoft generated objects, but it
         breaks gas generated objects.  */
      if (syment->n_value == 0)
       {
         asection *sec;
         char buf[SYMNMLEN + 1];

         sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
         if (sec != NULL
             && (strcmp (bfd_get_section_name (abfd, sec),
                       _bfd_coff_internal_syment_name (abfd, syment, buf))
                == 0))
           return COFF_SYMBOL_PE_SECTION;
       }
#endif

      return COFF_SYMBOL_LOCAL;
    }

  if (syment->n_sclass == C_SECTION)
    {
      /* In some cases in a DLL generated by the Microsoft linker, the
         n_value field will contain garbage.  FIXME: This should
         probably be handled by the swapping function instead.  */
      syment->n_value = 0;
      if (syment->n_scnum == 0)
       return COFF_SYMBOL_UNDEFINED;
      return COFF_SYMBOL_PE_SECTION;
    }
#endif /* COFF_WITH_PE */

  /* If it is not a global symbol, we presume it is a local symbol.  */
  if (syment->n_scnum == 0)
    {
      char buf[SYMNMLEN + 1];

      (*_bfd_error_handler)
       (_("warning: %B: local symbol `%s' has no section"),
        abfd, _bfd_coff_internal_syment_name (abfd, syment, buf));
    }

  return COFF_SYMBOL_LOCAL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2938 of file coffcode.h.

{
  asection *current;
  asection *previous = NULL;
  file_ptr sofar = bfd_coff_filhsz (abfd);
  bfd_boolean align_adjust;
#ifdef ALIGN_SECTIONS_IN_FILE
  file_ptr old_sofar;
#endif

#ifdef RS6000COFF_C
  /* On XCOFF, if we have symbols, set up the .debug section.  */
  if (bfd_get_symcount (abfd) > 0)
    {
      bfd_size_type sz;
      bfd_size_type i, symcount;
      asymbol **symp;

      sz = 0;
      symcount = bfd_get_symcount (abfd);
      for (symp = abfd->outsymbols, i = 0; i < symcount; symp++, i++)
       {
         coff_symbol_type *cf;

         cf = coff_symbol_from (abfd, *symp);
         if (cf != NULL
             && cf->native != NULL
             && SYMNAME_IN_DEBUG (&cf->native->u.syment))
           {
             size_t len;

             len = strlen (bfd_asymbol_name (*symp));
             if (len > SYMNMLEN || bfd_coff_force_symnames_in_strings (abfd))
              sz += len + 1 + bfd_coff_debug_string_prefix_length (abfd);
           }
       }
      if (sz > 0)
       {
         asection *dsec;

         dsec = bfd_make_section_old_way (abfd, DOT_DEBUG);
         if (dsec == NULL)
           abort ();
         dsec->size = sz;
         dsec->flags |= SEC_HAS_CONTENTS;
       }
    }
#endif

#ifdef COFF_IMAGE_WITH_PE
  int page_size;

  if (coff_data (abfd)->link_info)
    {
      page_size = pe_data (abfd)->pe_opthdr.FileAlignment;

      /* If no file alignment has been set, default to one.
        This repairs 'ld -r' for arm-wince-pe target.  */
      if (page_size == 0)
        page_size = 1;
    }
  else
    page_size = PE_DEF_FILE_ALIGNMENT;
#else
#ifdef COFF_PAGE_SIZE
  int page_size = COFF_PAGE_SIZE;
#endif
#endif

  if (bfd_get_start_address (abfd))
    /*  A start address may have been added to the original file. In this
       case it will need an optional header to record it.  */
    abfd->flags |= EXEC_P;

  if (abfd->flags & EXEC_P)
    sofar += bfd_coff_aoutsz (abfd);
#ifdef RS6000COFF_C
  else if (xcoff_data (abfd)->full_aouthdr)
    sofar += bfd_coff_aoutsz (abfd);
  else
    sofar += SMALL_AOUTSZ;
#endif

  sofar += abfd->section_count * bfd_coff_scnhsz (abfd);

#ifdef RS6000COFF_C
  /* XCOFF handles overflows in the reloc and line number count fields
     by allocating a new section header to hold the correct counts.  */
  for (current = abfd->sections; current != NULL; current = current->next)
    if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
      sofar += bfd_coff_scnhsz (abfd);
#endif

#ifdef COFF_IMAGE_WITH_PE
  {
    /* PE requires the sections to be in memory order when listed in
       the section headers.  It also does not like empty loadable
       sections.  The sections apparently do not have to be in the
       right order in the image file itself, but we do need to get the
       target_index values right.  */

    unsigned int count;
    asection **section_list;
    unsigned int i;
    int target_index;
    bfd_size_type amt;

    count = 0;
    for (current = abfd->sections; current != NULL; current = current->next)
      ++count;

    /* We allocate an extra cell to simplify the final loop.  */
    amt = sizeof (struct asection *) * (count + 1);
    section_list = bfd_malloc (amt);
    if (section_list == NULL)
      return FALSE;

    i = 0;
    for (current = abfd->sections; current != NULL; current = current->next)
      {
       section_list[i] = current;
       ++i;
      }
    section_list[i] = NULL;

    qsort (section_list, count, sizeof (asection *), sort_by_secaddr);

    /* Rethread the linked list into sorted order; at the same time,
       assign target_index values.  */
    target_index = 1;
    abfd->sections = NULL;
    abfd->section_last = NULL;
    for (i = 0; i < count; i++)
      {
       current = section_list[i];
       bfd_section_list_append (abfd, current);

       /* Later, if the section has zero size, we'll be throwing it
          away, so we don't want to number it now.  Note that having
          a zero size and having real contents are different
          concepts: .bss has no contents, but (usually) non-zero
          size.  */
       if (current->size == 0)
         {
           /* Discard.  However, it still might have (valid) symbols
              in it, so arbitrarily set it to section 1 (indexing is
              1-based here; usually .text).  __end__ and other
              contents of .endsection really have this happen.
              FIXME: This seems somewhat dubious.  */
           current->target_index = 1;
         }
       else
         current->target_index = target_index++;
      }

    free (section_list);
  }
#else /* ! COFF_IMAGE_WITH_PE */
  {
    /* Set the target_index field.  */
    int target_index;

    target_index = 1;
    for (current = abfd->sections; current != NULL; current = current->next)
      current->target_index = target_index++;
  }
#endif /* ! COFF_IMAGE_WITH_PE */

  align_adjust = FALSE;
  for (current = abfd->sections;
       current != NULL;
       current = current->next)
    {
#ifdef COFF_IMAGE_WITH_PE
      /* With PE we have to pad each section to be a multiple of its
        page size too, and remember both sizes.  */
      if (coff_section_data (abfd, current) == NULL)
       {
         bfd_size_type amt = sizeof (struct coff_section_tdata);

         current->used_by_bfd = bfd_zalloc (abfd, amt);
         if (current->used_by_bfd == NULL)
           return FALSE;
       }
      if (pei_section_data (abfd, current) == NULL)
       {
         bfd_size_type amt = sizeof (struct pei_section_tdata);

         coff_section_data (abfd, current)->tdata = bfd_zalloc (abfd, amt);
         if (coff_section_data (abfd, current)->tdata == NULL)
           return FALSE;
       }
      if (pei_section_data (abfd, current)->virt_size == 0)
       pei_section_data (abfd, current)->virt_size = current->size;
#endif

      /* Only deal with sections which have contents.  */
      if (!(current->flags & SEC_HAS_CONTENTS))
       continue;

#ifdef COFF_IMAGE_WITH_PE
      /* Make sure we skip empty sections in a PE image.  */
      if (current->size == 0)
       continue;
#endif

      /* Align the sections in the file to the same boundary on
        which they are aligned in virtual memory.  I960 doesn't
        do this (FIXME) so we can stay in sync with Intel.  960
        doesn't yet page from files...  */
#ifdef ALIGN_SECTIONS_IN_FILE
      if ((abfd->flags & EXEC_P) != 0)
       {
         /* Make sure this section is aligned on the right boundary - by
            padding the previous section up if necessary.  */
         old_sofar = sofar;

#ifdef RS6000COFF_C
         /* AIX loader checks the text section alignment of (vma - filepos)
            So even though the filepos may be aligned wrt the o_algntext, for
            AIX executables, this check fails. This shows up when a native
            AIX executable is stripped with gnu strip because the default vma
            of native is 0x10000150 but default for gnu is 0x10000140.  Gnu
            stripped gnu excutable passes this check because the filepos is
            0x0140.  This problem also show up with 64 bit shared objects. The
            data section must also be aligned.  */
         if (!strcmp (current->name, _TEXT)
             || !strcmp (current->name, _DATA))
           {
             bfd_vma pad;
             bfd_vma align;

             sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);

             align = 1 << current->alignment_power;
             pad = abs (current->vma - sofar) % align;

             if (pad)
              {
                pad = align - pad;
                sofar += pad;
              }
           }
         else
#else
           {
             sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
           }
#endif
         if (previous != NULL)
           previous->size += sofar - old_sofar;
       }

#endif

      /* In demand paged files the low order bits of the file offset
        must match the low order bits of the virtual address.  */
#ifdef COFF_PAGE_SIZE
      if ((abfd->flags & D_PAGED) != 0
         && (current->flags & SEC_ALLOC) != 0)
       sofar += (current->vma - (bfd_vma) sofar) % page_size;
#endif
      current->filepos = sofar;

#ifdef COFF_IMAGE_WITH_PE
      /* Set the padded size.  */
      current->size = (current->size + page_size -1) & -page_size;
#endif

      sofar += current->size;

#ifdef ALIGN_SECTIONS_IN_FILE
      /* Make sure that this section is of the right size too.  */
      if ((abfd->flags & EXEC_P) == 0)
       {
         bfd_size_type old_size;

         old_size = current->size;
         current->size = BFD_ALIGN (current->size,
                                 1 << current->alignment_power);
         align_adjust = current->size != old_size;
         sofar += current->size - old_size;
       }
      else
       {
         old_sofar = sofar;
         sofar = BFD_ALIGN (sofar, 1 << current->alignment_power);
         align_adjust = sofar != old_sofar;
         current->size += sofar - old_sofar;
       }
#endif

#ifdef COFF_IMAGE_WITH_PE
      /* For PE we need to make sure we pad out to the aligned
         size, in case the caller only writes out data to the
         unaligned size.  */
      if (pei_section_data (abfd, current)->virt_size < current->size)
       align_adjust = TRUE;
#endif

#ifdef _LIB
      /* Force .lib sections to start at zero.  The vma is then
        incremented in coff_set_section_contents.  This is right for
        SVR3.2.  */
      if (strcmp (current->name, _LIB) == 0)
       bfd_set_section_vma (abfd, current, 0);
#endif

      previous = current;
    }

  /* It is now safe to write to the output file.  If we needed an
     alignment adjustment for the last section, then make sure that
     there is a byte at offset sofar.  If there are no symbols and no
     relocs, then nothing follows the last section.  If we don't force
     the last byte out, then the file may appear to be truncated.  */
  if (align_adjust)
    {
      bfd_byte b;

      b = 0;
      if (bfd_seek (abfd, sofar - 1, SEEK_SET) != 0
         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
       return FALSE;
    }

  /* Make sure the relocations are aligned.  We don't need to make
     sure that this byte exists, because it will only matter if there
     really are relocs.  */
  sofar = BFD_ALIGN (sofar, 1 << COFF_DEFAULT_SECTION_ALIGNMENT_POWER);

  obj_relocbase (abfd) = sofar;
  abfd->output_has_begun = TRUE;

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean coff_final_link_postscript ( bfd *abfd  ATTRIBUTE_UNUSED,
struct coff_final_link_info *pfinfo  ATTRIBUTE_UNUSED 
) [static]

Definition at line 5097 of file coffcode.h.

{
  return TRUE;
}
static bfd_boolean coff_link_output_has_begun ( bfd abfd,
struct coff_final_link_info *info  ATTRIBUTE_UNUSED 
) [static]

Definition at line 5087 of file coffcode.h.

{
  return abfd->output_has_begun;
}
static bfd_boolean coff_mkobject ( bfd abfd) [static]

Definition at line 1752 of file coffcode.h.

{
  coff_data_type *coff;
  bfd_size_type amt = sizeof (coff_data_type);

  abfd->tdata.coff_obj_data = bfd_zalloc (abfd, amt);
  if (abfd->tdata.coff_obj_data == NULL)
    return FALSE;
  coff = coff_data (abfd);
  coff->symbols = NULL;
  coff->conversion_table = NULL;
  coff->raw_syments = NULL;
  coff->relocbase = 0;
  coff->local_toc_sym_map = 0;

/*  make_abs_section(abfd);*/

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void* coff_mkobject_hook ( bfd ,
void *  ,
void *   
) [static]
static void* coff_mkobject_hook ( bfd abfd,
void *  filehdr,
void *aouthdr  ATTRIBUTE_UNUSED 
) [static]

Definition at line 1777 of file coffcode.h.

{
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
  coff_data_type *coff;

  if (! coff_mkobject (abfd))
    return NULL;

  coff = coff_data (abfd);

  coff->sym_filepos = internal_f->f_symptr;

  /* These members communicate important constants about the symbol
     table to GDB's symbol-reading code.  These `constants'
     unfortunately vary among coff implementations...  */
  coff->local_n_btmask = N_BTMASK;
  coff->local_n_btshft = N_BTSHFT;
  coff->local_n_tmask = N_TMASK;
  coff->local_n_tshift = N_TSHIFT;
  coff->local_symesz = bfd_coff_symesz (abfd);
  coff->local_auxesz = bfd_coff_auxesz (abfd);
  coff->local_linesz = bfd_coff_linesz (abfd);

  coff->timestamp = internal_f->f_timdat;

  obj_raw_syment_count (abfd) =
    obj_conv_table_size (abfd) =
      internal_f->f_nsyms;

#ifdef RS6000COFF_C
  if ((internal_f->f_flags & F_SHROBJ) != 0)
    abfd->flags |= DYNAMIC;
  if (aouthdr != NULL && internal_f->f_opthdr >= bfd_coff_aoutsz (abfd))
    {
      struct internal_aouthdr *internal_a =
       (struct internal_aouthdr *) aouthdr;
      struct xcoff_tdata *xcoff;

      xcoff = xcoff_data (abfd);
# ifdef U803XTOCMAGIC
      xcoff->xcoff64 = internal_f->f_magic == U803XTOCMAGIC;
# else
      xcoff->xcoff64 = 0;
# endif
      xcoff->full_aouthdr = TRUE;
      xcoff->toc = internal_a->o_toc;
      xcoff->sntoc = internal_a->o_sntoc;
      xcoff->snentry = internal_a->o_snentry;
      bfd_xcoff_text_align_power (abfd) = internal_a->o_algntext;
      bfd_xcoff_data_align_power (abfd) = internal_a->o_algndata;
      xcoff->modtype = internal_a->o_modtype;
      xcoff->cputype = internal_a->o_cputype;
      xcoff->maxdata = internal_a->o_maxdata;
      xcoff->maxstack = internal_a->o_maxstack;
    }
#endif

#ifdef ARM
  /* Set the flags field from the COFF header read in.  */
  if (! _bfd_coff_arm_set_private_flags (abfd, internal_f->f_flags))
    coff->flags = 0;
#endif

#ifdef COFF_WITH_PE
  /* FIXME: I'm not sure this is ever executed, since peicode.h
     defines coff_mkobject_hook.  */
  if ((internal_f->f_flags & IMAGE_FILE_DEBUG_STRIPPED) == 0)
    abfd->flags |= HAS_DEBUG;
#endif

  return coff;
}

Here is the call graph for this function:

static bfd_boolean coff_new_section_hook ( bfd abfd,
asection section 
) [static]

Definition at line 1547 of file coffcode.h.

{
  combined_entry_type *native;
  bfd_size_type amt;

  section->alignment_power = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;

#ifdef RS6000COFF_C
  if (bfd_xcoff_text_align_power (abfd) != 0
      && strcmp (bfd_get_section_name (abfd, section), ".text") == 0)
    section->alignment_power = bfd_xcoff_text_align_power (abfd);
  if (bfd_xcoff_data_align_power (abfd) != 0
      && strcmp (bfd_get_section_name (abfd, section), ".data") == 0)
    section->alignment_power = bfd_xcoff_data_align_power (abfd);
#endif

  /* Set up the section symbol.  */
  if (!_bfd_generic_new_section_hook (abfd, section))
    return FALSE;

  /* Allocate aux records for section symbols, to store size and
     related info.

     @@ The 10 is a guess at a plausible maximum number of aux entries
     (but shouldn't be a constant).  */
  amt = sizeof (combined_entry_type) * 10;
  native = bfd_zalloc (abfd, amt);
  if (native == NULL)
    return FALSE;

  /* We don't need to set up n_name, n_value, or n_scnum in the native
     symbol information, since they'll be overridden by the BFD symbol
     anyhow.  However, we do need to set the type and storage class,
     in case this symbol winds up getting written out.  The value 0
     for n_numaux is already correct.  */

  native->u.syment.n_type = T_NULL;
  native->u.syment.n_sclass = C_STAT;

  coffsymbol (section->symbol)->native = native;

  coff_set_custom_section_alignment (abfd, section,
                                 coff_section_alignment_table,
                                 coff_section_alignment_table_size);

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean coff_print_aux ( bfd *abfd  ATTRIBUTE_UNUSED,
FILE *file  ATTRIBUTE_UNUSED,
combined_entry_type *table_base  ATTRIBUTE_UNUSED,
combined_entry_type *symbol  ATTRIBUTE_UNUSED,
combined_entry_type *aux  ATTRIBUTE_UNUSED,
unsigned int indaux  ATTRIBUTE_UNUSED 
) [static]

Definition at line 2347 of file coffcode.h.

{
#ifdef RS6000COFF_C
  if ((symbol->u.syment.n_sclass == C_EXT
       || symbol->u.syment.n_sclass == C_HIDEXT)
      && indaux + 1 == symbol->u.syment.n_numaux)
    {
      /* This is a csect entry.  */
      fprintf (file, "AUX ");
      if (SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp) != XTY_LD)
       {
         BFD_ASSERT (! aux->fix_scnlen);
#ifdef XCOFF64
         fprintf (file, "val %5lld",
                 (long long) aux->u.auxent.x_csect.x_scnlen.l);
#else
         fprintf (file, "val %5ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
#endif
       }
      else
       {
         fprintf (file, "indx ");
         if (! aux->fix_scnlen)
#ifdef XCOFF64
           fprintf (file, "%4lld",
                   (long long) aux->u.auxent.x_csect.x_scnlen.l);
#else
           fprintf (file, "%4ld", (long) aux->u.auxent.x_csect.x_scnlen.l);
#endif
         else
           fprintf (file, "%4ld",
                   (long) (aux->u.auxent.x_csect.x_scnlen.p - table_base));
       }
      fprintf (file,
              " prmhsh %ld snhsh %u typ %d algn %d clss %u stb %ld snstb %u",
              aux->u.auxent.x_csect.x_parmhash,
              (unsigned int) aux->u.auxent.x_csect.x_snhash,
              SMTYP_SMTYP (aux->u.auxent.x_csect.x_smtyp),
              SMTYP_ALIGN (aux->u.auxent.x_csect.x_smtyp),
              (unsigned int) aux->u.auxent.x_csect.x_smclas,
              aux->u.auxent.x_csect.x_stab,
              (unsigned int) aux->u.auxent.x_csect.x_snstab);
      return TRUE;
    }
#endif

  /* Return FALSE to indicate that no special action was taken.  */
  return FALSE;
}

Here is the call graph for this function:

static bfd_boolean coff_set_arch_mach ( bfd abfd,
enum bfd_architecture  arch,
unsigned long  machine 
) [static]

Definition at line 2890 of file coffcode.h.

{
  unsigned dummy1;
  unsigned short dummy2;

  if (! bfd_default_set_arch_mach (abfd, arch, machine))
    return FALSE;

  if (arch != bfd_arch_unknown
      && ! coff_set_flags (abfd, &dummy1, &dummy2))
    return FALSE;           /* We can't represent this type.  */

  return TRUE;                     /* We're easy...  */
}

Here is the call graph for this function:

static bfd_boolean coff_set_arch_mach_hook ( bfd abfd,
void *  filehdr 
) [static]

Definition at line 1861 of file coffcode.h.

{
  unsigned long machine;
  enum bfd_architecture arch;
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;

  /* Zero selects the default machine for an arch.  */
  machine = 0;
  switch (internal_f->f_magic)
    {
#ifdef OR32_MAGIC_BIG
    case OR32_MAGIC_BIG:
    case OR32_MAGIC_LITTLE:
      arch = bfd_arch_or32;
      break;
#endif
#ifdef PPCMAGIC
    case PPCMAGIC:
      arch = bfd_arch_powerpc;
      break;
#endif
#ifdef I386MAGIC
    case I386MAGIC:
    case I386PTXMAGIC:
    case I386AIXMAGIC:             /* Danbury PS/2 AIX C Compiler.  */
    case LYNXCOFFMAGIC:            /* Shadows the m68k Lynx number below, sigh.  */
      arch = bfd_arch_i386;
      break;
#endif
#ifdef AMD64MAGIC
    case AMD64MAGIC:
      arch = bfd_arch_i386;
      machine = bfd_mach_x86_64;
      break;
#endif
#ifdef IA64MAGIC
    case IA64MAGIC:
      arch = bfd_arch_ia64;
      break;
#endif
#ifdef ARMMAGIC
    case ARMMAGIC:
    case ARMPEMAGIC:
    case THUMBPEMAGIC:
      arch = bfd_arch_arm;
      machine = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
      if (machine == bfd_mach_arm_unknown)
       {
         switch (internal_f->f_flags & F_ARM_ARCHITECTURE_MASK)
           {
           case F_ARM_2:  machine = bfd_mach_arm_2;  break;
           case F_ARM_2a: machine = bfd_mach_arm_2a; break;
           case F_ARM_3:  machine = bfd_mach_arm_3;  break;
           default:
           case F_ARM_3M: machine = bfd_mach_arm_3M; break;
           case F_ARM_4:  machine = bfd_mach_arm_4;  break;
           case F_ARM_4T: machine = bfd_mach_arm_4T; break;
             /* The COFF header does not have enough bits available
               to cover all the different ARM architectures.  So
               we interpret F_ARM_5, the highest flag value to mean
               "the highest ARM architecture known to BFD" which is
               currently the XScale.  */
           case F_ARM_5:  machine = bfd_mach_arm_XScale;  break;
           }
       }
      break;
#endif
#ifdef MC68MAGIC
    case MC68MAGIC:
    case M68MAGIC:
#ifdef MC68KBCSMAGIC
    case MC68KBCSMAGIC:
#endif
#ifdef APOLLOM68KMAGIC
    case APOLLOM68KMAGIC:
#endif
#ifdef LYNXCOFFMAGIC
    case LYNXCOFFMAGIC:
#endif
      arch = bfd_arch_m68k;
      machine = bfd_mach_m68020;
      break;
#endif
#ifdef MAXQ20MAGIC
    case MAXQ20MAGIC:
      arch = bfd_arch_maxq;
      switch (internal_f->f_flags & F_MACHMASK)
       { 
        case F_MAXQ10:
          machine = bfd_mach_maxq10;
          break;
        case F_MAXQ20:
          machine = bfd_mach_maxq20;
          break;
        default:
          return FALSE;
       }
      break;
#endif
#ifdef MC88MAGIC
    case MC88MAGIC:
    case MC88DMAGIC:
    case MC88OMAGIC:
      arch = bfd_arch_m88k;
      machine = 88100;
      break;
#endif
#ifdef Z80MAGIC
    case Z80MAGIC:
      arch = bfd_arch_z80;
      switch (internal_f->f_flags & F_MACHMASK)
       {
       case 0:
       case bfd_mach_z80strict << 12:
       case bfd_mach_z80 << 12:
       case bfd_mach_z80full << 12:
       case bfd_mach_r800 << 12:
         machine = ((unsigned)internal_f->f_flags & F_MACHMASK) >> 12;
         break;
       default:
         return FALSE;
       }
      break;
#endif
#ifdef Z8KMAGIC
    case Z8KMAGIC:
      arch = bfd_arch_z8k;
      switch (internal_f->f_flags & F_MACHMASK)
       {
       case F_Z8001:
         machine = bfd_mach_z8001;
         break;
       case F_Z8002:
         machine = bfd_mach_z8002;
         break;
       default:
         return FALSE;
       }
      break;
#endif
#ifdef I860
    case I860MAGIC:
      arch = bfd_arch_i860;
      break;
#endif
#ifdef I960
#ifdef I960ROMAGIC
    case I960ROMAGIC:
    case I960RWMAGIC:
      arch = bfd_arch_i960;
      switch (F_I960TYPE & internal_f->f_flags)
       {
       default:
       case F_I960CORE:
         machine = bfd_mach_i960_core;
         break;
       case F_I960KB:
         machine = bfd_mach_i960_kb_sb;
         break;
       case F_I960MC:
         machine = bfd_mach_i960_mc;
         break;
       case F_I960XA:
         machine = bfd_mach_i960_xa;
         break;
       case F_I960CA:
         machine = bfd_mach_i960_ca;
         break;
       case F_I960KA:
         machine = bfd_mach_i960_ka_sa;
         break;
       case F_I960JX:
         machine = bfd_mach_i960_jx;
         break;
       case F_I960HX:
         machine = bfd_mach_i960_hx;
         break;
       }
      break;
#endif
#endif

#ifdef RS6000COFF_C
#ifdef XCOFF64
    case U64_TOCMAGIC:
    case U803XTOCMAGIC:
#else
    case U802ROMAGIC:
    case U802WRMAGIC:
    case U802TOCMAGIC:
#endif
      {
       int cputype;

       if (xcoff_data (abfd)->cputype != -1)
         cputype = xcoff_data (abfd)->cputype & 0xff;
       else
         {
           /* We did not get a value from the a.out header.  If the
              file has not been stripped, we may be able to get the
              architecture information from the first symbol, if it
              is a .file symbol.  */
           if (obj_raw_syment_count (abfd) == 0)
             cputype = 0;
           else
             {
              bfd_byte *buf;
              struct internal_syment sym;
              bfd_size_type amt = bfd_coff_symesz (abfd);

              buf = bfd_malloc (amt);
              if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
                  || bfd_bread (buf, amt, abfd) != amt)
                {
                  free (buf);
                  return FALSE;
                }
              bfd_coff_swap_sym_in (abfd, buf, & sym);
              if (sym.n_sclass == C_FILE)
                cputype = sym.n_type & 0xff;
              else
                cputype = 0;
              free (buf);
             }
         }

       /* FIXME: We don't handle all cases here.  */
       switch (cputype)
         {
         default:
         case 0:
           arch = bfd_xcoff_architecture (abfd);
           machine = bfd_xcoff_machine (abfd);
           break;

         case 1:
           arch = bfd_arch_powerpc;
           machine = bfd_mach_ppc_601;
           break;
         case 2: /* 64 bit PowerPC */
           arch = bfd_arch_powerpc;
           machine = bfd_mach_ppc_620;
           break;
         case 3:
           arch = bfd_arch_powerpc;
           machine = bfd_mach_ppc;
           break;
         case 4:
           arch = bfd_arch_rs6000;
           machine = bfd_mach_rs6k;
           break;
         }
      }
      break;
#endif

#ifdef WE32KMAGIC
    case WE32KMAGIC:
      arch = bfd_arch_we32k;
      break;
#endif

#ifdef H8300MAGIC
    case H8300MAGIC:
      arch = bfd_arch_h8300;
      machine = bfd_mach_h8300;
      /* !! FIXME this probably isn't the right place for this.  */
      abfd->flags |= BFD_IS_RELAXABLE;
      break;
#endif

#ifdef H8300HMAGIC
    case H8300HMAGIC:
      arch = bfd_arch_h8300;
      machine = bfd_mach_h8300h;
      /* !! FIXME this probably isn't the right place for this.  */
      abfd->flags |= BFD_IS_RELAXABLE;
      break;
#endif

#ifdef H8300SMAGIC
    case H8300SMAGIC:
      arch = bfd_arch_h8300;
      machine = bfd_mach_h8300s;
      /* !! FIXME this probably isn't the right place for this.  */
      abfd->flags |= BFD_IS_RELAXABLE;
      break;
#endif

#ifdef H8300HNMAGIC
    case H8300HNMAGIC:
      arch = bfd_arch_h8300;
      machine = bfd_mach_h8300hn;
      /* !! FIXME this probably isn't the right place for this.  */
      abfd->flags |= BFD_IS_RELAXABLE;
      break;
#endif

#ifdef H8300SNMAGIC
    case H8300SNMAGIC:
      arch = bfd_arch_h8300;
      machine = bfd_mach_h8300sn;
      /* !! FIXME this probably isn't the right place for this.  */
      abfd->flags |= BFD_IS_RELAXABLE;
      break;
#endif

#ifdef SH_ARCH_MAGIC_BIG
    case SH_ARCH_MAGIC_BIG:
    case SH_ARCH_MAGIC_LITTLE:
#ifdef COFF_WITH_PE
    case SH_ARCH_MAGIC_WINCE:
#endif
      arch = bfd_arch_sh;
      break;
#endif

#ifdef MIPS_ARCH_MAGIC_WINCE
    case MIPS_ARCH_MAGIC_WINCE:
      arch = bfd_arch_mips;
      break;
#endif

#ifdef H8500MAGIC
    case H8500MAGIC:
      arch = bfd_arch_h8500;
      break;
#endif

#ifdef SPARCMAGIC
    case SPARCMAGIC:
#ifdef LYNXCOFFMAGIC
    case LYNXCOFFMAGIC:
#endif
      arch = bfd_arch_sparc;
      break;
#endif

#ifdef TIC30MAGIC
    case TIC30MAGIC:
      arch = bfd_arch_tic30;
      break;
#endif

#ifdef TICOFF0MAGIC
#ifdef TICOFF_TARGET_ARCH
      /* This TI COFF section should be used by all new TI COFF v0 targets.  */
    case TICOFF0MAGIC:
      arch = TICOFF_TARGET_ARCH;
      machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
      break;
#endif
#endif

#ifdef TICOFF1MAGIC
      /* This TI COFF section should be used by all new TI COFF v1/2 targets.  */
      /* TI COFF1 and COFF2 use the target_id field to specify which arch.  */
    case TICOFF1MAGIC:
    case TICOFF2MAGIC:
      switch (internal_f->f_target_id)
        {
#ifdef TI_TARGET_ID
        case TI_TARGET_ID:
          arch = TICOFF_TARGET_ARCH;
         machine = TICOFF_TARGET_MACHINE_GET (internal_f->f_flags);
          break;
#endif
        default:
          arch = bfd_arch_obscure;
          (*_bfd_error_handler)
            (_("Unrecognized TI COFF target id '0x%x'"),
             internal_f->f_target_id);
          break;
        }
      break;
#endif

#ifdef TIC80_ARCH_MAGIC
    case TIC80_ARCH_MAGIC:
      arch = bfd_arch_tic80;
      break;
#endif

#ifdef MCOREMAGIC
    case MCOREMAGIC:
      arch = bfd_arch_mcore;
      break;
#endif

#ifdef W65MAGIC
    case W65MAGIC:
      arch = bfd_arch_w65;
      break;
#endif

    default:                /* Unreadable input file type.  */
      arch = bfd_arch_obscure;
      break;
    }

  bfd_default_set_arch_mach (abfd, arch, machine);
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void coff_set_custom_section_alignment ( bfd *abfd  ATTRIBUTE_UNUSED,
asection section,
const struct coff_section_alignment_entry alignment_table,
const unsigned int  table_size 
) [static]

Definition at line 1484 of file coffcode.h.

{
  const unsigned int default_alignment = COFF_DEFAULT_SECTION_ALIGNMENT_POWER;
  unsigned int i;

  for (i = 0; i < table_size; ++i)
    {
      const char *secname = bfd_get_section_name (abfd, section);

      if (alignment_table[i].comparison_length == (unsigned int) -1
         ? strcmp (alignment_table[i].name, secname) == 0
         : strncmp (alignment_table[i].name, secname,
                   alignment_table[i].comparison_length) == 0)
       break;
    }
  if (i >= table_size)
    return;

  if (alignment_table[i].default_alignment_min != COFF_ALIGNMENT_FIELD_EMPTY
      && default_alignment < alignment_table[i].default_alignment_min)
    return;

  if (alignment_table[i].default_alignment_max != COFF_ALIGNMENT_FIELD_EMPTY
#if COFF_DEFAULT_SECTION_ALIGNMENT_POWER != 0
      && default_alignment > alignment_table[i].default_alignment_max
#endif
      )
    return;

  section->alignment_power = alignment_table[i].alignment_power;
}

Here is the call graph for this function:

static bfd_boolean coff_set_flags ( bfd ,
unsigned int ,
unsigned short *   
) [static]

Here is the caller graph for this function:

static bfd_boolean coff_set_flags ( bfd abfd,
unsigned int *magicp  ATTRIBUTE_UNUSED,
unsigned short *flagsp  ATTRIBUTE_UNUSED 
) [static]

Definition at line 2583 of file coffcode.h.

{
  switch (bfd_get_arch (abfd))
    {
#ifdef Z80MAGIC
    case bfd_arch_z80:
      *magicp = Z80MAGIC;
      switch (bfd_get_mach (abfd))
       {
       case 0:
       case bfd_mach_z80strict:
       case bfd_mach_z80:
       case bfd_mach_z80full:
       case bfd_mach_r800:
         *flagsp = bfd_get_mach (abfd) << 12;
         break;
       default:
         return FALSE;
       }
      return TRUE;
#endif

#ifdef Z8KMAGIC
    case bfd_arch_z8k:
      *magicp = Z8KMAGIC;

      switch (bfd_get_mach (abfd))
       {
       case bfd_mach_z8001: *flagsp = F_Z8001;   break;
       case bfd_mach_z8002: *flagsp = F_Z8002;   break;
       default:           return FALSE;
       }
      return TRUE;
#endif

#ifdef I960ROMAGIC
    case bfd_arch_i960:

      {
       unsigned flags;

       *magicp = I960ROMAGIC;

       switch (bfd_get_mach (abfd))
         {
         case bfd_mach_i960_core:  flags = F_I960CORE; break;
         case bfd_mach_i960_kb_sb: flags = F_I960KB;    break;
         case bfd_mach_i960_mc:    flags = F_I960MC;    break;
         case bfd_mach_i960_xa:    flags = F_I960XA;    break;
         case bfd_mach_i960_ca:    flags = F_I960CA;    break;
         case bfd_mach_i960_ka_sa: flags = F_I960KA;    break;
         case bfd_mach_i960_jx:    flags = F_I960JX;    break;
         case bfd_mach_i960_hx:    flags = F_I960HX;    break;
         default:                return FALSE;
         }
       *flagsp = flags;
       return TRUE;
      }
      break;
#endif

#ifdef TIC30MAGIC
    case bfd_arch_tic30:
      *magicp = TIC30MAGIC;
      return TRUE;
#endif

#ifdef TICOFF_DEFAULT_MAGIC
    case TICOFF_TARGET_ARCH:
      /* If there's no indication of which version we want, use the default.  */
      if (!abfd->xvec )
        *magicp = TICOFF_DEFAULT_MAGIC;
      else
        {
          /* We may want to output in a different COFF version.  */
          switch (abfd->xvec->name[4])
            {
            case '0':
              *magicp = TICOFF0MAGIC;
              break;
            case '1':
              *magicp = TICOFF1MAGIC;
              break;
            case '2':
              *magicp = TICOFF2MAGIC;
              break;
            default:
              return FALSE;
            }
        }
      TICOFF_TARGET_MACHINE_SET (flagsp, bfd_get_mach (abfd));
      return TRUE;
#endif

#ifdef TIC80_ARCH_MAGIC
    case bfd_arch_tic80:
      *magicp = TIC80_ARCH_MAGIC;
      return TRUE;
#endif

#ifdef ARMMAGIC
    case bfd_arch_arm:
#ifdef ARM_WINCE
      * magicp = ARMPEMAGIC;
#else
      * magicp = ARMMAGIC;
#endif
      * flagsp = 0;
      if (APCS_SET (abfd))
       {
         if (APCS_26_FLAG (abfd))
           * flagsp |= F_APCS26;

         if (APCS_FLOAT_FLAG (abfd))
           * flagsp |= F_APCS_FLOAT;

         if (PIC_FLAG (abfd))
           * flagsp |= F_PIC;
       }
      if (INTERWORK_SET (abfd) && INTERWORK_FLAG (abfd))
       * flagsp |= F_INTERWORK;
      switch (bfd_get_mach (abfd))
       {
       case bfd_mach_arm_2:  * flagsp |= F_ARM_2;  break;
       case bfd_mach_arm_2a: * flagsp |= F_ARM_2a; break;
       case bfd_mach_arm_3:  * flagsp |= F_ARM_3;  break;
       case bfd_mach_arm_3M: * flagsp |= F_ARM_3M; break;
       case bfd_mach_arm_4:  * flagsp |= F_ARM_4;  break;
       case bfd_mach_arm_4T: * flagsp |= F_ARM_4T; break;
       case bfd_mach_arm_5:  * flagsp |= F_ARM_5;  break;
         /* FIXME: we do not have F_ARM vaues greater than F_ARM_5.
            See also the comment in coff_set_arch_mach_hook().  */
       case bfd_mach_arm_5T: * flagsp |= F_ARM_5;  break;
       case bfd_mach_arm_5TE: * flagsp |= F_ARM_5; break;
       case bfd_mach_arm_XScale: * flagsp |= F_ARM_5; break;
       }
      return TRUE;
#endif

#ifdef PPCMAGIC
    case bfd_arch_powerpc:
      *magicp = PPCMAGIC;
      return TRUE;
#endif

#if defined(I386MAGIC) || defined(AMD64MAGIC)
    case bfd_arch_i386:
#if defined(I386MAGIC)
      *magicp = I386MAGIC;
#endif
#if defined LYNXOS
      /* Just overwrite the usual value if we're doing Lynx.  */
      *magicp = LYNXCOFFMAGIC;
#endif
#if defined AMD64MAGIC
      *magicp = AMD64MAGIC;
#endif
      return TRUE;
#endif

#ifdef I860MAGIC
    case bfd_arch_i860:
      *magicp = I860MAGIC;
      return TRUE;
#endif

#ifdef IA64MAGIC
    case bfd_arch_ia64:
      *magicp = IA64MAGIC;
      return TRUE;
#endif

#ifdef MC68MAGIC
    case bfd_arch_m68k:
#ifdef APOLLOM68KMAGIC
      *magicp = APOLLO_COFF_VERSION_NUMBER;
#else
      /* NAMES_HAVE_UNDERSCORE may be defined by coff-u68k.c.  */
#ifdef NAMES_HAVE_UNDERSCORE
      *magicp = MC68KBCSMAGIC;
#else
      *magicp = MC68MAGIC;
#endif
#endif
#ifdef LYNXOS
      /* Just overwrite the usual value if we're doing Lynx.  */
      *magicp = LYNXCOFFMAGIC;
#endif
      return TRUE;
#endif

#ifdef MC88MAGIC
    case bfd_arch_m88k:
      *magicp = MC88OMAGIC;
      return TRUE;
#endif

#ifdef H8300MAGIC
    case bfd_arch_h8300:
      switch (bfd_get_mach (abfd))
       {
       case bfd_mach_h8300:   *magicp = H8300MAGIC;   return TRUE;
       case bfd_mach_h8300h:  *magicp = H8300HMAGIC;  return TRUE;
       case bfd_mach_h8300s:  *magicp = H8300SMAGIC;  return TRUE;
       case bfd_mach_h8300hn: *magicp = H8300HNMAGIC; return TRUE;
       case bfd_mach_h8300sn: *magicp = H8300SNMAGIC; return TRUE;
       default: break;
       }
      break;
#endif

#ifdef SH_ARCH_MAGIC_BIG
    case bfd_arch_sh:
#ifdef COFF_IMAGE_WITH_PE
      *magicp = SH_ARCH_MAGIC_WINCE;
#else
      if (bfd_big_endian (abfd))
       *magicp = SH_ARCH_MAGIC_BIG;
      else
       *magicp = SH_ARCH_MAGIC_LITTLE;
#endif
      return TRUE;
#endif

#ifdef MIPS_ARCH_MAGIC_WINCE
    case bfd_arch_mips:
      *magicp = MIPS_ARCH_MAGIC_WINCE;
      return TRUE;
#endif

#ifdef SPARCMAGIC
    case bfd_arch_sparc:
      *magicp = SPARCMAGIC;
#ifdef LYNXOS
      /* Just overwrite the usual value if we're doing Lynx.  */
      *magicp = LYNXCOFFMAGIC;
#endif
      return TRUE;
#endif

#ifdef H8500MAGIC
    case bfd_arch_h8500:
      *magicp = H8500MAGIC;
      return TRUE;
      break;
#endif

#ifdef WE32KMAGIC
    case bfd_arch_we32k:
      *magicp = WE32KMAGIC;
      return TRUE;
#endif

#ifdef RS6000COFF_C
    case bfd_arch_rs6000:
#ifndef PPCMAGIC
    case bfd_arch_powerpc:
#endif
      BFD_ASSERT (bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
      *magicp = bfd_xcoff_magic_number (abfd);
      return TRUE;
#endif

#ifdef MCOREMAGIC
    case bfd_arch_mcore:
      * magicp = MCOREMAGIC;
      return TRUE;
#endif

#ifdef W65MAGIC
    case bfd_arch_w65:
      *magicp = W65MAGIC;
      return TRUE;
#endif

#ifdef OR32_MAGIC_BIG
    case bfd_arch_or32:
      if (bfd_big_endian (abfd))
        * magicp = OR32_MAGIC_BIG;
      else
        * magicp = OR32_MAGIC_LITTLE;
      return TRUE;
#endif

#ifdef MAXQ20MAGIC
    case bfd_arch_maxq:
      * magicp = MAXQ20MAGIC;
      switch (bfd_get_mach (abfd))
       {
       case bfd_mach_maxq10: * flagsp = F_MAXQ10; return TRUE;
       case bfd_mach_maxq20: * flagsp = F_MAXQ20; return TRUE;
       default:            return FALSE;
       }
#endif

    default:                /* Unknown architecture.  */
      /* Fall through to "return FALSE" below, to avoid
        "statement never reached" errors on the one below.  */
      break;
    }

  return FALSE;
}

Here is the call graph for this function:

static bfd_boolean coff_set_section_contents ( bfd ,
asection ,
const void *  ,
file_ptr  ,
bfd_size_type   
) [static]

Here is the caller graph for this function:

static bfd_boolean coff_set_section_contents ( bfd abfd,
sec_ptr  section,
const void *  location,
file_ptr  offset,
bfd_size_type  count 
) [static]

Definition at line 4156 of file coffcode.h.

{
  if (! abfd->output_has_begun)    /* Set by bfd.c handler.  */
    {
      if (! coff_compute_section_file_positions (abfd))
       return FALSE;
    }

#if defined(_LIB) && !defined(TARG_AUX)
   /* The physical address field of a .lib section is used to hold the
      number of shared libraries in the section.  This code counts the
      number of sections being written, and increments the lma field
      with the number.

      I have found no documentation on the contents of this section.
      Experimentation indicates that the section contains zero or more
      records, each of which has the following structure:

      - a (four byte) word holding the length of this record, in words,
      - a word that always seems to be set to "2",
      - the path to a shared library, null-terminated and then padded
        to a whole word boundary.

      bfd_assert calls have been added to alert if an attempt is made
      to write a section which doesn't follow these assumptions.  The
      code has been tested on ISC 4.1 by me, and on SCO by Robert Lipe
      <robertl@arnet.com> (Thanks!).

      Gvran Uddeborg <gvran@uddeborg.pp.se>.  */
    if (strcmp (section->name, _LIB) == 0)
      {
       bfd_byte *rec, *recend;

       rec = (bfd_byte *) location;
       recend = rec + count;
       while (rec < recend)
         {
           ++section->lma;
           rec += bfd_get_32 (abfd, rec) * 4;
         }

       BFD_ASSERT (rec == recend);
      }
#endif

  /* Don't write out bss sections - one way to do this is to
       see if the filepos has not been set.  */
  if (section->filepos == 0)
    return TRUE;

  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)
    return FALSE;

  if (count == 0)
    return TRUE;

  return bfd_bwrite (location, count, abfd) == count;
}

Here is the call graph for this function:

static bfd_boolean coff_slurp_line_table ( bfd abfd,
asection asect 
) [static]

Definition at line 4256 of file coffcode.h.

{
  LINENO *native_lineno;
  alent *lineno_cache;
  bfd_size_type amt;

  BFD_ASSERT (asect->lineno == NULL);

  amt = (bfd_size_type) bfd_coff_linesz (abfd) * asect->lineno_count;
  native_lineno = (LINENO *) buy_and_read (abfd, asect->line_filepos, amt);
  if (native_lineno == NULL)
    {
      (*_bfd_error_handler)
        (_("%B: warning: line number table read failed"), abfd);
      return FALSE;
    }
  amt = ((bfd_size_type) asect->lineno_count + 1) * sizeof (alent);
  lineno_cache = bfd_alloc (abfd, amt);
  if (lineno_cache == NULL)
    return FALSE;
  else
    {
      unsigned int counter = 0;
      alent *cache_ptr = lineno_cache;
      LINENO *src = native_lineno;

      while (counter < asect->lineno_count)
       {
         struct internal_lineno dst;

         bfd_coff_swap_lineno_in (abfd, src, &dst);
         cache_ptr->line_number = dst.l_lnno;

         if (cache_ptr->line_number == 0)
           {
             bfd_boolean warned;
             bfd_signed_vma symndx;
             coff_symbol_type *sym;

             warned = FALSE;
             symndx = dst.l_addr.l_symndx;
             if (symndx < 0
                || (bfd_vma) symndx >= obj_raw_syment_count (abfd))
              {
                (*_bfd_error_handler)
                  (_("%B: warning: illegal symbol index %ld in line numbers"),
                   abfd, dst.l_addr.l_symndx);
                symndx = 0;
                warned = TRUE;
              }
             /* FIXME: We should not be casting between ints and
                 pointers like this.  */
             sym = ((coff_symbol_type *)
                   ((symndx + obj_raw_syments (abfd))
                    ->u.syment._n._n_n._n_zeroes));
             cache_ptr->u.sym = (asymbol *) sym;
             if (sym->lineno != NULL && ! warned)
              {
                (*_bfd_error_handler)
                  (_("%B: warning: duplicate line number information for `%s'"),
                   abfd, bfd_asymbol_name (&sym->symbol));
              }
             sym->lineno = cache_ptr;
           }
         else
           cache_ptr->u.offset = dst.l_addr.l_paddr
             - bfd_section_vma (abfd, asect);

         cache_ptr++;
         src++;
         counter++;
       }
      cache_ptr->line_number = 0;

    }
  asect->lineno = lineno_cache;
  /* FIXME, free native_lineno here, or use alloca or something.  */
  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean coff_slurp_reloc_table ( bfd ,
asection ,
asymbol **   
) [static]

Here is the caller graph for this function:

static bfd_boolean coff_slurp_reloc_table ( bfd abfd,
sec_ptr  asect,
asymbol **  symbols 
) [static]

Definition at line 4837 of file coffcode.h.

{
  RELOC *native_relocs;
  arelent *reloc_cache;
  arelent *cache_ptr;
  unsigned int idx;
  bfd_size_type amt;

  if (asect->relocation)
    return TRUE;
  if (asect->reloc_count == 0)
    return TRUE;
  if (asect->flags & SEC_CONSTRUCTOR)
    return TRUE;
  if (!coff_slurp_symbol_table (abfd))
    return FALSE;

  amt = (bfd_size_type) bfd_coff_relsz (abfd) * asect->reloc_count;
  native_relocs = (RELOC *) buy_and_read (abfd, asect->rel_filepos, amt);
  amt = (bfd_size_type) asect->reloc_count * sizeof (arelent);
  reloc_cache = bfd_alloc (abfd, amt);

  if (reloc_cache == NULL || native_relocs == NULL)
    return FALSE;

  for (idx = 0; idx < asect->reloc_count; idx++)
    {
      struct internal_reloc dst;
      struct external_reloc *src;
#ifndef RELOC_PROCESSING
      asymbol *ptr;
#endif

      cache_ptr = reloc_cache + idx;
      src = native_relocs + idx;

      coff_swap_reloc_in (abfd, src, &dst);

#ifdef RELOC_PROCESSING
      RELOC_PROCESSING (cache_ptr, &dst, symbols, abfd, asect);
#else
      cache_ptr->address = dst.r_vaddr;

      if (dst.r_symndx != -1)
       {
         if (dst.r_symndx < 0 || dst.r_symndx >= obj_conv_table_size (abfd))
           {
             (*_bfd_error_handler)
              (_("%B: warning: illegal symbol index %ld in relocs"),
               abfd, dst.r_symndx);
             cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
             ptr = NULL;
           }
         else
           {
             cache_ptr->sym_ptr_ptr = (symbols
                                   + obj_convert (abfd)[dst.r_symndx]);
             ptr = *(cache_ptr->sym_ptr_ptr);
           }
       }
      else
       {
         cache_ptr->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
         ptr = NULL;
       }

      /* The symbols definitions that we have read in have been
        relocated as if their sections started at 0. But the offsets
        refering to the symbols in the raw data have not been
        modified, so we have to have a negative addend to compensate.

        Note that symbols which used to be common must be left alone.  */

      /* Calculate any reloc addend by looking at the symbol.  */
      CALC_ADDEND (abfd, ptr, dst, cache_ptr);

      cache_ptr->address -= asect->vma;
      /* !! cache_ptr->section = NULL;*/

      /* Fill in the cache_ptr->howto field from dst.r_type.  */
      RTYPE2HOWTO (cache_ptr, &dst);
#endif /* RELOC_PROCESSING */

      if (cache_ptr->howto == NULL)
       {
         (*_bfd_error_handler)
           (_("%B: illegal relocation type %d at address 0x%lx"),
            abfd, dst.r_type, (long) dst.r_vaddr);
         bfd_set_error (bfd_error_bad_value);
         return FALSE;
       }
    }

  asect->relocation = reloc_cache;
  return TRUE;
}

Here is the call graph for this function:

static bfd_boolean coff_slurp_symbol_table ( bfd abfd) [static]

Definition at line 4341 of file coffcode.h.

{
  combined_entry_type *native_symbols;
  coff_symbol_type *cached_area;
  unsigned int *table_ptr;
  bfd_size_type amt;
  unsigned int number_of_symbols = 0;

  if (obj_symbols (abfd))
    return TRUE;

  /* Read in the symbol table.  */
  if ((native_symbols = coff_get_normalized_symtab (abfd)) == NULL)
    return FALSE;

  /* Allocate enough room for all the symbols in cached form.  */
  amt = obj_raw_syment_count (abfd);
  amt *= sizeof (coff_symbol_type);
  cached_area = bfd_alloc (abfd, amt);
  if (cached_area == NULL)
    return FALSE;

  amt = obj_raw_syment_count (abfd);
  amt *= sizeof (unsigned int);
  table_ptr = bfd_alloc (abfd, amt);

  if (table_ptr == NULL)
    return FALSE;
  else
    {
      coff_symbol_type *dst = cached_area;
      unsigned int last_native_index = obj_raw_syment_count (abfd);
      unsigned int this_index = 0;

      while (this_index < last_native_index)
       {
         combined_entry_type *src = native_symbols + this_index;
         table_ptr[this_index] = number_of_symbols;
         dst->symbol.the_bfd = abfd;

         dst->symbol.name = (char *) (src->u.syment._n._n_n._n_offset);
         /* We use the native name field to point to the cached field.  */
         src->u.syment._n._n_n._n_zeroes = (long) dst;
         dst->symbol.section = coff_section_from_bfd_index (abfd,
                                               src->u.syment.n_scnum);
         dst->symbol.flags = 0;
         dst->done_lineno = FALSE;

         switch (src->u.syment.n_sclass)
           {
#ifdef I960
           case C_LEAFEXT:
             /* Fall through to next case.  */
#endif

           case C_EXT:
           case C_WEAKEXT:
#if defined ARM
            case C_THUMBEXT:
            case C_THUMBEXTFUNC:
#endif
#ifdef RS6000COFF_C
           case C_HIDEXT:
#endif
#ifdef C_SYSTEM
           case C_SYSTEM:   /* System Wide variable.  */
#endif
#ifdef COFF_WITH_PE
            /* In PE, 0x68 (104) denotes a section symbol.  */
            case C_SECTION:
           /* In PE, 0x69 (105) denotes a weak external symbol.  */
           case C_NT_WEAK:
#endif
             switch (coff_classify_symbol (abfd, &src->u.syment))
              {
              case COFF_SYMBOL_GLOBAL:
                dst->symbol.flags = BSF_EXPORT | BSF_GLOBAL;
#if defined COFF_WITH_PE
                /* PE sets the symbol to a value relative to the
                     start of the section.  */
                dst->symbol.value = src->u.syment.n_value;
#else
                dst->symbol.value = (src->u.syment.n_value
                                   - dst->symbol.section->vma);
#endif
                if (ISFCN ((src->u.syment.n_type)))
                  /* A function ext does not go at the end of a
                     file.  */
                  dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
                break;

              case COFF_SYMBOL_COMMON:
                dst->symbol.section = bfd_com_section_ptr;
                dst->symbol.value = src->u.syment.n_value;
                break;

              case COFF_SYMBOL_UNDEFINED:
                dst->symbol.section = bfd_und_section_ptr;
                dst->symbol.value = 0;
                break;

              case COFF_SYMBOL_PE_SECTION:
                dst->symbol.flags |= BSF_EXPORT | BSF_SECTION_SYM;
                dst->symbol.value = 0;
                break;

              case COFF_SYMBOL_LOCAL:
                dst->symbol.flags = BSF_LOCAL;
#if defined COFF_WITH_PE
                /* PE sets the symbol to a value relative to the
                     start of the section.  */
                dst->symbol.value = src->u.syment.n_value;
#else
                dst->symbol.value = (src->u.syment.n_value
                                   - dst->symbol.section->vma);
#endif
                if (ISFCN ((src->u.syment.n_type)))
                  dst->symbol.flags |= BSF_NOT_AT_END | BSF_FUNCTION;
                break;
              }

#ifdef RS6000COFF_C
             /* A symbol with a csect entry should not go at the end.  */
             if (src->u.syment.n_numaux > 0)
              dst->symbol.flags |= BSF_NOT_AT_END;
#endif

#ifdef COFF_WITH_PE
             if (src->u.syment.n_sclass == C_NT_WEAK)
              dst->symbol.flags |= BSF_WEAK;

             if (src->u.syment.n_sclass == C_SECTION
                && src->u.syment.n_scnum > 0)
              dst->symbol.flags = BSF_LOCAL;
#endif
             if (src->u.syment.n_sclass == C_WEAKEXT)
              dst->symbol.flags |= BSF_WEAK;

             break;

           case C_STAT:      /* Static.  */
#ifdef I960
           case C_LEAFSTAT:  /* Static leaf procedure.  */
#endif
#if defined ARM
            case C_THUMBSTAT:    /* Thumb static.  */
            case C_THUMBLABEL:   /* Thumb label.  */
            case C_THUMBSTATFUNC:/* Thumb static function.  */
#endif
           case C_LABEL:     /* Label.  */
             if (src->u.syment.n_scnum == N_DEBUG)
              dst->symbol.flags = BSF_DEBUGGING;
             else
              dst->symbol.flags = BSF_LOCAL;

             /* Base the value as an index from the base of the
               section, if there is one.  */
             if (dst->symbol.section)
              {
#if defined COFF_WITH_PE
                /* PE sets the symbol to a value relative to the
                     start of the section.  */
                dst->symbol.value = src->u.syment.n_value;
#else
                dst->symbol.value = (src->u.syment.n_value
                                   - dst->symbol.section->vma);
#endif
              }
             else
              dst->symbol.value = src->u.syment.n_value;
             break;

           case C_MOS:             /* Member of structure.  */
           case C_EOS:             /* End of structure.  */
           case C_REGPARM:  /* Register parameter.  */
           case C_REG:             /* register variable.  */
              /* C_AUTOARG conflicts with TI COFF C_UEXT.  */
#if !defined (TIC80COFF) && !defined (TICOFF)
#ifdef C_AUTOARG
           case C_AUTOARG:  /* 960-specific storage class.  */
#endif
#endif
           case C_TPDEF:    /* Type definition.  */
           case C_ARG:
           case C_AUTO:     /* Automatic variable.  */
           case C_FIELD:    /* Bit field.  */
           case C_ENTAG:    /* Enumeration tag.  */
           case C_MOE:             /* Member of enumeration.  */
           case C_MOU:             /* Member of union.  */
           case C_UNTAG:    /* Union tag.  */
             dst->symbol.flags = BSF_DEBUGGING;
             dst->symbol.value = (src->u.syment.n_value);
             break;

           case C_FILE:     /* File name.  */
           case C_STRTAG:   /* Structure tag.  */
#ifdef RS6000COFF_C
           case C_GSYM:
           case C_LSYM:
           case C_PSYM:
           case C_RSYM:
           case C_RPSYM:
           case C_STSYM:
           case C_TCSYM:
           case C_BCOMM:
           case C_ECOML:
           case C_ECOMM:
           case C_DECL:
           case C_ENTRY:
           case C_FUN:
           case C_ESTAT:
#endif
             dst->symbol.flags = BSF_DEBUGGING;
             dst->symbol.value = (src->u.syment.n_value);
             break;

#ifdef RS6000COFF_C
           case C_BINCL:    /* Beginning of include file.  */
           case C_EINCL:    /* Ending of include file.  */
             /* The value is actually a pointer into the line numbers
                 of the file.  We locate the line number entry, and
                 set the section to the section which contains it, and
                 the value to the index in that section.  */
             {
              asection *sec;

              dst->symbol.flags = BSF_DEBUGGING;
              for (sec = abfd->sections; sec != NULL; sec = sec->next)
                if (sec->line_filepos <= (file_ptr) src->u.syment.n_value
                    && ((file_ptr) (sec->line_filepos
                                  + sec->lineno_count * bfd_coff_linesz (abfd))
                       > (file_ptr) src->u.syment.n_value))
                  break;
              if (sec == NULL)
                dst->symbol.value = 0;
              else
                {
                  dst->symbol.section = sec;
                  dst->symbol.value = ((src->u.syment.n_value
                                     - sec->line_filepos)
                                    / bfd_coff_linesz (abfd));
                  src->fix_line = 1;
                }
             }
             break;

           case C_BSTAT:
             dst->symbol.flags = BSF_DEBUGGING;

             /* The value is actually a symbol index.  Save a pointer
               to the symbol instead of the index.  FIXME: This
               should use a union.  */
             src->u.syment.n_value =
              (long) (native_symbols + src->u.syment.n_value);
             dst->symbol.value = src->u.syment.n_value;
             src->fix_value = 1;
             break;
#endif

           case C_BLOCK:    /* ".bb" or ".eb".  */
           case C_FCN:             /* ".bf" or ".ef" (or PE ".lf").  */
           case C_EFCN:     /* Physical end of function.  */
#if defined COFF_WITH_PE
             /* PE sets the symbol to a value relative to the start
               of the section.  */
             dst->symbol.value = src->u.syment.n_value;
             if (strcmp (dst->symbol.name, ".bf") != 0)
              {
                /* PE uses funny values for .ef and .lf; don't
                     relocate them.  */
                dst->symbol.flags = BSF_DEBUGGING;
              }
             else
              dst->symbol.flags = BSF_DEBUGGING | BSF_DEBUGGING_RELOC;
#else
             /* Base the value as an index from the base of the
               section.  */
             dst->symbol.flags = BSF_LOCAL;
             dst->symbol.value = (src->u.syment.n_value
                               - dst->symbol.section->vma);
#endif
             break;

           case C_STATLAB:  /* Static load time label.  */
              dst->symbol.value = src->u.syment.n_value;
              dst->symbol.flags = BSF_GLOBAL;
              break;

           case C_NULL:
             /* PE DLLs sometimes have zeroed out symbols for some
                 reason.  Just ignore them without a warning.  */
             if (src->u.syment.n_type == 0
                && src->u.syment.n_value == 0
                && src->u.syment.n_scnum == 0)
              break;
             /* Fall through.  */
           case C_EXTDEF:   /* External definition.  */
           case C_ULABEL:   /* Undefined label.  */
           case C_USTATIC:  /* Undefined static.  */
#ifndef COFF_WITH_PE
            /* C_LINE in regular coff is 0x68.  NT has taken over this storage
               class to represent a section symbol.  */
           case C_LINE:     /* line # reformatted as symbol table entry.  */
             /* NT uses 0x67 for a weak symbol, not C_ALIAS.  */
           case C_ALIAS:    /* Duplicate tag.  */
#endif
             /* New storage classes for TI COFF.  */
#if defined(TIC80COFF) || defined(TICOFF)
           case C_UEXT:     /* Tentative external definition.  */
#endif
           case C_EXTLAB:   /* External load time label.  */
           case C_HIDDEN:   /* Ext symbol in dmert public lib.  */
           default:
             (*_bfd_error_handler)
              (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
               abfd, src->u.syment.n_sclass,
               dst->symbol.section->name, dst->symbol.name);
             dst->symbol.flags = BSF_DEBUGGING;
             dst->symbol.value = (src->u.syment.n_value);
             break;
           }

         dst->native = src;

         dst->symbol.udata.i = 0;
         dst->lineno = NULL;
         this_index += (src->u.syment.n_numaux) + 1;
         dst++;
         number_of_symbols++;
       }
    }

  obj_symbols (abfd) = cached_area;
  obj_raw_syments (abfd) = native_symbols;

  bfd_get_symcount (abfd) = number_of_symbols;
  obj_convert (abfd) = table_ptr;
  /* Slurp the line tables for each section too.  */
  {
    asection *p;

    p = abfd->sections;
    while (p)
      {
       coff_slurp_line_table (abfd, p);
       p = p->next;
      }
  }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean coff_write_object_contents ( bfd abfd) [static]

Definition at line 3366 of file coffcode.h.

{
  asection *current;
  bfd_boolean hasrelocs = FALSE;
  bfd_boolean haslinno = FALSE;
  bfd_boolean hasdebug = FALSE;
  file_ptr scn_base;
  file_ptr reloc_base;
  file_ptr lineno_base;
  file_ptr sym_base;
  unsigned long reloc_size = 0, reloc_count = 0;
  unsigned long lnno_size = 0;
  bfd_boolean long_section_names;
  asection *text_sec = NULL;
  asection *data_sec = NULL;
  asection *bss_sec = NULL;
  struct internal_filehdr internal_f;
  struct internal_aouthdr internal_a;
#ifdef COFF_LONG_SECTION_NAMES
  size_t string_size = STRING_SIZE_SIZE;
#endif

  bfd_set_error (bfd_error_system_call);

  /* Make a pass through the symbol table to count line number entries and
     put them into the correct asections.  */
  lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);

  if (! abfd->output_has_begun)
    {
      if (! coff_compute_section_file_positions (abfd))
       return FALSE;
    }

  reloc_base = obj_relocbase (abfd);

  /* Work out the size of the reloc and linno areas.  */

  for (current = abfd->sections; current != NULL; current =
       current->next)
    {
#ifdef COFF_WITH_PE
      /* We store the actual reloc count in the first reloc's addr.  */
      if (obj_pe (abfd) && current->reloc_count >= 0xffff)
       reloc_count ++;
#endif
      reloc_count += current->reloc_count;
    }

  reloc_size = reloc_count * bfd_coff_relsz (abfd);

  lineno_base = reloc_base + reloc_size;
  sym_base = lineno_base + lnno_size;

  /* Indicate in each section->line_filepos its actual file address.  */
  for (current = abfd->sections; current != NULL; current =
       current->next)
    {
      if (current->lineno_count)
       {
         current->line_filepos = lineno_base;
         current->moving_line_filepos = lineno_base;
         lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
       }
      else
       current->line_filepos = 0;

      if (current->reloc_count)
       {
         current->rel_filepos = reloc_base;
         reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
#ifdef COFF_WITH_PE
         /* Extra reloc to hold real count.  */
         if (obj_pe (abfd) && current->reloc_count >= 0xffff)
           reloc_base += bfd_coff_relsz (abfd);
#endif
       }
      else
       current->rel_filepos = 0;
    }

  /* Write section headers to the file.  */
  internal_f.f_nscns = 0;

  if ((abfd->flags & EXEC_P) != 0)
    scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
  else
    {
      scn_base = bfd_coff_filhsz (abfd);
#ifdef RS6000COFF_C
#ifndef XCOFF64
      if (xcoff_data (abfd)->full_aouthdr)
       scn_base += bfd_coff_aoutsz (abfd);
      else
       scn_base += SMALL_AOUTSZ;
#endif
#endif
    }

  if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
    return FALSE;

  long_section_names = FALSE;
  for (current = abfd->sections;
       current != NULL;
       current = current->next)
    {
      struct internal_scnhdr section;
      bfd_boolean is_reloc_section = FALSE;

#ifdef COFF_IMAGE_WITH_PE
      if (strcmp (current->name, ".reloc") == 0)
       {
         is_reloc_section = TRUE;
         hasrelocs = TRUE;
         pe_data (abfd)->has_reloc_section = 1;
       }
#endif

      internal_f.f_nscns++;

      strncpy (section.s_name, current->name, SCNNMLEN);

#ifdef COFF_LONG_SECTION_NAMES
      /* Handle long section names as in PE.  This must be compatible
         with the code in coff_write_symbols and _bfd_coff_final_link.  */
      {
       size_t len;

       len = strlen (current->name);
       if (len > SCNNMLEN)
         {
           memset (section.s_name, 0, SCNNMLEN);
           sprintf (section.s_name, "/%lu", (unsigned long) string_size);
           string_size += len + 1;
           long_section_names = TRUE;
         }
      }
#endif

#ifdef _LIB
      /* Always set s_vaddr of .lib to 0.  This is right for SVR3.2
        Ian Taylor <ian@cygnus.com>.  */
      if (strcmp (current->name, _LIB) == 0)
       section.s_vaddr = 0;
      else
#endif
      section.s_vaddr = current->vma;
      section.s_paddr = current->lma;
      section.s_size =  current->size;
#ifdef coff_get_section_load_page
      section.s_page = coff_get_section_load_page (current);
#endif

#ifdef COFF_WITH_PE
      section.s_paddr = 0;
#endif
#ifdef COFF_IMAGE_WITH_PE
      /* Reminder: s_paddr holds the virtual size of the section.  */
      if (coff_section_data (abfd, current) != NULL
         && pei_section_data (abfd, current) != NULL)
       section.s_paddr = pei_section_data (abfd, current)->virt_size;
      else
       section.s_paddr = 0;
#endif

      /* If this section has no size or is unloadable then the scnptr
        will be 0 too.  */
      if (current->size == 0
         || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
       section.s_scnptr = 0;
      else
       section.s_scnptr = current->filepos;

      section.s_relptr = current->rel_filepos;
      section.s_lnnoptr = current->line_filepos;
      section.s_nreloc = current->reloc_count;
      section.s_nlnno = current->lineno_count;
#ifndef COFF_IMAGE_WITH_PE
      /* In PEI, relocs come in the .reloc section.  */
      if (current->reloc_count != 0)
       hasrelocs = TRUE;
#endif
      if (current->lineno_count != 0)
       haslinno = TRUE;
      if ((current->flags & SEC_DEBUGGING) != 0
         && ! is_reloc_section)
       hasdebug = TRUE;

#ifdef RS6000COFF_C
#ifndef XCOFF64
      /* Indicate the use of an XCOFF overflow section header.  */
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
       {
         section.s_nreloc = 0xffff;
         section.s_nlnno = 0xffff;
       }
#endif
#endif

      section.s_flags = sec_to_styp_flags (current->name, current->flags);

      if (!strcmp (current->name, _TEXT))
       text_sec = current;
      else if (!strcmp (current->name, _DATA))
       data_sec = current;
      else if (!strcmp (current->name, _BSS))
       bss_sec = current;

#ifdef I960
      section.s_align = (current->alignment_power
                      ? 1 << current->alignment_power
                      : 0);
#endif
#ifdef TIC80COFF
      /* TI COFF puts the alignment power in bits 8-11 of the flags.  */
      section.s_flags |= (current->alignment_power & 0xF) << 8;
#endif
#ifdef COFF_ENCODE_ALIGNMENT
      COFF_ENCODE_ALIGNMENT(section, current->alignment_power);
#endif

#ifdef COFF_IMAGE_WITH_PE
      /* Suppress output of the sections if they are null.  ld
        includes the bss and data sections even if there is no size
        assigned to them.  NT loader doesn't like it if these section
        headers are included if the sections themselves are not
        needed.  See also coff_compute_section_file_positions.  */
      if (section.s_size == 0)
       internal_f.f_nscns--;
      else
#endif
       {
         SCNHDR buff;
         bfd_size_type amt = bfd_coff_scnhsz (abfd);

         if (coff_swap_scnhdr_out (abfd, &section, &buff) == 0
             || bfd_bwrite (& buff, amt, abfd) != amt)
           return FALSE;
       }

#ifdef COFF_WITH_PE
      /* PE stores COMDAT section information in the symbol table.  If
         this section is supposed to have some COMDAT info, track down
         the symbol in the symbol table and modify it.  */
      if ((current->flags & SEC_LINK_ONCE) != 0)
       {
         unsigned int i, count;
         asymbol **psym;
         coff_symbol_type *csym = NULL;
         asymbol **psymsec;

         psymsec = NULL;
         count = bfd_get_symcount (abfd);
         for (i = 0, psym = abfd->outsymbols; i < count; i++, psym++)
           {
             if ((*psym)->section != current)
              continue;

             /* Remember the location of the first symbol in this
                 section.  */
             if (psymsec == NULL)
              psymsec = psym;

             /* See if this is the section symbol.  */
             if (strcmp ((*psym)->name, current->name) == 0)
              {
                csym = coff_symbol_from (abfd, *psym);
                if (csym == NULL
                    || csym->native == NULL
                    || csym->native->u.syment.n_numaux < 1
                    || csym->native->u.syment.n_sclass != C_STAT
                    || csym->native->u.syment.n_type != T_NULL)
                  continue;

                /* Here *PSYM is the section symbol for CURRENT.  */

                break;
              }
           }

         /* Did we find it?
            Note that we might not if we're converting the file from
            some other object file format.  */
         if (i < count)
           {
             combined_entry_type *aux;

             /* We don't touch the x_checksum field.  The
               x_associated field is not currently supported.  */

             aux = csym->native + 1;
             switch (current->flags & SEC_LINK_DUPLICATES)
              {
              case SEC_LINK_DUPLICATES_DISCARD:
                aux->u.auxent.x_scn.x_comdat = IMAGE_COMDAT_SELECT_ANY;
                break;

              case SEC_LINK_DUPLICATES_ONE_ONLY:
                aux->u.auxent.x_scn.x_comdat =
                  IMAGE_COMDAT_SELECT_NODUPLICATES;
                break;

              case SEC_LINK_DUPLICATES_SAME_SIZE:
                aux->u.auxent.x_scn.x_comdat =
                  IMAGE_COMDAT_SELECT_SAME_SIZE;
                break;

              case SEC_LINK_DUPLICATES_SAME_CONTENTS:
                aux->u.auxent.x_scn.x_comdat =
                  IMAGE_COMDAT_SELECT_EXACT_MATCH;
                break;
              }

             /* The COMDAT symbol must be the first symbol from this
                 section in the symbol table.  In order to make this
                 work, we move the COMDAT symbol before the first
                 symbol we found in the search above.  It's OK to
                 rearrange the symbol table at this point, because
                 coff_renumber_symbols is going to rearrange it
                 further and fix up all the aux entries.  */
             if (psym != psymsec)
              {
                asymbol *hold;
                asymbol **pcopy;

                hold = *psym;
                for (pcopy = psym; pcopy > psymsec; pcopy--)
                  pcopy[0] = pcopy[-1];
                *psymsec = hold;
              }
           }
       }
#endif /* COFF_WITH_PE */
    }

#ifdef RS6000COFF_C
#ifndef XCOFF64
  /* XCOFF handles overflows in the reloc and line number count fields
     by creating a new section header to hold the correct values.  */
  for (current = abfd->sections; current != NULL; current = current->next)
    {
      if (current->reloc_count >= 0xffff || current->lineno_count >= 0xffff)
       {
         struct internal_scnhdr scnhdr;
         SCNHDR buff;
         bfd_size_type amt;

         internal_f.f_nscns++;
         strncpy (&(scnhdr.s_name[0]), current->name, 8);
         scnhdr.s_paddr = current->reloc_count;
         scnhdr.s_vaddr = current->lineno_count;
         scnhdr.s_size = 0;
         scnhdr.s_scnptr = 0;
         scnhdr.s_relptr = current->rel_filepos;
         scnhdr.s_lnnoptr = current->line_filepos;
         scnhdr.s_nreloc = current->target_index;
         scnhdr.s_nlnno = current->target_index;
         scnhdr.s_flags = STYP_OVRFLO;
         amt = bfd_coff_scnhsz (abfd);
         if (coff_swap_scnhdr_out (abfd, &scnhdr, &buff) == 0
             || bfd_bwrite (& buff, amt, abfd) != amt)
           return FALSE;
       }
    }
#endif
#endif

  /* OK, now set up the filehdr...  */

  /* Don't include the internal abs section in the section count */

  /* We will NOT put a fucking timestamp in the header here. Every time you
     put it back, I will come in and take it out again.  I'm sorry.  This
     field does not belong here.  We fill it with a 0 so it compares the
     same but is not a reasonable time. -- gnu@cygnus.com  */
  internal_f.f_timdat = 0;
  internal_f.f_flags = 0;

  if (abfd->flags & EXEC_P)
    internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
  else
    {
      internal_f.f_opthdr = 0;
#ifdef RS6000COFF_C
#ifndef XCOFF64
      if (xcoff_data (abfd)->full_aouthdr)
       internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
      else
       internal_f.f_opthdr = SMALL_AOUTSZ;
#endif
#endif
    }

  if (!hasrelocs)
    internal_f.f_flags |= F_RELFLG;
  if (!haslinno)
    internal_f.f_flags |= F_LNNO;
  if (abfd->flags & EXEC_P)
    internal_f.f_flags |= F_EXEC;
#ifdef COFF_IMAGE_WITH_PE
  if (! hasdebug)
    internal_f.f_flags |= IMAGE_FILE_DEBUG_STRIPPED;
  if (pe_data (abfd)->real_flags & IMAGE_FILE_LARGE_ADDRESS_AWARE)
    internal_f.f_flags |= IMAGE_FILE_LARGE_ADDRESS_AWARE;
#endif

#ifndef COFF_WITH_pex64
#ifdef COFF_WITH_PE
  internal_f.f_flags |= IMAGE_FILE_32BIT_MACHINE;
#else
  if (bfd_little_endian (abfd))
    internal_f.f_flags |= F_AR32WR;
  else
    internal_f.f_flags |= F_AR32W;
#endif
#endif

#ifdef TI_TARGET_ID
  /* Target id is used in TI COFF v1 and later; COFF0 won't use this field,
     but it doesn't hurt to set it internally.  */
  internal_f.f_target_id = TI_TARGET_ID;
#endif
#ifdef TIC80_TARGET_ID
  internal_f.f_target_id = TIC80_TARGET_ID;
#endif

  /* FIXME, should do something about the other byte orders and
     architectures.  */

#ifdef RS6000COFF_C
  if ((abfd->flags & DYNAMIC) != 0)
    internal_f.f_flags |= F_SHROBJ;
  if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
    internal_f.f_flags |= F_DYNLOAD;
#endif

  memset (&internal_a, 0, sizeof internal_a);

  /* Set up architecture-dependent stuff.  */
  {
    unsigned int magic = 0;
    unsigned short flags = 0;

    coff_set_flags (abfd, &magic, &flags);
    internal_f.f_magic = magic;
    internal_f.f_flags |= flags;
    /* ...and the "opt"hdr...  */

#ifdef TICOFF_AOUT_MAGIC
    internal_a.magic = TICOFF_AOUT_MAGIC;
#define __A_MAGIC_SET__
#endif
#ifdef TIC80COFF
    internal_a.magic = TIC80_ARCH_MAGIC;
#define __A_MAGIC_SET__
#endif /* TIC80 */
#ifdef I860
    /* FIXME: What are the a.out magic numbers for the i860?  */
    internal_a.magic = 0;
#define __A_MAGIC_SET__
#endif /* I860 */
#ifdef I960
    internal_a.magic = (magic == I960ROMAGIC ? NMAGIC : OMAGIC);
#define __A_MAGIC_SET__
#endif /* I960 */
#if M88
#define __A_MAGIC_SET__
    internal_a.magic = PAGEMAGICBCS;
#endif /* M88 */

#if APOLLO_M68
#define __A_MAGIC_SET__
    internal_a.magic = APOLLO_COFF_VERSION_NUMBER;
#endif

#if defined(M68) || defined(WE32K) || defined(M68K)
#define __A_MAGIC_SET__
#if defined(LYNXOS)
    internal_a.magic = LYNXCOFFMAGIC;
#else
#if defined(TARG_AUX)
    internal_a.magic = (abfd->flags & D_PAGED ? PAGEMAGICPEXECPAGED :
                     abfd->flags & WP_TEXT ? PAGEMAGICPEXECSWAPPED :
                     PAGEMAGICEXECSWAPPED);
#else
#if defined (PAGEMAGICPEXECPAGED)
    internal_a.magic = PAGEMAGICPEXECPAGED;
#endif
#endif /* TARG_AUX */
#endif /* LYNXOS */
#endif /* M68 || WE32K || M68K */

#if defined(ARM)
#define __A_MAGIC_SET__
    internal_a.magic = ZMAGIC;
#endif

#if defined(PPC_PE)
#define __A_MAGIC_SET__
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
#endif

#if defined MCORE_PE
#define __A_MAGIC_SET__
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
#endif

#if defined(I386)
#define __A_MAGIC_SET__
#if defined LYNXOS
    internal_a.magic = LYNXCOFFMAGIC;
#elif defined AMD64
    internal_a.magic = IMAGE_NT_OPTIONAL_HDR64_MAGIC;
#else
    internal_a.magic = ZMAGIC;
#endif
#endif /* I386 */

#if defined(IA64)
#define __A_MAGIC_SET__
    internal_a.magic = PE32PMAGIC;
#endif /* IA64 */

#if defined(SPARC)
#define __A_MAGIC_SET__
#if defined(LYNXOS)
    internal_a.magic = LYNXCOFFMAGIC;
#endif /* LYNXOS */
#endif /* SPARC */

#ifdef RS6000COFF_C
#define __A_MAGIC_SET__
    internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
    (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
    RS6K_AOUTHDR_OMAGIC;
#endif

#if defined(SH) && defined(COFF_WITH_PE)
#define __A_MAGIC_SET__
    internal_a.magic = SH_PE_MAGIC;
#endif

#if defined(MIPS) && defined(COFF_WITH_PE)
#define __A_MAGIC_SET__
    internal_a.magic = MIPS_PE_MAGIC;
#endif

#ifdef OR32
#define __A_MAGIC_SET__
    internal_a.magic = NMAGIC; /* Assume separate i/d.  */
#endif

#ifdef MAXQ20MAGIC
#define __A_MAGIC_SET__
      internal_a.magic = MAXQ20MAGIC;
#endif
 
#ifndef __A_MAGIC_SET__
#include "Your aouthdr magic number is not being set!"
#else
#undef __A_MAGIC_SET__
#endif
  }

  /* FIXME: Does anybody ever set this to another value?  */
  internal_a.vstamp = 0;

  /* Now should write relocs, strings, syms.  */
  obj_sym_filepos (abfd) = sym_base;

  if (bfd_get_symcount (abfd) != 0)
    {
      int firstundef;

      if (!coff_renumber_symbols (abfd, &firstundef))
       return FALSE;
      coff_mangle_symbols (abfd);
      if (! coff_write_symbols (abfd))
       return FALSE;
      if (! coff_write_linenumbers (abfd))
       return FALSE;
      if (! coff_write_relocs (abfd, firstundef))
       return FALSE;
    }
#ifdef COFF_LONG_SECTION_NAMES
  else if (long_section_names && ! obj_coff_strings_written (abfd))
    {
      /* If we have long section names we have to write out the string
         table even if there are no symbols.  */
      if (! coff_write_symbols (abfd))
       return FALSE;
    }
#endif
#ifdef COFF_IMAGE_WITH_PE
#ifdef PPC_PE
  else if ((abfd->flags & EXEC_P) != 0)
    {
      bfd_byte b;

      /* PowerPC PE appears to require that all executable files be
         rounded up to the page size.  */
      b = 0;
      if (bfd_seek (abfd,
                  (file_ptr) BFD_ALIGN (sym_base, COFF_PAGE_SIZE) - 1,
                  SEEK_SET) != 0
         || bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
       return FALSE;
    }
#endif
#endif

  /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
     backend linker, and obj_raw_syment_count is not valid until after
     coff_write_symbols is called.  */
  if (obj_raw_syment_count (abfd) != 0)
    {
      internal_f.f_symptr = sym_base;
#ifdef RS6000COFF_C
      /* AIX appears to require that F_RELFLG not be set if there are
         local symbols but no relocations.  */
      internal_f.f_flags &=~ F_RELFLG;
#endif
    }
  else
    {
      if (long_section_names)
       internal_f.f_symptr = sym_base;
      else
       internal_f.f_symptr = 0;
      internal_f.f_flags |= F_LSYMS;
    }

  if (text_sec)
    {
      internal_a.tsize = text_sec->size;
      internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
    }
  if (data_sec)
    {
      internal_a.dsize = data_sec->size;
      internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
    }
  if (bss_sec)
    {
      internal_a.bsize = bss_sec->size;
      if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
       internal_a.data_start = bss_sec->vma;
    }

  internal_a.entry = bfd_get_start_address (abfd);
  internal_f.f_nsyms = obj_raw_syment_count (abfd);

#ifdef RS6000COFF_C
  if (xcoff_data (abfd)->full_aouthdr)
    {
      bfd_vma toc;
      asection *loader_sec;

      internal_a.vstamp = 1;

      internal_a.o_snentry = xcoff_data (abfd)->snentry;
      if (internal_a.o_snentry == 0)
       internal_a.entry = (bfd_vma) -1;

      if (text_sec != NULL)
       {
         internal_a.o_sntext = text_sec->target_index;
         internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
       }
      else
       {
         internal_a.o_sntext = 0;
         internal_a.o_algntext = 0;
       }
      if (data_sec != NULL)
       {
         internal_a.o_sndata = data_sec->target_index;
         internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
       }
      else
       {
         internal_a.o_sndata = 0;
         internal_a.o_algndata = 0;
       }
      loader_sec = bfd_get_section_by_name (abfd, ".loader");
      if (loader_sec != NULL)
       internal_a.o_snloader = loader_sec->target_index;
      else
       internal_a.o_snloader = 0;
      if (bss_sec != NULL)
       internal_a.o_snbss = bss_sec->target_index;
      else
       internal_a.o_snbss = 0;

      toc = xcoff_data (abfd)->toc;
      internal_a.o_toc = toc;
      internal_a.o_sntoc = xcoff_data (abfd)->sntoc;

      internal_a.o_modtype = xcoff_data (abfd)->modtype;
      if (xcoff_data (abfd)->cputype != -1)
       internal_a.o_cputype = xcoff_data (abfd)->cputype;
      else
       {
         switch (bfd_get_arch (abfd))
           {
           case bfd_arch_rs6000:
             internal_a.o_cputype = 4;
             break;
           case bfd_arch_powerpc:
             if (bfd_get_mach (abfd) == bfd_mach_ppc)
              internal_a.o_cputype = 3;
             else
              internal_a.o_cputype = 1;
             break;
           default:
             abort ();
           }
       }
      internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
      internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
    }
#endif

  /* Now write them.  */
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
    return FALSE;

  {
    char * buff;
    bfd_size_type amount = bfd_coff_filhsz (abfd);

    buff = bfd_malloc (amount);
    if (buff == NULL)
      return FALSE;

    bfd_coff_swap_filehdr_out (abfd, & internal_f, buff);
    amount = bfd_bwrite (buff, amount, abfd);

    free (buff);

    if (amount != bfd_coff_filhsz (abfd))
      return FALSE;
  }

  if (abfd->flags & EXEC_P)
    {
      /* Note that peicode.h fills in a PEAOUTHDR, not an AOUTHDR.
        include/coff/pe.h sets AOUTSZ == sizeof (PEAOUTHDR)).  */
      char * buff;
      bfd_size_type amount = bfd_coff_aoutsz (abfd);

      buff = bfd_malloc (amount);
      if (buff == NULL)
       return FALSE;

      coff_swap_aouthdr_out (abfd, & internal_a, buff);
      amount = bfd_bwrite (buff, amount, abfd);

      free (buff);

      if (amount != bfd_coff_aoutsz (abfd))
       return FALSE;

#ifdef COFF_IMAGE_WITH_PE
      if (! coff_apply_checksum (abfd))
       return FALSE;
#endif
    }
#ifdef RS6000COFF_C
  else
    {
      AOUTHDR buff;
      size_t size;

      /* XCOFF seems to always write at least a small a.out header.  */
      coff_swap_aouthdr_out (abfd, & internal_a, & buff);
      if (xcoff_data (abfd)->full_aouthdr)
       size = bfd_coff_aoutsz (abfd);
      else
       size = SMALL_AOUTSZ;
      if (bfd_bwrite (& buff, (bfd_size_type) size, abfd) != size)
       return FALSE;
    }
#endif

  return TRUE;
}

Here is the call graph for this function:

static bfd_boolean coff_write_relocs ( bfd abfd,
int  first_undef 
) [static]

Definition at line 2436 of file coffcode.h.

{
  asection *s;

  for (s = abfd->sections; s != NULL; s = s->next)
    {
      unsigned int i;
      struct external_reloc dst;
      arelent **p;

#ifndef TARG_AUX
      p = s->orelocation;
#else
      {
       /* Sort relocations before we write them out.  */
       bfd_size_type amt;

       amt = s->reloc_count;
       amt *= sizeof (arelent *);
       p = bfd_malloc (amt);
       if (p == NULL && s->reloc_count > 0)
         return FALSE;
       memcpy (p, s->orelocation, (size_t) amt);
       qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
      }
#endif

      if (bfd_seek (abfd, s->rel_filepos, SEEK_SET) != 0)
       return FALSE;

#ifdef COFF_WITH_PE
      if (obj_pe (abfd) && s->reloc_count >= 0xffff)
       {
         /* Encode real count here as first reloc.  */
         struct internal_reloc n;

         memset (& n, 0, sizeof (n));
         /* Add one to count *this* reloc (grr).  */
         n.r_vaddr = s->reloc_count + 1;
         coff_swap_reloc_out (abfd, &n, &dst);
         if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
                       abfd) != bfd_coff_relsz (abfd))
           return FALSE;
       }
#endif

      for (i = 0; i < s->reloc_count; i++)
       {
         struct internal_reloc n;
         arelent *q = p[i];

         memset (& n, 0, sizeof (n));

         /* Now we've renumbered the symbols we know where the
            undefined symbols live in the table.  Check the reloc
            entries for symbols who's output bfd isn't the right one.
            This is because the symbol was undefined (which means
            that all the pointers are never made to point to the same
            place). This is a bad thing,'cause the symbols attached
            to the output bfd are indexed, so that the relocation
            entries know which symbol index they point to.  So we
            have to look up the output symbol here.  */

         if (q->sym_ptr_ptr[0]->the_bfd != abfd)
           {
             int j;
             const char *sname = q->sym_ptr_ptr[0]->name;
             asymbol **outsyms = abfd->outsymbols;

             for (j = first_undef; outsyms[j]; j++)
              {
                const char *intable = outsyms[j]->name;

                if (strcmp (intable, sname) == 0)
                  {
                    /* Got a hit, so repoint the reloc.  */
                    q->sym_ptr_ptr = outsyms + j;
                    break;
                  }
              }
           }

         n.r_vaddr = q->address + s->vma;

#ifdef R_IHCONST
         /* The 29k const/consth reloc pair is a real kludge.  The consth
            part doesn't have a symbol; it has an offset.  So rebuilt
            that here.  */
         if (q->howto->type == R_IHCONST)
           n.r_symndx = q->addend;
         else
#endif
           if (q->sym_ptr_ptr)
             {
#ifdef SECTION_RELATIVE_ABSOLUTE_SYMBOL_P
                if (SECTION_RELATIVE_ABSOLUTE_SYMBOL_P (q, s))
#else
              if ((*q->sym_ptr_ptr)->section == bfd_abs_section_ptr
                  && ((*q->sym_ptr_ptr)->flags & BSF_SECTION_SYM) != 0)
#endif
                /* This is a relocation relative to the absolute symbol.  */
                n.r_symndx = -1;
              else
                {
                  n.r_symndx = get_index ((*(q->sym_ptr_ptr)));
                  /* Check to see if the symbol reloc points to a symbol
                     we don't have in our symbol table.  */
                  if (n.r_symndx > obj_conv_table_size (abfd))
                    {
                     bfd_set_error (bfd_error_bad_value);
                     _bfd_error_handler (_("%B: reloc against a non-existant symbol index: %ld"),
                                       abfd, n.r_symndx);
                     return FALSE;
                    }
                }
             }

#ifdef SWAP_OUT_RELOC_OFFSET
         n.r_offset = q->addend;
#endif

#ifdef SELECT_RELOC
         /* Work out reloc type from what is required.  */
         SELECT_RELOC (n, q->howto);
#else
         n.r_type = q->howto->type;
#endif
         coff_swap_reloc_out (abfd, &n, &dst);

         if (bfd_bwrite (& dst, (bfd_size_type) bfd_coff_relsz (abfd),
                      abfd) != bfd_coff_relsz (abfd))
           return FALSE;
       }

#ifdef TARG_AUX
      if (p != NULL)
       free (p);
#endif
    }

  return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int dummy_reloc16_estimate ( bfd *abfd  ATTRIBUTE_UNUSED,
asection *input_section  ATTRIBUTE_UNUSED,
arelent *reloc  ATTRIBUTE_UNUSED,
unsigned int shrink  ATTRIBUTE_UNUSED,
struct bfd_link_info *link_info  ATTRIBUTE_UNUSED 
) [static]

Definition at line 5006 of file coffcode.h.

{
  abort ();
  return 0;
}
static void dummy_reloc16_extra_cases ( bfd *abfd  ATTRIBUTE_UNUSED,
struct bfd_link_info *link_info  ATTRIBUTE_UNUSED,
struct bfd_link_order *link_order  ATTRIBUTE_UNUSED,
arelent *reloc  ATTRIBUTE_UNUSED,
bfd_byte *data  ATTRIBUTE_UNUSED,
unsigned int *src_ptr  ATTRIBUTE_UNUSED,
unsigned int *dst_ptr  ATTRIBUTE_UNUSED 
) [static]

Definition at line 5025 of file coffcode.h.

{
  abort ();
}
static long sec_to_styp_flags ( const char *  sec_name,
flagword  sec_flags 
) [static]

Definition at line 396 of file coffcode.h.

{
  long styp_flags = 0;

  if (!strcmp (sec_name, _TEXT))
    {
      styp_flags = STYP_TEXT;
    }
  else if (!strcmp (sec_name, _DATA))
    {
      styp_flags = STYP_DATA;
    }
  else if (!strcmp (sec_name, _BSS))
    {
      styp_flags = STYP_BSS;
#ifdef _COMMENT
    }
  else if (!strcmp (sec_name, _COMMENT))
    {
      styp_flags = STYP_INFO;
#endif /* _COMMENT */
#ifdef _LIB
    }
  else if (!strcmp (sec_name, _LIB))
    {
      styp_flags = STYP_LIB;
#endif /* _LIB */
#ifdef _LIT
    }
  else if (!strcmp (sec_name, _LIT))
    {
      styp_flags = STYP_LIT;
#endif /* _LIT */
    }
  else if (CONST_STRNEQ (sec_name, DOT_DEBUG))
    {
      /* Handle the XCOFF debug section and DWARF2 debug sections.  */
      if (!sec_name[6])
        styp_flags = STYP_XCOFF_DEBUG;
      else
        styp_flags = STYP_DEBUG_INFO;
    }
  else if (CONST_STRNEQ (sec_name, ".stab"))
    {
      styp_flags = STYP_DEBUG_INFO;
    }
#ifdef COFF_LONG_SECTION_NAMES
  else if (CONST_STRNEQ (sec_name, GNU_LINKONCE_WI))
    {
      styp_flags = STYP_DEBUG_INFO;
    }
#endif
#ifdef RS6000COFF_C
  else if (!strcmp (sec_name, _PAD))
    {
      styp_flags = STYP_PAD;
    }
  else if (!strcmp (sec_name, _LOADER))
    {
      styp_flags = STYP_LOADER;
    }
  else if (!strcmp (sec_name, _EXCEPT))
    {
      styp_flags = STYP_EXCEPT;
    }
  else if (!strcmp (sec_name, _TYPCHK))
    {
      styp_flags = STYP_TYPCHK;
    }
#endif
  /* Try and figure out what it should be */
  else if (sec_flags & SEC_CODE)
    {
      styp_flags = STYP_TEXT;
    }
  else if (sec_flags & SEC_DATA)
    {
      styp_flags = STYP_DATA;
    }
  else if (sec_flags & SEC_READONLY)
    {
#ifdef STYP_LIT                    /* 29k readonly text/data section */
      styp_flags = STYP_LIT;
#else
      styp_flags = STYP_TEXT;
#endif /* STYP_LIT */
    }
  else if (sec_flags & SEC_LOAD)
    {
      styp_flags = STYP_TEXT;
    }
  else if (sec_flags & SEC_ALLOC)
    {
      styp_flags = STYP_BSS;
    }

#ifdef STYP_CLINK
  if (sec_flags & SEC_TIC54X_CLINK)
    styp_flags |= STYP_CLINK;
#endif

#ifdef STYP_BLOCK
  if (sec_flags & SEC_TIC54X_BLOCK)
    styp_flags |= STYP_BLOCK;
#endif

#ifdef STYP_NOLOAD
  if ((sec_flags & (SEC_NEVER_LOAD | SEC_COFF_SHARED_LIBRARY)) != 0)
    styp_flags |= STYP_NOLOAD;
#endif

  return styp_flags;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bfd_boolean styp_to_sec_flags ( bfd ,
void *  ,
const char *  ,
asection ,
flagword  
) [static]
static bfd_boolean styp_to_sec_flags ( bfd *abfd  ATTRIBUTE_UNUSED,
void *  hdr,
const char *  name,
asection *section  ATTRIBUTE_UNUSED,
flagword flags_ptr 
) [static]

Definition at line 590 of file coffcode.h.

{
  struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
  long styp_flags = internal_s->s_flags;
  flagword sec_flags = 0;

#ifdef STYP_BLOCK
  if (styp_flags & STYP_BLOCK)
    sec_flags |= SEC_TIC54X_BLOCK;
#endif

#ifdef STYP_CLINK
  if (styp_flags & STYP_CLINK)
    sec_flags |= SEC_TIC54X_CLINK;
#endif

#ifdef STYP_NOLOAD
  if (styp_flags & STYP_NOLOAD)
    sec_flags |= SEC_NEVER_LOAD;
#endif /* STYP_NOLOAD */

  /* For 386 COFF, at least, an unloadable text or data section is
     actually a shared library section.  */
  if (styp_flags & STYP_TEXT)
    {
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
      else
       sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
    }
  else if (styp_flags & STYP_DATA)
    {
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
      else
       sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
    }
  else if (styp_flags & STYP_BSS)
    {
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
      else
#endif
       sec_flags |= SEC_ALLOC;
    }
  else if (styp_flags & STYP_INFO)
    {
      /* We mark these as SEC_DEBUGGING, but only if COFF_PAGE_SIZE is
        defined.  coff_compute_section_file_positions uses
        COFF_PAGE_SIZE to ensure that the low order bits of the
        section VMA and the file offset match.  If we don't know
        COFF_PAGE_SIZE, we can't ensure the correct correspondence,
        and demand page loading of the file will fail.  */
#if defined (COFF_PAGE_SIZE) && !defined (COFF_ALIGN_IN_S_FLAGS)
      sec_flags |= SEC_DEBUGGING;
#endif
    }
  else if (styp_flags & STYP_PAD)
    sec_flags = 0;
  else if (strcmp (name, _TEXT) == 0)
    {
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_CODE | SEC_COFF_SHARED_LIBRARY;
      else
       sec_flags |= SEC_CODE | SEC_LOAD | SEC_ALLOC;
    }
  else if (strcmp (name, _DATA) == 0)
    {
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_DATA | SEC_COFF_SHARED_LIBRARY;
      else
       sec_flags |= SEC_DATA | SEC_LOAD | SEC_ALLOC;
    }
  else if (strcmp (name, _BSS) == 0)
    {
#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
      if (sec_flags & SEC_NEVER_LOAD)
       sec_flags |= SEC_ALLOC | SEC_COFF_SHARED_LIBRARY;
      else
#endif
       sec_flags |= SEC_ALLOC;
    }
  else if (CONST_STRNEQ (name, DOT_DEBUG)
#ifdef _COMMENT
          || strcmp (name, _COMMENT) == 0
#endif
#ifdef COFF_LONG_SECTION_NAMES
          || CONST_STRNEQ (name, GNU_LINKONCE_WI)
#endif
          || CONST_STRNEQ (name, ".stab"))
    {
#ifdef COFF_PAGE_SIZE
      sec_flags |= SEC_DEBUGGING;
#endif
    }
#ifdef _LIB
  else if (strcmp (name, _LIB) == 0)
    ;
#endif
#ifdef _LIT
  else if (strcmp (name, _LIT) == 0)
    sec_flags = SEC_LOAD | SEC_ALLOC | SEC_READONLY;
#endif
  else
    sec_flags |= SEC_ALLOC | SEC_LOAD;

#ifdef STYP_LIT                    /* A29k readonly text/data section type.  */
  if ((styp_flags & STYP_LIT) == STYP_LIT)
    sec_flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY);
#endif /* STYP_LIT */

#ifdef STYP_OTHER_LOAD             /* Other loaded sections.  */
  if (styp_flags & STYP_OTHER_LOAD)
    sec_flags = (SEC_LOAD | SEC_ALLOC);
#endif /* STYP_SDATA */

#if defined (COFF_LONG_SECTION_NAMES) && defined (COFF_SUPPORT_GNU_LINKONCE)
  /* As a GNU extension, if the name begins with .gnu.linkonce, we
     only link a single copy of the section.  This is used to support
     g++.  g++ will emit each template expansion in its own section.
     The symbols will be defined as weak, so that multiple definitions
     are permitted.  The GNU linker extension is to actually discard
     all but one of the sections.  */
  if (CONST_STRNEQ (name, ".gnu.linkonce"))
    sec_flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
#endif

  if (flags_ptr == NULL)
    return FALSE;

  * flags_ptr = sec_flags;
  return TRUE;
}

Here is the call graph for this function:


Variable Documentation

const bfd_coff_backend_data bfd_coff_std_swap_table ATTRIBUTE_UNUSED [static]

Definition at line 5147 of file coffcode.h.

Initial value:
  sizeof coff_section_alignment_table / sizeof coff_section_alignment_table[0]

Definition at line 1540 of file coffcode.h.