1 /* ELF object file format
2 Copyright (C) 1992-2022 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
;
746 /* PR 28054: Set the SEC_ELF_OCTETS flag for debugging sections.
747 Based on the code in bfd/elf.c:_bfd_elf_make_section_from_shdr().
749 FIXME: We do not set the SEC_DEBUGGING flag because that causes
750 problems for the FT32 and MSP430 targets. Investigate and fix. */
751 if ((flags
& SEC_ALLOC
) == 0 && name
[0] == '.')
753 if ( startswith (name
, ".debug")
754 || startswith (name
, ".zdebug")
755 || startswith (name
, ".gnu.debuglto_.debug_")
756 || startswith (name
, ".gnu.linkonce.wi.")
757 || startswith (name
, GNU_BUILD_ATTRS_SECTION_NAME
)
758 || startswith (name
, ".note.gnu"))
759 flags
|= SEC_ELF_OCTETS
;
766 if (type
== SHT_NULL
)
767 type
= bfd_elf_get_default_section_type (flags
);
768 elf_section_type (sec
) = type
;
769 elf_section_flags (sec
) = attr
;
770 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->sh_info
;
772 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
773 if (type
== SHT_NOBITS
)
774 seg_info (sec
)->bss
= 1;
776 /* Set the section ID and flags. */
777 sec
->section_id
= match_p
->section_id
;
778 flags
|= match_p
->flags
;
780 /* Set the linked-to symbol name. */
781 sec
->map_head
.linked_to_symbol_name
782 = match_p
->linked_to_symbol_name
;
784 bfd_set_section_flags (sec
, flags
);
785 if (flags
& SEC_MERGE
)
786 sec
->entsize
= entsize
;
787 elf_group_name (sec
) = match_p
->group_name
;
789 /* Add a symbol for this section to the symbol table. */
790 secsym
= symbol_find (name
);
793 /* We could be repurposing an undefined symbol here: make sure we
794 reset sy_value to look like other section symbols in order to avoid
795 trying to incorrectly resolve this section symbol later on. */
796 static const expressionS exp
= { .X_op
= O_constant
};
797 symbol_set_value_expression (secsym
, &exp
);
798 symbol_set_bfdsym (secsym
, sec
->symbol
);
801 symbol_table_insert (section_symbol (sec
));
806 && (unsigned) type
!= elf_section_type (old_sec
))
809 /* This is a special section with known type. User
810 assembly might get the section type wrong; Even high
811 profile projects like glibc have done so in the past.
812 So don't error in this case. */
813 as_warn (_("ignoring changed section type for %s"), name
);
815 /* Do error when assembly isn't self-consistent. */
816 as_bad (_("changed section type for %s"), name
);
821 /* If section attributes are specified the second time we see a
822 particular section, then check that they are the same as we
823 saw the first time. */
824 if (((old_sec
->flags
^ flags
)
825 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
826 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
827 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
828 | SEC_THREAD_LOCAL
)))
831 as_warn (_("ignoring changed section attributes for %s"), name
);
833 as_bad (_("changed section attributes for %s"), name
);
836 /* FIXME: Maybe we should consider removing a previously set
837 processor or application specific attribute as suspicious? */
838 elf_section_flags (sec
) = attr
;
840 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
841 as_bad (_("changed section entity size for %s"), name
);
845 #ifdef md_elf_section_change_hook
846 md_elf_section_change_hook ();
851 obj_elf_parse_section_letters (char *str
, size_t len
,
852 bool *is_clone
, bfd_vma
*gnu_attr
)
864 if (len
> 1 && str
[1] == 'm')
868 if (len
> 1 && str
[1] == 's')
879 attr
|= SHF_LINK_ORDER
;
885 attr
|= SHF_EXECINSTR
;
900 *gnu_attr
|= SHF_GNU_MBIND
;
903 *gnu_attr
|= SHF_GNU_RETAIN
;
910 const char *bad_msg
= _("unrecognized .section attribute:"
911 " want a,e,o,w,x,M,S,G,T or number");
912 #ifdef md_elf_section_letter
913 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
914 if (md_attr
!= (bfd_vma
) -1)
921 struct elf_backend_data
*bed
;
922 bfd_vma numeric_flags
= strtoul (str
, &end
, 0);
924 attr
|= numeric_flags
;
926 bed
= (struct elf_backend_data
*)
927 get_elf_backend_data (stdoutput
);
929 if (bed
->elf_osabi
== ELFOSABI_NONE
930 || bed
->elf_osabi
== ELFOSABI_STANDALONE
931 || bed
->elf_osabi
== ELFOSABI_GNU
932 || bed
->elf_osabi
== ELFOSABI_FREEBSD
)
934 /* Add flags in the SHF_MASKOS range to gnu_attr for
935 OSABIs that support those flags.
936 Also adding the flags for ELFOSABI_{NONE,STANDALONE}
937 allows them to be validated later in obj_elf_section.
938 We can't just always set these bits in gnu_attr for
939 all OSABIs, since Binutils does not recognize all
940 SHF_MASKOS bits for non-GNU OSABIs. It's therefore
941 possible that numeric flags are being used to set bits
942 in the SHF_MASKOS range for those targets, and we
943 don't want assembly to fail in those situations. */
944 *gnu_attr
|= (numeric_flags
& SHF_MASKOS
);
947 /* Update str and len, allowing for the fact that
948 we will execute str++ and len-- below. */
954 as_fatal ("%s", bad_msg
);
965 obj_elf_section_type (char *str
, size_t len
, bool warn
)
967 if (len
== 8 && startswith (str
, "progbits"))
969 if (len
== 6 && startswith (str
, "nobits"))
971 if (len
== 4 && startswith (str
, "note"))
973 if (len
== 10 && startswith (str
, "init_array"))
974 return SHT_INIT_ARRAY
;
975 if (len
== 10 && startswith (str
, "fini_array"))
976 return SHT_FINI_ARRAY
;
977 if (len
== 13 && startswith (str
, "preinit_array"))
978 return SHT_PREINIT_ARRAY
;
980 #ifdef md_elf_section_type
982 int md_type
= md_elf_section_type (str
, len
);
991 int type
= strtoul (str
, & end
, 0);
993 if (warn
&& (size_t) (end
- str
) != len
)
994 as_warn (_("extraneous characters at end of numeric section type"));
1000 as_warn (_("unrecognized section type"));
1005 obj_elf_section_word (char *str
, size_t len
, int *type
)
1009 if (len
== 5 && startswith (str
, "write"))
1011 if (len
== 5 && startswith (str
, "alloc"))
1013 if (len
== 9 && startswith (str
, "execinstr"))
1014 return SHF_EXECINSTR
;
1015 if (len
== 7 && startswith (str
, "exclude"))
1017 if (len
== 3 && startswith (str
, "tls"))
1020 #ifdef md_elf_section_word
1022 bfd_vma md_attr
= md_elf_section_word (str
, len
);
1028 ret
= obj_elf_section_type (str
, len
, false);
1032 as_warn (_("unrecognized section attribute"));
1037 /* Get name of section. */
1039 obj_elf_section_name (void)
1044 if (*input_line_pointer
== '"')
1048 name
= demand_copy_C_string (&dummy
);
1051 ignore_rest_of_line ();
1057 char *end
= input_line_pointer
;
1059 while (0 == strchr ("\n\t,; ", *end
))
1061 if (end
== input_line_pointer
)
1063 as_bad (_("missing name"));
1064 ignore_rest_of_line ();
1068 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1070 while (flag_sectname_subst
)
1072 char *subst
= strchr (name
, '%');
1073 if (subst
&& subst
[1] == 'S')
1075 int oldlen
= strlen (name
);
1076 int substlen
= strlen (now_seg
->name
);
1077 int newlen
= oldlen
- 2 + substlen
;
1078 char *newname
= XNEWVEC (char, newlen
+ 1);
1079 int headlen
= subst
- name
;
1080 memcpy (newname
, name
, headlen
);
1081 strcpy (newname
+ headlen
, now_seg
->name
);
1082 strcat (newname
+ headlen
, subst
+ 2);
1090 #ifdef tc_canonicalize_section_name
1091 name
= tc_canonicalize_section_name (name
);
1093 input_line_pointer
= end
;
1100 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1102 const char * gname
= obj_elf_section_name ();
1106 as_warn (_("group name not parseable"));
1110 if (elf_group_name (now_seg
))
1112 as_warn (_("section %s already has a group (%s)"),
1113 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1117 elf_group_name (now_seg
) = xstrdup (gname
);
1118 elf_section_flags (now_seg
) |= SHF_GROUP
;
1122 obj_elf_section (int push
)
1131 subsegT new_subsection
= -1;
1132 struct elf_section_match match
;
1133 unsigned long linked_to_section_index
= -1UL;
1139 #ifdef md_flush_pending_output
1140 md_flush_pending_output ();
1143 obj_elf_section_change_hook ();
1145 s_mri_sect (&mri_type
);
1147 #ifdef md_elf_section_change_hook
1148 md_elf_section_change_hook ();
1154 name
= obj_elf_section_name ();
1158 memset (&match
, 0, sizeof (match
));
1161 if ((sym
= symbol_find (name
)) != NULL
1162 && ! symbol_section_p (sym
)
1163 && S_IS_DEFINED (sym
)
1164 && ! S_IS_VOLATILE (sym
)
1165 && ! S_CAN_BE_REDEFINED (sym
))
1167 as_bad (_("section name '%s' already defined as another symbol"), name
);
1168 ignore_rest_of_line ();
1177 if (*input_line_pointer
== ',')
1179 /* Skip the comma. */
1180 ++input_line_pointer
;
1183 if (push
&& ISDIGIT (*input_line_pointer
))
1185 /* .pushsection has an optional subsection. */
1186 new_subsection
= (subsegT
) get_absolute_expression ();
1190 /* Stop if we don't see a comma. */
1191 if (*input_line_pointer
!= ',')
1194 /* Skip the comma. */
1195 ++input_line_pointer
;
1199 if (*input_line_pointer
== '"')
1203 beg
= demand_copy_C_string (&dummy
);
1206 ignore_rest_of_line ();
1209 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1210 &is_clone
, &gnu_attr
);
1213 if (*input_line_pointer
== ',')
1216 char *save
= input_line_pointer
;
1218 ++input_line_pointer
;
1220 c
= *input_line_pointer
;
1223 beg
= demand_copy_C_string (&dummy
);
1226 ignore_rest_of_line ();
1229 type
= obj_elf_section_type (beg
, strlen (beg
), true);
1231 else if (c
== '@' || c
== '%')
1233 ++input_line_pointer
;
1235 if (ISDIGIT (* input_line_pointer
))
1236 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1239 c
= get_symbol_name (& beg
);
1240 (void) restore_line_pointer (c
);
1241 type
= obj_elf_section_type (beg
,
1242 input_line_pointer
- beg
,
1247 input_line_pointer
= save
;
1251 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1253 ++input_line_pointer
;
1255 entsize
= get_absolute_expression ();
1259 as_warn (_("invalid merge entity size"));
1264 else if ((attr
& SHF_MERGE
) != 0)
1266 as_warn (_("entity size for SHF_MERGE not specified"));
1270 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1272 ++input_line_pointer
;
1274 /* Check for a numeric section index, rather than a symbol name. */
1275 if (ISDIGIT (* input_line_pointer
))
1277 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1282 unsigned int length
;
1284 c
= get_symbol_name (& beg
);
1285 (void) restore_line_pointer (c
);
1286 length
= input_line_pointer
- beg
;
1288 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1292 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1294 as_warn (_("? section flag ignored with G present"));
1298 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1300 ++input_line_pointer
;
1301 match
.group_name
= obj_elf_section_name ();
1302 if (match
.group_name
== NULL
)
1304 else if (*input_line_pointer
== ',')
1306 ++input_line_pointer
;
1308 if (startswith (input_line_pointer
, "comdat"))
1310 input_line_pointer
+= 6;
1314 else if (startswith (name
, ".gnu.linkonce"))
1317 else if ((attr
& SHF_GROUP
) != 0)
1319 as_warn (_("group name for SHF_GROUP not specified"));
1325 const char *now_group
= elf_group_name (now_seg
);
1326 if (now_group
!= NULL
)
1328 match
.group_name
= xstrdup (now_group
);
1329 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1333 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1335 char *save
= input_line_pointer
;
1336 ++input_line_pointer
;
1338 if (ISDIGIT (* input_line_pointer
))
1340 char *t
= input_line_pointer
;
1341 match
.sh_info
= strtoul (input_line_pointer
,
1342 &input_line_pointer
, 0);
1343 if (match
.sh_info
== (unsigned int) -1)
1345 as_warn (_("unsupported mbind section info: %s"), t
);
1350 input_line_pointer
= save
;
1353 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1354 match
.sh_flags
|= SHF_GNU_RETAIN
;
1356 if (*input_line_pointer
== ',')
1358 char *save
= input_line_pointer
;
1360 ++input_line_pointer
;
1362 if (startswith (input_line_pointer
, "unique"))
1364 input_line_pointer
+= 6;
1366 if (*input_line_pointer
== ',')
1368 ++input_line_pointer
;
1370 if (ISDIGIT (* input_line_pointer
))
1374 char *t
= input_line_pointer
;
1375 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1378 id
= strtoul (input_line_pointer
,
1379 &input_line_pointer
, 0);
1380 overflow
= (id
== (unsigned long) -1
1381 && errno
== ERANGE
);
1386 (input_line_pointer
,
1387 (const char **) &input_line_pointer
, 0);
1388 overflow
= id
== ~(bfd_vma
) 0;
1390 if (overflow
|| id
> (unsigned int) -1)
1392 char *linefeed
, saved_char
= 0;
1393 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1395 saved_char
= *linefeed
;
1398 as_bad (_("unsupported section id: %s"), t
);
1400 *linefeed
= saved_char
;
1404 match
.section_id
= id
;
1405 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1411 input_line_pointer
= save
;
1421 if (*input_line_pointer
!= '#')
1423 as_bad (_("character following name is not '#'"));
1424 ignore_rest_of_line ();
1427 ++input_line_pointer
;
1428 c
= get_symbol_name (& beg
);
1429 (void) restore_line_pointer (c
);
1431 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1436 while (*input_line_pointer
++ == ',');
1437 --input_line_pointer
;
1442 demand_empty_rest_of_line ();
1444 if ((gnu_attr
& (SHF_GNU_MBIND
| SHF_GNU_RETAIN
)) != 0)
1446 const struct elf_backend_data
*bed
;
1447 bool mbind_p
= (gnu_attr
& SHF_GNU_MBIND
) != 0;
1449 if (mbind_p
&& (attr
& SHF_ALLOC
) == 0)
1450 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1452 bed
= get_elf_backend_data (stdoutput
);
1454 if (bed
->elf_osabi
!= ELFOSABI_GNU
1455 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
1456 && bed
->elf_osabi
!= ELFOSABI_NONE
)
1457 as_bad (_("%s section is supported only by GNU and FreeBSD targets"),
1458 mbind_p
? "GNU_MBIND" : "GNU_RETAIN");
1462 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1463 if ((gnu_attr
& SHF_GNU_RETAIN
) != 0)
1464 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_retain
;
1470 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1473 if (linked_to_section_index
!= -1UL)
1475 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1476 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1477 /* FIXME: Should we perform some sanity checking on the section index ? */
1480 if (push
&& new_subsection
!= -1)
1481 subseg_set (now_seg
, new_subsection
);
1484 /* Change to the .bss section. */
1487 obj_elf_bss (int i ATTRIBUTE_UNUSED
)
1491 #ifdef md_flush_pending_output
1492 md_flush_pending_output ();
1495 obj_elf_section_change_hook ();
1497 temp
= get_absolute_expression ();
1498 subseg_set (bss_section
, (subsegT
) temp
);
1499 demand_empty_rest_of_line ();
1501 #ifdef md_elf_section_change_hook
1502 md_elf_section_change_hook ();
1506 /* Change to the .data section. */
1509 obj_elf_data (int i
)
1511 #ifdef md_flush_pending_output
1512 md_flush_pending_output ();
1515 obj_elf_section_change_hook ();
1519 #ifdef md_elf_section_change_hook
1520 md_elf_section_change_hook ();
1524 /* Change to the .text section. */
1527 obj_elf_text (int i
)
1529 #ifdef md_flush_pending_output
1530 md_flush_pending_output ();
1533 obj_elf_section_change_hook ();
1537 #ifdef md_elf_section_change_hook
1538 md_elf_section_change_hook ();
1542 /* Change to the *ABS* section. */
1545 obj_elf_struct (int i
)
1547 #ifdef md_flush_pending_output
1548 md_flush_pending_output ();
1551 obj_elf_section_change_hook ();
1555 #ifdef md_elf_section_change_hook
1556 md_elf_section_change_hook ();
1561 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1565 #ifdef md_flush_pending_output
1566 md_flush_pending_output ();
1569 obj_elf_section_change_hook ();
1571 temp
= get_absolute_expression ();
1572 subseg_set (now_seg
, (subsegT
) temp
);
1573 demand_empty_rest_of_line ();
1575 #ifdef md_elf_section_change_hook
1576 md_elf_section_change_hook ();
1580 /* This can be called from the processor backends if they change
1584 obj_elf_section_change_hook (void)
1586 previous_section
= now_seg
;
1587 previous_subsection
= now_subseg
;
1591 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1596 if (previous_section
== 0)
1598 as_warn (_(".previous without corresponding .section; ignored"));
1602 #ifdef md_flush_pending_output
1603 md_flush_pending_output ();
1606 new_section
= previous_section
;
1607 new_subsection
= previous_subsection
;
1608 obj_elf_section_change_hook ();
1610 subseg_set (new_section
, new_subsection
);
1612 #ifdef md_elf_section_change_hook
1613 md_elf_section_change_hook ();
1618 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1620 struct section_stack
*top
= section_stack
;
1624 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1628 #ifdef md_flush_pending_output
1629 md_flush_pending_output ();
1632 section_stack
= top
->next
;
1633 previous_section
= top
->prev_seg
;
1634 previous_subsection
= top
->prev_subseg
;
1635 subseg_set (top
->seg
, top
->subseg
);
1638 #ifdef md_elf_section_change_hook
1639 md_elf_section_change_hook ();
1644 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1646 /* Assume delimiter is part of expression. BSD4.2 as fails with
1647 delightful bug, so we are not being incompatible here. */
1648 new_logical_line (NULL
, get_absolute_expression ());
1649 demand_empty_rest_of_line ();
1652 static struct elf_versioned_name_list
*
1653 obj_elf_find_and_add_versioned_name (const char *version_name
,
1654 const char *sym_name
,
1656 struct elf_obj_sy
*sy_obj
)
1658 struct elf_versioned_name_list
*versioned_name
;
1661 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1664 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1665 names, we have to disable this. */
1666 if (0 && *p
== '\0')
1668 as_bad (_("missing version name in `%s' for symbol `%s'"),
1669 version_name
, sym_name
);
1673 versioned_name
= sy_obj
->versioned_name
;
1683 if (strcmp (versioned_name
->name
, version_name
) == 0)
1684 return versioned_name
;
1687 as_bad (_("only one version name with `@@@' is allowed "
1688 "for symbol `%s'"), sym_name
);
1692 sy_obj
->rename
= true;
1695 as_bad (_("invalid version name '%s' for symbol `%s'"),
1696 version_name
, sym_name
);
1701 versioned_name
!= NULL
;
1702 versioned_name
= versioned_name
->next
)
1703 if (strcmp (versioned_name
->name
, version_name
) == 0)
1704 return versioned_name
;
1706 /* Add this versioned name to the head of the list, */
1707 versioned_name
= (struct elf_versioned_name_list
*)
1708 xmalloc (sizeof (*versioned_name
));
1709 versioned_name
->name
= xstrdup (version_name
);
1710 versioned_name
->next
= sy_obj
->versioned_name
;
1711 sy_obj
->versioned_name
= versioned_name
;
1713 return versioned_name
;
1716 /* This handles the .symver pseudo-op, which is used to specify a
1717 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1718 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1719 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1720 with the same value as the symbol NAME. */
1723 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1726 const char *sym_name
;
1730 struct elf_obj_sy
*sy_obj
;
1733 sym
= get_sym_from_input_line_and_check ();
1735 if (*input_line_pointer
!= ',')
1737 as_bad (_("expected comma after name in .symver"));
1738 ignore_rest_of_line ();
1742 ++input_line_pointer
;
1745 /* Temporarily include '@' in symbol names. */
1746 old_lexat
= lex_type
[(unsigned char) '@'];
1747 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1748 c
= get_symbol_name (& name
);
1749 lex_type
[(unsigned char) '@'] = old_lexat
;
1750 sym_name
= S_GET_NAME (sym
);
1752 if (S_IS_COMMON (sym
))
1754 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1756 ignore_rest_of_line ();
1760 p
= strchr (name
, ELF_VER_CHR
);
1763 as_bad (_("missing version name in `%s' for symbol `%s'"),
1765 ignore_rest_of_line ();
1769 sy_obj
= symbol_get_obj (sym
);
1770 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1773 sy_obj
->bad_version
= true;
1774 ignore_rest_of_line ();
1778 (void) restore_line_pointer (c
);
1780 if (*input_line_pointer
== ',')
1782 char *save
= input_line_pointer
;
1784 ++input_line_pointer
;
1786 if (startswith (input_line_pointer
, "local"))
1788 input_line_pointer
+= 5;
1789 sy_obj
->visibility
= visibility_local
;
1791 else if (startswith (input_line_pointer
, "hidden"))
1793 input_line_pointer
+= 6;
1794 sy_obj
->visibility
= visibility_hidden
;
1796 else if (startswith (input_line_pointer
, "remove"))
1798 input_line_pointer
+= 6;
1799 sy_obj
->visibility
= visibility_remove
;
1802 input_line_pointer
= save
;
1805 demand_empty_rest_of_line ();
1808 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1809 to the linker the hierarchy in which a particular table resides. The
1810 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1813 obj_elf_get_vtable_inherit (void)
1815 char *cname
, *pname
;
1816 symbolS
*csym
, *psym
;
1819 if (*input_line_pointer
== '#')
1820 ++input_line_pointer
;
1822 c
= get_symbol_name (& cname
);
1823 csym
= symbol_find (cname
);
1825 /* GCFIXME: should check that we don't have two .vtable_inherits for
1826 the same child symbol. Also, we can currently only do this if the
1827 child symbol is already exists and is placed in a fragment. */
1829 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1831 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1836 *input_line_pointer
= c
;
1838 SKIP_WHITESPACE_AFTER_NAME ();
1839 if (*input_line_pointer
!= ',')
1841 as_bad (_("expected comma after name in .vtable_inherit"));
1842 ignore_rest_of_line ();
1846 ++input_line_pointer
;
1849 if (*input_line_pointer
== '#')
1850 ++input_line_pointer
;
1852 if (input_line_pointer
[0] == '0'
1853 && (input_line_pointer
[1] == '\0'
1854 || ISSPACE (input_line_pointer
[1])))
1856 psym
= section_symbol (absolute_section
);
1857 ++input_line_pointer
;
1861 c
= get_symbol_name (& pname
);
1862 psym
= symbol_find_or_make (pname
);
1863 restore_line_pointer (c
);
1866 demand_empty_rest_of_line ();
1871 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1872 return fix_new (symbol_get_frag (csym
),
1873 symbol_get_value_expression (csym
)->X_add_number
,
1874 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1877 /* This is a version of obj_elf_get_vtable_inherit() that is
1878 suitable for use in struct _pseudo_type tables. */
1881 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1883 (void) obj_elf_get_vtable_inherit ();
1886 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1887 to the linker that a vtable slot was used. The syntax is
1888 ".vtable_entry tablename, offset". */
1891 obj_elf_get_vtable_entry (void)
1896 if (*input_line_pointer
== '#')
1897 ++input_line_pointer
;
1899 sym
= get_sym_from_input_line_and_check ();
1900 if (*input_line_pointer
!= ',')
1902 as_bad (_("expected comma after name in .vtable_entry"));
1903 ignore_rest_of_line ();
1907 ++input_line_pointer
;
1908 if (*input_line_pointer
== '#')
1909 ++input_line_pointer
;
1911 offset
= get_absolute_expression ();
1913 demand_empty_rest_of_line ();
1915 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1916 BFD_RELOC_VTABLE_ENTRY
);
1919 /* This is a version of obj_elf_get_vtable_entry() that is
1920 suitable for use in struct _pseudo_type tables. */
1923 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1925 (void) obj_elf_get_vtable_entry ();
1928 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1931 skip_past_char (char ** str
, char c
)
1941 #define skip_past_comma(str) skip_past_char (str, ',')
1943 /* A list of attributes that have been explicitly set by the assembly code.
1944 VENDOR is the vendor id, BASE is the tag shifted right by the number
1945 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1946 struct recorded_attribute_info
{
1947 struct recorded_attribute_info
*next
;
1952 static struct recorded_attribute_info
*recorded_attributes
;
1954 /* Record that we have seen an explicit specification of attribute TAG
1955 for vendor VENDOR. */
1958 record_attribute (int vendor
, unsigned int tag
)
1962 struct recorded_attribute_info
*rai
;
1964 base
= tag
/ (8 * sizeof (rai
->mask
));
1965 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1966 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1967 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1973 rai
= XNEW (struct recorded_attribute_info
);
1974 rai
->next
= recorded_attributes
;
1975 rai
->vendor
= vendor
;
1978 recorded_attributes
= rai
;
1981 /* Return true if we have seen an explicit specification of attribute TAG
1982 for vendor VENDOR. */
1985 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1989 struct recorded_attribute_info
*rai
;
1991 base
= tag
/ (8 * sizeof (rai
->mask
));
1992 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1993 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1994 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1995 return (rai
->mask
& mask
) != 0;
1999 /* Parse an attribute directive for VENDOR.
2000 Returns the attribute number read, or zero on error. */
2003 obj_elf_vendor_attribute (int vendor
)
2011 /* Read the first number or name. */
2012 skip_whitespace (input_line_pointer
);
2013 s
= input_line_pointer
;
2014 if (ISDIGIT (*input_line_pointer
))
2017 if (exp
.X_op
!= O_constant
)
2019 tag
= exp
.X_add_number
;
2025 /* A name may contain '_', but no other punctuation. */
2026 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
2027 ++input_line_pointer
)
2032 name
= xstrndup (s
, i
);
2034 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2035 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2038 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
2041 as_bad (_("Attribute name not recognised: %s"), name
);
2042 ignore_rest_of_line ();
2049 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
2051 if (skip_past_comma (&input_line_pointer
) == -1)
2056 if (exp
.X_op
!= O_constant
)
2058 as_bad (_("expected numeric constant"));
2059 ignore_rest_of_line ();
2062 i
= exp
.X_add_number
;
2065 && skip_past_comma (&input_line_pointer
) == -1)
2067 as_bad (_("expected comma"));
2068 ignore_rest_of_line ();
2075 skip_whitespace (input_line_pointer
);
2076 if (*input_line_pointer
!= '"')
2078 s
= demand_copy_C_string (&len
);
2081 record_attribute (vendor
, tag
);
2085 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2088 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2091 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2097 demand_empty_rest_of_line ();
2100 as_bad (_("bad string constant"));
2101 ignore_rest_of_line ();
2104 as_bad (_("expected <tag> , <value>"));
2105 ignore_rest_of_line ();
2109 /* Parse a .gnu_attribute directive. */
2112 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2114 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2118 elf_obj_read_begin_hook (void)
2120 #ifdef NEED_ECOFF_DEBUG
2121 if (ECOFF_DEBUGGING
)
2122 ecoff_read_begin_hook ();
2127 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2129 struct elf_obj_sy
*sy_obj
;
2131 sy_obj
= symbol_get_obj (symbolP
);
2132 sy_obj
->size
= NULL
;
2133 sy_obj
->versioned_name
= NULL
;
2135 #ifdef NEED_ECOFF_DEBUG
2136 if (ECOFF_DEBUGGING
)
2137 ecoff_symbol_new_hook (symbolP
);
2141 /* Deduplicate size expressions. We might get into trouble with
2142 multiple freeing or use after free if we leave them pointing to the
2143 same expressionS. */
2146 elf_obj_symbol_clone_hook (symbolS
*newsym
, symbolS
*orgsym ATTRIBUTE_UNUSED
)
2148 struct elf_obj_sy
*newelf
= symbol_get_obj (newsym
);
2151 expressionS
*exp
= XNEW (expressionS
);
2152 *exp
= *newelf
->size
;
2158 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2160 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2161 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2162 /* If size is unset, copy size from src. Because we don't track whether
2163 .size has been used, we can't differentiate .size dest, 0 from the case
2164 where dest's size is unset. */
2165 if (!destelf
->size
&& S_GET_SIZE (dest
) == 0)
2169 destelf
->size
= XNEW (expressionS
);
2170 *destelf
->size
= *srcelf
->size
;
2172 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2174 /* Don't copy visibility. */
2175 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2176 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2180 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2185 asection
*seg
= now_seg
;
2186 subsegT subseg
= now_subseg
;
2187 Elf_Internal_Note i_note
;
2188 Elf_External_Note e_note
;
2189 asection
*note_secp
= NULL
;
2192 if (*input_line_pointer
== '\"')
2196 ++input_line_pointer
; /* -> 1st char of string. */
2197 name
= input_line_pointer
;
2199 while (is_a_char (c
= next_char_of_string ()))
2201 c
= *input_line_pointer
;
2202 *input_line_pointer
= '\0';
2203 *(input_line_pointer
- 1) = '\0';
2204 *input_line_pointer
= c
;
2206 /* Create the .note section. */
2207 note_secp
= subseg_new (".note", 0);
2208 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2209 record_alignment (note_secp
, 2);
2211 /* Process the version string. */
2212 len
= strlen (name
) + 1;
2214 /* PR 3456: Although the name field is padded out to an 4-byte
2215 boundary, the namesz field should not be adjusted. */
2216 i_note
.namesz
= len
;
2217 i_note
.descsz
= 0; /* No description. */
2218 i_note
.type
= NT_VERSION
;
2219 p
= frag_more (sizeof (e_note
.namesz
));
2220 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2221 p
= frag_more (sizeof (e_note
.descsz
));
2222 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2223 p
= frag_more (sizeof (e_note
.type
));
2224 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2225 p
= frag_more (len
);
2226 memcpy (p
, name
, len
);
2228 frag_align (2, 0, 0);
2230 subseg_set (seg
, subseg
);
2233 as_bad (_("expected quoted string"));
2235 demand_empty_rest_of_line ();
2239 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2242 char c
= get_symbol_name (&name
);
2247 p
= input_line_pointer
;
2249 SKIP_WHITESPACE_AFTER_NAME ();
2250 if (*input_line_pointer
!= ',')
2253 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2255 ignore_rest_of_line ();
2258 input_line_pointer
++;
2260 if (exp
.X_op
== O_absent
)
2262 as_bad (_("missing expression in .size directive"));
2263 exp
.X_op
= O_constant
;
2264 exp
.X_add_number
= 0;
2267 sym
= symbol_find_or_make (name
);
2269 if (exp
.X_op
== O_constant
)
2271 S_SET_SIZE (sym
, exp
.X_add_number
);
2272 xfree (symbol_get_obj (sym
)->size
);
2273 symbol_get_obj (sym
)->size
= NULL
;
2277 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2278 *symbol_get_obj (sym
)->size
= exp
;
2280 demand_empty_rest_of_line ();
2283 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2284 There are six syntaxes:
2286 The first (used on Solaris) is
2288 The second (used on UnixWare) is
2290 The third (reportedly to be used on Irix 6.0) is
2292 The fourth (used on NetBSD/Arm and Linux/ARM) is
2294 The fifth (used on SVR4/860) is
2295 .type SYM,"function"
2296 The sixth (emitted by recent SunPRO under Solaris) is
2298 where the integer is the STT_* value.
2302 obj_elf_type_name (char *cp
)
2306 p
= input_line_pointer
;
2307 if (*input_line_pointer
>= '0'
2308 && *input_line_pointer
<= '9')
2310 while (*input_line_pointer
>= '0'
2311 && *input_line_pointer
<= '9')
2312 ++input_line_pointer
;
2313 *cp
= *input_line_pointer
;
2314 *input_line_pointer
= '\0';
2317 *cp
= get_symbol_name (&p
);
2323 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2327 const char *type_name
;
2329 elf_symbol_type
*elfsym
;
2331 sym
= get_sym_from_input_line_and_check ();
2332 c
= *input_line_pointer
;
2333 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2335 if (*input_line_pointer
== ',')
2336 ++input_line_pointer
;
2339 if ( *input_line_pointer
== '#'
2340 || *input_line_pointer
== '@'
2341 || *input_line_pointer
== '"'
2342 || *input_line_pointer
== '%')
2343 ++input_line_pointer
;
2345 type_name
= obj_elf_type_name (& c
);
2348 if (strcmp (type_name
, "function") == 0
2349 || strcmp (type_name
, "2") == 0
2350 || strcmp (type_name
, "STT_FUNC") == 0)
2351 type
= BSF_FUNCTION
;
2352 else if (strcmp (type_name
, "object") == 0
2353 || strcmp (type_name
, "1") == 0
2354 || strcmp (type_name
, "STT_OBJECT") == 0)
2356 else if (strcmp (type_name
, "tls_object") == 0
2357 || strcmp (type_name
, "6") == 0
2358 || strcmp (type_name
, "STT_TLS") == 0)
2359 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2360 else if (strcmp (type_name
, "notype") == 0
2361 || strcmp (type_name
, "0") == 0
2362 || strcmp (type_name
, "STT_NOTYPE") == 0)
2364 else if (strcmp (type_name
, "common") == 0
2365 || strcmp (type_name
, "5") == 0
2366 || strcmp (type_name
, "STT_COMMON") == 0)
2370 if (! S_IS_COMMON (sym
))
2372 if (S_IS_VOLATILE (sym
))
2374 sym
= symbol_clone (sym
, 1);
2375 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2376 S_SET_VALUE (sym
, 0);
2377 S_SET_EXTERNAL (sym
);
2378 symbol_set_frag (sym
, &zero_address_frag
);
2379 S_CLEAR_VOLATILE (sym
);
2381 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2382 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2385 /* FIXME: Is it safe to just change the section ? */
2386 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2387 S_SET_VALUE (sym
, 0);
2388 S_SET_EXTERNAL (sym
);
2392 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2393 || strcmp (type_name
, "10") == 0
2394 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2396 const struct elf_backend_data
*bed
;
2398 bed
= get_elf_backend_data (stdoutput
);
2399 if (bed
->elf_osabi
!= ELFOSABI_NONE
2400 && bed
->elf_osabi
!= ELFOSABI_GNU
2401 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2402 as_bad (_("symbol type \"%s\" is supported only by GNU "
2403 "and FreeBSD targets"), type_name
);
2404 /* MIPS targets do not support IFUNCS. */
2405 else if (bed
->target_id
== MIPS_ELF_DATA
)
2406 as_bad (_("symbol type \"%s\" is not supported by "
2407 "MIPS targets"), type_name
);
2408 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2409 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2411 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2413 const struct elf_backend_data
*bed
;
2415 bed
= get_elf_backend_data (stdoutput
);
2416 if (bed
->elf_osabi
!= ELFOSABI_NONE
2417 && bed
->elf_osabi
!= ELFOSABI_GNU
)
2418 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2420 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2421 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2423 #ifdef md_elf_symbol_type
2424 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2428 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2430 *input_line_pointer
= c
;
2432 if (*input_line_pointer
== '"')
2433 ++input_line_pointer
;
2435 #ifdef md_elf_symbol_type_change
2436 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2439 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2441 if (type
!= BSF_FUNCTION
)
2442 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2443 if (type
!= BSF_OBJECT
)
2445 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2447 if (S_IS_COMMON (sym
))
2449 as_bad (_("cannot change type of common symbol '%s'"),
2455 /* Don't warn when changing to STT_NOTYPE. */
2458 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2460 if (new != (elfsym
->symbol
.flags
| type
))
2461 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2462 elfsym
->symbol
.flags
= new;
2465 elfsym
->symbol
.flags
&= ~mask
;
2468 demand_empty_rest_of_line ();
2472 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2474 static segT comment_section
;
2475 segT old_section
= now_seg
;
2476 int old_subsection
= now_subseg
;
2478 #ifdef md_flush_pending_output
2479 md_flush_pending_output ();
2482 if (!comment_section
)
2485 comment_section
= subseg_new (".comment", 0);
2486 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2487 | SEC_MERGE
| SEC_STRINGS
));
2488 comment_section
->entsize
= 1;
2489 #ifdef md_elf_section_change_hook
2490 md_elf_section_change_hook ();
2496 subseg_set (comment_section
, 0);
2498 subseg_set (old_section
, old_subsection
);
2501 #ifdef INIT_STAB_SECTION
2503 /* The first entry in a .stabs section is special. */
2506 obj_elf_init_stab_section (segT seg
)
2511 unsigned int stroff
;
2513 /* Force the section to align to a longword boundary. Without this,
2514 UnixWare ar crashes. */
2515 bfd_set_section_alignment (seg
, 2);
2517 /* Make space for this first symbol. */
2521 file
= remap_debug_filename (as_where (NULL
));
2522 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2523 stroff
= get_stab_string_offset (file
, stabstr_name
, true);
2524 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2525 md_number_to_chars (p
, stroff
, 4);
2526 seg_info (seg
)->stabu
.p
= p
;
2527 xfree ((char *) file
);
2532 /* Fill in the counts in the first entry in a .stabs section. */
2535 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2542 if (!startswith (sec
->name
, ".stab"))
2544 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2547 name
= concat (sec
->name
, "str", NULL
);
2548 strsec
= bfd_get_section_by_name (abfd
, name
);
2550 strsz
= bfd_section_size (strsec
);
2553 nsyms
= bfd_section_size (sec
) / 12 - 1;
2555 p
= seg_info (sec
)->stabu
.p
;
2556 gas_assert (p
!= 0);
2558 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2559 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2563 #ifdef NEED_ECOFF_DEBUG
2565 /* This function is called by the ECOFF code. It is supposed to
2566 record the external symbol information so that the backend can
2567 write it out correctly. The ELF backend doesn't actually handle
2568 this at the moment, so we do it ourselves. We save the information
2571 #ifdef OBJ_MAYBE_ELF
2575 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2577 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2580 /* This function is called by bfd_ecoff_debug_externals. It is
2581 supposed to *EXT to the external symbol information, and return
2582 whether the symbol should be used at all. */
2585 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2587 if (sym
->udata
.p
== NULL
)
2589 *ext
= *(EXTR
*) sym
->udata
.p
;
2593 /* This function is called by bfd_ecoff_debug_externals. It has
2594 nothing to do for ELF. */
2597 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2598 bfd_size_type indx ATTRIBUTE_UNUSED
)
2602 #endif /* NEED_ECOFF_DEBUG */
2605 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2607 struct elf_obj_sy
*sy_obj
;
2609 struct elf_versioned_name_list
*versioned_name
;
2611 #ifdef NEED_ECOFF_DEBUG
2612 if (ECOFF_DEBUGGING
)
2613 ecoff_frob_symbol (symp
);
2616 sy_obj
= symbol_get_obj (symp
);
2618 size
= sy_obj
->size
;
2621 if (resolve_expression (size
)
2622 && size
->X_op
== O_constant
)
2623 S_SET_SIZE (symp
, size
->X_add_number
);
2626 if (!flag_allow_nonconst_size
)
2627 as_bad (_(".size expression for %s "
2628 "does not evaluate to a constant"), S_GET_NAME (symp
));
2630 as_warn (_(".size expression for %s "
2631 "does not evaluate to a constant"), S_GET_NAME (symp
));
2633 free (sy_obj
->size
);
2634 sy_obj
->size
= NULL
;
2637 versioned_name
= sy_obj
->versioned_name
;
2640 /* This symbol was given a new name with the .symver directive.
2641 If this is an external reference, just rename the symbol to
2642 include the version string. This will make the relocs be
2643 against the correct versioned symbol. */
2645 /* We will have already reported an version error. */
2646 if (sy_obj
->bad_version
)
2648 /* elf_frob_file_before_adjust only allows one version symbol for
2650 else if (sy_obj
->rename
)
2651 S_SET_NAME (symp
, versioned_name
->name
);
2652 else if (S_IS_COMMON (symp
))
2654 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2655 versioned_name
->name
, S_GET_NAME (symp
));
2661 elf_symbol_type
*elfsym
;
2663 /* This is a definition. Add an alias for each version.
2664 FIXME: Using an alias will permit the debugging information
2665 to refer to the right symbol. However, it's not clear
2666 whether it is the best approach. */
2668 /* FIXME: Creating a new symbol here is risky. We're
2669 in the final loop over the symbol table. We can
2670 get away with it only because the symbol goes to
2671 the end of the list, where the loop will still see
2672 it. It would probably be better to do this in
2673 obj_frob_file_before_adjust. */
2674 for (; versioned_name
!= NULL
;
2675 versioned_name
= versioned_name
->next
)
2677 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2679 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2681 /* Subtracting out the frag address here is a hack
2682 because we are in the middle of the final loop. */
2685 - (symbol_get_frag (symp
)->fr_address
2686 / OCTETS_PER_BYTE
)));
2688 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2690 /* This will copy over the size information. */
2691 copy_symbol_attributes (symp2
, symp
);
2693 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2695 if (S_IS_WEAK (symp
))
2698 if (S_IS_EXTERNAL (symp
))
2699 S_SET_EXTERNAL (symp2
);
2702 switch (sy_obj
->visibility
)
2704 case visibility_unchanged
:
2706 case visibility_hidden
:
2707 bfdsym
= symbol_get_bfdsym (symp
);
2708 elfsym
= elf_symbol_from (bfdsym
);
2709 elfsym
->internal_elf_sym
.st_other
&= ~3;
2710 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2712 case visibility_remove
:
2713 /* Don't remove the symbol if it is used in relocation.
2714 Instead, mark it as to be removed and issue an error
2715 if the symbol has more than one versioned name. */
2716 if (symbol_used_in_reloc_p (symp
))
2718 if (sy_obj
->versioned_name
->next
!= NULL
)
2719 as_bad (_("symbol '%s' with multiple versions cannot be used in relocation"),
2721 symbol_mark_removed (symp
);
2724 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2726 case visibility_local
:
2727 S_CLEAR_EXTERNAL (symp
);
2733 /* Double check weak symbols. */
2734 if (S_IS_WEAK (symp
))
2736 if (S_IS_COMMON (symp
))
2737 as_bad (_("symbol `%s' can not be both weak and common"),
2742 /* Fix up SYMPP which has been marked to be removed by .symver. */
2745 elf_fixup_removed_symbol (symbolS
**sympp
)
2747 symbolS
*symp
= *sympp
;
2748 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2750 /* Replace the removed symbol with the versioned symbol. */
2751 symp
= symbol_find (sy_obj
->versioned_name
->name
);
2757 asection
**head
; /* Section lists. */
2758 unsigned int num_group
; /* Number of lists. */
2759 htab_t indexes
; /* Maps group name to index in head array. */
2762 static struct group_list groups
;
2764 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2765 add it to a list of sections belonging to the group. INF is a
2766 pointer to a struct group_list, which is where we store the head of
2767 each list. If its link_to_symbol_name isn't NULL, set up its
2768 linked-to section. */
2771 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2772 asection
*sec
, void *inf
)
2774 struct group_list
*list
= (struct group_list
*) inf
;
2775 const char *group_name
= elf_group_name (sec
);
2777 unsigned int *elem_idx
;
2778 unsigned int *idx_ptr
;
2780 if (sec
->map_head
.linked_to_symbol_name
)
2782 symbolS
*linked_to_sym
;
2783 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2784 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2785 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2786 sec
->map_head
.linked_to_symbol_name
,
2787 bfd_section_name (sec
));
2789 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2792 if (group_name
== NULL
)
2795 /* If this group already has a list, add the section to the head of
2797 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2798 if (elem_idx
!= NULL
)
2800 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2801 list
->head
[*elem_idx
] = sec
;
2805 /* New group. Make the arrays bigger in chunks to minimize calls to
2807 i
= list
->num_group
;
2810 unsigned int newsize
= i
+ 128;
2811 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2813 list
->head
[i
] = sec
;
2814 list
->num_group
+= 1;
2816 /* Add index to hash. */
2817 idx_ptr
= XNEW (unsigned int);
2819 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2823 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2825 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2826 free ((char *)tuple
->value
);
2830 /* Create symbols for group signature. */
2833 elf_adjust_symtab (void)
2837 /* Go find section groups. */
2838 groups
.num_group
= 0;
2840 groups
.indexes
= str_htab_create ();
2841 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2844 /* Make the SHT_GROUP sections that describe each section group. We
2845 can't set up the section contents here yet, because elf section
2846 indices have yet to be calculated. elf.c:set_group_contents does
2847 the rest of the work. */
2848 for (i
= 0; i
< groups
.num_group
; i
++)
2850 const char *group_name
= elf_group_name (groups
.head
[i
]);
2851 const char *sec_name
;
2856 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2857 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2858 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2860 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2861 if (s
!= groups
.head
[i
])
2863 as_warn (_("assuming all members of group `%s' are COMDAT"),
2869 sec_name
= ".group";
2870 s
= subseg_force_new (sec_name
, 0);
2872 || !bfd_set_section_flags (s
, flags
)
2873 || !bfd_set_section_alignment (s
, 2))
2875 as_fatal (_("can't create group: %s"),
2876 bfd_errmsg (bfd_get_error ()));
2878 elf_section_type (s
) = SHT_GROUP
;
2880 /* Pass a pointer to the first section in this group. */
2881 elf_next_in_group (s
) = groups
.head
[i
];
2882 elf_sec_group (groups
.head
[i
]) = s
;
2883 /* Make sure that the signature symbol for the group has the
2884 name of the group. */
2885 sy
= symbol_find_exact (group_name
);
2886 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2888 /* Create the symbol now. */
2889 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2891 /* Before Solaris 11 build 154, Sun ld rejects local group
2892 signature symbols, so make them weak hidden instead. */
2893 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2894 S_SET_OTHER (sy
, STV_HIDDEN
);
2896 symbol_get_obj (sy
)->local
= 1;
2898 symbol_table_insert (sy
);
2900 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2901 /* Mark the group signature symbol as used so that it will be
2902 included in the symbol table. */
2903 symbol_mark_used_in_reloc (sy
);
2908 elf_frob_file (void)
2910 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2912 #ifdef elf_tc_final_processing
2913 elf_tc_final_processing ();
2917 /* It removes any unneeded versioned symbols from the symbol table. */
2920 elf_frob_file_before_adjust (void)
2926 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2928 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2929 int is_defined
= !!S_IS_DEFINED (symp
);
2931 if (sy_obj
->versioned_name
)
2933 char *p
= strchr (sy_obj
->versioned_name
->name
,
2938 /* The @@@ syntax is a special case. If the symbol is
2939 not defined, 2 `@'s will be removed from the
2940 versioned_name. Otherwise, 1 `@' will be removed. */
2941 size_t l
= strlen (&p
[3]) + 1;
2942 memmove (&p
[1 + is_defined
], &p
[3], l
);
2947 /* Verify that the name isn't using the @@ syntax--this
2948 is reserved for definitions of the default version
2950 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2952 as_bad (_("invalid attempt to declare external "
2953 "version name as default in symbol `%s'"),
2954 sy_obj
->versioned_name
->name
);
2958 /* Only one version symbol is allowed for undefined
2960 if (sy_obj
->versioned_name
->next
)
2962 as_bad (_("multiple versions [`%s'|`%s'] for "
2964 sy_obj
->versioned_name
->name
,
2965 sy_obj
->versioned_name
->next
->name
,
2970 sy_obj
->rename
= true;
2974 /* If there was .symver or .weak, but symbol was neither
2975 defined nor used anywhere, remove it. */
2977 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2978 && symbol_used_p (symp
) == 0
2979 && symbol_used_in_reloc_p (symp
) == 0)
2980 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2985 /* It is required that we let write_relocs have the opportunity to
2986 optimize away fixups before output has begun, since it is possible
2987 to eliminate all fixups for a section and thus we never should
2988 have generated the relocation section. */
2991 elf_frob_file_after_relocs (void)
2995 /* Set SHT_GROUP section size. */
2996 for (i
= 0; i
< groups
.num_group
; i
++)
2998 asection
*s
, *head
, *group
;
3001 head
= groups
.head
[i
];
3003 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
3004 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
3006 group
= elf_sec_group (head
);
3007 subseg_set (group
, 0);
3008 bfd_set_section_size (group
, size
);
3009 group
->contents
= (unsigned char *) frag_more (size
);
3010 frag_now
->fr_fix
= frag_now_fix_octets ();
3011 frag_wane (frag_now
);
3015 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
3016 htab_delete (groups
.indexes
);
3018 #ifdef NEED_ECOFF_DEBUG
3019 if (ECOFF_DEBUGGING
)
3020 /* Generate the ECOFF debugging information. */
3022 const struct ecoff_debug_swap
*debug_swap
;
3023 struct ecoff_debug_info debug
;
3028 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
3029 know (debug_swap
!= NULL
);
3030 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
3032 /* Set up the pointers in debug. */
3033 #define SET(ptr, offset, type) \
3034 debug.ptr = (type) (buf + debug.symbolic_header.offset)
3036 SET (line
, cbLineOffset
, unsigned char *);
3037 SET (external_dnr
, cbDnOffset
, void *);
3038 SET (external_pdr
, cbPdOffset
, void *);
3039 SET (external_sym
, cbSymOffset
, void *);
3040 SET (external_opt
, cbOptOffset
, void *);
3041 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
3042 SET (ss
, cbSsOffset
, char *);
3043 SET (external_fdr
, cbFdOffset
, void *);
3044 SET (external_rfd
, cbRfdOffset
, void *);
3045 /* ssext and external_ext are set up just below. */
3049 /* Set up the external symbols. */
3050 debug
.ssext
= debug
.ssext_end
= NULL
;
3051 debug
.external_ext
= debug
.external_ext_end
= NULL
;
3052 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
3053 elf_get_extr
, elf_set_index
))
3054 as_fatal (_("failed to set up debugging information: %s"),
3055 bfd_errmsg (bfd_get_error ()));
3057 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
3058 gas_assert (sec
!= NULL
);
3060 know (!stdoutput
->output_has_begun
);
3062 /* We set the size of the section, call bfd_set_section_contents
3063 to force the ELF backend to allocate a file position, and then
3064 write out the data. FIXME: Is this really the best way to do
3066 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
3069 /* Pass BUF to bfd_set_section_contents because this will
3070 eventually become a call to fwrite, and ISO C prohibits
3071 passing a NULL pointer to a stdio function even if the
3072 pointer will not be used. */
3073 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
3074 as_fatal (_("can't start writing .mdebug section: %s"),
3075 bfd_errmsg (bfd_get_error ()));
3077 know (stdoutput
->output_has_begun
);
3078 know (sec
->filepos
!= 0);
3080 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
3082 as_fatal (_("could not write .mdebug section: %s"),
3083 bfd_errmsg (bfd_get_error ()));
3085 #endif /* NEED_ECOFF_DEBUG */
3089 elf_generate_asm_lineno (void)
3091 #ifdef NEED_ECOFF_DEBUG
3092 if (ECOFF_DEBUGGING
)
3093 ecoff_generate_asm_lineno ();
3098 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
3099 int what ATTRIBUTE_UNUSED
,
3100 const char *string ATTRIBUTE_UNUSED
,
3101 int type ATTRIBUTE_UNUSED
,
3102 int other ATTRIBUTE_UNUSED
,
3103 int desc ATTRIBUTE_UNUSED
)
3105 #ifdef NEED_ECOFF_DEBUG
3106 if (ECOFF_DEBUGGING
)
3107 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
3112 elf_separate_stab_sections (void)
3114 #ifdef NEED_ECOFF_DEBUG
3115 return (!ECOFF_DEBUGGING
);
3122 elf_init_stab_section (segT seg
)
3124 #ifdef NEED_ECOFF_DEBUG
3125 if (!ECOFF_DEBUGGING
)
3127 obj_elf_init_stab_section (seg
);
3130 const struct format_ops elf_format_ops
=
3132 bfd_target_elf_flavour
,
3133 0, /* dfl_leading_underscore */
3134 1, /* emit_section_symbols */
3139 elf_frob_file_before_adjust
,
3140 0, /* obj_frob_file_before_fix */
3141 elf_frob_file_after_relocs
,
3142 elf_s_get_size
, elf_s_set_size
,
3143 elf_s_get_align
, elf_s_set_align
,
3150 elf_copy_symbol_attributes
,
3151 elf_generate_asm_lineno
,
3153 elf_separate_stab_sections
,
3154 elf_init_stab_section
,
3155 elf_sec_sym_ok_for_reloc
,
3157 #ifdef NEED_ECOFF_DEBUG
3160 0, /* ecoff_set_ext */
3162 elf_obj_read_begin_hook
,
3163 elf_obj_symbol_new_hook
,
3164 elf_obj_symbol_clone_hook
,