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