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"
22 #include "aout/aout64.h"
26 /* in: segT out: N_TYPE bits */
27 const short seg_N_TYPE[] =
35 N_UNDF, /* expression */
39 N_REGISTER, /* register */
42 const segT N_TYPE_seg[N_TYPE + 2] =
43 { /* N_TYPE == 0x1E = 32-2 */
44 SEG_UNKNOWN, /* N_UNDF == 0 */
46 SEG_ABSOLUTE, /* N_ABS == 2 */
48 SEG_TEXT, /* N_TEXT == 4 */
50 SEG_DATA, /* N_DATA == 6 */
52 SEG_BSS, /* N_BSS == 8 */
54 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
55 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
56 SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF,
57 SEG_REGISTER, /* dummy N_REGISTER for regs = 30 */
62 static void obj_aout_stab PARAMS ((int what));
63 static void obj_aout_line PARAMS ((void));
64 static void obj_aout_desc PARAMS ((void));
66 const pseudo_typeS obj_pseudo_table[] =
68 /* stabs debug info */
69 {"line", obj_aout_line, 0}, /* source code line number */
70 {"ln", obj_aout_line, 0}, /* coff line number that we use anyway */
71 {"desc", obj_aout_desc, 0}, /* desc */
72 {"stabd", obj_aout_stab, 'd'},/* stabs */
73 {"stabn", obj_aout_stab, 'n'},/* stabs */
74 {"stabs", obj_aout_stab, 's'},/* stabs */
76 /* coff debug pseudos (ignored) */
79 {"endef", s_ignore, 0},
80 {"ident", s_ignore, 0},
81 {"line", s_ignore, 0},
84 {"size", s_ignore, 0},
86 {"type", s_ignore, 0},
88 {"version", s_ignore, 0},
90 /* stabs-in-coff (?) debug pseudos (ignored) */
91 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
94 {"ABORT", s_abort, 0},
96 {NULL} /* end sentinel */
97 }; /* obj_pseudo_table */
103 obj_aout_frob_symbol (sym, punt)
109 int desc, type, other;
111 flags = sym->bsym->flags;
112 desc = S_GET_DESC (sym);
113 type = S_GET_TYPE (sym);
114 other = S_GET_OTHER (sym);
115 sec = sym->bsym->section;
117 /* Only frob simple symbols this way right now. */
118 if (! (type & ~ (N_TYPE | N_EXT)))
120 if (sec == &bfd_abs_section
121 || sec == &bfd_und_section)
123 if (flags & BSF_EXPORT)
126 /* Set the debugging flag for constructor symbols so that BFD
127 leaves them alone. */
128 switch (type & N_TYPE)
134 sym->bsym->flags |= BSF_DEBUGGING;
140 sym->bsym->flags |= BSF_DEBUGGING;
143 S_SET_TYPE (sym, type);
153 * Crawl along a fixS chain. Emit the segment's relocations.
156 obj_emit_relocations (where, fixP, segment_address_in_file)
158 fixS *fixP; /* Fixup chain for this segment. */
159 relax_addressT segment_address_in_file;
161 for (; fixP; fixP = fixP->fx_next)
162 if (fixP->fx_addsy != NULL)
164 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
165 *where += md_reloc_size;
169 #ifndef obj_header_append
170 /* Aout file generation & utilities */
172 obj_header_append (where, headers)
174 object_headers *headers;
176 tc_headers_hook (headers);
179 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
180 *where += sizeof (headers->header.a_info);
181 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
182 *where += sizeof (headers->header.a_text);
183 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
184 *where += sizeof (headers->header.a_data);
185 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
186 *where += sizeof (headers->header.a_bss);
187 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
188 *where += sizeof (headers->header.a_syms);
189 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
190 *where += sizeof (headers->header.a_entry);
191 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
192 *where += sizeof (headers->header.a_trsize);
193 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
194 *where += sizeof (headers->header.a_drsize);
196 #else /* CROSS_COMPILE */
198 append (where, (char *) &headers->header, sizeof (headers->header));
199 #endif /* CROSS_COMPILE */
205 obj_symbol_to_chars (where, symbolP)
209 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
210 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
211 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
213 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
217 obj_emit_symbols (where, symbol_rootP)
219 symbolS *symbol_rootP;
223 /* Emit all symbols left in the symbol chain. */
224 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
226 /* Used to save the offset of the name. It is used to point
227 to the string in memory but must be a file offset. */
230 temp = S_GET_NAME (symbolP);
231 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
233 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
234 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
235 S_SET_EXTERNAL (symbolP);
237 obj_symbol_to_chars (where, symbolP);
238 S_SET_NAME (symbolP, temp);
242 #endif /* ! BFD_ASSEMBLER */
247 /* Assume delimiter is part of expression.
248 BSD4.2 as fails with delightful bug, so we
249 are not being incompatible here. */
250 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
251 demand_empty_rest_of_line ();
252 } /* obj_aout_line() */
257 * Handle .stabX directives, which used to be open-coded.
258 * So much creeping featurism overloaded the semantics that we decided
259 * to put all .stabX thinking in one place. Here.
261 * We try to make any .stabX directive legal. Other people's AS will often
262 * do assembly-time consistency checks: eg assigning meaning to n_type bits
263 * and "protecting" you from setting them to certain values. (They also zero
264 * certain bits before emitting symbols. Tut tut.)
266 * If an expression is not absolute we either gripe or use the relocation
267 * information. Other people's assemblers silently forget information they
268 * don't need and invent information they need that you didn't supply.
270 * .stabX directives always make a symbol table entry. It may be junk if
271 * the rest of your .stabX directive is malformed.
279 register symbolS *symbolP = 0;
280 register char *string;
283 int goof; /* TRUE if we have aborted. */
287 * Enter with input_line_pointer pointing past .stabX and any following
290 goof = 0; /* JF who forgot this?? */
293 string = demand_copy_C_string (&length);
295 if (*input_line_pointer == ',')
296 input_line_pointer++;
299 as_bad ("I need a comma after symbol's name");
307 * Input_line_pointer->after ','. String->symbol name.
311 symbolP = symbol_new (string, undefined_section, 0, (struct frag *) 0);
315 S_SET_NAME (symbolP, NULL); /* .stabd feature. */
316 S_SET_VALUE (symbolP, (char*) obstack_next_free (&frags) - frag_now->fr_literal);
317 symbolP->sy_frag = frag_now;
321 symbolP->sy_frag = &zero_address_frag;
325 symbolP->sy_frag = &zero_address_frag;
333 if (get_absolute_expression_and_terminator (&longint) == ',')
335 saved_type = longint;
336 S_SET_TYPE (symbolP, saved_type);
340 as_bad ("I want a comma after the n_type expression");
342 input_line_pointer--; /* Backup over a non-',' char. */
348 if (get_absolute_expression_and_terminator (&longint) == ',')
349 S_SET_OTHER (symbolP, longint);
352 as_bad ("I want a comma after the n_other expression");
354 input_line_pointer--; /* Backup over a non-',' char. */
360 S_SET_DESC (symbolP, get_absolute_expression ());
361 if (what == 's' || what == 'n')
363 if (*input_line_pointer != ',')
365 as_bad ("I want a comma after the n_desc expression");
370 input_line_pointer++;
375 if ((!goof) && (what == 's' || what == 'n'))
377 pseudo_set (symbolP);
378 S_SET_TYPE (symbolP, saved_type);
381 if (listing && !goof)
383 if (S_GET_TYPE (symbolP) == N_SLINE)
385 listing_source_line (S_GET_DESC (symbolP));
387 else if (S_GET_TYPE (symbolP) == N_SO || S_GET_TYPE (symbolP) == N_SOL)
389 listing_source_file (string);
395 ignore_rest_of_line ();
397 demand_empty_rest_of_line ();
398 } /* obj_aout_stab() */
406 register symbolS *symbolP;
410 * Frob invented at RMS' request. Set the n_desc of a symbol.
412 name = input_line_pointer;
413 c = get_symbol_end ();
414 p = input_line_pointer;
417 if (*input_line_pointer != ',')
420 as_bad ("Expected comma after name \"%s\"", name);
422 ignore_rest_of_line ();
426 input_line_pointer++;
427 temp = get_absolute_expression ();
429 symbolP = symbol_find_or_make (name);
431 S_SET_DESC (symbolP, temp);
433 demand_empty_rest_of_line ();
434 } /* obj_aout_desc() */
437 obj_read_begin_hook ()
440 } /* obj_read_begin_hook() */
442 #ifndef BFD_ASSEMBLER
445 obj_crawl_symbol_chain (headers)
446 object_headers *headers;
450 int symbol_number = 0;
452 tc_crawl_symbol_chain (headers);
454 symbolPP = &symbol_rootP; /*->last symbol chain link. */
455 while ((symbolP = *symbolPP) != NULL)
457 if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_DATA))
459 S_SET_SEGMENT (symbolP, SEG_TEXT);
460 } /* if pusing data into text */
462 resolve_symbol_value (symbolP);
464 /* OK, here is how we decide which symbols go out into the brave
465 new symtab. Symbols that do are:
467 * symbols with no name (stabd's?)
468 * symbols with debug info in their N_TYPE
470 Symbols that don't are:
471 * symbols that are registers
472 * symbols with \1 as their 3rd character (numeric labels)
473 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
474 switch was passed to gas.
476 All other symbols are output. We complain if a deleted
477 symbol was marked external. */
480 if (!S_IS_REGISTER (symbolP)
481 && (!S_GET_NAME (symbolP)
482 || S_IS_DEBUG (symbolP)
484 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
485 || !S_IS_DEFINED (symbolP)
486 || S_IS_EXTERNAL (symbolP)
488 || (S_GET_NAME (symbolP)[0] != '\001' && (flagseen['L'] || !S_LOCAL_NAME (symbolP)))))
490 symbolP->sy_number = symbol_number++;
492 /* The + 1 after strlen account for the \0 at the
493 end of each string */
494 if (!S_IS_STABD (symbolP))
497 symbolP->sy_name_offset = string_byte_count;
498 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
500 else /* .Stabd case. */
501 symbolP->sy_name_offset = 0;
502 symbolPP = &(symbol_next (symbolP));
506 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
508 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
511 /* Unhook it from the chain */
512 *symbolPP = symbol_next (symbolP);
513 } /* if this symbol should be in the output */
514 } /* for each symbol */
516 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
519 } /* obj_crawl_symbol_chain() */
522 * Find strings by crawling along symbol table chain.
526 obj_emit_strings (where)
532 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
533 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
534 *where += sizeof (string_byte_count);
535 #else /* CROSS_COMPILE */
536 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
537 #endif /* CROSS_COMPILE */
539 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
541 if (S_GET_NAME (symbolP))
542 append (&next_object_file_charP, S_GET_NAME (symbolP),
543 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
544 } /* walk symbol chain */
547 } /* obj_emit_strings() */
550 #define AOUT_VERSION 0
554 obj_pre_write_hook (headers)
555 object_headers *headers;
557 H_SET_DYNAMIC (headers, 0);
558 H_SET_VERSION (headers, AOUT_VERSION);
559 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
560 tc_aout_pre_write_hook (headers);
562 } /* obj_pre_write_hook() */
567 /* Strip out the section name */
569 char *section_name_end;
576 section_name = input_line_pointer;
577 c = get_symbol_end ();
578 section_name_end = input_line_pointer;
580 len = section_name_end - section_name;
581 input_line_pointer++;
582 save = input_line_pointer;
587 exp = get_absolute_expression ();
589 else if (*input_line_pointer == ',')
591 input_line_pointer++;
592 exp = get_absolute_expression ();
596 input_line_pointer = save;
601 as_bad ("subsegment index too high");
604 if (strcmp (section_name, ".text") == 0)
606 subseg_new (SEG_TEXT, (subsegT) exp);
609 if (strcmp (section_name, ".data") == 0)
612 subseg_new (SEG_TEXT, (subsegT) exp + 1000);
614 subseg_new (SEG_DATA, (subsegT) exp);
617 *section_name_end = c;
620 #endif /* ! BFD_ASSEMBLER */
622 /* end of obj-aout.c */