1 /* a.out object file format
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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.
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.
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
21 #define OBJ_HEADER "obj-aout.h"
25 #include "aout/aout64.h"
29 obj_aout_frob_symbol (symbolS
*sym
, int *punt ATTRIBUTE_UNUSED
)
35 flags
= symbol_get_bfdsym (sym
)->flags
;
36 type
= aout_symbol (symbol_get_bfdsym (sym
))->type
;
37 sec
= S_GET_SEGMENT (sym
);
39 /* Only frob simple symbols this way right now. */
40 if (! (type
& ~ (N_TYPE
| N_EXT
)))
42 if (type
== (N_UNDF
| N_EXT
)
43 && sec
== bfd_abs_section_ptr
)
45 sec
= bfd_und_section_ptr
;
46 S_SET_SEGMENT (sym
, sec
);
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
55 && (sec
== bfd_abs_section_ptr
56 || sec
== bfd_und_section_ptr
))
58 if (flags
& BSF_EXPORT
)
61 switch (type
& N_TYPE
)
67 /* Set the debugging flag for constructor symbols so that
68 BFD leaves them alone. */
69 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
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"),
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"),
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
;
96 symbol_get_bfdsym (sym
)->flags
|= BSF_EXPORT
;
97 symbol_get_bfdsym (sym
)->flags
&=~ BSF_LOCAL
;
101 /* Mark warning symbols. */
102 symbol_get_bfdsym (sym
)->flags
|= BSF_WARNING
;
107 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
109 aout_symbol (symbol_get_bfdsym (sym
))->type
= type
;
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"),
118 obj_aout_frob_file_before_fix (void)
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.... */
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,
128 else if (bfd_section_size (stdoutput
, data_section
) != 0)
129 x
= bfd_set_section_contents (stdoutput
, data_section
, &b
, (file_ptr
) 0,
136 obj_aout_line (int ignore ATTRIBUTE_UNUSED
)
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 ();
145 /* Handle .weak. This is a GNU extension. */
148 obj_aout_weak (int ignore ATTRIBUTE_UNUSED
)
156 name
= input_line_pointer
;
157 c
= get_symbol_end ();
158 symbolP
= symbol_find_or_make (name
);
159 *input_line_pointer
= c
;
161 S_SET_WEAK (symbolP
);
164 input_line_pointer
++;
166 if (*input_line_pointer
== '\n')
171 demand_empty_rest_of_line ();
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. */
180 obj_aout_type (int ignore ATTRIBUTE_UNUSED
)
186 name
= input_line_pointer
;
187 c
= get_symbol_end ();
188 sym
= symbol_find_or_make (name
);
189 *input_line_pointer
= c
;
191 if (*input_line_pointer
== ',')
193 ++input_line_pointer
;
195 if (*input_line_pointer
== '@')
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);
205 /* Ignore everything else on the line. */
209 /* Support for an AOUT emulation. */
212 aout_pop_insert (void)
214 pop_insert (aout_pseudo_table
);
218 obj_aout_s_get_other (symbolS
*sym
)
220 return aout_symbol (symbol_get_bfdsym (sym
))->other
;
224 obj_aout_s_set_other (symbolS
*sym
, int o
)
226 aout_symbol (symbol_get_bfdsym (sym
))->other
= o
;
230 obj_aout_sec_sym_ok_for_reloc (asection
*sec ATTRIBUTE_UNUSED
)
232 return obj_sec_sym_ok_for_reloc (sec
);
236 obj_aout_process_stab (segT seg ATTRIBUTE_UNUSED
,
243 aout_process_stab (w
, s
, t
, o
, d
);
247 obj_aout_s_get_desc (symbolS
*sym
)
249 return aout_symbol (symbol_get_bfdsym (sym
))->desc
;
253 obj_aout_s_set_desc (symbolS
*sym
, int d
)
255 aout_symbol (symbol_get_bfdsym (sym
))->desc
= d
;
259 obj_aout_s_get_type (symbolS
*sym
)
261 return aout_symbol (symbol_get_bfdsym (sym
))->type
;
265 obj_aout_s_set_type (symbolS
*sym
, int t
)
267 aout_symbol (symbol_get_bfdsym (sym
))->type
= t
;
271 obj_aout_separate_stab_sections (void)
276 /* When changed, make sure these table entries match the single-format
277 definitions in obj-aout.h. */
279 const struct format_ops aout_format_ops
=
281 bfd_target_aout_flavour
,
282 1, /* dfl_leading_underscore. */
283 0, /* emit_section_symbols. */
286 obj_aout_frob_symbol
,
288 0, /* frob_file_before_adjust. */
289 obj_aout_frob_file_before_fix
,
290 0, /* frob_file_after_relocs. */
293 0, /* s_get_align. */
294 0, /* s_set_align. */
295 obj_aout_s_get_other
,
296 obj_aout_s_set_other
,
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
,
308 0, /* ecoff_set_ext. */
309 0, /* read_begin_hook. */
310 0, /* symbol_new_hook. */
311 0, /* symbol_clone_hook. */
312 0 /* adjust_symtab. */
315 const pseudo_typeS aout_pseudo_table
[] =
317 {"line", obj_aout_line
, 0}, /* Source code line number. */
318 {"ln", obj_aout_line
, 0}, /* COFF line number that we use anyway. */
320 {"weak", obj_aout_weak
, 0}, /* Mark symbol as weak. */
322 {"type", obj_aout_type
, 0},
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},
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},
337 {"optim", s_ignore
, 0}, /* For sun386i cc (?). */
340 {"ABORT", s_abort
, 0},