* gdb.base/list.exp: Add expect patterns for output from
[deliverable/binutils-gdb.git] / gas / config / obj-aout.c
CommitLineData
fecd2382 1/* a.out object file format
85051959
ILT
2 Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc.
3
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as
8published by the Free Software Foundation; either version 2,
9or (at your option) any later version.
10
11GAS is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public
17License along with GAS; see the file COPYING. If not, write
18to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
fecd2382
RP
19
20#include "as.h"
604633ae 21#ifdef BFD_ASSEMBLER
645f842c 22#undef NO_RELOC
2c5c299f 23#include "aout/aout64.h"
604633ae 24#endif
fecd2382
RP
25#include "obstack.h"
26
85051959 27#ifndef BFD_ASSEMBLER
a39116f1 28/* in: segT out: N_TYPE bits */
85051959
ILT
29const short seg_N_TYPE[] =
30{
31 N_ABS,
32 N_TEXT,
33 N_DATA,
34 N_BSS,
35 N_UNDF, /* unknown */
85051959 36 N_UNDF, /* error */
5ac34ac3 37 N_UNDF, /* expression */
85051959
ILT
38 N_UNDF, /* debug */
39 N_UNDF, /* ntv */
40 N_UNDF, /* ptv */
41 N_REGISTER, /* register */
fecd2382
RP
42};
43
85051959
ILT
44const segT N_TYPE_seg[N_TYPE + 2] =
45{ /* N_TYPE == 0x1E = 32-2 */
46 SEG_UNKNOWN, /* N_UNDF == 0 */
47 SEG_GOOF,
48 SEG_ABSOLUTE, /* N_ABS == 2 */
49 SEG_GOOF,
50 SEG_TEXT, /* N_TEXT == 4 */
51 SEG_GOOF,
52 SEG_DATA, /* N_DATA == 6 */
53 SEG_GOOF,
54 SEG_BSS, /* N_BSS == 8 */
55 SEG_GOOF,
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 */
60 SEG_GOOF,
fecd2382 61};
85051959
ILT
62#endif
63
604633ae 64static void obj_aout_line PARAMS ((int));
02d4e923 65static void obj_aout_weak PARAMS ((int));
fecd2382 66
85051959
ILT
67const pseudo_typeS obj_pseudo_table[] =
68{
85051959
ILT
69 {"line", obj_aout_line, 0}, /* source code line number */
70 {"ln", obj_aout_line, 0}, /* coff line number that we use anyway */
fecd2382 71
02d4e923
ILT
72 {"weak", obj_aout_weak, 0}, /* mark symbol as weak. */
73
85051959
ILT
74 /* coff debug pseudos (ignored) */
75 {"def", s_ignore, 0},
76 {"dim", s_ignore, 0},
77 {"endef", s_ignore, 0},
78 {"ident", s_ignore, 0},
79 {"line", s_ignore, 0},
80 {"ln", s_ignore, 0},
81 {"scl", s_ignore, 0},
82 {"size", s_ignore, 0},
83 {"tag", s_ignore, 0},
84 {"type", s_ignore, 0},
85 {"val", s_ignore, 0},
86 {"version", s_ignore, 0},
87
85051959
ILT
88 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
89
90 /* other stuff */
91 {"ABORT", s_abort, 0},
92
93 {NULL} /* end sentinel */
94}; /* obj_pseudo_table */
95
96
97#ifdef BFD_ASSEMBLER
98
99void
100obj_aout_frob_symbol (sym, punt)
101 symbolS *sym;
102 int *punt;
103{
104 flagword flags;
105 asection *sec;
106 int desc, type, other;
107
85051959
ILT
108 flags = sym->bsym->flags;
109 desc = S_GET_DESC (sym);
110 type = S_GET_TYPE (sym);
111 other = S_GET_OTHER (sym);
112 sec = sym->bsym->section;
113
114 /* Only frob simple symbols this way right now. */
2c5c299f 115 if (! (type & ~ (N_TYPE | N_EXT)))
85051959 116 {
4bda835f
ILT
117 if (type == (N_UNDF | N_EXT)
118 && sec == &bfd_abs_section)
119 sym->bsym->section = sec = &bfd_und_section;
120
121 if ((type & N_TYPE) != N_INDR
def66e24
DM
122 && (type & N_TYPE) != N_SETA
123 && (type & N_TYPE) != N_SETT
124 && (type & N_TYPE) != N_SETD
125 && (type & N_TYPE) != N_SETB
13655af6 126 && type != N_WARNING
4bda835f
ILT
127 && (sec == &bfd_abs_section
128 || sec == &bfd_und_section))
85051959
ILT
129 return;
130 if (flags & BSF_EXPORT)
2c5c299f
ILT
131 type |= N_EXT;
132
2c5c299f
ILT
133 switch (type & N_TYPE)
134 {
135 case N_SETA:
136 case N_SETT:
137 case N_SETD:
138 case N_SETB:
4bda835f
ILT
139 /* Set the debugging flag for constructor symbols so that
140 BFD leaves them alone. */
2c5c299f
ILT
141 sym->bsym->flags |= BSF_DEBUGGING;
142 break;
4bda835f
ILT
143 case N_INDR:
144 /* Put indirect symbols in the indirect section. */
145 sym->bsym->section = &bfd_ind_section;
146 sym->bsym->flags |= BSF_INDIRECT;
645f842c
ILT
147 if (type & N_EXT)
148 {
149 sym->bsym->flags |= BSF_EXPORT;
150 sym->bsym->flags &=~ BSF_LOCAL;
151 }
4bda835f 152 break;
13655af6
ILT
153 case N_WARNING:
154 /* Mark warning symbols. */
155 sym->bsym->flags |= BSF_WARNING;
156 break;
2c5c299f 157 }
85051959
ILT
158 }
159 else
160 {
161 sym->bsym->flags |= BSF_DEBUGGING;
162 }
163
164 S_SET_TYPE (sym, type);
165}
166
645f842c
ILT
167void
168obj_aout_frob_file ()
169{
170 /* Relocation processing may require knowing the VMAs of the sections.
171 Since writing to a section will cause the BFD back end to compute the
172 VMAs, fake it out here.... */
173 bfd_byte b = 0;
174 boolean x = true;
175 if (bfd_section_size (stdoutput, text_section) != 0)
176 {
177 x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0,
178 (bfd_size_type) 1);
179 }
180 else if (bfd_section_size (stdoutput, data_section) != 0)
181 {
182 x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0,
183 (bfd_size_type) 1);
184 }
185 assert (x == true);
186}
187
85051959 188#else
fecd2382
RP
189
190/* Relocation. */
191
fecd2382
RP
192/*
193 * emit_relocations()
194 *
195 * Crawl along a fixS chain. Emit the segment's relocations.
196 */
85051959
ILT
197void
198obj_emit_relocations (where, fixP, segment_address_in_file)
199 char **where;
200 fixS *fixP; /* Fixup chain for this segment. */
201 relax_addressT segment_address_in_file;
fecd2382 202{
85051959 203 for (; fixP; fixP = fixP->fx_next)
645f842c 204 if (fixP->fx_done == 0)
85051959
ILT
205 {
206 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
207 *where += md_reloc_size;
208 }
209}
fecd2382 210
85051959 211#ifndef obj_header_append
fecd2382 212/* Aout file generation & utilities */
85051959
ILT
213void
214obj_header_append (where, headers)
215 char **where;
216 object_headers *headers;
fecd2382 217{
85051959
ILT
218 tc_headers_hook (headers);
219
a39116f1 220#ifdef CROSS_COMPILE
85051959
ILT
221 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
222 *where += sizeof (headers->header.a_info);
223 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
224 *where += sizeof (headers->header.a_text);
225 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
226 *where += sizeof (headers->header.a_data);
227 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
228 *where += sizeof (headers->header.a_bss);
229 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
230 *where += sizeof (headers->header.a_syms);
231 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
232 *where += sizeof (headers->header.a_entry);
233 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
234 *where += sizeof (headers->header.a_trsize);
235 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
236 *where += sizeof (headers->header.a_drsize);
237
a39116f1 238#else /* CROSS_COMPILE */
85051959
ILT
239
240 append (where, (char *) &headers->header, sizeof (headers->header));
a39116f1 241#endif /* CROSS_COMPILE */
fecd2382 242
85051959
ILT
243}
244#endif
245
246void
247obj_symbol_to_chars (where, symbolP)
248 char **where;
249 symbolS *symbolP;
fecd2382 250{
85051959
ILT
251 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
252 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
253 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
254
255 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
256}
fecd2382 257
85051959
ILT
258void
259obj_emit_symbols (where, symbol_rootP)
260 char **where;
261 symbolS *symbol_rootP;
fecd2382 262{
85051959
ILT
263 symbolS *symbolP;
264
265 /* Emit all symbols left in the symbol chain. */
266 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
267 {
268 /* Used to save the offset of the name. It is used to point
269 to the string in memory but must be a file offset. */
270 register char *temp;
271
272 temp = S_GET_NAME (symbolP);
273 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
fecd2382 274
85051959
ILT
275 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
276 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
277 S_SET_EXTERNAL (symbolP);
278
02d4e923
ILT
279 /* Adjust the type of a weak symbol. */
280 if (S_GET_WEAK (symbolP))
281 {
282 switch (S_GET_TYPE (symbolP))
283 {
284 case N_UNDF: S_SET_TYPE (symbolP, N_WEAKU); break;
285 case N_ABS: S_SET_TYPE (symbolP, N_WEAKA); break;
286 case N_TEXT: S_SET_TYPE (symbolP, N_WEAKT); break;
287 case N_DATA: S_SET_TYPE (symbolP, N_WEAKD); break;
288 case N_BSS: S_SET_TYPE (symbolP, N_WEAKB); break;
289 default: as_bad ("%s: bad type for weak symbol", temp); break;
290 }
291 }
292
85051959
ILT
293 obj_symbol_to_chars (where, symbolP);
294 S_SET_NAME (symbolP, temp);
295 }
296}
297
298#endif /* ! BFD_ASSEMBLER */
299
300static void
604633ae
ILT
301obj_aout_line (ignore)
302 int ignore;
85051959
ILT
303{
304 /* Assume delimiter is part of expression.
305 BSD4.2 as fails with delightful bug, so we
306 are not being incompatible here. */
307 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
308 demand_empty_rest_of_line ();
309} /* obj_aout_line() */
fecd2382 310
02d4e923
ILT
311/* Handle .weak. This is a GNU extension. */
312
313static void
314obj_aout_weak (ignore)
315 int ignore;
316{
317 char *name;
318 int c;
319 symbolS *symbolP;
320
321 do
322 {
323 name = input_line_pointer;
324 c = get_symbol_end ();
325 symbolP = symbol_find_or_make (name);
326 *input_line_pointer = c;
327 SKIP_WHITESPACE ();
328 S_SET_WEAK (symbolP);
329 if (c == ',')
330 {
331 input_line_pointer++;
332 SKIP_WHITESPACE ();
333 if (*input_line_pointer == '\n')
334 c = '\n';
335 }
336 }
337 while (c == ',');
338 demand_empty_rest_of_line ();
339}
340
85051959
ILT
341void
342obj_read_begin_hook ()
343{
4bda835f 344}
85051959
ILT
345
346#ifndef BFD_ASSEMBLER
fecd2382 347
85051959
ILT
348void
349obj_crawl_symbol_chain (headers)
350 object_headers *headers;
fecd2382 351{
85051959
ILT
352 symbolS *symbolP;
353 symbolS **symbolPP;
354 int symbol_number = 0;
355
85051959
ILT
356 tc_crawl_symbol_chain (headers);
357
358 symbolPP = &symbol_rootP; /*->last symbol chain link. */
359 while ((symbolP = *symbolPP) != NULL)
360 {
def66e24 361 if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_DATA))
85051959
ILT
362 {
363 S_SET_SEGMENT (symbolP, SEG_TEXT);
364 } /* if pusing data into text */
365
5868b1fe 366 resolve_symbol_value (symbolP);
85051959
ILT
367
368 /* OK, here is how we decide which symbols go out into the brave
369 new symtab. Symbols that do are:
370
371 * symbols with no name (stabd's?)
372 * symbols with debug info in their N_TYPE
373
374 Symbols that don't are:
375 * symbols that are registers
376 * symbols with \1 as their 3rd character (numeric labels)
377 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
378 switch was passed to gas.
379
380 All other symbols are output. We complain if a deleted
381 symbol was marked external. */
382
383
384 if (!S_IS_REGISTER (symbolP)
385 && (!S_GET_NAME (symbolP)
386 || S_IS_DEBUG (symbolP)
85051959
ILT
387 || !S_IS_DEFINED (symbolP)
388 || S_IS_EXTERNAL (symbolP)
645f842c 389 || (S_GET_NAME (symbolP)[0] != '\001'
def66e24 390 && (flag_keep_locals || !S_LOCAL_NAME (symbolP)))))
85051959
ILT
391 {
392 symbolP->sy_number = symbol_number++;
393
394 /* The + 1 after strlen account for the \0 at the
fecd2382 395 end of each string */
85051959
ILT
396 if (!S_IS_STABD (symbolP))
397 {
398 /* Ordinary case. */
399 symbolP->sy_name_offset = string_byte_count;
400 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
401 }
402 else /* .Stabd case. */
403 symbolP->sy_name_offset = 0;
404 symbolPP = &(symbol_next (symbolP));
405 }
406 else
407 {
408 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
645f842c
ILT
409 /* This warning should never get triggered any more.
410 Well, maybe if you're doing twisted things with
411 register names... */
85051959
ILT
412 {
413 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
414 } /* oops. */
415
416 /* Unhook it from the chain */
417 *symbolPP = symbol_next (symbolP);
418 } /* if this symbol should be in the output */
419 } /* for each symbol */
420
421 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
4bda835f 422}
fecd2382
RP
423
424/*
425 * Find strings by crawling along symbol table chain.
426 */
427
85051959
ILT
428void
429obj_emit_strings (where)
430 char **where;
fecd2382 431{
85051959
ILT
432 symbolS *symbolP;
433
a39116f1 434#ifdef CROSS_COMPILE
85051959
ILT
435 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
436 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
437 *where += sizeof (string_byte_count);
a39116f1 438#else /* CROSS_COMPILE */
85051959 439 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
a39116f1 440#endif /* CROSS_COMPILE */
fecd2382 441
85051959
ILT
442 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
443 {
444 if (S_GET_NAME (symbolP))
445 append (&next_object_file_charP, S_GET_NAME (symbolP),
446 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
447 } /* walk symbol chain */
4bda835f 448}
85051959
ILT
449
450#ifndef AOUT_VERSION
451#define AOUT_VERSION 0
452#endif
453
454void
455obj_pre_write_hook (headers)
456 object_headers *headers;
a39116f1 457{
85051959
ILT
458 H_SET_DYNAMIC (headers, 0);
459 H_SET_VERSION (headers, AOUT_VERSION);
460 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
461 tc_aout_pre_write_hook (headers);
4bda835f 462}
a39116f1 463
85051959
ILT
464void
465DEFUN_VOID (s_sect)
466{
467 /* Strip out the section name */
468 char *section_name;
469 char *section_name_end;
470 char c;
471
472 unsigned int len;
473 unsigned int exp;
474 char *save;
475
476 section_name = input_line_pointer;
477 c = get_symbol_end ();
478 section_name_end = input_line_pointer;
479
480 len = section_name_end - section_name;
481 input_line_pointer++;
482 save = input_line_pointer;
483
484 SKIP_WHITESPACE ();
485 if (c == ',')
486 {
487 exp = get_absolute_expression ();
488 }
489 else if (*input_line_pointer == ',')
490 {
491 input_line_pointer++;
492 exp = get_absolute_expression ();
493 }
494 else
495 {
496 input_line_pointer = save;
497 exp = 0;
498 }
499 if (exp >= 1000)
500 {
501 as_bad ("subsegment index too high");
502 }
503
504 if (strcmp (section_name, ".text") == 0)
505 {
604633ae 506 subseg_set (SEG_TEXT, (subsegT) exp);
85051959
ILT
507 }
508
509 if (strcmp (section_name, ".data") == 0)
510 {
def66e24 511 if (flag_readonly_data_in_text)
604633ae 512 subseg_set (SEG_TEXT, (subsegT) exp + 1000);
85051959 513 else
604633ae 514 subseg_set (SEG_DATA, (subsegT) exp);
85051959
ILT
515 }
516
517 *section_name_end = c;
518}
519
520#endif /* ! BFD_ASSEMBLER */
fecd2382
RP
521
522/* end of obj-aout.c */
This page took 0.168565 seconds and 4 git commands to generate.