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