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