1 /* a.out object file format
2 Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public
17 License along with GAS; see the file COPYING. If not, write
18 to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include "aout/stab_gnu.h"
25 /* in: segT out: N_TYPE bits */
26 const short seg_N_TYPE[] =
36 N_UNDF, /* bignum/flonum */
37 N_UNDF, /* difference */
41 N_REGISTER, /* register */
44 const segT N_TYPE_seg[N_TYPE + 2] =
45 { /* N_TYPE == 0x1E = 32-2 */
46 SEG_UNKNOWN, /* N_UNDF == 0 */
48 SEG_ABSOLUTE, /* N_ABS == 2 */
50 SEG_TEXT, /* N_TEXT == 4 */
52 SEG_DATA, /* N_DATA == 6 */
54 SEG_BSS, /* N_BSS == 8 */
56 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
57 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
58 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
59 SEG_REGISTER, /* dummy N_REGISTER for regs = 30 */
64 static void obj_aout_stab PARAMS ((int what));
65 static void obj_aout_line PARAMS ((void));
66 static void obj_aout_desc PARAMS ((void));
68 const pseudo_typeS obj_pseudo_table[] =
70 /* stabs debug info */
71 {"line", obj_aout_line, 0}, /* source code line number */
72 {"ln", obj_aout_line, 0}, /* coff line number that we use anyway */
73 {"desc", obj_aout_desc, 0}, /* desc */
74 {"stabd", obj_aout_stab, 'd'},/* stabs */
75 {"stabn", obj_aout_stab, 'n'},/* stabs */
76 {"stabs", obj_aout_stab, 's'},/* stabs */
78 /* coff debug pseudos (ignored) */
81 {"endef", s_ignore, 0},
82 {"ident", s_ignore, 0},
83 {"line", s_ignore, 0},
86 {"size", s_ignore, 0},
88 {"type", s_ignore, 0},
90 {"version", s_ignore, 0},
92 /* stabs-in-coff (?) debug pseudos (ignored) */
93 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
96 {"ABORT", s_abort, 0},
98 {NULL} /* end sentinel */
99 }; /* obj_pseudo_table */
105 obj_aout_frob_symbol (sym, punt)
111 int desc, type, other;
113 flags = sym->bsym->flags;
114 desc = S_GET_DESC (sym);
115 type = S_GET_TYPE (sym);
116 other = S_GET_OTHER (sym);
117 sec = sym->bsym->section;
119 /* Only frob simple symbols this way right now. */
120 if (! (type & ~0x1f))
122 if (sec == &bfd_abs_section
123 || sec == &bfd_und_section)
125 if (flags & BSF_EXPORT)
130 sym->bsym->flags |= BSF_DEBUGGING;
133 S_SET_TYPE (sym, type);
143 * Crawl along a fixS chain. Emit the segment's relocations.
146 obj_emit_relocations (where, fixP, segment_address_in_file)
148 fixS *fixP; /* Fixup chain for this segment. */
149 relax_addressT segment_address_in_file;
151 for (; fixP; fixP = fixP->fx_next)
152 if (fixP->fx_addsy != NULL)
154 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
155 *where += md_reloc_size;
159 #ifndef obj_header_append
160 /* Aout file generation & utilities */
162 obj_header_append (where, headers)
164 object_headers *headers;
166 tc_headers_hook (headers);
169 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
170 *where += sizeof (headers->header.a_info);
171 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
172 *where += sizeof (headers->header.a_text);
173 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
174 *where += sizeof (headers->header.a_data);
175 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
176 *where += sizeof (headers->header.a_bss);
177 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
178 *where += sizeof (headers->header.a_syms);
179 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
180 *where += sizeof (headers->header.a_entry);
181 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
182 *where += sizeof (headers->header.a_trsize);
183 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
184 *where += sizeof (headers->header.a_drsize);
186 #else /* CROSS_COMPILE */
188 append (where, (char *) &headers->header, sizeof (headers->header));
189 #endif /* CROSS_COMPILE */
195 obj_symbol_to_chars (where, symbolP)
199 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
200 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
201 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
203 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
207 obj_emit_symbols (where, symbol_rootP)
209 symbolS *symbol_rootP;
213 /* Emit all symbols left in the symbol chain. */
214 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
216 /* Used to save the offset of the name. It is used to point
217 to the string in memory but must be a file offset. */
220 temp = S_GET_NAME (symbolP);
221 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
223 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
224 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
225 S_SET_EXTERNAL (symbolP);
227 obj_symbol_to_chars (where, symbolP);
228 S_SET_NAME (symbolP, temp);
232 #endif /* ! BFD_ASSEMBLER */
237 /* Assume delimiter is part of expression.
238 BSD4.2 as fails with delightful bug, so we
239 are not being incompatible here. */
240 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
241 demand_empty_rest_of_line ();
242 } /* obj_aout_line() */
247 * Handle .stabX directives, which used to be open-coded.
248 * So much creeping featurism overloaded the semantics that we decided
249 * to put all .stabX thinking in one place. Here.
251 * We try to make any .stabX directive legal. Other people's AS will often
252 * do assembly-time consistency checks: eg assigning meaning to n_type bits
253 * and "protecting" you from setting them to certain values. (They also zero
254 * certain bits before emitting symbols. Tut tut.)
256 * If an expression is not absolute we either gripe or use the relocation
257 * information. Other people's assemblers silently forget information they
258 * don't need and invent information they need that you didn't supply.
260 * .stabX directives always make a symbol table entry. It may be junk if
261 * the rest of your .stabX directive is malformed.
269 register symbolS *symbolP = 0;
270 register char *string;
273 int goof; /* TRUE if we have aborted. */
277 * Enter with input_line_pointer pointing past .stabX and any following
280 goof = 0; /* JF who forgot this?? */
283 string = demand_copy_C_string (&length);
285 if (*input_line_pointer == ',')
286 input_line_pointer++;
289 as_bad ("I need a comma after symbol's name");
297 * Input_line_pointer->after ','. String->symbol name.
301 symbolP = symbol_new (string, undefined_section, 0, (struct frag *) 0);
305 S_SET_NAME (symbolP, NULL); /* .stabd feature. */
306 S_SET_VALUE (symbolP, (char*) obstack_next_free (&frags) - frag_now->fr_literal);
307 symbolP->sy_frag = frag_now;
311 symbolP->sy_frag = &zero_address_frag;
315 symbolP->sy_frag = &zero_address_frag;
323 if (get_absolute_expression_and_terminator (&longint) == ',')
325 saved_type = longint;
326 S_SET_TYPE (symbolP, saved_type);
330 as_bad ("I want a comma after the n_type expression");
332 input_line_pointer--; /* Backup over a non-',' char. */
338 if (get_absolute_expression_and_terminator (&longint) == ',')
339 S_SET_OTHER (symbolP, longint);
342 as_bad ("I want a comma after the n_other expression");
344 input_line_pointer--; /* Backup over a non-',' char. */
350 S_SET_DESC (symbolP, get_absolute_expression ());
351 if (what == 's' || what == 'n')
353 if (*input_line_pointer != ',')
355 as_bad ("I want a comma after the n_desc expression");
360 input_line_pointer++;
365 if ((!goof) && (what == 's' || what == 'n'))
367 pseudo_set (symbolP);
368 S_SET_TYPE (symbolP, saved_type);
371 if (listing && !goof)
373 if (S_GET_TYPE (symbolP) == N_SLINE)
375 listing_source_line (S_GET_DESC (symbolP));
377 else if (S_GET_TYPE (symbolP) == N_SO || S_GET_TYPE (symbolP) == N_SOL)
379 listing_source_file (string);
385 ignore_rest_of_line ();
387 demand_empty_rest_of_line ();
388 } /* obj_aout_stab() */
396 register symbolS *symbolP;
400 * Frob invented at RMS' request. Set the n_desc of a symbol.
402 name = input_line_pointer;
403 c = get_symbol_end ();
404 p = input_line_pointer;
407 if (*input_line_pointer != ',')
410 as_bad ("Expected comma after name \"%s\"", name);
412 ignore_rest_of_line ();
416 input_line_pointer++;
417 temp = get_absolute_expression ();
419 symbolP = symbol_find_or_make (name);
421 S_SET_DESC (symbolP, temp);
423 demand_empty_rest_of_line ();
424 } /* obj_aout_desc() */
427 obj_read_begin_hook ()
430 } /* obj_read_begin_hook() */
432 #ifndef BFD_ASSEMBLER
435 obj_crawl_symbol_chain (headers)
436 object_headers *headers;
440 int symbol_number = 0;
442 tc_crawl_symbol_chain (headers);
444 symbolPP = &symbol_rootP; /*->last symbol chain link. */
445 while ((symbolP = *symbolPP) != NULL)
447 if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_DATA))
449 S_SET_SEGMENT (symbolP, SEG_TEXT);
450 } /* if pusing data into text */
452 resolve_symbol_value (symbolP);
454 /* OK, here is how we decide which symbols go out into the brave
455 new symtab. Symbols that do are:
457 * symbols with no name (stabd's?)
458 * symbols with debug info in their N_TYPE
460 Symbols that don't are:
461 * symbols that are registers
462 * symbols with \1 as their 3rd character (numeric labels)
463 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
464 switch was passed to gas.
466 All other symbols are output. We complain if a deleted
467 symbol was marked external. */
470 if (!S_IS_REGISTER (symbolP)
471 && (!S_GET_NAME (symbolP)
472 || S_IS_DEBUG (symbolP)
474 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
475 || !S_IS_DEFINED (symbolP)
476 || S_IS_EXTERNAL (symbolP)
478 || (S_GET_NAME (symbolP)[0] != '\001' && (flagseen['L'] || !S_LOCAL_NAME (symbolP)))))
480 symbolP->sy_number = symbol_number++;
482 /* The + 1 after strlen account for the \0 at the
483 end of each string */
484 if (!S_IS_STABD (symbolP))
487 symbolP->sy_name_offset = string_byte_count;
488 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
490 else /* .Stabd case. */
491 symbolP->sy_name_offset = 0;
492 symbolPP = &(symbol_next (symbolP));
496 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
498 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
501 /* Unhook it from the chain */
502 *symbolPP = symbol_next (symbolP);
503 } /* if this symbol should be in the output */
504 } /* for each symbol */
506 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
509 } /* obj_crawl_symbol_chain() */
512 * Find strings by crawling along symbol table chain.
516 obj_emit_strings (where)
522 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
523 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
524 *where += sizeof (string_byte_count);
525 #else /* CROSS_COMPILE */
526 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
527 #endif /* CROSS_COMPILE */
529 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
531 if (S_GET_NAME (symbolP))
532 append (&next_object_file_charP, S_GET_NAME (symbolP),
533 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
534 } /* walk symbol chain */
537 } /* obj_emit_strings() */
540 #define AOUT_VERSION 0
544 obj_pre_write_hook (headers)
545 object_headers *headers;
547 H_SET_DYNAMIC (headers, 0);
548 H_SET_VERSION (headers, AOUT_VERSION);
549 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
550 tc_aout_pre_write_hook (headers);
552 } /* obj_pre_write_hook() */
557 /* Strip out the section name */
559 char *section_name_end;
566 section_name = input_line_pointer;
567 c = get_symbol_end ();
568 section_name_end = input_line_pointer;
570 len = section_name_end - section_name;
571 input_line_pointer++;
572 save = input_line_pointer;
577 exp = get_absolute_expression ();
579 else if (*input_line_pointer == ',')
581 input_line_pointer++;
582 exp = get_absolute_expression ();
586 input_line_pointer = save;
591 as_bad ("subsegment index too high");
594 if (strcmp (section_name, ".text") == 0)
596 subseg_new (SEG_TEXT, (subsegT) exp);
599 if (strcmp (section_name, ".data") == 0)
602 subseg_new (SEG_TEXT, (subsegT) exp + 1000);
604 subseg_new (SEG_DATA, (subsegT) exp);
607 *section_name_end = c;
610 #endif /* ! BFD_ASSEMBLER */
612 /* end of obj-aout.c */