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