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 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 const 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
= 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");
1444 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1445 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1446 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_retain
;
1452 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1455 if (linked_to_section_index
!= -1UL)
1457 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1458 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1459 /* FIXME: Should we perform some sanity checking on the section index ? */
1462 if (push
&& new_subsection
!= -1)
1463 subseg_set (now_seg
, new_subsection
);
1466 /* Change to the .data section. */
1469 obj_elf_data (int i
)
1471 #ifdef md_flush_pending_output
1472 md_flush_pending_output ();
1475 previous_section
= now_seg
;
1476 previous_subsection
= now_subseg
;
1479 #ifdef md_elf_section_change_hook
1480 md_elf_section_change_hook ();
1484 /* Change to the .text section. */
1487 obj_elf_text (int i
)
1489 #ifdef md_flush_pending_output
1490 md_flush_pending_output ();
1493 previous_section
= now_seg
;
1494 previous_subsection
= now_subseg
;
1497 #ifdef md_elf_section_change_hook
1498 md_elf_section_change_hook ();
1502 /* Change to the *ABS* section. */
1505 obj_elf_struct (int i
)
1507 #ifdef md_flush_pending_output
1508 md_flush_pending_output ();
1511 previous_section
= now_seg
;
1512 previous_subsection
= now_subseg
;
1515 #ifdef md_elf_section_change_hook
1516 md_elf_section_change_hook ();
1521 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1525 #ifdef md_flush_pending_output
1526 md_flush_pending_output ();
1529 previous_section
= now_seg
;
1530 previous_subsection
= now_subseg
;
1532 temp
= get_absolute_expression ();
1533 subseg_set (now_seg
, (subsegT
) temp
);
1534 demand_empty_rest_of_line ();
1536 #ifdef md_elf_section_change_hook
1537 md_elf_section_change_hook ();
1541 /* This can be called from the processor backends if they change
1545 obj_elf_section_change_hook (void)
1547 previous_section
= now_seg
;
1548 previous_subsection
= now_subseg
;
1552 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1557 if (previous_section
== 0)
1559 as_warn (_(".previous without corresponding .section; ignored"));
1563 #ifdef md_flush_pending_output
1564 md_flush_pending_output ();
1567 new_section
= previous_section
;
1568 new_subsection
= previous_subsection
;
1569 previous_section
= now_seg
;
1570 previous_subsection
= now_subseg
;
1571 subseg_set (new_section
, new_subsection
);
1573 #ifdef md_elf_section_change_hook
1574 md_elf_section_change_hook ();
1579 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1581 struct section_stack
*top
= section_stack
;
1585 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1589 #ifdef md_flush_pending_output
1590 md_flush_pending_output ();
1593 section_stack
= top
->next
;
1594 previous_section
= top
->prev_seg
;
1595 previous_subsection
= top
->prev_subseg
;
1596 subseg_set (top
->seg
, top
->subseg
);
1599 #ifdef md_elf_section_change_hook
1600 md_elf_section_change_hook ();
1605 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1607 /* Assume delimiter is part of expression. BSD4.2 as fails with
1608 delightful bug, so we are not being incompatible here. */
1609 new_logical_line (NULL
, get_absolute_expression ());
1610 demand_empty_rest_of_line ();
1613 static struct elf_versioned_name_list
*
1614 obj_elf_find_and_add_versioned_name (const char *version_name
,
1615 const char *sym_name
,
1617 struct elf_obj_sy
*sy_obj
)
1619 struct elf_versioned_name_list
*versioned_name
;
1622 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1625 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1626 names, we have to disable this. */
1627 if (0 && *p
== '\0')
1629 as_bad (_("missing version name in `%s' for symbol `%s'"),
1630 version_name
, sym_name
);
1634 versioned_name
= sy_obj
->versioned_name
;
1644 if (strcmp (versioned_name
->name
, version_name
) == 0)
1645 return versioned_name
;
1648 as_bad (_("only one version name with `@@@' is allowed "
1649 "for symbol `%s'"), sym_name
);
1653 sy_obj
->rename
= TRUE
;
1656 as_bad (_("invalid version name '%s' for symbol `%s'"),
1657 version_name
, sym_name
);
1662 versioned_name
!= NULL
;
1663 versioned_name
= versioned_name
->next
)
1664 if (strcmp (versioned_name
->name
, version_name
) == 0)
1665 return versioned_name
;
1667 /* Add this versioned name to the head of the list, */
1668 versioned_name
= (struct elf_versioned_name_list
*)
1669 xmalloc (sizeof (*versioned_name
));
1670 versioned_name
->name
= xstrdup (version_name
);
1671 versioned_name
->next
= sy_obj
->versioned_name
;
1672 sy_obj
->versioned_name
= versioned_name
;
1674 return versioned_name
;
1677 /* This handles the .symver pseudo-op, which is used to specify a
1678 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1679 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1680 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1681 with the same value as the symbol NAME. */
1684 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1687 const char *sym_name
;
1691 struct elf_obj_sy
*sy_obj
;
1694 sym
= get_sym_from_input_line_and_check ();
1696 if (*input_line_pointer
!= ',')
1698 as_bad (_("expected comma after name in .symver"));
1699 ignore_rest_of_line ();
1703 ++input_line_pointer
;
1706 /* Temporarily include '@' in symbol names. */
1707 old_lexat
= lex_type
[(unsigned char) '@'];
1708 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1709 c
= get_symbol_name (& name
);
1710 lex_type
[(unsigned char) '@'] = old_lexat
;
1711 sym_name
= S_GET_NAME (sym
);
1713 if (S_IS_COMMON (sym
))
1715 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1717 ignore_rest_of_line ();
1721 p
= strchr (name
, ELF_VER_CHR
);
1724 as_bad (_("missing version name in `%s' for symbol `%s'"),
1726 ignore_rest_of_line ();
1730 sy_obj
= symbol_get_obj (sym
);
1731 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1734 sy_obj
->bad_version
= TRUE
;
1735 ignore_rest_of_line ();
1739 (void) restore_line_pointer (c
);
1741 if (*input_line_pointer
== ',')
1743 char *save
= input_line_pointer
;
1745 ++input_line_pointer
;
1747 if (strncmp (input_line_pointer
, "local", 5) == 0)
1749 input_line_pointer
+= 5;
1750 sy_obj
->visibility
= visibility_local
;
1752 else if (strncmp (input_line_pointer
, "hidden", 6) == 0)
1754 input_line_pointer
+= 6;
1755 sy_obj
->visibility
= visibility_hidden
;
1757 else if (strncmp (input_line_pointer
, "remove", 6) == 0)
1759 input_line_pointer
+= 6;
1760 sy_obj
->visibility
= visibility_remove
;
1763 input_line_pointer
= save
;
1766 demand_empty_rest_of_line ();
1769 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1770 to the linker the hierarchy in which a particular table resides. The
1771 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1774 obj_elf_get_vtable_inherit (void)
1776 char *cname
, *pname
;
1777 symbolS
*csym
, *psym
;
1780 if (*input_line_pointer
== '#')
1781 ++input_line_pointer
;
1783 c
= get_symbol_name (& cname
);
1784 csym
= symbol_find (cname
);
1786 /* GCFIXME: should check that we don't have two .vtable_inherits for
1787 the same child symbol. Also, we can currently only do this if the
1788 child symbol is already exists and is placed in a fragment. */
1790 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1792 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1797 *input_line_pointer
= c
;
1799 SKIP_WHITESPACE_AFTER_NAME ();
1800 if (*input_line_pointer
!= ',')
1802 as_bad (_("expected comma after name in .vtable_inherit"));
1803 ignore_rest_of_line ();
1807 ++input_line_pointer
;
1810 if (*input_line_pointer
== '#')
1811 ++input_line_pointer
;
1813 if (input_line_pointer
[0] == '0'
1814 && (input_line_pointer
[1] == '\0'
1815 || ISSPACE (input_line_pointer
[1])))
1817 psym
= section_symbol (absolute_section
);
1818 ++input_line_pointer
;
1822 c
= get_symbol_name (& pname
);
1823 psym
= symbol_find_or_make (pname
);
1824 restore_line_pointer (c
);
1827 demand_empty_rest_of_line ();
1832 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1833 return fix_new (symbol_get_frag (csym
),
1834 symbol_get_value_expression (csym
)->X_add_number
,
1835 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1838 /* This is a version of obj_elf_get_vtable_inherit() that is
1839 suitable for use in struct _pseudo_type tables. */
1842 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1844 (void) obj_elf_get_vtable_inherit ();
1847 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1848 to the linker that a vtable slot was used. The syntax is
1849 ".vtable_entry tablename, offset". */
1852 obj_elf_get_vtable_entry (void)
1857 if (*input_line_pointer
== '#')
1858 ++input_line_pointer
;
1860 sym
= get_sym_from_input_line_and_check ();
1861 if (*input_line_pointer
!= ',')
1863 as_bad (_("expected comma after name in .vtable_entry"));
1864 ignore_rest_of_line ();
1868 ++input_line_pointer
;
1869 if (*input_line_pointer
== '#')
1870 ++input_line_pointer
;
1872 offset
= get_absolute_expression ();
1874 demand_empty_rest_of_line ();
1876 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1877 BFD_RELOC_VTABLE_ENTRY
);
1880 /* This is a version of obj_elf_get_vtable_entry() that is
1881 suitable for use in struct _pseudo_type tables. */
1884 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1886 (void) obj_elf_get_vtable_entry ();
1889 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1892 skip_past_char (char ** str
, char c
)
1902 #define skip_past_comma(str) skip_past_char (str, ',')
1904 /* A list of attributes that have been explicitly set by the assembly code.
1905 VENDOR is the vendor id, BASE is the tag shifted right by the number
1906 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1907 struct recorded_attribute_info
{
1908 struct recorded_attribute_info
*next
;
1913 static struct recorded_attribute_info
*recorded_attributes
;
1915 /* Record that we have seen an explicit specification of attribute TAG
1916 for vendor VENDOR. */
1919 record_attribute (int vendor
, unsigned int tag
)
1923 struct recorded_attribute_info
*rai
;
1925 base
= tag
/ (8 * sizeof (rai
->mask
));
1926 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1927 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1928 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1934 rai
= XNEW (struct recorded_attribute_info
);
1935 rai
->next
= recorded_attributes
;
1936 rai
->vendor
= vendor
;
1939 recorded_attributes
= rai
;
1942 /* Return true if we have seen an explicit specification of attribute TAG
1943 for vendor VENDOR. */
1946 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1950 struct recorded_attribute_info
*rai
;
1952 base
= tag
/ (8 * sizeof (rai
->mask
));
1953 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1954 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1955 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1956 return (rai
->mask
& mask
) != 0;
1960 /* Parse an attribute directive for VENDOR.
1961 Returns the attribute number read, or zero on error. */
1964 obj_elf_vendor_attribute (int vendor
)
1972 /* Read the first number or name. */
1973 skip_whitespace (input_line_pointer
);
1974 s
= input_line_pointer
;
1975 if (ISDIGIT (*input_line_pointer
))
1978 if (exp
.X_op
!= O_constant
)
1980 tag
= exp
.X_add_number
;
1986 /* A name may contain '_', but no other punctuation. */
1987 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1988 ++input_line_pointer
)
1993 name
= xstrndup (s
, i
);
1995 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
1996 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
1999 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2002 as_bad (_("Attribute name not recognised: %s"), name
);
2003 ignore_rest_of_line ();
2010 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2012 if (skip_past_comma (&input_line_pointer
) == -1)
2017 if (exp
.X_op
!= O_constant
)
2019 as_bad (_("expected numeric constant"));
2020 ignore_rest_of_line ();
2023 i
= exp
.X_add_number
;
2026 && skip_past_comma (&input_line_pointer
) == -1)
2028 as_bad (_("expected comma"));
2029 ignore_rest_of_line ();
2036 skip_whitespace (input_line_pointer
);
2037 if (*input_line_pointer
!= '"')
2039 s
= demand_copy_C_string (&len
);
2042 record_attribute (vendor
, tag
);
2046 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2049 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2052 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2058 demand_empty_rest_of_line ();
2061 as_bad (_("bad string constant"));
2062 ignore_rest_of_line ();
2065 as_bad (_("expected <tag> , <value>"));
2066 ignore_rest_of_line ();
2070 /* Parse a .gnu_attribute directive. */
2073 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2075 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2079 elf_obj_read_begin_hook (void)
2081 #ifdef NEED_ECOFF_DEBUG
2082 if (ECOFF_DEBUGGING
)
2083 ecoff_read_begin_hook ();
2088 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2090 struct elf_obj_sy
*sy_obj
;
2092 sy_obj
= symbol_get_obj (symbolP
);
2093 sy_obj
->size
= NULL
;
2094 sy_obj
->versioned_name
= NULL
;
2096 #ifdef NEED_ECOFF_DEBUG
2097 if (ECOFF_DEBUGGING
)
2098 ecoff_symbol_new_hook (symbolP
);
2102 /* Deduplicate size expressions. We might get into trouble with
2103 multiple freeing or use after free if we leave them pointing to the
2104 same expressionS. */
2107 elf_obj_symbol_clone_hook (symbolS
*newsym
, symbolS
*orgsym ATTRIBUTE_UNUSED
)
2109 struct elf_obj_sy
*newelf
= symbol_get_obj (newsym
);
2112 expressionS
*exp
= XNEW (expressionS
);
2113 *exp
= *newelf
->size
;
2118 /* When setting one symbol equal to another, by default we probably
2119 want them to have the same "size", whatever it means in the current
2123 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2125 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2126 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2129 if (destelf
->size
== NULL
)
2130 destelf
->size
= XNEW (expressionS
);
2131 *destelf
->size
= *srcelf
->size
;
2135 free (destelf
->size
);
2136 destelf
->size
= NULL
;
2138 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2139 /* Don't copy visibility. */
2140 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2141 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2145 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2150 asection
*seg
= now_seg
;
2151 subsegT subseg
= now_subseg
;
2152 Elf_Internal_Note i_note
;
2153 Elf_External_Note e_note
;
2154 asection
*note_secp
= NULL
;
2157 if (*input_line_pointer
== '\"')
2161 ++input_line_pointer
; /* -> 1st char of string. */
2162 name
= input_line_pointer
;
2164 while (is_a_char (c
= next_char_of_string ()))
2166 c
= *input_line_pointer
;
2167 *input_line_pointer
= '\0';
2168 *(input_line_pointer
- 1) = '\0';
2169 *input_line_pointer
= c
;
2171 /* Create the .note section. */
2172 note_secp
= subseg_new (".note", 0);
2173 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2174 record_alignment (note_secp
, 2);
2176 /* Process the version string. */
2177 len
= strlen (name
) + 1;
2179 /* PR 3456: Although the name field is padded out to an 4-byte
2180 boundary, the namesz field should not be adjusted. */
2181 i_note
.namesz
= len
;
2182 i_note
.descsz
= 0; /* No description. */
2183 i_note
.type
= NT_VERSION
;
2184 p
= frag_more (sizeof (e_note
.namesz
));
2185 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2186 p
= frag_more (sizeof (e_note
.descsz
));
2187 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2188 p
= frag_more (sizeof (e_note
.type
));
2189 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2190 p
= frag_more (len
);
2191 memcpy (p
, name
, len
);
2193 frag_align (2, 0, 0);
2195 subseg_set (seg
, subseg
);
2198 as_bad (_("expected quoted string"));
2200 demand_empty_rest_of_line ();
2204 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2207 char c
= get_symbol_name (&name
);
2212 p
= input_line_pointer
;
2214 SKIP_WHITESPACE_AFTER_NAME ();
2215 if (*input_line_pointer
!= ',')
2218 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2220 ignore_rest_of_line ();
2223 input_line_pointer
++;
2225 if (exp
.X_op
== O_absent
)
2227 as_bad (_("missing expression in .size directive"));
2228 exp
.X_op
= O_constant
;
2229 exp
.X_add_number
= 0;
2232 sym
= symbol_find_or_make (name
);
2234 if (exp
.X_op
== O_constant
)
2236 S_SET_SIZE (sym
, exp
.X_add_number
);
2237 xfree (symbol_get_obj (sym
)->size
);
2238 symbol_get_obj (sym
)->size
= NULL
;
2242 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2243 *symbol_get_obj (sym
)->size
= exp
;
2245 demand_empty_rest_of_line ();
2248 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2249 There are six syntaxes:
2251 The first (used on Solaris) is
2253 The second (used on UnixWare) is
2255 The third (reportedly to be used on Irix 6.0) is
2257 The fourth (used on NetBSD/Arm and Linux/ARM) is
2259 The fifth (used on SVR4/860) is
2260 .type SYM,"function"
2261 The sixth (emitted by recent SunPRO under Solaris) is
2263 where the integer is the STT_* value.
2267 obj_elf_type_name (char *cp
)
2271 p
= input_line_pointer
;
2272 if (*input_line_pointer
>= '0'
2273 && *input_line_pointer
<= '9')
2275 while (*input_line_pointer
>= '0'
2276 && *input_line_pointer
<= '9')
2277 ++input_line_pointer
;
2278 *cp
= *input_line_pointer
;
2279 *input_line_pointer
= '\0';
2282 *cp
= get_symbol_name (&p
);
2288 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2292 const char *type_name
;
2294 elf_symbol_type
*elfsym
;
2296 sym
= get_sym_from_input_line_and_check ();
2297 c
= *input_line_pointer
;
2298 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2300 if (*input_line_pointer
== ',')
2301 ++input_line_pointer
;
2304 if ( *input_line_pointer
== '#'
2305 || *input_line_pointer
== '@'
2306 || *input_line_pointer
== '"'
2307 || *input_line_pointer
== '%')
2308 ++input_line_pointer
;
2310 type_name
= obj_elf_type_name (& c
);
2313 if (strcmp (type_name
, "function") == 0
2314 || strcmp (type_name
, "2") == 0
2315 || strcmp (type_name
, "STT_FUNC") == 0)
2316 type
= BSF_FUNCTION
;
2317 else if (strcmp (type_name
, "object") == 0
2318 || strcmp (type_name
, "1") == 0
2319 || strcmp (type_name
, "STT_OBJECT") == 0)
2321 else if (strcmp (type_name
, "tls_object") == 0
2322 || strcmp (type_name
, "6") == 0
2323 || strcmp (type_name
, "STT_TLS") == 0)
2324 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2325 else if (strcmp (type_name
, "notype") == 0
2326 || strcmp (type_name
, "0") == 0
2327 || strcmp (type_name
, "STT_NOTYPE") == 0)
2329 else if (strcmp (type_name
, "common") == 0
2330 || strcmp (type_name
, "5") == 0
2331 || strcmp (type_name
, "STT_COMMON") == 0)
2335 if (! S_IS_COMMON (sym
))
2337 if (S_IS_VOLATILE (sym
))
2339 sym
= symbol_clone (sym
, 1);
2340 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2341 S_SET_VALUE (sym
, 0);
2342 S_SET_EXTERNAL (sym
);
2343 symbol_set_frag (sym
, &zero_address_frag
);
2344 S_CLEAR_VOLATILE (sym
);
2346 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2347 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2350 /* FIXME: Is it safe to just change the section ? */
2351 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2352 S_SET_VALUE (sym
, 0);
2353 S_SET_EXTERNAL (sym
);
2357 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2358 || strcmp (type_name
, "10") == 0
2359 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2361 const struct elf_backend_data
*bed
;
2363 bed
= get_elf_backend_data (stdoutput
);
2364 if (bed
->elf_osabi
!= ELFOSABI_NONE
2365 && bed
->elf_osabi
!= ELFOSABI_GNU
2366 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2367 as_bad (_("symbol type \"%s\" is supported only by GNU "
2368 "and FreeBSD targets"), type_name
);
2369 /* MIPS targets do not support IFUNCS. */
2370 else if (bed
->target_id
== MIPS_ELF_DATA
)
2371 as_bad (_("symbol type \"%s\" is not supported by "
2372 "MIPS targets"), type_name
);
2373 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2374 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2376 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2378 const struct elf_backend_data
*bed
;
2380 bed
= get_elf_backend_data (stdoutput
);
2381 if (bed
->elf_osabi
!= ELFOSABI_NONE
2382 && bed
->elf_osabi
!= ELFOSABI_GNU
)
2383 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2385 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2386 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2388 #ifdef md_elf_symbol_type
2389 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2393 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2395 *input_line_pointer
= c
;
2397 if (*input_line_pointer
== '"')
2398 ++input_line_pointer
;
2400 #ifdef md_elf_symbol_type_change
2401 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2404 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2406 if (type
!= BSF_FUNCTION
)
2407 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2408 if (type
!= BSF_OBJECT
)
2410 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2412 if (S_IS_COMMON (sym
))
2414 as_bad (_("cannot change type of common symbol '%s'"),
2420 /* Don't warn when changing to STT_NOTYPE. */
2423 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2425 if (new != (elfsym
->symbol
.flags
| type
))
2426 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2427 elfsym
->symbol
.flags
= new;
2430 elfsym
->symbol
.flags
&= ~mask
;
2433 demand_empty_rest_of_line ();
2437 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2439 static segT comment_section
;
2440 segT old_section
= now_seg
;
2441 int old_subsection
= now_subseg
;
2443 #ifdef md_flush_pending_output
2444 md_flush_pending_output ();
2447 if (!comment_section
)
2450 comment_section
= subseg_new (".comment", 0);
2451 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2452 | SEC_MERGE
| SEC_STRINGS
));
2453 comment_section
->entsize
= 1;
2454 #ifdef md_elf_section_change_hook
2455 md_elf_section_change_hook ();
2461 subseg_set (comment_section
, 0);
2463 subseg_set (old_section
, old_subsection
);
2466 #ifdef INIT_STAB_SECTION
2468 /* The first entry in a .stabs section is special. */
2471 obj_elf_init_stab_section (segT seg
)
2476 unsigned int stroff
;
2478 /* Force the section to align to a longword boundary. Without this,
2479 UnixWare ar crashes. */
2480 bfd_set_section_alignment (seg
, 2);
2482 /* Make space for this first symbol. */
2486 file
= remap_debug_filename (as_where (NULL
));
2487 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2488 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
2489 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2490 md_number_to_chars (p
, stroff
, 4);
2491 seg_info (seg
)->stabu
.p
= p
;
2492 xfree ((char *) file
);
2497 /* Fill in the counts in the first entry in a .stabs section. */
2500 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2507 if (strncmp (".stab", sec
->name
, 5))
2509 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2512 name
= concat (sec
->name
, "str", NULL
);
2513 strsec
= bfd_get_section_by_name (abfd
, name
);
2515 strsz
= bfd_section_size (strsec
);
2518 nsyms
= bfd_section_size (sec
) / 12 - 1;
2520 p
= seg_info (sec
)->stabu
.p
;
2521 gas_assert (p
!= 0);
2523 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2524 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2528 #ifdef NEED_ECOFF_DEBUG
2530 /* This function is called by the ECOFF code. It is supposed to
2531 record the external symbol information so that the backend can
2532 write it out correctly. The ELF backend doesn't actually handle
2533 this at the moment, so we do it ourselves. We save the information
2536 #ifdef OBJ_MAYBE_ELF
2540 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2542 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2545 /* This function is called by bfd_ecoff_debug_externals. It is
2546 supposed to *EXT to the external symbol information, and return
2547 whether the symbol should be used at all. */
2550 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2552 if (sym
->udata
.p
== NULL
)
2554 *ext
= *(EXTR
*) sym
->udata
.p
;
2558 /* This function is called by bfd_ecoff_debug_externals. It has
2559 nothing to do for ELF. */
2562 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2563 bfd_size_type indx ATTRIBUTE_UNUSED
)
2567 #endif /* NEED_ECOFF_DEBUG */
2570 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2572 struct elf_obj_sy
*sy_obj
;
2574 struct elf_versioned_name_list
*versioned_name
;
2576 #ifdef NEED_ECOFF_DEBUG
2577 if (ECOFF_DEBUGGING
)
2578 ecoff_frob_symbol (symp
);
2581 sy_obj
= symbol_get_obj (symp
);
2583 size
= sy_obj
->size
;
2586 if (resolve_expression (size
)
2587 && size
->X_op
== O_constant
)
2588 S_SET_SIZE (symp
, size
->X_add_number
);
2591 if (!flag_allow_nonconst_size
)
2592 as_bad (_(".size expression for %s "
2593 "does not evaluate to a constant"), S_GET_NAME (symp
));
2595 as_warn (_(".size expression for %s "
2596 "does not evaluate to a constant"), S_GET_NAME (symp
));
2598 free (sy_obj
->size
);
2599 sy_obj
->size
= NULL
;
2602 versioned_name
= sy_obj
->versioned_name
;
2605 /* This symbol was given a new name with the .symver directive.
2606 If this is an external reference, just rename the symbol to
2607 include the version string. This will make the relocs be
2608 against the correct versioned symbol. */
2610 /* We will have already reported an version error. */
2611 if (sy_obj
->bad_version
)
2613 /* elf_frob_file_before_adjust only allows one version symbol for
2615 else if (sy_obj
->rename
)
2616 S_SET_NAME (symp
, versioned_name
->name
);
2617 else if (S_IS_COMMON (symp
))
2619 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2620 versioned_name
->name
, S_GET_NAME (symp
));
2626 elf_symbol_type
*elfsym
;
2628 /* This is a definition. Add an alias for each version.
2629 FIXME: Using an alias will permit the debugging information
2630 to refer to the right symbol. However, it's not clear
2631 whether it is the best approach. */
2633 /* FIXME: Creating a new symbol here is risky. We're
2634 in the final loop over the symbol table. We can
2635 get away with it only because the symbol goes to
2636 the end of the list, where the loop will still see
2637 it. It would probably be better to do this in
2638 obj_frob_file_before_adjust. */
2639 for (; versioned_name
!= NULL
;
2640 versioned_name
= versioned_name
->next
)
2642 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2644 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2646 /* Subtracting out the frag address here is a hack
2647 because we are in the middle of the final loop. */
2650 - (symbol_get_frag (symp
)->fr_address
2651 / OCTETS_PER_BYTE
)));
2653 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2655 /* This will copy over the size information. */
2656 copy_symbol_attributes (symp2
, symp
);
2658 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2660 if (S_IS_WEAK (symp
))
2663 if (S_IS_EXTERNAL (symp
))
2664 S_SET_EXTERNAL (symp2
);
2667 switch (symbol_get_obj (symp
)->visibility
)
2669 case visibility_unchanged
:
2671 case visibility_hidden
:
2672 bfdsym
= symbol_get_bfdsym (symp
);
2673 elfsym
= elf_symbol_from (bfdsym
);
2674 elfsym
->internal_elf_sym
.st_other
&= ~3;
2675 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2677 case visibility_remove
:
2678 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2680 case visibility_local
:
2681 S_CLEAR_EXTERNAL (symp
);
2687 /* Double check weak symbols. */
2688 if (S_IS_WEAK (symp
))
2690 if (S_IS_COMMON (symp
))
2691 as_bad (_("symbol `%s' can not be both weak and common"),
2698 asection
**head
; /* Section lists. */
2699 unsigned int num_group
; /* Number of lists. */
2700 htab_t indexes
; /* Maps group name to index in head array. */
2703 static struct group_list groups
;
2705 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2706 add it to a list of sections belonging to the group. INF is a
2707 pointer to a struct group_list, which is where we store the head of
2708 each list. If its link_to_symbol_name isn't NULL, set up its
2709 linked-to section. */
2712 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2713 asection
*sec
, void *inf
)
2715 struct group_list
*list
= (struct group_list
*) inf
;
2716 const char *group_name
= elf_group_name (sec
);
2718 unsigned int *elem_idx
;
2719 unsigned int *idx_ptr
;
2721 if (sec
->map_head
.linked_to_symbol_name
)
2723 symbolS
*linked_to_sym
;
2724 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2725 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2726 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2727 sec
->map_head
.linked_to_symbol_name
,
2728 bfd_section_name (sec
));
2730 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2733 if (group_name
== NULL
)
2736 /* If this group already has a list, add the section to the head of
2738 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2739 if (elem_idx
!= NULL
)
2741 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2742 list
->head
[*elem_idx
] = sec
;
2746 /* New group. Make the arrays bigger in chunks to minimize calls to
2748 i
= list
->num_group
;
2751 unsigned int newsize
= i
+ 128;
2752 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2754 list
->head
[i
] = sec
;
2755 list
->num_group
+= 1;
2757 /* Add index to hash. */
2758 idx_ptr
= XNEW (unsigned int);
2760 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2764 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2766 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2767 free ((char *)tuple
->value
);
2771 /* Create symbols for group signature. */
2774 elf_adjust_symtab (void)
2778 /* Go find section groups. */
2779 groups
.num_group
= 0;
2781 groups
.indexes
= str_htab_create ();
2782 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2785 /* Make the SHT_GROUP sections that describe each section group. We
2786 can't set up the section contents here yet, because elf section
2787 indices have yet to be calculated. elf.c:set_group_contents does
2788 the rest of the work. */
2789 for (i
= 0; i
< groups
.num_group
; i
++)
2791 const char *group_name
= elf_group_name (groups
.head
[i
]);
2792 const char *sec_name
;
2797 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2798 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2799 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2801 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2802 if (s
!= groups
.head
[i
])
2804 as_warn (_("assuming all members of group `%s' are COMDAT"),
2810 sec_name
= ".group";
2811 s
= subseg_force_new (sec_name
, 0);
2813 || !bfd_set_section_flags (s
, flags
)
2814 || !bfd_set_section_alignment (s
, 2))
2816 as_fatal (_("can't create group: %s"),
2817 bfd_errmsg (bfd_get_error ()));
2819 elf_section_type (s
) = SHT_GROUP
;
2821 /* Pass a pointer to the first section in this group. */
2822 elf_next_in_group (s
) = groups
.head
[i
];
2823 elf_sec_group (groups
.head
[i
]) = s
;
2824 /* Make sure that the signature symbol for the group has the
2825 name of the group. */
2826 sy
= symbol_find_exact (group_name
);
2827 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2829 /* Create the symbol now. */
2830 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2832 /* Before Solaris 11 build 154, Sun ld rejects local group
2833 signature symbols, so make them weak hidden instead. */
2834 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2835 S_SET_OTHER (sy
, STV_HIDDEN
);
2837 symbol_get_obj (sy
)->local
= 1;
2839 symbol_table_insert (sy
);
2841 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2846 elf_frob_file (void)
2848 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2850 #ifdef elf_tc_final_processing
2851 elf_tc_final_processing ();
2855 /* It removes any unneeded versioned symbols from the symbol table. */
2858 elf_frob_file_before_adjust (void)
2864 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2866 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2867 int is_defined
= !!S_IS_DEFINED (symp
);
2869 if (sy_obj
->versioned_name
)
2871 char *p
= strchr (sy_obj
->versioned_name
->name
,
2876 /* The @@@ syntax is a special case. If the symbol is
2877 not defined, 2 `@'s will be removed from the
2878 versioned_name. Otherwise, 1 `@' will be removed. */
2879 size_t l
= strlen (&p
[3]) + 1;
2880 memmove (&p
[1 + is_defined
], &p
[3], l
);
2885 /* Verify that the name isn't using the @@ syntax--this
2886 is reserved for definitions of the default version
2888 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2890 as_bad (_("invalid attempt to declare external "
2891 "version name as default in symbol `%s'"),
2892 sy_obj
->versioned_name
->name
);
2896 /* Only one version symbol is allowed for undefined
2898 if (sy_obj
->versioned_name
->next
)
2900 as_bad (_("multiple versions [`%s'|`%s'] for "
2902 sy_obj
->versioned_name
->name
,
2903 sy_obj
->versioned_name
->next
->name
,
2908 sy_obj
->rename
= TRUE
;
2912 /* If there was .symver or .weak, but symbol was neither
2913 defined nor used anywhere, remove it. */
2915 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2916 && symbol_used_p (symp
) == 0
2917 && symbol_used_in_reloc_p (symp
) == 0)
2918 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2923 /* It is required that we let write_relocs have the opportunity to
2924 optimize away fixups before output has begun, since it is possible
2925 to eliminate all fixups for a section and thus we never should
2926 have generated the relocation section. */
2929 elf_frob_file_after_relocs (void)
2933 /* Set SHT_GROUP section size. */
2934 for (i
= 0; i
< groups
.num_group
; i
++)
2936 asection
*s
, *head
, *group
;
2939 head
= groups
.head
[i
];
2941 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2942 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2944 group
= elf_sec_group (head
);
2945 subseg_set (group
, 0);
2946 bfd_set_section_size (group
, size
);
2947 group
->contents
= (unsigned char *) frag_more (size
);
2948 frag_now
->fr_fix
= frag_now_fix_octets ();
2949 frag_wane (frag_now
);
2953 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2954 htab_delete (groups
.indexes
);
2956 #ifdef NEED_ECOFF_DEBUG
2957 if (ECOFF_DEBUGGING
)
2958 /* Generate the ECOFF debugging information. */
2960 const struct ecoff_debug_swap
*debug_swap
;
2961 struct ecoff_debug_info debug
;
2966 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2967 know (debug_swap
!= NULL
);
2968 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2970 /* Set up the pointers in debug. */
2971 #define SET(ptr, offset, type) \
2972 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2974 SET (line
, cbLineOffset
, unsigned char *);
2975 SET (external_dnr
, cbDnOffset
, void *);
2976 SET (external_pdr
, cbPdOffset
, void *);
2977 SET (external_sym
, cbSymOffset
, void *);
2978 SET (external_opt
, cbOptOffset
, void *);
2979 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2980 SET (ss
, cbSsOffset
, char *);
2981 SET (external_fdr
, cbFdOffset
, void *);
2982 SET (external_rfd
, cbRfdOffset
, void *);
2983 /* ssext and external_ext are set up just below. */
2987 /* Set up the external symbols. */
2988 debug
.ssext
= debug
.ssext_end
= NULL
;
2989 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2990 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2991 elf_get_extr
, elf_set_index
))
2992 as_fatal (_("failed to set up debugging information: %s"),
2993 bfd_errmsg (bfd_get_error ()));
2995 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2996 gas_assert (sec
!= NULL
);
2998 know (!stdoutput
->output_has_begun
);
3000 /* We set the size of the section, call bfd_set_section_contents
3001 to force the ELF backend to allocate a file position, and then
3002 write out the data. FIXME: Is this really the best way to do
3004 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
3007 /* Pass BUF to bfd_set_section_contents because this will
3008 eventually become a call to fwrite, and ISO C prohibits
3009 passing a NULL pointer to a stdio function even if the
3010 pointer will not be used. */
3011 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3012 as_fatal (_("can't start writing .mdebug section: %s"),
3013 bfd_errmsg (bfd_get_error ()));
3015 know (stdoutput
->output_has_begun
);
3016 know (sec
->filepos
!= 0);
3018 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3020 as_fatal (_("could not write .mdebug section: %s"),
3021 bfd_errmsg (bfd_get_error ()));
3023 #endif /* NEED_ECOFF_DEBUG */
3027 elf_generate_asm_lineno (void)
3029 #ifdef NEED_ECOFF_DEBUG
3030 if (ECOFF_DEBUGGING
)
3031 ecoff_generate_asm_lineno ();
3036 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
3037 int what ATTRIBUTE_UNUSED
,
3038 const char *string ATTRIBUTE_UNUSED
,
3039 int type ATTRIBUTE_UNUSED
,
3040 int other ATTRIBUTE_UNUSED
,
3041 int desc ATTRIBUTE_UNUSED
)
3043 #ifdef NEED_ECOFF_DEBUG
3044 if (ECOFF_DEBUGGING
)
3045 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3050 elf_separate_stab_sections (void)
3052 #ifdef NEED_ECOFF_DEBUG
3053 return (!ECOFF_DEBUGGING
);
3060 elf_init_stab_section (segT seg
)
3062 #ifdef NEED_ECOFF_DEBUG
3063 if (!ECOFF_DEBUGGING
)
3065 obj_elf_init_stab_section (seg
);
3068 const struct format_ops elf_format_ops
=
3070 bfd_target_elf_flavour
,
3071 0, /* dfl_leading_underscore */
3072 1, /* emit_section_symbols */
3077 elf_frob_file_before_adjust
,
3078 0, /* obj_frob_file_before_fix */
3079 elf_frob_file_after_relocs
,
3080 elf_s_get_size
, elf_s_set_size
,
3081 elf_s_get_align
, elf_s_set_align
,
3088 elf_copy_symbol_attributes
,
3089 elf_generate_asm_lineno
,
3091 elf_separate_stab_sections
,
3092 elf_init_stab_section
,
3093 elf_sec_sym_ok_for_reloc
,
3095 #ifdef NEED_ECOFF_DEBUG
3098 0, /* ecoff_set_ext */
3100 elf_obj_read_begin_hook
,
3101 elf_obj_symbol_new_hook
,
3102 elf_obj_symbol_clone_hook
,