1 /* ELF object file format
2 Copyright (C) 1992-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 3,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 #define OBJ_HEADER "obj-elf.h"
23 #include "safe-ctype.h"
26 #include "dwarf2dbg.h"
28 #ifndef ECOFF_DEBUGGING
29 #define ECOFF_DEBUGGING 0
31 #define NEED_ECOFF_DEBUG
34 #ifdef NEED_ECOFF_DEBUG
36 #include "bfd/ecoff-bfd.h"
40 #include "elf/alpha.h"
52 #include "elf/x86-64.h"
60 #include "elf/nios2.h"
67 static void obj_elf_line (int);
68 static void obj_elf_size (int);
69 static void obj_elf_type (int);
70 static void obj_elf_ident (int);
71 static void obj_elf_weak (int);
72 static void obj_elf_local (int);
73 static void obj_elf_visibility (int);
74 static void obj_elf_symver (int);
75 static void obj_elf_subsection (int);
76 static void obj_elf_popsection (int);
77 static void obj_elf_gnu_attribute (int);
78 static void obj_elf_tls_common (int);
79 static void obj_elf_lcomm (int);
80 static void obj_elf_struct (int);
81 static void obj_elf_attach_to_group (int);
83 static const pseudo_typeS elf_pseudo_table
[] =
85 {"attach_to_group", obj_elf_attach_to_group
, 0},
86 {"comm", obj_elf_common
, 0},
87 {"common", obj_elf_common
, 1},
88 {"ident", obj_elf_ident
, 0},
89 {"lcomm", obj_elf_lcomm
, 0},
90 {"local", obj_elf_local
, 0},
91 {"previous", obj_elf_previous
, 0},
92 {"section", obj_elf_section
, 0},
93 {"section.s", obj_elf_section
, 0},
94 {"sect", obj_elf_section
, 0},
95 {"sect.s", obj_elf_section
, 0},
96 {"pushsection", obj_elf_section
, 1},
97 {"popsection", obj_elf_popsection
, 0},
98 {"size", obj_elf_size
, 0},
99 {"type", obj_elf_type
, 0},
100 {"version", obj_elf_version
, 0},
101 {"weak", obj_elf_weak
, 0},
103 /* These define symbol visibility. */
104 {"internal", obj_elf_visibility
, STV_INTERNAL
},
105 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
106 {"protected", obj_elf_visibility
, STV_PROTECTED
},
108 /* These are used for stabs-in-elf configurations. */
109 {"line", obj_elf_line
, 0},
111 /* This is a GNU extension to handle symbol versions. */
112 {"symver", obj_elf_symver
, 0},
114 /* A GNU extension to change subsection only. */
115 {"subsection", obj_elf_subsection
, 0},
117 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
118 {"vtable_inherit", obj_elf_vtable_inherit
, 0},
119 {"vtable_entry", obj_elf_vtable_entry
, 0},
121 /* A GNU extension for object attributes. */
122 {"gnu_attribute", obj_elf_gnu_attribute
, 0},
124 /* These are used for dwarf. */
128 /* These are used for dwarf2. */
129 { "file", dwarf2_directive_file
, 0 },
130 { "loc", dwarf2_directive_loc
, 0 },
131 { "loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0 },
133 /* We need to trap the section changing calls to handle .previous. */
134 {"data", obj_elf_data
, 0},
135 {"offset", obj_elf_struct
, 0},
136 {"struct", obj_elf_struct
, 0},
137 {"text", obj_elf_text
, 0},
139 {"tls_common", obj_elf_tls_common
, 0},
145 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
147 #ifdef NEED_ECOFF_DEBUG
148 /* COFF style debugging information for ECOFF. .ln is not used; .loc
150 { "def", ecoff_directive_def
, 0 },
151 { "dim", ecoff_directive_dim
, 0 },
152 { "endef", ecoff_directive_endef
, 0 },
153 { "file", ecoff_directive_file
, 0 },
154 { "scl", ecoff_directive_scl
, 0 },
155 { "tag", ecoff_directive_tag
, 0 },
156 { "val", ecoff_directive_val
, 0 },
158 /* COFF debugging requires pseudo-ops .size and .type, but ELF
159 already has meanings for those. We use .esize and .etype
160 instead. These are only generated by gcc anyhow. */
161 { "esize", ecoff_directive_size
, 0 },
162 { "etype", ecoff_directive_type
, 0 },
164 /* ECOFF specific debugging information. */
165 { "aent", ecoff_directive_ent
, 1 },
166 { "begin", ecoff_directive_begin
, 0 },
167 { "bend", ecoff_directive_bend
, 0 },
168 { "end", ecoff_directive_end
, 0 },
169 { "ent", ecoff_directive_ent
, 0 },
170 { "fmask", ecoff_directive_fmask
, 0 },
171 { "frame", ecoff_directive_frame
, 0 },
172 { "loc", ecoff_directive_loc
, 0 },
173 { "mask", ecoff_directive_mask
, 0 },
175 /* Other ECOFF directives. */
176 { "extern", ecoff_directive_extern
, 0 },
178 /* These are used on Irix. I don't know how to implement them. */
179 { "alias", s_ignore
, 0 },
180 { "bgnb", s_ignore
, 0 },
181 { "endb", s_ignore
, 0 },
182 { "lab", s_ignore
, 0 },
183 { "noalias", s_ignore
, 0 },
184 { "verstamp", s_ignore
, 0 },
185 { "vreg", s_ignore
, 0 },
188 {NULL
, NULL
, 0} /* end sentinel */
192 #include "aout/aout64.h"
194 /* This is called when the assembler starts. */
196 asection
*elf_com_section_ptr
;
203 /* Add symbols for the known sections to the symbol table. */
204 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
205 symbol_table_insert (section_symbol (s
));
206 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
207 symbol_table_insert (section_symbol (s
));
208 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
209 symbol_table_insert (section_symbol (s
));
210 elf_com_section_ptr
= bfd_com_section_ptr
;
214 elf_pop_insert (void)
216 pop_insert (elf_pseudo_table
);
218 pop_insert (ecoff_debug_pseudo_table
);
222 elf_s_get_size (symbolS
*sym
)
224 return S_GET_SIZE (sym
);
228 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
230 S_SET_SIZE (sym
, sz
);
234 elf_s_get_align (symbolS
*sym
)
236 return S_GET_ALIGN (sym
);
240 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
242 S_SET_ALIGN (sym
, align
);
246 elf_s_get_other (symbolS
*sym
)
248 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
252 elf_s_set_other (symbolS
*sym
, int other
)
254 S_SET_OTHER (sym
, other
);
258 elf_sec_sym_ok_for_reloc (asection
*sec
)
260 return obj_sec_sym_ok_for_reloc (sec
);
264 elf_file_symbol (const char *s
, int appfile
)
269 || symbol_rootP
== NULL
270 || (bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
271 || (bsym
->flags
& BSF_FILE
) == 0)
276 sym
= symbol_new (s
, absolute_section
, &zero_address_frag
, 0);
278 name_length
= strlen (s
);
279 if (name_length
> strlen (S_GET_NAME (sym
)))
281 obstack_grow (¬es
, s
, name_length
+ 1);
282 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
285 strcpy ((char *) S_GET_NAME (sym
), s
);
287 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
289 if (symbol_rootP
!= sym
290 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
291 || (bsym
->flags
& BSF_FILE
) == 0))
293 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
294 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
298 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
302 #ifdef NEED_ECOFF_DEBUG
303 ecoff_new_file (s
, appfile
);
307 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
308 Parse a possible alignment value. */
311 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
314 int is_local
= symbol_get_obj (symbolP
)->local
;
316 if (*input_line_pointer
== ',')
318 char *save
= input_line_pointer
;
320 input_line_pointer
++;
323 if (*input_line_pointer
== '"')
325 /* For sparc. Accept .common symbol, length, "bss" */
326 input_line_pointer
++;
327 /* Some use the dot, some don't. */
328 if (*input_line_pointer
== '.')
329 input_line_pointer
++;
330 /* Some say data, some say bss. */
331 if (strncmp (input_line_pointer
, "bss\"", 4) == 0)
332 input_line_pointer
+= 4;
333 else if (strncmp (input_line_pointer
, "data\"", 5) == 0)
334 input_line_pointer
+= 5;
337 char *p
= input_line_pointer
;
342 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
343 if (*input_line_pointer
++ == '"')
345 c
= *input_line_pointer
;
346 *input_line_pointer
= '\0';
347 as_bad (_("bad .common segment %s"), p
);
348 *input_line_pointer
= c
;
349 ignore_rest_of_line ();
352 /* ??? Don't ask me why these are always global. */
357 input_line_pointer
= save
;
358 align
= parse_align (is_local
);
359 if (align
== (addressT
) -1)
366 bss_alloc (symbolP
, size
, align
);
367 S_CLEAR_EXTERNAL (symbolP
);
371 S_SET_VALUE (symbolP
, size
);
372 S_SET_ALIGN (symbolP
, align
);
373 S_SET_EXTERNAL (symbolP
);
374 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
377 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
383 obj_elf_common (int is_common
)
385 if (flag_mri
&& is_common
)
388 s_comm_internal (0, elf_common_parse
);
392 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
394 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
397 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
401 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
403 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
406 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
410 get_sym_from_input_line_and_check (void)
416 c
= get_symbol_name (& name
);
417 sym
= symbol_find_or_make (name
);
418 *input_line_pointer
= c
;
419 SKIP_WHITESPACE_AFTER_NAME ();
421 /* There is no symbol name if input_line_pointer has not moved. */
422 if (name
== input_line_pointer
)
423 as_bad (_("Missing symbol name in directive"));
428 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
435 symbolP
= get_sym_from_input_line_and_check ();
436 c
= *input_line_pointer
;
437 S_CLEAR_EXTERNAL (symbolP
);
438 symbol_get_obj (symbolP
)->local
= 1;
441 input_line_pointer
++;
443 if (*input_line_pointer
== '\n')
448 demand_empty_rest_of_line ();
452 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
459 symbolP
= get_sym_from_input_line_and_check ();
460 c
= *input_line_pointer
;
461 S_SET_WEAK (symbolP
);
464 input_line_pointer
++;
466 if (*input_line_pointer
== '\n')
471 demand_empty_rest_of_line ();
475 obj_elf_visibility (int visibility
)
480 elf_symbol_type
*elfsym
;
484 symbolP
= get_sym_from_input_line_and_check ();
486 bfdsym
= symbol_get_bfdsym (symbolP
);
487 elfsym
= elf_symbol_from (bfdsym
);
491 elfsym
->internal_elf_sym
.st_other
&= ~3;
492 elfsym
->internal_elf_sym
.st_other
|= visibility
;
494 c
= *input_line_pointer
;
497 input_line_pointer
++;
501 if (*input_line_pointer
== '\n')
507 demand_empty_rest_of_line ();
510 static segT previous_section
;
511 static int previous_subsection
;
515 struct section_stack
*next
;
517 int subseg
, prev_subseg
;
520 static struct section_stack
*section_stack
;
522 /* 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 info
= elf_section_data (sec
)->this_hdr
.sh_info
;
534 return (info
== match
->info
535 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
536 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
537 && sec
->section_id
== match
->section_id
538 && (group_name
== gname
539 || (group_name
!= NULL
541 && strcmp (group_name
, gname
) == 0))
542 && (linked_to_symbol_name
== match
->linked_to_symbol_name
543 || (linked_to_symbol_name
!= NULL
544 && match
->linked_to_symbol_name
!= NULL
545 && strcmp (linked_to_symbol_name
,
546 match
->linked_to_symbol_name
) == 0)));
549 /* Handle the .section pseudo-op. This code supports two different
552 The first is found on Solaris, and looks like
553 .section ".sec1",#alloc,#execinstr,#write
554 Here the names after '#' are the SHF_* flags to turn on for the
555 section. I'm not sure how it determines the SHT_* type (BFD
556 doesn't really give us control over the type, anyhow).
558 The second format is found on UnixWare, and probably most SVR4
559 machines, and looks like
560 .section .sec1,"a",@progbits
561 The quoted string may contain any combination of a, w, x, and
562 represents the SHF_* flags to turn on for the section. The string
563 beginning with '@' can be progbits or nobits. There should be
564 other possibilities, but I don't know what they are. In any case,
565 BFD doesn't really let us set the section type. */
568 obj_elf_change_section (const char *name
,
572 struct elf_section_match
*match_p
,
579 const struct elf_backend_data
*bed
;
580 const struct bfd_elf_special_section
*ssect
;
584 static struct elf_section_match unused_match
;
585 match_p
= &unused_match
;
588 #ifdef md_flush_pending_output
589 md_flush_pending_output ();
592 /* Switch to the section, creating it if necessary. */
595 struct section_stack
*elt
;
596 elt
= XNEW (struct section_stack
);
597 elt
->next
= section_stack
;
599 elt
->prev_seg
= previous_section
;
600 elt
->subseg
= now_subseg
;
601 elt
->prev_subseg
= previous_subsection
;
604 previous_section
= now_seg
;
605 previous_subsection
= now_subseg
;
607 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section_by_match
,
615 sec
= subseg_force_new (name
, 0);
617 bed
= get_elf_backend_data (stdoutput
);
618 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
622 bfd_boolean override
= FALSE
;
624 if (type
== SHT_NULL
)
626 else if (type
!= ssect
->type
)
629 /* Some older versions of gcc will emit
631 .section .init_array,"aw",@progbits
633 for __attribute__ ((section (".init_array"))).
634 "@progbits" is incorrect. Also for x86-64 large bss
635 sections, some older versions of gcc will emit
637 .section .lbss,"aw",@progbits
639 "@progbits" is incorrect. */
641 && (bed
->s
->arch_size
!= 64
642 || !(ssect
->attr
& SHF_X86_64_LARGE
))
644 && ssect
->type
!= SHT_INIT_ARRAY
645 && ssect
->type
!= SHT_FINI_ARRAY
646 && ssect
->type
!= SHT_PREINIT_ARRAY
)
648 /* We allow to specify any type for a .note section. */
649 if (ssect
->type
!= SHT_NOTE
650 /* Processor and application defined types are allowed too. */
651 && type
< SHT_LOPROC
)
652 as_warn (_("setting incorrect section type for %s"),
657 as_warn (_("ignoring incorrect section type for %s"),
663 if (old_sec
== NULL
&& ((attr
& ~(SHF_MASKOS
| SHF_MASKPROC
))
664 & ~ssect
->attr
) != 0)
666 /* As a GNU extension, we permit a .note section to be
667 allocatable. If the linker sees an allocatable .note
668 section, it will create a PT_NOTE segment in the output
669 file. We also allow "x" for .note.GNU-stack. */
670 if (ssect
->type
== SHT_NOTE
671 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
673 /* Allow different SHF_MERGE and SHF_STRINGS if we have
674 something like .rodata.str. */
675 else if (ssect
->suffix_length
== -2
676 && name
[ssect
->prefix_length
] == '.'
680 & ~SHF_STRINGS
) == 0)
682 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
683 else if (attr
== SHF_ALLOC
684 && (strcmp (name
, ".interp") == 0
685 || strcmp (name
, ".strtab") == 0
686 || strcmp (name
, ".symtab") == 0))
688 /* .note.GNU-stack can have SHF_EXECINSTR. */
689 else if (attr
== SHF_EXECINSTR
690 && strcmp (name
, ".note.GNU-stack") == 0)
693 /* A section on Alpha may have SHF_ALPHA_GPREL. */
694 else if ((attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
698 else if (attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
699 && (ssect
->type
== SHT_INIT_ARRAY
700 || ssect
->type
== SHT_FINI_ARRAY
701 || ssect
->type
== SHT_PREINIT_ARRAY
))
702 /* RX init/fini arrays can and should have the "awx" attributes set. */
707 if (match_p
->group_name
== NULL
)
708 as_warn (_("setting incorrect section attributes for %s"),
714 if (!override
&& old_sec
== NULL
)
718 /* Convert ELF type and flags to BFD flags. */
720 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
721 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
722 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
723 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
724 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
725 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
726 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
727 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
728 #ifdef md_elf_section_flags
729 flags
= md_elf_section_flags (flags
, attr
, type
);
733 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
739 if (type
== SHT_NULL
)
740 type
= bfd_elf_get_default_section_type (flags
);
741 elf_section_type (sec
) = type
;
742 elf_section_flags (sec
) = attr
;
743 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->info
;
745 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
746 if (type
== SHT_NOBITS
)
747 seg_info (sec
)->bss
= 1;
749 /* Set the section ID and flags. */
750 sec
->section_id
= match_p
->section_id
;
751 flags
|= match_p
->flags
;
753 /* Set the linked-to symbol name. */
754 sec
->map_head
.linked_to_symbol_name
755 = match_p
->linked_to_symbol_name
;
757 bfd_set_section_flags (sec
, flags
);
758 if (flags
& SEC_MERGE
)
759 sec
->entsize
= entsize
;
760 elf_group_name (sec
) = match_p
->group_name
;
762 /* Add a symbol for this section to the symbol table. */
763 secsym
= symbol_find (name
);
766 /* We could be repurposing an undefined symbol here: make sure we
767 reset sy_value to look like other section symbols in order to avoid
768 trying to incorrectly resolve this section symbol later on. */
769 static const expressionS exp
= { .X_op
= O_constant
};
770 symbol_set_value_expression (secsym
, &exp
);
771 symbol_set_bfdsym (secsym
, sec
->symbol
);
774 symbol_table_insert (section_symbol (sec
));
779 && (unsigned) type
!= elf_section_type (old_sec
))
782 /* This is a special section with known type. User
783 assembly might get the section type wrong; Even high
784 profile projects like glibc have done so in the past.
785 So don't error in this case. */
786 as_warn (_("ignoring changed section type for %s"), name
);
788 /* Do error when assembly isn't self-consistent. */
789 as_bad (_("changed section type for %s"), name
);
794 /* If section attributes are specified the second time we see a
795 particular section, then check that they are the same as we
796 saw the first time. */
797 if (((old_sec
->flags
^ flags
)
798 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
799 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
800 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
801 | SEC_THREAD_LOCAL
)))
804 as_warn (_("ignoring changed section attributes for %s"), name
);
806 as_bad (_("changed section attributes for %s"), name
);
809 /* FIXME: Maybe we should consider removing a previously set
810 processor or application specific attribute as suspicious ? */
811 elf_section_flags (sec
) = attr
;
813 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
814 as_bad (_("changed section entity size for %s"), name
);
818 #ifdef md_elf_section_change_hook
819 md_elf_section_change_hook ();
824 obj_elf_parse_section_letters (char *str
, size_t len
,
825 bfd_boolean
*is_clone
, bfd_vma
*gnu_attr
)
841 attr
|= SHF_LINK_ORDER
;
847 attr
|= SHF_EXECINSTR
;
862 *gnu_attr
|= SHF_GNU_MBIND
;
869 if (*(str
- 1) == 'a')
872 if (len
> 1 && str
[1] == 's')
882 const char *bad_msg
= _("unrecognized .section attribute:"
883 " want a,e,o,w,x,M,S,G,T or number");
884 #ifdef md_elf_section_letter
885 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
886 if (md_attr
!= (bfd_vma
) -1)
894 attr
|= strtoul (str
, & end
, 0);
895 /* Update str and len, allowing for the fact that
896 we will execute str++ and len-- below. */
902 as_fatal ("%s", bad_msg
);
913 obj_elf_section_type (char *str
, size_t len
, bfd_boolean warn
)
915 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
917 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
919 if (len
== 4 && strncmp (str
, "note", 4) == 0)
921 if (len
== 10 && strncmp (str
, "init_array", 10) == 0)
922 return SHT_INIT_ARRAY
;
923 if (len
== 10 && strncmp (str
, "fini_array", 10) == 0)
924 return SHT_FINI_ARRAY
;
925 if (len
== 13 && strncmp (str
, "preinit_array", 13) == 0)
926 return SHT_PREINIT_ARRAY
;
928 #ifdef md_elf_section_type
930 int md_type
= md_elf_section_type (str
, len
);
939 int type
= strtoul (str
, & end
, 0);
941 if (warn
&& (size_t) (end
- str
) != len
)
942 as_warn (_("extraneous characters at end of numeric section type"));
948 as_warn (_("unrecognized section type"));
953 obj_elf_section_word (char *str
, size_t len
, int *type
)
957 if (len
== 5 && strncmp (str
, "write", 5) == 0)
959 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
961 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
962 return SHF_EXECINSTR
;
963 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
965 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
968 #ifdef md_elf_section_word
970 bfd_vma md_attr
= md_elf_section_word (str
, len
);
976 ret
= obj_elf_section_type (str
, len
, FALSE
);
980 as_warn (_("unrecognized section attribute"));
985 /* Get name of section. */
987 obj_elf_section_name (void)
992 if (*input_line_pointer
== '"')
996 name
= demand_copy_C_string (&dummy
);
999 ignore_rest_of_line ();
1005 char *end
= input_line_pointer
;
1007 while (0 == strchr ("\n\t,; ", *end
))
1009 if (end
== input_line_pointer
)
1011 as_bad (_("missing name"));
1012 ignore_rest_of_line ();
1016 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1018 while (flag_sectname_subst
)
1020 char *subst
= strchr (name
, '%');
1021 if (subst
&& subst
[1] == 'S')
1023 int oldlen
= strlen (name
);
1024 int substlen
= strlen (now_seg
->name
);
1025 int newlen
= oldlen
- 2 + substlen
;
1026 char *newname
= XNEWVEC (char, newlen
+ 1);
1027 int headlen
= subst
- name
;
1028 memcpy (newname
, name
, headlen
);
1029 strcpy (newname
+ headlen
, now_seg
->name
);
1030 strcat (newname
+ headlen
, subst
+ 2);
1038 #ifdef tc_canonicalize_section_name
1039 name
= tc_canonicalize_section_name (name
);
1041 input_line_pointer
= end
;
1048 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1050 const char * gname
= obj_elf_section_name ();
1054 as_warn (_("group name not parseable"));
1058 if (elf_group_name (now_seg
))
1060 as_warn (_("section %s already has a group (%s)"),
1061 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1065 elf_group_name (now_seg
) = xstrdup (gname
);
1066 elf_section_flags (now_seg
) |= SHF_GROUP
;
1070 obj_elf_section (int push
)
1079 subsegT new_subsection
= -1;
1080 struct elf_section_match match
;
1081 unsigned long linked_to_section_index
= -1UL;
1087 #ifdef md_flush_pending_output
1088 md_flush_pending_output ();
1091 previous_section
= now_seg
;
1092 previous_subsection
= now_subseg
;
1094 s_mri_sect (&mri_type
);
1096 #ifdef md_elf_section_change_hook
1097 md_elf_section_change_hook ();
1103 name
= obj_elf_section_name ();
1107 memset (&match
, 0, sizeof (match
));
1110 if ((sym
= symbol_find (name
)) != NULL
1111 && ! symbol_section_p (sym
)
1112 && S_IS_DEFINED (sym
)
1113 && ! S_IS_VOLATILE (sym
)
1114 && ! S_CAN_BE_REDEFINED (sym
))
1116 as_bad (_("section name '%s' already defined as another symbol"), name
);
1117 ignore_rest_of_line ();
1126 if (*input_line_pointer
== ',')
1128 /* Skip the comma. */
1129 ++input_line_pointer
;
1132 if (push
&& ISDIGIT (*input_line_pointer
))
1134 /* .pushsection has an optional subsection. */
1135 new_subsection
= (subsegT
) get_absolute_expression ();
1139 /* Stop if we don't see a comma. */
1140 if (*input_line_pointer
!= ',')
1143 /* Skip the comma. */
1144 ++input_line_pointer
;
1148 if (*input_line_pointer
== '"')
1150 bfd_boolean is_clone
;
1152 beg
= demand_copy_C_string (&dummy
);
1155 ignore_rest_of_line ();
1158 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1159 &is_clone
, &gnu_attr
);
1162 if (*input_line_pointer
== ',')
1165 char *save
= input_line_pointer
;
1167 ++input_line_pointer
;
1169 c
= *input_line_pointer
;
1172 beg
= demand_copy_C_string (&dummy
);
1175 ignore_rest_of_line ();
1178 type
= obj_elf_section_type (beg
, strlen (beg
), TRUE
);
1180 else if (c
== '@' || c
== '%')
1182 ++input_line_pointer
;
1184 if (ISDIGIT (* input_line_pointer
))
1185 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1188 c
= get_symbol_name (& beg
);
1189 (void) restore_line_pointer (c
);
1190 type
= obj_elf_section_type (beg
,
1191 input_line_pointer
- beg
,
1196 input_line_pointer
= save
;
1200 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1202 ++input_line_pointer
;
1204 entsize
= get_absolute_expression ();
1208 as_warn (_("invalid merge entity size"));
1213 else if ((attr
& SHF_MERGE
) != 0)
1215 as_warn (_("entity size for SHF_MERGE not specified"));
1219 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1221 ++input_line_pointer
;
1223 /* Check for a numeric section index, rather than a symbol name. */
1224 if (ISDIGIT (* input_line_pointer
))
1226 linked_to_section_index
= strtoul (input_line_pointer
, & input_line_pointer
, 0);
1231 unsigned int length
;
1233 c
= get_symbol_name (& beg
);
1234 (void) restore_line_pointer (c
);
1235 length
= input_line_pointer
- beg
;
1237 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1241 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1243 as_warn (_("? section flag ignored with G present"));
1247 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1249 ++input_line_pointer
;
1250 match
.group_name
= obj_elf_section_name ();
1251 if (match
.group_name
== NULL
)
1253 else if (*input_line_pointer
== ',')
1255 ++input_line_pointer
;
1257 if (strncmp (input_line_pointer
, "comdat", 6) == 0)
1259 input_line_pointer
+= 6;
1263 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1266 else if ((attr
& SHF_GROUP
) != 0)
1268 as_warn (_("group name for SHF_GROUP not specified"));
1274 const char *now_group
= elf_group_name (now_seg
);
1275 if (now_group
!= NULL
)
1277 match
.group_name
= xstrdup (now_group
);
1278 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1282 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1284 char *save
= input_line_pointer
;
1285 ++input_line_pointer
;
1287 if (ISDIGIT (* input_line_pointer
))
1289 char *t
= input_line_pointer
;
1290 match
.info
= strtoul (input_line_pointer
,
1291 &input_line_pointer
, 0);
1292 if (match
.info
== (unsigned int) -1)
1294 as_warn (_("unsupported mbind section info: %s"), t
);
1299 input_line_pointer
= save
;
1302 if (*input_line_pointer
== ',')
1304 char *save
= input_line_pointer
;
1306 ++input_line_pointer
;
1308 if (strncmp (input_line_pointer
, "unique", 6) == 0)
1310 input_line_pointer
+= 6;
1312 if (*input_line_pointer
== ',')
1314 ++input_line_pointer
;
1316 if (ISDIGIT (* input_line_pointer
))
1319 bfd_boolean overflow
;
1320 char *t
= input_line_pointer
;
1321 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1324 id
= strtoul (input_line_pointer
,
1325 &input_line_pointer
, 0);
1326 overflow
= (id
== (unsigned long) -1
1327 && errno
== ERANGE
);
1332 (input_line_pointer
,
1333 (const char **) &input_line_pointer
, 0);
1334 overflow
= id
== ~(bfd_vma
) 0;
1336 if (overflow
|| id
> (unsigned int) -1)
1338 char *linefeed
, saved_char
= 0;
1339 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1341 saved_char
= *linefeed
;
1344 as_bad (_("unsupported section id: %s"), t
);
1346 *linefeed
= saved_char
;
1350 match
.section_id
= id
;
1351 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1357 input_line_pointer
= save
;
1367 if (*input_line_pointer
!= '#')
1369 as_bad (_("character following name is not '#'"));
1370 ignore_rest_of_line ();
1373 ++input_line_pointer
;
1374 c
= get_symbol_name (& beg
);
1375 (void) restore_line_pointer (c
);
1377 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1382 while (*input_line_pointer
++ == ',');
1383 --input_line_pointer
;
1388 demand_empty_rest_of_line ();
1390 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1393 if ((gnu_attr
& SHF_GNU_MBIND
) != 0)
1395 struct elf_backend_data
*bed
;
1397 if ((attr
& SHF_ALLOC
) == 0)
1398 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1400 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
1401 if (bed
->elf_osabi
== ELFOSABI_NONE
)
1402 bed
->elf_osabi
= ELFOSABI_GNU
;
1403 else if (bed
->elf_osabi
!= ELFOSABI_GNU
1404 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
1405 as_bad (_("GNU_MBIND section is supported only by GNU "
1406 "and FreeBSD targets"));
1407 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1409 elf_section_flags (now_seg
) |= gnu_attr
;
1411 if (linked_to_section_index
!= -1UL)
1413 elf_section_flags (now_seg
) |= SHF_LINK_ORDER
;
1414 elf_section_data (now_seg
)->this_hdr
.sh_link
= linked_to_section_index
;
1415 /* FIXME: Should we perform some sanity checking on the section index ? */
1418 if (push
&& new_subsection
!= -1)
1419 subseg_set (now_seg
, new_subsection
);
1422 /* Change to the .data section. */
1425 obj_elf_data (int i
)
1427 #ifdef md_flush_pending_output
1428 md_flush_pending_output ();
1431 previous_section
= now_seg
;
1432 previous_subsection
= now_subseg
;
1435 #ifdef md_elf_section_change_hook
1436 md_elf_section_change_hook ();
1440 /* Change to the .text section. */
1443 obj_elf_text (int i
)
1445 #ifdef md_flush_pending_output
1446 md_flush_pending_output ();
1449 previous_section
= now_seg
;
1450 previous_subsection
= now_subseg
;
1453 #ifdef md_elf_section_change_hook
1454 md_elf_section_change_hook ();
1458 /* Change to the *ABS* section. */
1461 obj_elf_struct (int i
)
1463 #ifdef md_flush_pending_output
1464 md_flush_pending_output ();
1467 previous_section
= now_seg
;
1468 previous_subsection
= now_subseg
;
1471 #ifdef md_elf_section_change_hook
1472 md_elf_section_change_hook ();
1477 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1481 #ifdef md_flush_pending_output
1482 md_flush_pending_output ();
1485 previous_section
= now_seg
;
1486 previous_subsection
= now_subseg
;
1488 temp
= get_absolute_expression ();
1489 subseg_set (now_seg
, (subsegT
) temp
);
1490 demand_empty_rest_of_line ();
1492 #ifdef md_elf_section_change_hook
1493 md_elf_section_change_hook ();
1497 /* This can be called from the processor backends if they change
1501 obj_elf_section_change_hook (void)
1503 previous_section
= now_seg
;
1504 previous_subsection
= now_subseg
;
1508 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1513 if (previous_section
== 0)
1515 as_warn (_(".previous without corresponding .section; ignored"));
1519 #ifdef md_flush_pending_output
1520 md_flush_pending_output ();
1523 new_section
= previous_section
;
1524 new_subsection
= previous_subsection
;
1525 previous_section
= now_seg
;
1526 previous_subsection
= now_subseg
;
1527 subseg_set (new_section
, new_subsection
);
1529 #ifdef md_elf_section_change_hook
1530 md_elf_section_change_hook ();
1535 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1537 struct section_stack
*top
= section_stack
;
1541 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1545 #ifdef md_flush_pending_output
1546 md_flush_pending_output ();
1549 section_stack
= top
->next
;
1550 previous_section
= top
->prev_seg
;
1551 previous_subsection
= top
->prev_subseg
;
1552 subseg_set (top
->seg
, top
->subseg
);
1555 #ifdef md_elf_section_change_hook
1556 md_elf_section_change_hook ();
1561 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1563 /* Assume delimiter is part of expression. BSD4.2 as fails with
1564 delightful bug, so we are not being incompatible here. */
1565 new_logical_line (NULL
, get_absolute_expression ());
1566 demand_empty_rest_of_line ();
1569 static struct elf_versioned_name_list
*
1570 obj_elf_find_and_add_versioned_name (const char *version_name
,
1571 const char *sym_name
,
1573 struct elf_obj_sy
*sy_obj
)
1575 struct elf_versioned_name_list
*versioned_name
;
1578 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1581 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1582 names, we have to disable this. */
1583 if (0 && *p
== '\0')
1585 as_bad (_("missing version name in `%s' for symbol `%s'"),
1586 version_name
, sym_name
);
1590 versioned_name
= sy_obj
->versioned_name
;
1600 if (strcmp (versioned_name
->name
, version_name
) == 0)
1601 return versioned_name
;
1604 as_bad (_("only one version name with `@@@' is allowed "
1605 "for symbol `%s'"), sym_name
);
1609 sy_obj
->rename
= TRUE
;
1612 as_bad (_("invalid version name '%s' for symbol `%s'"),
1613 version_name
, sym_name
);
1618 versioned_name
!= NULL
;
1619 versioned_name
= versioned_name
->next
)
1620 if (strcmp (versioned_name
->name
, version_name
) == 0)
1621 return versioned_name
;
1623 /* Add this versioned name to the head of the list, */
1624 versioned_name
= (struct elf_versioned_name_list
*)
1625 xmalloc (sizeof (*versioned_name
));
1626 versioned_name
->name
= xstrdup (version_name
);
1627 versioned_name
->next
= sy_obj
->versioned_name
;
1628 sy_obj
->versioned_name
= versioned_name
;
1630 return versioned_name
;
1633 /* This handles the .symver pseudo-op, which is used to specify a
1634 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1635 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1636 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1637 with the same value as the symbol NAME. */
1640 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1643 const char *sym_name
;
1647 struct elf_obj_sy
*sy_obj
;
1650 sym
= get_sym_from_input_line_and_check ();
1652 if (*input_line_pointer
!= ',')
1654 as_bad (_("expected comma after name in .symver"));
1655 ignore_rest_of_line ();
1659 ++input_line_pointer
;
1662 /* Temporarily include '@' in symbol names. */
1663 old_lexat
= lex_type
[(unsigned char) '@'];
1664 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1665 c
= get_symbol_name (& name
);
1666 lex_type
[(unsigned char) '@'] = old_lexat
;
1667 sym_name
= S_GET_NAME (sym
);
1669 if (S_IS_COMMON (sym
))
1671 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1673 ignore_rest_of_line ();
1677 p
= strchr (name
, ELF_VER_CHR
);
1680 as_bad (_("missing version name in `%s' for symbol `%s'"),
1682 ignore_rest_of_line ();
1686 sy_obj
= symbol_get_obj (sym
);
1687 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1690 sy_obj
->bad_version
= TRUE
;
1691 ignore_rest_of_line ();
1695 (void) restore_line_pointer (c
);
1697 if (*input_line_pointer
== ',')
1699 char *save
= input_line_pointer
;
1701 ++input_line_pointer
;
1703 if (strncmp (input_line_pointer
, "local", 5) == 0)
1705 input_line_pointer
+= 5;
1706 sy_obj
->visibility
= visibility_local
;
1708 else if (strncmp (input_line_pointer
, "hidden", 6) == 0)
1710 input_line_pointer
+= 6;
1711 sy_obj
->visibility
= visibility_hidden
;
1713 else if (strncmp (input_line_pointer
, "remove", 6) == 0)
1715 input_line_pointer
+= 6;
1716 sy_obj
->visibility
= visibility_remove
;
1719 input_line_pointer
= save
;
1722 demand_empty_rest_of_line ();
1725 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1726 to the linker the hierarchy in which a particular table resides. The
1727 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1730 obj_elf_get_vtable_inherit (void)
1732 char *cname
, *pname
;
1733 symbolS
*csym
, *psym
;
1736 if (*input_line_pointer
== '#')
1737 ++input_line_pointer
;
1739 c
= get_symbol_name (& cname
);
1740 csym
= symbol_find (cname
);
1742 /* GCFIXME: should check that we don't have two .vtable_inherits for
1743 the same child symbol. Also, we can currently only do this if the
1744 child symbol is already exists and is placed in a fragment. */
1746 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1748 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1753 *input_line_pointer
= c
;
1755 SKIP_WHITESPACE_AFTER_NAME ();
1756 if (*input_line_pointer
!= ',')
1758 as_bad (_("expected comma after name in .vtable_inherit"));
1759 ignore_rest_of_line ();
1763 ++input_line_pointer
;
1766 if (*input_line_pointer
== '#')
1767 ++input_line_pointer
;
1769 if (input_line_pointer
[0] == '0'
1770 && (input_line_pointer
[1] == '\0'
1771 || ISSPACE (input_line_pointer
[1])))
1773 psym
= section_symbol (absolute_section
);
1774 ++input_line_pointer
;
1778 c
= get_symbol_name (& pname
);
1779 psym
= symbol_find_or_make (pname
);
1780 restore_line_pointer (c
);
1783 demand_empty_rest_of_line ();
1788 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1789 return fix_new (symbol_get_frag (csym
),
1790 symbol_get_value_expression (csym
)->X_add_number
,
1791 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1794 /* This is a version of obj_elf_get_vtable_inherit() that is
1795 suitable for use in struct _pseudo_type tables. */
1798 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1800 (void) obj_elf_get_vtable_inherit ();
1803 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1804 to the linker that a vtable slot was used. The syntax is
1805 ".vtable_entry tablename, offset". */
1808 obj_elf_get_vtable_entry (void)
1813 if (*input_line_pointer
== '#')
1814 ++input_line_pointer
;
1816 sym
= get_sym_from_input_line_and_check ();
1817 if (*input_line_pointer
!= ',')
1819 as_bad (_("expected comma after name in .vtable_entry"));
1820 ignore_rest_of_line ();
1824 ++input_line_pointer
;
1825 if (*input_line_pointer
== '#')
1826 ++input_line_pointer
;
1828 offset
= get_absolute_expression ();
1830 demand_empty_rest_of_line ();
1832 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1833 BFD_RELOC_VTABLE_ENTRY
);
1836 /* This is a version of obj_elf_get_vtable_entry() that is
1837 suitable for use in struct _pseudo_type tables. */
1840 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1842 (void) obj_elf_get_vtable_entry ();
1845 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1848 skip_past_char (char ** str
, char c
)
1858 #define skip_past_comma(str) skip_past_char (str, ',')
1860 /* A list of attributes that have been explicitly set by the assembly code.
1861 VENDOR is the vendor id, BASE is the tag shifted right by the number
1862 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1863 struct recorded_attribute_info
{
1864 struct recorded_attribute_info
*next
;
1869 static struct recorded_attribute_info
*recorded_attributes
;
1871 /* Record that we have seen an explicit specification of attribute TAG
1872 for vendor VENDOR. */
1875 record_attribute (int vendor
, unsigned int tag
)
1879 struct recorded_attribute_info
*rai
;
1881 base
= tag
/ (8 * sizeof (rai
->mask
));
1882 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1883 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1884 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1890 rai
= XNEW (struct recorded_attribute_info
);
1891 rai
->next
= recorded_attributes
;
1892 rai
->vendor
= vendor
;
1895 recorded_attributes
= rai
;
1898 /* Return true if we have seen an explicit specification of attribute TAG
1899 for vendor VENDOR. */
1902 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1906 struct recorded_attribute_info
*rai
;
1908 base
= tag
/ (8 * sizeof (rai
->mask
));
1909 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1910 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1911 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1912 return (rai
->mask
& mask
) != 0;
1916 /* Parse an attribute directive for VENDOR.
1917 Returns the attribute number read, or zero on error. */
1920 obj_elf_vendor_attribute (int vendor
)
1928 /* Read the first number or name. */
1929 skip_whitespace (input_line_pointer
);
1930 s
= input_line_pointer
;
1931 if (ISDIGIT (*input_line_pointer
))
1934 if (exp
.X_op
!= O_constant
)
1936 tag
= exp
.X_add_number
;
1942 /* A name may contain '_', but no other punctuation. */
1943 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1944 ++input_line_pointer
)
1949 name
= xstrndup (s
, i
);
1951 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
1952 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
1955 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
1958 as_bad (_("Attribute name not recognised: %s"), name
);
1959 ignore_rest_of_line ();
1966 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
1968 if (skip_past_comma (&input_line_pointer
) == -1)
1973 if (exp
.X_op
!= O_constant
)
1975 as_bad (_("expected numeric constant"));
1976 ignore_rest_of_line ();
1979 i
= exp
.X_add_number
;
1982 && skip_past_comma (&input_line_pointer
) == -1)
1984 as_bad (_("expected comma"));
1985 ignore_rest_of_line ();
1992 skip_whitespace (input_line_pointer
);
1993 if (*input_line_pointer
!= '"')
1995 s
= demand_copy_C_string (&len
);
1998 record_attribute (vendor
, tag
);
2002 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
2005 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
2008 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
2014 demand_empty_rest_of_line ();
2017 as_bad (_("bad string constant"));
2018 ignore_rest_of_line ();
2021 as_bad (_("expected <tag> , <value>"));
2022 ignore_rest_of_line ();
2026 /* Parse a .gnu_attribute directive. */
2029 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2031 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2035 elf_obj_read_begin_hook (void)
2037 #ifdef NEED_ECOFF_DEBUG
2038 if (ECOFF_DEBUGGING
)
2039 ecoff_read_begin_hook ();
2044 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2046 struct elf_obj_sy
*sy_obj
;
2048 sy_obj
= symbol_get_obj (symbolP
);
2049 sy_obj
->size
= NULL
;
2050 sy_obj
->versioned_name
= NULL
;
2052 #ifdef NEED_ECOFF_DEBUG
2053 if (ECOFF_DEBUGGING
)
2054 ecoff_symbol_new_hook (symbolP
);
2058 /* When setting one symbol equal to another, by default we probably
2059 want them to have the same "size", whatever it means in the current
2063 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2065 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2066 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2069 if (destelf
->size
== NULL
)
2070 destelf
->size
= XNEW (expressionS
);
2071 *destelf
->size
= *srcelf
->size
;
2075 free (destelf
->size
);
2076 destelf
->size
= NULL
;
2078 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2079 /* Don't copy visibility. */
2080 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2081 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2085 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2090 asection
*seg
= now_seg
;
2091 subsegT subseg
= now_subseg
;
2092 Elf_Internal_Note i_note
;
2093 Elf_External_Note e_note
;
2094 asection
*note_secp
= NULL
;
2097 if (*input_line_pointer
== '\"')
2101 ++input_line_pointer
; /* -> 1st char of string. */
2102 name
= input_line_pointer
;
2104 while (is_a_char (c
= next_char_of_string ()))
2106 c
= *input_line_pointer
;
2107 *input_line_pointer
= '\0';
2108 *(input_line_pointer
- 1) = '\0';
2109 *input_line_pointer
= c
;
2111 /* Create the .note section. */
2112 note_secp
= subseg_new (".note", 0);
2113 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2114 record_alignment (note_secp
, 2);
2116 /* Process the version string. */
2117 len
= strlen (name
) + 1;
2119 /* PR 3456: Although the name field is padded out to an 4-byte
2120 boundary, the namesz field should not be adjusted. */
2121 i_note
.namesz
= len
;
2122 i_note
.descsz
= 0; /* No description. */
2123 i_note
.type
= NT_VERSION
;
2124 p
= frag_more (sizeof (e_note
.namesz
));
2125 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2126 p
= frag_more (sizeof (e_note
.descsz
));
2127 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2128 p
= frag_more (sizeof (e_note
.type
));
2129 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2130 p
= frag_more (len
);
2131 memcpy (p
, name
, len
);
2133 frag_align (2, 0, 0);
2135 subseg_set (seg
, subseg
);
2138 as_bad (_("expected quoted string"));
2140 demand_empty_rest_of_line ();
2144 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2147 char c
= get_symbol_name (&name
);
2152 p
= input_line_pointer
;
2154 SKIP_WHITESPACE_AFTER_NAME ();
2155 if (*input_line_pointer
!= ',')
2158 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2160 ignore_rest_of_line ();
2163 input_line_pointer
++;
2165 if (exp
.X_op
== O_absent
)
2167 as_bad (_("missing expression in .size directive"));
2168 exp
.X_op
= O_constant
;
2169 exp
.X_add_number
= 0;
2172 sym
= symbol_find_or_make (name
);
2174 if (exp
.X_op
== O_constant
)
2176 S_SET_SIZE (sym
, exp
.X_add_number
);
2177 xfree (symbol_get_obj (sym
)->size
);
2178 symbol_get_obj (sym
)->size
= NULL
;
2182 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2183 *symbol_get_obj (sym
)->size
= exp
;
2185 demand_empty_rest_of_line ();
2188 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2189 There are six syntaxes:
2191 The first (used on Solaris) is
2193 The second (used on UnixWare) is
2195 The third (reportedly to be used on Irix 6.0) is
2197 The fourth (used on NetBSD/Arm and Linux/ARM) is
2199 The fifth (used on SVR4/860) is
2200 .type SYM,"function"
2201 The sixth (emitted by recent SunPRO under Solaris) is
2203 where the integer is the STT_* value.
2207 obj_elf_type_name (char *cp
)
2211 p
= input_line_pointer
;
2212 if (*input_line_pointer
>= '0'
2213 && *input_line_pointer
<= '9')
2215 while (*input_line_pointer
>= '0'
2216 && *input_line_pointer
<= '9')
2217 ++input_line_pointer
;
2218 *cp
= *input_line_pointer
;
2219 *input_line_pointer
= '\0';
2222 *cp
= get_symbol_name (&p
);
2228 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2232 const char *type_name
;
2234 elf_symbol_type
*elfsym
;
2236 sym
= get_sym_from_input_line_and_check ();
2237 c
= *input_line_pointer
;
2238 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2240 if (*input_line_pointer
== ',')
2241 ++input_line_pointer
;
2244 if ( *input_line_pointer
== '#'
2245 || *input_line_pointer
== '@'
2246 || *input_line_pointer
== '"'
2247 || *input_line_pointer
== '%')
2248 ++input_line_pointer
;
2250 type_name
= obj_elf_type_name (& c
);
2253 if (strcmp (type_name
, "function") == 0
2254 || strcmp (type_name
, "2") == 0
2255 || strcmp (type_name
, "STT_FUNC") == 0)
2256 type
= BSF_FUNCTION
;
2257 else if (strcmp (type_name
, "object") == 0
2258 || strcmp (type_name
, "1") == 0
2259 || strcmp (type_name
, "STT_OBJECT") == 0)
2261 else if (strcmp (type_name
, "tls_object") == 0
2262 || strcmp (type_name
, "6") == 0
2263 || strcmp (type_name
, "STT_TLS") == 0)
2264 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2265 else if (strcmp (type_name
, "notype") == 0
2266 || strcmp (type_name
, "0") == 0
2267 || strcmp (type_name
, "STT_NOTYPE") == 0)
2269 else if (strcmp (type_name
, "common") == 0
2270 || strcmp (type_name
, "5") == 0
2271 || strcmp (type_name
, "STT_COMMON") == 0)
2275 if (! S_IS_COMMON (sym
))
2277 if (S_IS_VOLATILE (sym
))
2279 sym
= symbol_clone (sym
, 1);
2280 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2281 S_SET_VALUE (sym
, 0);
2282 S_SET_EXTERNAL (sym
);
2283 symbol_set_frag (sym
, &zero_address_frag
);
2284 S_CLEAR_VOLATILE (sym
);
2286 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2287 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2290 /* FIXME: Is it safe to just change the section ? */
2291 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2292 S_SET_VALUE (sym
, 0);
2293 S_SET_EXTERNAL (sym
);
2297 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2298 || strcmp (type_name
, "10") == 0
2299 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2301 struct elf_backend_data
*bed
;
2303 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2304 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2305 bed
->elf_osabi
= ELFOSABI_GNU
;
2306 else if (bed
->elf_osabi
!= ELFOSABI_GNU
2307 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2308 as_bad (_("symbol type \"%s\" is supported only by GNU "
2309 "and FreeBSD targets"), type_name
);
2310 /* MIPS targets do not support IFUNCS. */
2311 else if (bed
->target_id
== MIPS_ELF_DATA
)
2312 as_bad (_("symbol type \"%s\" is not supported by "
2313 "MIPS targets"), type_name
);
2314 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2315 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2317 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2319 struct elf_backend_data
*bed
;
2321 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2322 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2323 bed
->elf_osabi
= ELFOSABI_GNU
;
2324 else if (bed
->elf_osabi
!= ELFOSABI_GNU
)
2325 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2327 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2328 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2330 #ifdef md_elf_symbol_type
2331 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2335 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2337 *input_line_pointer
= c
;
2339 if (*input_line_pointer
== '"')
2340 ++input_line_pointer
;
2342 #ifdef md_elf_symbol_type_change
2343 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2346 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2348 if (type
!= BSF_FUNCTION
)
2349 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2350 if (type
!= BSF_OBJECT
)
2352 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2354 if (S_IS_COMMON (sym
))
2356 as_bad (_("cannot change type of common symbol '%s'"),
2362 /* Don't warn when changing to STT_NOTYPE. */
2365 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2367 if (new != (elfsym
->symbol
.flags
| type
))
2368 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2369 elfsym
->symbol
.flags
= new;
2372 elfsym
->symbol
.flags
&= ~mask
;
2375 demand_empty_rest_of_line ();
2379 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2381 static segT comment_section
;
2382 segT old_section
= now_seg
;
2383 int old_subsection
= now_subseg
;
2385 #ifdef md_flush_pending_output
2386 md_flush_pending_output ();
2389 if (!comment_section
)
2392 comment_section
= subseg_new (".comment", 0);
2393 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2394 | SEC_MERGE
| SEC_STRINGS
));
2395 comment_section
->entsize
= 1;
2396 #ifdef md_elf_section_change_hook
2397 md_elf_section_change_hook ();
2403 subseg_set (comment_section
, 0);
2405 subseg_set (old_section
, old_subsection
);
2408 #ifdef INIT_STAB_SECTION
2410 /* The first entry in a .stabs section is special. */
2413 obj_elf_init_stab_section (segT seg
)
2418 unsigned int stroff
;
2420 /* Force the section to align to a longword boundary. Without this,
2421 UnixWare ar crashes. */
2422 bfd_set_section_alignment (seg
, 2);
2424 /* Make space for this first symbol. */
2428 file
= as_where (NULL
);
2429 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2430 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
2431 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2432 md_number_to_chars (p
, stroff
, 4);
2433 seg_info (seg
)->stabu
.p
= p
;
2438 /* Fill in the counts in the first entry in a .stabs section. */
2441 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2448 if (strncmp (".stab", sec
->name
, 5))
2450 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2453 name
= concat (sec
->name
, "str", NULL
);
2454 strsec
= bfd_get_section_by_name (abfd
, name
);
2456 strsz
= bfd_section_size (strsec
);
2459 nsyms
= bfd_section_size (sec
) / 12 - 1;
2461 p
= seg_info (sec
)->stabu
.p
;
2462 gas_assert (p
!= 0);
2464 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2465 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2469 #ifdef NEED_ECOFF_DEBUG
2471 /* This function is called by the ECOFF code. It is supposed to
2472 record the external symbol information so that the backend can
2473 write it out correctly. The ELF backend doesn't actually handle
2474 this at the moment, so we do it ourselves. We save the information
2477 #ifdef OBJ_MAYBE_ELF
2481 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2483 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2486 /* This function is called by bfd_ecoff_debug_externals. It is
2487 supposed to *EXT to the external symbol information, and return
2488 whether the symbol should be used at all. */
2491 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2493 if (sym
->udata
.p
== NULL
)
2495 *ext
= *(EXTR
*) sym
->udata
.p
;
2499 /* This function is called by bfd_ecoff_debug_externals. It has
2500 nothing to do for ELF. */
2503 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2504 bfd_size_type indx ATTRIBUTE_UNUSED
)
2508 #endif /* NEED_ECOFF_DEBUG */
2511 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2513 struct elf_obj_sy
*sy_obj
;
2515 struct elf_versioned_name_list
*versioned_name
;
2517 #ifdef NEED_ECOFF_DEBUG
2518 if (ECOFF_DEBUGGING
)
2519 ecoff_frob_symbol (symp
);
2522 sy_obj
= symbol_get_obj (symp
);
2524 size
= sy_obj
->size
;
2527 if (resolve_expression (size
)
2528 && size
->X_op
== O_constant
)
2529 S_SET_SIZE (symp
, size
->X_add_number
);
2532 if (!flag_allow_nonconst_size
)
2533 as_bad (_(".size expression for %s "
2534 "does not evaluate to a constant"), S_GET_NAME (symp
));
2536 as_warn (_(".size expression for %s "
2537 "does not evaluate to a constant"), S_GET_NAME (symp
));
2539 free (sy_obj
->size
);
2540 sy_obj
->size
= NULL
;
2543 versioned_name
= sy_obj
->versioned_name
;
2546 /* This symbol was given a new name with the .symver directive.
2547 If this is an external reference, just rename the symbol to
2548 include the version string. This will make the relocs be
2549 against the correct versioned symbol. */
2551 /* We will have already reported an version error. */
2552 if (sy_obj
->bad_version
)
2554 /* elf_frob_file_before_adjust only allows one version symbol for
2556 else if (sy_obj
->rename
)
2557 S_SET_NAME (symp
, versioned_name
->name
);
2558 else if (S_IS_COMMON (symp
))
2560 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2561 versioned_name
->name
, S_GET_NAME (symp
));
2567 elf_symbol_type
*elfsym
;
2569 /* This is a definition. Add an alias for each version.
2570 FIXME: Using an alias will permit the debugging information
2571 to refer to the right symbol. However, it's not clear
2572 whether it is the best approach. */
2574 /* FIXME: Creating a new symbol here is risky. We're
2575 in the final loop over the symbol table. We can
2576 get away with it only because the symbol goes to
2577 the end of the list, where the loop will still see
2578 it. It would probably be better to do this in
2579 obj_frob_file_before_adjust. */
2580 for (; versioned_name
!= NULL
;
2581 versioned_name
= versioned_name
->next
)
2583 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2585 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2587 /* Subtracting out the frag address here is a hack
2588 because we are in the middle of the final loop. */
2591 - (symbol_get_frag (symp
)->fr_address
2592 / OCTETS_PER_BYTE
)));
2594 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2596 /* This will copy over the size information. */
2597 copy_symbol_attributes (symp2
, symp
);
2599 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2601 if (S_IS_WEAK (symp
))
2604 if (S_IS_EXTERNAL (symp
))
2605 S_SET_EXTERNAL (symp2
);
2608 switch (symbol_get_obj (symp
)->visibility
)
2610 case visibility_unchanged
:
2612 case visibility_hidden
:
2613 bfdsym
= symbol_get_bfdsym (symp
);
2614 elfsym
= elf_symbol_from (bfdsym
);
2615 elfsym
->internal_elf_sym
.st_other
&= ~3;
2616 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2618 case visibility_remove
:
2619 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2621 case visibility_local
:
2622 S_CLEAR_EXTERNAL (symp
);
2628 /* Double check weak symbols. */
2629 if (S_IS_WEAK (symp
))
2631 if (S_IS_COMMON (symp
))
2632 as_bad (_("symbol `%s' can not be both weak and common"),
2639 asection
**head
; /* Section lists. */
2640 unsigned int num_group
; /* Number of lists. */
2641 htab_t indexes
; /* Maps group name to index in head array. */
2644 static struct group_list groups
;
2646 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2647 add it to a list of sections belonging to the group. INF is a
2648 pointer to a struct group_list, which is where we store the head of
2649 each list. If its link_to_symbol_name isn't NULL, set up its
2650 linked-to section. */
2653 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2654 asection
*sec
, void *inf
)
2656 struct group_list
*list
= (struct group_list
*) inf
;
2657 const char *group_name
= elf_group_name (sec
);
2659 unsigned int *elem_idx
;
2660 unsigned int *idx_ptr
;
2662 if (sec
->map_head
.linked_to_symbol_name
)
2664 symbolS
*linked_to_sym
;
2665 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2666 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2667 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2668 sec
->map_head
.linked_to_symbol_name
,
2669 bfd_section_name (sec
));
2671 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2674 if (group_name
== NULL
)
2677 /* If this group already has a list, add the section to the head of
2679 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2680 if (elem_idx
!= NULL
)
2682 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2683 list
->head
[*elem_idx
] = sec
;
2687 /* New group. Make the arrays bigger in chunks to minimize calls to
2689 i
= list
->num_group
;
2692 unsigned int newsize
= i
+ 128;
2693 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2695 list
->head
[i
] = sec
;
2696 list
->num_group
+= 1;
2698 /* Add index to hash. */
2699 idx_ptr
= XNEW (unsigned int);
2701 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2705 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2707 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2708 free ((char *)tuple
->value
);
2712 /* Create symbols for group signature. */
2715 elf_adjust_symtab (void)
2719 /* Go find section groups. */
2720 groups
.num_group
= 0;
2722 groups
.indexes
= str_htab_create ();
2723 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2726 /* Make the SHT_GROUP sections that describe each section group. We
2727 can't set up the section contents here yet, because elf section
2728 indices have yet to be calculated. elf.c:set_group_contents does
2729 the rest of the work. */
2730 for (i
= 0; i
< groups
.num_group
; i
++)
2732 const char *group_name
= elf_group_name (groups
.head
[i
]);
2733 const char *sec_name
;
2738 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2739 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2740 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2742 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2743 if (s
!= groups
.head
[i
])
2745 as_warn (_("assuming all members of group `%s' are COMDAT"),
2751 sec_name
= ".group";
2752 s
= subseg_force_new (sec_name
, 0);
2754 || !bfd_set_section_flags (s
, flags
)
2755 || !bfd_set_section_alignment (s
, 2))
2757 as_fatal (_("can't create group: %s"),
2758 bfd_errmsg (bfd_get_error ()));
2760 elf_section_type (s
) = SHT_GROUP
;
2762 /* Pass a pointer to the first section in this group. */
2763 elf_next_in_group (s
) = groups
.head
[i
];
2764 elf_sec_group (groups
.head
[i
]) = s
;
2765 /* Make sure that the signature symbol for the group has the
2766 name of the group. */
2767 sy
= symbol_find_exact (group_name
);
2768 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2770 /* Create the symbol now. */
2771 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2773 /* Before Solaris 11 build 154, Sun ld rejects local group
2774 signature symbols, so make them weak hidden instead. */
2775 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2776 S_SET_OTHER (sy
, STV_HIDDEN
);
2778 symbol_get_obj (sy
)->local
= 1;
2780 symbol_table_insert (sy
);
2782 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2787 elf_frob_file (void)
2789 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2791 #ifdef elf_tc_final_processing
2792 elf_tc_final_processing ();
2796 /* It removes any unneeded versioned symbols from the symbol table. */
2799 elf_frob_file_before_adjust (void)
2805 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2807 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2808 int is_defined
= !!S_IS_DEFINED (symp
);
2810 if (sy_obj
->versioned_name
)
2812 char *p
= strchr (sy_obj
->versioned_name
->name
,
2817 /* The @@@ syntax is a special case. If the symbol is
2818 not defined, 2 `@'s will be removed from the
2819 versioned_name. Otherwise, 1 `@' will be removed. */
2820 size_t l
= strlen (&p
[3]) + 1;
2821 memmove (&p
[1 + is_defined
], &p
[3], l
);
2826 /* Verify that the name isn't using the @@ syntax--this
2827 is reserved for definitions of the default version
2829 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2831 as_bad (_("invalid attempt to declare external "
2832 "version name as default in symbol `%s'"),
2833 sy_obj
->versioned_name
->name
);
2837 /* Only one version symbol is allowed for undefined
2839 if (sy_obj
->versioned_name
->next
)
2841 as_bad (_("multiple versions [`%s'|`%s'] for "
2843 sy_obj
->versioned_name
->name
,
2844 sy_obj
->versioned_name
->next
->name
,
2849 sy_obj
->rename
= TRUE
;
2853 /* If there was .symver or .weak, but symbol was neither
2854 defined nor used anywhere, remove it. */
2856 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2857 && symbol_used_p (symp
) == 0
2858 && symbol_used_in_reloc_p (symp
) == 0)
2859 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2864 /* It is required that we let write_relocs have the opportunity to
2865 optimize away fixups before output has begun, since it is possible
2866 to eliminate all fixups for a section and thus we never should
2867 have generated the relocation section. */
2870 elf_frob_file_after_relocs (void)
2874 /* Set SHT_GROUP section size. */
2875 for (i
= 0; i
< groups
.num_group
; i
++)
2877 asection
*s
, *head
, *group
;
2880 head
= groups
.head
[i
];
2882 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2883 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2885 group
= elf_sec_group (head
);
2886 subseg_set (group
, 0);
2887 bfd_set_section_size (group
, size
);
2888 group
->contents
= (unsigned char *) frag_more (size
);
2889 frag_now
->fr_fix
= frag_now_fix_octets ();
2890 frag_wane (frag_now
);
2894 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2895 htab_delete (groups
.indexes
);
2897 #ifdef NEED_ECOFF_DEBUG
2898 if (ECOFF_DEBUGGING
)
2899 /* Generate the ECOFF debugging information. */
2901 const struct ecoff_debug_swap
*debug_swap
;
2902 struct ecoff_debug_info debug
;
2907 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2908 know (debug_swap
!= NULL
);
2909 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2911 /* Set up the pointers in debug. */
2912 #define SET(ptr, offset, type) \
2913 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2915 SET (line
, cbLineOffset
, unsigned char *);
2916 SET (external_dnr
, cbDnOffset
, void *);
2917 SET (external_pdr
, cbPdOffset
, void *);
2918 SET (external_sym
, cbSymOffset
, void *);
2919 SET (external_opt
, cbOptOffset
, void *);
2920 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2921 SET (ss
, cbSsOffset
, char *);
2922 SET (external_fdr
, cbFdOffset
, void *);
2923 SET (external_rfd
, cbRfdOffset
, void *);
2924 /* ssext and external_ext are set up just below. */
2928 /* Set up the external symbols. */
2929 debug
.ssext
= debug
.ssext_end
= NULL
;
2930 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2931 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2932 elf_get_extr
, elf_set_index
))
2933 as_fatal (_("failed to set up debugging information: %s"),
2934 bfd_errmsg (bfd_get_error ()));
2936 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2937 gas_assert (sec
!= NULL
);
2939 know (!stdoutput
->output_has_begun
);
2941 /* We set the size of the section, call bfd_set_section_contents
2942 to force the ELF backend to allocate a file position, and then
2943 write out the data. FIXME: Is this really the best way to do
2945 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
2948 /* Pass BUF to bfd_set_section_contents because this will
2949 eventually become a call to fwrite, and ISO C prohibits
2950 passing a NULL pointer to a stdio function even if the
2951 pointer will not be used. */
2952 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
2953 as_fatal (_("can't start writing .mdebug section: %s"),
2954 bfd_errmsg (bfd_get_error ()));
2956 know (stdoutput
->output_has_begun
);
2957 know (sec
->filepos
!= 0);
2959 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2961 as_fatal (_("could not write .mdebug section: %s"),
2962 bfd_errmsg (bfd_get_error ()));
2964 #endif /* NEED_ECOFF_DEBUG */
2968 elf_generate_asm_lineno (void)
2970 #ifdef NEED_ECOFF_DEBUG
2971 if (ECOFF_DEBUGGING
)
2972 ecoff_generate_asm_lineno ();
2977 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
2978 int what ATTRIBUTE_UNUSED
,
2979 const char *string ATTRIBUTE_UNUSED
,
2980 int type ATTRIBUTE_UNUSED
,
2981 int other ATTRIBUTE_UNUSED
,
2982 int desc ATTRIBUTE_UNUSED
)
2984 #ifdef NEED_ECOFF_DEBUG
2985 if (ECOFF_DEBUGGING
)
2986 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
2991 elf_separate_stab_sections (void)
2993 #ifdef NEED_ECOFF_DEBUG
2994 return (!ECOFF_DEBUGGING
);
3001 elf_init_stab_section (segT seg
)
3003 #ifdef NEED_ECOFF_DEBUG
3004 if (!ECOFF_DEBUGGING
)
3006 obj_elf_init_stab_section (seg
);
3009 const struct format_ops elf_format_ops
=
3011 bfd_target_elf_flavour
,
3012 0, /* dfl_leading_underscore */
3013 1, /* emit_section_symbols */
3018 elf_frob_file_before_adjust
,
3019 0, /* obj_frob_file_before_fix */
3020 elf_frob_file_after_relocs
,
3021 elf_s_get_size
, elf_s_set_size
,
3022 elf_s_get_align
, elf_s_set_align
,
3029 elf_copy_symbol_attributes
,
3030 elf_generate_asm_lineno
,
3032 elf_separate_stab_sections
,
3033 elf_init_stab_section
,
3034 elf_sec_sym_ok_for_reloc
,
3036 #ifdef NEED_ECOFF_DEBUG
3039 0, /* ecoff_set_ext */
3041 elf_obj_read_begin_hook
,
3042 elf_obj_symbol_new_hook
,