1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-elf.h"
27 #ifndef ECOFF_DEBUGGING
28 #define ECOFF_DEBUGGING 0
30 #define NEED_ECOFF_DEBUG
33 #ifdef NEED_ECOFF_DEBUG
38 #include "elf/alpha.h"
49 static bfd_vma elf_s_get_size PARAMS ((symbolS *));
50 static void elf_s_set_size PARAMS ((symbolS *, bfd_vma));
51 static bfd_vma elf_s_get_align PARAMS ((symbolS *));
52 static void elf_s_set_align PARAMS ((symbolS *, bfd_vma));
53 static void elf_copy_symbol_attributes PARAMS ((symbolS *, symbolS *));
54 static int elf_sec_sym_ok_for_reloc PARAMS ((asection *));
55 static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));
57 #ifdef NEED_ECOFF_DEBUG
58 static boolean elf_get_extr PARAMS ((asymbol *, EXTR *));
59 static void elf_set_index PARAMS ((asymbol *, bfd_size_type));
62 static void obj_elf_line PARAMS ((int));
63 void obj_elf_version PARAMS ((int));
64 static void obj_elf_size PARAMS ((int));
65 static void obj_elf_type PARAMS ((int));
66 static void obj_elf_ident PARAMS ((int));
67 static void obj_elf_weak PARAMS ((int));
68 static void obj_elf_local PARAMS ((int));
69 static void obj_elf_visibility PARAMS ((int));
70 static void obj_elf_symver PARAMS ((int));
71 static void obj_elf_vtable_inherit PARAMS ((int));
72 static void obj_elf_vtable_entry PARAMS ((int));
73 static void obj_elf_subsection PARAMS ((int));
74 static void obj_elf_popsection PARAMS ((int));
76 static const pseudo_typeS elf_pseudo_table[] =
78 {"comm", obj_elf_common, 0},
79 {"common", obj_elf_common, 1},
80 {"ident", obj_elf_ident, 0},
81 {"local", obj_elf_local, 0},
82 {"previous", obj_elf_previous, 0},
83 {"section", obj_elf_section, 0},
84 {"section.s", obj_elf_section, 0},
85 {"sect", obj_elf_section, 0},
86 {"sect.s", obj_elf_section, 0},
87 {"pushsection", obj_elf_section, 1},
88 {"popsection", obj_elf_popsection, 0},
89 {"size", obj_elf_size, 0},
90 {"type", obj_elf_type, 0},
91 {"version", obj_elf_version, 0},
92 {"weak", obj_elf_weak, 0},
94 /* These define symbol visibility. */
95 {"internal", obj_elf_visibility, STV_INTERNAL},
96 {"hidden", obj_elf_visibility, STV_HIDDEN},
97 {"protected", obj_elf_visibility, STV_PROTECTED},
99 /* These are used for stabs-in-elf configurations. */
100 {"line", obj_elf_line, 0},
102 /* This is a GNU extension to handle symbol versions. */
103 {"symver", obj_elf_symver, 0},
105 /* A GNU extension to change subsection only. */
106 {"subsection", obj_elf_subsection, 0},
108 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
109 {"vtable_inherit", obj_elf_vtable_inherit, 0},
110 {"vtable_entry", obj_elf_vtable_entry, 0},
112 /* These are used for dwarf. */
117 /* We need to trap the section changing calls to handle .previous. */
118 {"data", obj_elf_data, 0},
119 {"text", obj_elf_text, 0},
125 static const pseudo_typeS ecoff_debug_pseudo_table[] =
127 #ifdef NEED_ECOFF_DEBUG
128 /* COFF style debugging information for ECOFF. .ln is not used; .loc
130 { "def", ecoff_directive_def, 0 },
131 { "dim", ecoff_directive_dim, 0 },
132 { "endef", ecoff_directive_endef, 0 },
133 { "file", ecoff_directive_file, 0 },
134 { "scl", ecoff_directive_scl, 0 },
135 { "tag", ecoff_directive_tag, 0 },
136 { "val", ecoff_directive_val, 0 },
138 /* COFF debugging requires pseudo-ops .size and .type, but ELF
139 already has meanings for those. We use .esize and .etype
140 instead. These are only generated by gcc anyhow. */
141 { "esize", ecoff_directive_size, 0 },
142 { "etype", ecoff_directive_type, 0 },
144 /* ECOFF specific debugging information. */
145 { "begin", ecoff_directive_begin, 0 },
146 { "bend", ecoff_directive_bend, 0 },
147 { "end", ecoff_directive_end, 0 },
148 { "ent", ecoff_directive_ent, 0 },
149 { "fmask", ecoff_directive_fmask, 0 },
150 { "frame", ecoff_directive_frame, 0 },
151 { "loc", ecoff_directive_loc, 0 },
152 { "mask", ecoff_directive_mask, 0 },
154 /* Other ECOFF directives. */
155 { "extern", ecoff_directive_extern, 0 },
157 /* These are used on Irix. I don't know how to implement them. */
158 { "alias", s_ignore, 0 },
159 { "bgnb", s_ignore, 0 },
160 { "endb", s_ignore, 0 },
161 { "lab", s_ignore, 0 },
162 { "noalias", s_ignore, 0 },
163 { "verstamp", s_ignore, 0 },
164 { "vreg", s_ignore, 0 },
167 {NULL, NULL, 0} /* end sentinel */
171 #include "aout/aout64.h"
173 /* This is called when the assembler starts. */
178 /* Add symbols for the known sections to the symbol table. */
179 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
180 TEXT_SECTION_NAME)));
181 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
182 DATA_SECTION_NAME)));
183 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
190 pop_insert (elf_pseudo_table);
192 pop_insert (ecoff_debug_pseudo_table);
199 return S_GET_SIZE (sym);
203 elf_s_set_size (sym, sz)
207 S_SET_SIZE (sym, sz);
211 elf_s_get_align (sym)
214 return S_GET_ALIGN (sym);
218 elf_s_set_align (sym, align)
222 S_SET_ALIGN (sym, align);
226 elf_s_get_other (sym)
229 return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
233 elf_copy_symbol_attributes (dest, src)
236 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
240 elf_sec_sym_ok_for_reloc (sec)
243 return obj_sec_sym_ok_for_reloc (sec);
252 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
253 symbol_set_frag (sym, &zero_address_frag);
254 symbol_get_bfdsym (sym)->flags |= BSF_FILE;
256 if (symbol_rootP != sym)
258 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
259 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
261 verify_symbol_chain (symbol_rootP, symbol_lastP);
265 #ifdef NEED_ECOFF_DEBUG
271 obj_elf_common (is_common)
281 if (flag_mri && is_common)
287 name = input_line_pointer;
288 c = get_symbol_end ();
289 /* just after name is now '\0' */
290 p = input_line_pointer;
293 if (*input_line_pointer != ',')
295 as_bad (_("Expected comma after symbol-name"));
296 ignore_rest_of_line ();
299 input_line_pointer++; /* skip ',' */
300 if ((temp = get_absolute_expression ()) < 0)
302 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp);
303 ignore_rest_of_line ();
308 symbolP = symbol_find_or_make (name);
310 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
312 as_bad (_("Ignoring attempt to re-define symbol"));
313 ignore_rest_of_line ();
316 if (S_GET_VALUE (symbolP) != 0)
318 if (S_GET_VALUE (symbolP) != (valueT) size)
320 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
321 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
324 know (symbolP->sy_frag == &zero_address_frag);
325 if (*input_line_pointer != ',')
330 input_line_pointer++;
333 if (! have_align || *input_line_pointer != '"')
339 temp = get_absolute_expression ();
343 as_warn (_("Common alignment negative; 0 assumed"));
346 if (symbol_get_obj (symbolP)->local)
355 old_subsec = now_subseg;
358 /* convert to a power of 2 alignment */
359 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
362 as_bad (_("Common alignment not a power of 2"));
363 ignore_rest_of_line ();
369 record_alignment (bss_section, align);
370 subseg_set (bss_section, 0);
372 frag_align (align, 0, 0);
373 if (S_GET_SEGMENT (symbolP) == bss_section)
374 symbol_get_frag (symbolP)->fr_symbol = 0;
375 symbol_set_frag (symbolP, frag_now);
376 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
377 (offsetT) size, (char *) 0);
379 S_SET_SIZE (symbolP, size);
380 S_SET_SEGMENT (symbolP, bss_section);
381 S_CLEAR_EXTERNAL (symbolP);
382 subseg_set (old_sec, old_subsec);
387 S_SET_VALUE (symbolP, (valueT) size);
388 S_SET_ALIGN (symbolP, temp);
389 S_SET_EXTERNAL (symbolP);
390 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
395 input_line_pointer++;
396 /* @@ Some use the dot, some don't. Can we get some consistency?? */
397 if (*input_line_pointer == '.')
398 input_line_pointer++;
399 /* @@ Some say data, some say bss. */
400 if (strncmp (input_line_pointer, "bss\"", 4)
401 && strncmp (input_line_pointer, "data\"", 5))
403 while (*--input_line_pointer != '"')
405 input_line_pointer--;
406 goto bad_common_segment;
408 while (*input_line_pointer++ != '"')
410 goto allocate_common;
413 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
415 demand_empty_rest_of_line ();
420 p = input_line_pointer;
421 while (*p && *p != '\n')
425 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
427 input_line_pointer = p;
428 ignore_rest_of_line ();
434 obj_elf_local (ignore)
435 int ignore ATTRIBUTE_UNUSED;
443 name = input_line_pointer;
444 c = get_symbol_end ();
445 symbolP = symbol_find_or_make (name);
446 *input_line_pointer = c;
448 S_CLEAR_EXTERNAL (symbolP);
449 symbol_get_obj (symbolP)->local = 1;
452 input_line_pointer++;
454 if (*input_line_pointer == '\n')
459 demand_empty_rest_of_line ();
463 obj_elf_weak (ignore)
464 int ignore ATTRIBUTE_UNUSED;
472 name = input_line_pointer;
473 c = get_symbol_end ();
474 symbolP = symbol_find_or_make (name);
475 *input_line_pointer = c;
477 S_SET_WEAK (symbolP);
478 symbol_get_obj (symbolP)->local = 1;
481 input_line_pointer++;
483 if (*input_line_pointer == '\n')
488 demand_empty_rest_of_line ();
492 obj_elf_visibility (visibility)
499 elf_symbol_type *elfsym;
503 name = input_line_pointer;
504 c = get_symbol_end ();
505 symbolP = symbol_find_or_make (name);
506 *input_line_pointer = c;
510 bfdsym = symbol_get_bfdsym (symbolP);
511 elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
515 elfsym->internal_elf_sym.st_other = visibility;
519 input_line_pointer ++;
523 if (*input_line_pointer == '\n')
529 demand_empty_rest_of_line ();
533 static segT previous_section;
534 static int previous_subsection;
538 struct section_stack *next;
540 int subseg, prev_subseg;
543 static struct section_stack *section_stack;
546 /* Handle the .section pseudo-op. This code supports two different
549 The first is found on Solaris, and looks like
550 .section ".sec1",#alloc,#execinstr,#write
551 Here the names after '#' are the SHF_* flags to turn on for the
552 section. I'm not sure how it determines the SHT_* type (BFD
553 doesn't really give us control over the type, anyhow).
555 The second format is found on UnixWare, and probably most SVR4
556 machines, and looks like
557 .section .sec1,"a",@progbits
558 The quoted string may contain any combination of a, w, x, and
559 represents the SHF_* flags to turn on for the section. The string
560 beginning with '@' can be progbits or nobits. There should be
561 other possibilities, but I don't know what they are. In any case,
562 BFD doesn't really let us set the section type. */
564 /* Certain named sections have particular defined types, listed on p.
566 struct special_section
573 static struct special_section const special_sections[] =
575 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
576 { ".comment", SHT_PROGBITS, 0 },
577 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
578 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
579 { ".debug", SHT_PROGBITS, 0 },
580 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
581 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
582 { ".line", SHT_PROGBITS, 0 },
583 { ".note", SHT_NOTE, 0 },
584 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
585 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
586 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
588 #ifdef ELF_TC_SPECIAL_SECTIONS
589 ELF_TC_SPECIAL_SECTIONS
593 /* The following section names are special, but they can not
594 reasonably appear in assembler code. Some of the attributes are
595 processor dependent. */
596 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
597 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
598 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
599 { ".got", SHT_PROGBITS, 0 },
600 { ".hash", SHT_HASH, SHF_ALLOC },
601 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
602 { ".plt", SHT_PROGBITS, 0 },
603 { ".shstrtab",SHT_STRTAB, 0 },
604 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
605 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
612 obj_elf_change_section (name, type, attr, push)
614 int type, attr, push;
619 #ifdef md_flush_pending_output
620 md_flush_pending_output ();
623 /* Switch to the section, creating it if necessary. */
626 struct section_stack *elt;
627 elt = xmalloc (sizeof (struct section_stack));
628 elt->next = section_stack;
630 elt->prev_seg = previous_section;
631 elt->subseg = now_subseg;
632 elt->prev_subseg = previous_subsection;
635 previous_section = now_seg;
636 previous_subsection = now_subseg;
638 new_sec = bfd_get_section_by_name (stdoutput, name) == NULL;
639 sec = subseg_new (name, 0);
647 /* See if this is one of the special sections. */
648 for (i = 0; special_sections[i].name != NULL; i++)
649 if (strcmp (name, special_sections[i].name) == 0)
651 if (type == SHT_NULL)
652 type = special_sections[i].type;
653 else if (type != special_sections[i].type)
654 as_warn (_("Setting incorrect section type for %s"), name);
656 if ((attr &~ special_sections[i].attributes) != 0)
658 /* As a GNU extension, we permit a .note section to be
659 allocatable. If the linker sees an allocateable .note
660 section, it will create a PT_NOTE segment in the output
662 if (strcmp (name, ".note") != 0
663 || attr != SHF_ALLOC)
664 as_warn (_("Setting incorrect section attributes for %s"),
667 attr |= special_sections[i].attributes;
671 /* Convert ELF type and flags to BFD flags. */
673 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
674 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
675 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
676 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0));
677 #ifdef md_elf_section_flags
678 flags = md_elf_section_flags (flags, attr, type);
681 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
682 if (type == SHT_NOBITS)
683 seg_info (sec)->bss = 1;
685 bfd_set_section_flags (stdoutput, sec, flags);
687 /* Add a symbol for this section to the symbol table. */
688 secsym = symbol_find (name);
690 symbol_set_bfdsym (secsym, sec->symbol);
692 symbol_table_insert (section_symbol (sec));
695 #ifdef md_elf_section_change_hook
696 md_elf_section_change_hook ();
701 obj_elf_parse_section_letters (str, len)
718 attr |= SHF_EXECINSTR;
722 char *bad_msg = _("Unrecognized .section attribute: want a,w,x");
723 #ifdef md_elf_section_letter
724 int md_attr = md_elf_section_letter (*str, &bad_msg);
730 as_warn ("%s", bad_msg);
743 obj_elf_section_word (str, len)
747 if (len == 5 && strncmp (str, "write", 5) == 0)
749 if (len == 5 && strncmp (str, "alloc", 5) == 0)
751 if (len == 9 && strncmp (str, "execinstr", 9) == 0)
752 return SHF_EXECINSTR;
754 #ifdef md_elf_section_word
756 int md_attr = md_elf_section_word (str, len);
762 as_warn (_("Unrecognized section attribute"));
767 obj_elf_section_type (str, len)
771 if (len == 8 && strncmp (str, "progbits", 8) == 0)
773 if (len == 6 && strncmp (str, "nobits", 6) == 0)
776 #ifdef md_elf_section_type
778 int md_type = md_elf_section_type (str, len);
784 as_warn (_("Unrecognized section type"));
789 obj_elf_section (push)
792 char *name, *beg, *end;
793 int type, attr, dummy;
799 #ifdef md_flush_pending_output
800 md_flush_pending_output ();
803 previous_section = now_seg;
804 previous_subsection = now_subseg;
806 s_mri_sect (&mri_type);
808 #ifdef md_elf_section_change_hook
809 md_elf_section_change_hook ();
815 /* Get name of section. */
817 if (*input_line_pointer == '"')
819 name = demand_copy_C_string (&dummy);
822 ignore_rest_of_line ();
828 end = input_line_pointer;
829 while (0 == strchr ("\n\t,; ", *end))
831 if (end == input_line_pointer)
833 as_warn (_("Missing section name"));
834 ignore_rest_of_line ();
838 name = xmalloc (end - input_line_pointer + 1);
839 memcpy (name, input_line_pointer, end - input_line_pointer);
840 name[end - input_line_pointer] = '\0';
841 input_line_pointer = end;
848 if (*input_line_pointer == ',')
850 /* Skip the comma. */
851 ++input_line_pointer;
854 if (*input_line_pointer == '"')
856 beg = demand_copy_C_string (&dummy);
859 ignore_rest_of_line ();
862 attr |= obj_elf_parse_section_letters (beg, strlen (beg));
865 if (*input_line_pointer == ',')
868 ++input_line_pointer;
870 c = *input_line_pointer;
873 beg = demand_copy_C_string (&dummy);
876 ignore_rest_of_line ();
879 type = obj_elf_section_type (beg, strlen (beg));
881 else if (c == '@' || c == '%')
883 beg = ++input_line_pointer;
884 c = get_symbol_end ();
885 *input_line_pointer = c;
886 type = obj_elf_section_type (beg, input_line_pointer - beg);
897 if (*input_line_pointer != '#')
899 as_warn (_("Bad .section directive - character following name is not '#'"));
900 ignore_rest_of_line ();
903 beg = ++input_line_pointer;
904 c = get_symbol_end ();
905 *input_line_pointer = c;
907 attr |= obj_elf_section_word (beg, input_line_pointer - beg);
911 while (*input_line_pointer++ == ',');
912 --input_line_pointer;
916 demand_empty_rest_of_line ();
918 obj_elf_change_section (name, type, attr, push);
921 /* Change to the .data section. */
927 #ifdef md_flush_pending_output
928 md_flush_pending_output ();
931 previous_section = now_seg;
932 previous_subsection = now_subseg;
935 #ifdef md_elf_section_change_hook
936 md_elf_section_change_hook ();
940 /* Change to the .text section. */
946 #ifdef md_flush_pending_output
947 md_flush_pending_output ();
950 previous_section = now_seg;
951 previous_subsection = now_subseg;
954 #ifdef md_elf_section_change_hook
955 md_elf_section_change_hook ();
960 obj_elf_subsection (ignore)
961 int ignore ATTRIBUTE_UNUSED;
965 #ifdef md_flush_pending_output
966 md_flush_pending_output ();
969 previous_section = now_seg;
970 previous_subsection = now_subseg;
972 temp = get_absolute_expression ();
973 subseg_set (now_seg, (subsegT) temp);
974 demand_empty_rest_of_line ();
976 #ifdef md_elf_section_change_hook
977 md_elf_section_change_hook ();
981 /* This can be called from the processor backends if they change
985 obj_elf_section_change_hook ()
987 previous_section = now_seg;
988 previous_subsection = now_subseg;
992 obj_elf_previous (ignore)
993 int ignore ATTRIBUTE_UNUSED;
998 if (previous_section == 0)
1000 as_bad (_(".previous without corresponding .section; ignored"));
1004 #ifdef md_flush_pending_output
1005 md_flush_pending_output ();
1008 new_section = previous_section;
1009 new_subsection = previous_subsection;
1010 previous_section = now_seg;
1011 previous_subsection = now_subseg;
1012 subseg_set (new_section, new_subsection);
1014 #ifdef md_elf_section_change_hook
1015 md_elf_section_change_hook ();
1020 obj_elf_popsection (xxx)
1021 int xxx ATTRIBUTE_UNUSED;
1023 struct section_stack *top = section_stack;
1027 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1031 #ifdef md_flush_pending_output
1032 md_flush_pending_output ();
1035 section_stack = top->next;
1036 previous_section = top->prev_seg;
1037 previous_subsection = top->prev_subseg;
1038 subseg_set (top->seg, top->subseg);
1041 #ifdef md_elf_section_change_hook
1042 md_elf_section_change_hook ();
1047 obj_elf_line (ignore)
1048 int ignore ATTRIBUTE_UNUSED;
1050 /* Assume delimiter is part of expression. BSD4.2 as fails with
1051 delightful bug, so we are not being incompatible here. */
1052 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
1053 demand_empty_rest_of_line ();
1056 /* This handles the .symver pseudo-op, which is used to specify a
1057 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1058 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1059 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1060 with the same value as the symbol NAME. */
1063 obj_elf_symver (ignore)
1064 int ignore ATTRIBUTE_UNUSED;
1070 name = input_line_pointer;
1071 c = get_symbol_end ();
1073 sym = symbol_find_or_make (name);
1075 *input_line_pointer = c;
1077 if (symbol_get_obj (sym)->versioned_name != NULL)
1079 as_bad (_("multiple .symver directives for symbol `%s'"),
1081 ignore_rest_of_line ();
1086 if (*input_line_pointer != ',')
1088 as_bad (_("expected comma after name in .symver"));
1089 ignore_rest_of_line ();
1093 ++input_line_pointer;
1094 name = input_line_pointer;
1097 c = get_symbol_end ();
1098 if (c != ELF_VER_CHR)
1100 *input_line_pointer++ = c;
1103 symbol_get_obj (sym)->versioned_name = xstrdup (name);
1105 *input_line_pointer = c;
1107 if (strchr (symbol_get_obj (sym)->versioned_name, ELF_VER_CHR) == NULL)
1109 as_bad (_("missing version name in `%s' for symbol `%s'"),
1110 symbol_get_obj (sym)->versioned_name, S_GET_NAME (sym));
1111 ignore_rest_of_line ();
1115 demand_empty_rest_of_line ();
1118 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1119 to the linker the hierarchy in which a particular table resides. The
1120 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1123 obj_elf_vtable_inherit (ignore)
1124 int ignore ATTRIBUTE_UNUSED;
1126 char *cname, *pname;
1127 symbolS *csym, *psym;
1130 if (*input_line_pointer == '#')
1131 ++input_line_pointer;
1133 cname = input_line_pointer;
1134 c = get_symbol_end ();
1135 csym = symbol_find (cname);
1137 /* GCFIXME: should check that we don't have two .vtable_inherits for
1138 the same child symbol. Also, we can currently only do this if the
1139 child symbol is already exists and is placed in a fragment. */
1141 if (csym == NULL || symbol_get_frag (csym) == NULL)
1143 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1148 *input_line_pointer = c;
1151 if (*input_line_pointer != ',')
1153 as_bad ("expected comma after name in .vtable_inherit");
1154 ignore_rest_of_line ();
1158 ++input_line_pointer;
1161 if (*input_line_pointer == '#')
1162 ++input_line_pointer;
1164 if (input_line_pointer[0] == '0'
1165 && (input_line_pointer[1] == '\0'
1166 || isspace ((unsigned char) input_line_pointer[1])))
1168 psym = section_symbol (absolute_section);
1169 ++input_line_pointer;
1173 pname = input_line_pointer;
1174 c = get_symbol_end ();
1175 psym = symbol_find_or_make (pname);
1176 *input_line_pointer = c;
1179 demand_empty_rest_of_line ();
1184 assert (symbol_get_value_expression (csym)->X_op == O_constant);
1185 fix_new (symbol_get_frag (csym),
1186 symbol_get_value_expression (csym)->X_add_number, 0, psym, 0, 0,
1187 BFD_RELOC_VTABLE_INHERIT);
1190 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1191 to the linker that a vtable slot was used. The syntax is
1192 ".vtable_entry tablename, offset". */
1195 obj_elf_vtable_entry (ignore)
1196 int ignore ATTRIBUTE_UNUSED;
1203 if (*input_line_pointer == '#')
1204 ++input_line_pointer;
1206 name = input_line_pointer;
1207 c = get_symbol_end ();
1208 sym = symbol_find_or_make (name);
1209 *input_line_pointer = c;
1212 if (*input_line_pointer != ',')
1214 as_bad ("expected comma after name in .vtable_entry");
1215 ignore_rest_of_line ();
1219 ++input_line_pointer;
1220 if (*input_line_pointer == '#')
1221 ++input_line_pointer;
1223 offset = get_absolute_expression ();
1225 fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
1226 BFD_RELOC_VTABLE_ENTRY);
1228 demand_empty_rest_of_line ();
1232 elf_obj_read_begin_hook ()
1234 #ifdef NEED_ECOFF_DEBUG
1235 if (ECOFF_DEBUGGING)
1236 ecoff_read_begin_hook ();
1241 elf_obj_symbol_new_hook (symbolP)
1244 struct elf_obj_sy *sy_obj;
1246 sy_obj = symbol_get_obj (symbolP);
1247 sy_obj->size = NULL;
1248 sy_obj->versioned_name = NULL;
1250 #ifdef NEED_ECOFF_DEBUG
1251 if (ECOFF_DEBUGGING)
1252 ecoff_symbol_new_hook (symbolP);
1257 obj_elf_version (ignore)
1258 int ignore ATTRIBUTE_UNUSED;
1264 asection *seg = now_seg;
1265 subsegT subseg = now_subseg;
1266 Elf_Internal_Note i_note;
1267 Elf_External_Note e_note;
1268 asection *note_secp = (asection *) NULL;
1272 if (*input_line_pointer == '\"')
1274 ++input_line_pointer; /* -> 1st char of string. */
1275 name = input_line_pointer;
1277 while (is_a_char (c = next_char_of_string ()))
1279 c = *input_line_pointer;
1280 *input_line_pointer = '\0';
1281 *(input_line_pointer - 1) = '\0';
1282 *input_line_pointer = c;
1284 /* create the .note section */
1286 note_secp = subseg_new (".note", 0);
1287 bfd_set_section_flags (stdoutput,
1289 SEC_HAS_CONTENTS | SEC_READONLY);
1291 /* process the version string */
1293 len = strlen (name);
1295 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1296 i_note.descsz = 0; /* no description */
1297 i_note.type = NT_VERSION;
1298 p = frag_more (sizeof (e_note.namesz));
1299 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1300 p = frag_more (sizeof (e_note.descsz));
1301 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1302 p = frag_more (sizeof (e_note.type));
1303 md_number_to_chars (p, (valueT) i_note.type, 4);
1305 for (i = 0; i < len; i++)
1309 FRAG_APPEND_1_CHAR (ch);
1312 frag_align (2, 0, 0);
1314 subseg_set (seg, subseg);
1318 as_bad (_("Expected quoted string"));
1320 demand_empty_rest_of_line ();
1324 obj_elf_size (ignore)
1325 int ignore ATTRIBUTE_UNUSED;
1327 char *name = input_line_pointer;
1328 char c = get_symbol_end ();
1333 p = input_line_pointer;
1336 if (*input_line_pointer != ',')
1339 as_bad (_("expected comma after name `%s' in .size directive"), name);
1341 ignore_rest_of_line ();
1344 input_line_pointer++;
1346 if (exp.X_op == O_absent)
1348 as_bad (_("missing expression in .size directive"));
1349 exp.X_op = O_constant;
1350 exp.X_add_number = 0;
1353 sym = symbol_find_or_make (name);
1355 if (exp.X_op == O_constant)
1356 S_SET_SIZE (sym, exp.X_add_number);
1359 symbol_get_obj (sym)->size =
1360 (expressionS *) xmalloc (sizeof (expressionS));
1361 *symbol_get_obj (sym)->size = exp;
1363 demand_empty_rest_of_line ();
1366 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1367 There are four syntaxes:
1369 The first (used on Solaris) is
1371 The second (used on UnixWare) is
1373 The third (reportedly to be used on Irix 6.0) is
1375 The fourth (used on NetBSD/Arm and Linux/ARM) is
1380 obj_elf_type (ignore)
1381 int ignore ATTRIBUTE_UNUSED;
1386 const char *typename;
1389 name = input_line_pointer;
1390 c = get_symbol_end ();
1391 sym = symbol_find_or_make (name);
1392 *input_line_pointer = c;
1395 if (*input_line_pointer == ',')
1396 ++input_line_pointer;
1399 if ( *input_line_pointer == '#'
1400 || *input_line_pointer == '@'
1401 || *input_line_pointer == '%')
1402 ++input_line_pointer;
1404 typename = input_line_pointer;
1405 c = get_symbol_end ();
1408 if (strcmp (typename, "function") == 0
1409 || strcmp (typename, "STT_FUNC") == 0)
1410 type = BSF_FUNCTION;
1411 else if (strcmp (typename, "object") == 0
1412 || strcmp (typename, "STT_OBJECT") == 0)
1415 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename);
1417 *input_line_pointer = c;
1419 symbol_get_bfdsym (sym)->flags |= type;
1421 demand_empty_rest_of_line ();
1425 obj_elf_ident (ignore)
1426 int ignore ATTRIBUTE_UNUSED;
1428 static segT comment_section;
1429 segT old_section = now_seg;
1430 int old_subsection = now_subseg;
1432 #ifdef md_flush_pending_output
1433 md_flush_pending_output ();
1436 if (!comment_section)
1439 comment_section = subseg_new (".comment", 0);
1440 bfd_set_section_flags (stdoutput, comment_section,
1441 SEC_READONLY | SEC_HAS_CONTENTS);
1446 subseg_set (comment_section, 0);
1448 subseg_set (old_section, old_subsection);
1451 #ifdef INIT_STAB_SECTION
1453 /* The first entry in a .stabs section is special. */
1456 obj_elf_init_stab_section (seg)
1462 unsigned int stroff;
1464 /* Force the section to align to a longword boundary. Without this,
1465 UnixWare ar crashes. */
1466 bfd_set_section_alignment (stdoutput, seg, 2);
1468 /* Make space for this first symbol. */
1472 as_where (&file, (unsigned int *) NULL);
1473 stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4);
1474 strcpy (stabstr_name, segment_name (seg));
1475 strcat (stabstr_name, "str");
1476 stroff = get_stab_string_offset (file, stabstr_name);
1478 md_number_to_chars (p, stroff, 4);
1479 seg_info (seg)->stabu.p = p;
1484 /* Fill in the counts in the first entry in a .stabs section. */
1487 adjust_stab_sections (abfd, sec, xxx)
1490 PTR xxx ATTRIBUTE_UNUSED;
1497 if (strncmp (".stab", sec->name, 5))
1499 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1502 name = (char *) alloca (strlen (sec->name) + 4);
1503 strcpy (name, sec->name);
1504 strcat (name, "str");
1505 strsec = bfd_get_section_by_name (abfd, name);
1507 strsz = bfd_section_size (abfd, strsec);
1510 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1512 p = seg_info (sec)->stabu.p;
1515 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1516 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1519 #ifdef NEED_ECOFF_DEBUG
1521 /* This function is called by the ECOFF code. It is supposed to
1522 record the external symbol information so that the backend can
1523 write it out correctly. The ELF backend doesn't actually handle
1524 this at the moment, so we do it ourselves. We save the information
1528 elf_ecoff_set_ext (sym, ext)
1530 struct ecoff_extr *ext;
1532 symbol_get_bfdsym (sym)->udata.p = (PTR) ext;
1535 /* This function is called by bfd_ecoff_debug_externals. It is
1536 supposed to *EXT to the external symbol information, and return
1537 whether the symbol should be used at all. */
1540 elf_get_extr (sym, ext)
1544 if (sym->udata.p == NULL)
1546 *ext = *(EXTR *) sym->udata.p;
1550 /* This function is called by bfd_ecoff_debug_externals. It has
1551 nothing to do for ELF. */
1555 elf_set_index (sym, indx)
1556 asymbol *sym ATTRIBUTE_UNUSED;
1557 bfd_size_type indx ATTRIBUTE_UNUSED;
1561 #endif /* NEED_ECOFF_DEBUG */
1564 elf_frob_symbol (symp, puntp)
1568 struct elf_obj_sy *sy_obj;
1570 #ifdef NEED_ECOFF_DEBUG
1571 if (ECOFF_DEBUGGING)
1572 ecoff_frob_symbol (symp);
1575 sy_obj = symbol_get_obj (symp);
1577 if (sy_obj->size != NULL)
1579 switch (sy_obj->size->X_op)
1583 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1584 + sy_obj->size->X_add_number
1585 - S_GET_VALUE (sy_obj->size->X_op_symbol)));
1589 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1590 + sy_obj->size->X_add_number));
1593 as_bad (_(".size expression too complicated to fix up"));
1596 free (sy_obj->size);
1597 sy_obj->size = NULL;
1600 if (sy_obj->versioned_name != NULL)
1602 /* This symbol was given a new name with the .symver directive.
1604 If this is an external reference, just rename the symbol to
1605 include the version string. This will make the relocs be
1606 against the correct versioned symbol.
1608 If this is a definition, add an alias. FIXME: Using an alias
1609 will permit the debugging information to refer to the right
1610 symbol. However, it's not clear whether it is the best
1613 if (! S_IS_DEFINED (symp))
1617 /* Verify that the name isn't using the @@ syntax--this is
1618 reserved for definitions of the default version to link
1620 p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
1622 if (p[1] == ELF_VER_CHR)
1624 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1625 sy_obj->versioned_name);
1628 S_SET_NAME (symp, sy_obj->versioned_name);
1634 /* FIXME: Creating a new symbol here is risky. We're in the
1635 final loop over the symbol table. We can get away with
1636 it only because the symbol goes to the end of the list,
1637 where the loop will still see it. It would probably be
1638 better to do this in obj_frob_file_before_adjust. */
1640 symp2 = symbol_find_or_make (sy_obj->versioned_name);
1642 /* Now we act as though we saw symp2 = sym. */
1644 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1646 /* Subtracting out the frag address here is a hack because
1647 we are in the middle of the final loop. */
1650 - symbol_get_frag (symp)->fr_address));
1652 symbol_set_frag (symp2, symbol_get_frag (symp));
1654 /* This will copy over the size information. */
1655 copy_symbol_attributes (symp2, symp);
1657 if (S_IS_WEAK (symp))
1660 if (S_IS_EXTERNAL (symp))
1661 S_SET_EXTERNAL (symp2);
1665 /* Double check weak symbols. */
1666 if (S_IS_WEAK (symp))
1668 if (S_IS_COMMON (symp))
1669 as_bad (_("Symbol `%s' can not be both weak and common"),
1674 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1675 any undefined non-function symbol to STT_OBJECT. We try to be
1676 compatible, since newer Irix 5 and 6 linkers care. However, we
1677 only set undefined symbols to be STT_OBJECT if we are on Irix,
1678 because that is the only time gcc will generate the necessary
1679 .global directives to mark functions. */
1681 if (S_IS_COMMON (symp))
1682 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1684 if (strstr (TARGET_OS, "irix") != NULL
1685 && ! S_IS_DEFINED (symp)
1686 && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
1687 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1691 /* Frob the PowerPC, so that the symbol always has object type
1692 if it is not some other type. VxWorks needs this. */
1693 if ((symbol_get_bfdsym (symp)->flags
1694 & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1695 && S_IS_DEFINED (symp))
1696 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1703 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
1705 #ifdef elf_tc_final_processing
1706 elf_tc_final_processing ();
1710 /* It is required that we let write_relocs have the opportunity to
1711 optimize away fixups before output has begun, since it is possible
1712 to eliminate all fixups for a section and thus we never should
1713 have generated the relocation section. */
1716 elf_frob_file_after_relocs ()
1718 #ifdef NEED_ECOFF_DEBUG
1719 if (ECOFF_DEBUGGING)
1720 /* Generate the ECOFF debugging information. */
1722 const struct ecoff_debug_swap *debug_swap;
1723 struct ecoff_debug_info debug;
1728 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
1729 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
1730 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
1732 /* Set up the pointers in debug. */
1733 #define SET(ptr, offset, type) \
1734 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1736 SET (line, cbLineOffset, unsigned char *);
1737 SET (external_dnr, cbDnOffset, PTR);
1738 SET (external_pdr, cbPdOffset, PTR);
1739 SET (external_sym, cbSymOffset, PTR);
1740 SET (external_opt, cbOptOffset, PTR);
1741 SET (external_aux, cbAuxOffset, union aux_ext *);
1742 SET (ss, cbSsOffset, char *);
1743 SET (external_fdr, cbFdOffset, PTR);
1744 SET (external_rfd, cbRfdOffset, PTR);
1745 /* ssext and external_ext are set up just below. */
1749 /* Set up the external symbols. */
1750 debug.ssext = debug.ssext_end = NULL;
1751 debug.external_ext = debug.external_ext_end = NULL;
1752 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true,
1753 elf_get_extr, elf_set_index))
1754 as_fatal (_("Failed to set up debugging information: %s"),
1755 bfd_errmsg (bfd_get_error ()));
1757 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
1758 assert (sec != NULL);
1760 know (stdoutput->output_has_begun == false);
1762 /* We set the size of the section, call bfd_set_section_contents
1763 to force the ELF backend to allocate a file position, and then
1764 write out the data. FIXME: Is this really the best way to do
1766 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
1768 /* Pass BUF to bfd_set_section_contents because this will
1769 eventually become a call to fwrite, and ISO C prohibits
1770 passing a NULL pointer to a stdio function even if the
1771 pointer will not be used. */
1772 if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf,
1773 (file_ptr) 0, (bfd_size_type) 0))
1774 as_fatal (_("Can't start writing .mdebug section: %s"),
1775 bfd_errmsg (bfd_get_error ()));
1777 know (stdoutput->output_has_begun == true);
1778 know (sec->filepos != 0);
1780 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
1782 as_fatal (_("Could not write .mdebug section: %s"),
1783 bfd_errmsg (bfd_get_error ()));
1785 #endif /* NEED_ECOFF_DEBUG */
1790 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1791 SCO specific identifier in the .notes section to satisfy the SCO
1794 This looks more complicated than it really is. As opposed to the
1795 "obvious" solution, this should handle the cross dev cases
1796 correctly. (i.e, hosting on a 64 bit big endian processor, but
1797 generating SCO Elf code) Efficiency isn't a concern, as there
1798 should be exactly one of these sections per object module.
1800 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1803 int_32 namesz = 4 ; Name size
1804 int_32 descsz = 12 ; Descriptive information
1806 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1807 int_32 version = (major ver # << 16) | version of tools ;
1808 int_32 source = (tool_id << 16 ) | 1 ;
1809 int_32 info = 0 ; These are set by the SCO tools, but we
1810 don't know enough about the source
1811 environment to set them. SCO ld currently
1812 ignores them, and recommends we set them
1815 #define SCO_MAJOR_VERSION 0x1
1816 #define SCO_MINOR_VERSION 0x1
1826 asection *seg = now_seg;
1827 subsegT subseg = now_subseg;
1828 Elf_Internal_Note i_note;
1829 Elf_External_Note e_note;
1830 asection *note_secp = (asection *) NULL;
1833 /* create the .note section */
1835 note_secp = subseg_new (".note", 0);
1836 bfd_set_section_flags (stdoutput,
1838 SEC_HAS_CONTENTS | SEC_READONLY);
1840 /* process the version string */
1843 i_note.descsz = 12; /* 12 descriptive bytes */
1844 i_note.type = NT_VERSION; /* Contains a version string */
1846 p = frag_more (sizeof (i_note.namesz));
1847 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1849 p = frag_more (sizeof (i_note.descsz));
1850 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1852 p = frag_more (sizeof (i_note.type));
1853 md_number_to_chars (p, (valueT) i_note.type, 4);
1858 /* Note: this is the version number of the ELF we're representing */
1860 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
1862 /* Here, we pick a magic number for ourselves (yes, I "registered"
1863 it with SCO. The bottom bit shows that we are compat with the
1866 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
1868 /* If we knew (or cared) what the source language options were, we'd
1869 fill them in here. SCO has given us permission to ignore these
1870 and just set them to zero. */
1872 md_number_to_chars (p, 0x0000, 4);
1874 frag_align (2, 0, 0);
1876 /* We probably can't restore the current segment, for there likely
1879 subseg_set (seg, subseg);
1883 #endif /* SCO_ELF */
1885 const struct format_ops elf_format_ops =
1887 bfd_target_elf_flavour,
1888 0, /* dfl_leading_underscore */
1889 1, /* emit_section_symbols */
1892 elf_frob_file_after_relocs,
1893 elf_s_get_size, elf_s_set_size,
1894 elf_s_get_align, elf_s_set_align,
1897 elf_copy_symbol_attributes,
1898 #ifdef NEED_ECOFF_DEBUG
1899 ecoff_generate_asm_lineno,
1902 0, /* generate_asm_lineno */
1903 0, /* process_stab */
1905 elf_sec_sym_ok_for_reloc,
1907 #ifdef NEED_ECOFF_DEBUG
1910 0, /* ecoff_set_ext */
1912 elf_obj_read_begin_hook,
1913 elf_obj_symbol_new_hook,