]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* ELF object file format |
49309057 ILT |
2 | Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999 |
3 | Free Software Foundation, Inc. | |
252b5132 RH |
4 | |
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
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 2, | |
10 | or (at your option) any later version. | |
11 | ||
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. | |
16 | ||
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, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | #define OBJ_HEADER "obj-elf.h" | |
23 | #include "as.h" | |
24 | #include "subsegs.h" | |
25 | #include "obstack.h" | |
26 | ||
27 | #ifndef ECOFF_DEBUGGING | |
28 | #define ECOFF_DEBUGGING 0 | |
29 | #else | |
30 | #define NEED_ECOFF_DEBUG | |
31 | #endif | |
32 | ||
33 | #ifdef NEED_ECOFF_DEBUG | |
34 | #include "ecoff.h" | |
35 | #endif | |
36 | ||
37 | #ifdef TC_ALPHA | |
38 | #include "elf/alpha.h" | |
39 | #endif | |
40 | ||
41 | #ifdef TC_MIPS | |
42 | #include "elf/mips.h" | |
43 | #endif | |
44 | ||
45 | #ifdef TC_PPC | |
46 | #include "elf/ppc.h" | |
47 | #endif | |
48 | ||
49 | static bfd_vma elf_s_get_size PARAMS ((symbolS *)); | |
50 | static void elf_s_set_size PARAMS ((symbolS *, bfd_vma)); | |
51 | static bfd_vma elf_s_get_align PARAMS ((symbolS *)); | |
52 | static void elf_s_set_align PARAMS ((symbolS *, bfd_vma)); | |
53 | static void elf_copy_symbol_attributes PARAMS ((symbolS *, symbolS *)); | |
54 | static int elf_sec_sym_ok_for_reloc PARAMS ((asection *)); | |
55 | static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR)); | |
56 | ||
57 | #ifdef NEED_ECOFF_DEBUG | |
58 | static boolean elf_get_extr PARAMS ((asymbol *, EXTR *)); | |
59 | static void elf_set_index PARAMS ((asymbol *, bfd_size_type)); | |
60 | #endif | |
61 | ||
62 | static void obj_elf_line PARAMS ((int)); | |
63 | void obj_elf_version PARAMS ((int)); | |
64 | static void obj_elf_size PARAMS ((int)); | |
65 | static void obj_elf_type PARAMS ((int)); | |
66 | static void obj_elf_ident PARAMS ((int)); | |
67 | static void obj_elf_weak PARAMS ((int)); | |
68 | static void obj_elf_local PARAMS ((int)); | |
69 | static void obj_elf_common PARAMS ((int)); | |
70 | static void obj_elf_symver PARAMS ((int)); | |
71 | static void obj_elf_vtable_inherit PARAMS ((int)); | |
72 | static void obj_elf_vtable_entry PARAMS ((int)); | |
73 | static void obj_elf_data PARAMS ((int)); | |
74 | static void obj_elf_text PARAMS ((int)); | |
75 | static void obj_elf_subsection PARAMS ((int)); | |
76 | ||
77 | static const pseudo_typeS elf_pseudo_table[] = | |
78 | { | |
79 | {"comm", obj_elf_common, 0}, | |
80 | {"ident", obj_elf_ident, 0}, | |
81 | {"local", obj_elf_local, 0}, | |
82 | {"previous", obj_elf_previous, 0}, | |
83 | {"section", obj_elf_section, 0}, | |
84 | {"section.s", obj_elf_section, 0}, | |
85 | {"sect", obj_elf_section, 0}, | |
86 | {"sect.s", obj_elf_section, 0}, | |
87 | {"size", obj_elf_size, 0}, | |
88 | {"type", obj_elf_type, 0}, | |
89 | {"version", obj_elf_version, 0}, | |
90 | {"weak", obj_elf_weak, 0}, | |
91 | ||
92 | /* These are used for stabs-in-elf configurations. */ | |
93 | {"line", obj_elf_line, 0}, | |
94 | ||
95 | /* This is a GNU extension to handle symbol versions. */ | |
96 | {"symver", obj_elf_symver, 0}, | |
97 | ||
98 | /* A GNU extension to change subsection only. */ | |
99 | {"subsection", obj_elf_subsection, 0}, | |
100 | ||
101 | /* These are GNU extensions to aid in garbage collecting C++ vtables. */ | |
102 | {"vtable_inherit", obj_elf_vtable_inherit, 0}, | |
103 | {"vtable_entry", obj_elf_vtable_entry, 0}, | |
104 | ||
105 | /* These are used for dwarf. */ | |
106 | {"2byte", cons, 2}, | |
107 | {"4byte", cons, 4}, | |
108 | {"8byte", cons, 8}, | |
109 | ||
110 | /* We need to trap the section changing calls to handle .previous. */ | |
111 | {"data", obj_elf_data, 0}, | |
112 | {"text", obj_elf_text, 0}, | |
113 | ||
114 | /* End sentinel. */ | |
115 | {NULL}, | |
116 | }; | |
117 | ||
118 | static const pseudo_typeS ecoff_debug_pseudo_table[] = | |
119 | { | |
120 | #ifdef NEED_ECOFF_DEBUG | |
121 | /* COFF style debugging information for ECOFF. .ln is not used; .loc | |
122 | is used instead. */ | |
123 | { "def", ecoff_directive_def, 0 }, | |
124 | { "dim", ecoff_directive_dim, 0 }, | |
125 | { "endef", ecoff_directive_endef, 0 }, | |
126 | { "file", ecoff_directive_file, 0 }, | |
127 | { "scl", ecoff_directive_scl, 0 }, | |
128 | { "tag", ecoff_directive_tag, 0 }, | |
129 | { "val", ecoff_directive_val, 0 }, | |
130 | ||
131 | /* COFF debugging requires pseudo-ops .size and .type, but ELF | |
132 | already has meanings for those. We use .esize and .etype | |
133 | instead. These are only generated by gcc anyhow. */ | |
134 | { "esize", ecoff_directive_size, 0 }, | |
135 | { "etype", ecoff_directive_type, 0 }, | |
136 | ||
137 | /* ECOFF specific debugging information. */ | |
138 | { "begin", ecoff_directive_begin, 0 }, | |
139 | { "bend", ecoff_directive_bend, 0 }, | |
140 | { "end", ecoff_directive_end, 0 }, | |
141 | { "ent", ecoff_directive_ent, 0 }, | |
142 | { "fmask", ecoff_directive_fmask, 0 }, | |
143 | { "frame", ecoff_directive_frame, 0 }, | |
144 | { "loc", ecoff_directive_loc, 0 }, | |
145 | { "mask", ecoff_directive_mask, 0 }, | |
146 | ||
147 | /* Other ECOFF directives. */ | |
148 | { "extern", ecoff_directive_extern, 0 }, | |
149 | ||
150 | /* These are used on Irix. I don't know how to implement them. */ | |
151 | { "alias", s_ignore, 0 }, | |
152 | { "bgnb", s_ignore, 0 }, | |
153 | { "endb", s_ignore, 0 }, | |
154 | { "lab", s_ignore, 0 }, | |
155 | { "noalias", s_ignore, 0 }, | |
156 | { "verstamp", s_ignore, 0 }, | |
157 | { "vreg", s_ignore, 0 }, | |
158 | #endif | |
159 | ||
160 | {NULL} /* end sentinel */ | |
161 | }; | |
162 | ||
163 | #undef NO_RELOC | |
164 | #include "aout/aout64.h" | |
165 | ||
166 | /* This is called when the assembler starts. */ | |
167 | ||
168 | void | |
169 | elf_begin () | |
170 | { | |
171 | /* Add symbols for the known sections to the symbol table. */ | |
172 | symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput, | |
173 | TEXT_SECTION_NAME))); | |
174 | symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput, | |
175 | DATA_SECTION_NAME))); | |
176 | symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput, | |
177 | BSS_SECTION_NAME))); | |
178 | } | |
179 | ||
180 | void | |
181 | elf_pop_insert () | |
182 | { | |
183 | pop_insert (elf_pseudo_table); | |
184 | if (ECOFF_DEBUGGING) | |
185 | pop_insert (ecoff_debug_pseudo_table); | |
186 | } | |
187 | ||
188 | static bfd_vma | |
189 | elf_s_get_size (sym) | |
190 | symbolS *sym; | |
191 | { | |
192 | return S_GET_SIZE (sym); | |
193 | } | |
194 | ||
195 | static void | |
196 | elf_s_set_size (sym, sz) | |
197 | symbolS *sym; | |
198 | bfd_vma sz; | |
199 | { | |
200 | S_SET_SIZE (sym, sz); | |
201 | } | |
202 | ||
203 | static bfd_vma | |
204 | elf_s_get_align (sym) | |
205 | symbolS *sym; | |
206 | { | |
207 | return S_GET_ALIGN (sym); | |
208 | } | |
209 | ||
210 | static void | |
211 | elf_s_set_align (sym, align) | |
212 | symbolS *sym; | |
213 | bfd_vma align; | |
214 | { | |
215 | S_SET_ALIGN (sym, align); | |
216 | } | |
217 | ||
218 | static void | |
219 | elf_copy_symbol_attributes (dest, src) | |
220 | symbolS *dest, *src; | |
221 | { | |
222 | OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src); | |
223 | } | |
224 | ||
225 | static int | |
226 | elf_sec_sym_ok_for_reloc (sec) | |
227 | asection *sec; | |
228 | { | |
229 | return obj_sec_sym_ok_for_reloc (sec); | |
230 | } | |
231 | ||
232 | void | |
233 | elf_file_symbol (s) | |
234 | char *s; | |
235 | { | |
236 | symbolS *sym; | |
237 | ||
238 | sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0); | |
49309057 ILT |
239 | symbol_set_frag (sym, &zero_address_frag); |
240 | symbol_get_bfdsym (sym)->flags |= BSF_FILE; | |
252b5132 RH |
241 | |
242 | if (symbol_rootP != sym) | |
243 | { | |
244 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
245 | symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP); | |
246 | #ifdef DEBUG | |
247 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
248 | #endif | |
249 | } | |
250 | ||
251 | #ifdef NEED_ECOFF_DEBUG | |
252 | ecoff_new_file (s); | |
253 | #endif | |
254 | } | |
255 | ||
256 | static void | |
257 | obj_elf_common (ignore) | |
258 | int ignore; | |
259 | { | |
260 | char *name; | |
261 | char c; | |
262 | char *p; | |
263 | int temp, size; | |
264 | symbolS *symbolP; | |
265 | int have_align; | |
266 | ||
267 | name = input_line_pointer; | |
268 | c = get_symbol_end (); | |
269 | /* just after name is now '\0' */ | |
270 | p = input_line_pointer; | |
271 | *p = c; | |
272 | SKIP_WHITESPACE (); | |
273 | if (*input_line_pointer != ',') | |
274 | { | |
275 | as_bad (_("Expected comma after symbol-name")); | |
276 | ignore_rest_of_line (); | |
277 | return; | |
278 | } | |
279 | input_line_pointer++; /* skip ',' */ | |
280 | if ((temp = get_absolute_expression ()) < 0) | |
281 | { | |
282 | as_bad (_(".COMMon length (%d.) <0! Ignored."), temp); | |
283 | ignore_rest_of_line (); | |
284 | return; | |
285 | } | |
286 | size = temp; | |
287 | *p = 0; | |
288 | symbolP = symbol_find_or_make (name); | |
289 | *p = c; | |
290 | if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) | |
291 | { | |
292 | as_bad (_("Ignoring attempt to re-define symbol")); | |
293 | ignore_rest_of_line (); | |
294 | return; | |
295 | } | |
296 | if (S_GET_VALUE (symbolP) != 0) | |
297 | { | |
298 | if (S_GET_VALUE (symbolP) != size) | |
299 | { | |
300 | as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."), | |
301 | S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size); | |
302 | } | |
303 | } | |
304 | know (symbolP->sy_frag == &zero_address_frag); | |
305 | if (*input_line_pointer != ',') | |
306 | have_align = 0; | |
307 | else | |
308 | { | |
309 | have_align = 1; | |
310 | input_line_pointer++; | |
311 | SKIP_WHITESPACE (); | |
312 | } | |
313 | if (! have_align || *input_line_pointer != '"') | |
314 | { | |
315 | if (! have_align) | |
316 | temp = 0; | |
317 | else | |
318 | { | |
319 | temp = get_absolute_expression (); | |
320 | if (temp < 0) | |
321 | { | |
322 | temp = 0; | |
323 | as_warn (_("Common alignment negative; 0 assumed")); | |
324 | } | |
325 | } | |
49309057 | 326 | if (symbol_get_obj (symbolP)->local) |
252b5132 RH |
327 | { |
328 | segT old_sec; | |
329 | int old_subsec; | |
330 | char *pfrag; | |
331 | int align; | |
332 | ||
333 | /* allocate_bss: */ | |
334 | old_sec = now_seg; | |
335 | old_subsec = now_subseg; | |
336 | if (temp) | |
337 | { | |
338 | /* convert to a power of 2 alignment */ | |
339 | for (align = 0; (temp & 1) == 0; temp >>= 1, ++align); | |
340 | if (temp != 1) | |
341 | { | |
342 | as_bad (_("Common alignment not a power of 2")); | |
343 | ignore_rest_of_line (); | |
344 | return; | |
345 | } | |
346 | } | |
347 | else | |
348 | align = 0; | |
349 | record_alignment (bss_section, align); | |
350 | subseg_set (bss_section, 0); | |
351 | if (align) | |
352 | frag_align (align, 0, 0); | |
353 | if (S_GET_SEGMENT (symbolP) == bss_section) | |
49309057 ILT |
354 | symbol_get_frag (symbolP)->fr_symbol = 0; |
355 | symbol_set_frag (symbolP, frag_now); | |
252b5132 RH |
356 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, |
357 | (offsetT) size, (char *) 0); | |
358 | *pfrag = 0; | |
359 | S_SET_SIZE (symbolP, size); | |
360 | S_SET_SEGMENT (symbolP, bss_section); | |
361 | S_CLEAR_EXTERNAL (symbolP); | |
362 | subseg_set (old_sec, old_subsec); | |
363 | } | |
364 | else | |
365 | { | |
366 | allocate_common: | |
367 | S_SET_VALUE (symbolP, (valueT) size); | |
368 | S_SET_ALIGN (symbolP, temp); | |
369 | S_SET_EXTERNAL (symbolP); | |
370 | S_SET_SEGMENT (symbolP, bfd_com_section_ptr); | |
371 | } | |
372 | } | |
373 | else | |
374 | { | |
375 | input_line_pointer++; | |
376 | /* @@ Some use the dot, some don't. Can we get some consistency?? */ | |
377 | if (*input_line_pointer == '.') | |
378 | input_line_pointer++; | |
379 | /* @@ Some say data, some say bss. */ | |
380 | if (strncmp (input_line_pointer, "bss\"", 4) | |
381 | && strncmp (input_line_pointer, "data\"", 5)) | |
382 | { | |
383 | while (*--input_line_pointer != '"') | |
384 | ; | |
385 | input_line_pointer--; | |
386 | goto bad_common_segment; | |
387 | } | |
388 | while (*input_line_pointer++ != '"') | |
389 | ; | |
390 | goto allocate_common; | |
391 | } | |
392 | ||
49309057 | 393 | symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; |
252b5132 RH |
394 | |
395 | demand_empty_rest_of_line (); | |
396 | return; | |
397 | ||
398 | { | |
399 | bad_common_segment: | |
400 | p = input_line_pointer; | |
401 | while (*p && *p != '\n') | |
402 | p++; | |
403 | c = *p; | |
404 | *p = '\0'; | |
405 | as_bad (_("bad .common segment %s"), input_line_pointer + 1); | |
406 | *p = c; | |
407 | input_line_pointer = p; | |
408 | ignore_rest_of_line (); | |
409 | return; | |
410 | } | |
411 | } | |
412 | ||
413 | static void | |
414 | obj_elf_local (ignore) | |
415 | int ignore; | |
416 | { | |
417 | char *name; | |
418 | int c; | |
419 | symbolS *symbolP; | |
420 | ||
421 | do | |
422 | { | |
423 | name = input_line_pointer; | |
424 | c = get_symbol_end (); | |
425 | symbolP = symbol_find_or_make (name); | |
426 | *input_line_pointer = c; | |
427 | SKIP_WHITESPACE (); | |
428 | S_CLEAR_EXTERNAL (symbolP); | |
49309057 | 429 | symbol_get_obj (symbolP)->local = 1; |
252b5132 RH |
430 | if (c == ',') |
431 | { | |
432 | input_line_pointer++; | |
433 | SKIP_WHITESPACE (); | |
434 | if (*input_line_pointer == '\n') | |
435 | c = '\n'; | |
436 | } | |
437 | } | |
438 | while (c == ','); | |
439 | demand_empty_rest_of_line (); | |
440 | } | |
441 | ||
442 | static void | |
443 | obj_elf_weak (ignore) | |
444 | int ignore; | |
445 | { | |
446 | char *name; | |
447 | int c; | |
448 | symbolS *symbolP; | |
449 | ||
450 | do | |
451 | { | |
452 | name = input_line_pointer; | |
453 | c = get_symbol_end (); | |
454 | symbolP = symbol_find_or_make (name); | |
455 | *input_line_pointer = c; | |
456 | SKIP_WHITESPACE (); | |
457 | S_SET_WEAK (symbolP); | |
49309057 | 458 | symbol_get_obj (symbolP)->local = 1; |
252b5132 RH |
459 | if (c == ',') |
460 | { | |
461 | input_line_pointer++; | |
462 | SKIP_WHITESPACE (); | |
463 | if (*input_line_pointer == '\n') | |
464 | c = '\n'; | |
465 | } | |
466 | } | |
467 | while (c == ','); | |
468 | demand_empty_rest_of_line (); | |
469 | } | |
470 | ||
471 | static segT previous_section; | |
472 | static int previous_subsection; | |
473 | ||
474 | /* Handle the .section pseudo-op. This code supports two different | |
475 | syntaxes. | |
476 | ||
477 | The first is found on Solaris, and looks like | |
478 | .section ".sec1",#alloc,#execinstr,#write | |
479 | Here the names after '#' are the SHF_* flags to turn on for the | |
480 | section. I'm not sure how it determines the SHT_* type (BFD | |
481 | doesn't really give us control over the type, anyhow). | |
482 | ||
483 | The second format is found on UnixWare, and probably most SVR4 | |
484 | machines, and looks like | |
485 | .section .sec1,"a",@progbits | |
486 | The quoted string may contain any combination of a, w, x, and | |
487 | represents the SHF_* flags to turn on for the section. The string | |
488 | beginning with '@' can be progbits or nobits. There should be | |
489 | other possibilities, but I don't know what they are. In any case, | |
490 | BFD doesn't really let us set the section type. */ | |
491 | ||
492 | /* Certain named sections have particular defined types, listed on p. | |
493 | 4-19 of the ABI. */ | |
494 | struct special_section | |
495 | { | |
496 | const char *name; | |
497 | int type; | |
498 | int attributes; | |
499 | }; | |
500 | ||
501 | static struct special_section special_sections[] = | |
502 | { | |
503 | { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, | |
504 | { ".comment", SHT_PROGBITS, 0 }, | |
505 | { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
506 | { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, | |
507 | { ".debug", SHT_PROGBITS, 0 }, | |
508 | { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR }, | |
509 | { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR }, | |
510 | { ".line", SHT_PROGBITS, 0 }, | |
511 | { ".note", SHT_NOTE, 0 }, | |
512 | { ".rodata", SHT_PROGBITS, SHF_ALLOC }, | |
513 | { ".rodata1", SHT_PROGBITS, SHF_ALLOC }, | |
514 | { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR }, | |
515 | ||
516 | #ifdef ELF_TC_SPECIAL_SECTIONS | |
517 | ELF_TC_SPECIAL_SECTIONS | |
518 | #endif | |
519 | ||
520 | #if 0 | |
521 | /* The following section names are special, but they can not | |
522 | reasonably appear in assembler code. Some of the attributes are | |
523 | processor dependent. */ | |
524 | { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ }, | |
525 | { ".dynstr", SHT_STRTAB, SHF_ALLOC }, | |
526 | { ".dynsym", SHT_DYNSYM, SHF_ALLOC }, | |
527 | { ".got", SHT_PROGBITS, 0 }, | |
528 | { ".hash", SHT_HASH, SHF_ALLOC }, | |
529 | { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ }, | |
530 | { ".plt", SHT_PROGBITS, 0 }, | |
531 | { ".shstrtab",SHT_STRTAB, 0 }, | |
532 | { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ }, | |
533 | { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ }, | |
534 | #endif | |
535 | ||
536 | { NULL, 0, 0 } | |
537 | }; | |
538 | ||
539 | void | |
540 | obj_elf_section (xxx) | |
541 | int xxx; | |
542 | { | |
543 | char *string; | |
544 | int new_sec; | |
545 | segT sec; | |
546 | int type, attr; | |
547 | int i; | |
548 | flagword flags; | |
549 | symbolS *secsym; | |
550 | ||
551 | #ifdef md_flush_pending_output | |
552 | md_flush_pending_output (); | |
553 | #endif | |
554 | ||
555 | if (flag_mri) | |
556 | { | |
557 | char mri_type; | |
558 | ||
559 | previous_section = now_seg; | |
560 | previous_subsection = now_subseg; | |
561 | ||
562 | s_mri_sect (&mri_type); | |
563 | ||
564 | #ifdef md_elf_section_change_hook | |
565 | md_elf_section_change_hook (); | |
566 | #endif | |
567 | ||
568 | return; | |
569 | } | |
570 | ||
571 | /* Get name of section. */ | |
572 | SKIP_WHITESPACE (); | |
573 | if (*input_line_pointer == '"') | |
574 | { | |
575 | string = demand_copy_C_string (&xxx); | |
576 | if (string == NULL) | |
577 | { | |
578 | ignore_rest_of_line (); | |
579 | return; | |
580 | } | |
581 | } | |
582 | else | |
583 | { | |
584 | char *p = input_line_pointer; | |
585 | char c; | |
586 | while (0 == strchr ("\n\t,; ", *p)) | |
587 | p++; | |
588 | if (p == input_line_pointer) | |
589 | { | |
590 | as_warn (_("Missing section name")); | |
591 | ignore_rest_of_line (); | |
592 | return; | |
593 | } | |
594 | c = *p; | |
595 | *p = 0; | |
596 | string = xmalloc ((unsigned long) (p - input_line_pointer + 1)); | |
597 | strcpy (string, input_line_pointer); | |
598 | *p = c; | |
599 | input_line_pointer = p; | |
600 | } | |
601 | ||
602 | /* Switch to the section, creating it if necessary. */ | |
603 | previous_section = now_seg; | |
604 | previous_subsection = now_subseg; | |
605 | ||
606 | new_sec = bfd_get_section_by_name (stdoutput, string) == NULL; | |
607 | sec = subseg_new (string, 0); | |
608 | ||
609 | /* If this section already existed, we don't bother to change the | |
610 | flag values. */ | |
611 | if (! new_sec) | |
612 | { | |
613 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
614 | ++input_line_pointer; | |
615 | ++input_line_pointer; | |
616 | ||
617 | #ifdef md_elf_section_change_hook | |
618 | md_elf_section_change_hook (); | |
619 | #endif | |
620 | ||
621 | return; | |
622 | } | |
623 | ||
624 | SKIP_WHITESPACE (); | |
625 | ||
626 | type = SHT_NULL; | |
627 | attr = 0; | |
628 | ||
629 | if (*input_line_pointer == ',') | |
630 | { | |
631 | /* Skip the comma. */ | |
632 | ++input_line_pointer; | |
633 | ||
634 | SKIP_WHITESPACE (); | |
635 | ||
636 | if (*input_line_pointer == '"') | |
637 | { | |
638 | /* Pick up a string with a combination of a, w, x. */ | |
639 | ++input_line_pointer; | |
640 | while (*input_line_pointer != '"') | |
641 | { | |
642 | switch (*input_line_pointer) | |
643 | { | |
644 | case 'a': | |
645 | attr |= SHF_ALLOC; | |
646 | break; | |
647 | case 'w': | |
648 | attr |= SHF_WRITE; | |
649 | break; | |
650 | case 'x': | |
651 | attr |= SHF_EXECINSTR; | |
652 | break; | |
653 | default: | |
654 | { | |
655 | char *bad_msg = _("Bad .section directive: want a,w,x in string"); | |
656 | #ifdef md_elf_section_letter | |
657 | int md_attr = md_elf_section_letter (*input_line_pointer, &bad_msg); | |
658 | if (md_attr) | |
659 | attr |= md_attr; | |
660 | else | |
661 | #endif | |
662 | { | |
663 | as_warn (bad_msg); | |
664 | ignore_rest_of_line (); | |
665 | return; | |
666 | } | |
667 | } | |
668 | } | |
669 | ++input_line_pointer; | |
670 | } | |
671 | ||
672 | /* Skip the closing quote. */ | |
673 | ++input_line_pointer; | |
674 | ||
675 | SKIP_WHITESPACE (); | |
676 | if (*input_line_pointer == ',') | |
677 | { | |
678 | ++input_line_pointer; | |
679 | SKIP_WHITESPACE (); | |
680 | if (*input_line_pointer == '@' || *input_line_pointer == '%') | |
681 | { | |
682 | ++input_line_pointer; | |
683 | if (strncmp (input_line_pointer, "progbits", | |
684 | sizeof "progbits" - 1) == 0) | |
685 | { | |
686 | type = SHT_PROGBITS; | |
687 | input_line_pointer += sizeof "progbits" - 1; | |
688 | } | |
689 | else if (strncmp (input_line_pointer, "nobits", | |
690 | sizeof "nobits" - 1) == 0) | |
691 | { | |
692 | type = SHT_NOBITS; | |
693 | input_line_pointer += sizeof "nobits" - 1; | |
694 | } | |
695 | else | |
696 | { | |
697 | #ifdef md_elf_section_type | |
698 | int md_type = md_elf_section_type (&input_line_pointer); | |
699 | if (md_type) | |
700 | type = md_type; | |
701 | else | |
702 | #endif | |
703 | { | |
704 | as_warn (_("Unrecognized section type")); | |
705 | ignore_rest_of_line (); | |
706 | } | |
707 | } | |
708 | } | |
709 | } | |
710 | } | |
711 | else | |
712 | { | |
713 | do | |
714 | { | |
715 | SKIP_WHITESPACE (); | |
716 | if (*input_line_pointer != '#') | |
717 | { | |
718 | as_warn (_("Bad .section directive - character following name is not '#'")); | |
719 | ignore_rest_of_line (); | |
720 | return; | |
721 | } | |
722 | ++input_line_pointer; | |
723 | if (strncmp (input_line_pointer, "write", | |
724 | sizeof "write" - 1) == 0) | |
725 | { | |
726 | attr |= SHF_WRITE; | |
727 | input_line_pointer += sizeof "write" - 1; | |
728 | } | |
729 | else if (strncmp (input_line_pointer, "alloc", | |
730 | sizeof "alloc" - 1) == 0) | |
731 | { | |
732 | attr |= SHF_ALLOC; | |
733 | input_line_pointer += sizeof "alloc" - 1; | |
734 | } | |
735 | else if (strncmp (input_line_pointer, "execinstr", | |
736 | sizeof "execinstr" - 1) == 0) | |
737 | { | |
738 | attr |= SHF_EXECINSTR; | |
739 | input_line_pointer += sizeof "execinstr" - 1; | |
740 | } | |
741 | else | |
742 | { | |
743 | #ifdef md_elf_section_word | |
744 | int md_attr = md_elf_section_word (&input_line_pointer); | |
745 | if (md_attr) | |
746 | attr |= md_attr; | |
747 | else | |
748 | #endif | |
749 | { | |
750 | as_warn (_("Unrecognized section attribute")); | |
751 | ignore_rest_of_line (); | |
752 | return; | |
753 | } | |
754 | } | |
755 | SKIP_WHITESPACE (); | |
756 | } | |
757 | while (*input_line_pointer++ == ','); | |
758 | --input_line_pointer; | |
759 | } | |
760 | } | |
761 | ||
762 | /* See if this is one of the special sections. */ | |
763 | for (i = 0; special_sections[i].name != NULL; i++) | |
764 | { | |
765 | if (string[1] == special_sections[i].name[1] | |
766 | && strcmp (string, special_sections[i].name) == 0) | |
767 | { | |
768 | if (type == SHT_NULL) | |
769 | type = special_sections[i].type; | |
770 | else if (type != special_sections[i].type) | |
771 | as_warn (_("Setting incorrect section type for %s"), string); | |
772 | ||
773 | if ((attr &~ special_sections[i].attributes) != 0) | |
774 | { | |
775 | /* As a GNU extension, we permit a .note section to be | |
776 | allocatable. If the linker sees an allocateable | |
777 | .note section, it will create a PT_NOTE segment in | |
778 | the output file. */ | |
779 | if (strcmp (string, ".note") != 0 | |
780 | || attr != SHF_ALLOC) | |
781 | as_warn (_("Setting incorrect section attributes for %s"), | |
782 | string); | |
783 | } | |
784 | attr |= special_sections[i].attributes; | |
785 | ||
786 | break; | |
787 | } | |
788 | } | |
789 | ||
790 | flags = (SEC_RELOC | |
791 | | ((attr & SHF_WRITE) ? 0 : SEC_READONLY) | |
792 | | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0) | |
793 | | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0) | |
794 | | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0)); | |
795 | if (special_sections[i].name == NULL) | |
796 | { | |
797 | if (type == SHT_PROGBITS) | |
798 | flags |= SEC_ALLOC | SEC_LOAD; | |
799 | else if (type == SHT_NOBITS) | |
800 | { | |
801 | flags |= SEC_ALLOC; | |
802 | flags &=~ SEC_LOAD; | |
803 | } | |
804 | ||
805 | #ifdef md_elf_section_flags | |
806 | flags = md_elf_section_flags (flags, attr, type); | |
807 | #endif | |
808 | } | |
809 | ||
810 | /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */ | |
811 | if (type == SHT_NOBITS) | |
812 | seg_info (sec)->bss = 1; | |
813 | ||
814 | bfd_set_section_flags (stdoutput, sec, flags); | |
815 | ||
816 | /* Add a symbol for this section to the symbol table. */ | |
817 | secsym = symbol_find (string); | |
818 | if (secsym != NULL) | |
49309057 | 819 | symbol_set_bfdsym (secsym, sec->symbol); |
252b5132 RH |
820 | else |
821 | symbol_table_insert (section_symbol (sec)); | |
822 | ||
823 | #ifdef md_elf_section_change_hook | |
824 | md_elf_section_change_hook (); | |
825 | #endif | |
826 | ||
827 | demand_empty_rest_of_line (); | |
828 | } | |
829 | ||
830 | /* Change to the .data section. */ | |
831 | ||
832 | static void | |
833 | obj_elf_data (i) | |
834 | int i; | |
835 | { | |
836 | #ifdef md_flush_pending_output | |
837 | md_flush_pending_output (); | |
838 | #endif | |
839 | ||
840 | previous_section = now_seg; | |
841 | previous_subsection = now_subseg; | |
842 | s_data (i); | |
843 | ||
844 | #ifdef md_elf_section_change_hook | |
845 | md_elf_section_change_hook (); | |
846 | #endif | |
847 | } | |
848 | ||
849 | /* Change to the .text section. */ | |
850 | ||
851 | static void | |
852 | obj_elf_text (i) | |
853 | int i; | |
854 | { | |
855 | #ifdef md_flush_pending_output | |
856 | md_flush_pending_output (); | |
857 | #endif | |
858 | ||
859 | previous_section = now_seg; | |
860 | previous_subsection = now_subseg; | |
861 | s_text (i); | |
862 | ||
863 | #ifdef md_elf_section_change_hook | |
864 | md_elf_section_change_hook (); | |
865 | #endif | |
866 | } | |
867 | ||
868 | static void | |
869 | obj_elf_subsection (ignore) | |
870 | int ignore; | |
871 | { | |
872 | register int temp; | |
873 | ||
874 | #ifdef md_flush_pending_output | |
875 | md_flush_pending_output (); | |
876 | #endif | |
877 | ||
878 | previous_section = now_seg; | |
879 | previous_subsection = now_subseg; | |
880 | ||
881 | temp = get_absolute_expression (); | |
882 | subseg_set (now_seg, (subsegT) temp); | |
883 | demand_empty_rest_of_line (); | |
884 | ||
885 | #ifdef md_elf_section_change_hook | |
886 | md_elf_section_change_hook (); | |
887 | #endif | |
888 | } | |
889 | ||
890 | /* This can be called from the processor backends if they change | |
891 | sections. */ | |
892 | ||
893 | void | |
894 | obj_elf_section_change_hook () | |
895 | { | |
896 | previous_section = now_seg; | |
897 | previous_subsection = now_subseg; | |
898 | } | |
899 | ||
900 | void | |
901 | obj_elf_previous (ignore) | |
902 | int ignore; | |
903 | { | |
904 | if (previous_section == 0) | |
905 | { | |
906 | as_bad (_(".previous without corresponding .section; ignored")); | |
907 | return; | |
908 | } | |
909 | ||
910 | #ifdef md_flush_pending_output | |
911 | md_flush_pending_output (); | |
912 | #endif | |
913 | ||
914 | subseg_set (previous_section, previous_subsection); | |
915 | previous_section = 0; | |
916 | ||
917 | #ifdef md_elf_section_change_hook | |
918 | md_elf_section_change_hook (); | |
919 | #endif | |
920 | } | |
921 | ||
922 | static void | |
923 | obj_elf_line (ignore) | |
924 | int ignore; | |
925 | { | |
926 | /* Assume delimiter is part of expression. BSD4.2 as fails with | |
927 | delightful bug, so we are not being incompatible here. */ | |
928 | new_logical_line ((char *) NULL, (int) (get_absolute_expression ())); | |
929 | demand_empty_rest_of_line (); | |
930 | } | |
931 | ||
932 | /* This handles the .symver pseudo-op, which is used to specify a | |
933 | symbol version. The syntax is ``.symver NAME,SYMVERNAME''. | |
934 | SYMVERNAME may contain ELF_VER_CHR ('@') characters. This | |
935 | pseudo-op causes the assembler to emit a symbol named SYMVERNAME | |
936 | with the same value as the symbol NAME. */ | |
937 | ||
938 | static void | |
939 | obj_elf_symver (ignore) | |
940 | int ignore; | |
941 | { | |
942 | char *name; | |
943 | char c; | |
944 | symbolS *sym; | |
945 | ||
946 | name = input_line_pointer; | |
947 | c = get_symbol_end (); | |
948 | ||
949 | sym = symbol_find_or_make (name); | |
950 | ||
951 | *input_line_pointer = c; | |
952 | ||
49309057 | 953 | if (symbol_get_obj (sym)->versioned_name != NULL) |
252b5132 RH |
954 | { |
955 | as_bad (_("multiple .symver directives for symbol `%s'"), | |
956 | S_GET_NAME (sym)); | |
957 | ignore_rest_of_line (); | |
958 | return; | |
959 | } | |
960 | ||
961 | SKIP_WHITESPACE (); | |
962 | if (*input_line_pointer != ',') | |
963 | { | |
964 | as_bad (_("expected comma after name in .symver")); | |
965 | ignore_rest_of_line (); | |
966 | return; | |
967 | } | |
968 | ||
969 | ++input_line_pointer; | |
970 | name = input_line_pointer; | |
971 | while (1) | |
972 | { | |
973 | c = get_symbol_end (); | |
974 | if (c != ELF_VER_CHR) | |
975 | break; | |
976 | *input_line_pointer++ = c; | |
977 | } | |
978 | ||
49309057 | 979 | symbol_get_obj (sym)->versioned_name = xstrdup (name); |
252b5132 RH |
980 | |
981 | *input_line_pointer = c; | |
982 | ||
49309057 | 983 | if (strchr (symbol_get_obj (sym)->versioned_name, ELF_VER_CHR) == NULL) |
252b5132 RH |
984 | { |
985 | as_bad (_("missing version name in `%s' for symbol `%s'"), | |
49309057 | 986 | symbol_get_obj (sym)->versioned_name, S_GET_NAME (sym)); |
252b5132 RH |
987 | ignore_rest_of_line (); |
988 | return; | |
989 | } | |
990 | ||
991 | demand_empty_rest_of_line (); | |
992 | } | |
993 | ||
994 | /* This handles the .vtable_inherit pseudo-op, which is used to indicate | |
995 | to the linker the hierarchy in which a particular table resides. The | |
996 | syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */ | |
997 | ||
998 | static void | |
999 | obj_elf_vtable_inherit (ignore) | |
1000 | { | |
1001 | char *cname, *pname; | |
1002 | symbolS *csym, *psym; | |
1003 | char c, bad = 0; | |
1004 | ||
1005 | if (*input_line_pointer == '#') | |
1006 | ++input_line_pointer; | |
1007 | ||
1008 | cname = input_line_pointer; | |
1009 | c = get_symbol_end (); | |
1010 | csym = symbol_find (cname); | |
1011 | ||
1012 | /* GCFIXME: should check that we don't have two .vtable_inherits for | |
1013 | the same child symbol. Also, we can currently only do this if the | |
1014 | child symbol is already exists and is placed in a fragment. */ | |
1015 | ||
49309057 | 1016 | if (csym == NULL || symbol_get_frag (csym) == NULL) |
252b5132 RH |
1017 | { |
1018 | as_bad ("expected `%s' to have already been set for .vtable_inherit", | |
1019 | cname); | |
1020 | bad = 1; | |
1021 | } | |
1022 | ||
1023 | *input_line_pointer = c; | |
1024 | ||
1025 | SKIP_WHITESPACE (); | |
1026 | if (*input_line_pointer != ',') | |
1027 | { | |
1028 | as_bad ("expected comma after name in .vtable_inherit"); | |
1029 | ignore_rest_of_line (); | |
1030 | return; | |
1031 | } | |
1032 | ||
1033 | ++input_line_pointer; | |
1034 | SKIP_WHITESPACE (); | |
1035 | ||
1036 | if (*input_line_pointer == '#') | |
1037 | ++input_line_pointer; | |
1038 | ||
1039 | if (input_line_pointer[0] == '0' | |
1040 | && (input_line_pointer[1] == '\0' | |
d9a62219 | 1041 | || isspace ((unsigned char) input_line_pointer[1]))) |
252b5132 RH |
1042 | { |
1043 | psym = section_symbol (absolute_section); | |
1044 | ++input_line_pointer; | |
1045 | } | |
1046 | else | |
1047 | { | |
1048 | pname = input_line_pointer; | |
1049 | c = get_symbol_end (); | |
1050 | psym = symbol_find_or_make (pname); | |
1051 | *input_line_pointer = c; | |
1052 | } | |
1053 | ||
1054 | demand_empty_rest_of_line (); | |
1055 | ||
1056 | if (bad) | |
1057 | return; | |
1058 | ||
49309057 ILT |
1059 | assert (symbol_get_value_expression (csym)->X_op == O_constant); |
1060 | fix_new (symbol_get_frag (csym), | |
1061 | symbol_get_value_expression (csym)->X_add_number, 0, psym, 0, 0, | |
252b5132 RH |
1062 | BFD_RELOC_VTABLE_INHERIT); |
1063 | } | |
1064 | ||
1065 | /* This handles the .vtable_entry pseudo-op, which is used to indicate | |
1066 | to the linker that a vtable slot was used. The syntax is | |
1067 | ".vtable_entry tablename, offset". */ | |
1068 | ||
1069 | static void | |
1070 | obj_elf_vtable_entry (ignore) | |
1071 | { | |
1072 | char *name; | |
1073 | symbolS *sym; | |
1074 | offsetT offset; | |
1075 | char c; | |
1076 | ||
1077 | if (*input_line_pointer == '#') | |
1078 | ++input_line_pointer; | |
1079 | ||
1080 | name = input_line_pointer; | |
1081 | c = get_symbol_end (); | |
1082 | sym = symbol_find_or_make (name); | |
1083 | *input_line_pointer = c; | |
1084 | ||
1085 | SKIP_WHITESPACE (); | |
1086 | if (*input_line_pointer != ',') | |
1087 | { | |
1088 | as_bad ("expected comma after name in .vtable_entry"); | |
1089 | ignore_rest_of_line (); | |
1090 | return; | |
1091 | } | |
1092 | ||
1093 | ++input_line_pointer; | |
1094 | if (*input_line_pointer == '#') | |
1095 | ++input_line_pointer; | |
1096 | ||
1097 | offset = get_absolute_expression (); | |
1098 | ||
1099 | fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0, | |
1100 | BFD_RELOC_VTABLE_ENTRY); | |
1101 | ||
1102 | demand_empty_rest_of_line (); | |
1103 | } | |
1104 | ||
1105 | void | |
1106 | obj_read_begin_hook () | |
1107 | { | |
1108 | #ifdef NEED_ECOFF_DEBUG | |
1109 | if (ECOFF_DEBUGGING) | |
1110 | ecoff_read_begin_hook (); | |
1111 | #endif | |
1112 | } | |
1113 | ||
1114 | void | |
1115 | obj_symbol_new_hook (symbolP) | |
1116 | symbolS *symbolP; | |
1117 | { | |
49309057 ILT |
1118 | struct elf_obj_sy *sy_obj; |
1119 | ||
1120 | sy_obj = symbol_get_obj (symbolP); | |
1121 | sy_obj->size = NULL; | |
1122 | sy_obj->versioned_name = NULL; | |
252b5132 RH |
1123 | |
1124 | #ifdef NEED_ECOFF_DEBUG | |
1125 | if (ECOFF_DEBUGGING) | |
1126 | ecoff_symbol_new_hook (symbolP); | |
1127 | #endif | |
1128 | } | |
1129 | ||
1130 | void | |
1131 | obj_elf_version (ignore) | |
1132 | int ignore; | |
1133 | { | |
1134 | char *name; | |
1135 | unsigned int c; | |
1136 | char ch; | |
1137 | char *p; | |
1138 | asection *seg = now_seg; | |
1139 | subsegT subseg = now_subseg; | |
1140 | Elf_Internal_Note i_note; | |
1141 | Elf_External_Note e_note; | |
1142 | asection *note_secp = (asection *) NULL; | |
1143 | int i, len; | |
1144 | ||
1145 | SKIP_WHITESPACE (); | |
1146 | if (*input_line_pointer == '\"') | |
1147 | { | |
1148 | ++input_line_pointer; /* -> 1st char of string. */ | |
1149 | name = input_line_pointer; | |
1150 | ||
1151 | while (is_a_char (c = next_char_of_string ())) | |
1152 | ; | |
1153 | c = *input_line_pointer; | |
1154 | *input_line_pointer = '\0'; | |
1155 | *(input_line_pointer - 1) = '\0'; | |
1156 | *input_line_pointer = c; | |
1157 | ||
1158 | /* create the .note section */ | |
1159 | ||
1160 | note_secp = subseg_new (".note", 0); | |
1161 | bfd_set_section_flags (stdoutput, | |
1162 | note_secp, | |
1163 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1164 | ||
1165 | /* process the version string */ | |
1166 | ||
1167 | len = strlen (name); | |
1168 | ||
1169 | i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */ | |
1170 | i_note.descsz = 0; /* no description */ | |
1171 | i_note.type = NT_VERSION; | |
1172 | p = frag_more (sizeof (e_note.namesz)); | |
1173 | md_number_to_chars (p, (valueT) i_note.namesz, 4); | |
1174 | p = frag_more (sizeof (e_note.descsz)); | |
1175 | md_number_to_chars (p, (valueT) i_note.descsz, 4); | |
1176 | p = frag_more (sizeof (e_note.type)); | |
1177 | md_number_to_chars (p, (valueT) i_note.type, 4); | |
1178 | ||
1179 | for (i = 0; i < len; i++) | |
1180 | { | |
1181 | ch = *(name + i); | |
1182 | { | |
1183 | FRAG_APPEND_1_CHAR (ch); | |
1184 | } | |
1185 | } | |
1186 | frag_align (2, 0, 0); | |
1187 | ||
1188 | subseg_set (seg, subseg); | |
1189 | } | |
1190 | else | |
1191 | { | |
1192 | as_bad (_("Expected quoted string")); | |
1193 | } | |
1194 | demand_empty_rest_of_line (); | |
1195 | } | |
1196 | ||
1197 | static void | |
1198 | obj_elf_size (ignore) | |
1199 | int ignore; | |
1200 | { | |
1201 | char *name = input_line_pointer; | |
1202 | char c = get_symbol_end (); | |
1203 | char *p; | |
1204 | expressionS exp; | |
1205 | symbolS *sym; | |
1206 | ||
1207 | p = input_line_pointer; | |
1208 | *p = c; | |
1209 | SKIP_WHITESPACE (); | |
1210 | if (*input_line_pointer != ',') | |
1211 | { | |
1212 | *p = 0; | |
1213 | as_bad (_("expected comma after name `%s' in .size directive"), name); | |
1214 | *p = c; | |
1215 | ignore_rest_of_line (); | |
1216 | return; | |
1217 | } | |
1218 | input_line_pointer++; | |
1219 | expression (&exp); | |
1220 | if (exp.X_op == O_absent) | |
1221 | { | |
1222 | as_bad (_("missing expression in .size directive")); | |
1223 | exp.X_op = O_constant; | |
1224 | exp.X_add_number = 0; | |
1225 | } | |
1226 | *p = 0; | |
1227 | sym = symbol_find_or_make (name); | |
1228 | *p = c; | |
1229 | if (exp.X_op == O_constant) | |
1230 | S_SET_SIZE (sym, exp.X_add_number); | |
1231 | else | |
1232 | { | |
49309057 ILT |
1233 | symbol_get_obj (sym)->size = |
1234 | (expressionS *) xmalloc (sizeof (expressionS)); | |
1235 | *symbol_get_obj (sym)->size = exp; | |
252b5132 RH |
1236 | } |
1237 | demand_empty_rest_of_line (); | |
1238 | } | |
1239 | ||
1240 | /* Handle the ELF .type pseudo-op. This sets the type of a symbol. | |
1241 | There are four syntaxes: | |
1242 | ||
1243 | The first (used on Solaris) is | |
1244 | .type SYM,#function | |
1245 | The second (used on UnixWare) is | |
1246 | .type SYM,@function | |
1247 | The third (reportedly to be used on Irix 6.0) is | |
1248 | .type SYM STT_FUNC | |
1249 | The fourth (used on NetBSD/Arm and Linux/ARM) is | |
1250 | .type SYM,%function | |
1251 | */ | |
1252 | ||
1253 | static void | |
1254 | obj_elf_type (ignore) | |
1255 | int ignore; | |
1256 | { | |
1257 | char *name; | |
1258 | char c; | |
1259 | int type; | |
1260 | const char *typename; | |
1261 | symbolS *sym; | |
1262 | ||
1263 | name = input_line_pointer; | |
1264 | c = get_symbol_end (); | |
1265 | sym = symbol_find_or_make (name); | |
1266 | *input_line_pointer = c; | |
1267 | ||
1268 | SKIP_WHITESPACE (); | |
1269 | if (*input_line_pointer == ',') | |
1270 | ++input_line_pointer; | |
1271 | ||
1272 | SKIP_WHITESPACE (); | |
1273 | if ( *input_line_pointer == '#' | |
1274 | || *input_line_pointer == '@' | |
1275 | || *input_line_pointer == '%') | |
1276 | ++input_line_pointer; | |
1277 | ||
1278 | typename = input_line_pointer; | |
1279 | c = get_symbol_end (); | |
1280 | ||
1281 | type = 0; | |
1282 | if (strcmp (typename, "function") == 0 | |
1283 | || strcmp (typename, "STT_FUNC") == 0) | |
1284 | type = BSF_FUNCTION; | |
1285 | else if (strcmp (typename, "object") == 0 | |
1286 | || strcmp (typename, "STT_OBJECT") == 0) | |
1287 | type = BSF_OBJECT; | |
1288 | else | |
1289 | as_bad (_("ignoring unrecognized symbol type \"%s\""), typename); | |
1290 | ||
1291 | *input_line_pointer = c; | |
1292 | ||
49309057 | 1293 | symbol_get_bfdsym (sym)->flags |= type; |
252b5132 RH |
1294 | |
1295 | demand_empty_rest_of_line (); | |
1296 | } | |
1297 | ||
1298 | static void | |
1299 | obj_elf_ident (ignore) | |
1300 | int ignore; | |
1301 | { | |
1302 | static segT comment_section; | |
1303 | segT old_section = now_seg; | |
1304 | int old_subsection = now_subseg; | |
1305 | ||
1306 | if (!comment_section) | |
1307 | { | |
1308 | char *p; | |
1309 | comment_section = subseg_new (".comment", 0); | |
1310 | bfd_set_section_flags (stdoutput, comment_section, | |
1311 | SEC_READONLY | SEC_HAS_CONTENTS); | |
1312 | p = frag_more (1); | |
1313 | *p = 0; | |
1314 | } | |
1315 | else | |
1316 | subseg_set (comment_section, 0); | |
1317 | stringer (1); | |
1318 | subseg_set (old_section, old_subsection); | |
1319 | } | |
1320 | ||
1321 | #ifdef INIT_STAB_SECTION | |
1322 | ||
1323 | /* The first entry in a .stabs section is special. */ | |
1324 | ||
1325 | void | |
1326 | obj_elf_init_stab_section (seg) | |
1327 | segT seg; | |
1328 | { | |
1329 | char *file; | |
1330 | char *p; | |
1331 | char *stabstr_name; | |
1332 | unsigned int stroff; | |
1333 | ||
1334 | /* Force the section to align to a longword boundary. Without this, | |
1335 | UnixWare ar crashes. */ | |
1336 | bfd_set_section_alignment (stdoutput, seg, 2); | |
1337 | ||
1338 | /* Make space for this first symbol. */ | |
1339 | p = frag_more (12); | |
1340 | /* Zero it out. */ | |
1341 | memset (p, 0, 12); | |
1342 | as_where (&file, (unsigned int *) NULL); | |
1343 | stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4); | |
1344 | strcpy (stabstr_name, segment_name (seg)); | |
1345 | strcat (stabstr_name, "str"); | |
1346 | stroff = get_stab_string_offset (file, stabstr_name); | |
1347 | know (stroff == 1); | |
1348 | md_number_to_chars (p, stroff, 4); | |
1349 | seg_info (seg)->stabu.p = p; | |
1350 | } | |
1351 | ||
1352 | #endif | |
1353 | ||
1354 | /* Fill in the counts in the first entry in a .stabs section. */ | |
1355 | ||
1356 | static void | |
1357 | adjust_stab_sections (abfd, sec, xxx) | |
1358 | bfd *abfd; | |
1359 | asection *sec; | |
1360 | PTR xxx; | |
1361 | { | |
1362 | char *name; | |
1363 | asection *strsec; | |
1364 | char *p; | |
1365 | int strsz, nsyms; | |
1366 | ||
1367 | if (strncmp (".stab", sec->name, 5)) | |
1368 | return; | |
1369 | if (!strcmp ("str", sec->name + strlen (sec->name) - 3)) | |
1370 | return; | |
1371 | ||
1372 | name = (char *) alloca (strlen (sec->name) + 4); | |
1373 | strcpy (name, sec->name); | |
1374 | strcat (name, "str"); | |
1375 | strsec = bfd_get_section_by_name (abfd, name); | |
1376 | if (strsec) | |
1377 | strsz = bfd_section_size (abfd, strsec); | |
1378 | else | |
1379 | strsz = 0; | |
1380 | nsyms = bfd_section_size (abfd, sec) / 12 - 1; | |
1381 | ||
1382 | p = seg_info (sec)->stabu.p; | |
1383 | assert (p != 0); | |
1384 | ||
1385 | bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6); | |
1386 | bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8); | |
1387 | } | |
1388 | ||
1389 | #ifdef NEED_ECOFF_DEBUG | |
1390 | ||
1391 | /* This function is called by the ECOFF code. It is supposed to | |
1392 | record the external symbol information so that the backend can | |
1393 | write it out correctly. The ELF backend doesn't actually handle | |
1394 | this at the moment, so we do it ourselves. We save the information | |
1395 | in the symbol. */ | |
1396 | ||
1397 | void | |
1398 | elf_ecoff_set_ext (sym, ext) | |
1399 | symbolS *sym; | |
1400 | struct ecoff_extr *ext; | |
1401 | { | |
49309057 | 1402 | symbol_get_bfdsym (sym)->udata.p = (PTR) ext; |
252b5132 RH |
1403 | } |
1404 | ||
1405 | /* This function is called by bfd_ecoff_debug_externals. It is | |
1406 | supposed to *EXT to the external symbol information, and return | |
1407 | whether the symbol should be used at all. */ | |
1408 | ||
1409 | static boolean | |
1410 | elf_get_extr (sym, ext) | |
1411 | asymbol *sym; | |
1412 | EXTR *ext; | |
1413 | { | |
1414 | if (sym->udata.p == NULL) | |
1415 | return false; | |
1416 | *ext = *(EXTR *) sym->udata.p; | |
1417 | return true; | |
1418 | } | |
1419 | ||
1420 | /* This function is called by bfd_ecoff_debug_externals. It has | |
1421 | nothing to do for ELF. */ | |
1422 | ||
1423 | /*ARGSUSED*/ | |
1424 | static void | |
1425 | elf_set_index (sym, indx) | |
1426 | asymbol *sym; | |
1427 | bfd_size_type indx; | |
1428 | { | |
1429 | } | |
1430 | ||
1431 | #endif /* NEED_ECOFF_DEBUG */ | |
1432 | ||
1433 | void | |
1434 | elf_frob_symbol (symp, puntp) | |
1435 | symbolS *symp; | |
1436 | int *puntp; | |
1437 | { | |
49309057 ILT |
1438 | struct elf_obj_sy *sy_obj; |
1439 | ||
252b5132 RH |
1440 | #ifdef NEED_ECOFF_DEBUG |
1441 | if (ECOFF_DEBUGGING) | |
1442 | ecoff_frob_symbol (symp); | |
1443 | #endif | |
1444 | ||
49309057 ILT |
1445 | sy_obj = symbol_get_obj (symp); |
1446 | ||
1447 | if (sy_obj->size != NULL) | |
252b5132 | 1448 | { |
49309057 | 1449 | switch (sy_obj->size->X_op) |
252b5132 RH |
1450 | { |
1451 | case O_subtract: | |
1452 | S_SET_SIZE (symp, | |
49309057 ILT |
1453 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1454 | + sy_obj->size->X_add_number | |
1455 | - S_GET_VALUE (sy_obj->size->X_op_symbol))); | |
252b5132 RH |
1456 | break; |
1457 | case O_constant: | |
1458 | S_SET_SIZE (symp, | |
49309057 ILT |
1459 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1460 | + sy_obj->size->X_add_number)); | |
252b5132 RH |
1461 | break; |
1462 | default: | |
1463 | as_bad (_(".size expression too complicated to fix up")); | |
1464 | break; | |
1465 | } | |
49309057 ILT |
1466 | free (sy_obj->size); |
1467 | sy_obj->size = NULL; | |
252b5132 RH |
1468 | } |
1469 | ||
49309057 | 1470 | if (sy_obj->versioned_name != NULL) |
252b5132 RH |
1471 | { |
1472 | /* This symbol was given a new name with the .symver directive. | |
1473 | ||
1474 | If this is an external reference, just rename the symbol to | |
1475 | include the version string. This will make the relocs be | |
1476 | against the correct versioned symbol. | |
1477 | ||
1478 | If this is a definition, add an alias. FIXME: Using an alias | |
1479 | will permit the debugging information to refer to the right | |
1480 | symbol. However, it's not clear whether it is the best | |
1481 | approach. */ | |
1482 | ||
1483 | if (! S_IS_DEFINED (symp)) | |
1484 | { | |
1485 | char *p; | |
1486 | ||
1487 | /* Verify that the name isn't using the @@ syntax--this is | |
1488 | reserved for definitions of the default version to link | |
1489 | against. */ | |
49309057 | 1490 | p = strchr (sy_obj->versioned_name, ELF_VER_CHR); |
252b5132 RH |
1491 | know (p != NULL); |
1492 | if (p[1] == ELF_VER_CHR) | |
1493 | { | |
1494 | as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"), | |
49309057 | 1495 | sy_obj->versioned_name); |
252b5132 RH |
1496 | *puntp = true; |
1497 | } | |
49309057 | 1498 | S_SET_NAME (symp, sy_obj->versioned_name); |
252b5132 RH |
1499 | } |
1500 | else | |
1501 | { | |
1502 | symbolS *symp2; | |
1503 | ||
1504 | /* FIXME: Creating a new symbol here is risky. We're in the | |
1505 | final loop over the symbol table. We can get away with | |
1506 | it only because the symbol goes to the end of the list, | |
1507 | where the loop will still see it. It would probably be | |
1508 | better to do this in obj_frob_file_before_adjust. */ | |
1509 | ||
49309057 | 1510 | symp2 = symbol_find_or_make (sy_obj->versioned_name); |
252b5132 RH |
1511 | |
1512 | /* Now we act as though we saw symp2 = sym. */ | |
1513 | ||
1514 | S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp)); | |
1515 | ||
1516 | /* Subtracting out the frag address here is a hack because | |
1517 | we are in the middle of the final loop. */ | |
49309057 ILT |
1518 | S_SET_VALUE (symp2, |
1519 | (S_GET_VALUE (symp) | |
1520 | - symbol_get_frag (symp)->fr_address)); | |
252b5132 | 1521 | |
49309057 | 1522 | symbol_set_frag (symp2, symbol_get_frag (symp)); |
252b5132 RH |
1523 | |
1524 | /* This will copy over the size information. */ | |
1525 | copy_symbol_attributes (symp2, symp); | |
1526 | ||
1527 | if (S_IS_WEAK (symp)) | |
1528 | S_SET_WEAK (symp2); | |
1529 | ||
1530 | if (S_IS_EXTERNAL (symp)) | |
1531 | S_SET_EXTERNAL (symp2); | |
1532 | } | |
1533 | } | |
1534 | ||
1535 | /* Double check weak symbols. */ | |
49309057 | 1536 | if (S_IS_WEAK (symp)) |
252b5132 RH |
1537 | { |
1538 | if (S_IS_COMMON (symp)) | |
1539 | as_bad (_("Symbol `%s' can not be both weak and common"), | |
1540 | S_GET_NAME (symp)); | |
1541 | } | |
1542 | ||
1543 | #ifdef TC_MIPS | |
1544 | /* The Irix 5 and 6 assemblers set the type of any common symbol and | |
1545 | any undefined non-function symbol to STT_OBJECT. We try to be | |
1546 | compatible, since newer Irix 5 and 6 linkers care. However, we | |
1547 | only set undefined symbols to be STT_OBJECT if we are on Irix, | |
1548 | because that is the only time gcc will generate the necessary | |
1549 | .global directives to mark functions. */ | |
1550 | ||
1551 | if (S_IS_COMMON (symp)) | |
49309057 | 1552 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1553 | |
1554 | if (strstr (TARGET_OS, "irix") != NULL | |
49309057 ILT |
1555 | && ! S_IS_DEFINED (symp) |
1556 | && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0) | |
1557 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; | |
252b5132 RH |
1558 | #endif |
1559 | ||
1560 | #ifdef TC_PPC | |
1561 | /* Frob the PowerPC, so that the symbol always has object type | |
1562 | if it is not some other type. VxWorks needs this. */ | |
49309057 ILT |
1563 | if ((symbol_get_bfdsym (symp)->flags |
1564 | & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0 | |
252b5132 | 1565 | && S_IS_DEFINED (symp)) |
49309057 | 1566 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1567 | #endif |
1568 | } | |
1569 | ||
1570 | void | |
1571 | elf_frob_file () | |
1572 | { | |
1573 | bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0); | |
1574 | ||
1575 | #ifdef elf_tc_final_processing | |
1576 | elf_tc_final_processing (); | |
1577 | #endif | |
1578 | } | |
1579 | ||
1580 | /* It is required that we let write_relocs have the opportunity to | |
1581 | optimize away fixups before output has begun, since it is possible | |
1582 | to eliminate all fixups for a section and thus we never should | |
1583 | have generated the relocation section. */ | |
1584 | ||
1585 | void | |
1586 | elf_frob_file_after_relocs () | |
1587 | { | |
1588 | #ifdef NEED_ECOFF_DEBUG | |
1589 | if (ECOFF_DEBUGGING) | |
1590 | /* Generate the ECOFF debugging information. */ | |
1591 | { | |
1592 | const struct ecoff_debug_swap *debug_swap; | |
1593 | struct ecoff_debug_info debug; | |
1594 | char *buf; | |
1595 | asection *sec; | |
1596 | ||
1597 | debug_swap | |
1598 | = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap; | |
1599 | know (debug_swap != (const struct ecoff_debug_swap *) NULL); | |
1600 | ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap); | |
1601 | ||
1602 | /* Set up the pointers in debug. */ | |
1603 | #define SET(ptr, offset, type) \ | |
1604 | debug.ptr = (type) (buf + debug.symbolic_header.offset) | |
1605 | ||
1606 | SET (line, cbLineOffset, unsigned char *); | |
1607 | SET (external_dnr, cbDnOffset, PTR); | |
1608 | SET (external_pdr, cbPdOffset, PTR); | |
1609 | SET (external_sym, cbSymOffset, PTR); | |
1610 | SET (external_opt, cbOptOffset, PTR); | |
1611 | SET (external_aux, cbAuxOffset, union aux_ext *); | |
1612 | SET (ss, cbSsOffset, char *); | |
1613 | SET (external_fdr, cbFdOffset, PTR); | |
1614 | SET (external_rfd, cbRfdOffset, PTR); | |
1615 | /* ssext and external_ext are set up just below. */ | |
1616 | ||
1617 | #undef SET | |
1618 | ||
1619 | /* Set up the external symbols. */ | |
1620 | debug.ssext = debug.ssext_end = NULL; | |
1621 | debug.external_ext = debug.external_ext_end = NULL; | |
1622 | if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true, | |
1623 | elf_get_extr, elf_set_index)) | |
1624 | as_fatal (_("Failed to set up debugging information: %s"), | |
1625 | bfd_errmsg (bfd_get_error ())); | |
1626 | ||
1627 | sec = bfd_get_section_by_name (stdoutput, ".mdebug"); | |
1628 | assert (sec != NULL); | |
1629 | ||
1630 | know (stdoutput->output_has_begun == false); | |
1631 | ||
1632 | /* We set the size of the section, call bfd_set_section_contents | |
1633 | to force the ELF backend to allocate a file position, and then | |
1634 | write out the data. FIXME: Is this really the best way to do | |
1635 | this? */ | |
1636 | sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap); | |
1637 | ||
1638 | if (! bfd_set_section_contents (stdoutput, sec, (PTR) NULL, | |
1639 | (file_ptr) 0, (bfd_size_type) 0)) | |
1640 | as_fatal (_("Can't start writing .mdebug section: %s"), | |
1641 | bfd_errmsg (bfd_get_error ())); | |
1642 | ||
1643 | know (stdoutput->output_has_begun == true); | |
1644 | know (sec->filepos != 0); | |
1645 | ||
1646 | if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap, | |
1647 | sec->filepos)) | |
1648 | as_fatal (_("Could not write .mdebug section: %s"), | |
1649 | bfd_errmsg (bfd_get_error ())); | |
1650 | } | |
1651 | #endif /* NEED_ECOFF_DEBUG */ | |
1652 | } | |
1653 | ||
1654 | #ifdef SCO_ELF | |
1655 | ||
1656 | /* Heavily plagarized from obj_elf_version. The idea is to emit the | |
1657 | SCO specific identifier in the .notes section to satisfy the SCO | |
1658 | linker. | |
1659 | ||
1660 | This looks more complicated than it really is. As opposed to the | |
1661 | "obvious" solution, this should handle the cross dev cases | |
1662 | correctly. (i.e, hosting on a 64 bit big endian processor, but | |
1663 | generating SCO Elf code) Efficiency isn't a concern, as there | |
1664 | should be exactly one of these sections per object module. | |
1665 | ||
1666 | SCO OpenServer 5 identifies it's ELF modules with a standard ELF | |
1667 | .note section. | |
1668 | ||
1669 | int_32 namesz = 4 ; Name size | |
1670 | int_32 descsz = 12 ; Descriptive information | |
1671 | int_32 type = 1 ; | |
1672 | char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL | |
1673 | int_32 version = (major ver # << 16) | version of tools ; | |
1674 | int_32 source = (tool_id << 16 ) | 1 ; | |
1675 | int_32 info = 0 ; These are set by the SCO tools, but we | |
1676 | don't know enough about the source | |
1677 | environment to set them. SCO ld currently | |
1678 | ignores them, and recommends we set them | |
1679 | to zero. */ | |
1680 | ||
1681 | #define SCO_MAJOR_VERSION 0x1 | |
1682 | #define SCO_MINOR_VERSION 0x1 | |
1683 | ||
1684 | void | |
1685 | sco_id () | |
1686 | { | |
1687 | ||
1688 | char *name; | |
1689 | unsigned int c; | |
1690 | char ch; | |
1691 | char *p; | |
1692 | asection *seg = now_seg; | |
1693 | subsegT subseg = now_subseg; | |
1694 | Elf_Internal_Note i_note; | |
1695 | Elf_External_Note e_note; | |
1696 | asection *note_secp = (asection *) NULL; | |
1697 | int i, len; | |
1698 | ||
1699 | /* create the .note section */ | |
1700 | ||
1701 | note_secp = subseg_new (".note", 0); | |
1702 | bfd_set_section_flags (stdoutput, | |
1703 | note_secp, | |
1704 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1705 | ||
1706 | /* process the version string */ | |
1707 | ||
1708 | i_note.namesz = 4; | |
1709 | i_note.descsz = 12; /* 12 descriptive bytes */ | |
1710 | i_note.type = NT_VERSION; /* Contains a version string */ | |
1711 | ||
1712 | p = frag_more (sizeof (i_note.namesz)); | |
1713 | md_number_to_chars (p, (valueT) i_note.namesz, 4); | |
1714 | ||
1715 | p = frag_more (sizeof (i_note.descsz)); | |
1716 | md_number_to_chars (p, (valueT) i_note.descsz, 4); | |
1717 | ||
1718 | p = frag_more (sizeof (i_note.type)); | |
1719 | md_number_to_chars (p, (valueT) i_note.type, 4); | |
1720 | ||
1721 | p = frag_more (4); | |
1722 | strcpy (p, "SCO"); | |
1723 | ||
1724 | /* Note: this is the version number of the ELF we're representing */ | |
1725 | p = frag_more (4); | |
1726 | md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4); | |
1727 | ||
1728 | /* Here, we pick a magic number for ourselves (yes, I "registered" | |
1729 | it with SCO. The bottom bit shows that we are compat with the | |
1730 | SCO ABI. */ | |
1731 | p = frag_more (4); | |
1732 | md_number_to_chars (p, 0x4c520000 | 0x0001, 4); | |
1733 | ||
1734 | /* If we knew (or cared) what the source language options were, we'd | |
1735 | fill them in here. SCO has given us permission to ignore these | |
1736 | and just set them to zero. */ | |
1737 | p = frag_more (4); | |
1738 | md_number_to_chars (p, 0x0000, 4); | |
1739 | ||
1740 | frag_align (2, 0, 0); | |
1741 | ||
1742 | /* We probably can't restore the current segment, for there likely | |
1743 | isn't one yet... */ | |
1744 | if (seg && subseg) | |
1745 | subseg_set (seg, subseg); | |
1746 | ||
1747 | } | |
1748 | ||
1749 | #endif /* SCO_ELF */ | |
1750 | ||
1751 | const struct format_ops elf_format_ops = | |
1752 | { | |
1753 | bfd_target_elf_flavour, | |
1754 | 0, | |
1755 | 1, | |
1756 | elf_frob_symbol, | |
1757 | elf_frob_file, | |
1758 | elf_frob_file_after_relocs, | |
1759 | elf_s_get_size, elf_s_set_size, | |
1760 | elf_s_get_align, elf_s_set_align, | |
1761 | elf_copy_symbol_attributes, | |
1762 | #ifdef NEED_ECOFF_DEBUG | |
1763 | ecoff_generate_asm_lineno, | |
1764 | ecoff_stab, | |
1765 | #else | |
1766 | 0, | |
1767 | 0, /* process_stab */ | |
1768 | #endif | |
1769 | elf_sec_sym_ok_for_reloc, | |
1770 | elf_pop_insert, | |
1771 | #ifdef NEED_ECOFF_DEBUG | |
1772 | elf_ecoff_set_ext, | |
1773 | #else | |
1774 | 0, | |
1775 | #endif | |
1776 | obj_read_begin_hook, | |
1777 | obj_symbol_new_hook, | |
1778 | }; |