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, 2012
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
23 #define OBJ_HEADER "obj-aout.h"
27 #include "aout/aout64.h"
31 obj_aout_frob_symbol (symbolS
*sym
, int *punt ATTRIBUTE_UNUSED
)
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_ptr
)
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
57 && (sec
== bfd_abs_section_ptr
58 || sec
== bfd_und_section_ptr
))
60 if (flags
& BSF_EXPORT
)
63 switch (type
& N_TYPE
)
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"),
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"),
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
;
98 symbol_get_bfdsym (sym
)->flags
|= BSF_EXPORT
;
99 symbol_get_bfdsym (sym
)->flags
&=~ BSF_LOCAL
;
103 /* Mark warning symbols. */
104 symbol_get_bfdsym (sym
)->flags
|= BSF_WARNING
;
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"),
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.... */
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,
130 else if (bfd_section_size (stdoutput
, data_section
) != 0)
131 x
= bfd_set_section_contents (stdoutput
, data_section
, &b
, (file_ptr
) 0,
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. */
150 obj_aout_weak (int ignore ATTRIBUTE_UNUSED
)
158 name
= input_line_pointer
;
159 c
= get_symbol_end ();
160 symbolP
= symbol_find_or_make (name
);
161 *input_line_pointer
= c
;
163 S_SET_WEAK (symbolP
);
166 input_line_pointer
++;
168 if (*input_line_pointer
== '\n')
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. */
182 obj_aout_type (int ignore ATTRIBUTE_UNUSED
)
188 name
= input_line_pointer
;
189 c
= get_symbol_end ();
190 sym
= symbol_find_or_make (name
);
191 *input_line_pointer
= c
;
193 if (*input_line_pointer
== ',')
195 ++input_line_pointer
;
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. */
211 /* Support for an AOUT emulation. */
214 aout_pop_insert (void)
216 pop_insert (aout_pseudo_table
);
220 obj_aout_s_get_other (symbolS
*sym
)
222 return aout_symbol (symbol_get_bfdsym (sym
))->other
;
226 obj_aout_s_set_other (symbolS
*sym
, int o
)
228 aout_symbol (symbol_get_bfdsym (sym
))->other
= o
;
232 obj_aout_sec_sym_ok_for_reloc (asection
*sec ATTRIBUTE_UNUSED
)
234 return obj_sec_sym_ok_for_reloc (sec
);
238 obj_aout_process_stab (segT seg ATTRIBUTE_UNUSED
,
245 aout_process_stab (w
, s
, t
, o
, d
);
249 obj_aout_s_get_desc (symbolS
*sym
)
251 return aout_symbol (symbol_get_bfdsym (sym
))->desc
;
255 obj_aout_s_set_desc (symbolS
*sym
, int d
)
257 aout_symbol (symbol_get_bfdsym (sym
))->desc
= d
;
261 obj_aout_s_get_type (symbolS
*sym
)
263 return aout_symbol (symbol_get_bfdsym (sym
))->type
;
267 obj_aout_s_set_type (symbolS
*sym
, int t
)
269 aout_symbol (symbol_get_bfdsym (sym
))->type
= t
;
273 obj_aout_separate_stab_sections (void)
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. */
288 obj_aout_frob_symbol
,
290 0, /* frob_file_before_adjust. */
291 obj_aout_frob_file_before_fix
,
292 0, /* frob_file_after_relocs. */
295 0, /* s_get_align. */
296 0, /* s_set_align. */
297 obj_aout_s_get_other
,
298 obj_aout_s_set_other
,
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
,
310 0, /* ecoff_set_ext. */
311 0, /* read_begin_hook. */
312 0, /* symbol_new_hook. */
313 0, /* symbol_clone_hook. */
314 0 /* adjust_symtab. */
317 const pseudo_typeS aout_pseudo_table
[] =
319 {"line", obj_aout_line
, 0}, /* Source code line number. */
320 {"ln", obj_aout_line
, 0}, /* COFF line number that we use anyway. */
322 {"weak", obj_aout_weak
, 0}, /* Mark symbol as weak. */
324 {"type", obj_aout_type
, 0},
326 /* coff debug pseudos (ignored) */
327 {"def", s_ignore
, 0},
328 {"dim", s_ignore
, 0},
329 {"endef", s_ignore
, 0},
330 {"ident", s_ignore
, 0},
331 {"line", s_ignore
, 0},
333 {"scl", s_ignore
, 0},
334 {"size", s_ignore
, 0},
335 {"tag", s_ignore
, 0},
336 {"val", s_ignore
, 0},
337 {"version", s_ignore
, 0},
339 {"optim", s_ignore
, 0}, /* For sun386i cc (?). */
342 {"ABORT", s_abort
, 0},