1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-elf.h"
24 #include "safe-ctype.h"
27 #include "struc-symbol.h"
28 #include "dwarf2dbg.h"
30 #ifndef ECOFF_DEBUGGING
31 #define ECOFF_DEBUGGING 0
33 #define NEED_ECOFF_DEBUG
36 #ifdef NEED_ECOFF_DEBUG
41 #include "elf/alpha.h"
56 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
57 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
58 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
59 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
60 static void elf_s_set_other
PARAMS ((symbolS
*, int));
61 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
62 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
63 static void build_group_lists
PARAMS ((bfd
*, asection
*, PTR
));
64 static int elf_separate_stab_sections
PARAMS ((void));
65 static void elf_init_stab_section
PARAMS ((segT
));
66 static symbolS
*elf_common
PARAMS ((int));
68 #ifdef NEED_ECOFF_DEBUG
69 static bfd_boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
70 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
73 static void obj_elf_line
PARAMS ((int));
74 void obj_elf_version
PARAMS ((int));
75 static void obj_elf_size
PARAMS ((int));
76 static void obj_elf_type
PARAMS ((int));
77 static void obj_elf_ident
PARAMS ((int));
78 static void obj_elf_weak
PARAMS ((int));
79 static void obj_elf_local
PARAMS ((int));
80 static void obj_elf_visibility
PARAMS ((int));
81 static int obj_elf_parse_section_letters
PARAMS ((char *, size_t));
82 static int obj_elf_section_word
PARAMS ((char *, size_t));
83 static char *obj_elf_section_name
PARAMS ((void));
84 static int obj_elf_section_type
PARAMS ((char *, size_t));
85 static void obj_elf_symver
PARAMS ((int));
86 static void obj_elf_subsection
PARAMS ((int));
87 static void obj_elf_popsection
PARAMS ((int));
88 static void obj_elf_tls_common
PARAMS ((int));
90 static const pseudo_typeS elf_pseudo_table
[] =
92 {"comm", obj_elf_common
, 0},
93 {"common", obj_elf_common
, 1},
94 {"ident", obj_elf_ident
, 0},
95 {"local", obj_elf_local
, 0},
96 {"previous", obj_elf_previous
, 0},
97 {"section", obj_elf_section
, 0},
98 {"section.s", obj_elf_section
, 0},
99 {"sect", obj_elf_section
, 0},
100 {"sect.s", obj_elf_section
, 0},
101 {"pushsection", obj_elf_section
, 1},
102 {"popsection", obj_elf_popsection
, 0},
103 {"size", obj_elf_size
, 0},
104 {"type", obj_elf_type
, 0},
105 {"version", obj_elf_version
, 0},
106 {"weak", obj_elf_weak
, 0},
108 /* These define symbol visibility. */
109 {"internal", obj_elf_visibility
, STV_INTERNAL
},
110 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
111 {"protected", obj_elf_visibility
, STV_PROTECTED
},
113 /* These are used for stabs-in-elf configurations. */
114 {"line", obj_elf_line
, 0},
116 /* This is a GNU extension to handle symbol versions. */
117 {"symver", obj_elf_symver
, 0},
119 /* A GNU extension to change subsection only. */
120 {"subsection", obj_elf_subsection
, 0},
122 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
123 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
124 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
126 /* These are used for dwarf. */
130 /* These are used for dwarf2. */
131 { "file", (void (*) PARAMS ((int))) dwarf2_directive_file
, 0 },
132 { "loc", dwarf2_directive_loc
, 0 },
134 /* We need to trap the section changing calls to handle .previous. */
135 {"data", obj_elf_data
, 0},
136 {"text", obj_elf_text
, 0},
138 {"tls_common", obj_elf_tls_common
, 0},
144 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
146 #ifdef NEED_ECOFF_DEBUG
147 /* COFF style debugging information for ECOFF. .ln is not used; .loc
149 { "def", ecoff_directive_def
, 0 },
150 { "dim", ecoff_directive_dim
, 0 },
151 { "endef", ecoff_directive_endef
, 0 },
152 { "file", ecoff_directive_file
, 0 },
153 { "scl", ecoff_directive_scl
, 0 },
154 { "tag", ecoff_directive_tag
, 0 },
155 { "val", ecoff_directive_val
, 0 },
157 /* COFF debugging requires pseudo-ops .size and .type, but ELF
158 already has meanings for those. We use .esize and .etype
159 instead. These are only generated by gcc anyhow. */
160 { "esize", ecoff_directive_size
, 0 },
161 { "etype", ecoff_directive_type
, 0 },
163 /* ECOFF specific debugging information. */
164 { "begin", ecoff_directive_begin
, 0 },
165 { "bend", ecoff_directive_bend
, 0 },
166 { "end", ecoff_directive_end
, 0 },
167 { "ent", ecoff_directive_ent
, 0 },
168 { "fmask", ecoff_directive_fmask
, 0 },
169 { "frame", ecoff_directive_frame
, 0 },
170 { "loc", ecoff_directive_loc
, 0 },
171 { "mask", ecoff_directive_mask
, 0 },
173 /* Other ECOFF directives. */
174 { "extern", ecoff_directive_extern
, 0 },
176 /* These are used on Irix. I don't know how to implement them. */
177 { "alias", s_ignore
, 0 },
178 { "bgnb", s_ignore
, 0 },
179 { "endb", s_ignore
, 0 },
180 { "lab", s_ignore
, 0 },
181 { "noalias", s_ignore
, 0 },
182 { "verstamp", s_ignore
, 0 },
183 { "vreg", s_ignore
, 0 },
186 {NULL
, NULL
, 0} /* end sentinel */
190 #include "aout/aout64.h"
192 /* This is called when the assembler starts. */
197 /* Add symbols for the known sections to the symbol table. */
198 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
199 TEXT_SECTION_NAME
)));
200 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
201 DATA_SECTION_NAME
)));
202 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
209 pop_insert (elf_pseudo_table
);
211 pop_insert (ecoff_debug_pseudo_table
);
218 return S_GET_SIZE (sym
);
222 elf_s_set_size (sym
, sz
)
226 S_SET_SIZE (sym
, sz
);
230 elf_s_get_align (sym
)
233 return S_GET_ALIGN (sym
);
237 elf_s_set_align (sym
, align
)
241 S_SET_ALIGN (sym
, align
);
245 elf_s_get_other (sym
)
248 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
252 elf_s_set_other (sym
, other
)
256 S_SET_OTHER (sym
, other
);
260 elf_sec_sym_ok_for_reloc (sec
)
263 return obj_sec_sym_ok_for_reloc (sec
);
272 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
273 symbol_set_frag (sym
, &zero_address_frag
);
274 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
276 if (symbol_rootP
!= sym
)
278 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
279 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
281 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
285 #ifdef NEED_ECOFF_DEBUG
291 elf_common (is_common
)
297 offsetT temp
, size
, sign
;
302 if (flag_mri
&& is_common
)
308 name
= input_line_pointer
;
309 c
= get_symbol_end ();
310 /* just after name is now '\0' */
311 p
= input_line_pointer
;
314 if (*input_line_pointer
!= ',')
316 as_bad (_("expected comma after symbol-name"));
317 ignore_rest_of_line ();
320 input_line_pointer
++; /* skip ',' */
321 temp
= get_absolute_expr (&exp
);
322 sign
= (offsetT
) 1 << (stdoutput
->arch_info
->bits_per_address
- 1);
323 size
= temp
& ((sign
<< 1) - 1);
324 if (temp
!= size
|| !exp
.X_unsigned
)
326 as_bad (_(".COMMon length (%ld) out of range, ignored."), (long) temp
);
327 ignore_rest_of_line ();
331 symbolP
= symbol_find_or_make (name
);
333 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
335 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP
));
336 ignore_rest_of_line ();
339 if (S_GET_VALUE (symbolP
) != 0)
341 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
343 as_warn (_("length of .comm \"%s\" is already %ld; not changed to %ld"),
344 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
),
348 know (symbolP
->sy_frag
== &zero_address_frag
);
349 if (*input_line_pointer
!= ',')
354 input_line_pointer
++;
357 if (! have_align
|| *input_line_pointer
!= '"')
363 temp
= get_absolute_expr (&exp
);
367 as_warn (_("common alignment negative; 0 assumed"));
370 if (symbol_get_obj (symbolP
)->local
)
379 old_subsec
= now_subseg
;
382 /* convert to a power of 2 alignment */
383 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
386 as_bad (_("common alignment not a power of 2"));
387 ignore_rest_of_line ();
393 record_alignment (bss_section
, align
);
394 subseg_set (bss_section
, 0);
396 frag_align (align
, 0, 0);
397 if (S_GET_SEGMENT (symbolP
) == bss_section
)
398 symbol_get_frag (symbolP
)->fr_symbol
= 0;
399 symbol_set_frag (symbolP
, frag_now
);
400 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
401 (offsetT
) size
, (char *) 0);
403 S_SET_SIZE (symbolP
, size
);
404 S_SET_SEGMENT (symbolP
, bss_section
);
405 S_CLEAR_EXTERNAL (symbolP
);
406 subseg_set (old_sec
, old_subsec
);
411 S_SET_VALUE (symbolP
, (valueT
) size
);
412 S_SET_ALIGN (symbolP
, temp
);
413 S_SET_EXTERNAL (symbolP
);
414 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
419 input_line_pointer
++;
420 /* @@ Some use the dot, some don't. Can we get some consistency?? */
421 if (*input_line_pointer
== '.')
422 input_line_pointer
++;
423 /* @@ Some say data, some say bss. */
424 if (strncmp (input_line_pointer
, "bss\"", 4)
425 && strncmp (input_line_pointer
, "data\"", 5))
427 while (*--input_line_pointer
!= '"')
429 input_line_pointer
--;
430 goto bad_common_segment
;
432 while (*input_line_pointer
++ != '"')
434 goto allocate_common
;
437 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
439 demand_empty_rest_of_line ();
444 p
= input_line_pointer
;
445 while (*p
&& *p
!= '\n')
449 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
451 input_line_pointer
= p
;
452 ignore_rest_of_line ();
458 obj_elf_common (is_common
)
461 elf_common (is_common
);
465 obj_elf_tls_common (ignore
)
466 int ignore ATTRIBUTE_UNUSED
;
468 symbolS
*symbolP
= elf_common (0);
471 symbol_get_bfdsym (symbolP
)->flags
|= BSF_THREAD_LOCAL
;
475 obj_elf_local (ignore
)
476 int ignore ATTRIBUTE_UNUSED
;
484 name
= input_line_pointer
;
485 c
= get_symbol_end ();
486 symbolP
= symbol_find_or_make (name
);
487 *input_line_pointer
= c
;
489 S_CLEAR_EXTERNAL (symbolP
);
490 symbol_get_obj (symbolP
)->local
= 1;
493 input_line_pointer
++;
495 if (*input_line_pointer
== '\n')
500 demand_empty_rest_of_line ();
504 obj_elf_weak (ignore
)
505 int ignore ATTRIBUTE_UNUSED
;
513 name
= input_line_pointer
;
514 c
= get_symbol_end ();
515 symbolP
= symbol_find_or_make (name
);
516 *input_line_pointer
= c
;
518 S_SET_WEAK (symbolP
);
519 symbol_get_obj (symbolP
)->local
= 1;
522 input_line_pointer
++;
524 if (*input_line_pointer
== '\n')
529 demand_empty_rest_of_line ();
533 obj_elf_visibility (visibility
)
540 elf_symbol_type
*elfsym
;
544 name
= input_line_pointer
;
545 c
= get_symbol_end ();
546 symbolP
= symbol_find_or_make (name
);
547 *input_line_pointer
= c
;
551 bfdsym
= symbol_get_bfdsym (symbolP
);
552 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
556 elfsym
->internal_elf_sym
.st_other
&= ~3;
557 elfsym
->internal_elf_sym
.st_other
|= visibility
;
561 input_line_pointer
++;
565 if (*input_line_pointer
== '\n')
571 demand_empty_rest_of_line ();
574 static segT previous_section
;
575 static int previous_subsection
;
579 struct section_stack
*next
;
581 int subseg
, prev_subseg
;
584 static struct section_stack
*section_stack
;
586 /* Handle the .section pseudo-op. This code supports two different
589 The first is found on Solaris, and looks like
590 .section ".sec1",#alloc,#execinstr,#write
591 Here the names after '#' are the SHF_* flags to turn on for the
592 section. I'm not sure how it determines the SHT_* type (BFD
593 doesn't really give us control over the type, anyhow).
595 The second format is found on UnixWare, and probably most SVR4
596 machines, and looks like
597 .section .sec1,"a",@progbits
598 The quoted string may contain any combination of a, w, x, and
599 represents the SHF_* flags to turn on for the section. The string
600 beginning with '@' can be progbits or nobits. There should be
601 other possibilities, but I don't know what they are. In any case,
602 BFD doesn't really let us set the section type. */
605 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
)
610 const char *group_name
;
620 #ifdef md_flush_pending_output
621 md_flush_pending_output ();
624 /* Switch to the section, creating it if necessary. */
627 struct section_stack
*elt
;
628 elt
= xmalloc (sizeof (struct section_stack
));
629 elt
->next
= section_stack
;
631 elt
->prev_seg
= previous_section
;
632 elt
->subseg
= now_subseg
;
633 elt
->prev_subseg
= previous_subsection
;
636 previous_section
= now_seg
;
637 previous_subsection
= now_subseg
;
639 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
640 sec
= subseg_new (name
, 0);
642 if (_bfd_elf_get_sec_type_attr (stdoutput
, name
, &def_type
,
645 if (type
== SHT_NULL
)
647 else if (type
!= def_type
)
650 /* FIXME: gcc, as of 2002-10-22, will emit
652 .section .init_array,"aw",@progbits
654 for __attribute__ ((section (".init_array"))).
655 "@progbits" is incorrect. */
656 && def_type
!= SHT_INIT_ARRAY
657 && def_type
!= SHT_FINI_ARRAY
658 && def_type
!= SHT_PREINIT_ARRAY
)
660 /* We allow to specify any type for a .note section. */
661 if (def_type
!= SHT_NOTE
)
662 as_warn (_("setting incorrect section type for %s"),
667 as_warn (_("ignoring incorrect section type for %s"),
673 if (old_sec
== NULL
&& (attr
&~ def_attr
) != 0)
675 /* As a GNU extension, we permit a .note section to be
676 allocatable. If the linker sees an allocateable .note
677 section, it will create a PT_NOTE segment in the output
679 if (strcmp (name
, ".note") != 0 || attr
!= SHF_ALLOC
)
680 as_warn (_("setting incorrect section attributes for %s"),
686 if (type
!= SHT_NULL
)
687 elf_section_type (sec
) = type
;
689 elf_section_flags (sec
) = attr
;
691 /* Convert ELF type and flags to BFD flags. */
693 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
694 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
695 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
696 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
697 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
698 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0)
699 | ((attr
& SHF_TLS
) ? SEC_THREAD_LOCAL
: 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;
713 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
714 bfd_set_section_flags (stdoutput
, sec
, flags
);
715 if (flags
& SEC_MERGE
)
716 sec
->entsize
= entsize
;
717 elf_group_name (sec
) = group_name
;
719 /* Add a symbol for this section to the symbol table. */
720 secsym
= symbol_find (name
);
722 symbol_set_bfdsym (secsym
, sec
->symbol
);
724 symbol_table_insert (section_symbol (sec
));
728 /* If section attributes are specified the second time we see a
729 particular section, then check that they are the same as we
730 saw the first time. */
731 if (((old_sec
->flags
^ flags
)
732 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
733 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
734 | SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
735 | SEC_THREAD_LOCAL
)))
736 as_warn (_("ignoring changed section attributes for %s"), name
);
737 if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
738 as_warn (_("ignoring changed section entity size for %s"), name
);
739 if ((attr
& SHF_GROUP
) != 0
740 && strcmp (elf_group_name (old_sec
), group_name
) != 0)
741 as_warn (_("ignoring new section group for %s"), name
);
744 #ifdef md_elf_section_change_hook
745 md_elf_section_change_hook ();
750 obj_elf_parse_section_letters (str
, len
)
767 attr
|= SHF_EXECINSTR
;
783 if (*(str
- 1) == 'a')
786 if (len
> 1 && str
[1] == 's')
795 char *bad_msg
= _("unrecognized .section attribute: want a,w,x,M,S,G,T");
796 #ifdef md_elf_section_letter
797 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
802 as_fatal ("%s", bad_msg
);
813 obj_elf_section_word (str
, len
)
817 if (len
== 5 && strncmp (str
, "write", 5) == 0)
819 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
821 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
822 return SHF_EXECINSTR
;
823 if (len
== 3 && strncmp (str
, "tls", 3) == 0)
826 #ifdef md_elf_section_word
828 int md_attr
= md_elf_section_word (str
, len
);
834 as_warn (_("unrecognized section attribute"));
839 obj_elf_section_type (str
, len
)
843 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
845 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
847 if (len
== 4 && strncmp (str
, "note", 4) == 0)
850 #ifdef md_elf_section_type
852 int md_type
= md_elf_section_type (str
, len
);
858 as_warn (_("unrecognized section type"));
862 /* Get name of section. */
864 obj_elf_section_name ()
869 if (*input_line_pointer
== '"')
873 name
= demand_copy_C_string (&dummy
);
876 ignore_rest_of_line ();
882 char *end
= input_line_pointer
;
884 while (0 == strchr ("\n\t,; ", *end
))
886 if (end
== input_line_pointer
)
888 as_warn (_("missing name"));
889 ignore_rest_of_line ();
893 name
= xmalloc (end
- input_line_pointer
+ 1);
894 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
895 name
[end
- input_line_pointer
] = '\0';
896 #ifdef tc_canonicalize_section_name
897 name
= tc_canonicalize_section_name (name
);
899 input_line_pointer
= end
;
906 obj_elf_section (push
)
909 char *name
, *group_name
, *beg
;
910 int type
, attr
, dummy
;
919 #ifdef md_flush_pending_output
920 md_flush_pending_output ();
923 previous_section
= now_seg
;
924 previous_subsection
= now_subseg
;
926 s_mri_sect (&mri_type
);
928 #ifdef md_elf_section_change_hook
929 md_elf_section_change_hook ();
934 #endif /* ! defined (TC_I370) */
936 name
= obj_elf_section_name ();
945 if (*input_line_pointer
== ',')
947 /* Skip the comma. */
948 ++input_line_pointer
;
951 if (*input_line_pointer
== '"')
953 beg
= demand_copy_C_string (&dummy
);
956 ignore_rest_of_line ();
959 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
962 if (*input_line_pointer
== ',')
965 char *save
= input_line_pointer
;
967 ++input_line_pointer
;
969 c
= *input_line_pointer
;
972 beg
= demand_copy_C_string (&dummy
);
975 ignore_rest_of_line ();
978 type
= obj_elf_section_type (beg
, strlen (beg
));
980 else if (c
== '@' || c
== '%')
982 beg
= ++input_line_pointer
;
983 c
= get_symbol_end ();
984 *input_line_pointer
= c
;
985 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
988 input_line_pointer
= save
;
992 if ((attr
& SHF_MERGE
) != 0 && *input_line_pointer
== ',')
994 ++input_line_pointer
;
996 entsize
= get_absolute_expression ();
1000 as_warn (_("invalid merge entity size"));
1005 else if ((attr
& SHF_MERGE
) != 0)
1007 as_warn (_("entity size for SHF_MERGE not specified"));
1011 if ((attr
& SHF_GROUP
) != 0 && *input_line_pointer
== ',')
1013 ++input_line_pointer
;
1014 group_name
= obj_elf_section_name ();
1015 if (group_name
== NULL
)
1017 else if (strncmp (input_line_pointer
, ",comdat", 7) == 0)
1019 input_line_pointer
+= 7;
1022 else if (strncmp (name
, ".gnu.linkonce", 13) == 0)
1025 else if ((attr
& SHF_GROUP
) != 0)
1027 as_warn (_("group name for SHF_GROUP not specified"));
1038 if (*input_line_pointer
!= '#')
1040 as_warn (_("character following name is not '#'"));
1041 ignore_rest_of_line ();
1044 beg
= ++input_line_pointer
;
1045 c
= get_symbol_end ();
1046 *input_line_pointer
= c
;
1048 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
1052 while (*input_line_pointer
++ == ',');
1053 --input_line_pointer
;
1057 demand_empty_rest_of_line ();
1059 obj_elf_change_section (name
, type
, attr
, entsize
, group_name
, linkonce
, push
);
1062 /* Change to the .data section. */
1068 #ifdef md_flush_pending_output
1069 md_flush_pending_output ();
1072 previous_section
= now_seg
;
1073 previous_subsection
= now_subseg
;
1076 #ifdef md_elf_section_change_hook
1077 md_elf_section_change_hook ();
1081 /* Change to the .text section. */
1087 #ifdef md_flush_pending_output
1088 md_flush_pending_output ();
1091 previous_section
= now_seg
;
1092 previous_subsection
= now_subseg
;
1095 #ifdef md_elf_section_change_hook
1096 md_elf_section_change_hook ();
1101 obj_elf_subsection (ignore
)
1102 int ignore ATTRIBUTE_UNUSED
;
1106 #ifdef md_flush_pending_output
1107 md_flush_pending_output ();
1110 previous_section
= now_seg
;
1111 previous_subsection
= now_subseg
;
1113 temp
= get_absolute_expression ();
1114 subseg_set (now_seg
, (subsegT
) temp
);
1115 demand_empty_rest_of_line ();
1117 #ifdef md_elf_section_change_hook
1118 md_elf_section_change_hook ();
1122 /* This can be called from the processor backends if they change
1126 obj_elf_section_change_hook ()
1128 previous_section
= now_seg
;
1129 previous_subsection
= now_subseg
;
1133 obj_elf_previous (ignore
)
1134 int ignore ATTRIBUTE_UNUSED
;
1139 if (previous_section
== 0)
1141 as_warn (_(".previous without corresponding .section; ignored"));
1145 #ifdef md_flush_pending_output
1146 md_flush_pending_output ();
1149 new_section
= previous_section
;
1150 new_subsection
= previous_subsection
;
1151 previous_section
= now_seg
;
1152 previous_subsection
= now_subseg
;
1153 subseg_set (new_section
, new_subsection
);
1155 #ifdef md_elf_section_change_hook
1156 md_elf_section_change_hook ();
1161 obj_elf_popsection (xxx
)
1162 int xxx ATTRIBUTE_UNUSED
;
1164 struct section_stack
*top
= section_stack
;
1168 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1172 #ifdef md_flush_pending_output
1173 md_flush_pending_output ();
1176 section_stack
= top
->next
;
1177 previous_section
= top
->prev_seg
;
1178 previous_subsection
= top
->prev_subseg
;
1179 subseg_set (top
->seg
, top
->subseg
);
1182 #ifdef md_elf_section_change_hook
1183 md_elf_section_change_hook ();
1188 obj_elf_line (ignore
)
1189 int ignore ATTRIBUTE_UNUSED
;
1191 /* Assume delimiter is part of expression. BSD4.2 as fails with
1192 delightful bug, so we are not being incompatible here. */
1193 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1194 demand_empty_rest_of_line ();
1197 /* This handles the .symver pseudo-op, which is used to specify a
1198 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1199 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1200 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1201 with the same value as the symbol NAME. */
1204 obj_elf_symver (ignore
)
1205 int ignore ATTRIBUTE_UNUSED
;
1212 name
= input_line_pointer
;
1213 c
= get_symbol_end ();
1215 sym
= symbol_find_or_make (name
);
1217 *input_line_pointer
= c
;
1220 if (*input_line_pointer
!= ',')
1222 as_bad (_("expected comma after name in .symver"));
1223 ignore_rest_of_line ();
1227 ++input_line_pointer
;
1229 name
= input_line_pointer
;
1231 /* Temporarily include '@' in symbol names. */
1232 old_lexat
= lex_type
[(unsigned char) '@'];
1233 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1234 c
= get_symbol_end ();
1235 lex_type
[(unsigned char) '@'] = old_lexat
;
1237 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1239 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1241 *input_line_pointer
= c
;
1243 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1244 ELF_VER_CHR
) == NULL
)
1246 as_bad (_("missing version name in `%s' for symbol `%s'"),
1247 symbol_get_obj (sym
)->versioned_name
,
1249 ignore_rest_of_line ();
1255 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1257 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1258 name
, symbol_get_obj (sym
)->versioned_name
,
1260 ignore_rest_of_line ();
1264 *input_line_pointer
= c
;
1267 demand_empty_rest_of_line ();
1270 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1271 to the linker the hierarchy in which a particular table resides. The
1272 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1275 obj_elf_vtable_inherit (ignore
)
1276 int ignore ATTRIBUTE_UNUSED
;
1278 char *cname
, *pname
;
1279 symbolS
*csym
, *psym
;
1282 if (*input_line_pointer
== '#')
1283 ++input_line_pointer
;
1285 cname
= input_line_pointer
;
1286 c
= get_symbol_end ();
1287 csym
= symbol_find (cname
);
1289 /* GCFIXME: should check that we don't have two .vtable_inherits for
1290 the same child symbol. Also, we can currently only do this if the
1291 child symbol is already exists and is placed in a fragment. */
1293 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1295 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1300 *input_line_pointer
= c
;
1303 if (*input_line_pointer
!= ',')
1305 as_bad ("expected comma after name in .vtable_inherit");
1306 ignore_rest_of_line ();
1310 ++input_line_pointer
;
1313 if (*input_line_pointer
== '#')
1314 ++input_line_pointer
;
1316 if (input_line_pointer
[0] == '0'
1317 && (input_line_pointer
[1] == '\0'
1318 || ISSPACE (input_line_pointer
[1])))
1320 psym
= section_symbol (absolute_section
);
1321 ++input_line_pointer
;
1325 pname
= input_line_pointer
;
1326 c
= get_symbol_end ();
1327 psym
= symbol_find_or_make (pname
);
1328 *input_line_pointer
= c
;
1331 demand_empty_rest_of_line ();
1336 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1337 return fix_new (symbol_get_frag (csym
),
1338 symbol_get_value_expression (csym
)->X_add_number
,
1339 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1342 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1343 to the linker that a vtable slot was used. The syntax is
1344 ".vtable_entry tablename, offset". */
1347 obj_elf_vtable_entry (ignore
)
1348 int ignore ATTRIBUTE_UNUSED
;
1355 if (*input_line_pointer
== '#')
1356 ++input_line_pointer
;
1358 name
= input_line_pointer
;
1359 c
= get_symbol_end ();
1360 sym
= symbol_find_or_make (name
);
1361 *input_line_pointer
= c
;
1364 if (*input_line_pointer
!= ',')
1366 as_bad ("expected comma after name in .vtable_entry");
1367 ignore_rest_of_line ();
1371 ++input_line_pointer
;
1372 if (*input_line_pointer
== '#')
1373 ++input_line_pointer
;
1375 offset
= get_absolute_expression ();
1377 demand_empty_rest_of_line ();
1379 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1380 BFD_RELOC_VTABLE_ENTRY
);
1384 elf_obj_read_begin_hook ()
1386 #ifdef NEED_ECOFF_DEBUG
1387 if (ECOFF_DEBUGGING
)
1388 ecoff_read_begin_hook ();
1393 elf_obj_symbol_new_hook (symbolP
)
1396 struct elf_obj_sy
*sy_obj
;
1398 sy_obj
= symbol_get_obj (symbolP
);
1399 sy_obj
->size
= NULL
;
1400 sy_obj
->versioned_name
= NULL
;
1402 #ifdef NEED_ECOFF_DEBUG
1403 if (ECOFF_DEBUGGING
)
1404 ecoff_symbol_new_hook (symbolP
);
1408 /* When setting one symbol equal to another, by default we probably
1409 want them to have the same "size", whatever it means in the current
1413 elf_copy_symbol_attributes (dest
, src
)
1414 symbolS
*dest
, *src
;
1416 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1417 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1420 if (destelf
->size
== NULL
)
1422 (expressionS
*) xmalloc (sizeof (expressionS
));
1423 *destelf
->size
= *srcelf
->size
;
1427 if (destelf
->size
!= NULL
)
1428 free (destelf
->size
);
1429 destelf
->size
= NULL
;
1431 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1432 /* Don't copy visibility. */
1433 S_SET_OTHER (dest
, (ELF_ST_VISIBILITY (S_GET_OTHER (dest
))
1434 | (S_GET_OTHER (src
) & ~ELF_ST_VISIBILITY (-1))));
1438 obj_elf_version (ignore
)
1439 int ignore ATTRIBUTE_UNUSED
;
1444 asection
*seg
= now_seg
;
1445 subsegT subseg
= now_subseg
;
1446 Elf_Internal_Note i_note
;
1447 Elf_External_Note e_note
;
1448 asection
*note_secp
= (asection
*) NULL
;
1452 if (*input_line_pointer
== '\"')
1454 ++input_line_pointer
; /* -> 1st char of string. */
1455 name
= input_line_pointer
;
1457 while (is_a_char (c
= next_char_of_string ()))
1459 c
= *input_line_pointer
;
1460 *input_line_pointer
= '\0';
1461 *(input_line_pointer
- 1) = '\0';
1462 *input_line_pointer
= c
;
1464 /* create the .note section */
1466 note_secp
= subseg_new (".note", 0);
1467 bfd_set_section_flags (stdoutput
,
1469 SEC_HAS_CONTENTS
| SEC_READONLY
);
1471 /* process the version string */
1473 len
= strlen (name
);
1475 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1476 i_note
.descsz
= 0; /* no description */
1477 i_note
.type
= NT_VERSION
;
1478 p
= frag_more (sizeof (e_note
.namesz
));
1479 md_number_to_chars (p
, (valueT
) i_note
.namesz
, sizeof (e_note
.namesz
));
1480 p
= frag_more (sizeof (e_note
.descsz
));
1481 md_number_to_chars (p
, (valueT
) i_note
.descsz
, sizeof (e_note
.descsz
));
1482 p
= frag_more (sizeof (e_note
.type
));
1483 md_number_to_chars (p
, (valueT
) i_note
.type
, sizeof (e_note
.type
));
1484 p
= frag_more (len
+ 1);
1487 frag_align (2, 0, 0);
1489 subseg_set (seg
, subseg
);
1493 as_bad (_("expected quoted string"));
1495 demand_empty_rest_of_line ();
1499 obj_elf_size (ignore
)
1500 int ignore ATTRIBUTE_UNUSED
;
1502 char *name
= input_line_pointer
;
1503 char c
= get_symbol_end ();
1508 p
= input_line_pointer
;
1511 if (*input_line_pointer
!= ',')
1514 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1516 ignore_rest_of_line ();
1519 input_line_pointer
++;
1521 if (exp
.X_op
== O_absent
)
1523 as_bad (_("missing expression in .size directive"));
1524 exp
.X_op
= O_constant
;
1525 exp
.X_add_number
= 0;
1528 sym
= symbol_find_or_make (name
);
1530 if (exp
.X_op
== O_constant
)
1532 S_SET_SIZE (sym
, exp
.X_add_number
);
1533 if (symbol_get_obj (sym
)->size
)
1535 xfree (symbol_get_obj (sym
)->size
);
1536 symbol_get_obj (sym
)->size
= NULL
;
1541 symbol_get_obj (sym
)->size
=
1542 (expressionS
*) xmalloc (sizeof (expressionS
));
1543 *symbol_get_obj (sym
)->size
= exp
;
1545 demand_empty_rest_of_line ();
1548 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1549 There are five syntaxes:
1551 The first (used on Solaris) is
1553 The second (used on UnixWare) is
1555 The third (reportedly to be used on Irix 6.0) is
1557 The fourth (used on NetBSD/Arm and Linux/ARM) is
1559 The fifth (used on SVR4/860) is
1560 .type SYM,"function"
1564 obj_elf_type (ignore
)
1565 int ignore ATTRIBUTE_UNUSED
;
1570 const char *typename
;
1572 elf_symbol_type
*elfsym
;
1574 name
= input_line_pointer
;
1575 c
= get_symbol_end ();
1576 sym
= symbol_find_or_make (name
);
1577 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1578 *input_line_pointer
= c
;
1581 if (*input_line_pointer
== ',')
1582 ++input_line_pointer
;
1585 if ( *input_line_pointer
== '#'
1586 || *input_line_pointer
== '@'
1587 || *input_line_pointer
== '"'
1588 || *input_line_pointer
== '%')
1589 ++input_line_pointer
;
1591 typename
= input_line_pointer
;
1592 c
= get_symbol_end ();
1595 if (strcmp (typename
, "function") == 0
1596 || strcmp (typename
, "STT_FUNC") == 0)
1597 type
= BSF_FUNCTION
;
1598 else if (strcmp (typename
, "object") == 0
1599 || strcmp (typename
, "STT_OBJECT") == 0)
1601 else if (strcmp (typename
, "tls_object") == 0
1602 || strcmp (typename
, "STT_TLS") == 0)
1603 type
= BSF_OBJECT
| BSF_THREAD_LOCAL
;
1604 else if (strcmp (typename
, "notype") == 0
1605 || strcmp (typename
, "STT_NOTYPE") == 0)
1607 #ifdef md_elf_symbol_type
1608 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1612 as_bad (_("unrecognized symbol type \"%s\""), typename
);
1614 *input_line_pointer
= c
;
1616 if (*input_line_pointer
== '"')
1617 ++input_line_pointer
;
1619 elfsym
->symbol
.flags
|= type
;
1621 demand_empty_rest_of_line ();
1625 obj_elf_ident (ignore
)
1626 int ignore ATTRIBUTE_UNUSED
;
1628 static segT comment_section
;
1629 segT old_section
= now_seg
;
1630 int old_subsection
= now_subseg
;
1632 #ifdef md_flush_pending_output
1633 md_flush_pending_output ();
1636 if (!comment_section
)
1639 comment_section
= subseg_new (".comment", 0);
1640 bfd_set_section_flags (stdoutput
, comment_section
,
1641 SEC_READONLY
| SEC_HAS_CONTENTS
);
1646 subseg_set (comment_section
, 0);
1648 subseg_set (old_section
, old_subsection
);
1651 #ifdef INIT_STAB_SECTION
1653 /* The first entry in a .stabs section is special. */
1656 obj_elf_init_stab_section (seg
)
1662 unsigned int stroff
;
1664 /* Force the section to align to a longword boundary. Without this,
1665 UnixWare ar crashes. */
1666 bfd_set_section_alignment (stdoutput
, seg
, 2);
1668 /* Make space for this first symbol. */
1672 as_where (&file
, (unsigned int *) NULL
);
1673 stabstr_name
= (char *) xmalloc (strlen (segment_name (seg
)) + 4);
1674 strcpy (stabstr_name
, segment_name (seg
));
1675 strcat (stabstr_name
, "str");
1676 stroff
= get_stab_string_offset (file
, stabstr_name
);
1678 md_number_to_chars (p
, stroff
, 4);
1679 seg_info (seg
)->stabu
.p
= p
;
1684 /* Fill in the counts in the first entry in a .stabs section. */
1687 adjust_stab_sections (abfd
, sec
, xxx
)
1690 PTR xxx ATTRIBUTE_UNUSED
;
1697 if (strncmp (".stab", sec
->name
, 5))
1699 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1702 name
= (char *) alloca (strlen (sec
->name
) + 4);
1703 strcpy (name
, sec
->name
);
1704 strcat (name
, "str");
1705 strsec
= bfd_get_section_by_name (abfd
, name
);
1707 strsz
= bfd_section_size (abfd
, strsec
);
1710 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1712 p
= seg_info (sec
)->stabu
.p
;
1715 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1716 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1719 #ifdef NEED_ECOFF_DEBUG
1721 /* This function is called by the ECOFF code. It is supposed to
1722 record the external symbol information so that the backend can
1723 write it out correctly. The ELF backend doesn't actually handle
1724 this at the moment, so we do it ourselves. We save the information
1728 elf_ecoff_set_ext (sym
, ext
)
1730 struct ecoff_extr
*ext
;
1732 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1735 /* This function is called by bfd_ecoff_debug_externals. It is
1736 supposed to *EXT to the external symbol information, and return
1737 whether the symbol should be used at all. */
1740 elf_get_extr (sym
, ext
)
1744 if (sym
->udata
.p
== NULL
)
1746 *ext
= *(EXTR
*) sym
->udata
.p
;
1750 /* This function is called by bfd_ecoff_debug_externals. It has
1751 nothing to do for ELF. */
1755 elf_set_index (sym
, indx
)
1756 asymbol
*sym ATTRIBUTE_UNUSED
;
1757 bfd_size_type indx ATTRIBUTE_UNUSED
;
1761 #endif /* NEED_ECOFF_DEBUG */
1764 elf_frob_symbol (symp
, puntp
)
1768 struct elf_obj_sy
*sy_obj
;
1770 #ifdef NEED_ECOFF_DEBUG
1771 if (ECOFF_DEBUGGING
)
1772 ecoff_frob_symbol (symp
);
1775 sy_obj
= symbol_get_obj (symp
);
1777 if (sy_obj
->size
!= NULL
)
1779 switch (sy_obj
->size
->X_op
)
1783 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1784 + sy_obj
->size
->X_add_number
1785 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1789 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1790 + sy_obj
->size
->X_add_number
));
1793 as_bad (_(".size expression too complicated to fix up"));
1796 free (sy_obj
->size
);
1797 sy_obj
->size
= NULL
;
1800 if (sy_obj
->versioned_name
!= NULL
)
1804 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1807 /* This symbol was given a new name with the .symver directive.
1809 If this is an external reference, just rename the symbol to
1810 include the version string. This will make the relocs be
1811 against the correct versioned symbol.
1813 If this is a definition, add an alias. FIXME: Using an alias
1814 will permit the debugging information to refer to the right
1815 symbol. However, it's not clear whether it is the best
1818 if (! S_IS_DEFINED (symp
))
1820 /* Verify that the name isn't using the @@ syntax--this is
1821 reserved for definitions of the default version to link
1823 if (p
[1] == ELF_VER_CHR
)
1825 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1826 sy_obj
->versioned_name
);
1829 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1833 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1837 /* The @@@ syntax is a special case. It renames the
1838 symbol name to versioned_name with one `@' removed. */
1839 l
= strlen (&p
[3]) + 1;
1840 memmove (&p
[2], &p
[3], l
);
1841 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1847 /* FIXME: Creating a new symbol here is risky. We're
1848 in the final loop over the symbol table. We can
1849 get away with it only because the symbol goes to
1850 the end of the list, where the loop will still see
1851 it. It would probably be better to do this in
1852 obj_frob_file_before_adjust. */
1854 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1856 /* Now we act as though we saw symp2 = sym. */
1858 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1860 /* Subtracting out the frag address here is a hack
1861 because we are in the middle of the final loop. */
1864 - symbol_get_frag (symp
)->fr_address
));
1866 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1868 /* This will copy over the size information. */
1869 copy_symbol_attributes (symp2
, symp
);
1871 S_SET_OTHER (symp2
, S_GET_OTHER (symp
));
1873 if (S_IS_WEAK (symp
))
1876 if (S_IS_EXTERNAL (symp
))
1877 S_SET_EXTERNAL (symp2
);
1882 /* Double check weak symbols. */
1883 if (S_IS_WEAK (symp
))
1885 if (S_IS_COMMON (symp
))
1886 as_bad (_("symbol `%s' can not be both weak and common"),
1891 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1892 any undefined non-function symbol to STT_OBJECT. We try to be
1893 compatible, since newer Irix 5 and 6 linkers care. However, we
1894 only set undefined symbols to be STT_OBJECT if we are on Irix,
1895 because that is the only time gcc will generate the necessary
1896 .global directives to mark functions. */
1898 if (S_IS_COMMON (symp
))
1899 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1901 if (strstr (TARGET_OS
, "irix") != NULL
1902 && ! S_IS_DEFINED (symp
)
1903 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1904 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1908 /* If TC_PPC is defined, we used to force the type of a symbol to be
1909 BSF_OBJECT if it was otherwise unset. This was required by some
1910 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1911 that this is no longer needed, so it is now commented out. */
1912 if ((symbol_get_bfdsym (symp
)->flags
1913 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1914 && S_IS_DEFINED (symp
))
1915 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1921 asection
**head
; /* Section lists. */
1922 unsigned int *elt_count
; /* Number of sections in each list. */
1923 unsigned int num_group
; /* Number of lists. */
1926 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1927 add it to a list of sections belonging to the group. INF is a
1928 pointer to a struct group_list, which is where we store the head of
1932 build_group_lists (abfd
, sec
, inf
)
1933 bfd
*abfd ATTRIBUTE_UNUSED
;
1937 struct group_list
*list
= (struct group_list
*) inf
;
1938 const char *group_name
= elf_group_name (sec
);
1941 if (group_name
== NULL
)
1944 /* If this group already has a list, add the section to the head of
1946 for (i
= 0; i
< list
->num_group
; i
++)
1948 if (strcmp (group_name
, elf_group_name (list
->head
[i
])) == 0)
1950 elf_next_in_group (sec
) = list
->head
[i
];
1951 list
->head
[i
] = sec
;
1952 list
->elt_count
[i
] += 1;
1957 /* New group. Make the arrays bigger in chunks to minimize calls to
1959 i
= list
->num_group
;
1962 unsigned int newsize
= i
+ 128;
1963 list
->head
= xrealloc (list
->head
, newsize
* sizeof (*list
->head
));
1964 list
->elt_count
= xrealloc (list
->elt_count
,
1965 newsize
* sizeof (*list
->elt_count
));
1967 list
->head
[i
] = sec
;
1968 list
->elt_count
[i
] = 1;
1969 list
->num_group
+= 1;
1975 struct group_list list
;
1978 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1980 /* Go find section groups. */
1983 list
.elt_count
= NULL
;
1984 bfd_map_over_sections (stdoutput
, build_group_lists
, (PTR
) &list
);
1986 /* Make the SHT_GROUP sections that describe each section group. We
1987 can't set up the section contents here yet, because elf section
1988 indices have yet to be calculated. elf.c:set_group_contents does
1989 the rest of the work. */
1990 for (i
= 0; i
< list
.num_group
; i
++)
1992 const char *group_name
= elf_group_name (list
.head
[i
]);
1993 const char *sec_name
;
1999 flags
= SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_GROUP
;
2000 for (s
= list
.head
[i
]; s
!= NULL
; s
= elf_next_in_group (s
))
2001 if ((s
->flags
^ flags
) & SEC_LINK_ONCE
)
2003 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
2004 if (s
!= list
.head
[i
])
2006 as_warn (_("assuming all members of group `%s' are COMDAT"),
2012 sec_name
= group_name
;
2013 sy
= symbol_find_exact (group_name
);
2016 && (sy
== symbol_lastP
2017 || (sy
->sy_next
!= NULL
2018 && sy
->sy_next
->sy_previous
== sy
)))
2021 sec_name
= ".group";
2023 s
= subseg_force_new (sec_name
, 0);
2025 || !bfd_set_section_flags (stdoutput
, s
, flags
)
2026 || !bfd_set_section_alignment (stdoutput
, s
, 2))
2028 as_fatal (_("can't create group: %s"),
2029 bfd_errmsg (bfd_get_error ()));
2031 elf_section_type (s
) = SHT_GROUP
;
2033 /* Pass a pointer to the first section in this group. */
2034 elf_next_in_group (s
) = list
.head
[i
];
2036 elf_group_id (s
) = sy
->bsym
;
2038 s
->_raw_size
= 4 * (list
.elt_count
[i
] + 1);
2039 s
->contents
= frag_more (s
->_raw_size
);
2040 frag_now
->fr_fix
= frag_now_fix_octets ();
2043 #ifdef elf_tc_final_processing
2044 elf_tc_final_processing ();
2048 /* It removes any unneeded versioned symbols from the symbol table. */
2051 elf_frob_file_before_adjust ()
2057 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2058 if (!S_IS_DEFINED (symp
))
2060 if (symbol_get_obj (symp
)->versioned_name
)
2064 /* The @@@ syntax is a special case. If the symbol is
2065 not defined, 2 `@'s will be removed from the
2068 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
2071 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
2073 size_t l
= strlen (&p
[3]) + 1;
2074 memmove (&p
[1], &p
[3], l
);
2076 if (symbol_used_p (symp
) == 0
2077 && symbol_used_in_reloc_p (symp
) == 0)
2078 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2081 /* If there was .weak foo, but foo was neither defined nor
2082 used anywhere, remove it. */
2084 else if (S_IS_WEAK (symp
)
2085 && symbol_used_p (symp
) == 0
2086 && symbol_used_in_reloc_p (symp
) == 0)
2087 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2092 /* It is required that we let write_relocs have the opportunity to
2093 optimize away fixups before output has begun, since it is possible
2094 to eliminate all fixups for a section and thus we never should
2095 have generated the relocation section. */
2098 elf_frob_file_after_relocs ()
2100 #ifdef NEED_ECOFF_DEBUG
2101 if (ECOFF_DEBUGGING
)
2102 /* Generate the ECOFF debugging information. */
2104 const struct ecoff_debug_swap
*debug_swap
;
2105 struct ecoff_debug_info debug
;
2110 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
2111 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
2112 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
2114 /* Set up the pointers in debug. */
2115 #define SET(ptr, offset, type) \
2116 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2118 SET (line
, cbLineOffset
, unsigned char *);
2119 SET (external_dnr
, cbDnOffset
, PTR
);
2120 SET (external_pdr
, cbPdOffset
, PTR
);
2121 SET (external_sym
, cbSymOffset
, PTR
);
2122 SET (external_opt
, cbOptOffset
, PTR
);
2123 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
2124 SET (ss
, cbSsOffset
, char *);
2125 SET (external_fdr
, cbFdOffset
, PTR
);
2126 SET (external_rfd
, cbRfdOffset
, PTR
);
2127 /* ssext and external_ext are set up just below. */
2131 /* Set up the external symbols. */
2132 debug
.ssext
= debug
.ssext_end
= NULL
;
2133 debug
.external_ext
= debug
.external_ext_end
= NULL
;
2134 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, TRUE
,
2135 elf_get_extr
, elf_set_index
))
2136 as_fatal (_("failed to set up debugging information: %s"),
2137 bfd_errmsg (bfd_get_error ()));
2139 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
2140 assert (sec
!= NULL
);
2142 know (!stdoutput
->output_has_begun
);
2144 /* We set the size of the section, call bfd_set_section_contents
2145 to force the ELF backend to allocate a file position, and then
2146 write out the data. FIXME: Is this really the best way to do
2148 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
2150 /* Pass BUF to bfd_set_section_contents because this will
2151 eventually become a call to fwrite, and ISO C prohibits
2152 passing a NULL pointer to a stdio function even if the
2153 pointer will not be used. */
2154 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
2155 (file_ptr
) 0, (bfd_size_type
) 0))
2156 as_fatal (_("can't start writing .mdebug section: %s"),
2157 bfd_errmsg (bfd_get_error ()));
2159 know (stdoutput
->output_has_begun
);
2160 know (sec
->filepos
!= 0);
2162 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
2164 as_fatal (_("could not write .mdebug section: %s"),
2165 bfd_errmsg (bfd_get_error ()));
2167 #endif /* NEED_ECOFF_DEBUG */
2172 /* Heavily plagarized from obj_elf_version. The idea is to emit the
2173 SCO specific identifier in the .notes section to satisfy the SCO
2176 This looks more complicated than it really is. As opposed to the
2177 "obvious" solution, this should handle the cross dev cases
2178 correctly. (i.e, hosting on a 64 bit big endian processor, but
2179 generating SCO Elf code) Efficiency isn't a concern, as there
2180 should be exactly one of these sections per object module.
2182 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2185 int_32 namesz = 4 ; Name size
2186 int_32 descsz = 12 ; Descriptive information
2188 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2189 int_32 version = (major ver # << 16) | version of tools ;
2190 int_32 source = (tool_id << 16 ) | 1 ;
2191 int_32 info = 0 ; These are set by the SCO tools, but we
2192 don't know enough about the source
2193 environment to set them. SCO ld currently
2194 ignores them, and recommends we set them
2197 #define SCO_MAJOR_VERSION 0x1
2198 #define SCO_MINOR_VERSION 0x1
2208 asection
*seg
= now_seg
;
2209 subsegT subseg
= now_subseg
;
2210 Elf_Internal_Note i_note
;
2211 Elf_External_Note e_note
;
2212 asection
*note_secp
= (asection
*) NULL
;
2215 /* create the .note section */
2217 note_secp
= subseg_new (".note", 0);
2218 bfd_set_section_flags (stdoutput
,
2220 SEC_HAS_CONTENTS
| SEC_READONLY
);
2222 /* process the version string */
2225 i_note
.descsz
= 12; /* 12 descriptive bytes */
2226 i_note
.type
= NT_VERSION
; /* Contains a version string */
2228 p
= frag_more (sizeof (i_note
.namesz
));
2229 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2231 p
= frag_more (sizeof (i_note
.descsz
));
2232 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2234 p
= frag_more (sizeof (i_note
.type
));
2235 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2240 /* Note: this is the version number of the ELF we're representing */
2242 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2244 /* Here, we pick a magic number for ourselves (yes, I "registered"
2245 it with SCO. The bottom bit shows that we are compat with the
2248 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2250 /* If we knew (or cared) what the source language options were, we'd
2251 fill them in here. SCO has given us permission to ignore these
2252 and just set them to zero. */
2254 md_number_to_chars (p
, 0x0000, 4);
2256 frag_align (2, 0, 0);
2258 /* We probably can't restore the current segment, for there likely
2261 subseg_set (seg
, subseg
);
2265 #endif /* SCO_ELF */
2268 elf_separate_stab_sections ()
2270 #ifdef NEED_ECOFF_DEBUG
2271 return (!ECOFF_DEBUGGING
);
2278 elf_init_stab_section (seg
)
2281 #ifdef NEED_ECOFF_DEBUG
2282 if (!ECOFF_DEBUGGING
)
2284 obj_elf_init_stab_section (seg
);
2287 const struct format_ops elf_format_ops
=
2289 bfd_target_elf_flavour
,
2290 0, /* dfl_leading_underscore */
2291 1, /* emit_section_symbols */
2296 elf_frob_file_before_adjust
,
2297 0, /* obj_frob_file_before_fix */
2298 elf_frob_file_after_relocs
,
2299 elf_s_get_size
, elf_s_set_size
,
2300 elf_s_get_align
, elf_s_set_align
,
2307 elf_copy_symbol_attributes
,
2308 #ifdef NEED_ECOFF_DEBUG
2309 ecoff_generate_asm_lineno
,
2312 0, /* generate_asm_lineno */
2313 0, /* process_stab */
2315 elf_separate_stab_sections
,
2316 elf_init_stab_section
,
2317 elf_sec_sym_ok_for_reloc
,
2319 #ifdef NEED_ECOFF_DEBUG
2322 0, /* ecoff_set_ext */
2324 elf_obj_read_begin_hook
,
2325 elf_obj_symbol_new_hook