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