1 /* ELF object file format
2 Copyright (C) 1992-2020 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 dwarf. */
128 /* These are used for dwarf2. */
129 { "file", dwarf2_directive_file
, 0 },
130 { "loc", dwarf2_directive_loc
, 0 },
131 { "loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0 },
133 /* We need to trap the section changing calls to handle .previous. */
134 {"data", obj_elf_data
, 0},
135 {"offset", obj_elf_struct
, 0},
136 {"struct", obj_elf_struct
, 0},
137 {"text", obj_elf_text
, 0},
139 {"tls_common", obj_elf_tls_common
, 0},
145 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
147 #ifdef NEED_ECOFF_DEBUG
148 /* COFF style debugging information for ECOFF. .ln is not used; .loc
150 { "def", ecoff_directive_def
, 0 },
151 { "dim", ecoff_directive_dim
, 0 },
152 { "endef", ecoff_directive_endef
, 0 },
153 { "file", ecoff_directive_file
, 0 },
154 { "scl", ecoff_directive_scl
, 0 },
155 { "tag", ecoff_directive_tag
, 0 },
156 { "val", ecoff_directive_val
, 0 },
158 /* COFF debugging requires pseudo-ops .size and .type, but ELF
159 already has meanings for those. We use .esize and .etype
160 instead. These are only generated by gcc anyhow. */
161 { "esize", ecoff_directive_size
, 0 },
162 { "etype", ecoff_directive_type
, 0 },
164 /* ECOFF specific debugging information. */
165 { "aent", ecoff_directive_ent
, 1 },
166 { "begin", ecoff_directive_begin
, 0 },
167 { "bend", ecoff_directive_bend
, 0 },
168 { "end", ecoff_directive_end
, 0 },
169 { "ent", ecoff_directive_ent
, 0 },
170 { "fmask", ecoff_directive_fmask
, 0 },
171 { "frame", ecoff_directive_frame
, 0 },
172 { "loc", ecoff_directive_loc
, 0 },
173 { "mask", ecoff_directive_mask
, 0 },
175 /* Other ECOFF directives. */
176 { "extern", ecoff_directive_extern
, 0 },
178 /* These are used on Irix. I don't know how to implement them. */
179 { "alias", s_ignore
, 0 },
180 { "bgnb", s_ignore
, 0 },
181 { "endb", s_ignore
, 0 },
182 { "lab", s_ignore
, 0 },
183 { "noalias", s_ignore
, 0 },
184 { "verstamp", s_ignore
, 0 },
185 { "vreg", s_ignore
, 0 },
188 {NULL
, NULL
, 0} /* end sentinel */
192 #include "aout/aout64.h"
194 /* This is called when the assembler starts. */
196 asection
*elf_com_section_ptr
;
203 /* Add symbols for the known sections to the symbol table. */
204 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
205 symbol_table_insert (section_symbol (s
));
206 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
207 symbol_table_insert (section_symbol (s
));
208 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
209 symbol_table_insert (section_symbol (s
));
210 elf_com_section_ptr
= bfd_com_section_ptr
;
214 elf_pop_insert (void)
216 pop_insert (elf_pseudo_table
);
218 pop_insert (ecoff_debug_pseudo_table
);
222 elf_s_get_size (symbolS
*sym
)
224 return S_GET_SIZE (sym
);
228 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
230 S_SET_SIZE (sym
, sz
);
234 elf_s_get_align (symbolS
*sym
)
236 return S_GET_ALIGN (sym
);
240 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
242 S_SET_ALIGN (sym
, align
);
246 elf_s_get_other (symbolS
*sym
)
248 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
252 elf_s_set_other (symbolS
*sym
, int other
)
254 S_SET_OTHER (sym
, other
);
258 elf_sec_sym_ok_for_reloc (asection
*sec
)
260 return obj_sec_sym_ok_for_reloc (sec
);
264 elf_file_symbol (const char *s
, int appfile
)
269 || symbol_rootP
== NULL
270 || (bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
271 || (bsym
->flags
& BSF_FILE
) == 0)
276 sym
= symbol_new (s
, absolute_section
, &zero_address_frag
, 0);
278 name_length
= strlen (s
);
279 if (name_length
> strlen (S_GET_NAME (sym
)))
281 obstack_grow (¬es
, s
, name_length
+ 1);
282 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
285 strcpy ((char *) S_GET_NAME (sym
), s
);
287 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
289 if (symbol_rootP
!= sym
290 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
291 || (bsym
->flags
& BSF_FILE
) == 0))
293 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
294 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
298 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
302 #ifdef NEED_ECOFF_DEBUG
303 ecoff_new_file (s
, appfile
);
307 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
308 Parse a possible alignment value. */
311 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
314 int is_local
= symbol_get_obj (symbolP
)->local
;
316 if (*input_line_pointer
== ',')
318 char *save
= input_line_pointer
;
320 input_line_pointer
++;
323 if (*input_line_pointer
== '"')
325 /* For sparc. Accept .common symbol, length, "bss" */
326 input_line_pointer
++;
327 /* Some use the dot, some don't. */
328 if (*input_line_pointer
== '.')
329 input_line_pointer
++;
330 /* Some say data, some say bss. */
331 if (strncmp (input_line_pointer
, "bss\"", 4) == 0)
332 input_line_pointer
+= 4;
333 else if (strncmp (input_line_pointer
, "data\"", 5) == 0)
334 input_line_pointer
+= 5;
337 char *p
= input_line_pointer
;
342 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
343 if (*input_line_pointer
++ == '"')
345 c
= *input_line_pointer
;
346 *input_line_pointer
= '\0';
347 as_bad (_("bad .common segment %s"), p
);
348 *input_line_pointer
= c
;
349 ignore_rest_of_line ();
352 /* ??? Don't ask me why these are always global. */
357 input_line_pointer
= save
;
358 align
= parse_align (is_local
);
359 if (align
== (addressT
) -1)
366 bss_alloc (symbolP
, size
, align
);
367 S_CLEAR_EXTERNAL (symbolP
);
371 S_SET_VALUE (symbolP
, size
);
372 S_SET_ALIGN (symbolP
, align
);
373 S_SET_EXTERNAL (symbolP
);
374 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
377 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
383 obj_elf_common (int is_common
)
385 if (flag_mri
&& is_common
)
388 s_comm_internal (0, elf_common_parse
);
392 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
394 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
397 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
401 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
403 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
406 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
410 get_sym_from_input_line_and_check (void)
416 c
= get_symbol_name (& name
);
417 sym
= symbol_find_or_make (name
);
418 *input_line_pointer
= c
;
419 SKIP_WHITESPACE_AFTER_NAME ();
421 /* There is no symbol name if input_line_pointer has not moved. */
422 if (name
== input_line_pointer
)
423 as_bad (_("Missing symbol name in directive"));
428 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
435 symbolP
= get_sym_from_input_line_and_check ();
436 c
= *input_line_pointer
;
437 S_CLEAR_EXTERNAL (symbolP
);
438 symbol_get_obj (symbolP
)->local
= 1;
441 input_line_pointer
++;
443 if (*input_line_pointer
== '\n')
448 demand_empty_rest_of_line ();
452 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
459 symbolP
= get_sym_from_input_line_and_check ();
460 c
= *input_line_pointer
;
461 S_SET_WEAK (symbolP
);
464 input_line_pointer
++;
466 if (*input_line_pointer
== '\n')
471 demand_empty_rest_of_line ();
475 obj_elf_visibility (int visibility
)
480 elf_symbol_type
*elfsym
;
484 symbolP
= get_sym_from_input_line_and_check ();
486 bfdsym
= symbol_get_bfdsym (symbolP
);
487 elfsym
= elf_symbol_from (bfdsym
);
491 elfsym
->internal_elf_sym
.st_other
&= ~3;
492 elfsym
->internal_elf_sym
.st_other
|= visibility
;
494 c
= *input_line_pointer
;
497 input_line_pointer
++;
501 if (*input_line_pointer
== '\n')
507 demand_empty_rest_of_line ();
510 static segT previous_section
;
511 static int previous_subsection
;
515 struct section_stack
*next
;
517 int subseg
, prev_subseg
;
520 static struct section_stack
*section_stack
;
522 /* ELF section flags for unique sections. */
523 #define SEC_ASSEMBLER_SHF_MASK SHF_GNU_RETAIN
525 /* Return TRUE iff SEC matches the section info INF. */
528 get_section_by_match (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
530 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
531 const char *gname
= match
->group_name
;
532 const char *group_name
= elf_group_name (sec
);
533 const char *linked_to_symbol_name
534 = sec
->map_head
.linked_to_symbol_name
;
535 unsigned int sh_info
= elf_section_data (sec
)->this_hdr
.sh_info
;
536 bfd_vma sh_flags
= (elf_section_data (sec
)->this_hdr
.sh_flags
537 & SEC_ASSEMBLER_SHF_MASK
);
539 return (sh_info
== match
->sh_info
540 && sh_flags
== match
->sh_flags
541 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
542 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
543 && sec
->section_id
== match
->section_id
544 && (group_name
== gname
545 || (group_name
!= NULL
547 && strcmp (group_name
, gname
) == 0))
548 && (linked_to_symbol_name
== match
->linked_to_symbol_name
549 || (linked_to_symbol_name
!= NULL
550 && match
->linked_to_symbol_name
!= NULL
551 && strcmp (linked_to_symbol_name
,
552 match
->linked_to_symbol_name
) == 0)));
555 /* Handle the .section pseudo-op. This code supports two different
558 The first is found on Solaris, and looks like
559 .section ".sec1",#alloc,#execinstr,#write
560 Here the names after '#' are the SHF_* flags to turn on for the
561 section. I'm not sure how it determines the SHT_* type (BFD
562 doesn't really give us control over the type, anyhow).
564 The second format is found on UnixWare, and probably most SVR4
565 machines, and looks like
566 .section .sec1,"a",@progbits
567 The quoted string may contain any combination of a, w, x, and
568 represents the SHF_* flags to turn on for the section. The string
569 beginning with '@' can be progbits or nobits. There should be
570 other possibilities, but I don't know what they are. In any case,
571 BFD doesn't really let us set the section type. */
574 obj_elf_change_section (const char *name
,
578 struct elf_section_match
*match_p
,
585 const struct elf_backend_data
*bed
;
586 const struct bfd_elf_special_section
*ssect
;
590 static struct elf_section_match unused_match
;
591 match_p
= &unused_match
;
594 #ifdef md_flush_pending_output
595 md_flush_pending_output ();
598 /* Switch to the section, creating it if necessary. */
601 struct section_stack
*elt
;
602 elt
= XNEW (struct section_stack
);
603 elt
->next
= section_stack
;
605 elt
->prev_seg
= previous_section
;
606 elt
->subseg
= now_subseg
;
607 elt
->prev_subseg
= previous_subsection
;
610 previous_section
= now_seg
;
611 previous_subsection
= now_subseg
;
613 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section_by_match
,
621 sec
= subseg_force_new (name
, 0);
623 bed
= get_elf_backend_data (stdoutput
);
624 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
628 bfd_boolean override
= FALSE
;
630 if (type
== SHT_NULL
)
632 else if (type
!= ssect
->type
)
635 /* Some older versions of gcc will emit
637 .section .init_array,"aw",@progbits
639 for __attribute__ ((section (".init_array"))).
640 "@progbits" is incorrect. Also for x86-64 large bss
641 sections, some older versions of gcc will emit
643 .section .lbss,"aw",@progbits
645 "@progbits" is incorrect. */
647 && (bed
->s
->arch_size
!= 64
648 || !(ssect
->attr
& SHF_X86_64_LARGE
))
650 && ssect
->type
!= SHT_INIT_ARRAY
651 && ssect
->type
!= SHT_FINI_ARRAY
652 && ssect
->type
!= SHT_PREINIT_ARRAY
)
654 /* We allow to specify any type for a .note section. */
655 if (ssect
->type
!= SHT_NOTE
656 /* Processor and application defined types are allowed too. */
657 && type
< SHT_LOPROC
)
658 as_warn (_("setting incorrect section type for %s"),
663 as_warn (_("ignoring incorrect section type for %s"),
669 if (old_sec
== NULL
&& ((attr
& ~(SHF_MASKOS
| SHF_MASKPROC
))
670 & ~ssect
->attr
) != 0)
672 /* As a GNU extension, we permit a .note section to be
673 allocatable. If the linker sees an allocatable .note
674 section, it will create a PT_NOTE segment in the output
675 file. We also allow "x" for .note.GNU-stack. */
676 if (ssect
->type
== SHT_NOTE
677 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
679 /* Allow different SHF_MERGE and SHF_STRINGS if we have
680 something like .rodata.str. */
681 else if (ssect
->suffix_length
== -2
682 && name
[ssect
->prefix_length
] == '.'
686 & ~SHF_STRINGS
) == 0)
688 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
689 else if (attr
== SHF_ALLOC
690 && (strcmp (name
, ".interp") == 0
691 || strcmp (name
, ".strtab") == 0
692 || strcmp (name
, ".symtab") == 0))
694 /* .note.GNU-stack can have SHF_EXECINSTR. */
695 else if (attr
== SHF_EXECINSTR
696 && strcmp (name
, ".note.GNU-stack") == 0)
699 /* A section on Alpha may have SHF_ALPHA_GPREL. */
700 else if ((attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
704 else if (attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
705 && (ssect
->type
== SHT_INIT_ARRAY
706 || ssect
->type
== SHT_FINI_ARRAY
707 || ssect
->type
== SHT_PREINIT_ARRAY
))
708 /* RX init/fini arrays can and should have the "awx" attributes set. */
713 if (match_p
->group_name
== NULL
)
714 as_warn (_("setting incorrect section attributes for %s"),
720 if (!override
&& old_sec
== NULL
)
724 /* Convert ELF type and flags to BFD flags. */
726 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
727 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
728 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
729 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
730 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
731 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
732 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
733 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
734 #ifdef md_elf_section_flags
735 flags
= md_elf_section_flags (flags
, attr
, type
);
739 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
745 if (type
== SHT_NULL
)
746 type
= bfd_elf_get_default_section_type (flags
);
747 elf_section_type (sec
) = type
;
748 elf_section_flags (sec
) = attr
;
749 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->sh_info
;
751 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
752 if (type
== SHT_NOBITS
)
753 seg_info (sec
)->bss
= 1;
755 /* Set the section ID and flags. */
756 sec
->section_id
= match_p
->section_id
;
757 flags
|= match_p
->flags
;
759 /* Set the linked-to symbol name. */
760 sec
->map_head
.linked_to_symbol_name
761 = match_p
->linked_to_symbol_name
;
763 bfd_set_section_flags (sec
, flags
);
764 if (flags
& SEC_MERGE
)
765 sec
->entsize
= entsize
;
766 elf_group_name (sec
) = match_p
->group_name
;
768 /* Add a symbol for this section to the symbol table. */
769 secsym
= symbol_find (name
);
772 /* We could be repurposing an undefined symbol here: make sure we
773 reset sy_value to look like other section symbols in order to avoid
774 trying to incorrectly resolve this section symbol later on. */
775 static const expressionS exp
= { .X_op
= O_constant
};
776 symbol_set_value_expression (secsym
, &exp
);
777 symbol_set_bfdsym (secsym
, sec
->symbol
);
780 symbol_table_insert (section_symbol (sec
));
785 && (unsigned) type
!= elf_section_type (old_sec
))
788 /* This is a special section with known type. User
789 assembly might get the section type wrong; Even high
790 profile projects like glibc have done so in the past.
791 So don't error in this case. */
792 as_warn (_("ignoring changed section type for %s"), name
);
794 /* Do error when assembly isn't self-consistent. */
795 as_bad (_("changed section type for %s"), name
);
800 /* If section attributes are specified the second time we see a
801 particular section, then check that they are the same as we
802 saw the first time. */
803 if (((old_sec
->flags
^ flags
)
804 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
805 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
806 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
807 | SEC_THREAD_LOCAL
)))
810 as_warn (_("ignoring changed section attributes for %s"), name
);
812 as_bad (_("changed section attributes for %s"), name
);
815 /* FIXME: Maybe we should consider removing a previously set
816 processor or application specific attribute as suspicious? */
817 elf_section_flags (sec
) = attr
;
819 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
820 as_bad (_("changed section entity size for %s"), name
);
824 #ifdef md_elf_section_change_hook
825 md_elf_section_change_hook ();
830 obj_elf_parse_section_letters (char *str
, size_t len
,
831 bfd_boolean
*is_clone
, bfd_vma
*gnu_attr
)
847 attr
|= SHF_LINK_ORDER
;
853 attr
|= SHF_EXECINSTR
;
868 *gnu_attr
|= SHF_GNU_MBIND
;
871 *gnu_attr
|= SHF_GNU_RETAIN
;
878 if (*(str
- 1) == 'a')
881 if (len
> 1 && str
[1] == 's')
891 const char *bad_msg
= _("unrecognized .section attribute:"
892 " want a,e,o,w,x,M,S,G,T or number");
893 #ifdef md_elf_section_letter
894 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
895 if (md_attr
!= (bfd_vma
) -1)
902 struct elf_backend_data
*bed
;
903 bfd_vma numeric_flags
= strtoul (str
, &end
, 0);
905 attr
|= numeric_flags
;
907 bed
= (struct elf_backend_data
*)
908 get_elf_backend_data (stdoutput
);
910 if (bed
->elf_osabi
== ELFOSABI_NONE
911 || bed
->elf_osabi
== ELFOSABI_STANDALONE
912 || bed
->elf_osabi
== ELFOSABI_GNU
913 || bed
->elf_osabi
== ELFOSABI_FREEBSD
)
915 /* Add flags in the SHF_MASKOS range to gnu_attr for
916 OSABIs that support those flags.
917 Also adding the flags for ELFOSABI_{NONE,STANDALONE}
918 allows them to be validated later in obj_elf_section.
919 We can't just always set these bits in gnu_attr for
920 all OSABIs, since Binutils does not recognize all
921 SHF_MASKOS bits for non-GNU OSABIs. It's therefore
922 possible that numeric flags are being used to set bits
923 in the SHF_MASKOS range for those targets, and we
924 don't want assembly to fail in those situations. */
925 *gnu_attr
|= (numeric_flags
& SHF_MASKOS
);
928 /* Update str and len, allowing for the fact that
929 we will execute str++ and len-- below. */
935 as_fatal ("%s", bad_msg
);
946 obj_elf_section_type (char *str
, size_t len
, bfd_boolean warn
)
948 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
950 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
952 if (len
== 4 && strncmp (str
, "note", 4) == 0)
954 if (len
== 10 && strncmp (str
, "init_array", 10) == 0)
955 return SHT_INIT_ARRAY
;
956 if (len
== 10 && strncmp (str
, "fini_array", 10) == 0)
957 return SHT_FINI_ARRAY
;
958 if (len
== 13 && strncmp (str
, "preinit_array", 13) == 0)
959 return SHT_PREINIT_ARRAY
;
961 #ifdef md_elf_section_type
963 int md_type
= md_elf_section_type (str
, len
);
972 int type
= strtoul (str
, & end
, 0);
974 if (warn
&& (size_t) (end
- str
) != len
)
975 as_warn (_("extraneous characters at end of numeric section type"));
981 as_warn (_("unrecognized section type"));
986 obj_elf_section_word (char *str
, size_t len
, int *type
)
990 if (len
== 5 && strncmp (str
, "write", 5) == 0)
992 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
994 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
995 return SHF_EXECINSTR
;
996 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
998 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
1001 #ifdef md_elf_section_word
1003 bfd_vma md_attr
= md_elf_section_word (str
, len
);
1009 ret
= obj_elf_section_type (str
, len
, FALSE
);
1013 as_warn (_("unrecognized section attribute"));
1018 /* Get name of section. */
1020 obj_elf_section_name (void)
1025 if (*input_line_pointer
== '"')
1029 name
= demand_copy_C_string (&dummy
);
1032 ignore_rest_of_line ();
1038 char *end
= input_line_pointer
;
1040 while (0 == strchr ("\n\t,; ", *end
))
1042 if (end
== input_line_pointer
)
1044 as_bad (_("missing name"));
1045 ignore_rest_of_line ();
1049 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1051 while (flag_sectname_subst
)
1053 char *subst
= strchr (name
, '%');
1054 if (subst
&& subst
[1] == 'S')
1056 int oldlen
= strlen (name
);
1057 int substlen
= strlen (now_seg
->name
);
1058 int newlen
= oldlen
- 2 + substlen
;
1059 char *newname
= XNEWVEC (char, newlen
+ 1);
1060 int headlen
= subst
- name
;
1061 memcpy (newname
, name
, headlen
);
1062 strcpy (newname
+ headlen
, now_seg
->name
);
1063 strcat (newname
+ headlen
, subst
+ 2);
1071 #ifdef tc_canonicalize_section_name
1072 name
= tc_canonicalize_section_name (name
);
1074 input_line_pointer
= end
;
1081 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1083 const char * gname
= obj_elf_section_name ();
1087 as_warn (_("group name not parseable"));
1091 if (elf_group_name (now_seg
))
1093 as_warn (_("section %s already has a group (%s)"),
1094 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1098 elf_group_name (now_seg
) = xstrdup (gname
);
1099 elf_section_flags (now_seg
) |= SHF_GROUP
;
1103 obj_elf_section (int push
)
1112 subsegT new_subsection
= -1;
1113 struct elf_section_match match
;
1114 unsigned long linked_to_section_index
= -1UL;
1120 #ifdef md_flush_pending_output
1121 md_flush_pending_output ();
1124 previous_section
= now_seg
;
1125 previous_subsection
= now_subseg
;
1127 s_mri_sect (&mri_type
);
1129 #ifdef md_elf_section_change_hook
1130 md_elf_section_change_hook ();
1136 name
= obj_elf_section_name ();
1140 memset (&match
, 0, sizeof (match
));
1143 if ((sym
= symbol_find (name
)) != NULL
1144 && ! symbol_section_p (sym
)
1145 && S_IS_DEFINED (sym
)
1146 && ! S_IS_VOLATILE (sym
)
1147 && ! S_CAN_BE_REDEFINED (sym
))
1149 as_bad (_("section name '%s' already defined as another symbol"), name
);
1150 ignore_rest_of_line ();
1159 if (*input_line_pointer
== ',')
1161 /* Skip the comma. */
1162 ++input_line_pointer
;
1165 if (push
&& ISDIGIT (*input_line_pointer
))
1167 /* .pushsection has an optional subsection. */
1168 new_subsection
= (subsegT
) get_absolute_expression ();
1172 /* Stop if we don't see a comma. */
1173 if (*input_line_pointer
!= ',')
1176 /* Skip the comma. */
1177 ++input_line_pointer
;
1181 if (*input_line_pointer
== '"')
1183 bfd_boolean is_clone
;
1185 beg
= demand_copy_C_string (&dummy
);
1188 ignore_rest_of_line ();
1191 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1192 &is_clone
, &gnu_attr
);
1195 if (*input_line_pointer
== ',')
1198 char *save
= input_line_pointer
;
1200 ++input_line_pointer
;
1202 c
= *input_line_pointer
;
1205 beg
= demand_copy_C_string (&dummy
);
1208 ignore_rest_of_line ();
1211 type
= obj_elf_section_type (beg
, strlen (beg
), TRUE
);
1213 else if (c
== '@' || c
== '%')
1215 ++input_line_pointer
;
1217 if (ISDIGIT (* input_line_pointer
))
1218 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1221 c
= get_symbol_name (& beg
);
1222 (void) restore_line_pointer (c
);
1223 type
= obj_elf_section_type (beg
,
1224 input_line_pointer
- beg
,
1229 input_line_pointer
= save
;
1233 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1235 ++input_line_pointer
;
1237 entsize
= get_absolute_expression ();
1241 as_warn (_("invalid merge entity size"));
1246 else if ((attr
& SHF_MERGE
) != 0)
1248 as_warn (_("entity size for SHF_MERGE not specified"));
1252 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1254 ++input_line_pointer
;
1256 /* Check for a numeric section index, rather than a symbol name. */
1257 if (ISDIGIT (* input_line_pointer
))
1259 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1264 unsigned int length
;
1266 c
= get_symbol_name (& beg
);
1267 (void) restore_line_pointer (c
);
1268 length
= input_line_pointer
- beg
;
1270 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1274 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1276 as_warn (_("? section flag ignored with G present"));
1280 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1282 ++input_line_pointer
;
1283 match
.group_name
= obj_elf_section_name ();
1284 if (match
.group_name
== NULL
)
1286 else if (*input_line_pointer
== ',')
1288 ++input_line_pointer
;
1290 if (strncmp (input_line_pointer
, "comdat", 6) == 0)
1292 input_line_pointer
+= 6;
1296 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1299 else if ((attr
& SHF_GROUP
) != 0)
1301 as_warn (_("group name for SHF_GROUP not specified"));
1307 const char *now_group
= elf_group_name (now_seg
);
1308 if (now_group
!= NULL
)
1310 match
.group_name
= xstrdup (now_group
);
1311 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1315 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1317 char *save
= input_line_pointer
;
1318 ++input_line_pointer
;
1320 if (ISDIGIT (* input_line_pointer
))
1322 char *t
= input_line_pointer
;
1323 match
.sh_info
= strtoul (input_line_pointer
,
1324 &input_line_pointer
, 0);
1325 if (match
.sh_info
== (unsigned int) -1)
1327 as_warn (_("unsupported mbind section info: %s"), t
);
1332 input_line_pointer
= save
;
1335 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1336 match
.sh_flags
|= SHF_GNU_RETAIN
;
1338 if (*input_line_pointer
== ',')
1340 char *save
= input_line_pointer
;
1342 ++input_line_pointer
;
1344 if (strncmp (input_line_pointer
, "unique", 6) == 0)
1346 input_line_pointer
+= 6;
1348 if (*input_line_pointer
== ',')
1350 ++input_line_pointer
;
1352 if (ISDIGIT (* input_line_pointer
))
1355 bfd_boolean overflow
;
1356 char *t
= input_line_pointer
;
1357 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1360 id
= strtoul (input_line_pointer
,
1361 &input_line_pointer
, 0);
1362 overflow
= (id
== (unsigned long) -1
1363 && errno
== ERANGE
);
1368 (input_line_pointer
,
1369 (const char **) &input_line_pointer
, 0);
1370 overflow
= id
== ~(bfd_vma
) 0;
1372 if (overflow
|| id
> (unsigned int) -1)
1374 char *linefeed
, saved_char
= 0;
1375 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1377 saved_char
= *linefeed
;
1380 as_bad (_("unsupported section id: %s"), t
);
1382 *linefeed
= saved_char
;
1386 match
.section_id
= id
;
1387 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1393 input_line_pointer
= save
;
1403 if (*input_line_pointer
!= '#')
1405 as_bad (_("character following name is not '#'"));
1406 ignore_rest_of_line ();
1409 ++input_line_pointer
;
1410 c
= get_symbol_name (& beg
);
1411 (void) restore_line_pointer (c
);
1413 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1418 while (*input_line_pointer
++ == ',');
1419 --input_line_pointer
;
1424 demand_empty_rest_of_line ();
1426 if ((gnu_attr
& (SHF_GNU_MBIND
| SHF_GNU_RETAIN
)) != 0)
1428 struct elf_backend_data
*bed
;
1429 bfd_boolean mbind_p
= (gnu_attr
& SHF_GNU_MBIND
) != 0;
1431 if (mbind_p
&& (attr
& SHF_ALLOC
) == 0)
1432 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1434 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
1436 if (bed
->elf_osabi
!= ELFOSABI_GNU
1437 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
1438 && bed
->elf_osabi
!= ELFOSABI_NONE
)
1439 as_bad (_("%s section is supported only by GNU and FreeBSD targets"),
1440 mbind_p
? "GNU_MBIND" : "GNU_RETAIN");
1443 if (bed
->elf_osabi
== ELFOSABI_NONE
)
1444 bed
->elf_osabi
= ELFOSABI_GNU
;
1447 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1448 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1449 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_retain
;
1455 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1458 if (linked_to_section_index
!= -1UL)
1460 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1461 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1462 /* FIXME: Should we perform some sanity checking on the section index ? */
1465 if (push
&& new_subsection
!= -1)
1466 subseg_set (now_seg
, new_subsection
);
1469 /* Change to the .data section. */
1472 obj_elf_data (int i
)
1474 #ifdef md_flush_pending_output
1475 md_flush_pending_output ();
1478 previous_section
= now_seg
;
1479 previous_subsection
= now_subseg
;
1482 #ifdef md_elf_section_change_hook
1483 md_elf_section_change_hook ();
1487 /* Change to the .text section. */
1490 obj_elf_text (int i
)
1492 #ifdef md_flush_pending_output
1493 md_flush_pending_output ();
1496 previous_section
= now_seg
;
1497 previous_subsection
= now_subseg
;
1500 #ifdef md_elf_section_change_hook
1501 md_elf_section_change_hook ();
1505 /* Change to the *ABS* section. */
1508 obj_elf_struct (int i
)
1510 #ifdef md_flush_pending_output
1511 md_flush_pending_output ();
1514 previous_section
= now_seg
;
1515 previous_subsection
= now_subseg
;
1518 #ifdef md_elf_section_change_hook
1519 md_elf_section_change_hook ();
1524 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1528 #ifdef md_flush_pending_output
1529 md_flush_pending_output ();
1532 previous_section
= now_seg
;
1533 previous_subsection
= now_subseg
;
1535 temp
= get_absolute_expression ();
1536 subseg_set (now_seg
, (subsegT
) temp
);
1537 demand_empty_rest_of_line ();
1539 #ifdef md_elf_section_change_hook
1540 md_elf_section_change_hook ();
1544 /* This can be called from the processor backends if they change
1548 obj_elf_section_change_hook (void)
1550 previous_section
= now_seg
;
1551 previous_subsection
= now_subseg
;
1555 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1560 if (previous_section
== 0)
1562 as_warn (_(".previous without corresponding .section; ignored"));
1566 #ifdef md_flush_pending_output
1567 md_flush_pending_output ();
1570 new_section
= previous_section
;
1571 new_subsection
= previous_subsection
;
1572 previous_section
= now_seg
;
1573 previous_subsection
= now_subseg
;
1574 subseg_set (new_section
, new_subsection
);
1576 #ifdef md_elf_section_change_hook
1577 md_elf_section_change_hook ();
1582 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1584 struct section_stack
*top
= section_stack
;
1588 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1592 #ifdef md_flush_pending_output
1593 md_flush_pending_output ();
1596 section_stack
= top
->next
;
1597 previous_section
= top
->prev_seg
;
1598 previous_subsection
= top
->prev_subseg
;
1599 subseg_set (top
->seg
, top
->subseg
);
1602 #ifdef md_elf_section_change_hook
1603 md_elf_section_change_hook ();
1608 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1610 /* Assume delimiter is part of expression. BSD4.2 as fails with
1611 delightful bug, so we are not being incompatible here. */
1612 new_logical_line (NULL
, get_absolute_expression ());
1613 demand_empty_rest_of_line ();
1616 static struct elf_versioned_name_list
*
1617 obj_elf_find_and_add_versioned_name (const char *version_name
,
1618 const char *sym_name
,
1620 struct elf_obj_sy
*sy_obj
)
1622 struct elf_versioned_name_list
*versioned_name
;
1625 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1628 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1629 names, we have to disable this. */
1630 if (0 && *p
== '\0')
1632 as_bad (_("missing version name in `%s' for symbol `%s'"),
1633 version_name
, sym_name
);
1637 versioned_name
= sy_obj
->versioned_name
;
1647 if (strcmp (versioned_name
->name
, version_name
) == 0)
1648 return versioned_name
;
1651 as_bad (_("only one version name with `@@@' is allowed "
1652 "for symbol `%s'"), sym_name
);
1656 sy_obj
->rename
= TRUE
;
1659 as_bad (_("invalid version name '%s' for symbol `%s'"),
1660 version_name
, sym_name
);
1665 versioned_name
!= NULL
;
1666 versioned_name
= versioned_name
->next
)
1667 if (strcmp (versioned_name
->name
, version_name
) == 0)
1668 return versioned_name
;
1670 /* Add this versioned name to the head of the list, */
1671 versioned_name
= (struct elf_versioned_name_list
*)
1672 xmalloc (sizeof (*versioned_name
));
1673 versioned_name
->name
= xstrdup (version_name
);
1674 versioned_name
->next
= sy_obj
->versioned_name
;
1675 sy_obj
->versioned_name
= versioned_name
;
1677 return versioned_name
;
1680 /* This handles the .symver pseudo-op, which is used to specify a
1681 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1682 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1683 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1684 with the same value as the symbol NAME. */
1687 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1690 const char *sym_name
;
1694 struct elf_obj_sy
*sy_obj
;
1697 sym
= get_sym_from_input_line_and_check ();
1699 if (*input_line_pointer
!= ',')
1701 as_bad (_("expected comma after name in .symver"));
1702 ignore_rest_of_line ();
1706 ++input_line_pointer
;
1709 /* Temporarily include '@' in symbol names. */
1710 old_lexat
= lex_type
[(unsigned char) '@'];
1711 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1712 c
= get_symbol_name (& name
);
1713 lex_type
[(unsigned char) '@'] = old_lexat
;
1714 sym_name
= S_GET_NAME (sym
);
1716 if (S_IS_COMMON (sym
))
1718 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1720 ignore_rest_of_line ();
1724 p
= strchr (name
, ELF_VER_CHR
);
1727 as_bad (_("missing version name in `%s' for symbol `%s'"),
1729 ignore_rest_of_line ();
1733 sy_obj
= symbol_get_obj (sym
);
1734 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1737 sy_obj
->bad_version
= TRUE
;
1738 ignore_rest_of_line ();
1742 (void) restore_line_pointer (c
);
1744 if (*input_line_pointer
== ',')
1746 char *save
= input_line_pointer
;
1748 ++input_line_pointer
;
1750 if (strncmp (input_line_pointer
, "local", 5) == 0)
1752 input_line_pointer
+= 5;
1753 sy_obj
->visibility
= visibility_local
;
1755 else if (strncmp (input_line_pointer
, "hidden", 6) == 0)
1757 input_line_pointer
+= 6;
1758 sy_obj
->visibility
= visibility_hidden
;
1760 else if (strncmp (input_line_pointer
, "remove", 6) == 0)
1762 input_line_pointer
+= 6;
1763 sy_obj
->visibility
= visibility_remove
;
1766 input_line_pointer
= save
;
1769 demand_empty_rest_of_line ();
1772 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1773 to the linker the hierarchy in which a particular table resides. The
1774 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1777 obj_elf_get_vtable_inherit (void)
1779 char *cname
, *pname
;
1780 symbolS
*csym
, *psym
;
1783 if (*input_line_pointer
== '#')
1784 ++input_line_pointer
;
1786 c
= get_symbol_name (& cname
);
1787 csym
= symbol_find (cname
);
1789 /* GCFIXME: should check that we don't have two .vtable_inherits for
1790 the same child symbol. Also, we can currently only do this if the
1791 child symbol is already exists and is placed in a fragment. */
1793 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1795 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1800 *input_line_pointer
= c
;
1802 SKIP_WHITESPACE_AFTER_NAME ();
1803 if (*input_line_pointer
!= ',')
1805 as_bad (_("expected comma after name in .vtable_inherit"));
1806 ignore_rest_of_line ();
1810 ++input_line_pointer
;
1813 if (*input_line_pointer
== '#')
1814 ++input_line_pointer
;
1816 if (input_line_pointer
[0] == '0'
1817 && (input_line_pointer
[1] == '\0'
1818 || ISSPACE (input_line_pointer
[1])))
1820 psym
= section_symbol (absolute_section
);
1821 ++input_line_pointer
;
1825 c
= get_symbol_name (& pname
);
1826 psym
= symbol_find_or_make (pname
);
1827 restore_line_pointer (c
);
1830 demand_empty_rest_of_line ();
1835 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1836 return fix_new (symbol_get_frag (csym
),
1837 symbol_get_value_expression (csym
)->X_add_number
,
1838 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1841 /* This is a version of obj_elf_get_vtable_inherit() that is
1842 suitable for use in struct _pseudo_type tables. */
1845 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1847 (void) obj_elf_get_vtable_inherit ();
1850 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1851 to the linker that a vtable slot was used. The syntax is
1852 ".vtable_entry tablename, offset". */
1855 obj_elf_get_vtable_entry (void)
1860 if (*input_line_pointer
== '#')
1861 ++input_line_pointer
;
1863 sym
= get_sym_from_input_line_and_check ();
1864 if (*input_line_pointer
!= ',')
1866 as_bad (_("expected comma after name in .vtable_entry"));
1867 ignore_rest_of_line ();
1871 ++input_line_pointer
;
1872 if (*input_line_pointer
== '#')
1873 ++input_line_pointer
;
1875 offset
= get_absolute_expression ();
1877 demand_empty_rest_of_line ();
1879 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1880 BFD_RELOC_VTABLE_ENTRY
);
1883 /* This is a version of obj_elf_get_vtable_entry() that is
1884 suitable for use in struct _pseudo_type tables. */
1887 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1889 (void) obj_elf_get_vtable_entry ();
1892 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1895 skip_past_char (char ** str
, char c
)
1905 #define skip_past_comma(str) skip_past_char (str, ',')
1907 /* A list of attributes that have been explicitly set by the assembly code.
1908 VENDOR is the vendor id, BASE is the tag shifted right by the number
1909 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1910 struct recorded_attribute_info
{
1911 struct recorded_attribute_info
*next
;
1916 static struct recorded_attribute_info
*recorded_attributes
;
1918 /* Record that we have seen an explicit specification of attribute TAG
1919 for vendor VENDOR. */
1922 record_attribute (int vendor
, unsigned int tag
)
1926 struct recorded_attribute_info
*rai
;
1928 base
= tag
/ (8 * sizeof (rai
->mask
));
1929 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1930 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1931 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1937 rai
= XNEW (struct recorded_attribute_info
);
1938 rai
->next
= recorded_attributes
;
1939 rai
->vendor
= vendor
;
1942 recorded_attributes
= rai
;
1945 /* Return true if we have seen an explicit specification of attribute TAG
1946 for vendor VENDOR. */
1949 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1953 struct recorded_attribute_info
*rai
;
1955 base
= tag
/ (8 * sizeof (rai
->mask
));
1956 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1957 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1958 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1959 return (rai
->mask
& mask
) != 0;
1963 /* Parse an attribute directive for VENDOR.
1964 Returns the attribute number read, or zero on error. */
1967 obj_elf_vendor_attribute (int vendor
)
1975 /* Read the first number or name. */
1976 skip_whitespace (input_line_pointer
);
1977 s
= input_line_pointer
;
1978 if (ISDIGIT (*input_line_pointer
))
1981 if (exp
.X_op
!= O_constant
)
1983 tag
= exp
.X_add_number
;
1989 /* A name may contain '_', but no other punctuation. */
1990 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1991 ++input_line_pointer
)
1996 name
= xstrndup (s
, i
);
1998 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
1999 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2002 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2005 as_bad (_("Attribute name not recognised: %s"), name
);
2006 ignore_rest_of_line ();
2013 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2015 if (skip_past_comma (&input_line_pointer
) == -1)
2020 if (exp
.X_op
!= O_constant
)
2022 as_bad (_("expected numeric constant"));
2023 ignore_rest_of_line ();
2026 i
= exp
.X_add_number
;
2029 && skip_past_comma (&input_line_pointer
) == -1)
2031 as_bad (_("expected comma"));
2032 ignore_rest_of_line ();
2039 skip_whitespace (input_line_pointer
);
2040 if (*input_line_pointer
!= '"')
2042 s
= demand_copy_C_string (&len
);
2045 record_attribute (vendor
, tag
);
2049 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2052 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2055 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2061 demand_empty_rest_of_line ();
2064 as_bad (_("bad string constant"));
2065 ignore_rest_of_line ();
2068 as_bad (_("expected <tag> , <value>"));
2069 ignore_rest_of_line ();
2073 /* Parse a .gnu_attribute directive. */
2076 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2078 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2082 elf_obj_read_begin_hook (void)
2084 #ifdef NEED_ECOFF_DEBUG
2085 if (ECOFF_DEBUGGING
)
2086 ecoff_read_begin_hook ();
2091 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2093 struct elf_obj_sy
*sy_obj
;
2095 sy_obj
= symbol_get_obj (symbolP
);
2096 sy_obj
->size
= NULL
;
2097 sy_obj
->versioned_name
= NULL
;
2099 #ifdef NEED_ECOFF_DEBUG
2100 if (ECOFF_DEBUGGING
)
2101 ecoff_symbol_new_hook (symbolP
);
2105 /* When setting one symbol equal to another, by default we probably
2106 want them to have the same "size", whatever it means in the current
2110 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2112 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2113 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2116 if (destelf
->size
== NULL
)
2117 destelf
->size
= XNEW (expressionS
);
2118 *destelf
->size
= *srcelf
->size
;
2122 free (destelf
->size
);
2123 destelf
->size
= NULL
;
2125 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2126 /* Don't copy visibility. */
2127 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2128 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2132 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2137 asection
*seg
= now_seg
;
2138 subsegT subseg
= now_subseg
;
2139 Elf_Internal_Note i_note
;
2140 Elf_External_Note e_note
;
2141 asection
*note_secp
= NULL
;
2144 if (*input_line_pointer
== '\"')
2148 ++input_line_pointer
; /* -> 1st char of string. */
2149 name
= input_line_pointer
;
2151 while (is_a_char (c
= next_char_of_string ()))
2153 c
= *input_line_pointer
;
2154 *input_line_pointer
= '\0';
2155 *(input_line_pointer
- 1) = '\0';
2156 *input_line_pointer
= c
;
2158 /* Create the .note section. */
2159 note_secp
= subseg_new (".note", 0);
2160 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2161 record_alignment (note_secp
, 2);
2163 /* Process the version string. */
2164 len
= strlen (name
) + 1;
2166 /* PR 3456: Although the name field is padded out to an 4-byte
2167 boundary, the namesz field should not be adjusted. */
2168 i_note
.namesz
= len
;
2169 i_note
.descsz
= 0; /* No description. */
2170 i_note
.type
= NT_VERSION
;
2171 p
= frag_more (sizeof (e_note
.namesz
));
2172 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2173 p
= frag_more (sizeof (e_note
.descsz
));
2174 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2175 p
= frag_more (sizeof (e_note
.type
));
2176 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2177 p
= frag_more (len
);
2178 memcpy (p
, name
, len
);
2180 frag_align (2, 0, 0);
2182 subseg_set (seg
, subseg
);
2185 as_bad (_("expected quoted string"));
2187 demand_empty_rest_of_line ();
2191 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2194 char c
= get_symbol_name (&name
);
2199 p
= input_line_pointer
;
2201 SKIP_WHITESPACE_AFTER_NAME ();
2202 if (*input_line_pointer
!= ',')
2205 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2207 ignore_rest_of_line ();
2210 input_line_pointer
++;
2212 if (exp
.X_op
== O_absent
)
2214 as_bad (_("missing expression in .size directive"));
2215 exp
.X_op
= O_constant
;
2216 exp
.X_add_number
= 0;
2219 sym
= symbol_find_or_make (name
);
2221 if (exp
.X_op
== O_constant
)
2223 S_SET_SIZE (sym
, exp
.X_add_number
);
2224 xfree (symbol_get_obj (sym
)->size
);
2225 symbol_get_obj (sym
)->size
= NULL
;
2229 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2230 *symbol_get_obj (sym
)->size
= exp
;
2232 demand_empty_rest_of_line ();
2235 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2236 There are six syntaxes:
2238 The first (used on Solaris) is
2240 The second (used on UnixWare) is
2242 The third (reportedly to be used on Irix 6.0) is
2244 The fourth (used on NetBSD/Arm and Linux/ARM) is
2246 The fifth (used on SVR4/860) is
2247 .type SYM,"function"
2248 The sixth (emitted by recent SunPRO under Solaris) is
2250 where the integer is the STT_* value.
2254 obj_elf_type_name (char *cp
)
2258 p
= input_line_pointer
;
2259 if (*input_line_pointer
>= '0'
2260 && *input_line_pointer
<= '9')
2262 while (*input_line_pointer
>= '0'
2263 && *input_line_pointer
<= '9')
2264 ++input_line_pointer
;
2265 *cp
= *input_line_pointer
;
2266 *input_line_pointer
= '\0';
2269 *cp
= get_symbol_name (&p
);
2275 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2279 const char *type_name
;
2281 elf_symbol_type
*elfsym
;
2283 sym
= get_sym_from_input_line_and_check ();
2284 c
= *input_line_pointer
;
2285 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2287 if (*input_line_pointer
== ',')
2288 ++input_line_pointer
;
2291 if ( *input_line_pointer
== '#'
2292 || *input_line_pointer
== '@'
2293 || *input_line_pointer
== '"'
2294 || *input_line_pointer
== '%')
2295 ++input_line_pointer
;
2297 type_name
= obj_elf_type_name (& c
);
2300 if (strcmp (type_name
, "function") == 0
2301 || strcmp (type_name
, "2") == 0
2302 || strcmp (type_name
, "STT_FUNC") == 0)
2303 type
= BSF_FUNCTION
;
2304 else if (strcmp (type_name
, "object") == 0
2305 || strcmp (type_name
, "1") == 0
2306 || strcmp (type_name
, "STT_OBJECT") == 0)
2308 else if (strcmp (type_name
, "tls_object") == 0
2309 || strcmp (type_name
, "6") == 0
2310 || strcmp (type_name
, "STT_TLS") == 0)
2311 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2312 else if (strcmp (type_name
, "notype") == 0
2313 || strcmp (type_name
, "0") == 0
2314 || strcmp (type_name
, "STT_NOTYPE") == 0)
2316 else if (strcmp (type_name
, "common") == 0
2317 || strcmp (type_name
, "5") == 0
2318 || strcmp (type_name
, "STT_COMMON") == 0)
2322 if (! S_IS_COMMON (sym
))
2324 if (S_IS_VOLATILE (sym
))
2326 sym
= symbol_clone (sym
, 1);
2327 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2328 S_SET_VALUE (sym
, 0);
2329 S_SET_EXTERNAL (sym
);
2330 symbol_set_frag (sym
, &zero_address_frag
);
2331 S_CLEAR_VOLATILE (sym
);
2333 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2334 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2337 /* FIXME: Is it safe to just change the section ? */
2338 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2339 S_SET_VALUE (sym
, 0);
2340 S_SET_EXTERNAL (sym
);
2344 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2345 || strcmp (type_name
, "10") == 0
2346 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2348 struct elf_backend_data
*bed
;
2350 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2351 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2352 bed
->elf_osabi
= ELFOSABI_GNU
;
2353 else if (bed
->elf_osabi
!= ELFOSABI_GNU
2354 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2355 as_bad (_("symbol type \"%s\" is supported only by GNU "
2356 "and FreeBSD targets"), type_name
);
2357 /* MIPS targets do not support IFUNCS. */
2358 else if (bed
->target_id
== MIPS_ELF_DATA
)
2359 as_bad (_("symbol type \"%s\" is not supported by "
2360 "MIPS targets"), type_name
);
2361 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2362 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2364 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2366 struct elf_backend_data
*bed
;
2368 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2369 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2370 bed
->elf_osabi
= ELFOSABI_GNU
;
2371 else if (bed
->elf_osabi
!= ELFOSABI_GNU
)
2372 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2374 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2375 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2377 #ifdef md_elf_symbol_type
2378 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2382 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2384 *input_line_pointer
= c
;
2386 if (*input_line_pointer
== '"')
2387 ++input_line_pointer
;
2389 #ifdef md_elf_symbol_type_change
2390 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2393 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2395 if (type
!= BSF_FUNCTION
)
2396 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2397 if (type
!= BSF_OBJECT
)
2399 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2401 if (S_IS_COMMON (sym
))
2403 as_bad (_("cannot change type of common symbol '%s'"),
2409 /* Don't warn when changing to STT_NOTYPE. */
2412 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2414 if (new != (elfsym
->symbol
.flags
| type
))
2415 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2416 elfsym
->symbol
.flags
= new;
2419 elfsym
->symbol
.flags
&= ~mask
;
2422 demand_empty_rest_of_line ();
2426 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2428 static segT comment_section
;
2429 segT old_section
= now_seg
;
2430 int old_subsection
= now_subseg
;
2432 #ifdef md_flush_pending_output
2433 md_flush_pending_output ();
2436 if (!comment_section
)
2439 comment_section
= subseg_new (".comment", 0);
2440 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2441 | SEC_MERGE
| SEC_STRINGS
));
2442 comment_section
->entsize
= 1;
2443 #ifdef md_elf_section_change_hook
2444 md_elf_section_change_hook ();
2450 subseg_set (comment_section
, 0);
2452 subseg_set (old_section
, old_subsection
);
2455 #ifdef INIT_STAB_SECTION
2457 /* The first entry in a .stabs section is special. */
2460 obj_elf_init_stab_section (segT seg
)
2465 unsigned int stroff
;
2467 /* Force the section to align to a longword boundary. Without this,
2468 UnixWare ar crashes. */
2469 bfd_set_section_alignment (seg
, 2);
2471 /* Make space for this first symbol. */
2475 file
= remap_debug_filename (as_where (NULL
));
2476 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2477 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
2478 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2479 md_number_to_chars (p
, stroff
, 4);
2480 seg_info (seg
)->stabu
.p
= p
;
2481 xfree ((char *) file
);
2486 /* Fill in the counts in the first entry in a .stabs section. */
2489 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2496 if (strncmp (".stab", sec
->name
, 5))
2498 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2501 name
= concat (sec
->name
, "str", NULL
);
2502 strsec
= bfd_get_section_by_name (abfd
, name
);
2504 strsz
= bfd_section_size (strsec
);
2507 nsyms
= bfd_section_size (sec
) / 12 - 1;
2509 p
= seg_info (sec
)->stabu
.p
;
2510 gas_assert (p
!= 0);
2512 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2513 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2517 #ifdef NEED_ECOFF_DEBUG
2519 /* This function is called by the ECOFF code. It is supposed to
2520 record the external symbol information so that the backend can
2521 write it out correctly. The ELF backend doesn't actually handle
2522 this at the moment, so we do it ourselves. We save the information
2525 #ifdef OBJ_MAYBE_ELF
2529 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2531 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2534 /* This function is called by bfd_ecoff_debug_externals. It is
2535 supposed to *EXT to the external symbol information, and return
2536 whether the symbol should be used at all. */
2539 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2541 if (sym
->udata
.p
== NULL
)
2543 *ext
= *(EXTR
*) sym
->udata
.p
;
2547 /* This function is called by bfd_ecoff_debug_externals. It has
2548 nothing to do for ELF. */
2551 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2552 bfd_size_type indx ATTRIBUTE_UNUSED
)
2556 #endif /* NEED_ECOFF_DEBUG */
2559 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2561 struct elf_obj_sy
*sy_obj
;
2563 struct elf_versioned_name_list
*versioned_name
;
2565 #ifdef NEED_ECOFF_DEBUG
2566 if (ECOFF_DEBUGGING
)
2567 ecoff_frob_symbol (symp
);
2570 sy_obj
= symbol_get_obj (symp
);
2572 size
= sy_obj
->size
;
2575 if (resolve_expression (size
)
2576 && size
->X_op
== O_constant
)
2577 S_SET_SIZE (symp
, size
->X_add_number
);
2580 if (!flag_allow_nonconst_size
)
2581 as_bad (_(".size expression for %s "
2582 "does not evaluate to a constant"), S_GET_NAME (symp
));
2584 as_warn (_(".size expression for %s "
2585 "does not evaluate to a constant"), S_GET_NAME (symp
));
2587 free (sy_obj
->size
);
2588 sy_obj
->size
= NULL
;
2591 versioned_name
= sy_obj
->versioned_name
;
2594 /* This symbol was given a new name with the .symver directive.
2595 If this is an external reference, just rename the symbol to
2596 include the version string. This will make the relocs be
2597 against the correct versioned symbol. */
2599 /* We will have already reported an version error. */
2600 if (sy_obj
->bad_version
)
2602 /* elf_frob_file_before_adjust only allows one version symbol for
2604 else if (sy_obj
->rename
)
2605 S_SET_NAME (symp
, versioned_name
->name
);
2606 else if (S_IS_COMMON (symp
))
2608 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2609 versioned_name
->name
, S_GET_NAME (symp
));
2615 elf_symbol_type
*elfsym
;
2617 /* This is a definition. Add an alias for each version.
2618 FIXME: Using an alias will permit the debugging information
2619 to refer to the right symbol. However, it's not clear
2620 whether it is the best approach. */
2622 /* FIXME: Creating a new symbol here is risky. We're
2623 in the final loop over the symbol table. We can
2624 get away with it only because the symbol goes to
2625 the end of the list, where the loop will still see
2626 it. It would probably be better to do this in
2627 obj_frob_file_before_adjust. */
2628 for (; versioned_name
!= NULL
;
2629 versioned_name
= versioned_name
->next
)
2631 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2633 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2635 /* Subtracting out the frag address here is a hack
2636 because we are in the middle of the final loop. */
2639 - (symbol_get_frag (symp
)->fr_address
2640 / OCTETS_PER_BYTE
)));
2642 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2644 /* This will copy over the size information. */
2645 copy_symbol_attributes (symp2
, symp
);
2647 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2649 if (S_IS_WEAK (symp
))
2652 if (S_IS_EXTERNAL (symp
))
2653 S_SET_EXTERNAL (symp2
);
2656 switch (symbol_get_obj (symp
)->visibility
)
2658 case visibility_unchanged
:
2660 case visibility_hidden
:
2661 bfdsym
= symbol_get_bfdsym (symp
);
2662 elfsym
= elf_symbol_from (bfdsym
);
2663 elfsym
->internal_elf_sym
.st_other
&= ~3;
2664 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2666 case visibility_remove
:
2667 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2669 case visibility_local
:
2670 S_CLEAR_EXTERNAL (symp
);
2676 /* Double check weak symbols. */
2677 if (S_IS_WEAK (symp
))
2679 if (S_IS_COMMON (symp
))
2680 as_bad (_("symbol `%s' can not be both weak and common"),
2687 asection
**head
; /* Section lists. */
2688 unsigned int num_group
; /* Number of lists. */
2689 htab_t indexes
; /* Maps group name to index in head array. */
2692 static struct group_list groups
;
2694 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2695 add it to a list of sections belonging to the group. INF is a
2696 pointer to a struct group_list, which is where we store the head of
2697 each list. If its link_to_symbol_name isn't NULL, set up its
2698 linked-to section. */
2701 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2702 asection
*sec
, void *inf
)
2704 struct group_list
*list
= (struct group_list
*) inf
;
2705 const char *group_name
= elf_group_name (sec
);
2707 unsigned int *elem_idx
;
2708 unsigned int *idx_ptr
;
2710 if (sec
->map_head
.linked_to_symbol_name
)
2712 symbolS
*linked_to_sym
;
2713 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2714 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2715 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2716 sec
->map_head
.linked_to_symbol_name
,
2717 bfd_section_name (sec
));
2719 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2722 if (group_name
== NULL
)
2725 /* If this group already has a list, add the section to the head of
2727 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2728 if (elem_idx
!= NULL
)
2730 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2731 list
->head
[*elem_idx
] = sec
;
2735 /* New group. Make the arrays bigger in chunks to minimize calls to
2737 i
= list
->num_group
;
2740 unsigned int newsize
= i
+ 128;
2741 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2743 list
->head
[i
] = sec
;
2744 list
->num_group
+= 1;
2746 /* Add index to hash. */
2747 idx_ptr
= XNEW (unsigned int);
2749 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2753 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2755 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2756 free ((char *)tuple
->value
);
2760 /* Create symbols for group signature. */
2763 elf_adjust_symtab (void)
2767 /* Go find section groups. */
2768 groups
.num_group
= 0;
2770 groups
.indexes
= str_htab_create ();
2771 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2774 /* Make the SHT_GROUP sections that describe each section group. We
2775 can't set up the section contents here yet, because elf section
2776 indices have yet to be calculated. elf.c:set_group_contents does
2777 the rest of the work. */
2778 for (i
= 0; i
< groups
.num_group
; i
++)
2780 const char *group_name
= elf_group_name (groups
.head
[i
]);
2781 const char *sec_name
;
2786 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2787 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2788 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2790 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2791 if (s
!= groups
.head
[i
])
2793 as_warn (_("assuming all members of group `%s' are COMDAT"),
2799 sec_name
= ".group";
2800 s
= subseg_force_new (sec_name
, 0);
2802 || !bfd_set_section_flags (s
, flags
)
2803 || !bfd_set_section_alignment (s
, 2))
2805 as_fatal (_("can't create group: %s"),
2806 bfd_errmsg (bfd_get_error ()));
2808 elf_section_type (s
) = SHT_GROUP
;
2810 /* Pass a pointer to the first section in this group. */
2811 elf_next_in_group (s
) = groups
.head
[i
];
2812 elf_sec_group (groups
.head
[i
]) = s
;
2813 /* Make sure that the signature symbol for the group has the
2814 name of the group. */
2815 sy
= symbol_find_exact (group_name
);
2816 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2818 /* Create the symbol now. */
2819 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2821 /* Before Solaris 11 build 154, Sun ld rejects local group
2822 signature symbols, so make them weak hidden instead. */
2823 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2824 S_SET_OTHER (sy
, STV_HIDDEN
);
2826 symbol_get_obj (sy
)->local
= 1;
2828 symbol_table_insert (sy
);
2830 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2835 elf_frob_file (void)
2837 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2839 #ifdef elf_tc_final_processing
2840 elf_tc_final_processing ();
2844 /* It removes any unneeded versioned symbols from the symbol table. */
2847 elf_frob_file_before_adjust (void)
2853 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2855 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2856 int is_defined
= !!S_IS_DEFINED (symp
);
2858 if (sy_obj
->versioned_name
)
2860 char *p
= strchr (sy_obj
->versioned_name
->name
,
2865 /* The @@@ syntax is a special case. If the symbol is
2866 not defined, 2 `@'s will be removed from the
2867 versioned_name. Otherwise, 1 `@' will be removed. */
2868 size_t l
= strlen (&p
[3]) + 1;
2869 memmove (&p
[1 + is_defined
], &p
[3], l
);
2874 /* Verify that the name isn't using the @@ syntax--this
2875 is reserved for definitions of the default version
2877 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2879 as_bad (_("invalid attempt to declare external "
2880 "version name as default in symbol `%s'"),
2881 sy_obj
->versioned_name
->name
);
2885 /* Only one version symbol is allowed for undefined
2887 if (sy_obj
->versioned_name
->next
)
2889 as_bad (_("multiple versions [`%s'|`%s'] for "
2891 sy_obj
->versioned_name
->name
,
2892 sy_obj
->versioned_name
->next
->name
,
2897 sy_obj
->rename
= TRUE
;
2901 /* If there was .symver or .weak, but symbol was neither
2902 defined nor used anywhere, remove it. */
2904 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2905 && symbol_used_p (symp
) == 0
2906 && symbol_used_in_reloc_p (symp
) == 0)
2907 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2912 /* It is required that we let write_relocs have the opportunity to
2913 optimize away fixups before output has begun, since it is possible
2914 to eliminate all fixups for a section and thus we never should
2915 have generated the relocation section. */
2918 elf_frob_file_after_relocs (void)
2922 /* Set SHT_GROUP section size. */
2923 for (i
= 0; i
< groups
.num_group
; i
++)
2925 asection
*s
, *head
, *group
;
2928 head
= groups
.head
[i
];
2930 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2931 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2933 group
= elf_sec_group (head
);
2934 subseg_set (group
, 0);
2935 bfd_set_section_size (group
, size
);
2936 group
->contents
= (unsigned char *) frag_more (size
);
2937 frag_now
->fr_fix
= frag_now_fix_octets ();
2938 frag_wane (frag_now
);
2942 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2943 htab_delete (groups
.indexes
);
2945 #ifdef NEED_ECOFF_DEBUG
2946 if (ECOFF_DEBUGGING
)
2947 /* Generate the ECOFF debugging information. */
2949 const struct ecoff_debug_swap
*debug_swap
;
2950 struct ecoff_debug_info debug
;
2955 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2956 know (debug_swap
!= NULL
);
2957 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2959 /* Set up the pointers in debug. */
2960 #define SET(ptr, offset, type) \
2961 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2963 SET (line
, cbLineOffset
, unsigned char *);
2964 SET (external_dnr
, cbDnOffset
, void *);
2965 SET (external_pdr
, cbPdOffset
, void *);
2966 SET (external_sym
, cbSymOffset
, void *);
2967 SET (external_opt
, cbOptOffset
, void *);
2968 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2969 SET (ss
, cbSsOffset
, char *);
2970 SET (external_fdr
, cbFdOffset
, void *);
2971 SET (external_rfd
, cbRfdOffset
, void *);
2972 /* ssext and external_ext are set up just below. */
2976 /* Set up the external symbols. */
2977 debug
.ssext
= debug
.ssext_end
= NULL
;
2978 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2979 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2980 elf_get_extr
, elf_set_index
))
2981 as_fatal (_("failed to set up debugging information: %s"),
2982 bfd_errmsg (bfd_get_error ()));
2984 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2985 gas_assert (sec
!= NULL
);
2987 know (!stdoutput
->output_has_begun
);
2989 /* We set the size of the section, call bfd_set_section_contents
2990 to force the ELF backend to allocate a file position, and then
2991 write out the data. FIXME: Is this really the best way to do
2993 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
2996 /* Pass BUF to bfd_set_section_contents because this will
2997 eventually become a call to fwrite, and ISO C prohibits
2998 passing a NULL pointer to a stdio function even if the
2999 pointer will not be used. */
3000 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3001 as_fatal (_("can't start writing .mdebug section: %s"),
3002 bfd_errmsg (bfd_get_error ()));
3004 know (stdoutput
->output_has_begun
);
3005 know (sec
->filepos
!= 0);
3007 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3009 as_fatal (_("could not write .mdebug section: %s"),
3010 bfd_errmsg (bfd_get_error ()));
3012 #endif /* NEED_ECOFF_DEBUG */
3016 elf_generate_asm_lineno (void)
3018 #ifdef NEED_ECOFF_DEBUG
3019 if (ECOFF_DEBUGGING
)
3020 ecoff_generate_asm_lineno ();
3025 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
3026 int what ATTRIBUTE_UNUSED
,
3027 const char *string ATTRIBUTE_UNUSED
,
3028 int type ATTRIBUTE_UNUSED
,
3029 int other ATTRIBUTE_UNUSED
,
3030 int desc ATTRIBUTE_UNUSED
)
3032 #ifdef NEED_ECOFF_DEBUG
3033 if (ECOFF_DEBUGGING
)
3034 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3039 elf_separate_stab_sections (void)
3041 #ifdef NEED_ECOFF_DEBUG
3042 return (!ECOFF_DEBUGGING
);
3049 elf_init_stab_section (segT seg
)
3051 #ifdef NEED_ECOFF_DEBUG
3052 if (!ECOFF_DEBUGGING
)
3054 obj_elf_init_stab_section (seg
);
3057 const struct format_ops elf_format_ops
=
3059 bfd_target_elf_flavour
,
3060 0, /* dfl_leading_underscore */
3061 1, /* emit_section_symbols */
3066 elf_frob_file_before_adjust
,
3067 0, /* obj_frob_file_before_fix */
3068 elf_frob_file_after_relocs
,
3069 elf_s_get_size
, elf_s_set_size
,
3070 elf_s_get_align
, elf_s_set_align
,
3077 elf_copy_symbol_attributes
,
3078 elf_generate_asm_lineno
,
3080 elf_separate_stab_sections
,
3081 elf_init_stab_section
,
3082 elf_sec_sym_ok_for_reloc
,
3084 #ifdef NEED_ECOFF_DEBUG
3087 0, /* ecoff_set_ext */
3089 elf_obj_read_begin_hook
,
3090 elf_obj_symbol_new_hook
,