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
[] =
34 N_UNDF
, /* expression */
38 N_REGISTER
, /* register */
41 const segT N_TYPE_seg
[N_TYPE
+ 2] =
42 { /* N_TYPE == 0x1E = 32-2 */
43 SEG_UNKNOWN
, /* N_UNDF == 0 */
45 SEG_ABSOLUTE
, /* N_ABS == 2 */
47 SEG_TEXT
, /* N_TEXT == 4 */
49 SEG_DATA
, /* N_DATA == 6 */
51 SEG_BSS
, /* N_BSS == 8 */
53 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
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
,
56 SEG_REGISTER
, /* dummy N_REGISTER for regs = 30 */
61 static void obj_aout_stab
PARAMS ((int what
));
62 static void obj_aout_line
PARAMS ((void));
63 static void obj_aout_desc
PARAMS ((void));
65 const pseudo_typeS obj_pseudo_table
[] =
67 /* stabs debug info */
68 {"line", obj_aout_line
, 0}, /* source code line number */
69 {"ln", obj_aout_line
, 0}, /* coff line number that we use anyway */
70 {"desc", obj_aout_desc
, 0}, /* desc */
71 {"stabd", obj_aout_stab
, 'd'},/* stabs */
72 {"stabn", obj_aout_stab
, 'n'},/* stabs */
73 {"stabs", obj_aout_stab
, 's'},/* stabs */
75 /* coff debug pseudos (ignored) */
78 {"endef", s_ignore
, 0},
79 {"ident", s_ignore
, 0},
80 {"line", s_ignore
, 0},
83 {"size", s_ignore
, 0},
85 {"type", s_ignore
, 0},
87 {"version", s_ignore
, 0},
89 /* stabs-in-coff (?) debug pseudos (ignored) */
90 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
93 {"ABORT", s_abort
, 0},
95 {NULL
} /* end sentinel */
96 }; /* obj_pseudo_table */
102 obj_aout_frob_symbol (sym
, punt
)
108 int desc
, type
, other
;
110 flags
= sym
->bsym
->flags
;
111 desc
= S_GET_DESC (sym
);
112 type
= S_GET_TYPE (sym
);
113 other
= S_GET_OTHER (sym
);
114 sec
= sym
->bsym
->section
;
116 /* Only frob simple symbols this way right now. */
117 if (! (type
& ~0x1f))
119 if (sec
== &bfd_abs_section
120 || sec
== &bfd_und_section
)
122 if (flags
& BSF_EXPORT
)
127 sym
->bsym
->flags
|= BSF_DEBUGGING
;
130 S_SET_TYPE (sym
, type
);
140 * Crawl along a fixS chain. Emit the segment's relocations.
143 obj_emit_relocations (where
, fixP
, segment_address_in_file
)
145 fixS
*fixP
; /* Fixup chain for this segment. */
146 relax_addressT segment_address_in_file
;
148 for (; fixP
; fixP
= fixP
->fx_next
)
149 if (fixP
->fx_addsy
!= NULL
)
151 tc_aout_fix_to_chars (*where
, fixP
, segment_address_in_file
);
152 *where
+= md_reloc_size
;
156 #ifndef obj_header_append
157 /* Aout file generation & utilities */
159 obj_header_append (where
, headers
)
161 object_headers
*headers
;
163 tc_headers_hook (headers
);
166 md_number_to_chars (*where
, headers
->header
.a_info
, sizeof (headers
->header
.a_info
));
167 *where
+= sizeof (headers
->header
.a_info
);
168 md_number_to_chars (*where
, headers
->header
.a_text
, sizeof (headers
->header
.a_text
));
169 *where
+= sizeof (headers
->header
.a_text
);
170 md_number_to_chars (*where
, headers
->header
.a_data
, sizeof (headers
->header
.a_data
));
171 *where
+= sizeof (headers
->header
.a_data
);
172 md_number_to_chars (*where
, headers
->header
.a_bss
, sizeof (headers
->header
.a_bss
));
173 *where
+= sizeof (headers
->header
.a_bss
);
174 md_number_to_chars (*where
, headers
->header
.a_syms
, sizeof (headers
->header
.a_syms
));
175 *where
+= sizeof (headers
->header
.a_syms
);
176 md_number_to_chars (*where
, headers
->header
.a_entry
, sizeof (headers
->header
.a_entry
));
177 *where
+= sizeof (headers
->header
.a_entry
);
178 md_number_to_chars (*where
, headers
->header
.a_trsize
, sizeof (headers
->header
.a_trsize
));
179 *where
+= sizeof (headers
->header
.a_trsize
);
180 md_number_to_chars (*where
, headers
->header
.a_drsize
, sizeof (headers
->header
.a_drsize
));
181 *where
+= sizeof (headers
->header
.a_drsize
);
183 #else /* CROSS_COMPILE */
185 append (where
, (char *) &headers
->header
, sizeof (headers
->header
));
186 #endif /* CROSS_COMPILE */
192 obj_symbol_to_chars (where
, symbolP
)
196 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP
)), S_GET_OFFSET (symbolP
), sizeof (S_GET_OFFSET (symbolP
)));
197 md_number_to_chars ((char *) &(S_GET_DESC (symbolP
)), S_GET_DESC (symbolP
), sizeof (S_GET_DESC (symbolP
)));
198 md_number_to_chars ((char *) &(symbolP
->sy_symbol
.n_value
), S_GET_VALUE (symbolP
), sizeof (symbolP
->sy_symbol
.n_value
));
200 append (where
, (char *) &symbolP
->sy_symbol
, sizeof (obj_symbol_type
));
204 obj_emit_symbols (where
, symbol_rootP
)
206 symbolS
*symbol_rootP
;
210 /* Emit all symbols left in the symbol chain. */
211 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
213 /* Used to save the offset of the name. It is used to point
214 to the string in memory but must be a file offset. */
217 temp
= S_GET_NAME (symbolP
);
218 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
220 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
221 if (!S_IS_DEBUG (symbolP
) && !S_IS_DEFINED (symbolP
))
222 S_SET_EXTERNAL (symbolP
);
224 obj_symbol_to_chars (where
, symbolP
);
225 S_SET_NAME (symbolP
, temp
);
229 #endif /* ! BFD_ASSEMBLER */
234 /* Assume delimiter is part of expression.
235 BSD4.2 as fails with delightful bug, so we
236 are not being incompatible here. */
237 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
238 demand_empty_rest_of_line ();
239 } /* obj_aout_line() */
244 * Handle .stabX directives, which used to be open-coded.
245 * So much creeping featurism overloaded the semantics that we decided
246 * to put all .stabX thinking in one place. Here.
248 * We try to make any .stabX directive legal. Other people's AS will often
249 * do assembly-time consistency checks: eg assigning meaning to n_type bits
250 * and "protecting" you from setting them to certain values. (They also zero
251 * certain bits before emitting symbols. Tut tut.)
253 * If an expression is not absolute we either gripe or use the relocation
254 * information. Other people's assemblers silently forget information they
255 * don't need and invent information they need that you didn't supply.
257 * .stabX directives always make a symbol table entry. It may be junk if
258 * the rest of your .stabX directive is malformed.
266 register symbolS
*symbolP
= 0;
267 register char *string
;
270 int goof
; /* TRUE if we have aborted. */
274 * Enter with input_line_pointer pointing past .stabX and any following
277 goof
= 0; /* JF who forgot this?? */
280 string
= demand_copy_C_string (&length
);
282 if (*input_line_pointer
== ',')
283 input_line_pointer
++;
286 as_bad ("I need a comma after symbol's name");
294 * Input_line_pointer->after ','. String->symbol name.
298 symbolP
= symbol_new (string
, undefined_section
, 0, (struct frag
*) 0);
302 S_SET_NAME (symbolP
, NULL
); /* .stabd feature. */
303 S_SET_VALUE (symbolP
, (char*) obstack_next_free (&frags
) - frag_now
->fr_literal
);
304 symbolP
->sy_frag
= frag_now
;
308 symbolP
->sy_frag
= &zero_address_frag
;
312 symbolP
->sy_frag
= &zero_address_frag
;
320 if (get_absolute_expression_and_terminator (&longint
) == ',')
322 saved_type
= longint
;
323 S_SET_TYPE (symbolP
, saved_type
);
327 as_bad ("I want a comma after the n_type expression");
329 input_line_pointer
--; /* Backup over a non-',' char. */
335 if (get_absolute_expression_and_terminator (&longint
) == ',')
336 S_SET_OTHER (symbolP
, longint
);
339 as_bad ("I want a comma after the n_other expression");
341 input_line_pointer
--; /* Backup over a non-',' char. */
347 S_SET_DESC (symbolP
, get_absolute_expression ());
348 if (what
== 's' || what
== 'n')
350 if (*input_line_pointer
!= ',')
352 as_bad ("I want a comma after the n_desc expression");
357 input_line_pointer
++;
362 if ((!goof
) && (what
== 's' || what
== 'n'))
364 pseudo_set (symbolP
);
365 S_SET_TYPE (symbolP
, saved_type
);
368 if (listing
&& !goof
)
370 if (S_GET_TYPE (symbolP
) == N_SLINE
)
372 listing_source_line (S_GET_DESC (symbolP
));
374 else if (S_GET_TYPE (symbolP
) == N_SO
|| S_GET_TYPE (symbolP
) == N_SOL
)
376 listing_source_file (string
);
382 ignore_rest_of_line ();
384 demand_empty_rest_of_line ();
385 } /* obj_aout_stab() */
393 register symbolS
*symbolP
;
397 * Frob invented at RMS' request. Set the n_desc of a symbol.
399 name
= input_line_pointer
;
400 c
= get_symbol_end ();
401 p
= input_line_pointer
;
404 if (*input_line_pointer
!= ',')
407 as_bad ("Expected comma after name \"%s\"", name
);
409 ignore_rest_of_line ();
413 input_line_pointer
++;
414 temp
= get_absolute_expression ();
416 symbolP
= symbol_find_or_make (name
);
418 S_SET_DESC (symbolP
, temp
);
420 demand_empty_rest_of_line ();
421 } /* obj_aout_desc() */
424 obj_read_begin_hook ()
427 } /* obj_read_begin_hook() */
429 #ifndef BFD_ASSEMBLER
432 obj_crawl_symbol_chain (headers
)
433 object_headers
*headers
;
437 int symbol_number
= 0;
439 tc_crawl_symbol_chain (headers
);
441 symbolPP
= &symbol_rootP
; /*->last symbol chain link. */
442 while ((symbolP
= *symbolPP
) != NULL
)
444 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
446 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
447 } /* if pusing data into text */
449 resolve_symbol_value (symbolP
);
451 /* OK, here is how we decide which symbols go out into the brave
452 new symtab. Symbols that do are:
454 * symbols with no name (stabd's?)
455 * symbols with debug info in their N_TYPE
457 Symbols that don't are:
458 * symbols that are registers
459 * symbols with \1 as their 3rd character (numeric labels)
460 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
461 switch was passed to gas.
463 All other symbols are output. We complain if a deleted
464 symbol was marked external. */
467 if (!S_IS_REGISTER (symbolP
)
468 && (!S_GET_NAME (symbolP
)
469 || S_IS_DEBUG (symbolP
)
471 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
472 || !S_IS_DEFINED (symbolP
)
473 || S_IS_EXTERNAL (symbolP
)
475 || (S_GET_NAME (symbolP
)[0] != '\001' && (flagseen
['L'] || !S_LOCAL_NAME (symbolP
)))))
477 symbolP
->sy_number
= symbol_number
++;
479 /* The + 1 after strlen account for the \0 at the
480 end of each string */
481 if (!S_IS_STABD (symbolP
))
484 symbolP
->sy_name_offset
= string_byte_count
;
485 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
487 else /* .Stabd case. */
488 symbolP
->sy_name_offset
= 0;
489 symbolPP
= &(symbol_next (symbolP
));
493 if (S_IS_EXTERNAL (symbolP
) || !S_IS_DEFINED (symbolP
))
495 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP
)));
498 /* Unhook it from the chain */
499 *symbolPP
= symbol_next (symbolP
);
500 } /* if this symbol should be in the output */
501 } /* for each symbol */
503 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
506 } /* obj_crawl_symbol_chain() */
509 * Find strings by crawling along symbol table chain.
513 obj_emit_strings (where
)
519 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
520 md_number_to_chars (*where
, string_byte_count
, sizeof (string_byte_count
));
521 *where
+= sizeof (string_byte_count
);
522 #else /* CROSS_COMPILE */
523 append (where
, (char *) &string_byte_count
, (unsigned long) sizeof (string_byte_count
));
524 #endif /* CROSS_COMPILE */
526 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
528 if (S_GET_NAME (symbolP
))
529 append (&next_object_file_charP
, S_GET_NAME (symbolP
),
530 (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
531 } /* walk symbol chain */
534 } /* obj_emit_strings() */
537 #define AOUT_VERSION 0
541 obj_pre_write_hook (headers
)
542 object_headers
*headers
;
544 H_SET_DYNAMIC (headers
, 0);
545 H_SET_VERSION (headers
, AOUT_VERSION
);
546 H_SET_MACHTYPE (headers
, AOUT_MACHTYPE
);
547 tc_aout_pre_write_hook (headers
);
549 } /* obj_pre_write_hook() */
554 /* Strip out the section name */
556 char *section_name_end
;
563 section_name
= input_line_pointer
;
564 c
= get_symbol_end ();
565 section_name_end
= input_line_pointer
;
567 len
= section_name_end
- section_name
;
568 input_line_pointer
++;
569 save
= input_line_pointer
;
574 exp
= get_absolute_expression ();
576 else if (*input_line_pointer
== ',')
578 input_line_pointer
++;
579 exp
= get_absolute_expression ();
583 input_line_pointer
= save
;
588 as_bad ("subsegment index too high");
591 if (strcmp (section_name
, ".text") == 0)
593 subseg_new (SEG_TEXT
, (subsegT
) exp
);
596 if (strcmp (section_name
, ".data") == 0)
599 subseg_new (SEG_TEXT
, (subsegT
) exp
+ 1000);
601 subseg_new (SEG_DATA
, (subsegT
) exp
);
604 *section_name_end
= c
;
607 #endif /* ! BFD_ASSEMBLER */
609 /* end of obj-aout.c */