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"
23 #include "aout/aout64.h"
28 /* in: segT out: N_TYPE bits */
29 const short seg_N_TYPE[] =
37 N_UNDF, /* expression */
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 ((int));
66 static void obj_aout_desc PARAMS ((int));
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 & ~ (N_TYPE | N_EXT)))
122 if (sec == &bfd_abs_section
123 || sec == &bfd_und_section)
125 if (flags & BSF_EXPORT)
128 /* Set the debugging flag for constructor symbols so that BFD
129 leaves them alone. */
130 switch (type & N_TYPE)
136 sym->bsym->flags |= BSF_DEBUGGING;
142 sym->bsym->flags |= BSF_DEBUGGING;
145 S_SET_TYPE (sym, type);
155 * Crawl along a fixS chain. Emit the segment's relocations.
158 obj_emit_relocations (where, fixP, segment_address_in_file)
160 fixS *fixP; /* Fixup chain for this segment. */
161 relax_addressT segment_address_in_file;
163 for (; fixP; fixP = fixP->fx_next)
164 if (fixP->fx_addsy != NULL)
166 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
167 *where += md_reloc_size;
171 #ifndef obj_header_append
172 /* Aout file generation & utilities */
174 obj_header_append (where, headers)
176 object_headers *headers;
178 tc_headers_hook (headers);
181 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
182 *where += sizeof (headers->header.a_info);
183 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
184 *where += sizeof (headers->header.a_text);
185 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
186 *where += sizeof (headers->header.a_data);
187 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
188 *where += sizeof (headers->header.a_bss);
189 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
190 *where += sizeof (headers->header.a_syms);
191 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
192 *where += sizeof (headers->header.a_entry);
193 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
194 *where += sizeof (headers->header.a_trsize);
195 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
196 *where += sizeof (headers->header.a_drsize);
198 #else /* CROSS_COMPILE */
200 append (where, (char *) &headers->header, sizeof (headers->header));
201 #endif /* CROSS_COMPILE */
207 obj_symbol_to_chars (where, symbolP)
211 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
212 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
213 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
215 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
219 obj_emit_symbols (where, symbol_rootP)
221 symbolS *symbol_rootP;
225 /* Emit all symbols left in the symbol chain. */
226 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
228 /* Used to save the offset of the name. It is used to point
229 to the string in memory but must be a file offset. */
232 temp = S_GET_NAME (symbolP);
233 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
235 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
236 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
237 S_SET_EXTERNAL (symbolP);
239 obj_symbol_to_chars (where, symbolP);
240 S_SET_NAME (symbolP, temp);
244 #endif /* ! BFD_ASSEMBLER */
247 obj_aout_line (ignore)
250 /* Assume delimiter is part of expression.
251 BSD4.2 as fails with delightful bug, so we
252 are not being incompatible here. */
253 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
254 demand_empty_rest_of_line ();
255 } /* obj_aout_line() */
260 * Handle .stabX directives, which used to be open-coded.
261 * So much creeping featurism overloaded the semantics that we decided
262 * to put all .stabX thinking in one place. Here.
264 * We try to make any .stabX directive legal. Other people's AS will often
265 * do assembly-time consistency checks: eg assigning meaning to n_type bits
266 * and "protecting" you from setting them to certain values. (They also zero
267 * certain bits before emitting symbols. Tut tut.)
269 * If an expression is not absolute we either gripe or use the relocation
270 * information. Other people's assemblers silently forget information they
271 * don't need and invent information they need that you didn't supply.
273 * .stabX directives always make a symbol table entry. It may be junk if
274 * the rest of your .stabX directive is malformed.
282 register symbolS *symbolP = 0;
283 register char *string;
286 int goof; /* TRUE if we have aborted. */
290 * Enter with input_line_pointer pointing past .stabX and any following
293 goof = 0; /* JF who forgot this?? */
296 string = demand_copy_C_string (&length);
298 if (*input_line_pointer == ',')
299 input_line_pointer++;
302 as_bad ("I need a comma after symbol's name");
310 * Input_line_pointer->after ','. String->symbol name.
314 symbolP = symbol_new (string, undefined_section, 0, (struct frag *) 0);
318 S_SET_NAME (symbolP, NULL); /* .stabd feature. */
319 S_SET_VALUE (symbolP, (valueT) frag_now_fix ());
320 symbolP->sy_frag = frag_now;
324 symbolP->sy_frag = &zero_address_frag;
328 symbolP->sy_frag = &zero_address_frag;
336 if (get_absolute_expression_and_terminator (&longint) == ',')
338 saved_type = longint;
339 S_SET_TYPE (symbolP, saved_type);
343 as_bad ("I want a comma after the n_type expression");
345 input_line_pointer--; /* Backup over a non-',' char. */
351 if (get_absolute_expression_and_terminator (&longint) == ',')
352 S_SET_OTHER (symbolP, longint);
355 as_bad ("I want a comma after the n_other expression");
357 input_line_pointer--; /* Backup over a non-',' char. */
363 S_SET_DESC (symbolP, get_absolute_expression ());
364 if (what == 's' || what == 'n')
366 if (*input_line_pointer != ',')
368 as_bad ("I want a comma after the n_desc expression");
373 input_line_pointer++;
378 if ((!goof) && (what == 's' || what == 'n'))
380 pseudo_set (symbolP);
381 S_SET_TYPE (symbolP, saved_type);
384 if (listing && !goof)
386 if (S_GET_TYPE (symbolP) == N_SLINE)
388 listing_source_line ((unsigned int) S_GET_DESC (symbolP));
390 else if (S_GET_TYPE (symbolP) == N_SO || S_GET_TYPE (symbolP) == N_SOL)
392 listing_source_file (string);
398 ignore_rest_of_line ();
400 demand_empty_rest_of_line ();
401 } /* obj_aout_stab() */
404 obj_aout_desc (ignore)
410 register symbolS *symbolP;
414 * Frob invented at RMS' request. Set the n_desc of a symbol.
416 name = input_line_pointer;
417 c = get_symbol_end ();
418 p = input_line_pointer;
421 if (*input_line_pointer != ',')
424 as_bad ("Expected comma after name \"%s\"", name);
426 ignore_rest_of_line ();
430 input_line_pointer++;
431 temp = get_absolute_expression ();
433 symbolP = symbol_find_or_make (name);
435 S_SET_DESC (symbolP, temp);
437 demand_empty_rest_of_line ();
438 } /* obj_aout_desc() */
441 obj_read_begin_hook ()
444 } /* obj_read_begin_hook() */
446 #ifndef BFD_ASSEMBLER
449 obj_crawl_symbol_chain (headers)
450 object_headers *headers;
454 int symbol_number = 0;
456 tc_crawl_symbol_chain (headers);
458 symbolPP = &symbol_rootP; /*->last symbol chain link. */
459 while ((symbolP = *symbolPP) != NULL)
461 if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_DATA))
463 S_SET_SEGMENT (symbolP, SEG_TEXT);
464 } /* if pusing data into text */
466 resolve_symbol_value (symbolP);
468 /* OK, here is how we decide which symbols go out into the brave
469 new symtab. Symbols that do are:
471 * symbols with no name (stabd's?)
472 * symbols with debug info in their N_TYPE
474 Symbols that don't are:
475 * symbols that are registers
476 * symbols with \1 as their 3rd character (numeric labels)
477 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
478 switch was passed to gas.
480 All other symbols are output. We complain if a deleted
481 symbol was marked external. */
484 if (!S_IS_REGISTER (symbolP)
485 && (!S_GET_NAME (symbolP)
486 || S_IS_DEBUG (symbolP)
488 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
489 || !S_IS_DEFINED (symbolP)
490 || S_IS_EXTERNAL (symbolP)
492 || (S_GET_NAME (symbolP)[0] != '\001' && (flagseen['L'] || !S_LOCAL_NAME (symbolP)))))
494 symbolP->sy_number = symbol_number++;
496 /* The + 1 after strlen account for the \0 at the
497 end of each string */
498 if (!S_IS_STABD (symbolP))
501 symbolP->sy_name_offset = string_byte_count;
502 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
504 else /* .Stabd case. */
505 symbolP->sy_name_offset = 0;
506 symbolPP = &(symbol_next (symbolP));
510 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
512 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
515 /* Unhook it from the chain */
516 *symbolPP = symbol_next (symbolP);
517 } /* if this symbol should be in the output */
518 } /* for each symbol */
520 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
523 } /* obj_crawl_symbol_chain() */
526 * Find strings by crawling along symbol table chain.
530 obj_emit_strings (where)
536 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
537 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
538 *where += sizeof (string_byte_count);
539 #else /* CROSS_COMPILE */
540 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
541 #endif /* CROSS_COMPILE */
543 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
545 if (S_GET_NAME (symbolP))
546 append (&next_object_file_charP, S_GET_NAME (symbolP),
547 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
548 } /* walk symbol chain */
551 } /* obj_emit_strings() */
554 #define AOUT_VERSION 0
558 obj_pre_write_hook (headers)
559 object_headers *headers;
561 H_SET_DYNAMIC (headers, 0);
562 H_SET_VERSION (headers, AOUT_VERSION);
563 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
564 tc_aout_pre_write_hook (headers);
566 } /* obj_pre_write_hook() */
571 /* Strip out the section name */
573 char *section_name_end;
580 section_name = input_line_pointer;
581 c = get_symbol_end ();
582 section_name_end = input_line_pointer;
584 len = section_name_end - section_name;
585 input_line_pointer++;
586 save = input_line_pointer;
591 exp = get_absolute_expression ();
593 else if (*input_line_pointer == ',')
595 input_line_pointer++;
596 exp = get_absolute_expression ();
600 input_line_pointer = save;
605 as_bad ("subsegment index too high");
608 if (strcmp (section_name, ".text") == 0)
610 subseg_set (SEG_TEXT, (subsegT) exp);
613 if (strcmp (section_name, ".data") == 0)
616 subseg_set (SEG_TEXT, (subsegT) exp + 1000);
618 subseg_set (SEG_DATA, (subsegT) exp);
621 *section_name_end = c;
624 #endif /* ! BFD_ASSEMBLER */
626 /* end of obj-aout.c */