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"
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 bfd_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)
293 offsetT temp, size, sign;
298 if (flag_mri && is_common)
304 name = input_line_pointer;
305 c = get_symbol_end ();
306 /* just after name is now '\0' */
307 p = input_line_pointer;
310 if (*input_line_pointer != ',')
312 as_bad (_("expected comma after symbol-name"));
313 ignore_rest_of_line ();
316 input_line_pointer++; /* skip ',' */
317 temp = get_absolute_expr (&exp);
318 sign = (offsetT) 1 << (stdoutput->arch_info->bits_per_address - 1);
319 size = temp & ((sign << 1) - 1);
320 if (temp != size || !exp.X_unsigned)
322 as_bad (_(".COMMon length (%ld) out of range, ignored."), (long) temp);
323 ignore_rest_of_line ();
327 symbolP = symbol_find_or_make (name);
329 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
331 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
332 ignore_rest_of_line ();
335 if (S_GET_VALUE (symbolP) != 0)
337 if (S_GET_VALUE (symbolP) != (valueT) size)
339 as_warn (_("length of .comm \"%s\" is already %ld; not changed to %ld"),
340 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP),
344 know (symbolP->sy_frag == &zero_address_frag);
345 if (*input_line_pointer != ',')
350 input_line_pointer++;
353 if (! have_align || *input_line_pointer != '"')
359 temp = get_absolute_expr (&exp);
363 as_warn (_("common alignment negative; 0 assumed"));
366 if (symbol_get_obj (symbolP)->local)
375 old_subsec = now_subseg;
378 /* convert to a power of 2 alignment */
379 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
382 as_bad (_("common alignment not a power of 2"));
383 ignore_rest_of_line ();
389 record_alignment (bss_section, align);
390 subseg_set (bss_section, 0);
392 frag_align (align, 0, 0);
393 if (S_GET_SEGMENT (symbolP) == bss_section)
394 symbol_get_frag (symbolP)->fr_symbol = 0;
395 symbol_set_frag (symbolP, frag_now);
396 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
397 (offsetT) size, (char *) 0);
399 S_SET_SIZE (symbolP, size);
400 S_SET_SEGMENT (symbolP, bss_section);
401 S_CLEAR_EXTERNAL (symbolP);
402 subseg_set (old_sec, old_subsec);
407 S_SET_VALUE (symbolP, (valueT) size);
408 S_SET_ALIGN (symbolP, temp);
409 S_SET_EXTERNAL (symbolP);
410 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
415 input_line_pointer++;
416 /* @@ Some use the dot, some don't. Can we get some consistency?? */
417 if (*input_line_pointer == '.')
418 input_line_pointer++;
419 /* @@ Some say data, some say bss. */
420 if (strncmp (input_line_pointer, "bss\"", 4)
421 && strncmp (input_line_pointer, "data\"", 5))
423 while (*--input_line_pointer != '"')
425 input_line_pointer--;
426 goto bad_common_segment;
428 while (*input_line_pointer++ != '"')
430 goto allocate_common;
433 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
435 demand_empty_rest_of_line ();
440 p = input_line_pointer;
441 while (*p && *p != '\n')
445 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
447 input_line_pointer = p;
448 ignore_rest_of_line ();
454 obj_elf_common (is_common)
457 elf_common (is_common);
461 obj_elf_tls_common (ignore)
462 int ignore ATTRIBUTE_UNUSED;
464 symbolS *symbolP = elf_common (0);
467 symbol_get_bfdsym (symbolP)->flags |= BSF_THREAD_LOCAL;
471 obj_elf_local (ignore)
472 int ignore ATTRIBUTE_UNUSED;
480 name = input_line_pointer;
481 c = get_symbol_end ();
482 symbolP = symbol_find_or_make (name);
483 *input_line_pointer = c;
485 S_CLEAR_EXTERNAL (symbolP);
486 symbol_get_obj (symbolP)->local = 1;
489 input_line_pointer++;
491 if (*input_line_pointer == '\n')
496 demand_empty_rest_of_line ();
500 obj_elf_weak (ignore)
501 int ignore ATTRIBUTE_UNUSED;
509 name = input_line_pointer;
510 c = get_symbol_end ();
511 symbolP = symbol_find_or_make (name);
512 *input_line_pointer = c;
514 S_SET_WEAK (symbolP);
515 symbol_get_obj (symbolP)->local = 1;
518 input_line_pointer++;
520 if (*input_line_pointer == '\n')
525 demand_empty_rest_of_line ();
529 obj_elf_visibility (visibility)
536 elf_symbol_type *elfsym;
540 name = input_line_pointer;
541 c = get_symbol_end ();
542 symbolP = symbol_find_or_make (name);
543 *input_line_pointer = c;
547 bfdsym = symbol_get_bfdsym (symbolP);
548 elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
552 elfsym->internal_elf_sym.st_other &= ~3;
553 elfsym->internal_elf_sym.st_other |= visibility;
557 input_line_pointer ++;
561 if (*input_line_pointer == '\n')
567 demand_empty_rest_of_line ();
570 static segT previous_section;
571 static int previous_subsection;
575 struct section_stack *next;
577 int subseg, prev_subseg;
580 static struct section_stack *section_stack;
582 /* Handle the .section pseudo-op. This code supports two different
585 The first is found on Solaris, and looks like
586 .section ".sec1",#alloc,#execinstr,#write
587 Here the names after '#' are the SHF_* flags to turn on for the
588 section. I'm not sure how it determines the SHT_* type (BFD
589 doesn't really give us control over the type, anyhow).
591 The second format is found on UnixWare, and probably most SVR4
592 machines, and looks like
593 .section .sec1,"a",@progbits
594 The quoted string may contain any combination of a, w, x, and
595 represents the SHF_* flags to turn on for the section. The string
596 beginning with '@' can be progbits or nobits. There should be
597 other possibilities, but I don't know what they are. In any case,
598 BFD doesn't really let us set the section type. */
600 /* Certain named sections have particular defined types, listed on p.
602 struct special_section
609 static struct special_section const special_sections[] =
611 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
612 { ".comment", SHT_PROGBITS, 0 },
613 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
614 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
615 { ".debug", SHT_PROGBITS, 0 },
616 #if defined (TC_HPPA) && !defined (TE_LINUX) && TARGET_ARCH_SIZE == 64
617 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
618 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
620 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
621 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
623 { ".line", SHT_PROGBITS, 0 },
624 { ".note", SHT_NOTE, 0 },
625 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
626 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
627 { ".tbss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_TLS },
628 { ".tdata", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_TLS },
629 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
630 { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE },
631 { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE },
632 { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE },
634 #ifdef ELF_TC_SPECIAL_SECTIONS
635 ELF_TC_SPECIAL_SECTIONS
639 /* The following section names are special, but they can not
640 reasonably appear in assembler code. Some of the attributes are
641 processor dependent. */
642 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
643 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
644 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
645 { ".got", SHT_PROGBITS, 0 },
646 { ".hash", SHT_HASH, SHF_ALLOC },
647 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
648 { ".plt", SHT_PROGBITS, 0 },
649 { ".shstrtab",SHT_STRTAB, 0 },
650 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
651 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
658 obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push)
663 const char *group_name;
672 #ifdef md_flush_pending_output
673 md_flush_pending_output ();
676 /* Switch to the section, creating it if necessary. */
679 struct section_stack *elt;
680 elt = xmalloc (sizeof (struct section_stack));
681 elt->next = section_stack;
683 elt->prev_seg = previous_section;
684 elt->subseg = now_subseg;
685 elt->prev_subseg = previous_subsection;
688 previous_section = now_seg;
689 previous_subsection = now_subseg;
691 old_sec = bfd_get_section_by_name (stdoutput, name);
692 sec = subseg_new (name, 0);
694 /* See if this is one of the special sections. */
695 for (i = 0; special_sections[i].name != NULL; i++)
696 if (strcmp (name, special_sections[i].name) == 0)
698 if (type == SHT_NULL)
699 type = special_sections[i].type;
700 else if (type != special_sections[i].type)
703 /* FIXME: gcc, as of 2002-10-22, will emit
705 .section .init_array,"aw",@progbits
707 for __attribute__ ((section (".init_array"))).
708 "@progbits" is incorrect. */
709 && special_sections[i].type != SHT_INIT_ARRAY
710 && special_sections[i].type != SHT_FINI_ARRAY
711 && special_sections[i].type != SHT_PREINIT_ARRAY)
713 as_warn (_("setting incorrect section type for %s"), name);
717 as_warn (_("ignoring incorrect section type for %s"), name);
718 type = special_sections[i].type;
721 if ((attr &~ special_sections[i].attributes) != 0
724 /* As a GNU extension, we permit a .note section to be
725 allocatable. If the linker sees an allocateable .note
726 section, it will create a PT_NOTE segment in the output
728 if (strcmp (name, ".note") != 0
729 || attr != SHF_ALLOC)
730 as_warn (_("setting incorrect section attributes for %s"),
733 attr |= special_sections[i].attributes;
737 /* Convert ELF type and flags to BFD flags. */
739 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
740 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
741 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
742 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0)
743 | ((attr & SHF_MERGE) ? SEC_MERGE : 0)
744 | ((attr & SHF_STRINGS) ? SEC_STRINGS : 0)
745 | ((attr & SHF_TLS) ? SEC_THREAD_LOCAL : 0));
746 #ifdef md_elf_section_flags
747 flags = md_elf_section_flags (flags, attr, type);
754 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
755 if (type == SHT_NOBITS)
756 seg_info (sec)->bss = 1;
759 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
760 bfd_set_section_flags (stdoutput, sec, flags);
761 if (flags & SEC_MERGE)
762 sec->entsize = entsize;
763 elf_group_name (sec) = group_name;
765 /* Add a symbol for this section to the symbol table. */
766 secsym = symbol_find (name);
768 symbol_set_bfdsym (secsym, sec->symbol);
770 symbol_table_insert (section_symbol (sec));
774 /* If section attributes are specified the second time we see a
775 particular section, then check that they are the same as we
776 saw the first time. */
777 if (((old_sec->flags ^ flags)
778 & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
779 | SEC_EXCLUDE | SEC_SORT_ENTRIES | SEC_MERGE | SEC_STRINGS
780 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD
781 | SEC_THREAD_LOCAL)))
782 as_warn (_("ignoring changed section attributes for %s"), name);
783 if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize)
784 as_warn (_("ignoring changed section entity size for %s"), name);
785 if ((attr & SHF_GROUP) != 0
786 && strcmp (elf_group_name (old_sec), group_name) != 0)
787 as_warn (_("ignoring new section group for %s"), name);
790 #ifdef md_elf_section_change_hook
791 md_elf_section_change_hook ();
796 obj_elf_parse_section_letters (str, len)
813 attr |= SHF_EXECINSTR;
829 if (*(str - 1) == 'a')
832 if (len > 1 && str[1] == 's')
841 char *bad_msg = _("unrecognized .section attribute: want a,w,x,M,S,G,T");
842 #ifdef md_elf_section_letter
843 int md_attr = md_elf_section_letter (*str, &bad_msg);
849 as_warn ("%s", bad_msg);
862 obj_elf_section_word (str, len)
866 if (len == 5 && strncmp (str, "write", 5) == 0)
868 if (len == 5 && strncmp (str, "alloc", 5) == 0)
870 if (len == 9 && strncmp (str, "execinstr", 9) == 0)
871 return SHF_EXECINSTR;
872 if (len == 3 && strncmp (str, "tls", 3) == 0)
875 #ifdef md_elf_section_word
877 int md_attr = md_elf_section_word (str, len);
883 as_warn (_("unrecognized section attribute"));
888 obj_elf_section_type (str, len)
892 if (len == 8 && strncmp (str, "progbits", 8) == 0)
894 if (len == 6 && strncmp (str, "nobits", 6) == 0)
897 #ifdef md_elf_section_type
899 int md_type = md_elf_section_type (str, len);
905 as_warn (_("unrecognized section type"));
909 /* Get name of section. */
911 obj_elf_section_name ()
916 if (*input_line_pointer == '"')
920 name = demand_copy_C_string (&dummy);
923 ignore_rest_of_line ();
929 char *end = input_line_pointer;
931 while (0 == strchr ("\n\t,; ", *end))
933 if (end == input_line_pointer)
935 as_warn (_("missing name"));
936 ignore_rest_of_line ();
940 name = xmalloc (end - input_line_pointer + 1);
941 memcpy (name, input_line_pointer, end - input_line_pointer);
942 name[end - input_line_pointer] = '\0';
943 input_line_pointer = end;
950 obj_elf_section (push)
953 char *name, *group_name, *beg;
954 int type, attr, dummy;
963 #ifdef md_flush_pending_output
964 md_flush_pending_output ();
967 previous_section = now_seg;
968 previous_subsection = now_subseg;
970 s_mri_sect (&mri_type);
972 #ifdef md_elf_section_change_hook
973 md_elf_section_change_hook ();
978 #endif /* ! defined (TC_I370) */
980 name = obj_elf_section_name ();
989 if (*input_line_pointer == ',')
991 /* Skip the comma. */
992 ++input_line_pointer;
995 if (*input_line_pointer == '"')
997 beg = demand_copy_C_string (&dummy);
1000 ignore_rest_of_line ();
1003 attr |= obj_elf_parse_section_letters (beg, strlen (beg));
1006 if (*input_line_pointer == ',')
1009 char *save = input_line_pointer;
1011 ++input_line_pointer;
1013 c = *input_line_pointer;
1016 beg = demand_copy_C_string (&dummy);
1019 ignore_rest_of_line ();
1022 type = obj_elf_section_type (beg, strlen (beg));
1024 else if (c == '@' || c == '%')
1026 beg = ++input_line_pointer;
1027 c = get_symbol_end ();
1028 *input_line_pointer = c;
1029 type = obj_elf_section_type (beg, input_line_pointer - beg);
1032 input_line_pointer = save;
1036 if ((attr & SHF_MERGE) != 0 && *input_line_pointer == ',')
1038 ++input_line_pointer;
1040 entsize = get_absolute_expression ();
1044 as_warn (_("invalid merge entity size"));
1049 else if ((attr & SHF_MERGE) != 0)
1051 as_warn (_("entity size for SHF_MERGE not specified"));
1055 if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
1057 ++input_line_pointer;
1058 group_name = obj_elf_section_name ();
1059 if (group_name == NULL)
1061 else if (strncmp (input_line_pointer, ",comdat", 7) == 0)
1063 input_line_pointer += 7;
1066 else if (strncmp (name, ".gnu.linkonce", 13) == 0)
1069 else if ((attr & SHF_GROUP) != 0)
1071 as_warn (_("group name for SHF_GROUP not specified"));
1082 if (*input_line_pointer != '#')
1084 as_warn (_("character following name is not '#'"));
1085 ignore_rest_of_line ();
1088 beg = ++input_line_pointer;
1089 c = get_symbol_end ();
1090 *input_line_pointer = c;
1092 attr |= obj_elf_section_word (beg, input_line_pointer - beg);
1096 while (*input_line_pointer++ == ',');
1097 --input_line_pointer;
1101 demand_empty_rest_of_line ();
1103 obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
1106 /* Change to the .data section. */
1112 #ifdef md_flush_pending_output
1113 md_flush_pending_output ();
1116 previous_section = now_seg;
1117 previous_subsection = now_subseg;
1120 #ifdef md_elf_section_change_hook
1121 md_elf_section_change_hook ();
1125 /* Change to the .text section. */
1131 #ifdef md_flush_pending_output
1132 md_flush_pending_output ();
1135 previous_section = now_seg;
1136 previous_subsection = now_subseg;
1139 #ifdef md_elf_section_change_hook
1140 md_elf_section_change_hook ();
1145 obj_elf_subsection (ignore)
1146 int ignore ATTRIBUTE_UNUSED;
1150 #ifdef md_flush_pending_output
1151 md_flush_pending_output ();
1154 previous_section = now_seg;
1155 previous_subsection = now_subseg;
1157 temp = get_absolute_expression ();
1158 subseg_set (now_seg, (subsegT) temp);
1159 demand_empty_rest_of_line ();
1161 #ifdef md_elf_section_change_hook
1162 md_elf_section_change_hook ();
1166 /* This can be called from the processor backends if they change
1170 obj_elf_section_change_hook ()
1172 previous_section = now_seg;
1173 previous_subsection = now_subseg;
1177 obj_elf_previous (ignore)
1178 int ignore ATTRIBUTE_UNUSED;
1183 if (previous_section == 0)
1185 as_warn (_(".previous without corresponding .section; ignored"));
1189 #ifdef md_flush_pending_output
1190 md_flush_pending_output ();
1193 new_section = previous_section;
1194 new_subsection = previous_subsection;
1195 previous_section = now_seg;
1196 previous_subsection = now_subseg;
1197 subseg_set (new_section, new_subsection);
1199 #ifdef md_elf_section_change_hook
1200 md_elf_section_change_hook ();
1205 obj_elf_popsection (xxx)
1206 int xxx ATTRIBUTE_UNUSED;
1208 struct section_stack *top = section_stack;
1212 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1216 #ifdef md_flush_pending_output
1217 md_flush_pending_output ();
1220 section_stack = top->next;
1221 previous_section = top->prev_seg;
1222 previous_subsection = top->prev_subseg;
1223 subseg_set (top->seg, top->subseg);
1226 #ifdef md_elf_section_change_hook
1227 md_elf_section_change_hook ();
1232 obj_elf_line (ignore)
1233 int ignore ATTRIBUTE_UNUSED;
1235 /* Assume delimiter is part of expression. BSD4.2 as fails with
1236 delightful bug, so we are not being incompatible here. */
1237 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
1238 demand_empty_rest_of_line ();
1241 /* This handles the .symver pseudo-op, which is used to specify a
1242 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1243 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1244 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1245 with the same value as the symbol NAME. */
1248 obj_elf_symver (ignore)
1249 int ignore ATTRIBUTE_UNUSED;
1256 name = input_line_pointer;
1257 c = get_symbol_end ();
1259 sym = symbol_find_or_make (name);
1261 *input_line_pointer = c;
1264 if (*input_line_pointer != ',')
1266 as_bad (_("expected comma after name in .symver"));
1267 ignore_rest_of_line ();
1271 ++input_line_pointer;
1273 name = input_line_pointer;
1275 /* Temporarily include '@' in symbol names. */
1276 old_lexat = lex_type[(unsigned char) '@'];
1277 lex_type[(unsigned char) '@'] |= LEX_NAME;
1278 c = get_symbol_end ();
1279 lex_type[(unsigned char) '@'] = old_lexat;
1281 if (symbol_get_obj (sym)->versioned_name == NULL)
1283 symbol_get_obj (sym)->versioned_name = xstrdup (name);
1285 *input_line_pointer = c;
1287 if (strchr (symbol_get_obj (sym)->versioned_name,
1288 ELF_VER_CHR) == NULL)
1290 as_bad (_("missing version name in `%s' for symbol `%s'"),
1291 symbol_get_obj (sym)->versioned_name,
1293 ignore_rest_of_line ();
1299 if (strcmp (symbol_get_obj (sym)->versioned_name, name))
1301 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1302 name, symbol_get_obj (sym)->versioned_name,
1304 ignore_rest_of_line ();
1308 *input_line_pointer = c;
1311 demand_empty_rest_of_line ();
1314 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1315 to the linker the hierarchy in which a particular table resides. The
1316 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1319 obj_elf_vtable_inherit (ignore)
1320 int ignore ATTRIBUTE_UNUSED;
1322 char *cname, *pname;
1323 symbolS *csym, *psym;
1326 if (*input_line_pointer == '#')
1327 ++input_line_pointer;
1329 cname = input_line_pointer;
1330 c = get_symbol_end ();
1331 csym = symbol_find (cname);
1333 /* GCFIXME: should check that we don't have two .vtable_inherits for
1334 the same child symbol. Also, we can currently only do this if the
1335 child symbol is already exists and is placed in a fragment. */
1337 if (csym == NULL || symbol_get_frag (csym) == NULL)
1339 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1344 *input_line_pointer = c;
1347 if (*input_line_pointer != ',')
1349 as_bad ("expected comma after name in .vtable_inherit");
1350 ignore_rest_of_line ();
1354 ++input_line_pointer;
1357 if (*input_line_pointer == '#')
1358 ++input_line_pointer;
1360 if (input_line_pointer[0] == '0'
1361 && (input_line_pointer[1] == '\0'
1362 || ISSPACE (input_line_pointer[1])))
1364 psym = section_symbol (absolute_section);
1365 ++input_line_pointer;
1369 pname = input_line_pointer;
1370 c = get_symbol_end ();
1371 psym = symbol_find_or_make (pname);
1372 *input_line_pointer = c;
1375 demand_empty_rest_of_line ();
1380 assert (symbol_get_value_expression (csym)->X_op == O_constant);
1381 return fix_new (symbol_get_frag (csym),
1382 symbol_get_value_expression (csym)->X_add_number,
1383 0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
1386 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1387 to the linker that a vtable slot was used. The syntax is
1388 ".vtable_entry tablename, offset". */
1391 obj_elf_vtable_entry (ignore)
1392 int ignore ATTRIBUTE_UNUSED;
1399 if (*input_line_pointer == '#')
1400 ++input_line_pointer;
1402 name = input_line_pointer;
1403 c = get_symbol_end ();
1404 sym = symbol_find_or_make (name);
1405 *input_line_pointer = c;
1408 if (*input_line_pointer != ',')
1410 as_bad ("expected comma after name in .vtable_entry");
1411 ignore_rest_of_line ();
1415 ++input_line_pointer;
1416 if (*input_line_pointer == '#')
1417 ++input_line_pointer;
1419 offset = get_absolute_expression ();
1421 demand_empty_rest_of_line ();
1423 return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
1424 BFD_RELOC_VTABLE_ENTRY);
1428 elf_obj_read_begin_hook ()
1430 #ifdef NEED_ECOFF_DEBUG
1431 if (ECOFF_DEBUGGING)
1432 ecoff_read_begin_hook ();
1437 elf_obj_symbol_new_hook (symbolP)
1440 struct elf_obj_sy *sy_obj;
1442 sy_obj = symbol_get_obj (symbolP);
1443 sy_obj->size = NULL;
1444 sy_obj->versioned_name = NULL;
1446 #ifdef NEED_ECOFF_DEBUG
1447 if (ECOFF_DEBUGGING)
1448 ecoff_symbol_new_hook (symbolP);
1452 /* When setting one symbol equal to another, by default we probably
1453 want them to have the same "size", whatever it means in the current
1457 elf_copy_symbol_attributes (dest, src)
1458 symbolS *dest, *src;
1460 struct elf_obj_sy *srcelf = symbol_get_obj (src);
1461 struct elf_obj_sy *destelf = symbol_get_obj (dest);
1464 if (destelf->size == NULL)
1466 (expressionS *) xmalloc (sizeof (expressionS));
1467 *destelf->size = *srcelf->size;
1471 if (destelf->size != NULL)
1472 free (destelf->size);
1473 destelf->size = NULL;
1475 S_SET_SIZE (dest, S_GET_SIZE (src));
1476 /* Don't copy visibility. */
1477 S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest))
1478 | (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1))));
1482 obj_elf_version (ignore)
1483 int ignore ATTRIBUTE_UNUSED;
1488 asection *seg = now_seg;
1489 subsegT subseg = now_subseg;
1490 Elf_Internal_Note i_note;
1491 Elf_External_Note e_note;
1492 asection *note_secp = (asection *) NULL;
1496 if (*input_line_pointer == '\"')
1498 ++input_line_pointer; /* -> 1st char of string. */
1499 name = input_line_pointer;
1501 while (is_a_char (c = next_char_of_string ()))
1503 c = *input_line_pointer;
1504 *input_line_pointer = '\0';
1505 *(input_line_pointer - 1) = '\0';
1506 *input_line_pointer = c;
1508 /* create the .note section */
1510 note_secp = subseg_new (".note", 0);
1511 bfd_set_section_flags (stdoutput,
1513 SEC_HAS_CONTENTS | SEC_READONLY);
1515 /* process the version string */
1517 len = strlen (name);
1519 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1520 i_note.descsz = 0; /* no description */
1521 i_note.type = NT_VERSION;
1522 p = frag_more (sizeof (e_note.namesz));
1523 md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz));
1524 p = frag_more (sizeof (e_note.descsz));
1525 md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz));
1526 p = frag_more (sizeof (e_note.type));
1527 md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type));
1528 p = frag_more (len + 1);
1531 frag_align (2, 0, 0);
1533 subseg_set (seg, subseg);
1537 as_bad (_("expected quoted string"));
1539 demand_empty_rest_of_line ();
1543 obj_elf_size (ignore)
1544 int ignore ATTRIBUTE_UNUSED;
1546 char *name = input_line_pointer;
1547 char c = get_symbol_end ();
1552 p = input_line_pointer;
1555 if (*input_line_pointer != ',')
1558 as_bad (_("expected comma after name `%s' in .size directive"), name);
1560 ignore_rest_of_line ();
1563 input_line_pointer++;
1565 if (exp.X_op == O_absent)
1567 as_bad (_("missing expression in .size directive"));
1568 exp.X_op = O_constant;
1569 exp.X_add_number = 0;
1572 sym = symbol_find_or_make (name);
1574 if (exp.X_op == O_constant)
1576 S_SET_SIZE (sym, exp.X_add_number);
1577 if (symbol_get_obj (sym)->size)
1579 xfree (symbol_get_obj (sym)->size);
1580 symbol_get_obj (sym)->size = NULL;
1585 symbol_get_obj (sym)->size =
1586 (expressionS *) xmalloc (sizeof (expressionS));
1587 *symbol_get_obj (sym)->size = exp;
1589 demand_empty_rest_of_line ();
1592 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1593 There are five syntaxes:
1595 The first (used on Solaris) is
1597 The second (used on UnixWare) is
1599 The third (reportedly to be used on Irix 6.0) is
1601 The fourth (used on NetBSD/Arm and Linux/ARM) is
1603 The fifth (used on SVR4/860) is
1604 .type SYM,"function"
1608 obj_elf_type (ignore)
1609 int ignore ATTRIBUTE_UNUSED;
1614 const char *typename;
1616 elf_symbol_type *elfsym;
1618 name = input_line_pointer;
1619 c = get_symbol_end ();
1620 sym = symbol_find_or_make (name);
1621 elfsym = (elf_symbol_type *) symbol_get_bfdsym (sym);
1622 *input_line_pointer = c;
1625 if (*input_line_pointer == ',')
1626 ++input_line_pointer;
1629 if ( *input_line_pointer == '#'
1630 || *input_line_pointer == '@'
1631 || *input_line_pointer == '"'
1632 || *input_line_pointer == '%')
1633 ++input_line_pointer;
1635 typename = input_line_pointer;
1636 c = get_symbol_end ();
1639 if (strcmp (typename, "function") == 0
1640 || strcmp (typename, "STT_FUNC") == 0)
1641 type = BSF_FUNCTION;
1642 else if (strcmp (typename, "object") == 0
1643 || strcmp (typename, "STT_OBJECT") == 0)
1645 else if (strcmp (typename, "tls_object") == 0
1646 || strcmp (typename, "STT_TLS") == 0)
1647 type = BSF_OBJECT | BSF_THREAD_LOCAL;
1648 #ifdef md_elf_symbol_type
1649 else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1)
1653 as_bad (_("unrecognized symbol type \"%s\""), typename);
1655 *input_line_pointer = c;
1657 if (*input_line_pointer == '"')
1658 ++input_line_pointer;
1660 elfsym->symbol.flags |= type;
1662 demand_empty_rest_of_line ();
1666 obj_elf_ident (ignore)
1667 int ignore ATTRIBUTE_UNUSED;
1669 static segT comment_section;
1670 segT old_section = now_seg;
1671 int old_subsection = now_subseg;
1673 #ifdef md_flush_pending_output
1674 md_flush_pending_output ();
1677 if (!comment_section)
1680 comment_section = subseg_new (".comment", 0);
1681 bfd_set_section_flags (stdoutput, comment_section,
1682 SEC_READONLY | SEC_HAS_CONTENTS);
1687 subseg_set (comment_section, 0);
1689 subseg_set (old_section, old_subsection);
1692 #ifdef INIT_STAB_SECTION
1694 /* The first entry in a .stabs section is special. */
1697 obj_elf_init_stab_section (seg)
1703 unsigned int stroff;
1705 /* Force the section to align to a longword boundary. Without this,
1706 UnixWare ar crashes. */
1707 bfd_set_section_alignment (stdoutput, seg, 2);
1709 /* Make space for this first symbol. */
1713 as_where (&file, (unsigned int *) NULL);
1714 stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4);
1715 strcpy (stabstr_name, segment_name (seg));
1716 strcat (stabstr_name, "str");
1717 stroff = get_stab_string_offset (file, stabstr_name);
1719 md_number_to_chars (p, stroff, 4);
1720 seg_info (seg)->stabu.p = p;
1725 /* Fill in the counts in the first entry in a .stabs section. */
1728 adjust_stab_sections (abfd, sec, xxx)
1731 PTR xxx ATTRIBUTE_UNUSED;
1738 if (strncmp (".stab", sec->name, 5))
1740 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1743 name = (char *) alloca (strlen (sec->name) + 4);
1744 strcpy (name, sec->name);
1745 strcat (name, "str");
1746 strsec = bfd_get_section_by_name (abfd, name);
1748 strsz = bfd_section_size (abfd, strsec);
1751 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1753 p = seg_info (sec)->stabu.p;
1756 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1757 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1760 #ifdef NEED_ECOFF_DEBUG
1762 /* This function is called by the ECOFF code. It is supposed to
1763 record the external symbol information so that the backend can
1764 write it out correctly. The ELF backend doesn't actually handle
1765 this at the moment, so we do it ourselves. We save the information
1769 elf_ecoff_set_ext (sym, ext)
1771 struct ecoff_extr *ext;
1773 symbol_get_bfdsym (sym)->udata.p = (PTR) ext;
1776 /* This function is called by bfd_ecoff_debug_externals. It is
1777 supposed to *EXT to the external symbol information, and return
1778 whether the symbol should be used at all. */
1781 elf_get_extr (sym, ext)
1785 if (sym->udata.p == NULL)
1787 *ext = *(EXTR *) sym->udata.p;
1791 /* This function is called by bfd_ecoff_debug_externals. It has
1792 nothing to do for ELF. */
1796 elf_set_index (sym, indx)
1797 asymbol *sym ATTRIBUTE_UNUSED;
1798 bfd_size_type indx ATTRIBUTE_UNUSED;
1802 #endif /* NEED_ECOFF_DEBUG */
1805 elf_frob_symbol (symp, puntp)
1809 struct elf_obj_sy *sy_obj;
1811 #ifdef NEED_ECOFF_DEBUG
1812 if (ECOFF_DEBUGGING)
1813 ecoff_frob_symbol (symp);
1816 sy_obj = symbol_get_obj (symp);
1818 if (sy_obj->size != NULL)
1820 switch (sy_obj->size->X_op)
1824 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1825 + sy_obj->size->X_add_number
1826 - S_GET_VALUE (sy_obj->size->X_op_symbol)));
1830 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1831 + sy_obj->size->X_add_number));
1834 as_bad (_(".size expression too complicated to fix up"));
1837 free (sy_obj->size);
1838 sy_obj->size = NULL;
1841 if (sy_obj->versioned_name != NULL)
1845 p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
1848 /* This symbol was given a new name with the .symver directive.
1850 If this is an external reference, just rename the symbol to
1851 include the version string. This will make the relocs be
1852 against the correct versioned symbol.
1854 If this is a definition, add an alias. FIXME: Using an alias
1855 will permit the debugging information to refer to the right
1856 symbol. However, it's not clear whether it is the best
1859 if (! S_IS_DEFINED (symp))
1861 /* Verify that the name isn't using the @@ syntax--this is
1862 reserved for definitions of the default version to link
1864 if (p[1] == ELF_VER_CHR)
1866 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1867 sy_obj->versioned_name);
1870 S_SET_NAME (symp, sy_obj->versioned_name);
1874 if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR)
1878 /* The @@@ syntax is a special case. It renames the
1879 symbol name to versioned_name with one `@' removed. */
1880 l = strlen (&p[3]) + 1;
1881 memmove (&p [2], &p[3], l);
1882 S_SET_NAME (symp, sy_obj->versioned_name);
1888 /* FIXME: Creating a new symbol here is risky. We're
1889 in the final loop over the symbol table. We can
1890 get away with it only because the symbol goes to
1891 the end of the list, where the loop will still see
1892 it. It would probably be better to do this in
1893 obj_frob_file_before_adjust. */
1895 symp2 = symbol_find_or_make (sy_obj->versioned_name);
1897 /* Now we act as though we saw symp2 = sym. */
1899 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1901 /* Subtracting out the frag address here is a hack
1902 because we are in the middle of the final loop. */
1905 - symbol_get_frag (symp)->fr_address));
1907 symbol_set_frag (symp2, symbol_get_frag (symp));
1909 /* This will copy over the size information. */
1910 copy_symbol_attributes (symp2, symp);
1912 S_SET_OTHER (symp2, S_GET_OTHER (symp));
1914 if (S_IS_WEAK (symp))
1917 if (S_IS_EXTERNAL (symp))
1918 S_SET_EXTERNAL (symp2);
1923 /* Double check weak symbols. */
1924 if (S_IS_WEAK (symp))
1926 if (S_IS_COMMON (symp))
1927 as_bad (_("symbol `%s' can not be both weak and common"),
1932 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1933 any undefined non-function symbol to STT_OBJECT. We try to be
1934 compatible, since newer Irix 5 and 6 linkers care. However, we
1935 only set undefined symbols to be STT_OBJECT if we are on Irix,
1936 because that is the only time gcc will generate the necessary
1937 .global directives to mark functions. */
1939 if (S_IS_COMMON (symp))
1940 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1942 if (strstr (TARGET_OS, "irix") != NULL
1943 && ! S_IS_DEFINED (symp)
1944 && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
1945 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1949 /* If TC_PPC is defined, we used to force the type of a symbol to be
1950 BSF_OBJECT if it was otherwise unset. This was required by some
1951 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1952 that this is no longer needed, so it is now commented out. */
1953 if ((symbol_get_bfdsym (symp)->flags
1954 & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1955 && S_IS_DEFINED (symp))
1956 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1962 asection **head; /* Section lists. */
1963 unsigned int *elt_count; /* Number of sections in each list. */
1964 unsigned int num_group; /* Number of lists. */
1967 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1968 add it to a list of sections belonging to the group. INF is a
1969 pointer to a struct group_list, which is where we store the head of
1973 build_group_lists (abfd, sec, inf)
1974 bfd *abfd ATTRIBUTE_UNUSED;
1978 struct group_list *list = (struct group_list *) inf;
1979 const char *group_name = elf_group_name (sec);
1982 if (group_name == NULL)
1985 /* If this group already has a list, add the section to the head of
1987 for (i = 0; i < list->num_group; i++)
1989 if (strcmp (group_name, elf_group_name (list->head[i])) == 0)
1991 elf_next_in_group (sec) = list->head[i];
1992 list->head[i] = sec;
1993 list->elt_count[i] += 1;
1998 /* New group. Make the arrays bigger in chunks to minimize calls to
2000 i = list->num_group;
2003 unsigned int newsize = i + 128;
2004 list->head = xrealloc (list->head, newsize * sizeof (*list->head));
2005 list->elt_count = xrealloc (list->elt_count,
2006 newsize * sizeof (*list->elt_count));
2008 list->head[i] = sec;
2009 list->elt_count[i] = 1;
2010 list->num_group += 1;
2016 struct group_list list;
2019 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
2021 /* Go find section groups. */
2024 list.elt_count = NULL;
2025 bfd_map_over_sections (stdoutput, build_group_lists, (PTR) &list);
2027 /* Make the SHT_GROUP sections that describe each section group. We
2028 can't set up the section contents here yet, because elf section
2029 indices have yet to be calculated. elf.c:set_group_contents does
2030 the rest of the work. */
2031 for (i = 0; i < list.num_group; i++)
2033 const char *group_name = elf_group_name (list.head[i]);
2034 const char *sec_name;
2040 flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP;
2041 for (s = list.head[i]; s != NULL; s = elf_next_in_group (s))
2042 if ((s->flags ^ flags) & SEC_LINK_ONCE)
2044 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
2045 if (s != list.head[i])
2047 as_warn (_("assuming all members of group `%s' are COMDAT"),
2053 sec_name = group_name;
2054 sy = symbol_find_exact (group_name);
2057 && (sy == symbol_lastP
2058 || (sy->sy_next != NULL
2059 && sy->sy_next->sy_previous == sy)))
2062 sec_name = ".group";
2064 s = subseg_force_new (sec_name, 0);
2066 || !bfd_set_section_flags (stdoutput, s, flags)
2067 || !bfd_set_section_alignment (stdoutput, s, 2))
2069 as_fatal (_("can't create group: %s"),
2070 bfd_errmsg (bfd_get_error ()));
2073 /* Pass a pointer to the first section in this group. */
2074 elf_next_in_group (s) = list.head[i];
2076 elf_group_id (s) = sy->bsym;
2078 s->_raw_size = 4 * (list.elt_count[i] + 1);
2079 s->contents = frag_more (s->_raw_size);
2080 frag_now->fr_fix = frag_now_fix_octets ();
2083 #ifdef elf_tc_final_processing
2084 elf_tc_final_processing ();
2088 /* It removes any unneeded versioned symbols from the symbol table. */
2091 elf_frob_file_before_adjust ()
2097 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
2098 if (!S_IS_DEFINED (symp))
2100 if (symbol_get_obj (symp)->versioned_name)
2104 /* The @@@ syntax is a special case. If the symbol is
2105 not defined, 2 `@'s will be removed from the
2108 p = strchr (symbol_get_obj (symp)->versioned_name,
2111 if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR)
2113 size_t l = strlen (&p[3]) + 1;
2114 memmove (&p [1], &p[3], l);
2116 if (symbol_used_p (symp) == 0
2117 && symbol_used_in_reloc_p (symp) == 0)
2118 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2121 /* If there was .weak foo, but foo was neither defined nor
2122 used anywhere, remove it. */
2124 else if (S_IS_WEAK (symp)
2125 && symbol_used_p (symp) == 0
2126 && symbol_used_in_reloc_p (symp) == 0)
2127 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2132 /* It is required that we let write_relocs have the opportunity to
2133 optimize away fixups before output has begun, since it is possible
2134 to eliminate all fixups for a section and thus we never should
2135 have generated the relocation section. */
2138 elf_frob_file_after_relocs ()
2140 #ifdef NEED_ECOFF_DEBUG
2141 if (ECOFF_DEBUGGING)
2142 /* Generate the ECOFF debugging information. */
2144 const struct ecoff_debug_swap *debug_swap;
2145 struct ecoff_debug_info debug;
2150 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
2151 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
2152 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
2154 /* Set up the pointers in debug. */
2155 #define SET(ptr, offset, type) \
2156 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2158 SET (line, cbLineOffset, unsigned char *);
2159 SET (external_dnr, cbDnOffset, PTR);
2160 SET (external_pdr, cbPdOffset, PTR);
2161 SET (external_sym, cbSymOffset, PTR);
2162 SET (external_opt, cbOptOffset, PTR);
2163 SET (external_aux, cbAuxOffset, union aux_ext *);
2164 SET (ss, cbSsOffset, char *);
2165 SET (external_fdr, cbFdOffset, PTR);
2166 SET (external_rfd, cbRfdOffset, PTR);
2167 /* ssext and external_ext are set up just below. */
2171 /* Set up the external symbols. */
2172 debug.ssext = debug.ssext_end = NULL;
2173 debug.external_ext = debug.external_ext_end = NULL;
2174 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, TRUE,
2175 elf_get_extr, elf_set_index))
2176 as_fatal (_("failed to set up debugging information: %s"),
2177 bfd_errmsg (bfd_get_error ()));
2179 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
2180 assert (sec != NULL);
2182 know (!stdoutput->output_has_begun);
2184 /* We set the size of the section, call bfd_set_section_contents
2185 to force the ELF backend to allocate a file position, and then
2186 write out the data. FIXME: Is this really the best way to do
2188 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
2190 /* Pass BUF to bfd_set_section_contents because this will
2191 eventually become a call to fwrite, and ISO C prohibits
2192 passing a NULL pointer to a stdio function even if the
2193 pointer will not be used. */
2194 if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf,
2195 (file_ptr) 0, (bfd_size_type) 0))
2196 as_fatal (_("can't start writing .mdebug section: %s"),
2197 bfd_errmsg (bfd_get_error ()));
2199 know (stdoutput->output_has_begun);
2200 know (sec->filepos != 0);
2202 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
2204 as_fatal (_("could not write .mdebug section: %s"),
2205 bfd_errmsg (bfd_get_error ()));
2207 #endif /* NEED_ECOFF_DEBUG */
2212 /* Heavily plagarized from obj_elf_version. The idea is to emit the
2213 SCO specific identifier in the .notes section to satisfy the SCO
2216 This looks more complicated than it really is. As opposed to the
2217 "obvious" solution, this should handle the cross dev cases
2218 correctly. (i.e, hosting on a 64 bit big endian processor, but
2219 generating SCO Elf code) Efficiency isn't a concern, as there
2220 should be exactly one of these sections per object module.
2222 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2225 int_32 namesz = 4 ; Name size
2226 int_32 descsz = 12 ; Descriptive information
2228 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2229 int_32 version = (major ver # << 16) | version of tools ;
2230 int_32 source = (tool_id << 16 ) | 1 ;
2231 int_32 info = 0 ; These are set by the SCO tools, but we
2232 don't know enough about the source
2233 environment to set them. SCO ld currently
2234 ignores them, and recommends we set them
2237 #define SCO_MAJOR_VERSION 0x1
2238 #define SCO_MINOR_VERSION 0x1
2248 asection *seg = now_seg;
2249 subsegT subseg = now_subseg;
2250 Elf_Internal_Note i_note;
2251 Elf_External_Note e_note;
2252 asection *note_secp = (asection *) NULL;
2255 /* create the .note section */
2257 note_secp = subseg_new (".note", 0);
2258 bfd_set_section_flags (stdoutput,
2260 SEC_HAS_CONTENTS | SEC_READONLY);
2262 /* process the version string */
2265 i_note.descsz = 12; /* 12 descriptive bytes */
2266 i_note.type = NT_VERSION; /* Contains a version string */
2268 p = frag_more (sizeof (i_note.namesz));
2269 md_number_to_chars (p, (valueT) i_note.namesz, 4);
2271 p = frag_more (sizeof (i_note.descsz));
2272 md_number_to_chars (p, (valueT) i_note.descsz, 4);
2274 p = frag_more (sizeof (i_note.type));
2275 md_number_to_chars (p, (valueT) i_note.type, 4);
2280 /* Note: this is the version number of the ELF we're representing */
2282 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
2284 /* Here, we pick a magic number for ourselves (yes, I "registered"
2285 it with SCO. The bottom bit shows that we are compat with the
2288 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
2290 /* If we knew (or cared) what the source language options were, we'd
2291 fill them in here. SCO has given us permission to ignore these
2292 and just set them to zero. */
2294 md_number_to_chars (p, 0x0000, 4);
2296 frag_align (2, 0, 0);
2298 /* We probably can't restore the current segment, for there likely
2301 subseg_set (seg, subseg);
2305 #endif /* SCO_ELF */
2308 elf_separate_stab_sections ()
2310 #ifdef NEED_ECOFF_DEBUG
2311 return (!ECOFF_DEBUGGING);
2318 elf_init_stab_section (seg)
2321 #ifdef NEED_ECOFF_DEBUG
2322 if (!ECOFF_DEBUGGING)
2324 obj_elf_init_stab_section (seg);
2327 const struct format_ops elf_format_ops =
2329 bfd_target_elf_flavour,
2330 0, /* dfl_leading_underscore */
2331 1, /* emit_section_symbols */
2336 elf_frob_file_before_adjust,
2337 0, /* obj_frob_file_before_fix */
2338 elf_frob_file_after_relocs,
2339 elf_s_get_size, elf_s_set_size,
2340 elf_s_get_align, elf_s_set_align,
2347 elf_copy_symbol_attributes,
2348 #ifdef NEED_ECOFF_DEBUG
2349 ecoff_generate_asm_lineno,
2352 0, /* generate_asm_lineno */
2353 0, /* process_stab */
2355 elf_separate_stab_sections,
2356 elf_init_stab_section,
2357 elf_sec_sym_ok_for_reloc,
2359 #ifdef NEED_ECOFF_DEBUG
2362 0, /* ecoff_set_ext */
2364 elf_obj_read_begin_hook,
2365 elf_obj_symbol_new_hook