record that files were removed
[deliverable/binutils-gdb.git] / gas / config / obj-aout.c
CommitLineData
fecd2382 1/* a.out object file format
a87b3269 2 Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
a39116f1
RP
3
4 This file is part of GAS, the GNU Assembler.
5
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.
10
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.
15
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. */
fecd2382
RP
19
20#include "as.h"
a39116f1 21#include "aout/stab_gnu.h"
fecd2382
RP
22#include "obstack.h"
23
a39116f1 24/* in: segT out: N_TYPE bits */
fecd2382 25const short seg_N_TYPE[] = {
a39116f1
RP
26 N_ABS,
27 N_TEXT,
28 N_DATA,
29 N_BSS,
30 N_UNDF, /* unknown */
31 N_UNDF, /* absent */
32 N_UNDF, /* pass1 */
33 N_UNDF, /* error */
34 N_UNDF, /* bignum/flonum */
35 N_UNDF, /* difference */
36 N_UNDF, /* debug */
37 N_UNDF, /* ntv */
38 N_UNDF, /* ptv */
39 N_REGISTER, /* register */
fecd2382
RP
40};
41
42const segT N_TYPE_seg [N_TYPE+2] = { /* N_TYPE == 0x1E = 32-2 */
43 SEG_UNKNOWN, /* N_UNDF == 0 */
44 SEG_GOOF,
45 SEG_ABSOLUTE, /* N_ABS == 2 */
46 SEG_GOOF,
47 SEG_TEXT, /* N_TEXT == 4 */
48 SEG_GOOF,
49 SEG_DATA, /* N_DATA == 6 */
50 SEG_GOOF,
51 SEG_BSS, /* N_BSS == 8 */
52 SEG_GOOF,
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 */
57 SEG_GOOF,
58};
59
a87b3269 60#if __STDC__ == 1
fecd2382
RP
61static void obj_aout_stab(int what);
62static void obj_aout_line(void);
63static void obj_aout_desc(void);
a87b3269 64#else /* not __STDC__ */
fecd2382
RP
65static void obj_aout_desc();
66static void obj_aout_stab();
67static void obj_aout_line();
a87b3269 68#endif /* not __STDC__ */
fecd2382
RP
69
70const pseudo_typeS obj_pseudo_table[] = {
a39116f1
RP
71#ifndef IGNORE_DEBUG
72 /* stabs debug info */
fecd2382 73 { "line", obj_aout_line, 0 }, /* source code line number */
a39116f1
RP
74 { "ln", obj_aout_line, 0 }, /* coff line number that we use anyway */
75 { "desc", obj_aout_desc, 0 }, /* desc */
fecd2382
RP
76 { "stabd", obj_aout_stab, 'd' }, /* stabs */
77 { "stabn", obj_aout_stab, 'n' }, /* stabs */
78 { "stabs", obj_aout_stab, 's' }, /* stabs */
a39116f1
RP
79#else /* IGNORE_DEBUG */
80 { "line", obj_aout_line, 0 }, /* source code line number */
81 { "ln", obj_aout_line, 0 }, /* coff line number that we use anyway */
82 { "desc", obj_aout_desc, 0 }, /* desc */
83 { "stabd", obj_aout_stab, 'd' }, /* stabs */
84 { "stabn", obj_aout_stab, 'n' }, /* stabs */
85 { "stabs", obj_aout_stab, 's' }, /* stabs */
86#endif /* IGNORE_DEBUG */
87
88 /* coff debug pseudos (ignored) */
89 { "def", s_ignore, 0 },
90 { "dim", s_ignore, 0 },
91 { "endef", s_ignore, 0 },
92 { "ident", s_ignore, 0 },
93 { "line", s_ignore, 0 },
94 { "ln", s_ignore, 0 },
95 { "scl", s_ignore, 0 },
96 { "size", s_ignore, 0 },
97 { "tag", s_ignore, 0 },
98 { "type", s_ignore, 0 },
99 { "val", s_ignore, 0 },
100 { "version", s_ignore, 0 },
101
102 /* stabs-in-coff (?) debug pseudos (ignored) */
103 { "optim", s_ignore, 0 }, /* For sun386i cc (?) */
104
105 /* other stuff */
106 { "ABORT", s_abort, 0 },
107
fecd2382
RP
108 { NULL} /* end sentinel */
109}; /* obj_pseudo_table */
110
111
112/* Relocation. */
113
fecd2382
RP
114/*
115 * emit_relocations()
116 *
117 * Crawl along a fixS chain. Emit the segment's relocations.
118 */
119void obj_emit_relocations(where, fixP, segment_address_in_file)
120char **where;
121fixS *fixP; /* Fixup chain for this segment. */
122relax_addressT segment_address_in_file;
123{
fecd2382 124 for (; fixP; fixP = fixP->fx_next) {
a39116f1
RP
125 if (fixP->fx_addsy != NULL) {
126 tc_aout_fix_to_chars(*where, fixP, segment_address_in_file);
fecd2382
RP
127 *where += md_reloc_size;
128 } /* if there is an add symbol */
129 } /* for each fix */
a39116f1 130
fecd2382 131 return;
a39116f1 132} /* obj_emit_relocations() */
fecd2382
RP
133
134/* Aout file generation & utilities */
135void obj_header_append(where, headers)
136char **where;
137object_headers *headers;
138{
139 tc_headers_hook(headers);
a39116f1
RP
140
141#ifdef CROSS_COMPILE
fecd2382
RP
142 md_number_to_chars(*where, headers->header.a_info, sizeof(headers->header.a_info));
143 *where += sizeof(headers->header.a_info);
144 md_number_to_chars(*where, headers->header.a_text, sizeof(headers->header.a_text));
145 *where += sizeof(headers->header.a_text);
146 md_number_to_chars(*where, headers->header.a_data, sizeof(headers->header.a_data));
147 *where += sizeof(headers->header.a_data);
148 md_number_to_chars(*where, headers->header.a_bss, sizeof(headers->header.a_bss));
149 *where += sizeof(headers->header.a_bss);
150 md_number_to_chars(*where, headers->header.a_syms, sizeof(headers->header.a_syms));
151 *where += sizeof(headers->header.a_syms);
152 md_number_to_chars(*where, headers->header.a_entry, sizeof(headers->header.a_entry));
153 *where += sizeof(headers->header.a_entry);
154 md_number_to_chars(*where, headers->header.a_trsize, sizeof(headers->header.a_trsize));
155 *where += sizeof(headers->header.a_trsize);
156 md_number_to_chars(*where, headers->header.a_drsize, sizeof(headers->header.a_drsize));
157 *where += sizeof(headers->header.a_drsize);
a39116f1
RP
158
159#else /* CROSS_COMPILE */
160
fecd2382 161 append(where, (char *) &headers->header, sizeof(headers->header));
a39116f1
RP
162#endif /* CROSS_COMPILE */
163
fecd2382
RP
164 return;
165} /* obj_append_header() */
166
167void obj_symbol_to_chars(where, symbolP)
168char **where;
169symbolS *symbolP;
170{
171 md_number_to_chars((char *)&(S_GET_OFFSET(symbolP)), S_GET_OFFSET(symbolP), sizeof(S_GET_OFFSET(symbolP)));
172 md_number_to_chars((char *)&(S_GET_DESC(symbolP)), S_GET_DESC(symbolP), sizeof(S_GET_DESC(symbolP)));
173 md_number_to_chars((char *)&(S_GET_VALUE(symbolP)), S_GET_VALUE(symbolP), sizeof(S_GET_VALUE(symbolP)));
a39116f1 174
fecd2382
RP
175 append(where, (char *)&symbolP->sy_symbol, sizeof(obj_symbol_type));
176} /* obj_symbol_to_chars() */
177
178void obj_emit_symbols(where, symbol_rootP)
179char **where;
180symbolS *symbol_rootP;
181{
a39116f1
RP
182 symbolS * symbolP;
183
184 /*
185 * Emit all symbols left in the symbol chain.
186 */
187 for(symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
188 /* Used to save the offset of the name. It is used to point
189 to the string in memory but must be a file offset. */
190 register char *temp;
191
192 temp = S_GET_NAME(symbolP);
193 S_SET_OFFSET(symbolP, symbolP->sy_name_offset);
194
195 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
196 if (!S_IS_DEBUG(symbolP) && !S_IS_DEFINED(symbolP)) S_SET_EXTERNAL(symbolP);
197
198 obj_symbol_to_chars(where, symbolP);
199 S_SET_NAME(symbolP,temp);
200 }
fecd2382
RP
201} /* emit_symbols() */
202
a39116f1
RP
203#if comment
204/* uneeded if symbol is born zeroed. */
fecd2382
RP
205void obj_symbol_new_hook(symbolP)
206symbolS *symbolP;
207{
208 S_SET_OTHER(symbolP, 0);
209 S_SET_DESC(symbolP, 0);
210 return;
211} /* obj_symbol_new_hook() */
a39116f1 212#endif /* comment */
fecd2382
RP
213
214static void obj_aout_line() {
215 /* Assume delimiter is part of expression. */
216 /* BSD4.2 as fails with delightful bug, so we */
217 /* are not being incompatible here. */
218 new_logical_line((char *)NULL, (int)(get_absolute_expression()));
219 demand_empty_rest_of_line();
220} /* obj_aout_line() */
221
222/*
223 * stab()
224 *
225 * Handle .stabX directives, which used to be open-coded.
226 * So much creeping featurism overloaded the semantics that we decided
227 * to put all .stabX thinking in one place. Here.
228 *
229 * We try to make any .stabX directive legal. Other people's AS will often
230 * do assembly-time consistency checks: eg assigning meaning to n_type bits
231 * and "protecting" you from setting them to certain values. (They also zero
232 * certain bits before emitting symbols. Tut tut.)
233 *
234 * If an expression is not absolute we either gripe or use the relocation
235 * information. Other people's assemblers silently forget information they
236 * don't need and invent information they need that you didn't supply.
237 *
238 * .stabX directives always make a symbol table entry. It may be junk if
239 * the rest of your .stabX directive is malformed.
240 */
241static void obj_aout_stab(what)
242int what;
243{
a39116f1
RP
244 extern int listing;
245
246 register symbolS * symbolP = 0;
247 register char * string;
248 int saved_type = 0;
249 int length;
250 int goof; /* TRUE if we have aborted. */
251 long longint;
252
253 /*
254 * Enter with input_line_pointer pointing past .stabX and any following
255 * whitespace.
256 */
fecd2382
RP
257 goof = 0; /* JF who forgot this?? */
258 if (what == 's') {
259 string = demand_copy_C_string(& length);
260 SKIP_WHITESPACE();
261 if (* input_line_pointer == ',')
a39116f1 262 input_line_pointer ++;
fecd2382
RP
263 else {
264 as_bad("I need a comma after symbol's name");
265 goof = 1;
266 }
267 } else
a39116f1
RP
268 string = "";
269
270 /*
271 * Input_line_pointer->after ','. String->symbol name.
272 */
fecd2382
RP
273 if (! goof) {
274 symbolP = symbol_new(string,
275 SEG_UNKNOWN,
276 0,
277 (struct frag *)0);
278 switch (what) {
279 case 'd':
280 S_SET_NAME(symbolP, NULL); /* .stabd feature. */
281 S_SET_VALUE(symbolP, obstack_next_free(&frags) - frag_now->fr_literal);
282 symbolP->sy_frag = frag_now;
283 break;
a39116f1 284
fecd2382
RP
285 case 'n':
286 symbolP->sy_frag = &zero_address_frag;
287 break;
a39116f1 288
fecd2382
RP
289 case 's':
290 symbolP->sy_frag = & zero_address_frag;
291 break;
a39116f1 292
fecd2382
RP
293 default:
294 BAD_CASE(what);
295 break;
296 }
a39116f1 297
fecd2382 298 if (get_absolute_expression_and_terminator(&longint) == ',')
a39116f1 299 symbolP->sy_symbol.n_type = saved_type = longint;
fecd2382
RP
300 else {
301 as_bad("I want a comma after the n_type expression");
302 goof = 1;
303 input_line_pointer --; /* Backup over a non-',' char. */
304 }
305 }
a39116f1 306
fecd2382
RP
307 if (!goof) {
308 if (get_absolute_expression_and_terminator(&longint) == ',')
a39116f1 309 S_SET_OTHER(symbolP, longint);
fecd2382
RP
310 else {
311 as_bad("I want a comma after the n_other expression");
312 goof = 1;
313 input_line_pointer--; /* Backup over a non-',' char. */
314 }
315 }
a39116f1 316
fecd2382
RP
317 if (!goof) {
318 S_SET_DESC(symbolP, get_absolute_expression());
319 if (what == 's' || what == 'n') {
320 if (*input_line_pointer != ',') {
321 as_bad("I want a comma after the n_desc expression");
322 goof = 1;
323 } else {
324 input_line_pointer++;
325 }
326 }
327 }
a39116f1 328
fecd2382
RP
329 if ((!goof) && (what=='s' || what=='n')) {
330 pseudo_set(symbolP);
331 symbolP->sy_symbol.n_type = saved_type;
332 }
a39116f1
RP
333#ifndef NO_LISTING
334 if (listing && !goof)
335 {
336 if (symbolP->sy_symbol.n_type == N_SLINE)
337 {
338
339 listing_source_line(symbolP->sy_symbol.n_desc);
340 }
341 else if (symbolP->sy_symbol.n_type == N_SO
342 || symbolP->sy_symbol.n_type == N_SOL)
343 {
344 listing_source_file(string);
345 }
346 }
347#endif
348
fecd2382 349 if (goof)
a39116f1 350 ignore_rest_of_line();
fecd2382 351 else
a39116f1 352 demand_empty_rest_of_line ();
fecd2382
RP
353} /* obj_aout_stab() */
354
355static void obj_aout_desc() {
356 register char *name;
357 register char c;
358 register char *p;
359 register symbolS *symbolP;
360 register int temp;
a39116f1 361
fecd2382
RP
362 /*
363 * Frob invented at RMS' request. Set the n_desc of a symbol.
a39116f1 364 */
fecd2382
RP
365 name = input_line_pointer;
366 c = get_symbol_end();
367 p = input_line_pointer;
368 * p = c;
369 SKIP_WHITESPACE();
370 if (*input_line_pointer != ',') {
371 *p = 0;
372 as_bad("Expected comma after name \"%s\"", name);
373 *p = c;
374 ignore_rest_of_line();
375 } else {
376 input_line_pointer ++;
377 temp = get_absolute_expression();
378 *p = 0;
379 symbolP = symbol_find_or_make(name);
380 *p = c;
381 S_SET_DESC(symbolP,temp);
382 }
383 demand_empty_rest_of_line();
384} /* obj_aout_desc() */
385
386void obj_read_begin_hook() {
387 return;
388} /* obj_read_begin_hook() */
389
390void obj_crawl_symbol_chain(headers)
391object_headers *headers;
392{
393 symbolS *symbolP;
394 symbolS **symbolPP;
395 int symbol_number = 0;
a39116f1 396
fecd2382
RP
397 /* JF deal with forward references first... */
398 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
399 if (symbolP->sy_forward) {
400 S_SET_VALUE(symbolP, S_GET_VALUE(symbolP)
401 + S_GET_VALUE(symbolP->sy_forward)
402 + symbolP->sy_forward->sy_frag->fr_address);
a39116f1 403
fecd2382
RP
404 symbolP->sy_forward=0;
405 } /* if it has a forward reference */
406 } /* walk the symbol chain */
a39116f1 407
fecd2382 408 tc_crawl_symbol_chain(headers);
a39116f1 409
fecd2382
RP
410 symbolPP = &symbol_rootP; /*->last symbol chain link. */
411 while ((symbolP = *symbolPP) != NULL) {
412 if (flagseen['R'] && (S_GET_SEGMENT(symbolP) == SEG_DATA)) {
413 S_SET_SEGMENT(symbolP, SEG_TEXT);
414 } /* if pusing data into text */
a39116f1 415
fecd2382 416 S_SET_VALUE(symbolP, S_GET_VALUE(symbolP) + symbolP->sy_frag->fr_address);
a39116f1 417
fecd2382
RP
418 /* OK, here is how we decide which symbols go out into the
419 brave new symtab. Symbols that do are:
a39116f1 420
fecd2382
RP
421 * symbols with no name (stabd's?)
422 * symbols with debug info in their N_TYPE
a39116f1 423
fecd2382
RP
424 Symbols that don't are:
425 * symbols that are registers
426 * symbols with \1 as their 3rd character (numeric labels)
427 * "local labels" as defined by S_LOCAL_NAME(name)
428 if the -L switch was passed to gas.
a39116f1 429
fecd2382
RP
430 All other symbols are output. We complain if a deleted
431 symbol was marked external. */
a39116f1
RP
432
433
fecd2382
RP
434 if (!S_IS_REGISTER(symbolP)
435 && (!S_GET_NAME(symbolP)
436 || S_IS_DEBUG(symbolP)
437#ifdef TC_I960
438 /* FIXME-SOON this ifdef seems highly dubious to me. xoxorich. */
439 || !S_IS_DEFINED(symbolP)
440 || S_IS_EXTERNAL(symbolP)
441#endif /* TC_I960 */
442 || (S_GET_NAME(symbolP)[0] != '\001' && (flagseen ['L'] || ! S_LOCAL_NAME(symbolP))))) {
443 symbolP->sy_number = symbol_number++;
a39116f1 444
fecd2382
RP
445 /* The + 1 after strlen account for the \0 at the
446 end of each string */
447 if (!S_IS_STABD(symbolP)) {
448 /* Ordinary case. */
449 symbolP->sy_name_offset = string_byte_count;
450 string_byte_count += strlen(S_GET_NAME(symbolP)) + 1;
451 }
452 else /* .Stabd case. */
453 symbolP->sy_name_offset = 0;
454 symbolPP = &(symbol_next(symbolP));
455 } else {
456 if (S_IS_EXTERNAL(symbolP) || !S_IS_DEFINED(symbolP)) {
a39116f1 457 as_bad("Local symbol %s never defined.", decode_local_label_name(S_GET_NAME(symbolP)));
fecd2382 458 } /* oops. */
a39116f1 459
fecd2382
RP
460 /* Unhook it from the chain */
461 *symbolPP = symbol_next(symbolP);
462 } /* if this symbol should be in the output */
463 } /* for each symbol */
a39116f1 464
fecd2382 465 H_SET_SYMBOL_TABLE_SIZE(headers, symbol_number);
a39116f1 466
fecd2382
RP
467 return;
468} /* obj_crawl_symbol_chain() */
469
470/*
471 * Find strings by crawling along symbol table chain.
472 */
473
474void obj_emit_strings(where)
475char **where;
476{
477 symbolS *symbolP;
a39116f1
RP
478
479#ifdef CROSS_COMPILE
fecd2382
RP
480 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
481 md_number_to_chars(*where, string_byte_count, sizeof(string_byte_count));
482 *where += sizeof(string_byte_count);
a39116f1 483#else /* CROSS_COMPILE */
fecd2382 484 append (where, (char *)&string_byte_count, (unsigned long)sizeof(string_byte_count));
a39116f1
RP
485#endif /* CROSS_COMPILE */
486
fecd2382
RP
487 for(symbolP = symbol_rootP; symbolP; symbolP = symbol_next(symbolP)) {
488 if(S_GET_NAME(symbolP))
489 append(&next_object_file_charP, S_GET_NAME(symbolP),
490 (unsigned long)(strlen (S_GET_NAME(symbolP)) + 1));
491 } /* walk symbol chain */
a39116f1 492
fecd2382
RP
493 return;
494} /* obj_emit_strings() */
495
a39116f1
RP
496void obj_pre_write_hook(headers)
497object_headers *headers;
498{
499 H_SET_DYNAMIC(headers, 0);
500 H_SET_VERSION(headers, 0);
501 H_SET_MACHTYPE(headers, AOUT_MACHTYPE);
502 tc_aout_pre_write_hook(headers);
503 return;
504} /* obj_pre_write_hook() */
505
fecd2382
RP
506/*
507 * Local Variables:
508 * comment-column: 0
509 * fill-column: 131
510 * End:
511 */
512
513/* end of obj-aout.c */
This page took 0.063676 seconds and 4 git commands to generate.