1 /* ELF object file format
2 Copyright (C) 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 #define OBJ_HEADER "obj-elf.h"
26 #ifndef ECOFF_DEBUGGING
27 #define ECOFF_DEBUGGING 0
29 #define NEED_ECOFF_DEBUG
32 #ifdef NEED_ECOFF_DEBUG
44 #ifdef NEED_ECOFF_DEBUG
45 static boolean elf_get_extr PARAMS ((asymbol *, EXTR *));
46 static void elf_set_index PARAMS ((asymbol *, bfd_size_type));
49 static void obj_elf_line PARAMS ((int));
50 void obj_elf_version PARAMS ((int));
51 static void obj_elf_size PARAMS ((int));
52 static void obj_elf_type PARAMS ((int));
53 static void obj_elf_ident PARAMS ((int));
54 static void obj_elf_weak PARAMS ((int));
55 static void obj_elf_local PARAMS ((int));
56 static void obj_elf_common PARAMS ((int));
57 static void obj_elf_data PARAMS ((int));
58 static void obj_elf_text PARAMS ((int));
60 static const pseudo_typeS elf_pseudo_table[] =
62 {"comm", obj_elf_common, 0},
63 {"ident", obj_elf_ident, 0},
64 {"local", obj_elf_local, 0},
65 {"previous", obj_elf_previous, 0},
66 {"section", obj_elf_section, 0},
67 {"section.s", obj_elf_section, 0},
68 {"sect", obj_elf_section, 0},
69 {"sect.s", obj_elf_section, 0},
70 {"size", obj_elf_size, 0},
71 {"type", obj_elf_type, 0},
72 {"version", obj_elf_version, 0},
73 {"weak", obj_elf_weak, 0},
75 /* These are used for stabs-in-elf configurations. */
76 {"line", obj_elf_line, 0},
78 /* These are used for dwarf. */
83 /* We need to trap the section changing calls to handle .previous. */
84 {"data", obj_elf_data, 0},
85 {"text", obj_elf_text, 0},
91 static const pseudo_typeS ecoff_debug_pseudo_table[] =
93 #ifdef NEED_ECOFF_DEBUG
94 /* COFF style debugging information for ECOFF. .ln is not used; .loc
96 { "def", ecoff_directive_def, 0 },
97 { "dim", ecoff_directive_dim, 0 },
98 { "endef", ecoff_directive_endef, 0 },
99 { "file", ecoff_directive_file, 0 },
100 { "scl", ecoff_directive_scl, 0 },
101 { "tag", ecoff_directive_tag, 0 },
102 { "val", ecoff_directive_val, 0 },
104 /* COFF debugging requires pseudo-ops .size and .type, but ELF
105 already has meanings for those. We use .esize and .etype
106 instead. These are only generated by gcc anyhow. */
107 { "esize", ecoff_directive_size, 0 },
108 { "etype", ecoff_directive_type, 0 },
110 /* ECOFF specific debugging information. */
111 { "begin", ecoff_directive_begin, 0 },
112 { "bend", ecoff_directive_bend, 0 },
113 { "end", ecoff_directive_end, 0 },
114 { "ent", ecoff_directive_ent, 0 },
115 { "fmask", ecoff_directive_fmask, 0 },
116 { "frame", ecoff_directive_frame, 0 },
117 { "loc", ecoff_directive_loc, 0 },
118 { "mask", ecoff_directive_mask, 0 },
120 /* Other ECOFF directives. */
121 { "extern", ecoff_directive_extern, 0 },
123 /* These are used on Irix. I don't know how to implement them. */
124 { "alias", s_ignore, 0 },
125 { "bgnb", s_ignore, 0 },
126 { "endb", s_ignore, 0 },
127 { "lab", s_ignore, 0 },
128 { "noalias", s_ignore, 0 },
129 { "verstamp", s_ignore, 0 },
130 { "vreg", s_ignore, 0 },
133 {NULL} /* end sentinel */
137 #include "aout/aout64.h"
142 pop_insert (elf_pseudo_table);
144 pop_insert (ecoff_debug_pseudo_table);
151 return S_GET_SIZE (sym);
155 elf_s_set_size (sym, sz)
159 S_SET_SIZE (sym, sz);
163 elf_s_get_align (sym)
166 return S_GET_ALIGN (sym);
170 elf_s_set_align (sym, align)
174 S_SET_ALIGN (sym, align);
178 elf_copy_symbol_attributes (dest, src)
181 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
185 elf_sec_sym_ok_for_reloc (sec)
188 return obj_sec_sym_ok_for_reloc (sec);
197 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
198 sym->sy_frag = &zero_address_frag;
199 sym->bsym->flags |= BSF_FILE;
201 if (symbol_rootP != sym)
203 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
204 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
206 verify_symbol_chain (symbol_rootP, symbol_lastP);
212 obj_elf_common (ignore)
222 name = input_line_pointer;
223 c = get_symbol_end ();
224 /* just after name is now '\0' */
225 p = input_line_pointer;
228 if (*input_line_pointer != ',')
230 as_bad ("Expected comma after symbol-name");
231 ignore_rest_of_line ();
234 input_line_pointer++; /* skip ',' */
235 if ((temp = get_absolute_expression ()) < 0)
237 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
238 ignore_rest_of_line ();
243 symbolP = symbol_find_or_make (name);
245 if (S_IS_DEFINED (symbolP))
247 as_bad ("Ignoring attempt to re-define symbol");
248 ignore_rest_of_line ();
251 if (S_GET_VALUE (symbolP) != 0)
253 if (S_GET_VALUE (symbolP) != size)
255 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
256 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
259 know (symbolP->sy_frag == &zero_address_frag);
260 if (*input_line_pointer != ',')
265 input_line_pointer++;
268 if (! have_align || *input_line_pointer != '"')
274 temp = get_absolute_expression ();
278 as_warn ("Common alignment negative; 0 assumed");
290 old_subsec = now_subseg;
293 /* convert to a power of 2 alignment */
294 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
297 as_bad ("Common alignment not a power of 2");
298 ignore_rest_of_line ();
304 record_alignment (bss_section, align);
305 subseg_set (bss_section, 0);
307 frag_align (align, 0);
308 if (S_GET_SEGMENT (symbolP) == bss_section)
309 symbolP->sy_frag->fr_symbol = 0;
310 symbolP->sy_frag = frag_now;
311 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
314 S_SET_SIZE (symbolP, size);
315 S_SET_SEGMENT (symbolP, bss_section);
316 S_CLEAR_EXTERNAL (symbolP);
317 subseg_set (old_sec, old_subsec);
322 S_SET_VALUE (symbolP, (valueT) size);
323 S_SET_ALIGN (symbolP, temp);
324 S_SET_EXTERNAL (symbolP);
325 /* should be common, but this is how gas does it for now */
326 S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
331 input_line_pointer++;
332 /* @@ Some use the dot, some don't. Can we get some consistency?? */
333 if (*input_line_pointer == '.')
334 input_line_pointer++;
335 /* @@ Some say data, some say bss. */
336 if (strncmp (input_line_pointer, "bss\"", 4)
337 && strncmp (input_line_pointer, "data\"", 5))
339 while (*--input_line_pointer != '"')
341 input_line_pointer--;
342 goto bad_common_segment;
344 while (*input_line_pointer++ != '"')
346 goto allocate_common;
348 demand_empty_rest_of_line ();
353 p = input_line_pointer;
354 while (*p && *p != '\n')
358 as_bad ("bad .common segment %s", input_line_pointer + 1);
360 input_line_pointer = p;
361 ignore_rest_of_line ();
367 obj_elf_local (ignore)
376 name = input_line_pointer;
377 c = get_symbol_end ();
378 symbolP = symbol_find_or_make (name);
379 *input_line_pointer = c;
381 S_CLEAR_EXTERNAL (symbolP);
385 input_line_pointer++;
387 if (*input_line_pointer == '\n')
392 demand_empty_rest_of_line ();
396 obj_elf_weak (ignore)
405 name = input_line_pointer;
406 c = get_symbol_end ();
407 symbolP = symbol_find_or_make (name);
408 *input_line_pointer = c;
410 S_SET_WEAK (symbolP);
414 input_line_pointer++;
416 if (*input_line_pointer == '\n')
421 demand_empty_rest_of_line ();
424 static segT previous_section;
425 static int previous_subsection;
427 /* Handle the .section pseudo-op. This code supports two different
430 The first is found on Solaris, and looks like
431 .section ".sec1",#alloc,#execinstr,#write
432 Here the names after '#' are the SHF_* flags to turn on for the
433 section. I'm not sure how it determines the SHT_* type (BFD
434 doesn't really give us control over the type, anyhow).
436 The second format is found on UnixWare, and probably most SVR4
437 machines, and looks like
438 .section .sec1,"a",@progbits
439 The quoted string may contain any combination of a, w, x, and
440 represents the SHF_* flags to turn on for the section. The string
441 beginning with '@' can be progbits or nobits. There should be
442 other possibilities, but I don't know what they are. In any case,
443 BFD doesn't really let us set the section type. */
445 /* Certain named sections have particular defined types, listed on p.
447 struct special_section
454 static struct special_section special_sections[] =
456 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
457 { ".comment", SHT_PROGBITS, 0 },
458 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
459 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
460 { ".debug", SHT_PROGBITS, 0 },
461 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
462 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
463 { ".line", SHT_PROGBITS, 0 },
464 { ".note", SHT_NOTE, 0 },
465 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
466 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
467 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
469 #ifdef ELF_TC_SPECIAL_SECTIONS
470 ELF_TC_SPECIAL_SECTIONS
474 /* The following section names are special, but they can not
475 reasonably appear in assembler code. Some of the attributes are
476 processor dependent. */
477 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
478 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
479 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
480 { ".got", SHT_PROGBITS, 0 },
481 { ".hash", SHT_HASH, SHF_ALLOC },
482 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
483 { ".plt", SHT_PROGBITS, 0 },
484 { ".shstrtab",SHT_STRTAB, 0 },
485 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
486 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
493 obj_elf_section (xxx)
503 #ifdef md_flush_pending_output
504 md_flush_pending_output ();
511 previous_section = now_seg;
512 previous_subsection = now_subseg;
514 s_mri_sect (&mri_type);
516 #ifdef md_elf_section_change_hook
517 md_elf_section_change_hook ();
523 /* Get name of section. */
525 if (*input_line_pointer == '"')
527 string = demand_copy_C_string (&xxx);
530 ignore_rest_of_line ();
536 char *p = input_line_pointer;
538 while (0 == strchr ("\n\t,; ", *p))
540 if (p == input_line_pointer)
542 as_warn ("Missing section name");
543 ignore_rest_of_line ();
548 string = xmalloc ((unsigned long) (p - input_line_pointer + 1));
549 strcpy (string, input_line_pointer);
551 input_line_pointer = p;
554 /* Switch to the section, creating it if necessary. */
555 previous_section = now_seg;
556 previous_subsection = now_subseg;
558 new_sec = bfd_get_section_by_name (stdoutput, string) == NULL;
559 sec = subseg_new (string, 0);
561 /* If this section already existed, we don't bother to change the
565 while (! is_end_of_line[(unsigned char) *input_line_pointer])
566 ++input_line_pointer;
567 ++input_line_pointer;
569 #ifdef md_elf_section_change_hook
570 md_elf_section_change_hook ();
581 if (*input_line_pointer == ',')
583 /* Skip the comma. */
584 ++input_line_pointer;
587 if (*input_line_pointer == '"')
589 /* Pick up a string with a combination of a, w, x. */
590 ++input_line_pointer;
591 while (*input_line_pointer != '"')
593 switch (*input_line_pointer)
602 attr |= SHF_EXECINSTR;
606 char *bad_msg = "Bad .section directive: want a,w,x in string";
607 #ifdef md_elf_section_letter
608 int md_attr = md_elf_section_letter (*input_line_pointer, &bad_msg);
615 ignore_rest_of_line ();
620 ++input_line_pointer;
623 /* Skip the closing quote. */
624 ++input_line_pointer;
627 if (*input_line_pointer == ',')
629 ++input_line_pointer;
631 if (*input_line_pointer == '@')
633 ++input_line_pointer;
634 if (strncmp (input_line_pointer, "progbits",
635 sizeof "progbits" - 1) == 0)
638 input_line_pointer += sizeof "progbits" - 1;
640 else if (strncmp (input_line_pointer, "nobits",
641 sizeof "nobits" - 1) == 0)
644 input_line_pointer += sizeof "nobits" - 1;
648 #ifdef md_elf_section_type
649 int md_type = md_elf_section_type (&input_line_pointer);
655 as_warn ("Unrecognized section type");
656 ignore_rest_of_line ();
667 if (*input_line_pointer != '#')
669 as_warn ("Bad .section directive");
670 ignore_rest_of_line ();
673 ++input_line_pointer;
674 if (strncmp (input_line_pointer, "write",
675 sizeof "write" - 1) == 0)
678 input_line_pointer += sizeof "write" - 1;
680 else if (strncmp (input_line_pointer, "alloc",
681 sizeof "alloc" - 1) == 0)
684 input_line_pointer += sizeof "alloc" - 1;
686 else if (strncmp (input_line_pointer, "execinstr",
687 sizeof "execinstr" - 1) == 0)
689 attr |= SHF_EXECINSTR;
690 input_line_pointer += sizeof "execinstr" - 1;
694 #ifdef md_elf_section_word
695 int md_attr = md_elf_section_word (&input_line_pointer);
701 as_warn ("Unrecognized section attribute");
702 ignore_rest_of_line ();
708 while (*input_line_pointer++ == ',');
709 --input_line_pointer;
713 /* See if this is one of the special sections. */
714 for (i = 0; special_sections[i].name != NULL; i++)
716 if (string[1] == special_sections[i].name[1]
717 && strcmp (string, special_sections[i].name) == 0)
719 if (type == SHT_NULL)
720 type = special_sections[i].type;
721 else if (type != special_sections[i].type)
722 as_warn ("Setting incorrect section type for %s", string);
724 if ((attr &~ special_sections[i].attributes) != 0)
725 as_warn ("Setting incorrect section attributes for %s", string);
726 attr |= special_sections[i].attributes;
733 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
734 | ((attr & SHF_ALLOC) ? SEC_ALLOC | SEC_LOAD : 0)
735 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0));
737 if (type == SHT_PROGBITS)
738 flags |= SEC_ALLOC | SEC_LOAD;
739 else if (type == SHT_NOBITS)
745 #ifdef md_elf_section_flags
746 if (special_sections[i].name == NULL)
747 flags = md_elf_section_flags (flags, attr, type);
750 bfd_set_section_flags (stdoutput, sec, flags);
752 #ifdef md_elf_section_change_hook
753 md_elf_section_change_hook ();
756 demand_empty_rest_of_line ();
759 /* Change to the .data section. */
765 previous_section = now_seg;
766 previous_subsection = now_subseg;
770 /* Change to the .text section. */
776 previous_section = now_seg;
777 previous_subsection = now_subseg;
782 obj_elf_previous (ignore)
785 if (previous_section == 0)
787 as_bad (".previous without corresponding .section; ignored");
790 subseg_set (previous_section, previous_subsection);
791 previous_section = 0;
795 obj_elf_line (ignore)
798 /* Assume delimiter is part of expression. BSD4.2 as fails with
799 delightful bug, so we are not being incompatible here. */
800 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
801 demand_empty_rest_of_line ();
805 obj_read_begin_hook ()
807 #ifdef NEED_ECOFF_DEBUG
809 ecoff_read_begin_hook ();
814 obj_symbol_new_hook (symbolP)
819 #ifdef NEED_ECOFF_DEBUG
821 ecoff_symbol_new_hook (symbolP);
826 obj_elf_version (ignore)
833 asection *seg = now_seg;
834 subsegT subseg = now_subseg;
835 Elf_Internal_Note i_note;
836 Elf_External_Note e_note;
837 asection *note_secp = (asection *) NULL;
841 if (*input_line_pointer == '\"')
843 ++input_line_pointer; /* -> 1st char of string. */
844 name = input_line_pointer;
846 while (is_a_char (c = next_char_of_string ()))
848 c = *input_line_pointer;
849 *input_line_pointer = '\0';
850 *(input_line_pointer - 1) = '\0';
851 *input_line_pointer = c;
853 /* create the .note section */
855 note_secp = subseg_new (".note", 0);
856 bfd_set_section_flags (stdoutput,
858 SEC_HAS_CONTENTS | SEC_READONLY);
860 /* process the version string */
864 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
865 i_note.descsz = 0; /* no description */
866 i_note.type = NT_VERSION;
867 p = frag_more (sizeof (e_note.namesz));
868 md_number_to_chars (p, (valueT) i_note.namesz, 4);
869 p = frag_more (sizeof (e_note.descsz));
870 md_number_to_chars (p, (valueT) i_note.descsz, 4);
871 p = frag_more (sizeof (e_note.type));
872 md_number_to_chars (p, (valueT) i_note.type, 4);
874 for (i = 0; i < len; i++)
878 FRAG_APPEND_1_CHAR (ch);
883 subseg_set (seg, subseg);
887 as_bad ("Expected quoted string");
889 demand_empty_rest_of_line ();
893 obj_elf_size (ignore)
896 char *name = input_line_pointer;
897 char c = get_symbol_end ();
902 p = input_line_pointer;
905 if (*input_line_pointer != ',')
908 as_bad ("expected comma after name `%s' in .size directive", name);
910 ignore_rest_of_line ();
913 input_line_pointer++;
915 if (exp.X_op == O_absent)
917 as_bad ("missing expression in .size directive");
918 exp.X_op = O_constant;
919 exp.X_add_number = 0;
922 sym = symbol_find_or_make (name);
924 if (exp.X_op == O_constant)
925 S_SET_SIZE (sym, exp.X_add_number);
928 sym->sy_obj = (expressionS *) xmalloc (sizeof (expressionS));
931 demand_empty_rest_of_line ();
934 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
935 There are three syntaxes. The first (used on Solaris) is
937 The second (used on UnixWare) is
939 The third (reportedly to be used on Irix 6.0) is
944 obj_elf_type (ignore)
950 const char *typename;
953 name = input_line_pointer;
954 c = get_symbol_end ();
955 sym = symbol_find_or_make (name);
956 *input_line_pointer = c;
959 if (*input_line_pointer == ',')
960 ++input_line_pointer;
963 if (*input_line_pointer == '#' || *input_line_pointer == '@')
964 ++input_line_pointer;
966 typename = input_line_pointer;
967 c = get_symbol_end ();
970 if (strcmp (typename, "function") == 0
971 || strcmp (typename, "STT_FUNC") == 0)
973 else if (strcmp (typename, "object") == 0
974 || strcmp (typename, "STT_OBJECT") == 0)
977 as_bad ("ignoring unrecognized symbol type \"%s\"", typename);
979 *input_line_pointer = c;
981 sym->bsym->flags |= type;
983 demand_empty_rest_of_line ();
987 obj_elf_ident (ignore)
990 static segT comment_section;
991 segT old_section = now_seg;
992 int old_subsection = now_subseg;
994 if (!comment_section)
997 comment_section = subseg_new (".comment", 0);
998 bfd_set_section_flags (stdoutput, comment_section,
999 SEC_READONLY | SEC_HAS_CONTENTS);
1004 subseg_set (comment_section, 0);
1006 subseg_set (old_section, old_subsection);
1009 #ifdef INIT_STAB_SECTION
1011 /* The first entry in a .stabs section is special. */
1014 obj_elf_init_stab_section (seg)
1020 unsigned int stroff;
1022 /* Force the section to align to a longword boundary. Without this,
1023 UnixWare ar crashes. */
1024 bfd_set_section_alignment (stdoutput, seg, 2);
1026 /* Make space for this first symbol. */
1030 as_where (&file, (unsigned int *) NULL);
1031 stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4);
1032 strcpy (stabstr_name, segment_name (seg));
1033 strcat (stabstr_name, "str");
1034 stroff = get_stab_string_offset (file, stabstr_name);
1036 md_number_to_chars (p, stroff, 4);
1037 seg_info (seg)->stabu.p = p;
1042 /* Fill in the counts in the first entry in a .stabs section. */
1045 adjust_stab_sections (abfd, sec, xxx)
1055 if (strncmp (".stab", sec->name, 5))
1057 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1060 name = (char *) alloca (strlen (sec->name) + 4);
1061 strcpy (name, sec->name);
1062 strcat (name, "str");
1063 strsec = bfd_get_section_by_name (abfd, name);
1065 strsz = bfd_section_size (abfd, strsec);
1068 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1070 p = seg_info (sec)->stabu.p;
1073 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1074 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1077 #ifdef NEED_ECOFF_DEBUG
1079 /* This function is called by the ECOFF code. It is supposed to
1080 record the external symbol information so that the backend can
1081 write it out correctly. The ELF backend doesn't actually handle
1082 this at the moment, so we do it ourselves. We save the information
1086 elf_ecoff_set_ext (sym, ext)
1088 struct ecoff_extr *ext;
1090 sym->bsym->udata.p = (PTR) ext;
1093 /* This function is called by bfd_ecoff_debug_externals. It is
1094 supposed to *EXT to the external symbol information, and return
1095 whether the symbol should be used at all. */
1098 elf_get_extr (sym, ext)
1102 if (sym->udata.p == NULL)
1104 *ext = *(EXTR *) sym->udata.p;
1108 /* This function is called by bfd_ecoff_debug_externals. It has
1109 nothing to do for ELF. */
1113 elf_set_index (sym, indx)
1119 #endif /* NEED_ECOFF_DEBUG */
1122 elf_frob_symbol (symp, puntp)
1126 #ifdef NEED_ECOFF_DEBUG
1127 if (ECOFF_DEBUGGING)
1128 ecoff_frob_symbol (symp);
1133 switch (symp->sy_obj->X_op)
1137 (S_GET_VALUE (symp->sy_obj->X_add_symbol)
1138 + symp->sy_obj->X_add_number
1139 - S_GET_VALUE (symp->sy_obj->X_op_symbol)));
1143 (S_GET_VALUE (symp->sy_obj->X_add_symbol)
1144 + symp->sy_obj->X_add_number));
1147 as_bad (".size expression too complicated to fix up");
1150 free (symp->sy_obj);
1154 /* Double check weak symbols. */
1155 if (symp->bsym->flags & BSF_WEAK)
1157 if (S_IS_COMMON (symp))
1158 as_bad ("Symbol `%s' can not be both weak and common",
1163 /* The Irix 5 assembler appears to set the type of any common symbol
1164 to STT_OBJECT. We try to be compatible, since the Irix 5 linker
1165 apparently sometimes cares. FIXME: What about Irix 6? */
1166 if (S_IS_COMMON (symp))
1167 symp->bsym->flags |= BSF_OBJECT;
1171 /* Frob the PowerPC, so that the symbol always has object type
1172 if it is not some other type. VxWorks needs this. */
1173 if ((symp->bsym->flags & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1174 && S_IS_DEFINED (symp))
1175 symp->bsym->flags |= BSF_OBJECT;
1182 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
1184 #ifdef elf_tc_final_processing
1185 elf_tc_final_processing ();
1188 #ifdef NEED_ECOFF_DEBUG
1189 if (ECOFF_DEBUGGING)
1190 /* Generate the ECOFF debugging information. */
1192 const struct ecoff_debug_swap *debug_swap;
1193 struct ecoff_debug_info debug;
1198 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
1199 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
1200 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
1202 /* Set up the pointers in debug. */
1203 #define SET(ptr, offset, type) \
1204 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1206 SET (line, cbLineOffset, unsigned char *);
1207 SET (external_dnr, cbDnOffset, PTR);
1208 SET (external_pdr, cbPdOffset, PTR);
1209 SET (external_sym, cbSymOffset, PTR);
1210 SET (external_opt, cbOptOffset, PTR);
1211 SET (external_aux, cbAuxOffset, union aux_ext *);
1212 SET (ss, cbSsOffset, char *);
1213 SET (external_fdr, cbFdOffset, PTR);
1214 SET (external_rfd, cbRfdOffset, PTR);
1215 /* ssext and external_ext are set up just below. */
1219 /* Set up the external symbols. */
1220 debug.ssext = debug.ssext_end = NULL;
1221 debug.external_ext = debug.external_ext_end = NULL;
1222 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true,
1223 elf_get_extr, elf_set_index))
1224 as_fatal ("Failed to set up debugging information: %s",
1225 bfd_errmsg (bfd_get_error ()));
1227 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
1228 assert (sec != NULL);
1230 know (stdoutput->output_has_begun == false);
1232 /* We set the size of the section, call bfd_set_section_contents
1233 to force the ELF backend to allocate a file position, and then
1234 write out the data. FIXME: Is this really the best way to do
1236 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
1238 if (! bfd_set_section_contents (stdoutput, sec, (PTR) NULL,
1239 (file_ptr) 0, (bfd_size_type) 0))
1240 as_fatal ("Can't start writing .mdebug section: %s",
1241 bfd_errmsg (bfd_get_error ()));
1243 know (stdoutput->output_has_begun == true);
1244 know (sec->filepos != 0);
1246 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
1248 as_fatal ("Could not write .mdebug section: %s",
1249 bfd_errmsg (bfd_get_error ()));
1251 #endif /* NEED_ECOFF_DEBUG */
1254 const struct format_ops elf_format_ops =
1256 bfd_target_elf_flavour,
1261 elf_s_get_size, elf_s_set_size,
1262 elf_s_get_align, elf_s_set_align,
1263 elf_copy_symbol_attributes,
1264 #ifdef NEED_ECOFF_DEBUG
1265 ecoff_generate_asm_lineno,
1269 0, /* process_stab */
1271 elf_sec_sym_ok_for_reloc,
1273 #ifdef NEED_ECOFF_DEBUG
1278 obj_read_begin_hook,
1279 obj_symbol_new_hook,