1 /* ELF object file format
2 Copyright (C) 1992-2021 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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.
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.
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
21 #define OBJ_HEADER "obj-elf.h"
23 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
28 #ifndef ECOFF_DEBUGGING
29 #define ECOFF_DEBUGGING 0
31 #define NEED_ECOFF_DEBUG
34 #ifdef NEED_ECOFF_DEBUG
36 #include "bfd/ecoff-bfd.h"
40 #include "elf/alpha.h"
52 #include "elf/x86-64.h"
60 #include "elf/nios2.h"
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);
83 static const pseudo_typeS elf_pseudo_table
[] =
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},
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
},
108 /* These are used for stabs-in-elf configurations. */
109 {"line", obj_elf_line
, 0},
111 /* This is a GNU extension to handle symbol versions. */
112 {"symver", obj_elf_symver
, 0},
114 /* A GNU extension to change subsection only. */
115 {"subsection", obj_elf_subsection
, 0},
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},
121 /* A GNU extension for object attributes. */
122 {"gnu_attribute", obj_elf_gnu_attribute
, 0},
124 /* These are used for dwarf2. */
125 { "file", dwarf2_directive_file
, 0 },
126 { "loc", dwarf2_directive_loc
, 0 },
127 { "loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0 },
129 /* We need to trap the section changing calls to handle .previous. */
130 {"data", obj_elf_data
, 0},
131 {"offset", obj_elf_struct
, 0},
132 {"struct", obj_elf_struct
, 0},
133 {"text", obj_elf_text
, 0},
135 {"tls_common", obj_elf_tls_common
, 0},
141 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
143 #ifdef NEED_ECOFF_DEBUG
144 /* COFF style debugging information for ECOFF. .ln is not used; .loc
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 },
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 },
160 /* ECOFF specific debugging information. */
161 { "aent", ecoff_directive_ent
, 1 },
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 },
171 /* Other ECOFF directives. */
172 { "extern", ecoff_directive_extern
, 0 },
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 },
184 {NULL
, NULL
, 0} /* end sentinel */
188 #include "aout/aout64.h"
190 /* This is called when the assembler starts. */
192 asection
*elf_com_section_ptr
;
199 /* Add symbols for the known sections to the symbol table. */
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
));
206 elf_com_section_ptr
= bfd_com_section_ptr
;
210 elf_pop_insert (void)
212 pop_insert (elf_pseudo_table
);
214 pop_insert (ecoff_debug_pseudo_table
);
218 elf_s_get_size (symbolS
*sym
)
220 return S_GET_SIZE (sym
);
224 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
226 S_SET_SIZE (sym
, sz
);
230 elf_s_get_align (symbolS
*sym
)
232 return S_GET_ALIGN (sym
);
236 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
238 S_SET_ALIGN (sym
, align
);
242 elf_s_get_other (symbolS
*sym
)
244 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
248 elf_s_set_other (symbolS
*sym
, int other
)
250 S_SET_OTHER (sym
, other
);
254 elf_sec_sym_ok_for_reloc (asection
*sec
)
256 return obj_sec_sym_ok_for_reloc (sec
);
260 elf_file_symbol (const char *s
, int appfile
)
265 || symbol_rootP
== NULL
266 || (bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
267 || (bsym
->flags
& BSF_FILE
) == 0)
272 sym
= symbol_new (s
, absolute_section
, &zero_address_frag
, 0);
274 name_length
= strlen (s
);
275 if (name_length
> strlen (S_GET_NAME (sym
)))
277 obstack_grow (¬es
, s
, name_length
+ 1);
278 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
281 strcpy ((char *) S_GET_NAME (sym
), s
);
283 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
285 if (symbol_rootP
!= sym
286 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
287 || (bsym
->flags
& BSF_FILE
) == 0))
289 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
290 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
294 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
298 #ifdef NEED_ECOFF_DEBUG
299 ecoff_new_file (s
, appfile
);
303 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
304 Parse a possible alignment value. */
307 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
310 int is_local
= symbol_get_obj (symbolP
)->local
;
312 if (*input_line_pointer
== ',')
314 char *save
= input_line_pointer
;
316 input_line_pointer
++;
319 if (*input_line_pointer
== '"')
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 (startswith (input_line_pointer
, "bss\""))
328 input_line_pointer
+= 4;
329 else if (startswith (input_line_pointer
, "data\""))
330 input_line_pointer
+= 5;
333 char *p
= input_line_pointer
;
338 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
339 if (*input_line_pointer
++ == '"')
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 ();
348 /* ??? Don't ask me why these are always global. */
353 input_line_pointer
= save
;
354 align
= parse_align (is_local
);
355 if (align
== (addressT
) -1)
362 bss_alloc (symbolP
, size
, align
);
363 S_CLEAR_EXTERNAL (symbolP
);
367 S_SET_VALUE (symbolP
, size
);
368 S_SET_ALIGN (symbolP
, align
);
369 S_SET_EXTERNAL (symbolP
);
370 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
373 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
379 obj_elf_common (int is_common
)
381 if (flag_mri
&& is_common
)
384 s_comm_internal (0, elf_common_parse
);
388 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
390 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
393 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
397 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
399 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
402 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
406 get_sym_from_input_line_and_check (void)
412 c
= get_symbol_name (& name
);
413 sym
= symbol_find_or_make (name
);
414 *input_line_pointer
= c
;
415 SKIP_WHITESPACE_AFTER_NAME ();
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"));
424 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
431 symbolP
= get_sym_from_input_line_and_check ();
432 c
= *input_line_pointer
;
433 S_CLEAR_EXTERNAL (symbolP
);
434 symbol_get_obj (symbolP
)->local
= 1;
437 input_line_pointer
++;
439 if (*input_line_pointer
== '\n')
444 demand_empty_rest_of_line ();
448 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
455 symbolP
= get_sym_from_input_line_and_check ();
456 c
= *input_line_pointer
;
457 S_SET_WEAK (symbolP
);
460 input_line_pointer
++;
462 if (*input_line_pointer
== '\n')
467 demand_empty_rest_of_line ();
471 obj_elf_visibility (int visibility
)
476 elf_symbol_type
*elfsym
;
480 symbolP
= get_sym_from_input_line_and_check ();
482 bfdsym
= symbol_get_bfdsym (symbolP
);
483 elfsym
= elf_symbol_from (bfdsym
);
487 elfsym
->internal_elf_sym
.st_other
&= ~3;
488 elfsym
->internal_elf_sym
.st_other
|= visibility
;
490 c
= *input_line_pointer
;
493 input_line_pointer
++;
497 if (*input_line_pointer
== '\n')
503 demand_empty_rest_of_line ();
506 static segT previous_section
;
507 static int previous_subsection
;
511 struct section_stack
*next
;
513 int subseg
, prev_subseg
;
516 static struct section_stack
*section_stack
;
518 /* ELF section flags for unique sections. */
519 #define SEC_ASSEMBLER_SHF_MASK SHF_GNU_RETAIN
521 /* Return TRUE iff SEC matches the section info INF. */
524 get_section_by_match (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
526 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
527 const char *gname
= match
->group_name
;
528 const char *group_name
= elf_group_name (sec
);
529 const char *linked_to_symbol_name
530 = sec
->map_head
.linked_to_symbol_name
;
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
);
535 return (sh_info
== match
->sh_info
536 && sh_flags
== match
->sh_flags
537 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
538 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
539 && sec
->section_id
== match
->section_id
540 && (group_name
== gname
541 || (group_name
!= NULL
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)));
551 /* Handle the .section pseudo-op. This code supports two different
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).
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. */
570 obj_elf_change_section (const char *name
,
574 struct elf_section_match
*match_p
,
581 const struct elf_backend_data
*bed
;
582 const struct bfd_elf_special_section
*ssect
;
586 static struct elf_section_match unused_match
;
587 match_p
= &unused_match
;
590 #ifdef md_flush_pending_output
591 md_flush_pending_output ();
594 /* Switch to the section, creating it if necessary. */
597 struct section_stack
*elt
;
598 elt
= XNEW (struct section_stack
);
599 elt
->next
= section_stack
;
601 elt
->prev_seg
= previous_section
;
602 elt
->subseg
= now_subseg
;
603 elt
->prev_subseg
= previous_subsection
;
606 previous_section
= now_seg
;
607 previous_subsection
= now_subseg
;
609 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section_by_match
,
617 sec
= subseg_force_new (name
, 0);
619 bed
= get_elf_backend_data (stdoutput
);
620 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
624 bool override
= false;
626 if (type
== SHT_NULL
)
628 else if (type
!= ssect
->type
)
631 /* Some older versions of gcc will emit
633 .section .init_array,"aw",@progbits
635 for __attribute__ ((section (".init_array"))).
636 "@progbits" is incorrect. Also for x86-64 large bss
637 sections, some older versions of gcc will emit
639 .section .lbss,"aw",@progbits
641 "@progbits" is incorrect. */
643 && (bed
->s
->arch_size
!= 64
644 || !(ssect
->attr
& SHF_X86_64_LARGE
))
646 && ssect
->type
!= SHT_INIT_ARRAY
647 && ssect
->type
!= SHT_FINI_ARRAY
648 && ssect
->type
!= SHT_PREINIT_ARRAY
)
650 /* We allow to specify any type for a .note section. */
651 if (ssect
->type
!= SHT_NOTE
652 /* Processor and application defined types are allowed too. */
653 && type
< SHT_LOPROC
)
654 as_warn (_("setting incorrect section type for %s"),
659 as_warn (_("ignoring incorrect section type for %s"),
665 if (old_sec
== NULL
&& ((attr
& ~(SHF_LINK_ORDER
668 & ~ssect
->attr
) != 0)
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
;
675 /* As a GNU extension, we permit a .note section to be
676 allocatable. If the linker sees an allocatable .note
677 section, it will create a PT_NOTE segment in the output
678 file. We also allow "x" for .note.GNU-stack. */
679 if (ssect
->type
== SHT_NOTE
680 && (generic_attr
== SHF_ALLOC
681 || generic_attr
== SHF_EXECINSTR
))
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
] == '.'
690 & ~SHF_STRINGS
) == 0)
692 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
693 else if (generic_attr
== SHF_ALLOC
694 && (strcmp (name
, ".interp") == 0
695 || strcmp (name
, ".strtab") == 0
696 || strcmp (name
, ".symtab") == 0))
698 /* .note.GNU-stack can have SHF_EXECINSTR. */
699 else if (generic_attr
== SHF_EXECINSTR
700 && strcmp (name
, ".note.GNU-stack") == 0)
703 /* A section on Alpha may have SHF_ALPHA_GPREL. */
704 else if ((generic_attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
708 else if (generic_attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
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. */
717 if (match_p
->group_name
== NULL
)
718 as_warn (_("setting incorrect section attributes for %s"),
724 if (!override
&& old_sec
== NULL
)
728 /* Convert ELF type and flags to BFD flags. */
730 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
731 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
732 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
733 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
734 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
735 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
736 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
737 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
738 #ifdef md_elf_section_flags
739 flags
= md_elf_section_flags (flags
, attr
, type
);
743 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
749 if (type
== SHT_NULL
)
750 type
= bfd_elf_get_default_section_type (flags
);
751 elf_section_type (sec
) = type
;
752 elf_section_flags (sec
) = attr
;
753 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->sh_info
;
755 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
756 if (type
== SHT_NOBITS
)
757 seg_info (sec
)->bss
= 1;
759 /* Set the section ID and flags. */
760 sec
->section_id
= match_p
->section_id
;
761 flags
|= match_p
->flags
;
763 /* Set the linked-to symbol name. */
764 sec
->map_head
.linked_to_symbol_name
765 = match_p
->linked_to_symbol_name
;
767 bfd_set_section_flags (sec
, flags
);
768 if (flags
& SEC_MERGE
)
769 sec
->entsize
= entsize
;
770 elf_group_name (sec
) = match_p
->group_name
;
772 /* Add a symbol for this section to the symbol table. */
773 secsym
= symbol_find (name
);
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. */
779 static const expressionS exp
= { .X_op
= O_constant
};
780 symbol_set_value_expression (secsym
, &exp
);
781 symbol_set_bfdsym (secsym
, sec
->symbol
);
784 symbol_table_insert (section_symbol (sec
));
789 && (unsigned) type
!= elf_section_type (old_sec
))
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
);
798 /* Do error when assembly isn't self-consistent. */
799 as_bad (_("changed section type for %s"), name
);
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
)))
814 as_warn (_("ignoring changed section attributes for %s"), name
);
816 as_bad (_("changed section attributes for %s"), name
);
819 /* FIXME: Maybe we should consider removing a previously set
820 processor or application specific attribute as suspicious? */
821 elf_section_flags (sec
) = attr
;
823 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
824 as_bad (_("changed section entity size for %s"), name
);
828 #ifdef md_elf_section_change_hook
829 md_elf_section_change_hook ();
834 obj_elf_parse_section_letters (char *str
, size_t len
,
835 bool *is_clone
, bfd_vma
*gnu_attr
)
851 attr
|= SHF_LINK_ORDER
;
857 attr
|= SHF_EXECINSTR
;
872 *gnu_attr
|= SHF_GNU_MBIND
;
875 *gnu_attr
|= SHF_GNU_RETAIN
;
882 if (*(str
- 1) == 'a')
885 if (len
> 1 && str
[1] == 's')
895 const char *bad_msg
= _("unrecognized .section attribute:"
896 " want a,e,o,w,x,M,S,G,T or number");
897 #ifdef md_elf_section_letter
898 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
899 if (md_attr
!= (bfd_vma
) -1)
906 struct elf_backend_data
*bed
;
907 bfd_vma numeric_flags
= strtoul (str
, &end
, 0);
909 attr
|= numeric_flags
;
911 bed
= (struct elf_backend_data
*)
912 get_elf_backend_data (stdoutput
);
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
)
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
);
932 /* Update str and len, allowing for the fact that
933 we will execute str++ and len-- below. */
939 as_fatal ("%s", bad_msg
);
950 obj_elf_section_type (char *str
, size_t len
, bool warn
)
952 if (len
== 8 && startswith (str
, "progbits"))
954 if (len
== 6 && startswith (str
, "nobits"))
956 if (len
== 4 && startswith (str
, "note"))
958 if (len
== 10 && startswith (str
, "init_array"))
959 return SHT_INIT_ARRAY
;
960 if (len
== 10 && startswith (str
, "fini_array"))
961 return SHT_FINI_ARRAY
;
962 if (len
== 13 && startswith (str
, "preinit_array"))
963 return SHT_PREINIT_ARRAY
;
965 #ifdef md_elf_section_type
967 int md_type
= md_elf_section_type (str
, len
);
976 int type
= strtoul (str
, & end
, 0);
978 if (warn
&& (size_t) (end
- str
) != len
)
979 as_warn (_("extraneous characters at end of numeric section type"));
985 as_warn (_("unrecognized section type"));
990 obj_elf_section_word (char *str
, size_t len
, int *type
)
994 if (len
== 5 && startswith (str
, "write"))
996 if (len
== 5 && startswith (str
, "alloc"))
998 if (len
== 9 && startswith (str
, "execinstr"))
999 return SHF_EXECINSTR
;
1000 if (len
== 7 && startswith (str
, "exclude"))
1002 if (len
== 3 && startswith (str
, "tls"))
1005 #ifdef md_elf_section_word
1007 bfd_vma md_attr
= md_elf_section_word (str
, len
);
1013 ret
= obj_elf_section_type (str
, len
, false);
1017 as_warn (_("unrecognized section attribute"));
1022 /* Get name of section. */
1024 obj_elf_section_name (void)
1029 if (*input_line_pointer
== '"')
1033 name
= demand_copy_C_string (&dummy
);
1036 ignore_rest_of_line ();
1042 char *end
= input_line_pointer
;
1044 while (0 == strchr ("\n\t,; ", *end
))
1046 if (end
== input_line_pointer
)
1048 as_bad (_("missing name"));
1049 ignore_rest_of_line ();
1053 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1055 while (flag_sectname_subst
)
1057 char *subst
= strchr (name
, '%');
1058 if (subst
&& subst
[1] == 'S')
1060 int oldlen
= strlen (name
);
1061 int substlen
= strlen (now_seg
->name
);
1062 int newlen
= oldlen
- 2 + substlen
;
1063 char *newname
= XNEWVEC (char, newlen
+ 1);
1064 int headlen
= subst
- name
;
1065 memcpy (newname
, name
, headlen
);
1066 strcpy (newname
+ headlen
, now_seg
->name
);
1067 strcat (newname
+ headlen
, subst
+ 2);
1075 #ifdef tc_canonicalize_section_name
1076 name
= tc_canonicalize_section_name (name
);
1078 input_line_pointer
= end
;
1085 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1087 const char * gname
= obj_elf_section_name ();
1091 as_warn (_("group name not parseable"));
1095 if (elf_group_name (now_seg
))
1097 as_warn (_("section %s already has a group (%s)"),
1098 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1102 elf_group_name (now_seg
) = xstrdup (gname
);
1103 elf_section_flags (now_seg
) |= SHF_GROUP
;
1107 obj_elf_section (int push
)
1116 subsegT new_subsection
= -1;
1117 struct elf_section_match match
;
1118 unsigned long linked_to_section_index
= -1UL;
1124 #ifdef md_flush_pending_output
1125 md_flush_pending_output ();
1128 previous_section
= now_seg
;
1129 previous_subsection
= now_subseg
;
1131 s_mri_sect (&mri_type
);
1133 #ifdef md_elf_section_change_hook
1134 md_elf_section_change_hook ();
1140 name
= obj_elf_section_name ();
1144 memset (&match
, 0, sizeof (match
));
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
))
1153 as_bad (_("section name '%s' already defined as another symbol"), name
);
1154 ignore_rest_of_line ();
1163 if (*input_line_pointer
== ',')
1165 /* Skip the comma. */
1166 ++input_line_pointer
;
1169 if (push
&& ISDIGIT (*input_line_pointer
))
1171 /* .pushsection has an optional subsection. */
1172 new_subsection
= (subsegT
) get_absolute_expression ();
1176 /* Stop if we don't see a comma. */
1177 if (*input_line_pointer
!= ',')
1180 /* Skip the comma. */
1181 ++input_line_pointer
;
1185 if (*input_line_pointer
== '"')
1189 beg
= demand_copy_C_string (&dummy
);
1192 ignore_rest_of_line ();
1195 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1196 &is_clone
, &gnu_attr
);
1199 if (*input_line_pointer
== ',')
1202 char *save
= input_line_pointer
;
1204 ++input_line_pointer
;
1206 c
= *input_line_pointer
;
1209 beg
= demand_copy_C_string (&dummy
);
1212 ignore_rest_of_line ();
1215 type
= obj_elf_section_type (beg
, strlen (beg
), true);
1217 else if (c
== '@' || c
== '%')
1219 ++input_line_pointer
;
1221 if (ISDIGIT (* input_line_pointer
))
1222 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1225 c
= get_symbol_name (& beg
);
1226 (void) restore_line_pointer (c
);
1227 type
= obj_elf_section_type (beg
,
1228 input_line_pointer
- beg
,
1233 input_line_pointer
= save
;
1237 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1239 ++input_line_pointer
;
1241 entsize
= get_absolute_expression ();
1245 as_warn (_("invalid merge entity size"));
1250 else if ((attr
& SHF_MERGE
) != 0)
1252 as_warn (_("entity size for SHF_MERGE not specified"));
1256 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1258 ++input_line_pointer
;
1260 /* Check for a numeric section index, rather than a symbol name. */
1261 if (ISDIGIT (* input_line_pointer
))
1263 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1268 unsigned int length
;
1270 c
= get_symbol_name (& beg
);
1271 (void) restore_line_pointer (c
);
1272 length
= input_line_pointer
- beg
;
1274 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1278 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1280 as_warn (_("? section flag ignored with G present"));
1284 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1286 ++input_line_pointer
;
1287 match
.group_name
= obj_elf_section_name ();
1288 if (match
.group_name
== NULL
)
1290 else if (*input_line_pointer
== ',')
1292 ++input_line_pointer
;
1294 if (startswith (input_line_pointer
, "comdat"))
1296 input_line_pointer
+= 6;
1300 else if (startswith (name
, ".gnu.linkonce"))
1303 else if ((attr
& SHF_GROUP
) != 0)
1305 as_warn (_("group name for SHF_GROUP not specified"));
1311 const char *now_group
= elf_group_name (now_seg
);
1312 if (now_group
!= NULL
)
1314 match
.group_name
= xstrdup (now_group
);
1315 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1319 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1321 char *save
= input_line_pointer
;
1322 ++input_line_pointer
;
1324 if (ISDIGIT (* input_line_pointer
))
1326 char *t
= input_line_pointer
;
1327 match
.sh_info
= strtoul (input_line_pointer
,
1328 &input_line_pointer
, 0);
1329 if (match
.sh_info
== (unsigned int) -1)
1331 as_warn (_("unsupported mbind section info: %s"), t
);
1336 input_line_pointer
= save
;
1339 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1340 match
.sh_flags
|= SHF_GNU_RETAIN
;
1342 if (*input_line_pointer
== ',')
1344 char *save
= input_line_pointer
;
1346 ++input_line_pointer
;
1348 if (startswith (input_line_pointer
, "unique"))
1350 input_line_pointer
+= 6;
1352 if (*input_line_pointer
== ',')
1354 ++input_line_pointer
;
1356 if (ISDIGIT (* input_line_pointer
))
1360 char *t
= input_line_pointer
;
1361 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1364 id
= strtoul (input_line_pointer
,
1365 &input_line_pointer
, 0);
1366 overflow
= (id
== (unsigned long) -1
1367 && errno
== ERANGE
);
1372 (input_line_pointer
,
1373 (const char **) &input_line_pointer
, 0);
1374 overflow
= id
== ~(bfd_vma
) 0;
1376 if (overflow
|| id
> (unsigned int) -1)
1378 char *linefeed
, saved_char
= 0;
1379 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1381 saved_char
= *linefeed
;
1384 as_bad (_("unsupported section id: %s"), t
);
1386 *linefeed
= saved_char
;
1390 match
.section_id
= id
;
1391 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1397 input_line_pointer
= save
;
1407 if (*input_line_pointer
!= '#')
1409 as_bad (_("character following name is not '#'"));
1410 ignore_rest_of_line ();
1413 ++input_line_pointer
;
1414 c
= get_symbol_name (& beg
);
1415 (void) restore_line_pointer (c
);
1417 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1422 while (*input_line_pointer
++ == ',');
1423 --input_line_pointer
;
1428 demand_empty_rest_of_line ();
1430 if ((gnu_attr
& (SHF_GNU_MBIND
| SHF_GNU_RETAIN
)) != 0)
1432 const struct elf_backend_data
*bed
;
1433 bool mbind_p
= (gnu_attr
& SHF_GNU_MBIND
) != 0;
1435 if (mbind_p
&& (attr
& SHF_ALLOC
) == 0)
1436 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1438 bed
= get_elf_backend_data (stdoutput
);
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");
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
;
1456 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1459 if (linked_to_section_index
!= -1UL)
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 ? */
1466 if (push
&& new_subsection
!= -1)
1467 subseg_set (now_seg
, new_subsection
);
1470 /* Change to the .data section. */
1473 obj_elf_data (int i
)
1475 #ifdef md_flush_pending_output
1476 md_flush_pending_output ();
1479 previous_section
= now_seg
;
1480 previous_subsection
= now_subseg
;
1483 #ifdef md_elf_section_change_hook
1484 md_elf_section_change_hook ();
1488 /* Change to the .text section. */
1491 obj_elf_text (int i
)
1493 #ifdef md_flush_pending_output
1494 md_flush_pending_output ();
1497 previous_section
= now_seg
;
1498 previous_subsection
= now_subseg
;
1501 #ifdef md_elf_section_change_hook
1502 md_elf_section_change_hook ();
1506 /* Change to the *ABS* section. */
1509 obj_elf_struct (int i
)
1511 #ifdef md_flush_pending_output
1512 md_flush_pending_output ();
1515 previous_section
= now_seg
;
1516 previous_subsection
= now_subseg
;
1519 #ifdef md_elf_section_change_hook
1520 md_elf_section_change_hook ();
1525 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1529 #ifdef md_flush_pending_output
1530 md_flush_pending_output ();
1533 previous_section
= now_seg
;
1534 previous_subsection
= now_subseg
;
1536 temp
= get_absolute_expression ();
1537 subseg_set (now_seg
, (subsegT
) temp
);
1538 demand_empty_rest_of_line ();
1540 #ifdef md_elf_section_change_hook
1541 md_elf_section_change_hook ();
1545 /* This can be called from the processor backends if they change
1549 obj_elf_section_change_hook (void)
1551 previous_section
= now_seg
;
1552 previous_subsection
= now_subseg
;
1556 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1561 if (previous_section
== 0)
1563 as_warn (_(".previous without corresponding .section; ignored"));
1567 #ifdef md_flush_pending_output
1568 md_flush_pending_output ();
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
);
1577 #ifdef md_elf_section_change_hook
1578 md_elf_section_change_hook ();
1583 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1585 struct section_stack
*top
= section_stack
;
1589 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1593 #ifdef md_flush_pending_output
1594 md_flush_pending_output ();
1597 section_stack
= top
->next
;
1598 previous_section
= top
->prev_seg
;
1599 previous_subsection
= top
->prev_subseg
;
1600 subseg_set (top
->seg
, top
->subseg
);
1603 #ifdef md_elf_section_change_hook
1604 md_elf_section_change_hook ();
1609 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1611 /* Assume delimiter is part of expression. BSD4.2 as fails with
1612 delightful bug, so we are not being incompatible here. */
1613 new_logical_line (NULL
, get_absolute_expression ());
1614 demand_empty_rest_of_line ();
1617 static struct elf_versioned_name_list
*
1618 obj_elf_find_and_add_versioned_name (const char *version_name
,
1619 const char *sym_name
,
1621 struct elf_obj_sy
*sy_obj
)
1623 struct elf_versioned_name_list
*versioned_name
;
1626 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
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')
1633 as_bad (_("missing version name in `%s' for symbol `%s'"),
1634 version_name
, sym_name
);
1638 versioned_name
= sy_obj
->versioned_name
;
1648 if (strcmp (versioned_name
->name
, version_name
) == 0)
1649 return versioned_name
;
1652 as_bad (_("only one version name with `@@@' is allowed "
1653 "for symbol `%s'"), sym_name
);
1657 sy_obj
->rename
= true;
1660 as_bad (_("invalid version name '%s' for symbol `%s'"),
1661 version_name
, sym_name
);
1666 versioned_name
!= NULL
;
1667 versioned_name
= versioned_name
->next
)
1668 if (strcmp (versioned_name
->name
, version_name
) == 0)
1669 return versioned_name
;
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
;
1678 return versioned_name
;
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. */
1688 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1691 const char *sym_name
;
1695 struct elf_obj_sy
*sy_obj
;
1698 sym
= get_sym_from_input_line_and_check ();
1700 if (*input_line_pointer
!= ',')
1702 as_bad (_("expected comma after name in .symver"));
1703 ignore_rest_of_line ();
1707 ++input_line_pointer
;
1710 /* Temporarily include '@' in symbol names. */
1711 old_lexat
= lex_type
[(unsigned char) '@'];
1712 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1713 c
= get_symbol_name (& name
);
1714 lex_type
[(unsigned char) '@'] = old_lexat
;
1715 sym_name
= S_GET_NAME (sym
);
1717 if (S_IS_COMMON (sym
))
1719 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1721 ignore_rest_of_line ();
1725 p
= strchr (name
, ELF_VER_CHR
);
1728 as_bad (_("missing version name in `%s' for symbol `%s'"),
1730 ignore_rest_of_line ();
1734 sy_obj
= symbol_get_obj (sym
);
1735 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1738 sy_obj
->bad_version
= true;
1739 ignore_rest_of_line ();
1743 (void) restore_line_pointer (c
);
1745 if (*input_line_pointer
== ',')
1747 char *save
= input_line_pointer
;
1749 ++input_line_pointer
;
1751 if (startswith (input_line_pointer
, "local"))
1753 input_line_pointer
+= 5;
1754 sy_obj
->visibility
= visibility_local
;
1756 else if (startswith (input_line_pointer
, "hidden"))
1758 input_line_pointer
+= 6;
1759 sy_obj
->visibility
= visibility_hidden
;
1761 else if (startswith (input_line_pointer
, "remove"))
1763 input_line_pointer
+= 6;
1764 sy_obj
->visibility
= visibility_remove
;
1767 input_line_pointer
= save
;
1770 demand_empty_rest_of_line ();
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". */
1778 obj_elf_get_vtable_inherit (void)
1780 char *cname
, *pname
;
1781 symbolS
*csym
, *psym
;
1784 if (*input_line_pointer
== '#')
1785 ++input_line_pointer
;
1787 c
= get_symbol_name (& cname
);
1788 csym
= symbol_find (cname
);
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. */
1794 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1796 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1801 *input_line_pointer
= c
;
1803 SKIP_WHITESPACE_AFTER_NAME ();
1804 if (*input_line_pointer
!= ',')
1806 as_bad (_("expected comma after name in .vtable_inherit"));
1807 ignore_rest_of_line ();
1811 ++input_line_pointer
;
1814 if (*input_line_pointer
== '#')
1815 ++input_line_pointer
;
1817 if (input_line_pointer
[0] == '0'
1818 && (input_line_pointer
[1] == '\0'
1819 || ISSPACE (input_line_pointer
[1])))
1821 psym
= section_symbol (absolute_section
);
1822 ++input_line_pointer
;
1826 c
= get_symbol_name (& pname
);
1827 psym
= symbol_find_or_make (pname
);
1828 restore_line_pointer (c
);
1831 demand_empty_rest_of_line ();
1836 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
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
);
1842 /* This is a version of obj_elf_get_vtable_inherit() that is
1843 suitable for use in struct _pseudo_type tables. */
1846 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1848 (void) obj_elf_get_vtable_inherit ();
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". */
1856 obj_elf_get_vtable_entry (void)
1861 if (*input_line_pointer
== '#')
1862 ++input_line_pointer
;
1864 sym
= get_sym_from_input_line_and_check ();
1865 if (*input_line_pointer
!= ',')
1867 as_bad (_("expected comma after name in .vtable_entry"));
1868 ignore_rest_of_line ();
1872 ++input_line_pointer
;
1873 if (*input_line_pointer
== '#')
1874 ++input_line_pointer
;
1876 offset
= get_absolute_expression ();
1878 demand_empty_rest_of_line ();
1880 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1881 BFD_RELOC_VTABLE_ENTRY
);
1884 /* This is a version of obj_elf_get_vtable_entry() that is
1885 suitable for use in struct _pseudo_type tables. */
1888 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1890 (void) obj_elf_get_vtable_entry ();
1893 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1896 skip_past_char (char ** str
, char c
)
1906 #define skip_past_comma(str) skip_past_char (str, ',')
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
;
1917 static struct recorded_attribute_info
*recorded_attributes
;
1919 /* Record that we have seen an explicit specification of attribute TAG
1920 for vendor VENDOR. */
1923 record_attribute (int vendor
, unsigned int tag
)
1927 struct recorded_attribute_info
*rai
;
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
)
1938 rai
= XNEW (struct recorded_attribute_info
);
1939 rai
->next
= recorded_attributes
;
1940 rai
->vendor
= vendor
;
1943 recorded_attributes
= rai
;
1946 /* Return true if we have seen an explicit specification of attribute TAG
1947 for vendor VENDOR. */
1950 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1954 struct recorded_attribute_info
*rai
;
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;
1964 /* Parse an attribute directive for VENDOR.
1965 Returns the attribute number read, or zero on error. */
1968 obj_elf_vendor_attribute (int vendor
)
1976 /* Read the first number or name. */
1977 skip_whitespace (input_line_pointer
);
1978 s
= input_line_pointer
;
1979 if (ISDIGIT (*input_line_pointer
))
1982 if (exp
.X_op
!= O_constant
)
1984 tag
= exp
.X_add_number
;
1990 /* A name may contain '_', but no other punctuation. */
1991 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1992 ++input_line_pointer
)
1997 name
= xstrndup (s
, i
);
1999 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2000 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2003 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2006 as_bad (_("Attribute name not recognised: %s"), name
);
2007 ignore_rest_of_line ();
2014 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2016 if (skip_past_comma (&input_line_pointer
) == -1)
2021 if (exp
.X_op
!= O_constant
)
2023 as_bad (_("expected numeric constant"));
2024 ignore_rest_of_line ();
2027 i
= exp
.X_add_number
;
2030 && skip_past_comma (&input_line_pointer
) == -1)
2032 as_bad (_("expected comma"));
2033 ignore_rest_of_line ();
2040 skip_whitespace (input_line_pointer
);
2041 if (*input_line_pointer
!= '"')
2043 s
= demand_copy_C_string (&len
);
2046 record_attribute (vendor
, tag
);
2050 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2053 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2056 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2062 demand_empty_rest_of_line ();
2065 as_bad (_("bad string constant"));
2066 ignore_rest_of_line ();
2069 as_bad (_("expected <tag> , <value>"));
2070 ignore_rest_of_line ();
2074 /* Parse a .gnu_attribute directive. */
2077 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2079 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2083 elf_obj_read_begin_hook (void)
2085 #ifdef NEED_ECOFF_DEBUG
2086 if (ECOFF_DEBUGGING
)
2087 ecoff_read_begin_hook ();
2092 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2094 struct elf_obj_sy
*sy_obj
;
2096 sy_obj
= symbol_get_obj (symbolP
);
2097 sy_obj
->size
= NULL
;
2098 sy_obj
->versioned_name
= NULL
;
2100 #ifdef NEED_ECOFF_DEBUG
2101 if (ECOFF_DEBUGGING
)
2102 ecoff_symbol_new_hook (symbolP
);
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. */
2111 elf_obj_symbol_clone_hook (symbolS
*newsym
, symbolS
*orgsym ATTRIBUTE_UNUSED
)
2113 struct elf_obj_sy
*newelf
= symbol_get_obj (newsym
);
2116 expressionS
*exp
= XNEW (expressionS
);
2117 *exp
= *newelf
->size
;
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
2127 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2129 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2130 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2133 if (destelf
->size
== NULL
)
2134 destelf
->size
= XNEW (expressionS
);
2135 *destelf
->size
= *srcelf
->size
;
2139 free (destelf
->size
);
2140 destelf
->size
= NULL
;
2142 S_SET_SIZE (dest
, S_GET_SIZE (src
));
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))));
2149 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2154 asection
*seg
= now_seg
;
2155 subsegT subseg
= now_subseg
;
2156 Elf_Internal_Note i_note
;
2157 Elf_External_Note e_note
;
2158 asection
*note_secp
= NULL
;
2161 if (*input_line_pointer
== '\"')
2165 ++input_line_pointer
; /* -> 1st char of string. */
2166 name
= input_line_pointer
;
2168 while (is_a_char (c
= next_char_of_string ()))
2170 c
= *input_line_pointer
;
2171 *input_line_pointer
= '\0';
2172 *(input_line_pointer
- 1) = '\0';
2173 *input_line_pointer
= c
;
2175 /* Create the .note section. */
2176 note_secp
= subseg_new (".note", 0);
2177 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2178 record_alignment (note_secp
, 2);
2180 /* Process the version string. */
2181 len
= strlen (name
) + 1;
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. */
2187 i_note
.type
= NT_VERSION
;
2188 p
= frag_more (sizeof (e_note
.namesz
));
2189 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2190 p
= frag_more (sizeof (e_note
.descsz
));
2191 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2192 p
= frag_more (sizeof (e_note
.type
));
2193 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2194 p
= frag_more (len
);
2195 memcpy (p
, name
, len
);
2197 frag_align (2, 0, 0);
2199 subseg_set (seg
, subseg
);
2202 as_bad (_("expected quoted string"));
2204 demand_empty_rest_of_line ();
2208 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2211 char c
= get_symbol_name (&name
);
2216 p
= input_line_pointer
;
2218 SKIP_WHITESPACE_AFTER_NAME ();
2219 if (*input_line_pointer
!= ',')
2222 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2224 ignore_rest_of_line ();
2227 input_line_pointer
++;
2229 if (exp
.X_op
== O_absent
)
2231 as_bad (_("missing expression in .size directive"));
2232 exp
.X_op
= O_constant
;
2233 exp
.X_add_number
= 0;
2236 sym
= symbol_find_or_make (name
);
2238 if (exp
.X_op
== O_constant
)
2240 S_SET_SIZE (sym
, exp
.X_add_number
);
2241 xfree (symbol_get_obj (sym
)->size
);
2242 symbol_get_obj (sym
)->size
= NULL
;
2246 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2247 *symbol_get_obj (sym
)->size
= exp
;
2249 demand_empty_rest_of_line ();
2252 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2253 There are six syntaxes:
2255 The first (used on Solaris) is
2257 The second (used on UnixWare) is
2259 The third (reportedly to be used on Irix 6.0) is
2261 The fourth (used on NetBSD/Arm and Linux/ARM) is
2263 The fifth (used on SVR4/860) is
2264 .type SYM,"function"
2265 The sixth (emitted by recent SunPRO under Solaris) is
2267 where the integer is the STT_* value.
2271 obj_elf_type_name (char *cp
)
2275 p
= input_line_pointer
;
2276 if (*input_line_pointer
>= '0'
2277 && *input_line_pointer
<= '9')
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';
2286 *cp
= get_symbol_name (&p
);
2292 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2296 const char *type_name
;
2298 elf_symbol_type
*elfsym
;
2300 sym
= get_sym_from_input_line_and_check ();
2301 c
= *input_line_pointer
;
2302 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2304 if (*input_line_pointer
== ',')
2305 ++input_line_pointer
;
2308 if ( *input_line_pointer
== '#'
2309 || *input_line_pointer
== '@'
2310 || *input_line_pointer
== '"'
2311 || *input_line_pointer
== '%')
2312 ++input_line_pointer
;
2314 type_name
= obj_elf_type_name (& c
);
2317 if (strcmp (type_name
, "function") == 0
2318 || strcmp (type_name
, "2") == 0
2319 || strcmp (type_name
, "STT_FUNC") == 0)
2320 type
= BSF_FUNCTION
;
2321 else if (strcmp (type_name
, "object") == 0
2322 || strcmp (type_name
, "1") == 0
2323 || strcmp (type_name
, "STT_OBJECT") == 0)
2325 else if (strcmp (type_name
, "tls_object") == 0
2326 || strcmp (type_name
, "6") == 0
2327 || strcmp (type_name
, "STT_TLS") == 0)
2328 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2329 else if (strcmp (type_name
, "notype") == 0
2330 || strcmp (type_name
, "0") == 0
2331 || strcmp (type_name
, "STT_NOTYPE") == 0)
2333 else if (strcmp (type_name
, "common") == 0
2334 || strcmp (type_name
, "5") == 0
2335 || strcmp (type_name
, "STT_COMMON") == 0)
2339 if (! S_IS_COMMON (sym
))
2341 if (S_IS_VOLATILE (sym
))
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
);
2350 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2351 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
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
);
2361 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2362 || strcmp (type_name
, "10") == 0
2363 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2365 const struct elf_backend_data
*bed
;
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
)
2371 as_bad (_("symbol type \"%s\" is supported only by GNU "
2372 "and FreeBSD targets"), type_name
);
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
);
2377 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2378 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2380 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2382 const struct elf_backend_data
*bed
;
2384 bed
= get_elf_backend_data (stdoutput
);
2385 if (bed
->elf_osabi
!= ELFOSABI_NONE
2386 && bed
->elf_osabi
!= ELFOSABI_GNU
)
2387 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2389 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2390 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2392 #ifdef md_elf_symbol_type
2393 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2397 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2399 *input_line_pointer
= c
;
2401 if (*input_line_pointer
== '"')
2402 ++input_line_pointer
;
2404 #ifdef md_elf_symbol_type_change
2405 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2408 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2410 if (type
!= BSF_FUNCTION
)
2411 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2412 if (type
!= BSF_OBJECT
)
2414 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2416 if (S_IS_COMMON (sym
))
2418 as_bad (_("cannot change type of common symbol '%s'"),
2424 /* Don't warn when changing to STT_NOTYPE. */
2427 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
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;
2434 elfsym
->symbol
.flags
&= ~mask
;
2437 demand_empty_rest_of_line ();
2441 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2443 static segT comment_section
;
2444 segT old_section
= now_seg
;
2445 int old_subsection
= now_subseg
;
2447 #ifdef md_flush_pending_output
2448 md_flush_pending_output ();
2451 if (!comment_section
)
2454 comment_section
= subseg_new (".comment", 0);
2455 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2456 | SEC_MERGE
| SEC_STRINGS
));
2457 comment_section
->entsize
= 1;
2458 #ifdef md_elf_section_change_hook
2459 md_elf_section_change_hook ();
2465 subseg_set (comment_section
, 0);
2467 subseg_set (old_section
, old_subsection
);
2470 #ifdef INIT_STAB_SECTION
2472 /* The first entry in a .stabs section is special. */
2475 obj_elf_init_stab_section (segT seg
)
2480 unsigned int stroff
;
2482 /* Force the section to align to a longword boundary. Without this,
2483 UnixWare ar crashes. */
2484 bfd_set_section_alignment (seg
, 2);
2486 /* Make space for this first symbol. */
2490 file
= remap_debug_filename (as_where (NULL
));
2491 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2492 stroff
= get_stab_string_offset (file
, stabstr_name
, true);
2493 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2494 md_number_to_chars (p
, stroff
, 4);
2495 seg_info (seg
)->stabu
.p
= p
;
2496 xfree ((char *) file
);
2501 /* Fill in the counts in the first entry in a .stabs section. */
2504 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2511 if (!startswith (sec
->name
, ".stab"))
2513 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2516 name
= concat (sec
->name
, "str", NULL
);
2517 strsec
= bfd_get_section_by_name (abfd
, name
);
2519 strsz
= bfd_section_size (strsec
);
2522 nsyms
= bfd_section_size (sec
) / 12 - 1;
2524 p
= seg_info (sec
)->stabu
.p
;
2525 gas_assert (p
!= 0);
2527 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2528 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2532 #ifdef NEED_ECOFF_DEBUG
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
2540 #ifdef OBJ_MAYBE_ELF
2544 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2546 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
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. */
2554 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2556 if (sym
->udata
.p
== NULL
)
2558 *ext
= *(EXTR
*) sym
->udata
.p
;
2562 /* This function is called by bfd_ecoff_debug_externals. It has
2563 nothing to do for ELF. */
2566 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2567 bfd_size_type indx ATTRIBUTE_UNUSED
)
2571 #endif /* NEED_ECOFF_DEBUG */
2574 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2576 struct elf_obj_sy
*sy_obj
;
2578 struct elf_versioned_name_list
*versioned_name
;
2580 #ifdef NEED_ECOFF_DEBUG
2581 if (ECOFF_DEBUGGING
)
2582 ecoff_frob_symbol (symp
);
2585 sy_obj
= symbol_get_obj (symp
);
2587 size
= sy_obj
->size
;
2590 if (resolve_expression (size
)
2591 && size
->X_op
== O_constant
)
2592 S_SET_SIZE (symp
, size
->X_add_number
);
2595 if (!flag_allow_nonconst_size
)
2596 as_bad (_(".size expression for %s "
2597 "does not evaluate to a constant"), S_GET_NAME (symp
));
2599 as_warn (_(".size expression for %s "
2600 "does not evaluate to a constant"), S_GET_NAME (symp
));
2602 free (sy_obj
->size
);
2603 sy_obj
->size
= NULL
;
2606 versioned_name
= sy_obj
->versioned_name
;
2609 /* This symbol was given a new name with the .symver directive.
2610 If this is an external reference, just rename the symbol to
2611 include the version string. This will make the relocs be
2612 against the correct versioned symbol. */
2614 /* We will have already reported an version error. */
2615 if (sy_obj
->bad_version
)
2617 /* elf_frob_file_before_adjust only allows one version symbol for
2619 else if (sy_obj
->rename
)
2620 S_SET_NAME (symp
, versioned_name
->name
);
2621 else if (S_IS_COMMON (symp
))
2623 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2624 versioned_name
->name
, S_GET_NAME (symp
));
2630 elf_symbol_type
*elfsym
;
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. */
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
)
2646 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2648 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2650 /* Subtracting out the frag address here is a hack
2651 because we are in the middle of the final loop. */
2654 - (symbol_get_frag (symp
)->fr_address
2655 / OCTETS_PER_BYTE
)));
2657 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2659 /* This will copy over the size information. */
2660 copy_symbol_attributes (symp2
, symp
);
2662 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2664 if (S_IS_WEAK (symp
))
2667 if (S_IS_EXTERNAL (symp
))
2668 S_SET_EXTERNAL (symp2
);
2671 switch (symbol_get_obj (symp
)->visibility
)
2673 case visibility_unchanged
:
2675 case visibility_hidden
:
2676 bfdsym
= symbol_get_bfdsym (symp
);
2677 elfsym
= elf_symbol_from (bfdsym
);
2678 elfsym
->internal_elf_sym
.st_other
&= ~3;
2679 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2681 case visibility_remove
:
2682 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2684 case visibility_local
:
2685 S_CLEAR_EXTERNAL (symp
);
2691 /* Double check weak symbols. */
2692 if (S_IS_WEAK (symp
))
2694 if (S_IS_COMMON (symp
))
2695 as_bad (_("symbol `%s' can not be both weak and common"),
2702 asection
**head
; /* Section lists. */
2703 unsigned int num_group
; /* Number of lists. */
2704 htab_t indexes
; /* Maps group name to index in head array. */
2707 static struct group_list groups
;
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
2712 each list. If its link_to_symbol_name isn't NULL, set up its
2713 linked-to section. */
2716 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2717 asection
*sec
, void *inf
)
2719 struct group_list
*list
= (struct group_list
*) inf
;
2720 const char *group_name
= elf_group_name (sec
);
2722 unsigned int *elem_idx
;
2723 unsigned int *idx_ptr
;
2725 if (sec
->map_head
.linked_to_symbol_name
)
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
));
2734 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2737 if (group_name
== NULL
)
2740 /* If this group already has a list, add the section to the head of
2742 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2743 if (elem_idx
!= NULL
)
2745 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2746 list
->head
[*elem_idx
] = sec
;
2750 /* New group. Make the arrays bigger in chunks to minimize calls to
2752 i
= list
->num_group
;
2755 unsigned int newsize
= i
+ 128;
2756 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2758 list
->head
[i
] = sec
;
2759 list
->num_group
+= 1;
2761 /* Add index to hash. */
2762 idx_ptr
= XNEW (unsigned int);
2764 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2768 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2770 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2771 free ((char *)tuple
->value
);
2775 /* Create symbols for group signature. */
2778 elf_adjust_symtab (void)
2782 /* Go find section groups. */
2783 groups
.num_group
= 0;
2785 groups
.indexes
= str_htab_create ();
2786 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
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. */
2793 for (i
= 0; i
< groups
.num_group
; i
++)
2795 const char *group_name
= elf_group_name (groups
.head
[i
]);
2796 const char *sec_name
;
2801 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2802 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2803 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2805 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2806 if (s
!= groups
.head
[i
])
2808 as_warn (_("assuming all members of group `%s' are COMDAT"),
2814 sec_name
= ".group";
2815 s
= subseg_force_new (sec_name
, 0);
2817 || !bfd_set_section_flags (s
, flags
)
2818 || !bfd_set_section_alignment (s
, 2))
2820 as_fatal (_("can't create group: %s"),
2821 bfd_errmsg (bfd_get_error ()));
2823 elf_section_type (s
) = SHT_GROUP
;
2825 /* Pass a pointer to the first section in this group. */
2826 elf_next_in_group (s
) = groups
.head
[i
];
2827 elf_sec_group (groups
.head
[i
]) = s
;
2828 /* Make sure that the signature symbol for the group has the
2829 name of the group. */
2830 sy
= symbol_find_exact (group_name
);
2831 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2833 /* Create the symbol now. */
2834 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
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
);
2841 symbol_get_obj (sy
)->local
= 1;
2843 symbol_table_insert (sy
);
2845 elf_group_id (s
) = symbol_get_bfdsym (sy
);
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
);
2853 elf_frob_file (void)
2855 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2857 #ifdef elf_tc_final_processing
2858 elf_tc_final_processing ();
2862 /* It removes any unneeded versioned symbols from the symbol table. */
2865 elf_frob_file_before_adjust (void)
2871 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2873 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2874 int is_defined
= !!S_IS_DEFINED (symp
);
2876 if (sy_obj
->versioned_name
)
2878 char *p
= strchr (sy_obj
->versioned_name
->name
,
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
);
2892 /* Verify that the name isn't using the @@ syntax--this
2893 is reserved for definitions of the default version
2895 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2897 as_bad (_("invalid attempt to declare external "
2898 "version name as default in symbol `%s'"),
2899 sy_obj
->versioned_name
->name
);
2903 /* Only one version symbol is allowed for undefined
2905 if (sy_obj
->versioned_name
->next
)
2907 as_bad (_("multiple versions [`%s'|`%s'] for "
2909 sy_obj
->versioned_name
->name
,
2910 sy_obj
->versioned_name
->next
->name
,
2915 sy_obj
->rename
= true;
2919 /* If there was .symver or .weak, but symbol was neither
2920 defined nor used anywhere, remove it. */
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
);
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. */
2936 elf_frob_file_after_relocs (void)
2940 /* Set SHT_GROUP section size. */
2941 for (i
= 0; i
< groups
.num_group
; i
++)
2943 asection
*s
, *head
, *group
;
2946 head
= groups
.head
[i
];
2948 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2949 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2951 group
= elf_sec_group (head
);
2952 subseg_set (group
, 0);
2953 bfd_set_section_size (group
, size
);
2954 group
->contents
= (unsigned char *) frag_more (size
);
2955 frag_now
->fr_fix
= frag_now_fix_octets ();
2956 frag_wane (frag_now
);
2960 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2961 htab_delete (groups
.indexes
);
2963 #ifdef NEED_ECOFF_DEBUG
2964 if (ECOFF_DEBUGGING
)
2965 /* Generate the ECOFF debugging information. */
2967 const struct ecoff_debug_swap
*debug_swap
;
2968 struct ecoff_debug_info debug
;
2973 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2974 know (debug_swap
!= NULL
);
2975 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2977 /* Set up the pointers in debug. */
2978 #define SET(ptr, offset, type) \
2979 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2981 SET (line
, cbLineOffset
, unsigned char *);
2982 SET (external_dnr
, cbDnOffset
, void *);
2983 SET (external_pdr
, cbPdOffset
, void *);
2984 SET (external_sym
, cbSymOffset
, void *);
2985 SET (external_opt
, cbOptOffset
, void *);
2986 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2987 SET (ss
, cbSsOffset
, char *);
2988 SET (external_fdr
, cbFdOffset
, void *);
2989 SET (external_rfd
, cbRfdOffset
, void *);
2990 /* ssext and external_ext are set up just below. */
2994 /* Set up the external symbols. */
2995 debug
.ssext
= debug
.ssext_end
= NULL
;
2996 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2997 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
2998 elf_get_extr
, elf_set_index
))
2999 as_fatal (_("failed to set up debugging information: %s"),
3000 bfd_errmsg (bfd_get_error ()));
3002 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
3003 gas_assert (sec
!= NULL
);
3005 know (!stdoutput
->output_has_begun
);
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
3011 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
3014 /* Pass BUF to bfd_set_section_contents because this will
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. */
3018 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3019 as_fatal (_("can't start writing .mdebug section: %s"),
3020 bfd_errmsg (bfd_get_error ()));
3022 know (stdoutput
->output_has_begun
);
3023 know (sec
->filepos
!= 0);
3025 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3027 as_fatal (_("could not write .mdebug section: %s"),
3028 bfd_errmsg (bfd_get_error ()));
3030 #endif /* NEED_ECOFF_DEBUG */
3034 elf_generate_asm_lineno (void)
3036 #ifdef NEED_ECOFF_DEBUG
3037 if (ECOFF_DEBUGGING
)
3038 ecoff_generate_asm_lineno ();
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
)
3050 #ifdef NEED_ECOFF_DEBUG
3051 if (ECOFF_DEBUGGING
)
3052 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3057 elf_separate_stab_sections (void)
3059 #ifdef NEED_ECOFF_DEBUG
3060 return (!ECOFF_DEBUGGING
);
3067 elf_init_stab_section (segT seg
)
3069 #ifdef NEED_ECOFF_DEBUG
3070 if (!ECOFF_DEBUGGING
)
3072 obj_elf_init_stab_section (seg
);
3075 const struct format_ops elf_format_ops
=
3077 bfd_target_elf_flavour
,
3078 0, /* dfl_leading_underscore */
3079 1, /* emit_section_symbols */
3084 elf_frob_file_before_adjust
,
3085 0, /* obj_frob_file_before_fix */
3086 elf_frob_file_after_relocs
,
3087 elf_s_get_size
, elf_s_set_size
,
3088 elf_s_get_align
, elf_s_set_align
,
3095 elf_copy_symbol_attributes
,
3096 elf_generate_asm_lineno
,
3098 elf_separate_stab_sections
,
3099 elf_init_stab_section
,
3100 elf_sec_sym_ok_for_reloc
,
3102 #ifdef NEED_ECOFF_DEBUG
3105 0, /* ecoff_set_ext */
3107 elf_obj_read_begin_hook
,
3108 elf_obj_symbol_new_hook
,
3109 elf_obj_symbol_clone_hook
,