Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* ELF object file format |
b3adc24a | 2 | Copyright (C) 1992-2020 Free Software Foundation, Inc. |
252b5132 RH |
3 | |
4 | This file is part of GAS, the GNU Assembler. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as | |
ec2655a6 | 8 | published by the Free Software Foundation; either version 3, |
252b5132 RH |
9 | or (at your option) any later version. |
10 | ||
11 | GAS is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | |
14 | the GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
18 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
19 | 02110-1301, USA. */ | |
252b5132 RH |
20 | |
21 | #define OBJ_HEADER "obj-elf.h" | |
22 | #include "as.h" | |
3882b010 | 23 | #include "safe-ctype.h" |
252b5132 RH |
24 | #include "subsegs.h" |
25 | #include "obstack.h" | |
87ccc1b0 | 26 | #include "dwarf2dbg.h" |
252b5132 RH |
27 | |
28 | #ifndef ECOFF_DEBUGGING | |
29 | #define ECOFF_DEBUGGING 0 | |
30 | #else | |
31 | #define NEED_ECOFF_DEBUG | |
32 | #endif | |
33 | ||
34 | #ifdef NEED_ECOFF_DEBUG | |
35 | #include "ecoff.h" | |
0ba9378a | 36 | #include "bfd/ecoff-bfd.h" |
252b5132 RH |
37 | #endif |
38 | ||
39 | #ifdef TC_ALPHA | |
40 | #include "elf/alpha.h" | |
41 | #endif | |
42 | ||
43 | #ifdef TC_MIPS | |
44 | #include "elf/mips.h" | |
45 | #endif | |
46 | ||
47 | #ifdef TC_PPC | |
48 | #include "elf/ppc.h" | |
49 | #endif | |
50 | ||
3b22753a L |
51 | #ifdef TC_I386 |
52 | #include "elf/x86-64.h" | |
53 | #endif | |
54 | ||
280d71bf DB |
55 | #ifdef TC_MEP |
56 | #include "elf/mep.h" | |
57 | #endif | |
58 | ||
36591ba1 SL |
59 | #ifdef TC_NIOS2 |
60 | #include "elf/nios2.h" | |
61 | #endif | |
62 | ||
93f11b16 DD |
63 | #ifdef TC_PRU |
64 | #include "elf/pru.h" | |
65 | #endif | |
66 | ||
dbe2df79 AM |
67 | static void obj_elf_line (int); |
68 | static void obj_elf_size (int); | |
69 | static void obj_elf_type (int); | |
70 | static void obj_elf_ident (int); | |
71 | static void obj_elf_weak (int); | |
72 | static void obj_elf_local (int); | |
73 | static void obj_elf_visibility (int); | |
74 | static void obj_elf_symver (int); | |
75 | static void obj_elf_subsection (int); | |
76 | static void obj_elf_popsection (int); | |
0420f52b | 77 | static void obj_elf_gnu_attribute (int); |
dbe2df79 | 78 | static void obj_elf_tls_common (int); |
13c56984 | 79 | static void obj_elf_lcomm (int); |
8fe53b44 | 80 | static void obj_elf_struct (int); |
252b5132 RH |
81 | |
82 | static const pseudo_typeS elf_pseudo_table[] = | |
83 | { | |
84 | {"comm", obj_elf_common, 0}, | |
9be1cda6 | 85 | {"common", obj_elf_common, 1}, |
252b5132 | 86 | {"ident", obj_elf_ident, 0}, |
13c56984 | 87 | {"lcomm", obj_elf_lcomm, 0}, |
252b5132 RH |
88 | {"local", obj_elf_local, 0}, |
89 | {"previous", obj_elf_previous, 0}, | |
90 | {"section", obj_elf_section, 0}, | |
91 | {"section.s", obj_elf_section, 0}, | |
92 | {"sect", obj_elf_section, 0}, | |
93 | {"sect.s", obj_elf_section, 0}, | |
9de8d8f1 RH |
94 | {"pushsection", obj_elf_section, 1}, |
95 | {"popsection", obj_elf_popsection, 0}, | |
252b5132 RH |
96 | {"size", obj_elf_size, 0}, |
97 | {"type", obj_elf_type, 0}, | |
98 | {"version", obj_elf_version, 0}, | |
99 | {"weak", obj_elf_weak, 0}, | |
100 | ||
bf514e21 | 101 | /* These define symbol visibility. */ |
2e13b764 NC |
102 | {"internal", obj_elf_visibility, STV_INTERNAL}, |
103 | {"hidden", obj_elf_visibility, STV_HIDDEN}, | |
104 | {"protected", obj_elf_visibility, STV_PROTECTED}, | |
105 | ||
252b5132 RH |
106 | /* These are used for stabs-in-elf configurations. */ |
107 | {"line", obj_elf_line, 0}, | |
108 | ||
109 | /* This is a GNU extension to handle symbol versions. */ | |
110 | {"symver", obj_elf_symver, 0}, | |
111 | ||
112 | /* A GNU extension to change subsection only. */ | |
113 | {"subsection", obj_elf_subsection, 0}, | |
114 | ||
115 | /* These are GNU extensions to aid in garbage collecting C++ vtables. */ | |
68d20676 NC |
116 | {"vtable_inherit", obj_elf_vtable_inherit, 0}, |
117 | {"vtable_entry", obj_elf_vtable_entry, 0}, | |
252b5132 | 118 | |
0420f52b MR |
119 | /* A GNU extension for object attributes. */ |
120 | {"gnu_attribute", obj_elf_gnu_attribute, 0}, | |
121 | ||
bf514e21 | 122 | /* These are used for dwarf. */ |
252b5132 RH |
123 | {"2byte", cons, 2}, |
124 | {"4byte", cons, 4}, | |
125 | {"8byte", cons, 8}, | |
87ccc1b0 | 126 | /* These are used for dwarf2. */ |
68d20676 | 127 | { "file", dwarf2_directive_file, 0 }, |
87ccc1b0 | 128 | { "loc", dwarf2_directive_loc, 0 }, |
07a53e5c | 129 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, |
252b5132 RH |
130 | |
131 | /* We need to trap the section changing calls to handle .previous. */ | |
132 | {"data", obj_elf_data, 0}, | |
8fe53b44 JB |
133 | {"offset", obj_elf_struct, 0}, |
134 | {"struct", obj_elf_struct, 0}, | |
252b5132 RH |
135 | {"text", obj_elf_text, 0}, |
136 | ||
13ae64f3 JJ |
137 | {"tls_common", obj_elf_tls_common, 0}, |
138 | ||
252b5132 | 139 | /* End sentinel. */ |
ab9da554 | 140 | {NULL, NULL, 0}, |
252b5132 RH |
141 | }; |
142 | ||
143 | static const pseudo_typeS ecoff_debug_pseudo_table[] = | |
144 | { | |
145 | #ifdef NEED_ECOFF_DEBUG | |
146 | /* COFF style debugging information for ECOFF. .ln is not used; .loc | |
147 | is used instead. */ | |
148 | { "def", ecoff_directive_def, 0 }, | |
149 | { "dim", ecoff_directive_dim, 0 }, | |
150 | { "endef", ecoff_directive_endef, 0 }, | |
151 | { "file", ecoff_directive_file, 0 }, | |
152 | { "scl", ecoff_directive_scl, 0 }, | |
153 | { "tag", ecoff_directive_tag, 0 }, | |
154 | { "val", ecoff_directive_val, 0 }, | |
155 | ||
156 | /* COFF debugging requires pseudo-ops .size and .type, but ELF | |
157 | already has meanings for those. We use .esize and .etype | |
158 | instead. These are only generated by gcc anyhow. */ | |
159 | { "esize", ecoff_directive_size, 0 }, | |
160 | { "etype", ecoff_directive_type, 0 }, | |
161 | ||
162 | /* ECOFF specific debugging information. */ | |
37f9ec62 | 163 | { "aent", ecoff_directive_ent, 1 }, |
252b5132 RH |
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 | ||
3b22753a L |
194 | asection *elf_com_section_ptr; |
195 | ||
252b5132 | 196 | void |
dbe2df79 | 197 | elf_begin (void) |
252b5132 | 198 | { |
dbe2df79 AM |
199 | asection *s; |
200 | ||
252b5132 | 201 | /* Add symbols for the known sections to the symbol table. */ |
dbe2df79 AM |
202 | s = bfd_get_section_by_name (stdoutput, TEXT_SECTION_NAME); |
203 | symbol_table_insert (section_symbol (s)); | |
204 | s = bfd_get_section_by_name (stdoutput, DATA_SECTION_NAME); | |
205 | symbol_table_insert (section_symbol (s)); | |
206 | s = bfd_get_section_by_name (stdoutput, BSS_SECTION_NAME); | |
207 | symbol_table_insert (section_symbol (s)); | |
3b22753a | 208 | elf_com_section_ptr = bfd_com_section_ptr; |
252b5132 RH |
209 | } |
210 | ||
211 | void | |
dbe2df79 | 212 | elf_pop_insert (void) |
252b5132 RH |
213 | { |
214 | pop_insert (elf_pseudo_table); | |
215 | if (ECOFF_DEBUGGING) | |
216 | pop_insert (ecoff_debug_pseudo_table); | |
217 | } | |
218 | ||
219 | static bfd_vma | |
dbe2df79 | 220 | elf_s_get_size (symbolS *sym) |
252b5132 RH |
221 | { |
222 | return S_GET_SIZE (sym); | |
223 | } | |
224 | ||
225 | static void | |
dbe2df79 | 226 | elf_s_set_size (symbolS *sym, bfd_vma sz) |
252b5132 RH |
227 | { |
228 | S_SET_SIZE (sym, sz); | |
229 | } | |
230 | ||
231 | static bfd_vma | |
dbe2df79 | 232 | elf_s_get_align (symbolS *sym) |
252b5132 RH |
233 | { |
234 | return S_GET_ALIGN (sym); | |
235 | } | |
236 | ||
237 | static void | |
dbe2df79 | 238 | elf_s_set_align (symbolS *sym, bfd_vma align) |
252b5132 RH |
239 | { |
240 | S_SET_ALIGN (sym, align); | |
241 | } | |
242 | ||
4c63da97 | 243 | int |
dbe2df79 | 244 | elf_s_get_other (symbolS *sym) |
4c63da97 AM |
245 | { |
246 | return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other; | |
247 | } | |
248 | ||
5110c57e | 249 | static void |
dbe2df79 | 250 | elf_s_set_other (symbolS *sym, int other) |
5110c57e HPN |
251 | { |
252 | S_SET_OTHER (sym, other); | |
253 | } | |
254 | ||
252b5132 | 255 | static int |
dbe2df79 | 256 | elf_sec_sym_ok_for_reloc (asection *sec) |
252b5132 RH |
257 | { |
258 | return obj_sec_sym_ok_for_reloc (sec); | |
259 | } | |
260 | ||
261 | void | |
c04f5787 | 262 | elf_file_symbol (const char *s, int appfile) |
252b5132 | 263 | { |
8d1015a8 AM |
264 | asymbol *bsym; |
265 | ||
c04f5787 AM |
266 | if (!appfile |
267 | || symbol_rootP == NULL | |
8d1015a8 AM |
268 | || (bsym = symbol_get_bfdsym (symbol_rootP)) == NULL |
269 | || (bsym->flags & BSF_FILE) == 0) | |
c04f5787 AM |
270 | { |
271 | symbolS *sym; | |
e57e6ddc | 272 | size_t name_length; |
252b5132 | 273 | |
c04f5787 AM |
274 | sym = symbol_new (s, absolute_section, 0, NULL); |
275 | symbol_set_frag (sym, &zero_address_frag); | |
efa19bfd JB |
276 | |
277 | name_length = strlen (s); | |
278 | if (name_length > strlen (S_GET_NAME (sym))) | |
279 | { | |
280 | obstack_grow (¬es, s, name_length + 1); | |
1e9cc1c2 | 281 | S_SET_NAME (sym, (const char *) obstack_finish (¬es)); |
efa19bfd JB |
282 | } |
283 | else | |
284 | strcpy ((char *) S_GET_NAME (sym), s); | |
285 | ||
c04f5787 | 286 | symbol_get_bfdsym (sym)->flags |= BSF_FILE; |
252b5132 | 287 | |
fbdf9406 | 288 | if (symbol_rootP != sym |
8d1015a8 AM |
289 | && ((bsym = symbol_get_bfdsym (symbol_rootP)) == NULL |
290 | || (bsym->flags & BSF_FILE) == 0)) | |
c04f5787 AM |
291 | { |
292 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
293 | symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP); | |
fbdf9406 JB |
294 | } |
295 | ||
252b5132 | 296 | #ifdef DEBUG |
fbdf9406 | 297 | verify_symbol_chain (symbol_rootP, symbol_lastP); |
252b5132 RH |
298 | #endif |
299 | } | |
300 | ||
301 | #ifdef NEED_ECOFF_DEBUG | |
f17c130b | 302 | ecoff_new_file (s, appfile); |
252b5132 RH |
303 | #endif |
304 | } | |
305 | ||
e13bab5a AM |
306 | /* Called from read.c:s_comm after we've parsed .comm symbol, size. |
307 | Parse a possible alignment value. */ | |
308 | ||
3b22753a | 309 | symbolS * |
e13bab5a | 310 | elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP, addressT size) |
252b5132 | 311 | { |
e13bab5a AM |
312 | addressT align = 0; |
313 | int is_local = symbol_get_obj (symbolP)->local; | |
252b5132 | 314 | |
e13bab5a | 315 | if (*input_line_pointer == ',') |
9be1cda6 | 316 | { |
e13bab5a | 317 | char *save = input_line_pointer; |
9be1cda6 | 318 | |
252b5132 RH |
319 | input_line_pointer++; |
320 | SKIP_WHITESPACE (); | |
e13bab5a AM |
321 | |
322 | if (*input_line_pointer == '"') | |
252b5132 | 323 | { |
e13bab5a AM |
324 | /* For sparc. Accept .common symbol, length, "bss" */ |
325 | input_line_pointer++; | |
326 | /* Some use the dot, some don't. */ | |
327 | if (*input_line_pointer == '.') | |
328 | input_line_pointer++; | |
329 | /* Some say data, some say bss. */ | |
330 | if (strncmp (input_line_pointer, "bss\"", 4) == 0) | |
331 | input_line_pointer += 4; | |
332 | else if (strncmp (input_line_pointer, "data\"", 5) == 0) | |
333 | input_line_pointer += 5; | |
334 | else | |
252b5132 | 335 | { |
e13bab5a AM |
336 | char *p = input_line_pointer; |
337 | char c; | |
338 | ||
339 | while (*--p != '"') | |
340 | ; | |
341 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) | |
342 | if (*input_line_pointer++ == '"') | |
343 | break; | |
344 | c = *input_line_pointer; | |
345 | *input_line_pointer = '\0'; | |
346 | as_bad (_("bad .common segment %s"), p); | |
347 | *input_line_pointer = c; | |
348 | ignore_rest_of_line (); | |
349 | return NULL; | |
252b5132 | 350 | } |
e13bab5a AM |
351 | /* ??? Don't ask me why these are always global. */ |
352 | is_local = 0; | |
252b5132 RH |
353 | } |
354 | else | |
355 | { | |
e13bab5a AM |
356 | input_line_pointer = save; |
357 | align = parse_align (is_local); | |
358 | if (align == (addressT) -1) | |
359 | return NULL; | |
252b5132 RH |
360 | } |
361 | } | |
e13bab5a AM |
362 | |
363 | if (is_local) | |
364 | { | |
365 | bss_alloc (symbolP, size, align); | |
366 | S_CLEAR_EXTERNAL (symbolP); | |
367 | } | |
252b5132 RH |
368 | else |
369 | { | |
e13bab5a AM |
370 | S_SET_VALUE (symbolP, size); |
371 | S_SET_ALIGN (symbolP, align); | |
372 | S_SET_EXTERNAL (symbolP); | |
3b22753a | 373 | S_SET_SEGMENT (symbolP, elf_com_section_ptr); |
252b5132 RH |
374 | } |
375 | ||
49309057 | 376 | symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; |
252b5132 | 377 | |
13ae64f3 | 378 | return symbolP; |
252b5132 RH |
379 | } |
380 | ||
13ae64f3 | 381 | void |
dbe2df79 | 382 | obj_elf_common (int is_common) |
13ae64f3 | 383 | { |
e13bab5a AM |
384 | if (flag_mri && is_common) |
385 | s_mri_common (0); | |
386 | else | |
387 | s_comm_internal (0, elf_common_parse); | |
13ae64f3 JJ |
388 | } |
389 | ||
390 | static void | |
dbe2df79 | 391 | obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED) |
13ae64f3 | 392 | { |
e13bab5a | 393 | symbolS *symbolP = s_comm_internal (0, elf_common_parse); |
13ae64f3 JJ |
394 | |
395 | if (symbolP) | |
396 | symbol_get_bfdsym (symbolP)->flags |= BSF_THREAD_LOCAL; | |
397 | } | |
398 | ||
13c56984 AM |
399 | static void |
400 | obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED) | |
401 | { | |
402 | symbolS *symbolP = s_comm_internal (0, s_lcomm_internal); | |
403 | ||
404 | if (symbolP) | |
405 | symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; | |
406 | } | |
407 | ||
6e8bd58f NS |
408 | static symbolS * |
409 | get_sym_from_input_line_and_check (void) | |
410 | { | |
411 | char *name; | |
412 | char c; | |
413 | symbolS *sym; | |
414 | ||
d02603dc | 415 | c = get_symbol_name (& name); |
6e8bd58f NS |
416 | sym = symbol_find_or_make (name); |
417 | *input_line_pointer = c; | |
d02603dc | 418 | SKIP_WHITESPACE_AFTER_NAME (); |
6e8bd58f NS |
419 | |
420 | /* There is no symbol name if input_line_pointer has not moved. */ | |
421 | if (name == input_line_pointer) | |
422 | as_bad (_("Missing symbol name in directive")); | |
423 | return sym; | |
424 | } | |
425 | ||
252b5132 | 426 | static void |
dbe2df79 | 427 | obj_elf_local (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 428 | { |
252b5132 RH |
429 | int c; |
430 | symbolS *symbolP; | |
431 | ||
432 | do | |
433 | { | |
01642c12 | 434 | symbolP = get_sym_from_input_line_and_check (); |
6e8bd58f | 435 | c = *input_line_pointer; |
252b5132 | 436 | S_CLEAR_EXTERNAL (symbolP); |
49309057 | 437 | symbol_get_obj (symbolP)->local = 1; |
252b5132 RH |
438 | if (c == ',') |
439 | { | |
440 | input_line_pointer++; | |
441 | SKIP_WHITESPACE (); | |
442 | if (*input_line_pointer == '\n') | |
443 | c = '\n'; | |
444 | } | |
445 | } | |
446 | while (c == ','); | |
447 | demand_empty_rest_of_line (); | |
448 | } | |
449 | ||
450 | static void | |
dbe2df79 | 451 | obj_elf_weak (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 452 | { |
252b5132 RH |
453 | int c; |
454 | symbolS *symbolP; | |
455 | ||
456 | do | |
457 | { | |
01642c12 | 458 | symbolP = get_sym_from_input_line_and_check (); |
6e8bd58f | 459 | c = *input_line_pointer; |
252b5132 | 460 | S_SET_WEAK (symbolP); |
252b5132 RH |
461 | if (c == ',') |
462 | { | |
463 | input_line_pointer++; | |
464 | SKIP_WHITESPACE (); | |
465 | if (*input_line_pointer == '\n') | |
466 | c = '\n'; | |
467 | } | |
468 | } | |
469 | while (c == ','); | |
470 | demand_empty_rest_of_line (); | |
471 | } | |
472 | ||
2e13b764 | 473 | static void |
dbe2df79 | 474 | obj_elf_visibility (int visibility) |
2e13b764 | 475 | { |
2e13b764 NC |
476 | int c; |
477 | symbolS *symbolP; | |
478 | asymbol *bfdsym; | |
479 | elf_symbol_type *elfsym; | |
480 | ||
481 | do | |
482 | { | |
6e8bd58f | 483 | symbolP = get_sym_from_input_line_and_check (); |
fa306131 | 484 | |
2e13b764 NC |
485 | bfdsym = symbol_get_bfdsym (symbolP); |
486 | elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym); | |
fa306131 | 487 | |
9c2799c2 | 488 | gas_assert (elfsym); |
fa306131 | 489 | |
20e420c2 RH |
490 | elfsym->internal_elf_sym.st_other &= ~3; |
491 | elfsym->internal_elf_sym.st_other |= visibility; | |
fa306131 | 492 | |
6e8bd58f | 493 | c = *input_line_pointer; |
2e13b764 NC |
494 | if (c == ',') |
495 | { | |
496 | input_line_pointer ++; | |
fa306131 | 497 | |
2e13b764 | 498 | SKIP_WHITESPACE (); |
fa306131 | 499 | |
2e13b764 NC |
500 | if (*input_line_pointer == '\n') |
501 | c = '\n'; | |
502 | } | |
503 | } | |
504 | while (c == ','); | |
fa306131 | 505 | |
2e13b764 NC |
506 | demand_empty_rest_of_line (); |
507 | } | |
508 | ||
252b5132 RH |
509 | static segT previous_section; |
510 | static int previous_subsection; | |
511 | ||
9de8d8f1 RH |
512 | struct section_stack |
513 | { | |
514 | struct section_stack *next; | |
515 | segT seg, prev_seg; | |
516 | int subseg, prev_subseg; | |
517 | }; | |
518 | ||
519 | static struct section_stack *section_stack; | |
520 | ||
fafe6678 | 521 | static bfd_boolean |
86654c12 L |
522 | get_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *inf) |
523 | { | |
a8c4d40b | 524 | struct elf_section_match *match = (struct elf_section_match *) inf; |
a91e1603 | 525 | const char *gname = match->group_name; |
86654c12 | 526 | const char *group_name = elf_group_name (sec); |
b7d07216 L |
527 | const char *linked_to_symbol_name |
528 | = sec->map_head.linked_to_symbol_name; | |
a91e1603 | 529 | unsigned int info = elf_section_data (sec)->this_hdr.sh_info; |
01fb1836 | 530 | |
a91e1603 | 531 | return (info == match->info |
a8c4d40b L |
532 | && ((bfd_section_flags (sec) & SEC_ASSEMBLER_SECTION_ID) |
533 | == (match->flags & SEC_ASSEMBLER_SECTION_ID)) | |
534 | && sec->section_id == match->section_id | |
a91e1603 L |
535 | && (group_name == gname |
536 | || (group_name != NULL | |
537 | && gname != NULL | |
b7d07216 L |
538 | && strcmp (group_name, gname) == 0)) |
539 | && (linked_to_symbol_name == match->linked_to_symbol_name | |
540 | || (linked_to_symbol_name != NULL | |
541 | && match->linked_to_symbol_name != NULL | |
542 | && strcmp (linked_to_symbol_name, | |
543 | match->linked_to_symbol_name) == 0))); | |
86654c12 L |
544 | } |
545 | ||
252b5132 RH |
546 | /* Handle the .section pseudo-op. This code supports two different |
547 | syntaxes. | |
548 | ||
549 | The first is found on Solaris, and looks like | |
550 | .section ".sec1",#alloc,#execinstr,#write | |
551 | Here the names after '#' are the SHF_* flags to turn on for the | |
552 | section. I'm not sure how it determines the SHT_* type (BFD | |
553 | doesn't really give us control over the type, anyhow). | |
554 | ||
555 | The second format is found on UnixWare, and probably most SVR4 | |
556 | machines, and looks like | |
557 | .section .sec1,"a",@progbits | |
558 | The quoted string may contain any combination of a, w, x, and | |
559 | represents the SHF_* flags to turn on for the section. The string | |
560 | beginning with '@' can be progbits or nobits. There should be | |
561 | other possibilities, but I don't know what they are. In any case, | |
562 | BFD doesn't really let us set the section type. */ | |
563 | ||
cca86cc8 | 564 | void |
dbe2df79 | 565 | obj_elf_change_section (const char *name, |
9fb71ee4 | 566 | unsigned int type, |
01e1a5bc | 567 | bfd_vma attr, |
dbe2df79 | 568 | int entsize, |
a8c4d40b | 569 | struct elf_section_match *match_p, |
dbe2df79 AM |
570 | int linkonce, |
571 | int push) | |
252b5132 | 572 | { |
fafe6678 | 573 | asection *old_sec; |
252b5132 | 574 | segT sec; |
742f45cf | 575 | flagword flags; |
551b43fd | 576 | const struct elf_backend_data *bed; |
f61e8019 | 577 | const struct bfd_elf_special_section *ssect; |
a8c4d40b L |
578 | |
579 | if (match_p == NULL) | |
580 | { | |
581 | static struct elf_section_match unused_match; | |
582 | match_p = &unused_match; | |
583 | } | |
252b5132 RH |
584 | |
585 | #ifdef md_flush_pending_output | |
586 | md_flush_pending_output (); | |
587 | #endif | |
588 | ||
9de8d8f1 RH |
589 | /* Switch to the section, creating it if necessary. */ |
590 | if (push) | |
591 | { | |
592 | struct section_stack *elt; | |
325801bd | 593 | elt = XNEW (struct section_stack); |
9de8d8f1 RH |
594 | elt->next = section_stack; |
595 | elt->seg = now_seg; | |
596 | elt->prev_seg = previous_section; | |
597 | elt->subseg = now_subseg; | |
598 | elt->prev_subseg = previous_subsection; | |
599 | section_stack = elt; | |
600 | } | |
601 | previous_section = now_seg; | |
602 | previous_subsection = now_subseg; | |
603 | ||
fafe6678 | 604 | old_sec = bfd_get_section_by_name_if (stdoutput, name, get_section, |
a8c4d40b | 605 | (void *) match_p); |
fafe6678 | 606 | if (old_sec) |
86654c12 | 607 | { |
fafe6678 | 608 | sec = old_sec; |
86654c12 L |
609 | subseg_set (sec, 0); |
610 | } | |
611 | else | |
612 | sec = subseg_force_new (name, 0); | |
613 | ||
551b43fd AM |
614 | bed = get_elf_backend_data (stdoutput); |
615 | ssect = (*bed->get_sec_type_attr) (stdoutput, sec); | |
9de8d8f1 | 616 | |
f61e8019 | 617 | if (ssect != NULL) |
2f89ff8d | 618 | { |
ea8f8eab L |
619 | bfd_boolean override = FALSE; |
620 | ||
2f89ff8d | 621 | if (type == SHT_NULL) |
f61e8019 AM |
622 | type = ssect->type; |
623 | else if (type != ssect->type) | |
2f89ff8d | 624 | { |
fafe6678 | 625 | if (old_sec == NULL |
23ddb850 | 626 | /* Some older versions of gcc will emit |
7ed1d346 | 627 | |
2f89ff8d | 628 | .section .init_array,"aw",@progbits |
7ed1d346 | 629 | |
2f89ff8d | 630 | for __attribute__ ((section (".init_array"))). |
3b22753a | 631 | "@progbits" is incorrect. Also for x86-64 large bss |
23ddb850 | 632 | sections, some older versions of gcc will emit |
3b22753a L |
633 | |
634 | .section .lbss,"aw",@progbits | |
635 | ||
2f89ff8d | 636 | "@progbits" is incorrect. */ |
3b22753a L |
637 | #ifdef TC_I386 |
638 | && (bed->s->arch_size != 64 | |
639 | || !(ssect->attr & SHF_X86_64_LARGE)) | |
640 | #endif | |
f61e8019 AM |
641 | && ssect->type != SHT_INIT_ARRAY |
642 | && ssect->type != SHT_FINI_ARRAY | |
643 | && ssect->type != SHT_PREINIT_ARRAY) | |
2f89ff8d L |
644 | { |
645 | /* We allow to specify any type for a .note section. */ | |
9fb71ee4 NC |
646 | if (ssect->type != SHT_NOTE |
647 | /* Processor and application defined types are allowed too. */ | |
648 | && type < SHT_LOPROC) | |
2f89ff8d L |
649 | as_warn (_("setting incorrect section type for %s"), |
650 | name); | |
651 | } | |
652 | else | |
653 | { | |
654 | as_warn (_("ignoring incorrect section type for %s"), | |
742f45cf | 655 | name); |
f61e8019 | 656 | type = ssect->type; |
2f89ff8d L |
657 | } |
658 | } | |
659 | ||
9fb71ee4 NC |
660 | if (old_sec == NULL && ((attr & ~(SHF_MASKOS | SHF_MASKPROC)) |
661 | & ~ssect->attr) != 0) | |
2f89ff8d L |
662 | { |
663 | /* As a GNU extension, we permit a .note section to be | |
f61e8019 | 664 | allocatable. If the linker sees an allocatable .note |
2f89ff8d | 665 | section, it will create a PT_NOTE segment in the output |
92191b29 | 666 | file. We also allow "x" for .note.GNU-stack. */ |
f61e8019 AM |
667 | if (ssect->type == SHT_NOTE |
668 | && (attr == SHF_ALLOC || attr == SHF_EXECINSTR)) | |
669 | ; | |
670 | /* Allow different SHF_MERGE and SHF_STRINGS if we have | |
671 | something like .rodata.str. */ | |
672 | else if (ssect->suffix_length == -2 | |
673 | && name[ssect->prefix_length] == '.' | |
ea8f8eab L |
674 | && (attr |
675 | & ~ssect->attr | |
676 | & ~SHF_MERGE | |
677 | & ~SHF_STRINGS) == 0) | |
f61e8019 | 678 | ; |
ea8f8eab L |
679 | /* .interp, .strtab and .symtab can have SHF_ALLOC. */ |
680 | else if (attr == SHF_ALLOC | |
681 | && (strcmp (name, ".interp") == 0 | |
682 | || strcmp (name, ".strtab") == 0 | |
683 | || strcmp (name, ".symtab") == 0)) | |
684 | override = TRUE; | |
b9f18452 L |
685 | /* .note.GNU-stack can have SHF_EXECINSTR. */ |
686 | else if (attr == SHF_EXECINSTR | |
687 | && strcmp (name, ".note.GNU-stack") == 0) | |
688 | override = TRUE; | |
7f841127 L |
689 | #ifdef TC_ALPHA |
690 | /* A section on Alpha may have SHF_ALPHA_GPREL. */ | |
691 | else if ((attr & ~ssect->attr) == SHF_ALPHA_GPREL) | |
692 | override = TRUE; | |
708e2187 NC |
693 | #endif |
694 | #ifdef TC_RX | |
695 | else if (attr == (SHF_EXECINSTR | SHF_WRITE | SHF_ALLOC) | |
696 | && (ssect->type == SHT_INIT_ARRAY | |
697 | || ssect->type == SHT_FINI_ARRAY | |
698 | || ssect->type == SHT_PREINIT_ARRAY)) | |
699 | /* RX init/fini arrays can and should have the "awx" attributes set. */ | |
700 | ; | |
7f841127 | 701 | #endif |
f61e8019 | 702 | else |
ea8f8eab | 703 | { |
a8c4d40b | 704 | if (match_p->group_name == NULL) |
86654c12 L |
705 | as_warn (_("setting incorrect section attributes for %s"), |
706 | name); | |
ea8f8eab L |
707 | override = TRUE; |
708 | } | |
2f89ff8d | 709 | } |
9fb71ee4 | 710 | |
fafe6678 | 711 | if (!override && old_sec == NULL) |
f61e8019 | 712 | attr |= ssect->attr; |
2f89ff8d | 713 | } |
742f45cf AM |
714 | |
715 | /* Convert ELF type and flags to BFD flags. */ | |
716 | flags = (SEC_RELOC | |
717 | | ((attr & SHF_WRITE) ? 0 : SEC_READONLY) | |
718 | | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0) | |
719 | | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0) | |
f5fa8ca2 JJ |
720 | | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0) |
721 | | ((attr & SHF_MERGE) ? SEC_MERGE : 0) | |
13ae64f3 | 722 | | ((attr & SHF_STRINGS) ? SEC_STRINGS : 0) |
18ae9cc1 | 723 | | ((attr & SHF_EXCLUDE) ? SEC_EXCLUDE: 0) |
13ae64f3 | 724 | | ((attr & SHF_TLS) ? SEC_THREAD_LOCAL : 0)); |
9de8d8f1 | 725 | #ifdef md_elf_section_flags |
742f45cf | 726 | flags = md_elf_section_flags (flags, attr, type); |
9de8d8f1 RH |
727 | #endif |
728 | ||
86654c12 L |
729 | if (linkonce) |
730 | flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
731 | ||
fafe6678 | 732 | if (old_sec == NULL) |
742f45cf AM |
733 | { |
734 | symbolS *secsym; | |
735 | ||
94be91de JB |
736 | if (type == SHT_NULL) |
737 | type = bfd_elf_get_default_section_type (flags); | |
7a6d0b32 JB |
738 | elf_section_type (sec) = type; |
739 | elf_section_flags (sec) = attr; | |
a8c4d40b | 740 | elf_section_data (sec)->this_hdr.sh_info = match_p->info; |
7a6d0b32 | 741 | |
9de8d8f1 RH |
742 | /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */ |
743 | if (type == SHT_NOBITS) | |
13c56984 | 744 | seg_info (sec)->bss = 1; |
9de8d8f1 | 745 | |
a8c4d40b L |
746 | /* Set the section ID and flags. */ |
747 | sec->section_id = match_p->section_id; | |
748 | flags |= match_p->flags; | |
749 | ||
b7d07216 L |
750 | /* Set the linked-to symbol name. */ |
751 | sec->map_head.linked_to_symbol_name | |
752 | = match_p->linked_to_symbol_name; | |
753 | ||
fd361982 | 754 | bfd_set_section_flags (sec, flags); |
f5fa8ca2 JJ |
755 | if (flags & SEC_MERGE) |
756 | sec->entsize = entsize; | |
a8c4d40b | 757 | elf_group_name (sec) = match_p->group_name; |
9de8d8f1 RH |
758 | |
759 | /* Add a symbol for this section to the symbol table. */ | |
760 | secsym = symbol_find (name); | |
761 | if (secsym != NULL) | |
d4d05d13 AC |
762 | { |
763 | /* We could be repurposing an undefined symbol here: make sure we | |
764 | reset sy_value to look like other section symbols in order to avoid | |
765 | trying to incorrectly resolve this section symbol later on. */ | |
766 | static const expressionS expr = { .X_op = O_constant }; | |
767 | symbol_set_value_expression (secsym, &expr); | |
768 | symbol_set_bfdsym (secsym, sec->symbol); | |
769 | } | |
9de8d8f1 | 770 | else |
13c56984 | 771 | symbol_table_insert (section_symbol (sec)); |
9de8d8f1 | 772 | } |
7a6d0b32 | 773 | else |
742f45cf | 774 | { |
7a6d0b32 JB |
775 | if (type != SHT_NULL |
776 | && (unsigned) type != elf_section_type (old_sec)) | |
33176d91 AM |
777 | { |
778 | if (ssect != NULL) | |
779 | /* This is a special section with known type. User | |
780 | assembly might get the section type wrong; Even high | |
781 | profile projects like glibc have done so in the past. | |
782 | So don't error in this case. */ | |
783 | as_warn (_("ignoring changed section type for %s"), name); | |
784 | else | |
785 | /* Do error when assembly isn't self-consistent. */ | |
786 | as_bad (_("changed section type for %s"), name); | |
787 | } | |
7a6d0b32 JB |
788 | |
789 | if (attr != 0) | |
790 | { | |
791 | /* If section attributes are specified the second time we see a | |
792 | particular section, then check that they are the same as we | |
793 | saw the first time. */ | |
794 | if (((old_sec->flags ^ flags) | |
795 | & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE | |
796 | | SEC_EXCLUDE | SEC_SORT_ENTRIES | SEC_MERGE | SEC_STRINGS | |
797 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD | |
798 | | SEC_THREAD_LOCAL))) | |
33176d91 AM |
799 | { |
800 | if (ssect != NULL) | |
801 | as_warn (_("ignoring changed section attributes for %s"), name); | |
802 | else | |
803 | as_bad (_("changed section attributes for %s"), name); | |
804 | } | |
9fb71ee4 NC |
805 | else |
806 | /* FIXME: Maybe we should consider removing a previously set | |
807 | processor or application specific attribute as suspicious ? */ | |
808 | elf_section_flags (sec) = attr; | |
809 | ||
7a6d0b32 | 810 | if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize) |
33176d91 | 811 | as_bad (_("changed section entity size for %s"), name); |
7a6d0b32 | 812 | } |
742f45cf | 813 | } |
9de8d8f1 RH |
814 | |
815 | #ifdef md_elf_section_change_hook | |
742f45cf | 816 | md_elf_section_change_hook (); |
9de8d8f1 RH |
817 | #endif |
818 | } | |
819 | ||
01e1a5bc | 820 | static bfd_vma |
df3a023b AM |
821 | obj_elf_parse_section_letters (char *str, size_t len, |
822 | bfd_boolean *is_clone, bfd_vma *gnu_attr) | |
9de8d8f1 | 823 | { |
01e1a5bc | 824 | bfd_vma attr = 0; |
f6616a06 | 825 | *is_clone = FALSE; |
9de8d8f1 RH |
826 | |
827 | while (len > 0) | |
828 | { | |
829 | switch (*str) | |
830 | { | |
831 | case 'a': | |
832 | attr |= SHF_ALLOC; | |
833 | break; | |
18ae9cc1 L |
834 | case 'e': |
835 | attr |= SHF_EXCLUDE; | |
836 | break; | |
b7d07216 L |
837 | case 'o': |
838 | attr |= SHF_LINK_ORDER; | |
839 | break; | |
9de8d8f1 RH |
840 | case 'w': |
841 | attr |= SHF_WRITE; | |
842 | break; | |
843 | case 'x': | |
844 | attr |= SHF_EXECINSTR; | |
845 | break; | |
9469ddf0 | 846 | case 'M': |
f5fa8ca2 JJ |
847 | attr |= SHF_MERGE; |
848 | break; | |
9469ddf0 | 849 | case 'S': |
f5fa8ca2 JJ |
850 | attr |= SHF_STRINGS; |
851 | break; | |
060adf0e AM |
852 | case 'G': |
853 | attr |= SHF_GROUP; | |
854 | break; | |
13ae64f3 JJ |
855 | case 'T': |
856 | attr |= SHF_TLS; | |
857 | break; | |
a91e1603 | 858 | case 'd': |
df3a023b | 859 | *gnu_attr |= SHF_GNU_MBIND; |
a91e1603 | 860 | break; |
01642c12 | 861 | case '?': |
f6616a06 | 862 | *is_clone = TRUE; |
01642c12 | 863 | break; |
34105363 L |
864 | /* Compatibility. */ |
865 | case 'm': | |
866 | if (*(str - 1) == 'a') | |
867 | { | |
868 | attr |= SHF_MERGE; | |
869 | if (len > 1 && str[1] == 's') | |
870 | { | |
871 | attr |= SHF_STRINGS; | |
872 | str++, len--; | |
873 | } | |
874 | break; | |
875 | } | |
1a0670f3 | 876 | /* Fall through. */ |
9de8d8f1 RH |
877 | default: |
878 | { | |
6d4af3c2 | 879 | const char *bad_msg = _("unrecognized .section attribute:" |
b7d07216 | 880 | " want a,e,o,w,x,M,S,G,T or number"); |
9de8d8f1 | 881 | #ifdef md_elf_section_letter |
01e1a5bc | 882 | bfd_vma md_attr = md_elf_section_letter (*str, &bad_msg); |
8f3bae45 | 883 | if (md_attr != (bfd_vma) -1) |
9de8d8f1 RH |
884 | attr |= md_attr; |
885 | else | |
886 | #endif | |
9fb71ee4 NC |
887 | if (ISDIGIT (*str)) |
888 | { | |
889 | char * end; | |
890 | ||
891 | attr |= strtoul (str, & end, 0); | |
892 | /* Update str and len, allowing for the fact that | |
893 | we will execute str++ and len-- below. */ | |
894 | end --; | |
895 | len -= (end - str); | |
896 | str = end; | |
897 | } | |
898 | else | |
899 | as_fatal ("%s", bad_msg); | |
9de8d8f1 RH |
900 | } |
901 | break; | |
902 | } | |
903 | str++, len--; | |
904 | } | |
905 | ||
906 | return attr; | |
907 | } | |
908 | ||
8d28c9d7 | 909 | static int |
44bf2362 | 910 | obj_elf_section_type (char *str, size_t len, bfd_boolean warn) |
9de8d8f1 RH |
911 | { |
912 | if (len == 8 && strncmp (str, "progbits", 8) == 0) | |
913 | return SHT_PROGBITS; | |
914 | if (len == 6 && strncmp (str, "nobits", 6) == 0) | |
915 | return SHT_NOBITS; | |
34f70875 L |
916 | if (len == 4 && strncmp (str, "note", 4) == 0) |
917 | return SHT_NOTE; | |
10b016c2 PB |
918 | if (len == 10 && strncmp (str, "init_array", 10) == 0) |
919 | return SHT_INIT_ARRAY; | |
920 | if (len == 10 && strncmp (str, "fini_array", 10) == 0) | |
921 | return SHT_FINI_ARRAY; | |
922 | if (len == 13 && strncmp (str, "preinit_array", 13) == 0) | |
923 | return SHT_PREINIT_ARRAY; | |
9de8d8f1 RH |
924 | |
925 | #ifdef md_elf_section_type | |
926 | { | |
927 | int md_type = md_elf_section_type (str, len); | |
928 | if (md_type >= 0) | |
929 | return md_type; | |
930 | } | |
931 | #endif | |
932 | ||
9fb71ee4 NC |
933 | if (ISDIGIT (*str)) |
934 | { | |
935 | char * end; | |
936 | int type = strtoul (str, & end, 0); | |
937 | ||
938 | if (warn && (size_t) (end - str) != len) | |
939 | as_warn (_("extraneous characters at end of numeric section type")); | |
940 | ||
941 | return type; | |
942 | } | |
943 | ||
44bf2362 NC |
944 | if (warn) |
945 | as_warn (_("unrecognized section type")); | |
946 | return 0; | |
947 | } | |
948 | ||
01e1a5bc | 949 | static bfd_vma |
44bf2362 NC |
950 | obj_elf_section_word (char *str, size_t len, int *type) |
951 | { | |
952 | int ret; | |
953 | ||
954 | if (len == 5 && strncmp (str, "write", 5) == 0) | |
955 | return SHF_WRITE; | |
956 | if (len == 5 && strncmp (str, "alloc", 5) == 0) | |
957 | return SHF_ALLOC; | |
958 | if (len == 9 && strncmp (str, "execinstr", 9) == 0) | |
959 | return SHF_EXECINSTR; | |
18ae9cc1 L |
960 | if (len == 7 && strncmp (str, "exclude", 7) == 0) |
961 | return SHF_EXCLUDE; | |
44bf2362 NC |
962 | if (len == 3 && strncmp (str, "tls", 3) == 0) |
963 | return SHF_TLS; | |
964 | ||
965 | #ifdef md_elf_section_word | |
966 | { | |
01e1a5bc NC |
967 | bfd_vma md_attr = md_elf_section_word (str, len); |
968 | if (md_attr > 0) | |
44bf2362 NC |
969 | return md_attr; |
970 | } | |
971 | #endif | |
972 | ||
973 | ret = obj_elf_section_type (str, len, FALSE); | |
974 | if (ret != 0) | |
975 | *type = ret; | |
976 | else | |
977 | as_warn (_("unrecognized section attribute")); | |
978 | ||
9de8d8f1 RH |
979 | return 0; |
980 | } | |
981 | ||
6ce8b369 | 982 | /* Get name of section. */ |
82b8a785 | 983 | const char * |
dbe2df79 | 984 | obj_elf_section_name (void) |
6ce8b369 AM |
985 | { |
986 | char *name; | |
987 | ||
988 | SKIP_WHITESPACE (); | |
989 | if (*input_line_pointer == '"') | |
990 | { | |
991 | int dummy; | |
992 | ||
993 | name = demand_copy_C_string (&dummy); | |
994 | if (name == NULL) | |
995 | { | |
996 | ignore_rest_of_line (); | |
997 | return NULL; | |
998 | } | |
999 | } | |
1000 | else | |
1001 | { | |
1002 | char *end = input_line_pointer; | |
1003 | ||
1004 | while (0 == strchr ("\n\t,; ", *end)) | |
1005 | end++; | |
1006 | if (end == input_line_pointer) | |
1007 | { | |
c95b35a9 | 1008 | as_bad (_("missing name")); |
6ce8b369 AM |
1009 | ignore_rest_of_line (); |
1010 | return NULL; | |
1011 | } | |
1012 | ||
29a2809e | 1013 | name = xmemdup0 (input_line_pointer, end - input_line_pointer); |
451133ce NP |
1014 | |
1015 | while (flag_sectname_subst) | |
1016 | { | |
1017 | char *subst = strchr (name, '%'); | |
1018 | if (subst && subst[1] == 'S') | |
1019 | { | |
1020 | int oldlen = strlen (name); | |
1021 | int substlen = strlen (now_seg->name); | |
1022 | int newlen = oldlen - 2 + substlen; | |
add39d23 | 1023 | char *newname = XNEWVEC (char, newlen + 1); |
451133ce NP |
1024 | int headlen = subst - name; |
1025 | memcpy (newname, name, headlen); | |
1026 | strcpy (newname + headlen, now_seg->name); | |
1027 | strcat (newname + headlen, subst + 2); | |
1028 | xfree (name); | |
1029 | name = newname; | |
1030 | } | |
1031 | else | |
1032 | break; | |
1033 | } | |
1034 | ||
612d7b83 L |
1035 | #ifdef tc_canonicalize_section_name |
1036 | name = tc_canonicalize_section_name (name); | |
1037 | #endif | |
6ce8b369 AM |
1038 | input_line_pointer = end; |
1039 | } | |
1040 | SKIP_WHITESPACE (); | |
1041 | return name; | |
1042 | } | |
1043 | ||
9de8d8f1 | 1044 | void |
dbe2df79 | 1045 | obj_elf_section (int push) |
9de8d8f1 | 1046 | { |
a8c4d40b | 1047 | const char *name; |
82b8a785 | 1048 | char *beg; |
01e1a5bc NC |
1049 | int type, dummy; |
1050 | bfd_vma attr; | |
df3a023b | 1051 | bfd_vma gnu_attr; |
f5fa8ca2 | 1052 | int entsize; |
d2dab548 | 1053 | int linkonce; |
6f932bce | 1054 | subsegT new_subsection = -1; |
a8c4d40b | 1055 | struct elf_section_match match; |
9de8d8f1 | 1056 | |
252b5132 RH |
1057 | if (flag_mri) |
1058 | { | |
1059 | char mri_type; | |
1060 | ||
9de8d8f1 | 1061 | #ifdef md_flush_pending_output |
60bcf0fa | 1062 | md_flush_pending_output (); |
9de8d8f1 RH |
1063 | #endif |
1064 | ||
252b5132 RH |
1065 | previous_section = now_seg; |
1066 | previous_subsection = now_subseg; | |
1067 | ||
1068 | s_mri_sect (&mri_type); | |
1069 | ||
1070 | #ifdef md_elf_section_change_hook | |
1071 | md_elf_section_change_hook (); | |
1072 | #endif | |
1073 | ||
1074 | return; | |
1075 | } | |
1076 | ||
6ce8b369 AM |
1077 | name = obj_elf_section_name (); |
1078 | if (name == NULL) | |
1079 | return; | |
f1f28025 | 1080 | |
a8c4d40b L |
1081 | memset (&match, 0, sizeof (match)); |
1082 | ||
f1f28025 NC |
1083 | symbolS * sym; |
1084 | if ((sym = symbol_find (name)) != NULL | |
1085 | && ! symbol_section_p (sym) | |
1086 | && S_IS_DEFINED (sym) | |
1087 | && ! S_IS_VOLATILE (sym) | |
1088 | && ! S_CAN_BE_REDEFINED (sym)) | |
1089 | { | |
1090 | as_bad (_("section name '%s' already defined as another symbol"), name); | |
1091 | ignore_rest_of_line (); | |
1092 | return; | |
1093 | } | |
252b5132 RH |
1094 | type = SHT_NULL; |
1095 | attr = 0; | |
df3a023b | 1096 | gnu_attr = 0; |
f5fa8ca2 | 1097 | entsize = 0; |
d2dab548 | 1098 | linkonce = 0; |
252b5132 RH |
1099 | |
1100 | if (*input_line_pointer == ',') | |
1101 | { | |
1102 | /* Skip the comma. */ | |
1103 | ++input_line_pointer; | |
252b5132 RH |
1104 | SKIP_WHITESPACE (); |
1105 | ||
9cfc3331 | 1106 | if (push && ISDIGIT (*input_line_pointer)) |
6f932bce | 1107 | { |
9cfc3331 | 1108 | /* .pushsection has an optional subsection. */ |
6f932bce | 1109 | new_subsection = (subsegT) get_absolute_expression (); |
9cfc3331 L |
1110 | |
1111 | SKIP_WHITESPACE (); | |
1112 | ||
1113 | /* Stop if we don't see a comma. */ | |
1114 | if (*input_line_pointer != ',') | |
1115 | goto done; | |
1116 | ||
1117 | /* Skip the comma. */ | |
1118 | ++input_line_pointer; | |
1119 | SKIP_WHITESPACE (); | |
6f932bce | 1120 | } |
9cfc3331 L |
1121 | |
1122 | if (*input_line_pointer == '"') | |
252b5132 | 1123 | { |
f6616a06 | 1124 | bfd_boolean is_clone; |
01642c12 | 1125 | |
9de8d8f1 RH |
1126 | beg = demand_copy_C_string (&dummy); |
1127 | if (beg == NULL) | |
252b5132 | 1128 | { |
9de8d8f1 RH |
1129 | ignore_rest_of_line (); |
1130 | return; | |
252b5132 | 1131 | } |
df3a023b AM |
1132 | attr |= obj_elf_parse_section_letters (beg, strlen (beg), |
1133 | &is_clone, &gnu_attr); | |
252b5132 RH |
1134 | |
1135 | SKIP_WHITESPACE (); | |
1136 | if (*input_line_pointer == ',') | |
1137 | { | |
9de8d8f1 | 1138 | char c; |
060adf0e AM |
1139 | char *save = input_line_pointer; |
1140 | ||
252b5132 RH |
1141 | ++input_line_pointer; |
1142 | SKIP_WHITESPACE (); | |
9de8d8f1 RH |
1143 | c = *input_line_pointer; |
1144 | if (c == '"') | |
252b5132 | 1145 | { |
9de8d8f1 RH |
1146 | beg = demand_copy_C_string (&dummy); |
1147 | if (beg == NULL) | |
252b5132 | 1148 | { |
9de8d8f1 RH |
1149 | ignore_rest_of_line (); |
1150 | return; | |
252b5132 | 1151 | } |
44bf2362 | 1152 | type = obj_elf_section_type (beg, strlen (beg), TRUE); |
9de8d8f1 RH |
1153 | } |
1154 | else if (c == '@' || c == '%') | |
1155 | { | |
d02603dc | 1156 | ++input_line_pointer; |
9fb71ee4 NC |
1157 | |
1158 | if (ISDIGIT (* input_line_pointer)) | |
df3a023b | 1159 | type = strtoul (input_line_pointer, &input_line_pointer, 0); |
9fb71ee4 NC |
1160 | else |
1161 | { | |
1162 | c = get_symbol_name (& beg); | |
1163 | (void) restore_line_pointer (c); | |
df3a023b AM |
1164 | type = obj_elf_section_type (beg, |
1165 | input_line_pointer - beg, | |
1166 | TRUE); | |
9fb71ee4 | 1167 | } |
252b5132 | 1168 | } |
060adf0e AM |
1169 | else |
1170 | input_line_pointer = save; | |
252b5132 | 1171 | } |
f5fa8ca2 JJ |
1172 | |
1173 | SKIP_WHITESPACE (); | |
6ce8b369 | 1174 | if ((attr & SHF_MERGE) != 0 && *input_line_pointer == ',') |
f5fa8ca2 JJ |
1175 | { |
1176 | ++input_line_pointer; | |
1177 | SKIP_WHITESPACE (); | |
1178 | entsize = get_absolute_expression (); | |
6ce8b369 | 1179 | SKIP_WHITESPACE (); |
f5fa8ca2 JJ |
1180 | if (entsize < 0) |
1181 | { | |
6ce8b369 | 1182 | as_warn (_("invalid merge entity size")); |
f5fa8ca2 JJ |
1183 | attr &= ~SHF_MERGE; |
1184 | entsize = 0; | |
1185 | } | |
1186 | } | |
6ce8b369 AM |
1187 | else if ((attr & SHF_MERGE) != 0) |
1188 | { | |
1189 | as_warn (_("entity size for SHF_MERGE not specified")); | |
1190 | attr &= ~SHF_MERGE; | |
1191 | } | |
060adf0e | 1192 | |
b7d07216 L |
1193 | if ((attr & SHF_LINK_ORDER) != 0 && *input_line_pointer == ',') |
1194 | { | |
1195 | char c; | |
1196 | unsigned int length; | |
1197 | ++input_line_pointer; | |
1198 | SKIP_WHITESPACE (); | |
1199 | c = get_symbol_name (& beg); | |
1200 | (void) restore_line_pointer (c); | |
1201 | length = input_line_pointer - beg; | |
1202 | if (length) | |
1203 | match.linked_to_symbol_name = xmemdup0 (beg, length); | |
1204 | } | |
1205 | ||
f6616a06 | 1206 | if ((attr & SHF_GROUP) != 0 && is_clone) |
01642c12 RM |
1207 | { |
1208 | as_warn (_("? section flag ignored with G present")); | |
f6616a06 | 1209 | is_clone = FALSE; |
01642c12 | 1210 | } |
060adf0e AM |
1211 | if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',') |
1212 | { | |
1213 | ++input_line_pointer; | |
a8c4d40b L |
1214 | match.group_name = obj_elf_section_name (); |
1215 | if (match.group_name == NULL) | |
060adf0e | 1216 | attr &= ~SHF_GROUP; |
59365e19 | 1217 | else if (*input_line_pointer == ',') |
d2dab548 | 1218 | { |
59365e19 AM |
1219 | ++input_line_pointer; |
1220 | SKIP_WHITESPACE (); | |
1221 | if (strncmp (input_line_pointer, "comdat", 6) == 0) | |
1222 | { | |
1223 | input_line_pointer += 6; | |
1224 | linkonce = 1; | |
1225 | } | |
d2dab548 AM |
1226 | } |
1227 | else if (strncmp (name, ".gnu.linkonce", 13) == 0) | |
1228 | linkonce = 1; | |
060adf0e AM |
1229 | } |
1230 | else if ((attr & SHF_GROUP) != 0) | |
1231 | { | |
1232 | as_warn (_("group name for SHF_GROUP not specified")); | |
1233 | attr &= ~SHF_GROUP; | |
1234 | } | |
01642c12 | 1235 | |
f6616a06 | 1236 | if (is_clone) |
01642c12 RM |
1237 | { |
1238 | const char *now_group = elf_group_name (now_seg); | |
1239 | if (now_group != NULL) | |
1240 | { | |
a8c4d40b | 1241 | match.group_name = xstrdup (now_group); |
01642c12 RM |
1242 | linkonce = (now_seg->flags & SEC_LINK_ONCE) != 0; |
1243 | } | |
1244 | } | |
a91e1603 | 1245 | |
df3a023b | 1246 | if ((gnu_attr & SHF_GNU_MBIND) != 0 && *input_line_pointer == ',') |
a91e1603 | 1247 | { |
a8c4d40b | 1248 | char *save = input_line_pointer; |
a91e1603 L |
1249 | ++input_line_pointer; |
1250 | SKIP_WHITESPACE (); | |
1251 | if (ISDIGIT (* input_line_pointer)) | |
1252 | { | |
1253 | char *t = input_line_pointer; | |
a8c4d40b L |
1254 | match.info = strtoul (input_line_pointer, |
1255 | &input_line_pointer, 0); | |
1256 | if (match.info == (unsigned int) -1) | |
a91e1603 L |
1257 | { |
1258 | as_warn (_("unsupported mbind section info: %s"), t); | |
a8c4d40b | 1259 | match.info = 0; |
a91e1603 L |
1260 | } |
1261 | } | |
a8c4d40b L |
1262 | else |
1263 | input_line_pointer = save; | |
1264 | } | |
1265 | ||
1266 | if (*input_line_pointer == ',') | |
1267 | { | |
1268 | char *save = input_line_pointer; | |
1269 | ++input_line_pointer; | |
1270 | SKIP_WHITESPACE (); | |
1271 | if (strncmp (input_line_pointer, "unique", 6) == 0) | |
1272 | { | |
1273 | input_line_pointer += 6; | |
1274 | SKIP_WHITESPACE (); | |
1275 | if (*input_line_pointer == ',') | |
1276 | { | |
1277 | ++input_line_pointer; | |
1278 | SKIP_WHITESPACE (); | |
1279 | if (ISDIGIT (* input_line_pointer)) | |
1280 | { | |
1281 | bfd_vma id; | |
1282 | bfd_boolean overflow; | |
1283 | char *t = input_line_pointer; | |
1284 | if (sizeof (bfd_vma) <= sizeof (unsigned long)) | |
1285 | { | |
1286 | errno = 0; | |
1287 | id = strtoul (input_line_pointer, | |
1288 | &input_line_pointer, 0); | |
1289 | overflow = (id == (unsigned long) -1 | |
1290 | && errno == ERANGE); | |
1291 | } | |
1292 | else | |
1293 | { | |
1294 | id = bfd_scan_vma | |
1295 | (input_line_pointer, | |
1296 | (const char **) &input_line_pointer, 0); | |
1297 | overflow = id == ~(bfd_vma) 0; | |
1298 | } | |
1299 | if (overflow || id > (unsigned int) -1) | |
1300 | { | |
1301 | char *linefeed, saved_char = 0; | |
1302 | if ((linefeed = strchr (t, '\n')) != NULL) | |
1303 | { | |
1304 | saved_char = *linefeed; | |
1305 | *linefeed = '\0'; | |
1306 | } | |
1307 | as_bad (_("unsupported section id: %s"), t); | |
1308 | if (saved_char) | |
1309 | *linefeed = saved_char; | |
1310 | } | |
1311 | else | |
1312 | { | |
1313 | match.section_id = id; | |
1314 | match.flags |= SEC_ASSEMBLER_SECTION_ID; | |
1315 | } | |
1316 | } | |
1317 | } | |
1318 | } | |
1319 | else | |
1320 | input_line_pointer = save; | |
a91e1603 | 1321 | } |
252b5132 RH |
1322 | } |
1323 | else | |
1324 | { | |
1325 | do | |
1326 | { | |
9de8d8f1 RH |
1327 | char c; |
1328 | ||
252b5132 RH |
1329 | SKIP_WHITESPACE (); |
1330 | if (*input_line_pointer != '#') | |
1331 | { | |
c95b35a9 | 1332 | as_bad (_("character following name is not '#'")); |
252b5132 RH |
1333 | ignore_rest_of_line (); |
1334 | return; | |
1335 | } | |
d02603dc NC |
1336 | ++input_line_pointer; |
1337 | c = get_symbol_name (& beg); | |
1338 | (void) restore_line_pointer (c); | |
9de8d8f1 | 1339 | |
df3a023b AM |
1340 | attr |= obj_elf_section_word (beg, input_line_pointer - beg, |
1341 | &type); | |
9de8d8f1 | 1342 | |
252b5132 RH |
1343 | SKIP_WHITESPACE (); |
1344 | } | |
1345 | while (*input_line_pointer++ == ','); | |
1346 | --input_line_pointer; | |
1347 | } | |
1348 | } | |
1349 | ||
dc1e8a47 | 1350 | done: |
252b5132 | 1351 | demand_empty_rest_of_line (); |
9de8d8f1 | 1352 | |
a8c4d40b L |
1353 | obj_elf_change_section (name, type, attr, entsize, &match, linkonce, |
1354 | push); | |
6f932bce | 1355 | |
df3a023b AM |
1356 | if ((gnu_attr & SHF_GNU_MBIND) != 0) |
1357 | { | |
1358 | struct elf_backend_data *bed; | |
1359 | ||
1360 | if ((attr & SHF_ALLOC) == 0) | |
1361 | as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name); | |
1362 | ||
1363 | bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput); | |
1364 | if (bed->elf_osabi == ELFOSABI_NONE) | |
1365 | bed->elf_osabi = ELFOSABI_GNU; | |
1366 | else if (bed->elf_osabi != ELFOSABI_GNU | |
1367 | && bed->elf_osabi != ELFOSABI_FREEBSD) | |
1368 | as_bad (_("GNU_MBIND section is supported only by GNU " | |
1369 | "and FreeBSD targets")); | |
cc364be6 | 1370 | elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_mbind; |
df3a023b AM |
1371 | } |
1372 | elf_section_flags (now_seg) |= gnu_attr; | |
1373 | ||
6f932bce NC |
1374 | if (push && new_subsection != -1) |
1375 | subseg_set (now_seg, new_subsection); | |
252b5132 RH |
1376 | } |
1377 | ||
1378 | /* Change to the .data section. */ | |
1379 | ||
16b93d88 | 1380 | void |
dbe2df79 | 1381 | obj_elf_data (int i) |
252b5132 RH |
1382 | { |
1383 | #ifdef md_flush_pending_output | |
1384 | md_flush_pending_output (); | |
1385 | #endif | |
1386 | ||
1387 | previous_section = now_seg; | |
1388 | previous_subsection = now_subseg; | |
1389 | s_data (i); | |
1390 | ||
1391 | #ifdef md_elf_section_change_hook | |
1392 | md_elf_section_change_hook (); | |
1393 | #endif | |
1394 | } | |
1395 | ||
1396 | /* Change to the .text section. */ | |
1397 | ||
16b93d88 | 1398 | void |
dbe2df79 | 1399 | obj_elf_text (int i) |
252b5132 RH |
1400 | { |
1401 | #ifdef md_flush_pending_output | |
1402 | md_flush_pending_output (); | |
1403 | #endif | |
1404 | ||
1405 | previous_section = now_seg; | |
1406 | previous_subsection = now_subseg; | |
1407 | s_text (i); | |
1408 | ||
1409 | #ifdef md_elf_section_change_hook | |
1410 | md_elf_section_change_hook (); | |
1411 | #endif | |
1412 | } | |
1413 | ||
8fe53b44 JB |
1414 | /* Change to the *ABS* section. */ |
1415 | ||
1416 | void | |
1417 | obj_elf_struct (int i) | |
1418 | { | |
1419 | #ifdef md_flush_pending_output | |
1420 | md_flush_pending_output (); | |
1421 | #endif | |
1422 | ||
1423 | previous_section = now_seg; | |
1424 | previous_subsection = now_subseg; | |
1425 | s_struct (i); | |
1426 | ||
1427 | #ifdef md_elf_section_change_hook | |
1428 | md_elf_section_change_hook (); | |
1429 | #endif | |
1430 | } | |
1431 | ||
252b5132 | 1432 | static void |
dbe2df79 | 1433 | obj_elf_subsection (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 1434 | { |
6f932bce | 1435 | int temp; |
252b5132 RH |
1436 | |
1437 | #ifdef md_flush_pending_output | |
1438 | md_flush_pending_output (); | |
1439 | #endif | |
1440 | ||
1441 | previous_section = now_seg; | |
1442 | previous_subsection = now_subseg; | |
1443 | ||
1444 | temp = get_absolute_expression (); | |
1445 | subseg_set (now_seg, (subsegT) temp); | |
1446 | demand_empty_rest_of_line (); | |
1447 | ||
1448 | #ifdef md_elf_section_change_hook | |
1449 | md_elf_section_change_hook (); | |
1450 | #endif | |
1451 | } | |
1452 | ||
1453 | /* This can be called from the processor backends if they change | |
1454 | sections. */ | |
1455 | ||
1456 | void | |
dbe2df79 | 1457 | obj_elf_section_change_hook (void) |
252b5132 RH |
1458 | { |
1459 | previous_section = now_seg; | |
1460 | previous_subsection = now_subseg; | |
1461 | } | |
1462 | ||
1463 | void | |
dbe2df79 | 1464 | obj_elf_previous (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 1465 | { |
9de8d8f1 RH |
1466 | segT new_section; |
1467 | int new_subsection; | |
1468 | ||
252b5132 RH |
1469 | if (previous_section == 0) |
1470 | { | |
6ce8b369 | 1471 | as_warn (_(".previous without corresponding .section; ignored")); |
252b5132 RH |
1472 | return; |
1473 | } | |
1474 | ||
1475 | #ifdef md_flush_pending_output | |
1476 | md_flush_pending_output (); | |
1477 | #endif | |
1478 | ||
9de8d8f1 RH |
1479 | new_section = previous_section; |
1480 | new_subsection = previous_subsection; | |
1481 | previous_section = now_seg; | |
1482 | previous_subsection = now_subseg; | |
1483 | subseg_set (new_section, new_subsection); | |
1484 | ||
1485 | #ifdef md_elf_section_change_hook | |
1486 | md_elf_section_change_hook (); | |
1487 | #endif | |
1488 | } | |
1489 | ||
1490 | static void | |
dbe2df79 | 1491 | obj_elf_popsection (int xxx ATTRIBUTE_UNUSED) |
9de8d8f1 RH |
1492 | { |
1493 | struct section_stack *top = section_stack; | |
1494 | ||
1495 | if (top == NULL) | |
1496 | { | |
6ce8b369 | 1497 | as_warn (_(".popsection without corresponding .pushsection; ignored")); |
9de8d8f1 RH |
1498 | return; |
1499 | } | |
1500 | ||
1501 | #ifdef md_flush_pending_output | |
1502 | md_flush_pending_output (); | |
1503 | #endif | |
1504 | ||
1505 | section_stack = top->next; | |
1506 | previous_section = top->prev_seg; | |
1507 | previous_subsection = top->prev_subseg; | |
1508 | subseg_set (top->seg, top->subseg); | |
1509 | free (top); | |
252b5132 RH |
1510 | |
1511 | #ifdef md_elf_section_change_hook | |
1512 | md_elf_section_change_hook (); | |
1513 | #endif | |
1514 | } | |
1515 | ||
1516 | static void | |
dbe2df79 | 1517 | obj_elf_line (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
1518 | { |
1519 | /* Assume delimiter is part of expression. BSD4.2 as fails with | |
bf514e21 | 1520 | delightful bug, so we are not being incompatible here. */ |
dbe2df79 | 1521 | new_logical_line (NULL, get_absolute_expression ()); |
252b5132 RH |
1522 | demand_empty_rest_of_line (); |
1523 | } | |
1524 | ||
6914be53 L |
1525 | static struct elf_versioned_name_list * |
1526 | obj_elf_find_and_add_versioned_name (const char *version_name, | |
1527 | const char *sym_name, | |
1528 | const char *ver, | |
1529 | struct elf_obj_sy *sy_obj) | |
1530 | { | |
1531 | struct elf_versioned_name_list *versioned_name; | |
1532 | const char *p; | |
1533 | ||
1534 | for (p = ver + 1; *p == ELF_VER_CHR; p++) | |
1535 | ; | |
1536 | ||
1537 | /* NB: Since some tests in ld/testsuite/ld-elfvers have no version | |
1538 | names, we have to disable this. */ | |
1539 | if (0 && *p == '\0') | |
1540 | { | |
1541 | as_bad (_("missing version name in `%s' for symbol `%s'"), | |
1542 | version_name, sym_name); | |
1543 | return NULL; | |
1544 | } | |
1545 | ||
1546 | versioned_name = sy_obj->versioned_name; | |
1547 | ||
1548 | switch (p - ver) | |
1549 | { | |
1550 | case 1: | |
1551 | case 2: | |
1552 | break; | |
1553 | case 3: | |
1554 | if (sy_obj->rename) | |
1555 | { | |
1556 | if (strcmp (versioned_name->name, version_name) == 0) | |
1557 | return versioned_name; | |
1558 | else | |
1559 | { | |
1560 | as_bad (_("only one version name with `@@@' is allowed " | |
1561 | "for symbol `%s'"), sym_name); | |
1562 | return NULL; | |
1563 | } | |
1564 | } | |
1565 | sy_obj->rename = TRUE; | |
1566 | break; | |
1567 | default: | |
1568 | as_bad (_("invalid version name '%s' for symbol `%s'"), | |
1569 | version_name, sym_name); | |
1570 | return NULL; | |
1571 | } | |
1572 | ||
1573 | for (; | |
1574 | versioned_name != NULL; | |
1575 | versioned_name = versioned_name->next) | |
1576 | if (strcmp (versioned_name->name, version_name) == 0) | |
1577 | return versioned_name; | |
1578 | ||
1579 | /* Add this versioned name to the head of the list, */ | |
1580 | versioned_name = (struct elf_versioned_name_list *) | |
1581 | xmalloc (sizeof (*versioned_name)); | |
1582 | versioned_name->name = xstrdup (version_name); | |
1583 | versioned_name->next = sy_obj->versioned_name; | |
1584 | sy_obj->versioned_name = versioned_name; | |
1585 | ||
1586 | return versioned_name; | |
1587 | } | |
1588 | ||
252b5132 RH |
1589 | /* This handles the .symver pseudo-op, which is used to specify a |
1590 | symbol version. The syntax is ``.symver NAME,SYMVERNAME''. | |
1591 | SYMVERNAME may contain ELF_VER_CHR ('@') characters. This | |
1592 | pseudo-op causes the assembler to emit a symbol named SYMVERNAME | |
1593 | with the same value as the symbol NAME. */ | |
1594 | ||
1595 | static void | |
dbe2df79 | 1596 | obj_elf_symver (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
1597 | { |
1598 | char *name; | |
6914be53 | 1599 | const char *sym_name; |
252b5132 | 1600 | char c; |
468cced8 | 1601 | char old_lexat; |
252b5132 | 1602 | symbolS *sym; |
6914be53 L |
1603 | struct elf_obj_sy *sy_obj; |
1604 | char *p; | |
252b5132 | 1605 | |
6e8bd58f | 1606 | sym = get_sym_from_input_line_and_check (); |
252b5132 | 1607 | |
252b5132 RH |
1608 | if (*input_line_pointer != ',') |
1609 | { | |
1610 | as_bad (_("expected comma after name in .symver")); | |
1611 | ignore_rest_of_line (); | |
1612 | return; | |
1613 | } | |
1614 | ||
1615 | ++input_line_pointer; | |
eba874d8 | 1616 | SKIP_WHITESPACE (); |
468cced8 AM |
1617 | |
1618 | /* Temporarily include '@' in symbol names. */ | |
1619 | old_lexat = lex_type[(unsigned char) '@']; | |
1620 | lex_type[(unsigned char) '@'] |= LEX_NAME; | |
d02603dc | 1621 | c = get_symbol_name (& name); |
468cced8 | 1622 | lex_type[(unsigned char) '@'] = old_lexat; |
6914be53 | 1623 | sym_name = S_GET_NAME (sym); |
252b5132 | 1624 | |
a3aea05a L |
1625 | if (S_IS_COMMON (sym)) |
1626 | { | |
1627 | as_bad (_("`%s' can't be versioned to common symbol '%s'"), | |
6914be53 | 1628 | name, sym_name); |
a3aea05a L |
1629 | ignore_rest_of_line (); |
1630 | return; | |
1631 | } | |
1632 | ||
6914be53 L |
1633 | p = strchr (name, ELF_VER_CHR); |
1634 | if (p == NULL) | |
339681c0 | 1635 | { |
6914be53 L |
1636 | as_bad (_("missing version name in `%s' for symbol `%s'"), |
1637 | name, sym_name); | |
1638 | ignore_rest_of_line (); | |
1639 | return; | |
1640 | } | |
1641 | ||
1642 | sy_obj = symbol_get_obj (sym); | |
1643 | if (obj_elf_find_and_add_versioned_name (name, sym_name, | |
1644 | p, sy_obj) == NULL) | |
1645 | { | |
1646 | sy_obj->bad_version = TRUE; | |
1647 | ignore_rest_of_line (); | |
1648 | return; | |
1649 | } | |
252b5132 | 1650 | |
6914be53 | 1651 | (void) restore_line_pointer (c); |
252b5132 | 1652 | |
6914be53 L |
1653 | if (*input_line_pointer == ',') |
1654 | { | |
1655 | char *save = input_line_pointer; | |
1656 | ||
1657 | ++input_line_pointer; | |
1658 | SKIP_WHITESPACE (); | |
1659 | if (strncmp (input_line_pointer, "local", 5) == 0) | |
339681c0 | 1660 | { |
6914be53 L |
1661 | input_line_pointer += 5; |
1662 | sy_obj->visibility = visibility_local; | |
339681c0 | 1663 | } |
6914be53 | 1664 | else if (strncmp (input_line_pointer, "hidden", 6) == 0) |
339681c0 | 1665 | { |
6914be53 L |
1666 | input_line_pointer += 6; |
1667 | sy_obj->visibility = visibility_hidden; | |
339681c0 | 1668 | } |
6914be53 L |
1669 | else if (strncmp (input_line_pointer, "remove", 6) == 0) |
1670 | { | |
1671 | input_line_pointer += 6; | |
1672 | sy_obj->visibility = visibility_remove; | |
1673 | } | |
1674 | else | |
1675 | input_line_pointer = save; | |
252b5132 RH |
1676 | } |
1677 | ||
1678 | demand_empty_rest_of_line (); | |
1679 | } | |
1680 | ||
1681 | /* This handles the .vtable_inherit pseudo-op, which is used to indicate | |
1682 | to the linker the hierarchy in which a particular table resides. The | |
1683 | syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */ | |
1684 | ||
904a31bf | 1685 | struct fix * |
68d20676 | 1686 | obj_elf_get_vtable_inherit (void) |
252b5132 RH |
1687 | { |
1688 | char *cname, *pname; | |
1689 | symbolS *csym, *psym; | |
1690 | char c, bad = 0; | |
1691 | ||
1692 | if (*input_line_pointer == '#') | |
1693 | ++input_line_pointer; | |
1694 | ||
d02603dc | 1695 | c = get_symbol_name (& cname); |
252b5132 RH |
1696 | csym = symbol_find (cname); |
1697 | ||
1698 | /* GCFIXME: should check that we don't have two .vtable_inherits for | |
1699 | the same child symbol. Also, we can currently only do this if the | |
1700 | child symbol is already exists and is placed in a fragment. */ | |
1701 | ||
49309057 | 1702 | if (csym == NULL || symbol_get_frag (csym) == NULL) |
252b5132 | 1703 | { |
bd3ba5d1 | 1704 | as_bad (_("expected `%s' to have already been set for .vtable_inherit"), |
252b5132 RH |
1705 | cname); |
1706 | bad = 1; | |
1707 | } | |
1708 | ||
1709 | *input_line_pointer = c; | |
1710 | ||
d02603dc | 1711 | SKIP_WHITESPACE_AFTER_NAME (); |
252b5132 RH |
1712 | if (*input_line_pointer != ',') |
1713 | { | |
bd3ba5d1 | 1714 | as_bad (_("expected comma after name in .vtable_inherit")); |
252b5132 | 1715 | ignore_rest_of_line (); |
904a31bf | 1716 | return NULL; |
252b5132 RH |
1717 | } |
1718 | ||
1719 | ++input_line_pointer; | |
1720 | SKIP_WHITESPACE (); | |
1721 | ||
1722 | if (*input_line_pointer == '#') | |
1723 | ++input_line_pointer; | |
1724 | ||
1725 | if (input_line_pointer[0] == '0' | |
1726 | && (input_line_pointer[1] == '\0' | |
3882b010 | 1727 | || ISSPACE (input_line_pointer[1]))) |
252b5132 RH |
1728 | { |
1729 | psym = section_symbol (absolute_section); | |
1730 | ++input_line_pointer; | |
1731 | } | |
1732 | else | |
1733 | { | |
d02603dc | 1734 | c = get_symbol_name (& pname); |
252b5132 | 1735 | psym = symbol_find_or_make (pname); |
d02603dc | 1736 | restore_line_pointer (c); |
252b5132 RH |
1737 | } |
1738 | ||
1739 | demand_empty_rest_of_line (); | |
1740 | ||
1741 | if (bad) | |
904a31bf | 1742 | return NULL; |
252b5132 | 1743 | |
9c2799c2 | 1744 | gas_assert (symbol_get_value_expression (csym)->X_op == O_constant); |
904a31bf AM |
1745 | return fix_new (symbol_get_frag (csym), |
1746 | symbol_get_value_expression (csym)->X_add_number, | |
1747 | 0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT); | |
252b5132 | 1748 | } |
fa306131 | 1749 | |
68d20676 NC |
1750 | /* This is a version of obj_elf_get_vtable_inherit() that is |
1751 | suitable for use in struct _pseudo_type tables. */ | |
1752 | ||
1753 | void | |
1754 | obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED) | |
1755 | { | |
1756 | (void) obj_elf_get_vtable_inherit (); | |
1757 | } | |
1758 | ||
252b5132 RH |
1759 | /* This handles the .vtable_entry pseudo-op, which is used to indicate |
1760 | to the linker that a vtable slot was used. The syntax is | |
1761 | ".vtable_entry tablename, offset". */ | |
1762 | ||
904a31bf | 1763 | struct fix * |
68d20676 | 1764 | obj_elf_get_vtable_entry (void) |
252b5132 | 1765 | { |
252b5132 RH |
1766 | symbolS *sym; |
1767 | offsetT offset; | |
252b5132 RH |
1768 | |
1769 | if (*input_line_pointer == '#') | |
1770 | ++input_line_pointer; | |
1771 | ||
6e8bd58f | 1772 | sym = get_sym_from_input_line_and_check (); |
252b5132 RH |
1773 | if (*input_line_pointer != ',') |
1774 | { | |
bd3ba5d1 | 1775 | as_bad (_("expected comma after name in .vtable_entry")); |
252b5132 | 1776 | ignore_rest_of_line (); |
904a31bf | 1777 | return NULL; |
252b5132 RH |
1778 | } |
1779 | ||
1780 | ++input_line_pointer; | |
1781 | if (*input_line_pointer == '#') | |
1782 | ++input_line_pointer; | |
1783 | ||
1784 | offset = get_absolute_expression (); | |
1785 | ||
252b5132 | 1786 | demand_empty_rest_of_line (); |
904a31bf AM |
1787 | |
1788 | return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0, | |
1789 | BFD_RELOC_VTABLE_ENTRY); | |
252b5132 RH |
1790 | } |
1791 | ||
68d20676 NC |
1792 | /* This is a version of obj_elf_get_vtable_entry() that is |
1793 | suitable for use in struct _pseudo_type tables. */ | |
1794 | ||
1795 | void | |
1796 | obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED) | |
1797 | { | |
1798 | (void) obj_elf_get_vtable_entry (); | |
1799 | } | |
1800 | ||
0420f52b MR |
1801 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) |
1802 | ||
1803 | static inline int | |
1804 | skip_past_char (char ** str, char c) | |
1805 | { | |
1806 | if (**str == c) | |
1807 | { | |
1808 | (*str)++; | |
1809 | return 0; | |
1810 | } | |
1811 | else | |
1812 | return -1; | |
1813 | } | |
1814 | #define skip_past_comma(str) skip_past_char (str, ',') | |
1815 | ||
9440a904 RS |
1816 | /* A list of attributes that have been explicitly set by the assembly code. |
1817 | VENDOR is the vendor id, BASE is the tag shifted right by the number | |
1818 | of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */ | |
1819 | struct recorded_attribute_info { | |
1820 | struct recorded_attribute_info *next; | |
1821 | int vendor; | |
1822 | unsigned int base; | |
1823 | unsigned long mask; | |
1824 | }; | |
1825 | static struct recorded_attribute_info *recorded_attributes; | |
1826 | ||
1827 | /* Record that we have seen an explicit specification of attribute TAG | |
1828 | for vendor VENDOR. */ | |
1829 | ||
1830 | static void | |
1831 | record_attribute (int vendor, unsigned int tag) | |
1832 | { | |
1833 | unsigned int base; | |
1834 | unsigned long mask; | |
1835 | struct recorded_attribute_info *rai; | |
1836 | ||
1837 | base = tag / (8 * sizeof (rai->mask)); | |
1838 | mask = 1UL << (tag % (8 * sizeof (rai->mask))); | |
1839 | for (rai = recorded_attributes; rai; rai = rai->next) | |
1840 | if (rai->vendor == vendor && rai->base == base) | |
1841 | { | |
1842 | rai->mask |= mask; | |
1843 | return; | |
1844 | } | |
1845 | ||
1846 | rai = XNEW (struct recorded_attribute_info); | |
1847 | rai->next = recorded_attributes; | |
1848 | rai->vendor = vendor; | |
1849 | rai->base = base; | |
1850 | rai->mask = mask; | |
1851 | recorded_attributes = rai; | |
1852 | } | |
1853 | ||
1854 | /* Return true if we have seen an explicit specification of attribute TAG | |
1855 | for vendor VENDOR. */ | |
1856 | ||
1857 | bfd_boolean | |
1858 | obj_elf_seen_attribute (int vendor, unsigned int tag) | |
1859 | { | |
1860 | unsigned int base; | |
1861 | unsigned long mask; | |
1862 | struct recorded_attribute_info *rai; | |
1863 | ||
1864 | base = tag / (8 * sizeof (rai->mask)); | |
1865 | mask = 1UL << (tag % (8 * sizeof (rai->mask))); | |
1866 | for (rai = recorded_attributes; rai; rai = rai->next) | |
1867 | if (rai->vendor == vendor && rai->base == base) | |
1868 | return (rai->mask & mask) != 0; | |
1869 | return FALSE; | |
1870 | } | |
1871 | ||
0420f52b MR |
1872 | /* Parse an attribute directive for VENDOR. |
1873 | Returns the attribute number read, or zero on error. */ | |
1874 | ||
1875 | int | |
1876 | obj_elf_vendor_attribute (int vendor) | |
1877 | { | |
1878 | expressionS exp; | |
1879 | int type; | |
1880 | int tag; | |
1881 | unsigned int i = 0; | |
1882 | char *s = NULL; | |
1883 | ||
1884 | /* Read the first number or name. */ | |
1885 | skip_whitespace (input_line_pointer); | |
1886 | s = input_line_pointer; | |
1887 | if (ISDIGIT (*input_line_pointer)) | |
1888 | { | |
1889 | expression (& exp); | |
1890 | if (exp.X_op != O_constant) | |
1891 | goto bad; | |
1892 | tag = exp.X_add_number; | |
1893 | } | |
1894 | else | |
1895 | { | |
1896 | char *name; | |
1897 | ||
1898 | /* A name may contain '_', but no other punctuation. */ | |
1899 | for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_'; | |
1900 | ++input_line_pointer) | |
1901 | i++; | |
1902 | if (i == 0) | |
1903 | goto bad; | |
1904 | ||
a44e2901 | 1905 | name = xstrndup (s, i); |
0420f52b MR |
1906 | |
1907 | #ifndef CONVERT_SYMBOLIC_ATTRIBUTE | |
1908 | #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1 | |
1909 | #endif | |
1910 | ||
1911 | tag = CONVERT_SYMBOLIC_ATTRIBUTE (name); | |
1912 | if (tag == -1) | |
1913 | { | |
1914 | as_bad (_("Attribute name not recognised: %s"), name); | |
1915 | ignore_rest_of_line (); | |
e1fa0163 | 1916 | free (name); |
0420f52b MR |
1917 | return 0; |
1918 | } | |
e1fa0163 | 1919 | free (name); |
0420f52b MR |
1920 | } |
1921 | ||
1922 | type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag); | |
1923 | ||
1924 | if (skip_past_comma (&input_line_pointer) == -1) | |
1925 | goto bad; | |
1926 | if (type & 1) | |
1927 | { | |
1928 | expression (& exp); | |
1929 | if (exp.X_op != O_constant) | |
1930 | { | |
1931 | as_bad (_("expected numeric constant")); | |
1932 | ignore_rest_of_line (); | |
1933 | return 0; | |
1934 | } | |
1935 | i = exp.X_add_number; | |
1936 | } | |
1937 | if ((type & 3) == 3 | |
1938 | && skip_past_comma (&input_line_pointer) == -1) | |
1939 | { | |
1940 | as_bad (_("expected comma")); | |
1941 | ignore_rest_of_line (); | |
1942 | return 0; | |
1943 | } | |
1944 | if (type & 2) | |
1945 | { | |
1946 | int len; | |
1947 | ||
1948 | skip_whitespace (input_line_pointer); | |
1949 | if (*input_line_pointer != '"') | |
1950 | goto bad_string; | |
1951 | s = demand_copy_C_string (&len); | |
1952 | } | |
1953 | ||
9440a904 | 1954 | record_attribute (vendor, tag); |
0420f52b MR |
1955 | switch (type & 3) |
1956 | { | |
1957 | case 3: | |
1958 | bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s); | |
1959 | break; | |
1960 | case 2: | |
1961 | bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s); | |
1962 | break; | |
1963 | case 1: | |
1964 | bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i); | |
1965 | break; | |
1966 | default: | |
1967 | abort (); | |
1968 | } | |
1969 | ||
1970 | demand_empty_rest_of_line (); | |
1971 | return tag; | |
dc1e8a47 | 1972 | bad_string: |
0420f52b MR |
1973 | as_bad (_("bad string constant")); |
1974 | ignore_rest_of_line (); | |
1975 | return 0; | |
dc1e8a47 | 1976 | bad: |
0420f52b MR |
1977 | as_bad (_("expected <tag> , <value>")); |
1978 | ignore_rest_of_line (); | |
1979 | return 0; | |
1980 | } | |
1981 | ||
1982 | /* Parse a .gnu_attribute directive. */ | |
1983 | ||
1984 | static void | |
1985 | obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED) | |
1986 | { | |
1987 | obj_elf_vendor_attribute (OBJ_ATTR_GNU); | |
1988 | } | |
1989 | ||
252b5132 | 1990 | void |
dbe2df79 | 1991 | elf_obj_read_begin_hook (void) |
252b5132 RH |
1992 | { |
1993 | #ifdef NEED_ECOFF_DEBUG | |
1994 | if (ECOFF_DEBUGGING) | |
1995 | ecoff_read_begin_hook (); | |
1996 | #endif | |
1997 | } | |
1998 | ||
1999 | void | |
dbe2df79 | 2000 | elf_obj_symbol_new_hook (symbolS *symbolP) |
252b5132 | 2001 | { |
49309057 ILT |
2002 | struct elf_obj_sy *sy_obj; |
2003 | ||
2004 | sy_obj = symbol_get_obj (symbolP); | |
2005 | sy_obj->size = NULL; | |
2006 | sy_obj->versioned_name = NULL; | |
252b5132 RH |
2007 | |
2008 | #ifdef NEED_ECOFF_DEBUG | |
2009 | if (ECOFF_DEBUGGING) | |
2010 | ecoff_symbol_new_hook (symbolP); | |
2011 | #endif | |
2012 | } | |
2013 | ||
8fd3e36b AM |
2014 | /* When setting one symbol equal to another, by default we probably |
2015 | want them to have the same "size", whatever it means in the current | |
2016 | context. */ | |
2017 | ||
2018 | void | |
dbe2df79 | 2019 | elf_copy_symbol_attributes (symbolS *dest, symbolS *src) |
8fd3e36b | 2020 | { |
060adf0e AM |
2021 | struct elf_obj_sy *srcelf = symbol_get_obj (src); |
2022 | struct elf_obj_sy *destelf = symbol_get_obj (dest); | |
2023 | if (srcelf->size) | |
2024 | { | |
2025 | if (destelf->size == NULL) | |
325801bd | 2026 | destelf->size = XNEW (expressionS); |
060adf0e AM |
2027 | *destelf->size = *srcelf->size; |
2028 | } | |
2029 | else | |
2030 | { | |
9fbb53c7 | 2031 | free (destelf->size); |
060adf0e AM |
2032 | destelf->size = NULL; |
2033 | } | |
2034 | S_SET_SIZE (dest, S_GET_SIZE (src)); | |
26eb4093 JJ |
2035 | /* Don't copy visibility. */ |
2036 | S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest)) | |
2037 | | (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1)))); | |
8fd3e36b AM |
2038 | } |
2039 | ||
252b5132 | 2040 | void |
dbe2df79 | 2041 | obj_elf_version (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
2042 | { |
2043 | char *name; | |
2044 | unsigned int c; | |
252b5132 RH |
2045 | char *p; |
2046 | asection *seg = now_seg; | |
2047 | subsegT subseg = now_subseg; | |
2048 | Elf_Internal_Note i_note; | |
2049 | Elf_External_Note e_note; | |
dbe2df79 | 2050 | asection *note_secp = NULL; |
252b5132 RH |
2051 | |
2052 | SKIP_WHITESPACE (); | |
2053 | if (*input_line_pointer == '\"') | |
2054 | { | |
6afdfa61 NC |
2055 | unsigned int len; |
2056 | ||
bf514e21 | 2057 | ++input_line_pointer; /* -> 1st char of string. */ |
252b5132 RH |
2058 | name = input_line_pointer; |
2059 | ||
2060 | while (is_a_char (c = next_char_of_string ())) | |
2061 | ; | |
2062 | c = *input_line_pointer; | |
2063 | *input_line_pointer = '\0'; | |
2064 | *(input_line_pointer - 1) = '\0'; | |
2065 | *input_line_pointer = c; | |
2066 | ||
6afdfa61 | 2067 | /* Create the .note section. */ |
252b5132 | 2068 | note_secp = subseg_new (".note", 0); |
fd361982 | 2069 | bfd_set_section_flags (note_secp, SEC_HAS_CONTENTS | SEC_READONLY); |
ed9c7ee0 | 2070 | record_alignment (note_secp, 2); |
252b5132 | 2071 | |
6afdfa61 NC |
2072 | /* Process the version string. */ |
2073 | len = strlen (name) + 1; | |
252b5132 | 2074 | |
6afdfa61 NC |
2075 | /* PR 3456: Although the name field is padded out to an 4-byte |
2076 | boundary, the namesz field should not be adjusted. */ | |
2077 | i_note.namesz = len; | |
2078 | i_note.descsz = 0; /* No description. */ | |
252b5132 RH |
2079 | i_note.type = NT_VERSION; |
2080 | p = frag_more (sizeof (e_note.namesz)); | |
dbe2df79 | 2081 | md_number_to_chars (p, i_note.namesz, sizeof (e_note.namesz)); |
252b5132 | 2082 | p = frag_more (sizeof (e_note.descsz)); |
dbe2df79 | 2083 | md_number_to_chars (p, i_note.descsz, sizeof (e_note.descsz)); |
252b5132 | 2084 | p = frag_more (sizeof (e_note.type)); |
dbe2df79 | 2085 | md_number_to_chars (p, i_note.type, sizeof (e_note.type)); |
6afdfa61 | 2086 | p = frag_more (len); |
5ab504f9 | 2087 | memcpy (p, name, len); |
252b5132 | 2088 | |
252b5132 RH |
2089 | frag_align (2, 0, 0); |
2090 | ||
2091 | subseg_set (seg, subseg); | |
2092 | } | |
2093 | else | |
6afdfa61 NC |
2094 | as_bad (_("expected quoted string")); |
2095 | ||
252b5132 RH |
2096 | demand_empty_rest_of_line (); |
2097 | } | |
2098 | ||
2099 | static void | |
dbe2df79 | 2100 | obj_elf_size (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 2101 | { |
d02603dc NC |
2102 | char *name; |
2103 | char c = get_symbol_name (&name); | |
252b5132 RH |
2104 | char *p; |
2105 | expressionS exp; | |
2106 | symbolS *sym; | |
2107 | ||
2108 | p = input_line_pointer; | |
2109 | *p = c; | |
d02603dc | 2110 | SKIP_WHITESPACE_AFTER_NAME (); |
252b5132 RH |
2111 | if (*input_line_pointer != ',') |
2112 | { | |
2113 | *p = 0; | |
2114 | as_bad (_("expected comma after name `%s' in .size directive"), name); | |
2115 | *p = c; | |
2116 | ignore_rest_of_line (); | |
2117 | return; | |
2118 | } | |
2119 | input_line_pointer++; | |
2120 | expression (&exp); | |
2121 | if (exp.X_op == O_absent) | |
2122 | { | |
2123 | as_bad (_("missing expression in .size directive")); | |
2124 | exp.X_op = O_constant; | |
2125 | exp.X_add_number = 0; | |
2126 | } | |
2127 | *p = 0; | |
2128 | sym = symbol_find_or_make (name); | |
2129 | *p = c; | |
2130 | if (exp.X_op == O_constant) | |
c538998c JJ |
2131 | { |
2132 | S_SET_SIZE (sym, exp.X_add_number); | |
9fbb53c7 AM |
2133 | xfree (symbol_get_obj (sym)->size); |
2134 | symbol_get_obj (sym)->size = NULL; | |
c538998c | 2135 | } |
252b5132 RH |
2136 | else |
2137 | { | |
325801bd | 2138 | symbol_get_obj (sym)->size = XNEW (expressionS); |
49309057 | 2139 | *symbol_get_obj (sym)->size = exp; |
252b5132 RH |
2140 | } |
2141 | demand_empty_rest_of_line (); | |
2142 | } | |
2143 | ||
2144 | /* Handle the ELF .type pseudo-op. This sets the type of a symbol. | |
44bf2362 | 2145 | There are six syntaxes: |
fa306131 | 2146 | |
252b5132 RH |
2147 | The first (used on Solaris) is |
2148 | .type SYM,#function | |
2149 | The second (used on UnixWare) is | |
2150 | .type SYM,@function | |
2151 | The third (reportedly to be used on Irix 6.0) is | |
2152 | .type SYM STT_FUNC | |
2153 | The fourth (used on NetBSD/Arm and Linux/ARM) is | |
2154 | .type SYM,%function | |
aa8c34c3 JE |
2155 | The fifth (used on SVR4/860) is |
2156 | .type SYM,"function" | |
44bf2362 NC |
2157 | The sixth (emitted by recent SunPRO under Solaris) is |
2158 | .type SYM,[0-9] | |
2159 | where the integer is the STT_* value. | |
252b5132 RH |
2160 | */ |
2161 | ||
44bf2362 NC |
2162 | static char * |
2163 | obj_elf_type_name (char *cp) | |
2164 | { | |
2165 | char *p; | |
2166 | ||
2167 | p = input_line_pointer; | |
2168 | if (*input_line_pointer >= '0' | |
2169 | && *input_line_pointer <= '9') | |
2170 | { | |
2171 | while (*input_line_pointer >= '0' | |
2172 | && *input_line_pointer <= '9') | |
2173 | ++input_line_pointer; | |
2174 | *cp = *input_line_pointer; | |
2175 | *input_line_pointer = '\0'; | |
2176 | } | |
2177 | else | |
d02603dc | 2178 | *cp = get_symbol_name (&p); |
44bf2362 NC |
2179 | |
2180 | return p; | |
2181 | } | |
2182 | ||
252b5132 | 2183 | static void |
dbe2df79 | 2184 | obj_elf_type (int ignore ATTRIBUTE_UNUSED) |
252b5132 | 2185 | { |
252b5132 RH |
2186 | char c; |
2187 | int type; | |
1e9cc1c2 | 2188 | const char *type_name; |
252b5132 | 2189 | symbolS *sym; |
904a31bf | 2190 | elf_symbol_type *elfsym; |
252b5132 | 2191 | |
6e8bd58f NS |
2192 | sym = get_sym_from_input_line_and_check (); |
2193 | c = *input_line_pointer; | |
904a31bf | 2194 | elfsym = (elf_symbol_type *) symbol_get_bfdsym (sym); |
252b5132 | 2195 | |
252b5132 RH |
2196 | if (*input_line_pointer == ',') |
2197 | ++input_line_pointer; | |
2198 | ||
2199 | SKIP_WHITESPACE (); | |
2200 | if ( *input_line_pointer == '#' | |
2201 | || *input_line_pointer == '@' | |
aa8c34c3 | 2202 | || *input_line_pointer == '"' |
252b5132 RH |
2203 | || *input_line_pointer == '%') |
2204 | ++input_line_pointer; | |
2205 | ||
1e9cc1c2 | 2206 | type_name = obj_elf_type_name (& c); |
252b5132 RH |
2207 | |
2208 | type = 0; | |
1e9cc1c2 NC |
2209 | if (strcmp (type_name, "function") == 0 |
2210 | || strcmp (type_name, "2") == 0 | |
2211 | || strcmp (type_name, "STT_FUNC") == 0) | |
252b5132 | 2212 | type = BSF_FUNCTION; |
1e9cc1c2 NC |
2213 | else if (strcmp (type_name, "object") == 0 |
2214 | || strcmp (type_name, "1") == 0 | |
2215 | || strcmp (type_name, "STT_OBJECT") == 0) | |
252b5132 | 2216 | type = BSF_OBJECT; |
1e9cc1c2 NC |
2217 | else if (strcmp (type_name, "tls_object") == 0 |
2218 | || strcmp (type_name, "6") == 0 | |
2219 | || strcmp (type_name, "STT_TLS") == 0) | |
b9734f35 | 2220 | type = BSF_OBJECT | BSF_THREAD_LOCAL; |
1e9cc1c2 NC |
2221 | else if (strcmp (type_name, "notype") == 0 |
2222 | || strcmp (type_name, "0") == 0 | |
2223 | || strcmp (type_name, "STT_NOTYPE") == 0) | |
e7b9a8c1 | 2224 | ; |
1e9cc1c2 NC |
2225 | else if (strcmp (type_name, "common") == 0 |
2226 | || strcmp (type_name, "5") == 0 | |
2227 | || strcmp (type_name, "STT_COMMON") == 0) | |
504b7d20 NC |
2228 | { |
2229 | type = BSF_OBJECT; | |
2230 | ||
2231 | if (! S_IS_COMMON (sym)) | |
2232 | { | |
2233 | if (S_IS_VOLATILE (sym)) | |
2234 | { | |
2235 | sym = symbol_clone (sym, 1); | |
2236 | S_SET_SEGMENT (sym, bfd_com_section_ptr); | |
2237 | S_SET_VALUE (sym, 0); | |
2238 | S_SET_EXTERNAL (sym); | |
2239 | symbol_set_frag (sym, &zero_address_frag); | |
2240 | S_CLEAR_VOLATILE (sym); | |
2241 | } | |
2242 | else if (S_IS_DEFINED (sym) || symbol_equated_p (sym)) | |
2243 | as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym)); | |
2244 | else | |
2245 | { | |
2246 | /* FIXME: Is it safe to just change the section ? */ | |
2247 | S_SET_SEGMENT (sym, bfd_com_section_ptr); | |
2248 | S_SET_VALUE (sym, 0); | |
2249 | S_SET_EXTERNAL (sym); | |
2250 | } | |
2251 | } | |
2252 | } | |
1e9cc1c2 NC |
2253 | else if (strcmp (type_name, "gnu_indirect_function") == 0 |
2254 | || strcmp (type_name, "10") == 0 | |
2255 | || strcmp (type_name, "STT_GNU_IFUNC") == 0) | |
d8045f23 | 2256 | { |
df3a023b AM |
2257 | struct elf_backend_data *bed; |
2258 | ||
2259 | bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput); | |
2260 | if (bed->elf_osabi == ELFOSABI_NONE) | |
2261 | bed->elf_osabi = ELFOSABI_GNU; | |
2262 | else if (bed->elf_osabi != ELFOSABI_GNU | |
2263 | && bed->elf_osabi != ELFOSABI_FREEBSD) | |
2264 | as_bad (_("symbol type \"%s\" is supported only by GNU " | |
2265 | "and FreeBSD targets"), type_name); | |
8e4979ac NC |
2266 | /* MIPS targets do not support IFUNCS. */ |
2267 | else if (bed->target_id == MIPS_ELF_DATA) | |
2268 | as_bad (_("symbol type \"%s\" is not supported by " | |
2269 | "MIPS targets"), type_name); | |
cc364be6 | 2270 | elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_ifunc; |
d8045f23 NC |
2271 | type = BSF_FUNCTION | BSF_GNU_INDIRECT_FUNCTION; |
2272 | } | |
1e9cc1c2 | 2273 | else if (strcmp (type_name, "gnu_unique_object") == 0) |
3e7a7d11 | 2274 | { |
d3ce72d0 | 2275 | struct elf_backend_data *bed; |
3e7a7d11 | 2276 | |
d3ce72d0 | 2277 | bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput); |
df3a023b AM |
2278 | if (bed->elf_osabi == ELFOSABI_NONE) |
2279 | bed->elf_osabi = ELFOSABI_GNU; | |
2280 | else if (bed->elf_osabi != ELFOSABI_GNU) | |
3e7a7d11 | 2281 | as_bad (_("symbol type \"%s\" is supported only by GNU targets"), |
1e9cc1c2 | 2282 | type_name); |
cc364be6 | 2283 | elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_unique; |
3e7a7d11 NC |
2284 | type = BSF_OBJECT | BSF_GNU_UNIQUE; |
2285 | } | |
904a31bf | 2286 | #ifdef md_elf_symbol_type |
1e9cc1c2 | 2287 | else if ((type = md_elf_symbol_type (type_name, sym, elfsym)) != -1) |
904a31bf AM |
2288 | ; |
2289 | #endif | |
252b5132 | 2290 | else |
1e9cc1c2 | 2291 | as_bad (_("unrecognized symbol type \"%s\""), type_name); |
252b5132 RH |
2292 | |
2293 | *input_line_pointer = c; | |
2294 | ||
aa8c34c3 JE |
2295 | if (*input_line_pointer == '"') |
2296 | ++input_line_pointer; | |
2297 | ||
f2d4ba38 JB |
2298 | #ifdef md_elf_symbol_type_change |
2299 | if (!md_elf_symbol_type_change (sym, elfsym, type)) | |
2300 | #endif | |
2301 | { | |
2302 | flagword mask = BSF_FUNCTION | BSF_OBJECT; | |
2303 | ||
2304 | if (type != BSF_FUNCTION) | |
2305 | mask |= BSF_GNU_INDIRECT_FUNCTION; | |
2306 | if (type != BSF_OBJECT) | |
2307 | { | |
2308 | mask |= BSF_GNU_UNIQUE | BSF_THREAD_LOCAL; | |
2309 | ||
2310 | if (S_IS_COMMON (sym)) | |
2311 | { | |
2312 | as_bad (_("cannot change type of common symbol '%s'"), | |
2313 | S_GET_NAME (sym)); | |
2314 | mask = type = 0; | |
2315 | } | |
2316 | } | |
2317 | ||
2318 | /* Don't warn when changing to STT_NOTYPE. */ | |
2319 | if (type) | |
2320 | { | |
2321 | flagword new = (elfsym->symbol.flags & ~mask) | type; | |
2322 | ||
2323 | if (new != (elfsym->symbol.flags | type)) | |
2324 | as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym)); | |
2325 | elfsym->symbol.flags = new; | |
2326 | } | |
2327 | else | |
2328 | elfsym->symbol.flags &= ~mask; | |
2329 | } | |
252b5132 RH |
2330 | |
2331 | demand_empty_rest_of_line (); | |
2332 | } | |
2333 | ||
2334 | static void | |
dbe2df79 | 2335 | obj_elf_ident (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
2336 | { |
2337 | static segT comment_section; | |
2338 | segT old_section = now_seg; | |
2339 | int old_subsection = now_subseg; | |
2340 | ||
5f91fe03 ILT |
2341 | #ifdef md_flush_pending_output |
2342 | md_flush_pending_output (); | |
2343 | #endif | |
2344 | ||
252b5132 RH |
2345 | if (!comment_section) |
2346 | { | |
2347 | char *p; | |
2348 | comment_section = subseg_new (".comment", 0); | |
fd361982 AM |
2349 | bfd_set_section_flags (comment_section, (SEC_READONLY | SEC_HAS_CONTENTS |
2350 | | SEC_MERGE | SEC_STRINGS)); | |
01fb1836 | 2351 | comment_section->entsize = 1; |
cd000bff DJ |
2352 | #ifdef md_elf_section_change_hook |
2353 | md_elf_section_change_hook (); | |
2354 | #endif | |
252b5132 RH |
2355 | p = frag_more (1); |
2356 | *p = 0; | |
2357 | } | |
2358 | else | |
2359 | subseg_set (comment_section, 0); | |
38a57ae7 | 2360 | stringer (8 + 1); |
252b5132 RH |
2361 | subseg_set (old_section, old_subsection); |
2362 | } | |
2363 | ||
2364 | #ifdef INIT_STAB_SECTION | |
2365 | ||
2366 | /* The first entry in a .stabs section is special. */ | |
2367 | ||
2368 | void | |
dbe2df79 | 2369 | obj_elf_init_stab_section (segT seg) |
252b5132 | 2370 | { |
3b4dbbbf | 2371 | const char *file; |
252b5132 RH |
2372 | char *p; |
2373 | char *stabstr_name; | |
2374 | unsigned int stroff; | |
2375 | ||
2376 | /* Force the section to align to a longword boundary. Without this, | |
2377 | UnixWare ar crashes. */ | |
fd361982 | 2378 | bfd_set_section_alignment (seg, 2); |
252b5132 | 2379 | |
bf514e21 | 2380 | /* Make space for this first symbol. */ |
252b5132 | 2381 | p = frag_more (12); |
bf514e21 | 2382 | /* Zero it out. */ |
252b5132 | 2383 | memset (p, 0, 12); |
3b4dbbbf | 2384 | file = as_where (NULL); |
29a2809e | 2385 | stabstr_name = concat (segment_name (seg), "str", (char *) NULL); |
0acc7632 | 2386 | stroff = get_stab_string_offset (file, stabstr_name, TRUE); |
91952a06 | 2387 | know (stroff == 1 || (stroff == 0 && file[0] == '\0')); |
252b5132 RH |
2388 | md_number_to_chars (p, stroff, 4); |
2389 | seg_info (seg)->stabu.p = p; | |
2390 | } | |
2391 | ||
2392 | #endif | |
2393 | ||
2394 | /* Fill in the counts in the first entry in a .stabs section. */ | |
2395 | ||
2396 | static void | |
dbe2df79 | 2397 | adjust_stab_sections (bfd *abfd, asection *sec, void *xxx ATTRIBUTE_UNUSED) |
252b5132 RH |
2398 | { |
2399 | char *name; | |
2400 | asection *strsec; | |
2401 | char *p; | |
2402 | int strsz, nsyms; | |
2403 | ||
2404 | if (strncmp (".stab", sec->name, 5)) | |
2405 | return; | |
2406 | if (!strcmp ("str", sec->name + strlen (sec->name) - 3)) | |
2407 | return; | |
2408 | ||
e1fa0163 | 2409 | name = concat (sec->name, "str", NULL); |
252b5132 RH |
2410 | strsec = bfd_get_section_by_name (abfd, name); |
2411 | if (strsec) | |
fd361982 | 2412 | strsz = bfd_section_size (strsec); |
252b5132 RH |
2413 | else |
2414 | strsz = 0; | |
fd361982 | 2415 | nsyms = bfd_section_size (sec) / 12 - 1; |
252b5132 RH |
2416 | |
2417 | p = seg_info (sec)->stabu.p; | |
9c2799c2 | 2418 | gas_assert (p != 0); |
252b5132 | 2419 | |
dbe2df79 AM |
2420 | bfd_h_put_16 (abfd, nsyms, p + 6); |
2421 | bfd_h_put_32 (abfd, strsz, p + 8); | |
e1fa0163 | 2422 | free (name); |
252b5132 RH |
2423 | } |
2424 | ||
2425 | #ifdef NEED_ECOFF_DEBUG | |
2426 | ||
2427 | /* This function is called by the ECOFF code. It is supposed to | |
2428 | record the external symbol information so that the backend can | |
2429 | write it out correctly. The ELF backend doesn't actually handle | |
2430 | this at the moment, so we do it ourselves. We save the information | |
2431 | in the symbol. */ | |
2432 | ||
ae4a729b AM |
2433 | #ifdef OBJ_MAYBE_ELF |
2434 | static | |
2435 | #endif | |
252b5132 | 2436 | void |
dbe2df79 | 2437 | elf_ecoff_set_ext (symbolS *sym, struct ecoff_extr *ext) |
252b5132 | 2438 | { |
dbe2df79 | 2439 | symbol_get_bfdsym (sym)->udata.p = ext; |
252b5132 RH |
2440 | } |
2441 | ||
2442 | /* This function is called by bfd_ecoff_debug_externals. It is | |
2443 | supposed to *EXT to the external symbol information, and return | |
2444 | whether the symbol should be used at all. */ | |
2445 | ||
b34976b6 | 2446 | static bfd_boolean |
dbe2df79 | 2447 | elf_get_extr (asymbol *sym, EXTR *ext) |
252b5132 RH |
2448 | { |
2449 | if (sym->udata.p == NULL) | |
b34976b6 | 2450 | return FALSE; |
252b5132 | 2451 | *ext = *(EXTR *) sym->udata.p; |
b34976b6 | 2452 | return TRUE; |
252b5132 RH |
2453 | } |
2454 | ||
2455 | /* This function is called by bfd_ecoff_debug_externals. It has | |
2456 | nothing to do for ELF. */ | |
2457 | ||
252b5132 | 2458 | static void |
dbe2df79 AM |
2459 | elf_set_index (asymbol *sym ATTRIBUTE_UNUSED, |
2460 | bfd_size_type indx ATTRIBUTE_UNUSED) | |
252b5132 RH |
2461 | { |
2462 | } | |
2463 | ||
2464 | #endif /* NEED_ECOFF_DEBUG */ | |
2465 | ||
2466 | void | |
dbe2df79 | 2467 | elf_frob_symbol (symbolS *symp, int *puntp) |
252b5132 | 2468 | { |
49309057 | 2469 | struct elf_obj_sy *sy_obj; |
49002d7f | 2470 | expressionS *size; |
6914be53 | 2471 | struct elf_versioned_name_list *versioned_name; |
49309057 | 2472 | |
252b5132 RH |
2473 | #ifdef NEED_ECOFF_DEBUG |
2474 | if (ECOFF_DEBUGGING) | |
2475 | ecoff_frob_symbol (symp); | |
2476 | #endif | |
2477 | ||
49309057 ILT |
2478 | sy_obj = symbol_get_obj (symp); |
2479 | ||
49002d7f L |
2480 | size = sy_obj->size; |
2481 | if (size != NULL) | |
252b5132 | 2482 | { |
49002d7f L |
2483 | if (resolve_expression (size) |
2484 | && size->X_op == O_constant) | |
2485 | S_SET_SIZE (symp, size->X_add_number); | |
e1e90034 | 2486 | else |
49002d7f | 2487 | { |
a90fb5e3 | 2488 | if (!flag_allow_nonconst_size) |
869fe6ea AM |
2489 | as_bad (_(".size expression for %s " |
2490 | "does not evaluate to a constant"), S_GET_NAME (symp)); | |
21be61f5 | 2491 | else |
869fe6ea AM |
2492 | as_warn (_(".size expression for %s " |
2493 | "does not evaluate to a constant"), S_GET_NAME (symp)); | |
49002d7f | 2494 | } |
49309057 ILT |
2495 | free (sy_obj->size); |
2496 | sy_obj->size = NULL; | |
252b5132 RH |
2497 | } |
2498 | ||
6914be53 L |
2499 | versioned_name = sy_obj->versioned_name; |
2500 | if (versioned_name) | |
252b5132 RH |
2501 | { |
2502 | /* This symbol was given a new name with the .symver directive. | |
13c56984 AM |
2503 | If this is an external reference, just rename the symbol to |
2504 | include the version string. This will make the relocs be | |
6914be53 | 2505 | against the correct versioned symbol. */ |
252b5132 | 2506 | |
6914be53 L |
2507 | /* We will have already reported an version error. */ |
2508 | if (sy_obj->bad_version) | |
2509 | *puntp = TRUE; | |
2510 | /* elf_frob_file_before_adjust only allows one version symbol for | |
2511 | renamed symbol. */ | |
2512 | else if (sy_obj->rename) | |
2513 | S_SET_NAME (symp, versioned_name->name); | |
2514 | else if (S_IS_COMMON (symp)) | |
252b5132 | 2515 | { |
6914be53 L |
2516 | as_bad (_("`%s' can't be versioned to common symbol '%s'"), |
2517 | versioned_name->name, S_GET_NAME (symp)); | |
2518 | *puntp = TRUE; | |
252b5132 RH |
2519 | } |
2520 | else | |
2521 | { | |
6914be53 L |
2522 | asymbol *bfdsym; |
2523 | elf_symbol_type *elfsym; | |
2524 | ||
2525 | /* This is a definition. Add an alias for each version. | |
2526 | FIXME: Using an alias will permit the debugging information | |
2527 | to refer to the right symbol. However, it's not clear | |
2528 | whether it is the best approach. */ | |
2529 | ||
2530 | /* FIXME: Creating a new symbol here is risky. We're | |
2531 | in the final loop over the symbol table. We can | |
2532 | get away with it only because the symbol goes to | |
2533 | the end of the list, where the loop will still see | |
2534 | it. It would probably be better to do this in | |
2535 | obj_frob_file_before_adjust. */ | |
2536 | for (; versioned_name != NULL; | |
2537 | versioned_name = versioned_name->next) | |
79082ff0 | 2538 | { |
6914be53 | 2539 | symbolS *symp2 = symbol_find_or_make (versioned_name->name); |
252b5132 | 2540 | |
79082ff0 | 2541 | S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp)); |
252b5132 | 2542 | |
79082ff0 L |
2543 | /* Subtracting out the frag address here is a hack |
2544 | because we are in the middle of the final loop. */ | |
2545 | S_SET_VALUE (symp2, | |
2546 | (S_GET_VALUE (symp) | |
2547 | - symbol_get_frag (symp)->fr_address)); | |
252b5132 | 2548 | |
79082ff0 | 2549 | symbol_set_frag (symp2, symbol_get_frag (symp)); |
252b5132 | 2550 | |
79082ff0 L |
2551 | /* This will copy over the size information. */ |
2552 | copy_symbol_attributes (symp2, symp); | |
252b5132 | 2553 | |
26eb4093 JJ |
2554 | S_SET_OTHER (symp2, S_GET_OTHER (symp)); |
2555 | ||
79082ff0 L |
2556 | if (S_IS_WEAK (symp)) |
2557 | S_SET_WEAK (symp2); | |
252b5132 | 2558 | |
79082ff0 L |
2559 | if (S_IS_EXTERNAL (symp)) |
2560 | S_SET_EXTERNAL (symp2); | |
2561 | } | |
6914be53 L |
2562 | |
2563 | switch (symbol_get_obj (symp)->visibility) | |
2564 | { | |
2565 | case visibility_unchanged: | |
2566 | break; | |
2567 | case visibility_hidden: | |
2568 | bfdsym = symbol_get_bfdsym (symp); | |
2569 | elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), | |
2570 | bfdsym); | |
2571 | elfsym->internal_elf_sym.st_other &= ~3; | |
2572 | elfsym->internal_elf_sym.st_other |= STV_HIDDEN; | |
2573 | break; | |
2574 | case visibility_remove: | |
31c89d60 | 2575 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); |
6914be53 L |
2576 | break; |
2577 | case visibility_local: | |
2578 | S_CLEAR_EXTERNAL (symp); | |
2579 | break; | |
2580 | } | |
252b5132 RH |
2581 | } |
2582 | } | |
2583 | ||
2584 | /* Double check weak symbols. */ | |
49309057 | 2585 | if (S_IS_WEAK (symp)) |
252b5132 RH |
2586 | { |
2587 | if (S_IS_COMMON (symp)) | |
6ce8b369 | 2588 | as_bad (_("symbol `%s' can not be both weak and common"), |
252b5132 RH |
2589 | S_GET_NAME (symp)); |
2590 | } | |
252b5132 RH |
2591 | } |
2592 | ||
060adf0e AM |
2593 | struct group_list |
2594 | { | |
2595 | asection **head; /* Section lists. */ | |
060adf0e | 2596 | unsigned int num_group; /* Number of lists. */ |
629310ab | 2597 | htab_t indexes; /* Maps group name to index in head array. */ |
060adf0e AM |
2598 | }; |
2599 | ||
db4677b8 AM |
2600 | static struct group_list groups; |
2601 | ||
060adf0e AM |
2602 | /* Called via bfd_map_over_sections. If SEC is a member of a group, |
2603 | add it to a list of sections belonging to the group. INF is a | |
2604 | pointer to a struct group_list, which is where we store the head of | |
b7d07216 L |
2605 | each list. If its link_to_symbol_name isn't NULL, set up its |
2606 | linked-to section. */ | |
060adf0e AM |
2607 | |
2608 | static void | |
b7d07216 L |
2609 | build_additional_section_info (bfd *abfd ATTRIBUTE_UNUSED, |
2610 | asection *sec, void *inf) | |
060adf0e | 2611 | { |
1e9cc1c2 | 2612 | struct group_list *list = (struct group_list *) inf; |
aa1f4858 | 2613 | const char *group_name = elf_group_name (sec); |
060adf0e | 2614 | unsigned int i; |
1e9cc1c2 NC |
2615 | unsigned int *elem_idx; |
2616 | unsigned int *idx_ptr; | |
060adf0e | 2617 | |
b7d07216 L |
2618 | if (sec->map_head.linked_to_symbol_name) |
2619 | { | |
2620 | symbolS *linked_to_sym; | |
2621 | linked_to_sym = symbol_find (sec->map_head.linked_to_symbol_name); | |
2622 | if (!linked_to_sym || !S_IS_DEFINED (linked_to_sym)) | |
2623 | as_bad (_("undefined linked-to symbol `%s' on section `%s'"), | |
2624 | sec->map_head.linked_to_symbol_name, | |
2625 | bfd_section_name (sec)); | |
2626 | else | |
2627 | elf_linked_to_section (sec) = S_GET_SEGMENT (linked_to_sym); | |
2628 | } | |
2629 | ||
060adf0e AM |
2630 | if (group_name == NULL) |
2631 | return; | |
2632 | ||
2633 | /* If this group already has a list, add the section to the head of | |
2634 | the list. */ | |
629310ab | 2635 | elem_idx = (unsigned int *) str_hash_find (list->indexes, group_name); |
1e9cc1c2 | 2636 | if (elem_idx != NULL) |
060adf0e | 2637 | { |
1e9cc1c2 NC |
2638 | elf_next_in_group (sec) = list->head[*elem_idx]; |
2639 | list->head[*elem_idx] = sec; | |
1e9cc1c2 | 2640 | return; |
060adf0e AM |
2641 | } |
2642 | ||
2643 | /* New group. Make the arrays bigger in chunks to minimize calls to | |
2644 | realloc. */ | |
2645 | i = list->num_group; | |
2646 | if ((i & 127) == 0) | |
2647 | { | |
2648 | unsigned int newsize = i + 128; | |
add39d23 | 2649 | list->head = XRESIZEVEC (asection *, list->head, newsize); |
060adf0e AM |
2650 | } |
2651 | list->head[i] = sec; | |
060adf0e | 2652 | list->num_group += 1; |
1e9cc1c2 NC |
2653 | |
2654 | /* Add index to hash. */ | |
325801bd | 2655 | idx_ptr = XNEW (unsigned int); |
1e9cc1c2 | 2656 | *idx_ptr = i; |
629310ab | 2657 | str_hash_insert (list->indexes, group_name, (char *)idx_ptr); |
1e9cc1c2 NC |
2658 | } |
2659 | ||
629310ab ML |
2660 | static int |
2661 | free_section_idx (void **slot, void *arg ATTRIBUTE_UNUSED) | |
1e9cc1c2 | 2662 | { |
629310ab ML |
2663 | string_tuple_t *tuple = *((string_tuple_t **) slot); |
2664 | free ((char *)tuple->value); | |
2665 | return 1; | |
060adf0e AM |
2666 | } |
2667 | ||
db4677b8 AM |
2668 | /* Create symbols for group signature. */ |
2669 | ||
252b5132 | 2670 | void |
709001e9 | 2671 | elf_adjust_symtab (void) |
252b5132 | 2672 | { |
060adf0e AM |
2673 | unsigned int i; |
2674 | ||
060adf0e | 2675 | /* Go find section groups. */ |
db4677b8 AM |
2676 | groups.num_group = 0; |
2677 | groups.head = NULL; | |
629310ab | 2678 | groups.indexes = str_htab_create (); |
b7d07216 L |
2679 | bfd_map_over_sections (stdoutput, build_additional_section_info, |
2680 | &groups); | |
3739860c | 2681 | |
060adf0e AM |
2682 | /* Make the SHT_GROUP sections that describe each section group. We |
2683 | can't set up the section contents here yet, because elf section | |
2684 | indices have yet to be calculated. elf.c:set_group_contents does | |
2685 | the rest of the work. */ | |
db4677b8 | 2686 | for (i = 0; i < groups.num_group; i++) |
060adf0e | 2687 | { |
db4677b8 | 2688 | const char *group_name = elf_group_name (groups.head[i]); |
9758f3fc | 2689 | const char *sec_name; |
060adf0e AM |
2690 | asection *s; |
2691 | flagword flags; | |
9758f3fc | 2692 | struct symbol *sy; |
060adf0e | 2693 | |
060adf0e | 2694 | flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP; |
db4677b8 | 2695 | for (s = groups.head[i]; s != NULL; s = elf_next_in_group (s)) |
68bfbfcc | 2696 | if ((s->flags ^ flags) & SEC_LINK_ONCE) |
d2dab548 AM |
2697 | { |
2698 | flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD; | |
db4677b8 | 2699 | if (s != groups.head[i]) |
d2dab548 AM |
2700 | { |
2701 | as_warn (_("assuming all members of group `%s' are COMDAT"), | |
2702 | group_name); | |
2703 | break; | |
2704 | } | |
2705 | } | |
2706 | ||
709001e9 | 2707 | sec_name = ".group"; |
9758f3fc | 2708 | s = subseg_force_new (sec_name, 0); |
060adf0e | 2709 | if (s == NULL |
fd361982 AM |
2710 | || !bfd_set_section_flags (s, flags) |
2711 | || !bfd_set_section_alignment (s, 2)) | |
060adf0e AM |
2712 | { |
2713 | as_fatal (_("can't create group: %s"), | |
2714 | bfd_errmsg (bfd_get_error ())); | |
2715 | } | |
2f89ff8d | 2716 | elf_section_type (s) = SHT_GROUP; |
060adf0e | 2717 | |
aa1f4858 | 2718 | /* Pass a pointer to the first section in this group. */ |
db4677b8 AM |
2719 | elf_next_in_group (s) = groups.head[i]; |
2720 | elf_sec_group (groups.head[i]) = s; | |
709001e9 MM |
2721 | /* Make sure that the signature symbol for the group has the |
2722 | name of the group. */ | |
2723 | sy = symbol_find_exact (group_name); | |
8d1015a8 | 2724 | if (!sy || !symbol_on_chain (sy, symbol_rootP, symbol_lastP)) |
709001e9 MM |
2725 | { |
2726 | /* Create the symbol now. */ | |
2727 | sy = symbol_new (group_name, now_seg, (valueT) 0, frag_now); | |
69b70cfe RO |
2728 | #ifdef TE_SOLARIS |
2729 | /* Before Solaris 11 build 154, Sun ld rejects local group | |
2730 | signature symbols, so make them weak hidden instead. */ | |
2731 | symbol_get_bfdsym (sy)->flags |= BSF_WEAK; | |
2732 | S_SET_OTHER (sy, STV_HIDDEN); | |
2733 | #else | |
709001e9 | 2734 | symbol_get_obj (sy)->local = 1; |
69b70cfe | 2735 | #endif |
709001e9 MM |
2736 | symbol_table_insert (sy); |
2737 | } | |
2738 | elf_group_id (s) = symbol_get_bfdsym (sy); | |
060adf0e | 2739 | } |
252b5132 RH |
2740 | } |
2741 | ||
709001e9 MM |
2742 | void |
2743 | elf_frob_file (void) | |
2744 | { | |
2745 | bfd_map_over_sections (stdoutput, adjust_stab_sections, NULL); | |
2746 | ||
2747 | #ifdef elf_tc_final_processing | |
2748 | elf_tc_final_processing (); | |
2749 | #endif | |
2750 | } | |
2751 | ||
4a1805b1 | 2752 | /* It removes any unneeded versioned symbols from the symbol table. */ |
339681c0 L |
2753 | |
2754 | void | |
dbe2df79 | 2755 | elf_frob_file_before_adjust (void) |
339681c0 L |
2756 | { |
2757 | if (symbol_rootP) | |
2758 | { | |
2759 | symbolS *symp; | |
2760 | ||
2761 | for (symp = symbol_rootP; symp; symp = symbol_next (symp)) | |
6914be53 L |
2762 | { |
2763 | struct elf_obj_sy *sy_obj = symbol_get_obj (symp); | |
2764 | int is_defined = !!S_IS_DEFINED (symp); | |
00e6e13d | 2765 | |
6914be53 L |
2766 | if (sy_obj->versioned_name) |
2767 | { | |
2768 | char *p = strchr (sy_obj->versioned_name->name, | |
2769 | ELF_VER_CHR); | |
00e6e13d | 2770 | |
6914be53 L |
2771 | if (sy_obj->rename) |
2772 | { | |
2773 | /* The @@@ syntax is a special case. If the symbol is | |
2774 | not defined, 2 `@'s will be removed from the | |
2775 | versioned_name. Otherwise, 1 `@' will be removed. */ | |
2776 | size_t l = strlen (&p[3]) + 1; | |
2777 | memmove (&p[1 + is_defined], &p[3], l); | |
2778 | } | |
2779 | ||
2780 | if (!is_defined) | |
2781 | { | |
2782 | /* Verify that the name isn't using the @@ syntax--this | |
2783 | is reserved for definitions of the default version | |
2784 | to link against. */ | |
2785 | if (!sy_obj->rename && p[1] == ELF_VER_CHR) | |
2786 | { | |
2787 | as_bad (_("invalid attempt to declare external " | |
2788 | "version name as default in symbol `%s'"), | |
2789 | sy_obj->versioned_name->name); | |
2790 | return; | |
2791 | } | |
2792 | ||
2793 | /* Only one version symbol is allowed for undefined | |
2794 | symbol. */ | |
2795 | if (sy_obj->versioned_name->next) | |
2796 | { | |
2797 | as_bad (_("multiple versions [`%s'|`%s'] for " | |
2798 | "symbol `%s'"), | |
2799 | sy_obj->versioned_name->name, | |
2800 | sy_obj->versioned_name->next->name, | |
2801 | S_GET_NAME (symp)); | |
2802 | return; | |
2803 | } | |
2804 | ||
2805 | sy_obj->rename = TRUE; | |
2806 | } | |
2807 | } | |
2808 | ||
2809 | /* If there was .symver or .weak, but symbol was neither | |
2810 | defined nor used anywhere, remove it. */ | |
2811 | if (!is_defined | |
2812 | && (sy_obj->versioned_name || S_IS_WEAK (symp)) | |
2813 | && symbol_used_p (symp) == 0 | |
2814 | && symbol_used_in_reloc_p (symp) == 0) | |
2815 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
2816 | } | |
339681c0 L |
2817 | } |
2818 | } | |
2819 | ||
252b5132 RH |
2820 | /* It is required that we let write_relocs have the opportunity to |
2821 | optimize away fixups before output has begun, since it is possible | |
2822 | to eliminate all fixups for a section and thus we never should | |
2823 | have generated the relocation section. */ | |
2824 | ||
2825 | void | |
dbe2df79 | 2826 | elf_frob_file_after_relocs (void) |
252b5132 | 2827 | { |
db4677b8 AM |
2828 | unsigned int i; |
2829 | ||
2830 | /* Set SHT_GROUP section size. */ | |
2831 | for (i = 0; i < groups.num_group; i++) | |
2832 | { | |
2833 | asection *s, *head, *group; | |
2834 | bfd_size_type size; | |
2835 | ||
2836 | head = groups.head[i]; | |
2837 | size = 4; | |
2838 | for (s = head; s != NULL; s = elf_next_in_group (s)) | |
2839 | size += (s->flags & SEC_RELOC) != 0 ? 8 : 4; | |
2840 | ||
2841 | group = elf_sec_group (head); | |
2842 | subseg_set (group, 0); | |
fd361982 | 2843 | bfd_set_section_size (group, size); |
db4677b8 AM |
2844 | group->contents = (unsigned char *) frag_more (size); |
2845 | frag_now->fr_fix = frag_now_fix_octets (); | |
2846 | frag_wane (frag_now); | |
2847 | } | |
2848 | ||
2849 | /* Cleanup hash. */ | |
629310ab ML |
2850 | htab_traverse (groups.indexes, free_section_idx, NULL); |
2851 | htab_delete (groups.indexes); | |
db4677b8 | 2852 | |
252b5132 RH |
2853 | #ifdef NEED_ECOFF_DEBUG |
2854 | if (ECOFF_DEBUGGING) | |
2855 | /* Generate the ECOFF debugging information. */ | |
2856 | { | |
2857 | const struct ecoff_debug_swap *debug_swap; | |
2858 | struct ecoff_debug_info debug; | |
2859 | char *buf; | |
2860 | asection *sec; | |
2861 | ||
2862 | debug_swap | |
2863 | = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap; | |
dbe2df79 | 2864 | know (debug_swap != NULL); |
252b5132 RH |
2865 | ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap); |
2866 | ||
2867 | /* Set up the pointers in debug. */ | |
2868 | #define SET(ptr, offset, type) \ | |
2869 | debug.ptr = (type) (buf + debug.symbolic_header.offset) | |
2870 | ||
2871 | SET (line, cbLineOffset, unsigned char *); | |
dbe2df79 AM |
2872 | SET (external_dnr, cbDnOffset, void *); |
2873 | SET (external_pdr, cbPdOffset, void *); | |
2874 | SET (external_sym, cbSymOffset, void *); | |
2875 | SET (external_opt, cbOptOffset, void *); | |
252b5132 RH |
2876 | SET (external_aux, cbAuxOffset, union aux_ext *); |
2877 | SET (ss, cbSsOffset, char *); | |
dbe2df79 AM |
2878 | SET (external_fdr, cbFdOffset, void *); |
2879 | SET (external_rfd, cbRfdOffset, void *); | |
252b5132 RH |
2880 | /* ssext and external_ext are set up just below. */ |
2881 | ||
2882 | #undef SET | |
2883 | ||
2884 | /* Set up the external symbols. */ | |
2885 | debug.ssext = debug.ssext_end = NULL; | |
2886 | debug.external_ext = debug.external_ext_end = NULL; | |
b34976b6 | 2887 | if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, TRUE, |
252b5132 | 2888 | elf_get_extr, elf_set_index)) |
6ce8b369 | 2889 | as_fatal (_("failed to set up debugging information: %s"), |
252b5132 RH |
2890 | bfd_errmsg (bfd_get_error ())); |
2891 | ||
2892 | sec = bfd_get_section_by_name (stdoutput, ".mdebug"); | |
9c2799c2 | 2893 | gas_assert (sec != NULL); |
252b5132 | 2894 | |
b34976b6 | 2895 | know (!stdoutput->output_has_begun); |
252b5132 RH |
2896 | |
2897 | /* We set the size of the section, call bfd_set_section_contents | |
2898 | to force the ELF backend to allocate a file position, and then | |
2899 | write out the data. FIXME: Is this really the best way to do | |
2900 | this? */ | |
fd361982 AM |
2901 | bfd_set_section_size (sec, bfd_ecoff_debug_size (stdoutput, &debug, |
2902 | debug_swap)); | |
252b5132 | 2903 | |
5f91fe03 | 2904 | /* Pass BUF to bfd_set_section_contents because this will |
13c56984 AM |
2905 | eventually become a call to fwrite, and ISO C prohibits |
2906 | passing a NULL pointer to a stdio function even if the | |
2907 | pointer will not be used. */ | |
dbe2df79 | 2908 | if (! bfd_set_section_contents (stdoutput, sec, buf, 0, 0)) |
6ce8b369 | 2909 | as_fatal (_("can't start writing .mdebug section: %s"), |
252b5132 RH |
2910 | bfd_errmsg (bfd_get_error ())); |
2911 | ||
b34976b6 | 2912 | know (stdoutput->output_has_begun); |
252b5132 RH |
2913 | know (sec->filepos != 0); |
2914 | ||
2915 | if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap, | |
2916 | sec->filepos)) | |
6ce8b369 | 2917 | as_fatal (_("could not write .mdebug section: %s"), |
252b5132 RH |
2918 | bfd_errmsg (bfd_get_error ())); |
2919 | } | |
2920 | #endif /* NEED_ECOFF_DEBUG */ | |
2921 | } | |
2922 | ||
bc6b4acc RO |
2923 | static void |
2924 | elf_generate_asm_lineno (void) | |
2925 | { | |
2926 | #ifdef NEED_ECOFF_DEBUG | |
2927 | if (ECOFF_DEBUGGING) | |
2928 | ecoff_generate_asm_lineno (); | |
2929 | #endif | |
2930 | } | |
2931 | ||
2932 | static void | |
bd937d21 L |
2933 | elf_process_stab (segT sec ATTRIBUTE_UNUSED, |
2934 | int what ATTRIBUTE_UNUSED, | |
2935 | const char *string ATTRIBUTE_UNUSED, | |
2936 | int type ATTRIBUTE_UNUSED, | |
2937 | int other ATTRIBUTE_UNUSED, | |
2938 | int desc ATTRIBUTE_UNUSED) | |
bc6b4acc RO |
2939 | { |
2940 | #ifdef NEED_ECOFF_DEBUG | |
2941 | if (ECOFF_DEBUGGING) | |
2942 | ecoff_stab (sec, what, string, type, other, desc); | |
2943 | #endif | |
2944 | } | |
2945 | ||
5110c57e | 2946 | static int |
dbe2df79 | 2947 | elf_separate_stab_sections (void) |
5110c57e HPN |
2948 | { |
2949 | #ifdef NEED_ECOFF_DEBUG | |
2950 | return (!ECOFF_DEBUGGING); | |
2951 | #else | |
2952 | return 1; | |
2953 | #endif | |
2954 | } | |
2955 | ||
2956 | static void | |
dbe2df79 | 2957 | elf_init_stab_section (segT seg) |
5110c57e HPN |
2958 | { |
2959 | #ifdef NEED_ECOFF_DEBUG | |
2960 | if (!ECOFF_DEBUGGING) | |
2961 | #endif | |
2962 | obj_elf_init_stab_section (seg); | |
2963 | } | |
2964 | ||
252b5132 RH |
2965 | const struct format_ops elf_format_ops = |
2966 | { | |
2967 | bfd_target_elf_flavour, | |
4c63da97 AM |
2968 | 0, /* dfl_leading_underscore */ |
2969 | 1, /* emit_section_symbols */ | |
5110c57e HPN |
2970 | elf_begin, |
2971 | elf_file_symbol, | |
252b5132 RH |
2972 | elf_frob_symbol, |
2973 | elf_frob_file, | |
339681c0 | 2974 | elf_frob_file_before_adjust, |
a161fe53 | 2975 | 0, /* obj_frob_file_before_fix */ |
252b5132 RH |
2976 | elf_frob_file_after_relocs, |
2977 | elf_s_get_size, elf_s_set_size, | |
2978 | elf_s_get_align, elf_s_set_align, | |
4c63da97 | 2979 | elf_s_get_other, |
5110c57e | 2980 | elf_s_set_other, |
4c63da97 | 2981 | 0, /* s_get_desc */ |
5110c57e HPN |
2982 | 0, /* s_set_desc */ |
2983 | 0, /* s_get_type */ | |
2984 | 0, /* s_set_type */ | |
252b5132 | 2985 | elf_copy_symbol_attributes, |
bc6b4acc RO |
2986 | elf_generate_asm_lineno, |
2987 | elf_process_stab, | |
5110c57e HPN |
2988 | elf_separate_stab_sections, |
2989 | elf_init_stab_section, | |
252b5132 RH |
2990 | elf_sec_sym_ok_for_reloc, |
2991 | elf_pop_insert, | |
2992 | #ifdef NEED_ECOFF_DEBUG | |
2993 | elf_ecoff_set_ext, | |
2994 | #else | |
4c63da97 | 2995 | 0, /* ecoff_set_ext */ |
252b5132 | 2996 | #endif |
4c63da97 | 2997 | elf_obj_read_begin_hook, |
4cae74aa | 2998 | elf_obj_symbol_new_hook, |
645ea3ea AM |
2999 | 0, |
3000 | elf_adjust_symtab | |
252b5132 | 3001 | }; |