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