1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 1997 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"
139 /* This is called when the assembler starts. */
144 /* Add symbols for the known sections to the symbol table. */
145 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
147 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
149 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
156 pop_insert (elf_pseudo_table
);
158 pop_insert (ecoff_debug_pseudo_table
);
165 return S_GET_SIZE (sym
);
169 elf_s_set_size (sym
, sz
)
173 S_SET_SIZE (sym
, sz
);
177 elf_s_get_align (sym
)
180 return S_GET_ALIGN (sym
);
184 elf_s_set_align (sym
, align
)
188 S_SET_ALIGN (sym
, align
);
192 elf_copy_symbol_attributes (dest
, src
)
195 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
199 elf_sec_sym_ok_for_reloc (sec
)
202 return obj_sec_sym_ok_for_reloc (sec
);
211 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
212 sym
->sy_frag
= &zero_address_frag
;
213 sym
->bsym
->flags
|= BSF_FILE
;
215 if (symbol_rootP
!= sym
)
217 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
218 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
220 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
224 #ifdef NEED_ECOFF_DEBUG
230 obj_elf_common (ignore
)
240 name
= input_line_pointer
;
241 c
= get_symbol_end ();
242 /* just after name is now '\0' */
243 p
= input_line_pointer
;
246 if (*input_line_pointer
!= ',')
248 as_bad ("Expected comma after symbol-name");
249 ignore_rest_of_line ();
252 input_line_pointer
++; /* skip ',' */
253 if ((temp
= get_absolute_expression ()) < 0)
255 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
256 ignore_rest_of_line ();
261 symbolP
= symbol_find_or_make (name
);
263 if (S_IS_DEFINED (symbolP
))
265 as_bad ("Ignoring attempt to re-define symbol");
266 ignore_rest_of_line ();
269 if (S_GET_VALUE (symbolP
) != 0)
271 if (S_GET_VALUE (symbolP
) != size
)
273 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
274 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
277 know (symbolP
->sy_frag
== &zero_address_frag
);
278 if (*input_line_pointer
!= ',')
283 input_line_pointer
++;
286 if (! have_align
|| *input_line_pointer
!= '"')
292 temp
= get_absolute_expression ();
296 as_warn ("Common alignment negative; 0 assumed");
308 old_subsec
= now_subseg
;
311 /* convert to a power of 2 alignment */
312 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
315 as_bad ("Common alignment not a power of 2");
316 ignore_rest_of_line ();
322 record_alignment (bss_section
, align
);
323 subseg_set (bss_section
, 0);
325 frag_align (align
, 0);
326 if (S_GET_SEGMENT (symbolP
) == bss_section
)
327 symbolP
->sy_frag
->fr_symbol
= 0;
328 symbolP
->sy_frag
= frag_now
;
329 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
332 S_SET_SIZE (symbolP
, size
);
333 S_SET_SEGMENT (symbolP
, bss_section
);
334 S_CLEAR_EXTERNAL (symbolP
);
335 subseg_set (old_sec
, old_subsec
);
340 S_SET_VALUE (symbolP
, (valueT
) size
);
341 S_SET_ALIGN (symbolP
, temp
);
342 S_SET_EXTERNAL (symbolP
);
343 /* should be common, but this is how gas does it for now */
344 S_SET_SEGMENT (symbolP
, bfd_und_section_ptr
);
349 input_line_pointer
++;
350 /* @@ Some use the dot, some don't. Can we get some consistency?? */
351 if (*input_line_pointer
== '.')
352 input_line_pointer
++;
353 /* @@ Some say data, some say bss. */
354 if (strncmp (input_line_pointer
, "bss\"", 4)
355 && strncmp (input_line_pointer
, "data\"", 5))
357 while (*--input_line_pointer
!= '"')
359 input_line_pointer
--;
360 goto bad_common_segment
;
362 while (*input_line_pointer
++ != '"')
364 goto allocate_common
;
366 demand_empty_rest_of_line ();
371 p
= input_line_pointer
;
372 while (*p
&& *p
!= '\n')
376 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
378 input_line_pointer
= p
;
379 ignore_rest_of_line ();
385 obj_elf_local (ignore
)
394 name
= input_line_pointer
;
395 c
= get_symbol_end ();
396 symbolP
= symbol_find_or_make (name
);
397 *input_line_pointer
= c
;
399 S_CLEAR_EXTERNAL (symbolP
);
403 input_line_pointer
++;
405 if (*input_line_pointer
== '\n')
410 demand_empty_rest_of_line ();
414 obj_elf_weak (ignore
)
423 name
= input_line_pointer
;
424 c
= get_symbol_end ();
425 symbolP
= symbol_find_or_make (name
);
426 *input_line_pointer
= c
;
428 S_SET_WEAK (symbolP
);
432 input_line_pointer
++;
434 if (*input_line_pointer
== '\n')
439 demand_empty_rest_of_line ();
442 static segT previous_section
;
443 static int previous_subsection
;
445 /* Handle the .section pseudo-op. This code supports two different
448 The first is found on Solaris, and looks like
449 .section ".sec1",#alloc,#execinstr,#write
450 Here the names after '#' are the SHF_* flags to turn on for the
451 section. I'm not sure how it determines the SHT_* type (BFD
452 doesn't really give us control over the type, anyhow).
454 The second format is found on UnixWare, and probably most SVR4
455 machines, and looks like
456 .section .sec1,"a",@progbits
457 The quoted string may contain any combination of a, w, x, and
458 represents the SHF_* flags to turn on for the section. The string
459 beginning with '@' can be progbits or nobits. There should be
460 other possibilities, but I don't know what they are. In any case,
461 BFD doesn't really let us set the section type. */
463 /* Certain named sections have particular defined types, listed on p.
465 struct special_section
472 static struct special_section special_sections
[] =
474 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
475 { ".comment", SHT_PROGBITS
, 0 },
476 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
477 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
478 { ".debug", SHT_PROGBITS
, 0 },
479 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
480 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
481 { ".line", SHT_PROGBITS
, 0 },
482 { ".note", SHT_NOTE
, 0 },
483 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
484 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
485 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
487 #ifdef ELF_TC_SPECIAL_SECTIONS
488 ELF_TC_SPECIAL_SECTIONS
492 /* The following section names are special, but they can not
493 reasonably appear in assembler code. Some of the attributes are
494 processor dependent. */
495 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
496 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
497 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
498 { ".got", SHT_PROGBITS
, 0 },
499 { ".hash", SHT_HASH
, SHF_ALLOC
},
500 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
501 { ".plt", SHT_PROGBITS
, 0 },
502 { ".shstrtab",SHT_STRTAB
, 0 },
503 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
504 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
511 obj_elf_section (xxx
)
522 #ifdef md_flush_pending_output
523 md_flush_pending_output ();
530 previous_section
= now_seg
;
531 previous_subsection
= now_subseg
;
533 s_mri_sect (&mri_type
);
535 #ifdef md_elf_section_change_hook
536 md_elf_section_change_hook ();
542 /* Get name of section. */
544 if (*input_line_pointer
== '"')
546 string
= demand_copy_C_string (&xxx
);
549 ignore_rest_of_line ();
555 char *p
= input_line_pointer
;
557 while (0 == strchr ("\n\t,; ", *p
))
559 if (p
== input_line_pointer
)
561 as_warn ("Missing section name");
562 ignore_rest_of_line ();
567 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
568 strcpy (string
, input_line_pointer
);
570 input_line_pointer
= p
;
573 /* Switch to the section, creating it if necessary. */
574 previous_section
= now_seg
;
575 previous_subsection
= now_subseg
;
577 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
578 sec
= subseg_new (string
, 0);
580 /* If this section already existed, we don't bother to change the
584 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
585 ++input_line_pointer
;
586 ++input_line_pointer
;
588 #ifdef md_elf_section_change_hook
589 md_elf_section_change_hook ();
600 if (*input_line_pointer
== ',')
602 /* Skip the comma. */
603 ++input_line_pointer
;
606 if (*input_line_pointer
== '"')
608 /* Pick up a string with a combination of a, w, x. */
609 ++input_line_pointer
;
610 while (*input_line_pointer
!= '"')
612 switch (*input_line_pointer
)
621 attr
|= SHF_EXECINSTR
;
625 char *bad_msg
= "Bad .section directive: want a,w,x in string";
626 #ifdef md_elf_section_letter
627 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
634 ignore_rest_of_line ();
639 ++input_line_pointer
;
642 /* Skip the closing quote. */
643 ++input_line_pointer
;
646 if (*input_line_pointer
== ',')
648 ++input_line_pointer
;
650 if (*input_line_pointer
== '@')
652 ++input_line_pointer
;
653 if (strncmp (input_line_pointer
, "progbits",
654 sizeof "progbits" - 1) == 0)
657 input_line_pointer
+= sizeof "progbits" - 1;
659 else if (strncmp (input_line_pointer
, "nobits",
660 sizeof "nobits" - 1) == 0)
663 input_line_pointer
+= sizeof "nobits" - 1;
667 #ifdef md_elf_section_type
668 int md_type
= md_elf_section_type (&input_line_pointer
);
674 as_warn ("Unrecognized section type");
675 ignore_rest_of_line ();
686 if (*input_line_pointer
!= '#')
688 as_warn ("Bad .section directive");
689 ignore_rest_of_line ();
692 ++input_line_pointer
;
693 if (strncmp (input_line_pointer
, "write",
694 sizeof "write" - 1) == 0)
697 input_line_pointer
+= sizeof "write" - 1;
699 else if (strncmp (input_line_pointer
, "alloc",
700 sizeof "alloc" - 1) == 0)
703 input_line_pointer
+= sizeof "alloc" - 1;
705 else if (strncmp (input_line_pointer
, "execinstr",
706 sizeof "execinstr" - 1) == 0)
708 attr
|= SHF_EXECINSTR
;
709 input_line_pointer
+= sizeof "execinstr" - 1;
713 #ifdef md_elf_section_word
714 int md_attr
= md_elf_section_word (&input_line_pointer
);
720 as_warn ("Unrecognized section attribute");
721 ignore_rest_of_line ();
727 while (*input_line_pointer
++ == ',');
728 --input_line_pointer
;
732 /* See if this is one of the special sections. */
733 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
735 if (string
[1] == special_sections
[i
].name
[1]
736 && strcmp (string
, special_sections
[i
].name
) == 0)
738 if (type
== SHT_NULL
)
739 type
= special_sections
[i
].type
;
740 else if (type
!= special_sections
[i
].type
)
741 as_warn ("Setting incorrect section type for %s", string
);
743 if ((attr
&~ special_sections
[i
].attributes
) != 0)
744 as_warn ("Setting incorrect section attributes for %s", string
);
745 attr
|= special_sections
[i
].attributes
;
752 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
753 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
754 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
755 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
756 if (special_sections
[i
].name
== NULL
)
758 if (type
== SHT_PROGBITS
)
759 flags
|= SEC_ALLOC
| SEC_LOAD
;
760 else if (type
== SHT_NOBITS
)
766 #ifdef md_elf_section_flags
767 flags
= md_elf_section_flags (flags
, attr
, type
);
771 bfd_set_section_flags (stdoutput
, sec
, flags
);
773 /* Add a symbol for this section to the symbol table. */
774 secsym
= symbol_find (string
);
776 secsym
->bsym
= sec
->symbol
;
778 symbol_table_insert (section_symbol (sec
));
780 #ifdef md_elf_section_change_hook
781 md_elf_section_change_hook ();
784 demand_empty_rest_of_line ();
787 /* Change to the .data section. */
793 previous_section
= now_seg
;
794 previous_subsection
= now_subseg
;
798 /* Change to the .text section. */
804 previous_section
= now_seg
;
805 previous_subsection
= now_subseg
;
810 obj_elf_previous (ignore
)
813 if (previous_section
== 0)
815 as_bad (".previous without corresponding .section; ignored");
818 subseg_set (previous_section
, previous_subsection
);
819 previous_section
= 0;
823 obj_elf_line (ignore
)
826 /* Assume delimiter is part of expression. BSD4.2 as fails with
827 delightful bug, so we are not being incompatible here. */
828 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
829 demand_empty_rest_of_line ();
833 obj_read_begin_hook ()
835 #ifdef NEED_ECOFF_DEBUG
837 ecoff_read_begin_hook ();
842 obj_symbol_new_hook (symbolP
)
847 #ifdef NEED_ECOFF_DEBUG
849 ecoff_symbol_new_hook (symbolP
);
854 obj_elf_version (ignore
)
861 asection
*seg
= now_seg
;
862 subsegT subseg
= now_subseg
;
863 Elf_Internal_Note i_note
;
864 Elf_External_Note e_note
;
865 asection
*note_secp
= (asection
*) NULL
;
869 if (*input_line_pointer
== '\"')
871 ++input_line_pointer
; /* -> 1st char of string. */
872 name
= input_line_pointer
;
874 while (is_a_char (c
= next_char_of_string ()))
876 c
= *input_line_pointer
;
877 *input_line_pointer
= '\0';
878 *(input_line_pointer
- 1) = '\0';
879 *input_line_pointer
= c
;
881 /* create the .note section */
883 note_secp
= subseg_new (".note", 0);
884 bfd_set_section_flags (stdoutput
,
886 SEC_HAS_CONTENTS
| SEC_READONLY
);
888 /* process the version string */
892 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
893 i_note
.descsz
= 0; /* no description */
894 i_note
.type
= NT_VERSION
;
895 p
= frag_more (sizeof (e_note
.namesz
));
896 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
897 p
= frag_more (sizeof (e_note
.descsz
));
898 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
899 p
= frag_more (sizeof (e_note
.type
));
900 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
902 for (i
= 0; i
< len
; i
++)
906 FRAG_APPEND_1_CHAR (ch
);
911 subseg_set (seg
, subseg
);
915 as_bad ("Expected quoted string");
917 demand_empty_rest_of_line ();
921 obj_elf_size (ignore
)
924 char *name
= input_line_pointer
;
925 char c
= get_symbol_end ();
930 p
= input_line_pointer
;
933 if (*input_line_pointer
!= ',')
936 as_bad ("expected comma after name `%s' in .size directive", name
);
938 ignore_rest_of_line ();
941 input_line_pointer
++;
943 if (exp
.X_op
== O_absent
)
945 as_bad ("missing expression in .size directive");
946 exp
.X_op
= O_constant
;
947 exp
.X_add_number
= 0;
950 sym
= symbol_find_or_make (name
);
952 if (exp
.X_op
== O_constant
)
953 S_SET_SIZE (sym
, exp
.X_add_number
);
956 sym
->sy_obj
= (expressionS
*) xmalloc (sizeof (expressionS
));
959 demand_empty_rest_of_line ();
962 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
963 There are three syntaxes. The first (used on Solaris) is
965 The second (used on UnixWare) is
967 The third (reportedly to be used on Irix 6.0) is
972 obj_elf_type (ignore
)
978 const char *typename
;
981 name
= input_line_pointer
;
982 c
= get_symbol_end ();
983 sym
= symbol_find_or_make (name
);
984 *input_line_pointer
= c
;
987 if (*input_line_pointer
== ',')
988 ++input_line_pointer
;
991 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
992 ++input_line_pointer
;
994 typename
= input_line_pointer
;
995 c
= get_symbol_end ();
998 if (strcmp (typename
, "function") == 0
999 || strcmp (typename
, "STT_FUNC") == 0)
1000 type
= BSF_FUNCTION
;
1001 else if (strcmp (typename
, "object") == 0
1002 || strcmp (typename
, "STT_OBJECT") == 0)
1005 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
1007 *input_line_pointer
= c
;
1009 sym
->bsym
->flags
|= type
;
1011 demand_empty_rest_of_line ();
1015 obj_elf_ident (ignore
)
1018 static segT comment_section
;
1019 segT old_section
= now_seg
;
1020 int old_subsection
= now_subseg
;
1022 if (!comment_section
)
1025 comment_section
= subseg_new (".comment", 0);
1026 bfd_set_section_flags (stdoutput
, comment_section
,
1027 SEC_READONLY
| SEC_HAS_CONTENTS
);
1032 subseg_set (comment_section
, 0);
1034 subseg_set (old_section
, old_subsection
);
1037 #ifdef INIT_STAB_SECTION
1039 /* The first entry in a .stabs section is special. */
1042 obj_elf_init_stab_section (seg
)
1048 unsigned int stroff
;
1050 /* Force the section to align to a longword boundary. Without this,
1051 UnixWare ar crashes. */
1052 bfd_set_section_alignment (stdoutput
, seg
, 2);
1054 /* Make space for this first symbol. */
1058 as_where (&file
, (unsigned int *) NULL
);
1059 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1060 strcpy (stabstr_name
, segment_name (seg
));
1061 strcat (stabstr_name
, "str");
1062 stroff
= get_stab_string_offset (file
, stabstr_name
);
1064 md_number_to_chars (p
, stroff
, 4);
1065 seg_info (seg
)->stabu
.p
= p
;
1070 /* Fill in the counts in the first entry in a .stabs section. */
1073 adjust_stab_sections (abfd
, sec
, xxx
)
1083 if (strncmp (".stab", sec
->name
, 5))
1085 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1088 name
= (char *) alloca (strlen (sec
->name
) + 4);
1089 strcpy (name
, sec
->name
);
1090 strcat (name
, "str");
1091 strsec
= bfd_get_section_by_name (abfd
, name
);
1093 strsz
= bfd_section_size (abfd
, strsec
);
1096 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1098 p
= seg_info (sec
)->stabu
.p
;
1101 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1102 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1105 #ifdef NEED_ECOFF_DEBUG
1107 /* This function is called by the ECOFF code. It is supposed to
1108 record the external symbol information so that the backend can
1109 write it out correctly. The ELF backend doesn't actually handle
1110 this at the moment, so we do it ourselves. We save the information
1114 elf_ecoff_set_ext (sym
, ext
)
1116 struct ecoff_extr
*ext
;
1118 sym
->bsym
->udata
.p
= (PTR
) ext
;
1121 /* This function is called by bfd_ecoff_debug_externals. It is
1122 supposed to *EXT to the external symbol information, and return
1123 whether the symbol should be used at all. */
1126 elf_get_extr (sym
, ext
)
1130 if (sym
->udata
.p
== NULL
)
1132 *ext
= *(EXTR
*) sym
->udata
.p
;
1136 /* This function is called by bfd_ecoff_debug_externals. It has
1137 nothing to do for ELF. */
1141 elf_set_index (sym
, indx
)
1147 #endif /* NEED_ECOFF_DEBUG */
1150 elf_frob_symbol (symp
, puntp
)
1154 #ifdef NEED_ECOFF_DEBUG
1155 if (ECOFF_DEBUGGING
)
1156 ecoff_frob_symbol (symp
);
1161 switch (symp
->sy_obj
->X_op
)
1165 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1166 + symp
->sy_obj
->X_add_number
1167 - S_GET_VALUE (symp
->sy_obj
->X_op_symbol
)));
1171 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1172 + symp
->sy_obj
->X_add_number
));
1175 as_bad (".size expression too complicated to fix up");
1178 free (symp
->sy_obj
);
1182 /* Double check weak symbols. */
1183 if (symp
->bsym
->flags
& BSF_WEAK
)
1185 if (S_IS_COMMON (symp
))
1186 as_bad ("Symbol `%s' can not be both weak and common",
1191 /* The Irix 5 assembler appears to set the type of any common symbol
1192 to STT_OBJECT. We try to be compatible, since the Irix 5 linker
1193 apparently sometimes cares. FIXME: What about Irix 6? */
1194 if (S_IS_COMMON (symp
))
1195 symp
->bsym
->flags
|= BSF_OBJECT
;
1199 /* Frob the PowerPC, so that the symbol always has object type
1200 if it is not some other type. VxWorks needs this. */
1201 if ((symp
->bsym
->flags
& (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1202 && S_IS_DEFINED (symp
))
1203 symp
->bsym
->flags
|= BSF_OBJECT
;
1210 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1212 #ifdef elf_tc_final_processing
1213 elf_tc_final_processing ();
1217 /* It is required that we let write_relocs have the opportunity to
1218 optimize away fixups before output has begun, since it is possible
1219 to eliminate all fixups for a section and thus we never should
1220 have generated the relocation section. */
1223 elf_frob_file_after_relocs ()
1225 #ifdef NEED_ECOFF_DEBUG
1226 if (ECOFF_DEBUGGING
)
1227 /* Generate the ECOFF debugging information. */
1229 const struct ecoff_debug_swap
*debug_swap
;
1230 struct ecoff_debug_info debug
;
1235 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1236 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1237 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1239 /* Set up the pointers in debug. */
1240 #define SET(ptr, offset, type) \
1241 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1243 SET (line
, cbLineOffset
, unsigned char *);
1244 SET (external_dnr
, cbDnOffset
, PTR
);
1245 SET (external_pdr
, cbPdOffset
, PTR
);
1246 SET (external_sym
, cbSymOffset
, PTR
);
1247 SET (external_opt
, cbOptOffset
, PTR
);
1248 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1249 SET (ss
, cbSsOffset
, char *);
1250 SET (external_fdr
, cbFdOffset
, PTR
);
1251 SET (external_rfd
, cbRfdOffset
, PTR
);
1252 /* ssext and external_ext are set up just below. */
1256 /* Set up the external symbols. */
1257 debug
.ssext
= debug
.ssext_end
= NULL
;
1258 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1259 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1260 elf_get_extr
, elf_set_index
))
1261 as_fatal ("Failed to set up debugging information: %s",
1262 bfd_errmsg (bfd_get_error ()));
1264 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1265 assert (sec
!= NULL
);
1267 know (stdoutput
->output_has_begun
== false);
1269 /* We set the size of the section, call bfd_set_section_contents
1270 to force the ELF backend to allocate a file position, and then
1271 write out the data. FIXME: Is this really the best way to do
1273 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1275 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1276 (file_ptr
) 0, (bfd_size_type
) 0))
1277 as_fatal ("Can't start writing .mdebug section: %s",
1278 bfd_errmsg (bfd_get_error ()));
1280 know (stdoutput
->output_has_begun
== true);
1281 know (sec
->filepos
!= 0);
1283 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1285 as_fatal ("Could not write .mdebug section: %s",
1286 bfd_errmsg (bfd_get_error ()));
1288 #endif /* NEED_ECOFF_DEBUG */
1291 const struct format_ops elf_format_ops
=
1293 bfd_target_elf_flavour
,
1298 elf_frob_file_after_relocs
,
1299 elf_s_get_size
, elf_s_set_size
,
1300 elf_s_get_align
, elf_s_set_align
,
1301 elf_copy_symbol_attributes
,
1302 #ifdef NEED_ECOFF_DEBUG
1303 ecoff_generate_asm_lineno
,
1307 0, /* process_stab */
1309 elf_sec_sym_ok_for_reloc
,
1311 #ifdef NEED_ECOFF_DEBUG
1316 obj_read_begin_hook
,
1317 obj_symbol_new_hook
,