Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* a.out object file format |
4c63da97 | 2 | Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 |
252b5132 RH |
3 | Free Software Foundation, Inc. |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as | |
9 | published by the Free Software Foundation; either version 2, | |
10 | or (at your option) any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
15 | the GNU General Public License for more details. | |
16 | ||
49309057 ILT |
17 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
252b5132 | 21 | |
4c63da97 AM |
22 | #define OBJ_HEADER "obj-aout.h" |
23 | ||
252b5132 RH |
24 | #include "as.h" |
25 | #ifdef BFD_ASSEMBLER | |
26 | #undef NO_RELOC | |
27 | #include "aout/aout64.h" | |
28 | #endif | |
29 | #include "obstack.h" | |
30 | ||
31 | #ifndef BFD_ASSEMBLER | |
32 | /* in: segT out: N_TYPE bits */ | |
33 | const short seg_N_TYPE[] = | |
34 | { | |
35 | N_ABS, | |
36 | N_TEXT, | |
37 | N_DATA, | |
38 | N_BSS, | |
39 | N_UNDF, /* unknown */ | |
40 | N_UNDF, /* error */ | |
41 | N_UNDF, /* expression */ | |
42 | N_UNDF, /* debug */ | |
43 | N_UNDF, /* ntv */ | |
44 | N_UNDF, /* ptv */ | |
45 | N_REGISTER, /* register */ | |
46 | }; | |
47 | ||
48 | const segT N_TYPE_seg[N_TYPE + 2] = | |
49 | { /* N_TYPE == 0x1E = 32-2 */ | |
50 | SEG_UNKNOWN, /* N_UNDF == 0 */ | |
51 | SEG_GOOF, | |
52 | SEG_ABSOLUTE, /* N_ABS == 2 */ | |
53 | SEG_GOOF, | |
54 | SEG_TEXT, /* N_TEXT == 4 */ | |
55 | SEG_GOOF, | |
56 | SEG_DATA, /* N_DATA == 6 */ | |
57 | SEG_GOOF, | |
58 | SEG_BSS, /* N_BSS == 8 */ | |
59 | SEG_GOOF, | |
60 | SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, | |
61 | SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, | |
62 | SEG_GOOF, SEG_GOOF, SEG_GOOF, SEG_GOOF, | |
63 | SEG_REGISTER, /* dummy N_REGISTER for regs = 30 */ | |
64 | SEG_GOOF, | |
65 | }; | |
66 | #endif | |
67 | ||
68 | static void obj_aout_line PARAMS ((int)); | |
69 | static void obj_aout_weak PARAMS ((int)); | |
70 | static void obj_aout_type PARAMS ((int)); | |
71 | ||
4c63da97 | 72 | const pseudo_typeS aout_pseudo_table[] = |
252b5132 RH |
73 | { |
74 | {"line", obj_aout_line, 0}, /* source code line number */ | |
75 | {"ln", obj_aout_line, 0}, /* coff line number that we use anyway */ | |
76 | ||
77 | {"weak", obj_aout_weak, 0}, /* mark symbol as weak. */ | |
78 | ||
79 | {"type", obj_aout_type, 0}, | |
80 | ||
81 | /* coff debug pseudos (ignored) */ | |
82 | {"def", s_ignore, 0}, | |
83 | {"dim", s_ignore, 0}, | |
84 | {"endef", s_ignore, 0}, | |
85 | {"ident", s_ignore, 0}, | |
86 | {"line", s_ignore, 0}, | |
87 | {"ln", s_ignore, 0}, | |
88 | {"scl", s_ignore, 0}, | |
89 | {"size", s_ignore, 0}, | |
90 | {"tag", s_ignore, 0}, | |
91 | {"val", s_ignore, 0}, | |
92 | {"version", s_ignore, 0}, | |
93 | ||
94 | {"optim", s_ignore, 0}, /* For sun386i cc (?) */ | |
95 | ||
96 | /* other stuff */ | |
97 | {"ABORT", s_abort, 0}, | |
98 | ||
4c63da97 AM |
99 | {NULL, NULL, 0} /* end sentinel */ |
100 | }; /* aout_pseudo_table */ | |
252b5132 RH |
101 | |
102 | ||
103 | #ifdef BFD_ASSEMBLER | |
104 | ||
105 | void | |
106 | obj_aout_frob_symbol (sym, punt) | |
107 | symbolS *sym; | |
5110c57e | 108 | int *punt ATTRIBUTE_UNUSED; |
252b5132 RH |
109 | { |
110 | flagword flags; | |
111 | asection *sec; | |
112 | int desc, type, other; | |
113 | ||
49309057 | 114 | flags = symbol_get_bfdsym (sym)->flags; |
4c63da97 AM |
115 | desc = aout_symbol (symbol_get_bfdsym (sym))->desc; |
116 | type = aout_symbol (symbol_get_bfdsym (sym))->type; | |
117 | other = aout_symbol (symbol_get_bfdsym (sym))->other; | |
49309057 | 118 | sec = S_GET_SEGMENT (sym); |
252b5132 RH |
119 | |
120 | /* Only frob simple symbols this way right now. */ | |
121 | if (! (type & ~ (N_TYPE | N_EXT))) | |
122 | { | |
123 | if (type == (N_UNDF | N_EXT) | |
124 | && sec == &bfd_abs_section) | |
49309057 ILT |
125 | { |
126 | sec = bfd_und_section_ptr; | |
127 | S_SET_SEGMENT (sym, sec); | |
128 | } | |
252b5132 RH |
129 | |
130 | if ((type & N_TYPE) != N_INDR | |
131 | && (type & N_TYPE) != N_SETA | |
132 | && (type & N_TYPE) != N_SETT | |
133 | && (type & N_TYPE) != N_SETD | |
134 | && (type & N_TYPE) != N_SETB | |
135 | && type != N_WARNING | |
136 | && (sec == &bfd_abs_section | |
137 | || sec == &bfd_und_section)) | |
138 | return; | |
139 | if (flags & BSF_EXPORT) | |
140 | type |= N_EXT; | |
141 | ||
142 | switch (type & N_TYPE) | |
143 | { | |
144 | case N_SETA: | |
145 | case N_SETT: | |
146 | case N_SETD: | |
147 | case N_SETB: | |
148 | /* Set the debugging flag for constructor symbols so that | |
149 | BFD leaves them alone. */ | |
49309057 | 150 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
151 | |
152 | /* You can't put a common symbol in a set. The way a set | |
153 | element works is that the symbol has a definition and a | |
154 | name, and the linker adds the definition to the set of | |
155 | that name. That does not work for a common symbol, | |
156 | because the linker can't tell which common symbol the | |
157 | user means. FIXME: Using as_bad here may be | |
158 | inappropriate, since the user may want to force a | |
159 | particular type without regard to the semantics of sets; | |
160 | on the other hand, we certainly don't want anybody to be | |
161 | mislead into thinking that their code will work. */ | |
162 | if (S_IS_COMMON (sym)) | |
163 | as_bad (_("Attempt to put a common symbol into set %s"), | |
164 | S_GET_NAME (sym)); | |
165 | /* Similarly, you can't put an undefined symbol in a set. */ | |
166 | else if (! S_IS_DEFINED (sym)) | |
167 | as_bad (_("Attempt to put an undefined symbol into set %s"), | |
168 | S_GET_NAME (sym)); | |
169 | ||
170 | break; | |
171 | case N_INDR: | |
172 | /* Put indirect symbols in the indirect section. */ | |
49309057 ILT |
173 | S_SET_SEGMENT (sym, bfd_ind_section_ptr); |
174 | symbol_get_bfdsym (sym)->flags |= BSF_INDIRECT; | |
252b5132 RH |
175 | if (type & N_EXT) |
176 | { | |
49309057 ILT |
177 | symbol_get_bfdsym (sym)->flags |= BSF_EXPORT; |
178 | symbol_get_bfdsym (sym)->flags &=~ BSF_LOCAL; | |
252b5132 RH |
179 | } |
180 | break; | |
181 | case N_WARNING: | |
182 | /* Mark warning symbols. */ | |
49309057 | 183 | symbol_get_bfdsym (sym)->flags |= BSF_WARNING; |
252b5132 RH |
184 | break; |
185 | } | |
186 | } | |
187 | else | |
188 | { | |
49309057 | 189 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
190 | } |
191 | ||
4c63da97 | 192 | aout_symbol (symbol_get_bfdsym (sym))->type = type; |
252b5132 RH |
193 | |
194 | /* Double check weak symbols. */ | |
49309057 | 195 | if (S_IS_WEAK (sym)) |
252b5132 RH |
196 | { |
197 | if (S_IS_COMMON (sym)) | |
198 | as_bad (_("Symbol `%s' can not be both weak and common"), | |
199 | S_GET_NAME (sym)); | |
200 | } | |
201 | } | |
202 | ||
203 | void | |
204 | obj_aout_frob_file () | |
205 | { | |
206 | /* Relocation processing may require knowing the VMAs of the sections. | |
207 | Since writing to a section will cause the BFD back end to compute the | |
208 | VMAs, fake it out here.... */ | |
209 | bfd_byte b = 0; | |
210 | boolean x = true; | |
211 | if (bfd_section_size (stdoutput, text_section) != 0) | |
212 | { | |
213 | x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0, | |
214 | (bfd_size_type) 1); | |
215 | } | |
216 | else if (bfd_section_size (stdoutput, data_section) != 0) | |
217 | { | |
218 | x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0, | |
219 | (bfd_size_type) 1); | |
220 | } | |
221 | assert (x == true); | |
222 | } | |
223 | ||
d02d939f | 224 | #else /* ! BFD_ASSEMBLER */ |
252b5132 RH |
225 | |
226 | /* Relocation. */ | |
227 | ||
228 | /* | |
229 | * emit_relocations() | |
230 | * | |
231 | * Crawl along a fixS chain. Emit the segment's relocations. | |
232 | */ | |
233 | void | |
234 | obj_emit_relocations (where, fixP, segment_address_in_file) | |
235 | char **where; | |
236 | fixS *fixP; /* Fixup chain for this segment. */ | |
237 | relax_addressT segment_address_in_file; | |
238 | { | |
239 | for (; fixP; fixP = fixP->fx_next) | |
240 | if (fixP->fx_done == 0) | |
241 | { | |
242 | symbolS *sym; | |
243 | ||
244 | sym = fixP->fx_addsy; | |
245 | while (sym->sy_value.X_op == O_symbol | |
246 | && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) | |
247 | sym = sym->sy_value.X_add_symbol; | |
248 | fixP->fx_addsy = sym; | |
249 | ||
250 | if (! sym->sy_resolved && ! S_IS_DEFINED (sym)) | |
251 | { | |
252 | char *file; | |
253 | unsigned int line; | |
254 | ||
255 | if (expr_symbol_where (sym, &file, &line)) | |
256 | as_bad_where (file, line, _("unresolved relocation")); | |
257 | else | |
258 | as_bad (_("bad relocation: symbol `%s' not in symbol table"), | |
259 | S_GET_NAME (sym)); | |
260 | } | |
261 | ||
262 | tc_aout_fix_to_chars (*where, fixP, segment_address_in_file); | |
263 | *where += md_reloc_size; | |
264 | } | |
265 | } | |
266 | ||
267 | #ifndef obj_header_append | |
268 | /* Aout file generation & utilities */ | |
269 | void | |
270 | obj_header_append (where, headers) | |
271 | char **where; | |
272 | object_headers *headers; | |
273 | { | |
274 | tc_headers_hook (headers); | |
275 | ||
276 | #ifdef CROSS_COMPILE | |
277 | md_number_to_chars (*where, headers->header.a_info, sizeof (headers->header.a_info)); | |
278 | *where += sizeof (headers->header.a_info); | |
279 | md_number_to_chars (*where, headers->header.a_text, sizeof (headers->header.a_text)); | |
280 | *where += sizeof (headers->header.a_text); | |
281 | md_number_to_chars (*where, headers->header.a_data, sizeof (headers->header.a_data)); | |
282 | *where += sizeof (headers->header.a_data); | |
283 | md_number_to_chars (*where, headers->header.a_bss, sizeof (headers->header.a_bss)); | |
284 | *where += sizeof (headers->header.a_bss); | |
285 | md_number_to_chars (*where, headers->header.a_syms, sizeof (headers->header.a_syms)); | |
286 | *where += sizeof (headers->header.a_syms); | |
287 | md_number_to_chars (*where, headers->header.a_entry, sizeof (headers->header.a_entry)); | |
288 | *where += sizeof (headers->header.a_entry); | |
289 | md_number_to_chars (*where, headers->header.a_trsize, sizeof (headers->header.a_trsize)); | |
290 | *where += sizeof (headers->header.a_trsize); | |
291 | md_number_to_chars (*where, headers->header.a_drsize, sizeof (headers->header.a_drsize)); | |
292 | *where += sizeof (headers->header.a_drsize); | |
293 | ||
294 | #else /* CROSS_COMPILE */ | |
295 | ||
296 | append (where, (char *) &headers->header, sizeof (headers->header)); | |
297 | #endif /* CROSS_COMPILE */ | |
298 | ||
299 | } | |
d02d939f | 300 | #endif /* ! defined (obj_header_append) */ |
252b5132 RH |
301 | |
302 | void | |
303 | obj_symbol_to_chars (where, symbolP) | |
304 | char **where; | |
305 | symbolS *symbolP; | |
306 | { | |
307 | md_number_to_chars ((char *) &(S_GET_OFFSET (symbolP)), S_GET_OFFSET (symbolP), sizeof (S_GET_OFFSET (symbolP))); | |
308 | md_number_to_chars ((char *) &(S_GET_DESC (symbolP)), S_GET_DESC (symbolP), sizeof (S_GET_DESC (symbolP))); | |
309 | md_number_to_chars ((char *) &(symbolP->sy_symbol.n_value), S_GET_VALUE (symbolP), sizeof (symbolP->sy_symbol.n_value)); | |
310 | ||
311 | append (where, (char *) &symbolP->sy_symbol, sizeof (obj_symbol_type)); | |
312 | } | |
313 | ||
314 | void | |
315 | obj_emit_symbols (where, symbol_rootP) | |
316 | char **where; | |
317 | symbolS *symbol_rootP; | |
318 | { | |
319 | symbolS *symbolP; | |
320 | ||
321 | /* Emit all symbols left in the symbol chain. */ | |
322 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) | |
323 | { | |
324 | /* Used to save the offset of the name. It is used to point | |
325 | to the string in memory but must be a file offset. */ | |
326 | register char *temp; | |
327 | ||
328 | temp = S_GET_NAME (symbolP); | |
329 | S_SET_OFFSET (symbolP, symbolP->sy_name_offset); | |
330 | ||
331 | /* Any symbol still undefined and is not a dbg symbol is made N_EXT. */ | |
332 | if (!S_IS_DEBUG (symbolP) && !S_IS_DEFINED (symbolP)) | |
333 | S_SET_EXTERNAL (symbolP); | |
334 | ||
335 | /* Adjust the type of a weak symbol. */ | |
336 | if (S_GET_WEAK (symbolP)) | |
337 | { | |
338 | switch (S_GET_TYPE (symbolP)) | |
339 | { | |
340 | case N_UNDF: S_SET_TYPE (symbolP, N_WEAKU); break; | |
341 | case N_ABS: S_SET_TYPE (symbolP, N_WEAKA); break; | |
342 | case N_TEXT: S_SET_TYPE (symbolP, N_WEAKT); break; | |
343 | case N_DATA: S_SET_TYPE (symbolP, N_WEAKD); break; | |
344 | case N_BSS: S_SET_TYPE (symbolP, N_WEAKB); break; | |
345 | default: as_bad (_("%s: bad type for weak symbol"), temp); break; | |
346 | } | |
347 | } | |
348 | ||
349 | obj_symbol_to_chars (where, symbolP); | |
350 | S_SET_NAME (symbolP, temp); | |
351 | } | |
352 | } | |
353 | ||
354 | #endif /* ! BFD_ASSEMBLER */ | |
355 | ||
356 | static void | |
357 | obj_aout_line (ignore) | |
5110c57e | 358 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
359 | { |
360 | /* Assume delimiter is part of expression. | |
361 | BSD4.2 as fails with delightful bug, so we | |
362 | are not being incompatible here. */ | |
363 | new_logical_line ((char *) NULL, (int) (get_absolute_expression ())); | |
364 | demand_empty_rest_of_line (); | |
365 | } /* obj_aout_line() */ | |
366 | ||
367 | /* Handle .weak. This is a GNU extension. */ | |
368 | ||
369 | static void | |
370 | obj_aout_weak (ignore) | |
5110c57e | 371 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
372 | { |
373 | char *name; | |
374 | int c; | |
375 | symbolS *symbolP; | |
376 | ||
377 | do | |
378 | { | |
379 | name = input_line_pointer; | |
380 | c = get_symbol_end (); | |
381 | symbolP = symbol_find_or_make (name); | |
382 | *input_line_pointer = c; | |
383 | SKIP_WHITESPACE (); | |
384 | S_SET_WEAK (symbolP); | |
385 | if (c == ',') | |
386 | { | |
387 | input_line_pointer++; | |
388 | SKIP_WHITESPACE (); | |
389 | if (*input_line_pointer == '\n') | |
390 | c = '\n'; | |
391 | } | |
392 | } | |
393 | while (c == ','); | |
394 | demand_empty_rest_of_line (); | |
395 | } | |
396 | ||
397 | /* Handle .type. On {Net,Open}BSD, this is used to set the n_other field, | |
398 | which is then apparently used when doing dynamic linking. Older | |
9d87310a | 399 | versions of gas ignored the .type pseudo-op, so we also ignore it if |
252b5132 RH |
400 | we can't parse it. */ |
401 | ||
402 | static void | |
403 | obj_aout_type (ignore) | |
5110c57e | 404 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
405 | { |
406 | char *name; | |
407 | int c; | |
408 | symbolS *sym; | |
409 | ||
410 | name = input_line_pointer; | |
411 | c = get_symbol_end (); | |
9d87310a | 412 | sym = symbol_find_or_make (name); |
252b5132 | 413 | *input_line_pointer = c; |
9d87310a HPN |
414 | SKIP_WHITESPACE (); |
415 | if (*input_line_pointer == ',') | |
252b5132 | 416 | { |
9d87310a | 417 | ++input_line_pointer; |
252b5132 | 418 | SKIP_WHITESPACE (); |
9d87310a | 419 | if (*input_line_pointer == '@') |
252b5132 RH |
420 | { |
421 | ++input_line_pointer; | |
9d87310a | 422 | if (strncmp (input_line_pointer, "object", 6) == 0) |
4c63da97 | 423 | #ifdef BFD_ASSEMBLER |
9d87310a | 424 | aout_symbol (symbol_get_bfdsym (sym))->other = 1; |
4c63da97 | 425 | #else |
9d87310a | 426 | S_SET_OTHER (sym, 1); |
4c63da97 | 427 | #endif |
9d87310a | 428 | else if (strncmp (input_line_pointer, "function", 8) == 0) |
4c63da97 | 429 | #ifdef BFD_ASSEMBLER |
9d87310a | 430 | aout_symbol (symbol_get_bfdsym (sym))->other = 2; |
4c63da97 | 431 | #else |
9d87310a | 432 | S_SET_OTHER (sym, 2); |
4c63da97 | 433 | #endif |
252b5132 RH |
434 | } |
435 | } | |
436 | ||
437 | /* Ignore everything else on the line. */ | |
438 | s_ignore (0); | |
439 | } | |
440 | ||
252b5132 RH |
441 | #ifndef BFD_ASSEMBLER |
442 | ||
443 | void | |
444 | obj_crawl_symbol_chain (headers) | |
445 | object_headers *headers; | |
446 | { | |
447 | symbolS *symbolP; | |
448 | symbolS **symbolPP; | |
449 | int symbol_number = 0; | |
450 | ||
451 | tc_crawl_symbol_chain (headers); | |
452 | ||
453 | symbolPP = &symbol_rootP; /*->last symbol chain link. */ | |
454 | while ((symbolP = *symbolPP) != NULL) | |
455 | { | |
456 | if (symbolP->sy_mri_common) | |
457 | { | |
458 | if (S_IS_EXTERNAL (symbolP)) | |
459 | as_bad (_("%s: global symbols not supported in common sections"), | |
460 | S_GET_NAME (symbolP)); | |
461 | *symbolPP = symbol_next (symbolP); | |
462 | continue; | |
463 | } | |
464 | ||
465 | if (flag_readonly_data_in_text && (S_GET_SEGMENT (symbolP) == SEG_DATA)) | |
466 | { | |
467 | S_SET_SEGMENT (symbolP, SEG_TEXT); | |
468 | } /* if pusing data into text */ | |
469 | ||
470 | resolve_symbol_value (symbolP, 1); | |
471 | ||
472 | /* Skip symbols which were equated to undefined or common | |
473 | symbols. */ | |
474 | if (symbolP->sy_value.X_op == O_symbol | |
475 | && (! S_IS_DEFINED (symbolP) || S_IS_COMMON (symbolP))) | |
476 | { | |
477 | *symbolPP = symbol_next (symbolP); | |
478 | continue; | |
479 | } | |
480 | ||
481 | /* OK, here is how we decide which symbols go out into the brave | |
482 | new symtab. Symbols that do are: | |
483 | ||
484 | * symbols with no name (stabd's?) | |
485 | * symbols with debug info in their N_TYPE | |
486 | ||
487 | Symbols that don't are: | |
488 | * symbols that are registers | |
489 | * symbols with \1 as their 3rd character (numeric labels) | |
490 | * "local labels" as defined by S_LOCAL_NAME(name) if the -L | |
491 | switch was passed to gas. | |
492 | ||
493 | All other symbols are output. We complain if a deleted | |
494 | symbol was marked external. */ | |
495 | ||
496 | ||
497 | if (!S_IS_REGISTER (symbolP) | |
498 | && (!S_GET_NAME (symbolP) | |
499 | || S_IS_DEBUG (symbolP) | |
500 | || !S_IS_DEFINED (symbolP) | |
501 | || S_IS_EXTERNAL (symbolP) | |
502 | || (S_GET_NAME (symbolP)[0] != '\001' | |
503 | && (flag_keep_locals || !S_LOCAL_NAME (symbolP))))) | |
504 | { | |
505 | symbolP->sy_number = symbol_number++; | |
506 | ||
507 | /* The + 1 after strlen account for the \0 at the | |
508 | end of each string */ | |
509 | if (!S_IS_STABD (symbolP)) | |
510 | { | |
511 | /* Ordinary case. */ | |
512 | symbolP->sy_name_offset = string_byte_count; | |
513 | string_byte_count += strlen (S_GET_NAME (symbolP)) + 1; | |
514 | } | |
515 | else /* .Stabd case. */ | |
516 | symbolP->sy_name_offset = 0; | |
a1605869 | 517 | symbolPP = &symbolP->sy_next; |
252b5132 RH |
518 | } |
519 | else | |
520 | { | |
521 | if (S_IS_EXTERNAL (symbolP) || !S_IS_DEFINED (symbolP)) | |
522 | /* This warning should never get triggered any more. | |
523 | Well, maybe if you're doing twisted things with | |
524 | register names... */ | |
525 | { | |
526 | as_bad (_("Local symbol %s never defined."), decode_local_label_name (S_GET_NAME (symbolP))); | |
527 | } /* oops. */ | |
528 | ||
529 | /* Unhook it from the chain */ | |
530 | *symbolPP = symbol_next (symbolP); | |
531 | } /* if this symbol should be in the output */ | |
532 | } /* for each symbol */ | |
533 | ||
534 | H_SET_SYMBOL_TABLE_SIZE (headers, symbol_number); | |
535 | } | |
536 | ||
537 | /* | |
538 | * Find strings by crawling along symbol table chain. | |
539 | */ | |
540 | ||
541 | void | |
542 | obj_emit_strings (where) | |
543 | char **where; | |
544 | { | |
545 | symbolS *symbolP; | |
546 | ||
547 | #ifdef CROSS_COMPILE | |
548 | /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */ | |
549 | md_number_to_chars (*where, string_byte_count, sizeof (string_byte_count)); | |
550 | *where += sizeof (string_byte_count); | |
551 | #else /* CROSS_COMPILE */ | |
552 | append (where, (char *) &string_byte_count, (unsigned long) sizeof (string_byte_count)); | |
553 | #endif /* CROSS_COMPILE */ | |
554 | ||
555 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) | |
556 | { | |
557 | if (S_GET_NAME (symbolP)) | |
558 | append (&next_object_file_charP, S_GET_NAME (symbolP), | |
559 | (unsigned long) (strlen (S_GET_NAME (symbolP)) + 1)); | |
560 | } /* walk symbol chain */ | |
561 | } | |
562 | ||
563 | #ifndef AOUT_VERSION | |
564 | #define AOUT_VERSION 0 | |
565 | #endif | |
566 | ||
567 | void | |
568 | obj_pre_write_hook (headers) | |
569 | object_headers *headers; | |
570 | { | |
571 | H_SET_DYNAMIC (headers, 0); | |
572 | H_SET_VERSION (headers, AOUT_VERSION); | |
573 | H_SET_MACHTYPE (headers, AOUT_MACHTYPE); | |
574 | tc_aout_pre_write_hook (headers); | |
575 | } | |
576 | ||
577 | void | |
1994a7c7 | 578 | s_sect () |
252b5132 RH |
579 | { |
580 | /* Strip out the section name */ | |
581 | char *section_name; | |
582 | char *section_name_end; | |
583 | char c; | |
584 | ||
585 | unsigned int len; | |
586 | unsigned int exp; | |
587 | char *save; | |
588 | ||
589 | section_name = input_line_pointer; | |
590 | c = get_symbol_end (); | |
591 | section_name_end = input_line_pointer; | |
592 | ||
593 | len = section_name_end - section_name; | |
594 | input_line_pointer++; | |
595 | save = input_line_pointer; | |
596 | ||
597 | SKIP_WHITESPACE (); | |
598 | if (c == ',') | |
599 | { | |
600 | exp = get_absolute_expression (); | |
601 | } | |
602 | else if (*input_line_pointer == ',') | |
603 | { | |
604 | input_line_pointer++; | |
605 | exp = get_absolute_expression (); | |
606 | } | |
607 | else | |
608 | { | |
609 | input_line_pointer = save; | |
610 | exp = 0; | |
611 | } | |
612 | if (exp >= 1000) | |
613 | { | |
614 | as_bad (_("subsegment index too high")); | |
615 | } | |
616 | ||
617 | if (strcmp (section_name, ".text") == 0) | |
618 | { | |
619 | subseg_set (SEG_TEXT, (subsegT) exp); | |
620 | } | |
621 | ||
622 | if (strcmp (section_name, ".data") == 0) | |
623 | { | |
624 | if (flag_readonly_data_in_text) | |
625 | subseg_set (SEG_TEXT, (subsegT) exp + 1000); | |
626 | else | |
627 | subseg_set (SEG_DATA, (subsegT) exp); | |
628 | } | |
629 | ||
630 | *section_name_end = c; | |
631 | } | |
632 | ||
633 | #endif /* ! BFD_ASSEMBLER */ | |
634 | ||
4c63da97 AM |
635 | #ifdef BFD_ASSEMBLER |
636 | ||
637 | /* Support for an AOUT emulation. */ | |
638 | ||
639 | static void aout_pop_insert PARAMS ((void)); | |
640 | static int obj_aout_s_get_other PARAMS ((symbolS *)); | |
5110c57e | 641 | static void obj_aout_s_set_other PARAMS ((symbolS *, int)); |
4c63da97 | 642 | static int obj_aout_s_get_desc PARAMS ((symbolS *)); |
5110c57e HPN |
643 | static void obj_aout_s_set_desc PARAMS ((symbolS *, int)); |
644 | static int obj_aout_s_get_type PARAMS ((symbolS *)); | |
645 | static void obj_aout_s_set_type PARAMS ((symbolS *, int)); | |
646 | static int obj_aout_separate_stab_sections PARAMS ((void)); | |
647 | static int obj_aout_sec_sym_ok_for_reloc PARAMS ((asection *)); | |
648 | static void obj_aout_process_stab PARAMS ((segT, int, const char *, int, int, int)); | |
4c63da97 AM |
649 | |
650 | static void | |
651 | aout_pop_insert () | |
652 | { | |
653 | pop_insert (aout_pseudo_table); | |
654 | } | |
655 | ||
656 | static int | |
657 | obj_aout_s_get_other (sym) | |
658 | symbolS *sym; | |
659 | { | |
660 | return aout_symbol (symbol_get_bfdsym (sym))->other; | |
661 | } | |
662 | ||
5110c57e HPN |
663 | static void |
664 | obj_aout_s_set_other (sym, o) | |
665 | symbolS *sym; | |
666 | int o; | |
667 | { | |
668 | aout_symbol (symbol_get_bfdsym (sym))->other = o; | |
669 | } | |
670 | ||
671 | static int | |
672 | obj_aout_sec_sym_ok_for_reloc (sec) | |
673 | asection *sec ATTRIBUTE_UNUSED; | |
674 | { | |
675 | return obj_sec_sym_ok_for_reloc (sec); | |
676 | } | |
677 | ||
678 | static void | |
679 | obj_aout_process_stab (seg, w, s, t, o, d) | |
680 | segT seg ATTRIBUTE_UNUSED; | |
681 | int w; | |
682 | const char *s; | |
683 | int t; | |
684 | int o; | |
685 | int d; | |
686 | { | |
687 | aout_process_stab (w, s, t, o, d); | |
688 | } | |
689 | ||
4c63da97 AM |
690 | static int |
691 | obj_aout_s_get_desc (sym) | |
692 | symbolS *sym; | |
693 | { | |
694 | return aout_symbol (symbol_get_bfdsym (sym))->desc; | |
695 | } | |
696 | ||
5110c57e HPN |
697 | static void |
698 | obj_aout_s_set_desc (sym, d) | |
699 | symbolS *sym; | |
700 | int d; | |
701 | { | |
702 | aout_symbol (symbol_get_bfdsym (sym))->desc = d; | |
703 | } | |
704 | ||
705 | static int | |
706 | obj_aout_s_get_type (sym) | |
707 | symbolS *sym; | |
708 | { | |
709 | return aout_symbol (symbol_get_bfdsym (sym))->type; | |
710 | } | |
711 | ||
712 | static void | |
713 | obj_aout_s_set_type (sym, t) | |
714 | symbolS *sym; | |
715 | int t; | |
716 | { | |
717 | aout_symbol (symbol_get_bfdsym (sym))->type = t; | |
718 | } | |
719 | ||
720 | static int | |
721 | obj_aout_separate_stab_sections () | |
722 | { | |
723 | return 0; | |
724 | } | |
4c63da97 | 725 | |
5110c57e HPN |
726 | /* When changed, make sure these table entries match the single-format |
727 | definitions in obj-aout.h. */ | |
4c63da97 AM |
728 | const struct format_ops aout_format_ops = |
729 | { | |
730 | bfd_target_aout_flavour, | |
731 | 1, /* dfl_leading_underscore */ | |
732 | 0, /* emit_section_symbols */ | |
5110c57e HPN |
733 | 0, /* begin */ |
734 | 0, /* app_file */ | |
4c63da97 AM |
735 | obj_aout_frob_symbol, |
736 | obj_aout_frob_file, | |
737 | 0, /* frob_file_after_relocs */ | |
738 | 0, /* s_get_size */ | |
739 | 0, /* s_set_size */ | |
740 | 0, /* s_get_align */ | |
741 | 0, /* s_set_align */ | |
742 | obj_aout_s_get_other, | |
5110c57e | 743 | obj_aout_s_set_other, |
4c63da97 | 744 | obj_aout_s_get_desc, |
5110c57e HPN |
745 | obj_aout_s_set_desc, |
746 | obj_aout_s_get_type, | |
747 | obj_aout_s_set_type, | |
4c63da97 AM |
748 | 0, /* copy_symbol_attributes */ |
749 | 0, /* generate_asm_lineno */ | |
5110c57e HPN |
750 | obj_aout_process_stab, |
751 | obj_aout_separate_stab_sections, | |
752 | 0, /* init_stab_section */ | |
753 | obj_aout_sec_sym_ok_for_reloc, | |
4c63da97 AM |
754 | aout_pop_insert, |
755 | 0, /* ecoff_set_ext */ | |
756 | 0, /* read_begin_hook */ | |
757 | 0 /* symbol_new_hook */ | |
758 | }; | |
759 | #endif BFD_ASSEMBLER | |
760 | ||
252b5132 | 761 | /* end of obj-aout.c */ |