don't sanitize out v9 stuff any more
[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));
fecd2382 65
85051959
ILT
66const pseudo_typeS obj_pseudo_table[] =
67{
85051959
ILT
68 {"line", obj_aout_line, 0}, /* source code line number */
69 {"ln", obj_aout_line, 0}, /* coff line number that we use anyway */
fecd2382 70
85051959
ILT
71 /* coff debug pseudos (ignored) */
72 {"def", s_ignore, 0},
73 {"dim", s_ignore, 0},
74 {"endef", s_ignore, 0},
75 {"ident", s_ignore, 0},
76 {"line", s_ignore, 0},
77 {"ln", s_ignore, 0},
78 {"scl", s_ignore, 0},
79 {"size", s_ignore, 0},
80 {"tag", s_ignore, 0},
81 {"type", s_ignore, 0},
82 {"val", s_ignore, 0},
83 {"version", s_ignore, 0},
84
85051959
ILT
85 {"optim", s_ignore, 0}, /* For sun386i cc (?) */
86
87 /* other stuff */
88 {"ABORT", s_abort, 0},
89
90 {NULL} /* end sentinel */
91}; /* obj_pseudo_table */
92
93
94#ifdef BFD_ASSEMBLER
95
96void
97obj_aout_frob_symbol (sym, punt)
98 symbolS *sym;
99 int *punt;
100{
101 flagword flags;
102 asection *sec;
103 int desc, type, other;
104
85051959
ILT
105 flags = sym->bsym->flags;
106 desc = S_GET_DESC (sym);
107 type = S_GET_TYPE (sym);
108 other = S_GET_OTHER (sym);
109 sec = sym->bsym->section;
110
111 /* Only frob simple symbols this way right now. */
2c5c299f 112 if (! (type & ~ (N_TYPE | N_EXT)))
85051959 113 {
4bda835f
ILT
114 if (type == (N_UNDF | N_EXT)
115 && sec == &bfd_abs_section)
116 sym->bsym->section = sec = &bfd_und_section;
117
118 if ((type & N_TYPE) != N_INDR
13655af6 119 && type != N_WARNING
4bda835f
ILT
120 && (sec == &bfd_abs_section
121 || sec == &bfd_und_section))
85051959
ILT
122 return;
123 if (flags & BSF_EXPORT)
2c5c299f
ILT
124 type |= N_EXT;
125
2c5c299f
ILT
126 switch (type & N_TYPE)
127 {
128 case N_SETA:
129 case N_SETT:
130 case N_SETD:
131 case N_SETB:
4bda835f
ILT
132 /* Set the debugging flag for constructor symbols so that
133 BFD leaves them alone. */
2c5c299f
ILT
134 sym->bsym->flags |= BSF_DEBUGGING;
135 break;
4bda835f
ILT
136 case N_INDR:
137 /* Put indirect symbols in the indirect section. */
138 sym->bsym->section = &bfd_ind_section;
139 sym->bsym->flags |= BSF_INDIRECT;
645f842c
ILT
140 if (type & N_EXT)
141 {
142 sym->bsym->flags |= BSF_EXPORT;
143 sym->bsym->flags &=~ BSF_LOCAL;
144 }
4bda835f 145 break;
13655af6
ILT
146 case N_WARNING:
147 /* Mark warning symbols. */
148 sym->bsym->flags |= BSF_WARNING;
149 break;
2c5c299f 150 }
85051959
ILT
151 }
152 else
153 {
154 sym->bsym->flags |= BSF_DEBUGGING;
155 }
156
157 S_SET_TYPE (sym, type);
158}
159
645f842c
ILT
160void
161obj_aout_frob_file ()
162{
163 /* Relocation processing may require knowing the VMAs of the sections.
164 Since writing to a section will cause the BFD back end to compute the
165 VMAs, fake it out here.... */
166 bfd_byte b = 0;
167 boolean x = true;
168 if (bfd_section_size (stdoutput, text_section) != 0)
169 {
170 x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0,
171 (bfd_size_type) 1);
172 }
173 else if (bfd_section_size (stdoutput, data_section) != 0)
174 {
175 x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0,
176 (bfd_size_type) 1);
177 }
178 assert (x == true);
179}
180
85051959 181#else
fecd2382
RP
182
183/* Relocation. */
184
fecd2382
RP
185/*
186 * emit_relocations()
187 *
188 * Crawl along a fixS chain. Emit the segment's relocations.
189 */
85051959
ILT
190void
191obj_emit_relocations (where, fixP, segment_address_in_file)
192 char **where;
193 fixS *fixP; /* Fixup chain for this segment. */
194 relax_addressT segment_address_in_file;
fecd2382 195{
85051959 196 for (; fixP; fixP = fixP->fx_next)
645f842c 197 if (fixP->fx_done == 0)
85051959
ILT
198 {
199 tc_aout_fix_to_chars (*where, fixP, segment_address_in_file);
200 *where += md_reloc_size;
201 }
202}
fecd2382 203
85051959 204#ifndef obj_header_append
fecd2382 205/* Aout file generation & utilities */
85051959
ILT
206void
207obj_header_append (where, headers)
208 char **where;
209 object_headers *headers;
fecd2382 210{
85051959
ILT
211 tc_headers_hook (headers);
212
a39116f1 213#ifdef CROSS_COMPILE
85051959
ILT
214 md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info));
215 *where += sizeof (headers->header.a_info);
216 md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text));
217 *where += sizeof (headers->header.a_text);
218 md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data));
219 *where += sizeof (headers->header.a_data);
220 md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss));
221 *where += sizeof (headers->header.a_bss);
222 md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms));
223 *where += sizeof (headers->header.a_syms);
224 md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry));
225 *where += sizeof (headers->header.a_entry);
226 md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize));
227 *where += sizeof (headers->header.a_trsize);
228 md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize));
229 *where += sizeof (headers->header.a_drsize);
230
a39116f1 231#else /* CROSS_COMPILE */
85051959
ILT
232
233 append (where, (char *) &headers->header, sizeof (headers->header));
a39116f1 234#endif /* CROSS_COMPILE */
fecd2382 235
85051959
ILT
236}
237#endif
238
239void
240obj_symbol_to_chars (where, symbolP)
241 char **where;
242 symbolS *symbolP;
fecd2382 243{
85051959
ILT
244 md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP)));
245 md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP)));
246 md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value));
247
248 append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type));
249}
fecd2382 250
85051959
ILT
251void
252obj_emit_symbols (where, symbol_rootP)
253 char **where;
254 symbolS *symbol_rootP;
fecd2382 255{
85051959
ILT
256 symbolS *symbolP;
257
258 /* Emit all symbols left in the symbol chain. */
259 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
260 {
261 /* Used to save the offset of the name. It is used to point
262 to the string in memory but must be a file offset. */
263 register char *temp;
264
265 temp = S_GET_NAME (symbolP);
266 S_SET_OFFSET (symbolP, symbolP->sy_name_offset);
fecd2382 267
85051959
ILT
268 /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */
269 if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP))
270 S_SET_EXTERNAL (symbolP);
271
272 obj_symbol_to_chars (where, symbolP);
273 S_SET_NAME (symbolP, temp);
274 }
275}
276
277#endif /* ! BFD_ASSEMBLER */
278
279static void
604633ae
ILT
280obj_aout_line (ignore)
281 int ignore;
85051959
ILT
282{
283 /* Assume delimiter is part of expression.
284 BSD4.2 as fails with delightful bug, so we
285 are not being incompatible here. */
286 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
287 demand_empty_rest_of_line ();
288} /* obj_aout_line() */
fecd2382 289
85051959
ILT
290void
291obj_read_begin_hook ()
292{
4bda835f 293}
85051959
ILT
294
295#ifndef BFD_ASSEMBLER
fecd2382 296
85051959
ILT
297void
298obj_crawl_symbol_chain (headers)
299 object_headers *headers;
fecd2382 300{
85051959
ILT
301 symbolS *symbolP;
302 symbolS **symbolPP;
303 int symbol_number = 0;
304
85051959
ILT
305 tc_crawl_symbol_chain (headers);
306
307 symbolPP = &symbol_rootP; /*->last symbol chain link. */
308 while ((symbolP = *symbolPP) != NULL)
309 {
310 if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_DATA))
311 {
312 S_SET_SEGMENT (symbolP, SEG_TEXT);
313 } /* if pusing data into text */
314
5868b1fe 315 resolve_symbol_value (symbolP);
85051959
ILT
316
317 /* OK, here is how we decide which symbols go out into the brave
318 new symtab. Symbols that do are:
319
320 * symbols with no name (stabd's?)
321 * symbols with debug info in their N_TYPE
322
323 Symbols that don't are:
324 * symbols that are registers
325 * symbols with \1 as their 3rd character (numeric labels)
326 * "local labels" as defined by S_LOCAL_NAME(name) if the -L
327 switch was passed to gas.
328
329 All other symbols are output. We complain if a deleted
330 symbol was marked external. */
331
332
333 if (!S_IS_REGISTER (symbolP)
334 && (!S_GET_NAME (symbolP)
335 || S_IS_DEBUG (symbolP)
85051959
ILT
336 || !S_IS_DEFINED (symbolP)
337 || S_IS_EXTERNAL (symbolP)
645f842c
ILT
338 || (S_GET_NAME (symbolP)[0] != '\001'
339 && (flagseen['L'] || !S_LOCAL_NAME (symbolP)))))
85051959
ILT
340 {
341 symbolP->sy_number = symbol_number++;
342
343 /* The + 1 after strlen account for the \0 at the
fecd2382 344 end of each string */
85051959
ILT
345 if (!S_IS_STABD (symbolP))
346 {
347 /* Ordinary case. */
348 symbolP->sy_name_offset = string_byte_count;
349 string_byte_count += strlen (S_GET_NAME (symbolP)) + 1;
350 }
351 else /* .Stabd case. */
352 symbolP->sy_name_offset = 0;
353 symbolPP = &(symbol_next (symbolP));
354 }
355 else
356 {
357 if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP))
645f842c
ILT
358 /* This warning should never get triggered any more.
359 Well, maybe if you're doing twisted things with
360 register names... */
85051959
ILT
361 {
362 as_bad ("Local symbol %s never defined.", decode_local_label_name (S_GET_NAME (symbolP)));
363 } /* oops. */
364
365 /* Unhook it from the chain */
366 *symbolPP = symbol_next (symbolP);
367 } /* if this symbol should be in the output */
368 } /* for each symbol */
369
370 H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number);
4bda835f 371}
fecd2382
RP
372
373/*
374 * Find strings by crawling along symbol table chain.
375 */
376
85051959
ILT
377void
378obj_emit_strings (where)
379 char **where;
fecd2382 380{
85051959
ILT
381 symbolS *symbolP;
382
a39116f1 383#ifdef CROSS_COMPILE
85051959
ILT
384 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
385 md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count));
386 *where += sizeof (string_byte_count);
a39116f1 387#else /* CROSS_COMPILE */
85051959 388 append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count));
a39116f1 389#endif /* CROSS_COMPILE */
fecd2382 390
85051959
ILT
391 for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP))
392 {
393 if (S_GET_NAME (symbolP))
394 append (&next_object_file_charP, S_GET_NAME (symbolP),
395 (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1));
396 } /* walk symbol chain */
4bda835f 397}
85051959
ILT
398
399#ifndef AOUT_VERSION
400#define AOUT_VERSION 0
401#endif
402
403void
404obj_pre_write_hook (headers)
405 object_headers *headers;
a39116f1 406{
85051959
ILT
407 H_SET_DYNAMIC (headers, 0);
408 H_SET_VERSION (headers, AOUT_VERSION);
409 H_SET_MACHTYPE (headers, AOUT_MACHTYPE);
410 tc_aout_pre_write_hook (headers);
4bda835f 411}
a39116f1 412
85051959
ILT
413void
414DEFUN_VOID (s_sect)
415{
416 /* Strip out the section name */
417 char *section_name;
418 char *section_name_end;
419 char c;
420
421 unsigned int len;
422 unsigned int exp;
423 char *save;
424
425 section_name = input_line_pointer;
426 c = get_symbol_end ();
427 section_name_end = input_line_pointer;
428
429 len = section_name_end - section_name;
430 input_line_pointer++;
431 save = input_line_pointer;
432
433 SKIP_WHITESPACE ();
434 if (c == ',')
435 {
436 exp = get_absolute_expression ();
437 }
438 else if (*input_line_pointer == ',')
439 {
440 input_line_pointer++;
441 exp = get_absolute_expression ();
442 }
443 else
444 {
445 input_line_pointer = save;
446 exp = 0;
447 }
448 if (exp >= 1000)
449 {
450 as_bad ("subsegment index too high");
451 }
452
453 if (strcmp (section_name, ".text") == 0)
454 {
604633ae 455 subseg_set (SEG_TEXT, (subsegT) exp);
85051959
ILT
456 }
457
458 if (strcmp (section_name, ".data") == 0)
459 {
460 if (flagseen['R'])
604633ae 461 subseg_set (SEG_TEXT, (subsegT) exp + 1000);
85051959 462 else
604633ae 463 subseg_set (SEG_DATA, (subsegT) exp);
85051959
ILT
464 }
465
466 *section_name_end = c;
467}
468
469#endif /* ! BFD_ASSEMBLER */
fecd2382
RP
470
471/* end of obj-aout.c */
This page took 0.175744 seconds and 4 git commands to generate.