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);
82 static const pseudo_typeS elf_pseudo_table
[] =
84 {"comm", obj_elf_common
, 0},
85 {"common", obj_elf_common
, 1},
86 {"ident", obj_elf_ident
, 0},
87 {"lcomm", obj_elf_lcomm
, 0},
88 {"local", obj_elf_local
, 0},
89 {"previous", obj_elf_previous
, 0},
90 {"section", obj_elf_section
, 0},
91 {"section.s", obj_elf_section
, 0},
92 {"sect", obj_elf_section
, 0},
93 {"sect.s", obj_elf_section
, 0},
94 {"pushsection", obj_elf_section
, 1},
95 {"popsection", obj_elf_popsection
, 0},
96 {"size", obj_elf_size
, 0},
97 {"type", obj_elf_type
, 0},
98 {"version", obj_elf_version
, 0},
99 {"weak", obj_elf_weak
, 0},
101 /* These define symbol visibility. */
102 {"internal", obj_elf_visibility
, STV_INTERNAL
},
103 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
104 {"protected", obj_elf_visibility
, STV_PROTECTED
},
106 /* These are used for stabs-in-elf configurations. */
107 {"line", obj_elf_line
, 0},
109 /* This is a GNU extension to handle symbol versions. */
110 {"symver", obj_elf_symver
, 0},
112 /* A GNU extension to change subsection only. */
113 {"subsection", obj_elf_subsection
, 0},
115 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
116 {"vtable_inherit", obj_elf_vtable_inherit
, 0},
117 {"vtable_entry", obj_elf_vtable_entry
, 0},
119 /* A GNU extension for object attributes. */
120 {"gnu_attribute", obj_elf_gnu_attribute
, 0},
122 /* These are used for dwarf. */
126 /* These are used for dwarf2. */
127 { "file", dwarf2_directive_file
, 0 },
128 { "loc", dwarf2_directive_loc
, 0 },
129 { "loc_mark_labels", dwarf2_directive_loc_mark_labels
, 0 },
131 /* We need to trap the section changing calls to handle .previous. */
132 {"data", obj_elf_data
, 0},
133 {"offset", obj_elf_struct
, 0},
134 {"struct", obj_elf_struct
, 0},
135 {"text", obj_elf_text
, 0},
137 {"tls_common", obj_elf_tls_common
, 0},
143 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
145 #ifdef NEED_ECOFF_DEBUG
146 /* COFF style debugging information for ECOFF. .ln is not used; .loc
148 { "def", ecoff_directive_def
, 0 },
149 { "dim", ecoff_directive_dim
, 0 },
150 { "endef", ecoff_directive_endef
, 0 },
151 { "file", ecoff_directive_file
, 0 },
152 { "scl", ecoff_directive_scl
, 0 },
153 { "tag", ecoff_directive_tag
, 0 },
154 { "val", ecoff_directive_val
, 0 },
156 /* COFF debugging requires pseudo-ops .size and .type, but ELF
157 already has meanings for those. We use .esize and .etype
158 instead. These are only generated by gcc anyhow. */
159 { "esize", ecoff_directive_size
, 0 },
160 { "etype", ecoff_directive_type
, 0 },
162 /* ECOFF specific debugging information. */
163 { "aent", ecoff_directive_ent
, 1 },
164 { "begin", ecoff_directive_begin
, 0 },
165 { "bend", ecoff_directive_bend
, 0 },
166 { "end", ecoff_directive_end
, 0 },
167 { "ent", ecoff_directive_ent
, 0 },
168 { "fmask", ecoff_directive_fmask
, 0 },
169 { "frame", ecoff_directive_frame
, 0 },
170 { "loc", ecoff_directive_loc
, 0 },
171 { "mask", ecoff_directive_mask
, 0 },
173 /* Other ECOFF directives. */
174 { "extern", ecoff_directive_extern
, 0 },
176 /* These are used on Irix. I don't know how to implement them. */
177 { "alias", s_ignore
, 0 },
178 { "bgnb", s_ignore
, 0 },
179 { "endb", s_ignore
, 0 },
180 { "lab", s_ignore
, 0 },
181 { "noalias", s_ignore
, 0 },
182 { "verstamp", s_ignore
, 0 },
183 { "vreg", s_ignore
, 0 },
186 {NULL
, NULL
, 0} /* end sentinel */
190 #include "aout/aout64.h"
192 /* This is called when the assembler starts. */
194 asection
*elf_com_section_ptr
;
201 /* Add symbols for the known sections to the symbol table. */
202 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
203 symbol_table_insert (section_symbol (s
));
204 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
205 symbol_table_insert (section_symbol (s
));
206 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
207 symbol_table_insert (section_symbol (s
));
208 elf_com_section_ptr
= bfd_com_section_ptr
;
212 elf_pop_insert (void)
214 pop_insert (elf_pseudo_table
);
216 pop_insert (ecoff_debug_pseudo_table
);
220 elf_s_get_size (symbolS
*sym
)
222 return S_GET_SIZE (sym
);
226 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
228 S_SET_SIZE (sym
, sz
);
232 elf_s_get_align (symbolS
*sym
)
234 return S_GET_ALIGN (sym
);
238 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
240 S_SET_ALIGN (sym
, align
);
244 elf_s_get_other (symbolS
*sym
)
246 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
250 elf_s_set_other (symbolS
*sym
, int other
)
252 S_SET_OTHER (sym
, other
);
256 elf_sec_sym_ok_for_reloc (asection
*sec
)
258 return obj_sec_sym_ok_for_reloc (sec
);
262 elf_file_symbol (const char *s
, int appfile
)
267 || symbol_rootP
== NULL
268 || (bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
269 || (bsym
->flags
& BSF_FILE
) == 0)
274 sym
= symbol_new (s
, absolute_section
, 0, NULL
);
275 symbol_set_frag (sym
, &zero_address_frag
);
277 name_length
= strlen (s
);
278 if (name_length
> strlen (S_GET_NAME (sym
)))
280 obstack_grow (¬es
, s
, name_length
+ 1);
281 S_SET_NAME (sym
, (const char *) obstack_finish (¬es
));
284 strcpy ((char *) S_GET_NAME (sym
), s
);
286 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
288 if (symbol_rootP
!= sym
289 && ((bsym
= symbol_get_bfdsym (symbol_rootP
)) == NULL
290 || (bsym
->flags
& BSF_FILE
) == 0))
292 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
293 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
297 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
301 #ifdef NEED_ECOFF_DEBUG
302 ecoff_new_file (s
, appfile
);
306 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
307 Parse a possible alignment value. */
310 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
313 int is_local
= symbol_get_obj (symbolP
)->local
;
315 if (*input_line_pointer
== ',')
317 char *save
= input_line_pointer
;
319 input_line_pointer
++;
322 if (*input_line_pointer
== '"')
324 /* For sparc. Accept .common symbol, length, "bss" */
325 input_line_pointer
++;
326 /* Some use the dot, some don't. */
327 if (*input_line_pointer
== '.')
328 input_line_pointer
++;
329 /* Some say data, some say bss. */
330 if (strncmp (input_line_pointer
, "bss\"", 4) == 0)
331 input_line_pointer
+= 4;
332 else if (strncmp (input_line_pointer
, "data\"", 5) == 0)
333 input_line_pointer
+= 5;
336 char *p
= input_line_pointer
;
341 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
342 if (*input_line_pointer
++ == '"')
344 c
= *input_line_pointer
;
345 *input_line_pointer
= '\0';
346 as_bad (_("bad .common segment %s"), p
);
347 *input_line_pointer
= c
;
348 ignore_rest_of_line ();
351 /* ??? Don't ask me why these are always global. */
356 input_line_pointer
= save
;
357 align
= parse_align (is_local
);
358 if (align
== (addressT
) -1)
365 bss_alloc (symbolP
, size
, align
);
366 S_CLEAR_EXTERNAL (symbolP
);
370 S_SET_VALUE (symbolP
, size
);
371 S_SET_ALIGN (symbolP
, align
);
372 S_SET_EXTERNAL (symbolP
);
373 S_SET_SEGMENT (symbolP
, elf_com_section_ptr
);
376 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
382 obj_elf_common (int is_common
)
384 if (flag_mri
&& is_common
)
387 s_comm_internal (0, elf_common_parse
);
391 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
393 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
396 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
400 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
402 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
405 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
409 get_sym_from_input_line_and_check (void)
415 c
= get_symbol_name (& name
);
416 sym
= symbol_find_or_make (name
);
417 *input_line_pointer
= c
;
418 SKIP_WHITESPACE_AFTER_NAME ();
420 /* There is no symbol name if input_line_pointer has not moved. */
421 if (name
== input_line_pointer
)
422 as_bad (_("Missing symbol name in directive"));
427 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
434 symbolP
= get_sym_from_input_line_and_check ();
435 c
= *input_line_pointer
;
436 S_CLEAR_EXTERNAL (symbolP
);
437 symbol_get_obj (symbolP
)->local
= 1;
440 input_line_pointer
++;
442 if (*input_line_pointer
== '\n')
447 demand_empty_rest_of_line ();
451 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
458 symbolP
= get_sym_from_input_line_and_check ();
459 c
= *input_line_pointer
;
460 S_SET_WEAK (symbolP
);
463 input_line_pointer
++;
465 if (*input_line_pointer
== '\n')
470 demand_empty_rest_of_line ();
474 obj_elf_visibility (int visibility
)
479 elf_symbol_type
*elfsym
;
483 symbolP
= get_sym_from_input_line_and_check ();
485 bfdsym
= symbol_get_bfdsym (symbolP
);
486 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
490 elfsym
->internal_elf_sym
.st_other
&= ~3;
491 elfsym
->internal_elf_sym
.st_other
|= visibility
;
493 c
= *input_line_pointer
;
496 input_line_pointer
++;
500 if (*input_line_pointer
== '\n')
506 demand_empty_rest_of_line ();
509 static segT previous_section
;
510 static int previous_subsection
;
514 struct section_stack
*next
;
516 int subseg
, prev_subseg
;
519 static struct section_stack
*section_stack
;
522 get_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
524 struct elf_section_match
*match
= (struct elf_section_match
*) inf
;
525 const char *gname
= match
->group_name
;
526 const char *group_name
= elf_group_name (sec
);
527 unsigned int info
= elf_section_data (sec
)->this_hdr
.sh_info
;
529 return (info
== match
->info
530 && ((bfd_section_flags (sec
) & SEC_ASSEMBLER_SECTION_ID
)
531 == (match
->flags
& SEC_ASSEMBLER_SECTION_ID
))
532 && sec
->section_id
== match
->section_id
533 && (group_name
== gname
534 || (group_name
!= NULL
536 && strcmp (group_name
, gname
) == 0)));
539 /* Handle the .section pseudo-op. This code supports two different
542 The first is found on Solaris, and looks like
543 .section ".sec1",#alloc,#execinstr,#write
544 Here the names after '#' are the SHF_* flags to turn on for the
545 section. I'm not sure how it determines the SHT_* type (BFD
546 doesn't really give us control over the type, anyhow).
548 The second format is found on UnixWare, and probably most SVR4
549 machines, and looks like
550 .section .sec1,"a",@progbits
551 The quoted string may contain any combination of a, w, x, and
552 represents the SHF_* flags to turn on for the section. The string
553 beginning with '@' can be progbits or nobits. There should be
554 other possibilities, but I don't know what they are. In any case,
555 BFD doesn't really let us set the section type. */
558 obj_elf_change_section (const char *name
,
562 struct elf_section_match
*match_p
,
569 const struct elf_backend_data
*bed
;
570 const struct bfd_elf_special_section
*ssect
;
574 static struct elf_section_match unused_match
;
575 match_p
= &unused_match
;
578 #ifdef md_flush_pending_output
579 md_flush_pending_output ();
582 /* Switch to the section, creating it if necessary. */
585 struct section_stack
*elt
;
586 elt
= XNEW (struct section_stack
);
587 elt
->next
= section_stack
;
589 elt
->prev_seg
= previous_section
;
590 elt
->subseg
= now_subseg
;
591 elt
->prev_subseg
= previous_subsection
;
594 previous_section
= now_seg
;
595 previous_subsection
= now_subseg
;
597 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section
,
605 sec
= subseg_force_new (name
, 0);
607 bed
= get_elf_backend_data (stdoutput
);
608 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
612 bfd_boolean override
= FALSE
;
614 if (type
== SHT_NULL
)
616 else if (type
!= ssect
->type
)
619 /* Some older versions of gcc will emit
621 .section .init_array,"aw",@progbits
623 for __attribute__ ((section (".init_array"))).
624 "@progbits" is incorrect. Also for x86-64 large bss
625 sections, some older versions of gcc will emit
627 .section .lbss,"aw",@progbits
629 "@progbits" is incorrect. */
631 && (bed
->s
->arch_size
!= 64
632 || !(ssect
->attr
& SHF_X86_64_LARGE
))
634 && ssect
->type
!= SHT_INIT_ARRAY
635 && ssect
->type
!= SHT_FINI_ARRAY
636 && ssect
->type
!= SHT_PREINIT_ARRAY
)
638 /* We allow to specify any type for a .note section. */
639 if (ssect
->type
!= SHT_NOTE
640 /* Processor and application defined types are allowed too. */
641 && type
< SHT_LOPROC
)
642 as_warn (_("setting incorrect section type for %s"),
647 as_warn (_("ignoring incorrect section type for %s"),
653 if (old_sec
== NULL
&& ((attr
& ~(SHF_MASKOS
| SHF_MASKPROC
))
654 & ~ssect
->attr
) != 0)
656 /* As a GNU extension, we permit a .note section to be
657 allocatable. If the linker sees an allocatable .note
658 section, it will create a PT_NOTE segment in the output
659 file. We also allow "x" for .note.GNU-stack. */
660 if (ssect
->type
== SHT_NOTE
661 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
663 /* Allow different SHF_MERGE and SHF_STRINGS if we have
664 something like .rodata.str. */
665 else if (ssect
->suffix_length
== -2
666 && name
[ssect
->prefix_length
] == '.'
670 & ~SHF_STRINGS
) == 0)
672 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
673 else if (attr
== SHF_ALLOC
674 && (strcmp (name
, ".interp") == 0
675 || strcmp (name
, ".strtab") == 0
676 || strcmp (name
, ".symtab") == 0))
678 /* .note.GNU-stack can have SHF_EXECINSTR. */
679 else if (attr
== SHF_EXECINSTR
680 && strcmp (name
, ".note.GNU-stack") == 0)
683 /* A section on Alpha may have SHF_ALPHA_GPREL. */
684 else if ((attr
& ~ssect
->attr
) == SHF_ALPHA_GPREL
)
688 else if (attr
== (SHF_EXECINSTR
| SHF_WRITE
| SHF_ALLOC
)
689 && (ssect
->type
== SHT_INIT_ARRAY
690 || ssect
->type
== SHT_FINI_ARRAY
691 || ssect
->type
== SHT_PREINIT_ARRAY
))
692 /* RX init/fini arrays can and should have the "awx" attributes set. */
697 if (match_p
->group_name
== NULL
)
698 as_warn (_("setting incorrect section attributes for %s"),
704 if (!override
&& old_sec
== NULL
)
708 /* Convert ELF type and flags to BFD flags. */
710 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
711 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
712 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
713 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
714 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
715 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
716 | ((attr
& SHF_EXCLUDE
) ? SEC_EXCLUDE
: 0)
717 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
718 #ifdef md_elf_section_flags
719 flags
= md_elf_section_flags (flags
, attr
, type
);
723 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
729 if (type
== SHT_NULL
)
730 type
= bfd_elf_get_default_section_type (flags
);
731 elf_section_type (sec
) = type
;
732 elf_section_flags (sec
) = attr
;
733 elf_section_data (sec
)->this_hdr
.sh_info
= match_p
->info
;
735 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
736 if (type
== SHT_NOBITS
)
737 seg_info (sec
)->bss
= 1;
739 /* Set the section ID and flags. */
740 sec
->section_id
= match_p
->section_id
;
741 flags
|= match_p
->flags
;
743 bfd_set_section_flags (sec
, flags
);
744 if (flags
& SEC_MERGE
)
745 sec
->entsize
= entsize
;
746 elf_group_name (sec
) = match_p
->group_name
;
748 /* Add a symbol for this section to the symbol table. */
749 secsym
= symbol_find (name
);
751 symbol_set_bfdsym (secsym
, sec
->symbol
);
753 symbol_table_insert (section_symbol (sec
));
758 && (unsigned) type
!= elf_section_type (old_sec
))
759 as_warn (_("ignoring changed section type for %s"), name
);
763 /* If section attributes are specified the second time we see a
764 particular section, then check that they are the same as we
765 saw the first time. */
766 if (((old_sec
->flags
^ flags
)
767 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
768 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
769 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
770 | SEC_THREAD_LOCAL
)))
771 as_warn (_("ignoring changed section attributes for %s"), name
);
773 /* FIXME: Maybe we should consider removing a previously set
774 processor or application specific attribute as suspicious ? */
775 elf_section_flags (sec
) = attr
;
777 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
778 as_warn (_("ignoring changed section entity size for %s"), name
);
782 #ifdef md_elf_section_change_hook
783 md_elf_section_change_hook ();
788 obj_elf_parse_section_letters (char *str
, size_t len
,
789 bfd_boolean
*is_clone
, bfd_vma
*gnu_attr
)
808 attr
|= SHF_EXECINSTR
;
823 *gnu_attr
|= SHF_GNU_MBIND
;
830 if (*(str
- 1) == 'a')
833 if (len
> 1 && str
[1] == 's')
843 const char *bad_msg
= _("unrecognized .section attribute:"
844 " want a,e,w,x,M,S,G,T or number");
845 #ifdef md_elf_section_letter
846 bfd_vma md_attr
= md_elf_section_letter (*str
, &bad_msg
);
847 if (md_attr
!= (bfd_vma
) -1)
855 attr
|= strtoul (str
, & end
, 0);
856 /* Update str and len, allowing for the fact that
857 we will execute str++ and len-- below. */
863 as_fatal ("%s", bad_msg
);
874 obj_elf_section_type (char *str
, size_t len
, bfd_boolean warn
)
876 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
878 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
880 if (len
== 4 && strncmp (str
, "note", 4) == 0)
882 if (len
== 10 && strncmp (str
, "init_array", 10) == 0)
883 return SHT_INIT_ARRAY
;
884 if (len
== 10 && strncmp (str
, "fini_array", 10) == 0)
885 return SHT_FINI_ARRAY
;
886 if (len
== 13 && strncmp (str
, "preinit_array", 13) == 0)
887 return SHT_PREINIT_ARRAY
;
889 #ifdef md_elf_section_type
891 int md_type
= md_elf_section_type (str
, len
);
900 int type
= strtoul (str
, & end
, 0);
902 if (warn
&& (size_t) (end
- str
) != len
)
903 as_warn (_("extraneous characters at end of numeric section type"));
909 as_warn (_("unrecognized section type"));
914 obj_elf_section_word (char *str
, size_t len
, int *type
)
918 if (len
== 5 && strncmp (str
, "write", 5) == 0)
920 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
922 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
923 return SHF_EXECINSTR
;
924 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
926 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
929 #ifdef md_elf_section_word
931 bfd_vma md_attr
= md_elf_section_word (str
, len
);
937 ret
= obj_elf_section_type (str
, len
, FALSE
);
941 as_warn (_("unrecognized section attribute"));
946 /* Get name of section. */
948 obj_elf_section_name (void)
953 if (*input_line_pointer
== '"')
957 name
= demand_copy_C_string (&dummy
);
960 ignore_rest_of_line ();
966 char *end
= input_line_pointer
;
968 while (0 == strchr ("\n\t,; ", *end
))
970 if (end
== input_line_pointer
)
972 as_bad (_("missing name"));
973 ignore_rest_of_line ();
977 name
= xmemdup0 (input_line_pointer
, end
- input_line_pointer
);
979 while (flag_sectname_subst
)
981 char *subst
= strchr (name
, '%');
982 if (subst
&& subst
[1] == 'S')
984 int oldlen
= strlen (name
);
985 int substlen
= strlen (now_seg
->name
);
986 int newlen
= oldlen
- 2 + substlen
;
987 char *newname
= XNEWVEC (char, newlen
+ 1);
988 int headlen
= subst
- name
;
989 memcpy (newname
, name
, headlen
);
990 strcpy (newname
+ headlen
, now_seg
->name
);
991 strcat (newname
+ headlen
, subst
+ 2);
999 #ifdef tc_canonicalize_section_name
1000 name
= tc_canonicalize_section_name (name
);
1002 input_line_pointer
= end
;
1009 obj_elf_section (int push
)
1018 subsegT new_subsection
= -1;
1019 struct elf_section_match match
;
1025 #ifdef md_flush_pending_output
1026 md_flush_pending_output ();
1029 previous_section
= now_seg
;
1030 previous_subsection
= now_subseg
;
1032 s_mri_sect (&mri_type
);
1034 #ifdef md_elf_section_change_hook
1035 md_elf_section_change_hook ();
1041 name
= obj_elf_section_name ();
1045 memset (&match
, 0, sizeof (match
));
1048 if ((sym
= symbol_find (name
)) != NULL
1049 && ! symbol_section_p (sym
)
1050 && S_IS_DEFINED (sym
)
1051 && ! S_IS_VOLATILE (sym
)
1052 && ! S_CAN_BE_REDEFINED (sym
))
1054 as_bad (_("section name '%s' already defined as another symbol"), name
);
1055 ignore_rest_of_line ();
1064 if (*input_line_pointer
== ',')
1066 /* Skip the comma. */
1067 ++input_line_pointer
;
1070 if (push
&& ISDIGIT (*input_line_pointer
))
1072 /* .pushsection has an optional subsection. */
1073 new_subsection
= (subsegT
) get_absolute_expression ();
1077 /* Stop if we don't see a comma. */
1078 if (*input_line_pointer
!= ',')
1081 /* Skip the comma. */
1082 ++input_line_pointer
;
1086 if (*input_line_pointer
== '"')
1088 bfd_boolean is_clone
;
1090 beg
= demand_copy_C_string (&dummy
);
1093 ignore_rest_of_line ();
1096 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
),
1097 &is_clone
, &gnu_attr
);
1100 if (*input_line_pointer
== ',')
1103 char *save
= input_line_pointer
;
1105 ++input_line_pointer
;
1107 c
= *input_line_pointer
;
1110 beg
= demand_copy_C_string (&dummy
);
1113 ignore_rest_of_line ();
1116 type
= obj_elf_section_type (beg
, strlen (beg
), TRUE
);
1118 else if (c
== '@' || c
== '%')
1120 ++input_line_pointer
;
1122 if (ISDIGIT (* input_line_pointer
))
1123 type
= strtoul (input_line_pointer
, &input_line_pointer
, 0);
1126 c
= get_symbol_name (& beg
);
1127 (void) restore_line_pointer (c
);
1128 type
= obj_elf_section_type (beg
,
1129 input_line_pointer
- beg
,
1134 input_line_pointer
= save
;
1138 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1140 ++input_line_pointer
;
1142 entsize
= get_absolute_expression ();
1146 as_warn (_("invalid merge entity size"));
1151 else if ((attr
& SHF_MERGE
) != 0)
1153 as_warn (_("entity size for SHF_MERGE not specified"));
1157 if ((attr
& SHF_GROUP
) != 0 && is_clone
)
1159 as_warn (_("? section flag ignored with G present"));
1162 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1164 ++input_line_pointer
;
1165 match
.group_name
= obj_elf_section_name ();
1166 if (match
.group_name
== NULL
)
1168 else if (*input_line_pointer
== ',')
1170 ++input_line_pointer
;
1172 if (strncmp (input_line_pointer
, "comdat", 6) == 0)
1174 input_line_pointer
+= 6;
1178 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1181 else if ((attr
& SHF_GROUP
) != 0)
1183 as_warn (_("group name for SHF_GROUP not specified"));
1189 const char *now_group
= elf_group_name (now_seg
);
1190 if (now_group
!= NULL
)
1192 match
.group_name
= xstrdup (now_group
);
1193 linkonce
= (now_seg
->flags
& SEC_LINK_ONCE
) != 0;
1197 if ((gnu_attr
& SHF_GNU_MBIND
) != 0 && *input_line_pointer
== ',')
1199 char *save
= input_line_pointer
;
1200 ++input_line_pointer
;
1202 if (ISDIGIT (* input_line_pointer
))
1204 char *t
= input_line_pointer
;
1205 match
.info
= strtoul (input_line_pointer
,
1206 &input_line_pointer
, 0);
1207 if (match
.info
== (unsigned int) -1)
1209 as_warn (_("unsupported mbind section info: %s"), t
);
1214 input_line_pointer
= save
;
1217 if (*input_line_pointer
== ',')
1219 char *save
= input_line_pointer
;
1220 ++input_line_pointer
;
1222 if (strncmp (input_line_pointer
, "unique", 6) == 0)
1224 input_line_pointer
+= 6;
1226 if (*input_line_pointer
== ',')
1228 ++input_line_pointer
;
1230 if (ISDIGIT (* input_line_pointer
))
1233 bfd_boolean overflow
;
1234 char *t
= input_line_pointer
;
1235 if (sizeof (bfd_vma
) <= sizeof (unsigned long))
1238 id
= strtoul (input_line_pointer
,
1239 &input_line_pointer
, 0);
1240 overflow
= (id
== (unsigned long) -1
1241 && errno
== ERANGE
);
1246 (input_line_pointer
,
1247 (const char **) &input_line_pointer
, 0);
1248 overflow
= id
== ~(bfd_vma
) 0;
1250 if (overflow
|| id
> (unsigned int) -1)
1252 char *linefeed
, saved_char
= 0;
1253 if ((linefeed
= strchr (t
, '\n')) != NULL
)
1255 saved_char
= *linefeed
;
1258 as_bad (_("unsupported section id: %s"), t
);
1260 *linefeed
= saved_char
;
1264 match
.section_id
= id
;
1265 match
.flags
|= SEC_ASSEMBLER_SECTION_ID
;
1271 input_line_pointer
= save
;
1281 if (*input_line_pointer
!= '#')
1283 as_bad (_("character following name is not '#'"));
1284 ignore_rest_of_line ();
1287 ++input_line_pointer
;
1288 c
= get_symbol_name (& beg
);
1289 (void) restore_line_pointer (c
);
1291 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
,
1296 while (*input_line_pointer
++ == ',');
1297 --input_line_pointer
;
1302 demand_empty_rest_of_line ();
1304 obj_elf_change_section (name
, type
, attr
, entsize
, &match
, linkonce
,
1307 if ((gnu_attr
& SHF_GNU_MBIND
) != 0)
1309 struct elf_backend_data
*bed
;
1311 if ((attr
& SHF_ALLOC
) == 0)
1312 as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name
);
1314 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
1315 if (bed
->elf_osabi
== ELFOSABI_NONE
)
1316 bed
->elf_osabi
= ELFOSABI_GNU
;
1317 else if (bed
->elf_osabi
!= ELFOSABI_GNU
1318 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
1319 as_bad (_("GNU_MBIND section is supported only by GNU "
1320 "and FreeBSD targets"));
1321 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_mbind
;
1323 elf_section_flags (now_seg
) |= gnu_attr
;
1325 if (push
&& new_subsection
!= -1)
1326 subseg_set (now_seg
, new_subsection
);
1329 /* Change to the .data section. */
1332 obj_elf_data (int i
)
1334 #ifdef md_flush_pending_output
1335 md_flush_pending_output ();
1338 previous_section
= now_seg
;
1339 previous_subsection
= now_subseg
;
1342 #ifdef md_elf_section_change_hook
1343 md_elf_section_change_hook ();
1347 /* Change to the .text section. */
1350 obj_elf_text (int i
)
1352 #ifdef md_flush_pending_output
1353 md_flush_pending_output ();
1356 previous_section
= now_seg
;
1357 previous_subsection
= now_subseg
;
1360 #ifdef md_elf_section_change_hook
1361 md_elf_section_change_hook ();
1365 /* Change to the *ABS* section. */
1368 obj_elf_struct (int i
)
1370 #ifdef md_flush_pending_output
1371 md_flush_pending_output ();
1374 previous_section
= now_seg
;
1375 previous_subsection
= now_subseg
;
1378 #ifdef md_elf_section_change_hook
1379 md_elf_section_change_hook ();
1384 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1388 #ifdef md_flush_pending_output
1389 md_flush_pending_output ();
1392 previous_section
= now_seg
;
1393 previous_subsection
= now_subseg
;
1395 temp
= get_absolute_expression ();
1396 subseg_set (now_seg
, (subsegT
) temp
);
1397 demand_empty_rest_of_line ();
1399 #ifdef md_elf_section_change_hook
1400 md_elf_section_change_hook ();
1404 /* This can be called from the processor backends if they change
1408 obj_elf_section_change_hook (void)
1410 previous_section
= now_seg
;
1411 previous_subsection
= now_subseg
;
1415 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1420 if (previous_section
== 0)
1422 as_warn (_(".previous without corresponding .section; ignored"));
1426 #ifdef md_flush_pending_output
1427 md_flush_pending_output ();
1430 new_section
= previous_section
;
1431 new_subsection
= previous_subsection
;
1432 previous_section
= now_seg
;
1433 previous_subsection
= now_subseg
;
1434 subseg_set (new_section
, new_subsection
);
1436 #ifdef md_elf_section_change_hook
1437 md_elf_section_change_hook ();
1442 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1444 struct section_stack
*top
= section_stack
;
1448 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1452 #ifdef md_flush_pending_output
1453 md_flush_pending_output ();
1456 section_stack
= top
->next
;
1457 previous_section
= top
->prev_seg
;
1458 previous_subsection
= top
->prev_subseg
;
1459 subseg_set (top
->seg
, top
->subseg
);
1462 #ifdef md_elf_section_change_hook
1463 md_elf_section_change_hook ();
1468 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1470 /* Assume delimiter is part of expression. BSD4.2 as fails with
1471 delightful bug, so we are not being incompatible here. */
1472 new_logical_line (NULL
, get_absolute_expression ());
1473 demand_empty_rest_of_line ();
1476 /* This handles the .symver pseudo-op, which is used to specify a
1477 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1478 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1479 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1480 with the same value as the symbol NAME. */
1483 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1490 sym
= get_sym_from_input_line_and_check ();
1492 if (*input_line_pointer
!= ',')
1494 as_bad (_("expected comma after name in .symver"));
1495 ignore_rest_of_line ();
1499 ++input_line_pointer
;
1502 /* Temporarily include '@' in symbol names. */
1503 old_lexat
= lex_type
[(unsigned char) '@'];
1504 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1505 c
= get_symbol_name (& name
);
1506 lex_type
[(unsigned char) '@'] = old_lexat
;
1508 if (S_IS_COMMON (sym
))
1510 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
1511 name
, S_GET_NAME (sym
));
1512 ignore_rest_of_line ();
1516 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1518 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1520 (void) restore_line_pointer (c
);
1522 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1523 ELF_VER_CHR
) == NULL
)
1525 as_bad (_("missing version name in `%s' for symbol `%s'"),
1526 symbol_get_obj (sym
)->versioned_name
,
1528 ignore_rest_of_line ();
1534 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1536 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1537 name
, symbol_get_obj (sym
)->versioned_name
,
1539 ignore_rest_of_line ();
1543 (void) restore_line_pointer (c
);
1546 demand_empty_rest_of_line ();
1549 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1550 to the linker the hierarchy in which a particular table resides. The
1551 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1554 obj_elf_get_vtable_inherit (void)
1556 char *cname
, *pname
;
1557 symbolS
*csym
, *psym
;
1560 if (*input_line_pointer
== '#')
1561 ++input_line_pointer
;
1563 c
= get_symbol_name (& cname
);
1564 csym
= symbol_find (cname
);
1566 /* GCFIXME: should check that we don't have two .vtable_inherits for
1567 the same child symbol. Also, we can currently only do this if the
1568 child symbol is already exists and is placed in a fragment. */
1570 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1572 as_bad (_("expected `%s' to have already been set for .vtable_inherit"),
1577 *input_line_pointer
= c
;
1579 SKIP_WHITESPACE_AFTER_NAME ();
1580 if (*input_line_pointer
!= ',')
1582 as_bad (_("expected comma after name in .vtable_inherit"));
1583 ignore_rest_of_line ();
1587 ++input_line_pointer
;
1590 if (*input_line_pointer
== '#')
1591 ++input_line_pointer
;
1593 if (input_line_pointer
[0] == '0'
1594 && (input_line_pointer
[1] == '\0'
1595 || ISSPACE (input_line_pointer
[1])))
1597 psym
= section_symbol (absolute_section
);
1598 ++input_line_pointer
;
1602 c
= get_symbol_name (& pname
);
1603 psym
= symbol_find_or_make (pname
);
1604 restore_line_pointer (c
);
1607 demand_empty_rest_of_line ();
1612 gas_assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1613 return fix_new (symbol_get_frag (csym
),
1614 symbol_get_value_expression (csym
)->X_add_number
,
1615 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1618 /* This is a version of obj_elf_get_vtable_inherit() that is
1619 suitable for use in struct _pseudo_type tables. */
1622 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1624 (void) obj_elf_get_vtable_inherit ();
1627 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1628 to the linker that a vtable slot was used. The syntax is
1629 ".vtable_entry tablename, offset". */
1632 obj_elf_get_vtable_entry (void)
1637 if (*input_line_pointer
== '#')
1638 ++input_line_pointer
;
1640 sym
= get_sym_from_input_line_and_check ();
1641 if (*input_line_pointer
!= ',')
1643 as_bad (_("expected comma after name in .vtable_entry"));
1644 ignore_rest_of_line ();
1648 ++input_line_pointer
;
1649 if (*input_line_pointer
== '#')
1650 ++input_line_pointer
;
1652 offset
= get_absolute_expression ();
1654 demand_empty_rest_of_line ();
1656 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1657 BFD_RELOC_VTABLE_ENTRY
);
1660 /* This is a version of obj_elf_get_vtable_entry() that is
1661 suitable for use in struct _pseudo_type tables. */
1664 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1666 (void) obj_elf_get_vtable_entry ();
1669 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1672 skip_past_char (char ** str
, char c
)
1682 #define skip_past_comma(str) skip_past_char (str, ',')
1684 /* A list of attributes that have been explicitly set by the assembly code.
1685 VENDOR is the vendor id, BASE is the tag shifted right by the number
1686 of bits in MASK, and bit N of MASK is set if tag BASE+N has been set. */
1687 struct recorded_attribute_info
{
1688 struct recorded_attribute_info
*next
;
1693 static struct recorded_attribute_info
*recorded_attributes
;
1695 /* Record that we have seen an explicit specification of attribute TAG
1696 for vendor VENDOR. */
1699 record_attribute (int vendor
, unsigned int tag
)
1703 struct recorded_attribute_info
*rai
;
1705 base
= tag
/ (8 * sizeof (rai
->mask
));
1706 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1707 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1708 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1714 rai
= XNEW (struct recorded_attribute_info
);
1715 rai
->next
= recorded_attributes
;
1716 rai
->vendor
= vendor
;
1719 recorded_attributes
= rai
;
1722 /* Return true if we have seen an explicit specification of attribute TAG
1723 for vendor VENDOR. */
1726 obj_elf_seen_attribute (int vendor
, unsigned int tag
)
1730 struct recorded_attribute_info
*rai
;
1732 base
= tag
/ (8 * sizeof (rai
->mask
));
1733 mask
= 1UL << (tag
% (8 * sizeof (rai
->mask
)));
1734 for (rai
= recorded_attributes
; rai
; rai
= rai
->next
)
1735 if (rai
->vendor
== vendor
&& rai
->base
== base
)
1736 return (rai
->mask
& mask
) != 0;
1740 /* Parse an attribute directive for VENDOR.
1741 Returns the attribute number read, or zero on error. */
1744 obj_elf_vendor_attribute (int vendor
)
1752 /* Read the first number or name. */
1753 skip_whitespace (input_line_pointer
);
1754 s
= input_line_pointer
;
1755 if (ISDIGIT (*input_line_pointer
))
1758 if (exp
.X_op
!= O_constant
)
1760 tag
= exp
.X_add_number
;
1766 /* A name may contain '_', but no other punctuation. */
1767 for (; ISALNUM (*input_line_pointer
) || *input_line_pointer
== '_';
1768 ++input_line_pointer
)
1773 name
= xstrndup (s
, i
);
1775 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
1776 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
1779 tag
= CONVERT_SYMBOLIC_ATTRIBUTE (name
);
1782 as_bad (_("Attribute name not recognised: %s"), name
);
1783 ignore_rest_of_line ();
1790 type
= _bfd_elf_obj_attrs_arg_type (stdoutput
, vendor
, tag
);
1792 if (skip_past_comma (&input_line_pointer
) == -1)
1797 if (exp
.X_op
!= O_constant
)
1799 as_bad (_("expected numeric constant"));
1800 ignore_rest_of_line ();
1803 i
= exp
.X_add_number
;
1806 && skip_past_comma (&input_line_pointer
) == -1)
1808 as_bad (_("expected comma"));
1809 ignore_rest_of_line ();
1816 skip_whitespace (input_line_pointer
);
1817 if (*input_line_pointer
!= '"')
1819 s
= demand_copy_C_string (&len
);
1822 record_attribute (vendor
, tag
);
1826 bfd_elf_add_obj_attr_int_string (stdoutput
, vendor
, tag
, i
, s
);
1829 bfd_elf_add_obj_attr_string (stdoutput
, vendor
, tag
, s
);
1832 bfd_elf_add_obj_attr_int (stdoutput
, vendor
, tag
, i
);
1838 demand_empty_rest_of_line ();
1841 as_bad (_("bad string constant"));
1842 ignore_rest_of_line ();
1845 as_bad (_("expected <tag> , <value>"));
1846 ignore_rest_of_line ();
1850 /* Parse a .gnu_attribute directive. */
1853 obj_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED
)
1855 obj_elf_vendor_attribute (OBJ_ATTR_GNU
);
1859 elf_obj_read_begin_hook (void)
1861 #ifdef NEED_ECOFF_DEBUG
1862 if (ECOFF_DEBUGGING
)
1863 ecoff_read_begin_hook ();
1868 elf_obj_symbol_new_hook (symbolS
*symbolP
)
1870 struct elf_obj_sy
*sy_obj
;
1872 sy_obj
= symbol_get_obj (symbolP
);
1873 sy_obj
->size
= NULL
;
1874 sy_obj
->versioned_name
= NULL
;
1876 #ifdef NEED_ECOFF_DEBUG
1877 if (ECOFF_DEBUGGING
)
1878 ecoff_symbol_new_hook (symbolP
);
1882 /* When setting one symbol equal to another, by default we probably
1883 want them to have the same "size", whatever it means in the current
1887 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
1889 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1890 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1893 if (destelf
->size
== NULL
)
1894 destelf
->size
= XNEW (expressionS
);
1895 *destelf
->size
= *srcelf
->size
;
1899 if (destelf
->size
!= NULL
)
1900 free (destelf
->size
);
1901 destelf
->size
= NULL
;
1903 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1904 /* Don't copy visibility. */
1905 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1906 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1910 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
1915 asection
*seg
= now_seg
;
1916 subsegT subseg
= now_subseg
;
1917 Elf_Internal_Note i_note
;
1918 Elf_External_Note e_note
;
1919 asection
*note_secp
= NULL
;
1922 if (*input_line_pointer
== '\"')
1926 ++input_line_pointer
; /* -> 1st char of string. */
1927 name
= input_line_pointer
;
1929 while (is_a_char (c
= next_char_of_string ()))
1931 c
= *input_line_pointer
;
1932 *input_line_pointer
= '\0';
1933 *(input_line_pointer
- 1) = '\0';
1934 *input_line_pointer
= c
;
1936 /* Create the .note section. */
1937 note_secp
= subseg_new (".note", 0);
1938 bfd_set_section_flags (note_secp
, SEC_HAS_CONTENTS
| SEC_READONLY
);
1939 record_alignment (note_secp
, 2);
1941 /* Process the version string. */
1942 len
= strlen (name
) + 1;
1944 /* PR 3456: Although the name field is padded out to an 4-byte
1945 boundary, the namesz field should not be adjusted. */
1946 i_note
.namesz
= len
;
1947 i_note
.descsz
= 0; /* No description. */
1948 i_note
.type
= NT_VERSION
;
1949 p
= frag_more (sizeof (e_note
.namesz
));
1950 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
1951 p
= frag_more (sizeof (e_note
.descsz
));
1952 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
1953 p
= frag_more (sizeof (e_note
.type
));
1954 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
1955 p
= frag_more (len
);
1956 memcpy (p
, name
, len
);
1958 frag_align (2, 0, 0);
1960 subseg_set (seg
, subseg
);
1963 as_bad (_("expected quoted string"));
1965 demand_empty_rest_of_line ();
1969 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
1972 char c
= get_symbol_name (&name
);
1977 p
= input_line_pointer
;
1979 SKIP_WHITESPACE_AFTER_NAME ();
1980 if (*input_line_pointer
!= ',')
1983 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1985 ignore_rest_of_line ();
1988 input_line_pointer
++;
1990 if (exp
.X_op
== O_absent
)
1992 as_bad (_("missing expression in .size directive"));
1993 exp
.X_op
= O_constant
;
1994 exp
.X_add_number
= 0;
1997 sym
= symbol_find_or_make (name
);
1999 if (exp
.X_op
== O_constant
)
2001 S_SET_SIZE (sym
, exp
.X_add_number
);
2002 if (symbol_get_obj (sym
)->size
)
2004 xfree (symbol_get_obj (sym
)->size
);
2005 symbol_get_obj (sym
)->size
= NULL
;
2010 symbol_get_obj (sym
)->size
= XNEW (expressionS
);
2011 *symbol_get_obj (sym
)->size
= exp
;
2013 demand_empty_rest_of_line ();
2016 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
2017 There are six syntaxes:
2019 The first (used on Solaris) is
2021 The second (used on UnixWare) is
2023 The third (reportedly to be used on Irix 6.0) is
2025 The fourth (used on NetBSD/Arm and Linux/ARM) is
2027 The fifth (used on SVR4/860) is
2028 .type SYM,"function"
2029 The sixth (emitted by recent SunPRO under Solaris) is
2031 where the integer is the STT_* value.
2035 obj_elf_type_name (char *cp
)
2039 p
= input_line_pointer
;
2040 if (*input_line_pointer
>= '0'
2041 && *input_line_pointer
<= '9')
2043 while (*input_line_pointer
>= '0'
2044 && *input_line_pointer
<= '9')
2045 ++input_line_pointer
;
2046 *cp
= *input_line_pointer
;
2047 *input_line_pointer
= '\0';
2050 *cp
= get_symbol_name (&p
);
2056 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
2060 const char *type_name
;
2062 elf_symbol_type
*elfsym
;
2064 sym
= get_sym_from_input_line_and_check ();
2065 c
= *input_line_pointer
;
2066 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
2068 if (*input_line_pointer
== ',')
2069 ++input_line_pointer
;
2072 if ( *input_line_pointer
== '#'
2073 || *input_line_pointer
== '@'
2074 || *input_line_pointer
== '"'
2075 || *input_line_pointer
== '%')
2076 ++input_line_pointer
;
2078 type_name
= obj_elf_type_name (& c
);
2081 if (strcmp (type_name
, "function") == 0
2082 || strcmp (type_name
, "2") == 0
2083 || strcmp (type_name
, "STT_FUNC") == 0)
2084 type
= BSF_FUNCTION
;
2085 else if (strcmp (type_name
, "object") == 0
2086 || strcmp (type_name
, "1") == 0
2087 || strcmp (type_name
, "STT_OBJECT") == 0)
2089 else if (strcmp (type_name
, "tls_object") == 0
2090 || strcmp (type_name
, "6") == 0
2091 || strcmp (type_name
, "STT_TLS") == 0)
2092 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
2093 else if (strcmp (type_name
, "notype") == 0
2094 || strcmp (type_name
, "0") == 0
2095 || strcmp (type_name
, "STT_NOTYPE") == 0)
2097 else if (strcmp (type_name
, "common") == 0
2098 || strcmp (type_name
, "5") == 0
2099 || strcmp (type_name
, "STT_COMMON") == 0)
2103 if (! S_IS_COMMON (sym
))
2105 if (S_IS_VOLATILE (sym
))
2107 sym
= symbol_clone (sym
, 1);
2108 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2109 S_SET_VALUE (sym
, 0);
2110 S_SET_EXTERNAL (sym
);
2111 symbol_set_frag (sym
, &zero_address_frag
);
2112 S_CLEAR_VOLATILE (sym
);
2114 else if (S_IS_DEFINED (sym
) || symbol_equated_p (sym
))
2115 as_bad (_("symbol '%s' is already defined"), S_GET_NAME (sym
));
2118 /* FIXME: Is it safe to just change the section ? */
2119 S_SET_SEGMENT (sym
, bfd_com_section_ptr
);
2120 S_SET_VALUE (sym
, 0);
2121 S_SET_EXTERNAL (sym
);
2125 else if (strcmp (type_name
, "gnu_indirect_function") == 0
2126 || strcmp (type_name
, "10") == 0
2127 || strcmp (type_name
, "STT_GNU_IFUNC") == 0)
2129 struct elf_backend_data
*bed
;
2131 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2132 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2133 bed
->elf_osabi
= ELFOSABI_GNU
;
2134 else if (bed
->elf_osabi
!= ELFOSABI_GNU
2135 && bed
->elf_osabi
!= ELFOSABI_FREEBSD
)
2136 as_bad (_("symbol type \"%s\" is supported only by GNU "
2137 "and FreeBSD targets"), type_name
);
2138 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_ifunc
;
2139 type
= BSF_FUNCTION
| BSF_GNU_INDIRECT_FUNCTION
;
2141 else if (strcmp (type_name
, "gnu_unique_object") == 0)
2143 struct elf_backend_data
*bed
;
2145 bed
= (struct elf_backend_data
*) get_elf_backend_data (stdoutput
);
2146 if (bed
->elf_osabi
== ELFOSABI_NONE
)
2147 bed
->elf_osabi
= ELFOSABI_GNU
;
2148 else if (bed
->elf_osabi
!= ELFOSABI_GNU
)
2149 as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
2151 elf_tdata (stdoutput
)->has_gnu_osabi
|= elf_gnu_osabi_unique
;
2152 type
= BSF_OBJECT
| BSF_GNU_UNIQUE
;
2154 #ifdef md_elf_symbol_type
2155 else if ((type
= md_elf_symbol_type (type_name
, sym
, elfsym
)) != -1)
2159 as_bad (_("unrecognized symbol type \"%s\""), type_name
);
2161 *input_line_pointer
= c
;
2163 if (*input_line_pointer
== '"')
2164 ++input_line_pointer
;
2166 #ifdef md_elf_symbol_type_change
2167 if (!md_elf_symbol_type_change (sym
, elfsym
, type
))
2170 flagword mask
= BSF_FUNCTION
| BSF_OBJECT
;
2172 if (type
!= BSF_FUNCTION
)
2173 mask
|= BSF_GNU_INDIRECT_FUNCTION
;
2174 if (type
!= BSF_OBJECT
)
2176 mask
|= BSF_GNU_UNIQUE
| BSF_THREAD_LOCAL
;
2178 if (S_IS_COMMON (sym
))
2180 as_bad (_("cannot change type of common symbol '%s'"),
2186 /* Don't warn when changing to STT_NOTYPE. */
2189 flagword
new = (elfsym
->symbol
.flags
& ~mask
) | type
;
2191 if (new != (elfsym
->symbol
.flags
| type
))
2192 as_warn (_("symbol '%s' already has its type set"), S_GET_NAME (sym
));
2193 elfsym
->symbol
.flags
= new;
2196 elfsym
->symbol
.flags
&= ~mask
;
2199 demand_empty_rest_of_line ();
2203 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
2205 static segT comment_section
;
2206 segT old_section
= now_seg
;
2207 int old_subsection
= now_subseg
;
2209 #ifdef md_flush_pending_output
2210 md_flush_pending_output ();
2213 if (!comment_section
)
2216 comment_section
= subseg_new (".comment", 0);
2217 bfd_set_section_flags (comment_section
, (SEC_READONLY
| SEC_HAS_CONTENTS
2218 | SEC_MERGE
| SEC_STRINGS
));
2219 comment_section
->entsize
= 1;
2220 #ifdef md_elf_section_change_hook
2221 md_elf_section_change_hook ();
2227 subseg_set (comment_section
, 0);
2229 subseg_set (old_section
, old_subsection
);
2232 #ifdef INIT_STAB_SECTION
2234 /* The first entry in a .stabs section is special. */
2237 obj_elf_init_stab_section (segT seg
)
2242 unsigned int stroff
;
2244 /* Force the section to align to a longword boundary. Without this,
2245 UnixWare ar crashes. */
2246 bfd_set_section_alignment (seg
, 2);
2248 /* Make space for this first symbol. */
2252 file
= as_where (NULL
);
2253 stabstr_name
= concat (segment_name (seg
), "str", (char *) NULL
);
2254 stroff
= get_stab_string_offset (file
, stabstr_name
, TRUE
);
2255 know (stroff
== 1 || (stroff
== 0 && file
[0] == '\0'));
2256 md_number_to_chars (p
, stroff
, 4);
2257 seg_info (seg
)->stabu
.p
= p
;
2262 /* Fill in the counts in the first entry in a .stabs section. */
2265 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
2272 if (strncmp (".stab", sec
->name
, 5))
2274 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
2277 name
= concat (sec
->name
, "str", NULL
);
2278 strsec
= bfd_get_section_by_name (abfd
, name
);
2280 strsz
= bfd_section_size (strsec
);
2283 nsyms
= bfd_section_size (sec
) / 12 - 1;
2285 p
= seg_info (sec
)->stabu
.p
;
2286 gas_assert (p
!= 0);
2288 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
2289 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
2293 #ifdef NEED_ECOFF_DEBUG
2295 /* This function is called by the ECOFF code. It is supposed to
2296 record the external symbol information so that the backend can
2297 write it out correctly. The ELF backend doesn't actually handle
2298 this at the moment, so we do it ourselves. We save the information
2301 #ifdef OBJ_MAYBE_ELF
2305 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
2307 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
2310 /* This function is called by bfd_ecoff_debug_externals. It is
2311 supposed to *EXT to the external symbol information, and return
2312 whether the symbol should be used at all. */
2315 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
2317 if (sym
->udata
.p
== NULL
)
2319 *ext
= *(EXTR
*) sym
->udata
.p
;
2323 /* This function is called by bfd_ecoff_debug_externals. It has
2324 nothing to do for ELF. */
2327 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
2328 bfd_size_type indx ATTRIBUTE_UNUSED
)
2332 #endif /* NEED_ECOFF_DEBUG */
2335 elf_frob_symbol (symbolS
*symp
, int *puntp
)
2337 struct elf_obj_sy
*sy_obj
;
2340 #ifdef NEED_ECOFF_DEBUG
2341 if (ECOFF_DEBUGGING
)
2342 ecoff_frob_symbol (symp
);
2345 sy_obj
= symbol_get_obj (symp
);
2347 size
= sy_obj
->size
;
2350 if (resolve_expression (size
)
2351 && size
->X_op
== O_constant
)
2352 S_SET_SIZE (symp
, size
->X_add_number
);
2355 if (!flag_allow_nonconst_size
)
2356 as_bad (_(".size expression for %s "
2357 "does not evaluate to a constant"), S_GET_NAME (symp
));
2359 as_warn (_(".size expression for %s "
2360 "does not evaluate to a constant"), S_GET_NAME (symp
));
2362 free (sy_obj
->size
);
2363 sy_obj
->size
= NULL
;
2366 if (sy_obj
->versioned_name
!= NULL
)
2370 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
2372 /* We will have already reported an error about a missing version. */
2375 /* This symbol was given a new name with the .symver directive.
2377 If this is an external reference, just rename the symbol to
2378 include the version string. This will make the relocs be
2379 against the correct versioned symbol.
2381 If this is a definition, add an alias. FIXME: Using an alias
2382 will permit the debugging information to refer to the right
2383 symbol. However, it's not clear whether it is the best
2386 else if (! S_IS_DEFINED (symp
))
2388 /* Verify that the name isn't using the @@ syntax--this is
2389 reserved for definitions of the default version to link
2391 if (p
[1] == ELF_VER_CHR
)
2393 as_bad (_("invalid attempt to declare external version name"
2394 " as default in symbol `%s'"),
2395 sy_obj
->versioned_name
);
2398 S_SET_NAME (symp
, sy_obj
->versioned_name
);
2402 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
2406 /* The @@@ syntax is a special case. It renames the
2407 symbol name to versioned_name with one `@' removed. */
2408 l
= strlen (&p
[3]) + 1;
2409 memmove (&p
[2], &p
[3], l
);
2410 S_SET_NAME (symp
, sy_obj
->versioned_name
);
2416 /* FIXME: Creating a new symbol here is risky. We're
2417 in the final loop over the symbol table. We can
2418 get away with it only because the symbol goes to
2419 the end of the list, where the loop will still see
2420 it. It would probably be better to do this in
2421 obj_frob_file_before_adjust. */
2423 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
2425 /* Now we act as though we saw symp2 = sym. */
2426 if (S_IS_COMMON (symp
))
2428 as_bad (_("`%s' can't be versioned to common symbol '%s'"),
2429 sy_obj
->versioned_name
, S_GET_NAME (symp
));
2434 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
2436 /* Subtracting out the frag address here is a hack
2437 because we are in the middle of the final loop. */
2440 - symbol_get_frag (symp
)->fr_address
));
2442 symbol_set_frag (symp2
, symbol_get_frag (symp
));
2444 /* This will copy over the size information. */
2445 copy_symbol_attributes (symp2
, symp
);
2447 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
2449 if (S_IS_WEAK (symp
))
2452 if (S_IS_EXTERNAL (symp
))
2453 S_SET_EXTERNAL (symp2
);
2458 /* Double check weak symbols. */
2459 if (S_IS_WEAK (symp
))
2461 if (S_IS_COMMON (symp
))
2462 as_bad (_("symbol `%s' can not be both weak and common"),
2469 asection
**head
; /* Section lists. */
2470 unsigned int num_group
; /* Number of lists. */
2471 struct hash_control
*indexes
; /* Maps group name to index in head array. */
2474 static struct group_list groups
;
2476 /* Called via bfd_map_over_sections. If SEC is a member of a group,
2477 add it to a list of sections belonging to the group. INF is a
2478 pointer to a struct group_list, which is where we store the head of
2482 build_group_lists (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
2484 struct group_list
*list
= (struct group_list
*) inf
;
2485 const char *group_name
= elf_group_name (sec
);
2487 unsigned int *elem_idx
;
2488 unsigned int *idx_ptr
;
2490 if (group_name
== NULL
)
2493 /* If this group already has a list, add the section to the head of
2495 elem_idx
= (unsigned int *) hash_find (list
->indexes
, group_name
);
2496 if (elem_idx
!= NULL
)
2498 elf_next_in_group (sec
) = list
->head
[*elem_idx
];
2499 list
->head
[*elem_idx
] = sec
;
2503 /* New group. Make the arrays bigger in chunks to minimize calls to
2505 i
= list
->num_group
;
2508 unsigned int newsize
= i
+ 128;
2509 list
->head
= XRESIZEVEC (asection
*, list
->head
, newsize
);
2511 list
->head
[i
] = sec
;
2512 list
->num_group
+= 1;
2514 /* Add index to hash. */
2515 idx_ptr
= XNEW (unsigned int);
2517 hash_insert (list
->indexes
, group_name
, idx_ptr
);
2520 static void free_section_idx (const char *key ATTRIBUTE_UNUSED
, void *val
)
2522 free ((unsigned int *) val
);
2525 /* Create symbols for group signature. */
2528 elf_adjust_symtab (void)
2532 /* Go find section groups. */
2533 groups
.num_group
= 0;
2535 groups
.indexes
= hash_new ();
2536 bfd_map_over_sections (stdoutput
, build_group_lists
, &groups
);
2538 /* Make the SHT_GROUP sections that describe each section group. We
2539 can't set up the section contents here yet, because elf section
2540 indices have yet to be calculated. elf.c:set_group_contents does
2541 the rest of the work. */
2542 for (i
= 0; i
< groups
.num_group
; i
++)
2544 const char *group_name
= elf_group_name (groups
.head
[i
]);
2545 const char *sec_name
;
2550 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2551 for (s
= groups
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2552 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2554 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2555 if (s
!= groups
.head
[i
])
2557 as_warn (_("assuming all members of group `%s' are COMDAT"),
2563 sec_name
= ".group";
2564 s
= subseg_force_new (sec_name
, 0);
2566 || !bfd_set_section_flags (s
, flags
)
2567 || !bfd_set_section_alignment (s
, 2))
2569 as_fatal (_("can't create group: %s"),
2570 bfd_errmsg (bfd_get_error ()));
2572 elf_section_type (s
) = SHT_GROUP
;
2574 /* Pass a pointer to the first section in this group. */
2575 elf_next_in_group (s
) = groups
.head
[i
];
2576 elf_sec_group (groups
.head
[i
]) = s
;
2577 /* Make sure that the signature symbol for the group has the
2578 name of the group. */
2579 sy
= symbol_find_exact (group_name
);
2580 if (!sy
|| !symbol_on_chain (sy
, symbol_rootP
, symbol_lastP
))
2582 /* Create the symbol now. */
2583 sy
= symbol_new (group_name
, now_seg
, (valueT
) 0, frag_now
);
2585 /* Before Solaris 11 build 154, Sun ld rejects local group
2586 signature symbols, so make them weak hidden instead. */
2587 symbol_get_bfdsym (sy
)->flags
|= BSF_WEAK
;
2588 S_SET_OTHER (sy
, STV_HIDDEN
);
2590 symbol_get_obj (sy
)->local
= 1;
2592 symbol_table_insert (sy
);
2594 elf_group_id (s
) = symbol_get_bfdsym (sy
);
2599 elf_frob_file (void)
2601 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
2603 #ifdef elf_tc_final_processing
2604 elf_tc_final_processing ();
2608 /* It removes any unneeded versioned symbols from the symbol table. */
2611 elf_frob_file_before_adjust (void)
2617 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2618 if (!S_IS_DEFINED (symp
))
2620 if (symbol_get_obj (symp
)->versioned_name
)
2624 /* The @@@ syntax is a special case. If the symbol is
2625 not defined, 2 `@'s will be removed from the
2628 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
2630 if (p
!= NULL
&& p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
2632 size_t l
= strlen (&p
[3]) + 1;
2633 memmove (&p
[1], &p
[3], l
);
2635 if (symbol_used_p (symp
) == 0
2636 && symbol_used_in_reloc_p (symp
) == 0)
2637 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2640 /* If there was .weak foo, but foo was neither defined nor
2641 used anywhere, remove it. */
2643 else if (S_IS_WEAK (symp
)
2644 && symbol_used_p (symp
) == 0
2645 && symbol_used_in_reloc_p (symp
) == 0)
2646 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2651 /* It is required that we let write_relocs have the opportunity to
2652 optimize away fixups before output has begun, since it is possible
2653 to eliminate all fixups for a section and thus we never should
2654 have generated the relocation section. */
2657 elf_frob_file_after_relocs (void)
2661 /* Set SHT_GROUP section size. */
2662 for (i
= 0; i
< groups
.num_group
; i
++)
2664 asection
*s
, *head
, *group
;
2667 head
= groups
.head
[i
];
2669 for (s
= head
; s
!= NULL
; s
= elf_next_in_group (s
))
2670 size
+= (s
->flags
& SEC_RELOC
) != 0 ? 8 : 4;
2672 group
= elf_sec_group (head
);
2673 subseg_set (group
, 0);
2674 bfd_set_section_size (group
, size
);
2675 group
->contents
= (unsigned char *) frag_more (size
);
2676 frag_now
->fr_fix
= frag_now_fix_octets ();
2677 frag_wane (frag_now
);
2681 hash_traverse (groups
.indexes
, free_section_idx
);
2682 hash_die (groups
.indexes
);
2684 #ifdef NEED_ECOFF_DEBUG
2685 if (ECOFF_DEBUGGING
)
2686 /* Generate the ECOFF debugging information. */
2688 const struct ecoff_debug_swap
*debug_swap
;
2689 struct ecoff_debug_info debug
;
2694 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2695 know (debug_swap
!= NULL
);
2696 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2698 /* Set up the pointers in debug. */
2699 #define SET(ptr, offset, type) \
2700 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2702 SET (line
, cbLineOffset
, unsigned char *);
2703 SET (external_dnr
, cbDnOffset
, void *);
2704 SET (external_pdr
, cbPdOffset
, void *);
2705 SET (external_sym
, cbSymOffset
, void *);
2706 SET (external_opt
, cbOptOffset
, void *);
2707 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2708 SET (ss
, cbSsOffset
, char *);
2709 SET (external_fdr
, cbFdOffset
, void *);
2710 SET (external_rfd
, cbRfdOffset
, void *);
2711 /* ssext and external_ext are set up just below. */
2715 /* Set up the external symbols. */
2716 debug
.ssext
= debug
.ssext_end
= NULL
;
2717 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2718 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2719 elf_get_extr
, elf_set_index
))
2720 as_fatal (_("failed to set up debugging information: %s"),
2721 bfd_errmsg (bfd_get_error ()));
2723 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2724 gas_assert (sec
!= NULL
);
2726 know (!stdoutput
->output_has_begun
);
2728 /* We set the size of the section, call bfd_set_section_contents
2729 to force the ELF backend to allocate a file position, and then
2730 write out the data. FIXME: Is this really the best way to do
2732 bfd_set_section_size (sec
, bfd_ecoff_debug_size (stdoutput
, &debug
,
2735 /* Pass BUF to bfd_set_section_contents because this will
2736 eventually become a call to fwrite, and ISO C prohibits
2737 passing a NULL pointer to a stdio function even if the
2738 pointer will not be used. */
2739 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
2740 as_fatal (_("can't start writing .mdebug section: %s"),
2741 bfd_errmsg (bfd_get_error ()));
2743 know (stdoutput
->output_has_begun
);
2744 know (sec
->filepos
!= 0);
2746 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2748 as_fatal (_("could not write .mdebug section: %s"),
2749 bfd_errmsg (bfd_get_error ()));
2751 #endif /* NEED_ECOFF_DEBUG */
2755 elf_generate_asm_lineno (void)
2757 #ifdef NEED_ECOFF_DEBUG
2758 if (ECOFF_DEBUGGING
)
2759 ecoff_generate_asm_lineno ();
2764 elf_process_stab (segT sec ATTRIBUTE_UNUSED
,
2765 int what ATTRIBUTE_UNUSED
,
2766 const char *string ATTRIBUTE_UNUSED
,
2767 int type ATTRIBUTE_UNUSED
,
2768 int other ATTRIBUTE_UNUSED
,
2769 int desc ATTRIBUTE_UNUSED
)
2771 #ifdef NEED_ECOFF_DEBUG
2772 if (ECOFF_DEBUGGING
)
2773 ecoff_stab (sec
, what
, string
, type
, other
, desc
);
2778 elf_separate_stab_sections (void)
2780 #ifdef NEED_ECOFF_DEBUG
2781 return (!ECOFF_DEBUGGING
);
2788 elf_init_stab_section (segT seg
)
2790 #ifdef NEED_ECOFF_DEBUG
2791 if (!ECOFF_DEBUGGING
)
2793 obj_elf_init_stab_section (seg
);
2796 const struct format_ops elf_format_ops
=
2798 bfd_target_elf_flavour
,
2799 0, /* dfl_leading_underscore */
2800 1, /* emit_section_symbols */
2805 elf_frob_file_before_adjust
,
2806 0, /* obj_frob_file_before_fix */
2807 elf_frob_file_after_relocs
,
2808 elf_s_get_size
, elf_s_set_size
,
2809 elf_s_get_align
, elf_s_set_align
,
2816 elf_copy_symbol_attributes
,
2817 elf_generate_asm_lineno
,
2819 elf_separate_stab_sections
,
2820 elf_init_stab_section
,
2821 elf_sec_sym_ok_for_reloc
,
2823 #ifdef NEED_ECOFF_DEBUG
2826 0, /* ecoff_set_ext */
2828 elf_obj_read_begin_hook
,
2829 elf_obj_symbol_new_hook
,