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 /* Is this part format-dependent? */
118 + S_GET_VALUE (sym->sy_forward)
119 + sym->sy_forward->sy_frag->fr_address
124 flags = sym->bsym->flags;
125 desc = S_GET_DESC (sym);
126 type = S_GET_TYPE (sym);
127 other = S_GET_OTHER (sym);
128 sec = sym->bsym->section;
130 /* Only frob simple symbols this way right now. */
131 if (! (type & ~0x1f))
133 if (sec == &bfd_abs_section
134 || sec == &bfd_und_section)
136 if (flags & BSF_EXPORT)
141 sym->bsym->flags |= BSF_DEBUGGING;
144 S_SET_TYPE (sym, type);
154 * Crawl along a fixS chain. Emit the segment's relocations.
157 obj_emit_relocations (where, fixP, segment_address_in_file)
159 fixS *fixP; /* Fixup chain for this segment. */
160 relax_addressT segment_address_in_file;
162 for (; fixP; fixP = fixP->fx_next)
163 if (fixP->fx_addsy != NULL)
165 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
166 *where += md_reloc_size;
170 #ifndef obj_header_append
171 /* Aout file generation & utilities */
173 obj_header_append (where, headers)
175 object_headers *headers;
177 tc_headers_hook (headers);
180 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
181 *where += sizeof (headers->header.a_info);
182 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
183 *where += sizeof (headers->header.a_text);
184 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
185 *where += sizeof (headers->header.a_data);
186 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
187 *where += sizeof (headers->header.a_bss);
188 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
189 *where += sizeof (headers->header.a_syms);
190 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
191 *where += sizeof (headers->header.a_entry);
192 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
193 *where += sizeof (headers->header.a_trsize);
194 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
195 *where += sizeof (headers->header.a_drsize);
197 #else /* CROSS_COMPILE */
199 append (where, (char *) &headers->header, sizeof (headers->header));
200 #endif /* CROSS_COMPILE */
206 obj_symbol_to_chars (where, symbolP)
210 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
211 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
212 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
214 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
218 obj_emit_symbols (where, symbol_rootP)
220 symbolS *symbol_rootP;
224 /* Emit all symbols left in the symbol chain. */
225 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
227 /* Used to save the offset of the name. It is used to point
228 to the string in memory but must be a file offset. */
231 temp = S_GET_NAME (symbolP);
232 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
234 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
235 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
236 S_SET_EXTERNAL (symbolP);
238 obj_symbol_to_chars (where, symbolP);
239 S_SET_NAME (symbolP, temp);
243 #endif /* ! BFD_ASSEMBLER */
248 /* Assume delimiter is part of expression.
249 BSD4.2 as fails with delightful bug, so we
250 are not being incompatible here. */
251 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
252 demand_empty_rest_of_line ();
253 } /* obj_aout_line() */
258 * Handle .stabX directives, which used to be open-coded.
259 * So much creeping featurism overloaded the semantics that we decided
260 * to put all .stabX thinking in one place. Here.
262 * We try to make any .stabX directive legal. Other people's AS will often
263 * do assembly-time consistency checks: eg assigning meaning to n_type bits
264 * and "protecting" you from setting them to certain values. (They also zero
265 * certain bits before emitting symbols. Tut tut.)
267 * If an expression is not absolute we either gripe or use the relocation
268 * information. Other people's assemblers silently forget information they
269 * don't need and invent information they need that you didn't supply.
271 * .stabX directives always make a symbol table entry. It may be junk if
272 * the rest of your .stabX directive is malformed.
280 register symbolS *symbolP = 0;
281 register char *string;
284 int goof; /* TRUE if we have aborted. */
288 * Enter with input_line_pointer pointing past .stabX and any following
291 goof = 0; /* JF who forgot this?? */
294 string = demand_copy_C_string (&length);
296 if (*input_line_pointer == ',')
297 input_line_pointer++;
300 as_bad ("I need a comma after symbol's name");
308 * Input_line_pointer->after ','. String->symbol name.
312 symbolP = symbol_new (string, undefined_section, 0, (struct frag *) 0);
316 S_SET_NAME (symbolP, NULL); /* .stabd feature. */
317 S_SET_VALUE (symbolP, (char*) obstack_next_free (&frags) - frag_now->fr_literal);
318 symbolP->sy_frag = frag_now;
322 symbolP->sy_frag = &zero_address_frag;
326 symbolP->sy_frag = &zero_address_frag;
334 if (get_absolute_expression_and_terminator (&longint) == ',')
336 saved_type = longint;
337 S_SET_TYPE (symbolP, saved_type);
341 as_bad ("I want a comma after the n_type expression");
343 input_line_pointer--; /* Backup over a non-',' char. */
349 if (get_absolute_expression_and_terminator (&longint) == ',')
350 S_SET_OTHER (symbolP, longint);
353 as_bad ("I want a comma after the n_other expression");
355 input_line_pointer--; /* Backup over a non-',' char. */
361 S_SET_DESC (symbolP, get_absolute_expression ());
362 if (what == 's' || what == 'n')
364 if (*input_line_pointer != ',')
366 as_bad ("I want a comma after the n_desc expression");
371 input_line_pointer++;
376 if ((!goof) && (what == 's' || what == 'n'))
378 pseudo_set (symbolP);
379 S_SET_TYPE (symbolP, saved_type);
382 if (listing && !goof)
384 if (S_GET_TYPE (symbolP) == N_SLINE)
386 listing_source_line (S_GET_DESC (symbolP));
388 else if (S_GET_TYPE (symbolP) == N_SO || S_GET_TYPE (symbolP) == N_SOL)
390 listing_source_file (string);
396 ignore_rest_of_line ();
398 demand_empty_rest_of_line ();
399 } /* obj_aout_stab() */
407 register symbolS *symbolP;
411 * Frob invented at RMS' request. Set the n_desc of a symbol.
413 name = input_line_pointer;
414 c = get_symbol_end ();
415 p = input_line_pointer;
418 if (*input_line_pointer != ',')
421 as_bad ("Expected comma after name \"%s\"", name);
423 ignore_rest_of_line ();
427 input_line_pointer++;
428 temp = get_absolute_expression ();
430 symbolP = symbol_find_or_make (name);
432 S_SET_DESC (symbolP, temp);
434 demand_empty_rest_of_line ();
435 } /* obj_aout_desc() */
438 obj_read_begin_hook ()
441 } /* obj_read_begin_hook() */
443 #ifndef BFD_ASSEMBLER
446 obj_crawl_symbol_chain (headers)
447 object_headers *headers;
451 int symbol_number = 0;
453 /* JF deal with forward references first... */
454 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
456 if (symbolP->sy_forward)
458 S_SET_VALUE (symbolP, S_GET_VALUE (symbolP)
459 + S_GET_VALUE (symbolP->sy_forward)
460 + symbolP->sy_forward->sy_frag->fr_address);
462 symbolP->sy_forward = 0;
463 } /* if it has a forward reference */
464 } /* walk the symbol chain */
466 tc_crawl_symbol_chain (headers);
468 symbolPP = &symbol_rootP; /*->last symbol chain link. */
469 while ((symbolP = *symbolPP) != NULL)
471 if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_DATA))
473 S_SET_SEGMENT (symbolP, SEG_TEXT);
474 } /* if pusing data into text */
476 S_SET_VALUE (symbolP, S_GET_VALUE (symbolP) + symbolP->sy_frag->fr_address);
478 /* OK, here is how we decide which symbols go out into the brave
479 new symtab. Symbols that do are:
481 * symbols with no name (stabd's?)
482 * symbols with debug info in their N_TYPE
484 Symbols that don't are:
485 * symbols that are registers
486 * symbols with \1 as their 3rd character (numeric labels)
487 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
488 switch was passed to gas.
490 All other symbols are output. We complain if a deleted
491 symbol was marked external. */
494 if (!S_IS_REGISTER (symbolP)
495 && (!S_GET_NAME (symbolP)
496 || S_IS_DEBUG (symbolP)
498 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
499 || !S_IS_DEFINED (symbolP)
500 || S_IS_EXTERNAL (symbolP)
502 || (S_GET_NAME (symbolP)[0] != '\001' && (flagseen['L'] || !S_LOCAL_NAME (symbolP)))))
504 symbolP->sy_number = symbol_number++;
506 /* The + 1 after strlen account for the \0 at the
507 end of each string */
508 if (!S_IS_STABD (symbolP))
511 symbolP->sy_name_offset = string_byte_count;
512 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
514 else /* .Stabd case. */
515 symbolP->sy_name_offset = 0;
516 symbolPP = &(symbol_next (symbolP));
520 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
522 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
525 /* Unhook it from the chain */
526 *symbolPP = symbol_next (symbolP);
527 } /* if this symbol should be in the output */
528 } /* for each symbol */
530 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
533 } /* obj_crawl_symbol_chain() */
536 * Find strings by crawling along symbol table chain.
540 obj_emit_strings (where)
546 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
547 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
548 *where += sizeof (string_byte_count);
549 #else /* CROSS_COMPILE */
550 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
551 #endif /* CROSS_COMPILE */
553 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
555 if (S_GET_NAME (symbolP))
556 append (&next_object_file_charP, S_GET_NAME (symbolP),
557 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
558 } /* walk symbol chain */
561 } /* obj_emit_strings() */
564 #define AOUT_VERSION 0
568 obj_pre_write_hook (headers)
569 object_headers *headers;
571 H_SET_DYNAMIC (headers, 0);
572 H_SET_VERSION (headers, AOUT_VERSION);
573 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
574 tc_aout_pre_write_hook (headers);
576 } /* obj_pre_write_hook() */
581 /* Strip out the section name */
583 char *section_name_end;
590 section_name = input_line_pointer;
591 c = get_symbol_end ();
592 section_name_end = input_line_pointer;
594 len = section_name_end - section_name;
595 input_line_pointer++;
596 save = input_line_pointer;
601 exp = get_absolute_expression ();
603 else if (*input_line_pointer == ',')
605 input_line_pointer++;
606 exp = get_absolute_expression ();
610 input_line_pointer = save;
615 as_bad ("subsegment index too high");
618 if (strcmp (section_name, ".text") == 0)
620 subseg_new (SEG_TEXT, (subsegT) exp);
623 if (strcmp (section_name, ".data") == 0)
626 subseg_new (SEG_TEXT, (subsegT) exp + 1000);
628 subseg_new (SEG_DATA, (subsegT) exp);
631 *section_name_end = c;
634 #endif /* ! BFD_ASSEMBLER */
636 /* end of obj-aout.c */