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"
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
);
226 obj_elf_common (ignore
)
236 name
= input_line_pointer
;
237 c
= get_symbol_end ();
238 /* just after name is now '\0' */
239 p
= input_line_pointer
;
242 if (*input_line_pointer
!= ',')
244 as_bad ("Expected comma after symbol-name");
245 ignore_rest_of_line ();
248 input_line_pointer
++; /* skip ',' */
249 if ((temp
= get_absolute_expression ()) < 0)
251 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
252 ignore_rest_of_line ();
257 symbolP
= symbol_find_or_make (name
);
259 if (S_IS_DEFINED (symbolP
))
261 as_bad ("Ignoring attempt to re-define symbol");
262 ignore_rest_of_line ();
265 if (S_GET_VALUE (symbolP
) != 0)
267 if (S_GET_VALUE (symbolP
) != size
)
269 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
270 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
273 know (symbolP
->sy_frag
== &zero_address_frag
);
274 if (*input_line_pointer
!= ',')
279 input_line_pointer
++;
282 if (! have_align
|| *input_line_pointer
!= '"')
288 temp
= get_absolute_expression ();
292 as_warn ("Common alignment negative; 0 assumed");
304 old_subsec
= now_subseg
;
307 /* convert to a power of 2 alignment */
308 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
311 as_bad ("Common alignment not a power of 2");
312 ignore_rest_of_line ();
318 record_alignment (bss_section
, align
);
319 subseg_set (bss_section
, 0);
321 frag_align (align
, 0);
322 if (S_GET_SEGMENT (symbolP
) == bss_section
)
323 symbolP
->sy_frag
->fr_symbol
= 0;
324 symbolP
->sy_frag
= frag_now
;
325 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
328 S_SET_SIZE (symbolP
, size
);
329 S_SET_SEGMENT (symbolP
, bss_section
);
330 S_CLEAR_EXTERNAL (symbolP
);
331 subseg_set (old_sec
, old_subsec
);
336 S_SET_VALUE (symbolP
, (valueT
) size
);
337 S_SET_ALIGN (symbolP
, temp
);
338 S_SET_EXTERNAL (symbolP
);
339 /* should be common, but this is how gas does it for now */
340 S_SET_SEGMENT (symbolP
, bfd_und_section_ptr
);
345 input_line_pointer
++;
346 /* @@ Some use the dot, some don't. Can we get some consistency?? */
347 if (*input_line_pointer
== '.')
348 input_line_pointer
++;
349 /* @@ Some say data, some say bss. */
350 if (strncmp (input_line_pointer
, "bss\"", 4)
351 && strncmp (input_line_pointer
, "data\"", 5))
353 while (*--input_line_pointer
!= '"')
355 input_line_pointer
--;
356 goto bad_common_segment
;
358 while (*input_line_pointer
++ != '"')
360 goto allocate_common
;
362 demand_empty_rest_of_line ();
367 p
= input_line_pointer
;
368 while (*p
&& *p
!= '\n')
372 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
374 input_line_pointer
= p
;
375 ignore_rest_of_line ();
381 obj_elf_local (ignore
)
390 name
= input_line_pointer
;
391 c
= get_symbol_end ();
392 symbolP
= symbol_find_or_make (name
);
393 *input_line_pointer
= c
;
395 S_CLEAR_EXTERNAL (symbolP
);
399 input_line_pointer
++;
401 if (*input_line_pointer
== '\n')
406 demand_empty_rest_of_line ();
410 obj_elf_weak (ignore
)
419 name
= input_line_pointer
;
420 c
= get_symbol_end ();
421 symbolP
= symbol_find_or_make (name
);
422 *input_line_pointer
= c
;
424 S_SET_WEAK (symbolP
);
428 input_line_pointer
++;
430 if (*input_line_pointer
== '\n')
435 demand_empty_rest_of_line ();
438 static segT previous_section
;
439 static int previous_subsection
;
441 /* Handle the .section pseudo-op. This code supports two different
444 The first is found on Solaris, and looks like
445 .section ".sec1",#alloc,#execinstr,#write
446 Here the names after '#' are the SHF_* flags to turn on for the
447 section. I'm not sure how it determines the SHT_* type (BFD
448 doesn't really give us control over the type, anyhow).
450 The second format is found on UnixWare, and probably most SVR4
451 machines, and looks like
452 .section .sec1,"a",@progbits
453 The quoted string may contain any combination of a, w, x, and
454 represents the SHF_* flags to turn on for the section. The string
455 beginning with '@' can be progbits or nobits. There should be
456 other possibilities, but I don't know what they are. In any case,
457 BFD doesn't really let us set the section type. */
459 /* Certain named sections have particular defined types, listed on p.
461 struct special_section
468 static struct special_section special_sections
[] =
470 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
471 { ".comment", SHT_PROGBITS
, 0 },
472 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
473 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
474 { ".debug", SHT_PROGBITS
, 0 },
475 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
476 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
477 { ".line", SHT_PROGBITS
, 0 },
478 { ".note", SHT_NOTE
, 0 },
479 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
480 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
481 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
483 #ifdef ELF_TC_SPECIAL_SECTIONS
484 ELF_TC_SPECIAL_SECTIONS
488 /* The following section names are special, but they can not
489 reasonably appear in assembler code. Some of the attributes are
490 processor dependent. */
491 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
492 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
493 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
494 { ".got", SHT_PROGBITS
, 0 },
495 { ".hash", SHT_HASH
, SHF_ALLOC
},
496 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
497 { ".plt", SHT_PROGBITS
, 0 },
498 { ".shstrtab",SHT_STRTAB
, 0 },
499 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
500 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
507 obj_elf_section (xxx
)
518 #ifdef md_flush_pending_output
519 md_flush_pending_output ();
526 previous_section
= now_seg
;
527 previous_subsection
= now_subseg
;
529 s_mri_sect (&mri_type
);
531 #ifdef md_elf_section_change_hook
532 md_elf_section_change_hook ();
538 /* Get name of section. */
540 if (*input_line_pointer
== '"')
542 string
= demand_copy_C_string (&xxx
);
545 ignore_rest_of_line ();
551 char *p
= input_line_pointer
;
553 while (0 == strchr ("\n\t,; ", *p
))
555 if (p
== input_line_pointer
)
557 as_warn ("Missing section name");
558 ignore_rest_of_line ();
563 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
564 strcpy (string
, input_line_pointer
);
566 input_line_pointer
= p
;
569 /* Switch to the section, creating it if necessary. */
570 previous_section
= now_seg
;
571 previous_subsection
= now_subseg
;
573 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
574 sec
= subseg_new (string
, 0);
576 /* If this section already existed, we don't bother to change the
580 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
581 ++input_line_pointer
;
582 ++input_line_pointer
;
584 #ifdef md_elf_section_change_hook
585 md_elf_section_change_hook ();
596 if (*input_line_pointer
== ',')
598 /* Skip the comma. */
599 ++input_line_pointer
;
602 if (*input_line_pointer
== '"')
604 /* Pick up a string with a combination of a, w, x. */
605 ++input_line_pointer
;
606 while (*input_line_pointer
!= '"')
608 switch (*input_line_pointer
)
617 attr
|= SHF_EXECINSTR
;
621 char *bad_msg
= "Bad .section directive: want a,w,x in string";
622 #ifdef md_elf_section_letter
623 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
630 ignore_rest_of_line ();
635 ++input_line_pointer
;
638 /* Skip the closing quote. */
639 ++input_line_pointer
;
642 if (*input_line_pointer
== ',')
644 ++input_line_pointer
;
646 if (*input_line_pointer
== '@')
648 ++input_line_pointer
;
649 if (strncmp (input_line_pointer
, "progbits",
650 sizeof "progbits" - 1) == 0)
653 input_line_pointer
+= sizeof "progbits" - 1;
655 else if (strncmp (input_line_pointer
, "nobits",
656 sizeof "nobits" - 1) == 0)
659 input_line_pointer
+= sizeof "nobits" - 1;
663 #ifdef md_elf_section_type
664 int md_type
= md_elf_section_type (&input_line_pointer
);
670 as_warn ("Unrecognized section type");
671 ignore_rest_of_line ();
682 if (*input_line_pointer
!= '#')
684 as_warn ("Bad .section directive");
685 ignore_rest_of_line ();
688 ++input_line_pointer
;
689 if (strncmp (input_line_pointer
, "write",
690 sizeof "write" - 1) == 0)
693 input_line_pointer
+= sizeof "write" - 1;
695 else if (strncmp (input_line_pointer
, "alloc",
696 sizeof "alloc" - 1) == 0)
699 input_line_pointer
+= sizeof "alloc" - 1;
701 else if (strncmp (input_line_pointer
, "execinstr",
702 sizeof "execinstr" - 1) == 0)
704 attr
|= SHF_EXECINSTR
;
705 input_line_pointer
+= sizeof "execinstr" - 1;
709 #ifdef md_elf_section_word
710 int md_attr
= md_elf_section_word (&input_line_pointer
);
716 as_warn ("Unrecognized section attribute");
717 ignore_rest_of_line ();
723 while (*input_line_pointer
++ == ',');
724 --input_line_pointer
;
728 /* See if this is one of the special sections. */
729 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
731 if (string
[1] == special_sections
[i
].name
[1]
732 && strcmp (string
, special_sections
[i
].name
) == 0)
734 if (type
== SHT_NULL
)
735 type
= special_sections
[i
].type
;
736 else if (type
!= special_sections
[i
].type
)
737 as_warn ("Setting incorrect section type for %s", string
);
739 if ((attr
&~ special_sections
[i
].attributes
) != 0)
740 as_warn ("Setting incorrect section attributes for %s", string
);
741 attr
|= special_sections
[i
].attributes
;
748 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
749 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
750 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
751 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
752 if (special_sections
[i
].name
== NULL
)
754 if (type
== SHT_PROGBITS
)
755 flags
|= SEC_ALLOC
| SEC_LOAD
;
756 else if (type
== SHT_NOBITS
)
762 #ifdef md_elf_section_flags
763 flags
= md_elf_section_flags (flags
, attr
, type
);
767 bfd_set_section_flags (stdoutput
, sec
, flags
);
769 /* Add a symbol for this section to the symbol table. */
770 secsym
= symbol_find (string
);
772 secsym
->bsym
= sec
->symbol
;
774 symbol_table_insert (section_symbol (sec
));
776 #ifdef md_elf_section_change_hook
777 md_elf_section_change_hook ();
780 demand_empty_rest_of_line ();
783 /* Change to the .data section. */
789 previous_section
= now_seg
;
790 previous_subsection
= now_subseg
;
794 /* Change to the .text section. */
800 previous_section
= now_seg
;
801 previous_subsection
= now_subseg
;
806 obj_elf_previous (ignore
)
809 if (previous_section
== 0)
811 as_bad (".previous without corresponding .section; ignored");
814 subseg_set (previous_section
, previous_subsection
);
815 previous_section
= 0;
819 obj_elf_line (ignore
)
822 /* Assume delimiter is part of expression. BSD4.2 as fails with
823 delightful bug, so we are not being incompatible here. */
824 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
825 demand_empty_rest_of_line ();
829 obj_read_begin_hook ()
831 #ifdef NEED_ECOFF_DEBUG
833 ecoff_read_begin_hook ();
838 obj_symbol_new_hook (symbolP
)
843 #ifdef NEED_ECOFF_DEBUG
845 ecoff_symbol_new_hook (symbolP
);
850 obj_elf_version (ignore
)
857 asection
*seg
= now_seg
;
858 subsegT subseg
= now_subseg
;
859 Elf_Internal_Note i_note
;
860 Elf_External_Note e_note
;
861 asection
*note_secp
= (asection
*) NULL
;
865 if (*input_line_pointer
== '\"')
867 ++input_line_pointer
; /* -> 1st char of string. */
868 name
= input_line_pointer
;
870 while (is_a_char (c
= next_char_of_string ()))
872 c
= *input_line_pointer
;
873 *input_line_pointer
= '\0';
874 *(input_line_pointer
- 1) = '\0';
875 *input_line_pointer
= c
;
877 /* create the .note section */
879 note_secp
= subseg_new (".note", 0);
880 bfd_set_section_flags (stdoutput
,
882 SEC_HAS_CONTENTS
| SEC_READONLY
);
884 /* process the version string */
888 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
889 i_note
.descsz
= 0; /* no description */
890 i_note
.type
= NT_VERSION
;
891 p
= frag_more (sizeof (e_note
.namesz
));
892 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
893 p
= frag_more (sizeof (e_note
.descsz
));
894 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
895 p
= frag_more (sizeof (e_note
.type
));
896 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
898 for (i
= 0; i
< len
; i
++)
902 FRAG_APPEND_1_CHAR (ch
);
907 subseg_set (seg
, subseg
);
911 as_bad ("Expected quoted string");
913 demand_empty_rest_of_line ();
917 obj_elf_size (ignore
)
920 char *name
= input_line_pointer
;
921 char c
= get_symbol_end ();
926 p
= input_line_pointer
;
929 if (*input_line_pointer
!= ',')
932 as_bad ("expected comma after name `%s' in .size directive", name
);
934 ignore_rest_of_line ();
937 input_line_pointer
++;
939 if (exp
.X_op
== O_absent
)
941 as_bad ("missing expression in .size directive");
942 exp
.X_op
= O_constant
;
943 exp
.X_add_number
= 0;
946 sym
= symbol_find_or_make (name
);
948 if (exp
.X_op
== O_constant
)
949 S_SET_SIZE (sym
, exp
.X_add_number
);
952 sym
->sy_obj
= (expressionS
*) xmalloc (sizeof (expressionS
));
955 demand_empty_rest_of_line ();
958 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
959 There are three syntaxes. The first (used on Solaris) is
961 The second (used on UnixWare) is
963 The third (reportedly to be used on Irix 6.0) is
968 obj_elf_type (ignore
)
974 const char *typename
;
977 name
= input_line_pointer
;
978 c
= get_symbol_end ();
979 sym
= symbol_find_or_make (name
);
980 *input_line_pointer
= c
;
983 if (*input_line_pointer
== ',')
984 ++input_line_pointer
;
987 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
988 ++input_line_pointer
;
990 typename
= input_line_pointer
;
991 c
= get_symbol_end ();
994 if (strcmp (typename
, "function") == 0
995 || strcmp (typename
, "STT_FUNC") == 0)
997 else if (strcmp (typename
, "object") == 0
998 || strcmp (typename
, "STT_OBJECT") == 0)
1001 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
1003 *input_line_pointer
= c
;
1005 sym
->bsym
->flags
|= type
;
1007 demand_empty_rest_of_line ();
1011 obj_elf_ident (ignore
)
1014 static segT comment_section
;
1015 segT old_section
= now_seg
;
1016 int old_subsection
= now_subseg
;
1018 if (!comment_section
)
1021 comment_section
= subseg_new (".comment", 0);
1022 bfd_set_section_flags (stdoutput
, comment_section
,
1023 SEC_READONLY
| SEC_HAS_CONTENTS
);
1028 subseg_set (comment_section
, 0);
1030 subseg_set (old_section
, old_subsection
);
1033 #ifdef INIT_STAB_SECTION
1035 /* The first entry in a .stabs section is special. */
1038 obj_elf_init_stab_section (seg
)
1044 unsigned int stroff
;
1046 /* Force the section to align to a longword boundary. Without this,
1047 UnixWare ar crashes. */
1048 bfd_set_section_alignment (stdoutput
, seg
, 2);
1050 /* Make space for this first symbol. */
1054 as_where (&file
, (unsigned int *) NULL
);
1055 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1056 strcpy (stabstr_name
, segment_name (seg
));
1057 strcat (stabstr_name
, "str");
1058 stroff
= get_stab_string_offset (file
, stabstr_name
);
1060 md_number_to_chars (p
, stroff
, 4);
1061 seg_info (seg
)->stabu
.p
= p
;
1066 /* Fill in the counts in the first entry in a .stabs section. */
1069 adjust_stab_sections (abfd
, sec
, xxx
)
1079 if (strncmp (".stab", sec
->name
, 5))
1081 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1084 name
= (char *) alloca (strlen (sec
->name
) + 4);
1085 strcpy (name
, sec
->name
);
1086 strcat (name
, "str");
1087 strsec
= bfd_get_section_by_name (abfd
, name
);
1089 strsz
= bfd_section_size (abfd
, strsec
);
1092 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1094 p
= seg_info (sec
)->stabu
.p
;
1097 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1098 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1101 #ifdef NEED_ECOFF_DEBUG
1103 /* This function is called by the ECOFF code. It is supposed to
1104 record the external symbol information so that the backend can
1105 write it out correctly. The ELF backend doesn't actually handle
1106 this at the moment, so we do it ourselves. We save the information
1110 elf_ecoff_set_ext (sym
, ext
)
1112 struct ecoff_extr
*ext
;
1114 sym
->bsym
->udata
.p
= (PTR
) ext
;
1117 /* This function is called by bfd_ecoff_debug_externals. It is
1118 supposed to *EXT to the external symbol information, and return
1119 whether the symbol should be used at all. */
1122 elf_get_extr (sym
, ext
)
1126 if (sym
->udata
.p
== NULL
)
1128 *ext
= *(EXTR
*) sym
->udata
.p
;
1132 /* This function is called by bfd_ecoff_debug_externals. It has
1133 nothing to do for ELF. */
1137 elf_set_index (sym
, indx
)
1143 #endif /* NEED_ECOFF_DEBUG */
1146 elf_frob_symbol (symp
, puntp
)
1150 #ifdef NEED_ECOFF_DEBUG
1151 if (ECOFF_DEBUGGING
)
1152 ecoff_frob_symbol (symp
);
1157 switch (symp
->sy_obj
->X_op
)
1161 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1162 + symp
->sy_obj
->X_add_number
1163 - S_GET_VALUE (symp
->sy_obj
->X_op_symbol
)));
1167 (S_GET_VALUE (symp
->sy_obj
->X_add_symbol
)
1168 + symp
->sy_obj
->X_add_number
));
1171 as_bad (".size expression too complicated to fix up");
1174 free (symp
->sy_obj
);
1178 /* Double check weak symbols. */
1179 if (symp
->bsym
->flags
& BSF_WEAK
)
1181 if (S_IS_COMMON (symp
))
1182 as_bad ("Symbol `%s' can not be both weak and common",
1187 /* The Irix 5 assembler appears to set the type of any common symbol
1188 to STT_OBJECT. We try to be compatible, since the Irix 5 linker
1189 apparently sometimes cares. FIXME: What about Irix 6? */
1190 if (S_IS_COMMON (symp
))
1191 symp
->bsym
->flags
|= BSF_OBJECT
;
1195 /* Frob the PowerPC, so that the symbol always has object type
1196 if it is not some other type. VxWorks needs this. */
1197 if ((symp
->bsym
->flags
& (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1198 && S_IS_DEFINED (symp
))
1199 symp
->bsym
->flags
|= BSF_OBJECT
;
1206 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1208 #ifdef elf_tc_final_processing
1209 elf_tc_final_processing ();
1213 /* It is required that we let write_relocs have the opportunity to
1214 optimize away fixups before output has begun, since it is possible
1215 to eliminate all fixups for a section and thus we never should
1216 have generated the relocation section. */
1219 elf_frob_file_after_relocs ()
1221 #ifdef NEED_ECOFF_DEBUG
1222 if (ECOFF_DEBUGGING
)
1223 /* Generate the ECOFF debugging information. */
1225 const struct ecoff_debug_swap
*debug_swap
;
1226 struct ecoff_debug_info debug
;
1231 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1232 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1233 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1235 /* Set up the pointers in debug. */
1236 #define SET(ptr, offset, type) \
1237 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1239 SET (line
, cbLineOffset
, unsigned char *);
1240 SET (external_dnr
, cbDnOffset
, PTR
);
1241 SET (external_pdr
, cbPdOffset
, PTR
);
1242 SET (external_sym
, cbSymOffset
, PTR
);
1243 SET (external_opt
, cbOptOffset
, PTR
);
1244 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1245 SET (ss
, cbSsOffset
, char *);
1246 SET (external_fdr
, cbFdOffset
, PTR
);
1247 SET (external_rfd
, cbRfdOffset
, PTR
);
1248 /* ssext and external_ext are set up just below. */
1252 /* Set up the external symbols. */
1253 debug
.ssext
= debug
.ssext_end
= NULL
;
1254 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1255 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1256 elf_get_extr
, elf_set_index
))
1257 as_fatal ("Failed to set up debugging information: %s",
1258 bfd_errmsg (bfd_get_error ()));
1260 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1261 assert (sec
!= NULL
);
1263 know (stdoutput
->output_has_begun
== false);
1265 /* We set the size of the section, call bfd_set_section_contents
1266 to force the ELF backend to allocate a file position, and then
1267 write out the data. FIXME: Is this really the best way to do
1269 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1271 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1272 (file_ptr
) 0, (bfd_size_type
) 0))
1273 as_fatal ("Can't start writing .mdebug section: %s",
1274 bfd_errmsg (bfd_get_error ()));
1276 know (stdoutput
->output_has_begun
== true);
1277 know (sec
->filepos
!= 0);
1279 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1281 as_fatal ("Could not write .mdebug section: %s",
1282 bfd_errmsg (bfd_get_error ()));
1284 #endif /* NEED_ECOFF_DEBUG */
1287 const struct format_ops elf_format_ops
=
1289 bfd_target_elf_flavour
,
1294 elf_s_get_size
, elf_s_set_size
,
1295 elf_s_get_align
, elf_s_set_align
,
1296 elf_copy_symbol_attributes
,
1297 #ifdef NEED_ECOFF_DEBUG
1298 ecoff_generate_asm_lineno
,
1302 0, /* process_stab */
1304 elf_sec_sym_ok_for_reloc
,
1306 #ifdef NEED_ECOFF_DEBUG
1311 obj_read_begin_hook
,
1312 obj_symbol_new_hook
,