1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004 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, 59 Temple Place - Suite 330, 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);
69 static const pseudo_typeS elf_pseudo_table
[] =
71 {"comm", obj_elf_common
, 0},
72 {"common", obj_elf_common
, 1},
73 {"ident", obj_elf_ident
, 0},
74 {"lcomm", obj_elf_lcomm
, 0},
75 {"local", obj_elf_local
, 0},
76 {"previous", obj_elf_previous
, 0},
77 {"section", obj_elf_section
, 0},
78 {"section.s", obj_elf_section
, 0},
79 {"sect", obj_elf_section
, 0},
80 {"sect.s", obj_elf_section
, 0},
81 {"pushsection", obj_elf_section
, 1},
82 {"popsection", obj_elf_popsection
, 0},
83 {"size", obj_elf_size
, 0},
84 {"type", obj_elf_type
, 0},
85 {"version", obj_elf_version
, 0},
86 {"weak", obj_elf_weak
, 0},
88 /* These define symbol visibility. */
89 {"internal", obj_elf_visibility
, STV_INTERNAL
},
90 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
91 {"protected", obj_elf_visibility
, STV_PROTECTED
},
93 /* These are used for stabs-in-elf configurations. */
94 {"line", obj_elf_line
, 0},
96 /* This is a GNU extension to handle symbol versions. */
97 {"symver", obj_elf_symver
, 0},
99 /* A GNU extension to change subsection only. */
100 {"subsection", obj_elf_subsection
, 0},
102 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
103 {"vtable_inherit", (void (*) (int)) &obj_elf_vtable_inherit
, 0},
104 {"vtable_entry", (void (*) (int)) &obj_elf_vtable_entry
, 0},
106 /* These are used for dwarf. */
110 /* These are used for dwarf2. */
111 { "file", (void (*) (int)) dwarf2_directive_file
, 0 },
112 { "loc", dwarf2_directive_loc
, 0 },
114 /* We need to trap the section changing calls to handle .previous. */
115 {"data", obj_elf_data
, 0},
116 {"text", obj_elf_text
, 0},
118 {"tls_common", obj_elf_tls_common
, 0},
124 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
126 #ifdef NEED_ECOFF_DEBUG
127 /* COFF style debugging information for ECOFF. .ln is not used; .loc
129 { "def", ecoff_directive_def
, 0 },
130 { "dim", ecoff_directive_dim
, 0 },
131 { "endef", ecoff_directive_endef
, 0 },
132 { "file", ecoff_directive_file
, 0 },
133 { "scl", ecoff_directive_scl
, 0 },
134 { "tag", ecoff_directive_tag
, 0 },
135 { "val", ecoff_directive_val
, 0 },
137 /* COFF debugging requires pseudo-ops .size and .type, but ELF
138 already has meanings for those. We use .esize and .etype
139 instead. These are only generated by gcc anyhow. */
140 { "esize", ecoff_directive_size
, 0 },
141 { "etype", ecoff_directive_type
, 0 },
143 /* ECOFF specific debugging information. */
144 { "begin", ecoff_directive_begin
, 0 },
145 { "bend", ecoff_directive_bend
, 0 },
146 { "end", ecoff_directive_end
, 0 },
147 { "ent", ecoff_directive_ent
, 0 },
148 { "fmask", ecoff_directive_fmask
, 0 },
149 { "frame", ecoff_directive_frame
, 0 },
150 { "loc", ecoff_directive_loc
, 0 },
151 { "mask", ecoff_directive_mask
, 0 },
153 /* Other ECOFF directives. */
154 { "extern", ecoff_directive_extern
, 0 },
156 /* These are used on Irix. I don't know how to implement them. */
157 { "alias", s_ignore
, 0 },
158 { "bgnb", s_ignore
, 0 },
159 { "endb", s_ignore
, 0 },
160 { "lab", s_ignore
, 0 },
161 { "noalias", s_ignore
, 0 },
162 { "verstamp", s_ignore
, 0 },
163 { "vreg", s_ignore
, 0 },
166 {NULL
, NULL
, 0} /* end sentinel */
170 #include "aout/aout64.h"
172 /* This is called when the assembler starts. */
179 /* Add symbols for the known sections to the symbol table. */
180 s
= bfd_get_section_by_name (stdoutput
, TEXT_SECTION_NAME
);
181 symbol_table_insert (section_symbol (s
));
182 s
= bfd_get_section_by_name (stdoutput
, DATA_SECTION_NAME
);
183 symbol_table_insert (section_symbol (s
));
184 s
= bfd_get_section_by_name (stdoutput
, BSS_SECTION_NAME
);
185 symbol_table_insert (section_symbol (s
));
189 elf_pop_insert (void)
191 pop_insert (elf_pseudo_table
);
193 pop_insert (ecoff_debug_pseudo_table
);
197 elf_s_get_size (symbolS
*sym
)
199 return S_GET_SIZE (sym
);
203 elf_s_set_size (symbolS
*sym
, bfd_vma sz
)
205 S_SET_SIZE (sym
, sz
);
209 elf_s_get_align (symbolS
*sym
)
211 return S_GET_ALIGN (sym
);
215 elf_s_set_align (symbolS
*sym
, bfd_vma align
)
217 S_SET_ALIGN (sym
, align
);
221 elf_s_get_other (symbolS
*sym
)
223 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
227 elf_s_set_other (symbolS
*sym
, int other
)
229 S_SET_OTHER (sym
, other
);
233 elf_sec_sym_ok_for_reloc (asection
*sec
)
235 return obj_sec_sym_ok_for_reloc (sec
);
239 elf_file_symbol (const char *s
)
243 sym
= symbol_new (s
, absolute_section
, 0, NULL
);
244 symbol_set_frag (sym
, &zero_address_frag
);
245 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
247 if (symbol_rootP
!= sym
)
249 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
250 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
252 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
256 #ifdef NEED_ECOFF_DEBUG
261 /* Called from read.c:s_comm after we've parsed .comm symbol, size.
262 Parse a possible alignment value. */
265 elf_common_parse (int ignore ATTRIBUTE_UNUSED
, symbolS
*symbolP
, addressT size
)
268 int is_local
= symbol_get_obj (symbolP
)->local
;
270 if (*input_line_pointer
== ',')
272 char *save
= input_line_pointer
;
274 input_line_pointer
++;
277 if (*input_line_pointer
== '"')
279 /* For sparc. Accept .common symbol, length, "bss" */
280 input_line_pointer
++;
281 /* Some use the dot, some don't. */
282 if (*input_line_pointer
== '.')
283 input_line_pointer
++;
284 /* Some say data, some say bss. */
285 if (strncmp (input_line_pointer
, "bss\"", 4) == 0)
286 input_line_pointer
+= 4;
287 else if (strncmp (input_line_pointer
, "data\"", 5) == 0)
288 input_line_pointer
+= 5;
291 char *p
= input_line_pointer
;
296 while (!is_end_of_line
[(unsigned char) *input_line_pointer
])
297 if (*input_line_pointer
++ == '"')
299 c
= *input_line_pointer
;
300 *input_line_pointer
= '\0';
301 as_bad (_("bad .common segment %s"), p
);
302 *input_line_pointer
= c
;
303 ignore_rest_of_line ();
306 /* ??? Don't ask me why these are always global. */
311 input_line_pointer
= save
;
312 align
= parse_align (is_local
);
313 if (align
== (addressT
) -1)
320 bss_alloc (symbolP
, size
, align
);
321 S_CLEAR_EXTERNAL (symbolP
);
325 S_SET_VALUE (symbolP
, size
);
326 S_SET_ALIGN (symbolP
, align
);
327 S_SET_EXTERNAL (symbolP
);
328 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
331 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
337 obj_elf_common (int is_common
)
339 if (flag_mri
&& is_common
)
342 s_comm_internal (0, elf_common_parse
);
346 obj_elf_tls_common (int ignore ATTRIBUTE_UNUSED
)
348 symbolS
*symbolP
= s_comm_internal (0, elf_common_parse
);
351 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
355 obj_elf_lcomm (int ignore ATTRIBUTE_UNUSED
)
357 symbolS
*symbolP
= s_comm_internal (0, s_lcomm_internal
);
360 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
364 obj_elf_local (int ignore ATTRIBUTE_UNUSED
)
372 name
= input_line_pointer
;
373 c
= get_symbol_end ();
374 symbolP
= symbol_find_or_make (name
);
375 *input_line_pointer
= c
;
377 S_CLEAR_EXTERNAL (symbolP
);
378 symbol_get_obj (symbolP
)->local
= 1;
381 input_line_pointer
++;
383 if (*input_line_pointer
== '\n')
388 demand_empty_rest_of_line ();
392 obj_elf_weak (int ignore ATTRIBUTE_UNUSED
)
400 name
= input_line_pointer
;
401 c
= get_symbol_end ();
402 symbolP
= symbol_find_or_make (name
);
403 *input_line_pointer
= c
;
405 S_SET_WEAK (symbolP
);
406 symbol_get_obj (symbolP
)->local
= 1;
409 input_line_pointer
++;
411 if (*input_line_pointer
== '\n')
416 demand_empty_rest_of_line ();
420 obj_elf_visibility (int visibility
)
426 elf_symbol_type
*elfsym
;
430 name
= input_line_pointer
;
431 c
= get_symbol_end ();
432 symbolP
= symbol_find_or_make (name
);
433 *input_line_pointer
= c
;
437 bfdsym
= symbol_get_bfdsym (symbolP
);
438 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
442 elfsym
->internal_elf_sym
.st_other
&= ~3;
443 elfsym
->internal_elf_sym
.st_other
|= visibility
;
447 input_line_pointer
++;
451 if (*input_line_pointer
== '\n')
457 demand_empty_rest_of_line ();
460 static segT previous_section
;
461 static int previous_subsection
;
465 struct section_stack
*next
;
467 int subseg
, prev_subseg
;
470 static struct section_stack
*section_stack
;
473 get_section (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
475 const char *gname
= inf
;
476 const char *group_name
= elf_group_name (sec
);
478 return (group_name
== gname
479 || (group_name
!= NULL
481 && strcmp (group_name
, gname
) == 0));
484 /* Handle the .section pseudo-op. This code supports two different
487 The first is found on Solaris, and looks like
488 .section ".sec1",#alloc,#execinstr,#write
489 Here the names after '#' are the SHF_* flags to turn on for the
490 section. I'm not sure how it determines the SHT_* type (BFD
491 doesn't really give us control over the type, anyhow).
493 The second format is found on UnixWare, and probably most SVR4
494 machines, and looks like
495 .section .sec1,"a",@progbits
496 The quoted string may contain any combination of a, w, x, and
497 represents the SHF_* flags to turn on for the section. The string
498 beginning with '@' can be progbits or nobits. There should be
499 other possibilities, but I don't know what they are. In any case,
500 BFD doesn't really let us set the section type. */
503 obj_elf_change_section (const char *name
,
507 const char *group_name
,
514 const struct bfd_elf_special_section
*ssect
;
516 #ifdef md_flush_pending_output
517 md_flush_pending_output ();
520 /* Switch to the section, creating it if necessary. */
523 struct section_stack
*elt
;
524 elt
= xmalloc (sizeof (struct section_stack
));
525 elt
->next
= section_stack
;
527 elt
->prev_seg
= previous_section
;
528 elt
->subseg
= now_subseg
;
529 elt
->prev_subseg
= previous_subsection
;
532 previous_section
= now_seg
;
533 previous_subsection
= now_subseg
;
535 old_sec
= bfd_get_section_by_name_if (stdoutput
, name
, get_section
,
536 (void *) group_name
);
543 sec
= subseg_force_new (name
, 0);
545 ssect
= _bfd_elf_get_sec_type_attr (stdoutput
, name
);
549 bfd_boolean override
= FALSE
;
551 if (type
== SHT_NULL
)
553 else if (type
!= ssect
->type
)
556 /* FIXME: gcc, as of 2002-10-22, will emit
558 .section .init_array,"aw",@progbits
560 for __attribute__ ((section (".init_array"))).
561 "@progbits" is incorrect. */
562 && ssect
->type
!= SHT_INIT_ARRAY
563 && ssect
->type
!= SHT_FINI_ARRAY
564 && ssect
->type
!= SHT_PREINIT_ARRAY
)
566 /* We allow to specify any type for a .note section. */
567 if (ssect
->type
!= SHT_NOTE
)
568 as_warn (_("setting incorrect section type for %s"),
573 as_warn (_("ignoring incorrect section type for %s"),
579 if (old_sec
== NULL
&& (attr
& ~ssect
->attr
) != 0)
581 /* As a GNU extension, we permit a .note section to be
582 allocatable. If the linker sees an allocatable .note
583 section, it will create a PT_NOTE segment in the output
584 file. We also allow "x" for .note.GNU-stack. */
585 if (ssect
->type
== SHT_NOTE
586 && (attr
== SHF_ALLOC
|| attr
== SHF_EXECINSTR
))
588 /* Allow different SHF_MERGE and SHF_STRINGS if we have
589 something like .rodata.str. */
590 else if (ssect
->suffix_length
== -2
591 && name
[ssect
->prefix_length
] == '.'
595 & ~SHF_STRINGS
) == 0)
597 /* .interp, .strtab and .symtab can have SHF_ALLOC. */
598 else if (attr
== SHF_ALLOC
599 && (strcmp (name
, ".interp") == 0
600 || strcmp (name
, ".strtab") == 0
601 || strcmp (name
, ".symtab") == 0))
603 /* .note.GNU-stack can have SHF_EXECINSTR. */
604 else if (attr
== SHF_EXECINSTR
605 && strcmp (name
, ".note.GNU-stack") == 0)
609 if (group_name
== NULL
)
610 as_warn (_("setting incorrect section attributes for %s"),
615 if (!override
&& old_sec
== NULL
)
619 if (type
!= SHT_NULL
)
620 elf_section_type (sec
) = type
;
622 elf_section_flags (sec
) = attr
;
624 /* Convert ELF type and flags to BFD flags. */
626 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
627 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
628 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
629 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
630 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
631 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
632 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
633 #ifdef md_elf_section_flags
634 flags
= md_elf_section_flags (flags
, attr
, type
);
638 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
644 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
645 if (type
== SHT_NOBITS
)
646 seg_info (sec
)->bss
= 1;
648 bfd_set_section_flags (stdoutput
, sec
, flags
);
649 if (flags
& SEC_MERGE
)
650 sec
->entsize
= entsize
;
651 elf_group_name (sec
) = group_name
;
653 /* Add a symbol for this section to the symbol table. */
654 secsym
= symbol_find (name
);
656 symbol_set_bfdsym (secsym
, sec
->symbol
);
658 symbol_table_insert (section_symbol (sec
));
662 /* If section attributes are specified the second time we see a
663 particular section, then check that they are the same as we
664 saw the first time. */
665 if (((old_sec
->flags
^ flags
)
666 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
667 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
668 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
669 | SEC_THREAD_LOCAL
)))
670 as_warn (_("ignoring changed section attributes for %s"), name
);
671 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
672 as_warn (_("ignoring changed section entity size for %s"), name
);
675 #ifdef md_elf_section_change_hook
676 md_elf_section_change_hook ();
681 obj_elf_parse_section_letters (char *str
, size_t len
)
696 attr
|= SHF_EXECINSTR
;
712 if (*(str
- 1) == 'a')
715 if (len
> 1 && str
[1] == 's')
724 char *bad_msg
= _("unrecognized .section attribute: want a,w,x,M,S,G,T");
725 #ifdef md_elf_section_letter
726 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
731 as_fatal ("%s", bad_msg
);
742 obj_elf_section_word (char *str
, size_t len
)
744 if (len
== 5 && strncmp (str
, "write", 5) == 0)
746 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
748 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
749 return SHF_EXECINSTR
;
750 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
753 #ifdef md_elf_section_word
755 int md_attr
= md_elf_section_word (str
, len
);
761 as_warn (_("unrecognized section attribute"));
766 obj_elf_section_type (char *str
, size_t len
)
768 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
770 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
772 if (len
== 4 && strncmp (str
, "note", 4) == 0)
775 #ifdef md_elf_section_type
777 int md_type
= md_elf_section_type (str
, len
);
783 as_warn (_("unrecognized section type"));
787 /* Get name of section. */
789 obj_elf_section_name (void)
794 if (*input_line_pointer
== '"')
798 name
= demand_copy_C_string (&dummy
);
801 ignore_rest_of_line ();
807 char *end
= input_line_pointer
;
809 while (0 == strchr ("\n\t,; ", *end
))
811 if (end
== input_line_pointer
)
813 as_bad (_("missing name"));
814 ignore_rest_of_line ();
818 name
= xmalloc (end
- input_line_pointer
+ 1);
819 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
820 name
[end
- input_line_pointer
] = '\0';
821 #ifdef tc_canonicalize_section_name
822 name
= tc_canonicalize_section_name (name
);
824 input_line_pointer
= end
;
831 obj_elf_section (int push
)
833 char *name
, *group_name
, *beg
;
834 int type
, attr
, dummy
;
843 #ifdef md_flush_pending_output
844 md_flush_pending_output ();
847 previous_section
= now_seg
;
848 previous_subsection
= now_subseg
;
850 s_mri_sect (&mri_type
);
852 #ifdef md_elf_section_change_hook
853 md_elf_section_change_hook ();
858 #endif /* ! defined (TC_I370) */
860 name
= obj_elf_section_name ();
869 if (*input_line_pointer
== ',')
871 /* Skip the comma. */
872 ++input_line_pointer
;
875 if (*input_line_pointer
== '"')
877 beg
= demand_copy_C_string (&dummy
);
880 ignore_rest_of_line ();
883 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
886 if (*input_line_pointer
== ',')
889 char *save
= input_line_pointer
;
891 ++input_line_pointer
;
893 c
= *input_line_pointer
;
896 beg
= demand_copy_C_string (&dummy
);
899 ignore_rest_of_line ();
902 type
= obj_elf_section_type (beg
, strlen (beg
));
904 else if (c
== '@' || c
== '%')
906 beg
= ++input_line_pointer
;
907 c
= get_symbol_end ();
908 *input_line_pointer
= c
;
909 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
912 input_line_pointer
= save
;
916 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
918 ++input_line_pointer
;
920 entsize
= get_absolute_expression ();
924 as_warn (_("invalid merge entity size"));
929 else if ((attr
& SHF_MERGE
) != 0)
931 as_warn (_("entity size for SHF_MERGE not specified"));
935 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
937 ++input_line_pointer
;
938 group_name
= obj_elf_section_name ();
939 if (group_name
== NULL
)
941 else if (strncmp (input_line_pointer
, ",comdat", 7) == 0)
943 input_line_pointer
+= 7;
946 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
949 else if ((attr
& SHF_GROUP
) != 0)
951 as_warn (_("group name for SHF_GROUP not specified"));
962 if (*input_line_pointer
!= '#')
964 as_bad (_("character following name is not '#'"));
965 ignore_rest_of_line ();
968 beg
= ++input_line_pointer
;
969 c
= get_symbol_end ();
970 *input_line_pointer
= c
;
972 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
976 while (*input_line_pointer
++ == ',');
977 --input_line_pointer
;
981 demand_empty_rest_of_line ();
983 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
);
986 /* Change to the .data section. */
991 #ifdef md_flush_pending_output
992 md_flush_pending_output ();
995 previous_section
= now_seg
;
996 previous_subsection
= now_subseg
;
999 #ifdef md_elf_section_change_hook
1000 md_elf_section_change_hook ();
1004 /* Change to the .text section. */
1007 obj_elf_text (int i
)
1009 #ifdef md_flush_pending_output
1010 md_flush_pending_output ();
1013 previous_section
= now_seg
;
1014 previous_subsection
= now_subseg
;
1017 #ifdef md_elf_section_change_hook
1018 md_elf_section_change_hook ();
1023 obj_elf_subsection (int ignore ATTRIBUTE_UNUSED
)
1027 #ifdef md_flush_pending_output
1028 md_flush_pending_output ();
1031 previous_section
= now_seg
;
1032 previous_subsection
= now_subseg
;
1034 temp
= get_absolute_expression ();
1035 subseg_set (now_seg
, (subsegT
) temp
);
1036 demand_empty_rest_of_line ();
1038 #ifdef md_elf_section_change_hook
1039 md_elf_section_change_hook ();
1043 /* This can be called from the processor backends if they change
1047 obj_elf_section_change_hook (void)
1049 previous_section
= now_seg
;
1050 previous_subsection
= now_subseg
;
1054 obj_elf_previous (int ignore ATTRIBUTE_UNUSED
)
1059 if (previous_section
== 0)
1061 as_warn (_(".previous without corresponding .section; ignored"));
1065 #ifdef md_flush_pending_output
1066 md_flush_pending_output ();
1069 new_section
= previous_section
;
1070 new_subsection
= previous_subsection
;
1071 previous_section
= now_seg
;
1072 previous_subsection
= now_subseg
;
1073 subseg_set (new_section
, new_subsection
);
1075 #ifdef md_elf_section_change_hook
1076 md_elf_section_change_hook ();
1081 obj_elf_popsection (int xxx ATTRIBUTE_UNUSED
)
1083 struct section_stack
*top
= section_stack
;
1087 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1091 #ifdef md_flush_pending_output
1092 md_flush_pending_output ();
1095 section_stack
= top
->next
;
1096 previous_section
= top
->prev_seg
;
1097 previous_subsection
= top
->prev_subseg
;
1098 subseg_set (top
->seg
, top
->subseg
);
1101 #ifdef md_elf_section_change_hook
1102 md_elf_section_change_hook ();
1107 obj_elf_line (int ignore ATTRIBUTE_UNUSED
)
1109 /* Assume delimiter is part of expression. BSD4.2 as fails with
1110 delightful bug, so we are not being incompatible here. */
1111 new_logical_line (NULL
, get_absolute_expression ());
1112 demand_empty_rest_of_line ();
1115 /* This handles the .symver pseudo-op, which is used to specify a
1116 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1117 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1118 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1119 with the same value as the symbol NAME. */
1122 obj_elf_symver (int ignore ATTRIBUTE_UNUSED
)
1129 name
= input_line_pointer
;
1130 c
= get_symbol_end ();
1132 sym
= symbol_find_or_make (name
);
1134 *input_line_pointer
= c
;
1137 if (*input_line_pointer
!= ',')
1139 as_bad (_("expected comma after name in .symver"));
1140 ignore_rest_of_line ();
1144 ++input_line_pointer
;
1146 name
= input_line_pointer
;
1148 /* Temporarily include '@' in symbol names. */
1149 old_lexat
= lex_type
[(unsigned char) '@'];
1150 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1151 c
= get_symbol_end ();
1152 lex_type
[(unsigned char) '@'] = old_lexat
;
1154 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1156 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1158 *input_line_pointer
= c
;
1160 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1161 ELF_VER_CHR
) == NULL
)
1163 as_bad (_("missing version name in `%s' for symbol `%s'"),
1164 symbol_get_obj (sym
)->versioned_name
,
1166 ignore_rest_of_line ();
1172 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1174 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1175 name
, symbol_get_obj (sym
)->versioned_name
,
1177 ignore_rest_of_line ();
1181 *input_line_pointer
= c
;
1184 demand_empty_rest_of_line ();
1187 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1188 to the linker the hierarchy in which a particular table resides. The
1189 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1192 obj_elf_vtable_inherit (int ignore ATTRIBUTE_UNUSED
)
1194 char *cname
, *pname
;
1195 symbolS
*csym
, *psym
;
1198 if (*input_line_pointer
== '#')
1199 ++input_line_pointer
;
1201 cname
= input_line_pointer
;
1202 c
= get_symbol_end ();
1203 csym
= symbol_find (cname
);
1205 /* GCFIXME: should check that we don't have two .vtable_inherits for
1206 the same child symbol. Also, we can currently only do this if the
1207 child symbol is already exists and is placed in a fragment. */
1209 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1211 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1216 *input_line_pointer
= c
;
1219 if (*input_line_pointer
!= ',')
1221 as_bad ("expected comma after name in .vtable_inherit");
1222 ignore_rest_of_line ();
1226 ++input_line_pointer
;
1229 if (*input_line_pointer
== '#')
1230 ++input_line_pointer
;
1232 if (input_line_pointer
[0] == '0'
1233 && (input_line_pointer
[1] == '\0'
1234 || ISSPACE (input_line_pointer
[1])))
1236 psym
= section_symbol (absolute_section
);
1237 ++input_line_pointer
;
1241 pname
= input_line_pointer
;
1242 c
= get_symbol_end ();
1243 psym
= symbol_find_or_make (pname
);
1244 *input_line_pointer
= c
;
1247 demand_empty_rest_of_line ();
1252 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1253 return fix_new (symbol_get_frag (csym
),
1254 symbol_get_value_expression (csym
)->X_add_number
,
1255 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1258 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1259 to the linker that a vtable slot was used. The syntax is
1260 ".vtable_entry tablename, offset". */
1263 obj_elf_vtable_entry (int ignore ATTRIBUTE_UNUSED
)
1270 if (*input_line_pointer
== '#')
1271 ++input_line_pointer
;
1273 name
= input_line_pointer
;
1274 c
= get_symbol_end ();
1275 sym
= symbol_find_or_make (name
);
1276 *input_line_pointer
= c
;
1279 if (*input_line_pointer
!= ',')
1281 as_bad ("expected comma after name in .vtable_entry");
1282 ignore_rest_of_line ();
1286 ++input_line_pointer
;
1287 if (*input_line_pointer
== '#')
1288 ++input_line_pointer
;
1290 offset
= get_absolute_expression ();
1292 demand_empty_rest_of_line ();
1294 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1295 BFD_RELOC_VTABLE_ENTRY
);
1299 elf_obj_read_begin_hook (void)
1301 #ifdef NEED_ECOFF_DEBUG
1302 if (ECOFF_DEBUGGING
)
1303 ecoff_read_begin_hook ();
1308 elf_obj_symbol_new_hook (symbolS
*symbolP
)
1310 struct elf_obj_sy
*sy_obj
;
1312 sy_obj
= symbol_get_obj (symbolP
);
1313 sy_obj
->size
= NULL
;
1314 sy_obj
->versioned_name
= NULL
;
1316 #ifdef NEED_ECOFF_DEBUG
1317 if (ECOFF_DEBUGGING
)
1318 ecoff_symbol_new_hook (symbolP
);
1322 /* When setting one symbol equal to another, by default we probably
1323 want them to have the same "size", whatever it means in the current
1327 elf_copy_symbol_attributes (symbolS
*dest
, symbolS
*src
)
1329 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1330 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1333 if (destelf
->size
== NULL
)
1334 destelf
->size
= xmalloc (sizeof (expressionS
));
1335 *destelf
->size
= *srcelf
->size
;
1339 if (destelf
->size
!= NULL
)
1340 free (destelf
->size
);
1341 destelf
->size
= NULL
;
1343 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1344 /* Don't copy visibility. */
1345 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1346 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1350 obj_elf_version (int ignore ATTRIBUTE_UNUSED
)
1355 asection
*seg
= now_seg
;
1356 subsegT subseg
= now_subseg
;
1357 Elf_Internal_Note i_note
;
1358 Elf_External_Note e_note
;
1359 asection
*note_secp
= NULL
;
1363 if (*input_line_pointer
== '\"')
1365 ++input_line_pointer
; /* -> 1st char of string. */
1366 name
= input_line_pointer
;
1368 while (is_a_char (c
= next_char_of_string ()))
1370 c
= *input_line_pointer
;
1371 *input_line_pointer
= '\0';
1372 *(input_line_pointer
- 1) = '\0';
1373 *input_line_pointer
= c
;
1375 /* create the .note section */
1377 note_secp
= subseg_new (".note", 0);
1378 bfd_set_section_flags (stdoutput
,
1380 SEC_HAS_CONTENTS
| SEC_READONLY
);
1382 /* process the version string */
1384 len
= strlen (name
);
1386 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1387 i_note
.descsz
= 0; /* no description */
1388 i_note
.type
= NT_VERSION
;
1389 p
= frag_more (sizeof (e_note
.namesz
));
1390 md_number_to_chars (p
, i_note
.namesz
, sizeof (e_note
.namesz
));
1391 p
= frag_more (sizeof (e_note
.descsz
));
1392 md_number_to_chars (p
, i_note
.descsz
, sizeof (e_note
.descsz
));
1393 p
= frag_more (sizeof (e_note
.type
));
1394 md_number_to_chars (p
, i_note
.type
, sizeof (e_note
.type
));
1395 p
= frag_more (len
+ 1);
1398 frag_align (2, 0, 0);
1400 subseg_set (seg
, subseg
);
1404 as_bad (_("expected quoted string"));
1406 demand_empty_rest_of_line ();
1410 obj_elf_size (int ignore ATTRIBUTE_UNUSED
)
1412 char *name
= input_line_pointer
;
1413 char c
= get_symbol_end ();
1418 p
= input_line_pointer
;
1421 if (*input_line_pointer
!= ',')
1424 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1426 ignore_rest_of_line ();
1429 input_line_pointer
++;
1431 if (exp
.X_op
== O_absent
)
1433 as_bad (_("missing expression in .size directive"));
1434 exp
.X_op
= O_constant
;
1435 exp
.X_add_number
= 0;
1438 sym
= symbol_find_or_make (name
);
1440 if (exp
.X_op
== O_constant
)
1442 S_SET_SIZE (sym
, exp
.X_add_number
);
1443 if (symbol_get_obj (sym
)->size
)
1445 xfree (symbol_get_obj (sym
)->size
);
1446 symbol_get_obj (sym
)->size
= NULL
;
1451 symbol_get_obj (sym
)->size
= xmalloc (sizeof (expressionS
));
1452 *symbol_get_obj (sym
)->size
= exp
;
1454 demand_empty_rest_of_line ();
1457 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1458 There are five syntaxes:
1460 The first (used on Solaris) is
1462 The second (used on UnixWare) is
1464 The third (reportedly to be used on Irix 6.0) is
1466 The fourth (used on NetBSD/Arm and Linux/ARM) is
1468 The fifth (used on SVR4/860) is
1469 .type SYM,"function"
1473 obj_elf_type (int ignore ATTRIBUTE_UNUSED
)
1478 const char *typename
;
1480 elf_symbol_type
*elfsym
;
1482 name
= input_line_pointer
;
1483 c
= get_symbol_end ();
1484 sym
= symbol_find_or_make (name
);
1485 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1486 *input_line_pointer
= c
;
1489 if (*input_line_pointer
== ',')
1490 ++input_line_pointer
;
1493 if ( *input_line_pointer
== '#'
1494 || *input_line_pointer
== '@'
1495 || *input_line_pointer
== '"'
1496 || *input_line_pointer
== '%')
1497 ++input_line_pointer
;
1499 typename
= input_line_pointer
;
1500 c
= get_symbol_end ();
1503 if (strcmp (typename
, "function") == 0
1504 || strcmp (typename
, "STT_FUNC") == 0)
1505 type
= BSF_FUNCTION
;
1506 else if (strcmp (typename
, "object") == 0
1507 || strcmp (typename
, "STT_OBJECT") == 0)
1509 else if (strcmp (typename
, "tls_object") == 0
1510 || strcmp (typename
, "STT_TLS") == 0)
1511 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
1512 else if (strcmp (typename
, "notype") == 0
1513 || strcmp (typename
, "STT_NOTYPE") == 0)
1515 #ifdef md_elf_symbol_type
1516 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1520 as_bad (_("unrecognized symbol type \"%s\""), typename
);
1522 *input_line_pointer
= c
;
1524 if (*input_line_pointer
== '"')
1525 ++input_line_pointer
;
1527 elfsym
->symbol
.flags
|= type
;
1529 demand_empty_rest_of_line ();
1533 obj_elf_ident (int ignore ATTRIBUTE_UNUSED
)
1535 static segT comment_section
;
1536 segT old_section
= now_seg
;
1537 int old_subsection
= now_subseg
;
1539 #ifdef md_flush_pending_output
1540 md_flush_pending_output ();
1543 if (!comment_section
)
1546 comment_section
= subseg_new (".comment", 0);
1547 bfd_set_section_flags (stdoutput
, comment_section
,
1548 SEC_READONLY
| SEC_HAS_CONTENTS
);
1553 subseg_set (comment_section
, 0);
1555 subseg_set (old_section
, old_subsection
);
1558 #ifdef INIT_STAB_SECTION
1560 /* The first entry in a .stabs section is special. */
1563 obj_elf_init_stab_section (segT seg
)
1568 unsigned int stroff
;
1570 /* Force the section to align to a longword boundary. Without this,
1571 UnixWare ar crashes. */
1572 bfd_set_section_alignment (stdoutput
, seg
, 2);
1574 /* Make space for this first symbol. */
1578 as_where (&file
, NULL
);
1579 stabstr_name
= xmalloc (strlen (segment_name (seg
)) + 4);
1580 strcpy (stabstr_name
, segment_name (seg
));
1581 strcat (stabstr_name
, "str");
1582 stroff
= get_stab_string_offset (file
, stabstr_name
);
1584 md_number_to_chars (p
, stroff
, 4);
1585 seg_info (seg
)->stabu
.p
= p
;
1590 /* Fill in the counts in the first entry in a .stabs section. */
1593 adjust_stab_sections (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
1600 if (strncmp (".stab", sec
->name
, 5))
1602 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1605 name
= alloca (strlen (sec
->name
) + 4);
1606 strcpy (name
, sec
->name
);
1607 strcat (name
, "str");
1608 strsec
= bfd_get_section_by_name (abfd
, name
);
1610 strsz
= bfd_section_size (abfd
, strsec
);
1613 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1615 p
= seg_info (sec
)->stabu
.p
;
1618 bfd_h_put_16 (abfd
, nsyms
, p
+ 6);
1619 bfd_h_put_32 (abfd
, strsz
, p
+ 8);
1622 #ifdef NEED_ECOFF_DEBUG
1624 /* This function is called by the ECOFF code. It is supposed to
1625 record the external symbol information so that the backend can
1626 write it out correctly. The ELF backend doesn't actually handle
1627 this at the moment, so we do it ourselves. We save the information
1631 elf_ecoff_set_ext (symbolS
*sym
, struct ecoff_extr
*ext
)
1633 symbol_get_bfdsym (sym
)->udata
.p
= ext
;
1636 /* This function is called by bfd_ecoff_debug_externals. It is
1637 supposed to *EXT to the external symbol information, and return
1638 whether the symbol should be used at all. */
1641 elf_get_extr (asymbol
*sym
, EXTR
*ext
)
1643 if (sym
->udata
.p
== NULL
)
1645 *ext
= *(EXTR
*) sym
->udata
.p
;
1649 /* This function is called by bfd_ecoff_debug_externals. It has
1650 nothing to do for ELF. */
1653 elf_set_index (asymbol
*sym ATTRIBUTE_UNUSED
,
1654 bfd_size_type indx ATTRIBUTE_UNUSED
)
1658 #endif /* NEED_ECOFF_DEBUG */
1661 elf_frob_symbol (symbolS
*symp
, int *puntp
)
1663 struct elf_obj_sy
*sy_obj
;
1665 #ifdef NEED_ECOFF_DEBUG
1666 if (ECOFF_DEBUGGING
)
1667 ecoff_frob_symbol (symp
);
1670 sy_obj
= symbol_get_obj (symp
);
1672 if (sy_obj
->size
!= NULL
)
1674 switch (sy_obj
->size
->X_op
)
1678 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1679 + sy_obj
->size
->X_add_number
1680 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1684 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1685 + sy_obj
->size
->X_add_number
));
1688 as_bad (_(".size expression too complicated to fix up"));
1691 free (sy_obj
->size
);
1692 sy_obj
->size
= NULL
;
1695 if (sy_obj
->versioned_name
!= NULL
)
1699 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1702 /* This symbol was given a new name with the .symver directive.
1704 If this is an external reference, just rename the symbol to
1705 include the version string. This will make the relocs be
1706 against the correct versioned symbol.
1708 If this is a definition, add an alias. FIXME: Using an alias
1709 will permit the debugging information to refer to the right
1710 symbol. However, it's not clear whether it is the best
1713 if (! S_IS_DEFINED (symp
))
1715 /* Verify that the name isn't using the @@ syntax--this is
1716 reserved for definitions of the default version to link
1718 if (p
[1] == ELF_VER_CHR
)
1720 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1721 sy_obj
->versioned_name
);
1724 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1728 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1732 /* The @@@ syntax is a special case. It renames the
1733 symbol name to versioned_name with one `@' removed. */
1734 l
= strlen (&p
[3]) + 1;
1735 memmove (&p
[2], &p
[3], l
);
1736 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1742 /* FIXME: Creating a new symbol here is risky. We're
1743 in the final loop over the symbol table. We can
1744 get away with it only because the symbol goes to
1745 the end of the list, where the loop will still see
1746 it. It would probably be better to do this in
1747 obj_frob_file_before_adjust. */
1749 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1751 /* Now we act as though we saw symp2 = sym. */
1753 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1755 /* Subtracting out the frag address here is a hack
1756 because we are in the middle of the final loop. */
1759 - symbol_get_frag (symp
)->fr_address
));
1761 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1763 /* This will copy over the size information. */
1764 copy_symbol_attributes (symp2
, symp
);
1766 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
1768 if (S_IS_WEAK (symp
))
1771 if (S_IS_EXTERNAL (symp
))
1772 S_SET_EXTERNAL (symp2
);
1777 /* Double check weak symbols. */
1778 if (S_IS_WEAK (symp
))
1780 if (S_IS_COMMON (symp
))
1781 as_bad (_("symbol `%s' can not be both weak and common"),
1786 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1787 any undefined non-function symbol to STT_OBJECT. We try to be
1788 compatible, since newer Irix 5 and 6 linkers care. However, we
1789 only set undefined symbols to be STT_OBJECT if we are on Irix,
1790 because that is the only time gcc will generate the necessary
1791 .global directives to mark functions. */
1793 if (S_IS_COMMON (symp
))
1794 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1796 if (strstr (TARGET_OS
, "irix") != NULL
1797 && ! S_IS_DEFINED (symp
)
1798 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1799 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1803 /* If TC_PPC is defined, we used to force the type of a symbol to be
1804 BSF_OBJECT if it was otherwise unset. This was required by some
1805 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1806 that this is no longer needed, so it is now commented out. */
1807 if ((symbol_get_bfdsym (symp
)->flags
1808 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1809 && S_IS_DEFINED (symp
))
1810 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1816 asection
**head
; /* Section lists. */
1817 unsigned int *elt_count
; /* Number of sections in each list. */
1818 unsigned int num_group
; /* Number of lists. */
1821 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1822 add it to a list of sections belonging to the group. INF is a
1823 pointer to a struct group_list, which is where we store the head of
1827 build_group_lists (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *inf
)
1829 struct group_list
*list
= inf
;
1830 const char *group_name
= elf_group_name (sec
);
1833 if (group_name
== NULL
)
1836 /* If this group already has a list, add the section to the head of
1838 for (i
= 0; i
< list
->num_group
; i
++)
1840 if (strcmp (group_name
, elf_group_name (list
->head
[i
])) == 0)
1842 elf_next_in_group (sec
) = list
->head
[i
];
1843 list
->head
[i
] = sec
;
1844 list
->elt_count
[i
] += 1;
1849 /* New group. Make the arrays bigger in chunks to minimize calls to
1851 i
= list
->num_group
;
1854 unsigned int newsize
= i
+ 128;
1855 list
->head
= xrealloc (list
->head
, newsize
* sizeof (*list
->head
));
1856 list
->elt_count
= xrealloc (list
->elt_count
,
1857 newsize
* sizeof (*list
->elt_count
));
1859 list
->head
[i
] = sec
;
1860 list
->elt_count
[i
] = 1;
1861 list
->num_group
+= 1;
1865 elf_frob_file (void)
1867 struct group_list list
;
1870 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, NULL
);
1872 /* Go find section groups. */
1875 list
.elt_count
= NULL
;
1876 bfd_map_over_sections (stdoutput
, build_group_lists
, &list
);
1878 /* Make the SHT_GROUP sections that describe each section group. We
1879 can't set up the section contents here yet, because elf section
1880 indices have yet to be calculated. elf.c:set_group_contents does
1881 the rest of the work. */
1882 for (i
= 0; i
< list
.num_group
; i
++)
1884 const char *group_name
= elf_group_name (list
.head
[i
]);
1885 const char *sec_name
;
1892 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
1893 for (s
= list
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
1894 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
1896 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1897 if (s
!= list
.head
[i
])
1899 as_warn (_("assuming all members of group `%s' are COMDAT"),
1905 sec_name
= group_name
;
1906 sy
= symbol_find_exact (group_name
);
1909 && (sy
== symbol_lastP
1910 || (sy
->sy_next
!= NULL
1911 && sy
->sy_next
->sy_previous
== sy
)))
1914 sec_name
= ".group";
1916 s
= subseg_force_new (sec_name
, 0);
1918 || !bfd_set_section_flags (stdoutput
, s
, flags
)
1919 || !bfd_set_section_alignment (stdoutput
, s
, 2))
1921 as_fatal (_("can't create group: %s"),
1922 bfd_errmsg (bfd_get_error ()));
1924 elf_section_type (s
) = SHT_GROUP
;
1926 /* Pass a pointer to the first section in this group. */
1927 elf_next_in_group (s
) = list
.head
[i
];
1929 elf_group_id (s
) = sy
->bsym
;
1931 size
= 4 * (list
.elt_count
[i
] + 1);
1932 bfd_set_section_size (stdoutput
, s
, size
);
1933 s
->contents
= frag_more (size
);
1934 frag_now
->fr_fix
= frag_now_fix_octets ();
1937 #ifdef elf_tc_final_processing
1938 elf_tc_final_processing ();
1942 /* It removes any unneeded versioned symbols from the symbol table. */
1945 elf_frob_file_before_adjust (void)
1951 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1952 if (!S_IS_DEFINED (symp
))
1954 if (symbol_get_obj (symp
)->versioned_name
)
1958 /* The @@@ syntax is a special case. If the symbol is
1959 not defined, 2 `@'s will be removed from the
1962 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1965 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1967 size_t l
= strlen (&p
[3]) + 1;
1968 memmove (&p
[1], &p
[3], l
);
1970 if (symbol_used_p (symp
) == 0
1971 && symbol_used_in_reloc_p (symp
) == 0)
1972 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1975 /* If there was .weak foo, but foo was neither defined nor
1976 used anywhere, remove it. */
1978 else if (S_IS_WEAK (symp
)
1979 && symbol_used_p (symp
) == 0
1980 && symbol_used_in_reloc_p (symp
) == 0)
1981 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1986 /* It is required that we let write_relocs have the opportunity to
1987 optimize away fixups before output has begun, since it is possible
1988 to eliminate all fixups for a section and thus we never should
1989 have generated the relocation section. */
1992 elf_frob_file_after_relocs (void)
1994 #ifdef NEED_ECOFF_DEBUG
1995 if (ECOFF_DEBUGGING
)
1996 /* Generate the ECOFF debugging information. */
1998 const struct ecoff_debug_swap
*debug_swap
;
1999 struct ecoff_debug_info debug
;
2004 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2005 know (debug_swap
!= NULL
);
2006 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2008 /* Set up the pointers in debug. */
2009 #define SET(ptr, offset, type) \
2010 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2012 SET (line
, cbLineOffset
, unsigned char *);
2013 SET (external_dnr
, cbDnOffset
, void *);
2014 SET (external_pdr
, cbPdOffset
, void *);
2015 SET (external_sym
, cbSymOffset
, void *);
2016 SET (external_opt
, cbOptOffset
, void *);
2017 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2018 SET (ss
, cbSsOffset
, char *);
2019 SET (external_fdr
, cbFdOffset
, void *);
2020 SET (external_rfd
, cbRfdOffset
, void *);
2021 /* ssext and external_ext are set up just below. */
2025 /* Set up the external symbols. */
2026 debug
.ssext
= debug
.ssext_end
= NULL
;
2027 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2028 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2029 elf_get_extr
, elf_set_index
))
2030 as_fatal (_("failed to set up debugging information: %s"),
2031 bfd_errmsg (bfd_get_error ()));
2033 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2034 assert (sec
!= NULL
);
2036 know (!stdoutput
->output_has_begun
);
2038 /* We set the size of the section, call bfd_set_section_contents
2039 to force the ELF backend to allocate a file position, and then
2040 write out the data. FIXME: Is this really the best way to do
2042 bfd_set_section_size
2043 (stdoutput
, sec
, bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
));
2045 /* Pass BUF to bfd_set_section_contents because this will
2046 eventually become a call to fwrite, and ISO C prohibits
2047 passing a NULL pointer to a stdio function even if the
2048 pointer will not be used. */
2049 if (! bfd_set_section_contents (stdoutput
, sec
, buf
, 0, 0))
2050 as_fatal (_("can't start writing .mdebug section: %s"),
2051 bfd_errmsg (bfd_get_error ()));
2053 know (stdoutput
->output_has_begun
);
2054 know (sec
->filepos
!= 0);
2056 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2058 as_fatal (_("could not write .mdebug section: %s"),
2059 bfd_errmsg (bfd_get_error ()));
2061 #endif /* NEED_ECOFF_DEBUG */
2066 /* Heavily plagiarized from obj_elf_version. The idea is to emit the
2067 SCO specific identifier in the .notes section to satisfy the SCO
2070 This looks more complicated than it really is. As opposed to the
2071 "obvious" solution, this should handle the cross dev cases
2072 correctly. (i.e, hosting on a 64 bit big endian processor, but
2073 generating SCO Elf code) Efficiency isn't a concern, as there
2074 should be exactly one of these sections per object module.
2076 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2079 int_32 namesz = 4 ; Name size
2080 int_32 descsz = 12 ; Descriptive information
2082 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2083 int_32 version = (major ver # << 16) | version of tools ;
2084 int_32 source = (tool_id << 16 ) | 1 ;
2085 int_32 info = 0 ; These are set by the SCO tools, but we
2086 don't know enough about the source
2087 environment to set them. SCO ld currently
2088 ignores them, and recommends we set them
2091 #define SCO_MAJOR_VERSION 0x1
2092 #define SCO_MINOR_VERSION 0x1
2102 asection
*seg
= now_seg
;
2103 subsegT subseg
= now_subseg
;
2104 Elf_Internal_Note i_note
;
2105 Elf_External_Note e_note
;
2106 asection
*note_secp
= NULL
;
2109 /* create the .note section */
2111 note_secp
= subseg_new (".note", 0);
2112 bfd_set_section_flags (stdoutput
,
2114 SEC_HAS_CONTENTS
| SEC_READONLY
);
2116 /* process the version string */
2119 i_note
.descsz
= 12; /* 12 descriptive bytes */
2120 i_note
.type
= NT_VERSION
; /* Contains a version string */
2122 p
= frag_more (sizeof (i_note
.namesz
));
2123 md_number_to_chars (p
, i_note
.namesz
, 4);
2125 p
= frag_more (sizeof (i_note
.descsz
));
2126 md_number_to_chars (p
, i_note
.descsz
, 4);
2128 p
= frag_more (sizeof (i_note
.type
));
2129 md_number_to_chars (p
, i_note
.type
, 4);
2134 /* Note: this is the version number of the ELF we're representing */
2136 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2138 /* Here, we pick a magic number for ourselves (yes, I "registered"
2139 it with SCO. The bottom bit shows that we are compat with the
2142 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2144 /* If we knew (or cared) what the source language options were, we'd
2145 fill them in here. SCO has given us permission to ignore these
2146 and just set them to zero. */
2148 md_number_to_chars (p
, 0x0000, 4);
2150 frag_align (2, 0, 0);
2152 /* We probably can't restore the current segment, for there likely
2155 subseg_set (seg
, subseg
);
2159 #endif /* SCO_ELF */
2162 elf_separate_stab_sections (void)
2164 #ifdef NEED_ECOFF_DEBUG
2165 return (!ECOFF_DEBUGGING
);
2172 elf_init_stab_section (segT seg
)
2174 #ifdef NEED_ECOFF_DEBUG
2175 if (!ECOFF_DEBUGGING
)
2177 obj_elf_init_stab_section (seg
);
2180 const struct format_ops elf_format_ops
=
2182 bfd_target_elf_flavour
,
2183 0, /* dfl_leading_underscore */
2184 1, /* emit_section_symbols */
2189 elf_frob_file_before_adjust
,
2190 0, /* obj_frob_file_before_fix */
2191 elf_frob_file_after_relocs
,
2192 elf_s_get_size
, elf_s_set_size
,
2193 elf_s_get_align
, elf_s_set_align
,
2200 elf_copy_symbol_attributes
,
2201 #ifdef NEED_ECOFF_DEBUG
2202 ecoff_generate_asm_lineno
,
2205 0, /* generate_asm_lineno */
2206 0, /* process_stab */
2208 elf_separate_stab_sections
,
2209 elf_init_stab_section
,
2210 elf_sec_sym_ok_for_reloc
,
2212 #ifdef NEED_ECOFF_DEBUG
2215 0, /* ecoff_set_ext */
2217 elf_obj_read_begin_hook
,
2218 elf_obj_symbol_new_hook