PR ld/11843
[binutils.git] / gas / config / obj-aout.c
blob366fc5b1d5cd0d1cf2290e92d826a25e7f0c68b8
1 /* a.out object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2007, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 3,
11 or (at your option) any later version.
13 GAS is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #define OBJ_HEADER "obj-aout.h"
25 #include "as.h"
26 #undef NO_RELOC
27 #include "aout/aout64.h"
28 #include "obstack.h"
30 void
31 obj_aout_frob_symbol (symbolS *sym, int *punt ATTRIBUTE_UNUSED)
33 flagword flags;
34 asection *sec;
35 int type;
37 flags = symbol_get_bfdsym (sym)->flags;
38 type = aout_symbol (symbol_get_bfdsym (sym))->type;
39 sec = S_GET_SEGMENT (sym);
41 /* Only frob simple symbols this way right now. */
42 if (! (type & ~ (N_TYPE | N_EXT)))
44 if (type == (N_UNDF | N_EXT)
45 && sec == &bfd_abs_section)
47 sec = bfd_und_section_ptr;
48 S_SET_SEGMENT (sym, sec);
51 if ((type & N_TYPE) != N_INDR
52 && (type & N_TYPE) != N_SETA
53 && (type & N_TYPE) != N_SETT
54 && (type & N_TYPE) != N_SETD
55 && (type & N_TYPE) != N_SETB
56 && type != N_WARNING
57 && (sec == &bfd_abs_section
58 || sec == &bfd_und_section))
59 return;
60 if (flags & BSF_EXPORT)
61 type |= N_EXT;
63 switch (type & N_TYPE)
65 case N_SETA:
66 case N_SETT:
67 case N_SETD:
68 case N_SETB:
69 /* Set the debugging flag for constructor symbols so that
70 BFD leaves them alone. */
71 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
73 /* You can't put a common symbol in a set. The way a set
74 element works is that the symbol has a definition and a
75 name, and the linker adds the definition to the set of
76 that name. That does not work for a common symbol,
77 because the linker can't tell which common symbol the
78 user means. FIXME: Using as_bad here may be
79 inappropriate, since the user may want to force a
80 particular type without regard to the semantics of sets;
81 on the other hand, we certainly don't want anybody to be
82 mislead into thinking that their code will work. */
83 if (S_IS_COMMON (sym))
84 as_bad (_("Attempt to put a common symbol into set %s"),
85 S_GET_NAME (sym));
86 /* Similarly, you can't put an undefined symbol in a set. */
87 else if (! S_IS_DEFINED (sym))
88 as_bad (_("Attempt to put an undefined symbol into set %s"),
89 S_GET_NAME (sym));
91 break;
92 case N_INDR:
93 /* Put indirect symbols in the indirect section. */
94 S_SET_SEGMENT (sym, bfd_ind_section_ptr);
95 symbol_get_bfdsym (sym)->flags |= BSF_INDIRECT;
96 if (type & N_EXT)
98 symbol_get_bfdsym (sym)->flags |= BSF_EXPORT;
99 symbol_get_bfdsym (sym)->flags &=~ BSF_LOCAL;
101 break;
102 case N_WARNING:
103 /* Mark warning symbols. */
104 symbol_get_bfdsym (sym)->flags |= BSF_WARNING;
105 break;
108 else
109 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
111 aout_symbol (symbol_get_bfdsym (sym))->type = type;
113 /* Double check weak symbols. */
114 if (S_IS_WEAK (sym) && S_IS_COMMON (sym))
115 as_bad (_("Symbol `%s' can not be both weak and common"),
116 S_GET_NAME (sym));
119 void
120 obj_aout_frob_file_before_fix (void)
122 /* Relocation processing may require knowing the VMAs of the sections.
123 Since writing to a section will cause the BFD back end to compute the
124 VMAs, fake it out here.... */
125 bfd_byte b = 0;
126 bfd_boolean x = TRUE;
127 if (bfd_section_size (stdoutput, text_section) != 0)
128 x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0,
129 (bfd_size_type) 1);
130 else if (bfd_section_size (stdoutput, data_section) != 0)
131 x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0,
132 (bfd_size_type) 1);
134 gas_assert (x);
137 static void
138 obj_aout_line (int ignore ATTRIBUTE_UNUSED)
140 /* Assume delimiter is part of expression.
141 BSD4.2 as fails with delightful bug, so we
142 are not being incompatible here. */
143 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
144 demand_empty_rest_of_line ();
147 /* Handle .weak. This is a GNU extension. */
149 static void
150 obj_aout_weak (int ignore ATTRIBUTE_UNUSED)
152 char *name;
153 int c;
154 symbolS *symbolP;
158 name = input_line_pointer;
159 c = get_symbol_end ();
160 symbolP = symbol_find_or_make (name);
161 *input_line_pointer = c;
162 SKIP_WHITESPACE ();
163 S_SET_WEAK (symbolP);
164 if (c == ',')
166 input_line_pointer++;
167 SKIP_WHITESPACE ();
168 if (*input_line_pointer == '\n')
169 c = '\n';
172 while (c == ',');
173 demand_empty_rest_of_line ();
176 /* Handle .type. On {Net,Open}BSD, this is used to set the n_other field,
177 which is then apparently used when doing dynamic linking. Older
178 versions of gas ignored the .type pseudo-op, so we also ignore it if
179 we can't parse it. */
181 static void
182 obj_aout_type (int ignore ATTRIBUTE_UNUSED)
184 char *name;
185 int c;
186 symbolS *sym;
188 name = input_line_pointer;
189 c = get_symbol_end ();
190 sym = symbol_find_or_make (name);
191 *input_line_pointer = c;
192 SKIP_WHITESPACE ();
193 if (*input_line_pointer == ',')
195 ++input_line_pointer;
196 SKIP_WHITESPACE ();
197 if (*input_line_pointer == '@')
199 ++input_line_pointer;
200 if (strncmp (input_line_pointer, "object", 6) == 0)
201 S_SET_OTHER (sym, 1);
202 else if (strncmp (input_line_pointer, "function", 8) == 0)
203 S_SET_OTHER (sym, 2);
207 /* Ignore everything else on the line. */
208 s_ignore (0);
211 /* Support for an AOUT emulation. */
213 static void
214 aout_pop_insert (void)
216 pop_insert (aout_pseudo_table);
219 static int
220 obj_aout_s_get_other (symbolS *sym)
222 return aout_symbol (symbol_get_bfdsym (sym))->other;
225 static void
226 obj_aout_s_set_other (symbolS *sym, int o)
228 aout_symbol (symbol_get_bfdsym (sym))->other = o;
231 static int
232 obj_aout_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED)
234 return obj_sec_sym_ok_for_reloc (sec);
237 static void
238 obj_aout_process_stab (segT seg ATTRIBUTE_UNUSED,
239 int w,
240 const char *s,
241 int t,
242 int o,
243 int d)
245 aout_process_stab (w, s, t, o, d);
248 static int
249 obj_aout_s_get_desc (symbolS *sym)
251 return aout_symbol (symbol_get_bfdsym (sym))->desc;
254 static void
255 obj_aout_s_set_desc (symbolS *sym, int d)
257 aout_symbol (symbol_get_bfdsym (sym))->desc = d;
260 static int
261 obj_aout_s_get_type (symbolS *sym)
263 return aout_symbol (symbol_get_bfdsym (sym))->type;
266 static void
267 obj_aout_s_set_type (symbolS *sym, int t)
269 aout_symbol (symbol_get_bfdsym (sym))->type = t;
272 static int
273 obj_aout_separate_stab_sections (void)
275 return 0;
278 /* When changed, make sure these table entries match the single-format
279 definitions in obj-aout.h. */
281 const struct format_ops aout_format_ops =
283 bfd_target_aout_flavour,
284 1, /* dfl_leading_underscore. */
285 0, /* emit_section_symbols. */
286 0, /* begin. */
287 0, /* app_file. */
288 obj_aout_frob_symbol,
289 0, /* frob_file. */
290 0, /* frob_file_before_adjust. */
291 obj_aout_frob_file_before_fix,
292 0, /* frob_file_after_relocs. */
293 0, /* s_get_size. */
294 0, /* s_set_size. */
295 0, /* s_get_align. */
296 0, /* s_set_align. */
297 obj_aout_s_get_other,
298 obj_aout_s_set_other,
299 obj_aout_s_get_desc,
300 obj_aout_s_set_desc,
301 obj_aout_s_get_type,
302 obj_aout_s_set_type,
303 0, /* copy_symbol_attributes. */
304 0, /* generate_asm_lineno. */
305 obj_aout_process_stab,
306 obj_aout_separate_stab_sections,
307 0, /* init_stab_section. */
308 obj_aout_sec_sym_ok_for_reloc,
309 aout_pop_insert,
310 0, /* ecoff_set_ext. */
311 0, /* read_begin_hook. */
312 0, /* symbol_new_hook. */
313 0 /* symbol_clone_hook. */
316 const pseudo_typeS aout_pseudo_table[] =
318 {"line", obj_aout_line, 0}, /* Source code line number. */
319 {"ln", obj_aout_line, 0}, /* COFF line number that we use anyway. */
321 {"weak", obj_aout_weak, 0}, /* Mark symbol as weak. */
323 {"type", obj_aout_type, 0},
325 /* coff debug pseudos (ignored) */
326 {"def", s_ignore, 0},
327 {"dim", s_ignore, 0},
328 {"endef", s_ignore, 0},
329 {"ident", s_ignore, 0},
330 {"line", s_ignore, 0},
331 {"ln", s_ignore, 0},
332 {"scl", s_ignore, 0},
333 {"size", s_ignore, 0},
334 {"tag", s_ignore, 0},
335 {"val", s_ignore, 0},
336 {"version", s_ignore, 0},
338 {"optim", s_ignore, 0}, /* For sun386i cc (?). */
340 /* other stuff */
341 {"ABORT", s_abort, 0},
343 {NULL, NULL, 0}