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; |
2f89ff8d L |
617 | int def_type; |
618 | int def_attr; | |
252b5132 RH |
619 | |
620 | #ifdef md_flush_pending_output | |
621 | md_flush_pending_output (); | |
622 | #endif | |
623 | ||
9de8d8f1 RH |
624 | /* Switch to the section, creating it if necessary. */ |
625 | if (push) | |
626 | { | |
627 | struct section_stack *elt; | |
628 | elt = xmalloc (sizeof (struct section_stack)); | |
629 | elt->next = section_stack; | |
630 | elt->seg = now_seg; | |
631 | elt->prev_seg = previous_section; | |
632 | elt->subseg = now_subseg; | |
633 | elt->prev_subseg = previous_subsection; | |
634 | section_stack = elt; | |
635 | } | |
636 | previous_section = now_seg; | |
637 | previous_subsection = now_subseg; | |
638 | ||
742f45cf | 639 | old_sec = bfd_get_section_by_name (stdoutput, name); |
9de8d8f1 RH |
640 | sec = subseg_new (name, 0); |
641 | ||
2f89ff8d L |
642 | if (_bfd_elf_get_sec_type_attr (stdoutput, name, &def_type, |
643 | &def_attr)) | |
644 | { | |
645 | if (type == SHT_NULL) | |
646 | type = def_type; | |
647 | else if (type != def_type) | |
648 | { | |
649 | if (old_sec == NULL | |
650 | /* FIXME: gcc, as of 2002-10-22, will emit | |
7ed1d346 | 651 | |
2f89ff8d | 652 | .section .init_array,"aw",@progbits |
7ed1d346 | 653 | |
2f89ff8d L |
654 | for __attribute__ ((section (".init_array"))). |
655 | "@progbits" is incorrect. */ | |
656 | && def_type != SHT_INIT_ARRAY | |
657 | && def_type != SHT_FINI_ARRAY | |
658 | && def_type != SHT_PREINIT_ARRAY) | |
659 | { | |
660 | /* We allow to specify any type for a .note section. */ | |
661 | if (def_type != SHT_NOTE) | |
662 | as_warn (_("setting incorrect section type for %s"), | |
663 | name); | |
664 | } | |
665 | else | |
666 | { | |
667 | as_warn (_("ignoring incorrect section type for %s"), | |
742f45cf | 668 | name); |
2f89ff8d L |
669 | type = def_type; |
670 | } | |
671 | } | |
672 | ||
673 | if (old_sec == NULL && (attr &~ def_attr) != 0) | |
674 | { | |
675 | /* As a GNU extension, we permit a .note section to be | |
676 | allocatable. If the linker sees an allocateable .note | |
677 | section, it will create a PT_NOTE segment in the output | |
678 | file. */ | |
679 | if (strcmp (name, ".note") != 0 || attr != SHF_ALLOC) | |
680 | as_warn (_("setting incorrect section attributes for %s"), | |
681 | name); | |
682 | } | |
683 | attr |= def_attr; | |
2f89ff8d | 684 | } |
742f45cf | 685 | |
3cddba1e L |
686 | if (type != SHT_NULL) |
687 | elf_section_type (sec) = type; | |
688 | if (attr != 0) | |
689 | elf_section_flags (sec) = attr; | |
8e8c182c | 690 | |
742f45cf AM |
691 | /* Convert ELF type and flags to BFD flags. */ |
692 | flags = (SEC_RELOC | |
693 | | ((attr & SHF_WRITE) ? 0 : SEC_READONLY) | |
694 | | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0) | |
695 | | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0) | |
f5fa8ca2 JJ |
696 | | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0) |
697 | | ((attr & SHF_MERGE) ? SEC_MERGE : 0) | |
13ae64f3 JJ |
698 | | ((attr & SHF_STRINGS) ? SEC_STRINGS : 0) |
699 | | ((attr & SHF_TLS) ? SEC_THREAD_LOCAL : 0)); | |
9de8d8f1 | 700 | #ifdef md_elf_section_flags |
742f45cf | 701 | flags = md_elf_section_flags (flags, attr, type); |
9de8d8f1 RH |
702 | #endif |
703 | ||
742f45cf AM |
704 | if (old_sec == NULL) |
705 | { | |
706 | symbolS *secsym; | |
707 | ||
9de8d8f1 RH |
708 | /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */ |
709 | if (type == SHT_NOBITS) | |
710 | seg_info (sec)->bss = 1; | |
711 | ||
68bfbfcc AM |
712 | if (linkonce) |
713 | flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
9de8d8f1 | 714 | bfd_set_section_flags (stdoutput, sec, flags); |
f5fa8ca2 JJ |
715 | if (flags & SEC_MERGE) |
716 | sec->entsize = entsize; | |
aa1f4858 | 717 | elf_group_name (sec) = group_name; |
9de8d8f1 RH |
718 | |
719 | /* Add a symbol for this section to the symbol table. */ | |
720 | secsym = symbol_find (name); | |
721 | if (secsym != NULL) | |
722 | symbol_set_bfdsym (secsym, sec->symbol); | |
723 | else | |
724 | symbol_table_insert (section_symbol (sec)); | |
725 | } | |
742f45cf AM |
726 | else if (attr != 0) |
727 | { | |
728 | /* If section attributes are specified the second time we see a | |
729 | particular section, then check that they are the same as we | |
730 | saw the first time. */ | |
d2dab548 AM |
731 | if (((old_sec->flags ^ flags) |
732 | & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | |
733 | | SEC_EXCLUDE | SEC_SORT_ENTRIES | SEC_MERGE | SEC_STRINGS | |
68bfbfcc AM |
734 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD |
735 | | SEC_THREAD_LOCAL))) | |
6ce8b369 | 736 | as_warn (_("ignoring changed section attributes for %s"), name); |
d2dab548 | 737 | if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize) |
6ce8b369 | 738 | as_warn (_("ignoring changed section entity size for %s"), name); |
d2dab548 AM |
739 | if ((attr & SHF_GROUP) != 0 |
740 | && strcmp (elf_group_name (old_sec), group_name) != 0) | |
060adf0e | 741 | as_warn (_("ignoring new section group for %s"), name); |
742f45cf | 742 | } |
9de8d8f1 RH |
743 | |
744 | #ifdef md_elf_section_change_hook | |
742f45cf | 745 | md_elf_section_change_hook (); |
9de8d8f1 RH |
746 | #endif |
747 | } | |
748 | ||
8d28c9d7 | 749 | static int |
9de8d8f1 RH |
750 | obj_elf_parse_section_letters (str, len) |
751 | char *str; | |
752 | size_t len; | |
753 | { | |
754 | int attr = 0; | |
755 | ||
756 | while (len > 0) | |
757 | { | |
758 | switch (*str) | |
759 | { | |
760 | case 'a': | |
761 | attr |= SHF_ALLOC; | |
762 | break; | |
763 | case 'w': | |
764 | attr |= SHF_WRITE; | |
765 | break; | |
766 | case 'x': | |
767 | attr |= SHF_EXECINSTR; | |
768 | break; | |
9469ddf0 | 769 | case 'M': |
f5fa8ca2 JJ |
770 | attr |= SHF_MERGE; |
771 | break; | |
9469ddf0 | 772 | case 'S': |
f5fa8ca2 JJ |
773 | attr |= SHF_STRINGS; |
774 | break; | |
060adf0e AM |
775 | case 'G': |
776 | attr |= SHF_GROUP; | |
777 | break; | |
13ae64f3 JJ |
778 | case 'T': |
779 | attr |= SHF_TLS; | |
780 | break; | |
34105363 L |
781 | /* Compatibility. */ |
782 | case 'm': | |
783 | if (*(str - 1) == 'a') | |
784 | { | |
785 | attr |= SHF_MERGE; | |
786 | if (len > 1 && str[1] == 's') | |
787 | { | |
788 | attr |= SHF_STRINGS; | |
789 | str++, len--; | |
790 | } | |
791 | break; | |
792 | } | |
9de8d8f1 RH |
793 | default: |
794 | { | |
13ae64f3 | 795 | char *bad_msg = _("unrecognized .section attribute: want a,w,x,M,S,G,T"); |
9de8d8f1 RH |
796 | #ifdef md_elf_section_letter |
797 | int md_attr = md_elf_section_letter (*str, &bad_msg); | |
798 | if (md_attr >= 0) | |
799 | attr |= md_attr; | |
800 | else | |
801 | #endif | |
711ef82f | 802 | as_fatal ("%s", bad_msg); |
9de8d8f1 RH |
803 | } |
804 | break; | |
805 | } | |
806 | str++, len--; | |
807 | } | |
808 | ||
809 | return attr; | |
810 | } | |
811 | ||
8d28c9d7 | 812 | static int |
9de8d8f1 RH |
813 | obj_elf_section_word (str, len) |
814 | char *str; | |
815 | size_t len; | |
816 | { | |
817 | if (len == 5 && strncmp (str, "write", 5) == 0) | |
818 | return SHF_WRITE; | |
819 | if (len == 5 && strncmp (str, "alloc", 5) == 0) | |
820 | return SHF_ALLOC; | |
821 | if (len == 9 && strncmp (str, "execinstr", 9) == 0) | |
822 | return SHF_EXECINSTR; | |
b9734f35 JJ |
823 | if (len == 3 && strncmp (str, "tls", 3) == 0) |
824 | return SHF_TLS; | |
9de8d8f1 RH |
825 | |
826 | #ifdef md_elf_section_word | |
827 | { | |
828 | int md_attr = md_elf_section_word (str, len); | |
829 | if (md_attr >= 0) | |
830 | return md_attr; | |
831 | } | |
832 | #endif | |
833 | ||
6ce8b369 | 834 | as_warn (_("unrecognized section attribute")); |
9de8d8f1 RH |
835 | return 0; |
836 | } | |
837 | ||
8d28c9d7 | 838 | static int |
9de8d8f1 RH |
839 | obj_elf_section_type (str, len) |
840 | char *str; | |
841 | size_t len; | |
842 | { | |
843 | if (len == 8 && strncmp (str, "progbits", 8) == 0) | |
844 | return SHT_PROGBITS; | |
845 | if (len == 6 && strncmp (str, "nobits", 6) == 0) | |
846 | return SHT_NOBITS; | |
847 | ||
848 | #ifdef md_elf_section_type | |
849 | { | |
850 | int md_type = md_elf_section_type (str, len); | |
851 | if (md_type >= 0) | |
852 | return md_type; | |
853 | } | |
854 | #endif | |
855 | ||
6ce8b369 | 856 | as_warn (_("unrecognized section type")); |
9de8d8f1 RH |
857 | return 0; |
858 | } | |
859 | ||
6ce8b369 AM |
860 | /* Get name of section. */ |
861 | static char * | |
862 | obj_elf_section_name () | |
863 | { | |
864 | char *name; | |
865 | ||
866 | SKIP_WHITESPACE (); | |
867 | if (*input_line_pointer == '"') | |
868 | { | |
869 | int dummy; | |
870 | ||
871 | name = demand_copy_C_string (&dummy); | |
872 | if (name == NULL) | |
873 | { | |
874 | ignore_rest_of_line (); | |
875 | return NULL; | |
876 | } | |
877 | } | |
878 | else | |
879 | { | |
880 | char *end = input_line_pointer; | |
881 | ||
882 | while (0 == strchr ("\n\t,; ", *end)) | |
883 | end++; | |
884 | if (end == input_line_pointer) | |
885 | { | |
886 | as_warn (_("missing name")); | |
887 | ignore_rest_of_line (); | |
888 | return NULL; | |
889 | } | |
890 | ||
891 | name = xmalloc (end - input_line_pointer + 1); | |
892 | memcpy (name, input_line_pointer, end - input_line_pointer); | |
893 | name[end - input_line_pointer] = '\0'; | |
612d7b83 L |
894 | #ifdef tc_canonicalize_section_name |
895 | name = tc_canonicalize_section_name (name); | |
896 | #endif | |
6ce8b369 AM |
897 | input_line_pointer = end; |
898 | } | |
899 | SKIP_WHITESPACE (); | |
900 | return name; | |
901 | } | |
902 | ||
9de8d8f1 RH |
903 | void |
904 | obj_elf_section (push) | |
905 | int push; | |
906 | { | |
aa1f4858 | 907 | char *name, *group_name, *beg; |
9de8d8f1 | 908 | int type, attr, dummy; |
f5fa8ca2 | 909 | int entsize; |
d2dab548 | 910 | int linkonce; |
9de8d8f1 | 911 | |
5b93d8bb | 912 | #ifndef TC_I370 |
252b5132 RH |
913 | if (flag_mri) |
914 | { | |
915 | char mri_type; | |
916 | ||
9de8d8f1 | 917 | #ifdef md_flush_pending_output |
60bcf0fa | 918 | md_flush_pending_output (); |
9de8d8f1 RH |
919 | #endif |
920 | ||
252b5132 RH |
921 | previous_section = now_seg; |
922 | previous_subsection = now_subseg; | |
923 | ||
924 | s_mri_sect (&mri_type); | |
925 | ||
926 | #ifdef md_elf_section_change_hook | |
927 | md_elf_section_change_hook (); | |
928 | #endif | |
929 | ||
930 | return; | |
931 | } | |
5b93d8bb | 932 | #endif /* ! defined (TC_I370) */ |
252b5132 | 933 | |
6ce8b369 AM |
934 | name = obj_elf_section_name (); |
935 | if (name == NULL) | |
936 | return; | |
252b5132 RH |
937 | type = SHT_NULL; |
938 | attr = 0; | |
aa1f4858 | 939 | group_name = NULL; |
f5fa8ca2 | 940 | entsize = 0; |
d2dab548 | 941 | linkonce = 0; |
252b5132 RH |
942 | |
943 | if (*input_line_pointer == ',') | |
944 | { | |
945 | /* Skip the comma. */ | |
946 | ++input_line_pointer; | |
252b5132 RH |
947 | SKIP_WHITESPACE (); |
948 | ||
949 | if (*input_line_pointer == '"') | |
950 | { | |
9de8d8f1 RH |
951 | beg = demand_copy_C_string (&dummy); |
952 | if (beg == NULL) | |
252b5132 | 953 | { |
9de8d8f1 RH |
954 | ignore_rest_of_line (); |
955 | return; | |
252b5132 | 956 | } |
9de8d8f1 | 957 | attr |= obj_elf_parse_section_letters (beg, strlen (beg)); |
252b5132 RH |
958 | |
959 | SKIP_WHITESPACE (); | |
960 | if (*input_line_pointer == ',') | |
961 | { | |
9de8d8f1 | 962 | char c; |
060adf0e AM |
963 | char *save = input_line_pointer; |
964 | ||
252b5132 RH |
965 | ++input_line_pointer; |
966 | SKIP_WHITESPACE (); | |
9de8d8f1 RH |
967 | c = *input_line_pointer; |
968 | if (c == '"') | |
252b5132 | 969 | { |
9de8d8f1 RH |
970 | beg = demand_copy_C_string (&dummy); |
971 | if (beg == NULL) | |
252b5132 | 972 | { |
9de8d8f1 RH |
973 | ignore_rest_of_line (); |
974 | return; | |
252b5132 | 975 | } |
9de8d8f1 | 976 | type = obj_elf_section_type (beg, strlen (beg)); |
9de8d8f1 RH |
977 | } |
978 | else if (c == '@' || c == '%') | |
979 | { | |
980 | beg = ++input_line_pointer; | |
981 | c = get_symbol_end (); | |
982 | *input_line_pointer = c; | |
983 | type = obj_elf_section_type (beg, input_line_pointer - beg); | |
252b5132 | 984 | } |
060adf0e AM |
985 | else |
986 | input_line_pointer = save; | |
252b5132 | 987 | } |
f5fa8ca2 JJ |
988 | |
989 | SKIP_WHITESPACE (); | |
6ce8b369 | 990 | if ((attr & SHF_MERGE) != 0 && *input_line_pointer == ',') |
f5fa8ca2 JJ |
991 | { |
992 | ++input_line_pointer; | |
993 | SKIP_WHITESPACE (); | |
994 | entsize = get_absolute_expression (); | |
6ce8b369 | 995 | SKIP_WHITESPACE (); |
f5fa8ca2 JJ |
996 | if (entsize < 0) |
997 | { | |
6ce8b369 | 998 | as_warn (_("invalid merge entity size")); |
f5fa8ca2 JJ |
999 | attr &= ~SHF_MERGE; |
1000 | entsize = 0; | |
1001 | } | |
1002 | } | |
6ce8b369 AM |
1003 | else if ((attr & SHF_MERGE) != 0) |
1004 | { | |
1005 | as_warn (_("entity size for SHF_MERGE not specified")); | |
1006 | attr &= ~SHF_MERGE; | |
1007 | } | |
060adf0e AM |
1008 | |
1009 | if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',') | |
1010 | { | |
1011 | ++input_line_pointer; | |
aa1f4858 AM |
1012 | group_name = obj_elf_section_name (); |
1013 | if (group_name == NULL) | |
060adf0e | 1014 | attr &= ~SHF_GROUP; |
d2dab548 AM |
1015 | else if (strncmp (input_line_pointer, ",comdat", 7) == 0) |
1016 | { | |
1017 | input_line_pointer += 7; | |
1018 | linkonce = 1; | |
1019 | } | |
1020 | else if (strncmp (name, ".gnu.linkonce", 13) == 0) | |
1021 | linkonce = 1; | |
060adf0e AM |
1022 | } |
1023 | else if ((attr & SHF_GROUP) != 0) | |
1024 | { | |
1025 | as_warn (_("group name for SHF_GROUP not specified")); | |
1026 | attr &= ~SHF_GROUP; | |
1027 | } | |
252b5132 RH |
1028 | } |
1029 | else | |
1030 | { | |
1031 | do | |
1032 | { | |
9de8d8f1 RH |
1033 | char c; |
1034 | ||
252b5132 RH |
1035 | SKIP_WHITESPACE (); |
1036 | if (*input_line_pointer != '#') | |
1037 | { | |
6ce8b369 | 1038 | as_warn (_("character following name is not '#'")); |
252b5132 RH |
1039 | ignore_rest_of_line (); |
1040 | return; | |
1041 | } | |
9de8d8f1 RH |
1042 | beg = ++input_line_pointer; |
1043 | c = get_symbol_end (); | |
1044 | *input_line_pointer = c; | |
1045 | ||
1046 | attr |= obj_elf_section_word (beg, input_line_pointer - beg); | |
1047 | ||
252b5132 RH |
1048 | SKIP_WHITESPACE (); |
1049 | } | |
1050 | while (*input_line_pointer++ == ','); | |
1051 | --input_line_pointer; | |
1052 | } | |
1053 | } | |
1054 | ||
252b5132 | 1055 | demand_empty_rest_of_line (); |
9de8d8f1 | 1056 | |
d2dab548 | 1057 | obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push); |
252b5132 RH |
1058 | } |
1059 | ||
1060 | /* Change to the .data section. */ | |
1061 | ||
16b93d88 | 1062 | void |
252b5132 RH |
1063 | obj_elf_data (i) |
1064 | int i; | |
1065 | { | |
1066 | #ifdef md_flush_pending_output | |
1067 | md_flush_pending_output (); | |
1068 | #endif | |
1069 | ||
1070 | previous_section = now_seg; | |
1071 | previous_subsection = now_subseg; | |
1072 | s_data (i); | |
1073 | ||
1074 | #ifdef md_elf_section_change_hook | |
1075 | md_elf_section_change_hook (); | |
1076 | #endif | |
1077 | } | |
1078 | ||
1079 | /* Change to the .text section. */ | |
1080 | ||
16b93d88 | 1081 | void |
252b5132 RH |
1082 | obj_elf_text (i) |
1083 | int i; | |
1084 | { | |
1085 | #ifdef md_flush_pending_output | |
1086 | md_flush_pending_output (); | |
1087 | #endif | |
1088 | ||
1089 | previous_section = now_seg; | |
1090 | previous_subsection = now_subseg; | |
1091 | s_text (i); | |
1092 | ||
1093 | #ifdef md_elf_section_change_hook | |
1094 | md_elf_section_change_hook (); | |
1095 | #endif | |
1096 | } | |
1097 | ||
1098 | static void | |
1099 | obj_elf_subsection (ignore) | |
ab9da554 | 1100 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1101 | { |
1102 | register int temp; | |
1103 | ||
1104 | #ifdef md_flush_pending_output | |
1105 | md_flush_pending_output (); | |
1106 | #endif | |
1107 | ||
1108 | previous_section = now_seg; | |
1109 | previous_subsection = now_subseg; | |
1110 | ||
1111 | temp = get_absolute_expression (); | |
1112 | subseg_set (now_seg, (subsegT) temp); | |
1113 | demand_empty_rest_of_line (); | |
1114 | ||
1115 | #ifdef md_elf_section_change_hook | |
1116 | md_elf_section_change_hook (); | |
1117 | #endif | |
1118 | } | |
1119 | ||
1120 | /* This can be called from the processor backends if they change | |
1121 | sections. */ | |
1122 | ||
1123 | void | |
1124 | obj_elf_section_change_hook () | |
1125 | { | |
1126 | previous_section = now_seg; | |
1127 | previous_subsection = now_subseg; | |
1128 | } | |
1129 | ||
1130 | void | |
1131 | obj_elf_previous (ignore) | |
ab9da554 | 1132 | int ignore ATTRIBUTE_UNUSED; |
252b5132 | 1133 | { |
9de8d8f1 RH |
1134 | segT new_section; |
1135 | int new_subsection; | |
1136 | ||
252b5132 RH |
1137 | if (previous_section == 0) |
1138 | { | |
6ce8b369 | 1139 | as_warn (_(".previous without corresponding .section; ignored")); |
252b5132 RH |
1140 | return; |
1141 | } | |
1142 | ||
1143 | #ifdef md_flush_pending_output | |
1144 | md_flush_pending_output (); | |
1145 | #endif | |
1146 | ||
9de8d8f1 RH |
1147 | new_section = previous_section; |
1148 | new_subsection = previous_subsection; | |
1149 | previous_section = now_seg; | |
1150 | previous_subsection = now_subseg; | |
1151 | subseg_set (new_section, new_subsection); | |
1152 | ||
1153 | #ifdef md_elf_section_change_hook | |
1154 | md_elf_section_change_hook (); | |
1155 | #endif | |
1156 | } | |
1157 | ||
1158 | static void | |
1159 | obj_elf_popsection (xxx) | |
ab9da554 | 1160 | int xxx ATTRIBUTE_UNUSED; |
9de8d8f1 RH |
1161 | { |
1162 | struct section_stack *top = section_stack; | |
1163 | ||
1164 | if (top == NULL) | |
1165 | { | |
6ce8b369 | 1166 | as_warn (_(".popsection without corresponding .pushsection; ignored")); |
9de8d8f1 RH |
1167 | return; |
1168 | } | |
1169 | ||
1170 | #ifdef md_flush_pending_output | |
1171 | md_flush_pending_output (); | |
1172 | #endif | |
1173 | ||
1174 | section_stack = top->next; | |
1175 | previous_section = top->prev_seg; | |
1176 | previous_subsection = top->prev_subseg; | |
1177 | subseg_set (top->seg, top->subseg); | |
1178 | free (top); | |
252b5132 RH |
1179 | |
1180 | #ifdef md_elf_section_change_hook | |
1181 | md_elf_section_change_hook (); | |
1182 | #endif | |
1183 | } | |
1184 | ||
1185 | static void | |
1186 | obj_elf_line (ignore) | |
ab9da554 | 1187 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1188 | { |
1189 | /* Assume delimiter is part of expression. BSD4.2 as fails with | |
bf514e21 | 1190 | delightful bug, so we are not being incompatible here. */ |
252b5132 RH |
1191 | new_logical_line ((char *) NULL, (int) (get_absolute_expression ())); |
1192 | demand_empty_rest_of_line (); | |
1193 | } | |
1194 | ||
1195 | /* This handles the .symver pseudo-op, which is used to specify a | |
1196 | symbol version. The syntax is ``.symver NAME,SYMVERNAME''. | |
1197 | SYMVERNAME may contain ELF_VER_CHR ('@') characters. This | |
1198 | pseudo-op causes the assembler to emit a symbol named SYMVERNAME | |
1199 | with the same value as the symbol NAME. */ | |
1200 | ||
1201 | static void | |
1202 | obj_elf_symver (ignore) | |
ab9da554 | 1203 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1204 | { |
1205 | char *name; | |
1206 | char c; | |
468cced8 | 1207 | char old_lexat; |
252b5132 RH |
1208 | symbolS *sym; |
1209 | ||
1210 | name = input_line_pointer; | |
1211 | c = get_symbol_end (); | |
1212 | ||
1213 | sym = symbol_find_or_make (name); | |
1214 | ||
1215 | *input_line_pointer = c; | |
1216 | ||
252b5132 RH |
1217 | SKIP_WHITESPACE (); |
1218 | if (*input_line_pointer != ',') | |
1219 | { | |
1220 | as_bad (_("expected comma after name in .symver")); | |
1221 | ignore_rest_of_line (); | |
1222 | return; | |
1223 | } | |
1224 | ||
1225 | ++input_line_pointer; | |
eba874d8 | 1226 | SKIP_WHITESPACE (); |
252b5132 | 1227 | name = input_line_pointer; |
468cced8 AM |
1228 | |
1229 | /* Temporarily include '@' in symbol names. */ | |
1230 | old_lexat = lex_type[(unsigned char) '@']; | |
1231 | lex_type[(unsigned char) '@'] |= LEX_NAME; | |
1232 | c = get_symbol_end (); | |
1233 | lex_type[(unsigned char) '@'] = old_lexat; | |
252b5132 | 1234 | |
339681c0 L |
1235 | if (symbol_get_obj (sym)->versioned_name == NULL) |
1236 | { | |
1237 | symbol_get_obj (sym)->versioned_name = xstrdup (name); | |
252b5132 | 1238 | |
339681c0 | 1239 | *input_line_pointer = c; |
252b5132 | 1240 | |
6f620856 L |
1241 | if (strchr (symbol_get_obj (sym)->versioned_name, |
1242 | ELF_VER_CHR) == NULL) | |
339681c0 L |
1243 | { |
1244 | as_bad (_("missing version name in `%s' for symbol `%s'"), | |
1245 | symbol_get_obj (sym)->versioned_name, | |
1246 | S_GET_NAME (sym)); | |
1247 | ignore_rest_of_line (); | |
1248 | return; | |
1249 | } | |
1250 | } | |
1251 | else | |
252b5132 | 1252 | { |
339681c0 L |
1253 | if (strcmp (symbol_get_obj (sym)->versioned_name, name)) |
1254 | { | |
1255 | as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"), | |
1256 | name, symbol_get_obj (sym)->versioned_name, | |
1257 | S_GET_NAME (sym)); | |
1258 | ignore_rest_of_line (); | |
1259 | return; | |
1260 | } | |
1261 | ||
1262 | *input_line_pointer = c; | |
252b5132 RH |
1263 | } |
1264 | ||
1265 | demand_empty_rest_of_line (); | |
1266 | } | |
1267 | ||
1268 | /* This handles the .vtable_inherit pseudo-op, which is used to indicate | |
1269 | to the linker the hierarchy in which a particular table resides. The | |
1270 | syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */ | |
1271 | ||
904a31bf | 1272 | struct fix * |
252b5132 | 1273 | obj_elf_vtable_inherit (ignore) |
ab9da554 | 1274 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1275 | { |
1276 | char *cname, *pname; | |
1277 | symbolS *csym, *psym; | |
1278 | char c, bad = 0; | |
1279 | ||
1280 | if (*input_line_pointer == '#') | |
1281 | ++input_line_pointer; | |
1282 | ||
1283 | cname = input_line_pointer; | |
1284 | c = get_symbol_end (); | |
1285 | csym = symbol_find (cname); | |
1286 | ||
1287 | /* GCFIXME: should check that we don't have two .vtable_inherits for | |
1288 | the same child symbol. Also, we can currently only do this if the | |
1289 | child symbol is already exists and is placed in a fragment. */ | |
1290 | ||
49309057 | 1291 | if (csym == NULL || symbol_get_frag (csym) == NULL) |
252b5132 RH |
1292 | { |
1293 | as_bad ("expected `%s' to have already been set for .vtable_inherit", | |
1294 | cname); | |
1295 | bad = 1; | |
1296 | } | |
1297 | ||
1298 | *input_line_pointer = c; | |
1299 | ||
1300 | SKIP_WHITESPACE (); | |
1301 | if (*input_line_pointer != ',') | |
1302 | { | |
1303 | as_bad ("expected comma after name in .vtable_inherit"); | |
1304 | ignore_rest_of_line (); | |
904a31bf | 1305 | return NULL; |
252b5132 RH |
1306 | } |
1307 | ||
1308 | ++input_line_pointer; | |
1309 | SKIP_WHITESPACE (); | |
1310 | ||
1311 | if (*input_line_pointer == '#') | |
1312 | ++input_line_pointer; | |
1313 | ||
1314 | if (input_line_pointer[0] == '0' | |
1315 | && (input_line_pointer[1] == '\0' | |
3882b010 | 1316 | || ISSPACE (input_line_pointer[1]))) |
252b5132 RH |
1317 | { |
1318 | psym = section_symbol (absolute_section); | |
1319 | ++input_line_pointer; | |
1320 | } | |
1321 | else | |
1322 | { | |
1323 | pname = input_line_pointer; | |
1324 | c = get_symbol_end (); | |
1325 | psym = symbol_find_or_make (pname); | |
1326 | *input_line_pointer = c; | |
1327 | } | |
1328 | ||
1329 | demand_empty_rest_of_line (); | |
1330 | ||
1331 | if (bad) | |
904a31bf | 1332 | return NULL; |
252b5132 | 1333 | |
49309057 | 1334 | assert (symbol_get_value_expression (csym)->X_op == O_constant); |
904a31bf AM |
1335 | return fix_new (symbol_get_frag (csym), |
1336 | symbol_get_value_expression (csym)->X_add_number, | |
1337 | 0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT); | |
252b5132 | 1338 | } |
fa306131 | 1339 | |
252b5132 RH |
1340 | /* This handles the .vtable_entry pseudo-op, which is used to indicate |
1341 | to the linker that a vtable slot was used. The syntax is | |
1342 | ".vtable_entry tablename, offset". */ | |
1343 | ||
904a31bf | 1344 | struct fix * |
252b5132 | 1345 | obj_elf_vtable_entry (ignore) |
ab9da554 | 1346 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1347 | { |
1348 | char *name; | |
1349 | symbolS *sym; | |
1350 | offsetT offset; | |
1351 | char c; | |
1352 | ||
1353 | if (*input_line_pointer == '#') | |
1354 | ++input_line_pointer; | |
1355 | ||
1356 | name = input_line_pointer; | |
1357 | c = get_symbol_end (); | |
1358 | sym = symbol_find_or_make (name); | |
1359 | *input_line_pointer = c; | |
1360 | ||
1361 | SKIP_WHITESPACE (); | |
1362 | if (*input_line_pointer != ',') | |
1363 | { | |
1364 | as_bad ("expected comma after name in .vtable_entry"); | |
1365 | ignore_rest_of_line (); | |
904a31bf | 1366 | return NULL; |
252b5132 RH |
1367 | } |
1368 | ||
1369 | ++input_line_pointer; | |
1370 | if (*input_line_pointer == '#') | |
1371 | ++input_line_pointer; | |
1372 | ||
1373 | offset = get_absolute_expression (); | |
1374 | ||
252b5132 | 1375 | demand_empty_rest_of_line (); |
904a31bf AM |
1376 | |
1377 | return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0, | |
1378 | BFD_RELOC_VTABLE_ENTRY); | |
252b5132 RH |
1379 | } |
1380 | ||
1381 | void | |
4c63da97 | 1382 | elf_obj_read_begin_hook () |
252b5132 RH |
1383 | { |
1384 | #ifdef NEED_ECOFF_DEBUG | |
1385 | if (ECOFF_DEBUGGING) | |
1386 | ecoff_read_begin_hook (); | |
1387 | #endif | |
1388 | } | |
1389 | ||
1390 | void | |
4c63da97 | 1391 | elf_obj_symbol_new_hook (symbolP) |
252b5132 RH |
1392 | symbolS *symbolP; |
1393 | { | |
49309057 ILT |
1394 | struct elf_obj_sy *sy_obj; |
1395 | ||
1396 | sy_obj = symbol_get_obj (symbolP); | |
1397 | sy_obj->size = NULL; | |
1398 | sy_obj->versioned_name = NULL; | |
252b5132 RH |
1399 | |
1400 | #ifdef NEED_ECOFF_DEBUG | |
1401 | if (ECOFF_DEBUGGING) | |
1402 | ecoff_symbol_new_hook (symbolP); | |
1403 | #endif | |
1404 | } | |
1405 | ||
8fd3e36b AM |
1406 | /* When setting one symbol equal to another, by default we probably |
1407 | want them to have the same "size", whatever it means in the current | |
1408 | context. */ | |
1409 | ||
1410 | void | |
1411 | elf_copy_symbol_attributes (dest, src) | |
1412 | symbolS *dest, *src; | |
1413 | { | |
060adf0e AM |
1414 | struct elf_obj_sy *srcelf = symbol_get_obj (src); |
1415 | struct elf_obj_sy *destelf = symbol_get_obj (dest); | |
1416 | if (srcelf->size) | |
1417 | { | |
1418 | if (destelf->size == NULL) | |
1419 | destelf->size = | |
1420 | (expressionS *) xmalloc (sizeof (expressionS)); | |
1421 | *destelf->size = *srcelf->size; | |
1422 | } | |
1423 | else | |
1424 | { | |
1425 | if (destelf->size != NULL) | |
1426 | free (destelf->size); | |
1427 | destelf->size = NULL; | |
1428 | } | |
1429 | S_SET_SIZE (dest, S_GET_SIZE (src)); | |
26eb4093 JJ |
1430 | /* Don't copy visibility. */ |
1431 | S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest)) | |
1432 | | (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1)))); | |
8fd3e36b AM |
1433 | } |
1434 | ||
252b5132 RH |
1435 | void |
1436 | obj_elf_version (ignore) | |
ab9da554 | 1437 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1438 | { |
1439 | char *name; | |
1440 | unsigned int c; | |
252b5132 RH |
1441 | char *p; |
1442 | asection *seg = now_seg; | |
1443 | subsegT subseg = now_subseg; | |
1444 | Elf_Internal_Note i_note; | |
1445 | Elf_External_Note e_note; | |
1446 | asection *note_secp = (asection *) NULL; | |
e4afe742 | 1447 | int len; |
252b5132 RH |
1448 | |
1449 | SKIP_WHITESPACE (); | |
1450 | if (*input_line_pointer == '\"') | |
1451 | { | |
bf514e21 | 1452 | ++input_line_pointer; /* -> 1st char of string. */ |
252b5132 RH |
1453 | name = input_line_pointer; |
1454 | ||
1455 | while (is_a_char (c = next_char_of_string ())) | |
1456 | ; | |
1457 | c = *input_line_pointer; | |
1458 | *input_line_pointer = '\0'; | |
1459 | *(input_line_pointer - 1) = '\0'; | |
1460 | *input_line_pointer = c; | |
1461 | ||
1462 | /* create the .note section */ | |
1463 | ||
1464 | note_secp = subseg_new (".note", 0); | |
1465 | bfd_set_section_flags (stdoutput, | |
1466 | note_secp, | |
1467 | SEC_HAS_CONTENTS | SEC_READONLY); | |
1468 | ||
1469 | /* process the version string */ | |
1470 | ||
1471 | len = strlen (name); | |
1472 | ||
1473 | i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */ | |
1474 | i_note.descsz = 0; /* no description */ | |
1475 | i_note.type = NT_VERSION; | |
1476 | p = frag_more (sizeof (e_note.namesz)); | |
e4afe742 | 1477 | md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz)); |
252b5132 | 1478 | p = frag_more (sizeof (e_note.descsz)); |
e4afe742 | 1479 | md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz)); |
252b5132 | 1480 | p = frag_more (sizeof (e_note.type)); |
e4afe742 AM |
1481 | md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type)); |
1482 | p = frag_more (len + 1); | |
1483 | strcpy (p, name); | |
252b5132 | 1484 | |
252b5132 RH |
1485 | frag_align (2, 0, 0); |
1486 | ||
1487 | subseg_set (seg, subseg); | |
1488 | } | |
1489 | else | |
1490 | { | |
6ce8b369 | 1491 | as_bad (_("expected quoted string")); |
252b5132 RH |
1492 | } |
1493 | demand_empty_rest_of_line (); | |
1494 | } | |
1495 | ||
1496 | static void | |
1497 | obj_elf_size (ignore) | |
ab9da554 | 1498 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1499 | { |
1500 | char *name = input_line_pointer; | |
1501 | char c = get_symbol_end (); | |
1502 | char *p; | |
1503 | expressionS exp; | |
1504 | symbolS *sym; | |
1505 | ||
1506 | p = input_line_pointer; | |
1507 | *p = c; | |
1508 | SKIP_WHITESPACE (); | |
1509 | if (*input_line_pointer != ',') | |
1510 | { | |
1511 | *p = 0; | |
1512 | as_bad (_("expected comma after name `%s' in .size directive"), name); | |
1513 | *p = c; | |
1514 | ignore_rest_of_line (); | |
1515 | return; | |
1516 | } | |
1517 | input_line_pointer++; | |
1518 | expression (&exp); | |
1519 | if (exp.X_op == O_absent) | |
1520 | { | |
1521 | as_bad (_("missing expression in .size directive")); | |
1522 | exp.X_op = O_constant; | |
1523 | exp.X_add_number = 0; | |
1524 | } | |
1525 | *p = 0; | |
1526 | sym = symbol_find_or_make (name); | |
1527 | *p = c; | |
1528 | if (exp.X_op == O_constant) | |
c538998c JJ |
1529 | { |
1530 | S_SET_SIZE (sym, exp.X_add_number); | |
1531 | if (symbol_get_obj (sym)->size) | |
1532 | { | |
1533 | xfree (symbol_get_obj (sym)->size); | |
1534 | symbol_get_obj (sym)->size = NULL; | |
1535 | } | |
1536 | } | |
252b5132 RH |
1537 | else |
1538 | { | |
49309057 ILT |
1539 | symbol_get_obj (sym)->size = |
1540 | (expressionS *) xmalloc (sizeof (expressionS)); | |
1541 | *symbol_get_obj (sym)->size = exp; | |
252b5132 RH |
1542 | } |
1543 | demand_empty_rest_of_line (); | |
1544 | } | |
1545 | ||
1546 | /* Handle the ELF .type pseudo-op. This sets the type of a symbol. | |
aa8c34c3 | 1547 | There are five syntaxes: |
fa306131 | 1548 | |
252b5132 RH |
1549 | The first (used on Solaris) is |
1550 | .type SYM,#function | |
1551 | The second (used on UnixWare) is | |
1552 | .type SYM,@function | |
1553 | The third (reportedly to be used on Irix 6.0) is | |
1554 | .type SYM STT_FUNC | |
1555 | The fourth (used on NetBSD/Arm and Linux/ARM) is | |
1556 | .type SYM,%function | |
aa8c34c3 JE |
1557 | The fifth (used on SVR4/860) is |
1558 | .type SYM,"function" | |
252b5132 RH |
1559 | */ |
1560 | ||
1561 | static void | |
1562 | obj_elf_type (ignore) | |
ab9da554 | 1563 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1564 | { |
1565 | char *name; | |
1566 | char c; | |
1567 | int type; | |
1568 | const char *typename; | |
1569 | symbolS *sym; | |
904a31bf | 1570 | elf_symbol_type *elfsym; |
252b5132 RH |
1571 | |
1572 | name = input_line_pointer; | |
1573 | c = get_symbol_end (); | |
1574 | sym = symbol_find_or_make (name); | |
904a31bf | 1575 | elfsym = (elf_symbol_type *) symbol_get_bfdsym (sym); |
252b5132 RH |
1576 | *input_line_pointer = c; |
1577 | ||
1578 | SKIP_WHITESPACE (); | |
1579 | if (*input_line_pointer == ',') | |
1580 | ++input_line_pointer; | |
1581 | ||
1582 | SKIP_WHITESPACE (); | |
1583 | if ( *input_line_pointer == '#' | |
1584 | || *input_line_pointer == '@' | |
aa8c34c3 | 1585 | || *input_line_pointer == '"' |
252b5132 RH |
1586 | || *input_line_pointer == '%') |
1587 | ++input_line_pointer; | |
1588 | ||
1589 | typename = input_line_pointer; | |
1590 | c = get_symbol_end (); | |
1591 | ||
1592 | type = 0; | |
1593 | if (strcmp (typename, "function") == 0 | |
1594 | || strcmp (typename, "STT_FUNC") == 0) | |
1595 | type = BSF_FUNCTION; | |
1596 | else if (strcmp (typename, "object") == 0 | |
1597 | || strcmp (typename, "STT_OBJECT") == 0) | |
1598 | type = BSF_OBJECT; | |
b9734f35 JJ |
1599 | else if (strcmp (typename, "tls_object") == 0 |
1600 | || strcmp (typename, "STT_TLS") == 0) | |
1601 | type = BSF_OBJECT | BSF_THREAD_LOCAL; | |
e7b9a8c1 L |
1602 | else if (strcmp (typename, "notype") == 0 |
1603 | || strcmp (typename, "STT_NOTYPE") == 0) | |
1604 | ; | |
904a31bf AM |
1605 | #ifdef md_elf_symbol_type |
1606 | else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1) | |
1607 | ; | |
1608 | #endif | |
252b5132 | 1609 | else |
6ce8b369 | 1610 | as_bad (_("unrecognized symbol type \"%s\""), typename); |
252b5132 RH |
1611 | |
1612 | *input_line_pointer = c; | |
1613 | ||
aa8c34c3 JE |
1614 | if (*input_line_pointer == '"') |
1615 | ++input_line_pointer; | |
1616 | ||
904a31bf | 1617 | elfsym->symbol.flags |= type; |
252b5132 RH |
1618 | |
1619 | demand_empty_rest_of_line (); | |
1620 | } | |
1621 | ||
1622 | static void | |
1623 | obj_elf_ident (ignore) | |
ab9da554 | 1624 | int ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
1625 | { |
1626 | static segT comment_section; | |
1627 | segT old_section = now_seg; | |
1628 | int old_subsection = now_subseg; | |
1629 | ||
5f91fe03 ILT |
1630 | #ifdef md_flush_pending_output |
1631 | md_flush_pending_output (); | |
1632 | #endif | |
1633 | ||
252b5132 RH |
1634 | if (!comment_section) |
1635 | { | |
1636 | char *p; | |
1637 | comment_section = subseg_new (".comment", 0); | |
1638 | bfd_set_section_flags (stdoutput, comment_section, | |
1639 | SEC_READONLY | SEC_HAS_CONTENTS); | |
1640 | p = frag_more (1); | |
1641 | *p = 0; | |
1642 | } | |
1643 | else | |
1644 | subseg_set (comment_section, 0); | |
1645 | stringer (1); | |
1646 | subseg_set (old_section, old_subsection); | |
1647 | } | |
1648 | ||
1649 | #ifdef INIT_STAB_SECTION | |
1650 | ||
1651 | /* The first entry in a .stabs section is special. */ | |
1652 | ||
1653 | void | |
1654 | obj_elf_init_stab_section (seg) | |
1655 | segT seg; | |
1656 | { | |
1657 | char *file; | |
1658 | char *p; | |
1659 | char *stabstr_name; | |
1660 | unsigned int stroff; | |
1661 | ||
1662 | /* Force the section to align to a longword boundary. Without this, | |
1663 | UnixWare ar crashes. */ | |
1664 | bfd_set_section_alignment (stdoutput, seg, 2); | |
1665 | ||
bf514e21 | 1666 | /* Make space for this first symbol. */ |
252b5132 | 1667 | p = frag_more (12); |
bf514e21 | 1668 | /* Zero it out. */ |
252b5132 RH |
1669 | memset (p, 0, 12); |
1670 | as_where (&file, (unsigned int *) NULL); | |
f91fafbd | 1671 | stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4); |
252b5132 RH |
1672 | strcpy (stabstr_name, segment_name (seg)); |
1673 | strcat (stabstr_name, "str"); | |
1674 | stroff = get_stab_string_offset (file, stabstr_name); | |
1675 | know (stroff == 1); | |
1676 | md_number_to_chars (p, stroff, 4); | |
1677 | seg_info (seg)->stabu.p = p; | |
1678 | } | |
1679 | ||
1680 | #endif | |
1681 | ||
1682 | /* Fill in the counts in the first entry in a .stabs section. */ | |
1683 | ||
1684 | static void | |
1685 | adjust_stab_sections (abfd, sec, xxx) | |
1686 | bfd *abfd; | |
1687 | asection *sec; | |
ab9da554 | 1688 | PTR xxx ATTRIBUTE_UNUSED; |
252b5132 RH |
1689 | { |
1690 | char *name; | |
1691 | asection *strsec; | |
1692 | char *p; | |
1693 | int strsz, nsyms; | |
1694 | ||
1695 | if (strncmp (".stab", sec->name, 5)) | |
1696 | return; | |
1697 | if (!strcmp ("str", sec->name + strlen (sec->name) - 3)) | |
1698 | return; | |
1699 | ||
1700 | name = (char *) alloca (strlen (sec->name) + 4); | |
1701 | strcpy (name, sec->name); | |
1702 | strcat (name, "str"); | |
1703 | strsec = bfd_get_section_by_name (abfd, name); | |
1704 | if (strsec) | |
1705 | strsz = bfd_section_size (abfd, strsec); | |
1706 | else | |
1707 | strsz = 0; | |
1708 | nsyms = bfd_section_size (abfd, sec) / 12 - 1; | |
1709 | ||
1710 | p = seg_info (sec)->stabu.p; | |
1711 | assert (p != 0); | |
1712 | ||
1713 | bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6); | |
1714 | bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8); | |
1715 | } | |
1716 | ||
1717 | #ifdef NEED_ECOFF_DEBUG | |
1718 | ||
1719 | /* This function is called by the ECOFF code. It is supposed to | |
1720 | record the external symbol information so that the backend can | |
1721 | write it out correctly. The ELF backend doesn't actually handle | |
1722 | this at the moment, so we do it ourselves. We save the information | |
1723 | in the symbol. */ | |
1724 | ||
1725 | void | |
1726 | elf_ecoff_set_ext (sym, ext) | |
1727 | symbolS *sym; | |
1728 | struct ecoff_extr *ext; | |
1729 | { | |
49309057 | 1730 | symbol_get_bfdsym (sym)->udata.p = (PTR) ext; |
252b5132 RH |
1731 | } |
1732 | ||
1733 | /* This function is called by bfd_ecoff_debug_externals. It is | |
1734 | supposed to *EXT to the external symbol information, and return | |
1735 | whether the symbol should be used at all. */ | |
1736 | ||
b34976b6 | 1737 | static bfd_boolean |
252b5132 RH |
1738 | elf_get_extr (sym, ext) |
1739 | asymbol *sym; | |
1740 | EXTR *ext; | |
1741 | { | |
1742 | if (sym->udata.p == NULL) | |
b34976b6 | 1743 | return FALSE; |
252b5132 | 1744 | *ext = *(EXTR *) sym->udata.p; |
b34976b6 | 1745 | return TRUE; |
252b5132 RH |
1746 | } |
1747 | ||
1748 | /* This function is called by bfd_ecoff_debug_externals. It has | |
1749 | nothing to do for ELF. */ | |
1750 | ||
1751 | /*ARGSUSED*/ | |
1752 | static void | |
1753 | elf_set_index (sym, indx) | |
5f91fe03 ILT |
1754 | asymbol *sym ATTRIBUTE_UNUSED; |
1755 | bfd_size_type indx ATTRIBUTE_UNUSED; | |
252b5132 RH |
1756 | { |
1757 | } | |
1758 | ||
1759 | #endif /* NEED_ECOFF_DEBUG */ | |
1760 | ||
1761 | void | |
1762 | elf_frob_symbol (symp, puntp) | |
1763 | symbolS *symp; | |
1764 | int *puntp; | |
1765 | { | |
49309057 ILT |
1766 | struct elf_obj_sy *sy_obj; |
1767 | ||
252b5132 RH |
1768 | #ifdef NEED_ECOFF_DEBUG |
1769 | if (ECOFF_DEBUGGING) | |
1770 | ecoff_frob_symbol (symp); | |
1771 | #endif | |
1772 | ||
49309057 ILT |
1773 | sy_obj = symbol_get_obj (symp); |
1774 | ||
1775 | if (sy_obj->size != NULL) | |
252b5132 | 1776 | { |
49309057 | 1777 | switch (sy_obj->size->X_op) |
252b5132 RH |
1778 | { |
1779 | case O_subtract: | |
1780 | S_SET_SIZE (symp, | |
49309057 ILT |
1781 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1782 | + sy_obj->size->X_add_number | |
1783 | - S_GET_VALUE (sy_obj->size->X_op_symbol))); | |
252b5132 RH |
1784 | break; |
1785 | case O_constant: | |
1786 | S_SET_SIZE (symp, | |
49309057 ILT |
1787 | (S_GET_VALUE (sy_obj->size->X_add_symbol) |
1788 | + sy_obj->size->X_add_number)); | |
252b5132 RH |
1789 | break; |
1790 | default: | |
1791 | as_bad (_(".size expression too complicated to fix up")); | |
1792 | break; | |
1793 | } | |
49309057 ILT |
1794 | free (sy_obj->size); |
1795 | sy_obj->size = NULL; | |
252b5132 RH |
1796 | } |
1797 | ||
49309057 | 1798 | if (sy_obj->versioned_name != NULL) |
252b5132 | 1799 | { |
79082ff0 L |
1800 | char *p; |
1801 | ||
1802 | p = strchr (sy_obj->versioned_name, ELF_VER_CHR); | |
1803 | know (p != NULL); | |
1804 | ||
252b5132 RH |
1805 | /* This symbol was given a new name with the .symver directive. |
1806 | ||
1807 | If this is an external reference, just rename the symbol to | |
1808 | include the version string. This will make the relocs be | |
1809 | against the correct versioned symbol. | |
1810 | ||
1811 | If this is a definition, add an alias. FIXME: Using an alias | |
1812 | will permit the debugging information to refer to the right | |
1813 | symbol. However, it's not clear whether it is the best | |
1814 | approach. */ | |
1815 | ||
1816 | if (! S_IS_DEFINED (symp)) | |
1817 | { | |
252b5132 RH |
1818 | /* Verify that the name isn't using the @@ syntax--this is |
1819 | reserved for definitions of the default version to link | |
1820 | against. */ | |
252b5132 RH |
1821 | if (p[1] == ELF_VER_CHR) |
1822 | { | |
1823 | as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"), | |
49309057 | 1824 | sy_obj->versioned_name); |
b34976b6 | 1825 | *puntp = TRUE; |
252b5132 | 1826 | } |
49309057 | 1827 | S_SET_NAME (symp, sy_obj->versioned_name); |
252b5132 RH |
1828 | } |
1829 | else | |
1830 | { | |
79082ff0 L |
1831 | if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR) |
1832 | { | |
1833 | size_t l; | |
1834 | ||
1835 | /* The @@@ syntax is a special case. It renames the | |
1836 | symbol name to versioned_name with one `@' removed. */ | |
1837 | l = strlen (&p[3]) + 1; | |
1838 | memmove (&p [2], &p[3], l); | |
1839 | S_SET_NAME (symp, sy_obj->versioned_name); | |
1840 | } | |
1841 | else | |
1842 | { | |
1843 | symbolS *symp2; | |
252b5132 | 1844 | |
79082ff0 L |
1845 | /* FIXME: Creating a new symbol here is risky. We're |
1846 | in the final loop over the symbol table. We can | |
1847 | get away with it only because the symbol goes to | |
1848 | the end of the list, where the loop will still see | |
1849 | it. It would probably be better to do this in | |
1850 | obj_frob_file_before_adjust. */ | |
252b5132 | 1851 | |
79082ff0 | 1852 | symp2 = symbol_find_or_make (sy_obj->versioned_name); |
252b5132 | 1853 | |
79082ff0 | 1854 | /* Now we act as though we saw symp2 = sym. */ |
252b5132 | 1855 | |
79082ff0 | 1856 | S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp)); |
252b5132 | 1857 | |
79082ff0 L |
1858 | /* Subtracting out the frag address here is a hack |
1859 | because we are in the middle of the final loop. */ | |
1860 | S_SET_VALUE (symp2, | |
1861 | (S_GET_VALUE (symp) | |
1862 | - symbol_get_frag (symp)->fr_address)); | |
252b5132 | 1863 | |
79082ff0 | 1864 | symbol_set_frag (symp2, symbol_get_frag (symp)); |
252b5132 | 1865 | |
79082ff0 L |
1866 | /* This will copy over the size information. */ |
1867 | copy_symbol_attributes (symp2, symp); | |
252b5132 | 1868 | |
26eb4093 JJ |
1869 | S_SET_OTHER (symp2, S_GET_OTHER (symp)); |
1870 | ||
79082ff0 L |
1871 | if (S_IS_WEAK (symp)) |
1872 | S_SET_WEAK (symp2); | |
252b5132 | 1873 | |
79082ff0 L |
1874 | if (S_IS_EXTERNAL (symp)) |
1875 | S_SET_EXTERNAL (symp2); | |
1876 | } | |
252b5132 RH |
1877 | } |
1878 | } | |
1879 | ||
1880 | /* Double check weak symbols. */ | |
49309057 | 1881 | if (S_IS_WEAK (symp)) |
252b5132 RH |
1882 | { |
1883 | if (S_IS_COMMON (symp)) | |
6ce8b369 | 1884 | as_bad (_("symbol `%s' can not be both weak and common"), |
252b5132 RH |
1885 | S_GET_NAME (symp)); |
1886 | } | |
1887 | ||
1888 | #ifdef TC_MIPS | |
1889 | /* The Irix 5 and 6 assemblers set the type of any common symbol and | |
1890 | any undefined non-function symbol to STT_OBJECT. We try to be | |
1891 | compatible, since newer Irix 5 and 6 linkers care. However, we | |
1892 | only set undefined symbols to be STT_OBJECT if we are on Irix, | |
1893 | because that is the only time gcc will generate the necessary | |
1894 | .global directives to mark functions. */ | |
1895 | ||
1896 | if (S_IS_COMMON (symp)) | |
49309057 | 1897 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1898 | |
1899 | if (strstr (TARGET_OS, "irix") != NULL | |
49309057 ILT |
1900 | && ! S_IS_DEFINED (symp) |
1901 | && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0) | |
1902 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; | |
252b5132 RH |
1903 | #endif |
1904 | ||
c5e54cc2 ILT |
1905 | #if 0 /* TC_PPC */ |
1906 | /* If TC_PPC is defined, we used to force the type of a symbol to be | |
1907 | BSF_OBJECT if it was otherwise unset. This was required by some | |
1908 | version of VxWorks. Thomas de Lellis <tdel@windriver.com> says | |
1909 | that this is no longer needed, so it is now commented out. */ | |
49309057 ILT |
1910 | if ((symbol_get_bfdsym (symp)->flags |
1911 | & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0 | |
252b5132 | 1912 | && S_IS_DEFINED (symp)) |
49309057 | 1913 | symbol_get_bfdsym (symp)->flags |= BSF_OBJECT; |
252b5132 RH |
1914 | #endif |
1915 | } | |
1916 | ||
060adf0e AM |
1917 | struct group_list |
1918 | { | |
1919 | asection **head; /* Section lists. */ | |
1920 | unsigned int *elt_count; /* Number of sections in each list. */ | |
1921 | unsigned int num_group; /* Number of lists. */ | |
1922 | }; | |
1923 | ||
1924 | /* Called via bfd_map_over_sections. If SEC is a member of a group, | |
1925 | add it to a list of sections belonging to the group. INF is a | |
1926 | pointer to a struct group_list, which is where we store the head of | |
1927 | each list. */ | |
1928 | ||
1929 | static void | |
1930 | build_group_lists (abfd, sec, inf) | |
1931 | bfd *abfd ATTRIBUTE_UNUSED; | |
1932 | asection *sec; | |
1933 | PTR inf; | |
1934 | { | |
1935 | struct group_list *list = (struct group_list *) inf; | |
aa1f4858 | 1936 | const char *group_name = elf_group_name (sec); |
060adf0e AM |
1937 | unsigned int i; |
1938 | ||
1939 | if (group_name == NULL) | |
1940 | return; | |
1941 | ||
1942 | /* If this group already has a list, add the section to the head of | |
1943 | the list. */ | |
1944 | for (i = 0; i < list->num_group; i++) | |
1945 | { | |
aa1f4858 | 1946 | if (strcmp (group_name, elf_group_name (list->head[i])) == 0) |
060adf0e | 1947 | { |
aa1f4858 | 1948 | elf_next_in_group (sec) = list->head[i]; |
060adf0e AM |
1949 | list->head[i] = sec; |
1950 | list->elt_count[i] += 1; | |
1951 | return; | |
1952 | } | |
1953 | } | |
1954 | ||
1955 | /* New group. Make the arrays bigger in chunks to minimize calls to | |
1956 | realloc. */ | |
1957 | i = list->num_group; | |
1958 | if ((i & 127) == 0) | |
1959 | { | |
1960 | unsigned int newsize = i + 128; | |
1961 | list->head = xrealloc (list->head, newsize * sizeof (*list->head)); | |
1962 | list->elt_count = xrealloc (list->elt_count, | |
1963 | newsize * sizeof (*list->elt_count)); | |
1964 | } | |
1965 | list->head[i] = sec; | |
1966 | list->elt_count[i] = 1; | |
1967 | list->num_group += 1; | |
1968 | } | |
1969 | ||
252b5132 RH |
1970 | void |
1971 | elf_frob_file () | |
1972 | { | |
060adf0e AM |
1973 | struct group_list list; |
1974 | unsigned int i; | |
1975 | ||
252b5132 RH |
1976 | bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0); |
1977 | ||
060adf0e AM |
1978 | /* Go find section groups. */ |
1979 | list.num_group = 0; | |
1980 | list.head = NULL; | |
1981 | list.elt_count = NULL; | |
1982 | bfd_map_over_sections (stdoutput, build_group_lists, (PTR) &list); | |
1983 | ||
1984 | /* Make the SHT_GROUP sections that describe each section group. We | |
1985 | can't set up the section contents here yet, because elf section | |
1986 | indices have yet to be calculated. elf.c:set_group_contents does | |
1987 | the rest of the work. */ | |
1988 | for (i = 0; i < list.num_group; i++) | |
1989 | { | |
aa1f4858 | 1990 | const char *group_name = elf_group_name (list.head[i]); |
9758f3fc | 1991 | const char *sec_name; |
060adf0e AM |
1992 | asection *s; |
1993 | flagword flags; | |
9758f3fc AM |
1994 | struct symbol *sy; |
1995 | int has_sym; | |
060adf0e | 1996 | |
060adf0e | 1997 | flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP; |
d2dab548 | 1998 | for (s = list.head[i]; s != NULL; s = elf_next_in_group (s)) |
68bfbfcc | 1999 | if ((s->flags ^ flags) & SEC_LINK_ONCE) |
d2dab548 AM |
2000 | { |
2001 | flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
2002 | if (s != list.head[i]) | |
2003 | { | |
2004 | as_warn (_("assuming all members of group `%s' are COMDAT"), | |
2005 | group_name); | |
2006 | break; | |
2007 | } | |
2008 | } | |
2009 | ||
9758f3fc AM |
2010 | sec_name = group_name; |
2011 | sy = symbol_find_exact (group_name); | |
2012 | has_sym = 0; | |
2013 | if (sy != NULL | |
2014 | && (sy == symbol_lastP | |
2015 | || (sy->sy_next != NULL | |
2016 | && sy->sy_next->sy_previous == sy))) | |
2017 | { | |
2018 | has_sym = 1; | |
2019 | sec_name = ".group"; | |
2020 | } | |
2021 | s = subseg_force_new (sec_name, 0); | |
060adf0e AM |
2022 | if (s == NULL |
2023 | || !bfd_set_section_flags (stdoutput, s, flags) | |
2024 | || !bfd_set_section_alignment (stdoutput, s, 2)) | |
2025 | { | |
2026 | as_fatal (_("can't create group: %s"), | |
2027 | bfd_errmsg (bfd_get_error ())); | |
2028 | } | |
2f89ff8d | 2029 | elf_section_type (s) = SHT_GROUP; |
060adf0e | 2030 | |
aa1f4858 AM |
2031 | /* Pass a pointer to the first section in this group. */ |
2032 | elf_next_in_group (s) = list.head[i]; | |
9758f3fc AM |
2033 | if (has_sym) |
2034 | elf_group_id (s) = sy->bsym; | |
060adf0e AM |
2035 | |
2036 | s->_raw_size = 4 * (list.elt_count[i] + 1); | |
2037 | s->contents = frag_more (s->_raw_size); | |
2038 | frag_now->fr_fix = frag_now_fix_octets (); | |
2039 | } | |
2040 | ||
252b5132 RH |
2041 | #ifdef elf_tc_final_processing |
2042 | elf_tc_final_processing (); | |
2043 | #endif | |
2044 | } | |
2045 | ||
4a1805b1 | 2046 | /* It removes any unneeded versioned symbols from the symbol table. */ |
339681c0 L |
2047 | |
2048 | void | |
2049 | elf_frob_file_before_adjust () | |
2050 | { | |
2051 | if (symbol_rootP) | |
2052 | { | |
2053 | symbolS *symp; | |
2054 | ||
2055 | for (symp = symbol_rootP; symp; symp = symbol_next (symp)) | |
00e6e13d | 2056 | if (!S_IS_DEFINED (symp)) |
79082ff0 | 2057 | { |
00e6e13d | 2058 | if (symbol_get_obj (symp)->versioned_name) |
79082ff0 L |
2059 | { |
2060 | char *p; | |
2061 | ||
2062 | /* The @@@ syntax is a special case. If the symbol is | |
2063 | not defined, 2 `@'s will be removed from the | |
2064 | versioned_name. */ | |
2065 | ||
2066 | p = strchr (symbol_get_obj (symp)->versioned_name, | |
2067 | ELF_VER_CHR); | |
2068 | know (p != NULL); | |
2069 | if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR) | |
2070 | { | |
2071 | size_t l = strlen (&p[3]) + 1; | |
2072 | memmove (&p [1], &p[3], l); | |
2073 | } | |
2074 | if (symbol_used_p (symp) == 0 | |
2075 | && symbol_used_in_reloc_p (symp) == 0) | |
2076 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
2077 | } | |
00e6e13d JJ |
2078 | |
2079 | /* If there was .weak foo, but foo was neither defined nor | |
2080 | used anywhere, remove it. */ | |
2081 | ||
2082 | else if (S_IS_WEAK (symp) | |
2083 | && symbol_used_p (symp) == 0 | |
2084 | && symbol_used_in_reloc_p (symp) == 0) | |
2085 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
79082ff0 | 2086 | } |
339681c0 L |
2087 | } |
2088 | } | |
2089 | ||
252b5132 RH |
2090 | /* It is required that we let write_relocs have the opportunity to |
2091 | optimize away fixups before output has begun, since it is possible | |
2092 | to eliminate all fixups for a section and thus we never should | |
2093 | have generated the relocation section. */ | |
2094 | ||
2095 | void | |
2096 | elf_frob_file_after_relocs () | |
2097 | { | |
2098 | #ifdef NEED_ECOFF_DEBUG | |
2099 | if (ECOFF_DEBUGGING) | |
2100 | /* Generate the ECOFF debugging information. */ | |
2101 | { | |
2102 | const struct ecoff_debug_swap *debug_swap; | |
2103 | struct ecoff_debug_info debug; | |
2104 | char *buf; | |
2105 | asection *sec; | |
2106 | ||
2107 | debug_swap | |
2108 | = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap; | |
2109 | know (debug_swap != (const struct ecoff_debug_swap *) NULL); | |
2110 | ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap); | |
2111 | ||
2112 | /* Set up the pointers in debug. */ | |
2113 | #define SET(ptr, offset, type) \ | |
2114 | debug.ptr = (type) (buf + debug.symbolic_header.offset) | |
2115 | ||
2116 | SET (line, cbLineOffset, unsigned char *); | |
2117 | SET (external_dnr, cbDnOffset, PTR); | |
2118 | SET (external_pdr, cbPdOffset, PTR); | |
2119 | SET (external_sym, cbSymOffset, PTR); | |
2120 | SET (external_opt, cbOptOffset, PTR); | |
2121 | SET (external_aux, cbAuxOffset, union aux_ext *); | |
2122 | SET (ss, cbSsOffset, char *); | |
2123 | SET (external_fdr, cbFdOffset, PTR); | |
2124 | SET (external_rfd, cbRfdOffset, PTR); | |
2125 | /* ssext and external_ext are set up just below. */ | |
2126 | ||
2127 | #undef SET | |
2128 | ||
2129 | /* Set up the external symbols. */ | |
2130 | debug.ssext = debug.ssext_end = NULL; | |
2131 | debug.external_ext = debug.external_ext_end = NULL; | |
b34976b6 | 2132 | if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, TRUE, |
252b5132 | 2133 | elf_get_extr, elf_set_index)) |
6ce8b369 | 2134 | as_fatal (_("failed to set up debugging information: %s"), |
252b5132 RH |
2135 | bfd_errmsg (bfd_get_error ())); |
2136 | ||
2137 | sec = bfd_get_section_by_name (stdoutput, ".mdebug"); | |
2138 | assert (sec != NULL); | |
2139 | ||
b34976b6 | 2140 | know (!stdoutput->output_has_begun); |
252b5132 RH |
2141 | |
2142 | /* We set the size of the section, call bfd_set_section_contents | |
2143 | to force the ELF backend to allocate a file position, and then | |
2144 | write out the data. FIXME: Is this really the best way to do | |
2145 | this? */ | |
2146 | sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap); | |
2147 | ||
5f91fe03 ILT |
2148 | /* Pass BUF to bfd_set_section_contents because this will |
2149 | eventually become a call to fwrite, and ISO C prohibits | |
2150 | passing a NULL pointer to a stdio function even if the | |
2151 | pointer will not be used. */ | |
2152 | if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf, | |
252b5132 | 2153 | (file_ptr) 0, (bfd_size_type) 0)) |
6ce8b369 | 2154 | as_fatal (_("can't start writing .mdebug section: %s"), |
252b5132 RH |
2155 | bfd_errmsg (bfd_get_error ())); |
2156 | ||
b34976b6 | 2157 | know (stdoutput->output_has_begun); |
252b5132 RH |
2158 | know (sec->filepos != 0); |
2159 | ||
2160 | if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap, | |
2161 | sec->filepos)) | |
6ce8b369 | 2162 | as_fatal (_("could not write .mdebug section: %s"), |
252b5132 RH |
2163 | bfd_errmsg (bfd_get_error ())); |
2164 | } | |
2165 | #endif /* NEED_ECOFF_DEBUG */ | |
2166 | } | |
2167 | ||
2168 | #ifdef SCO_ELF | |
2169 | ||
2170 | /* Heavily plagarized from obj_elf_version. The idea is to emit the | |
2171 | SCO specific identifier in the .notes section to satisfy the SCO | |
2172 | linker. | |
2173 | ||
2174 | This looks more complicated than it really is. As opposed to the | |
2175 | "obvious" solution, this should handle the cross dev cases | |
2176 | correctly. (i.e, hosting on a 64 bit big endian processor, but | |
2177 | generating SCO Elf code) Efficiency isn't a concern, as there | |
2178 | should be exactly one of these sections per object module. | |
2179 | ||
2180 | SCO OpenServer 5 identifies it's ELF modules with a standard ELF | |
2181 | .note section. | |
2182 | ||
fa306131 AM |
2183 | int_32 namesz = 4 ; Name size |
2184 | int_32 descsz = 12 ; Descriptive information | |
2185 | int_32 type = 1 ; | |
2186 | char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL | |
252b5132 RH |
2187 | int_32 version = (major ver # << 16) | version of tools ; |
2188 | int_32 source = (tool_id << 16 ) | 1 ; | |
2189 | int_32 info = 0 ; These are set by the SCO tools, but we | |
fa306131 | 2190 | don't know enough about the source |
252b5132 RH |
2191 | environment to set them. SCO ld currently |
2192 | ignores them, and recommends we set them | |
2193 | to zero. */ | |
2194 | ||
2195 | #define SCO_MAJOR_VERSION 0x1 | |
2196 | #define SCO_MINOR_VERSION 0x1 | |
2197 | ||
2198 | void | |
2199 | sco_id () | |
2200 | { | |
2201 | ||
2202 | char *name; | |
2203 | unsigned int c; | |
2204 | char ch; | |
2205 | char *p; | |
2206 | asection *seg = now_seg; | |
2207 | subsegT subseg = now_subseg; | |
2208 | Elf_Internal_Note i_note; | |
2209 | Elf_External_Note e_note; | |
2210 | asection *note_secp = (asection *) NULL; | |
2211 | int i, len; | |
2212 | ||
2213 | /* create the .note section */ | |
2214 | ||
2215 | note_secp = subseg_new (".note", 0); | |
2216 | bfd_set_section_flags (stdoutput, | |
2217 | note_secp, | |
2218 | SEC_HAS_CONTENTS | SEC_READONLY); | |
2219 | ||
2220 | /* process the version string */ | |
2221 | ||
fa306131 | 2222 | i_note.namesz = 4; |
252b5132 RH |
2223 | i_note.descsz = 12; /* 12 descriptive bytes */ |
2224 | i_note.type = NT_VERSION; /* Contains a version string */ | |
2225 | ||
2226 | p = frag_more (sizeof (i_note.namesz)); | |
2227 | md_number_to_chars (p, (valueT) i_note.namesz, 4); | |
2228 | ||
2229 | p = frag_more (sizeof (i_note.descsz)); | |
2230 | md_number_to_chars (p, (valueT) i_note.descsz, 4); | |
2231 | ||
2232 | p = frag_more (sizeof (i_note.type)); | |
2233 | md_number_to_chars (p, (valueT) i_note.type, 4); | |
2234 | ||
2235 | p = frag_more (4); | |
fa306131 | 2236 | strcpy (p, "SCO"); |
252b5132 RH |
2237 | |
2238 | /* Note: this is the version number of the ELF we're representing */ | |
2239 | p = frag_more (4); | |
2240 | md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4); | |
2241 | ||
2242 | /* Here, we pick a magic number for ourselves (yes, I "registered" | |
2243 | it with SCO. The bottom bit shows that we are compat with the | |
2244 | SCO ABI. */ | |
2245 | p = frag_more (4); | |
2246 | md_number_to_chars (p, 0x4c520000 | 0x0001, 4); | |
2247 | ||
2248 | /* If we knew (or cared) what the source language options were, we'd | |
2249 | fill them in here. SCO has given us permission to ignore these | |
2250 | and just set them to zero. */ | |
2251 | p = frag_more (4); | |
2252 | md_number_to_chars (p, 0x0000, 4); | |
fa306131 | 2253 | |
252b5132 RH |
2254 | frag_align (2, 0, 0); |
2255 | ||
2256 | /* We probably can't restore the current segment, for there likely | |
2257 | isn't one yet... */ | |
2258 | if (seg && subseg) | |
2259 | subseg_set (seg, subseg); | |
2260 | ||
2261 | } | |
2262 | ||
2263 | #endif /* SCO_ELF */ | |
2264 | ||
5110c57e HPN |
2265 | static int |
2266 | elf_separate_stab_sections () | |
2267 | { | |
2268 | #ifdef NEED_ECOFF_DEBUG | |
2269 | return (!ECOFF_DEBUGGING); | |
2270 | #else | |
2271 | return 1; | |
2272 | #endif | |
2273 | } | |
2274 | ||
2275 | static void | |
2276 | elf_init_stab_section (seg) | |
2277 | segT seg; | |
2278 | { | |
2279 | #ifdef NEED_ECOFF_DEBUG | |
2280 | if (!ECOFF_DEBUGGING) | |
2281 | #endif | |
2282 | obj_elf_init_stab_section (seg); | |
2283 | } | |
2284 | ||
252b5132 RH |
2285 | const struct format_ops elf_format_ops = |
2286 | { | |
2287 | bfd_target_elf_flavour, | |
4c63da97 AM |
2288 | 0, /* dfl_leading_underscore */ |
2289 | 1, /* emit_section_symbols */ | |
5110c57e HPN |
2290 | elf_begin, |
2291 | elf_file_symbol, | |
252b5132 RH |
2292 | elf_frob_symbol, |
2293 | elf_frob_file, | |
339681c0 | 2294 | elf_frob_file_before_adjust, |
a161fe53 | 2295 | 0, /* obj_frob_file_before_fix */ |
252b5132 RH |
2296 | elf_frob_file_after_relocs, |
2297 | elf_s_get_size, elf_s_set_size, | |
2298 | elf_s_get_align, elf_s_set_align, | |
4c63da97 | 2299 | elf_s_get_other, |
5110c57e | 2300 | elf_s_set_other, |
4c63da97 | 2301 | 0, /* s_get_desc */ |
5110c57e HPN |
2302 | 0, /* s_set_desc */ |
2303 | 0, /* s_get_type */ | |
2304 | 0, /* s_set_type */ | |
252b5132 RH |
2305 | elf_copy_symbol_attributes, |
2306 | #ifdef NEED_ECOFF_DEBUG | |
2307 | ecoff_generate_asm_lineno, | |
2308 | ecoff_stab, | |
2309 | #else | |
4c63da97 AM |
2310 | 0, /* generate_asm_lineno */ |
2311 | 0, /* process_stab */ | |
252b5132 | 2312 | #endif |
5110c57e HPN |
2313 | elf_separate_stab_sections, |
2314 | elf_init_stab_section, | |
252b5132 RH |
2315 | elf_sec_sym_ok_for_reloc, |
2316 | elf_pop_insert, | |
2317 | #ifdef NEED_ECOFF_DEBUG | |
2318 | elf_ecoff_set_ext, | |
2319 | #else | |
4c63da97 | 2320 | 0, /* ecoff_set_ext */ |
252b5132 | 2321 | #endif |
4c63da97 | 2322 | elf_obj_read_begin_hook, |
5110c57e | 2323 | elf_obj_symbol_new_hook |
252b5132 | 2324 | }; |