* mipsread.c (parse_partial_symbols): Do not add undefined
[deliverable/binutils-gdb.git] / bfd / coffcode.h
index c2c65e7304acea599ec616114f01c69bee86d51f..7ca1616606a7b2f772edd62f48d1317ce4a6e5f8 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for the generic parts of most COFF variants, for BFD.
-   Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -303,51 +303,89 @@ CODE_FRAGMENT
  *     in styp_to_sec_flags().
  */
 static long
-DEFUN(sec_to_styp_flags, (sec_name, sec_flags),
-       CONST char *            sec_name        AND
-       flagword        sec_flags)
+sec_to_styp_flags (sec_name, sec_flags)
+     CONST char *sec_name;
+     flagword sec_flags;
 {
-    long styp_flags = 0;
+  long styp_flags = 0;
 
-    if (!strcmp(sec_name, _TEXT)) {
-       return((long)STYP_TEXT);
-    } else if (!strcmp(sec_name, _DATA)) {
-       return((long)STYP_DATA);
+  if (!strcmp(sec_name, _TEXT)) 
+    {
+      styp_flags = STYP_TEXT;
+    }
+  else if (!strcmp(sec_name, _DATA)) 
+    {
+      styp_flags = STYP_DATA;
 #ifdef TWO_DATA_SECS
-    } else if (!strcmp(sec_name, ".data2")) {
-        return((long)STYP_DATA);
-#endif /* TWO_DATA_SECS */
-    } else if (!strcmp(sec_name, _BSS)) {
-       return((long)STYP_BSS);
+    }
+  else if (!strcmp(sec_name, ".data2")) 
+    {
+      styp_flags = STYP_DATA;
+#endif                         /* TWO_DATA_SECS */
+    }
+  else if (!strcmp(sec_name, _BSS)) 
+    {
+      styp_flags = STYP_BSS;
 #ifdef _COMMENT
-    } else if (!strcmp(sec_name, _COMMENT)) {
-        return((long)STYP_INFO);
-#endif /* _COMMENT */
+    } 
+  else if (!strcmp(sec_name, _COMMENT)) 
+    {
+      styp_flags = STYP_INFO;
+#endif                         /* _COMMENT */
 #ifdef _LIB
-    } else if (!strcmp(sec_name, _LIB)) {
-        return((long)STYP_LIB);
-#endif /* _LIB */
     }
-
-/* Try and figure out what it should be */
-   if (sec_flags & SEC_CODE) styp_flags = STYP_TEXT;
-   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 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 (!strcmp(sec_name, ".debug"))
+    {
+      styp_flags = STYP_INFO;
+    }
+  else if (!strcmp(sec_name, ".stab")
+          || !strncmp(sec_name, ".stabstr", 8))
+    {
+      styp_flags = STYP_INFO;
+    }
+  /* 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;
-
-   if (styp_flags == 0) styp_flags = STYP_BSS;
+      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_NOLOAD
-   if (sec_flags & SEC_NEVER_LOAD)
-        styp_flags |= STYP_NOLOAD;
+  if (sec_flags & SEC_NEVER_LOAD)
+   styp_flags |= STYP_NOLOAD;
 #endif
 
-   return(styp_flags);
+  return(styp_flags);
 }
 /*
  * Return a word with SEC_* flags set to represent the incoming
@@ -390,12 +428,19 @@ DEFUN(styp_to_sec_flags, (abfd, hdr),
   }
   else if (styp_flags & STYP_BSS) 
   {
-    sec_flags |= SEC_ALLOC;
+#ifdef BSS_NOLOAD_IS_SHARED_LIBRARY
+    if (sec_flags & SEC_NEVER_LOAD)
+      sec_flags |= SEC_ALLOC | SEC_SHARED_LIBRARY;
+    else
+#endif
+      sec_flags |= SEC_ALLOC;
   }
   else if (styp_flags & STYP_INFO) 
-  {
-    sec_flags |= SEC_NEVER_LOAD;
-  }
+    {
+      /* Assume that any informational section is primarily for debugging
+        and therefore a prime candidate for stripping. */
+      sec_flags |= SEC_DEBUGGING;
+    }
   else
   {
     sec_flags |= SEC_ALLOC | SEC_LOAD;
@@ -417,7 +462,7 @@ DEFUN(styp_to_sec_flags, (abfd, hdr),
   return(sec_flags);
 }
 
-#define        get_index(symbol)       ((int) (symbol)->udata)
+#define        get_index(symbol)       ((long) (symbol)->udata)
 
 /*
 INTERNAL_DEFINITION
@@ -516,7 +561,8 @@ dependent COFF routines
 .       PTR     internal_filehdr));
 . PTR (*_bfd_coff_mkobject_hook) PARAMS ((
 .       bfd     *abfd,
-.       PTR     internal_filehdr));
+.       PTR     internal_filehdr,
+.       PTR     internal_aouthdr));
 . flagword (*_bfd_styp_to_sec_flags_hook) PARAMS ((
 .       bfd     *abfd,
 .       PTR     internal_scnhdr));
@@ -534,11 +580,17 @@ dependent COFF routines
 .       struct internal_syment *sym));
 . void (*_bfd_coff_reloc16_extra_cases) PARAMS ((
 .       bfd     *abfd,
-.       bfd_seclet_type *seclet,
+.       struct bfd_seclet *seclet,
 .       arelent *reloc,
 .       bfd_byte *data,
 .       unsigned int *src_ptr,
 .       unsigned int *dst_ptr));
+. int (*_bfd_coff_reloc16_estimate) PARAMS ((
+.       asection *input_section,
+.       asymbol **symbols,
+.       arelent *r,
+.       unsigned int shrink)); 
+.
 .} bfd_coff_backend_data;
 .
 .#define coff_backend_info(abfd) ((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
@@ -594,8 +646,8 @@ dependent COFF routines
 .
 .#define bfd_coff_set_arch_mach_hook(abfd, filehdr)\
 .        ((coff_backend_info (abfd)->_bfd_coff_set_arch_mach_hook) (abfd, filehdr))
-.#define bfd_coff_mkobject_hook(abfd, filehdr)\
-.        ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr))
+.#define bfd_coff_mkobject_hook(abfd, filehdr, aouthdr)\
+.        ((coff_backend_info (abfd)->_bfd_coff_mkobject_hook) (abfd, filehdr, aouthdr))
 .
 .#define bfd_coff_styp_to_sec_flags_hook(abfd, scnhdr)\
 .        ((coff_backend_info (abfd)->_bfd_styp_to_sec_flags_hook) (abfd, scnhdr))
@@ -615,6 +667,10 @@ dependent COFF routines
 .#define bfd_coff_reloc16_extra_cases(abfd, seclet, reloc, data, src_ptr, dst_ptr)\
 .        ((coff_backend_info (abfd)->_bfd_coff_reloc16_extra_cases)\
 .         (abfd, seclet, reloc, data, src_ptr, dst_ptr))
+.
+.#define bfd_coff_reloc16_estimate(abfd, section, symbols, reloc, shrink)\
+.        ((coff_backend_info (abfd)->_bfd_coff_reloc16_estimate)\
+.         (section, symbols, reloc, shrink))
 . 
 */
 
@@ -653,6 +709,8 @@ DEFUN (coff_make_section_hook, (abfd, name),
        char *name)
 {
 #ifdef TWO_DATA_SECS
+  /* FIXME: This predates the call to bfd_make_section_anyway
+     in make_a_section_from_file, and can probably go away.  */
   /* On SCO a file created by the Microsoft assembler can have two
      .data sections.  We use .data2 for the second one.  */
   if (strcmp (name, _DATA) == 0)
@@ -733,9 +791,10 @@ DEFUN(coff_mkobject,(abfd),
 /* Create the COFF backend specific information.  */
 
 static          PTR
-DEFUN(coff_mkobject_hook,(abfd, filehdr),
+DEFUN(coff_mkobject_hook,(abfd, filehdr, aouthdr),
       bfd            *abfd AND
-      PTR           filehdr)
+      PTR           filehdr AND
+      PTR           aouthdr)
 {
   struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
   coff_data_type *coff;
@@ -770,9 +829,9 @@ DEFUN(coff_mkobject_hook,(abfd, filehdr),
    at linking together COFF files for different architectures.  */
 
 static boolean
-DEFUN (coff_set_arch_mach_hook, (abfd, filehdr),
-       bfd *abfd AND
-       PTR filehdr)
+coff_set_arch_mach_hook(abfd, filehdr)
+     bfd *abfd;
+     PTR filehdr;
 {
   long machine;
   enum bfd_architecture arch;
@@ -782,9 +841,9 @@ DEFUN (coff_set_arch_mach_hook, (abfd, filehdr),
   switch (internal_f->f_magic) {
 #ifdef I386MAGIC
   case I386MAGIC:
-#ifdef I386AIXMAGIC
+  case I386PTXMAGIC:
   case I386AIXMAGIC:           /* Danbury PS/2 AIX C Compiler */
-#endif
+  case I386LYNXMAGIC:
     arch = bfd_arch_i386;
     machine = 0;
     break;
@@ -798,18 +857,10 @@ DEFUN (coff_set_arch_mach_hook, (abfd, filehdr),
     break;
 #endif
 
-#ifdef MIPS
-  case  MIPS_MAGIC_1:
-  case  MIPS_MAGIC_2:
-  case  MIPS_MAGIC_3:
-    arch = bfd_arch_mips;
-    machine = 0;
-    break;
-#endif
-
 #ifdef MC68MAGIC
   case MC68MAGIC:
   case M68MAGIC:
+  case MC68KBCSMAGIC:
     arch = bfd_arch_m68k;
     machine = 68020;
     break;
@@ -888,6 +939,31 @@ DEFUN (coff_set_arch_mach_hook, (abfd, filehdr),
 #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 SHMAGIC
+  case SHMAGIC:
+    arch = bfd_arch_sh;
+    machine = 0;
+    break;
+#endif
+
+#ifdef H8500MAGIC
+  case H8500MAGIC:
+    arch = bfd_arch_h8500;
     machine = 0;
     break;
 #endif
@@ -1056,12 +1132,6 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
       }
     break;
 #endif
-#ifdef MIPS
-  case bfd_arch_mips:
-    *magicp = MIPS_MAGIC_2;
-    return true;
-    break;
-#endif
 #ifdef I386MAGIC
   case bfd_arch_i386:
     *magicp = I386MAGIC;
@@ -1083,7 +1153,28 @@ DEFUN(coff_set_flags,(abfd, magicp, flagsp),
 #endif
 #ifdef H8300MAGIC
     case bfd_arch_h8300:
-      *magicp = H8300MAGIC;
+    switch (bfd_get_mach (abfd)) 
+      {
+      case bfd_mach_h8300:
+       *magicp = H8300MAGIC;
+       return true;
+      case bfd_mach_h8300h:
+       *magicp = H8300HMAGIC;
+       return true;
+      }
+      break;
+#endif
+
+#ifdef SHMAGIC
+  case bfd_arch_sh:
+      *magicp = SHMAGIC;
+      return true;
+      break;
+#endif
+
+#ifdef H8500MAGIC
+    case bfd_arch_h8500:
+      *magicp = H8500MAGIC;
       return true;
       break;
 #endif
@@ -1147,7 +1238,9 @@ DEFUN(coff_compute_section_file_positions,(abfd),
   asection       *current;
   asection     *previous = (asection *)NULL;
   file_ptr        sofar = FILHSZ;
+#ifndef I960
   file_ptr     old_sofar;
+#endif
   if (bfd_get_start_address(abfd)) 
   {
     /*  A start address may have been added to the original file. In this
@@ -1159,6 +1252,10 @@ DEFUN(coff_compute_section_file_positions,(abfd),
    sofar += AOUTSZ;
 
   sofar += abfd->section_count * SCNHSZ;
+#ifdef USE_DISCARDED_SECTIONS_COUNT
+  /* Count any sections that were removed, so overall size doesn't change. */
+  sofar += discarded_sections_count * SCNHSZ;
+#endif
   for (current = abfd->sections;
        current != (asection *)NULL;
        current = current->next) {
@@ -1199,6 +1296,14 @@ DEFUN(coff_compute_section_file_positions,(abfd),
       current->_raw_size += sofar - old_sofar ;
 #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;
     }
   obj_relocbase(abfd) = sofar;
@@ -1321,7 +1426,7 @@ DEFUN(coff_write_object_contents,(abfd),
   /* Make a pass through the symbol table to count line number entries and
      put them into the correct asections */
 
-  coff_count_linenumbers(abfd);
+  lnno_size =  coff_count_linenumbers(abfd) * LINESZ;
   data_base = scn_base;
 
   /* Work out the size of the reloc and linno areas */
@@ -1334,7 +1439,6 @@ DEFUN(coff_write_object_contents,(abfd),
     {
        
       reloc_size += current->reloc_count * RELSZ;
-      lnno_size += current->lineno_count * LINESZ;
       data_base += SCNHSZ;
     }
       
@@ -1398,8 +1502,8 @@ DEFUN(coff_write_object_contents,(abfd),
          section.s_vaddr = 0;
        else
 #endif
-         section.s_vaddr = current->vma + pad;
-       section.s_paddr = current->vma + pad;
+       section.s_vaddr = current->lma + pad;
+       section.s_paddr = current->lma + pad;
        section.s_size = current->_raw_size - pad;
        /*
          If this section has no size or is unloadable then the scnptr
@@ -1529,10 +1633,10 @@ DEFUN(coff_write_object_contents,(abfd),
   internal_a.magic = PAGEMAGICBCS;
 #endif                         /* M88 */
 
-#if M68 || MIPS || WE32K
+#if M68 || WE32K
 #define __A_MAGIC_SET__
   /* Never was anything here for the 68k */
-#endif                         /* M68 || MIPS || WE32K */
+#endif                         /* M68 || WE32K */
 
 #if I386
 # define __A_MAGIC_SET__
@@ -1611,9 +1715,14 @@ DEFUN(coff_set_section_contents,(abfd, section, location, offset, count),
        right for SVR3.2.  Shared libraries should probably get more
        generic support.  Ian Taylor <ian@cygnus.com>.  */
     if (strcmp (section->name, _LIB) == 0)
-      ++section->vma;
+      ++section->lma;
 #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;
+
     bfd_seek(abfd, (file_ptr) (section->filepos + offset), SEEK_SET);
 
     if (count != 0) {
@@ -1792,7 +1901,7 @@ DEFUN(coff_slurp_symbol_table,(abfd),
       /*
        We use the native name field to point to the cached field
        */
-      src->u.syment._n._n_n._n_zeroes = (int) dst;
+      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;
@@ -1997,8 +2106,9 @@ SUBSUBSECTION
 
 #ifndef CALC_ADDEND
 #define CALC_ADDEND(abfd, ptr, reloc, cache_ptr)       \
-           if (ptr && bfd_asymbol_bfd(ptr) == abfd             \
-               && ((ptr->flags & BSF_OLD_COMMON)== 0)) \
+           if (ptr && bfd_asymbol_bfd(ptr) == abfd     \
+               && !bfd_is_com_section(ptr->section)    \
+               && !(ptr->flags & BSF_OLD_COMMON))      \
            {                                           \
                cache_ptr->addend = -(ptr->section->vma + ptr->value);  \
            }                                           \
@@ -2157,10 +2267,36 @@ bfd *abfd;
   }
 #endif
 
+#ifndef coff_reloc16_estimate
+#define coff_reloc16_estimate dummy_reloc16_estimate
+
+static dummy_reloc16_estimate(input_section, symbols, reloc, shrink)
+     asection *input_section;
+     asymbol **symbols;
+     arelent *reloc;
+     int shrink;
+{
+  abort();
+  
+}
+
+#endif
+
 #ifndef coff_reloc16_extra_cases
-#define coff_reloc16_extra_cases \
-  (void (*) PARAMS ((bfd *, bfd_seclet_type *, arelent *, bfd_byte *,\
-                    unsigned int *, unsigned int *))) abort
+#define coff_reloc16_extra_cases dummy_reloc16_extra_cases
+/* This works even if abort is not declared in any header file.  */
+static void
+dummy_reloc16_extra_cases (abfd, seclet, reloc, data, src_ptr, dst_ptr)
+     bfd *abfd;
+     struct bfd_seclet *seclet;
+     arelent *reloc;
+     bfd_byte *data;
+     unsigned int *src_ptr;
+     unsigned int *dst_ptr;
+{
+  fprintf(stderr, "%s\n", reloc->howto->name);
+  abort ();
+}
 #endif
 
 static CONST bfd_coff_backend_data bfd_coff_std_swap_table = {
@@ -2178,7 +2314,8 @@ static CONST bfd_coff_backend_data bfd_coff_std_swap_table = {
  coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in,
  coff_bad_format_hook, coff_set_arch_mach_hook, coff_mkobject_hook,
  styp_to_sec_flags, coff_make_section_hook, coff_set_alignment_hook,
- coff_slurp_symbol_table, symname_in_debug_hook, coff_reloc16_extra_cases
+ coff_slurp_symbol_table, symname_in_debug_hook, 
+ coff_reloc16_extra_cases, coff_reloc16_estimate
 };
 
 #define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
@@ -2198,3 +2335,6 @@ static CONST bfd_coff_backend_data bfd_coff_std_swap_table = {
                        (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
 #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_seclet_link           bfd_generic_seclet_link
+#define coff_bfd_reloc_type_lookup \
+  ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
This page took 0.028704 seconds and 4 git commands to generate.