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