Subversion Repositories Kolibri OS

Rev

Rev 5222 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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