Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* a.out object file format |
4b95cf5c | 2 | Copyright (C) 1989-2014 Free Software Foundation, Inc. |
252b5132 | 3 | |
ea1562b3 | 4 | This file is part of GAS, the GNU Assembler. |
252b5132 | 5 | |
ea1562b3 NC |
6 | GAS is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as | |
ec2655a6 | 8 | published by the Free Software Foundation; either version 3, |
ea1562b3 | 9 | or (at your option) any later version. |
252b5132 | 10 | |
ea1562b3 NC |
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. | |
252b5132 | 15 | |
ea1562b3 NC |
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 | |
4b4da160 NC |
18 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | 02110-1301, USA. */ | |
252b5132 | 20 | |
4c63da97 AM |
21 | #define OBJ_HEADER "obj-aout.h" |
22 | ||
252b5132 | 23 | #include "as.h" |
252b5132 RH |
24 | #undef NO_RELOC |
25 | #include "aout/aout64.h" | |
252b5132 RH |
26 | #include "obstack.h" |
27 | ||
252b5132 | 28 | void |
ea1562b3 | 29 | obj_aout_frob_symbol (symbolS *sym, int *punt ATTRIBUTE_UNUSED) |
252b5132 RH |
30 | { |
31 | flagword flags; | |
32 | asection *sec; | |
87975d2a | 33 | int type; |
252b5132 | 34 | |
49309057 | 35 | flags = symbol_get_bfdsym (sym)->flags; |
4c63da97 | 36 | type = aout_symbol (symbol_get_bfdsym (sym))->type; |
49309057 | 37 | sec = S_GET_SEGMENT (sym); |
252b5132 RH |
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) | |
45dfa85a | 43 | && sec == bfd_abs_section_ptr) |
49309057 ILT |
44 | { |
45 | sec = bfd_und_section_ptr; | |
46 | S_SET_SEGMENT (sym, sec); | |
47 | } | |
252b5132 RH |
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 | |
45dfa85a AM |
55 | && (sec == bfd_abs_section_ptr |
56 | || sec == bfd_und_section_ptr)) | |
252b5132 RH |
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. */ | |
49309057 | 69 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 RH |
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. */ | |
49309057 ILT |
92 | S_SET_SEGMENT (sym, bfd_ind_section_ptr); |
93 | symbol_get_bfdsym (sym)->flags |= BSF_INDIRECT; | |
252b5132 RH |
94 | if (type & N_EXT) |
95 | { | |
49309057 ILT |
96 | symbol_get_bfdsym (sym)->flags |= BSF_EXPORT; |
97 | symbol_get_bfdsym (sym)->flags &=~ BSF_LOCAL; | |
252b5132 RH |
98 | } |
99 | break; | |
100 | case N_WARNING: | |
101 | /* Mark warning symbols. */ | |
49309057 | 102 | symbol_get_bfdsym (sym)->flags |= BSF_WARNING; |
252b5132 RH |
103 | break; |
104 | } | |
105 | } | |
106 | else | |
ea1562b3 | 107 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING; |
252b5132 | 108 | |
4c63da97 | 109 | aout_symbol (symbol_get_bfdsym (sym))->type = type; |
252b5132 RH |
110 | |
111 | /* Double check weak symbols. */ | |
ea1562b3 NC |
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)); | |
252b5132 RH |
115 | } |
116 | ||
117 | void | |
ea1562b3 | 118 | obj_aout_frob_file_before_fix (void) |
252b5132 RH |
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; | |
b34976b6 | 124 | bfd_boolean x = TRUE; |
252b5132 | 125 | if (bfd_section_size (stdoutput, text_section) != 0) |
ea1562b3 NC |
126 | x = bfd_set_section_contents (stdoutput, text_section, &b, (file_ptr) 0, |
127 | (bfd_size_type) 1); | |
252b5132 | 128 | else if (bfd_section_size (stdoutput, data_section) != 0) |
ea1562b3 NC |
129 | x = bfd_set_section_contents (stdoutput, data_section, &b, (file_ptr) 0, |
130 | (bfd_size_type) 1); | |
131 | ||
9c2799c2 | 132 | gas_assert (x); |
252b5132 RH |
133 | } |
134 | ||
252b5132 | 135 | static void |
ea1562b3 | 136 | obj_aout_line (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
137 | { |
138 | /* Assume delimiter is part of expression. | |
139 | BSD4.2 as fails with delightful bug, so we | |
dcd619be | 140 | are not being incompatible here. */ |
252b5132 RH |
141 | new_logical_line ((char *) NULL, (int) (get_absolute_expression ())); |
142 | demand_empty_rest_of_line (); | |
ea1562b3 | 143 | } |
252b5132 RH |
144 | |
145 | /* Handle .weak. This is a GNU extension. */ | |
146 | ||
147 | static void | |
ea1562b3 | 148 | obj_aout_weak (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
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 | |
9d87310a | 176 | versions of gas ignored the .type pseudo-op, so we also ignore it if |
252b5132 RH |
177 | we can't parse it. */ |
178 | ||
179 | static void | |
ea1562b3 | 180 | obj_aout_type (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
181 | { |
182 | char *name; | |
183 | int c; | |
184 | symbolS *sym; | |
185 | ||
186 | name = input_line_pointer; | |
187 | c = get_symbol_end (); | |
9d87310a | 188 | sym = symbol_find_or_make (name); |
252b5132 | 189 | *input_line_pointer = c; |
9d87310a HPN |
190 | SKIP_WHITESPACE (); |
191 | if (*input_line_pointer == ',') | |
252b5132 | 192 | { |
9d87310a | 193 | ++input_line_pointer; |
252b5132 | 194 | SKIP_WHITESPACE (); |
9d87310a | 195 | if (*input_line_pointer == '@') |
252b5132 RH |
196 | { |
197 | ++input_line_pointer; | |
9d87310a | 198 | if (strncmp (input_line_pointer, "object", 6) == 0) |
53fbb48a | 199 | S_SET_OTHER (sym, 1); |
9d87310a | 200 | else if (strncmp (input_line_pointer, "function", 8) == 0) |
53fbb48a | 201 | S_SET_OTHER (sym, 2); |
252b5132 RH |
202 | } |
203 | } | |
204 | ||
205 | /* Ignore everything else on the line. */ | |
206 | s_ignore (0); | |
207 | } | |
208 | ||
4c63da97 AM |
209 | /* Support for an AOUT emulation. */ |
210 | ||
4c63da97 | 211 | static void |
ea1562b3 | 212 | aout_pop_insert (void) |
4c63da97 AM |
213 | { |
214 | pop_insert (aout_pseudo_table); | |
215 | } | |
216 | ||
217 | static int | |
ea1562b3 | 218 | obj_aout_s_get_other (symbolS *sym) |
4c63da97 AM |
219 | { |
220 | return aout_symbol (symbol_get_bfdsym (sym))->other; | |
221 | } | |
222 | ||
5110c57e | 223 | static void |
ea1562b3 | 224 | obj_aout_s_set_other (symbolS *sym, int o) |
5110c57e HPN |
225 | { |
226 | aout_symbol (symbol_get_bfdsym (sym))->other = o; | |
227 | } | |
228 | ||
229 | static int | |
ea1562b3 | 230 | obj_aout_sec_sym_ok_for_reloc (asection *sec ATTRIBUTE_UNUSED) |
5110c57e HPN |
231 | { |
232 | return obj_sec_sym_ok_for_reloc (sec); | |
233 | } | |
234 | ||
235 | static void | |
ea1562b3 NC |
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) | |
5110c57e HPN |
242 | { |
243 | aout_process_stab (w, s, t, o, d); | |
244 | } | |
245 | ||
4c63da97 | 246 | static int |
ea1562b3 | 247 | obj_aout_s_get_desc (symbolS *sym) |
4c63da97 AM |
248 | { |
249 | return aout_symbol (symbol_get_bfdsym (sym))->desc; | |
250 | } | |
251 | ||
5110c57e | 252 | static void |
ea1562b3 | 253 | obj_aout_s_set_desc (symbolS *sym, int d) |
5110c57e HPN |
254 | { |
255 | aout_symbol (symbol_get_bfdsym (sym))->desc = d; | |
256 | } | |
257 | ||
258 | static int | |
ea1562b3 | 259 | obj_aout_s_get_type (symbolS *sym) |
5110c57e HPN |
260 | { |
261 | return aout_symbol (symbol_get_bfdsym (sym))->type; | |
262 | } | |
263 | ||
264 | static void | |
ea1562b3 | 265 | obj_aout_s_set_type (symbolS *sym, int t) |
5110c57e HPN |
266 | { |
267 | aout_symbol (symbol_get_bfdsym (sym))->type = t; | |
268 | } | |
269 | ||
270 | static int | |
ea1562b3 | 271 | obj_aout_separate_stab_sections (void) |
5110c57e HPN |
272 | { |
273 | return 0; | |
274 | } | |
4c63da97 | 275 | |
5110c57e HPN |
276 | /* When changed, make sure these table entries match the single-format |
277 | definitions in obj-aout.h. */ | |
ea1562b3 | 278 | |
4c63da97 AM |
279 | const struct format_ops aout_format_ops = |
280 | { | |
281 | bfd_target_aout_flavour, | |
ea1562b3 NC |
282 | 1, /* dfl_leading_underscore. */ |
283 | 0, /* emit_section_symbols. */ | |
284 | 0, /* begin. */ | |
285 | 0, /* app_file. */ | |
4c63da97 | 286 | obj_aout_frob_symbol, |
ea1562b3 NC |
287 | 0, /* frob_file. */ |
288 | 0, /* frob_file_before_adjust. */ | |
a161fe53 | 289 | obj_aout_frob_file_before_fix, |
ea1562b3 NC |
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. */ | |
4c63da97 | 295 | obj_aout_s_get_other, |
5110c57e | 296 | obj_aout_s_set_other, |
4c63da97 | 297 | obj_aout_s_get_desc, |
5110c57e HPN |
298 | obj_aout_s_set_desc, |
299 | obj_aout_s_get_type, | |
300 | obj_aout_s_set_type, | |
ea1562b3 NC |
301 | 0, /* copy_symbol_attributes. */ |
302 | 0, /* generate_asm_lineno. */ | |
5110c57e HPN |
303 | obj_aout_process_stab, |
304 | obj_aout_separate_stab_sections, | |
ea1562b3 | 305 | 0, /* init_stab_section. */ |
5110c57e | 306 | obj_aout_sec_sym_ok_for_reloc, |
4c63da97 | 307 | aout_pop_insert, |
ea1562b3 NC |
308 | 0, /* ecoff_set_ext. */ |
309 | 0, /* read_begin_hook. */ | |
645ea3ea AM |
310 | 0, /* symbol_new_hook. */ |
311 | 0, /* symbol_clone_hook. */ | |
312 | 0 /* adjust_symtab. */ | |
4c63da97 | 313 | }; |
ea1562b3 NC |
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 | }; |