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