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 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 3,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 #define OBJ_HEADER "obj-aout.h"
26 #include "aout/aout64.h"
30 obj_aout_frob_symbol (symbolS
*sym
, int *punt ATTRIBUTE_UNUSED
)
34 int desc
, type
, other
;
36 flags
= symbol_get_bfdsym (sym
)->flags
;
37 desc
= aout_symbol (symbol_get_bfdsym (sym
))->desc
;
38 type
= aout_symbol (symbol_get_bfdsym (sym
))->type
;
39 other
= aout_symbol (symbol_get_bfdsym (sym
))->other
;
40 sec
= S_GET_SEGMENT (sym
);
42 /* Only frob simple symbols this way right now. */
43 if (! (type
& ~ (N_TYPE
| N_EXT
)))
45 if (type
== (N_UNDF
| N_EXT
)
46 && sec
== &bfd_abs_section
)
48 sec
= bfd_und_section_ptr
;
49 S_SET_SEGMENT (sym
, sec
);
52 if ((type
& N_TYPE
) != N_INDR
53 && (type
& N_TYPE
) != N_SETA
54 && (type
& N_TYPE
) != N_SETT
55 && (type
& N_TYPE
) != N_SETD
56 && (type
& N_TYPE
) != N_SETB
58 && (sec
== &bfd_abs_section
59 || sec
== &bfd_und_section
))
61 if (flags
& BSF_EXPORT
)
64 switch (type
& N_TYPE
)
70 /* Set the debugging flag for constructor symbols so that
71 BFD leaves them alone. */
72 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
74 /* You can't put a common symbol in a set. The way a set
75 element works is that the symbol has a definition and a
76 name, and the linker adds the definition to the set of
77 that name. That does not work for a common symbol,
78 because the linker can't tell which common symbol the
79 user means. FIXME: Using as_bad here may be
80 inappropriate, since the user may want to force a
81 particular type without regard to the semantics of sets;
82 on the other hand, we certainly don't want anybody to be
83 mislead into thinking that their code will work. */
84 if (S_IS_COMMON (sym
))
85 as_bad (_("Attempt to put a common symbol into set %s"),
87 /* Similarly, you can't put an undefined symbol in a set. */
88 else if (! S_IS_DEFINED (sym
))
89 as_bad (_("Attempt to put an undefined symbol into set %s"),
94 /* Put indirect symbols in the indirect section. */
95 S_SET_SEGMENT (sym
, bfd_ind_section_ptr
);
96 symbol_get_bfdsym (sym
)->flags
|= BSF_INDIRECT
;
99 symbol_get_bfdsym (sym
)->flags
|= BSF_EXPORT
;
100 symbol_get_bfdsym (sym
)->flags
&=~ BSF_LOCAL
;
104 /* Mark warning symbols. */
105 symbol_get_bfdsym (sym
)->flags
|= BSF_WARNING
;
110 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
112 aout_symbol (symbol_get_bfdsym (sym
))->type
= type
;
114 /* Double check weak symbols. */
115 if (S_IS_WEAK (sym
) && S_IS_COMMON (sym
))
116 as_bad (_("Symbol `%s' can not be both weak and common"),
121 obj_aout_frob_file_before_fix (void)
123 /* Relocation processing may require knowing the VMAs of the sections.
124 Since writing to a section will cause the BFD back end to compute the
125 VMAs, fake it out here.... */
127 bfd_boolean x
= TRUE
;
128 if (bfd_section_size (stdoutput
, text_section
) != 0)
129 x
= bfd_set_section_contents (stdoutput
, text_section
, &b
, (file_ptr
) 0,
131 else if (bfd_section_size (stdoutput
, data_section
) != 0)
132 x
= bfd_set_section_contents (stdoutput
, data_section
, &b
, (file_ptr
) 0,
139 obj_aout_line (int ignore ATTRIBUTE_UNUSED
)
141 /* Assume delimiter is part of expression.
142 BSD4.2 as fails with delightful bug, so we
143 are not being incompatible here. */
144 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
145 demand_empty_rest_of_line ();
148 /* Handle .weak. This is a GNU extension. */
151 obj_aout_weak (int ignore ATTRIBUTE_UNUSED
)
159 name
= input_line_pointer
;
160 c
= get_symbol_end ();
161 symbolP
= symbol_find_or_make (name
);
162 *input_line_pointer
= c
;
164 S_SET_WEAK (symbolP
);
167 input_line_pointer
++;
169 if (*input_line_pointer
== '\n')
174 demand_empty_rest_of_line ();
177 /* Handle .type. On {Net,Open}BSD, this is used to set the n_other field,
178 which is then apparently used when doing dynamic linking. Older
179 versions of gas ignored the .type pseudo-op, so we also ignore it if
180 we can't parse it. */
183 obj_aout_type (int ignore ATTRIBUTE_UNUSED
)
189 name
= input_line_pointer
;
190 c
= get_symbol_end ();
191 sym
= symbol_find_or_make (name
);
192 *input_line_pointer
= c
;
194 if (*input_line_pointer
== ',')
196 ++input_line_pointer
;
198 if (*input_line_pointer
== '@')
200 ++input_line_pointer
;
201 if (strncmp (input_line_pointer
, "object", 6) == 0)
202 S_SET_OTHER (sym
, 1);
203 else if (strncmp (input_line_pointer
, "function", 8) == 0)
204 S_SET_OTHER (sym
, 2);
208 /* Ignore everything else on the line. */
212 /* Support for an AOUT emulation. */
215 aout_pop_insert (void)
217 pop_insert (aout_pseudo_table
);
221 obj_aout_s_get_other (symbolS
*sym
)
223 return aout_symbol (symbol_get_bfdsym (sym
))->other
;
227 obj_aout_s_set_other (symbolS
*sym
, int o
)
229 aout_symbol (symbol_get_bfdsym (sym
))->other
= o
;
233 obj_aout_sec_sym_ok_for_reloc (asection
*sec ATTRIBUTE_UNUSED
)
235 return obj_sec_sym_ok_for_reloc (sec
);
239 obj_aout_process_stab (segT seg ATTRIBUTE_UNUSED
,
246 aout_process_stab (w
, s
, t
, o
, d
);
250 obj_aout_s_get_desc (symbolS
*sym
)
252 return aout_symbol (symbol_get_bfdsym (sym
))->desc
;
256 obj_aout_s_set_desc (symbolS
*sym
, int d
)
258 aout_symbol (symbol_get_bfdsym (sym
))->desc
= d
;
262 obj_aout_s_get_type (symbolS
*sym
)
264 return aout_symbol (symbol_get_bfdsym (sym
))->type
;
268 obj_aout_s_set_type (symbolS
*sym
, int t
)
270 aout_symbol (symbol_get_bfdsym (sym
))->type
= t
;
274 obj_aout_separate_stab_sections (void)
279 /* When changed, make sure these table entries match the single-format
280 definitions in obj-aout.h. */
282 const struct format_ops aout_format_ops
=
284 bfd_target_aout_flavour
,
285 1, /* dfl_leading_underscore. */
286 0, /* emit_section_symbols. */
289 obj_aout_frob_symbol
,
291 0, /* frob_file_before_adjust. */
292 obj_aout_frob_file_before_fix
,
293 0, /* frob_file_after_relocs. */
296 0, /* s_get_align. */
297 0, /* s_set_align. */
298 obj_aout_s_get_other
,
299 obj_aout_s_set_other
,
304 0, /* copy_symbol_attributes. */
305 0, /* generate_asm_lineno. */
306 obj_aout_process_stab
,
307 obj_aout_separate_stab_sections
,
308 0, /* init_stab_section. */
309 obj_aout_sec_sym_ok_for_reloc
,
311 0, /* ecoff_set_ext. */
312 0, /* read_begin_hook. */
313 0, /* symbol_new_hook. */
314 0 /* symbol_clone_hook. */
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},