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
;
523 get_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
525 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
526 const char *gname
= match
->group_name
;
527 const char *group_name
= elf_group_name (sec
);
528 const char *linked_to_symbol_name
529 = sec
->map_head
.linked_to_symbol_name
;
530 unsigned int info
= elf_section_data (sec
)->this_hdr
.sh_info
;
532 return (info
== match
->info
533 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
534 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
535 && sec
->section_id
== match
->section_id
536 && (group_name
== gname
537 || (group_name
!= NULL
539 && strcmp (group_name
, gname
) == 0))
540 && (linked_to_symbol_name
== match
->linked_to_symbol_name
541 || (linked_to_symbol_name
!= NULL
542 && match
->linked_to_symbol_name
!= NULL
543 && strcmp (linked_to_symbol_name
,
544 match
->linked_to_symbol_name
) == 0)));
547 /* Handle the .section pseudo-op. This code supports two different
550 The first is found on Solaris, and looks like
551 .section ".sec1",#alloc,#execinstr,#write
552 Here the names after '#' are the SHF_* flags to turn on for the
553 section. I'm not sure how it determines the SHT_* type (BFD
554 doesn't really give us control over the type, anyhow).
556 The second format is found on UnixWare, and probably most SVR4
557 machines, and looks like
558 .section .sec1,"a",@progbits
559 The quoted string may contain any combination of a, w, x, and
560 represents the SHF_* flags to turn on for the section. The string
561 beginning with '@' can be progbits or nobits. There should be
562 other possibilities, but I don't know what they are. In any case,
563 BFD doesn't really let us set the section type. */
566 obj_elf_change_section (const char *name
,
570 struct elf_section_match
*match_p
,
577 const struct elf_backend_data
*bed
;
578 const struct bfd_elf_special_section
*ssect
;
582 static struct elf_section_match unused_match
;
583 match_p
= &unused_match
;
586 #ifdef md_flush_pending_output
587 md_flush_pending_output ();
590 /* Switch to the section, creating it if necessary. */
593 struct section_stack
*elt
;
594 elt
= XNEW (struct section_stack
);
595 elt
->next
= section_stack
;
597 elt
->prev_seg
= previous_section
;
598 elt
->subseg
= now_subseg
;
599 elt
->prev_subseg
= previous_subsection
;
602 previous_section
= now_seg
;
603 previous_subsection
= now_subseg
;
605 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section
,
613 sec
= subseg_force_new (name
, 0);
615 bed
= get_elf_backend_data (stdoutput
);
616 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
620 bfd_boolean override
= FALSE
;
622 if (type
== SHT_NULL
)
624 else if (type
!= ssect
->type
)
627 /* Some older versions of gcc will emit
629 .section .init_array,"aw",@progbits
631 for __attribute__ ((section (".init_array"))).
632 "@progbits" is incorrect. Also for x86-64 large bss
633 sections, some older versions of gcc will emit
635 .section .lbss,"aw",@progbits
637 "@progbits" is incorrect. */
639 && (bed
->s
->arch_size
!= 64
640 || !(ssect
->attr
& SHF_X86_64_LARGE
))
642 && ssect
->type
!= SHT_INIT_ARRAY
643 && ssect
->type
!= SHT_FINI_ARRAY
644 && ssect
->type
!= SHT_PREINIT_ARRAY
)
646 /* We allow to specify any type for a .note section. */
647 if (ssect
->type
!= SHT_NOTE
648 /* Processor and application defined types are allowed too. */
649 && type
< SHT_LOPROC
)
650 as_warn (_("setting incorrect section type for %s"),
655 as_warn (_("ignoring incorrect section type for %s"),
661 if (old_sec
== NULL
&& ((attr
& ~(SHF_MASKOS
| SHF_MASKPROC
))
662 & ~ssect
->attr
) != 0)
664 /* As a GNU extension, we permit a .note section to be
665 allocatable. If the linker sees an allocatable .note
666 section, it will create a PT_NOTE segment in the output
667 file. We also allow "x" for .note.GNU-stack. */
668 if (ssect
->type
== SHT_NOTE
669 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
671 /* Allow different SHF_MERGE and SHF_STRINGS if we have
672 something like .rodata.str. */
673 else if (ssect
->suffix_length
== -2
674 && name
[ssect
->prefix_length
] == '.'
678 & ~SHF_STRINGS
) == 0)
680 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
681 else if (attr
== SHF_ALLOC
682 && (strcmp (name
, ".interp") == 0
683 || strcmp (name
, ".strtab") == 0
684 || strcmp (name
, ".symtab") == 0))
686 /* .note.GNU-stack can have SHF_EXECINSTR. */
687 else if (attr
== SHF_EXECINSTR
688 && strcmp (name
, ".note.GNU-stack") == 0)
691 /* A section on Alpha may have SHF_ALPHA_GPREL. */
692 else if ((attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
696 else if (attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
697 && (ssect
->type
== SHT_INIT_ARRAY
698 || ssect
->type
== SHT_FINI_ARRAY
699 || ssect
->type
== SHT_PREINIT_ARRAY
))
700 /* RX init/fini arrays can and should have the "awx" attributes set. */
705 if (match_p
->group_name
== NULL
)
706 as_warn (_("setting incorrect section attributes for %s"),
712 if (!override
&& old_sec
== NULL
)
716 /* Convert ELF type and flags to BFD flags. */
718 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
719 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
720 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
721 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
722 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
723 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
724 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
725 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
726 #ifdef md_elf_section_flags
727 flags
= md_elf_section_flags (flags
, attr
, type
);
731 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
737 if (type
== SHT_NULL
)
738 type
= bfd_elf_get_default_section_type (flags
);
739 elf_section_type (sec
) = type
;
740 elf_section_flags (sec
) = attr
;
741 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->info
;
743 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
744 if (type
== SHT_NOBITS
)
745 seg_info (sec
)->bss
= 1;
747 /* Set the section ID and flags. */
748 sec
->section_id
= match_p
->section_id
;
749 flags
|= match_p
->flags
;
751 /* Set the linked-to symbol name. */
752 sec
->map_head
.linked_to_symbol_name
753 = match_p
->linked_to_symbol_name
;
755 bfd_set_section_flags (sec
, flags
);
756 if (flags
& SEC_MERGE
)
757 sec
->entsize
= entsize
;
758 elf_group_name (sec
) = match_p
->group_name
;
760 /* Add a symbol for this section to the symbol table. */
761 secsym
= symbol_find (name
);
764 /* We could be repurposing an undefined symbol here: make sure we
765 reset sy_value to look like other section symbols in order to avoid
766 trying to incorrectly resolve this section symbol later on. */
767 static const expressionS exp
= { .X_op
= O_constant
};
768 symbol_set_value_expression (secsym
, &exp
);
769 symbol_set_bfdsym (secsym
, sec
->symbol
);
772 symbol_table_insert (section_symbol (sec
));
777 && (unsigned) type
!= elf_section_type (old_sec
))
780 /* This is a special section with known type. User
781 assembly might get the section type wrong; Even high
782 profile projects like glibc have done so in the past.
783 So don't error in this case. */
784 as_warn (_("ignoring changed section type for %s"), name
);
786 /* Do error when assembly isn't self-consistent. */
787 as_bad (_("changed section type for %s"), name
);
792 /* If section attributes are specified the second time we see a
793 particular section, then check that they are the same as we
794 saw the first time. */
795 if (((old_sec
->flags
^ flags
)
796 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
797 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
798 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
799 | SEC_THREAD_LOCAL
)))
802 as_warn (_("ignoring changed section attributes for %s"), name
);
804 as_bad (_("changed section attributes for %s"), name
);
807 /* FIXME: Maybe we should consider removing a previously set
808 processor or application specific attribute as suspicious ? */
809 elf_section_flags (sec
) = attr
;
811 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
812 as_bad (_("changed section entity size for %s"), name
);
816 #ifdef md_elf_section_change_hook
817 md_elf_section_change_hook ();
822 obj_elf_parse_section_letters (char *str
, size_t len
,
823 bfd_boolean
*is_clone
, bfd_vma
*gnu_attr
)
839 attr
|= SHF_LINK_ORDER
;
845 attr
|= SHF_EXECINSTR
;
860 *gnu_attr
|= SHF_GNU_MBIND
;
867 if (*(str
- 1) == 'a')
870 if (len
> 1 && str
[1] == 's')
880 const char *bad_msg
= _("unrecognized .section attribute:"
881 " want a,e,o,w,x,M,S,G,T or number");
882 #ifdef md_elf_section_letter
883 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
884 if (md_attr
!= (bfd_vma
) -1)
892 attr
|= strtoul (str
, & end
, 0);
893 /* Update str and len, allowing for the fact that
894 we will execute str++ and len-- below. */
900 as_fatal ("%s", bad_msg
);
911 obj_elf_section_type (char *str
, size_t len
, bfd_boolean warn
)
913 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
915 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
917 if (len
== 4 && strncmp (str
, "note", 4) == 0)
919 if (len
== 10 && strncmp (str
, "init_array", 10) == 0)
920 return SHT_INIT_ARRAY
;
921 if (len
== 10 && strncmp (str
, "fini_array", 10) == 0)
922 return SHT_FINI_ARRAY
;
923 if (len
== 13 && strncmp (str
, "preinit_array", 13) == 0)
924 return SHT_PREINIT_ARRAY
;
926 #ifdef md_elf_section_type
928 int md_type
= md_elf_section_type (str
, len
);
937 int type
= strtoul (str
, & end
, 0);
939 if (warn
&& (size_t) (end
- str
) != len
)
940 as_warn (_("extraneous characters at end of numeric section type"));
946 as_warn (_("unrecognized section type"));
951 obj_elf_section_word (char *str
, size_t len
, int *type
)
955 if (len
== 5 && strncmp (str
, "write", 5) == 0)
957 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
959 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
960 return SHF_EXECINSTR
;
961 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
963 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
966 #ifdef md_elf_section_word
968 bfd_vma md_attr
= md_elf_section_word (str
, len
);
974 ret
= obj_elf_section_type (str
, len
, FALSE
);
978 as_warn (_("unrecognized section attribute"));
983 /* Get name of section. */
985 obj_elf_section_name (void)
990 if (*input_line_pointer
== '"')
994 name
= demand_copy_C_string (&dummy
);
997 ignore_rest_of_line ();
1003 char *end
= input_line_pointer
;
1005 while (0 == strchr ("\n\t,; ", *end
))
1007 if (end
== input_line_pointer
)
1009 as_bad (_("missing name"));
1010 ignore_rest_of_line ();
1014 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
1016 while (flag_sectname_subst
)
1018 char *subst
= strchr (name
, '%');
1019 if (subst
&& subst
[1] == 'S')
1021 int oldlen
= strlen (name
);
1022 int substlen
= strlen (now_seg
->name
);
1023 int newlen
= oldlen
- 2 + substlen
;
1024 char *newname
= XNEWVEC (char, newlen
+ 1);
1025 int headlen
= subst
- name
;
1026 memcpy (newname
, name
, headlen
);
1027 strcpy (newname
+ headlen
, now_seg
->name
);
1028 strcat (newname
+ headlen
, subst
+ 2);
1036 #ifdef tc_canonicalize_section_name
1037 name
= tc_canonicalize_section_name (name
);
1039 input_line_pointer
= end
;
1046 obj_elf_attach_to_group (int dummy ATTRIBUTE_UNUSED
)
1048 const char * gname
= obj_elf_section_name ();
1052 as_warn (_("group name not parseable"));
1056 if (elf_group_name (now_seg
))
1058 as_warn (_("section %s already has a group (%s)"),
1059 bfd_section_name (now_seg
), elf_group_name (now_seg
));
1063 elf_group_name (now_seg
) = xstrdup (gname
);
1064 elf_section_flags (now_seg
) |= SHF_GROUP
;
1068 obj_elf_section (int push
)
1077 subsegT new_subsection
= -1;
1078 struct elf_section_match match
;
1084 #ifdef md_flush_pending_output
1085 md_flush_pending_output ();
1088 previous_section
= now_seg
;
1089 previous_subsection
= now_subseg
;
1091 s_mri_sect (&mri_type
);
1093 #ifdef md_elf_section_change_hook
1094 md_elf_section_change_hook ();
1100 name
= obj_elf_section_name ();
1104 memset (&match
, 0, sizeof (match
));
1107 if ((sym
= symbol_find (name
)) != NULL
1108 && ! symbol_section_p (sym
)
1109 && S_IS_DEFINED (sym
)
1110 && ! S_IS_VOLATILE (sym
)
1111 && ! S_CAN_BE_REDEFINED (sym
))
1113 as_bad (_("section name '%s' already defined as another symbol"), name
);
1114 ignore_rest_of_line ();
1123 if (*input_line_pointer
== ',')
1125 /* Skip the comma. */
1126 ++input_line_pointer
;
1129 if (push
&& ISDIGIT (*input_line_pointer
))
1131 /* .pushsection has an optional subsection. */
1132 new_subsection
= (subsegT
) get_absolute_expression ();
1136 /* Stop if we don't see a comma. */
1137 if (*input_line_pointer
!= ',')
1140 /* Skip the comma. */
1141 ++input_line_pointer
;
1145 if (*input_line_pointer
== '"')
1147 bfd_boolean is_clone
;
1149 beg
= demand_copy_C_string (&dummy
);
1152 ignore_rest_of_line ();
1155 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1156 &is_clone
, &gnu_attr
);
1159 if (*input_line_pointer
== ',')
1162 char *save
= input_line_pointer
;
1164 ++input_line_pointer
;
1166 c
= *input_line_pointer
;
1169 beg
= demand_copy_C_string (&dummy
);
1172 ignore_rest_of_line ();
1175 type
= obj_elf_section_type (beg
, strlen (beg
), TRUE
);
1177 else if (c
== '@' || c
== '%')
1179 ++input_line_pointer
;
1181 if (ISDIGIT (* input_line_pointer
))
1182 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1185 c
= get_symbol_name (& beg
);
1186 (void) restore_line_pointer (c
);
1187 type
= obj_elf_section_type (beg
,
1188 input_line_pointer
- beg
,
1193 input_line_pointer
= save
;
1197 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1199 ++input_line_pointer
;
1201 entsize
= get_absolute_expression ();
1205 as_warn (_("invalid merge entity size"));
1210 else if ((attr
& SHF_MERGE
) != 0)
1212 as_warn (_("entity size for SHF_MERGE not specified"));
1216 if ((attr
& SHF_LINK_ORDER
) != 0 && *input_line_pointer
== ',')
1219 unsigned int length
;
1220 ++input_line_pointer
;
1222 c
= get_symbol_name (& beg
);
1223 (void) restore_line_pointer (c
);
1224 length
= input_line_pointer
- beg
;
1226 match
.linked_to_symbol_name
= xmemdup0 (beg
, length
);
1229 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1231 as_warn (_("? section flag ignored with G present"));
1234 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1236 ++input_line_pointer
;
1237 match
.group_name
= obj_elf_section_name ();
1238 if (match
.group_name
== NULL
)
1240 else if (*input_line_pointer
== ',')
1242 ++input_line_pointer
;
1244 if (strncmp (input_line_pointer
, "comdat", 6) == 0)
1246 input_line_pointer
+= 6;
1250 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1253 else if ((attr
& SHF_GROUP
) != 0)
1255 as_warn (_("group name for SHF_GROUP not specified"));
1261 const char *now_group
= elf_group_name (now_seg
);
1262 if (now_group
!= NULL
)
1264 match
.group_name
= xstrdup (now_group
);
1265 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1269 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1271 char *save
= input_line_pointer
;
1272 ++input_line_pointer
;
1274 if (ISDIGIT (* input_line_pointer
))
1276 char *t
= input_line_pointer
;
1277 match
.info
= strtoul (input_line_pointer
,
1278 &input_line_pointer
, 0);
1279 if (match
.info
== (unsigned int) -1)
1281 as_warn (_("unsupported mbind section info: %s"), t
);
1286 input_line_pointer
= save
;
1289 if (*input_line_pointer
== ',')
1291 char *save
= input_line_pointer
;
1292 ++input_line_pointer
;
1294 if (strncmp (input_line_pointer
, "unique", 6) == 0)
1296 input_line_pointer
+= 6;
1298 if (*input_line_pointer
== ',')
1300 ++input_line_pointer
;
1302 if (ISDIGIT (* input_line_pointer
))
1305 bfd_boolean overflow
;
1306 char *t
= input_line_pointer
;
1307 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1310 id
= strtoul (input_line_pointer
,
1311 &input_line_pointer
, 0);
1312 overflow
= (id
== (unsigned long) -1
1313 && errno
== ERANGE
);
1318 (input_line_pointer
,
1319 (const char **) &input_line_pointer
, 0);
1320 overflow
= id
== ~(bfd_vma
) 0;
1322 if (overflow
|| id
> (unsigned int) -1)
1324 char *linefeed
, saved_char
= 0;
1325 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1327 saved_char
= *linefeed
;
1330 as_bad (_("unsupported section id: %s"), t
);
1332 *linefeed
= saved_char
;
1336 match
.section_id
= id
;
1337 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1343 input_line_pointer
= save
;
1353 if (*input_line_pointer
!= '#')
1355 as_bad (_("character following name is not '#'"));
1356 ignore_rest_of_line ();
1359 ++input_line_pointer
;
1360 c
= get_symbol_name (& beg
);
1361 (void) restore_line_pointer (c
);
1363 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1368 while (*input_line_pointer
++ == ',');
1369 --input_line_pointer
;
1374 demand_empty_rest_of_line ();
1376 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1379 if ((gnu_attr
& SHF_GNU_MBIND
) != 0)
1381 struct elf_backend_data
*bed
;
1383 if ((attr
& SHF_ALLOC
) == 0)
1384 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1386 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
1387 if (bed
->elf_osabi
== ELFOSABI_NONE
)
1388 bed
->elf_osabi
= ELFOSABI_GNU
;
1389 else if (bed
->elf_osabi
!= ELFOSABI_GNU
1390 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
1391 as_bad (_("GNU_MBIND section is supported only by GNU "
1392 "and FreeBSD targets"));
1393 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1395 elf_section_flags (now_seg
) |= gnu_attr
;
1397 if (push
&& new_subsection
!= -1)
1398 subseg_set (now_seg
, new_subsection
);
1401 /* Change to the .data section. */
1404 obj_elf_data (int i
)
1406 #ifdef md_flush_pending_output
1407 md_flush_pending_output ();
1410 previous_section
= now_seg
;
1411 previous_subsection
= now_subseg
;
1414 #ifdef md_elf_section_change_hook
1415 md_elf_section_change_hook ();
1419 /* Change to the .text section. */
1422 obj_elf_text (int i
)
1424 #ifdef md_flush_pending_output
1425 md_flush_pending_output ();
1428 previous_section
= now_seg
;
1429 previous_subsection
= now_subseg
;
1432 #ifdef md_elf_section_change_hook
1433 md_elf_section_change_hook ();
1437 /* Change to the *ABS* section. */
1440 obj_elf_struct (int i
)
1442 #ifdef md_flush_pending_output
1443 md_flush_pending_output ();
1446 previous_section
= now_seg
;
1447 previous_subsection
= now_subseg
;
1450 #ifdef md_elf_section_change_hook
1451 md_elf_section_change_hook ();
1456 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1460 #ifdef md_flush_pending_output
1461 md_flush_pending_output ();
1464 previous_section
= now_seg
;
1465 previous_subsection
= now_subseg
;
1467 temp
= get_absolute_expression ();
1468 subseg_set (now_seg
, (subsegT
) temp
);
1469 demand_empty_rest_of_line ();
1471 #ifdef md_elf_section_change_hook
1472 md_elf_section_change_hook ();
1476 /* This can be called from the processor backends if they change
1480 obj_elf_section_change_hook (void)
1482 previous_section
= now_seg
;
1483 previous_subsection
= now_subseg
;
1487 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1492 if (previous_section
== 0)
1494 as_warn (_(".previous without corresponding .section; ignored"));
1498 #ifdef md_flush_pending_output
1499 md_flush_pending_output ();
1502 new_section
= previous_section
;
1503 new_subsection
= previous_subsection
;
1504 previous_section
= now_seg
;
1505 previous_subsection
= now_subseg
;
1506 subseg_set (new_section
, new_subsection
);
1508 #ifdef md_elf_section_change_hook
1509 md_elf_section_change_hook ();
1514 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1516 struct section_stack
*top
= section_stack
;
1520 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1524 #ifdef md_flush_pending_output
1525 md_flush_pending_output ();
1528 section_stack
= top
->next
;
1529 previous_section
= top
->prev_seg
;
1530 previous_subsection
= top
->prev_subseg
;
1531 subseg_set (top
->seg
, top
->subseg
);
1534 #ifdef md_elf_section_change_hook
1535 md_elf_section_change_hook ();
1540 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1542 /* Assume delimiter is part of expression. BSD4.2 as fails with
1543 delightful bug, so we are not being incompatible here. */
1544 new_logical_line (NULL
, get_absolute_expression ());
1545 demand_empty_rest_of_line ();
1548 static struct elf_versioned_name_list
*
1549 obj_elf_find_and_add_versioned_name (const char *version_name
,
1550 const char *sym_name
,
1552 struct elf_obj_sy
*sy_obj
)
1554 struct elf_versioned_name_list
*versioned_name
;
1557 for (p
= ver
+ 1; *p
== ELF_VER_CHR
; p
++)
1560 /* NB: Since some tests in ld/testsuite/ld-elfvers have no version
1561 names, we have to disable this. */
1562 if (0 && *p
== '\0')
1564 as_bad (_("missing version name in `%s' for symbol `%s'"),
1565 version_name
, sym_name
);
1569 versioned_name
= sy_obj
->versioned_name
;
1579 if (strcmp (versioned_name
->name
, version_name
) == 0)
1580 return versioned_name
;
1583 as_bad (_("only one version name with `@@@' is allowed "
1584 "for symbol `%s'"), sym_name
);
1588 sy_obj
->rename
= TRUE
;
1591 as_bad (_("invalid version name '%s' for symbol `%s'"),
1592 version_name
, sym_name
);
1597 versioned_name
!= NULL
;
1598 versioned_name
= versioned_name
->next
)
1599 if (strcmp (versioned_name
->name
, version_name
) == 0)
1600 return versioned_name
;
1602 /* Add this versioned name to the head of the list, */
1603 versioned_name
= (struct elf_versioned_name_list
*)
1604 xmalloc (sizeof (*versioned_name
));
1605 versioned_name
->name
= xstrdup (version_name
);
1606 versioned_name
->next
= sy_obj
->versioned_name
;
1607 sy_obj
->versioned_name
= versioned_name
;
1609 return versioned_name
;
1612 /* This handles the .symver pseudo-op, which is used to specify a
1613 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1614 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1615 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1616 with the same value as the symbol NAME. */
1619 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1622 const char *sym_name
;
1626 struct elf_obj_sy
*sy_obj
;
1629 sym
= get_sym_from_input_line_and_check ();
1631 if (*input_line_pointer
!= ',')
1633 as_bad (_("expected comma after name in .symver"));
1634 ignore_rest_of_line ();
1638 ++input_line_pointer
;
1641 /* Temporarily include '@' in symbol names. */
1642 old_lexat
= lex_type
[(unsigned char) '@'];
1643 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1644 c
= get_symbol_name (& name
);
1645 lex_type
[(unsigned char) '@'] = old_lexat
;
1646 sym_name
= S_GET_NAME (sym
);
1648 if (S_IS_COMMON (sym
))
1650 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1652 ignore_rest_of_line ();
1656 p
= strchr (name
, ELF_VER_CHR
);
1659 as_bad (_("missing version name in `%s' for symbol `%s'"),
1661 ignore_rest_of_line ();
1665 sy_obj
= symbol_get_obj (sym
);
1666 if (obj_elf_find_and_add_versioned_name (name
, sym_name
,
1669 sy_obj
->bad_version
= TRUE
;
1670 ignore_rest_of_line ();
1674 (void) restore_line_pointer (c
);
1676 if (*input_line_pointer
== ',')
1678 char *save
= input_line_pointer
;
1680 ++input_line_pointer
;
1682 if (strncmp (input_line_pointer
, "local", 5) == 0)
1684 input_line_pointer
+= 5;
1685 sy_obj
->visibility
= visibility_local
;
1687 else if (strncmp (input_line_pointer
, "hidden", 6) == 0)
1689 input_line_pointer
+= 6;
1690 sy_obj
->visibility
= visibility_hidden
;
1692 else if (strncmp (input_line_pointer
, "remove", 6) == 0)
1694 input_line_pointer
+= 6;
1695 sy_obj
->visibility
= visibility_remove
;
1698 input_line_pointer
= save
;
1701 demand_empty_rest_of_line ();
1704 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1705 to the linker the hierarchy in which a particular table resides. The
1706 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1709 obj_elf_get_vtable_inherit (void)
1711 char *cname
, *pname
;
1712 symbolS
*csym
, *psym
;
1715 if (*input_line_pointer
== '#')
1716 ++input_line_pointer
;
1718 c
= get_symbol_name (& cname
);
1719 csym
= symbol_find (cname
);
1721 /* GCFIXME: should check that we don't have two .vtable_inherits for
1722 the same child symbol. Also, we can currently only do this if the
1723 child symbol is already exists and is placed in a fragment. */
1725 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1727 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1732 *input_line_pointer
= c
;
1734 SKIP_WHITESPACE_AFTER_NAME ();
1735 if (*input_line_pointer
!= ',')
1737 as_bad (_("expected comma after name in .vtable_inherit"));
1738 ignore_rest_of_line ();
1742 ++input_line_pointer
;
1745 if (*input_line_pointer
== '#')
1746 ++input_line_pointer
;
1748 if (input_line_pointer
[0] == '0'
1749 && (input_line_pointer
[1] == '\0'
1750 || ISSPACE (input_line_pointer
[1])))
1752 psym
= section_symbol (absolute_section
);
1753 ++input_line_pointer
;
1757 c
= get_symbol_name (& pname
);
1758 psym
= symbol_find_or_make (pname
);
1759 restore_line_pointer (c
);
1762 demand_empty_rest_of_line ();
1767 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1768 return fix_new (symbol_get_frag (csym
),
1769 symbol_get_value_expression (csym
)->X_add_number
,
1770 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1773 /* This is a version of obj_elf_get_vtable_inherit() that is
1774 suitable for use in struct _pseudo_type tables. */
1777 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1779 (void) obj_elf_get_vtable_inherit ();
1782 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1783 to the linker that a vtable slot was used. The syntax is
1784 ".vtable_entry tablename, offset". */
1787 obj_elf_get_vtable_entry (void)
1792 if (*input_line_pointer
== '#')
1793 ++input_line_pointer
;
1795 sym
= get_sym_from_input_line_and_check ();
1796 if (*input_line_pointer
!= ',')
1798 as_bad (_("expected comma after name in .vtable_entry"));
1799 ignore_rest_of_line ();
1803 ++input_line_pointer
;
1804 if (*input_line_pointer
== '#')
1805 ++input_line_pointer
;
1807 offset
= get_absolute_expression ();
1809 demand_empty_rest_of_line ();
1811 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1812 BFD_RELOC_VTABLE_ENTRY
);
1815 /* This is a version of obj_elf_get_vtable_entry() that is
1816 suitable for use in struct _pseudo_type tables. */
1819 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1821 (void) obj_elf_get_vtable_entry ();
1824 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1827 skip_past_char (char ** str
, char c
)
1837 #define skip_past_comma(str) skip_past_char (str, ',')
1839 /* A list of attributes that have been explicitly set by the assembly code.
1840 VENDOR is the vendor id, BASE is the tag shifted right by the number
1841 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1842 struct recorded_attribute_info
{
1843 struct recorded_attribute_info
*next
;
1848 static struct recorded_attribute_info
*recorded_attributes
;
1850 /* Record that we have seen an explicit specification of attribute TAG
1851 for vendor VENDOR. */
1854 record_attribute (int vendor
, unsigned int tag
)
1858 struct recorded_attribute_info
*rai
;
1860 base
= tag
/ (8 * sizeof (rai
->mask
));
1861 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1862 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1863 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1869 rai
= XNEW (struct recorded_attribute_info
);
1870 rai
->next
= recorded_attributes
;
1871 rai
->vendor
= vendor
;
1874 recorded_attributes
= rai
;
1877 /* Return true if we have seen an explicit specification of attribute TAG
1878 for vendor VENDOR. */
1881 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1885 struct recorded_attribute_info
*rai
;
1887 base
= tag
/ (8 * sizeof (rai
->mask
));
1888 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1889 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1890 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1891 return (rai
->mask
& mask
) != 0;
1895 /* Parse an attribute directive for VENDOR.
1896 Returns the attribute number read, or zero on error. */
1899 obj_elf_vendor_attribute (int vendor
)
1907 /* Read the first number or name. */
1908 skip_whitespace (input_line_pointer
);
1909 s
= input_line_pointer
;
1910 if (ISDIGIT (*input_line_pointer
))
1913 if (exp
.X_op
!= O_constant
)
1915 tag
= exp
.X_add_number
;
1921 /* A name may contain '_', but no other punctuation. */
1922 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1923 ++input_line_pointer
)
1928 name
= xstrndup (s
, i
);
1930 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
1931 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
1934 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
1937 as_bad (_("Attribute name not recognised: %s"), name
);
1938 ignore_rest_of_line ();
1945 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
1947 if (skip_past_comma (&input_line_pointer
) == -1)
1952 if (exp
.X_op
!= O_constant
)
1954 as_bad (_("expected numeric constant"));
1955 ignore_rest_of_line ();
1958 i
= exp
.X_add_number
;
1961 && skip_past_comma (&input_line_pointer
) == -1)
1963 as_bad (_("expected comma"));
1964 ignore_rest_of_line ();
1971 skip_whitespace (input_line_pointer
);
1972 if (*input_line_pointer
!= '"')
1974 s
= demand_copy_C_string (&len
);
1977 record_attribute (vendor
, tag
);
1981 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
1984 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
1987 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
1993 demand_empty_rest_of_line ();
1996 as_bad (_("bad string constant"));
1997 ignore_rest_of_line ();
2000 as_bad (_("expected <tag> , <value>"));
2001 ignore_rest_of_line ();
2005 /* Parse a .gnu_attribute directive. */
2008 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
2010 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
2014 elf_obj_read_begin_hook (void)
2016 #ifdef NEED_ECOFF_DEBUG
2017 if (ECOFF_DEBUGGING
)
2018 ecoff_read_begin_hook ();
2023 elf_obj_symbol_new_hook (symbolS
*symbolP
)
2025 struct elf_obj_sy
*sy_obj
;
2027 sy_obj
= symbol_get_obj (symbolP
);
2028 sy_obj
->size
= NULL
;
2029 sy_obj
->versioned_name
= NULL
;
2031 #ifdef NEED_ECOFF_DEBUG
2032 if (ECOFF_DEBUGGING
)
2033 ecoff_symbol_new_hook (symbolP
);
2037 /* When setting one symbol equal to another, by default we probably
2038 want them to have the same "size", whatever it means in the current
2042 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
2044 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
2045 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
2048 if (destelf
->size
== NULL
)
2049 destelf
->size
= XNEW (expressionS
);
2050 *destelf
->size
= *srcelf
->size
;
2054 free (destelf
->size
);
2055 destelf
->size
= NULL
;
2057 S_SET_SIZE (dest
, S_GET_SIZE (src
));
2058 /* Don't copy visibility. */
2059 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
2060 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
2064 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
2069 asection
*seg
= now_seg
;
2070 subsegT subseg
= now_subseg
;
2071 Elf_Internal_Note i_note
;
2072 Elf_External_Note e_note
;
2073 asection
*note_secp
= NULL
;
2076 if (*input_line_pointer
== '\"')
2080 ++input_line_pointer
; /* -> 1st char of string. */
2081 name
= input_line_pointer
;
2083 while (is_a_char (c
= next_char_of_string ()))
2085 c
= *input_line_pointer
;
2086 *input_line_pointer
= '\0';
2087 *(input_line_pointer
- 1) = '\0';
2088 *input_line_pointer
= c
;
2090 /* Create the .note section. */
2091 note_secp
= subseg_new (".note", 0);
2092 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
2093 record_alignment (note_secp
, 2);
2095 /* Process the version string. */
2096 len
= strlen (name
) + 1;
2098 /* PR 3456: Although the name field is padded out to an 4-byte
2099 boundary, the namesz field should not be adjusted. */
2100 i_note
.namesz
= len
;
2101 i_note
.descsz
= 0; /* No description. */
2102 i_note
.type
= NT_VERSION
;
2103 p
= frag_more (sizeof (e_note
.namesz
));
2104 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
2105 p
= frag_more (sizeof (e_note
.descsz
));
2106 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
2107 p
= frag_more (sizeof (e_note
.type
));
2108 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
2109 p
= frag_more (len
);
2110 memcpy (p
, name
, len
);
2112 frag_align (2, 0, 0);
2114 subseg_set (seg
, subseg
);
2117 as_bad (_("expected quoted string"));
2119 demand_empty_rest_of_line ();
2123 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
2126 char c
= get_symbol_name (&name
);
2131 p
= input_line_pointer
;
2133 SKIP_WHITESPACE_AFTER_NAME ();
2134 if (*input_line_pointer
!= ',')
2137 as_bad (_("expected comma after name `%s' in .size directive"), name
);
2139 ignore_rest_of_line ();
2142 input_line_pointer
++;
2144 if (exp
.X_op
== O_absent
)
2146 as_bad (_("missing expression in .size directive"));
2147 exp
.X_op
= O_constant
;
2148 exp
.X_add_number
= 0;
2151 sym
= symbol_find_or_make (name
);
2153 if (exp
.X_op
== O_constant
)
2155 S_SET_SIZE (sym
, exp
.X_add_number
);
2156 xfree (symbol_get_obj (sym
)->size
);
2157 symbol_get_obj (sym
)->size
= NULL
;
2161 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2162 *symbol_get_obj (sym
)->size
= exp
;
2164 demand_empty_rest_of_line ();
2167 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2168 There are six syntaxes:
2170 The first (used on Solaris) is
2172 The second (used on UnixWare) is
2174 The third (reportedly to be used on Irix 6.0) is
2176 The fourth (used on NetBSD/Arm and Linux/ARM) is
2178 The fifth (used on SVR4/860) is
2179 .type SYM,"function"
2180 The sixth (emitted by recent SunPRO under Solaris) is
2182 where the integer is the STT_* value.
2186 obj_elf_type_name (char *cp
)
2190 p
= input_line_pointer
;
2191 if (*input_line_pointer
>= '0'
2192 && *input_line_pointer
<= '9')
2194 while (*input_line_pointer
>= '0'
2195 && *input_line_pointer
<= '9')
2196 ++input_line_pointer
;
2197 *cp
= *input_line_pointer
;
2198 *input_line_pointer
= '\0';
2201 *cp
= get_symbol_name (&p
);
2207 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2211 const char *type_name
;
2213 elf_symbol_type
*elfsym
;
2215 sym
= get_sym_from_input_line_and_check ();
2216 c
= *input_line_pointer
;
2217 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2219 if (*input_line_pointer
== ',')
2220 ++input_line_pointer
;
2223 if ( *input_line_pointer
== '#'
2224 || *input_line_pointer
== '@'
2225 || *input_line_pointer
== '"'
2226 || *input_line_pointer
== '%')
2227 ++input_line_pointer
;
2229 type_name
= obj_elf_type_name (& c
);
2232 if (strcmp (type_name
, "function") == 0
2233 || strcmp (type_name
, "2") == 0
2234 || strcmp (type_name
, "STT_FUNC") == 0)
2235 type
= BSF_FUNCTION
;
2236 else if (strcmp (type_name
, "object") == 0
2237 || strcmp (type_name
, "1") == 0
2238 || strcmp (type_name
, "STT_OBJECT") == 0)
2240 else if (strcmp (type_name
, "tls_object") == 0
2241 || strcmp (type_name
, "6") == 0
2242 || strcmp (type_name
, "STT_TLS") == 0)
2243 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2244 else if (strcmp (type_name
, "notype") == 0
2245 || strcmp (type_name
, "0") == 0
2246 || strcmp (type_name
, "STT_NOTYPE") == 0)
2248 else if (strcmp (type_name
, "common") == 0
2249 || strcmp (type_name
, "5") == 0
2250 || strcmp (type_name
, "STT_COMMON") == 0)
2254 if (! S_IS_COMMON (sym
))
2256 if (S_IS_VOLATILE (sym
))
2258 sym
= symbol_clone (sym
, 1);
2259 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2260 S_SET_VALUE (sym
, 0);
2261 S_SET_EXTERNAL (sym
);
2262 symbol_set_frag (sym
, &zero_address_frag
);
2263 S_CLEAR_VOLATILE (sym
);
2265 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2266 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2269 /* FIXME: Is it safe to just change the section ? */
2270 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2271 S_SET_VALUE (sym
, 0);
2272 S_SET_EXTERNAL (sym
);
2276 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2277 || strcmp (type_name
, "10") == 0
2278 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2280 struct elf_backend_data
*bed
;
2282 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2283 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2284 bed
->elf_osabi
= ELFOSABI_GNU
;
2285 else if (bed
->elf_osabi
!= ELFOSABI_GNU
2286 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2287 as_bad (_("symbol type \"%s\" is supported only by GNU "
2288 "and FreeBSD targets"), type_name
);
2289 /* MIPS targets do not support IFUNCS. */
2290 else if (bed
->target_id
== MIPS_ELF_DATA
)
2291 as_bad (_("symbol type \"%s\" is not supported by "
2292 "MIPS targets"), type_name
);
2293 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2294 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2296 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2298 struct elf_backend_data
*bed
;
2300 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2301 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2302 bed
->elf_osabi
= ELFOSABI_GNU
;
2303 else if (bed
->elf_osabi
!= ELFOSABI_GNU
)
2304 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2306 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2307 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2309 #ifdef md_elf_symbol_type
2310 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2314 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2316 *input_line_pointer
= c
;
2318 if (*input_line_pointer
== '"')
2319 ++input_line_pointer
;
2321 #ifdef md_elf_symbol_type_change
2322 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2325 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2327 if (type
!= BSF_FUNCTION
)
2328 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2329 if (type
!= BSF_OBJECT
)
2331 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2333 if (S_IS_COMMON (sym
))
2335 as_bad (_("cannot change type of common symbol '%s'"),
2341 /* Don't warn when changing to STT_NOTYPE. */
2344 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2346 if (new != (elfsym
->symbol
.flags
| type
))
2347 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2348 elfsym
->symbol
.flags
= new;
2351 elfsym
->symbol
.flags
&= ~mask
;
2354 demand_empty_rest_of_line ();
2358 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2360 static segT comment_section
;
2361 segT old_section
= now_seg
;
2362 int old_subsection
= now_subseg
;
2364 #ifdef md_flush_pending_output
2365 md_flush_pending_output ();
2368 if (!comment_section
)
2371 comment_section
= subseg_new (".comment", 0);
2372 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2373 | SEC_MERGE
| SEC_STRINGS
));
2374 comment_section
->entsize
= 1;
2375 #ifdef md_elf_section_change_hook
2376 md_elf_section_change_hook ();
2382 subseg_set (comment_section
, 0);
2384 subseg_set (old_section
, old_subsection
);
2387 #ifdef INIT_STAB_SECTION
2389 /* The first entry in a .stabs section is special. */
2392 obj_elf_init_stab_section (segT seg
)
2397 unsigned int stroff
;
2399 /* Force the section to align to a longword boundary. Without this,
2400 UnixWare ar crashes. */
2401 bfd_set_section_alignment (seg
, 2);
2403 /* Make space for this first symbol. */
2407 file
= as_where (NULL
);
2408 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2409 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
2410 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2411 md_number_to_chars (p
, stroff
, 4);
2412 seg_info (seg
)->stabu
.p
= p
;
2417 /* Fill in the counts in the first entry in a .stabs section. */
2420 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2427 if (strncmp (".stab", sec
->name
, 5))
2429 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2432 name
= concat (sec
->name
, "str", NULL
);
2433 strsec
= bfd_get_section_by_name (abfd
, name
);
2435 strsz
= bfd_section_size (strsec
);
2438 nsyms
= bfd_section_size (sec
) / 12 - 1;
2440 p
= seg_info (sec
)->stabu
.p
;
2441 gas_assert (p
!= 0);
2443 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2444 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2448 #ifdef NEED_ECOFF_DEBUG
2450 /* This function is called by the ECOFF code. It is supposed to
2451 record the external symbol information so that the backend can
2452 write it out correctly. The ELF backend doesn't actually handle
2453 this at the moment, so we do it ourselves. We save the information
2456 #ifdef OBJ_MAYBE_ELF
2460 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2462 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2465 /* This function is called by bfd_ecoff_debug_externals. It is
2466 supposed to *EXT to the external symbol information, and return
2467 whether the symbol should be used at all. */
2470 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2472 if (sym
->udata
.p
== NULL
)
2474 *ext
= *(EXTR
*) sym
->udata
.p
;
2478 /* This function is called by bfd_ecoff_debug_externals. It has
2479 nothing to do for ELF. */
2482 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2483 bfd_size_type indx ATTRIBUTE_UNUSED
)
2487 #endif /* NEED_ECOFF_DEBUG */
2490 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2492 struct elf_obj_sy
*sy_obj
;
2494 struct elf_versioned_name_list
*versioned_name
;
2496 #ifdef NEED_ECOFF_DEBUG
2497 if (ECOFF_DEBUGGING
)
2498 ecoff_frob_symbol (symp
);
2501 sy_obj
= symbol_get_obj (symp
);
2503 size
= sy_obj
->size
;
2506 if (resolve_expression (size
)
2507 && size
->X_op
== O_constant
)
2508 S_SET_SIZE (symp
, size
->X_add_number
);
2511 if (!flag_allow_nonconst_size
)
2512 as_bad (_(".size expression for %s "
2513 "does not evaluate to a constant"), S_GET_NAME (symp
));
2515 as_warn (_(".size expression for %s "
2516 "does not evaluate to a constant"), S_GET_NAME (symp
));
2518 free (sy_obj
->size
);
2519 sy_obj
->size
= NULL
;
2522 versioned_name
= sy_obj
->versioned_name
;
2525 /* This symbol was given a new name with the .symver directive.
2526 If this is an external reference, just rename the symbol to
2527 include the version string. This will make the relocs be
2528 against the correct versioned symbol. */
2530 /* We will have already reported an version error. */
2531 if (sy_obj
->bad_version
)
2533 /* elf_frob_file_before_adjust only allows one version symbol for
2535 else if (sy_obj
->rename
)
2536 S_SET_NAME (symp
, versioned_name
->name
);
2537 else if (S_IS_COMMON (symp
))
2539 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2540 versioned_name
->name
, S_GET_NAME (symp
));
2546 elf_symbol_type
*elfsym
;
2548 /* This is a definition. Add an alias for each version.
2549 FIXME: Using an alias will permit the debugging information
2550 to refer to the right symbol. However, it's not clear
2551 whether it is the best approach. */
2553 /* FIXME: Creating a new symbol here is risky. We're
2554 in the final loop over the symbol table. We can
2555 get away with it only because the symbol goes to
2556 the end of the list, where the loop will still see
2557 it. It would probably be better to do this in
2558 obj_frob_file_before_adjust. */
2559 for (; versioned_name
!= NULL
;
2560 versioned_name
= versioned_name
->next
)
2562 symbolS
*symp2
= symbol_find_or_make (versioned_name
->name
);
2564 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2566 /* Subtracting out the frag address here is a hack
2567 because we are in the middle of the final loop. */
2570 - symbol_get_frag (symp
)->fr_address
));
2572 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2574 /* This will copy over the size information. */
2575 copy_symbol_attributes (symp2
, symp
);
2577 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2579 if (S_IS_WEAK (symp
))
2582 if (S_IS_EXTERNAL (symp
))
2583 S_SET_EXTERNAL (symp2
);
2586 switch (symbol_get_obj (symp
)->visibility
)
2588 case visibility_unchanged
:
2590 case visibility_hidden
:
2591 bfdsym
= symbol_get_bfdsym (symp
);
2592 elfsym
= elf_symbol_from (bfdsym
);
2593 elfsym
->internal_elf_sym
.st_other
&= ~3;
2594 elfsym
->internal_elf_sym
.st_other
|= STV_HIDDEN
;
2596 case visibility_remove
:
2597 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2599 case visibility_local
:
2600 S_CLEAR_EXTERNAL (symp
);
2606 /* Double check weak symbols. */
2607 if (S_IS_WEAK (symp
))
2609 if (S_IS_COMMON (symp
))
2610 as_bad (_("symbol `%s' can not be both weak and common"),
2617 asection
**head
; /* Section lists. */
2618 unsigned int num_group
; /* Number of lists. */
2619 htab_t indexes
; /* Maps group name to index in head array. */
2622 static struct group_list groups
;
2624 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2625 add it to a list of sections belonging to the group. INF is a
2626 pointer to a struct group_list, which is where we store the head of
2627 each list. If its link_to_symbol_name isn't NULL, set up its
2628 linked-to section. */
2631 build_additional_section_info (bfd
*abfd ATTRIBUTE_UNUSED
,
2632 asection
*sec
, void *inf
)
2634 struct group_list
*list
= (struct group_list
*) inf
;
2635 const char *group_name
= elf_group_name (sec
);
2637 unsigned int *elem_idx
;
2638 unsigned int *idx_ptr
;
2640 if (sec
->map_head
.linked_to_symbol_name
)
2642 symbolS
*linked_to_sym
;
2643 linked_to_sym
= symbol_find (sec
->map_head
.linked_to_symbol_name
);
2644 if (!linked_to_sym
|| !S_IS_DEFINED (linked_to_sym
))
2645 as_bad (_("undefined linked-to symbol `%s' on section `%s'"),
2646 sec
->map_head
.linked_to_symbol_name
,
2647 bfd_section_name (sec
));
2649 elf_linked_to_section (sec
) = S_GET_SEGMENT (linked_to_sym
);
2652 if (group_name
== NULL
)
2655 /* If this group already has a list, add the section to the head of
2657 elem_idx
= (unsigned int *) str_hash_find (list
->indexes
, group_name
);
2658 if (elem_idx
!= NULL
)
2660 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2661 list
->head
[*elem_idx
] = sec
;
2665 /* New group. Make the arrays bigger in chunks to minimize calls to
2667 i
= list
->num_group
;
2670 unsigned int newsize
= i
+ 128;
2671 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2673 list
->head
[i
] = sec
;
2674 list
->num_group
+= 1;
2676 /* Add index to hash. */
2677 idx_ptr
= XNEW (unsigned int);
2679 str_hash_insert (list
->indexes
, group_name
, idx_ptr
, 0);
2683 free_section_idx (void **slot
, void *arg ATTRIBUTE_UNUSED
)
2685 string_tuple_t
*tuple
= *((string_tuple_t
**) slot
);
2686 free ((char *)tuple
->value
);
2690 /* Create symbols for group signature. */
2693 elf_adjust_symtab (void)
2697 /* Go find section groups. */
2698 groups
.num_group
= 0;
2700 groups
.indexes
= str_htab_create ();
2701 bfd_map_over_sections (stdoutput
, build_additional_section_info
,
2704 /* Make the SHT_GROUP sections that describe each section group. We
2705 can't set up the section contents here yet, because elf section
2706 indices have yet to be calculated. elf.c:set_group_contents does
2707 the rest of the work. */
2708 for (i
= 0; i
< groups
.num_group
; i
++)
2710 const char *group_name
= elf_group_name (groups
.head
[i
]);
2711 const char *sec_name
;
2716 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2717 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2718 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2720 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2721 if (s
!= groups
.head
[i
])
2723 as_warn (_("assuming all members of group `%s' are COMDAT"),
2729 sec_name
= ".group";
2730 s
= subseg_force_new (sec_name
, 0);
2732 || !bfd_set_section_flags (s
, flags
)
2733 || !bfd_set_section_alignment (s
, 2))
2735 as_fatal (_("can't create group: %s"),
2736 bfd_errmsg (bfd_get_error ()));
2738 elf_section_type (s
) = SHT_GROUP
;
2740 /* Pass a pointer to the first section in this group. */
2741 elf_next_in_group (s
) = groups
.head
[i
];
2742 elf_sec_group (groups
.head
[i
]) = s
;
2743 /* Make sure that the signature symbol for the group has the
2744 name of the group. */
2745 sy
= symbol_find_exact (group_name
);
2746 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2748 /* Create the symbol now. */
2749 sy
= symbol_new (group_name
, now_seg
, frag_now
, 0);
2751 /* Before Solaris 11 build 154, Sun ld rejects local group
2752 signature symbols, so make them weak hidden instead. */
2753 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2754 S_SET_OTHER (sy
, STV_HIDDEN
);
2756 symbol_get_obj (sy
)->local
= 1;
2758 symbol_table_insert (sy
);
2760 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2765 elf_frob_file (void)
2767 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2769 #ifdef elf_tc_final_processing
2770 elf_tc_final_processing ();
2774 /* It removes any unneeded versioned symbols from the symbol table. */
2777 elf_frob_file_before_adjust (void)
2783 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2785 struct elf_obj_sy
*sy_obj
= symbol_get_obj (symp
);
2786 int is_defined
= !!S_IS_DEFINED (symp
);
2788 if (sy_obj
->versioned_name
)
2790 char *p
= strchr (sy_obj
->versioned_name
->name
,
2795 /* The @@@ syntax is a special case. If the symbol is
2796 not defined, 2 `@'s will be removed from the
2797 versioned_name. Otherwise, 1 `@' will be removed. */
2798 size_t l
= strlen (&p
[3]) + 1;
2799 memmove (&p
[1 + is_defined
], &p
[3], l
);
2804 /* Verify that the name isn't using the @@ syntax--this
2805 is reserved for definitions of the default version
2807 if (!sy_obj
->rename
&& p
[1] == ELF_VER_CHR
)
2809 as_bad (_("invalid attempt to declare external "
2810 "version name as default in symbol `%s'"),
2811 sy_obj
->versioned_name
->name
);
2815 /* Only one version symbol is allowed for undefined
2817 if (sy_obj
->versioned_name
->next
)
2819 as_bad (_("multiple versions [`%s'|`%s'] for "
2821 sy_obj
->versioned_name
->name
,
2822 sy_obj
->versioned_name
->next
->name
,
2827 sy_obj
->rename
= TRUE
;
2831 /* If there was .symver or .weak, but symbol was neither
2832 defined nor used anywhere, remove it. */
2834 && (sy_obj
->versioned_name
|| S_IS_WEAK (symp
))
2835 && symbol_used_p (symp
) == 0
2836 && symbol_used_in_reloc_p (symp
) == 0)
2837 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2842 /* It is required that we let write_relocs have the opportunity to
2843 optimize away fixups before output has begun, since it is possible
2844 to eliminate all fixups for a section and thus we never should
2845 have generated the relocation section. */
2848 elf_frob_file_after_relocs (void)
2852 /* Set SHT_GROUP section size. */
2853 for (i
= 0; i
< groups
.num_group
; i
++)
2855 asection
*s
, *head
, *group
;
2858 head
= groups
.head
[i
];
2860 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2861 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2863 group
= elf_sec_group (head
);
2864 subseg_set (group
, 0);
2865 bfd_set_section_size (group
, size
);
2866 group
->contents
= (unsigned char *) frag_more (size
);
2867 frag_now
->fr_fix
= frag_now_fix_octets ();
2868 frag_wane (frag_now
);
2872 htab_traverse (groups
.indexes
, free_section_idx
, NULL
);
2873 htab_delete (groups
.indexes
);
2875 #ifdef NEED_ECOFF_DEBUG
2876 if (ECOFF_DEBUGGING
)
2877 /* Generate the ECOFF debugging information. */
2879 const struct ecoff_debug_swap
*debug_swap
;
2880 struct ecoff_debug_info debug
;
2885 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2886 know (debug_swap
!= NULL
);
2887 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2889 /* Set up the pointers in debug. */
2890 #define SET(ptr, offset, type) \
2891 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2893 SET (line
, cbLineOffset
, unsigned char *);
2894 SET (external_dnr
, cbDnOffset
, void *);
2895 SET (external_pdr
, cbPdOffset
, void *);
2896 SET (external_sym
, cbSymOffset
, void *);
2897 SET (external_opt
, cbOptOffset
, void *);
2898 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2899 SET (ss
, cbSsOffset
, char *);
2900 SET (external_fdr
, cbFdOffset
, void *);
2901 SET (external_rfd
, cbRfdOffset
, void *);
2902 /* ssext and external_ext are set up just below. */
2906 /* Set up the external symbols. */
2907 debug
.ssext
= debug
.ssext_end
= NULL
;
2908 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2909 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2910 elf_get_extr
, elf_set_index
))
2911 as_fatal (_("failed to set up debugging information: %s"),
2912 bfd_errmsg (bfd_get_error ()));
2914 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2915 gas_assert (sec
!= NULL
);
2917 know (!stdoutput
->output_has_begun
);
2919 /* We set the size of the section, call bfd_set_section_contents
2920 to force the ELF backend to allocate a file position, and then
2921 write out the data. FIXME: Is this really the best way to do
2923 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
2926 /* Pass BUF to bfd_set_section_contents because this will
2927 eventually become a call to fwrite, and ISO C prohibits
2928 passing a NULL pointer to a stdio function even if the
2929 pointer will not be used. */
2930 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
2931 as_fatal (_("can't start writing .mdebug section: %s"),
2932 bfd_errmsg (bfd_get_error ()));
2934 know (stdoutput
->output_has_begun
);
2935 know (sec
->filepos
!= 0);
2937 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2939 as_fatal (_("could not write .mdebug section: %s"),
2940 bfd_errmsg (bfd_get_error ()));
2942 #endif /* NEED_ECOFF_DEBUG */
2946 elf_generate_asm_lineno (void)
2948 #ifdef NEED_ECOFF_DEBUG
2949 if (ECOFF_DEBUGGING
)
2950 ecoff_generate_asm_lineno ();
2955 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
2956 int what ATTRIBUTE_UNUSED
,
2957 const char *string ATTRIBUTE_UNUSED
,
2958 int type ATTRIBUTE_UNUSED
,
2959 int other ATTRIBUTE_UNUSED
,
2960 int desc ATTRIBUTE_UNUSED
)
2962 #ifdef NEED_ECOFF_DEBUG
2963 if (ECOFF_DEBUGGING
)
2964 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
2969 elf_separate_stab_sections (void)
2971 #ifdef NEED_ECOFF_DEBUG
2972 return (!ECOFF_DEBUGGING
);
2979 elf_init_stab_section (segT seg
)
2981 #ifdef NEED_ECOFF_DEBUG
2982 if (!ECOFF_DEBUGGING
)
2984 obj_elf_init_stab_section (seg
);
2987 const struct format_ops elf_format_ops
=
2989 bfd_target_elf_flavour
,
2990 0, /* dfl_leading_underscore */
2991 1, /* emit_section_symbols */
2996 elf_frob_file_before_adjust
,
2997 0, /* obj_frob_file_before_fix */
2998 elf_frob_file_after_relocs
,
2999 elf_s_get_size
, elf_s_set_size
,
3000 elf_s_get_align
, elf_s_set_align
,
3007 elf_copy_symbol_attributes
,
3008 elf_generate_asm_lineno
,
3010 elf_separate_stab_sections
,
3011 elf_init_stab_section
,
3012 elf_sec_sym_ok_for_reloc
,
3014 #ifdef NEED_ECOFF_DEBUG
3017 0, /* ecoff_set_ext */
3019 elf_obj_read_begin_hook
,
3020 elf_obj_symbol_new_hook
,