1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
22 #define OBJ_HEADER "obj-elf.h"
24 #include "safe-ctype.h"
27 #include "struc-symbol.h"
28 #include "dwarf2dbg.h"
30 #ifndef ECOFF_DEBUGGING
31 #define ECOFF_DEBUGGING 0
33 #define NEED_ECOFF_DEBUG
36 #ifdef NEED_ECOFF_DEBUG
41 #include "elf/alpha.h"
56 static void obj_elf_line (int);
57 static void obj_elf_size (int);
58 static void obj_elf_type (int);
59 static void obj_elf_ident (int);
60 static void obj_elf_weak (int);
61 static void obj_elf_local (int);
62 static void obj_elf_visibility (int);
63 static void obj_elf_symver (int);
64 static void obj_elf_subsection (int);
65 static void obj_elf_popsection (int);
66 static void obj_elf_tls_common (int);
67 static void obj_elf_lcomm (int);
68 static void obj_elf_struct (int);
70 static const pseudo_typeS elf_pseudo_table
[] =
72 {"comm", obj_elf_common
, 0},
73 {"common", obj_elf_common
, 1},
74 {"ident", obj_elf_ident
, 0},
75 {"lcomm", obj_elf_lcomm
, 0},
76 {"local", obj_elf_local
, 0},
77 {"previous", obj_elf_previous
, 0},
78 {"section", obj_elf_section
, 0},
79 {"section.s", obj_elf_section
, 0},
80 {"sect", obj_elf_section
, 0},
81 {"sect.s", obj_elf_section
, 0},
82 {"pushsection", obj_elf_section
, 1},
83 {"popsection", obj_elf_popsection
, 0},
84 {"size", obj_elf_size
, 0},
85 {"type", obj_elf_type
, 0},
86 {"version", obj_elf_version
, 0},
87 {"weak", obj_elf_weak
, 0},
89 /* These define symbol visibility. */
90 {"internal", obj_elf_visibility
, STV_INTERNAL
},
91 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
92 {"protected", obj_elf_visibility
, STV_PROTECTED
},
94 /* These are used for stabs-in-elf configurations. */
95 {"line", obj_elf_line
, 0},
97 /* This is a GNU extension to handle symbol versions. */
98 {"symver", obj_elf_symver
, 0},
100 /* A GNU extension to change subsection only. */
101 {"subsection", obj_elf_subsection
, 0},
103 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
104 {"vtable_inherit", (void (*) (int)) &obj_elf_vtable_inherit
, 0},
105 {"vtable_entry", (void (*) (int)) &obj_elf_vtable_entry
, 0},
107 /* These are used for dwarf. */
111 /* These are used for dwarf2. */
112 { "file", (void (*) (int)) dwarf2_directive_file
, 0 },
113 { "loc", dwarf2_directive_loc
, 0 },
115 /* We need to trap the section changing calls to handle .previous. */
116 {"data", obj_elf_data
, 0},
117 {"offset", obj_elf_struct
, 0},
118 {"struct", obj_elf_struct
, 0},
119 {"text", obj_elf_text
, 0},
121 {"tls_common", obj_elf_tls_common
, 0},
127 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
129 #ifdef NEED_ECOFF_DEBUG
130 /* COFF style debugging information for ECOFF. .ln is not used; .loc
132 { "def", ecoff_directive_def
, 0 },
133 { "dim", ecoff_directive_dim
, 0 },
134 { "endef", ecoff_directive_endef
, 0 },
135 { "file", ecoff_directive_file
, 0 },
136 { "scl", ecoff_directive_scl
, 0 },
137 { "tag", ecoff_directive_tag
, 0 },
138 { "val", ecoff_directive_val
, 0 },
140 /* COFF debugging requires pseudo-ops .size and .type, but ELF
141 already has meanings for those. We use .esize and .etype
142 instead. These are only generated by gcc anyhow. */
143 { "esize", ecoff_directive_size
, 0 },
144 { "etype", ecoff_directive_type
, 0 },
146 /* ECOFF specific debugging information. */
147 { "begin", ecoff_directive_begin
, 0 },
148 { "bend", ecoff_directive_bend
, 0 },
149 { "end", ecoff_directive_end
, 0 },
150 { "ent", ecoff_directive_ent
, 0 },
151 { "fmask", ecoff_directive_fmask
, 0 },
152 { "frame", ecoff_directive_frame
, 0 },
153 { "loc", ecoff_directive_loc
, 0 },
154 { "mask", ecoff_directive_mask
, 0 },
156 /* Other ECOFF directives. */
157 { "extern", ecoff_directive_extern
, 0 },
159 /* These are used on Irix. I don't know how to implement them. */
160 { "alias", s_ignore
, 0 },
161 { "bgnb", s_ignore
, 0 },
162 { "endb", s_ignore
, 0 },
163 { "lab", s_ignore
, 0 },
164 { "noalias", s_ignore
, 0 },
165 { "verstamp", s_ignore
, 0 },
166 { "vreg", s_ignore
, 0 },
169 {NULL
, NULL
, 0} /* end sentinel */
173 #include "aout/aout64.h"
175 /* This is called when the assembler starts. */
182 /* Add symbols for the known sections to the symbol table. */
183 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
184 symbol_table_insert (section_symbol (s
));
185 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
186 symbol_table_insert (section_symbol (s
));
187 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
188 symbol_table_insert (section_symbol (s
));
192 elf_pop_insert (void)
194 pop_insert (elf_pseudo_table
);
196 pop_insert (ecoff_debug_pseudo_table
);
200 elf_s_get_size (symbolS
*sym
)
202 return S_GET_SIZE (sym
);
206 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
208 S_SET_SIZE (sym
, sz
);
212 elf_s_get_align (symbolS
*sym
)
214 return S_GET_ALIGN (sym
);
218 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
220 S_SET_ALIGN (sym
, align
);
224 elf_s_get_other (symbolS
*sym
)
226 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
230 elf_s_set_other (symbolS
*sym
, int other
)
232 S_SET_OTHER (sym
, other
);
236 elf_sec_sym_ok_for_reloc (asection
*sec
)
238 return obj_sec_sym_ok_for_reloc (sec
);
242 elf_file_symbol (const char *s
, int appfile
)
245 || symbol_rootP
== NULL
246 || symbol_rootP
->bsym
== NULL
247 || (symbol_rootP
->bsym
->flags
& BSF_FILE
) == 0)
251 sym
= symbol_new (s
, absolute_section
, 0, NULL
);
252 symbol_set_frag (sym
, &zero_address_frag
);
253 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
255 if (symbol_rootP
!= sym
)
257 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
258 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
260 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
265 #ifdef NEED_ECOFF_DEBUG
266 ecoff_new_file (s
, appfile
);
270 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
271 Parse a possible alignment value. */
274 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
277 int is_local
= symbol_get_obj (symbolP
)->local
;
279 if (*input_line_pointer
== ',')
281 char *save
= input_line_pointer
;
283 input_line_pointer
++;
286 if (*input_line_pointer
== '"')
288 /* For sparc. Accept .common symbol, length, "bss" */
289 input_line_pointer
++;
290 /* Some use the dot, some don't. */
291 if (*input_line_pointer
== '.')
292 input_line_pointer
++;
293 /* Some say data, some say bss. */
294 if (strncmp (input_line_pointer
, "bss\"", 4) == 0)
295 input_line_pointer
+= 4;
296 else if (strncmp (input_line_pointer
, "data\"", 5) == 0)
297 input_line_pointer
+= 5;
300 char *p
= input_line_pointer
;
305 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
306 if (*input_line_pointer
++ == '"')
308 c
= *input_line_pointer
;
309 *input_line_pointer
= '\0';
310 as_bad (_("bad .common segment %s"), p
);
311 *input_line_pointer
= c
;
312 ignore_rest_of_line ();
315 /* ??? Don't ask me why these are always global. */
320 input_line_pointer
= save
;
321 align
= parse_align (is_local
);
322 if (align
== (addressT
) -1)
329 bss_alloc (symbolP
, size
, align
);
330 S_CLEAR_EXTERNAL (symbolP
);
334 S_SET_VALUE (symbolP
, size
);
335 S_SET_ALIGN (symbolP
, align
);
336 S_SET_EXTERNAL (symbolP
);
337 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
340 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
346 obj_elf_common (int is_common
)
348 if (flag_mri
&& is_common
)
351 s_comm_internal (0, elf_common_parse
);
355 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
357 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
360 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
364 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
366 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
369 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
373 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
381 name
= input_line_pointer
;
382 c
= get_symbol_end ();
383 symbolP
= symbol_find_or_make (name
);
384 *input_line_pointer
= c
;
386 S_CLEAR_EXTERNAL (symbolP
);
387 symbol_get_obj (symbolP
)->local
= 1;
390 input_line_pointer
++;
392 if (*input_line_pointer
== '\n')
397 demand_empty_rest_of_line ();
401 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
409 name
= input_line_pointer
;
410 c
= get_symbol_end ();
411 symbolP
= symbol_find_or_make (name
);
412 *input_line_pointer
= c
;
414 S_SET_WEAK (symbolP
);
415 symbol_get_obj (symbolP
)->local
= 1;
418 input_line_pointer
++;
420 if (*input_line_pointer
== '\n')
425 demand_empty_rest_of_line ();
429 obj_elf_visibility (int visibility
)
435 elf_symbol_type
*elfsym
;
439 name
= input_line_pointer
;
440 c
= get_symbol_end ();
441 symbolP
= symbol_find_or_make (name
);
442 *input_line_pointer
= c
;
446 bfdsym
= symbol_get_bfdsym (symbolP
);
447 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
451 elfsym
->internal_elf_sym
.st_other
&= ~3;
452 elfsym
->internal_elf_sym
.st_other
|= visibility
;
456 input_line_pointer
++;
460 if (*input_line_pointer
== '\n')
466 demand_empty_rest_of_line ();
469 static segT previous_section
;
470 static int previous_subsection
;
474 struct section_stack
*next
;
476 int subseg
, prev_subseg
;
479 static struct section_stack
*section_stack
;
482 get_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
484 const char *gname
= inf
;
485 const char *group_name
= elf_group_name (sec
);
487 return (group_name
== gname
488 || (group_name
!= NULL
490 && strcmp (group_name
, gname
) == 0));
493 /* Handle the .section pseudo-op. This code supports two different
496 The first is found on Solaris, and looks like
497 .section ".sec1",#alloc,#execinstr,#write
498 Here the names after '#' are the SHF_* flags to turn on for the
499 section. I'm not sure how it determines the SHT_* type (BFD
500 doesn't really give us control over the type, anyhow).
502 The second format is found on UnixWare, and probably most SVR4
503 machines, and looks like
504 .section .sec1,"a",@progbits
505 The quoted string may contain any combination of a, w, x, and
506 represents the SHF_* flags to turn on for the section. The string
507 beginning with '@' can be progbits or nobits. There should be
508 other possibilities, but I don't know what they are. In any case,
509 BFD doesn't really let us set the section type. */
512 obj_elf_change_section (const char *name
,
516 const char *group_name
,
523 const struct elf_backend_data
*bed
;
524 const struct bfd_elf_special_section
*ssect
;
526 #ifdef md_flush_pending_output
527 md_flush_pending_output ();
530 /* Switch to the section, creating it if necessary. */
533 struct section_stack
*elt
;
534 elt
= xmalloc (sizeof (struct section_stack
));
535 elt
->next
= section_stack
;
537 elt
->prev_seg
= previous_section
;
538 elt
->subseg
= now_subseg
;
539 elt
->prev_subseg
= previous_subsection
;
542 previous_section
= now_seg
;
543 previous_subsection
= now_subseg
;
545 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section
,
546 (void *) group_name
);
553 sec
= subseg_force_new (name
, 0);
555 bed
= get_elf_backend_data (stdoutput
);
556 ssect
= (*bed
->get_sec_type_attr
) (stdoutput
, sec
);
560 bfd_boolean override
= FALSE
;
562 if (type
== SHT_NULL
)
564 else if (type
!= ssect
->type
)
567 /* FIXME: gcc, as of 2002-10-22, will emit
569 .section .init_array,"aw",@progbits
571 for __attribute__ ((section (".init_array"))).
572 "@progbits" is incorrect. */
573 && ssect
->type
!= SHT_INIT_ARRAY
574 && ssect
->type
!= SHT_FINI_ARRAY
575 && ssect
->type
!= SHT_PREINIT_ARRAY
)
577 /* We allow to specify any type for a .note section. */
578 if (ssect
->type
!= SHT_NOTE
)
579 as_warn (_("setting incorrect section type for %s"),
584 as_warn (_("ignoring incorrect section type for %s"),
590 if (old_sec
== NULL
&& (attr
& ~ssect
->attr
) != 0)
592 /* As a GNU extension, we permit a .note section to be
593 allocatable. If the linker sees an allocatable .note
594 section, it will create a PT_NOTE segment in the output
595 file. We also allow "x" for .note.GNU-stack. */
596 if (ssect
->type
== SHT_NOTE
597 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
599 /* Allow different SHF_MERGE and SHF_STRINGS if we have
600 something like .rodata.str. */
601 else if (ssect
->suffix_length
== -2
602 && name
[ssect
->prefix_length
] == '.'
606 & ~SHF_STRINGS
) == 0)
608 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
609 else if (attr
== SHF_ALLOC
610 && (strcmp (name
, ".interp") == 0
611 || strcmp (name
, ".strtab") == 0
612 || strcmp (name
, ".symtab") == 0))
614 /* .note.GNU-stack can have SHF_EXECINSTR. */
615 else if (attr
== SHF_EXECINSTR
616 && strcmp (name
, ".note.GNU-stack") == 0)
620 if (group_name
== NULL
)
621 as_warn (_("setting incorrect section attributes for %s"),
626 if (!override
&& old_sec
== NULL
)
630 /* Convert ELF type and flags to BFD flags. */
632 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
633 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
634 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
635 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
636 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
637 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
638 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
639 #ifdef md_elf_section_flags
640 flags
= md_elf_section_flags (flags
, attr
, type
);
644 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
650 elf_section_type (sec
) = type
;
651 elf_section_flags (sec
) = attr
;
653 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
654 if (type
== SHT_NOBITS
)
655 seg_info (sec
)->bss
= 1;
657 bfd_set_section_flags (stdoutput
, sec
, flags
);
658 if (flags
& SEC_MERGE
)
659 sec
->entsize
= entsize
;
660 elf_group_name (sec
) = group_name
;
662 /* Add a symbol for this section to the symbol table. */
663 secsym
= symbol_find (name
);
665 symbol_set_bfdsym (secsym
, sec
->symbol
);
667 symbol_table_insert (section_symbol (sec
));
672 && (unsigned) type
!= elf_section_type (old_sec
))
673 as_warn (_("ignoring changed section type for %s"), name
);
677 /* If section attributes are specified the second time we see a
678 particular section, then check that they are the same as we
679 saw the first time. */
680 if (((old_sec
->flags
^ flags
)
681 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
682 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
683 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
684 | SEC_THREAD_LOCAL
)))
685 as_warn (_("ignoring changed section attributes for %s"), name
);
686 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
687 as_warn (_("ignoring changed section entity size for %s"), name
);
691 #ifdef md_elf_section_change_hook
692 md_elf_section_change_hook ();
697 obj_elf_parse_section_letters (char *str
, size_t len
)
712 attr
|= SHF_EXECINSTR
;
728 if (*(str
- 1) == 'a')
731 if (len
> 1 && str
[1] == 's')
740 char *bad_msg
= _("unrecognized .section attribute: want a,w,x,M,S,G,T");
741 #ifdef md_elf_section_letter
742 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
747 as_fatal ("%s", bad_msg
);
758 obj_elf_section_word (char *str
, size_t len
)
760 if (len
== 5 && strncmp (str
, "write", 5) == 0)
762 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
764 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
765 return SHF_EXECINSTR
;
766 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
769 #ifdef md_elf_section_word
771 int md_attr
= md_elf_section_word (str
, len
);
777 as_warn (_("unrecognized section attribute"));
782 obj_elf_section_type (char *str
, size_t len
)
784 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
786 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
788 if (len
== 4 && strncmp (str
, "note", 4) == 0)
790 if (len
== 10 && strncmp (str
, "init_array", 10) == 0)
791 return SHT_INIT_ARRAY
;
792 if (len
== 10 && strncmp (str
, "fini_array", 10) == 0)
793 return SHT_FINI_ARRAY
;
794 if (len
== 13 && strncmp (str
, "preinit_array", 13) == 0)
795 return SHT_PREINIT_ARRAY
;
797 #ifdef md_elf_section_type
799 int md_type
= md_elf_section_type (str
, len
);
805 as_warn (_("unrecognized section type"));
809 /* Get name of section. */
811 obj_elf_section_name (void)
816 if (*input_line_pointer
== '"')
820 name
= demand_copy_C_string (&dummy
);
823 ignore_rest_of_line ();
829 char *end
= input_line_pointer
;
831 while (0 == strchr ("\n\t,; ", *end
))
833 if (end
== input_line_pointer
)
835 as_bad (_("missing name"));
836 ignore_rest_of_line ();
840 name
= xmalloc (end
- input_line_pointer
+ 1);
841 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
842 name
[end
- input_line_pointer
] = '\0';
843 #ifdef tc_canonicalize_section_name
844 name
= tc_canonicalize_section_name (name
);
846 input_line_pointer
= end
;
853 obj_elf_section (int push
)
855 char *name
, *group_name
, *beg
;
856 int type
, attr
, dummy
;
865 #ifdef md_flush_pending_output
866 md_flush_pending_output ();
869 previous_section
= now_seg
;
870 previous_subsection
= now_subseg
;
872 s_mri_sect (&mri_type
);
874 #ifdef md_elf_section_change_hook
875 md_elf_section_change_hook ();
880 #endif /* ! defined (TC_I370) */
882 name
= obj_elf_section_name ();
891 if (*input_line_pointer
== ',')
893 /* Skip the comma. */
894 ++input_line_pointer
;
897 if (*input_line_pointer
== '"')
899 beg
= demand_copy_C_string (&dummy
);
902 ignore_rest_of_line ();
905 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
908 if (*input_line_pointer
== ',')
911 char *save
= input_line_pointer
;
913 ++input_line_pointer
;
915 c
= *input_line_pointer
;
918 beg
= demand_copy_C_string (&dummy
);
921 ignore_rest_of_line ();
924 type
= obj_elf_section_type (beg
, strlen (beg
));
926 else if (c
== '@' || c
== '%')
928 beg
= ++input_line_pointer
;
929 c
= get_symbol_end ();
930 *input_line_pointer
= c
;
931 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
934 input_line_pointer
= save
;
938 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
940 ++input_line_pointer
;
942 entsize
= get_absolute_expression ();
946 as_warn (_("invalid merge entity size"));
951 else if ((attr
& SHF_MERGE
) != 0)
953 as_warn (_("entity size for SHF_MERGE not specified"));
957 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
959 ++input_line_pointer
;
960 group_name
= obj_elf_section_name ();
961 if (group_name
== NULL
)
963 else if (strncmp (input_line_pointer
, ",comdat", 7) == 0)
965 input_line_pointer
+= 7;
968 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
971 else if ((attr
& SHF_GROUP
) != 0)
973 as_warn (_("group name for SHF_GROUP not specified"));
984 if (*input_line_pointer
!= '#')
986 as_bad (_("character following name is not '#'"));
987 ignore_rest_of_line ();
990 beg
= ++input_line_pointer
;
991 c
= get_symbol_end ();
992 *input_line_pointer
= c
;
994 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
998 while (*input_line_pointer
++ == ',');
999 --input_line_pointer
;
1003 demand_empty_rest_of_line ();
1005 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
);
1008 /* Change to the .data section. */
1011 obj_elf_data (int i
)
1013 #ifdef md_flush_pending_output
1014 md_flush_pending_output ();
1017 previous_section
= now_seg
;
1018 previous_subsection
= now_subseg
;
1021 #ifdef md_elf_section_change_hook
1022 md_elf_section_change_hook ();
1026 /* Change to the .text section. */
1029 obj_elf_text (int i
)
1031 #ifdef md_flush_pending_output
1032 md_flush_pending_output ();
1035 previous_section
= now_seg
;
1036 previous_subsection
= now_subseg
;
1039 #ifdef md_elf_section_change_hook
1040 md_elf_section_change_hook ();
1044 /* Change to the *ABS* section. */
1047 obj_elf_struct (int i
)
1049 #ifdef md_flush_pending_output
1050 md_flush_pending_output ();
1053 previous_section
= now_seg
;
1054 previous_subsection
= now_subseg
;
1057 #ifdef md_elf_section_change_hook
1058 md_elf_section_change_hook ();
1063 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1067 #ifdef md_flush_pending_output
1068 md_flush_pending_output ();
1071 previous_section
= now_seg
;
1072 previous_subsection
= now_subseg
;
1074 temp
= get_absolute_expression ();
1075 subseg_set (now_seg
, (subsegT
) temp
);
1076 demand_empty_rest_of_line ();
1078 #ifdef md_elf_section_change_hook
1079 md_elf_section_change_hook ();
1083 /* This can be called from the processor backends if they change
1087 obj_elf_section_change_hook (void)
1089 previous_section
= now_seg
;
1090 previous_subsection
= now_subseg
;
1094 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1099 if (previous_section
== 0)
1101 as_warn (_(".previous without corresponding .section; ignored"));
1105 #ifdef md_flush_pending_output
1106 md_flush_pending_output ();
1109 new_section
= previous_section
;
1110 new_subsection
= previous_subsection
;
1111 previous_section
= now_seg
;
1112 previous_subsection
= now_subseg
;
1113 subseg_set (new_section
, new_subsection
);
1115 #ifdef md_elf_section_change_hook
1116 md_elf_section_change_hook ();
1121 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1123 struct section_stack
*top
= section_stack
;
1127 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1131 #ifdef md_flush_pending_output
1132 md_flush_pending_output ();
1135 section_stack
= top
->next
;
1136 previous_section
= top
->prev_seg
;
1137 previous_subsection
= top
->prev_subseg
;
1138 subseg_set (top
->seg
, top
->subseg
);
1141 #ifdef md_elf_section_change_hook
1142 md_elf_section_change_hook ();
1147 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1149 /* Assume delimiter is part of expression. BSD4.2 as fails with
1150 delightful bug, so we are not being incompatible here. */
1151 new_logical_line (NULL
, get_absolute_expression ());
1152 demand_empty_rest_of_line ();
1155 /* This handles the .symver pseudo-op, which is used to specify a
1156 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1157 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1158 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1159 with the same value as the symbol NAME. */
1162 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1169 name
= input_line_pointer
;
1170 c
= get_symbol_end ();
1172 sym
= symbol_find_or_make (name
);
1174 *input_line_pointer
= c
;
1177 if (*input_line_pointer
!= ',')
1179 as_bad (_("expected comma after name in .symver"));
1180 ignore_rest_of_line ();
1184 ++input_line_pointer
;
1186 name
= input_line_pointer
;
1188 /* Temporarily include '@' in symbol names. */
1189 old_lexat
= lex_type
[(unsigned char) '@'];
1190 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1191 c
= get_symbol_end ();
1192 lex_type
[(unsigned char) '@'] = old_lexat
;
1194 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1196 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1198 *input_line_pointer
= c
;
1200 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1201 ELF_VER_CHR
) == NULL
)
1203 as_bad (_("missing version name in `%s' for symbol `%s'"),
1204 symbol_get_obj (sym
)->versioned_name
,
1206 ignore_rest_of_line ();
1212 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1214 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1215 name
, symbol_get_obj (sym
)->versioned_name
,
1217 ignore_rest_of_line ();
1221 *input_line_pointer
= c
;
1224 demand_empty_rest_of_line ();
1227 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1228 to the linker the hierarchy in which a particular table resides. The
1229 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1232 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1234 char *cname
, *pname
;
1235 symbolS
*csym
, *psym
;
1238 if (*input_line_pointer
== '#')
1239 ++input_line_pointer
;
1241 cname
= input_line_pointer
;
1242 c
= get_symbol_end ();
1243 csym
= symbol_find (cname
);
1245 /* GCFIXME: should check that we don't have two .vtable_inherits for
1246 the same child symbol. Also, we can currently only do this if the
1247 child symbol is already exists and is placed in a fragment. */
1249 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1251 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1256 *input_line_pointer
= c
;
1259 if (*input_line_pointer
!= ',')
1261 as_bad ("expected comma after name in .vtable_inherit");
1262 ignore_rest_of_line ();
1266 ++input_line_pointer
;
1269 if (*input_line_pointer
== '#')
1270 ++input_line_pointer
;
1272 if (input_line_pointer
[0] == '0'
1273 && (input_line_pointer
[1] == '\0'
1274 || ISSPACE (input_line_pointer
[1])))
1276 psym
= section_symbol (absolute_section
);
1277 ++input_line_pointer
;
1281 pname
= input_line_pointer
;
1282 c
= get_symbol_end ();
1283 psym
= symbol_find_or_make (pname
);
1284 *input_line_pointer
= c
;
1287 demand_empty_rest_of_line ();
1292 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1293 return fix_new (symbol_get_frag (csym
),
1294 symbol_get_value_expression (csym
)->X_add_number
,
1295 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1298 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1299 to the linker that a vtable slot was used. The syntax is
1300 ".vtable_entry tablename, offset". */
1303 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1310 if (*input_line_pointer
== '#')
1311 ++input_line_pointer
;
1313 name
= input_line_pointer
;
1314 c
= get_symbol_end ();
1315 sym
= symbol_find_or_make (name
);
1316 *input_line_pointer
= c
;
1319 if (*input_line_pointer
!= ',')
1321 as_bad ("expected comma after name in .vtable_entry");
1322 ignore_rest_of_line ();
1326 ++input_line_pointer
;
1327 if (*input_line_pointer
== '#')
1328 ++input_line_pointer
;
1330 offset
= get_absolute_expression ();
1332 demand_empty_rest_of_line ();
1334 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1335 BFD_RELOC_VTABLE_ENTRY
);
1339 elf_obj_read_begin_hook (void)
1341 #ifdef NEED_ECOFF_DEBUG
1342 if (ECOFF_DEBUGGING
)
1343 ecoff_read_begin_hook ();
1348 elf_obj_symbol_new_hook (symbolS
*symbolP
)
1350 struct elf_obj_sy
*sy_obj
;
1352 sy_obj
= symbol_get_obj (symbolP
);
1353 sy_obj
->size
= NULL
;
1354 sy_obj
->versioned_name
= NULL
;
1356 #ifdef NEED_ECOFF_DEBUG
1357 if (ECOFF_DEBUGGING
)
1358 ecoff_symbol_new_hook (symbolP
);
1362 /* When setting one symbol equal to another, by default we probably
1363 want them to have the same "size", whatever it means in the current
1367 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
1369 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1370 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1373 if (destelf
->size
== NULL
)
1374 destelf
->size
= xmalloc (sizeof (expressionS
));
1375 *destelf
->size
= *srcelf
->size
;
1379 if (destelf
->size
!= NULL
)
1380 free (destelf
->size
);
1381 destelf
->size
= NULL
;
1383 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1384 /* Don't copy visibility. */
1385 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1386 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1390 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
1395 asection
*seg
= now_seg
;
1396 subsegT subseg
= now_subseg
;
1397 Elf_Internal_Note i_note
;
1398 Elf_External_Note e_note
;
1399 asection
*note_secp
= NULL
;
1403 if (*input_line_pointer
== '\"')
1405 ++input_line_pointer
; /* -> 1st char of string. */
1406 name
= input_line_pointer
;
1408 while (is_a_char (c
= next_char_of_string ()))
1410 c
= *input_line_pointer
;
1411 *input_line_pointer
= '\0';
1412 *(input_line_pointer
- 1) = '\0';
1413 *input_line_pointer
= c
;
1415 /* create the .note section */
1417 note_secp
= subseg_new (".note", 0);
1418 bfd_set_section_flags (stdoutput
,
1420 SEC_HAS_CONTENTS
| SEC_READONLY
);
1422 /* process the version string */
1424 len
= strlen (name
);
1426 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1427 i_note
.descsz
= 0; /* no description */
1428 i_note
.type
= NT_VERSION
;
1429 p
= frag_more (sizeof (e_note
.namesz
));
1430 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
1431 p
= frag_more (sizeof (e_note
.descsz
));
1432 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
1433 p
= frag_more (sizeof (e_note
.type
));
1434 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
1435 p
= frag_more (len
+ 1);
1438 frag_align (2, 0, 0);
1440 subseg_set (seg
, subseg
);
1444 as_bad (_("expected quoted string"));
1446 demand_empty_rest_of_line ();
1450 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
1452 char *name
= input_line_pointer
;
1453 char c
= get_symbol_end ();
1458 p
= input_line_pointer
;
1461 if (*input_line_pointer
!= ',')
1464 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1466 ignore_rest_of_line ();
1469 input_line_pointer
++;
1471 if (exp
.X_op
== O_absent
)
1473 as_bad (_("missing expression in .size directive"));
1474 exp
.X_op
= O_constant
;
1475 exp
.X_add_number
= 0;
1478 sym
= symbol_find_or_make (name
);
1480 if (exp
.X_op
== O_constant
)
1482 S_SET_SIZE (sym
, exp
.X_add_number
);
1483 if (symbol_get_obj (sym
)->size
)
1485 xfree (symbol_get_obj (sym
)->size
);
1486 symbol_get_obj (sym
)->size
= NULL
;
1491 symbol_get_obj (sym
)->size
= xmalloc (sizeof (expressionS
));
1492 *symbol_get_obj (sym
)->size
= exp
;
1494 demand_empty_rest_of_line ();
1497 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1498 There are five syntaxes:
1500 The first (used on Solaris) is
1502 The second (used on UnixWare) is
1504 The third (reportedly to be used on Irix 6.0) is
1506 The fourth (used on NetBSD/Arm and Linux/ARM) is
1508 The fifth (used on SVR4/860) is
1509 .type SYM,"function"
1513 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
1518 const char *typename
;
1520 elf_symbol_type
*elfsym
;
1522 name
= input_line_pointer
;
1523 c
= get_symbol_end ();
1524 sym
= symbol_find_or_make (name
);
1525 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1526 *input_line_pointer
= c
;
1529 if (*input_line_pointer
== ',')
1530 ++input_line_pointer
;
1533 if ( *input_line_pointer
== '#'
1534 || *input_line_pointer
== '@'
1535 || *input_line_pointer
== '"'
1536 || *input_line_pointer
== '%')
1537 ++input_line_pointer
;
1539 typename
= input_line_pointer
;
1540 c
= get_symbol_end ();
1543 if (strcmp (typename
, "function") == 0
1544 || strcmp (typename
, "STT_FUNC") == 0)
1545 type
= BSF_FUNCTION
;
1546 else if (strcmp (typename
, "object") == 0
1547 || strcmp (typename
, "STT_OBJECT") == 0)
1549 else if (strcmp (typename
, "tls_object") == 0
1550 || strcmp (typename
, "STT_TLS") == 0)
1551 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
1552 else if (strcmp (typename
, "notype") == 0
1553 || strcmp (typename
, "STT_NOTYPE") == 0)
1555 #ifdef md_elf_symbol_type
1556 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1560 as_bad (_("unrecognized symbol type \"%s\""), typename
);
1562 *input_line_pointer
= c
;
1564 if (*input_line_pointer
== '"')
1565 ++input_line_pointer
;
1567 elfsym
->symbol
.flags
|= type
;
1569 demand_empty_rest_of_line ();
1573 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
1575 static segT comment_section
;
1576 segT old_section
= now_seg
;
1577 int old_subsection
= now_subseg
;
1579 #ifdef md_flush_pending_output
1580 md_flush_pending_output ();
1583 if (!comment_section
)
1586 comment_section
= subseg_new (".comment", 0);
1587 bfd_set_section_flags (stdoutput
, comment_section
,
1588 SEC_READONLY
| SEC_HAS_CONTENTS
);
1593 subseg_set (comment_section
, 0);
1595 subseg_set (old_section
, old_subsection
);
1598 #ifdef INIT_STAB_SECTION
1600 /* The first entry in a .stabs section is special. */
1603 obj_elf_init_stab_section (segT seg
)
1608 unsigned int stroff
;
1610 /* Force the section to align to a longword boundary. Without this,
1611 UnixWare ar crashes. */
1612 bfd_set_section_alignment (stdoutput
, seg
, 2);
1614 /* Make space for this first symbol. */
1618 as_where (&file
, NULL
);
1619 stabstr_name
= xmalloc (strlen (segment_name (seg
)) + 4);
1620 strcpy (stabstr_name
, segment_name (seg
));
1621 strcat (stabstr_name
, "str");
1622 stroff
= get_stab_string_offset (file
, stabstr_name
);
1624 md_number_to_chars (p
, stroff
, 4);
1625 seg_info (seg
)->stabu
.p
= p
;
1630 /* Fill in the counts in the first entry in a .stabs section. */
1633 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
1640 if (strncmp (".stab", sec
->name
, 5))
1642 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1645 name
= alloca (strlen (sec
->name
) + 4);
1646 strcpy (name
, sec
->name
);
1647 strcat (name
, "str");
1648 strsec
= bfd_get_section_by_name (abfd
, name
);
1650 strsz
= bfd_section_size (abfd
, strsec
);
1653 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1655 p
= seg_info (sec
)->stabu
.p
;
1658 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
1659 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
1662 #ifdef NEED_ECOFF_DEBUG
1664 /* This function is called by the ECOFF code. It is supposed to
1665 record the external symbol information so that the backend can
1666 write it out correctly. The ELF backend doesn't actually handle
1667 this at the moment, so we do it ourselves. We save the information
1671 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
1673 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
1676 /* This function is called by bfd_ecoff_debug_externals. It is
1677 supposed to *EXT to the external symbol information, and return
1678 whether the symbol should be used at all. */
1681 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
1683 if (sym
->udata
.p
== NULL
)
1685 *ext
= *(EXTR
*) sym
->udata
.p
;
1689 /* This function is called by bfd_ecoff_debug_externals. It has
1690 nothing to do for ELF. */
1693 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
1694 bfd_size_type indx ATTRIBUTE_UNUSED
)
1698 #endif /* NEED_ECOFF_DEBUG */
1701 elf_frob_symbol (symbolS
*symp
, int *puntp
)
1703 struct elf_obj_sy
*sy_obj
;
1705 #ifdef NEED_ECOFF_DEBUG
1706 if (ECOFF_DEBUGGING
)
1707 ecoff_frob_symbol (symp
);
1710 sy_obj
= symbol_get_obj (symp
);
1712 if (sy_obj
->size
!= NULL
)
1714 switch (sy_obj
->size
->X_op
)
1718 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1719 + sy_obj
->size
->X_add_number
1720 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1724 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1725 + sy_obj
->size
->X_add_number
));
1728 as_bad (_(".size expression too complicated to fix up"));
1731 free (sy_obj
->size
);
1732 sy_obj
->size
= NULL
;
1735 if (sy_obj
->versioned_name
!= NULL
)
1739 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1742 /* This symbol was given a new name with the .symver directive.
1744 If this is an external reference, just rename the symbol to
1745 include the version string. This will make the relocs be
1746 against the correct versioned symbol.
1748 If this is a definition, add an alias. FIXME: Using an alias
1749 will permit the debugging information to refer to the right
1750 symbol. However, it's not clear whether it is the best
1753 if (! S_IS_DEFINED (symp
))
1755 /* Verify that the name isn't using the @@ syntax--this is
1756 reserved for definitions of the default version to link
1758 if (p
[1] == ELF_VER_CHR
)
1760 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1761 sy_obj
->versioned_name
);
1764 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1768 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1772 /* The @@@ syntax is a special case. It renames the
1773 symbol name to versioned_name with one `@' removed. */
1774 l
= strlen (&p
[3]) + 1;
1775 memmove (&p
[2], &p
[3], l
);
1776 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1782 /* FIXME: Creating a new symbol here is risky. We're
1783 in the final loop over the symbol table. We can
1784 get away with it only because the symbol goes to
1785 the end of the list, where the loop will still see
1786 it. It would probably be better to do this in
1787 obj_frob_file_before_adjust. */
1789 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1791 /* Now we act as though we saw symp2 = sym. */
1793 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1795 /* Subtracting out the frag address here is a hack
1796 because we are in the middle of the final loop. */
1799 - symbol_get_frag (symp
)->fr_address
));
1801 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1803 /* This will copy over the size information. */
1804 copy_symbol_attributes (symp2
, symp
);
1806 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
1808 if (S_IS_WEAK (symp
))
1811 if (S_IS_EXTERNAL (symp
))
1812 S_SET_EXTERNAL (symp2
);
1817 /* Double check weak symbols. */
1818 if (S_IS_WEAK (symp
))
1820 if (S_IS_COMMON (symp
))
1821 as_bad (_("symbol `%s' can not be both weak and common"),
1826 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1827 any undefined non-function symbol to STT_OBJECT. We try to be
1828 compatible, since newer Irix 5 and 6 linkers care. However, we
1829 only set undefined symbols to be STT_OBJECT if we are on Irix,
1830 because that is the only time gcc will generate the necessary
1831 .global directives to mark functions. */
1833 if (S_IS_COMMON (symp
))
1834 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1836 if (strstr (TARGET_OS
, "irix") != NULL
1837 && ! S_IS_DEFINED (symp
)
1838 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1839 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1845 asection
**head
; /* Section lists. */
1846 unsigned int *elt_count
; /* Number of sections in each list. */
1847 unsigned int num_group
; /* Number of lists. */
1850 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1851 add it to a list of sections belonging to the group. INF is a
1852 pointer to a struct group_list, which is where we store the head of
1856 build_group_lists (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
1858 struct group_list
*list
= inf
;
1859 const char *group_name
= elf_group_name (sec
);
1862 if (group_name
== NULL
)
1865 /* If this group already has a list, add the section to the head of
1867 for (i
= 0; i
< list
->num_group
; i
++)
1869 if (strcmp (group_name
, elf_group_name (list
->head
[i
])) == 0)
1871 elf_next_in_group (sec
) = list
->head
[i
];
1872 list
->head
[i
] = sec
;
1873 list
->elt_count
[i
] += 1;
1878 /* New group. Make the arrays bigger in chunks to minimize calls to
1880 i
= list
->num_group
;
1883 unsigned int newsize
= i
+ 128;
1884 list
->head
= xrealloc (list
->head
, newsize
* sizeof (*list
->head
));
1885 list
->elt_count
= xrealloc (list
->elt_count
,
1886 newsize
* sizeof (*list
->elt_count
));
1888 list
->head
[i
] = sec
;
1889 list
->elt_count
[i
] = 1;
1890 list
->num_group
+= 1;
1894 elf_frob_file (void)
1896 struct group_list list
;
1899 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
1901 /* Go find section groups. */
1904 list
.elt_count
= NULL
;
1905 bfd_map_over_sections (stdoutput
, build_group_lists
, &list
);
1907 /* Make the SHT_GROUP sections that describe each section group. We
1908 can't set up the section contents here yet, because elf section
1909 indices have yet to be calculated. elf.c:set_group_contents does
1910 the rest of the work. */
1911 for (i
= 0; i
< list
.num_group
; i
++)
1913 const char *group_name
= elf_group_name (list
.head
[i
]);
1914 const char *sec_name
;
1921 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
1922 for (s
= list
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
1923 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
1925 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1926 if (s
!= list
.head
[i
])
1928 as_warn (_("assuming all members of group `%s' are COMDAT"),
1934 sec_name
= group_name
;
1935 sy
= symbol_find_exact (group_name
);
1938 && (sy
== symbol_lastP
1939 || (sy
->sy_next
!= NULL
1940 && sy
->sy_next
->sy_previous
== sy
)))
1943 sec_name
= ".group";
1945 s
= subseg_force_new (sec_name
, 0);
1947 || !bfd_set_section_flags (stdoutput
, s
, flags
)
1948 || !bfd_set_section_alignment (stdoutput
, s
, 2))
1950 as_fatal (_("can't create group: %s"),
1951 bfd_errmsg (bfd_get_error ()));
1953 elf_section_type (s
) = SHT_GROUP
;
1955 /* Pass a pointer to the first section in this group. */
1956 elf_next_in_group (s
) = list
.head
[i
];
1958 elf_group_id (s
) = sy
->bsym
;
1960 size
= 4 * (list
.elt_count
[i
] + 1);
1961 bfd_set_section_size (stdoutput
, s
, size
);
1962 s
->contents
= (unsigned char *) frag_more (size
);
1963 frag_now
->fr_fix
= frag_now_fix_octets ();
1966 #ifdef elf_tc_final_processing
1967 elf_tc_final_processing ();
1971 /* It removes any unneeded versioned symbols from the symbol table. */
1974 elf_frob_file_before_adjust (void)
1980 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1981 if (!S_IS_DEFINED (symp
))
1983 if (symbol_get_obj (symp
)->versioned_name
)
1987 /* The @@@ syntax is a special case. If the symbol is
1988 not defined, 2 `@'s will be removed from the
1991 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1994 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1996 size_t l
= strlen (&p
[3]) + 1;
1997 memmove (&p
[1], &p
[3], l
);
1999 if (symbol_used_p (symp
) == 0
2000 && symbol_used_in_reloc_p (symp
) == 0)
2001 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2004 /* If there was .weak foo, but foo was neither defined nor
2005 used anywhere, remove it. */
2007 else if (S_IS_WEAK (symp
)
2008 && symbol_used_p (symp
) == 0
2009 && symbol_used_in_reloc_p (symp
) == 0)
2010 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2015 /* It is required that we let write_relocs have the opportunity to
2016 optimize away fixups before output has begun, since it is possible
2017 to eliminate all fixups for a section and thus we never should
2018 have generated the relocation section. */
2021 elf_frob_file_after_relocs (void)
2023 #ifdef NEED_ECOFF_DEBUG
2024 if (ECOFF_DEBUGGING
)
2025 /* Generate the ECOFF debugging information. */
2027 const struct ecoff_debug_swap
*debug_swap
;
2028 struct ecoff_debug_info debug
;
2033 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2034 know (debug_swap
!= NULL
);
2035 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2037 /* Set up the pointers in debug. */
2038 #define SET(ptr, offset, type) \
2039 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2041 SET (line
, cbLineOffset
, unsigned char *);
2042 SET (external_dnr
, cbDnOffset
, void *);
2043 SET (external_pdr
, cbPdOffset
, void *);
2044 SET (external_sym
, cbSymOffset
, void *);
2045 SET (external_opt
, cbOptOffset
, void *);
2046 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2047 SET (ss
, cbSsOffset
, char *);
2048 SET (external_fdr
, cbFdOffset
, void *);
2049 SET (external_rfd
, cbRfdOffset
, void *);
2050 /* ssext and external_ext are set up just below. */
2054 /* Set up the external symbols. */
2055 debug
.ssext
= debug
.ssext_end
= NULL
;
2056 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2057 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2058 elf_get_extr
, elf_set_index
))
2059 as_fatal (_("failed to set up debugging information: %s"),
2060 bfd_errmsg (bfd_get_error ()));
2062 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2063 assert (sec
!= NULL
);
2065 know (!stdoutput
->output_has_begun
);
2067 /* We set the size of the section, call bfd_set_section_contents
2068 to force the ELF backend to allocate a file position, and then
2069 write out the data. FIXME: Is this really the best way to do
2071 bfd_set_section_size
2072 (stdoutput
, sec
, bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
));
2074 /* Pass BUF to bfd_set_section_contents because this will
2075 eventually become a call to fwrite, and ISO C prohibits
2076 passing a NULL pointer to a stdio function even if the
2077 pointer will not be used. */
2078 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
2079 as_fatal (_("can't start writing .mdebug section: %s"),
2080 bfd_errmsg (bfd_get_error ()));
2082 know (stdoutput
->output_has_begun
);
2083 know (sec
->filepos
!= 0);
2085 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2087 as_fatal (_("could not write .mdebug section: %s"),
2088 bfd_errmsg (bfd_get_error ()));
2090 #endif /* NEED_ECOFF_DEBUG */
2095 /* Heavily plagiarized from obj_elf_version. The idea is to emit the
2096 SCO specific identifier in the .notes section to satisfy the SCO
2099 This looks more complicated than it really is. As opposed to the
2100 "obvious" solution, this should handle the cross dev cases
2101 correctly. (i.e, hosting on a 64 bit big endian processor, but
2102 generating SCO Elf code) Efficiency isn't a concern, as there
2103 should be exactly one of these sections per object module.
2105 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2108 int_32 namesz = 4 ; Name size
2109 int_32 descsz = 12 ; Descriptive information
2111 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2112 int_32 version = (major ver # << 16) | version of tools ;
2113 int_32 source = (tool_id << 16 ) | 1 ;
2114 int_32 info = 0 ; These are set by the SCO tools, but we
2115 don't know enough about the source
2116 environment to set them. SCO ld currently
2117 ignores them, and recommends we set them
2120 #define SCO_MAJOR_VERSION 0x1
2121 #define SCO_MINOR_VERSION 0x1
2131 asection
*seg
= now_seg
;
2132 subsegT subseg
= now_subseg
;
2133 Elf_Internal_Note i_note
;
2134 Elf_External_Note e_note
;
2135 asection
*note_secp
= NULL
;
2138 /* create the .note section */
2140 note_secp
= subseg_new (".note", 0);
2141 bfd_set_section_flags (stdoutput
,
2143 SEC_HAS_CONTENTS
| SEC_READONLY
);
2145 /* process the version string */
2148 i_note
.descsz
= 12; /* 12 descriptive bytes */
2149 i_note
.type
= NT_VERSION
; /* Contains a version string */
2151 p
= frag_more (sizeof (i_note
.namesz
));
2152 md_number_to_chars (p
, i_note
.namesz
, 4);
2154 p
= frag_more (sizeof (i_note
.descsz
));
2155 md_number_to_chars (p
, i_note
.descsz
, 4);
2157 p
= frag_more (sizeof (i_note
.type
));
2158 md_number_to_chars (p
, i_note
.type
, 4);
2163 /* Note: this is the version number of the ELF we're representing */
2165 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2167 /* Here, we pick a magic number for ourselves (yes, I "registered"
2168 it with SCO. The bottom bit shows that we are compat with the
2171 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2173 /* If we knew (or cared) what the source language options were, we'd
2174 fill them in here. SCO has given us permission to ignore these
2175 and just set them to zero. */
2177 md_number_to_chars (p
, 0x0000, 4);
2179 frag_align (2, 0, 0);
2181 /* We probably can't restore the current segment, for there likely
2184 subseg_set (seg
, subseg
);
2188 #endif /* SCO_ELF */
2191 elf_separate_stab_sections (void)
2193 #ifdef NEED_ECOFF_DEBUG
2194 return (!ECOFF_DEBUGGING
);
2201 elf_init_stab_section (segT seg
)
2203 #ifdef NEED_ECOFF_DEBUG
2204 if (!ECOFF_DEBUGGING
)
2206 obj_elf_init_stab_section (seg
);
2209 const struct format_ops elf_format_ops
=
2211 bfd_target_elf_flavour
,
2212 0, /* dfl_leading_underscore */
2213 1, /* emit_section_symbols */
2218 elf_frob_file_before_adjust
,
2219 0, /* obj_frob_file_before_fix */
2220 elf_frob_file_after_relocs
,
2221 elf_s_get_size
, elf_s_set_size
,
2222 elf_s_get_align
, elf_s_set_align
,
2229 elf_copy_symbol_attributes
,
2230 #ifdef NEED_ECOFF_DEBUG
2231 ecoff_generate_asm_lineno
,
2234 0, /* generate_asm_lineno */
2235 0, /* process_stab */
2237 elf_separate_stab_sections
,
2238 elf_init_stab_section
,
2239 elf_sec_sym_ok_for_reloc
,
2241 #ifdef NEED_ECOFF_DEBUG
2244 0, /* ecoff_set_ext */
2246 elf_obj_read_begin_hook
,
2247 elf_obj_symbol_new_hook