1 /* ELF object file format
2 Copyright (C) 1992-2021 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 3,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 #define OBJ_HEADER "obj-elf.h"
23 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
28 #ifndef ECOFF_DEBUGGING
29 #define ECOFF_DEBUGGING 0
31 #define NEED_ECOFF_DEBUG
34 #ifdef NEED_ECOFF_DEBUG
36 #include "bfd/ecoff-bfd.h"
40 #include "elf/alpha.h"
52 #include "elf/x86-64.h"
60 #include "elf/nios2.h"
67 static void obj_elf_line (int);
68 static void obj_elf_size (int);
69 static void obj_elf_type (int);
70 static void obj_elf_ident (int);
71 static void obj_elf_weak (int);
72 static void obj_elf_local (int);
73 static void obj_elf_visibility (int);
74 static void obj_elf_symver (int);
75 static void obj_elf_subsection (int);
76 static void obj_elf_popsection (int);
77 static void obj_elf_gnu_attribute (int);
78 static void obj_elf_tls_common (int);
79 static void obj_elf_lcomm (int);
80 static void obj_elf_struct (int);
81 static void obj_elf_attach_to_group (int);
83 static const pseudo_typeS elf_pseudo_table
[] =
85 {"attach_to_group", obj_elf_attach_to_group
, 0},
86 {"comm", obj_elf_common
, 0},
87 {"common", obj_elf_common
, 1},
88 {"ident", obj_elf_ident
, 0},
89 {"lcomm", obj_elf_lcomm
, 0},
90 {"local", obj_elf_local
, 0},
91 {"previous", obj_elf_previous
, 0},
92 {"section", obj_elf_section
, 0},
93 {"section.s", obj_elf_section
, 0},
94 {"sect", obj_elf_section
, 0},
95 {"sect.s", obj_elf_section
, 0},
96 {"pushsection", obj_elf_section
, 1},
97 {"popsection", obj_elf_popsection
, 0},
98 {"size", obj_elf_size
, 0},
99 {"type", obj_elf_type
, 0},
100 {"version", obj_elf_version
, 0},
101 {"weak", obj_elf_weak
, 0},
103 /* These define symbol visibility. */
104 {"internal", obj_elf_visibility
, STV_INTERNAL
},
105 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
106 {"protected", obj_elf_visibility
, STV_PROTECTED
},
108 /* These are used for stabs-in-elf configurations. */
109 {"line", obj_elf_line
, 0},
111 /* This is a GNU extension to handle symbol versions. */
112 {"symver", obj_elf_symver
, 0},
114 /* A GNU extension to change subsection only. */
115 {"subsection", obj_elf_subsection
, 0},
117 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
118 {"vtable_inherit", obj_elf_vtable_inherit
, 0},
119 {"vtable_entry", obj_elf_vtable_entry
, 0},
121 /* A GNU extension for object attributes. */
122 {"gnu_attribute", obj_elf_gnu_attribute
, 0},
124 /* These are used for dwarf2. */
125 { "file", dwarf2_directive_file
, 0 },
126 { "loc", dwarf2_directive_loc
, 0 },
127 { "loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0 },
129 /* We need to trap the section changing calls to handle .previous. */
130 {"data", obj_elf_data
, 0},
131 {"offset", obj_elf_struct
, 0},
132 {"struct", obj_elf_struct
, 0},
133 {"text", obj_elf_text
, 0},
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 /* This is called when the assembler starts. */
193 asection
*elf_com_section_ptr
;
200 /* Add symbols for the known sections to the symbol table. */
201 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
202 symbol_table_insert (section_symbol (s
));
203 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
204 symbol_table_insert (section_symbol (s
));
205 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
206 symbol_table_insert (section_symbol (s
));
207 elf_com_section_ptr
= bfd_com_section_ptr
;
211 elf_pop_insert (void)
213 pop_insert (elf_pseudo_table
);
215 pop_insert (ecoff_debug_pseudo_table
);
219 elf_s_get_size (symbolS
*sym
)
221 return S_GET_SIZE (sym
);
225 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
227 S_SET_SIZE (sym
, sz
);
231 elf_s_get_align (symbolS
*sym
)
233 return S_GET_ALIGN (sym
);
237 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
239 S_SET_ALIGN (sym
, align
);
243 elf_s_get_other (symbolS
*sym
)
245 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
249 elf_s_set_other (symbolS
*sym
, int other
)
251 S_SET_OTHER (sym
, other
);
255 elf_sec_sym_ok_for_reloc (asection
*sec
)
257 return obj_sec_sym_ok_for_reloc (sec
);
261 elf_file_symbol (const char *s
, int appfile
)
266 || symbol_rootP
== NULL
267 || (bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
268 || (bsym
->flags
& BSF_FILE
) == 0)
273 sym
= symbol_new (s
, absolute_section
, &zero_address_frag
, 0);
275 name_length
= strlen (s
);
276 if (name_length
> strlen (S_GET_NAME (sym
)))
278 obstack_grow (¬es
, s
, name_length
+ 1);
279 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
282 strcpy ((char *) S_GET_NAME (sym
), s
);
284 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
286 if (symbol_rootP
!= sym
287 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
288 || (bsym
->flags
& BSF_FILE
) == 0))
290 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
291 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
295 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
299 #ifdef NEED_ECOFF_DEBUG
300 ecoff_new_file (s
, appfile
);
304 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
305 Parse a possible alignment value. */
308 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
311 int is_local
= symbol_get_obj (symbolP
)->local
;
313 if (*input_line_pointer
== ',')
315 char *save
= input_line_pointer
;
317 input_line_pointer
++;
320 if (*input_line_pointer
== '"')
322 /* For sparc. Accept .common symbol, length, "bss" */
323 input_line_pointer
++;
324 /* Some use the dot, some don't. */
325 if (*input_line_pointer
== '.')
326 input_line_pointer
++;
327 /* Some say data, some say bss. */
328 if (startswith (input_line_pointer
, "bss\""))
329 input_line_pointer
+= 4;
330 else if (startswith (input_line_pointer
, "data\""))
331 input_line_pointer
+= 5;
334 char *p
= input_line_pointer
;
339 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
340 if (*input_line_pointer
++ == '"')
342 c
= *input_line_pointer
;
343 *input_line_pointer
= '\0';
344 as_bad (_("bad .common segment %s"), p
);
345 *input_line_pointer
= c
;
346 ignore_rest_of_line ();
349 /* ??? Don't ask me why these are always global. */
354 input_line_pointer
= save
;
355 align
= parse_align (is_local
);
356 if (align
== (addressT
) -1)
363 bss_alloc (symbolP
, size
, align
);
364 S_CLEAR_EXTERNAL (symbolP
);
368 S_SET_VALUE (symbolP
, size
);
369 S_SET_ALIGN (symbolP
, align
);
370 S_SET_EXTERNAL (symbolP
);
371 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
374 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
380 obj_elf_common (int is_common
)
382 if (flag_mri
&& is_common
)
385 s_comm_internal (0, elf_common_parse
);
389 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
391 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
394 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
398 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
400 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
403 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
407 get_sym_from_input_line_and_check (void)
413 c
= get_symbol_name (& name
);
414 sym
= symbol_find_or_make (name
);
415 *input_line_pointer
= c
;
416 SKIP_WHITESPACE_AFTER_NAME ();
418 /* There is no symbol name if input_line_pointer has not moved. */
419 if (name
== input_line_pointer
)
420 as_bad (_("Missing symbol name in directive"));
425 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
432 symbolP
= get_sym_from_input_line_and_check ();
433 c
= *input_line_pointer
;
434 S_CLEAR_EXTERNAL (symbolP
);
435 symbol_get_obj (symbolP
)->local
= 1;
438 input_line_pointer
++;
440 if (*input_line_pointer
== '\n')
445 demand_empty_rest_of_line ();
449 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
456 symbolP
= get_sym_from_input_line_and_check ();
457 c
= *input_line_pointer
;
458 S_SET_WEAK (symbolP
);
461 input_line_pointer
++;
463 if (*input_line_pointer
== '\n')
468 demand_empty_rest_of_line ();
472 obj_elf_visibility (int visibility
)
477 elf_symbol_type
*elfsym
;
481 symbolP
= get_sym_from_input_line_and_check ();
483 bfdsym
= symbol_get_bfdsym (symbolP
);
484 elfsym
= elf_symbol_from (bfdsym
);
488 elfsym
->internal_elf_sym
.st_other
&= ~3;
489 elfsym
->internal_elf_sym
.st_other
|= visibility
;
491 c
= *input_line_pointer
;
494 input_line_pointer
++;
498 if (*input_line_pointer
== '\n')
504 demand_empty_rest_of_line ();
507 static segT previous_section
;
508 static int previous_subsection
;
512 struct section_stack
*next
;
514 int subseg
, prev_subseg
;
517 static struct section_stack
*section_stack
;
519 /* ELF section flags for unique sections. */
520 #define SEC_ASSEMBLER_SHF_MASK SHF_GNU_RETAIN
522 /* Return TRUE iff SEC matches the section info INF. */
525 get_section_by_match (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
527 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
528 const char *gname
= match
->group_name
;
529 const char *group_name
= elf_group_name (sec
);
530 const char *linked_to_symbol_name
531 = sec
->map_head
.linked_to_symbol_name
;
532 unsigned int sh_info
= elf_section_data (sec
)->this_hdr
.sh_info
;
533 bfd_vma sh_flags
= (elf_section_data (sec
)->this_hdr
.sh_flags
534 & SEC_ASSEMBLER_SHF_MASK
);
536 return (sh_info
== match
->sh_info
537 && sh_flags
== match
->sh_flags
538 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
539 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
540 && sec
->section_id
== match
->section_id
541 && (group_name
== gname
542 || (group_name
!= NULL
544 && strcmp (group_name
, gname
) == 0))
545 && (linked_to_symbol_name
== match
->linked_to_symbol_name
546 || (linked_to_symbol_name
!= NULL
547 && match
->linked_to_symbol_name
!= NULL
548 && strcmp (linked_to_symbol_name
,
549 match
->linked_to_symbol_name
) == 0)));
552 /* Handle the .section pseudo-op. This code supports two different
555 The first is found on Solaris, and looks like
556 .section ".sec1",#alloc,#execinstr,#write
557 Here the names after '#' are the SHF_* flags to turn on for the
558 section. I'm not sure how it determines the SHT_* type (BFD
559 doesn't really give us control over the type, anyhow).
561 The second format is found on UnixWare, and probably most SVR4
562 machines, and looks like
563 .section .sec1,"a",@progbits
564 The quoted string may contain any combination of a, w, x, and
565 represents the SHF_* flags to turn on for the section. The string
566 beginning with '@' can be progbits or nobits. There should be
567 other possibilities, but I don't know what they are. In any case,
568 BFD doesn't really let us set the section type. */
571 obj_elf_change_section (const char *name
,
575 struct elf_section_match
*match_p
,
582 const struct elf_backend_data
*bed
;
583 const struct bfd_elf_special_section
*ssect
;
587 static struct elf_section_match unused_match
;
588 match_p
= &unused_match
;
591 #ifdef md_flush_pending_output
592 md_flush_pending_output ();
595 /* Switch to the section, creating it if necessary. */
598 struct section_stack
*elt
;
599 elt
= XNEW (struct section_stack
);
600 elt
->next
= section_stack
;
602 elt
->prev_seg
= previous_section
;
603 elt
->subseg
= now_subseg
;
604 elt
->prev_subseg
= previous_subsection
;
608 obj_elf_section_change_hook ();
610 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section_by_match
,
618 sec
= subseg_force_new (name
, 0);
620 bed
= get_elf_backend_data (stdoutput
);
621 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
625 bool override
= false;
627 if (type
== SHT_NULL
)
629 else if (type
!= ssect
->type
)
632 /* Some older versions of gcc will emit
634 .section .init_array,"aw",@progbits
636 for __attribute__ ((section (".init_array"))).
637 "@progbits" is incorrect. Also for x86-64 large bss
638 sections, some older versions of gcc will emit
640 .section .lbss,"aw",@progbits
642 "@progbits" is incorrect. */
644 && (bed
->s
->arch_size
!= 64
645 || !(ssect
->attr
& SHF_X86_64_LARGE
))
647 && ssect
->type
!= SHT_INIT_ARRAY
648 && ssect
->type
!= SHT_FINI_ARRAY
649 && ssect
->type
!= SHT_PREINIT_ARRAY
)
651 /* We allow to specify any type for a .note section. */
652 if (ssect
->type
!= SHT_NOTE
653 /* Processor and application defined types are allowed too. */
654 && type
< SHT_LOPROC
)
655 as_warn (_("setting incorrect section type for %s"),
660 as_warn (_("ignoring incorrect section type for %s"),
666 if (old_sec
== NULL
&& ((attr
& ~(SHF_LINK_ORDER
669 & ~ssect
->attr
) != 0)
671 /* Strip SHF_GNU_RETAIN. */
672 bfd_vma generic_attr
= attr
;
673 if (elf_tdata (stdoutput
)->has_gnu_osabi
)
674 generic_attr
&= ~SHF_GNU_RETAIN
;
676 /* As a GNU extension, we permit a .note section to be
677 allocatable. If the linker sees an allocatable .note
678 section, it will create a PT_NOTE segment in the output
679 file. We also allow "x" for .note.GNU-stack. */
680 if (ssect
->type
== SHT_NOTE
681 && (generic_attr
== SHF_ALLOC
682 || generic_attr
== SHF_EXECINSTR
))
684 /* Allow different SHF_MERGE and SHF_STRINGS if we have
685 something like .rodata.str. */
686 else if (ssect
->suffix_length
== -2
687 && name
[ssect
->prefix_length
] == '.'
691 & ~SHF_STRINGS
) == 0)
693 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
694 else if (generic_attr
== SHF_ALLOC
695 && (strcmp (name
, ".interp") == 0
696 || strcmp (name
, ".strtab") == 0
697 || strcmp (name
, ".symtab") == 0))
699 /* .note.GNU-stack can have SHF_EXECINSTR. */
700 else if (generic_attr
== SHF_EXECINSTR
701 && strcmp (name
, ".note.GNU-stack") == 0)
704 /* A section on Alpha may have SHF_ALPHA_GPREL. */
705 else if ((generic_attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
709 else if (generic_attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
710 && (ssect
->type
== SHT_INIT_ARRAY
711 || ssect
->type
== SHT_FINI_ARRAY
712 || ssect
->type
== SHT_PREINIT_ARRAY
))
713 /* RX init/fini arrays can and should have the "awx" attributes set. */
718 if (match_p
->group_name
== NULL
)
719 as_warn (_("setting incorrect section attributes for %s"),
725 if (!override
&& old_sec
== NULL
)
729 /* Convert ELF type and flags to BFD flags. */
731 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
732 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
733 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
734 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
735 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
736 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
737 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
738 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
739 #ifdef md_elf_section_flags
740 flags
= md_elf_section_flags (flags
, attr
, type
);
744 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
750 if (type
== SHT_NULL
)
751 type
= bfd_elf_get_default_section_type (flags
);
752 elf_section_type (sec
) = type
;
753 elf_section_flags (sec
) = attr
;
754 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->sh_info
;
756 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
757 if (type
== SHT_NOBITS
)
758 seg_info (sec
)->bss
= 1;
760 /* Set the section ID and flags. */
761 sec
->section_id
= match_p
->section_id
;
762 flags
|= match_p
->flags
;
764 /* Set the linked-to symbol name. */
765 sec
->map_head
.linked_to_symbol_name
766 = match_p
->linked_to_symbol_name
;
768 bfd_set_section_flags (sec
, flags
);
769 if (flags
& SEC_MERGE
)
770 sec
->entsize
= entsize
;
771 elf_group_name (sec
) = match_p
->group_name
;
773 /* Add a symbol for this section to the symbol table. */
774 secsym
= symbol_find (name
);
777 /* We could be repurposing an undefined symbol here: make sure we
778 reset sy_value to look like other section symbols in order to avoid
779 trying to incorrectly resolve this section symbol later on. */
780 static const expressionS exp
= { .X_op
= O_constant
};
781 symbol_set_value_expression (secsym
, &exp
);
782 symbol_set_bfdsym (secsym
, sec
->symbol
);
785 symbol_table_insert (section_symbol (sec
));
790 && (unsigned) type
!= elf_section_type (old_sec
))
793 /* This is a special section with known type. User
794 assembly might get the section type wrong; Even high
795 profile projects like glibc have done so in the past.
796 So don't error in this case. */
797 as_warn (_("ignoring changed section type for %s"), name
);
799 /* Do error when assembly isn't self-consistent. */
800 as_bad (_("changed section type for %s"), name
);
805 /* If section attributes are specified the second time we see a
806 particular section, then check that they are the same as we
807 saw the first time. */
808 if (((old_sec
->flags
^ flags
)
809 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
810 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
811 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
812 | SEC_THREAD_LOCAL
)))
815 as_warn (_("ignoring changed section attributes for %s"), name
);
817 as_bad (_("changed section attributes for %s"), name
);
820 /* FIXME: Maybe we should consider removing a previously set
821 processor or application specific attribute as suspicious? */
822 elf_section_flags (sec
) = attr
;
824 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
825 as_bad (_("changed section entity size for %s"), name
);
829 #ifdef md_elf_section_change_hook
830 md_elf_section_change_hook ();
835 obj_elf_parse_section_letters (char *str
, size_t len
,
836 bool *is_clone
, bfd_vma
*gnu_attr
)
852 attr
|= SHF_LINK_ORDER
;
858 attr
|= SHF_EXECINSTR
;
873 *gnu_attr
|= SHF_GNU_MBIND
;
876 *gnu_attr
|= SHF_GNU_RETAIN
;
883 if (*(str
- 1) == 'a')
886 if (len
> 1 && str
[1] == 's')
896 const char *bad_msg
= _("unrecognized .section attribute:"
897 " want a,e,o,w,x,M,S,G,T or number");
898 #ifdef md_elf_section_letter
899 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
900 if (md_attr
!= (bfd_vma
) -1)
907 struct elf_backend_data
*bed
;
908 bfd_vma numeric_flags
= strtoul (str
, &end
, 0);
910 attr
|= numeric_flags
;
912 bed
= (struct elf_backend_data
*)
913 get_elf_backend_data (stdoutput
);
915 if (bed
->elf_osabi
== ELFOSABI_NONE
916 || bed
->elf_osabi
== ELFOSABI_STANDALONE
917 || bed
->elf_osabi
== ELFOSABI_GNU
918 || bed
->elf_osabi
== ELFOSABI_FREEBSD
)
920 /* Add flags in the SHF_MASKOS range to gnu_attr for
921 OSABIs that support those flags.
922 Also adding the flags for ELFOSABI_{NONE,STANDALONE}
923 allows them to be validated later in obj_elf_section.
924 We can't just always set these bits in gnu_attr for
925 all OSABIs, since Binutils does not recognize all
926 SHF_MASKOS bits for non-GNU OSABIs. It's therefore
927 possible that numeric flags are being used to set bits
928 in the SHF_MASKOS range for those targets, and we
929 don't want assembly to fail in those situations. */
930 *gnu_attr
|= (numeric_flags
& SHF_MASKOS
);
933 /* Update str and len, allowing for the fact that
934 we will execute str++ and len-- below. */
940 as_fatal ("%s", bad_msg
);
951 obj_elf_section_type (char *str
, size_t len
, bool warn
)
953 if (len
== 8 && startswith (str
, "progbits"))
955 if (len
== 6 && startswith (str
, "nobits"))
957 if (len
== 4 && startswith (str
, "note"))
959 if (len
== 10 && startswith (str
, "init_array"))
960 return SHT_INIT_ARRAY
;
961 if (len
== 10 && startswith (str
, "fini_array"))
962 return SHT_FINI_ARRAY
;
963 if (len
== 13 && startswith (str
, "preinit_array"))
964 return SHT_PREINIT_ARRAY
;
966 #ifdef md_elf_section_type
968 int md_type
= md_elf_section_type (str
, len
);
977 int type
= strtoul (str
, & end
, 0);
979 if (warn
&& (size_t) (end
- str
) != len
)
980 as_warn (_("extraneous characters at end of numeric section type"));
986 as_warn (_("unrecognized section type"));
991 obj_elf_section_word (char *str
, size_t len
, int *type
)
995 if (len
== 5 && startswith (str
, "write"))
997 if (len
== 5 && startswith (str
, "alloc"))
999 if (len
== 9 && startswith (str
, "execinstr"))
1000 return SHF_EXECINSTR
;
1001 if (len
== 7 && startswith (str
, "exclude"))
1003 if (len
== 3 && startswith (str
, "tls"))
1006 #ifdef md_elf_section_word
1008 bfd_vma md_attr
= md_elf_section_word (str
, len
);
1014 ret
= obj_elf_section_type (str
, len
, false);
1018 as_warn (_("unrecognized section attribute"));
1023 /* Get name of section. */
1025 obj_elf_section_name (void)
1030 if (*input_line_pointer
== '"')
1034 name
= demand_copy_C_string (&dummy
);
1037 ignore_rest_of_line ();
1043 char *end
= input_line_pointer
;
1045 while (0 == strchr ("\n\t,; ", *end
))
1047 if (end
== input_line_pointer
)
1049 as_bad (_("missing name"));
1050 ignore_rest_of_line ();
1054 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1056 while (flag_sectname_subst
)
1058 char *subst
= strchr (name
, '%');
1059 if (subst
&& subst
[1] == 'S')
1061 int oldlen
= strlen (name
);
1062 int substlen
= strlen (now_seg
->name
);
1063 int newlen
= oldlen
- 2 + substlen
;
1064 char *newname
= XNEWVEC (char, newlen
+ 1);
1065 int headlen
= subst
- name
;
1066 memcpy (newname
, name
, headlen
);
1067 strcpy (newname
+ headlen
, now_seg
->name
);
1068 strcat (newname
+ headlen
, subst
+ 2);
1076 #ifdef tc_canonicalize_section_name
1077 name
= tc_canonicalize_section_name (name
);
1079 input_line_pointer
= end
;
1086 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1088 const char * gname
= obj_elf_section_name ();
1092 as_warn (_("group name not parseable"));
1096 if (elf_group_name (now_seg
))
1098 as_warn (_("section %s already has a group (%s)"),
1099 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1103 elf_group_name (now_seg
) = xstrdup (gname
);
1104 elf_section_flags (now_seg
) |= SHF_GROUP
;
1108 obj_elf_section (int push
)
1117 subsegT new_subsection
= -1;
1118 struct elf_section_match match
;
1119 unsigned long linked_to_section_index
= -1UL;
1125 #ifdef md_flush_pending_output
1126 md_flush_pending_output ();
1129 obj_elf_section_change_hook ();
1131 s_mri_sect (&mri_type
);
1133 #ifdef md_elf_section_change_hook
1134 md_elf_section_change_hook ();
1140 name
= obj_elf_section_name ();
1144 memset (&match
, 0, sizeof (match
));
1147 if ((sym
= symbol_find (name
)) != NULL
1148 && ! symbol_section_p (sym
)
1149 && S_IS_DEFINED (sym
)
1150 && ! S_IS_VOLATILE (sym
)
1151 && ! S_CAN_BE_REDEFINED (sym
))
1153 as_bad (_("section name '%s' already defined as another symbol"), name
);
1154 ignore_rest_of_line ();
1163 if (*input_line_pointer
== ',')
1165 /* Skip the comma. */
1166 ++input_line_pointer
;
1169 if (push
&& ISDIGIT (*input_line_pointer
))
1171 /* .pushsection has an optional subsection. */
1172 new_subsection
= (subsegT
) get_absolute_expression ();
1176 /* Stop if we don't see a comma. */
1177 if (*input_line_pointer
!= ',')
1180 /* Skip the comma. */
1181 ++input_line_pointer
;
1185 if (*input_line_pointer
== '"')
1189 beg
= demand_copy_C_string (&dummy
);
1192 ignore_rest_of_line ();
1195 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1196 &is_clone
, &gnu_attr
);
1199 if (*input_line_pointer
== ',')
1202 char *save
= input_line_pointer
;
1204 ++input_line_pointer
;
1206 c
= *input_line_pointer
;
1209 beg
= demand_copy_C_string (&dummy
);
1212 ignore_rest_of_line ();
1215 type
= obj_elf_section_type (beg
, strlen (beg
), true);
1217 else if (c
== '@' || c
== '%')
1219 ++input_line_pointer
;
1221 if (ISDIGIT (* input_line_pointer
))
1222 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1225 c
= get_symbol_name (& beg
);
1226 (void) restore_line_pointer (c
);
1227 type
= obj_elf_section_type (beg
,
1228 input_line_pointer
- beg
,
1233 input_line_pointer
= save
;
1237 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1239 ++input_line_pointer
;
1241 entsize
= get_absolute_expression ();
1245 as_warn (_("invalid merge entity size"));
1250 else if ((attr
& SHF_MERGE
) != 0)
1252 as_warn (_("entity size for SHF_MERGE not specified"));
1256 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1258 ++input_line_pointer
;
1260 /* Check for a numeric section index, rather than a symbol name. */
1261 if (ISDIGIT (* input_line_pointer
))
1263 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1268 unsigned int length
;
1270 c
= get_symbol_name (& beg
);
1271 (void) restore_line_pointer (c
);
1272 length
= input_line_pointer
- beg
;
1274 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1278 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1280 as_warn (_("? section flag ignored with G present"));
1284 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1286 ++input_line_pointer
;
1287 match
.group_name
= obj_elf_section_name ();
1288 if (match
.group_name
== NULL
)
1290 else if (*input_line_pointer
== ',')
1292 ++input_line_pointer
;
1294 if (startswith (input_line_pointer
, "comdat"))
1296 input_line_pointer
+= 6;
1300 else if (startswith (name
, ".gnu.linkonce"))
1303 else if ((attr
& SHF_GROUP
) != 0)
1305 as_warn (_("group name for SHF_GROUP not specified"));
1311 const char *now_group
= elf_group_name (now_seg
);
1312 if (now_group
!= NULL
)
1314 match
.group_name
= xstrdup (now_group
);
1315 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1319 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1321 char *save
= input_line_pointer
;
1322 ++input_line_pointer
;
1324 if (ISDIGIT (* input_line_pointer
))
1326 char *t
= input_line_pointer
;
1327 match
.sh_info
= strtoul (input_line_pointer
,
1328 &input_line_pointer
, 0);
1329 if (match
.sh_info
== (unsigned int) -1)
1331 as_warn (_("unsupported mbind section info: %s"), t
);
1336 input_line_pointer
= save
;
1339 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1340 match
.sh_flags
|= SHF_GNU_RETAIN
;
1342 if (*input_line_pointer
== ',')
1344 char *save
= input_line_pointer
;
1346 ++input_line_pointer
;
1348 if (startswith (input_line_pointer
, "unique"))
1350 input_line_pointer
+= 6;
1352 if (*input_line_pointer
== ',')
1354 ++input_line_pointer
;
1356 if (ISDIGIT (* input_line_pointer
))
1360 char *t
= input_line_pointer
;
1361 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1364 id
= strtoul (input_line_pointer
,
1365 &input_line_pointer
, 0);
1366 overflow
= (id
== (unsigned long) -1
1367 && errno
== ERANGE
);
1372 (input_line_pointer
,
1373 (const char **) &input_line_pointer
, 0);
1374 overflow
= id
== ~(bfd_vma
) 0;
1376 if (overflow
|| id
> (unsigned int) -1)
1378 char *linefeed
, saved_char
= 0;
1379 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1381 saved_char
= *linefeed
;
1384 as_bad (_("unsupported section id: %s"), t
);
1386 *linefeed
= saved_char
;
1390 match
.section_id
= id
;
1391 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1397 input_line_pointer
= save
;
1407 if (*input_line_pointer
!= '#')
1409 as_bad (_("character following name is not '#'"));
1410 ignore_rest_of_line ();
1413 ++input_line_pointer
;
1414 c
= get_symbol_name (& beg
);
1415 (void) restore_line_pointer (c
);
1417 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1422 while (*input_line_pointer
++ == ',');
1423 --input_line_pointer
;
1428 demand_empty_rest_of_line ();
1430 if ((gnu_attr
& (SHF_GNU_MBIND
| SHF_GNU_RETAIN
)) != 0)
1432 const struct elf_backend_data
*bed
;
1433 bool mbind_p
= (gnu_attr
& SHF_GNU_MBIND
) != 0;
1435 if (mbind_p
&& (attr
& SHF_ALLOC
) == 0)
1436 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1438 bed
= get_elf_backend_data (stdoutput
);
1440 if (bed
->elf_osabi
!= ELFOSABI_GNU
1441 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
1442 && bed
->elf_osabi
!= ELFOSABI_NONE
)
1443 as_bad (_("%s section is supported only by GNU and FreeBSD targets"),
1444 mbind_p
? "GNU_MBIND" : "GNU_RETAIN");
1448 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1449 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1450 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_retain
;
1456 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1459 if (linked_to_section_index
!= -1UL)
1461 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1462 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1463 /* FIXME: Should we perform some sanity checking on the section index ? */
1466 if (push
&& new_subsection
!= -1)
1467 subseg_set (now_seg
, new_subsection
);
1470 /* Change to the .bss section. */
1473 obj_elf_bss (int i ATTRIBUTE_UNUSED
)
1477 #ifdef md_flush_pending_output
1478 md_flush_pending_output ();
1481 obj_elf_section_change_hook ();
1483 temp
= get_absolute_expression ();
1484 subseg_set (bss_section
, (subsegT
) temp
);
1485 demand_empty_rest_of_line ();
1487 #ifdef md_elf_section_change_hook
1488 md_elf_section_change_hook ();
1492 /* Change to the .data section. */
1495 obj_elf_data (int i
)
1497 #ifdef md_flush_pending_output
1498 md_flush_pending_output ();
1501 obj_elf_section_change_hook ();
1505 #ifdef md_elf_section_change_hook
1506 md_elf_section_change_hook ();
1510 /* Change to the .text section. */
1513 obj_elf_text (int i
)
1515 #ifdef md_flush_pending_output
1516 md_flush_pending_output ();
1519 obj_elf_section_change_hook ();
1523 #ifdef md_elf_section_change_hook
1524 md_elf_section_change_hook ();
1528 /* Change to the *ABS* section. */
1531 obj_elf_struct (int i
)
1533 #ifdef md_flush_pending_output
1534 md_flush_pending_output ();
1537 obj_elf_section_change_hook ();
1541 #ifdef md_elf_section_change_hook
1542 md_elf_section_change_hook ();
1547 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1551 #ifdef md_flush_pending_output
1552 md_flush_pending_output ();
1555 obj_elf_section_change_hook ();
1557 temp
= get_absolute_expression ();
1558 subseg_set (now_seg
, (subsegT
) temp
);
1559 demand_empty_rest_of_line ();
1561 #ifdef md_elf_section_change_hook
1562 md_elf_section_change_hook ();
1566 /* This can be called from the processor backends if they change
1570 obj_elf_section_change_hook (void)
1572 previous_section
= now_seg
;
1573 previous_subsection
= now_subseg
;
1577 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1582 if (previous_section
== 0)
1584 as_warn (_(".previous without corresponding .section; ignored"));
1588 #ifdef md_flush_pending_output
1589 md_flush_pending_output ();
1592 new_section
= previous_section
;
1593 new_subsection
= previous_subsection
;
1594 obj_elf_section_change_hook ();
1596 subseg_set (new_section
, new_subsection
);
1598 #ifdef md_elf_section_change_hook
1599 md_elf_section_change_hook ();
1604 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1606 struct section_stack
*top
= section_stack
;
1610 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1614 #ifdef md_flush_pending_output
1615 md_flush_pending_output ();
1618 section_stack
= top
->next
;
1619 previous_section
= top
->prev_seg
;
1620 previous_subsection
= top
->prev_subseg
;
1621 subseg_set (top
->seg
, top
->subseg
);
1624 #ifdef md_elf_section_change_hook
1625 md_elf_section_change_hook ();
1630 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1632 /* Assume delimiter is part of expression. BSD4.2 as fails with
1633 delightful bug, so we are not being incompatible here. */
1634 new_logical_line (NULL
, get_absolute_expression ());
1635 demand_empty_rest_of_line ();
1638 static struct elf_versioned_name_list
*
1639 obj_elf_find_and_add_versioned_name (const char *version_name
,
1640 const char *sym_name
,
1642 struct elf_obj_sy
*sy_obj
)
1644 struct elf_versioned_name_list
*versioned_name
;
1647 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1650 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1651 names, we have to disable this. */
1652 if (0 && *p
== '\0')
1654 as_bad (_("missing version name in `%s' for symbol `%s'"),
1655 version_name
, sym_name
);
1659 versioned_name
= sy_obj
->versioned_name
;
1669 if (strcmp (versioned_name
->name
, version_name
) == 0)
1670 return versioned_name
;
1673 as_bad (_("only one version name with `@@@' is allowed "
1674 "for symbol `%s'"), sym_name
);
1678 sy_obj
->rename
= true;
1681 as_bad (_("invalid version name '%s' for symbol `%s'"),
1682 version_name
, sym_name
);
1687 versioned_name
!= NULL
;
1688 versioned_name
= versioned_name
->next
)
1689 if (strcmp (versioned_name
->name
, version_name
) == 0)
1690 return versioned_name
;
1692 /* Add this versioned name to the head of the list, */
1693 versioned_name
= (struct elf_versioned_name_list
*)
1694 xmalloc (sizeof (*versioned_name
));
1695 versioned_name
->name
= xstrdup (version_name
);
1696 versioned_name
->next
= sy_obj
->versioned_name
;
1697 sy_obj
->versioned_name
= versioned_name
;
1699 return versioned_name
;
1702 /* This handles the .symver pseudo-op, which is used to specify a
1703 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1704 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1705 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1706 with the same value as the symbol NAME. */
1709 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1712 const char *sym_name
;
1716 struct elf_obj_sy
*sy_obj
;
1719 sym
= get_sym_from_input_line_and_check ();
1721 if (*input_line_pointer
!= ',')
1723 as_bad (_("expected comma after name in .symver"));
1724 ignore_rest_of_line ();
1728 ++input_line_pointer
;
1731 /* Temporarily include '@' in symbol names. */
1732 old_lexat
= lex_type
[(unsigned char) '@'];
1733 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1734 c
= get_symbol_name (& name
);
1735 lex_type
[(unsigned char) '@'] = old_lexat
;
1736 sym_name
= S_GET_NAME (sym
);
1738 if (S_IS_COMMON (sym
))
1740 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1742 ignore_rest_of_line ();
1746 p
= strchr (name
, ELF_VER_CHR
);
1749 as_bad (_("missing version name in `%s' for symbol `%s'"),
1751 ignore_rest_of_line ();
1755 sy_obj
= symbol_get_obj (sym
);
1756 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1759 sy_obj
->bad_version
= true;
1760 ignore_rest_of_line ();
1764 (void) restore_line_pointer (c
);
1766 if (*input_line_pointer
== ',')
1768 char *save
= input_line_pointer
;
1770 ++input_line_pointer
;
1772 if (startswith (input_line_pointer
, "local"))
1774 input_line_pointer
+= 5;
1775 sy_obj
->visibility
= visibility_local
;
1777 else if (startswith (input_line_pointer
, "hidden"))
1779 input_line_pointer
+= 6;
1780 sy_obj
->visibility
= visibility_hidden
;
1782 else if (startswith (input_line_pointer
, "remove"))
1784 input_line_pointer
+= 6;
1785 sy_obj
->visibility
= visibility_remove
;
1788 input_line_pointer
= save
;
1791 demand_empty_rest_of_line ();
1794 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1795 to the linker the hierarchy in which a particular table resides. The
1796 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1799 obj_elf_get_vtable_inherit (void)
1801 char *cname
, *pname
;
1802 symbolS
*csym
, *psym
;
1805 if (*input_line_pointer
== '#')
1806 ++input_line_pointer
;
1808 c
= get_symbol_name (& cname
);
1809 csym
= symbol_find (cname
);
1811 /* GCFIXME: should check that we don't have two .vtable_inherits for
1812 the same child symbol. Also, we can currently only do this if the
1813 child symbol is already exists and is placed in a fragment. */
1815 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1817 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1822 *input_line_pointer
= c
;
1824 SKIP_WHITESPACE_AFTER_NAME ();
1825 if (*input_line_pointer
!= ',')
1827 as_bad (_("expected comma after name in .vtable_inherit"));
1828 ignore_rest_of_line ();
1832 ++input_line_pointer
;
1835 if (*input_line_pointer
== '#')
1836 ++input_line_pointer
;
1838 if (input_line_pointer
[0] == '0'
1839 && (input_line_pointer
[1] == '\0'
1840 || ISSPACE (input_line_pointer
[1])))
1842 psym
= section_symbol (absolute_section
);
1843 ++input_line_pointer
;
1847 c
= get_symbol_name (& pname
);
1848 psym
= symbol_find_or_make (pname
);
1849 restore_line_pointer (c
);
1852 demand_empty_rest_of_line ();
1857 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1858 return fix_new (symbol_get_frag (csym
),
1859 symbol_get_value_expression (csym
)->X_add_number
,
1860 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1863 /* This is a version of obj_elf_get_vtable_inherit() that is
1864 suitable for use in struct _pseudo_type tables. */
1867 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1869 (void) obj_elf_get_vtable_inherit ();
1872 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1873 to the linker that a vtable slot was used. The syntax is
1874 ".vtable_entry tablename, offset". */
1877 obj_elf_get_vtable_entry (void)
1882 if (*input_line_pointer
== '#')
1883 ++input_line_pointer
;
1885 sym
= get_sym_from_input_line_and_check ();
1886 if (*input_line_pointer
!= ',')
1888 as_bad (_("expected comma after name in .vtable_entry"));
1889 ignore_rest_of_line ();
1893 ++input_line_pointer
;
1894 if (*input_line_pointer
== '#')
1895 ++input_line_pointer
;
1897 offset
= get_absolute_expression ();
1899 demand_empty_rest_of_line ();
1901 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1902 BFD_RELOC_VTABLE_ENTRY
);
1905 /* This is a version of obj_elf_get_vtable_entry() that is
1906 suitable for use in struct _pseudo_type tables. */
1909 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1911 (void) obj_elf_get_vtable_entry ();
1914 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1917 skip_past_char (char ** str
, char c
)
1927 #define skip_past_comma(str) skip_past_char (str, ',')
1929 /* A list of attributes that have been explicitly set by the assembly code.
1930 VENDOR is the vendor id, BASE is the tag shifted right by the number
1931 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1932 struct recorded_attribute_info
{
1933 struct recorded_attribute_info
*next
;
1938 static struct recorded_attribute_info
*recorded_attributes
;
1940 /* Record that we have seen an explicit specification of attribute TAG
1941 for vendor VENDOR. */
1944 record_attribute (int vendor
, unsigned int tag
)
1948 struct recorded_attribute_info
*rai
;
1950 base
= tag
/ (8 * sizeof (rai
->mask
));
1951 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1952 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1953 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1959 rai
= XNEW (struct recorded_attribute_info
);
1960 rai
->next
= recorded_attributes
;
1961 rai
->vendor
= vendor
;
1964 recorded_attributes
= rai
;
1967 /* Return true if we have seen an explicit specification of attribute TAG
1968 for vendor VENDOR. */
1971 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1975 struct recorded_attribute_info
*rai
;
1977 base
= tag
/ (8 * sizeof (rai
->mask
));
1978 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1979 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1980 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1981 return (rai
->mask
& mask
) != 0;
1985 /* Parse an attribute directive for VENDOR.
1986 Returns the attribute number read, or zero on error. */
1989 obj_elf_vendor_attribute (int vendor
)
1997 /* Read the first number or name. */
1998 skip_whitespace (input_line_pointer
);
1999 s
= input_line_pointer
;
2000 if (ISDIGIT (*input_line_pointer
))
2003 if (exp
.X_op
!= O_constant
)
2005 tag
= exp
.X_add_number
;
2011 /* A name may contain '_', but no other punctuation. */
2012 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
2013 ++input_line_pointer
)
2018 name
= xstrndup (s
, i
);
2020 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2021 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2024 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2027 as_bad (_("Attribute name not recognised: %s"), name
);
2028 ignore_rest_of_line ();
2035 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2037 if (skip_past_comma (&input_line_pointer
) == -1)
2042 if (exp
.X_op
!= O_constant
)
2044 as_bad (_("expected numeric constant"));
2045 ignore_rest_of_line ();
2048 i
= exp
.X_add_number
;
2051 && skip_past_comma (&input_line_pointer
) == -1)
2053 as_bad (_("expected comma"));
2054 ignore_rest_of_line ();
2061 skip_whitespace (input_line_pointer
);
2062 if (*input_line_pointer
!= '"')
2064 s
= demand_copy_C_string (&len
);
2067 record_attribute (vendor
, tag
);
2071 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2074 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2077 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2083 demand_empty_rest_of_line ();
2086 as_bad (_("bad string constant"));
2087 ignore_rest_of_line ();
2090 as_bad (_("expected <tag> , <value>"));
2091 ignore_rest_of_line ();
2095 /* Parse a .gnu_attribute directive. */
2098 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2100 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2104 elf_obj_read_begin_hook (void)
2106 #ifdef NEED_ECOFF_DEBUG
2107 if (ECOFF_DEBUGGING
)
2108 ecoff_read_begin_hook ();
2113 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2115 struct elf_obj_sy
*sy_obj
;
2117 sy_obj
= symbol_get_obj (symbolP
);
2118 sy_obj
->size
= NULL
;
2119 sy_obj
->versioned_name
= NULL
;
2121 #ifdef NEED_ECOFF_DEBUG
2122 if (ECOFF_DEBUGGING
)
2123 ecoff_symbol_new_hook (symbolP
);
2127 /* Deduplicate size expressions. We might get into trouble with
2128 multiple freeing or use after free if we leave them pointing to the
2129 same expressionS. */
2132 elf_obj_symbol_clone_hook (symbolS
*newsym
, symbolS
*orgsym ATTRIBUTE_UNUSED
)
2134 struct elf_obj_sy
*newelf
= symbol_get_obj (newsym
);
2137 expressionS
*exp
= XNEW (expressionS
);
2138 *exp
= *newelf
->size
;
2143 /* When setting one symbol equal to another, by default we probably
2144 want them to have the same "size", whatever it means in the current
2148 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2150 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2151 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2154 if (destelf
->size
== NULL
)
2155 destelf
->size
= XNEW (expressionS
);
2156 *destelf
->size
= *srcelf
->size
;
2160 free (destelf
->size
);
2161 destelf
->size
= NULL
;
2163 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2164 /* Don't copy visibility. */
2165 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2166 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2170 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2175 asection
*seg
= now_seg
;
2176 subsegT subseg
= now_subseg
;
2177 Elf_Internal_Note i_note
;
2178 Elf_External_Note e_note
;
2179 asection
*note_secp
= NULL
;
2182 if (*input_line_pointer
== '\"')
2186 ++input_line_pointer
; /* -> 1st char of string. */
2187 name
= input_line_pointer
;
2189 while (is_a_char (c
= next_char_of_string ()))
2191 c
= *input_line_pointer
;
2192 *input_line_pointer
= '\0';
2193 *(input_line_pointer
- 1) = '\0';
2194 *input_line_pointer
= c
;
2196 /* Create the .note section. */
2197 note_secp
= subseg_new (".note", 0);
2198 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2199 record_alignment (note_secp
, 2);
2201 /* Process the version string. */
2202 len
= strlen (name
) + 1;
2204 /* PR 3456: Although the name field is padded out to an 4-byte
2205 boundary, the namesz field should not be adjusted. */
2206 i_note
.namesz
= len
;
2207 i_note
.descsz
= 0; /* No description. */
2208 i_note
.type
= NT_VERSION
;
2209 p
= frag_more (sizeof (e_note
.namesz
));
2210 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2211 p
= frag_more (sizeof (e_note
.descsz
));
2212 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2213 p
= frag_more (sizeof (e_note
.type
));
2214 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2215 p
= frag_more (len
);
2216 memcpy (p
, name
, len
);
2218 frag_align (2, 0, 0);
2220 subseg_set (seg
, subseg
);
2223 as_bad (_("expected quoted string"));
2225 demand_empty_rest_of_line ();
2229 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2232 char c
= get_symbol_name (&name
);
2237 p
= input_line_pointer
;
2239 SKIP_WHITESPACE_AFTER_NAME ();
2240 if (*input_line_pointer
!= ',')
2243 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2245 ignore_rest_of_line ();
2248 input_line_pointer
++;
2250 if (exp
.X_op
== O_absent
)
2252 as_bad (_("missing expression in .size directive"));
2253 exp
.X_op
= O_constant
;
2254 exp
.X_add_number
= 0;
2257 sym
= symbol_find_or_make (name
);
2259 if (exp
.X_op
== O_constant
)
2261 S_SET_SIZE (sym
, exp
.X_add_number
);
2262 xfree (symbol_get_obj (sym
)->size
);
2263 symbol_get_obj (sym
)->size
= NULL
;
2267 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2268 *symbol_get_obj (sym
)->size
= exp
;
2270 demand_empty_rest_of_line ();
2273 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2274 There are six syntaxes:
2276 The first (used on Solaris) is
2278 The second (used on UnixWare) is
2280 The third (reportedly to be used on Irix 6.0) is
2282 The fourth (used on NetBSD/Arm and Linux/ARM) is
2284 The fifth (used on SVR4/860) is
2285 .type SYM,"function"
2286 The sixth (emitted by recent SunPRO under Solaris) is
2288 where the integer is the STT_* value.
2292 obj_elf_type_name (char *cp
)
2296 p
= input_line_pointer
;
2297 if (*input_line_pointer
>= '0'
2298 && *input_line_pointer
<= '9')
2300 while (*input_line_pointer
>= '0'
2301 && *input_line_pointer
<= '9')
2302 ++input_line_pointer
;
2303 *cp
= *input_line_pointer
;
2304 *input_line_pointer
= '\0';
2307 *cp
= get_symbol_name (&p
);
2313 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2317 const char *type_name
;
2319 elf_symbol_type
*elfsym
;
2321 sym
= get_sym_from_input_line_and_check ();
2322 c
= *input_line_pointer
;
2323 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2325 if (*input_line_pointer
== ',')
2326 ++input_line_pointer
;
2329 if ( *input_line_pointer
== '#'
2330 || *input_line_pointer
== '@'
2331 || *input_line_pointer
== '"'
2332 || *input_line_pointer
== '%')
2333 ++input_line_pointer
;
2335 type_name
= obj_elf_type_name (& c
);
2338 if (strcmp (type_name
, "function") == 0
2339 || strcmp (type_name
, "2") == 0
2340 || strcmp (type_name
, "STT_FUNC") == 0)
2341 type
= BSF_FUNCTION
;
2342 else if (strcmp (type_name
, "object") == 0
2343 || strcmp (type_name
, "1") == 0
2344 || strcmp (type_name
, "STT_OBJECT") == 0)
2346 else if (strcmp (type_name
, "tls_object") == 0
2347 || strcmp (type_name
, "6") == 0
2348 || strcmp (type_name
, "STT_TLS") == 0)
2349 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2350 else if (strcmp (type_name
, "notype") == 0
2351 || strcmp (type_name
, "0") == 0
2352 || strcmp (type_name
, "STT_NOTYPE") == 0)
2354 else if (strcmp (type_name
, "common") == 0
2355 || strcmp (type_name
, "5") == 0
2356 || strcmp (type_name
, "STT_COMMON") == 0)
2360 if (! S_IS_COMMON (sym
))
2362 if (S_IS_VOLATILE (sym
))
2364 sym
= symbol_clone (sym
, 1);
2365 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2366 S_SET_VALUE (sym
, 0);
2367 S_SET_EXTERNAL (sym
);
2368 symbol_set_frag (sym
, &zero_address_frag
);
2369 S_CLEAR_VOLATILE (sym
);
2371 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2372 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2375 /* FIXME: Is it safe to just change the section ? */
2376 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2377 S_SET_VALUE (sym
, 0);
2378 S_SET_EXTERNAL (sym
);
2382 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2383 || strcmp (type_name
, "10") == 0
2384 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2386 const struct elf_backend_data
*bed
;
2388 bed
= get_elf_backend_data (stdoutput
);
2389 if (bed
->elf_osabi
!= ELFOSABI_NONE
2390 && bed
->elf_osabi
!= ELFOSABI_GNU
2391 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2392 as_bad (_("symbol type \"%s\" is supported only by GNU "
2393 "and FreeBSD targets"), type_name
);
2394 /* MIPS targets do not support IFUNCS. */
2395 else if (bed
->target_id
== MIPS_ELF_DATA
)
2396 as_bad (_("symbol type \"%s\" is not supported by "
2397 "MIPS targets"), type_name
);
2398 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2399 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2401 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2403 const struct elf_backend_data
*bed
;
2405 bed
= get_elf_backend_data (stdoutput
);
2406 if (bed
->elf_osabi
!= ELFOSABI_NONE
2407 && bed
->elf_osabi
!= ELFOSABI_GNU
)
2408 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2410 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2411 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2413 #ifdef md_elf_symbol_type
2414 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2418 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2420 *input_line_pointer
= c
;
2422 if (*input_line_pointer
== '"')
2423 ++input_line_pointer
;
2425 #ifdef md_elf_symbol_type_change
2426 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2429 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2431 if (type
!= BSF_FUNCTION
)
2432 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2433 if (type
!= BSF_OBJECT
)
2435 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2437 if (S_IS_COMMON (sym
))
2439 as_bad (_("cannot change type of common symbol '%s'"),
2445 /* Don't warn when changing to STT_NOTYPE. */
2448 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2450 if (new != (elfsym
->symbol
.flags
| type
))
2451 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2452 elfsym
->symbol
.flags
= new;
2455 elfsym
->symbol
.flags
&= ~mask
;
2458 demand_empty_rest_of_line ();
2462 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2464 static segT comment_section
;
2465 segT old_section
= now_seg
;
2466 int old_subsection
= now_subseg
;
2468 #ifdef md_flush_pending_output
2469 md_flush_pending_output ();
2472 if (!comment_section
)
2475 comment_section
= subseg_new (".comment", 0);
2476 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2477 | SEC_MERGE
| SEC_STRINGS
));
2478 comment_section
->entsize
= 1;
2479 #ifdef md_elf_section_change_hook
2480 md_elf_section_change_hook ();
2486 subseg_set (comment_section
, 0);
2488 subseg_set (old_section
, old_subsection
);
2491 #ifdef INIT_STAB_SECTION
2493 /* The first entry in a .stabs section is special. */
2496 obj_elf_init_stab_section (segT seg
)
2501 unsigned int stroff
;
2503 /* Force the section to align to a longword boundary. Without this,
2504 UnixWare ar crashes. */
2505 bfd_set_section_alignment (seg
, 2);
2507 /* Make space for this first symbol. */
2511 file
= remap_debug_filename (as_where (NULL
));
2512 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2513 stroff
= get_stab_string_offset (file
, stabstr_name
, true);
2514 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2515 md_number_to_chars (p
, stroff
, 4);
2516 seg_info (seg
)->stabu
.p
= p
;
2517 xfree ((char *) file
);
2522 /* Fill in the counts in the first entry in a .stabs section. */
2525 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2532 if (!startswith (sec
->name
, ".stab"))
2534 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2537 name
= concat (sec
->name
, "str", NULL
);
2538 strsec
= bfd_get_section_by_name (abfd
, name
);
2540 strsz
= bfd_section_size (strsec
);
2543 nsyms
= bfd_section_size (sec
) / 12 - 1;
2545 p
= seg_info (sec
)->stabu
.p
;
2546 gas_assert (p
!= 0);
2548 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2549 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2553 #ifdef NEED_ECOFF_DEBUG
2555 /* This function is called by the ECOFF code. It is supposed to
2556 record the external symbol information so that the backend can
2557 write it out correctly. The ELF backend doesn't actually handle
2558 this at the moment, so we do it ourselves. We save the information
2561 #ifdef OBJ_MAYBE_ELF
2565 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2567 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2570 /* This function is called by bfd_ecoff_debug_externals. It is
2571 supposed to *EXT to the external symbol information, and return
2572 whether the symbol should be used at all. */
2575 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2577 if (sym
->udata
.p
== NULL
)
2579 *ext
= *(EXTR
*) sym
->udata
.p
;
2583 /* This function is called by bfd_ecoff_debug_externals. It has
2584 nothing to do for ELF. */
2587 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2588 bfd_size_type indx ATTRIBUTE_UNUSED
)
2592 #endif /* NEED_ECOFF_DEBUG */
2595 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2597 struct elf_obj_sy
*sy_obj
;
2599 struct elf_versioned_name_list
*versioned_name
;
2601 #ifdef NEED_ECOFF_DEBUG
2602 if (ECOFF_DEBUGGING
)
2603 ecoff_frob_symbol (symp
);
2606 sy_obj
= symbol_get_obj (symp
);
2608 size
= sy_obj
->size
;
2611 if (resolve_expression (size
)
2612 && size
->X_op
== O_constant
)
2613 S_SET_SIZE (symp
, size
->X_add_number
);
2616 if (!flag_allow_nonconst_size
)
2617 as_bad (_(".size expression for %s "
2618 "does not evaluate to a constant"), S_GET_NAME (symp
));
2620 as_warn (_(".size expression for %s "
2621 "does not evaluate to a constant"), S_GET_NAME (symp
));
2623 free (sy_obj
->size
);
2624 sy_obj
->size
= NULL
;
2627 versioned_name
= sy_obj
->versioned_name
;
2630 /* This symbol was given a new name with the .symver directive.
2631 If this is an external reference, just rename the symbol to
2632 include the version string. This will make the relocs be
2633 against the correct versioned symbol. */
2635 /* We will have already reported an version error. */
2636 if (sy_obj
->bad_version
)
2638 /* elf_frob_file_before_adjust only allows one version symbol for
2640 else if (sy_obj
->rename
)
2641 S_SET_NAME (symp
, versioned_name
->name
);
2642 else if (S_IS_COMMON (symp
))
2644 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2645 versioned_name
->name
, S_GET_NAME (symp
));
2651 elf_symbol_type
*elfsym
;
2653 /* This is a definition. Add an alias for each version.
2654 FIXME: Using an alias will permit the debugging information
2655 to refer to the right symbol. However, it's not clear
2656 whether it is the best approach. */
2658 /* FIXME: Creating a new symbol here is risky. We're
2659 in the final loop over the symbol table. We can
2660 get away with it only because the symbol goes to
2661 the end of the list, where the loop will still see
2662 it. It would probably be better to do this in
2663 obj_frob_file_before_adjust. */
2664 for (; versioned_name
!= NULL
;
2665 versioned_name
= versioned_name
->next
)
2667 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2669 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2671 /* Subtracting out the frag address here is a hack
2672 because we are in the middle of the final loop. */
2675 - (symbol_get_frag (symp
)->fr_address
2676 / OCTETS_PER_BYTE
)));
2678 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2680 /* This will copy over the size information. */
2681 copy_symbol_attributes (symp2
, symp
);
2683 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2685 if (S_IS_WEAK (symp
))
2688 if (S_IS_EXTERNAL (symp
))
2689 S_SET_EXTERNAL (symp2
);
2692 switch (symbol_get_obj (symp
)->visibility
)
2694 case visibility_unchanged
:
2696 case visibility_hidden
:
2697 bfdsym
= symbol_get_bfdsym (symp
);
2698 elfsym
= elf_symbol_from (bfdsym
);
2699 elfsym
->internal_elf_sym
.st_other
&= ~3;
2700 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2702 case visibility_remove
:
2703 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2705 case visibility_local
:
2706 S_CLEAR_EXTERNAL (symp
);
2712 /* Double check weak symbols. */
2713 if (S_IS_WEAK (symp
))
2715 if (S_IS_COMMON (symp
))
2716 as_bad (_("symbol `%s' can not be both weak and common"),
2723 asection
**head
; /* Section lists. */
2724 unsigned int num_group
; /* Number of lists. */
2725 htab_t indexes
; /* Maps group name to index in head array. */
2728 static struct group_list groups
;
2730 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2731 add it to a list of sections belonging to the group. INF is a
2732 pointer to a struct group_list, which is where we store the head of
2733 each list. If its link_to_symbol_name isn't NULL, set up its
2734 linked-to section. */
2737 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2738 asection
*sec
, void *inf
)
2740 struct group_list
*list
= (struct group_list
*) inf
;
2741 const char *group_name
= elf_group_name (sec
);
2743 unsigned int *elem_idx
;
2744 unsigned int *idx_ptr
;
2746 if (sec
->map_head
.linked_to_symbol_name
)
2748 symbolS
*linked_to_sym
;
2749 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2750 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2751 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2752 sec
->map_head
.linked_to_symbol_name
,
2753 bfd_section_name (sec
));
2755 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2758 if (group_name
== NULL
)
2761 /* If this group already has a list, add the section to the head of
2763 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2764 if (elem_idx
!= NULL
)
2766 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2767 list
->head
[*elem_idx
] = sec
;
2771 /* New group. Make the arrays bigger in chunks to minimize calls to
2773 i
= list
->num_group
;
2776 unsigned int newsize
= i
+ 128;
2777 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2779 list
->head
[i
] = sec
;
2780 list
->num_group
+= 1;
2782 /* Add index to hash. */
2783 idx_ptr
= XNEW (unsigned int);
2785 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2789 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2791 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2792 free ((char *)tuple
->value
);
2796 /* Create symbols for group signature. */
2799 elf_adjust_symtab (void)
2803 /* Go find section groups. */
2804 groups
.num_group
= 0;
2806 groups
.indexes
= str_htab_create ();
2807 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2810 /* Make the SHT_GROUP sections that describe each section group. We
2811 can't set up the section contents here yet, because elf section
2812 indices have yet to be calculated. elf.c:set_group_contents does
2813 the rest of the work. */
2814 for (i
= 0; i
< groups
.num_group
; i
++)
2816 const char *group_name
= elf_group_name (groups
.head
[i
]);
2817 const char *sec_name
;
2822 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2823 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2824 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2826 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2827 if (s
!= groups
.head
[i
])
2829 as_warn (_("assuming all members of group `%s' are COMDAT"),
2835 sec_name
= ".group";
2836 s
= subseg_force_new (sec_name
, 0);
2838 || !bfd_set_section_flags (s
, flags
)
2839 || !bfd_set_section_alignment (s
, 2))
2841 as_fatal (_("can't create group: %s"),
2842 bfd_errmsg (bfd_get_error ()));
2844 elf_section_type (s
) = SHT_GROUP
;
2846 /* Pass a pointer to the first section in this group. */
2847 elf_next_in_group (s
) = groups
.head
[i
];
2848 elf_sec_group (groups
.head
[i
]) = s
;
2849 /* Make sure that the signature symbol for the group has the
2850 name of the group. */
2851 sy
= symbol_find_exact (group_name
);
2852 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2854 /* Create the symbol now. */
2855 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2857 /* Before Solaris 11 build 154, Sun ld rejects local group
2858 signature symbols, so make them weak hidden instead. */
2859 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2860 S_SET_OTHER (sy
, STV_HIDDEN
);
2862 symbol_get_obj (sy
)->local
= 1;
2864 symbol_table_insert (sy
);
2866 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2867 /* Mark the group signature symbol as used so that it will be
2868 included in the symbol table. */
2869 symbol_mark_used_in_reloc (sy
);
2874 elf_frob_file (void)
2876 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2878 #ifdef elf_tc_final_processing
2879 elf_tc_final_processing ();
2883 /* It removes any unneeded versioned symbols from the symbol table. */
2886 elf_frob_file_before_adjust (void)
2892 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2894 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2895 int is_defined
= !!S_IS_DEFINED (symp
);
2897 if (sy_obj
->versioned_name
)
2899 char *p
= strchr (sy_obj
->versioned_name
->name
,
2904 /* The @@@ syntax is a special case. If the symbol is
2905 not defined, 2 `@'s will be removed from the
2906 versioned_name. Otherwise, 1 `@' will be removed. */
2907 size_t l
= strlen (&p
[3]) + 1;
2908 memmove (&p
[1 + is_defined
], &p
[3], l
);
2913 /* Verify that the name isn't using the @@ syntax--this
2914 is reserved for definitions of the default version
2916 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2918 as_bad (_("invalid attempt to declare external "
2919 "version name as default in symbol `%s'"),
2920 sy_obj
->versioned_name
->name
);
2924 /* Only one version symbol is allowed for undefined
2926 if (sy_obj
->versioned_name
->next
)
2928 as_bad (_("multiple versions [`%s'|`%s'] for "
2930 sy_obj
->versioned_name
->name
,
2931 sy_obj
->versioned_name
->next
->name
,
2936 sy_obj
->rename
= true;
2940 /* If there was .symver or .weak, but symbol was neither
2941 defined nor used anywhere, remove it. */
2943 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2944 && symbol_used_p (symp
) == 0
2945 && symbol_used_in_reloc_p (symp
) == 0)
2946 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2951 /* It is required that we let write_relocs have the opportunity to
2952 optimize away fixups before output has begun, since it is possible
2953 to eliminate all fixups for a section and thus we never should
2954 have generated the relocation section. */
2957 elf_frob_file_after_relocs (void)
2961 /* Set SHT_GROUP section size. */
2962 for (i
= 0; i
< groups
.num_group
; i
++)
2964 asection
*s
, *head
, *group
;
2967 head
= groups
.head
[i
];
2969 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2970 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2972 group
= elf_sec_group (head
);
2973 subseg_set (group
, 0);
2974 bfd_set_section_size (group
, size
);
2975 group
->contents
= (unsigned char *) frag_more (size
);
2976 frag_now
->fr_fix
= frag_now_fix_octets ();
2977 frag_wane (frag_now
);
2981 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2982 htab_delete (groups
.indexes
);
2984 #ifdef NEED_ECOFF_DEBUG
2985 if (ECOFF_DEBUGGING
)
2986 /* Generate the ECOFF debugging information. */
2988 const struct ecoff_debug_swap
*debug_swap
;
2989 struct ecoff_debug_info debug
;
2994 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2995 know (debug_swap
!= NULL
);
2996 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2998 /* Set up the pointers in debug. */
2999 #define SET(ptr, offset, type) \
3000 debug.ptr = (type) (buf + debug.symbolic_header.offset)
3002 SET (line
, cbLineOffset
, unsigned char *);
3003 SET (external_dnr
, cbDnOffset
, void *);
3004 SET (external_pdr
, cbPdOffset
, void *);
3005 SET (external_sym
, cbSymOffset
, void *);
3006 SET (external_opt
, cbOptOffset
, void *);
3007 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
3008 SET (ss
, cbSsOffset
, char *);
3009 SET (external_fdr
, cbFdOffset
, void *);
3010 SET (external_rfd
, cbRfdOffset
, void *);
3011 /* ssext and external_ext are set up just below. */
3015 /* Set up the external symbols. */
3016 debug
.ssext
= debug
.ssext_end
= NULL
;
3017 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3018 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
3019 elf_get_extr
, elf_set_index
))
3020 as_fatal (_("failed to set up debugging information: %s"),
3021 bfd_errmsg (bfd_get_error ()));
3023 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
3024 gas_assert (sec
!= NULL
);
3026 know (!stdoutput
->output_has_begun
);
3028 /* We set the size of the section, call bfd_set_section_contents
3029 to force the ELF backend to allocate a file position, and then
3030 write out the data. FIXME: Is this really the best way to do
3032 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
3035 /* Pass BUF to bfd_set_section_contents because this will
3036 eventually become a call to fwrite, and ISO C prohibits
3037 passing a NULL pointer to a stdio function even if the
3038 pointer will not be used. */
3039 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3040 as_fatal (_("can't start writing .mdebug section: %s"),
3041 bfd_errmsg (bfd_get_error ()));
3043 know (stdoutput
->output_has_begun
);
3044 know (sec
->filepos
!= 0);
3046 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3048 as_fatal (_("could not write .mdebug section: %s"),
3049 bfd_errmsg (bfd_get_error ()));
3051 #endif /* NEED_ECOFF_DEBUG */
3055 elf_generate_asm_lineno (void)
3057 #ifdef NEED_ECOFF_DEBUG
3058 if (ECOFF_DEBUGGING
)
3059 ecoff_generate_asm_lineno ();
3064 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
3065 int what ATTRIBUTE_UNUSED
,
3066 const char *string ATTRIBUTE_UNUSED
,
3067 int type ATTRIBUTE_UNUSED
,
3068 int other ATTRIBUTE_UNUSED
,
3069 int desc ATTRIBUTE_UNUSED
)
3071 #ifdef NEED_ECOFF_DEBUG
3072 if (ECOFF_DEBUGGING
)
3073 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3078 elf_separate_stab_sections (void)
3080 #ifdef NEED_ECOFF_DEBUG
3081 return (!ECOFF_DEBUGGING
);
3088 elf_init_stab_section (segT seg
)
3090 #ifdef NEED_ECOFF_DEBUG
3091 if (!ECOFF_DEBUGGING
)
3093 obj_elf_init_stab_section (seg
);
3096 const struct format_ops elf_format_ops
=
3098 bfd_target_elf_flavour
,
3099 0, /* dfl_leading_underscore */
3100 1, /* emit_section_symbols */
3105 elf_frob_file_before_adjust
,
3106 0, /* obj_frob_file_before_fix */
3107 elf_frob_file_after_relocs
,
3108 elf_s_get_size
, elf_s_set_size
,
3109 elf_s_get_align
, elf_s_set_align
,
3116 elf_copy_symbol_attributes
,
3117 elf_generate_asm_lineno
,
3119 elf_separate_stab_sections
,
3120 elf_init_stab_section
,
3121 elf_sec_sym_ok_for_reloc
,
3123 #ifdef NEED_ECOFF_DEBUG
3126 0, /* ecoff_set_ext */
3128 elf_obj_read_begin_hook
,
3129 elf_obj_symbol_new_hook
,
3130 elf_obj_symbol_clone_hook
,