]>
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 | { |
252b5132 RH |
620 | int new_sec; |
621 | segT sec; | |
252b5132 RH |
622 | |
623 | #ifdef md_flush_pending_output | |
624 | md_flush_pending_output (); | |
625 | #endif | |
626 | ||
9de8d8f1 RH |
627 | /* Switch to the section, creating it if necessary. */ |
628 | if (push) | |
629 | { | |
630 | struct section_stack *elt; | |
631 | elt = xmalloc (sizeof (struct section_stack)); | |
632 | elt->next = section_stack; | |
633 | elt->seg = now_seg; | |
634 | elt->prev_seg = previous_section; | |
635 | elt->subseg = now_subseg; | |
636 | elt->prev_subseg = previous_subsection; | |
637 | section_stack = elt; | |
638 | } | |
639 | previous_section = now_seg; | |
640 | previous_subsection = now_subseg; | |
641 | ||
642 | new_sec = bfd_get_section_by_name (stdoutput, name) == NULL; | |
643 | sec = subseg_new (name, 0); | |
644 | ||
645 | if (new_sec) | |
646 | { | |
647 | flagword flags; | |
648 | symbolS *secsym; | |
649 | int i; | |
650 | ||
651 | /* See if this is one of the special sections. */ | |
652 | for (i = 0; special_sections[i].name != NULL; i++) | |
653 | if (strcmp (name, special_sections[i].name) == 0) | |
654 | { | |
655 | if (type == SHT_NULL) | |
656 | type = special_sections[i].type; | |
657 | else if (type != special_sections[i].type) | |
658 | as_warn (_("Setting incorrect section type for %s"), name); | |
659 | ||
660 | if ((attr &~ special_sections[i].attributes) != 0) | |
661 | { | |
662 | /* As a GNU extension, we permit a .note section to be | |
663 | allocatable. If the linker sees an allocateable .note | |
664 | section, it will create a PT_NOTE segment in the output | |
665 | file. */ | |
666 | if (strcmp (name, ".note") != 0 | |
667 | || attr != SHF_ALLOC) | |
668 | as_warn (_("Setting incorrect section attributes for %s"), | |
669 | name); | |
670 | } | |
671 | attr |= special_sections[i].attributes; | |
672 | break; | |
673 | } | |
674 | ||
675 | /* Convert ELF type and flags to BFD flags. */ | |
676 | flags = (SEC_RELOC | |
677 | | ((attr & SHF_WRITE) ? 0 : SEC_READONLY) | |
678 | | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0) | |
679 | | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0) | |
680 | | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0)); | |
681 | #ifdef md_elf_section_flags | |
682 | flags = md_elf_section_flags (flags, attr, type); | |
683 | #endif | |
684 | ||
685 | /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */ | |
686 | if (type == SHT_NOBITS) | |
687 | seg_info (sec)->bss = 1; | |
688 | ||
689 | bfd_set_section_flags (stdoutput, sec, flags); | |
690 | ||
691 | /* Add a symbol for this section to the symbol table. */ | |
692 | secsym = symbol_find (name); | |
693 | if (secsym != NULL) | |
694 | symbol_set_bfdsym (secsym, sec->symbol); | |
695 | else | |
696 | symbol_table_insert (section_symbol (sec)); | |
697 | } | |
698 | ||
699 | #ifdef md_elf_section_change_hook | |
700 | md_elf_section_change_hook (); | |
701 | #endif | |
702 | } | |
703 | ||
704 | int | |
705 | obj_elf_parse_section_letters (str, len) | |
706 | char *str; | |
707 | size_t len; | |
708 | { | |
709 | int attr = 0; | |
710 | ||
711 | while (len > 0) | |
712 | { | |
713 | switch (*str) | |
714 | { | |
715 | case 'a': | |
716 | attr |= SHF_ALLOC; | |
717 | break; | |
718 | case 'w': | |
719 | attr |= SHF_WRITE; | |
720 | break; | |
721 | case 'x': | |
722 | attr |= SHF_EXECINSTR; | |
723 | break; | |
724 | default: | |
725 | { | |
726 | char *bad_msg = _("Unrecognized .section attribute: want a,w,x"); | |
727 | #ifdef md_elf_section_letter | |
728 | int md_attr = md_elf_section_letter (*str, &bad_msg); | |
729 | if (md_attr >= 0) | |
730 | attr |= md_attr; | |
731 | else | |
732 | #endif | |
733 | { | |
4c63da97 | 734 | as_warn ("%s", bad_msg); |
9de8d8f1 RH |
735 | attr = -1; |
736 | } | |
737 | } | |
738 | break; | |
739 | } | |
740 | str++, len--; | |
741 | } | |
742 | ||
743 | return attr; | |
744 | } | |
745 | ||
746 | int | |
747 | obj_elf_section_word (str, len) | |
748 | char *str; | |
749 | size_t len; | |
750 | { | |
751 | if (len == 5 && strncmp (str, "write", 5) == 0) | |
752 | return SHF_WRITE; | |
753 | if (len == 5 && strncmp (str, "alloc", 5) == 0) | |
754 | return SHF_ALLOC; | |
755 | if (len == 9 && strncmp (str, "execinstr", 9) == 0) | |
756 | return SHF_EXECINSTR; | |
757 | ||
758 | #ifdef md_elf_section_word | |
759 | { | |
760 | int md_attr = md_elf_section_word (str, len); | |
761 | if (md_attr >= 0) | |
762 | return md_attr; | |
763 | } | |
764 | #endif | |
765 | ||
766 | as_warn (_("Unrecognized section attribute")); | |
767 | return 0; | |
768 | } | |
769 | ||
770 | int | |
771 | obj_elf_section_type (str, len) | |
772 | char *str; | |
773 | size_t len; | |
774 | { | |
775 | if (len == 8 && strncmp (str, "progbits", 8) == 0) | |
776 | return SHT_PROGBITS; | |
777 | if (len == 6 && strncmp (str, "nobits", 6) == 0) | |
778 | return SHT_NOBITS; | |
779 | ||
780 | #ifdef md_elf_section_type | |
781 | { | |
782 | int md_type = md_elf_section_type (str, len); | |
783 | if (md_type >= 0) | |
784 | return md_type; | |
785 | } | |
786 | #endif | |
787 | ||
788 | as_warn (_("Unrecognized section type")); | |
789 | return 0; | |
790 | } | |
791 | ||
792 | void | |
793 | obj_elf_section (push) | |
794 | int push; | |
795 | { | |
796 | char *name, *beg, *end; | |
797 | int type, attr, dummy; | |
798 | ||
5b93d8bb | 799 | #ifndef TC_I370 |
252b5132 RH |
800 | if (flag_mri) |
801 | { | |
802 | char mri_type; | |
803 | ||
9de8d8f1 RH |
804 | #ifdef md_flush_pending_output |
805 | md_flush_pending_output (); | |
806 | #endif | |
807 | ||
252b5132 RH |
808 | previous_section = now_seg; |
809 | previous_subsection = now_subseg; | |
810 | ||
811 | s_mri_sect (&mri_type); | |
812 | ||
813 | #ifdef md_elf_section_change_hook | |
814 | md_elf_section_change_hook (); | |
815 | #endif | |
816 | ||
817 | return; | |
818 | } | |
5b93d8bb | 819 | #endif /* ! defined (TC_I370) */ |
252b5132 RH |
820 | |
821 | /* Get name of section. */ | |
822 | SKIP_WHITESPACE (); | |
823 | if (*input_line_pointer == '"') | |
824 | { | |
9de8d8f1 RH |
825 | name = demand_copy_C_string (&dummy); |
826 | if (name == NULL) | |
252b5132 RH |
827 | { |
828 | ignore_rest_of_line (); | |
829 | return; | |
830 | } | |
831 | } | |
832 | else | |
833 | { | |
9de8d8f1 RH |
834 | end = input_line_pointer; |
835 | while (0 == strchr ("\n\t,; ", *end)) | |
836 | end++; | |
837 | if (end == input_line_pointer) | |
252b5132 RH |
838 | { |
839 | as_warn (_("Missing section name")); | |
840 | ignore_rest_of_line (); | |
841 | return; | |
842 | } | |
fa306131 | 843 | |
9de8d8f1 RH |
844 | name = xmalloc (end - input_line_pointer + 1); |
845 | memcpy (name, input_line_pointer, end - input_line_pointer); | |
846 | name[end - input_line_pointer] = '\0'; | |
847 | input_line_pointer = end; | |
252b5132 | 848 | } |
252b5132 RH |
849 | SKIP_WHITESPACE (); |
850 | ||
851 | type = SHT_NULL; | |
852 | attr = 0; | |
853 | ||
854 | if (*input_line_pointer == ',') | |
855 | { | |
856 | /* Skip the comma. */ | |
857 | ++input_line_pointer; | |
252b5132 RH |
858 | SKIP_WHITESPACE (); |
859 | ||
860 | if (*input_line_pointer == '"') | |
861 | { | |
9de8d8f1 RH |
862 | beg = demand_copy_C_string (&dummy); |
863 | if (beg == NULL) | |
252b5132 | 864 | { |
9de8d8f1 RH |
865 | ignore_rest_of_line (); |
866 | return; | |
252b5132 | 867 | } |
9de8d8f1 | 868 | attr |= obj_elf_parse_section_letters (beg, strlen (beg)); |
252b5132 RH |
869 | |
870 | SKIP_WHITESPACE (); | |
871 | if (*input_line_pointer == ',') | |
872 | { | |
9de8d8f1 | 873 | char c; |
252b5132 RH |
874 | ++input_line_pointer; |
875 | SKIP_WHITESPACE (); | |
9de8d8f1 RH |
876 | c = *input_line_pointer; |
877 | if (c == '"') | |
252b5132 | 878 | { |
9de8d8f1 RH |
879 | beg = demand_copy_C_string (&dummy); |
880 | if (beg == NULL) | |
252b5132 | 881 | { |
9de8d8f1 RH |
882 | ignore_rest_of_line (); |
883 | return; | |
252b5132 | 884 | } |
9de8d8f1 | 885 | type = obj_elf_section_type (beg, strlen (beg)); |
9de8d8f1 RH |
886 | } |
887 | else if (c == '@' || c == '%') | |
888 | { | |
889 | beg = ++input_line_pointer; | |
890 | c = get_symbol_end (); | |
891 | *input_line_pointer = c; | |
892 | type = obj_elf_section_type (beg, input_line_pointer - beg); | |
252b5132 RH |
893 | } |
894 | } | |
895 | } | |
896 | else | |
897 | { | |
898 | do | |
899 | { | |
9de8d8f1 RH |
900 | char c; |
901 | ||
252b5132 RH |
902 | SKIP_WHITESPACE (); |
903 | if (*input_line_pointer != '#') | |
904 | { | |
905 | as_warn (_("Bad .section directive - character following name is not '#'")); | |
906 | ignore_rest_of_line (); | |
907 | return; | |
908 | } | |
9de8d8f1 RH |
909 | beg = ++input_line_pointer; |
910 | c = get_symbol_end (); | |
911 | *input_line_pointer = c; | |
912 | ||
913 | attr |= obj_elf_section_word (beg, input_line_pointer - beg); | |
914 | ||
252b5132 RH |
915 | SKIP_WHITESPACE (); |
916 | } | |
917 | while (*input_line_pointer++ == ','); | |
918 | --input_line_pointer; | |
919 | } | |
920 | } | |
921 | ||
252b5132 | 922 | demand_empty_rest_of_line (); |
9de8d8f1 RH |
923 | |
924 | obj_elf_change_section (name, type, attr, push); | |
252b5132 RH |
925 | } |
926 | ||
927 | /* Change to the .data section. */ | |
928 | ||
16b93d88 | 929 | void |
252b5132 RH |
930 | obj_elf_data (i) |
931 | int i; | |
932 | { | |
933 | #ifdef md_flush_pending_output | |
934 | md_flush_pending_output (); | |
935 | #endif | |
936 | ||
937 | previous_section = now_seg; | |
938 | previous_subsection = now_subseg; | |
939 | s_data (i); | |
940 | ||
941 | #ifdef md_elf_section_change_hook | |
942 | md_elf_section_change_hook (); | |
943 | #endif | |
944 | } | |
945 | ||
946 | /* Change to the .text section. */ | |
947 | ||
16b93d88 | 948 | void |
252b5132 RH |
949 | obj_elf_text (i) |
950 | int i; | |
951 | { | |
952 | #ifdef md_flush_pending_output | |
953 | md_flush_pending_output (); | |
954 | #endif | |
955 | ||
956 | previous_section = now_seg; | |
957 | previous_subsection = now_subseg; | |
958 | s_text (i); | |
959 | ||
960 | #ifdef md_elf_section_change_hook | |
961 | md_elf_section_change_hook (); | |
962 | #endif | |
963 | } | |
964 | ||
965 | static void | |
966 | obj_elf_subsection (ignore) | |
ab9da554 | 967 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
968 | { |
969 | register int temp; | |
970 | ||
971 | #ifdef md_flush_pending_output | |
972 | md_flush_pending_output (); | |
973 | #endif | |
974 | ||
975 | previous_section = now_seg; | |
976 | previous_subsection = now_subseg; | |
977 | ||
978 | temp = get_absolute_expression (); | |
979 | subseg_set (now_seg, (subsegT) temp); | |
980 | demand_empty_rest_of_line (); | |
981 | ||
982 | #ifdef md_elf_section_change_hook | |
983 | md_elf_section_change_hook (); | |
984 | #endif | |
985 | } | |
986 | ||
987 | /* This can be called from the processor backends if they change | |
988 | sections. */ | |
989 | ||
990 | void | |
991 | obj_elf_section_change_hook () | |
992 | { | |
993 | previous_section = now_seg; | |
994 | previous_subsection = now_subseg; | |
995 | } | |
996 | ||
997 | void | |
998 | obj_elf_previous (ignore) | |
ab9da554 | 999 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 1000 | { |
9de8d8f1 RH |
1001 | segT new_section; |
1002 | int new_subsection; | |
1003 | ||
252b5132 RH |
1004 | if (previous_section == 0) |
1005 | { | |
1006 | as_bad (_(".previous without corresponding .section; ignored")); | |
1007 | return; | |
1008 | } | |
1009 | ||
1010 | #ifdef md_flush_pending_output | |
1011 | md_flush_pending_output (); | |
1012 | #endif | |
1013 | ||
9de8d8f1 RH |
1014 | new_section = previous_section; |
1015 | new_subsection = previous_subsection; | |
1016 | previous_section = now_seg; | |
1017 | previous_subsection = now_subseg; | |
1018 | subseg_set (new_section, new_subsection); | |
1019 | ||
1020 | #ifdef md_elf_section_change_hook | |
1021 | md_elf_section_change_hook (); | |
1022 | #endif | |
1023 | } | |
1024 | ||
1025 | static void | |
1026 | obj_elf_popsection (xxx) | |
ab9da554 | 1027 | int xxx ATTRIBUTE_UNUSED; |
9de8d8f1 RH |
1028 | { |
1029 | struct section_stack *top = section_stack; | |
1030 | ||
1031 | if (top == NULL) | |
1032 | { | |
1033 | as_bad (_(".popsection without corresponding .pushsection; ignored")); | |
1034 | return; | |
1035 | } | |
1036 | ||
1037 | #ifdef md_flush_pending_output | |
1038 | md_flush_pending_output (); | |
1039 | #endif | |
1040 | ||
1041 | section_stack = top->next; | |
1042 | previous_section = top->prev_seg; | |
1043 | previous_subsection = top->prev_subseg; | |
1044 | subseg_set (top->seg, top->subseg); | |
1045 | free (top); | |
252b5132 RH |
1046 | |
1047 | #ifdef md_elf_section_change_hook | |
1048 | md_elf_section_change_hook (); | |
1049 | #endif | |
1050 | } | |
1051 | ||
1052 | static void | |
1053 | obj_elf_line (ignore) | |
ab9da554 | 1054 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1055 | { |
1056 | /* Assume delimiter is part of expression. BSD4.2 as fails with | |
1057 | delightful bug, so we are not being incompatible here. */ | |
1058 | new_logical_line ((char *) NULL, (int) (get_absolute_expression ())); | |
1059 | demand_empty_rest_of_line (); | |
1060 | } | |
1061 | ||
1062 | /* This handles the .symver pseudo-op, which is used to specify a | |
1063 | symbol version. The syntax is ``.symver NAME,SYMVERNAME''. | |
1064 | SYMVERNAME may contain ELF_VER_CHR ('@') characters. This | |
1065 | pseudo-op causes the assembler to emit a symbol named SYMVERNAME | |
1066 | with the same value as the symbol NAME. */ | |
1067 | ||
1068 | static void | |
1069 | obj_elf_symver (ignore) | |
ab9da554 | 1070 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1071 | { |
1072 | char *name; | |
1073 | char c; | |
1074 | symbolS *sym; | |
1075 | ||
1076 | name = input_line_pointer; | |
1077 | c = get_symbol_end (); | |
1078 | ||
1079 | sym = symbol_find_or_make (name); | |
1080 | ||
1081 | *input_line_pointer = c; | |
1082 | ||
49309057 | 1083 | if (symbol_get_obj (sym)->versioned_name != NULL) |
252b5132 RH |
1084 | { |
1085 | as_bad (_("multiple .symver directives for symbol `%s'"), | |
1086 | S_GET_NAME (sym)); | |
1087 | ignore_rest_of_line (); | |
1088 | return; | |
1089 | } | |
1090 | ||
1091 | SKIP_WHITESPACE (); | |
1092 | if (*input_line_pointer != ',') | |
1093 | { | |
1094 | as_bad (_("expected comma after name in .symver")); | |
1095 | ignore_rest_of_line (); | |
1096 | return; | |
1097 | } | |
1098 | ||
1099 | ++input_line_pointer; | |
1100 | name = input_line_pointer; | |
1101 | while (1) | |
1102 | { | |
1103 | c = get_symbol_end (); | |
1104 | if (c != ELF_VER_CHR) | |
1105 | break; | |
1106 | *input_line_pointer++ = c; | |
1107 | } | |
1108 | ||
49309057 | 1109 | symbol_get_obj (sym)->versioned_name = xstrdup (name); |
252b5132 RH |
1110 | |
1111 | *input_line_pointer = c; | |
1112 | ||
49309057 | 1113 | if (strchr (symbol_get_obj (sym)->versioned_name, ELF_VER_CHR) == NULL) |
252b5132 RH |
1114 | { |
1115 | as_bad (_("missing version name in `%s' for symbol `%s'"), | |
49309057 | 1116 | symbol_get_obj (sym)->versioned_name, S_GET_NAME (sym)); |
252b5132 RH |
1117 | ignore_rest_of_line (); |
1118 | return; | |
1119 | } | |
1120 | ||
1121 | demand_empty_rest_of_line (); | |
1122 | } | |
1123 | ||
1124 | /* This handles the .vtable_inherit pseudo-op, which is used to indicate | |
1125 | to the linker the hierarchy in which a particular table resides. The | |
1126 | syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */ | |
1127 | ||
1128 | static void | |
1129 | obj_elf_vtable_inherit (ignore) | |
ab9da554 | 1130 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1131 | { |
1132 | char *cname, *pname; | |
1133 | symbolS *csym, *psym; | |
1134 | char c, bad = 0; | |
1135 | ||
1136 | if (*input_line_pointer == '#') | |
1137 | ++input_line_pointer; | |
1138 | ||
1139 | cname = input_line_pointer; | |
1140 | c = get_symbol_end (); | |
1141 | csym = symbol_find (cname); | |
1142 | ||
1143 | /* GCFIXME: should check that we don't have two .vtable_inherits for | |
1144 | the same child symbol. Also, we can currently only do this if the | |
1145 | child symbol is already exists and is placed in a fragment. */ | |
1146 | ||
49309057 | 1147 | if (csym == NULL || symbol_get_frag (csym) == NULL) |
252b5132 RH |
1148 | { |
1149 | as_bad ("expected `%s' to have already been set for .vtable_inherit", | |
1150 | cname); | |
1151 | bad = 1; | |
1152 | } | |
1153 | ||
1154 | *input_line_pointer = c; | |
1155 | ||
1156 | SKIP_WHITESPACE (); | |
1157 | if (*input_line_pointer != ',') | |
1158 | { | |
1159 | as_bad ("expected comma after name in .vtable_inherit"); | |
1160 | ignore_rest_of_line (); | |
1161 | return; | |
1162 | } | |
1163 | ||
1164 | ++input_line_pointer; | |
1165 | SKIP_WHITESPACE (); | |
1166 | ||
1167 | if (*input_line_pointer == '#') | |
1168 | ++input_line_pointer; | |
1169 | ||
1170 | if (input_line_pointer[0] == '0' | |
1171 | && (input_line_pointer[1] == '\0' | |
d9a62219 | 1172 | || isspace ((unsigned char) input_line_pointer[1]))) |
252b5132 RH |
1173 | { |
1174 | psym = section_symbol (absolute_section); | |
1175 | ++input_line_pointer; | |
1176 | } | |
1177 | else | |
1178 | { | |
1179 | pname = input_line_pointer; | |
1180 | c = get_symbol_end (); | |
1181 | psym = symbol_find_or_make (pname); | |
1182 | *input_line_pointer = c; | |
1183 | } | |
1184 | ||
1185 | demand_empty_rest_of_line (); | |
1186 | ||
1187 | if (bad) | |
1188 | return; | |
1189 | ||
49309057 ILT |
1190 | assert (symbol_get_value_expression (csym)->X_op == O_constant); |
1191 | fix_new (symbol_get_frag (csym), | |
1192 | symbol_get_value_expression (csym)->X_add_number, 0, psym, 0, 0, | |
252b5132 RH |
1193 | BFD_RELOC_VTABLE_INHERIT); |
1194 | } | |
fa306131 | 1195 | |
252b5132 RH |
1196 | /* This handles the .vtable_entry pseudo-op, which is used to indicate |
1197 | to the linker that a vtable slot was used. The syntax is | |
1198 | ".vtable_entry tablename, offset". */ | |
1199 | ||
1200 | static void | |
1201 | obj_elf_vtable_entry (ignore) | |
ab9da554 | 1202 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1203 | { |
1204 | char *name; | |
1205 | symbolS *sym; | |
1206 | offsetT offset; | |
1207 | char c; | |
1208 | ||
1209 | if (*input_line_pointer == '#') | |
1210 | ++input_line_pointer; | |
1211 | ||
1212 | name = input_line_pointer; | |
1213 | c = get_symbol_end (); | |
1214 | sym = symbol_find_or_make (name); | |
1215 | *input_line_pointer = c; | |
1216 | ||
1217 | SKIP_WHITESPACE (); | |
1218 | if (*input_line_pointer != ',') | |
1219 | { | |
1220 | as_bad ("expected comma after name in .vtable_entry"); | |
1221 | ignore_rest_of_line (); | |
1222 | return; | |
1223 | } | |
1224 | ||
1225 | ++input_line_pointer; | |
1226 | if (*input_line_pointer == '#') | |
1227 | ++input_line_pointer; | |
1228 | ||
1229 | offset = get_absolute_expression (); | |
1230 | ||
1231 | fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0, | |
1232 | BFD_RELOC_VTABLE_ENTRY); | |
1233 | ||
1234 | demand_empty_rest_of_line (); | |
1235 | } | |
1236 | ||
1237 | void | |
4c63da97 | 1238 | elf_obj_read_begin_hook () |
252b5132 RH |
1239 | { |
1240 | #ifdef NEED_ECOFF_DEBUG | |
1241 | if (ECOFF_DEBUGGING) | |
1242 | ecoff_read_begin_hook (); | |
1243 | #endif | |
1244 | } | |
1245 | ||
1246 | void | |
4c63da97 | 1247 | elf_obj_symbol_new_hook (symbolP) |
252b5132 RH |
1248 | symbolS *symbolP; |
1249 | { | |
49309057 ILT |
1250 | struct elf_obj_sy *sy_obj; |
1251 | ||
1252 | sy_obj = symbol_get_obj (symbolP); | |
1253 | sy_obj->size = NULL; | |
1254 | sy_obj->versioned_name = NULL; | |
252b5132 RH |
1255 | |
1256 | #ifdef NEED_ECOFF_DEBUG | |
1257 | if (ECOFF_DEBUGGING) | |
1258 | ecoff_symbol_new_hook (symbolP); | |
1259 | #endif | |
1260 | } | |
1261 | ||
1262 | void | |
1263 | obj_elf_version (ignore) | |
ab9da554 | 1264 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1265 | { |
1266 | char *name; | |
1267 | unsigned int c; | |
1268 | char ch; | |
1269 | char *p; | |
1270 | asection *seg = now_seg; | |
1271 | subsegT subseg = now_subseg; | |
1272 | Elf_Internal_Note i_note; | |
1273 | Elf_External_Note e_note; | |
1274 | asection *note_secp = (asection *) NULL; | |
1275 | int i, len; | |
1276 | ||
1277 | SKIP_WHITESPACE (); | |
1278 | if (*input_line_pointer == '\"') | |
1279 | { | |
1280 | ++input_line_pointer; /* -> 1st char of string. */ | |
1281 | name = input_line_pointer; | |
1282 | ||
1283 | while (is_a_char (c = next_char_of_string ())) | |
1284 | ; | |
1285 | c = *input_line_pointer; | |
1286 | *input_line_pointer = '\0'; | |
1287 | *(input_line_pointer - 1) = '\0'; | |
1288 | *input_line_pointer = c; | |
1289 | ||
1290 | /* create the .note section */ | |
1291 | ||
1292 | note_secp = subseg_new (".note", 0); | |
1293 | bfd_set_section_flags (stdoutput, | |
1294 | note_secp, | |
1295 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1296 | ||
1297 | /* process the version string */ | |
1298 | ||
1299 | len = strlen (name); | |
1300 | ||
1301 | i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */ | |
1302 | i_note.descsz = 0; /* no description */ | |
1303 | i_note.type = NT_VERSION; | |
1304 | p = frag_more (sizeof (e_note.namesz)); | |
1305 | md_number_to_chars (p, (valueT) i_note.namesz, 4); | |
1306 | p = frag_more (sizeof (e_note.descsz)); | |
1307 | md_number_to_chars (p, (valueT) i_note.descsz, 4); | |
1308 | p = frag_more (sizeof (e_note.type)); | |
1309 | md_number_to_chars (p, (valueT) i_note.type, 4); | |
1310 | ||
1311 | for (i = 0; i < len; i++) | |
1312 | { | |
1313 | ch = *(name + i); | |
1314 | { | |
1315 | FRAG_APPEND_1_CHAR (ch); | |
1316 | } | |
1317 | } | |
1318 | frag_align (2, 0, 0); | |
1319 | ||
1320 | subseg_set (seg, subseg); | |
1321 | } | |
1322 | else | |
1323 | { | |
1324 | as_bad (_("Expected quoted string")); | |
1325 | } | |
1326 | demand_empty_rest_of_line (); | |
1327 | } | |
1328 | ||
1329 | static void | |
1330 | obj_elf_size (ignore) | |
ab9da554 | 1331 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1332 | { |
1333 | char *name = input_line_pointer; | |
1334 | char c = get_symbol_end (); | |
1335 | char *p; | |
1336 | expressionS exp; | |
1337 | symbolS *sym; | |
1338 | ||
1339 | p = input_line_pointer; | |
1340 | *p = c; | |
1341 | SKIP_WHITESPACE (); | |
1342 | if (*input_line_pointer != ',') | |
1343 | { | |
1344 | *p = 0; | |
1345 | as_bad (_("expected comma after name `%s' in .size directive"), name); | |
1346 | *p = c; | |
1347 | ignore_rest_of_line (); | |
1348 | return; | |
1349 | } | |
1350 | input_line_pointer++; | |
1351 | expression (&exp); | |
1352 | if (exp.X_op == O_absent) | |
1353 | { | |
1354 | as_bad (_("missing expression in .size directive")); | |
1355 | exp.X_op = O_constant; | |
1356 | exp.X_add_number = 0; | |
1357 | } | |
1358 | *p = 0; | |
1359 | sym = symbol_find_or_make (name); | |
1360 | *p = c; | |
1361 | if (exp.X_op == O_constant) | |
1362 | S_SET_SIZE (sym, exp.X_add_number); | |
1363 | else | |
1364 | { | |
49309057 ILT |
1365 | symbol_get_obj (sym)->size = |
1366 | (expressionS *) xmalloc (sizeof (expressionS)); | |
1367 | *symbol_get_obj (sym)->size = exp; | |
252b5132 RH |
1368 | } |
1369 | demand_empty_rest_of_line (); | |
1370 | } | |
1371 | ||
1372 | /* Handle the ELF .type pseudo-op. This sets the type of a symbol. | |
1373 | There are four syntaxes: | |
fa306131 | 1374 | |
252b5132 RH |
1375 | The first (used on Solaris) is |
1376 | .type SYM,#function | |
1377 | The second (used on UnixWare) is | |
1378 | .type SYM,@function | |
1379 | The third (reportedly to be used on Irix 6.0) is | |
1380 | .type SYM STT_FUNC | |
1381 | The fourth (used on NetBSD/Arm and Linux/ARM) is | |
1382 | .type SYM,%function | |
1383 | */ | |
1384 | ||
1385 | static void | |
1386 | obj_elf_type (ignore) | |
ab9da554 | 1387 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1388 | { |
1389 | char *name; | |
1390 | char c; | |
1391 | int type; | |
1392 | const char *typename; | |
1393 | symbolS *sym; | |
1394 | ||
1395 | name = input_line_pointer; | |
1396 | c = get_symbol_end (); | |
1397 | sym = symbol_find_or_make (name); | |
1398 | *input_line_pointer = c; | |
1399 | ||
1400 | SKIP_WHITESPACE (); | |
1401 | if (*input_line_pointer == ',') | |
1402 | ++input_line_pointer; | |
1403 | ||
1404 | SKIP_WHITESPACE (); | |
1405 | if ( *input_line_pointer == '#' | |
1406 | || *input_line_pointer == '@' | |
1407 | || *input_line_pointer == '%') | |
1408 | ++input_line_pointer; | |
1409 | ||
1410 | typename = input_line_pointer; | |
1411 | c = get_symbol_end (); | |
1412 | ||
1413 | type = 0; | |
1414 | if (strcmp (typename, "function") == 0 | |
1415 | || strcmp (typename, "STT_FUNC") == 0) | |
1416 | type = BSF_FUNCTION; | |
1417 | else if (strcmp (typename, "object") == 0 | |
1418 | || strcmp (typename, "STT_OBJECT") == 0) | |
1419 | type = BSF_OBJECT; | |
1420 | else | |
1421 | as_bad (_("ignoring unrecognized symbol type \"%s\""), typename); | |
1422 | ||
1423 | *input_line_pointer = c; | |
1424 | ||
49309057 | 1425 | symbol_get_bfdsym (sym)->flags |= type; |
252b5132 RH |
1426 | |
1427 | demand_empty_rest_of_line (); | |
1428 | } | |
1429 | ||
1430 | static void | |
1431 | obj_elf_ident (ignore) | |
ab9da554 | 1432 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1433 | { |
1434 | static segT comment_section; | |
1435 | segT old_section = now_seg; | |
1436 | int old_subsection = now_subseg; | |
1437 | ||
5f91fe03 ILT |
1438 | #ifdef md_flush_pending_output |
1439 | md_flush_pending_output (); | |
1440 | #endif | |
1441 | ||
252b5132 RH |
1442 | if (!comment_section) |
1443 | { | |
1444 | char *p; | |
1445 | comment_section = subseg_new (".comment", 0); | |
1446 | bfd_set_section_flags (stdoutput, comment_section, | |
1447 | SEC_READONLY | SEC_HAS_CONTENTS); | |
1448 | p = frag_more (1); | |
1449 | *p = 0; | |
1450 | } | |
1451 | else | |
1452 | subseg_set (comment_section, 0); | |
1453 | stringer (1); | |
1454 | subseg_set (old_section, old_subsection); | |
1455 | } | |
1456 | ||
1457 | #ifdef INIT_STAB_SECTION | |
1458 | ||
1459 | /* The first entry in a .stabs section is special. */ | |
1460 | ||
1461 | void | |
1462 | obj_elf_init_stab_section (seg) | |
1463 | segT seg; | |
1464 | { | |
1465 | char *file; | |
1466 | char *p; | |
1467 | char *stabstr_name; | |
1468 | unsigned int stroff; | |
1469 | ||
1470 | /* Force the section to align to a longword boundary. Without this, | |
1471 | UnixWare ar crashes. */ | |
1472 | bfd_set_section_alignment (stdoutput, seg, 2); | |
1473 | ||
1474 | /* Make space for this first symbol. */ | |
1475 | p = frag_more (12); | |
1476 | /* Zero it out. */ | |
1477 | memset (p, 0, 12); | |
1478 | as_where (&file, (unsigned int *) NULL); | |
1479 | stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4); | |
1480 | strcpy (stabstr_name, segment_name (seg)); | |
1481 | strcat (stabstr_name, "str"); | |
1482 | stroff = get_stab_string_offset (file, stabstr_name); | |
1483 | know (stroff == 1); | |
1484 | md_number_to_chars (p, stroff, 4); | |
1485 | seg_info (seg)->stabu.p = p; | |
1486 | } | |
1487 | ||
1488 | #endif | |
1489 | ||
1490 | /* Fill in the counts in the first entry in a .stabs section. */ | |
1491 | ||
1492 | static void | |
1493 | adjust_stab_sections (abfd, sec, xxx) | |
1494 | bfd *abfd; | |
1495 | asection *sec; | |
ab9da554 | 1496 | PTR xxx ATTRIBUTE_UNUSED; |
252b5132 RH |
1497 | { |
1498 | char *name; | |
1499 | asection *strsec; | |
1500 | char *p; | |
1501 | int strsz, nsyms; | |
1502 | ||
1503 | if (strncmp (".stab", sec->name, 5)) | |
1504 | return; | |
1505 | if (!strcmp ("str", sec->name + strlen (sec->name) - 3)) | |
1506 | return; | |
1507 | ||
1508 | name = (char *) alloca (strlen (sec->name) + 4); | |
1509 | strcpy (name, sec->name); | |
1510 | strcat (name, "str"); | |
1511 | strsec = bfd_get_section_by_name (abfd, name); | |
1512 | if (strsec) | |
1513 | strsz = bfd_section_size (abfd, strsec); | |
1514 | else | |
1515 | strsz = 0; | |
1516 | nsyms = bfd_section_size (abfd, sec) / 12 - 1; | |
1517 | ||
1518 | p = seg_info (sec)->stabu.p; | |
1519 | assert (p != 0); | |
1520 | ||
1521 | bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6); | |
1522 | bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8); | |
1523 | } | |
1524 | ||
1525 | #ifdef NEED_ECOFF_DEBUG | |
1526 | ||
1527 | /* This function is called by the ECOFF code. It is supposed to | |
1528 | record the external symbol information so that the backend can | |
1529 | write it out correctly. The ELF backend doesn't actually handle | |
1530 | this at the moment, so we do it ourselves. We save the information | |
1531 | in the symbol. */ | |
1532 | ||
1533 | void | |
1534 | elf_ecoff_set_ext (sym, ext) | |
1535 | symbolS *sym; | |
1536 | struct ecoff_extr *ext; | |
1537 | { | |
49309057 | 1538 | symbol_get_bfdsym (sym)->udata.p = (PTR) ext; |
252b5132 RH |
1539 | } |
1540 | ||
1541 | /* This function is called by bfd_ecoff_debug_externals. It is | |
1542 | supposed to *EXT to the external symbol information, and return | |
1543 | whether the symbol should be used at all. */ | |
1544 | ||
1545 | static boolean | |
1546 | elf_get_extr (sym, ext) | |
1547 | asymbol *sym; | |
1548 | EXTR *ext; | |
1549 | { | |
1550 | if (sym->udata.p == NULL) | |
1551 | return false; | |
1552 | *ext = *(EXTR *) sym->udata.p; | |
1553 | return true; | |
1554 | } | |
1555 | ||
1556 | /* This function is called by bfd_ecoff_debug_externals. It has | |
1557 | nothing to do for ELF. */ | |
1558 | ||
1559 | /*ARGSUSED*/ | |
1560 | static void | |
1561 | elf_set_index (sym, indx) | |
5f91fe03 ILT |
1562 | asymbol *sym ATTRIBUTE_UNUSED; |
1563 | bfd_size_type indx ATTRIBUTE_UNUSED; | |
252b5132 RH |
1564 | { |
1565 | } | |
1566 | ||
1567 | #endif /* NEED_ECOFF_DEBUG */ | |
1568 | ||
1569 | void | |
1570 | elf_frob_symbol (symp, puntp) | |
1571 | symbolS *symp; | |
1572 | int *puntp; | |
1573 | { | |
49309057 ILT |
1574 | struct elf_obj_sy *sy_obj; |
1575 | ||
252b5132 RH |
1576 | #ifdef NEED_ECOFF_DEBUG |
1577 | if (ECOFF_DEBUGGING) | |
1578 | ecoff_frob_symbol (symp); | |
1579 | #endif | |
1580 | ||
49309057 ILT |
1581 | sy_obj = symbol_get_obj (symp); |
1582 | ||
1583 | if (sy_obj->size != NULL) | |
252b5132 | 1584 | { |
49309057 | 1585 | switch (sy_obj->size->X_op) |
252b5132 RH |
1586 | { |
1587 | case O_subtract: | |
1588 | S_SET_SIZE (symp, | |
49309057 ILT |
1589 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1590 | + sy_obj->size->X_add_number | |
1591 | - S_GET_VALUE (sy_obj->size->X_op_symbol))); | |
252b5132 RH |
1592 | break; |
1593 | case O_constant: | |
1594 | S_SET_SIZE (symp, | |
49309057 ILT |
1595 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1596 | + sy_obj->size->X_add_number)); | |
252b5132 RH |
1597 | break; |
1598 | default: | |
1599 | as_bad (_(".size expression too complicated to fix up")); | |
1600 | break; | |
1601 | } | |
49309057 ILT |
1602 | free (sy_obj->size); |
1603 | sy_obj->size = NULL; | |
252b5132 RH |
1604 | } |
1605 | ||
49309057 | 1606 | if (sy_obj->versioned_name != NULL) |
252b5132 RH |
1607 | { |
1608 | /* This symbol was given a new name with the .symver directive. | |
1609 | ||
1610 | If this is an external reference, just rename the symbol to | |
1611 | include the version string. This will make the relocs be | |
1612 | against the correct versioned symbol. | |
1613 | ||
1614 | If this is a definition, add an alias. FIXME: Using an alias | |
1615 | will permit the debugging information to refer to the right | |
1616 | symbol. However, it's not clear whether it is the best | |
1617 | approach. */ | |
1618 | ||
1619 | if (! S_IS_DEFINED (symp)) | |
1620 | { | |
1621 | char *p; | |
1622 | ||
1623 | /* Verify that the name isn't using the @@ syntax--this is | |
1624 | reserved for definitions of the default version to link | |
1625 | against. */ | |
49309057 | 1626 | p = strchr (sy_obj->versioned_name, ELF_VER_CHR); |
252b5132 RH |
1627 | know (p != NULL); |
1628 | if (p[1] == ELF_VER_CHR) | |
1629 | { | |
1630 | as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"), | |
49309057 | 1631 | sy_obj->versioned_name); |
252b5132 RH |
1632 | *puntp = true; |
1633 | } | |
49309057 | 1634 | S_SET_NAME (symp, sy_obj->versioned_name); |
252b5132 RH |
1635 | } |
1636 | else | |
1637 | { | |
1638 | symbolS *symp2; | |
1639 | ||
1640 | /* FIXME: Creating a new symbol here is risky. We're in the | |
1641 | final loop over the symbol table. We can get away with | |
1642 | it only because the symbol goes to the end of the list, | |
1643 | where the loop will still see it. It would probably be | |
1644 | better to do this in obj_frob_file_before_adjust. */ | |
1645 | ||
49309057 | 1646 | symp2 = symbol_find_or_make (sy_obj->versioned_name); |
252b5132 RH |
1647 | |
1648 | /* Now we act as though we saw symp2 = sym. */ | |
1649 | ||
1650 | S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp)); | |
1651 | ||
1652 | /* Subtracting out the frag address here is a hack because | |
1653 | we are in the middle of the final loop. */ | |
49309057 ILT |
1654 | S_SET_VALUE (symp2, |
1655 | (S_GET_VALUE (symp) | |
1656 | - symbol_get_frag (symp)->fr_address)); | |
252b5132 | 1657 | |
49309057 | 1658 | symbol_set_frag (symp2, symbol_get_frag (symp)); |
252b5132 RH |
1659 | |
1660 | /* This will copy over the size information. */ | |
1661 | copy_symbol_attributes (symp2, symp); | |
1662 | ||
1663 | if (S_IS_WEAK (symp)) | |
1664 | S_SET_WEAK (symp2); | |
1665 | ||
1666 | if (S_IS_EXTERNAL (symp)) | |
1667 | S_SET_EXTERNAL (symp2); | |
1668 | } | |
1669 | } | |
1670 | ||
1671 | /* Double check weak symbols. */ | |
49309057 | 1672 | if (S_IS_WEAK (symp)) |
252b5132 RH |
1673 | { |
1674 | if (S_IS_COMMON (symp)) | |
1675 | as_bad (_("Symbol `%s' can not be both weak and common"), | |
1676 | S_GET_NAME (symp)); | |
1677 | } | |
1678 | ||
1679 | #ifdef TC_MIPS | |
1680 | /* The Irix 5 and 6 assemblers set the type of any common symbol and | |
1681 | any undefined non-function symbol to STT_OBJECT. We try to be | |
1682 | compatible, since newer Irix 5 and 6 linkers care. However, we | |
1683 | only set undefined symbols to be STT_OBJECT if we are on Irix, | |
1684 | because that is the only time gcc will generate the necessary | |
1685 | .global directives to mark functions. */ | |
1686 | ||
1687 | if (S_IS_COMMON (symp)) | |
49309057 | 1688 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1689 | |
1690 | if (strstr (TARGET_OS, "irix") != NULL | |
49309057 ILT |
1691 | && ! S_IS_DEFINED (symp) |
1692 | && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0) | |
1693 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; | |
252b5132 RH |
1694 | #endif |
1695 | ||
c5e54cc2 ILT |
1696 | #if 0 /* TC_PPC */ |
1697 | /* If TC_PPC is defined, we used to force the type of a symbol to be | |
1698 | BSF_OBJECT if it was otherwise unset. This was required by some | |
1699 | version of VxWorks. Thomas de Lellis <[email protected]> says | |
1700 | that this is no longer needed, so it is now commented out. */ | |
49309057 ILT |
1701 | if ((symbol_get_bfdsym (symp)->flags |
1702 | & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0 | |
252b5132 | 1703 | && S_IS_DEFINED (symp)) |
49309057 | 1704 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1705 | #endif |
1706 | } | |
1707 | ||
1708 | void | |
1709 | elf_frob_file () | |
1710 | { | |
1711 | bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0); | |
1712 | ||
1713 | #ifdef elf_tc_final_processing | |
1714 | elf_tc_final_processing (); | |
1715 | #endif | |
1716 | } | |
1717 | ||
1718 | /* It is required that we let write_relocs have the opportunity to | |
1719 | optimize away fixups before output has begun, since it is possible | |
1720 | to eliminate all fixups for a section and thus we never should | |
1721 | have generated the relocation section. */ | |
1722 | ||
1723 | void | |
1724 | elf_frob_file_after_relocs () | |
1725 | { | |
1726 | #ifdef NEED_ECOFF_DEBUG | |
1727 | if (ECOFF_DEBUGGING) | |
1728 | /* Generate the ECOFF debugging information. */ | |
1729 | { | |
1730 | const struct ecoff_debug_swap *debug_swap; | |
1731 | struct ecoff_debug_info debug; | |
1732 | char *buf; | |
1733 | asection *sec; | |
1734 | ||
1735 | debug_swap | |
1736 | = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap; | |
1737 | know (debug_swap != (const struct ecoff_debug_swap *) NULL); | |
1738 | ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap); | |
1739 | ||
1740 | /* Set up the pointers in debug. */ | |
1741 | #define SET(ptr, offset, type) \ | |
1742 | debug.ptr = (type) (buf + debug.symbolic_header.offset) | |
1743 | ||
1744 | SET (line, cbLineOffset, unsigned char *); | |
1745 | SET (external_dnr, cbDnOffset, PTR); | |
1746 | SET (external_pdr, cbPdOffset, PTR); | |
1747 | SET (external_sym, cbSymOffset, PTR); | |
1748 | SET (external_opt, cbOptOffset, PTR); | |
1749 | SET (external_aux, cbAuxOffset, union aux_ext *); | |
1750 | SET (ss, cbSsOffset, char *); | |
1751 | SET (external_fdr, cbFdOffset, PTR); | |
1752 | SET (external_rfd, cbRfdOffset, PTR); | |
1753 | /* ssext and external_ext are set up just below. */ | |
1754 | ||
1755 | #undef SET | |
1756 | ||
1757 | /* Set up the external symbols. */ | |
1758 | debug.ssext = debug.ssext_end = NULL; | |
1759 | debug.external_ext = debug.external_ext_end = NULL; | |
1760 | if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true, | |
1761 | elf_get_extr, elf_set_index)) | |
1762 | as_fatal (_("Failed to set up debugging information: %s"), | |
1763 | bfd_errmsg (bfd_get_error ())); | |
1764 | ||
1765 | sec = bfd_get_section_by_name (stdoutput, ".mdebug"); | |
1766 | assert (sec != NULL); | |
1767 | ||
1768 | know (stdoutput->output_has_begun == false); | |
1769 | ||
1770 | /* We set the size of the section, call bfd_set_section_contents | |
1771 | to force the ELF backend to allocate a file position, and then | |
1772 | write out the data. FIXME: Is this really the best way to do | |
1773 | this? */ | |
1774 | sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap); | |
1775 | ||
5f91fe03 ILT |
1776 | /* Pass BUF to bfd_set_section_contents because this will |
1777 | eventually become a call to fwrite, and ISO C prohibits | |
1778 | passing a NULL pointer to a stdio function even if the | |
1779 | pointer will not be used. */ | |
1780 | if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf, | |
252b5132 RH |
1781 | (file_ptr) 0, (bfd_size_type) 0)) |
1782 | as_fatal (_("Can't start writing .mdebug section: %s"), | |
1783 | bfd_errmsg (bfd_get_error ())); | |
1784 | ||
1785 | know (stdoutput->output_has_begun == true); | |
1786 | know (sec->filepos != 0); | |
1787 | ||
1788 | if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap, | |
1789 | sec->filepos)) | |
1790 | as_fatal (_("Could not write .mdebug section: %s"), | |
1791 | bfd_errmsg (bfd_get_error ())); | |
1792 | } | |
1793 | #endif /* NEED_ECOFF_DEBUG */ | |
1794 | } | |
1795 | ||
1796 | #ifdef SCO_ELF | |
1797 | ||
1798 | /* Heavily plagarized from obj_elf_version. The idea is to emit the | |
1799 | SCO specific identifier in the .notes section to satisfy the SCO | |
1800 | linker. | |
1801 | ||
1802 | This looks more complicated than it really is. As opposed to the | |
1803 | "obvious" solution, this should handle the cross dev cases | |
1804 | correctly. (i.e, hosting on a 64 bit big endian processor, but | |
1805 | generating SCO Elf code) Efficiency isn't a concern, as there | |
1806 | should be exactly one of these sections per object module. | |
1807 | ||
1808 | SCO OpenServer 5 identifies it's ELF modules with a standard ELF | |
1809 | .note section. | |
1810 | ||
fa306131 AM |
1811 | int_32 namesz = 4 ; Name size |
1812 | int_32 descsz = 12 ; Descriptive information | |
1813 | int_32 type = 1 ; | |
1814 | char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL | |
252b5132 RH |
1815 | int_32 version = (major ver # << 16) | version of tools ; |
1816 | int_32 source = (tool_id << 16 ) | 1 ; | |
1817 | int_32 info = 0 ; These are set by the SCO tools, but we | |
fa306131 | 1818 | don't know enough about the source |
252b5132 RH |
1819 | environment to set them. SCO ld currently |
1820 | ignores them, and recommends we set them | |
1821 | to zero. */ | |
1822 | ||
1823 | #define SCO_MAJOR_VERSION 0x1 | |
1824 | #define SCO_MINOR_VERSION 0x1 | |
1825 | ||
1826 | void | |
1827 | sco_id () | |
1828 | { | |
1829 | ||
1830 | char *name; | |
1831 | unsigned int c; | |
1832 | char ch; | |
1833 | char *p; | |
1834 | asection *seg = now_seg; | |
1835 | subsegT subseg = now_subseg; | |
1836 | Elf_Internal_Note i_note; | |
1837 | Elf_External_Note e_note; | |
1838 | asection *note_secp = (asection *) NULL; | |
1839 | int i, len; | |
1840 | ||
1841 | /* create the .note section */ | |
1842 | ||
1843 | note_secp = subseg_new (".note", 0); | |
1844 | bfd_set_section_flags (stdoutput, | |
1845 | note_secp, | |
1846 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1847 | ||
1848 | /* process the version string */ | |
1849 | ||
fa306131 | 1850 | i_note.namesz = 4; |
252b5132 RH |
1851 | i_note.descsz = 12; /* 12 descriptive bytes */ |
1852 | i_note.type = NT_VERSION; /* Contains a version string */ | |
1853 | ||
1854 | p = frag_more (sizeof (i_note.namesz)); | |
1855 | md_number_to_chars (p, (valueT) i_note.namesz, 4); | |
1856 | ||
1857 | p = frag_more (sizeof (i_note.descsz)); | |
1858 | md_number_to_chars (p, (valueT) i_note.descsz, 4); | |
1859 | ||
1860 | p = frag_more (sizeof (i_note.type)); | |
1861 | md_number_to_chars (p, (valueT) i_note.type, 4); | |
1862 | ||
1863 | p = frag_more (4); | |
fa306131 | 1864 | strcpy (p, "SCO"); |
252b5132 RH |
1865 | |
1866 | /* Note: this is the version number of the ELF we're representing */ | |
1867 | p = frag_more (4); | |
1868 | md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4); | |
1869 | ||
1870 | /* Here, we pick a magic number for ourselves (yes, I "registered" | |
1871 | it with SCO. The bottom bit shows that we are compat with the | |
1872 | SCO ABI. */ | |
1873 | p = frag_more (4); | |
1874 | md_number_to_chars (p, 0x4c520000 | 0x0001, 4); | |
1875 | ||
1876 | /* If we knew (or cared) what the source language options were, we'd | |
1877 | fill them in here. SCO has given us permission to ignore these | |
1878 | and just set them to zero. */ | |
1879 | p = frag_more (4); | |
1880 | md_number_to_chars (p, 0x0000, 4); | |
fa306131 | 1881 | |
252b5132 RH |
1882 | frag_align (2, 0, 0); |
1883 | ||
1884 | /* We probably can't restore the current segment, for there likely | |
1885 | isn't one yet... */ | |
1886 | if (seg && subseg) | |
1887 | subseg_set (seg, subseg); | |
1888 | ||
1889 | } | |
1890 | ||
1891 | #endif /* SCO_ELF */ | |
1892 | ||
1893 | const struct format_ops elf_format_ops = | |
1894 | { | |
1895 | bfd_target_elf_flavour, | |
4c63da97 AM |
1896 | 0, /* dfl_leading_underscore */ |
1897 | 1, /* emit_section_symbols */ | |
252b5132 RH |
1898 | elf_frob_symbol, |
1899 | elf_frob_file, | |
1900 | elf_frob_file_after_relocs, | |
1901 | elf_s_get_size, elf_s_set_size, | |
1902 | elf_s_get_align, elf_s_set_align, | |
4c63da97 AM |
1903 | elf_s_get_other, |
1904 | 0, /* s_get_desc */ | |
252b5132 RH |
1905 | elf_copy_symbol_attributes, |
1906 | #ifdef NEED_ECOFF_DEBUG | |
1907 | ecoff_generate_asm_lineno, | |
1908 | ecoff_stab, | |
1909 | #else | |
4c63da97 AM |
1910 | 0, /* generate_asm_lineno */ |
1911 | 0, /* process_stab */ | |
252b5132 RH |
1912 | #endif |
1913 | elf_sec_sym_ok_for_reloc, | |
1914 | elf_pop_insert, | |
1915 | #ifdef NEED_ECOFF_DEBUG | |
1916 | elf_ecoff_set_ext, | |
1917 | #else | |
4c63da97 | 1918 | 0, /* ecoff_set_ext */ |
252b5132 | 1919 | #endif |
4c63da97 AM |
1920 | elf_obj_read_begin_hook, |
1921 | elf_obj_symbol_new_hook, | |
252b5132 | 1922 | }; |