Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* coff object file format
  2.    Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  3.    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010
  4.    Free Software Foundation, Inc.
  5.  
  6.    This file is part of GAS.
  7.  
  8.    GAS is free software; you can redistribute it and/or modify
  9.    it under the terms of the GNU General Public License as published by
  10.    the Free Software Foundation; either version 3, or (at your option)
  11.    any later version.
  12.  
  13.    GAS is distributed in the hope that it will be useful,
  14.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    GNU General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with GAS; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  21.    02110-1301, USA.  */
  22.  
  23. #define OBJ_HEADER "obj-coff.h"
  24.  
  25. #include "as.h"
  26. #include "safe-ctype.h"
  27. #include "obstack.h"
  28. #include "subsegs.h"
  29. #include "struc-symbol.h"
  30.  
  31. #ifdef TE_PE
  32. #include "coff/pe.h"
  33. #endif
  34.  
  35. #ifdef OBJ_XCOFF
  36. #include "coff/xcoff.h"
  37. #endif
  38.  
  39. #define streq(a,b)     (strcmp ((a), (b)) == 0)
  40. #define strneq(a,b,n)  (strncmp ((a), (b), (n)) == 0)
  41.  
  42. /* I think this is probably always correct.  */
  43. #ifndef KEEP_RELOC_INFO
  44. #define KEEP_RELOC_INFO
  45. #endif
  46.  
  47. /* obj_coff_section will use this macro to set a new section's
  48.    attributes when a directive has no valid flags or the "w" flag is
  49.    used.  This default should be appropriate for most.  */
  50. #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
  51. #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
  52. #endif
  53.  
  54. /* This is used to hold the symbol built by a sequence of pseudo-ops
  55.    from .def and .endef.  */
  56. static symbolS *def_symbol_in_progress;
  57. #ifdef TE_PE
  58. /* PE weak alternate symbols begin with this string.  */
  59. static const char weak_altprefix[] = ".weak.";
  60. #endif /* TE_PE */
  61.  
  62. #include "obj-coff-seh.c"
  63.  
  64. typedef struct
  65.   {
  66.     unsigned long chunk_size;
  67.     unsigned long element_size;
  68.     unsigned long size;
  69.     char *data;
  70.     unsigned long pointer;
  71.   }
  72. stack;
  73.  
  74. /* Stack stuff.  */
  75.  
  76. static stack *
  77. stack_init (unsigned long chunk_size,
  78.             unsigned long element_size)
  79. {
  80.   stack *st;
  81.  
  82.   st = malloc (sizeof (* st));
  83.   if (!st)
  84.     return NULL;
  85.   st->data = malloc (chunk_size);
  86.   if (!st->data)
  87.     {
  88.       free (st);
  89.       return NULL;
  90.     }
  91.   st->pointer = 0;
  92.   st->size = chunk_size;
  93.   st->chunk_size = chunk_size;
  94.   st->element_size = element_size;
  95.   return st;
  96. }
  97.  
  98. static char *
  99. stack_push (stack *st, char *element)
  100. {
  101.   if (st->pointer + st->element_size >= st->size)
  102.     {
  103.       st->size += st->chunk_size;
  104.       if ((st->data = xrealloc (st->data, st->size)) == NULL)
  105.         return NULL;
  106.     }
  107.   memcpy (st->data + st->pointer, element, st->element_size);
  108.   st->pointer += st->element_size;
  109.   return st->data + st->pointer;
  110. }
  111.  
  112. static char *
  113. stack_pop (stack *st)
  114. {
  115.   if (st->pointer < st->element_size)
  116.     {
  117.       st->pointer = 0;
  118.       return NULL;
  119.     }
  120.   st->pointer -= st->element_size;
  121.   return st->data + st->pointer;
  122. }
  123. /* Maintain a list of the tagnames of the structures.  */
  124.  
  125. static struct hash_control *tag_hash;
  126.  
  127. static void
  128. tag_init (void)
  129. {
  130.   tag_hash = hash_new ();
  131. }
  132.  
  133. static void
  134. tag_insert (const char *name, symbolS *symbolP)
  135. {
  136.   const char *error_string;
  137.  
  138.   if ((error_string = hash_jam (tag_hash, name, (char *) symbolP)))
  139.     as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
  140.               name, error_string);
  141. }
  142.  
  143. static symbolS *
  144. tag_find (char *name)
  145. {
  146.   return (symbolS *) hash_find (tag_hash, name);
  147. }
  148.  
  149. static symbolS *
  150. tag_find_or_make (char *name)
  151. {
  152.   symbolS *symbolP;
  153.  
  154.   if ((symbolP = tag_find (name)) == NULL)
  155.     {
  156.       symbolP = symbol_new (name, undefined_section,
  157.                             0, &zero_address_frag);
  158.  
  159.       tag_insert (S_GET_NAME (symbolP), symbolP);
  160.       symbol_table_insert (symbolP);
  161.     }
  162.  
  163.   return symbolP;
  164. }
  165.  
  166. /* We accept the .bss directive to set the section for backward
  167.    compatibility with earlier versions of gas.  */
  168.  
  169. static void
  170. obj_coff_bss (int ignore ATTRIBUTE_UNUSED)
  171. {
  172.   if (*input_line_pointer == '\n')
  173.     subseg_new (".bss", get_absolute_expression ());
  174.   else
  175.     s_lcomm (0);
  176. }
  177.  
  178. #ifdef TE_PE
  179. /* Called from read.c:s_comm after we've parsed .comm symbol, size.
  180.    Parse a possible alignment value.  */
  181.  
  182. static symbolS *
  183. obj_coff_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size)
  184. {
  185.   addressT align = 0;
  186.  
  187.   if (*input_line_pointer == ',')
  188.     {
  189.       align = parse_align (0);
  190.       if (align == (addressT) -1)
  191.         return NULL;
  192.     }
  193.  
  194.   S_SET_VALUE (symbolP, size);
  195.   S_SET_EXTERNAL (symbolP);
  196.   S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
  197.  
  198.   symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
  199.  
  200.   /* There is no S_SET_ALIGN (symbolP, align) in COFF/PE.
  201.      Instead we must add a note to the .drectve section.  */
  202.   if (align)
  203.     {
  204.       segT current_seg = now_seg;
  205.       subsegT current_subseg = now_subseg;
  206.       flagword oldflags;
  207.       asection *sec;
  208.       size_t pfxlen, numlen;
  209.       char *frag;
  210.       char numbuff[20];
  211.  
  212.       sec = subseg_new (".drectve", 0);
  213.       oldflags = bfd_get_section_flags (stdoutput, sec);
  214.       if (oldflags == SEC_NO_FLAGS)
  215.         {
  216.           if (!bfd_set_section_flags (stdoutput, sec,
  217.                 TC_COFF_SECTION_DEFAULT_ATTRIBUTES))
  218.             as_warn (_("error setting flags for \"%s\": %s"),
  219.                 bfd_section_name (stdoutput, sec),
  220.                 bfd_errmsg (bfd_get_error ()));
  221.         }
  222.  
  223.       /* Emit a string.  Note no NUL-termination.  */
  224.       pfxlen = strlen (" -aligncomm:") + 2 + strlen (S_GET_NAME (symbolP)) + 1;
  225.       numlen = snprintf (numbuff, sizeof (numbuff), "%d", (int) align);
  226.       frag = frag_more (pfxlen + numlen);
  227.       (void) sprintf (frag, " -aligncomm:\"%s\",", S_GET_NAME (symbolP));
  228.       memcpy (frag + pfxlen, numbuff, numlen);
  229.       /* Restore original subseg. */
  230.       subseg_set (current_seg, current_subseg);
  231.     }
  232.  
  233.   return symbolP;
  234. }
  235.  
  236. static void
  237. obj_coff_comm (int ignore ATTRIBUTE_UNUSED)
  238. {
  239.   s_comm_internal (ignore, obj_coff_common_parse);
  240. }
  241. #endif /* TE_PE */
  242.  
  243. #define GET_FILENAME_STRING(X) \
  244.   ((char *) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
  245.  
  246. /* @@ Ick.  */
  247. static segT
  248. fetch_coff_debug_section (void)
  249. {
  250.   static segT debug_section;
  251.  
  252.   if (!debug_section)
  253.     {
  254.       const asymbol *s;
  255.  
  256.       s = bfd_make_debug_symbol (stdoutput, NULL, 0);
  257.       gas_assert (s != 0);
  258.       debug_section = s->section;
  259.     }
  260.   return debug_section;
  261. }
  262.  
  263. void
  264. SA_SET_SYM_ENDNDX (symbolS *sym, symbolS *val)
  265. {
  266.   combined_entry_type *entry, *p;
  267.  
  268.   entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
  269.   p = coffsymbol (symbol_get_bfdsym (val))->native;
  270.   entry->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p = p;
  271.   entry->fix_end = 1;
  272. }
  273.  
  274. static void
  275. SA_SET_SYM_TAGNDX (symbolS *sym, symbolS *val)
  276. {
  277.   combined_entry_type *entry, *p;
  278.  
  279.   entry = &coffsymbol (symbol_get_bfdsym (sym))->native[1];
  280.   p = coffsymbol (symbol_get_bfdsym (val))->native;
  281.   entry->u.auxent.x_sym.x_tagndx.p = p;
  282.   entry->fix_tag = 1;
  283. }
  284.  
  285. static int
  286. S_GET_DATA_TYPE (symbolS *sym)
  287. {
  288.   return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type;
  289. }
  290.  
  291. int
  292. S_SET_DATA_TYPE (symbolS *sym, int val)
  293. {
  294.   coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_type = val;
  295.   return val;
  296. }
  297.  
  298. int
  299. S_GET_STORAGE_CLASS (symbolS *sym)
  300. {
  301.   return coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass;
  302. }
  303.  
  304. int
  305. S_SET_STORAGE_CLASS (symbolS *sym, int val)
  306. {
  307.   coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_sclass = val;
  308.   return val;
  309. }
  310.  
  311. /* Merge a debug symbol containing debug information into a normal symbol.  */
  312.  
  313. static void
  314. c_symbol_merge (symbolS *debug, symbolS *normal)
  315. {
  316.   S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug));
  317.   S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug));
  318.  
  319.   if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal))
  320.     /* Take the most we have.  */
  321.     S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug));
  322.  
  323.   if (S_GET_NUMBER_AUXILIARY (debug) > 0)
  324.     /* Move all the auxiliary information.  */
  325.     memcpy (SYM_AUXINFO (normal), SYM_AUXINFO (debug),
  326.             (S_GET_NUMBER_AUXILIARY (debug)
  327.              * sizeof (*SYM_AUXINFO (debug))));
  328.  
  329.   /* Move the debug flags.  */
  330.   SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug));
  331. }
  332.  
  333. void
  334. c_dot_file_symbol (const char *filename, int appfile ATTRIBUTE_UNUSED)
  335. {
  336.   symbolS *symbolP;
  337.  
  338.   /* BFD converts filename to a .file symbol with an aux entry.  It
  339.      also handles chaining.  */
  340.   symbolP = symbol_new (filename, bfd_abs_section_ptr, 0, &zero_address_frag);
  341.  
  342.   S_SET_STORAGE_CLASS (symbolP, C_FILE);
  343.   S_SET_NUMBER_AUXILIARY (symbolP, 1);
  344.  
  345.   symbol_get_bfdsym (symbolP)->flags = BSF_DEBUGGING;
  346.  
  347. #ifndef NO_LISTING
  348.   {
  349.     extern int listing;
  350.  
  351.     if (listing)
  352.       listing_source_file (filename);
  353.   }
  354. #endif
  355.  
  356.   /* Make sure that the symbol is first on the symbol chain.  */
  357.   if (symbol_rootP != symbolP)
  358.     {
  359.       symbol_remove (symbolP, &symbol_rootP, &symbol_lastP);
  360.       symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP);
  361.     }
  362. }
  363.  
  364. /* Line number handling.  */
  365.  
  366. struct line_no
  367. {
  368.   struct line_no *next;
  369.   fragS *frag;
  370.   alent l;
  371. };
  372.  
  373. int coff_line_base;
  374.  
  375. /* Symbol of last function, which we should hang line#s off of.  */
  376. static symbolS *line_fsym;
  377.  
  378. #define in_function()           (line_fsym != 0)
  379. #define clear_function()        (line_fsym = 0)
  380. #define set_function(F)         (line_fsym = (F), coff_add_linesym (F))
  381.  
  382. void
  383. coff_obj_symbol_new_hook (symbolS *symbolP)
  384. {
  385.   long   sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
  386.   char * s  = xmalloc (sz);
  387.  
  388.   memset (s, 0, sz);
  389.   coffsymbol (symbol_get_bfdsym (symbolP))->native = (combined_entry_type *) s;
  390.  
  391.   S_SET_DATA_TYPE (symbolP, T_NULL);
  392.   S_SET_STORAGE_CLASS (symbolP, 0);
  393.   S_SET_NUMBER_AUXILIARY (symbolP, 0);
  394.  
  395.   if (S_IS_STRING (symbolP))
  396.     SF_SET_STRING (symbolP);
  397.  
  398.   if (S_IS_LOCAL (symbolP))
  399.     SF_SET_LOCAL (symbolP);
  400. }
  401.  
  402. void
  403. coff_obj_symbol_clone_hook (symbolS *newsymP, symbolS *orgsymP)
  404. {
  405.   long sz = (OBJ_COFF_MAX_AUXENTRIES + 1) * sizeof (combined_entry_type);
  406.   combined_entry_type * s = xmalloc (sz);
  407.  
  408.   memcpy (s, coffsymbol (symbol_get_bfdsym (orgsymP))->native, sz);
  409.   coffsymbol (symbol_get_bfdsym (newsymP))->native = s;
  410.  
  411.   SF_SET (newsymP, SF_GET (orgsymP));
  412. }
  413.  
  414. /* Handle .ln directives.  */
  415.  
  416. static symbolS *current_lineno_sym;
  417. static struct line_no *line_nos;
  418. /* FIXME:  Blindly assume all .ln directives will be in the .text section.  */
  419. int coff_n_line_nos;
  420.  
  421. static void
  422. add_lineno (fragS * frag, addressT offset, int num)
  423. {
  424.   struct line_no * new_line = xmalloc (sizeof (* new_line));
  425.  
  426.   if (!current_lineno_sym)
  427.     abort ();
  428.  
  429. #ifndef OBJ_XCOFF
  430.   /* The native aix assembler accepts negative line number.  */
  431.  
  432.   if (num <= 0)
  433.     {
  434.       /* Zero is used as an end marker in the file.  */
  435.       as_warn (_("Line numbers must be positive integers\n"));
  436.       num = 1;
  437.     }
  438. #endif /* OBJ_XCOFF */
  439.   new_line->next = line_nos;
  440.   new_line->frag = frag;
  441.   new_line->l.line_number = num;
  442.   new_line->l.u.offset = offset;
  443.   line_nos = new_line;
  444.   coff_n_line_nos++;
  445. }
  446.  
  447. void
  448. coff_add_linesym (symbolS *sym)
  449. {
  450.   if (line_nos)
  451.     {
  452.       coffsymbol (symbol_get_bfdsym (current_lineno_sym))->lineno =
  453.         (alent *) line_nos;
  454.       coff_n_line_nos++;
  455.       line_nos = 0;
  456.     }
  457.   current_lineno_sym = sym;
  458. }
  459.  
  460. static void
  461. obj_coff_ln (int appline)
  462. {
  463.   int l;
  464.  
  465.   if (! appline && def_symbol_in_progress != NULL)
  466.     {
  467.       as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
  468.       demand_empty_rest_of_line ();
  469.       return;
  470.     }
  471.  
  472.   l = get_absolute_expression ();
  473.  
  474.   /* If there is no lineno symbol, treat a .ln
  475.      directive as if it were a .appline directive.  */
  476.   if (appline || current_lineno_sym == NULL)
  477.     new_logical_line ((char *) NULL, l - 1);
  478.   else
  479.     add_lineno (frag_now, frag_now_fix (), l);
  480.  
  481. #ifndef NO_LISTING
  482.   {
  483.     extern int listing;
  484.  
  485.     if (listing)
  486.       {
  487.         if (! appline)
  488.           l += coff_line_base - 1;
  489.         listing_source_line (l);
  490.       }
  491.   }
  492. #endif
  493.  
  494.   demand_empty_rest_of_line ();
  495. }
  496.  
  497. /* .loc is essentially the same as .ln; parse it for assembler
  498.    compatibility.  */
  499.  
  500. static void
  501. obj_coff_loc (int ignore ATTRIBUTE_UNUSED)
  502. {
  503.   int lineno;
  504.  
  505.   /* FIXME: Why do we need this check?  We need it for ECOFF, but why
  506.      do we need it for COFF?  */
  507.   if (now_seg != text_section)
  508.     {
  509.       as_warn (_(".loc outside of .text"));
  510.       demand_empty_rest_of_line ();
  511.       return;
  512.     }
  513.  
  514.   if (def_symbol_in_progress != NULL)
  515.     {
  516.       as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
  517.       demand_empty_rest_of_line ();
  518.       return;
  519.     }
  520.  
  521.   /* Skip the file number.  */
  522.   SKIP_WHITESPACE ();
  523.   get_absolute_expression ();
  524.   SKIP_WHITESPACE ();
  525.  
  526.   lineno = get_absolute_expression ();
  527.  
  528. #ifndef NO_LISTING
  529.   {
  530.     extern int listing;
  531.  
  532.     if (listing)
  533.       {
  534.         lineno += coff_line_base - 1;
  535.         listing_source_line (lineno);
  536.       }
  537.   }
  538. #endif
  539.  
  540.   demand_empty_rest_of_line ();
  541.  
  542.   add_lineno (frag_now, frag_now_fix (), lineno);
  543. }
  544.  
  545. /* Handle the .ident pseudo-op.  */
  546.  
  547. static void
  548. obj_coff_ident (int ignore ATTRIBUTE_UNUSED)
  549. {
  550.   segT current_seg = now_seg;
  551.   subsegT current_subseg = now_subseg;
  552.  
  553. #ifdef TE_PE
  554.   {
  555.     segT sec;
  556.  
  557.     /* We could put it in .comment, but that creates an extra section
  558.        that shouldn't be loaded into memory, which requires linker
  559.        changes...  For now, until proven otherwise, use .rdata.  */
  560.     sec = subseg_new (".rdata$zzz", 0);
  561.     bfd_set_section_flags (stdoutput, sec,
  562.                            ((SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA)
  563.                             & bfd_applicable_section_flags (stdoutput)));
  564.   }
  565. #else
  566.   subseg_new (".comment", 0);
  567. #endif
  568.  
  569.   stringer (8 + 1);
  570.   subseg_set (current_seg, current_subseg);
  571. }
  572.  
  573. /* Handle .def directives.
  574.  
  575.    One might ask : why can't we symbol_new if the symbol does not
  576.    already exist and fill it with debug information.  Because of
  577.    the C_EFCN special symbol. It would clobber the value of the
  578.    function symbol before we have a chance to notice that it is
  579.    a C_EFCN. And a second reason is that the code is more clear this
  580.    way. (at least I think it is :-).  */
  581.  
  582. #define SKIP_SEMI_COLON()       while (*input_line_pointer++ != ';')
  583. #define SKIP_WHITESPACES()      while (*input_line_pointer == ' ' || \
  584.                                        *input_line_pointer == '\t')  \
  585.                                   input_line_pointer++;
  586.  
  587. static void
  588. obj_coff_def (int what ATTRIBUTE_UNUSED)
  589. {
  590.   char name_end;                /* Char after the end of name.  */
  591.   char *symbol_name;            /* Name of the debug symbol.  */
  592.   char *symbol_name_copy;       /* Temporary copy of the name.  */
  593.   unsigned int symbol_name_length;
  594.  
  595.   if (def_symbol_in_progress != NULL)
  596.     {
  597.       as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
  598.       demand_empty_rest_of_line ();
  599.       return;
  600.     }
  601.  
  602.   SKIP_WHITESPACES ();
  603.  
  604.   symbol_name = input_line_pointer;
  605.   name_end = get_symbol_end ();
  606.   symbol_name_length = strlen (symbol_name);
  607.   symbol_name_copy = xmalloc (symbol_name_length + 1);
  608.   strcpy (symbol_name_copy, symbol_name);
  609. #ifdef tc_canonicalize_symbol_name
  610.   symbol_name_copy = tc_canonicalize_symbol_name (symbol_name_copy);
  611. #endif
  612.  
  613.   /* Initialize the new symbol.  */
  614.   def_symbol_in_progress = symbol_make (symbol_name_copy);
  615.   symbol_set_frag (def_symbol_in_progress, &zero_address_frag);
  616.   S_SET_VALUE (def_symbol_in_progress, 0);
  617.  
  618.   if (S_IS_STRING (def_symbol_in_progress))
  619.     SF_SET_STRING (def_symbol_in_progress);
  620.  
  621.   *input_line_pointer = name_end;
  622.  
  623.   demand_empty_rest_of_line ();
  624. }
  625.  
  626. static void
  627. obj_coff_endef (int ignore ATTRIBUTE_UNUSED)
  628. {
  629.   symbolS *symbolP = NULL;
  630.  
  631.   if (def_symbol_in_progress == NULL)
  632.     {
  633.       as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
  634.       demand_empty_rest_of_line ();
  635.       return;
  636.     }
  637.  
  638.   /* Set the section number according to storage class.  */
  639.   switch (S_GET_STORAGE_CLASS (def_symbol_in_progress))
  640.     {
  641.     case C_STRTAG:
  642.     case C_ENTAG:
  643.     case C_UNTAG:
  644.       SF_SET_TAG (def_symbol_in_progress);
  645.       /* Fall through.  */
  646.     case C_FILE:
  647.     case C_TPDEF:
  648.       SF_SET_DEBUG (def_symbol_in_progress);
  649.       S_SET_SEGMENT (def_symbol_in_progress, fetch_coff_debug_section ());
  650.       break;
  651.  
  652.     case C_EFCN:
  653.       SF_SET_LOCAL (def_symbol_in_progress);    /* Do not emit this symbol.  */
  654.       /* Fall through.  */
  655.     case C_BLOCK:
  656.       SF_SET_PROCESS (def_symbol_in_progress);  /* Will need processing before writing.  */
  657.       /* Fall through.  */
  658.     case C_FCN:
  659.       {
  660.         const char *name;
  661.  
  662.         S_SET_SEGMENT (def_symbol_in_progress, text_section);
  663.  
  664.         name = S_GET_NAME (def_symbol_in_progress);
  665.         if (name[0] == '.' && name[2] == 'f' && name[3] == '\0')
  666.           {
  667.             switch (name[1])
  668.               {
  669.               case 'b':
  670.                 /* .bf */
  671.                 if (! in_function ())
  672.                   as_warn (_("`%s' symbol without preceding function"), name);
  673.                 /* Will need relocating.  */
  674.                 SF_SET_PROCESS (def_symbol_in_progress);
  675.                 clear_function ();
  676.                 break;
  677. #ifdef TE_PE
  678.               case 'e':
  679.                 /* .ef */
  680.                 /* The MS compilers output the actual endline, not the
  681.                    function-relative one... we want to match without
  682.                    changing the assembler input.  */
  683.                 SA_SET_SYM_LNNO (def_symbol_in_progress,
  684.                                  (SA_GET_SYM_LNNO (def_symbol_in_progress)
  685.                                   + coff_line_base));
  686.                 break;
  687. #endif
  688.               }
  689.           }
  690.       }
  691.       break;
  692.  
  693. #ifdef C_AUTOARG
  694.     case C_AUTOARG:
  695. #endif /* C_AUTOARG */
  696.     case C_AUTO:
  697.     case C_REG:
  698.     case C_ARG:
  699.     case C_REGPARM:
  700.     case C_FIELD:
  701.  
  702.     /* According to the COFF documentation:
  703.  
  704.        http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
  705.  
  706.        A special section number (-2) marks symbolic debugging symbols,
  707.        including structure/union/enumeration tag names, typedefs, and
  708.        the name of the file. A section number of -1 indicates that the
  709.        symbol has a value but is not relocatable. Examples of
  710.        absolute-valued symbols include automatic and register variables,
  711.        function arguments, and .eos symbols.
  712.  
  713.        But from Ian Lance Taylor:
  714.  
  715.        http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
  716.  
  717.        the actual tools all marked them as section -1. So the GNU COFF
  718.        assembler follows historical COFF assemblers.
  719.  
  720.        However, it causes problems for djgpp
  721.  
  722.        http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
  723.  
  724.        By defining STRICTCOFF, a COFF port can make the assembler to
  725.        follow the documented behavior.  */
  726. #ifdef STRICTCOFF
  727.     case C_MOS:
  728.     case C_MOE:
  729.     case C_MOU:
  730.     case C_EOS:
  731. #endif
  732.       SF_SET_DEBUG (def_symbol_in_progress);
  733.       S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
  734.       break;
  735.  
  736. #ifndef STRICTCOFF
  737.     case C_MOS:
  738.     case C_MOE:
  739.     case C_MOU:
  740.     case C_EOS:
  741.       S_SET_SEGMENT (def_symbol_in_progress, absolute_section);
  742.       break;
  743. #endif
  744.  
  745.     case C_EXT:
  746.     case C_WEAKEXT:
  747. #ifdef TE_PE
  748.     case C_NT_WEAK:
  749. #endif
  750.     case C_STAT:
  751.     case C_LABEL:
  752.       /* Valid but set somewhere else (s_comm, s_lcomm, colon).  */
  753.       break;
  754.  
  755.     default:
  756.     case C_USTATIC:
  757.     case C_EXTDEF:
  758.     case C_ULABEL:
  759.       as_warn (_("unexpected storage class %d"),
  760.                S_GET_STORAGE_CLASS (def_symbol_in_progress));
  761.       break;
  762.     }
  763.  
  764.   /* Now that we have built a debug symbol, try to find if we should
  765.      merge with an existing symbol or not.  If a symbol is C_EFCN or
  766.      absolute_section or untagged SEG_DEBUG it never merges.  We also
  767.      don't merge labels, which are in a different namespace, nor
  768.      symbols which have not yet been defined since they are typically
  769.      unique, nor do we merge tags with non-tags.  */
  770.  
  771.   /* Two cases for functions.  Either debug followed by definition or
  772.      definition followed by debug.  For definition first, we will
  773.      merge the debug symbol into the definition.  For debug first, the
  774.      lineno entry MUST point to the definition function or else it
  775.      will point off into space when obj_crawl_symbol_chain() merges
  776.      the debug symbol into the real symbol.  Therefor, let's presume
  777.      the debug symbol is a real function reference.  */
  778.  
  779.   /* FIXME-SOON If for some reason the definition label/symbol is
  780.      never seen, this will probably leave an undefined symbol at link
  781.      time.  */
  782.  
  783.   if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN
  784.       || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL
  785.       || (streq (bfd_get_section_name (stdoutput,
  786.                                        S_GET_SEGMENT (def_symbol_in_progress)),
  787.                  "*DEBUG*")
  788.           && !SF_GET_TAG (def_symbol_in_progress))
  789.       || S_GET_SEGMENT (def_symbol_in_progress) == absolute_section
  790.       || ! symbol_constant_p (def_symbol_in_progress)
  791.       || (symbolP = symbol_find (S_GET_NAME (def_symbol_in_progress))) == NULL
  792.       || SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))
  793.     {
  794.       /* If it already is at the end of the symbol list, do nothing */
  795.       if (def_symbol_in_progress != symbol_lastP)
  796.         {
  797.           symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
  798.           symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP,
  799.                          &symbol_lastP);
  800.         }
  801.     }
  802.   else
  803.     {
  804.       /* This symbol already exists, merge the newly created symbol
  805.          into the old one.  This is not mandatory. The linker can
  806.          handle duplicate symbols correctly. But I guess that it save
  807.          a *lot* of space if the assembly file defines a lot of
  808.          symbols. [loic]  */
  809.  
  810.       /* The debug entry (def_symbol_in_progress) is merged into the
  811.          previous definition.  */
  812.  
  813.       c_symbol_merge (def_symbol_in_progress, symbolP);
  814.       symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
  815.  
  816.       def_symbol_in_progress = symbolP;
  817.  
  818.       if (SF_GET_FUNCTION (def_symbol_in_progress)
  819.           || SF_GET_TAG (def_symbol_in_progress)
  820.           || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_STAT)
  821.         {
  822.           /* For functions, and tags, and static symbols, the symbol
  823.              *must* be where the debug symbol appears.  Move the
  824.              existing symbol to the current place.  */
  825.           /* If it already is at the end of the symbol list, do nothing.  */
  826.           if (def_symbol_in_progress != symbol_lastP)
  827.             {
  828.               symbol_remove (def_symbol_in_progress, &symbol_rootP, &symbol_lastP);
  829.               symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, &symbol_lastP);
  830.             }
  831.         }
  832.     }
  833.  
  834.   if (SF_GET_TAG (def_symbol_in_progress))
  835.     {
  836.       symbolS *oldtag;
  837.  
  838.       oldtag = symbol_find (S_GET_NAME (def_symbol_in_progress));
  839.       if (oldtag == NULL || ! SF_GET_TAG (oldtag))
  840.         tag_insert (S_GET_NAME (def_symbol_in_progress),
  841.                     def_symbol_in_progress);
  842.     }
  843.  
  844.   if (SF_GET_FUNCTION (def_symbol_in_progress))
  845.     {
  846.       set_function (def_symbol_in_progress);
  847.       SF_SET_PROCESS (def_symbol_in_progress);
  848.  
  849.       if (symbolP == NULL)
  850.         /* That is, if this is the first time we've seen the
  851.            function.  */
  852.         symbol_table_insert (def_symbol_in_progress);
  853.  
  854.     }
  855.  
  856.   def_symbol_in_progress = NULL;
  857.   demand_empty_rest_of_line ();
  858. }
  859.  
  860. static void
  861. obj_coff_dim (int ignore ATTRIBUTE_UNUSED)
  862. {
  863.   int d_index;
  864.  
  865.   if (def_symbol_in_progress == NULL)
  866.     {
  867.       as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
  868.       demand_empty_rest_of_line ();
  869.       return;
  870.     }
  871.  
  872.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  873.  
  874.   for (d_index = 0; d_index < DIMNUM; d_index++)
  875.     {
  876.       SKIP_WHITESPACES ();
  877.       SA_SET_SYM_DIMEN (def_symbol_in_progress, d_index,
  878.                         get_absolute_expression ());
  879.  
  880.       switch (*input_line_pointer)
  881.         {
  882.         case ',':
  883.           input_line_pointer++;
  884.           break;
  885.  
  886.         default:
  887.           as_warn (_("badly formed .dim directive ignored"));
  888.           /* Fall through.  */
  889.         case '\n':
  890.         case ';':
  891.           d_index = DIMNUM;
  892.           break;
  893.         }
  894.     }
  895.  
  896.   demand_empty_rest_of_line ();
  897. }
  898.  
  899. static void
  900. obj_coff_line (int ignore ATTRIBUTE_UNUSED)
  901. {
  902.   int this_base;
  903.  
  904.   if (def_symbol_in_progress == NULL)
  905.     {
  906.       /* Probably stabs-style line?  */
  907.       obj_coff_ln (0);
  908.       return;
  909.     }
  910.  
  911.   this_base = get_absolute_expression ();
  912.   if (streq (".bf", S_GET_NAME (def_symbol_in_progress)))
  913.     coff_line_base = this_base;
  914.  
  915.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  916.   SA_SET_SYM_LNNO (def_symbol_in_progress, this_base);
  917.  
  918.   demand_empty_rest_of_line ();
  919.  
  920. #ifndef NO_LISTING
  921.   if (streq (".bf", S_GET_NAME (def_symbol_in_progress)))
  922.     {
  923.       extern int listing;
  924.  
  925.       if (listing)
  926.         listing_source_line ((unsigned int) this_base);
  927.     }
  928. #endif
  929. }
  930.  
  931. static void
  932. obj_coff_size (int ignore ATTRIBUTE_UNUSED)
  933. {
  934.   if (def_symbol_in_progress == NULL)
  935.     {
  936.       as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
  937.       demand_empty_rest_of_line ();
  938.       return;
  939.     }
  940.  
  941.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  942.   SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ());
  943.   demand_empty_rest_of_line ();
  944. }
  945.  
  946. static void
  947. obj_coff_scl (int ignore ATTRIBUTE_UNUSED)
  948. {
  949.   if (def_symbol_in_progress == NULL)
  950.     {
  951.       as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
  952.       demand_empty_rest_of_line ();
  953.       return;
  954.     }
  955.  
  956.   S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ());
  957.   demand_empty_rest_of_line ();
  958. }
  959.  
  960. static void
  961. obj_coff_tag (int ignore ATTRIBUTE_UNUSED)
  962. {
  963.   char *symbol_name;
  964.   char name_end;
  965.  
  966.   if (def_symbol_in_progress == NULL)
  967.     {
  968.       as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
  969.       demand_empty_rest_of_line ();
  970.       return;
  971.     }
  972.  
  973.   S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1);
  974.   symbol_name = input_line_pointer;
  975.   name_end = get_symbol_end ();
  976.  
  977. #ifdef tc_canonicalize_symbol_name
  978.   symbol_name = tc_canonicalize_symbol_name (symbol_name);
  979. #endif
  980.  
  981.   /* Assume that the symbol referred to by .tag is always defined.
  982.      This was a bad assumption.  I've added find_or_make. xoxorich.  */
  983.   SA_SET_SYM_TAGNDX (def_symbol_in_progress,
  984.                      tag_find_or_make (symbol_name));
  985.   if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L)
  986.     as_warn (_("tag not found for .tag %s"), symbol_name);
  987.  
  988.   SF_SET_TAGGED (def_symbol_in_progress);
  989.   *input_line_pointer = name_end;
  990.  
  991.   demand_empty_rest_of_line ();
  992. }
  993.  
  994. static void
  995. obj_coff_type (int ignore ATTRIBUTE_UNUSED)
  996. {
  997.   if (def_symbol_in_progress == NULL)
  998.     {
  999.       as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
  1000.       demand_empty_rest_of_line ();
  1001.       return;
  1002.     }
  1003.  
  1004.   S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ());
  1005.  
  1006.   if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) &&
  1007.       S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF)
  1008.     SF_SET_FUNCTION (def_symbol_in_progress);
  1009.  
  1010.   demand_empty_rest_of_line ();
  1011. }
  1012.  
  1013. static void
  1014. obj_coff_val (int ignore ATTRIBUTE_UNUSED)
  1015. {
  1016.   if (def_symbol_in_progress == NULL)
  1017.     {
  1018.       as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
  1019.       demand_empty_rest_of_line ();
  1020.       return;
  1021.     }
  1022.  
  1023.   if (is_name_beginner (*input_line_pointer))
  1024.     {
  1025.       char *symbol_name = input_line_pointer;
  1026.       char name_end = get_symbol_end ();
  1027.  
  1028. #ifdef tc_canonicalize_symbol_name
  1029.   symbol_name = tc_canonicalize_symbol_name (symbol_name);
  1030. #endif
  1031.       if (streq (symbol_name, "."))
  1032.         {
  1033.           /* If the .val is != from the .def (e.g. statics).  */
  1034.           symbol_set_frag (def_symbol_in_progress, frag_now);
  1035.           S_SET_VALUE (def_symbol_in_progress, (valueT) frag_now_fix ());
  1036.         }
  1037.       else if (! streq (S_GET_NAME (def_symbol_in_progress), symbol_name))
  1038.         {
  1039.           expressionS exp;
  1040.  
  1041.           exp.X_op = O_symbol;
  1042.           exp.X_add_symbol = symbol_find_or_make (symbol_name);
  1043.           exp.X_op_symbol = NULL;
  1044.           exp.X_add_number = 0;
  1045.           symbol_set_value_expression (def_symbol_in_progress, &exp);
  1046.  
  1047.           /* If the segment is undefined when the forward reference is
  1048.              resolved, then copy the segment id from the forward
  1049.              symbol.  */
  1050.           SF_SET_GET_SEGMENT (def_symbol_in_progress);
  1051.  
  1052.           /* FIXME: gcc can generate address expressions here in
  1053.              unusual cases (search for "obscure" in sdbout.c).  We
  1054.              just ignore the offset here, thus generating incorrect
  1055.              debugging information.  We ignore the rest of the line
  1056.              just below.  */
  1057.         }
  1058.       /* Otherwise, it is the name of a non debug symbol and its value
  1059.          will be calculated later.  */
  1060.       *input_line_pointer = name_end;
  1061.     }
  1062.   else
  1063.     {
  1064.       S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ());
  1065.     }
  1066.  
  1067.   demand_empty_rest_of_line ();
  1068. }
  1069.  
  1070. #ifdef TE_PE
  1071.  
  1072. /* Return nonzero if name begins with weak alternate symbol prefix.  */
  1073.  
  1074. static int
  1075. weak_is_altname (const char * name)
  1076. {
  1077.   return strneq (name, weak_altprefix, sizeof (weak_altprefix) - 1);
  1078. }
  1079.  
  1080. /* Return the name of the alternate symbol
  1081.    name corresponding to a weak symbol's name.  */
  1082.  
  1083. static const char *
  1084. weak_name2altname (const char * name)
  1085. {
  1086.   char *alt_name;
  1087.  
  1088.   alt_name = xmalloc (sizeof (weak_altprefix) + strlen (name));
  1089.   strcpy (alt_name, weak_altprefix);
  1090.   return strcat (alt_name, name);
  1091. }
  1092.  
  1093. /* Return the name of the weak symbol corresponding to an
  1094.    alternate symbol.  */
  1095.  
  1096. static const char *
  1097. weak_altname2name (const char * name)
  1098. {
  1099.   gas_assert (weak_is_altname (name));
  1100.   return xstrdup (name + 6);
  1101. }
  1102.  
  1103. /* Make a weak symbol name unique by
  1104.    appending the name of an external symbol.  */
  1105.  
  1106. static const char *
  1107. weak_uniquify (const char * name)
  1108. {
  1109.   char *ret;
  1110.   const char * unique = "";
  1111.  
  1112. #ifdef TE_PE
  1113.   if (an_external_name != NULL)
  1114.     unique = an_external_name;
  1115. #endif
  1116.   gas_assert (weak_is_altname (name));
  1117.  
  1118.   ret = xmalloc (strlen (name) + strlen (unique) + 2);
  1119.   strcpy (ret, name);
  1120.   strcat (ret, ".");
  1121.   strcat (ret, unique);
  1122.   return ret;
  1123. }
  1124.  
  1125. void
  1126. pecoff_obj_set_weak_hook (symbolS *symbolP)
  1127. {
  1128.   symbolS *alternateP;
  1129.  
  1130.   /* See _Microsoft Portable Executable and Common Object
  1131.      File Format Specification_, section 5.5.3.
  1132.      Create a symbol representing the alternate value.
  1133.      coff_frob_symbol will set the value of this symbol from
  1134.      the value of the weak symbol itself.  */
  1135.   S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
  1136.   S_SET_NUMBER_AUXILIARY (symbolP, 1);
  1137.   SA_SET_SYM_FSIZE (symbolP, IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY);
  1138.  
  1139.   alternateP = symbol_find_or_make (weak_name2altname (S_GET_NAME (symbolP)));
  1140.   S_SET_EXTERNAL (alternateP);
  1141.   S_SET_STORAGE_CLASS (alternateP, C_NT_WEAK);
  1142.  
  1143.   SA_SET_SYM_TAGNDX (symbolP, alternateP);
  1144. }
  1145.  
  1146. void
  1147. pecoff_obj_clear_weak_hook (symbolS *symbolP)
  1148. {
  1149.   symbolS *alternateP;
  1150.  
  1151.   S_SET_STORAGE_CLASS (symbolP, 0);
  1152.   SA_SET_SYM_FSIZE (symbolP, 0);
  1153.  
  1154.   alternateP = symbol_find (weak_name2altname (S_GET_NAME (symbolP)));
  1155.   S_CLEAR_EXTERNAL (alternateP);
  1156. }
  1157.  
  1158. #endif  /* TE_PE */
  1159.  
  1160. /* Handle .weak.  This is a GNU extension in formats other than PE. */
  1161.  
  1162. static void
  1163. obj_coff_weak (int ignore ATTRIBUTE_UNUSED)
  1164. {
  1165.   char *name;
  1166.   int c;
  1167.   symbolS *symbolP;
  1168.  
  1169.   do
  1170.     {
  1171.       name = input_line_pointer;
  1172.       c = get_symbol_end ();
  1173.       if (*name == 0)
  1174.         {
  1175.           as_warn (_("badly formed .weak directive ignored"));
  1176.           ignore_rest_of_line ();
  1177.           return;
  1178.         }
  1179.       c = 0;
  1180.       symbolP = symbol_find_or_make (name);
  1181.       *input_line_pointer = c;
  1182.       SKIP_WHITESPACE ();
  1183.       S_SET_WEAK (symbolP);
  1184.  
  1185.       if (c == ',')
  1186.         {
  1187.           input_line_pointer++;
  1188.           SKIP_WHITESPACE ();
  1189.           if (*input_line_pointer == '\n')
  1190.             c = '\n';
  1191.         }
  1192.  
  1193.     }
  1194.   while (c == ',');
  1195.  
  1196.   demand_empty_rest_of_line ();
  1197. }
  1198.  
  1199. void
  1200. coff_obj_read_begin_hook (void)
  1201. {
  1202.   /* These had better be the same.  Usually 18 bytes.  */
  1203.   know (sizeof (SYMENT) == sizeof (AUXENT));
  1204.   know (SYMESZ == AUXESZ);
  1205.   tag_init ();
  1206. }
  1207.  
  1208. symbolS *coff_last_function;
  1209. #ifndef OBJ_XCOFF
  1210. static symbolS *coff_last_bf;
  1211. #endif
  1212.  
  1213. void
  1214. coff_frob_symbol (symbolS *symp, int *punt)
  1215. {
  1216.   static symbolS *last_tagP;
  1217.   static stack *block_stack;
  1218.   static symbolS *set_end;
  1219.   symbolS *next_set_end = NULL;
  1220.  
  1221.   if (symp == &abs_symbol)
  1222.     {
  1223.       *punt = 1;
  1224.       return;
  1225.     }
  1226.  
  1227.   if (current_lineno_sym)
  1228.     coff_add_linesym (NULL);
  1229.  
  1230.   if (!block_stack)
  1231.     block_stack = stack_init (512, sizeof (symbolS*));
  1232.  
  1233. #ifdef TE_PE
  1234.   if (S_GET_STORAGE_CLASS (symp) == C_NT_WEAK
  1235.       && ! S_IS_WEAK (symp)
  1236.       && weak_is_altname (S_GET_NAME (symp)))
  1237.     {
  1238.       /* This is a weak alternate symbol.  All processing of
  1239.          PECOFFweak symbols is done here, through the alternate.  */
  1240.       symbolS *weakp = symbol_find_noref (weak_altname2name
  1241.                                           (S_GET_NAME (symp)), 1);
  1242.  
  1243.       gas_assert (weakp);
  1244.       gas_assert (S_GET_NUMBER_AUXILIARY (weakp) == 1);
  1245.  
  1246.       if (! S_IS_WEAK (weakp))
  1247.         {
  1248.           /* The symbol was turned from weak to strong.  Discard altname.  */
  1249.           *punt = 1;
  1250.           return;
  1251.         }
  1252.       else if (symbol_equated_p (weakp))
  1253.         {
  1254.           /* The weak symbol has an alternate specified; symp is unneeded.  */
  1255.           S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
  1256.           SA_SET_SYM_TAGNDX (weakp,
  1257.             symbol_get_value_expression (weakp)->X_add_symbol);
  1258.  
  1259.           S_CLEAR_EXTERNAL (symp);
  1260.           *punt = 1;
  1261.           return;
  1262.         }
  1263.       else
  1264.         {
  1265.           /* The weak symbol has been assigned an alternate value.
  1266.              Copy this value to symp, and set symp as weakp's alternate.  */
  1267.           if (S_GET_STORAGE_CLASS (weakp) != C_NT_WEAK)
  1268.             {
  1269.               S_SET_STORAGE_CLASS (symp, S_GET_STORAGE_CLASS (weakp));
  1270.               S_SET_STORAGE_CLASS (weakp, C_NT_WEAK);
  1271.             }
  1272.  
  1273.           if (S_IS_DEFINED (weakp))
  1274.             {
  1275.               /* This is a defined weak symbol.  Copy value information
  1276.                  from the weak symbol itself to the alternate symbol.  */
  1277.               symbol_set_value_expression (symp,
  1278.                                            symbol_get_value_expression (weakp));
  1279.               symbol_set_frag (symp, symbol_get_frag (weakp));
  1280.               S_SET_SEGMENT (symp, S_GET_SEGMENT (weakp));
  1281.             }
  1282.           else
  1283.             {
  1284.               /* This is an undefined weak symbol.
  1285.                  Define the alternate symbol to zero.  */
  1286.               S_SET_VALUE (symp, 0);
  1287.               S_SET_SEGMENT (symp, absolute_section);
  1288.             }
  1289.  
  1290.           S_SET_NAME (symp, weak_uniquify (S_GET_NAME (symp)));
  1291.           S_SET_STORAGE_CLASS (symp, C_EXT);
  1292.  
  1293.           S_SET_VALUE (weakp, 0);
  1294.           S_SET_SEGMENT (weakp, undefined_section);
  1295.         }
  1296.     }
  1297. #else /* TE_PE */
  1298.   if (S_IS_WEAK (symp))
  1299.     S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
  1300. #endif /* TE_PE */
  1301.  
  1302.   if (!S_IS_DEFINED (symp)
  1303.       && !S_IS_WEAK (symp)
  1304.       && S_GET_STORAGE_CLASS (symp) != C_STAT)
  1305.     S_SET_STORAGE_CLASS (symp, C_EXT);
  1306.  
  1307.   if (!SF_GET_DEBUG (symp))
  1308.     {
  1309.       symbolS * real;
  1310.  
  1311.       if (!SF_GET_LOCAL (symp)
  1312.           && !SF_GET_STATICS (symp)
  1313.           && S_GET_STORAGE_CLASS (symp) != C_LABEL
  1314.           && symbol_constant_p (symp)
  1315.           && (real = symbol_find_noref (S_GET_NAME (symp), 1))
  1316.           && S_GET_STORAGE_CLASS (real) == C_NULL
  1317.           && real != symp)
  1318.         {
  1319.           c_symbol_merge (symp, real);
  1320.           *punt = 1;
  1321.           return;
  1322.         }
  1323.  
  1324.       if (!S_IS_DEFINED (symp) && !SF_GET_LOCAL (symp))
  1325.         {
  1326.           gas_assert (S_GET_VALUE (symp) == 0);
  1327.           if (S_IS_WEAKREFD (symp))
  1328.             *punt = 1;
  1329.           else
  1330.             S_SET_EXTERNAL (symp);
  1331.         }
  1332.       else if (S_GET_STORAGE_CLASS (symp) == C_NULL)
  1333.         {
  1334.           if (S_GET_SEGMENT (symp) == text_section
  1335.               && symp != seg_info (text_section)->sym)
  1336.             S_SET_STORAGE_CLASS (symp, C_LABEL);
  1337.           else
  1338.             S_SET_STORAGE_CLASS (symp, C_STAT);
  1339.         }
  1340.  
  1341.       if (SF_GET_PROCESS (symp))
  1342.         {
  1343.           if (S_GET_STORAGE_CLASS (symp) == C_BLOCK)
  1344.             {
  1345.               if (streq (S_GET_NAME (symp), ".bb"))
  1346.                 stack_push (block_stack, (char *) &symp);
  1347.               else
  1348.                 {
  1349.                   symbolS *begin;
  1350.  
  1351.                   begin = *(symbolS **) stack_pop (block_stack);
  1352.                   if (begin == 0)
  1353.                     as_warn (_("mismatched .eb"));
  1354.                   else
  1355.                     next_set_end = begin;
  1356.                 }
  1357.             }
  1358.  
  1359.           if (coff_last_function == 0 && SF_GET_FUNCTION (symp)
  1360.               && S_IS_DEFINED (symp))
  1361.             {
  1362.               union internal_auxent *auxp;
  1363.  
  1364.               coff_last_function = symp;
  1365.               if (S_GET_NUMBER_AUXILIARY (symp) < 1)
  1366.                 S_SET_NUMBER_AUXILIARY (symp, 1);
  1367.               auxp = SYM_AUXENT (symp);
  1368.               memset (auxp->x_sym.x_fcnary.x_ary.x_dimen, 0,
  1369.                       sizeof (auxp->x_sym.x_fcnary.x_ary.x_dimen));
  1370.             }
  1371.  
  1372.           if (S_GET_STORAGE_CLASS (symp) == C_EFCN
  1373.               && S_IS_DEFINED (symp))
  1374.             {
  1375.               if (coff_last_function == 0)
  1376.                 as_fatal (_("C_EFCN symbol for %s out of scope"),
  1377.                           S_GET_NAME (symp));
  1378.               SA_SET_SYM_FSIZE (coff_last_function,
  1379.                                 (long) (S_GET_VALUE (symp)
  1380.                                         - S_GET_VALUE (coff_last_function)));
  1381.               next_set_end = coff_last_function;
  1382.               coff_last_function = 0;
  1383.             }
  1384.         }
  1385.  
  1386.       if (S_IS_EXTERNAL (symp))
  1387.         S_SET_STORAGE_CLASS (symp, C_EXT);
  1388.       else if (SF_GET_LOCAL (symp))
  1389.         *punt = 1;
  1390.  
  1391.       if (SF_GET_FUNCTION (symp))
  1392.         symbol_get_bfdsym (symp)->flags |= BSF_FUNCTION;
  1393.     }
  1394.  
  1395.   /* Double check weak symbols.  */
  1396.   if (S_IS_WEAK (symp) && S_IS_COMMON (symp))
  1397.     as_bad (_("Symbol `%s' can not be both weak and common"),
  1398.             S_GET_NAME (symp));
  1399.  
  1400.   if (SF_GET_TAG (symp))
  1401.     last_tagP = symp;
  1402.   else if (S_GET_STORAGE_CLASS (symp) == C_EOS)
  1403.     next_set_end = last_tagP;
  1404.  
  1405. #ifdef OBJ_XCOFF
  1406.   /* This is pretty horrible, but we have to set *punt correctly in
  1407.      order to call SA_SET_SYM_ENDNDX correctly.  */
  1408.   if (! symbol_used_in_reloc_p (symp)
  1409.       && ((symbol_get_bfdsym (symp)->flags & BSF_SECTION_SYM) != 0
  1410.           || (! (S_IS_EXTERNAL (symp) || S_IS_WEAK (symp))
  1411.               && ! symbol_get_tc (symp)->output
  1412.               && S_GET_STORAGE_CLASS (symp) != C_FILE)))
  1413.     *punt = 1;
  1414. #endif
  1415.  
  1416.   if (set_end != (symbolS *) NULL
  1417.       && ! *punt
  1418.       && ((symbol_get_bfdsym (symp)->flags & BSF_NOT_AT_END) != 0
  1419.           || (S_IS_DEFINED (symp)
  1420.               && ! S_IS_COMMON (symp)
  1421.               && (! S_IS_EXTERNAL (symp) || SF_GET_FUNCTION (symp)))))
  1422.     {
  1423.       SA_SET_SYM_ENDNDX (set_end, symp);
  1424.       set_end = NULL;
  1425.     }
  1426.  
  1427.   if (next_set_end != NULL)
  1428.     {
  1429.       if (set_end != NULL)
  1430.         as_warn (_("Warning: internal error: forgetting to set endndx of %s"),
  1431.                  S_GET_NAME (set_end));
  1432.       set_end = next_set_end;
  1433.     }
  1434.  
  1435. #ifndef OBJ_XCOFF
  1436.   if (! *punt
  1437.       && S_GET_STORAGE_CLASS (symp) == C_FCN
  1438.       && streq (S_GET_NAME (symp), ".bf"))
  1439.     {
  1440.       if (coff_last_bf != NULL)
  1441.         SA_SET_SYM_ENDNDX (coff_last_bf, symp);
  1442.       coff_last_bf = symp;
  1443.     }
  1444. #endif
  1445.   if (coffsymbol (symbol_get_bfdsym (symp))->lineno)
  1446.     {
  1447.       int i;
  1448.       struct line_no *lptr;
  1449.       alent *l;
  1450.  
  1451.       lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
  1452.       for (i = 0; lptr; lptr = lptr->next)
  1453.         i++;
  1454.       lptr = (struct line_no *) coffsymbol (symbol_get_bfdsym (symp))->lineno;
  1455.  
  1456.       /* We need i entries for line numbers, plus 1 for the first
  1457.          entry which BFD will override, plus 1 for the last zero
  1458.          entry (a marker for BFD).  */
  1459.       l = xmalloc ((i + 2) * sizeof (* l));
  1460.       coffsymbol (symbol_get_bfdsym (symp))->lineno = l;
  1461.       l[i + 1].line_number = 0;
  1462.       l[i + 1].u.sym = NULL;
  1463.       for (; i > 0; i--)
  1464.         {
  1465.           if (lptr->frag)
  1466.             lptr->l.u.offset += lptr->frag->fr_address / OCTETS_PER_BYTE;
  1467.           l[i] = lptr->l;
  1468.           lptr = lptr->next;
  1469.         }
  1470.     }
  1471. }
  1472.  
  1473. void
  1474. coff_adjust_section_syms (bfd *abfd ATTRIBUTE_UNUSED,
  1475.                           asection *sec,
  1476.                           void * x ATTRIBUTE_UNUSED)
  1477. {
  1478.   symbolS *secsym;
  1479.   segment_info_type *seginfo = seg_info (sec);
  1480.   int nlnno, nrelocs = 0;
  1481.  
  1482.   /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
  1483.      tc-ppc.c.  Do not get confused by it.  */
  1484.   if (seginfo == NULL)
  1485.     return;
  1486.  
  1487.   if (streq (sec->name, ".text"))
  1488.     nlnno = coff_n_line_nos;
  1489.   else
  1490.     nlnno = 0;
  1491.   {
  1492.     /* @@ Hope that none of the fixups expand to more than one reloc
  1493.        entry...  */
  1494.     fixS *fixp = seginfo->fix_root;
  1495.     while (fixp)
  1496.       {
  1497.         if (! fixp->fx_done)
  1498.           nrelocs++;
  1499.         fixp = fixp->fx_next;
  1500.       }
  1501.   }
  1502.   if (bfd_get_section_size (sec) == 0
  1503.       && nrelocs == 0
  1504.       && nlnno == 0
  1505.       && sec != text_section
  1506.       && sec != data_section
  1507.       && sec != bss_section)
  1508.     return;
  1509.  
  1510.   secsym = section_symbol (sec);
  1511.   /* This is an estimate; we'll plug in the real value using
  1512.      SET_SECTION_RELOCS later */
  1513.   SA_SET_SCN_NRELOC (secsym, nrelocs);
  1514.   SA_SET_SCN_NLINNO (secsym, nlnno);
  1515. }
  1516.  
  1517. void
  1518. coff_frob_file_after_relocs (void)
  1519. {
  1520.   bfd_map_over_sections (stdoutput, coff_adjust_section_syms, NULL);
  1521. }
  1522.  
  1523. /* Implement the .section pseudo op:
  1524.         .section name {, "flags"}
  1525.                   ^         ^
  1526.                   |         +--- optional flags: 'b' for bss
  1527.                   |                              'i' for info
  1528.                   +-- section name               'l' for lib
  1529.                                                  'n' for noload
  1530.                                                  'o' for over
  1531.                                                  'w' for data
  1532.                                                  'd' (apparently m88k for data)
  1533.                                                  'e' for exclude
  1534.                                                  'x' for text
  1535.                                                  'r' for read-only data
  1536.                                                  's' for shared data (PE)
  1537.                                                  'y' for noread
  1538.                                            '0' - '9' for power-of-two alignment (GNU extension).
  1539.    But if the argument is not a quoted string, treat it as a
  1540.    subsegment number.
  1541.  
  1542.    Note the 'a' flag is silently ignored.  This allows the same
  1543.    .section directive to be parsed in both ELF and COFF formats.  */
  1544.  
  1545. void
  1546. obj_coff_section (int ignore ATTRIBUTE_UNUSED)
  1547. {
  1548.   /* Strip out the section name.  */
  1549.   char *section_name;
  1550.   char c;
  1551.   int alignment = -1;
  1552.   char *name;
  1553.   unsigned int exp;
  1554.   flagword flags, oldflags;
  1555.   asection *sec;
  1556.  
  1557.   if (flag_mri)
  1558.     {
  1559.       char type;
  1560.  
  1561.       s_mri_sect (&type);
  1562.       return;
  1563.     }
  1564.  
  1565.   section_name = input_line_pointer;
  1566.   c = get_symbol_end ();
  1567.  
  1568.   name = xmalloc (input_line_pointer - section_name + 1);
  1569.   strcpy (name, section_name);
  1570.  
  1571.   *input_line_pointer = c;
  1572.  
  1573.   SKIP_WHITESPACE ();
  1574.  
  1575.   exp = 0;
  1576.   flags = SEC_NO_FLAGS;
  1577.  
  1578.   if (*input_line_pointer == ',')
  1579.     {
  1580.       ++input_line_pointer;
  1581.       SKIP_WHITESPACE ();
  1582.       if (*input_line_pointer != '"')
  1583.         exp = get_absolute_expression ();
  1584.       else
  1585.         {
  1586.           unsigned char attr;
  1587.           int readonly_removed = 0;
  1588.           int load_removed = 0;
  1589.  
  1590.           while (attr = *++input_line_pointer,
  1591.                  attr != '"'
  1592.                  && ! is_end_of_line[attr])
  1593.             {
  1594.               if (ISDIGIT (attr))
  1595.                 {
  1596.                   alignment = attr - '0';
  1597.                   continue;
  1598.                 }
  1599.               switch (attr)
  1600.                 {
  1601.                 case 'e':
  1602.                   /* Exclude section from linking.  */
  1603.                   flags |= SEC_EXCLUDE;
  1604.                   break;
  1605.  
  1606.                 case 'b':
  1607.                   /* Uninitialised data section.  */
  1608.                   flags |= SEC_ALLOC;
  1609.                   flags &=~ SEC_LOAD;
  1610.                   break;
  1611.  
  1612.                 case 'n':
  1613.                   /* Section not loaded.  */
  1614.                   flags &=~ SEC_LOAD;
  1615.                   flags |= SEC_NEVER_LOAD;
  1616.                   load_removed = 1;
  1617.                   break;
  1618.  
  1619.                 case 's':
  1620.                   /* Shared section.  */
  1621.                   flags |= SEC_COFF_SHARED;
  1622.                   /* Fall through.  */
  1623.                 case 'd':
  1624.                   /* Data section.  */
  1625.                   flags |= SEC_DATA;
  1626.                   if (! load_removed)
  1627.                     flags |= SEC_LOAD;
  1628.                   flags &=~ SEC_READONLY;
  1629.                   break;
  1630.  
  1631.                 case 'w':
  1632.                   /* Writable section.  */
  1633.                   flags &=~ SEC_READONLY;
  1634.                   readonly_removed = 1;
  1635.                   break;
  1636.  
  1637.                 case 'a':
  1638.                   /* Ignore.  Here for compatibility with ELF.  */
  1639.                   break;
  1640.  
  1641.                 case 'r': /* Read-only section.  Implies a data section.  */
  1642.                   readonly_removed = 0;
  1643.                   /* Fall through.  */
  1644.                 case 'x': /* Executable section.  */
  1645.                   /* If we are setting the 'x' attribute or if the 'r'
  1646.                      attribute is being used to restore the readonly status
  1647.                      of a code section (eg "wxr") then set the SEC_CODE flag,
  1648.                      otherwise set the SEC_DATA flag.  */
  1649.                   flags |= (attr == 'x' || (flags & SEC_CODE) ? SEC_CODE : SEC_DATA);
  1650.                   if (! load_removed)
  1651.                     flags |= SEC_LOAD;
  1652.                   /* Note - the READONLY flag is set here, even for the 'x'
  1653.                      attribute in order to be compatible with the MSVC
  1654.                      linker.  */
  1655.                   if (! readonly_removed)
  1656.                     flags |= SEC_READONLY;
  1657.                   break;
  1658.  
  1659.                 case 'y':
  1660.                   flags |= SEC_COFF_NOREAD | SEC_READONLY;
  1661.                   break;
  1662.  
  1663.                 case 'i': /* STYP_INFO */
  1664.                 case 'l': /* STYP_LIB */
  1665.                 case 'o': /* STYP_OVER */
  1666.                   as_warn (_("unsupported section attribute '%c'"), attr);
  1667.                   break;
  1668.  
  1669.                 default:
  1670.                   as_warn (_("unknown section attribute '%c'"), attr);
  1671.                   break;
  1672.                 }
  1673.             }
  1674.           if (attr == '"')
  1675.             ++input_line_pointer;
  1676.         }
  1677.     }
  1678.  
  1679.   sec = subseg_new (name, (subsegT) exp);
  1680.  
  1681.   if (alignment >= 0)
  1682.     sec->alignment_power = alignment;
  1683.  
  1684.   oldflags = bfd_get_section_flags (stdoutput, sec);
  1685.   if (oldflags == SEC_NO_FLAGS)
  1686.     {
  1687.       /* Set section flags for a new section just created by subseg_new.
  1688.          Provide a default if no flags were parsed.  */
  1689.       if (flags == SEC_NO_FLAGS)
  1690.         flags = TC_COFF_SECTION_DEFAULT_ATTRIBUTES;
  1691.  
  1692. #ifdef COFF_LONG_SECTION_NAMES
  1693.       /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
  1694.          sections so adjust_reloc_syms in write.c will correctly handle
  1695.          relocs which refer to non-local symbols in these sections.  */
  1696.       if (strneq (name, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1))
  1697.         flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
  1698. #endif
  1699.  
  1700.       if (! bfd_set_section_flags (stdoutput, sec, flags))
  1701.         as_warn (_("error setting flags for \"%s\": %s"),
  1702.                  bfd_section_name (stdoutput, sec),
  1703.                  bfd_errmsg (bfd_get_error ()));
  1704.     }
  1705.   else if (flags != SEC_NO_FLAGS)
  1706.     {
  1707.       /* This section's attributes have already been set.  Warn if the
  1708.          attributes don't match.  */
  1709.       flagword matchflags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
  1710.                              | SEC_DATA | SEC_COFF_SHARED | SEC_NEVER_LOAD
  1711.                              | SEC_COFF_NOREAD);
  1712.       if ((flags ^ oldflags) & matchflags)
  1713.         as_warn (_("Ignoring changed section attributes for %s"), name);
  1714.     }
  1715.  
  1716.   demand_empty_rest_of_line ();
  1717. }
  1718.  
  1719. void
  1720. coff_adjust_symtab (void)
  1721. {
  1722.   if (symbol_rootP == NULL
  1723.       || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
  1724.     c_dot_file_symbol ("fake", 0);
  1725. }
  1726.  
  1727. void
  1728. coff_frob_section (segT sec)
  1729. {
  1730.   segT strsec;
  1731.   char *p;
  1732.   fragS *fragp;
  1733.   bfd_vma n_entries;
  1734.  
  1735.   /* The COFF back end in BFD requires that all section sizes be
  1736.      rounded up to multiples of the corresponding section alignments,
  1737.      supposedly because standard COFF has no other way of encoding alignment
  1738.      for sections.  If your COFF flavor has a different way of encoding
  1739.      section alignment, then skip this step, as TICOFF does.  */
  1740.   bfd_vma size = bfd_get_section_size (sec);
  1741. #if !defined(TICOFF)
  1742.   bfd_vma align_power = (bfd_vma) sec->alignment_power + OCTETS_PER_BYTE_POWER;
  1743.   bfd_vma mask = ((bfd_vma) 1 << align_power) - 1;
  1744.  
  1745.   if (size & mask)
  1746.     {
  1747.       bfd_vma new_size;
  1748.       fragS *last;
  1749.  
  1750.       new_size = (size + mask) & ~mask;
  1751.       bfd_set_section_size (stdoutput, sec, new_size);
  1752.  
  1753.       /* If the size had to be rounded up, add some padding in
  1754.          the last non-empty frag.  */
  1755.       fragp = seg_info (sec)->frchainP->frch_root;
  1756.       last = seg_info (sec)->frchainP->frch_last;
  1757.       while (fragp->fr_next != last)
  1758.         fragp = fragp->fr_next;
  1759.       last->fr_address = size;
  1760.       fragp->fr_offset += new_size - size;
  1761.     }
  1762. #endif
  1763.  
  1764.   /* If the section size is non-zero, the section symbol needs an aux
  1765.      entry associated with it, indicating the size.  We don't know
  1766.      all the values yet; coff_frob_symbol will fill them in later.  */
  1767. #ifndef TICOFF
  1768.   if (size != 0
  1769.       || sec == text_section
  1770.       || sec == data_section
  1771.       || sec == bss_section)
  1772. #endif
  1773.     {
  1774.       symbolS *secsym = section_symbol (sec);
  1775.       unsigned char sclass = C_STAT;
  1776.  
  1777. #ifdef OBJ_XCOFF
  1778.       if (bfd_get_section_flags (stdoutput, sec) & SEC_DEBUGGING)
  1779.         sclass = C_DWARF;
  1780. #endif
  1781.       S_SET_STORAGE_CLASS (secsym, sclass);
  1782.       S_SET_NUMBER_AUXILIARY (secsym, 1);
  1783.       SF_SET_STATICS (secsym);
  1784.       SA_SET_SCN_SCNLEN (secsym, size);
  1785.     }
  1786.   /* FIXME: These should be in a "stabs.h" file, or maybe as.h.  */
  1787. #ifndef STAB_SECTION_NAME
  1788. #define STAB_SECTION_NAME ".stab"
  1789. #endif
  1790. #ifndef STAB_STRING_SECTION_NAME
  1791. #define STAB_STRING_SECTION_NAME ".stabstr"
  1792. #endif
  1793.   if (! streq (STAB_STRING_SECTION_NAME, sec->name))
  1794.     return;
  1795.  
  1796.   strsec = sec;
  1797.   sec = subseg_get (STAB_SECTION_NAME, 0);
  1798.   /* size is already rounded up, since other section will be listed first */
  1799.   size = bfd_get_section_size (strsec);
  1800.  
  1801.   n_entries = bfd_get_section_size (sec) / 12 - 1;
  1802.  
  1803.   /* Find first non-empty frag.  It should be large enough.  */
  1804.   fragp = seg_info (sec)->frchainP->frch_root;
  1805.   while (fragp && fragp->fr_fix == 0)
  1806.     fragp = fragp->fr_next;
  1807.   gas_assert (fragp != 0 && fragp->fr_fix >= 12);
  1808.  
  1809.   /* Store the values.  */
  1810.   p = fragp->fr_literal;
  1811.   bfd_h_put_16 (stdoutput, n_entries, (bfd_byte *) p + 6);
  1812.   bfd_h_put_32 (stdoutput, size, (bfd_byte *) p + 8);
  1813. }
  1814.  
  1815. void
  1816. obj_coff_init_stab_section (segT seg)
  1817. {
  1818.   char *file;
  1819.   char *p;
  1820.   char *stabstr_name;
  1821.   unsigned int stroff;
  1822.  
  1823.   /* Make space for this first symbol.  */
  1824.   p = frag_more (12);
  1825.   /* Zero it out.  */
  1826.   memset (p, 0, 12);
  1827.   as_where (&file, (unsigned int *) NULL);
  1828.   stabstr_name = xmalloc (strlen (seg->name) + 4);
  1829.   strcpy (stabstr_name, seg->name);
  1830.   strcat (stabstr_name, "str");
  1831.   stroff = get_stab_string_offset (file, stabstr_name);
  1832.   know (stroff == 1);
  1833.   md_number_to_chars (p, stroff, 4);
  1834. }
  1835.  
  1836. #ifdef DEBUG
  1837. const char * s_get_name (symbolS *);
  1838.  
  1839. const char *
  1840. s_get_name (symbolS *s)
  1841. {
  1842.   return ((s == NULL) ? "(NULL)" : S_GET_NAME (s));
  1843. }
  1844.  
  1845. void symbol_dump (void);
  1846.  
  1847. void
  1848. symbol_dump (void)
  1849. {
  1850.   symbolS *symbolP;
  1851.  
  1852.   for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
  1853.     printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
  1854.             (unsigned long) symbolP,
  1855.             S_GET_NAME (symbolP),
  1856.             (long) S_GET_DATA_TYPE (symbolP),
  1857.             S_GET_STORAGE_CLASS (symbolP),
  1858.             (int) S_GET_SEGMENT (symbolP));
  1859. }
  1860.  
  1861. #endif /* DEBUG */
  1862.  
  1863. const pseudo_typeS coff_pseudo_table[] =
  1864. {
  1865.   {"ABORT", s_abort, 0},
  1866.   {"appline", obj_coff_ln, 1},
  1867.   /* We accept the .bss directive for backward compatibility with
  1868.      earlier versions of gas.  */
  1869.   {"bss", obj_coff_bss, 0},
  1870. #ifdef TE_PE
  1871.   /* PE provides an enhanced version of .comm with alignment.  */
  1872.   {"comm", obj_coff_comm, 0},
  1873. #endif /* TE_PE */
  1874.   {"def", obj_coff_def, 0},
  1875.   {"dim", obj_coff_dim, 0},
  1876.   {"endef", obj_coff_endef, 0},
  1877.   {"ident", obj_coff_ident, 0},
  1878.   {"line", obj_coff_line, 0},
  1879.   {"ln", obj_coff_ln, 0},
  1880.   {"scl", obj_coff_scl, 0},
  1881.   {"sect", obj_coff_section, 0},
  1882.   {"sect.s", obj_coff_section, 0},
  1883.   {"section", obj_coff_section, 0},
  1884.   {"section.s", obj_coff_section, 0},
  1885.   /* FIXME: We ignore the MRI short attribute.  */
  1886.   {"size", obj_coff_size, 0},
  1887.   {"tag", obj_coff_tag, 0},
  1888.   {"type", obj_coff_type, 0},
  1889.   {"val", obj_coff_val, 0},
  1890.   {"version", s_ignore, 0},
  1891.   {"loc", obj_coff_loc, 0},
  1892.   {"optim", s_ignore, 0},       /* For sun386i cc (?) */
  1893.   {"weak", obj_coff_weak, 0},
  1894. #if defined TC_TIC4X
  1895.   /* The tic4x uses sdef instead of def.  */
  1896.   {"sdef", obj_coff_def, 0},
  1897. #endif
  1898. #if defined(SEH_CMDS)
  1899.   SEH_CMDS
  1900. #endif
  1901.   {NULL, NULL, 0}
  1902. };
  1903.  
  1904. /* Support for a COFF emulation.  */
  1905.  
  1906. static void
  1907. coff_pop_insert (void)
  1908. {
  1909.   pop_insert (coff_pseudo_table);
  1910. }
  1911.  
  1912. static int
  1913. coff_separate_stab_sections (void)
  1914. {
  1915.   return 1;
  1916. }
  1917.  
  1918. const struct format_ops coff_format_ops =
  1919. {
  1920.   bfd_target_coff_flavour,
  1921.   0,    /* dfl_leading_underscore */
  1922.   1,    /* emit_section_symbols */
  1923.   0,    /* begin */
  1924.   c_dot_file_symbol,
  1925.   coff_frob_symbol,
  1926.   0,    /* frob_file */
  1927.   0,    /* frob_file_before_adjust */
  1928.   0,    /* frob_file_before_fix */
  1929.   coff_frob_file_after_relocs,
  1930.   0,    /* s_get_size */
  1931.   0,    /* s_set_size */
  1932.   0,    /* s_get_align */
  1933.   0,    /* s_set_align */
  1934.   0,    /* s_get_other */
  1935.   0,    /* s_set_other */
  1936.   0,    /* s_get_desc */
  1937.   0,    /* s_set_desc */
  1938.   0,    /* s_get_type */
  1939.   0,    /* s_set_type */
  1940.   0,    /* copy_symbol_attributes */
  1941.   0,    /* generate_asm_lineno */
  1942.   0,    /* process_stab */
  1943.   coff_separate_stab_sections,
  1944.   obj_coff_init_stab_section,
  1945.   0,    /* sec_sym_ok_for_reloc */
  1946.   coff_pop_insert,
  1947.   0,    /* ecoff_set_ext */
  1948.   coff_obj_read_begin_hook,
  1949.   coff_obj_symbol_new_hook,
  1950.   coff_obj_symbol_clone_hook,
  1951.   coff_adjust_symtab
  1952. };
  1953.