1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 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"
29 #ifndef ECOFF_DEBUGGING
30 #define ECOFF_DEBUGGING 0
32 #define NEED_ECOFF_DEBUG
35 #ifdef NEED_ECOFF_DEBUG
40 #include "elf/alpha.h"
55 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
56 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
57 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
58 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
59 static void elf_s_set_other
PARAMS ((symbolS
*, int));
60 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
61 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
62 static void build_group_lists
PARAMS ((bfd
*, asection
*, PTR
));
63 static int elf_separate_stab_sections
PARAMS ((void));
64 static void elf_init_stab_section
PARAMS ((segT
));
65 static symbolS
*elf_common
PARAMS ((int));
67 #ifdef NEED_ECOFF_DEBUG
68 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
69 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
72 static void obj_elf_line
PARAMS ((int));
73 void obj_elf_version
PARAMS ((int));
74 static void obj_elf_size
PARAMS ((int));
75 static void obj_elf_type
PARAMS ((int));
76 static void obj_elf_ident
PARAMS ((int));
77 static void obj_elf_weak
PARAMS ((int));
78 static void obj_elf_local
PARAMS ((int));
79 static void obj_elf_visibility
PARAMS ((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));
87 static void obj_elf_tls_common
PARAMS ((int));
89 static const pseudo_typeS elf_pseudo_table
[] =
91 {"comm", obj_elf_common
, 0},
92 {"common", obj_elf_common
, 1},
93 {"ident", obj_elf_ident
, 0},
94 {"local", obj_elf_local
, 0},
95 {"previous", obj_elf_previous
, 0},
96 {"section", obj_elf_section
, 0},
97 {"section.s", obj_elf_section
, 0},
98 {"sect", obj_elf_section
, 0},
99 {"sect.s", obj_elf_section
, 0},
100 {"pushsection", obj_elf_section
, 1},
101 {"popsection", obj_elf_popsection
, 0},
102 {"size", obj_elf_size
, 0},
103 {"type", obj_elf_type
, 0},
104 {"version", obj_elf_version
, 0},
105 {"weak", obj_elf_weak
, 0},
107 /* These define symbol visibility. */
108 {"internal", obj_elf_visibility
, STV_INTERNAL
},
109 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
110 {"protected", obj_elf_visibility
, STV_PROTECTED
},
112 /* These are used for stabs-in-elf configurations. */
113 {"line", obj_elf_line
, 0},
115 /* This is a GNU extension to handle symbol versions. */
116 {"symver", obj_elf_symver
, 0},
118 /* A GNU extension to change subsection only. */
119 {"subsection", obj_elf_subsection
, 0},
121 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
122 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
123 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
125 /* These are used for dwarf. */
130 /* We need to trap the section changing calls to handle .previous. */
131 {"data", obj_elf_data
, 0},
132 {"text", obj_elf_text
, 0},
134 {"tls_common", obj_elf_tls_common
, 0},
140 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
142 #ifdef NEED_ECOFF_DEBUG
143 /* COFF style debugging information for ECOFF. .ln is not used; .loc
145 { "def", ecoff_directive_def
, 0 },
146 { "dim", ecoff_directive_dim
, 0 },
147 { "endef", ecoff_directive_endef
, 0 },
148 { "file", ecoff_directive_file
, 0 },
149 { "scl", ecoff_directive_scl
, 0 },
150 { "tag", ecoff_directive_tag
, 0 },
151 { "val", ecoff_directive_val
, 0 },
153 /* COFF debugging requires pseudo-ops .size and .type, but ELF
154 already has meanings for those. We use .esize and .etype
155 instead. These are only generated by gcc anyhow. */
156 { "esize", ecoff_directive_size
, 0 },
157 { "etype", ecoff_directive_type
, 0 },
159 /* ECOFF specific debugging information. */
160 { "begin", ecoff_directive_begin
, 0 },
161 { "bend", ecoff_directive_bend
, 0 },
162 { "end", ecoff_directive_end
, 0 },
163 { "ent", ecoff_directive_ent
, 0 },
164 { "fmask", ecoff_directive_fmask
, 0 },
165 { "frame", ecoff_directive_frame
, 0 },
166 { "loc", ecoff_directive_loc
, 0 },
167 { "mask", ecoff_directive_mask
, 0 },
169 /* Other ECOFF directives. */
170 { "extern", ecoff_directive_extern
, 0 },
172 /* These are used on Irix. I don't know how to implement them. */
173 { "alias", s_ignore
, 0 },
174 { "bgnb", s_ignore
, 0 },
175 { "endb", s_ignore
, 0 },
176 { "lab", s_ignore
, 0 },
177 { "noalias", s_ignore
, 0 },
178 { "verstamp", s_ignore
, 0 },
179 { "vreg", s_ignore
, 0 },
182 {NULL
, NULL
, 0} /* end sentinel */
186 #include "aout/aout64.h"
188 /* This is called when the assembler starts. */
193 /* Add symbols for the known sections to the symbol table. */
194 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
195 TEXT_SECTION_NAME
)));
196 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
197 DATA_SECTION_NAME
)));
198 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
205 pop_insert (elf_pseudo_table
);
207 pop_insert (ecoff_debug_pseudo_table
);
214 return S_GET_SIZE (sym
);
218 elf_s_set_size (sym
, sz
)
222 S_SET_SIZE (sym
, sz
);
226 elf_s_get_align (sym
)
229 return S_GET_ALIGN (sym
);
233 elf_s_set_align (sym
, align
)
237 S_SET_ALIGN (sym
, align
);
241 elf_s_get_other (sym
)
244 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
248 elf_s_set_other (sym
, other
)
252 S_SET_OTHER (sym
, other
);
256 elf_sec_sym_ok_for_reloc (sec
)
259 return obj_sec_sym_ok_for_reloc (sec
);
268 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
269 symbol_set_frag (sym
, &zero_address_frag
);
270 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
272 if (symbol_rootP
!= sym
)
274 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
275 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
277 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
281 #ifdef NEED_ECOFF_DEBUG
287 elf_common (is_common
)
297 if (flag_mri
&& is_common
)
303 name
= input_line_pointer
;
304 c
= get_symbol_end ();
305 /* just after name is now '\0' */
306 p
= input_line_pointer
;
309 if (*input_line_pointer
!= ',')
311 as_bad (_("expected comma after symbol-name"));
312 ignore_rest_of_line ();
315 input_line_pointer
++; /* skip ',' */
316 if ((temp
= get_absolute_expression ()) < 0)
318 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
319 ignore_rest_of_line ();
324 symbolP
= symbol_find_or_make (name
);
326 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
328 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP
));
329 ignore_rest_of_line ();
332 if (S_GET_VALUE (symbolP
) != 0)
334 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
336 as_warn (_("length of .comm \"%s\" is already %ld; not changed to %d"),
337 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
340 know (symbolP
->sy_frag
== &zero_address_frag
);
341 if (*input_line_pointer
!= ',')
346 input_line_pointer
++;
349 if (! have_align
|| *input_line_pointer
!= '"')
355 temp
= get_absolute_expression ();
359 as_warn (_("common alignment negative; 0 assumed"));
362 if (symbol_get_obj (symbolP
)->local
)
371 old_subsec
= now_subseg
;
374 /* convert to a power of 2 alignment */
375 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
378 as_bad (_("common alignment not a power of 2"));
379 ignore_rest_of_line ();
385 record_alignment (bss_section
, align
);
386 subseg_set (bss_section
, 0);
388 frag_align (align
, 0, 0);
389 if (S_GET_SEGMENT (symbolP
) == bss_section
)
390 symbol_get_frag (symbolP
)->fr_symbol
= 0;
391 symbol_set_frag (symbolP
, frag_now
);
392 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
393 (offsetT
) size
, (char *) 0);
395 S_SET_SIZE (symbolP
, size
);
396 S_SET_SEGMENT (symbolP
, bss_section
);
397 S_CLEAR_EXTERNAL (symbolP
);
398 subseg_set (old_sec
, old_subsec
);
403 S_SET_VALUE (symbolP
, (valueT
) size
);
404 S_SET_ALIGN (symbolP
, temp
);
405 S_SET_EXTERNAL (symbolP
);
406 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
411 input_line_pointer
++;
412 /* @@ Some use the dot, some don't. Can we get some consistency?? */
413 if (*input_line_pointer
== '.')
414 input_line_pointer
++;
415 /* @@ Some say data, some say bss. */
416 if (strncmp (input_line_pointer
, "bss\"", 4)
417 && strncmp (input_line_pointer
, "data\"", 5))
419 while (*--input_line_pointer
!= '"')
421 input_line_pointer
--;
422 goto bad_common_segment
;
424 while (*input_line_pointer
++ != '"')
426 goto allocate_common
;
429 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
431 demand_empty_rest_of_line ();
436 p
= input_line_pointer
;
437 while (*p
&& *p
!= '\n')
441 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
443 input_line_pointer
= p
;
444 ignore_rest_of_line ();
450 obj_elf_common (is_common
)
453 elf_common (is_common
);
457 obj_elf_tls_common (ignore
)
458 int ignore ATTRIBUTE_UNUSED
;
460 symbolS
*symbolP
= elf_common (0);
463 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
467 obj_elf_local (ignore
)
468 int ignore ATTRIBUTE_UNUSED
;
476 name
= input_line_pointer
;
477 c
= get_symbol_end ();
478 symbolP
= symbol_find_or_make (name
);
479 *input_line_pointer
= c
;
481 S_CLEAR_EXTERNAL (symbolP
);
482 symbol_get_obj (symbolP
)->local
= 1;
485 input_line_pointer
++;
487 if (*input_line_pointer
== '\n')
492 demand_empty_rest_of_line ();
496 obj_elf_weak (ignore
)
497 int ignore ATTRIBUTE_UNUSED
;
505 name
= input_line_pointer
;
506 c
= get_symbol_end ();
507 symbolP
= symbol_find_or_make (name
);
508 *input_line_pointer
= c
;
510 S_SET_WEAK (symbolP
);
511 symbol_get_obj (symbolP
)->local
= 1;
514 input_line_pointer
++;
516 if (*input_line_pointer
== '\n')
521 demand_empty_rest_of_line ();
525 obj_elf_visibility (visibility
)
532 elf_symbol_type
*elfsym
;
536 name
= input_line_pointer
;
537 c
= get_symbol_end ();
538 symbolP
= symbol_find_or_make (name
);
539 *input_line_pointer
= c
;
543 bfdsym
= symbol_get_bfdsym (symbolP
);
544 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
548 elfsym
->internal_elf_sym
.st_other
= visibility
;
552 input_line_pointer
++;
556 if (*input_line_pointer
== '\n')
562 demand_empty_rest_of_line ();
565 static segT previous_section
;
566 static int previous_subsection
;
570 struct section_stack
*next
;
572 int subseg
, prev_subseg
;
575 static struct section_stack
*section_stack
;
577 /* Handle the .section pseudo-op. This code supports two different
580 The first is found on Solaris, and looks like
581 .section ".sec1",#alloc,#execinstr,#write
582 Here the names after '#' are the SHF_* flags to turn on for the
583 section. I'm not sure how it determines the SHT_* type (BFD
584 doesn't really give us control over the type, anyhow).
586 The second format is found on UnixWare, and probably most SVR4
587 machines, and looks like
588 .section .sec1,"a",@progbits
589 The quoted string may contain any combination of a, w, x, and
590 represents the SHF_* flags to turn on for the section. The string
591 beginning with '@' can be progbits or nobits. There should be
592 other possibilities, but I don't know what they are. In any case,
593 BFD doesn't really let us set the section type. */
595 /* Certain named sections have particular defined types, listed on p.
597 struct special_section
604 static struct special_section
const special_sections
[] =
606 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
607 { ".comment", SHT_PROGBITS
, 0 },
608 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
609 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
610 { ".debug", SHT_PROGBITS
, 0 },
611 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
612 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
613 { ".line", SHT_PROGBITS
, 0 },
614 { ".note", SHT_NOTE
, 0 },
615 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
616 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
617 { ".tbss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_TLS
},
618 { ".tdata", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_TLS
},
619 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
621 /* FIXME: The current gcc, as of 2002-03-03, will emit
623 .section .init_array,"aw",@progbits
625 for __attribute__ ((section (".init_array"))). "@progbits" marks
626 the incorrect section type. For now, we make them with
627 SHT_PROGBITS. BFD will fix the section type. Gcc should be changed
633 { ".init_array",SHT_INIT_ARRAY
, SHF_ALLOC
+ SHF_WRITE
},
634 { ".fini_array",SHT_FINI_ARRAY
, SHF_ALLOC
+ SHF_WRITE
},
635 { ".preinit_array",SHT_PREINIT_ARRAY
, SHF_ALLOC
+ SHF_WRITE
},
637 { ".init_array",SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
638 { ".fini_array",SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
639 { ".preinit_array",SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
642 #ifdef ELF_TC_SPECIAL_SECTIONS
643 ELF_TC_SPECIAL_SECTIONS
647 /* The following section names are special, but they can not
648 reasonably appear in assembler code. Some of the attributes are
649 processor dependent. */
650 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
651 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
652 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
653 { ".got", SHT_PROGBITS
, 0 },
654 { ".hash", SHT_HASH
, SHF_ALLOC
},
655 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
656 { ".plt", SHT_PROGBITS
, 0 },
657 { ".shstrtab",SHT_STRTAB
, 0 },
658 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
659 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
666 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
)
671 const char *group_name
;
680 #ifdef md_flush_pending_output
681 md_flush_pending_output ();
684 /* Switch to the section, creating it if necessary. */
687 struct section_stack
*elt
;
688 elt
= xmalloc (sizeof (struct section_stack
));
689 elt
->next
= section_stack
;
691 elt
->prev_seg
= previous_section
;
692 elt
->subseg
= now_subseg
;
693 elt
->prev_subseg
= previous_subsection
;
696 previous_section
= now_seg
;
697 previous_subsection
= now_subseg
;
699 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
700 sec
= subseg_new (name
, 0);
702 /* See if this is one of the special sections. */
703 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
704 if (strcmp (name
, special_sections
[i
].name
) == 0)
706 if (type
== SHT_NULL
)
707 type
= special_sections
[i
].type
;
708 else if (type
!= special_sections
[i
].type
)
712 as_warn (_("setting incorrect section type for %s"), name
);
716 as_warn (_("ignoring incorrect section type for %s"), name
);
717 type
= special_sections
[i
].type
;
720 if ((attr
&~ special_sections
[i
].attributes
) != 0
723 /* As a GNU extension, we permit a .note section to be
724 allocatable. If the linker sees an allocateable .note
725 section, it will create a PT_NOTE segment in the output
727 if (strcmp (name
, ".note") != 0
728 || attr
!= SHF_ALLOC
)
729 as_warn (_("setting incorrect section attributes for %s"),
732 attr
|= special_sections
[i
].attributes
;
736 /* Convert ELF type and flags to BFD flags. */
738 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
739 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
740 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
741 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
742 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
743 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
744 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 0));
745 #ifdef md_elf_section_flags
746 flags
= md_elf_section_flags (flags
, attr
, type
);
753 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
754 if (type
== SHT_NOBITS
)
755 seg_info (sec
)->bss
= 1;
757 bfd_set_section_flags (stdoutput
, sec
, flags
);
758 if (flags
& SEC_MERGE
)
759 sec
->entsize
= entsize
;
760 elf_group_name (sec
) = group_name
;
761 elf_linkonce_p (sec
) = linkonce
;
763 /* Add a symbol for this section to the symbol table. */
764 secsym
= symbol_find (name
);
766 symbol_set_bfdsym (secsym
, sec
->symbol
);
768 symbol_table_insert (section_symbol (sec
));
772 /* If section attributes are specified the second time we see a
773 particular section, then check that they are the same as we
774 saw the first time. */
775 if (((old_sec
->flags
^ flags
)
776 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
777 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
779 || linkonce
!= elf_linkonce_p (sec
))
780 as_warn (_("ignoring changed section attributes for %s"), name
);
781 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
782 as_warn (_("ignoring changed section entity size for %s"), name
);
783 if ((attr
& SHF_GROUP
) != 0
784 && strcmp (elf_group_name (old_sec
), group_name
) != 0)
785 as_warn (_("ignoring new section group for %s"), name
);
788 #ifdef md_elf_section_change_hook
789 md_elf_section_change_hook ();
794 obj_elf_parse_section_letters (str
, len
)
811 attr
|= SHF_EXECINSTR
;
827 if (*(str
- 1) == 'a')
830 if (len
> 1 && str
[1] == 's')
839 char *bad_msg
= _("unrecognized .section attribute: want a,w,x,M,S,G,T");
840 #ifdef md_elf_section_letter
841 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
847 as_warn ("%s", bad_msg
);
860 obj_elf_section_word (str
, len
)
864 if (len
== 5 && strncmp (str
, "write", 5) == 0)
866 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
868 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
869 return SHF_EXECINSTR
;
871 #ifdef md_elf_section_word
873 int md_attr
= md_elf_section_word (str
, len
);
879 as_warn (_("unrecognized section attribute"));
884 obj_elf_section_type (str
, len
)
888 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
890 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
893 #ifdef md_elf_section_type
895 int md_type
= md_elf_section_type (str
, len
);
901 as_warn (_("unrecognized section type"));
905 /* Get name of section. */
907 obj_elf_section_name ()
912 if (*input_line_pointer
== '"')
916 name
= demand_copy_C_string (&dummy
);
919 ignore_rest_of_line ();
925 char *end
= input_line_pointer
;
927 while (0 == strchr ("\n\t,; ", *end
))
929 if (end
== input_line_pointer
)
931 as_warn (_("missing name"));
932 ignore_rest_of_line ();
936 name
= xmalloc (end
- input_line_pointer
+ 1);
937 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
938 name
[end
- input_line_pointer
] = '\0';
939 input_line_pointer
= end
;
946 obj_elf_section (push
)
949 char *name
, *group_name
, *beg
;
950 int type
, attr
, dummy
;
959 #ifdef md_flush_pending_output
960 md_flush_pending_output ();
963 previous_section
= now_seg
;
964 previous_subsection
= now_subseg
;
966 s_mri_sect (&mri_type
);
968 #ifdef md_elf_section_change_hook
969 md_elf_section_change_hook ();
974 #endif /* ! defined (TC_I370) */
976 name
= obj_elf_section_name ();
985 if (*input_line_pointer
== ',')
987 /* Skip the comma. */
988 ++input_line_pointer
;
991 if (*input_line_pointer
== '"')
993 beg
= demand_copy_C_string (&dummy
);
996 ignore_rest_of_line ();
999 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
1002 if (*input_line_pointer
== ',')
1005 char *save
= input_line_pointer
;
1007 ++input_line_pointer
;
1009 c
= *input_line_pointer
;
1012 beg
= demand_copy_C_string (&dummy
);
1015 ignore_rest_of_line ();
1018 type
= obj_elf_section_type (beg
, strlen (beg
));
1020 else if (c
== '@' || c
== '%')
1022 beg
= ++input_line_pointer
;
1023 c
= get_symbol_end ();
1024 *input_line_pointer
= c
;
1025 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
1028 input_line_pointer
= save
;
1032 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
1034 ++input_line_pointer
;
1036 entsize
= get_absolute_expression ();
1040 as_warn (_("invalid merge entity size"));
1045 else if ((attr
& SHF_MERGE
) != 0)
1047 as_warn (_("entity size for SHF_MERGE not specified"));
1051 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1053 ++input_line_pointer
;
1054 group_name
= obj_elf_section_name ();
1055 if (group_name
== NULL
)
1057 else if (strncmp (input_line_pointer
, ",comdat", 7) == 0)
1059 input_line_pointer
+= 7;
1062 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1065 else if ((attr
& SHF_GROUP
) != 0)
1067 as_warn (_("group name for SHF_GROUP not specified"));
1078 if (*input_line_pointer
!= '#')
1080 as_warn (_("character following name is not '#'"));
1081 ignore_rest_of_line ();
1084 beg
= ++input_line_pointer
;
1085 c
= get_symbol_end ();
1086 *input_line_pointer
= c
;
1088 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
1092 while (*input_line_pointer
++ == ',');
1093 --input_line_pointer
;
1097 demand_empty_rest_of_line ();
1099 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
);
1102 /* Change to the .data section. */
1108 #ifdef md_flush_pending_output
1109 md_flush_pending_output ();
1112 previous_section
= now_seg
;
1113 previous_subsection
= now_subseg
;
1116 #ifdef md_elf_section_change_hook
1117 md_elf_section_change_hook ();
1121 /* Change to the .text section. */
1127 #ifdef md_flush_pending_output
1128 md_flush_pending_output ();
1131 previous_section
= now_seg
;
1132 previous_subsection
= now_subseg
;
1135 #ifdef md_elf_section_change_hook
1136 md_elf_section_change_hook ();
1141 obj_elf_subsection (ignore
)
1142 int ignore ATTRIBUTE_UNUSED
;
1146 #ifdef md_flush_pending_output
1147 md_flush_pending_output ();
1150 previous_section
= now_seg
;
1151 previous_subsection
= now_subseg
;
1153 temp
= get_absolute_expression ();
1154 subseg_set (now_seg
, (subsegT
) temp
);
1155 demand_empty_rest_of_line ();
1157 #ifdef md_elf_section_change_hook
1158 md_elf_section_change_hook ();
1162 /* This can be called from the processor backends if they change
1166 obj_elf_section_change_hook ()
1168 previous_section
= now_seg
;
1169 previous_subsection
= now_subseg
;
1173 obj_elf_previous (ignore
)
1174 int ignore ATTRIBUTE_UNUSED
;
1179 if (previous_section
== 0)
1181 as_warn (_(".previous without corresponding .section; ignored"));
1185 #ifdef md_flush_pending_output
1186 md_flush_pending_output ();
1189 new_section
= previous_section
;
1190 new_subsection
= previous_subsection
;
1191 previous_section
= now_seg
;
1192 previous_subsection
= now_subseg
;
1193 subseg_set (new_section
, new_subsection
);
1195 #ifdef md_elf_section_change_hook
1196 md_elf_section_change_hook ();
1201 obj_elf_popsection (xxx
)
1202 int xxx ATTRIBUTE_UNUSED
;
1204 struct section_stack
*top
= section_stack
;
1208 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1212 #ifdef md_flush_pending_output
1213 md_flush_pending_output ();
1216 section_stack
= top
->next
;
1217 previous_section
= top
->prev_seg
;
1218 previous_subsection
= top
->prev_subseg
;
1219 subseg_set (top
->seg
, top
->subseg
);
1222 #ifdef md_elf_section_change_hook
1223 md_elf_section_change_hook ();
1228 obj_elf_line (ignore
)
1229 int ignore ATTRIBUTE_UNUSED
;
1231 /* Assume delimiter is part of expression. BSD4.2 as fails with
1232 delightful bug, so we are not being incompatible here. */
1233 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1234 demand_empty_rest_of_line ();
1237 /* This handles the .symver pseudo-op, which is used to specify a
1238 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1239 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1240 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1241 with the same value as the symbol NAME. */
1244 obj_elf_symver (ignore
)
1245 int ignore ATTRIBUTE_UNUSED
;
1252 name
= input_line_pointer
;
1253 c
= get_symbol_end ();
1255 sym
= symbol_find_or_make (name
);
1257 *input_line_pointer
= c
;
1260 if (*input_line_pointer
!= ',')
1262 as_bad (_("expected comma after name in .symver"));
1263 ignore_rest_of_line ();
1267 ++input_line_pointer
;
1268 name
= input_line_pointer
;
1270 /* Temporarily include '@' in symbol names. */
1271 old_lexat
= lex_type
[(unsigned char) '@'];
1272 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1273 c
= get_symbol_end ();
1274 lex_type
[(unsigned char) '@'] = old_lexat
;
1276 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1278 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1280 *input_line_pointer
= c
;
1282 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1283 ELF_VER_CHR
) == NULL
)
1285 as_bad (_("missing version name in `%s' for symbol `%s'"),
1286 symbol_get_obj (sym
)->versioned_name
,
1288 ignore_rest_of_line ();
1294 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1296 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1297 name
, symbol_get_obj (sym
)->versioned_name
,
1299 ignore_rest_of_line ();
1303 *input_line_pointer
= c
;
1306 demand_empty_rest_of_line ();
1309 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1310 to the linker the hierarchy in which a particular table resides. The
1311 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1314 obj_elf_vtable_inherit (ignore
)
1315 int ignore ATTRIBUTE_UNUSED
;
1317 char *cname
, *pname
;
1318 symbolS
*csym
, *psym
;
1321 if (*input_line_pointer
== '#')
1322 ++input_line_pointer
;
1324 cname
= input_line_pointer
;
1325 c
= get_symbol_end ();
1326 csym
= symbol_find (cname
);
1328 /* GCFIXME: should check that we don't have two .vtable_inherits for
1329 the same child symbol. Also, we can currently only do this if the
1330 child symbol is already exists and is placed in a fragment. */
1332 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1334 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1339 *input_line_pointer
= c
;
1342 if (*input_line_pointer
!= ',')
1344 as_bad ("expected comma after name in .vtable_inherit");
1345 ignore_rest_of_line ();
1349 ++input_line_pointer
;
1352 if (*input_line_pointer
== '#')
1353 ++input_line_pointer
;
1355 if (input_line_pointer
[0] == '0'
1356 && (input_line_pointer
[1] == '\0'
1357 || ISSPACE (input_line_pointer
[1])))
1359 psym
= section_symbol (absolute_section
);
1360 ++input_line_pointer
;
1364 pname
= input_line_pointer
;
1365 c
= get_symbol_end ();
1366 psym
= symbol_find_or_make (pname
);
1367 *input_line_pointer
= c
;
1370 demand_empty_rest_of_line ();
1375 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1376 return fix_new (symbol_get_frag (csym
),
1377 symbol_get_value_expression (csym
)->X_add_number
,
1378 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1381 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1382 to the linker that a vtable slot was used. The syntax is
1383 ".vtable_entry tablename, offset". */
1386 obj_elf_vtable_entry (ignore
)
1387 int ignore ATTRIBUTE_UNUSED
;
1394 if (*input_line_pointer
== '#')
1395 ++input_line_pointer
;
1397 name
= input_line_pointer
;
1398 c
= get_symbol_end ();
1399 sym
= symbol_find_or_make (name
);
1400 *input_line_pointer
= c
;
1403 if (*input_line_pointer
!= ',')
1405 as_bad ("expected comma after name in .vtable_entry");
1406 ignore_rest_of_line ();
1410 ++input_line_pointer
;
1411 if (*input_line_pointer
== '#')
1412 ++input_line_pointer
;
1414 offset
= get_absolute_expression ();
1416 demand_empty_rest_of_line ();
1418 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1419 BFD_RELOC_VTABLE_ENTRY
);
1423 elf_obj_read_begin_hook ()
1425 #ifdef NEED_ECOFF_DEBUG
1426 if (ECOFF_DEBUGGING
)
1427 ecoff_read_begin_hook ();
1432 elf_obj_symbol_new_hook (symbolP
)
1435 struct elf_obj_sy
*sy_obj
;
1437 sy_obj
= symbol_get_obj (symbolP
);
1438 sy_obj
->size
= NULL
;
1439 sy_obj
->versioned_name
= NULL
;
1441 #ifdef NEED_ECOFF_DEBUG
1442 if (ECOFF_DEBUGGING
)
1443 ecoff_symbol_new_hook (symbolP
);
1447 /* When setting one symbol equal to another, by default we probably
1448 want them to have the same "size", whatever it means in the current
1452 elf_copy_symbol_attributes (dest
, src
)
1453 symbolS
*dest
, *src
;
1455 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1456 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1459 if (destelf
->size
== NULL
)
1461 (expressionS
*) xmalloc (sizeof (expressionS
));
1462 *destelf
->size
= *srcelf
->size
;
1466 if (destelf
->size
!= NULL
)
1467 free (destelf
->size
);
1468 destelf
->size
= NULL
;
1470 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1471 /* Don't copy visibility. */
1472 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1473 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1477 obj_elf_version (ignore
)
1478 int ignore ATTRIBUTE_UNUSED
;
1483 asection
*seg
= now_seg
;
1484 subsegT subseg
= now_subseg
;
1485 Elf_Internal_Note i_note
;
1486 Elf_External_Note e_note
;
1487 asection
*note_secp
= (asection
*) NULL
;
1491 if (*input_line_pointer
== '\"')
1493 ++input_line_pointer
; /* -> 1st char of string. */
1494 name
= input_line_pointer
;
1496 while (is_a_char (c
= next_char_of_string ()))
1498 c
= *input_line_pointer
;
1499 *input_line_pointer
= '\0';
1500 *(input_line_pointer
- 1) = '\0';
1501 *input_line_pointer
= c
;
1503 /* create the .note section */
1505 note_secp
= subseg_new (".note", 0);
1506 bfd_set_section_flags (stdoutput
,
1508 SEC_HAS_CONTENTS
| SEC_READONLY
);
1510 /* process the version string */
1512 len
= strlen (name
);
1514 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1515 i_note
.descsz
= 0; /* no description */
1516 i_note
.type
= NT_VERSION
;
1517 p
= frag_more (sizeof (e_note
.namesz
));
1518 md_number_to_chars (p
, (valueT
) i_note
.namesz
, sizeof (e_note
.namesz
));
1519 p
= frag_more (sizeof (e_note
.descsz
));
1520 md_number_to_chars (p
, (valueT
) i_note
.descsz
, sizeof (e_note
.descsz
));
1521 p
= frag_more (sizeof (e_note
.type
));
1522 md_number_to_chars (p
, (valueT
) i_note
.type
, sizeof (e_note
.type
));
1523 p
= frag_more (len
+ 1);
1526 frag_align (2, 0, 0);
1528 subseg_set (seg
, subseg
);
1532 as_bad (_("expected quoted string"));
1534 demand_empty_rest_of_line ();
1538 obj_elf_size (ignore
)
1539 int ignore ATTRIBUTE_UNUSED
;
1541 char *name
= input_line_pointer
;
1542 char c
= get_symbol_end ();
1547 p
= input_line_pointer
;
1550 if (*input_line_pointer
!= ',')
1553 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1555 ignore_rest_of_line ();
1558 input_line_pointer
++;
1560 if (exp
.X_op
== O_absent
)
1562 as_bad (_("missing expression in .size directive"));
1563 exp
.X_op
= O_constant
;
1564 exp
.X_add_number
= 0;
1567 sym
= symbol_find_or_make (name
);
1569 if (exp
.X_op
== O_constant
)
1571 S_SET_SIZE (sym
, exp
.X_add_number
);
1572 if (symbol_get_obj (sym
)->size
)
1574 xfree (symbol_get_obj (sym
)->size
);
1575 symbol_get_obj (sym
)->size
= NULL
;
1580 symbol_get_obj (sym
)->size
=
1581 (expressionS
*) xmalloc (sizeof (expressionS
));
1582 *symbol_get_obj (sym
)->size
= exp
;
1584 demand_empty_rest_of_line ();
1587 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1588 There are five syntaxes:
1590 The first (used on Solaris) is
1592 The second (used on UnixWare) is
1594 The third (reportedly to be used on Irix 6.0) is
1596 The fourth (used on NetBSD/Arm and Linux/ARM) is
1598 The fifth (used on SVR4/860) is
1599 .type SYM,"function"
1603 obj_elf_type (ignore
)
1604 int ignore ATTRIBUTE_UNUSED
;
1609 const char *typename
;
1611 elf_symbol_type
*elfsym
;
1613 name
= input_line_pointer
;
1614 c
= get_symbol_end ();
1615 sym
= symbol_find_or_make (name
);
1616 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1617 *input_line_pointer
= c
;
1620 if (*input_line_pointer
== ',')
1621 ++input_line_pointer
;
1624 if ( *input_line_pointer
== '#'
1625 || *input_line_pointer
== '@'
1626 || *input_line_pointer
== '"'
1627 || *input_line_pointer
== '%')
1628 ++input_line_pointer
;
1630 typename
= input_line_pointer
;
1631 c
= get_symbol_end ();
1634 if (strcmp (typename
, "function") == 0
1635 || strcmp (typename
, "STT_FUNC") == 0)
1636 type
= BSF_FUNCTION
;
1637 else if (strcmp (typename
, "object") == 0
1638 || strcmp (typename
, "STT_OBJECT") == 0)
1640 #ifdef md_elf_symbol_type
1641 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1645 as_bad (_("unrecognized symbol type \"%s\""), typename
);
1647 *input_line_pointer
= c
;
1649 if (*input_line_pointer
== '"')
1650 ++input_line_pointer
;
1652 elfsym
->symbol
.flags
|= type
;
1654 demand_empty_rest_of_line ();
1658 obj_elf_ident (ignore
)
1659 int ignore ATTRIBUTE_UNUSED
;
1661 static segT comment_section
;
1662 segT old_section
= now_seg
;
1663 int old_subsection
= now_subseg
;
1665 #ifdef md_flush_pending_output
1666 md_flush_pending_output ();
1669 if (!comment_section
)
1672 comment_section
= subseg_new (".comment", 0);
1673 bfd_set_section_flags (stdoutput
, comment_section
,
1674 SEC_READONLY
| SEC_HAS_CONTENTS
);
1679 subseg_set (comment_section
, 0);
1681 subseg_set (old_section
, old_subsection
);
1684 #ifdef INIT_STAB_SECTION
1686 /* The first entry in a .stabs section is special. */
1689 obj_elf_init_stab_section (seg
)
1695 unsigned int stroff
;
1697 /* Force the section to align to a longword boundary. Without this,
1698 UnixWare ar crashes. */
1699 bfd_set_section_alignment (stdoutput
, seg
, 2);
1701 /* Make space for this first symbol. */
1705 as_where (&file
, (unsigned int *) NULL
);
1706 stabstr_name
= (char *) xmalloc (strlen (segment_name (seg
)) + 4);
1707 strcpy (stabstr_name
, segment_name (seg
));
1708 strcat (stabstr_name
, "str");
1709 stroff
= get_stab_string_offset (file
, stabstr_name
);
1711 md_number_to_chars (p
, stroff
, 4);
1712 seg_info (seg
)->stabu
.p
= p
;
1717 /* Fill in the counts in the first entry in a .stabs section. */
1720 adjust_stab_sections (abfd
, sec
, xxx
)
1723 PTR xxx ATTRIBUTE_UNUSED
;
1730 if (strncmp (".stab", sec
->name
, 5))
1732 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1735 name
= (char *) alloca (strlen (sec
->name
) + 4);
1736 strcpy (name
, sec
->name
);
1737 strcat (name
, "str");
1738 strsec
= bfd_get_section_by_name (abfd
, name
);
1740 strsz
= bfd_section_size (abfd
, strsec
);
1743 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1745 p
= seg_info (sec
)->stabu
.p
;
1748 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1749 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1752 #ifdef NEED_ECOFF_DEBUG
1754 /* This function is called by the ECOFF code. It is supposed to
1755 record the external symbol information so that the backend can
1756 write it out correctly. The ELF backend doesn't actually handle
1757 this at the moment, so we do it ourselves. We save the information
1761 elf_ecoff_set_ext (sym
, ext
)
1763 struct ecoff_extr
*ext
;
1765 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1768 /* This function is called by bfd_ecoff_debug_externals. It is
1769 supposed to *EXT to the external symbol information, and return
1770 whether the symbol should be used at all. */
1773 elf_get_extr (sym
, ext
)
1777 if (sym
->udata
.p
== NULL
)
1779 *ext
= *(EXTR
*) sym
->udata
.p
;
1783 /* This function is called by bfd_ecoff_debug_externals. It has
1784 nothing to do for ELF. */
1788 elf_set_index (sym
, indx
)
1789 asymbol
*sym ATTRIBUTE_UNUSED
;
1790 bfd_size_type indx ATTRIBUTE_UNUSED
;
1794 #endif /* NEED_ECOFF_DEBUG */
1797 elf_frob_symbol (symp
, puntp
)
1801 struct elf_obj_sy
*sy_obj
;
1803 #ifdef NEED_ECOFF_DEBUG
1804 if (ECOFF_DEBUGGING
)
1805 ecoff_frob_symbol (symp
);
1808 sy_obj
= symbol_get_obj (symp
);
1810 if (sy_obj
->size
!= NULL
)
1812 switch (sy_obj
->size
->X_op
)
1816 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1817 + sy_obj
->size
->X_add_number
1818 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1822 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1823 + sy_obj
->size
->X_add_number
));
1826 as_bad (_(".size expression too complicated to fix up"));
1829 free (sy_obj
->size
);
1830 sy_obj
->size
= NULL
;
1833 if (sy_obj
->versioned_name
!= NULL
)
1837 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1840 /* This symbol was given a new name with the .symver directive.
1842 If this is an external reference, just rename the symbol to
1843 include the version string. This will make the relocs be
1844 against the correct versioned symbol.
1846 If this is a definition, add an alias. FIXME: Using an alias
1847 will permit the debugging information to refer to the right
1848 symbol. However, it's not clear whether it is the best
1851 if (! S_IS_DEFINED (symp
))
1853 /* Verify that the name isn't using the @@ syntax--this is
1854 reserved for definitions of the default version to link
1856 if (p
[1] == ELF_VER_CHR
)
1858 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1859 sy_obj
->versioned_name
);
1862 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1866 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1870 /* The @@@ syntax is a special case. It renames the
1871 symbol name to versioned_name with one `@' removed. */
1872 l
= strlen (&p
[3]) + 1;
1873 memmove (&p
[2], &p
[3], l
);
1874 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1880 /* FIXME: Creating a new symbol here is risky. We're
1881 in the final loop over the symbol table. We can
1882 get away with it only because the symbol goes to
1883 the end of the list, where the loop will still see
1884 it. It would probably be better to do this in
1885 obj_frob_file_before_adjust. */
1887 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1889 /* Now we act as though we saw symp2 = sym. */
1891 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1893 /* Subtracting out the frag address here is a hack
1894 because we are in the middle of the final loop. */
1897 - symbol_get_frag (symp
)->fr_address
));
1899 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1901 /* This will copy over the size information. */
1902 copy_symbol_attributes (symp2
, symp
);
1904 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
1906 if (S_IS_WEAK (symp
))
1909 if (S_IS_EXTERNAL (symp
))
1910 S_SET_EXTERNAL (symp2
);
1915 /* Double check weak symbols. */
1916 if (S_IS_WEAK (symp
))
1918 if (S_IS_COMMON (symp
))
1919 as_bad (_("symbol `%s' can not be both weak and common"),
1924 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1925 any undefined non-function symbol to STT_OBJECT. We try to be
1926 compatible, since newer Irix 5 and 6 linkers care. However, we
1927 only set undefined symbols to be STT_OBJECT if we are on Irix,
1928 because that is the only time gcc will generate the necessary
1929 .global directives to mark functions. */
1931 if (S_IS_COMMON (symp
))
1932 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1934 if (strstr (TARGET_OS
, "irix") != NULL
1935 && ! S_IS_DEFINED (symp
)
1936 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1937 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1941 /* If TC_PPC is defined, we used to force the type of a symbol to be
1942 BSF_OBJECT if it was otherwise unset. This was required by some
1943 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1944 that this is no longer needed, so it is now commented out. */
1945 if ((symbol_get_bfdsym (symp
)->flags
1946 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1947 && S_IS_DEFINED (symp
))
1948 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1954 asection
**head
; /* Section lists. */
1955 unsigned int *elt_count
; /* Number of sections in each list. */
1956 unsigned int num_group
; /* Number of lists. */
1959 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1960 add it to a list of sections belonging to the group. INF is a
1961 pointer to a struct group_list, which is where we store the head of
1965 build_group_lists (abfd
, sec
, inf
)
1966 bfd
*abfd ATTRIBUTE_UNUSED
;
1970 struct group_list
*list
= (struct group_list
*) inf
;
1971 const char *group_name
= elf_group_name (sec
);
1974 if (group_name
== NULL
)
1977 /* If this group already has a list, add the section to the head of
1979 for (i
= 0; i
< list
->num_group
; i
++)
1981 if (strcmp (group_name
, elf_group_name (list
->head
[i
])) == 0)
1983 elf_next_in_group (sec
) = list
->head
[i
];
1984 list
->head
[i
] = sec
;
1985 list
->elt_count
[i
] += 1;
1990 /* New group. Make the arrays bigger in chunks to minimize calls to
1992 i
= list
->num_group
;
1995 unsigned int newsize
= i
+ 128;
1996 list
->head
= xrealloc (list
->head
, newsize
* sizeof (*list
->head
));
1997 list
->elt_count
= xrealloc (list
->elt_count
,
1998 newsize
* sizeof (*list
->elt_count
));
2000 list
->head
[i
] = sec
;
2001 list
->elt_count
[i
] = 1;
2002 list
->num_group
+= 1;
2008 struct group_list list
;
2011 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
2013 /* Go find section groups. */
2016 list
.elt_count
= NULL
;
2017 bfd_map_over_sections (stdoutput
, build_group_lists
, (PTR
) &list
);
2019 /* Make the SHT_GROUP sections that describe each section group. We
2020 can't set up the section contents here yet, because elf section
2021 indices have yet to be calculated. elf.c:set_group_contents does
2022 the rest of the work. */
2023 for (i
= 0; i
< list
.num_group
; i
++)
2025 const char *group_name
= elf_group_name (list
.head
[i
]);
2026 const char *sec_name
;
2032 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2033 for (s
= list
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2034 if (elf_linkonce_p (s
) != ((flags
& SEC_LINK_ONCE
) != 0))
2036 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2037 if (s
!= list
.head
[i
])
2039 as_warn (_("assuming all members of group `%s' are COMDAT"),
2045 sec_name
= group_name
;
2046 sy
= symbol_find_exact (group_name
);
2049 && (sy
== symbol_lastP
2050 || (sy
->sy_next
!= NULL
2051 && sy
->sy_next
->sy_previous
== sy
)))
2054 sec_name
= ".group";
2056 s
= subseg_force_new (sec_name
, 0);
2058 || !bfd_set_section_flags (stdoutput
, s
, flags
)
2059 || !bfd_set_section_alignment (stdoutput
, s
, 2))
2061 as_fatal (_("can't create group: %s"),
2062 bfd_errmsg (bfd_get_error ()));
2065 /* Pass a pointer to the first section in this group. */
2066 elf_next_in_group (s
) = list
.head
[i
];
2068 elf_group_id (s
) = sy
->bsym
;
2070 s
->_raw_size
= 4 * (list
.elt_count
[i
] + 1);
2071 s
->contents
= frag_more (s
->_raw_size
);
2072 frag_now
->fr_fix
= frag_now_fix_octets ();
2075 #ifdef elf_tc_final_processing
2076 elf_tc_final_processing ();
2080 /* It removes any unneeded versioned symbols from the symbol table. */
2083 elf_frob_file_before_adjust ()
2089 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2090 if (!S_IS_DEFINED (symp
))
2092 if (symbol_get_obj (symp
)->versioned_name
)
2096 /* The @@@ syntax is a special case. If the symbol is
2097 not defined, 2 `@'s will be removed from the
2100 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
2103 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
2105 size_t l
= strlen (&p
[3]) + 1;
2106 memmove (&p
[1], &p
[3], l
);
2108 if (symbol_used_p (symp
) == 0
2109 && symbol_used_in_reloc_p (symp
) == 0)
2110 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2113 /* If there was .weak foo, but foo was neither defined nor
2114 used anywhere, remove it. */
2116 else if (S_IS_WEAK (symp
)
2117 && symbol_used_p (symp
) == 0
2118 && symbol_used_in_reloc_p (symp
) == 0)
2119 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2124 /* It is required that we let write_relocs have the opportunity to
2125 optimize away fixups before output has begun, since it is possible
2126 to eliminate all fixups for a section and thus we never should
2127 have generated the relocation section. */
2130 elf_frob_file_after_relocs ()
2132 #ifdef NEED_ECOFF_DEBUG
2133 if (ECOFF_DEBUGGING
)
2134 /* Generate the ECOFF debugging information. */
2136 const struct ecoff_debug_swap
*debug_swap
;
2137 struct ecoff_debug_info debug
;
2142 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2143 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
2144 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2146 /* Set up the pointers in debug. */
2147 #define SET(ptr, offset, type) \
2148 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2150 SET (line
, cbLineOffset
, unsigned char *);
2151 SET (external_dnr
, cbDnOffset
, PTR
);
2152 SET (external_pdr
, cbPdOffset
, PTR
);
2153 SET (external_sym
, cbSymOffset
, PTR
);
2154 SET (external_opt
, cbOptOffset
, PTR
);
2155 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2156 SET (ss
, cbSsOffset
, char *);
2157 SET (external_fdr
, cbFdOffset
, PTR
);
2158 SET (external_rfd
, cbRfdOffset
, PTR
);
2159 /* ssext and external_ext are set up just below. */
2163 /* Set up the external symbols. */
2164 debug
.ssext
= debug
.ssext_end
= NULL
;
2165 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2166 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
2167 elf_get_extr
, elf_set_index
))
2168 as_fatal (_("failed to set up debugging information: %s"),
2169 bfd_errmsg (bfd_get_error ()));
2171 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2172 assert (sec
!= NULL
);
2174 know (stdoutput
->output_has_begun
== false);
2176 /* We set the size of the section, call bfd_set_section_contents
2177 to force the ELF backend to allocate a file position, and then
2178 write out the data. FIXME: Is this really the best way to do
2180 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
2182 /* Pass BUF to bfd_set_section_contents because this will
2183 eventually become a call to fwrite, and ISO C prohibits
2184 passing a NULL pointer to a stdio function even if the
2185 pointer will not be used. */
2186 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
2187 (file_ptr
) 0, (bfd_size_type
) 0))
2188 as_fatal (_("can't start writing .mdebug section: %s"),
2189 bfd_errmsg (bfd_get_error ()));
2191 know (stdoutput
->output_has_begun
== true);
2192 know (sec
->filepos
!= 0);
2194 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2196 as_fatal (_("could not write .mdebug section: %s"),
2197 bfd_errmsg (bfd_get_error ()));
2199 #endif /* NEED_ECOFF_DEBUG */
2204 /* Heavily plagarized from obj_elf_version. The idea is to emit the
2205 SCO specific identifier in the .notes section to satisfy the SCO
2208 This looks more complicated than it really is. As opposed to the
2209 "obvious" solution, this should handle the cross dev cases
2210 correctly. (i.e, hosting on a 64 bit big endian processor, but
2211 generating SCO Elf code) Efficiency isn't a concern, as there
2212 should be exactly one of these sections per object module.
2214 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2217 int_32 namesz = 4 ; Name size
2218 int_32 descsz = 12 ; Descriptive information
2220 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2221 int_32 version = (major ver # << 16) | version of tools ;
2222 int_32 source = (tool_id << 16 ) | 1 ;
2223 int_32 info = 0 ; These are set by the SCO tools, but we
2224 don't know enough about the source
2225 environment to set them. SCO ld currently
2226 ignores them, and recommends we set them
2229 #define SCO_MAJOR_VERSION 0x1
2230 #define SCO_MINOR_VERSION 0x1
2240 asection
*seg
= now_seg
;
2241 subsegT subseg
= now_subseg
;
2242 Elf_Internal_Note i_note
;
2243 Elf_External_Note e_note
;
2244 asection
*note_secp
= (asection
*) NULL
;
2247 /* create the .note section */
2249 note_secp
= subseg_new (".note", 0);
2250 bfd_set_section_flags (stdoutput
,
2252 SEC_HAS_CONTENTS
| SEC_READONLY
);
2254 /* process the version string */
2257 i_note
.descsz
= 12; /* 12 descriptive bytes */
2258 i_note
.type
= NT_VERSION
; /* Contains a version string */
2260 p
= frag_more (sizeof (i_note
.namesz
));
2261 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2263 p
= frag_more (sizeof (i_note
.descsz
));
2264 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2266 p
= frag_more (sizeof (i_note
.type
));
2267 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2272 /* Note: this is the version number of the ELF we're representing */
2274 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2276 /* Here, we pick a magic number for ourselves (yes, I "registered"
2277 it with SCO. The bottom bit shows that we are compat with the
2280 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2282 /* If we knew (or cared) what the source language options were, we'd
2283 fill them in here. SCO has given us permission to ignore these
2284 and just set them to zero. */
2286 md_number_to_chars (p
, 0x0000, 4);
2288 frag_align (2, 0, 0);
2290 /* We probably can't restore the current segment, for there likely
2293 subseg_set (seg
, subseg
);
2297 #endif /* SCO_ELF */
2300 elf_separate_stab_sections ()
2302 #ifdef NEED_ECOFF_DEBUG
2303 return (!ECOFF_DEBUGGING
);
2310 elf_init_stab_section (seg
)
2313 #ifdef NEED_ECOFF_DEBUG
2314 if (!ECOFF_DEBUGGING
)
2316 obj_elf_init_stab_section (seg
);
2319 const struct format_ops elf_format_ops
=
2321 bfd_target_elf_flavour
,
2322 0, /* dfl_leading_underscore */
2323 1, /* emit_section_symbols */
2328 elf_frob_file_before_adjust
,
2329 0, /* obj_frob_file_before_fix */
2330 elf_frob_file_after_relocs
,
2331 elf_s_get_size
, elf_s_set_size
,
2332 elf_s_get_align
, elf_s_set_align
,
2339 elf_copy_symbol_attributes
,
2340 #ifdef NEED_ECOFF_DEBUG
2341 ecoff_generate_asm_lineno
,
2344 0, /* generate_asm_lineno */
2345 0, /* process_stab */
2347 elf_separate_stab_sections
,
2348 elf_init_stab_section
,
2349 elf_sec_sym_ok_for_reloc
,
2351 #ifdef NEED_ECOFF_DEBUG
2354 0, /* ecoff_set_ext */
2356 elf_obj_read_begin_hook
,
2357 elf_obj_symbol_new_hook