1 /* b.out object file format
2 Copyright (C) 1989, 1990, 1991, 1992 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. */
22 #include "aout/stab_gnu.h"
23 const short /* in: segT out: N_TYPE bits */
34 N_UNDF
, /* bignum/flonum */
35 N_UNDF
, /* difference */
36 N_REGISTER
, /* register */
39 const segT N_TYPE_seg
[N_TYPE
+ 2] =
40 { /* N_TYPE == 0x1E = 32-2 */
41 SEG_UNKNOWN
, /* N_UNDF == 0 */
43 SEG_ABSOLUTE
, /* N_ABS == 2 */
45 SEG_TEXT
, /* N_TEXT == 4 */
47 SEG_DATA
, /* N_DATA == 6 */
49 SEG_BSS
, /* N_BSS == 8 */
51 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
52 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
53 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
54 SEG_REGISTER
, /* dummy N_REGISTER for regs = 30 */
59 static void obj_bout_stab (int what
);
60 static void obj_bout_line (void);
61 static void obj_bout_desc (void);
62 #else /* not __STDC__ */
63 static void obj_bout_desc ();
64 static void obj_bout_stab ();
65 static void obj_bout_line ();
66 #endif /* not __STDC__ */
68 const pseudo_typeS obj_pseudo_table
[] =
70 /* stabs (aka a.out aka b.out directives for debug symbols) */
71 {"desc", obj_bout_desc
, 0}, /* def */
72 {"line", obj_bout_line
, 0}, /* source code line number */
73 {"stabd", obj_bout_stab
, 'd'},/* stabs */
74 {"stabn", obj_bout_stab
, 'n'},/* stabs */
75 {"stabs", obj_bout_stab
, 's'},/* stabs */
77 /* coff debugging directives. Currently ignored silently */
80 {"endef", s_ignore
, 0},
83 {"size", s_ignore
, 0},
85 {"type", s_ignore
, 0},
88 /* other stuff we don't handle */
89 {"ABORT", s_ignore
, 0},
90 {"ident", s_ignore
, 0},
92 {NULL
} /* end sentinel */
93 }; /* obj_pseudo_table */
100 * Crawl along a fixS chain. Emit the segment's relocations.
103 obj_emit_relocations (where
, fixP
, segment_address_in_file
)
105 fixS
*fixP
; /* Fixup chain for this segment. */
106 relax_addressT segment_address_in_file
;
108 for (; fixP
; fixP
= fixP
->fx_next
)
110 if (fixP
->fx_addsy
!= NULL
111 || fixP
->fx_r_type
!= NO_RELOC
)
113 tc_bout_fix_to_chars (*where
, fixP
, segment_address_in_file
);
114 *where
+= sizeof (struct relocation_info
);
115 } /* if there's a symbol */
116 } /* for each fixup */
118 } /* emit_relocations() */
120 /* Aout file generation & utilities */
122 /* Convert a lvalue to machine dependent data */
124 obj_header_append (where
, headers
)
126 object_headers
*headers
;
128 /* Always leave in host byte order */
130 headers
->header
.a_talign
= section_alignment
[SEG_TEXT
];
132 if (headers
->header
.a_talign
< 2)
134 headers
->header
.a_talign
= 2;
135 } /* force to at least 2 */
137 headers
->header
.a_dalign
= section_alignment
[SEG_DATA
];
138 headers
->header
.a_balign
= section_alignment
[SEG_BSS
];
140 headers
->header
.a_tload
= 0;
141 headers
->header
.a_dload
= md_section_align (SEG_DATA
, H_GET_TEXT_SIZE (headers
));
143 headers
->header
.a_relaxable
= linkrelax
;
146 md_number_to_chars (*where
, headers
->header
.a_magic
, sizeof (headers
->header
.a_magic
));
147 *where
+= sizeof (headers
->header
.a_magic
);
148 md_number_to_chars (*where
, headers
->header
.a_text
, sizeof (headers
->header
.a_text
));
149 *where
+= sizeof (headers
->header
.a_text
);
150 md_number_to_chars (*where
, headers
->header
.a_data
, sizeof (headers
->header
.a_data
));
151 *where
+= sizeof (headers
->header
.a_data
);
152 md_number_to_chars (*where
, headers
->header
.a_bss
, sizeof (headers
->header
.a_bss
));
153 *where
+= sizeof (headers
->header
.a_bss
);
154 md_number_to_chars (*where
, headers
->header
.a_syms
, sizeof (headers
->header
.a_syms
));
155 *where
+= sizeof (headers
->header
.a_syms
);
156 md_number_to_chars (*where
, headers
->header
.a_entry
, sizeof (headers
->header
.a_entry
));
157 *where
+= sizeof (headers
->header
.a_entry
);
158 md_number_to_chars (*where
, headers
->header
.a_trsize
, sizeof (headers
->header
.a_trsize
));
159 *where
+= sizeof (headers
->header
.a_trsize
);
160 md_number_to_chars (*where
, headers
->header
.a_drsize
, sizeof (headers
->header
.a_drsize
));
161 *where
+= sizeof (headers
->header
.a_drsize
);
162 md_number_to_chars (*where
, headers
->header
.a_tload
, sizeof (headers
->header
.a_tload
));
163 *where
+= sizeof (headers
->header
.a_tload
);
164 md_number_to_chars (*where
, headers
->header
.a_dload
, sizeof (headers
->header
.a_dload
));
165 *where
+= sizeof (headers
->header
.a_dload
);
166 md_number_to_chars (*where
, headers
->header
.a_talign
, sizeof (headers
->header
.a_talign
));
167 *where
+= sizeof (headers
->header
.a_talign
);
168 md_number_to_chars (*where
, headers
->header
.a_dalign
, sizeof (headers
->header
.a_dalign
));
169 *where
+= sizeof (headers
->header
.a_dalign
);
170 md_number_to_chars (*where
, headers
->header
.a_balign
, sizeof (headers
->header
.a_balign
));
171 *where
+= sizeof (headers
->header
.a_balign
);
172 md_number_to_chars (*where
, headers
->header
.a_relaxable
, sizeof (headers
->header
.a_relaxable
));
173 *where
+= sizeof (headers
->header
.a_relaxable
);
174 #else /* ! CROSS_COMPILE */
175 append (where
, (char *) &headers
->header
, sizeof (headers
->header
));
176 #endif /* ! CROSS_COMPILE */
177 } /* a_header_append() */
180 obj_symbol_to_chars (where
, symbolP
)
184 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP
)), S_GET_OFFSET (symbolP
), sizeof (S_GET_OFFSET (symbolP
)));
185 md_number_to_chars ((char *) &(S_GET_DESC (symbolP
)), S_GET_DESC (symbolP
), sizeof (S_GET_DESC (symbolP
)));
186 md_number_to_chars ((char *) &(S_GET_VALUE (symbolP
)), S_GET_VALUE (symbolP
), sizeof (S_GET_VALUE (symbolP
)));
188 append (where
, (char *) &symbolP
->sy_symbol
, sizeof (obj_symbol_type
));
189 } /* obj_symbol_to_chars() */
192 obj_emit_symbols (where
, symbol_rootP
)
194 symbolS
*symbol_rootP
;
199 * Emit all symbols left in the symbol chain.
201 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
203 /* Used to save the offset of the name. It is used to point
204 to the string in memory but must be a file offset. */
207 temp
= S_GET_NAME (symbolP
);
208 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
210 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
211 if (!S_IS_DEBUG (symbolP
) && !S_IS_DEFINED (symbolP
))
212 S_SET_EXTERNAL (symbolP
);
214 obj_symbol_to_chars (where
, symbolP
);
215 S_SET_NAME (symbolP
, temp
);
217 } /* emit_symbols() */
220 obj_symbol_new_hook (symbolP
)
223 S_SET_OTHER (symbolP
, 0);
224 S_SET_DESC (symbolP
, 0);
226 } /* obj_symbol_new_hook() */
231 /* Assume delimiter is part of expression. */
232 /* BSD4.2 as fails with delightful bug, so we */
233 /* are not being incompatible here. */
234 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
235 demand_empty_rest_of_line ();
236 } /* obj_bout_line() */
241 * Handle .stabX directives, which used to be open-coded.
242 * So much creeping featurism overloaded the semantics that we decided
243 * to put all .stabX thinking in one place. Here.
245 * We try to make any .stabX directive legal. Other people's AS will often
246 * do assembly-time consistency checks: eg assigning meaning to n_type bits
247 * and "protecting" you from setting them to certain values. (They also zero
248 * certain bits before emitting symbols. Tut tut.)
250 * If an expression is not absolute we either gripe or use the relocation
251 * information. Other people's assemblers silently forget information they
252 * don't need and invent information they need that you didn't supply.
254 * .stabX directives always make a symbol table entry. It may be junk if
255 * the rest of your .stabX directive is malformed.
261 register symbolS
*symbolP
= 0;
262 register char *string
;
265 int goof
; /* TRUE if we have aborted. */
269 * Enter with input_line_pointer pointing past .stabX and any following
272 goof
= 0; /* JF who forgot this?? */
275 string
= demand_copy_C_string (&length
);
277 if (*input_line_pointer
== ',')
278 input_line_pointer
++;
281 as_bad ("I need a comma after symbol's name");
289 * Input_line_pointer->after ','. String->symbol name.
293 symbolP
= symbol_new (string
,
300 S_SET_NAME (symbolP
, NULL
); /* .stabd feature. */
301 S_SET_VALUE (symbolP
, obstack_next_free (&frags
) -
302 frag_now
->fr_literal
);
303 symbolP
->sy_frag
= frag_now
;
307 symbolP
->sy_frag
= &zero_address_frag
;
311 symbolP
->sy_frag
= &zero_address_frag
;
318 if (get_absolute_expression_and_terminator (&longint
) == ',')
319 symbolP
->sy_symbol
.n_type
= saved_type
= longint
;
322 as_bad ("I want a comma after the n_type expression");
324 input_line_pointer
--; /* Backup over a non-',' char. */
329 if (get_absolute_expression_and_terminator (&longint
) == ',')
330 S_SET_OTHER (symbolP
, longint
);
333 as_bad ("I want a comma after the n_other expression");
335 input_line_pointer
--; /* Backup over a non-',' char. */
340 S_SET_DESC (symbolP
, get_absolute_expression ());
341 if (what
== 's' || what
== 'n')
343 if (*input_line_pointer
!= ',')
345 as_bad ("I want a comma after the n_desc expression");
350 input_line_pointer
++;
354 if ((!goof
) && (what
== 's' || what
== 'n'))
356 pseudo_set (symbolP
);
357 symbolP
->sy_symbol
.n_type
= saved_type
;
363 if (listing
&& !goof
)
365 if (symbolP
->sy_symbol
.n_type
== N_SLINE
)
368 listing_source_line (symbolP
->sy_symbol
.n_desc
);
370 else if (symbolP
->sy_symbol
.n_type
== N_SO
371 || symbolP
->sy_symbol
.n_type
== N_SOL
)
373 listing_source_file (string
);
381 ignore_rest_of_line ();
383 demand_empty_rest_of_line ();
384 } /* obj_bout_stab() */
392 register symbolS
*symbolP
;
396 * Frob invented at RMS' request. Set the n_desc of a symbol.
398 name
= input_line_pointer
;
399 c
= get_symbol_end ();
400 p
= input_line_pointer
;
403 if (*input_line_pointer
!= ',')
406 as_bad ("Expected comma after name \"%s\"", name
);
408 ignore_rest_of_line ();
412 input_line_pointer
++;
413 temp
= get_absolute_expression ();
415 symbolP
= symbol_find_or_make (name
);
417 S_SET_DESC (symbolP
, temp
);
419 demand_empty_rest_of_line ();
420 } /* obj_bout_desc() */
423 obj_read_begin_hook ()
426 } /* obj_read_begin_hook() */
429 obj_crawl_symbol_chain (headers
)
430 object_headers
*headers
;
434 int symbol_number
= 0;
436 /* JF deal with forward references first... */
437 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
439 if (symbolP
->sy_forward
)
441 S_SET_VALUE (symbolP
, S_GET_VALUE (symbolP
)
442 + S_GET_VALUE (symbolP
->sy_forward
)
443 + symbolP
->sy_forward
->sy_frag
->fr_address
);
445 symbolP
->sy_forward
= 0;
446 } /* if it has a forward reference */
447 } /* walk the symbol chain */
449 tc_crawl_symbol_chain (headers
);
451 symbolPP
= &symbol_rootP
; /*->last symbol chain link. */
452 while ((symbolP
= *symbolPP
) != NULL
)
454 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
456 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
457 } /* if pusing data into text */
459 S_SET_VALUE (symbolP
, S_GET_VALUE (symbolP
) + symbolP
->sy_frag
->fr_address
);
461 /* OK, here is how we decide which symbols go out into the
462 brave new symtab. Symbols that do are:
464 * symbols with no name (stabd's?)
465 * symbols with debug info in their N_TYPE
467 Symbols that don't are:
468 * symbols that are registers
469 * symbols with \1 as their 3rd character (numeric labels)
470 * "local labels" as defined by S_LOCAL_NAME(name)
471 if the -L switch was passed to gas.
473 All other symbols are output. We complain if a deleted
474 symbol was marked external. */
478 && !S_IS_REGISTER (symbolP
)
479 && (!S_GET_NAME (symbolP
)
480 || S_IS_DEBUG (symbolP
)
482 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
483 || !S_IS_DEFINED (symbolP
)
484 || S_IS_EXTERNAL (symbolP
)
486 || (S_GET_NAME (symbolP
)[0] != '\001' && (flagseen
['L'] || !S_LOCAL_NAME (symbolP
)))))
488 symbolP
->sy_number
= symbol_number
++;
490 /* The + 1 after strlen account for the \0 at the
491 end of each string */
492 if (!S_IS_STABD (symbolP
))
495 symbolP
->sy_name_offset
= string_byte_count
;
496 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
498 else /* .Stabd case. */
499 symbolP
->sy_name_offset
= 0;
500 symbolPP
= &(symbol_next (symbolP
));
504 if (S_IS_EXTERNAL (symbolP
) || !S_IS_DEFINED (symbolP
))
506 as_bad ("Local symbol %s never defined", S_GET_NAME (symbolP
));
509 /* Unhook it from the chain */
510 *symbolPP
= symbol_next (symbolP
);
511 } /* if this symbol should be in the output */
512 } /* for each symbol */
514 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
517 } /* obj_crawl_symbol_chain() */
520 * Find strings by crawling along symbol table chain.
524 obj_emit_strings (where
)
530 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
531 md_number_to_chars (*where
, string_byte_count
, sizeof (string_byte_count
));
532 *where
+= sizeof (string_byte_count
);
533 #else /* CROSS_COMPILE */
534 append (where
, (char *) &string_byte_count
, (unsigned long) sizeof (string_byte_count
));
535 #endif /* CROSS_COMPILE */
537 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
539 if (S_GET_NAME (symbolP
))
540 append (where
, S_GET_NAME (symbolP
), (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
541 } /* walk symbol chain */
544 } /* obj_emit_strings() */
546 /* end of obj-bout.c */