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