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