1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 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"
28 #ifndef ECOFF_DEBUGGING
29 #define ECOFF_DEBUGGING 0
31 #define NEED_ECOFF_DEBUG
34 #ifdef NEED_ECOFF_DEBUG
39 #include "elf/alpha.h"
54 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
55 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
56 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
57 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
58 static void elf_s_set_other
PARAMS ((symbolS
*, int));
59 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
60 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
61 static void build_group_lists
PARAMS ((bfd
*, asection
*, PTR
));
62 static int elf_separate_stab_sections
PARAMS ((void));
63 static void elf_init_stab_section
PARAMS ((segT
));
65 #ifdef NEED_ECOFF_DEBUG
66 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
67 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
70 static void obj_elf_line
PARAMS ((int));
71 void obj_elf_version
PARAMS ((int));
72 static void obj_elf_size
PARAMS ((int));
73 static void obj_elf_type
PARAMS ((int));
74 static void obj_elf_ident
PARAMS ((int));
75 static void obj_elf_weak
PARAMS ((int));
76 static void obj_elf_local
PARAMS ((int));
77 static void obj_elf_visibility
PARAMS ((int));
78 static void obj_elf_change_section
79 PARAMS ((const char *, int, int, int, const char *, int));
80 static int obj_elf_parse_section_letters
PARAMS ((char *, size_t));
81 static int obj_elf_section_word
PARAMS ((char *, size_t));
82 static char *obj_elf_section_name
PARAMS ((void));
83 static int obj_elf_section_type
PARAMS ((char *, size_t));
84 static void obj_elf_symver
PARAMS ((int));
85 static void obj_elf_subsection
PARAMS ((int));
86 static void obj_elf_popsection
PARAMS ((int));
88 static const pseudo_typeS elf_pseudo_table
[] =
90 {"comm", obj_elf_common
, 0},
91 {"common", obj_elf_common
, 1},
92 {"ident", obj_elf_ident
, 0},
93 {"local", obj_elf_local
, 0},
94 {"previous", obj_elf_previous
, 0},
95 {"section", obj_elf_section
, 0},
96 {"section.s", obj_elf_section
, 0},
97 {"sect", obj_elf_section
, 0},
98 {"sect.s", obj_elf_section
, 0},
99 {"pushsection", obj_elf_section
, 1},
100 {"popsection", obj_elf_popsection
, 0},
101 {"size", obj_elf_size
, 0},
102 {"type", obj_elf_type
, 0},
103 {"version", obj_elf_version
, 0},
104 {"weak", obj_elf_weak
, 0},
106 /* These define symbol visibility. */
107 {"internal", obj_elf_visibility
, STV_INTERNAL
},
108 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
109 {"protected", obj_elf_visibility
, STV_PROTECTED
},
111 /* These are used for stabs-in-elf configurations. */
112 {"line", obj_elf_line
, 0},
114 /* This is a GNU extension to handle symbol versions. */
115 {"symver", obj_elf_symver
, 0},
117 /* A GNU extension to change subsection only. */
118 {"subsection", obj_elf_subsection
, 0},
120 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
121 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
122 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
124 /* These are used for dwarf. */
129 /* We need to trap the section changing calls to handle .previous. */
130 {"data", obj_elf_data
, 0},
131 {"text", obj_elf_text
, 0},
137 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
139 #ifdef NEED_ECOFF_DEBUG
140 /* COFF style debugging information for ECOFF. .ln is not used; .loc
142 { "def", ecoff_directive_def
, 0 },
143 { "dim", ecoff_directive_dim
, 0 },
144 { "endef", ecoff_directive_endef
, 0 },
145 { "file", ecoff_directive_file
, 0 },
146 { "scl", ecoff_directive_scl
, 0 },
147 { "tag", ecoff_directive_tag
, 0 },
148 { "val", ecoff_directive_val
, 0 },
150 /* COFF debugging requires pseudo-ops .size and .type, but ELF
151 already has meanings for those. We use .esize and .etype
152 instead. These are only generated by gcc anyhow. */
153 { "esize", ecoff_directive_size
, 0 },
154 { "etype", ecoff_directive_type
, 0 },
156 /* ECOFF specific debugging information. */
157 { "begin", ecoff_directive_begin
, 0 },
158 { "bend", ecoff_directive_bend
, 0 },
159 { "end", ecoff_directive_end
, 0 },
160 { "ent", ecoff_directive_ent
, 0 },
161 { "fmask", ecoff_directive_fmask
, 0 },
162 { "frame", ecoff_directive_frame
, 0 },
163 { "loc", ecoff_directive_loc
, 0 },
164 { "mask", ecoff_directive_mask
, 0 },
166 /* Other ECOFF directives. */
167 { "extern", ecoff_directive_extern
, 0 },
169 /* These are used on Irix. I don't know how to implement them. */
170 { "alias", s_ignore
, 0 },
171 { "bgnb", s_ignore
, 0 },
172 { "endb", s_ignore
, 0 },
173 { "lab", s_ignore
, 0 },
174 { "noalias", s_ignore
, 0 },
175 { "verstamp", s_ignore
, 0 },
176 { "vreg", s_ignore
, 0 },
179 {NULL
, NULL
, 0} /* end sentinel */
183 #include "aout/aout64.h"
185 /* This is called when the assembler starts. */
190 /* Add symbols for the known sections to the symbol table. */
191 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
192 TEXT_SECTION_NAME
)));
193 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
194 DATA_SECTION_NAME
)));
195 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
202 pop_insert (elf_pseudo_table
);
204 pop_insert (ecoff_debug_pseudo_table
);
211 return S_GET_SIZE (sym
);
215 elf_s_set_size (sym
, sz
)
219 S_SET_SIZE (sym
, sz
);
223 elf_s_get_align (sym
)
226 return S_GET_ALIGN (sym
);
230 elf_s_set_align (sym
, align
)
234 S_SET_ALIGN (sym
, align
);
238 elf_s_get_other (sym
)
241 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
245 elf_s_set_other (sym
, other
)
249 S_SET_OTHER (sym
, other
);
253 elf_sec_sym_ok_for_reloc (sec
)
256 return obj_sec_sym_ok_for_reloc (sec
);
265 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
266 symbol_set_frag (sym
, &zero_address_frag
);
267 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
269 if (symbol_rootP
!= sym
)
271 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
272 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
274 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
278 #ifdef NEED_ECOFF_DEBUG
284 obj_elf_common (is_common
)
294 if (flag_mri
&& is_common
)
300 name
= input_line_pointer
;
301 c
= get_symbol_end ();
302 /* just after name is now '\0' */
303 p
= input_line_pointer
;
306 if (*input_line_pointer
!= ',')
308 as_bad (_("expected comma after symbol-name"));
309 ignore_rest_of_line ();
312 input_line_pointer
++; /* skip ',' */
313 if ((temp
= get_absolute_expression ()) < 0)
315 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
316 ignore_rest_of_line ();
321 symbolP
= symbol_find_or_make (name
);
323 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
325 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP
));
326 ignore_rest_of_line ();
329 if (S_GET_VALUE (symbolP
) != 0)
331 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
333 as_warn (_("length of .comm \"%s\" is already %ld; not changed to %d"),
334 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
337 know (symbolP
->sy_frag
== &zero_address_frag
);
338 if (*input_line_pointer
!= ',')
343 input_line_pointer
++;
346 if (! have_align
|| *input_line_pointer
!= '"')
352 temp
= get_absolute_expression ();
356 as_warn (_("common alignment negative; 0 assumed"));
359 if (symbol_get_obj (symbolP
)->local
)
368 old_subsec
= now_subseg
;
371 /* convert to a power of 2 alignment */
372 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
375 as_bad (_("common alignment not a power of 2"));
376 ignore_rest_of_line ();
382 record_alignment (bss_section
, align
);
383 subseg_set (bss_section
, 0);
385 frag_align (align
, 0, 0);
386 if (S_GET_SEGMENT (symbolP
) == bss_section
)
387 symbol_get_frag (symbolP
)->fr_symbol
= 0;
388 symbol_set_frag (symbolP
, frag_now
);
389 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
390 (offsetT
) size
, (char *) 0);
392 S_SET_SIZE (symbolP
, size
);
393 S_SET_SEGMENT (symbolP
, bss_section
);
394 S_CLEAR_EXTERNAL (symbolP
);
395 subseg_set (old_sec
, old_subsec
);
400 S_SET_VALUE (symbolP
, (valueT
) size
);
401 S_SET_ALIGN (symbolP
, temp
);
402 S_SET_EXTERNAL (symbolP
);
403 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
408 input_line_pointer
++;
409 /* @@ Some use the dot, some don't. Can we get some consistency?? */
410 if (*input_line_pointer
== '.')
411 input_line_pointer
++;
412 /* @@ Some say data, some say bss. */
413 if (strncmp (input_line_pointer
, "bss\"", 4)
414 && strncmp (input_line_pointer
, "data\"", 5))
416 while (*--input_line_pointer
!= '"')
418 input_line_pointer
--;
419 goto bad_common_segment
;
421 while (*input_line_pointer
++ != '"')
423 goto allocate_common
;
426 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
428 demand_empty_rest_of_line ();
433 p
= input_line_pointer
;
434 while (*p
&& *p
!= '\n')
438 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
440 input_line_pointer
= p
;
441 ignore_rest_of_line ();
447 obj_elf_local (ignore
)
448 int ignore ATTRIBUTE_UNUSED
;
456 name
= input_line_pointer
;
457 c
= get_symbol_end ();
458 symbolP
= symbol_find_or_make (name
);
459 *input_line_pointer
= c
;
461 S_CLEAR_EXTERNAL (symbolP
);
462 symbol_get_obj (symbolP
)->local
= 1;
465 input_line_pointer
++;
467 if (*input_line_pointer
== '\n')
472 demand_empty_rest_of_line ();
476 obj_elf_weak (ignore
)
477 int ignore ATTRIBUTE_UNUSED
;
485 name
= input_line_pointer
;
486 c
= get_symbol_end ();
487 symbolP
= symbol_find_or_make (name
);
488 *input_line_pointer
= c
;
490 S_SET_WEAK (symbolP
);
491 symbol_get_obj (symbolP
)->local
= 1;
494 input_line_pointer
++;
496 if (*input_line_pointer
== '\n')
501 demand_empty_rest_of_line ();
505 obj_elf_visibility (visibility
)
512 elf_symbol_type
*elfsym
;
516 name
= input_line_pointer
;
517 c
= get_symbol_end ();
518 symbolP
= symbol_find_or_make (name
);
519 *input_line_pointer
= c
;
523 bfdsym
= symbol_get_bfdsym (symbolP
);
524 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
528 elfsym
->internal_elf_sym
.st_other
= visibility
;
532 input_line_pointer
++;
536 if (*input_line_pointer
== '\n')
542 demand_empty_rest_of_line ();
545 static segT previous_section
;
546 static int previous_subsection
;
550 struct section_stack
*next
;
552 int subseg
, prev_subseg
;
555 static struct section_stack
*section_stack
;
557 /* Handle the .section pseudo-op. This code supports two different
560 The first is found on Solaris, and looks like
561 .section ".sec1",#alloc,#execinstr,#write
562 Here the names after '#' are the SHF_* flags to turn on for the
563 section. I'm not sure how it determines the SHT_* type (BFD
564 doesn't really give us control over the type, anyhow).
566 The second format is found on UnixWare, and probably most SVR4
567 machines, and looks like
568 .section .sec1,"a",@progbits
569 The quoted string may contain any combination of a, w, x, and
570 represents the SHF_* flags to turn on for the section. The string
571 beginning with '@' can be progbits or nobits. There should be
572 other possibilities, but I don't know what they are. In any case,
573 BFD doesn't really let us set the section type. */
575 /* Certain named sections have particular defined types, listed on p.
577 struct special_section
584 static struct special_section
const special_sections
[] =
586 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
587 { ".comment", SHT_PROGBITS
, 0 },
588 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
589 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
590 { ".debug", SHT_PROGBITS
, 0 },
591 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
592 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
593 { ".line", SHT_PROGBITS
, 0 },
594 { ".note", SHT_NOTE
, 0 },
595 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
596 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
597 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
599 #ifdef ELF_TC_SPECIAL_SECTIONS
600 ELF_TC_SPECIAL_SECTIONS
604 /* The following section names are special, but they can not
605 reasonably appear in assembler code. Some of the attributes are
606 processor dependent. */
607 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
608 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
609 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
610 { ".got", SHT_PROGBITS
, 0 },
611 { ".hash", SHT_HASH
, SHF_ALLOC
},
612 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
613 { ".plt", SHT_PROGBITS
, 0 },
614 { ".shstrtab",SHT_STRTAB
, 0 },
615 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
616 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
623 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, push
)
628 const char *group_name
;
636 #ifdef md_flush_pending_output
637 md_flush_pending_output ();
640 /* Switch to the section, creating it if necessary. */
643 struct section_stack
*elt
;
644 elt
= xmalloc (sizeof (struct section_stack
));
645 elt
->next
= section_stack
;
647 elt
->prev_seg
= previous_section
;
648 elt
->subseg
= now_subseg
;
649 elt
->prev_subseg
= previous_subsection
;
652 previous_section
= now_seg
;
653 previous_subsection
= now_subseg
;
655 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
656 sec
= subseg_new (name
, 0);
658 /* See if this is one of the special sections. */
659 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
660 if (strcmp (name
, special_sections
[i
].name
) == 0)
662 if (type
== SHT_NULL
)
663 type
= special_sections
[i
].type
;
664 else if (type
!= special_sections
[i
].type
)
668 as_warn (_("setting incorrect section type for %s"), name
);
672 as_warn (_("ignoring incorrect section type for %s"), name
);
673 type
= special_sections
[i
].type
;
676 if ((attr
&~ special_sections
[i
].attributes
) != 0
679 /* As a GNU extension, we permit a .note section to be
680 allocatable. If the linker sees an allocateable .note
681 section, it will create a PT_NOTE segment in the output
683 if (strcmp (name
, ".note") != 0
684 || attr
!= SHF_ALLOC
)
685 as_warn (_("setting incorrect section attributes for %s"),
688 attr
|= special_sections
[i
].attributes
;
692 /* Convert ELF type and flags to BFD flags. */
694 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
695 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
696 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
697 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
698 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
699 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0));
700 #ifdef md_elf_section_flags
701 flags
= md_elf_section_flags (flags
, attr
, type
);
708 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
709 if (type
== SHT_NOBITS
)
710 seg_info (sec
)->bss
= 1;
712 bfd_set_section_flags (stdoutput
, sec
, flags
);
713 if (flags
& SEC_MERGE
)
714 sec
->entsize
= entsize
;
715 elf_group_name (sec
) = group_name
;
717 /* Add a symbol for this section to the symbol table. */
718 secsym
= symbol_find (name
);
720 symbol_set_bfdsym (secsym
, sec
->symbol
);
722 symbol_table_insert (section_symbol (sec
));
726 /* If section attributes are specified the second time we see a
727 particular section, then check that they are the same as we
728 saw the first time. */
729 if ((old_sec
->flags
^ flags
)
730 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
731 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
))
732 as_warn (_("ignoring changed section attributes for %s"), name
);
733 else if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
734 as_warn (_("ignoring changed section entity size for %s"), name
);
735 else if ((attr
& SHF_GROUP
) != 0
736 && strcmp (elf_group_name (old_sec
), group_name
) != 0)
737 as_warn (_("ignoring new section group for %s"), name
);
740 #ifdef md_elf_section_change_hook
741 md_elf_section_change_hook ();
746 obj_elf_parse_section_letters (str
, len
)
763 attr
|= SHF_EXECINSTR
;
776 if (*(str
- 1) == 'a')
779 if (len
> 1 && str
[1] == 's')
788 char *bad_msg
= _("unrecognized .section attribute: want a,w,x,M,S,G");
789 #ifdef md_elf_section_letter
790 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
796 as_warn ("%s", bad_msg
);
809 obj_elf_section_word (str
, len
)
813 if (len
== 5 && strncmp (str
, "write", 5) == 0)
815 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
817 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
818 return SHF_EXECINSTR
;
820 #ifdef md_elf_section_word
822 int md_attr
= md_elf_section_word (str
, len
);
828 as_warn (_("unrecognized section attribute"));
833 obj_elf_section_type (str
, len
)
837 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
839 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
842 #ifdef md_elf_section_type
844 int md_type
= md_elf_section_type (str
, len
);
850 as_warn (_("unrecognized section type"));
854 /* Get name of section. */
856 obj_elf_section_name ()
861 if (*input_line_pointer
== '"')
865 name
= demand_copy_C_string (&dummy
);
868 ignore_rest_of_line ();
874 char *end
= input_line_pointer
;
876 while (0 == strchr ("\n\t,; ", *end
))
878 if (end
== input_line_pointer
)
880 as_warn (_("missing name"));
881 ignore_rest_of_line ();
885 name
= xmalloc (end
- input_line_pointer
+ 1);
886 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
887 name
[end
- input_line_pointer
] = '\0';
888 input_line_pointer
= end
;
895 obj_elf_section (push
)
898 char *name
, *group_name
, *beg
;
899 int type
, attr
, dummy
;
907 #ifdef md_flush_pending_output
908 md_flush_pending_output ();
911 previous_section
= now_seg
;
912 previous_subsection
= now_subseg
;
914 s_mri_sect (&mri_type
);
916 #ifdef md_elf_section_change_hook
917 md_elf_section_change_hook ();
922 #endif /* ! defined (TC_I370) */
924 name
= obj_elf_section_name ();
932 if (*input_line_pointer
== ',')
934 /* Skip the comma. */
935 ++input_line_pointer
;
938 if (*input_line_pointer
== '"')
940 beg
= demand_copy_C_string (&dummy
);
943 ignore_rest_of_line ();
946 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
949 if (*input_line_pointer
== ',')
952 char *save
= input_line_pointer
;
954 ++input_line_pointer
;
956 c
= *input_line_pointer
;
959 beg
= demand_copy_C_string (&dummy
);
962 ignore_rest_of_line ();
965 type
= obj_elf_section_type (beg
, strlen (beg
));
967 else if (c
== '@' || c
== '%')
969 beg
= ++input_line_pointer
;
970 c
= get_symbol_end ();
971 *input_line_pointer
= c
;
972 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
975 input_line_pointer
= save
;
979 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
981 ++input_line_pointer
;
983 entsize
= get_absolute_expression ();
987 as_warn (_("invalid merge entity size"));
992 else if ((attr
& SHF_MERGE
) != 0)
994 as_warn (_("entity size for SHF_MERGE not specified"));
998 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1000 ++input_line_pointer
;
1001 group_name
= obj_elf_section_name ();
1002 if (group_name
== NULL
)
1005 else if ((attr
& SHF_GROUP
) != 0)
1007 as_warn (_("group name for SHF_GROUP not specified"));
1018 if (*input_line_pointer
!= '#')
1020 as_warn (_("character following name is not '#'"));
1021 ignore_rest_of_line ();
1024 beg
= ++input_line_pointer
;
1025 c
= get_symbol_end ();
1026 *input_line_pointer
= c
;
1028 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
1032 while (*input_line_pointer
++ == ',');
1033 --input_line_pointer
;
1037 demand_empty_rest_of_line ();
1039 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, push
);
1042 /* Change to the .data section. */
1048 #ifdef md_flush_pending_output
1049 md_flush_pending_output ();
1052 previous_section
= now_seg
;
1053 previous_subsection
= now_subseg
;
1056 #ifdef md_elf_section_change_hook
1057 md_elf_section_change_hook ();
1061 /* Change to the .text section. */
1067 #ifdef md_flush_pending_output
1068 md_flush_pending_output ();
1071 previous_section
= now_seg
;
1072 previous_subsection
= now_subseg
;
1075 #ifdef md_elf_section_change_hook
1076 md_elf_section_change_hook ();
1081 obj_elf_subsection (ignore
)
1082 int ignore ATTRIBUTE_UNUSED
;
1086 #ifdef md_flush_pending_output
1087 md_flush_pending_output ();
1090 previous_section
= now_seg
;
1091 previous_subsection
= now_subseg
;
1093 temp
= get_absolute_expression ();
1094 subseg_set (now_seg
, (subsegT
) temp
);
1095 demand_empty_rest_of_line ();
1097 #ifdef md_elf_section_change_hook
1098 md_elf_section_change_hook ();
1102 /* This can be called from the processor backends if they change
1106 obj_elf_section_change_hook ()
1108 previous_section
= now_seg
;
1109 previous_subsection
= now_subseg
;
1113 obj_elf_previous (ignore
)
1114 int ignore ATTRIBUTE_UNUSED
;
1119 if (previous_section
== 0)
1121 as_warn (_(".previous without corresponding .section; ignored"));
1125 #ifdef md_flush_pending_output
1126 md_flush_pending_output ();
1129 new_section
= previous_section
;
1130 new_subsection
= previous_subsection
;
1131 previous_section
= now_seg
;
1132 previous_subsection
= now_subseg
;
1133 subseg_set (new_section
, new_subsection
);
1135 #ifdef md_elf_section_change_hook
1136 md_elf_section_change_hook ();
1141 obj_elf_popsection (xxx
)
1142 int xxx ATTRIBUTE_UNUSED
;
1144 struct section_stack
*top
= section_stack
;
1148 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1152 #ifdef md_flush_pending_output
1153 md_flush_pending_output ();
1156 section_stack
= top
->next
;
1157 previous_section
= top
->prev_seg
;
1158 previous_subsection
= top
->prev_subseg
;
1159 subseg_set (top
->seg
, top
->subseg
);
1162 #ifdef md_elf_section_change_hook
1163 md_elf_section_change_hook ();
1168 obj_elf_line (ignore
)
1169 int ignore ATTRIBUTE_UNUSED
;
1171 /* Assume delimiter is part of expression. BSD4.2 as fails with
1172 delightful bug, so we are not being incompatible here. */
1173 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1174 demand_empty_rest_of_line ();
1177 /* This handles the .symver pseudo-op, which is used to specify a
1178 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1179 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1180 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1181 with the same value as the symbol NAME. */
1184 obj_elf_symver (ignore
)
1185 int ignore ATTRIBUTE_UNUSED
;
1192 name
= input_line_pointer
;
1193 c
= get_symbol_end ();
1195 sym
= symbol_find_or_make (name
);
1197 *input_line_pointer
= c
;
1200 if (*input_line_pointer
!= ',')
1202 as_bad (_("expected comma after name in .symver"));
1203 ignore_rest_of_line ();
1207 ++input_line_pointer
;
1208 name
= input_line_pointer
;
1210 /* Temporarily include '@' in symbol names. */
1211 old_lexat
= lex_type
[(unsigned char) '@'];
1212 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1213 c
= get_symbol_end ();
1214 lex_type
[(unsigned char) '@'] = old_lexat
;
1216 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1218 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1220 *input_line_pointer
= c
;
1222 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1223 ELF_VER_CHR
) == NULL
)
1225 as_bad (_("missing version name in `%s' for symbol `%s'"),
1226 symbol_get_obj (sym
)->versioned_name
,
1228 ignore_rest_of_line ();
1234 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1236 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1237 name
, symbol_get_obj (sym
)->versioned_name
,
1239 ignore_rest_of_line ();
1243 *input_line_pointer
= c
;
1246 demand_empty_rest_of_line ();
1249 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1250 to the linker the hierarchy in which a particular table resides. The
1251 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1254 obj_elf_vtable_inherit (ignore
)
1255 int ignore ATTRIBUTE_UNUSED
;
1257 char *cname
, *pname
;
1258 symbolS
*csym
, *psym
;
1261 if (*input_line_pointer
== '#')
1262 ++input_line_pointer
;
1264 cname
= input_line_pointer
;
1265 c
= get_symbol_end ();
1266 csym
= symbol_find (cname
);
1268 /* GCFIXME: should check that we don't have two .vtable_inherits for
1269 the same child symbol. Also, we can currently only do this if the
1270 child symbol is already exists and is placed in a fragment. */
1272 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1274 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1279 *input_line_pointer
= c
;
1282 if (*input_line_pointer
!= ',')
1284 as_bad ("expected comma after name in .vtable_inherit");
1285 ignore_rest_of_line ();
1289 ++input_line_pointer
;
1292 if (*input_line_pointer
== '#')
1293 ++input_line_pointer
;
1295 if (input_line_pointer
[0] == '0'
1296 && (input_line_pointer
[1] == '\0'
1297 || ISSPACE (input_line_pointer
[1])))
1299 psym
= section_symbol (absolute_section
);
1300 ++input_line_pointer
;
1304 pname
= input_line_pointer
;
1305 c
= get_symbol_end ();
1306 psym
= symbol_find_or_make (pname
);
1307 *input_line_pointer
= c
;
1310 demand_empty_rest_of_line ();
1315 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1316 return fix_new (symbol_get_frag (csym
),
1317 symbol_get_value_expression (csym
)->X_add_number
,
1318 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1321 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1322 to the linker that a vtable slot was used. The syntax is
1323 ".vtable_entry tablename, offset". */
1326 obj_elf_vtable_entry (ignore
)
1327 int ignore ATTRIBUTE_UNUSED
;
1334 if (*input_line_pointer
== '#')
1335 ++input_line_pointer
;
1337 name
= input_line_pointer
;
1338 c
= get_symbol_end ();
1339 sym
= symbol_find_or_make (name
);
1340 *input_line_pointer
= c
;
1343 if (*input_line_pointer
!= ',')
1345 as_bad ("expected comma after name in .vtable_entry");
1346 ignore_rest_of_line ();
1350 ++input_line_pointer
;
1351 if (*input_line_pointer
== '#')
1352 ++input_line_pointer
;
1354 offset
= get_absolute_expression ();
1356 demand_empty_rest_of_line ();
1358 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1359 BFD_RELOC_VTABLE_ENTRY
);
1363 elf_obj_read_begin_hook ()
1365 #ifdef NEED_ECOFF_DEBUG
1366 if (ECOFF_DEBUGGING
)
1367 ecoff_read_begin_hook ();
1372 elf_obj_symbol_new_hook (symbolP
)
1375 struct elf_obj_sy
*sy_obj
;
1377 sy_obj
= symbol_get_obj (symbolP
);
1378 sy_obj
->size
= NULL
;
1379 sy_obj
->versioned_name
= NULL
;
1381 #ifdef NEED_ECOFF_DEBUG
1382 if (ECOFF_DEBUGGING
)
1383 ecoff_symbol_new_hook (symbolP
);
1387 /* When setting one symbol equal to another, by default we probably
1388 want them to have the same "size", whatever it means in the current
1392 elf_copy_symbol_attributes (dest
, src
)
1393 symbolS
*dest
, *src
;
1395 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1396 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1399 if (destelf
->size
== NULL
)
1401 (expressionS
*) xmalloc (sizeof (expressionS
));
1402 *destelf
->size
= *srcelf
->size
;
1406 if (destelf
->size
!= NULL
)
1407 free (destelf
->size
);
1408 destelf
->size
= NULL
;
1410 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1411 /* Don't copy visibility. */
1412 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1413 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1417 obj_elf_version (ignore
)
1418 int ignore ATTRIBUTE_UNUSED
;
1423 asection
*seg
= now_seg
;
1424 subsegT subseg
= now_subseg
;
1425 Elf_Internal_Note i_note
;
1426 Elf_External_Note e_note
;
1427 asection
*note_secp
= (asection
*) NULL
;
1431 if (*input_line_pointer
== '\"')
1433 ++input_line_pointer
; /* -> 1st char of string. */
1434 name
= input_line_pointer
;
1436 while (is_a_char (c
= next_char_of_string ()))
1438 c
= *input_line_pointer
;
1439 *input_line_pointer
= '\0';
1440 *(input_line_pointer
- 1) = '\0';
1441 *input_line_pointer
= c
;
1443 /* create the .note section */
1445 note_secp
= subseg_new (".note", 0);
1446 bfd_set_section_flags (stdoutput
,
1448 SEC_HAS_CONTENTS
| SEC_READONLY
);
1450 /* process the version string */
1452 len
= strlen (name
);
1454 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1455 i_note
.descsz
= 0; /* no description */
1456 i_note
.type
= NT_VERSION
;
1457 p
= frag_more (sizeof (e_note
.namesz
));
1458 md_number_to_chars (p
, (valueT
) i_note
.namesz
, sizeof (e_note
.namesz
));
1459 p
= frag_more (sizeof (e_note
.descsz
));
1460 md_number_to_chars (p
, (valueT
) i_note
.descsz
, sizeof (e_note
.descsz
));
1461 p
= frag_more (sizeof (e_note
.type
));
1462 md_number_to_chars (p
, (valueT
) i_note
.type
, sizeof (e_note
.type
));
1463 p
= frag_more (len
+ 1);
1466 frag_align (2, 0, 0);
1468 subseg_set (seg
, subseg
);
1472 as_bad (_("expected quoted string"));
1474 demand_empty_rest_of_line ();
1478 obj_elf_size (ignore
)
1479 int ignore ATTRIBUTE_UNUSED
;
1481 char *name
= input_line_pointer
;
1482 char c
= get_symbol_end ();
1487 p
= input_line_pointer
;
1490 if (*input_line_pointer
!= ',')
1493 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1495 ignore_rest_of_line ();
1498 input_line_pointer
++;
1500 if (exp
.X_op
== O_absent
)
1502 as_bad (_("missing expression in .size directive"));
1503 exp
.X_op
= O_constant
;
1504 exp
.X_add_number
= 0;
1507 sym
= symbol_find_or_make (name
);
1509 if (exp
.X_op
== O_constant
)
1511 S_SET_SIZE (sym
, exp
.X_add_number
);
1512 if (symbol_get_obj (sym
)->size
)
1514 xfree (symbol_get_obj (sym
)->size
);
1515 symbol_get_obj (sym
)->size
= NULL
;
1520 symbol_get_obj (sym
)->size
=
1521 (expressionS
*) xmalloc (sizeof (expressionS
));
1522 *symbol_get_obj (sym
)->size
= exp
;
1524 demand_empty_rest_of_line ();
1527 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1528 There are five syntaxes:
1530 The first (used on Solaris) is
1532 The second (used on UnixWare) is
1534 The third (reportedly to be used on Irix 6.0) is
1536 The fourth (used on NetBSD/Arm and Linux/ARM) is
1538 The fifth (used on SVR4/860) is
1539 .type SYM,"function"
1543 obj_elf_type (ignore
)
1544 int ignore ATTRIBUTE_UNUSED
;
1549 const char *typename
;
1551 elf_symbol_type
*elfsym
;
1553 name
= input_line_pointer
;
1554 c
= get_symbol_end ();
1555 sym
= symbol_find_or_make (name
);
1556 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1557 *input_line_pointer
= c
;
1560 if (*input_line_pointer
== ',')
1561 ++input_line_pointer
;
1564 if ( *input_line_pointer
== '#'
1565 || *input_line_pointer
== '@'
1566 || *input_line_pointer
== '"'
1567 || *input_line_pointer
== '%')
1568 ++input_line_pointer
;
1570 typename
= input_line_pointer
;
1571 c
= get_symbol_end ();
1574 if (strcmp (typename
, "function") == 0
1575 || strcmp (typename
, "STT_FUNC") == 0)
1576 type
= BSF_FUNCTION
;
1577 else if (strcmp (typename
, "object") == 0
1578 || strcmp (typename
, "STT_OBJECT") == 0)
1580 #ifdef md_elf_symbol_type
1581 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1585 as_bad (_("unrecognized symbol type \"%s\""), typename
);
1587 *input_line_pointer
= c
;
1589 if (*input_line_pointer
== '"')
1590 ++input_line_pointer
;
1592 elfsym
->symbol
.flags
|= type
;
1594 demand_empty_rest_of_line ();
1598 obj_elf_ident (ignore
)
1599 int ignore ATTRIBUTE_UNUSED
;
1601 static segT comment_section
;
1602 segT old_section
= now_seg
;
1603 int old_subsection
= now_subseg
;
1605 #ifdef md_flush_pending_output
1606 md_flush_pending_output ();
1609 if (!comment_section
)
1612 comment_section
= subseg_new (".comment", 0);
1613 bfd_set_section_flags (stdoutput
, comment_section
,
1614 SEC_READONLY
| SEC_HAS_CONTENTS
);
1619 subseg_set (comment_section
, 0);
1621 subseg_set (old_section
, old_subsection
);
1624 #ifdef INIT_STAB_SECTION
1626 /* The first entry in a .stabs section is special. */
1629 obj_elf_init_stab_section (seg
)
1635 unsigned int stroff
;
1637 /* Force the section to align to a longword boundary. Without this,
1638 UnixWare ar crashes. */
1639 bfd_set_section_alignment (stdoutput
, seg
, 2);
1641 /* Make space for this first symbol. */
1645 as_where (&file
, (unsigned int *) NULL
);
1646 stabstr_name
= (char *) xmalloc (strlen (segment_name (seg
)) + 4);
1647 strcpy (stabstr_name
, segment_name (seg
));
1648 strcat (stabstr_name
, "str");
1649 stroff
= get_stab_string_offset (file
, stabstr_name
);
1651 md_number_to_chars (p
, stroff
, 4);
1652 seg_info (seg
)->stabu
.p
= p
;
1657 /* Fill in the counts in the first entry in a .stabs section. */
1660 adjust_stab_sections (abfd
, sec
, xxx
)
1663 PTR xxx ATTRIBUTE_UNUSED
;
1670 if (strncmp (".stab", sec
->name
, 5))
1672 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1675 name
= (char *) alloca (strlen (sec
->name
) + 4);
1676 strcpy (name
, sec
->name
);
1677 strcat (name
, "str");
1678 strsec
= bfd_get_section_by_name (abfd
, name
);
1680 strsz
= bfd_section_size (abfd
, strsec
);
1683 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1685 p
= seg_info (sec
)->stabu
.p
;
1688 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1689 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1692 #ifdef NEED_ECOFF_DEBUG
1694 /* This function is called by the ECOFF code. It is supposed to
1695 record the external symbol information so that the backend can
1696 write it out correctly. The ELF backend doesn't actually handle
1697 this at the moment, so we do it ourselves. We save the information
1701 elf_ecoff_set_ext (sym
, ext
)
1703 struct ecoff_extr
*ext
;
1705 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1708 /* This function is called by bfd_ecoff_debug_externals. It is
1709 supposed to *EXT to the external symbol information, and return
1710 whether the symbol should be used at all. */
1713 elf_get_extr (sym
, ext
)
1717 if (sym
->udata
.p
== NULL
)
1719 *ext
= *(EXTR
*) sym
->udata
.p
;
1723 /* This function is called by bfd_ecoff_debug_externals. It has
1724 nothing to do for ELF. */
1728 elf_set_index (sym
, indx
)
1729 asymbol
*sym ATTRIBUTE_UNUSED
;
1730 bfd_size_type indx ATTRIBUTE_UNUSED
;
1734 #endif /* NEED_ECOFF_DEBUG */
1737 elf_frob_symbol (symp
, puntp
)
1741 struct elf_obj_sy
*sy_obj
;
1743 #ifdef NEED_ECOFF_DEBUG
1744 if (ECOFF_DEBUGGING
)
1745 ecoff_frob_symbol (symp
);
1748 sy_obj
= symbol_get_obj (symp
);
1750 if (sy_obj
->size
!= NULL
)
1752 switch (sy_obj
->size
->X_op
)
1756 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1757 + sy_obj
->size
->X_add_number
1758 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1762 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1763 + sy_obj
->size
->X_add_number
));
1766 as_bad (_(".size expression too complicated to fix up"));
1769 free (sy_obj
->size
);
1770 sy_obj
->size
= NULL
;
1773 if (sy_obj
->versioned_name
!= NULL
)
1777 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1780 /* This symbol was given a new name with the .symver directive.
1782 If this is an external reference, just rename the symbol to
1783 include the version string. This will make the relocs be
1784 against the correct versioned symbol.
1786 If this is a definition, add an alias. FIXME: Using an alias
1787 will permit the debugging information to refer to the right
1788 symbol. However, it's not clear whether it is the best
1791 if (! S_IS_DEFINED (symp
))
1793 /* Verify that the name isn't using the @@ syntax--this is
1794 reserved for definitions of the default version to link
1796 if (p
[1] == ELF_VER_CHR
)
1798 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1799 sy_obj
->versioned_name
);
1802 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1806 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1810 /* The @@@ syntax is a special case. It renames the
1811 symbol name to versioned_name with one `@' removed. */
1812 l
= strlen (&p
[3]) + 1;
1813 memmove (&p
[2], &p
[3], l
);
1814 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1820 /* FIXME: Creating a new symbol here is risky. We're
1821 in the final loop over the symbol table. We can
1822 get away with it only because the symbol goes to
1823 the end of the list, where the loop will still see
1824 it. It would probably be better to do this in
1825 obj_frob_file_before_adjust. */
1827 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1829 /* Now we act as though we saw symp2 = sym. */
1831 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1833 /* Subtracting out the frag address here is a hack
1834 because we are in the middle of the final loop. */
1837 - symbol_get_frag (symp
)->fr_address
));
1839 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1841 /* This will copy over the size information. */
1842 copy_symbol_attributes (symp2
, symp
);
1844 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
1846 if (S_IS_WEAK (symp
))
1849 if (S_IS_EXTERNAL (symp
))
1850 S_SET_EXTERNAL (symp2
);
1855 /* Double check weak symbols. */
1856 if (S_IS_WEAK (symp
))
1858 if (S_IS_COMMON (symp
))
1859 as_bad (_("symbol `%s' can not be both weak and common"),
1864 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1865 any undefined non-function symbol to STT_OBJECT. We try to be
1866 compatible, since newer Irix 5 and 6 linkers care. However, we
1867 only set undefined symbols to be STT_OBJECT if we are on Irix,
1868 because that is the only time gcc will generate the necessary
1869 .global directives to mark functions. */
1871 if (S_IS_COMMON (symp
))
1872 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1874 if (strstr (TARGET_OS
, "irix") != NULL
1875 && ! S_IS_DEFINED (symp
)
1876 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1877 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1881 /* If TC_PPC is defined, we used to force the type of a symbol to be
1882 BSF_OBJECT if it was otherwise unset. This was required by some
1883 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1884 that this is no longer needed, so it is now commented out. */
1885 if ((symbol_get_bfdsym (symp
)->flags
1886 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1887 && S_IS_DEFINED (symp
))
1888 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1894 asection
**head
; /* Section lists. */
1895 unsigned int *elt_count
; /* Number of sections in each list. */
1896 unsigned int num_group
; /* Number of lists. */
1899 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1900 add it to a list of sections belonging to the group. INF is a
1901 pointer to a struct group_list, which is where we store the head of
1905 build_group_lists (abfd
, sec
, inf
)
1906 bfd
*abfd ATTRIBUTE_UNUSED
;
1910 struct group_list
*list
= (struct group_list
*) inf
;
1911 const char *group_name
= elf_group_name (sec
);
1914 if (group_name
== NULL
)
1917 /* If this group already has a list, add the section to the head of
1919 for (i
= 0; i
< list
->num_group
; i
++)
1921 if (strcmp (group_name
, elf_group_name (list
->head
[i
])) == 0)
1923 elf_next_in_group (sec
) = list
->head
[i
];
1924 list
->head
[i
] = sec
;
1925 list
->elt_count
[i
] += 1;
1930 /* New group. Make the arrays bigger in chunks to minimize calls to
1932 i
= list
->num_group
;
1935 unsigned int newsize
= i
+ 128;
1936 list
->head
= xrealloc (list
->head
, newsize
* sizeof (*list
->head
));
1937 list
->elt_count
= xrealloc (list
->elt_count
,
1938 newsize
* sizeof (*list
->elt_count
));
1940 list
->head
[i
] = sec
;
1941 list
->elt_count
[i
] = 1;
1942 list
->num_group
+= 1;
1948 struct group_list list
;
1951 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1953 /* Go find section groups. */
1956 list
.elt_count
= NULL
;
1957 bfd_map_over_sections (stdoutput
, build_group_lists
, (PTR
) &list
);
1959 /* Make the SHT_GROUP sections that describe each section group. We
1960 can't set up the section contents here yet, because elf section
1961 indices have yet to be calculated. elf.c:set_group_contents does
1962 the rest of the work. */
1963 for (i
= 0; i
< list
.num_group
; i
++)
1965 const char *group_name
= elf_group_name (list
.head
[i
]);
1969 s
= subseg_force_new (group_name
, 0);
1970 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
1972 || !bfd_set_section_flags (stdoutput
, s
, flags
)
1973 || !bfd_set_section_alignment (stdoutput
, s
, 2))
1975 as_fatal (_("can't create group: %s"),
1976 bfd_errmsg (bfd_get_error ()));
1979 /* Pass a pointer to the first section in this group. */
1980 elf_next_in_group (s
) = list
.head
[i
];
1982 s
->_raw_size
= 4 * (list
.elt_count
[i
] + 1);
1983 s
->contents
= frag_more (s
->_raw_size
);
1984 frag_now
->fr_fix
= frag_now_fix_octets ();
1987 #ifdef elf_tc_final_processing
1988 elf_tc_final_processing ();
1992 /* It removes any unneeded versioned symbols from the symbol table. */
1995 elf_frob_file_before_adjust ()
2001 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2002 if (!S_IS_DEFINED (symp
))
2004 if (symbol_get_obj (symp
)->versioned_name
)
2008 /* The @@@ syntax is a special case. If the symbol is
2009 not defined, 2 `@'s will be removed from the
2012 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
2015 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
2017 size_t l
= strlen (&p
[3]) + 1;
2018 memmove (&p
[1], &p
[3], l
);
2020 if (symbol_used_p (symp
) == 0
2021 && symbol_used_in_reloc_p (symp
) == 0)
2022 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2025 /* If there was .weak foo, but foo was neither defined nor
2026 used anywhere, remove it. */
2028 else if (S_IS_WEAK (symp
)
2029 && symbol_used_p (symp
) == 0
2030 && symbol_used_in_reloc_p (symp
) == 0)
2031 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2036 /* It is required that we let write_relocs have the opportunity to
2037 optimize away fixups before output has begun, since it is possible
2038 to eliminate all fixups for a section and thus we never should
2039 have generated the relocation section. */
2042 elf_frob_file_after_relocs ()
2044 #ifdef NEED_ECOFF_DEBUG
2045 if (ECOFF_DEBUGGING
)
2046 /* Generate the ECOFF debugging information. */
2048 const struct ecoff_debug_swap
*debug_swap
;
2049 struct ecoff_debug_info debug
;
2054 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2055 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
2056 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2058 /* Set up the pointers in debug. */
2059 #define SET(ptr, offset, type) \
2060 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2062 SET (line
, cbLineOffset
, unsigned char *);
2063 SET (external_dnr
, cbDnOffset
, PTR
);
2064 SET (external_pdr
, cbPdOffset
, PTR
);
2065 SET (external_sym
, cbSymOffset
, PTR
);
2066 SET (external_opt
, cbOptOffset
, PTR
);
2067 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2068 SET (ss
, cbSsOffset
, char *);
2069 SET (external_fdr
, cbFdOffset
, PTR
);
2070 SET (external_rfd
, cbRfdOffset
, PTR
);
2071 /* ssext and external_ext are set up just below. */
2075 /* Set up the external symbols. */
2076 debug
.ssext
= debug
.ssext_end
= NULL
;
2077 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2078 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
2079 elf_get_extr
, elf_set_index
))
2080 as_fatal (_("failed to set up debugging information: %s"),
2081 bfd_errmsg (bfd_get_error ()));
2083 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2084 assert (sec
!= NULL
);
2086 know (stdoutput
->output_has_begun
== false);
2088 /* We set the size of the section, call bfd_set_section_contents
2089 to force the ELF backend to allocate a file position, and then
2090 write out the data. FIXME: Is this really the best way to do
2092 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
2094 /* Pass BUF to bfd_set_section_contents because this will
2095 eventually become a call to fwrite, and ISO C prohibits
2096 passing a NULL pointer to a stdio function even if the
2097 pointer will not be used. */
2098 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
2099 (file_ptr
) 0, (bfd_size_type
) 0))
2100 as_fatal (_("can't start writing .mdebug section: %s"),
2101 bfd_errmsg (bfd_get_error ()));
2103 know (stdoutput
->output_has_begun
== true);
2104 know (sec
->filepos
!= 0);
2106 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2108 as_fatal (_("could not write .mdebug section: %s"),
2109 bfd_errmsg (bfd_get_error ()));
2111 #endif /* NEED_ECOFF_DEBUG */
2116 /* Heavily plagarized from obj_elf_version. The idea is to emit the
2117 SCO specific identifier in the .notes section to satisfy the SCO
2120 This looks more complicated than it really is. As opposed to the
2121 "obvious" solution, this should handle the cross dev cases
2122 correctly. (i.e, hosting on a 64 bit big endian processor, but
2123 generating SCO Elf code) Efficiency isn't a concern, as there
2124 should be exactly one of these sections per object module.
2126 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2129 int_32 namesz = 4 ; Name size
2130 int_32 descsz = 12 ; Descriptive information
2132 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2133 int_32 version = (major ver # << 16) | version of tools ;
2134 int_32 source = (tool_id << 16 ) | 1 ;
2135 int_32 info = 0 ; These are set by the SCO tools, but we
2136 don't know enough about the source
2137 environment to set them. SCO ld currently
2138 ignores them, and recommends we set them
2141 #define SCO_MAJOR_VERSION 0x1
2142 #define SCO_MINOR_VERSION 0x1
2152 asection
*seg
= now_seg
;
2153 subsegT subseg
= now_subseg
;
2154 Elf_Internal_Note i_note
;
2155 Elf_External_Note e_note
;
2156 asection
*note_secp
= (asection
*) NULL
;
2159 /* create the .note section */
2161 note_secp
= subseg_new (".note", 0);
2162 bfd_set_section_flags (stdoutput
,
2164 SEC_HAS_CONTENTS
| SEC_READONLY
);
2166 /* process the version string */
2169 i_note
.descsz
= 12; /* 12 descriptive bytes */
2170 i_note
.type
= NT_VERSION
; /* Contains a version string */
2172 p
= frag_more (sizeof (i_note
.namesz
));
2173 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2175 p
= frag_more (sizeof (i_note
.descsz
));
2176 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2178 p
= frag_more (sizeof (i_note
.type
));
2179 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2184 /* Note: this is the version number of the ELF we're representing */
2186 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2188 /* Here, we pick a magic number for ourselves (yes, I "registered"
2189 it with SCO. The bottom bit shows that we are compat with the
2192 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2194 /* If we knew (or cared) what the source language options were, we'd
2195 fill them in here. SCO has given us permission to ignore these
2196 and just set them to zero. */
2198 md_number_to_chars (p
, 0x0000, 4);
2200 frag_align (2, 0, 0);
2202 /* We probably can't restore the current segment, for there likely
2205 subseg_set (seg
, subseg
);
2209 #endif /* SCO_ELF */
2212 elf_separate_stab_sections ()
2214 #ifdef NEED_ECOFF_DEBUG
2215 return (!ECOFF_DEBUGGING
);
2222 elf_init_stab_section (seg
)
2225 #ifdef NEED_ECOFF_DEBUG
2226 if (!ECOFF_DEBUGGING
)
2228 obj_elf_init_stab_section (seg
);
2231 const struct format_ops elf_format_ops
=
2233 bfd_target_elf_flavour
,
2234 0, /* dfl_leading_underscore */
2235 1, /* emit_section_symbols */
2240 elf_frob_file_before_adjust
,
2241 elf_frob_file_after_relocs
,
2242 elf_s_get_size
, elf_s_set_size
,
2243 elf_s_get_align
, elf_s_set_align
,
2250 elf_copy_symbol_attributes
,
2251 #ifdef NEED_ECOFF_DEBUG
2252 ecoff_generate_asm_lineno
,
2255 0, /* generate_asm_lineno */
2256 0, /* process_stab */
2258 elf_separate_stab_sections
,
2259 elf_init_stab_section
,
2260 elf_sec_sym_ok_for_reloc
,
2262 #ifdef NEED_ECOFF_DEBUG
2265 0, /* ecoff_set_ext */
2267 elf_obj_read_begin_hook
,
2268 elf_obj_symbol_new_hook