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