1 /* ELF object file format
2 Copyright (C) 1992-2023 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},
134 {"bss", obj_elf_bss
, 0},
136 {"tls_common", obj_elf_tls_common
, 0},
142 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
144 #ifdef NEED_ECOFF_DEBUG
145 /* COFF style debugging information for ECOFF. .ln is not used; .loc
147 { "def", ecoff_directive_def
, 0 },
148 { "dim", ecoff_directive_dim
, 0 },
149 { "endef", ecoff_directive_endef
, 0 },
150 { "file", ecoff_directive_file
, 0 },
151 { "scl", ecoff_directive_scl
, 0 },
152 { "tag", ecoff_directive_tag
, 0 },
153 { "val", ecoff_directive_val
, 0 },
155 /* COFF debugging requires pseudo-ops .size and .type, but ELF
156 already has meanings for those. We use .esize and .etype
157 instead. These are only generated by gcc anyhow. */
158 { "esize", ecoff_directive_size
, 0 },
159 { "etype", ecoff_directive_type
, 0 },
161 /* ECOFF specific debugging information. */
162 { "aent", ecoff_directive_ent
, 1 },
163 { "begin", ecoff_directive_begin
, 0 },
164 { "bend", ecoff_directive_bend
, 0 },
165 { "end", ecoff_directive_end
, 0 },
166 { "ent", ecoff_directive_ent
, 0 },
167 { "fmask", ecoff_directive_fmask
, 0 },
168 { "frame", ecoff_directive_frame
, 0 },
169 { "loc", ecoff_directive_loc
, 0 },
170 { "mask", ecoff_directive_mask
, 0 },
172 /* Other ECOFF directives. */
173 { "extern", ecoff_directive_extern
, 0 },
175 /* These are used on Irix. I don't know how to implement them. */
176 { "alias", s_ignore
, 0 },
177 { "bgnb", s_ignore
, 0 },
178 { "endb", s_ignore
, 0 },
179 { "lab", s_ignore
, 0 },
180 { "noalias", s_ignore
, 0 },
181 { "verstamp", s_ignore
, 0 },
182 { "vreg", s_ignore
, 0 },
185 {NULL
, NULL
, 0} /* end sentinel */
189 #include "aout/aout64.h"
191 asection
*elf_com_section_ptr
;
194 elf_pop_insert (void)
196 pop_insert (elf_pseudo_table
);
198 pop_insert (ecoff_debug_pseudo_table
);
202 elf_s_get_size (symbolS
*sym
)
204 return S_GET_SIZE (sym
);
208 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
210 S_SET_SIZE (sym
, sz
);
214 elf_s_get_align (symbolS
*sym
)
216 return S_GET_ALIGN (sym
);
220 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
222 S_SET_ALIGN (sym
, align
);
226 elf_s_get_other (symbolS
*sym
)
228 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
232 elf_s_set_other (symbolS
*sym
, int other
)
234 S_SET_OTHER (sym
, other
);
238 elf_sec_sym_ok_for_reloc (asection
*sec
)
240 return obj_sec_sym_ok_for_reloc (sec
);
244 elf_file_symbol (const char *s
)
247 symbolS
*sym
= symbol_new (s
, absolute_section
, &zero_address_frag
, 0);
248 size_t name_length
= strlen (s
);
250 if (name_length
> strlen (S_GET_NAME (sym
)))
252 obstack_grow (¬es
, s
, name_length
+ 1);
253 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
256 strcpy ((char *) S_GET_NAME (sym
), s
);
258 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
260 if (symbol_rootP
!= sym
261 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
262 || (bsym
->flags
& BSF_FILE
) == 0))
264 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
265 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
269 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
272 #ifdef NEED_ECOFF_DEBUG
277 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
278 Parse a possible alignment value. */
281 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
284 int is_local
= symbol_get_obj (symbolP
)->local
;
286 if (*input_line_pointer
== ',')
288 char *save
= input_line_pointer
;
290 input_line_pointer
++;
293 if (*input_line_pointer
== '"')
295 /* For sparc. Accept .common symbol, length, "bss" */
296 input_line_pointer
++;
297 /* Some use the dot, some don't. */
298 if (*input_line_pointer
== '.')
299 input_line_pointer
++;
300 /* Some say data, some say bss. */
301 if (startswith (input_line_pointer
, "bss\""))
302 input_line_pointer
+= 4;
303 else if (startswith (input_line_pointer
, "data\""))
304 input_line_pointer
+= 5;
307 char *p
= input_line_pointer
;
312 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
313 if (*input_line_pointer
++ == '"')
315 c
= *input_line_pointer
;
316 *input_line_pointer
= '\0';
317 as_bad (_("bad .common segment %s"), p
);
318 *input_line_pointer
= c
;
319 ignore_rest_of_line ();
322 /* ??? Don't ask me why these are always global. */
327 input_line_pointer
= save
;
328 align
= parse_align (is_local
);
329 if (align
== (addressT
) -1)
336 bss_alloc (symbolP
, size
, align
);
337 S_CLEAR_EXTERNAL (symbolP
);
341 S_SET_VALUE (symbolP
, size
);
342 S_SET_ALIGN (symbolP
, align
);
343 S_SET_EXTERNAL (symbolP
);
344 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
347 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
353 obj_elf_common (int is_common
)
355 if (flag_mri
&& is_common
)
358 s_comm_internal (0, elf_common_parse
);
362 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
364 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
367 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
371 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
373 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
376 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
380 get_sym_from_input_line_and_check (void)
386 c
= get_symbol_name (& name
);
387 sym
= symbol_find_or_make (name
);
388 *input_line_pointer
= c
;
389 SKIP_WHITESPACE_AFTER_NAME ();
391 /* There is no symbol name if input_line_pointer has not moved. */
392 if (name
== input_line_pointer
)
393 as_bad (_("Missing symbol name in directive"));
398 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
405 symbolP
= get_sym_from_input_line_and_check ();
406 c
= *input_line_pointer
;
407 S_CLEAR_EXTERNAL (symbolP
);
408 symbol_get_obj (symbolP
)->local
= 1;
411 input_line_pointer
++;
413 if (*input_line_pointer
== '\n')
418 demand_empty_rest_of_line ();
422 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
429 symbolP
= get_sym_from_input_line_and_check ();
430 c
= *input_line_pointer
;
431 S_SET_WEAK (symbolP
);
434 input_line_pointer
++;
436 if (*input_line_pointer
== '\n')
441 demand_empty_rest_of_line ();
445 obj_elf_visibility (int visibility
)
450 elf_symbol_type
*elfsym
;
454 symbolP
= get_sym_from_input_line_and_check ();
456 bfdsym
= symbol_get_bfdsym (symbolP
);
457 elfsym
= elf_symbol_from (bfdsym
);
461 elfsym
->internal_elf_sym
.st_other
&= ~3;
462 elfsym
->internal_elf_sym
.st_other
|= visibility
;
464 c
= *input_line_pointer
;
467 input_line_pointer
++;
471 if (*input_line_pointer
== '\n')
477 demand_empty_rest_of_line ();
480 static segT previous_section
;
481 static int previous_subsection
;
485 struct section_stack
*next
;
487 int subseg
, prev_subseg
;
490 static struct section_stack
*section_stack
;
492 /* ELF section flags for unique sections. */
493 #define SEC_ASSEMBLER_SHF_MASK SHF_GNU_RETAIN
495 /* Return TRUE iff SEC matches the section info INF. */
498 get_section_by_match (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
500 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
501 const char *gname
= match
->group_name
;
502 const char *group_name
= elf_group_name (sec
);
503 const char *linked_to_symbol_name
504 = sec
->map_head
.linked_to_symbol_name
;
505 unsigned int sh_info
= elf_section_data (sec
)->this_hdr
.sh_info
;
506 bfd_vma sh_flags
= (elf_section_data (sec
)->this_hdr
.sh_flags
507 & SEC_ASSEMBLER_SHF_MASK
);
509 return (sh_info
== match
->sh_info
510 && sh_flags
== match
->sh_flags
511 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
512 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
513 && sec
->section_id
== match
->section_id
514 && (group_name
== gname
515 || (group_name
!= NULL
517 && strcmp (group_name
, gname
) == 0))
518 && (linked_to_symbol_name
== match
->linked_to_symbol_name
519 || (linked_to_symbol_name
!= NULL
520 && match
->linked_to_symbol_name
!= NULL
521 && strcmp (linked_to_symbol_name
,
522 match
->linked_to_symbol_name
) == 0)));
525 /* Handle the .section pseudo-op. This code supports two different
528 The first is found on Solaris, and looks like
529 .section ".sec1",#alloc,#execinstr,#write
530 Here the names after '#' are the SHF_* flags to turn on for the
531 section. I'm not sure how it determines the SHT_* type (BFD
532 doesn't really give us control over the type, anyhow).
534 The second format is found on UnixWare, and probably most SVR4
535 machines, and looks like
536 .section .sec1,"a",@progbits
537 The quoted string may contain any combination of a, w, x, and
538 represents the SHF_* flags to turn on for the section. The string
539 beginning with '@' can be progbits or nobits. There should be
540 other possibilities, but I don't know what they are. In any case,
541 BFD doesn't really let us set the section type. */
544 obj_elf_change_section (const char *name
,
548 struct elf_section_match
*match_p
,
555 const struct elf_backend_data
*bed
;
556 const struct bfd_elf_special_section
*ssect
;
560 static struct elf_section_match unused_match
;
561 match_p
= &unused_match
;
564 #ifdef md_flush_pending_output
565 md_flush_pending_output ();
568 /* Switch to the section, creating it if necessary. */
571 struct section_stack
*elt
;
572 elt
= XNEW (struct section_stack
);
573 elt
->next
= section_stack
;
575 elt
->prev_seg
= previous_section
;
576 elt
->subseg
= now_subseg
;
577 elt
->prev_subseg
= previous_subsection
;
581 obj_elf_section_change_hook ();
583 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section_by_match
,
591 sec
= subseg_force_new (name
, 0);
593 bed
= get_elf_backend_data (stdoutput
);
594 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
598 bool override
= false;
600 if (type
== SHT_NULL
)
602 else if (type
!= ssect
->type
)
605 /* Some older versions of gcc will emit
607 .section .init_array,"aw",@progbits
609 for __attribute__ ((section (".init_array"))).
610 "@progbits" is incorrect. Also for x86-64 large bss
611 sections, some older versions of gcc will emit
613 .section .lbss,"aw",@progbits
615 "@progbits" is incorrect. */
617 && (bed
->s
->arch_size
!= 64
618 || !(ssect
->attr
& SHF_X86_64_LARGE
))
620 && ssect
->type
!= SHT_INIT_ARRAY
621 && ssect
->type
!= SHT_FINI_ARRAY
622 && ssect
->type
!= SHT_PREINIT_ARRAY
)
624 /* We allow to specify any type for a .note section. */
625 if (ssect
->type
!= SHT_NOTE
626 /* Processor and application defined types are allowed too. */
627 && type
< SHT_LOPROC
)
628 as_warn (_("setting incorrect section type for %s"),
633 as_warn (_("ignoring incorrect section type for %s"),
639 if (old_sec
== NULL
&& ((attr
& ~(SHF_LINK_ORDER
642 & ~ssect
->attr
) != 0)
644 /* Strip SHF_GNU_RETAIN. */
645 bfd_vma generic_attr
= attr
;
646 if (elf_tdata (stdoutput
)->has_gnu_osabi
)
647 generic_attr
&= ~SHF_GNU_RETAIN
;
649 /* As a GNU extension, we permit a .note section to be
650 allocatable. If the linker sees an allocatable .note
651 section, it will create a PT_NOTE segment in the output
652 file. We also allow "x" for .note.GNU-stack. */
653 if (ssect
->type
== SHT_NOTE
654 && (generic_attr
== SHF_ALLOC
655 || generic_attr
== SHF_EXECINSTR
))
657 /* Allow different SHF_MERGE and SHF_STRINGS if we have
658 something like .rodata.str. */
659 else if (ssect
->suffix_length
== -2
660 && name
[ssect
->prefix_length
] == '.'
664 & ~SHF_STRINGS
) == 0)
666 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
667 else if (generic_attr
== SHF_ALLOC
668 && (strcmp (name
, ".interp") == 0
669 || strcmp (name
, ".strtab") == 0
670 || strcmp (name
, ".symtab") == 0))
672 /* .note.GNU-stack can have SHF_EXECINSTR. */
673 else if (generic_attr
== SHF_EXECINSTR
674 && strcmp (name
, ".note.GNU-stack") == 0)
677 /* A section on Alpha may have SHF_ALPHA_GPREL. */
678 else if ((generic_attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
682 else if (generic_attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
683 && (ssect
->type
== SHT_INIT_ARRAY
684 || ssect
->type
== SHT_FINI_ARRAY
685 || ssect
->type
== SHT_PREINIT_ARRAY
))
686 /* RX init/fini arrays can and should have the "awx" attributes set. */
691 if (match_p
->group_name
== NULL
)
692 as_warn (_("setting incorrect section attributes for %s"),
698 if (!override
&& old_sec
== NULL
)
702 /* Convert ELF type and flags to BFD flags. */
704 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
705 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
706 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
707 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
708 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
709 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
710 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
711 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
712 #ifdef md_elf_section_flags
713 flags
= md_elf_section_flags (flags
, attr
, type
);
717 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
719 /* PR 28054: Set the SEC_ELF_OCTETS flag for debugging sections.
720 Based on the code in bfd/elf.c:_bfd_elf_make_section_from_shdr().
722 FIXME: We do not set the SEC_DEBUGGING flag because that causes
723 problems for the FT32 and MSP430 targets. Investigate and fix. */
724 if ((flags
& SEC_ALLOC
) == 0 && name
[0] == '.')
726 if ( startswith (name
, ".debug")
727 || startswith (name
, ".zdebug")
728 || startswith (name
, ".gnu.debuglto_.debug_")
729 || startswith (name
, ".gnu.linkonce.wi.")
730 || startswith (name
, GNU_BUILD_ATTRS_SECTION_NAME
)
731 || startswith (name
, ".note.gnu"))
732 flags
|= SEC_ELF_OCTETS
;
739 if (type
== SHT_NULL
)
740 type
= bfd_elf_get_default_section_type (flags
);
741 elf_section_type (sec
) = type
;
742 elf_section_flags (sec
) = attr
;
743 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->sh_info
;
745 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
746 if (type
== SHT_NOBITS
)
747 seg_info (sec
)->bss
= 1;
749 /* Set the section ID and flags. */
750 sec
->section_id
= match_p
->section_id
;
751 flags
|= match_p
->flags
;
753 /* Set the linked-to symbol name. */
754 sec
->map_head
.linked_to_symbol_name
755 = match_p
->linked_to_symbol_name
;
757 bfd_set_section_flags (sec
, flags
);
758 if (flags
& SEC_MERGE
)
759 sec
->entsize
= entsize
;
760 elf_group_name (sec
) = match_p
->group_name
;
762 /* Add a symbol for this section to the symbol table. */
763 secsym
= symbol_find (name
);
766 /* We could be repurposing an undefined symbol here: make sure we
767 reset sy_value to look like other section symbols in order to avoid
768 trying to incorrectly resolve this section symbol later on. */
769 static const expressionS exp
= { .X_op
= O_constant
};
770 symbol_set_value_expression (secsym
, &exp
);
771 symbol_set_bfdsym (secsym
, sec
->symbol
);
774 symbol_table_insert (section_symbol (sec
));
779 && (unsigned) type
!= elf_section_type (old_sec
))
782 /* This is a special section with known type. User
783 assembly might get the section type wrong; Even high
784 profile projects like glibc have done so in the past.
785 So don't error in this case. */
786 as_warn (_("ignoring changed section type for %s"), name
);
788 /* Do error when assembly isn't self-consistent. */
789 as_bad (_("changed section type for %s"), name
);
794 /* If section attributes are specified the second time we see a
795 particular section, then check that they are the same as we
796 saw the first time. */
797 if (((old_sec
->flags
^ flags
)
798 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
799 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
800 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
801 | SEC_THREAD_LOCAL
)))
804 as_warn (_("ignoring changed section attributes for %s"), name
);
806 as_bad (_("changed section attributes for %s"), name
);
809 /* FIXME: Maybe we should consider removing a previously set
810 processor or application specific attribute as suspicious? */
811 elf_section_flags (sec
) = attr
;
813 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
814 as_bad (_("changed section entity size for %s"), name
);
818 #ifdef md_elf_section_change_hook
819 md_elf_section_change_hook ();
824 obj_elf_parse_section_letters (char *str
, size_t len
,
825 bool *is_clone
, bfd_vma
*gnu_attr
)
837 if (len
> 1 && str
[1] == 'm')
841 if (len
> 1 && str
[1] == 's')
852 attr
|= SHF_LINK_ORDER
;
858 attr
|= SHF_EXECINSTR
;
873 *gnu_attr
|= SHF_GNU_MBIND
;
876 *gnu_attr
|= SHF_GNU_RETAIN
;
883 const char *bad_msg
= _("unrecognized .section attribute:"
884 " want a,e,o,w,x,M,S,G,T or number");
885 #ifdef md_elf_section_letter
886 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
887 if (md_attr
!= (bfd_vma
) -1)
894 struct elf_backend_data
*bed
;
895 bfd_vma numeric_flags
= strtoul (str
, &end
, 0);
897 attr
|= numeric_flags
;
899 bed
= (struct elf_backend_data
*)
900 get_elf_backend_data (stdoutput
);
902 if (bed
->elf_osabi
== ELFOSABI_NONE
903 || bed
->elf_osabi
== ELFOSABI_STANDALONE
904 || bed
->elf_osabi
== ELFOSABI_GNU
905 || bed
->elf_osabi
== ELFOSABI_FREEBSD
)
907 /* Add flags in the SHF_MASKOS range to gnu_attr for
908 OSABIs that support those flags.
909 Also adding the flags for ELFOSABI_{NONE,STANDALONE}
910 allows them to be validated later in obj_elf_section.
911 We can't just always set these bits in gnu_attr for
912 all OSABIs, since Binutils does not recognize all
913 SHF_MASKOS bits for non-GNU OSABIs. It's therefore
914 possible that numeric flags are being used to set bits
915 in the SHF_MASKOS range for those targets, and we
916 don't want assembly to fail in those situations. */
917 *gnu_attr
|= (numeric_flags
& SHF_MASKOS
);
920 /* Update str and len, allowing for the fact that
921 we will execute str++ and len-- below. */
927 as_fatal ("%s", bad_msg
);
938 obj_elf_section_type (char *str
, size_t len
, bool warn
)
940 if (len
== 8 && startswith (str
, "progbits"))
942 if (len
== 6 && startswith (str
, "nobits"))
944 if (len
== 4 && startswith (str
, "note"))
946 if (len
== 10 && startswith (str
, "init_array"))
947 return SHT_INIT_ARRAY
;
948 if (len
== 10 && startswith (str
, "fini_array"))
949 return SHT_FINI_ARRAY
;
950 if (len
== 13 && startswith (str
, "preinit_array"))
951 return SHT_PREINIT_ARRAY
;
953 #ifdef md_elf_section_type
955 int md_type
= md_elf_section_type (str
, len
);
964 int type
= strtoul (str
, & end
, 0);
966 if (warn
&& (size_t) (end
- str
) != len
)
967 as_warn (_("extraneous characters at end of numeric section type"));
973 as_warn (_("unrecognized section type"));
979 obj_elf_section_word (char *str
, size_t len
, int *type
)
983 if (len
== 5 && startswith (str
, "write"))
985 if (len
== 5 && startswith (str
, "alloc"))
987 if (len
== 9 && startswith (str
, "execinstr"))
988 return SHF_EXECINSTR
;
989 if (len
== 7 && startswith (str
, "exclude"))
991 if (len
== 3 && startswith (str
, "tls"))
994 #ifdef md_elf_section_word
996 bfd_vma md_attr
= md_elf_section_word (str
, len
);
1002 ret
= obj_elf_section_type (str
, len
, false);
1006 as_warn (_("unrecognized section attribute"));
1012 /* Get name of section. */
1014 obj_elf_section_name (void)
1019 if (*input_line_pointer
== '"')
1023 name
= demand_copy_C_string (&dummy
);
1026 ignore_rest_of_line ();
1032 char *end
= input_line_pointer
;
1034 while (0 == strchr ("\n\t,; ", *end
))
1036 if (end
== input_line_pointer
)
1038 as_bad (_("missing name"));
1039 ignore_rest_of_line ();
1043 obstack_grow0 (¬es
, input_line_pointer
, end
- input_line_pointer
);
1044 name
= obstack_base (¬es
);
1046 while (flag_sectname_subst
)
1048 char *subst
= strchr (name
, '%');
1049 if (subst
&& subst
[1] == 'S')
1051 size_t head
= subst
- name
;
1052 size_t tail
= strlen (subst
+ 2) + 1;
1053 size_t slen
= strlen (now_seg
->name
);
1057 obstack_blank (¬es
, slen
- 2);
1058 name
= obstack_base (¬es
);
1060 memmove (name
+ head
+ slen
, name
+ head
+ 2, tail
);
1061 memcpy (name
+ head
, now_seg
->name
, slen
);
1067 obstack_finish (¬es
);
1069 #ifdef tc_canonicalize_section_name
1070 name
= tc_canonicalize_section_name (name
);
1072 input_line_pointer
= end
;
1079 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1081 const char * gname
= obj_elf_section_name ();
1085 as_warn (_("group name not parseable"));
1089 if (elf_group_name (now_seg
))
1091 as_warn (_("section %s already has a group (%s)"),
1092 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1096 elf_group_name (now_seg
) = gname
;
1097 elf_section_flags (now_seg
) |= SHF_GROUP
;
1101 obj_elf_section (int push
)
1110 subsegT new_subsection
= -1;
1111 struct elf_section_match match
;
1112 unsigned long linked_to_section_index
= -1UL;
1118 #ifdef md_flush_pending_output
1119 md_flush_pending_output ();
1122 obj_elf_section_change_hook ();
1124 s_mri_sect (&mri_type
);
1126 #ifdef md_elf_section_change_hook
1127 md_elf_section_change_hook ();
1133 name
= obj_elf_section_name ();
1137 memset (&match
, 0, sizeof (match
));
1140 if ((sym
= symbol_find (name
)) != NULL
1141 && ! symbol_section_p (sym
)
1142 && S_IS_DEFINED (sym
)
1143 && ! S_IS_VOLATILE (sym
)
1144 && ! S_CAN_BE_REDEFINED (sym
))
1146 as_bad (_("section name '%s' already defined as another symbol"), name
);
1147 ignore_rest_of_line ();
1156 if (*input_line_pointer
== ',')
1158 /* Skip the comma. */
1159 ++input_line_pointer
;
1162 if (push
&& ISDIGIT (*input_line_pointer
))
1164 /* .pushsection has an optional subsection. */
1165 new_subsection
= (subsegT
) get_absolute_expression ();
1169 /* Stop if we don't see a comma. */
1170 if (*input_line_pointer
!= ',')
1173 /* Skip the comma. */
1174 ++input_line_pointer
;
1178 if (*input_line_pointer
== '"')
1182 beg
= demand_copy_C_string (&dummy
);
1185 ignore_rest_of_line ();
1188 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1189 &is_clone
, &gnu_attr
);
1192 if (*input_line_pointer
== ',')
1195 char *save
= input_line_pointer
;
1197 ++input_line_pointer
;
1199 c
= *input_line_pointer
;
1202 beg
= demand_copy_C_string (&dummy
);
1205 ignore_rest_of_line ();
1208 type
= obj_elf_section_type (beg
, strlen (beg
), true);
1210 else if (c
== '@' || c
== '%')
1212 ++input_line_pointer
;
1214 if (ISDIGIT (* input_line_pointer
))
1215 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1218 c
= get_symbol_name (& beg
);
1219 (void) restore_line_pointer (c
);
1220 type
= obj_elf_section_type (beg
,
1221 input_line_pointer
- beg
,
1226 input_line_pointer
= save
;
1230 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1232 ++input_line_pointer
;
1234 entsize
= get_absolute_expression ();
1238 as_warn (_("invalid merge entity size"));
1243 else if ((attr
& SHF_MERGE
) != 0)
1245 as_warn (_("entity size for SHF_MERGE not specified"));
1249 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1251 ++input_line_pointer
;
1253 /* Check for a numeric section index, rather than a symbol name. */
1254 if (ISDIGIT (* input_line_pointer
))
1256 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1261 unsigned int length
;
1263 c
= get_symbol_name (& beg
);
1264 (void) restore_line_pointer (c
);
1265 length
= input_line_pointer
- beg
;
1267 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1271 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1273 as_warn (_("? section flag ignored with G present"));
1277 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1279 ++input_line_pointer
;
1280 match
.group_name
= obj_elf_section_name ();
1281 if (match
.group_name
== NULL
)
1283 else if (*input_line_pointer
== ',')
1285 ++input_line_pointer
;
1287 if (startswith (input_line_pointer
, "comdat"))
1289 input_line_pointer
+= 6;
1293 else if (startswith (name
, ".gnu.linkonce"))
1296 else if ((attr
& SHF_GROUP
) != 0)
1298 as_warn (_("group name for SHF_GROUP not specified"));
1304 const char *now_group
= elf_group_name (now_seg
);
1305 if (now_group
!= NULL
)
1307 match
.group_name
= now_group
;
1308 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1312 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1314 char *save
= input_line_pointer
;
1315 ++input_line_pointer
;
1317 if (ISDIGIT (* input_line_pointer
))
1319 char *t
= input_line_pointer
;
1320 match
.sh_info
= strtoul (input_line_pointer
,
1321 &input_line_pointer
, 0);
1322 if (match
.sh_info
== (unsigned int) -1)
1324 as_warn (_("unsupported mbind section info: %s"), t
);
1329 input_line_pointer
= save
;
1332 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1333 match
.sh_flags
|= SHF_GNU_RETAIN
;
1335 if (*input_line_pointer
== ',')
1337 char *save
= input_line_pointer
;
1339 ++input_line_pointer
;
1341 if (startswith (input_line_pointer
, "unique"))
1343 input_line_pointer
+= 6;
1345 if (*input_line_pointer
== ',')
1347 ++input_line_pointer
;
1349 if (ISDIGIT (* input_line_pointer
))
1353 char *t
= input_line_pointer
;
1354 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1357 id
= strtoul (input_line_pointer
,
1358 &input_line_pointer
, 0);
1359 overflow
= (id
== (unsigned long) -1
1360 && errno
== ERANGE
);
1365 (input_line_pointer
,
1366 (const char **) &input_line_pointer
, 0);
1367 overflow
= id
== ~(bfd_vma
) 0;
1369 if (overflow
|| id
> (unsigned int) -1)
1371 char *linefeed
, saved_char
= 0;
1372 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1374 saved_char
= *linefeed
;
1377 as_bad (_("unsupported section id: %s"), t
);
1379 *linefeed
= saved_char
;
1383 match
.section_id
= id
;
1384 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1390 input_line_pointer
= save
;
1401 if (*input_line_pointer
!= '#')
1403 as_bad (_("character following name is not '#'"));
1404 ignore_rest_of_line ();
1407 ++input_line_pointer
;
1408 c
= get_symbol_name (& beg
);
1409 (void) restore_line_pointer (c
);
1411 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1416 while (*input_line_pointer
++ == ',');
1417 --input_line_pointer
;
1423 demand_empty_rest_of_line ();
1425 if ((gnu_attr
& (SHF_GNU_MBIND
| SHF_GNU_RETAIN
)) != 0)
1427 const struct elf_backend_data
*bed
;
1428 bool mbind_p
= (gnu_attr
& SHF_GNU_MBIND
) != 0;
1430 if (mbind_p
&& (attr
& SHF_ALLOC
) == 0)
1431 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1433 bed
= get_elf_backend_data (stdoutput
);
1435 if (bed
->elf_osabi
!= ELFOSABI_GNU
1436 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
1437 && bed
->elf_osabi
!= ELFOSABI_NONE
)
1438 as_bad (_("%s section is supported only by GNU and FreeBSD targets"),
1439 mbind_p
? "GNU_MBIND" : "GNU_RETAIN");
1443 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1444 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1445 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_retain
;
1451 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1454 if (linked_to_section_index
!= -1UL)
1456 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1457 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1458 /* FIXME: Should we perform some sanity checking on the section index ? */
1461 if (push
&& new_subsection
!= -1)
1462 subseg_set (now_seg
, new_subsection
);
1465 /* Change to the .bss section. */
1468 obj_elf_bss (int i ATTRIBUTE_UNUSED
)
1472 #ifdef md_flush_pending_output
1473 md_flush_pending_output ();
1476 obj_elf_section_change_hook ();
1478 temp
= get_absolute_expression ();
1479 subseg_set (bss_section
, (subsegT
) temp
);
1480 demand_empty_rest_of_line ();
1482 #ifdef md_elf_section_change_hook
1483 md_elf_section_change_hook ();
1487 /* Change to the .data section. */
1490 obj_elf_data (int i
)
1492 #ifdef md_flush_pending_output
1493 md_flush_pending_output ();
1496 obj_elf_section_change_hook ();
1500 #ifdef md_elf_section_change_hook
1501 md_elf_section_change_hook ();
1505 /* Change to the .text section. */
1508 obj_elf_text (int i
)
1510 #ifdef md_flush_pending_output
1511 md_flush_pending_output ();
1514 obj_elf_section_change_hook ();
1518 #ifdef md_elf_section_change_hook
1519 md_elf_section_change_hook ();
1523 /* Change to the *ABS* section. */
1526 obj_elf_struct (int i
)
1528 #ifdef md_flush_pending_output
1529 md_flush_pending_output ();
1532 obj_elf_section_change_hook ();
1536 #ifdef md_elf_section_change_hook
1537 md_elf_section_change_hook ();
1542 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1546 #ifdef md_flush_pending_output
1547 md_flush_pending_output ();
1550 obj_elf_section_change_hook ();
1552 temp
= get_absolute_expression ();
1553 subseg_set (now_seg
, (subsegT
) temp
);
1554 demand_empty_rest_of_line ();
1556 #ifdef md_elf_section_change_hook
1557 md_elf_section_change_hook ();
1561 /* This can be called from the processor backends if they change
1565 obj_elf_section_change_hook (void)
1567 previous_section
= now_seg
;
1568 previous_subsection
= now_subseg
;
1572 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1577 if (previous_section
== 0)
1579 as_warn (_(".previous without corresponding .section; ignored"));
1583 #ifdef md_flush_pending_output
1584 md_flush_pending_output ();
1587 new_section
= previous_section
;
1588 new_subsection
= previous_subsection
;
1589 obj_elf_section_change_hook ();
1591 subseg_set (new_section
, new_subsection
);
1593 #ifdef md_elf_section_change_hook
1594 md_elf_section_change_hook ();
1599 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1601 struct section_stack
*top
= section_stack
;
1605 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1609 #ifdef md_flush_pending_output
1610 md_flush_pending_output ();
1613 section_stack
= top
->next
;
1614 previous_section
= top
->prev_seg
;
1615 previous_subsection
= top
->prev_subseg
;
1616 subseg_set (top
->seg
, top
->subseg
);
1619 #ifdef md_elf_section_change_hook
1620 md_elf_section_change_hook ();
1625 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1627 /* Assume delimiter is part of expression. BSD4.2 as fails with
1628 delightful bug, so we are not being incompatible here. */
1629 new_logical_line (NULL
, get_absolute_expression ());
1630 demand_empty_rest_of_line ();
1633 static struct elf_versioned_name_list
*
1634 obj_elf_find_and_add_versioned_name (const char *version_name
,
1635 const char *sym_name
,
1637 struct elf_obj_sy
*sy_obj
)
1639 struct elf_versioned_name_list
*versioned_name
;
1642 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1645 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1646 names, we have to disable this. */
1647 if (0 && *p
== '\0')
1649 as_bad (_("missing version name in `%s' for symbol `%s'"),
1650 version_name
, sym_name
);
1654 versioned_name
= sy_obj
->versioned_name
;
1664 if (strcmp (versioned_name
->name
, version_name
) == 0)
1665 return versioned_name
;
1668 as_bad (_("only one version name with `@@@' is allowed "
1669 "for symbol `%s'"), sym_name
);
1673 sy_obj
->rename
= true;
1676 as_bad (_("invalid version name '%s' for symbol `%s'"),
1677 version_name
, sym_name
);
1682 versioned_name
!= NULL
;
1683 versioned_name
= versioned_name
->next
)
1684 if (strcmp (versioned_name
->name
, version_name
) == 0)
1685 return versioned_name
;
1687 /* Add this versioned name to the head of the list, */
1688 versioned_name
= (struct elf_versioned_name_list
*)
1689 xmalloc (sizeof (*versioned_name
));
1690 versioned_name
->name
= xstrdup (version_name
);
1691 versioned_name
->next
= sy_obj
->versioned_name
;
1692 sy_obj
->versioned_name
= versioned_name
;
1694 return versioned_name
;
1697 /* This handles the .symver pseudo-op, which is used to specify a
1698 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1699 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1700 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1701 with the same value as the symbol NAME. */
1704 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1707 const char *sym_name
;
1711 struct elf_obj_sy
*sy_obj
;
1714 sym
= get_sym_from_input_line_and_check ();
1716 if (*input_line_pointer
!= ',')
1718 as_bad (_("expected comma after name in .symver"));
1719 ignore_rest_of_line ();
1723 ++input_line_pointer
;
1726 /* Temporarily include '@' in symbol names. */
1727 old_lexat
= lex_type
[(unsigned char) '@'];
1728 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1729 c
= get_symbol_name (& name
);
1730 lex_type
[(unsigned char) '@'] = old_lexat
;
1731 sym_name
= S_GET_NAME (sym
);
1733 if (S_IS_COMMON (sym
))
1735 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1737 ignore_rest_of_line ();
1741 p
= strchr (name
, ELF_VER_CHR
);
1744 as_bad (_("missing version name in `%s' for symbol `%s'"),
1746 ignore_rest_of_line ();
1750 sy_obj
= symbol_get_obj (sym
);
1751 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1754 sy_obj
->bad_version
= true;
1755 ignore_rest_of_line ();
1759 (void) restore_line_pointer (c
);
1761 if (*input_line_pointer
== ',')
1763 char *save
= input_line_pointer
;
1765 ++input_line_pointer
;
1767 if (startswith (input_line_pointer
, "local"))
1769 input_line_pointer
+= 5;
1770 sy_obj
->visibility
= visibility_local
;
1772 else if (startswith (input_line_pointer
, "hidden"))
1774 input_line_pointer
+= 6;
1775 sy_obj
->visibility
= visibility_hidden
;
1777 else if (startswith (input_line_pointer
, "remove"))
1779 input_line_pointer
+= 6;
1780 sy_obj
->visibility
= visibility_remove
;
1783 input_line_pointer
= save
;
1786 demand_empty_rest_of_line ();
1789 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1790 to the linker the hierarchy in which a particular table resides. The
1791 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1794 obj_elf_get_vtable_inherit (void)
1796 char *cname
, *pname
;
1797 symbolS
*csym
, *psym
;
1800 if (*input_line_pointer
== '#')
1801 ++input_line_pointer
;
1803 c
= get_symbol_name (& cname
);
1804 csym
= symbol_find (cname
);
1806 /* GCFIXME: should check that we don't have two .vtable_inherits for
1807 the same child symbol. Also, we can currently only do this if the
1808 child symbol is already exists and is placed in a fragment. */
1810 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1812 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1817 *input_line_pointer
= c
;
1819 SKIP_WHITESPACE_AFTER_NAME ();
1820 if (*input_line_pointer
!= ',')
1822 as_bad (_("expected comma after name in .vtable_inherit"));
1823 ignore_rest_of_line ();
1827 ++input_line_pointer
;
1830 if (*input_line_pointer
== '#')
1831 ++input_line_pointer
;
1833 if (input_line_pointer
[0] == '0'
1834 && (input_line_pointer
[1] == '\0'
1835 || ISSPACE (input_line_pointer
[1])))
1837 psym
= section_symbol (absolute_section
);
1838 ++input_line_pointer
;
1842 c
= get_symbol_name (& pname
);
1843 psym
= symbol_find_or_make (pname
);
1844 restore_line_pointer (c
);
1847 demand_empty_rest_of_line ();
1852 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1853 return fix_new (symbol_get_frag (csym
),
1854 symbol_get_value_expression (csym
)->X_add_number
,
1855 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1858 /* This is a version of obj_elf_get_vtable_inherit() that is
1859 suitable for use in struct _pseudo_type tables. */
1862 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1864 (void) obj_elf_get_vtable_inherit ();
1867 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1868 to the linker that a vtable slot was used. The syntax is
1869 ".vtable_entry tablename, offset". */
1872 obj_elf_get_vtable_entry (void)
1877 if (*input_line_pointer
== '#')
1878 ++input_line_pointer
;
1880 sym
= get_sym_from_input_line_and_check ();
1881 if (*input_line_pointer
!= ',')
1883 as_bad (_("expected comma after name in .vtable_entry"));
1884 ignore_rest_of_line ();
1888 ++input_line_pointer
;
1889 if (*input_line_pointer
== '#')
1890 ++input_line_pointer
;
1892 offset
= get_absolute_expression ();
1894 demand_empty_rest_of_line ();
1896 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1897 BFD_RELOC_VTABLE_ENTRY
);
1900 /* This is a version of obj_elf_get_vtable_entry() that is
1901 suitable for use in struct _pseudo_type tables. */
1904 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1906 (void) obj_elf_get_vtable_entry ();
1909 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1912 skip_past_char (char ** str
, char c
)
1922 #define skip_past_comma(str) skip_past_char (str, ',')
1924 /* A list of attributes that have been explicitly set by the assembly code.
1925 VENDOR is the vendor id, BASE is the tag shifted right by the number
1926 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1927 struct recorded_attribute_info
{
1928 struct recorded_attribute_info
*next
;
1933 static struct recorded_attribute_info
*recorded_attributes
;
1935 /* Record that we have seen an explicit specification of attribute TAG
1936 for vendor VENDOR. */
1939 record_attribute (int vendor
, unsigned int tag
)
1943 struct recorded_attribute_info
*rai
;
1945 base
= tag
/ (8 * sizeof (rai
->mask
));
1946 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1947 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1948 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1954 rai
= XNEW (struct recorded_attribute_info
);
1955 rai
->next
= recorded_attributes
;
1956 rai
->vendor
= vendor
;
1959 recorded_attributes
= rai
;
1962 /* Return true if we have seen an explicit specification of attribute TAG
1963 for vendor VENDOR. */
1966 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1970 struct recorded_attribute_info
*rai
;
1972 base
= tag
/ (8 * sizeof (rai
->mask
));
1973 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1974 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1975 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1976 return (rai
->mask
& mask
) != 0;
1980 /* Parse an attribute directive for VENDOR.
1981 Returns the attribute number read, or zero on error. */
1984 obj_elf_vendor_attribute (int vendor
)
1992 /* Read the first number or name. */
1993 skip_whitespace (input_line_pointer
);
1994 s
= input_line_pointer
;
1995 if (ISDIGIT (*input_line_pointer
))
1998 if (exp
.X_op
!= O_constant
)
2000 tag
= exp
.X_add_number
;
2006 /* A name may contain '_', but no other punctuation. */
2007 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
2008 ++input_line_pointer
)
2013 name
= xmemdup0 (s
, i
);
2015 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2016 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2019 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2022 as_bad (_("Attribute name not recognised: %s"), name
);
2023 ignore_rest_of_line ();
2030 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2032 if (skip_past_comma (&input_line_pointer
) == -1)
2037 if (exp
.X_op
!= O_constant
)
2039 as_bad (_("expected numeric constant"));
2040 ignore_rest_of_line ();
2043 i
= exp
.X_add_number
;
2046 && skip_past_comma (&input_line_pointer
) == -1)
2048 as_bad (_("expected comma"));
2049 ignore_rest_of_line ();
2056 skip_whitespace (input_line_pointer
);
2057 if (*input_line_pointer
!= '"')
2059 s
= demand_copy_C_string (&len
);
2062 record_attribute (vendor
, tag
);
2066 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2069 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2072 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2078 demand_empty_rest_of_line ();
2081 as_bad (_("bad string constant"));
2082 ignore_rest_of_line ();
2085 as_bad (_("expected <tag> , <value>"));
2086 ignore_rest_of_line ();
2090 /* Parse a .gnu_attribute directive. */
2093 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2095 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2099 elf_obj_read_begin_hook (void)
2101 #ifdef NEED_ECOFF_DEBUG
2102 if (ECOFF_DEBUGGING
)
2103 ecoff_read_begin_hook ();
2108 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2110 struct elf_obj_sy
*sy_obj
;
2112 sy_obj
= symbol_get_obj (symbolP
);
2113 sy_obj
->size
= NULL
;
2114 sy_obj
->versioned_name
= NULL
;
2116 #ifdef NEED_ECOFF_DEBUG
2117 if (ECOFF_DEBUGGING
)
2118 ecoff_symbol_new_hook (symbolP
);
2122 /* Deduplicate size expressions. We might get into trouble with
2123 multiple freeing or use after free if we leave them pointing to the
2124 same expressionS. */
2127 elf_obj_symbol_clone_hook (symbolS
*newsym
, symbolS
*orgsym ATTRIBUTE_UNUSED
)
2129 struct elf_obj_sy
*newelf
= symbol_get_obj (newsym
);
2132 expressionS
*exp
= XNEW (expressionS
);
2133 *exp
= *newelf
->size
;
2139 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2141 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2142 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2143 /* If size is unset, copy size from src. Because we don't track whether
2144 .size has been used, we can't differentiate .size dest, 0 from the case
2145 where dest's size is unset. */
2146 if (!destelf
->size
&& S_GET_SIZE (dest
) == 0)
2150 destelf
->size
= XNEW (expressionS
);
2151 *destelf
->size
= *srcelf
->size
;
2153 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2155 /* Don't copy visibility. */
2156 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2157 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2161 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2166 asection
*seg
= now_seg
;
2167 subsegT subseg
= now_subseg
;
2168 Elf_Internal_Note i_note
;
2169 Elf_External_Note e_note
;
2170 asection
*note_secp
= NULL
;
2173 if (*input_line_pointer
== '\"')
2177 ++input_line_pointer
; /* -> 1st char of string. */
2178 name
= input_line_pointer
;
2180 while (is_a_char (c
= next_char_of_string ()))
2182 c
= *input_line_pointer
;
2183 *input_line_pointer
= '\0';
2184 *(input_line_pointer
- 1) = '\0';
2185 *input_line_pointer
= c
;
2187 /* Create the .note section. */
2188 note_secp
= subseg_new (".note", 0);
2189 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2190 record_alignment (note_secp
, 2);
2192 /* Process the version string. */
2193 len
= strlen (name
) + 1;
2195 /* PR 3456: Although the name field is padded out to an 4-byte
2196 boundary, the namesz field should not be adjusted. */
2197 i_note
.namesz
= len
;
2198 i_note
.descsz
= 0; /* No description. */
2199 i_note
.type
= NT_VERSION
;
2200 p
= frag_more (sizeof (e_note
.namesz
));
2201 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2202 p
= frag_more (sizeof (e_note
.descsz
));
2203 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2204 p
= frag_more (sizeof (e_note
.type
));
2205 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2206 p
= frag_more (len
);
2207 memcpy (p
, name
, len
);
2209 frag_align (2, 0, 0);
2211 subseg_set (seg
, subseg
);
2214 as_bad (_("expected quoted string"));
2216 demand_empty_rest_of_line ();
2220 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2223 char c
= get_symbol_name (&name
);
2228 p
= input_line_pointer
;
2230 SKIP_WHITESPACE_AFTER_NAME ();
2231 if (*input_line_pointer
!= ',')
2234 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2236 ignore_rest_of_line ();
2239 input_line_pointer
++;
2241 if (exp
.X_op
== O_absent
)
2243 as_bad (_("missing expression in .size directive"));
2244 exp
.X_op
= O_constant
;
2245 exp
.X_add_number
= 0;
2248 sym
= symbol_find_or_make (name
);
2250 if (exp
.X_op
== O_constant
)
2252 S_SET_SIZE (sym
, exp
.X_add_number
);
2253 xfree (symbol_get_obj (sym
)->size
);
2254 symbol_get_obj (sym
)->size
= NULL
;
2258 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2259 *symbol_get_obj (sym
)->size
= exp
;
2261 demand_empty_rest_of_line ();
2264 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2265 There are six syntaxes:
2267 The first (used on Solaris) is
2269 The second (used on UnixWare) is
2271 The third (reportedly to be used on Irix 6.0) is
2273 The fourth (used on NetBSD/Arm and Linux/ARM) is
2275 The fifth (used on SVR4/860) is
2276 .type SYM,"function"
2277 The sixth (emitted by recent SunPRO under Solaris) is
2279 where the integer is the STT_* value.
2283 obj_elf_type_name (char *cp
)
2287 p
= input_line_pointer
;
2288 if (*input_line_pointer
>= '0'
2289 && *input_line_pointer
<= '9')
2291 while (*input_line_pointer
>= '0'
2292 && *input_line_pointer
<= '9')
2293 ++input_line_pointer
;
2294 *cp
= *input_line_pointer
;
2295 *input_line_pointer
= '\0';
2298 *cp
= get_symbol_name (&p
);
2304 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2308 const char *type_name
;
2310 elf_symbol_type
*elfsym
;
2312 sym
= get_sym_from_input_line_and_check ();
2313 c
= *input_line_pointer
;
2314 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2316 if (*input_line_pointer
== ',')
2317 ++input_line_pointer
;
2320 if ( *input_line_pointer
== '#'
2321 || *input_line_pointer
== '@'
2322 || *input_line_pointer
== '"'
2323 || *input_line_pointer
== '%')
2324 ++input_line_pointer
;
2326 type_name
= obj_elf_type_name (& c
);
2329 if (strcmp (type_name
, "function") == 0
2330 || strcmp (type_name
, "2") == 0
2331 || strcmp (type_name
, "STT_FUNC") == 0)
2332 type
= BSF_FUNCTION
;
2333 else if (strcmp (type_name
, "object") == 0
2334 || strcmp (type_name
, "1") == 0
2335 || strcmp (type_name
, "STT_OBJECT") == 0)
2337 else if (strcmp (type_name
, "tls_object") == 0
2338 || strcmp (type_name
, "6") == 0
2339 || strcmp (type_name
, "STT_TLS") == 0)
2340 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2341 else if (strcmp (type_name
, "notype") == 0
2342 || strcmp (type_name
, "0") == 0
2343 || strcmp (type_name
, "STT_NOTYPE") == 0)
2345 else if (strcmp (type_name
, "common") == 0
2346 || strcmp (type_name
, "5") == 0
2347 || strcmp (type_name
, "STT_COMMON") == 0)
2351 if (! S_IS_COMMON (sym
))
2353 if (S_IS_VOLATILE (sym
))
2355 sym
= symbol_clone (sym
, 1);
2356 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2357 S_SET_VALUE (sym
, 0);
2358 S_SET_EXTERNAL (sym
);
2359 symbol_set_frag (sym
, &zero_address_frag
);
2360 S_CLEAR_VOLATILE (sym
);
2362 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2363 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2366 /* FIXME: Is it safe to just change the section ? */
2367 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2368 S_SET_VALUE (sym
, 0);
2369 S_SET_EXTERNAL (sym
);
2373 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2374 || strcmp (type_name
, "10") == 0
2375 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2377 const struct elf_backend_data
*bed
;
2379 bed
= get_elf_backend_data (stdoutput
);
2380 if (bed
->elf_osabi
!= ELFOSABI_NONE
2381 && bed
->elf_osabi
!= ELFOSABI_GNU
2382 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2383 as_bad (_("symbol type \"%s\" is supported only by GNU "
2384 "and FreeBSD targets"), type_name
);
2385 /* MIPS targets do not support IFUNCS. */
2386 else if (bed
->target_id
== MIPS_ELF_DATA
)
2387 as_bad (_("symbol type \"%s\" is not supported by "
2388 "MIPS targets"), type_name
);
2389 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2390 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2392 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2394 const struct elf_backend_data
*bed
;
2396 bed
= get_elf_backend_data (stdoutput
);
2397 if (bed
->elf_osabi
!= ELFOSABI_NONE
2398 && bed
->elf_osabi
!= ELFOSABI_GNU
)
2399 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2401 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2402 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2404 #ifdef md_elf_symbol_type
2405 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2409 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2411 *input_line_pointer
= c
;
2413 if (*input_line_pointer
== '"')
2414 ++input_line_pointer
;
2416 #ifdef md_elf_symbol_type_change
2417 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2420 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2422 if (type
!= BSF_FUNCTION
)
2423 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2424 if (type
!= BSF_OBJECT
)
2426 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2428 if (S_IS_COMMON (sym
))
2430 as_bad (_("cannot change type of common symbol '%s'"),
2436 /* Don't warn when changing to STT_NOTYPE. */
2439 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2441 if (new != (elfsym
->symbol
.flags
| type
))
2442 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2443 elfsym
->symbol
.flags
= new;
2446 elfsym
->symbol
.flags
&= ~mask
;
2449 demand_empty_rest_of_line ();
2452 static segT comment_section
;
2455 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2457 segT old_section
= now_seg
;
2458 int old_subsection
= now_subseg
;
2460 #ifdef md_flush_pending_output
2461 md_flush_pending_output ();
2464 if (!comment_section
)
2467 comment_section
= subseg_new (".comment", 0);
2468 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2469 | SEC_MERGE
| SEC_STRINGS
));
2470 comment_section
->entsize
= 1;
2471 #ifdef md_elf_section_change_hook
2472 md_elf_section_change_hook ();
2478 subseg_set (comment_section
, 0);
2480 subseg_set (old_section
, old_subsection
);
2483 #ifdef INIT_STAB_SECTION
2485 /* The first entry in a .stabs section is special. */
2488 obj_elf_init_stab_section (segT seg
)
2493 unsigned int stroff
;
2495 /* Force the section to align to a longword boundary. Without this,
2496 UnixWare ar crashes. */
2497 bfd_set_section_alignment (seg
, 2);
2499 /* Make space for this first symbol. */
2503 file
= remap_debug_filename (as_where (NULL
));
2504 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2505 stroff
= get_stab_string_offset (file
, stabstr_name
, true);
2506 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2507 md_number_to_chars (p
, stroff
, 4);
2508 seg_info (seg
)->stabu
.p
= p
;
2514 /* Fill in the counts in the first entry in a .stabs section. */
2517 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2524 if (!startswith (sec
->name
, ".stab"))
2526 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2529 name
= concat (sec
->name
, "str", NULL
);
2530 strsec
= bfd_get_section_by_name (abfd
, name
);
2532 strsz
= bfd_section_size (strsec
);
2535 nsyms
= bfd_section_size (sec
) / 12 - 1;
2537 p
= seg_info (sec
)->stabu
.p
;
2538 gas_assert (p
!= 0);
2540 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2541 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2545 #ifdef NEED_ECOFF_DEBUG
2547 /* This function is called by the ECOFF code. It is supposed to
2548 record the external symbol information so that the backend can
2549 write it out correctly. The ELF backend doesn't actually handle
2550 this at the moment, so we do it ourselves. We save the information
2553 #ifdef OBJ_MAYBE_ELF
2557 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2559 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2562 /* This function is called by bfd_ecoff_debug_externals. It is
2563 supposed to *EXT to the external symbol information, and return
2564 whether the symbol should be used at all. */
2567 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2569 if (sym
->udata
.p
== NULL
)
2571 *ext
= *(EXTR
*) sym
->udata
.p
;
2575 /* This function is called by bfd_ecoff_debug_externals. It has
2576 nothing to do for ELF. */
2579 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2580 bfd_size_type indx ATTRIBUTE_UNUSED
)
2584 #endif /* NEED_ECOFF_DEBUG */
2587 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2589 struct elf_obj_sy
*sy_obj
;
2591 struct elf_versioned_name_list
*versioned_name
;
2593 #ifdef NEED_ECOFF_DEBUG
2594 if (ECOFF_DEBUGGING
)
2595 ecoff_frob_symbol (symp
);
2598 sy_obj
= symbol_get_obj (symp
);
2600 size
= sy_obj
->size
;
2603 if (resolve_expression (size
)
2604 && size
->X_op
== O_constant
)
2605 S_SET_SIZE (symp
, size
->X_add_number
);
2608 if (!flag_allow_nonconst_size
)
2609 as_bad (_(".size expression for %s "
2610 "does not evaluate to a constant"), S_GET_NAME (symp
));
2612 as_warn (_(".size expression for %s "
2613 "does not evaluate to a constant"), S_GET_NAME (symp
));
2615 free (sy_obj
->size
);
2616 sy_obj
->size
= NULL
;
2619 versioned_name
= sy_obj
->versioned_name
;
2622 /* This symbol was given a new name with the .symver directive.
2623 If this is an external reference, just rename the symbol to
2624 include the version string. This will make the relocs be
2625 against the correct versioned symbol. */
2627 /* We will have already reported an version error. */
2628 if (sy_obj
->bad_version
)
2630 /* elf_frob_file_before_adjust only allows one version symbol for
2632 else if (sy_obj
->rename
)
2633 S_SET_NAME (symp
, versioned_name
->name
);
2634 else if (S_IS_COMMON (symp
))
2636 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2637 versioned_name
->name
, S_GET_NAME (symp
));
2643 elf_symbol_type
*elfsym
;
2645 /* This is a definition. Add an alias for each version.
2646 FIXME: Using an alias will permit the debugging information
2647 to refer to the right symbol. However, it's not clear
2648 whether it is the best approach. */
2650 /* FIXME: Creating a new symbol here is risky. We're
2651 in the final loop over the symbol table. We can
2652 get away with it only because the symbol goes to
2653 the end of the list, where the loop will still see
2654 it. It would probably be better to do this in
2655 obj_frob_file_before_adjust. */
2656 for (; versioned_name
!= NULL
;
2657 versioned_name
= versioned_name
->next
)
2659 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2661 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2663 /* Subtracting out the frag address here is a hack
2664 because we are in the middle of the final loop. */
2667 - (symbol_get_frag (symp
)->fr_address
2668 / OCTETS_PER_BYTE
)));
2670 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2672 /* This will copy over the size information. */
2673 copy_symbol_attributes (symp2
, symp
);
2675 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2677 if (S_IS_WEAK (symp
))
2680 if (S_IS_EXTERNAL (symp
))
2681 S_SET_EXTERNAL (symp2
);
2684 switch (sy_obj
->visibility
)
2686 case visibility_unchanged
:
2688 case visibility_hidden
:
2689 bfdsym
= symbol_get_bfdsym (symp
);
2690 elfsym
= elf_symbol_from (bfdsym
);
2691 elfsym
->internal_elf_sym
.st_other
&= ~3;
2692 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2694 case visibility_remove
:
2695 /* Don't remove the symbol if it is used in relocation.
2696 Instead, mark it as to be removed and issue an error
2697 if the symbol has more than one versioned name. */
2698 if (symbol_used_in_reloc_p (symp
))
2700 if (sy_obj
->versioned_name
->next
!= NULL
)
2701 as_bad (_("symbol '%s' with multiple versions cannot be used in relocation"),
2703 symbol_mark_removed (symp
);
2706 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2708 case visibility_local
:
2709 S_CLEAR_EXTERNAL (symp
);
2715 /* Double check weak symbols. */
2716 if (S_IS_WEAK (symp
))
2718 if (S_IS_COMMON (symp
))
2719 as_bad (_("symbol `%s' can not be both weak and common"),
2724 /* Fix up SYMPP which has been marked to be removed by .symver. */
2727 elf_fixup_removed_symbol (symbolS
**sympp
)
2729 symbolS
*symp
= *sympp
;
2730 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2732 /* Replace the removed symbol with the versioned symbol. */
2733 symp
= symbol_find (sy_obj
->versioned_name
->name
);
2739 asection
**head
; /* Section lists. */
2740 unsigned int num_group
; /* Number of lists. */
2741 htab_t indexes
; /* Maps group name to index in head array. */
2744 static struct group_list groups
;
2746 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2747 add it to a list of sections belonging to the group. INF is a
2748 pointer to a struct group_list, which is where we store the head of
2749 each list. If its link_to_symbol_name isn't NULL, set up its
2750 linked-to section. */
2753 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2754 asection
*sec
, void *inf
)
2756 struct group_list
*list
= (struct group_list
*) inf
;
2757 const char *group_name
= elf_group_name (sec
);
2759 unsigned int *elem_idx
;
2760 unsigned int *idx_ptr
;
2762 if (sec
->map_head
.linked_to_symbol_name
)
2764 symbolS
*linked_to_sym
;
2765 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2766 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2767 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2768 sec
->map_head
.linked_to_symbol_name
,
2769 bfd_section_name (sec
));
2771 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2774 if (group_name
== NULL
)
2777 /* If this group already has a list, add the section to the head of
2779 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2780 if (elem_idx
!= NULL
)
2782 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2783 list
->head
[*elem_idx
] = sec
;
2787 /* New group. Make the arrays bigger in chunks to minimize calls to
2789 i
= list
->num_group
;
2792 unsigned int newsize
= i
+ 128;
2793 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2795 list
->head
[i
] = sec
;
2796 list
->num_group
+= 1;
2798 /* Add index to hash. */
2799 idx_ptr
= XNEW (unsigned int);
2801 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2805 free_section_idx (void *ent
)
2807 string_tuple_t
*tuple
= ent
;
2808 free ((char *) tuple
->value
);
2811 /* Create symbols for group signature. */
2814 elf_adjust_symtab (void)
2818 /* Go find section groups. */
2819 groups
.num_group
= 0;
2821 groups
.indexes
= htab_create_alloc (16, hash_string_tuple
, eq_string_tuple
,
2822 free_section_idx
, notes_calloc
, NULL
);
2823 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2826 /* Make the SHT_GROUP sections that describe each section group. We
2827 can't set up the section contents here yet, because elf section
2828 indices have yet to be calculated. elf.c:set_group_contents does
2829 the rest of the work. */
2830 for (i
= 0; i
< groups
.num_group
; i
++)
2832 const char *group_name
= elf_group_name (groups
.head
[i
]);
2833 const char *sec_name
;
2838 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2839 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2840 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2842 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2843 if (s
!= groups
.head
[i
])
2845 as_warn (_("assuming all members of group `%s' are COMDAT"),
2851 sec_name
= ".group";
2852 s
= subseg_force_new (sec_name
, 0);
2854 || !bfd_set_section_flags (s
, flags
)
2855 || !bfd_set_section_alignment (s
, 2))
2857 as_fatal (_("can't create group: %s"),
2858 bfd_errmsg (bfd_get_error ()));
2860 elf_section_type (s
) = SHT_GROUP
;
2862 /* Pass a pointer to the first section in this group. */
2863 elf_next_in_group (s
) = groups
.head
[i
];
2864 elf_sec_group (groups
.head
[i
]) = s
;
2865 /* Make sure that the signature symbol for the group has the
2866 name of the group. */
2867 sy
= symbol_find_exact (group_name
);
2868 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2870 /* Create the symbol now. */
2871 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2873 /* Before Solaris 11 build 154, Sun ld rejects local group
2874 signature symbols, so make them weak hidden instead. */
2875 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2876 S_SET_OTHER (sy
, STV_HIDDEN
);
2878 symbol_get_obj (sy
)->local
= 1;
2880 symbol_table_insert (sy
);
2882 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2883 /* Mark the group signature symbol as used so that it will be
2884 included in the symbol table. */
2885 symbol_mark_used_in_reloc (sy
);
2890 elf_frob_file (void)
2892 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2894 #ifdef elf_tc_final_processing
2895 elf_tc_final_processing ();
2899 /* It removes any unneeded versioned symbols from the symbol table. */
2902 elf_frob_file_before_adjust (void)
2908 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2910 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2911 int is_defined
= !!S_IS_DEFINED (symp
);
2913 if (sy_obj
->versioned_name
)
2915 char *p
= strchr (sy_obj
->versioned_name
->name
,
2920 /* The @@@ syntax is a special case. If the symbol is
2921 not defined, 2 `@'s will be removed from the
2922 versioned_name. Otherwise, 1 `@' will be removed. */
2923 size_t l
= strlen (&p
[3]) + 1;
2924 memmove (&p
[1 + is_defined
], &p
[3], l
);
2929 /* Verify that the name isn't using the @@ syntax--this
2930 is reserved for definitions of the default version
2932 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2934 as_bad (_("invalid attempt to declare external "
2935 "version name as default in symbol `%s'"),
2936 sy_obj
->versioned_name
->name
);
2940 /* Only one version symbol is allowed for undefined
2942 if (sy_obj
->versioned_name
->next
)
2944 as_bad (_("multiple versions [`%s'|`%s'] for "
2946 sy_obj
->versioned_name
->name
,
2947 sy_obj
->versioned_name
->next
->name
,
2952 sy_obj
->rename
= true;
2956 /* If there was .symver or .weak, but symbol was neither
2957 defined nor used anywhere, remove it. */
2959 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2960 && symbol_used_p (symp
) == 0
2961 && symbol_used_in_reloc_p (symp
) == 0)
2962 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2967 /* It is required that we let write_relocs have the opportunity to
2968 optimize away fixups before output has begun, since it is possible
2969 to eliminate all fixups for a section and thus we never should
2970 have generated the relocation section. */
2973 elf_frob_file_after_relocs (void)
2977 /* Set SHT_GROUP section size. */
2978 for (i
= 0; i
< groups
.num_group
; i
++)
2980 asection
*s
, *head
, *group
;
2983 head
= groups
.head
[i
];
2985 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2986 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2988 group
= elf_sec_group (head
);
2989 subseg_set (group
, 0);
2990 bfd_set_section_size (group
, size
);
2991 group
->contents
= (unsigned char *) frag_more (size
);
2992 frag_now
->fr_fix
= frag_now_fix_octets ();
2993 frag_wane (frag_now
);
2996 #ifdef NEED_ECOFF_DEBUG
2997 if (ECOFF_DEBUGGING
)
2998 /* Generate the ECOFF debugging information. */
3000 const struct ecoff_debug_swap
*debug_swap
;
3001 struct ecoff_debug_info debug
;
3006 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
3007 know (debug_swap
!= NULL
);
3008 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
3010 /* Set up the pointers in debug. */
3011 debug
.alloc_syments
= true;
3012 #define SET(ptr, offset, type) \
3013 debug.ptr = (type) (buf + debug.symbolic_header.offset)
3015 SET (line
, cbLineOffset
, unsigned char *);
3016 SET (external_dnr
, cbDnOffset
, void *);
3017 SET (external_pdr
, cbPdOffset
, void *);
3018 SET (external_sym
, cbSymOffset
, void *);
3019 SET (external_opt
, cbOptOffset
, void *);
3020 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
3021 SET (ss
, cbSsOffset
, char *);
3022 SET (external_fdr
, cbFdOffset
, void *);
3023 SET (external_rfd
, cbRfdOffset
, void *);
3024 /* ssext and external_ext are set up just below. */
3028 /* Set up the external symbols. */
3029 debug
.ssext
= debug
.ssext_end
= NULL
;
3030 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3031 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
3032 elf_get_extr
, elf_set_index
))
3033 as_fatal (_("failed to set up debugging information: %s"),
3034 bfd_errmsg (bfd_get_error ()));
3036 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
3037 gas_assert (sec
!= NULL
);
3039 know (!stdoutput
->output_has_begun
);
3041 /* We set the size of the section, call bfd_set_section_contents
3042 to force the ELF backend to allocate a file position, and then
3043 write out the data. FIXME: Is this really the best way to do
3045 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
3048 /* Pass BUF to bfd_set_section_contents because this will
3049 eventually become a call to fwrite, and ISO C prohibits
3050 passing a NULL pointer to a stdio function even if the
3051 pointer will not be used. */
3052 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3053 as_fatal (_("can't start writing .mdebug section: %s"),
3054 bfd_errmsg (bfd_get_error ()));
3056 know (stdoutput
->output_has_begun
);
3057 know (sec
->filepos
!= 0);
3059 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3061 as_fatal (_("could not write .mdebug section: %s"),
3062 bfd_errmsg (bfd_get_error ()));
3064 #endif /* NEED_ECOFF_DEBUG */
3068 elf_generate_asm_lineno (void)
3070 #ifdef NEED_ECOFF_DEBUG
3071 if (ECOFF_DEBUGGING
)
3072 ecoff_generate_asm_lineno ();
3077 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
3078 int what ATTRIBUTE_UNUSED
,
3079 const char *string ATTRIBUTE_UNUSED
,
3080 int type ATTRIBUTE_UNUSED
,
3081 int other ATTRIBUTE_UNUSED
,
3082 int desc ATTRIBUTE_UNUSED
)
3084 #ifdef NEED_ECOFF_DEBUG
3085 if (ECOFF_DEBUGGING
)
3086 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3091 elf_separate_stab_sections (void)
3093 #ifdef NEED_ECOFF_DEBUG
3094 return (!ECOFF_DEBUGGING
);
3101 elf_init_stab_section (segT seg
)
3103 #ifdef NEED_ECOFF_DEBUG
3104 if (!ECOFF_DEBUGGING
)
3106 obj_elf_init_stab_section (seg
);
3109 /* This is called when the assembler starts. */
3116 /* Add symbols for the known sections to the symbol table. */
3117 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
3118 symbol_table_insert (section_symbol (s
));
3119 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
3120 symbol_table_insert (section_symbol (s
));
3121 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
3122 symbol_table_insert (section_symbol (s
));
3123 elf_com_section_ptr
= bfd_com_section_ptr
;
3124 previous_section
= NULL
;
3125 previous_subsection
= 0;
3126 comment_section
= NULL
;
3127 memset (&groups
, 0, sizeof (groups
));
3133 while (section_stack
)
3135 struct section_stack
*top
= section_stack
;
3136 section_stack
= top
->next
;
3139 while (recorded_attributes
)
3141 struct recorded_attribute_info
*rai
= recorded_attributes
;
3142 recorded_attributes
= rai
->next
;
3147 htab_delete (groups
.indexes
);
3152 const struct format_ops elf_format_ops
=
3154 bfd_target_elf_flavour
,
3155 0, /* dfl_leading_underscore */
3156 1, /* emit_section_symbols */
3162 elf_frob_file_before_adjust
,
3163 0, /* obj_frob_file_before_fix */
3164 elf_frob_file_after_relocs
,
3165 elf_s_get_size
, elf_s_set_size
,
3166 elf_s_get_align
, elf_s_set_align
,
3173 elf_copy_symbol_attributes
,
3174 elf_generate_asm_lineno
,
3176 elf_separate_stab_sections
,
3177 elf_init_stab_section
,
3178 elf_sec_sym_ok_for_reloc
,
3180 #ifdef NEED_ECOFF_DEBUG
3183 0, /* ecoff_set_ext */
3185 elf_obj_read_begin_hook
,
3186 elf_obj_symbol_new_hook
,
3187 elf_obj_symbol_clone_hook
,