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