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
;
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));
736 if (special_sections
[i
].name
== NULL
)
738 if (type
== SHT_PROGBITS
)
739 flags
|= SEC_ALLOC
| SEC_LOAD
;
740 else if (type
== SHT_NOBITS
)
746 #ifdef md_elf_section_flags
747 flags
= md_elf_section_flags (flags
, attr
, type
);
751 bfd_set_section_flags (stdoutput
, sec
, flags
);
753 #ifdef md_elf_section_change_hook
754 md_elf_section_change_hook ();
757 demand_empty_rest_of_line ();
760 /* Change to the .data section. */
766 previous_section
= now_seg
;
767 previous_subsection
= now_subseg
;
771 /* Change to the .text section. */
777 previous_section
= now_seg
;
778 previous_subsection
= now_subseg
;
783 obj_elf_previous (ignore
)
786 if (previous_section
== 0)
788 as_bad (".previous without corresponding .section; ignored");
791 subseg_set (previous_section
, previous_subsection
);
792 previous_section
= 0;
796 obj_elf_line (ignore
)
799 /* Assume delimiter is part of expression. BSD4.2 as fails with
800 delightful bug, so we are not being incompatible here. */
801 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
802 demand_empty_rest_of_line ();
806 obj_read_begin_hook ()
808 #ifdef NEED_ECOFF_DEBUG
810 ecoff_read_begin_hook ();
815 obj_symbol_new_hook (symbolP
)
820 #ifdef NEED_ECOFF_DEBUG
822 ecoff_symbol_new_hook (symbolP
);
827 obj_elf_version (ignore
)
834 asection
*seg
= now_seg
;
835 subsegT subseg
= now_subseg
;
836 Elf_Internal_Note i_note
;
837 Elf_External_Note e_note
;
838 asection
*note_secp
= (asection
*) NULL
;
842 if (*input_line_pointer
== '\"')
844 ++input_line_pointer
; /* -> 1st char of string. */
845 name
= input_line_pointer
;
847 while (is_a_char (c
= next_char_of_string ()))
849 c
= *input_line_pointer
;
850 *input_line_pointer
= '\0';
851 *(input_line_pointer
- 1) = '\0';
852 *input_line_pointer
= c
;
854 /* create the .note section */
856 note_secp
= subseg_new (".note", 0);
857 bfd_set_section_flags (stdoutput
,
859 SEC_HAS_CONTENTS
| SEC_READONLY
);
861 /* process the version string */
865 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
866 i_note
.descsz
= 0; /* no description */
867 i_note
.type
= NT_VERSION
;
868 p
= frag_more (sizeof (e_note
.namesz
));
869 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
870 p
= frag_more (sizeof (e_note
.descsz
));
871 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
872 p
= frag_more (sizeof (e_note
.type
));
873 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
875 for (i
= 0; i
< len
; i
++)
879 FRAG_APPEND_1_CHAR (ch
);
884 subseg_set (seg
, subseg
);
888 as_bad ("Expected quoted string");
890 demand_empty_rest_of_line ();
894 obj_elf_size (ignore
)
897 char *name
= input_line_pointer
;
898 char c
= get_symbol_end ();
903 p
= input_line_pointer
;
906 if (*input_line_pointer
!= ',')
909 as_bad ("expected comma after name `%s' in .size directive", name
);
911 ignore_rest_of_line ();
914 input_line_pointer
++;
916 if (exp
.X_op
== O_absent
)
918 as_bad ("missing expression in .size directive");
919 exp
.X_op
= O_constant
;
920 exp
.X_add_number
= 0;
923 sym
= symbol_find_or_make (name
);
925 if (exp
.X_op
== O_constant
)
926 S_SET_SIZE (sym
, exp
.X_add_number
);
929 sym
->sy_obj
= (expressionS
*) xmalloc (sizeof (expressionS
));
932 demand_empty_rest_of_line ();
935 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
936 There are three syntaxes. The first (used on Solaris) is
938 The second (used on UnixWare) is
940 The third (reportedly to be used on Irix 6.0) is
945 obj_elf_type (ignore
)
951 const char *typename
;
954 name
= input_line_pointer
;
955 c
= get_symbol_end ();
956 sym
= symbol_find_or_make (name
);
957 *input_line_pointer
= c
;
960 if (*input_line_pointer
== ',')
961 ++input_line_pointer
;
964 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
965 ++input_line_pointer
;
967 typename
= input_line_pointer
;
968 c
= get_symbol_end ();
971 if (strcmp (typename
, "function") == 0
972 || strcmp (typename
, "STT_FUNC") == 0)
974 else if (strcmp (typename
, "object") == 0
975 || strcmp (typename
, "STT_OBJECT") == 0)
978 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
980 *input_line_pointer
= c
;
982 sym
->bsym
->flags
|= type
;
984 demand_empty_rest_of_line ();
988 obj_elf_ident (ignore
)
991 static segT comment_section
;
992 segT old_section
= now_seg
;
993 int old_subsection
= now_subseg
;
995 if (!comment_section
)
998 comment_section
= subseg_new (".comment", 0);
999 bfd_set_section_flags (stdoutput
, comment_section
,
1000 SEC_READONLY
| SEC_HAS_CONTENTS
);
1005 subseg_set (comment_section
, 0);
1007 subseg_set (old_section
, old_subsection
);
1010 #ifdef INIT_STAB_SECTION
1012 /* The first entry in a .stabs section is special. */
1015 obj_elf_init_stab_section (seg
)
1021 unsigned int stroff
;
1023 /* Force the section to align to a longword boundary. Without this,
1024 UnixWare ar crashes. */
1025 bfd_set_section_alignment (stdoutput
, seg
, 2);
1027 /* Make space for this first symbol. */
1031 as_where (&file
, (unsigned int *) NULL
);
1032 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1033 strcpy (stabstr_name
, segment_name (seg
));
1034 strcat (stabstr_name
, "str");
1035 stroff
= get_stab_string_offset (file
, stabstr_name
);
1037 md_number_to_chars (p
, stroff
, 4);
1038 seg_info (seg
)->stabu
.p
= p
;
1043 /* Fill in the counts in the first entry in a .stabs section. */
1046 adjust_stab_sections (abfd
, sec
, xxx
)
1056 if (strncmp (".stab", sec
->name
, 5))
1058 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1061 name
= (char *) alloca (strlen (sec
->name
) + 4);
1062 strcpy (name
, sec
->name
);
1063 strcat (name
, "str");
1064 strsec
= bfd_get_section_by_name (abfd
, name
);
1066 strsz
= bfd_section_size (abfd
, strsec
);
1069 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1071 p
= seg_info (sec
)->stabu
.p
;
1074 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1075 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1078 #ifdef NEED_ECOFF_DEBUG
1080 /* This function is called by the ECOFF code. It is supposed to
1081 record the external symbol information so that the backend can
1082 write it out correctly. The ELF backend doesn't actually handle
1083 this at the moment, so we do it ourselves. We save the information
1087 elf_ecoff_set_ext (sym
, ext
)
1089 struct ecoff_extr
*ext
;
1091 sym
->bsym
->udata
.p
= (PTR
) ext
;
1094 /* This function is called by bfd_ecoff_debug_externals. It is
1095 supposed to *EXT to the external symbol information, and return
1096 whether the symbol should be used at all. */
1099 elf_get_extr (sym
, ext
)
1103 if (sym
->udata
.p
== NULL
)
1105 *ext
= *(EXTR
*) sym
->udata
.p
;
1109 /* This function is called by bfd_ecoff_debug_externals. It has
1110 nothing to do for ELF. */
1114 elf_set_index (sym
, indx
)
1120 #endif /* NEED_ECOFF_DEBUG */
1123 elf_frob_symbol (symp
, puntp
)
1127 #ifdef NEED_ECOFF_DEBUG
1128 if (ECOFF_DEBUGGING
)
1129 ecoff_frob_symbol (symp
);
1134 switch (symp
->sy_obj
->X_op
)
1138 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1139 + symp
->sy_obj
->X_add_number
1140 - S_GET_VALUE (symp
->sy_obj
->X_op_symbol
)));
1144 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1145 + symp
->sy_obj
->X_add_number
));
1148 as_bad (".size expression too complicated to fix up");
1151 free (symp
->sy_obj
);
1155 /* Double check weak symbols. */
1156 if (symp
->bsym
->flags
& BSF_WEAK
)
1158 if (S_IS_COMMON (symp
))
1159 as_bad ("Symbol `%s' can not be both weak and common",
1167 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1169 #ifdef elf_tc_final_processing
1170 elf_tc_final_processing ();
1173 #ifdef NEED_ECOFF_DEBUG
1174 if (ECOFF_DEBUGGING
)
1175 /* Generate the ECOFF debugging information. */
1177 const struct ecoff_debug_swap
*debug_swap
;
1178 struct ecoff_debug_info debug
;
1183 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1184 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1185 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1187 /* Set up the pointers in debug. */
1188 #define SET(ptr, offset, type) \
1189 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1191 SET (line
, cbLineOffset
, unsigned char *);
1192 SET (external_dnr
, cbDnOffset
, PTR
);
1193 SET (external_pdr
, cbPdOffset
, PTR
);
1194 SET (external_sym
, cbSymOffset
, PTR
);
1195 SET (external_opt
, cbOptOffset
, PTR
);
1196 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1197 SET (ss
, cbSsOffset
, char *);
1198 SET (external_fdr
, cbFdOffset
, PTR
);
1199 SET (external_rfd
, cbRfdOffset
, PTR
);
1200 /* ssext and external_ext are set up just below. */
1204 /* Set up the external symbols. */
1205 debug
.ssext
= debug
.ssext_end
= NULL
;
1206 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1207 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1208 elf_get_extr
, elf_set_index
))
1209 as_fatal ("Failed to set up debugging information: %s",
1210 bfd_errmsg (bfd_get_error ()));
1212 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1213 assert (sec
!= NULL
);
1215 know (stdoutput
->output_has_begun
== false);
1217 /* We set the size of the section, call bfd_set_section_contents
1218 to force the ELF backend to allocate a file position, and then
1219 write out the data. FIXME: Is this really the best way to do
1221 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1223 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1224 (file_ptr
) 0, (bfd_size_type
) 0))
1225 as_fatal ("Can't start writing .mdebug section: %s",
1226 bfd_errmsg (bfd_get_error ()));
1228 know (stdoutput
->output_has_begun
== true);
1229 know (sec
->filepos
!= 0);
1231 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1233 as_fatal ("Could not write .mdebug section: %s",
1234 bfd_errmsg (bfd_get_error ()));
1236 #endif /* NEED_ECOFF_DEBUG */
1239 const struct format_ops elf_format_ops
=
1241 bfd_target_elf_flavour
,
1246 elf_s_get_size
, elf_s_set_size
,
1247 elf_s_get_align
, elf_s_set_align
,
1248 elf_copy_symbol_attributes
,
1249 #ifdef NEED_ECOFF_DEBUG
1250 ecoff_generate_asm_lineno
,
1254 0, /* process_stab */
1256 elf_sec_sym_ok_for_reloc
,
1258 #ifdef NEED_ECOFF_DEBUG
1263 obj_read_begin_hook
,
1264 obj_symbol_new_hook
,