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