1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-elf.h"
27 #ifndef ECOFF_DEBUGGING
28 #define ECOFF_DEBUGGING 0
30 #define NEED_ECOFF_DEBUG
33 #ifdef NEED_ECOFF_DEBUG
38 #include "elf/alpha.h"
53 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
54 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
55 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
56 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
57 static void elf_s_set_other
PARAMS ((symbolS
*, int));
58 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
59 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
60 static int elf_separate_stab_sections
PARAMS ((void));
61 static void elf_init_stab_section
PARAMS ((segT
));
63 #ifdef NEED_ECOFF_DEBUG
64 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
65 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
68 static void obj_elf_line
PARAMS ((int));
69 void obj_elf_version
PARAMS ((int));
70 static void obj_elf_size
PARAMS ((int));
71 static void obj_elf_type
PARAMS ((int));
72 static void obj_elf_ident
PARAMS ((int));
73 static void obj_elf_weak
PARAMS ((int));
74 static void obj_elf_local
PARAMS ((int));
75 static void obj_elf_visibility
PARAMS ((int));
76 static void obj_elf_symver
PARAMS ((int));
77 static void obj_elf_subsection
PARAMS ((int));
78 static void obj_elf_popsection
PARAMS ((int));
80 static const pseudo_typeS elf_pseudo_table
[] =
82 {"comm", obj_elf_common
, 0},
83 {"common", obj_elf_common
, 1},
84 {"ident", obj_elf_ident
, 0},
85 {"local", obj_elf_local
, 0},
86 {"previous", obj_elf_previous
, 0},
87 {"section", obj_elf_section
, 0},
88 {"section.s", obj_elf_section
, 0},
89 {"sect", obj_elf_section
, 0},
90 {"sect.s", obj_elf_section
, 0},
91 {"pushsection", obj_elf_section
, 1},
92 {"popsection", obj_elf_popsection
, 0},
93 {"size", obj_elf_size
, 0},
94 {"type", obj_elf_type
, 0},
95 {"version", obj_elf_version
, 0},
96 {"weak", obj_elf_weak
, 0},
98 /* These define symbol visibility. */
99 {"internal", obj_elf_visibility
, STV_INTERNAL
},
100 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
101 {"protected", obj_elf_visibility
, STV_PROTECTED
},
103 /* These are used for stabs-in-elf configurations. */
104 {"line", obj_elf_line
, 0},
106 /* This is a GNU extension to handle symbol versions. */
107 {"symver", obj_elf_symver
, 0},
109 /* A GNU extension to change subsection only. */
110 {"subsection", obj_elf_subsection
, 0},
112 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
113 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
114 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
116 /* These are used for dwarf. */
121 /* We need to trap the section changing calls to handle .previous. */
122 {"data", obj_elf_data
, 0},
123 {"text", obj_elf_text
, 0},
129 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
131 #ifdef NEED_ECOFF_DEBUG
132 /* COFF style debugging information for ECOFF. .ln is not used; .loc
134 { "def", ecoff_directive_def
, 0 },
135 { "dim", ecoff_directive_dim
, 0 },
136 { "endef", ecoff_directive_endef
, 0 },
137 { "file", ecoff_directive_file
, 0 },
138 { "scl", ecoff_directive_scl
, 0 },
139 { "tag", ecoff_directive_tag
, 0 },
140 { "val", ecoff_directive_val
, 0 },
142 /* COFF debugging requires pseudo-ops .size and .type, but ELF
143 already has meanings for those. We use .esize and .etype
144 instead. These are only generated by gcc anyhow. */
145 { "esize", ecoff_directive_size
, 0 },
146 { "etype", ecoff_directive_type
, 0 },
148 /* ECOFF specific debugging information. */
149 { "begin", ecoff_directive_begin
, 0 },
150 { "bend", ecoff_directive_bend
, 0 },
151 { "end", ecoff_directive_end
, 0 },
152 { "ent", ecoff_directive_ent
, 0 },
153 { "fmask", ecoff_directive_fmask
, 0 },
154 { "frame", ecoff_directive_frame
, 0 },
155 { "loc", ecoff_directive_loc
, 0 },
156 { "mask", ecoff_directive_mask
, 0 },
158 /* Other ECOFF directives. */
159 { "extern", ecoff_directive_extern
, 0 },
161 /* These are used on Irix. I don't know how to implement them. */
162 { "alias", s_ignore
, 0 },
163 { "bgnb", s_ignore
, 0 },
164 { "endb", s_ignore
, 0 },
165 { "lab", s_ignore
, 0 },
166 { "noalias", s_ignore
, 0 },
167 { "verstamp", s_ignore
, 0 },
168 { "vreg", s_ignore
, 0 },
171 {NULL
, NULL
, 0} /* end sentinel */
175 #include "aout/aout64.h"
177 /* This is called when the assembler starts. */
182 /* Add symbols for the known sections to the symbol table. */
183 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
184 TEXT_SECTION_NAME
)));
185 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
186 DATA_SECTION_NAME
)));
187 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
194 pop_insert (elf_pseudo_table
);
196 pop_insert (ecoff_debug_pseudo_table
);
203 return S_GET_SIZE (sym
);
207 elf_s_set_size (sym
, sz
)
211 S_SET_SIZE (sym
, sz
);
215 elf_s_get_align (sym
)
218 return S_GET_ALIGN (sym
);
222 elf_s_set_align (sym
, align
)
226 S_SET_ALIGN (sym
, align
);
230 elf_s_get_other (sym
)
233 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
237 elf_s_set_other (sym
, other
)
241 S_SET_OTHER (sym
, other
);
245 elf_sec_sym_ok_for_reloc (sec
)
248 return obj_sec_sym_ok_for_reloc (sec
);
257 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
258 symbol_set_frag (sym
, &zero_address_frag
);
259 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
261 if (symbol_rootP
!= sym
)
263 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
264 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
266 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
270 #ifdef NEED_ECOFF_DEBUG
276 obj_elf_common (is_common
)
286 if (flag_mri
&& is_common
)
292 name
= input_line_pointer
;
293 c
= get_symbol_end ();
294 /* just after name is now '\0' */
295 p
= input_line_pointer
;
298 if (*input_line_pointer
!= ',')
300 as_bad (_("Expected comma after symbol-name"));
301 ignore_rest_of_line ();
304 input_line_pointer
++; /* skip ',' */
305 if ((temp
= get_absolute_expression ()) < 0)
307 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
308 ignore_rest_of_line ();
313 symbolP
= symbol_find_or_make (name
);
315 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
317 as_bad (_("Ignoring attempt to re-define symbol"));
318 ignore_rest_of_line ();
321 if (S_GET_VALUE (symbolP
) != 0)
323 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
325 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
326 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
329 know (symbolP
->sy_frag
== &zero_address_frag
);
330 if (*input_line_pointer
!= ',')
335 input_line_pointer
++;
338 if (! have_align
|| *input_line_pointer
!= '"')
344 temp
= get_absolute_expression ();
348 as_warn (_("Common alignment negative; 0 assumed"));
351 if (symbol_get_obj (symbolP
)->local
)
360 old_subsec
= now_subseg
;
363 /* convert to a power of 2 alignment */
364 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
367 as_bad (_("Common alignment not a power of 2"));
368 ignore_rest_of_line ();
374 record_alignment (bss_section
, align
);
375 subseg_set (bss_section
, 0);
377 frag_align (align
, 0, 0);
378 if (S_GET_SEGMENT (symbolP
) == bss_section
)
379 symbol_get_frag (symbolP
)->fr_symbol
= 0;
380 symbol_set_frag (symbolP
, frag_now
);
381 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
382 (offsetT
) size
, (char *) 0);
384 S_SET_SIZE (symbolP
, size
);
385 S_SET_SEGMENT (symbolP
, bss_section
);
386 S_CLEAR_EXTERNAL (symbolP
);
387 subseg_set (old_sec
, old_subsec
);
392 S_SET_VALUE (symbolP
, (valueT
) size
);
393 S_SET_ALIGN (symbolP
, temp
);
394 S_SET_EXTERNAL (symbolP
);
395 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
400 input_line_pointer
++;
401 /* @@ Some use the dot, some don't. Can we get some consistency?? */
402 if (*input_line_pointer
== '.')
403 input_line_pointer
++;
404 /* @@ Some say data, some say bss. */
405 if (strncmp (input_line_pointer
, "bss\"", 4)
406 && strncmp (input_line_pointer
, "data\"", 5))
408 while (*--input_line_pointer
!= '"')
410 input_line_pointer
--;
411 goto bad_common_segment
;
413 while (*input_line_pointer
++ != '"')
415 goto allocate_common
;
418 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
420 demand_empty_rest_of_line ();
425 p
= input_line_pointer
;
426 while (*p
&& *p
!= '\n')
430 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
432 input_line_pointer
= p
;
433 ignore_rest_of_line ();
439 obj_elf_local (ignore
)
440 int ignore ATTRIBUTE_UNUSED
;
448 name
= input_line_pointer
;
449 c
= get_symbol_end ();
450 symbolP
= symbol_find_or_make (name
);
451 *input_line_pointer
= c
;
453 S_CLEAR_EXTERNAL (symbolP
);
454 symbol_get_obj (symbolP
)->local
= 1;
457 input_line_pointer
++;
459 if (*input_line_pointer
== '\n')
464 demand_empty_rest_of_line ();
468 obj_elf_weak (ignore
)
469 int ignore ATTRIBUTE_UNUSED
;
477 name
= input_line_pointer
;
478 c
= get_symbol_end ();
479 symbolP
= symbol_find_or_make (name
);
480 *input_line_pointer
= c
;
482 S_SET_WEAK (symbolP
);
483 symbol_get_obj (symbolP
)->local
= 1;
486 input_line_pointer
++;
488 if (*input_line_pointer
== '\n')
493 demand_empty_rest_of_line ();
497 obj_elf_visibility (visibility
)
504 elf_symbol_type
*elfsym
;
508 name
= input_line_pointer
;
509 c
= get_symbol_end ();
510 symbolP
= symbol_find_or_make (name
);
511 *input_line_pointer
= c
;
515 bfdsym
= symbol_get_bfdsym (symbolP
);
516 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
520 elfsym
->internal_elf_sym
.st_other
= visibility
;
524 input_line_pointer
++;
528 if (*input_line_pointer
== '\n')
534 demand_empty_rest_of_line ();
537 static segT previous_section
;
538 static int previous_subsection
;
542 struct section_stack
*next
;
544 int subseg
, prev_subseg
;
547 static struct section_stack
*section_stack
;
549 /* Handle the .section pseudo-op. This code supports two different
552 The first is found on Solaris, and looks like
553 .section ".sec1",#alloc,#execinstr,#write
554 Here the names after '#' are the SHF_* flags to turn on for the
555 section. I'm not sure how it determines the SHT_* type (BFD
556 doesn't really give us control over the type, anyhow).
558 The second format is found on UnixWare, and probably most SVR4
559 machines, and looks like
560 .section .sec1,"a",@progbits
561 The quoted string may contain any combination of a, w, x, and
562 represents the SHF_* flags to turn on for the section. The string
563 beginning with '@' can be progbits or nobits. There should be
564 other possibilities, but I don't know what they are. In any case,
565 BFD doesn't really let us set the section type. */
567 /* Certain named sections have particular defined types, listed on p.
569 struct special_section
576 static struct special_section
const special_sections
[] =
578 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
579 { ".comment", SHT_PROGBITS
, 0 },
580 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
581 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
582 { ".debug", SHT_PROGBITS
, 0 },
583 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
584 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
585 { ".line", SHT_PROGBITS
, 0 },
586 { ".note", SHT_NOTE
, 0 },
587 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
588 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
589 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
591 #ifdef ELF_TC_SPECIAL_SECTIONS
592 ELF_TC_SPECIAL_SECTIONS
596 /* The following section names are special, but they can not
597 reasonably appear in assembler code. Some of the attributes are
598 processor dependent. */
599 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
600 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
601 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
602 { ".got", SHT_PROGBITS
, 0 },
603 { ".hash", SHT_HASH
, SHF_ALLOC
},
604 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
605 { ".plt", SHT_PROGBITS
, 0 },
606 { ".shstrtab",SHT_STRTAB
, 0 },
607 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
608 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
615 obj_elf_change_section (name
, type
, attr
, entsize
, push
)
617 int type
, attr
, entsize
, push
;
624 #ifdef md_flush_pending_output
625 md_flush_pending_output ();
628 /* Switch to the section, creating it if necessary. */
631 struct section_stack
*elt
;
632 elt
= xmalloc (sizeof (struct section_stack
));
633 elt
->next
= section_stack
;
635 elt
->prev_seg
= previous_section
;
636 elt
->subseg
= now_subseg
;
637 elt
->prev_subseg
= previous_subsection
;
640 previous_section
= now_seg
;
641 previous_subsection
= now_subseg
;
643 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
644 sec
= subseg_new (name
, 0);
646 /* See if this is one of the special sections. */
647 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
648 if (strcmp (name
, special_sections
[i
].name
) == 0)
650 if (type
== SHT_NULL
)
651 type
= special_sections
[i
].type
;
652 else if (type
!= special_sections
[i
].type
)
656 as_warn (_("Setting incorrect section type for %s"), name
);
660 as_warn (_("Ignoring incorrect section type for %s"), name
);
661 type
= special_sections
[i
].type
;
664 if ((attr
&~ special_sections
[i
].attributes
) != 0
667 /* As a GNU extension, we permit a .note section to be
668 allocatable. If the linker sees an allocateable .note
669 section, it will create a PT_NOTE segment in the output
671 if (strcmp (name
, ".note") != 0
672 || attr
!= SHF_ALLOC
)
673 as_warn (_("Setting incorrect section attributes for %s"),
676 attr
|= special_sections
[i
].attributes
;
680 /* Convert ELF type and flags to BFD flags. */
682 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
683 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
684 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
685 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
686 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
687 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0));
688 #ifdef md_elf_section_flags
689 flags
= md_elf_section_flags (flags
, attr
, type
);
696 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
697 if (type
== SHT_NOBITS
)
698 seg_info (sec
)->bss
= 1;
700 bfd_set_section_flags (stdoutput
, sec
, flags
);
701 if (flags
& SEC_MERGE
)
702 sec
->entsize
= entsize
;
704 /* Add a symbol for this section to the symbol table. */
705 secsym
= symbol_find (name
);
707 symbol_set_bfdsym (secsym
, sec
->symbol
);
709 symbol_table_insert (section_symbol (sec
));
713 /* If section attributes are specified the second time we see a
714 particular section, then check that they are the same as we
715 saw the first time. */
716 if ((old_sec
->flags
^ flags
)
717 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
718 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
))
719 as_warn (_("Ignoring changed section attributes for %s"), name
);
720 else if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= entsize
)
721 as_warn (_("Ignoring changed section entity size for %s"), name
);
724 #ifdef md_elf_section_change_hook
725 md_elf_section_change_hook ();
730 obj_elf_parse_section_letters (str
, len
)
747 attr
|= SHF_EXECINSTR
;
757 char *bad_msg
= _("Unrecognized .section attribute: want a,m,s,w,x");
758 #ifdef md_elf_section_letter
759 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
765 as_warn ("%s", bad_msg
);
778 obj_elf_section_word (str
, len
)
782 if (len
== 5 && strncmp (str
, "write", 5) == 0)
784 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
786 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
787 return SHF_EXECINSTR
;
789 #ifdef md_elf_section_word
791 int md_attr
= md_elf_section_word (str
, len
);
797 as_warn (_("Unrecognized section attribute"));
802 obj_elf_section_type (str
, len
)
806 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
808 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
811 #ifdef md_elf_section_type
813 int md_type
= md_elf_section_type (str
, len
);
819 as_warn (_("Unrecognized section type"));
824 obj_elf_section (push
)
827 char *name
, *beg
, *end
;
828 int type
, attr
, dummy
;
836 #ifdef md_flush_pending_output
837 md_flush_pending_output ();
840 previous_section
= now_seg
;
841 previous_subsection
= now_subseg
;
843 s_mri_sect (&mri_type
);
845 #ifdef md_elf_section_change_hook
846 md_elf_section_change_hook ();
851 #endif /* ! defined (TC_I370) */
853 /* Get name of section. */
855 if (*input_line_pointer
== '"')
857 name
= demand_copy_C_string (&dummy
);
860 ignore_rest_of_line ();
866 end
= input_line_pointer
;
867 while (0 == strchr ("\n\t,; ", *end
))
869 if (end
== input_line_pointer
)
871 as_warn (_("Missing section name"));
872 ignore_rest_of_line ();
876 name
= xmalloc (end
- input_line_pointer
+ 1);
877 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
878 name
[end
- input_line_pointer
] = '\0';
879 input_line_pointer
= end
;
887 if (*input_line_pointer
== ',')
889 /* Skip the comma. */
890 ++input_line_pointer
;
893 if (*input_line_pointer
== '"')
895 beg
= demand_copy_C_string (&dummy
);
898 ignore_rest_of_line ();
901 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
904 if (*input_line_pointer
== ',')
907 ++input_line_pointer
;
909 c
= *input_line_pointer
;
912 beg
= demand_copy_C_string (&dummy
);
915 ignore_rest_of_line ();
918 type
= obj_elf_section_type (beg
, strlen (beg
));
920 else if (c
== '@' || c
== '%')
922 beg
= ++input_line_pointer
;
923 c
= get_symbol_end ();
924 *input_line_pointer
= c
;
925 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
930 if ((attr
& SHF_MERGE
) && *input_line_pointer
== ',')
932 ++input_line_pointer
;
934 entsize
= get_absolute_expression ();
937 as_warn (_("Bad .section directive - invalid merge entity size"));
950 if (*input_line_pointer
!= '#')
952 as_warn (_("Bad .section directive - character following name is not '#'"));
953 ignore_rest_of_line ();
956 beg
= ++input_line_pointer
;
957 c
= get_symbol_end ();
958 *input_line_pointer
= c
;
960 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
964 while (*input_line_pointer
++ == ',');
965 --input_line_pointer
;
969 demand_empty_rest_of_line ();
971 if ((attr
& SHF_MERGE
) && entsize
== 0)
973 as_warn (_("Entity size for SHF_MERGE not specified.\nSpecify entity size as 4th argument"));
977 obj_elf_change_section (name
, type
, attr
, entsize
, push
);
980 /* Change to the .data section. */
986 #ifdef md_flush_pending_output
987 md_flush_pending_output ();
990 previous_section
= now_seg
;
991 previous_subsection
= now_subseg
;
994 #ifdef md_elf_section_change_hook
995 md_elf_section_change_hook ();
999 /* Change to the .text section. */
1005 #ifdef md_flush_pending_output
1006 md_flush_pending_output ();
1009 previous_section
= now_seg
;
1010 previous_subsection
= now_subseg
;
1013 #ifdef md_elf_section_change_hook
1014 md_elf_section_change_hook ();
1019 obj_elf_subsection (ignore
)
1020 int ignore ATTRIBUTE_UNUSED
;
1024 #ifdef md_flush_pending_output
1025 md_flush_pending_output ();
1028 previous_section
= now_seg
;
1029 previous_subsection
= now_subseg
;
1031 temp
= get_absolute_expression ();
1032 subseg_set (now_seg
, (subsegT
) temp
);
1033 demand_empty_rest_of_line ();
1035 #ifdef md_elf_section_change_hook
1036 md_elf_section_change_hook ();
1040 /* This can be called from the processor backends if they change
1044 obj_elf_section_change_hook ()
1046 previous_section
= now_seg
;
1047 previous_subsection
= now_subseg
;
1051 obj_elf_previous (ignore
)
1052 int ignore ATTRIBUTE_UNUSED
;
1057 if (previous_section
== 0)
1059 as_bad (_(".previous without corresponding .section; ignored"));
1063 #ifdef md_flush_pending_output
1064 md_flush_pending_output ();
1067 new_section
= previous_section
;
1068 new_subsection
= previous_subsection
;
1069 previous_section
= now_seg
;
1070 previous_subsection
= now_subseg
;
1071 subseg_set (new_section
, new_subsection
);
1073 #ifdef md_elf_section_change_hook
1074 md_elf_section_change_hook ();
1079 obj_elf_popsection (xxx
)
1080 int xxx ATTRIBUTE_UNUSED
;
1082 struct section_stack
*top
= section_stack
;
1086 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1090 #ifdef md_flush_pending_output
1091 md_flush_pending_output ();
1094 section_stack
= top
->next
;
1095 previous_section
= top
->prev_seg
;
1096 previous_subsection
= top
->prev_subseg
;
1097 subseg_set (top
->seg
, top
->subseg
);
1100 #ifdef md_elf_section_change_hook
1101 md_elf_section_change_hook ();
1106 obj_elf_line (ignore
)
1107 int ignore ATTRIBUTE_UNUSED
;
1109 /* Assume delimiter is part of expression. BSD4.2 as fails with
1110 delightful bug, so we are not being incompatible here. */
1111 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1112 demand_empty_rest_of_line ();
1115 /* This handles the .symver pseudo-op, which is used to specify a
1116 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1117 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1118 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1119 with the same value as the symbol NAME. */
1122 obj_elf_symver (ignore
)
1123 int ignore ATTRIBUTE_UNUSED
;
1130 name
= input_line_pointer
;
1131 c
= get_symbol_end ();
1133 sym
= symbol_find_or_make (name
);
1135 *input_line_pointer
= c
;
1138 if (*input_line_pointer
!= ',')
1140 as_bad (_("expected comma after name in .symver"));
1141 ignore_rest_of_line ();
1145 ++input_line_pointer
;
1146 name
= input_line_pointer
;
1148 /* Temporarily include '@' in symbol names. */
1149 old_lexat
= lex_type
[(unsigned char) '@'];
1150 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1151 c
= get_symbol_end ();
1152 lex_type
[(unsigned char) '@'] = old_lexat
;
1154 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1156 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1158 *input_line_pointer
= c
;
1160 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1161 ELF_VER_CHR
) == NULL
)
1163 as_bad (_("missing version name in `%s' for symbol `%s'"),
1164 symbol_get_obj (sym
)->versioned_name
,
1166 ignore_rest_of_line ();
1172 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1174 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1175 name
, symbol_get_obj (sym
)->versioned_name
,
1177 ignore_rest_of_line ();
1181 *input_line_pointer
= c
;
1184 demand_empty_rest_of_line ();
1187 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1188 to the linker the hierarchy in which a particular table resides. The
1189 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1192 obj_elf_vtable_inherit (ignore
)
1193 int ignore ATTRIBUTE_UNUSED
;
1195 char *cname
, *pname
;
1196 symbolS
*csym
, *psym
;
1199 if (*input_line_pointer
== '#')
1200 ++input_line_pointer
;
1202 cname
= input_line_pointer
;
1203 c
= get_symbol_end ();
1204 csym
= symbol_find (cname
);
1206 /* GCFIXME: should check that we don't have two .vtable_inherits for
1207 the same child symbol. Also, we can currently only do this if the
1208 child symbol is already exists and is placed in a fragment. */
1210 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1212 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1217 *input_line_pointer
= c
;
1220 if (*input_line_pointer
!= ',')
1222 as_bad ("expected comma after name in .vtable_inherit");
1223 ignore_rest_of_line ();
1227 ++input_line_pointer
;
1230 if (*input_line_pointer
== '#')
1231 ++input_line_pointer
;
1233 if (input_line_pointer
[0] == '0'
1234 && (input_line_pointer
[1] == '\0'
1235 || isspace ((unsigned char) input_line_pointer
[1])))
1237 psym
= section_symbol (absolute_section
);
1238 ++input_line_pointer
;
1242 pname
= input_line_pointer
;
1243 c
= get_symbol_end ();
1244 psym
= symbol_find_or_make (pname
);
1245 *input_line_pointer
= c
;
1248 demand_empty_rest_of_line ();
1253 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1254 return fix_new (symbol_get_frag (csym
),
1255 symbol_get_value_expression (csym
)->X_add_number
,
1256 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1259 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1260 to the linker that a vtable slot was used. The syntax is
1261 ".vtable_entry tablename, offset". */
1264 obj_elf_vtable_entry (ignore
)
1265 int ignore ATTRIBUTE_UNUSED
;
1272 if (*input_line_pointer
== '#')
1273 ++input_line_pointer
;
1275 name
= input_line_pointer
;
1276 c
= get_symbol_end ();
1277 sym
= symbol_find_or_make (name
);
1278 *input_line_pointer
= c
;
1281 if (*input_line_pointer
!= ',')
1283 as_bad ("expected comma after name in .vtable_entry");
1284 ignore_rest_of_line ();
1288 ++input_line_pointer
;
1289 if (*input_line_pointer
== '#')
1290 ++input_line_pointer
;
1292 offset
= get_absolute_expression ();
1294 demand_empty_rest_of_line ();
1296 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1297 BFD_RELOC_VTABLE_ENTRY
);
1301 elf_obj_read_begin_hook ()
1303 #ifdef NEED_ECOFF_DEBUG
1304 if (ECOFF_DEBUGGING
)
1305 ecoff_read_begin_hook ();
1310 elf_obj_symbol_new_hook (symbolP
)
1313 struct elf_obj_sy
*sy_obj
;
1315 sy_obj
= symbol_get_obj (symbolP
);
1316 sy_obj
->size
= NULL
;
1317 sy_obj
->versioned_name
= NULL
;
1319 #ifdef NEED_ECOFF_DEBUG
1320 if (ECOFF_DEBUGGING
)
1321 ecoff_symbol_new_hook (symbolP
);
1325 /* When setting one symbol equal to another, by default we probably
1326 want them to have the same "size", whatever it means in the current
1330 elf_copy_symbol_attributes (dest
, src
)
1331 symbolS
*dest
, *src
;
1333 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1334 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1337 if (destelf
->size
== NULL
)
1339 (expressionS
*) xmalloc (sizeof (expressionS
));
1340 *destelf
->size
= *srcelf
->size
;
1344 if (destelf
->size
!= NULL
)
1345 free (destelf
->size
);
1346 destelf
->size
= NULL
;
1348 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1349 S_SET_OTHER (dest
, S_GET_OTHER (src
));
1353 obj_elf_version (ignore
)
1354 int ignore ATTRIBUTE_UNUSED
;
1360 asection
*seg
= now_seg
;
1361 subsegT subseg
= now_subseg
;
1362 Elf_Internal_Note i_note
;
1363 Elf_External_Note e_note
;
1364 asection
*note_secp
= (asection
*) NULL
;
1368 if (*input_line_pointer
== '\"')
1370 ++input_line_pointer
; /* -> 1st char of string. */
1371 name
= input_line_pointer
;
1373 while (is_a_char (c
= next_char_of_string ()))
1375 c
= *input_line_pointer
;
1376 *input_line_pointer
= '\0';
1377 *(input_line_pointer
- 1) = '\0';
1378 *input_line_pointer
= c
;
1380 /* create the .note section */
1382 note_secp
= subseg_new (".note", 0);
1383 bfd_set_section_flags (stdoutput
,
1385 SEC_HAS_CONTENTS
| SEC_READONLY
);
1387 /* process the version string */
1389 len
= strlen (name
);
1391 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1392 i_note
.descsz
= 0; /* no description */
1393 i_note
.type
= NT_VERSION
;
1394 p
= frag_more (sizeof (e_note
.namesz
));
1395 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1396 p
= frag_more (sizeof (e_note
.descsz
));
1397 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1398 p
= frag_more (sizeof (e_note
.type
));
1399 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1401 for (i
= 0; i
< len
; i
++)
1405 FRAG_APPEND_1_CHAR (ch
);
1408 frag_align (2, 0, 0);
1410 subseg_set (seg
, subseg
);
1414 as_bad (_("Expected quoted string"));
1416 demand_empty_rest_of_line ();
1420 obj_elf_size (ignore
)
1421 int ignore ATTRIBUTE_UNUSED
;
1423 char *name
= input_line_pointer
;
1424 char c
= get_symbol_end ();
1429 p
= input_line_pointer
;
1432 if (*input_line_pointer
!= ',')
1435 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1437 ignore_rest_of_line ();
1440 input_line_pointer
++;
1442 if (exp
.X_op
== O_absent
)
1444 as_bad (_("missing expression in .size directive"));
1445 exp
.X_op
= O_constant
;
1446 exp
.X_add_number
= 0;
1449 sym
= symbol_find_or_make (name
);
1451 if (exp
.X_op
== O_constant
)
1452 S_SET_SIZE (sym
, exp
.X_add_number
);
1455 symbol_get_obj (sym
)->size
=
1456 (expressionS
*) xmalloc (sizeof (expressionS
));
1457 *symbol_get_obj (sym
)->size
= exp
;
1459 demand_empty_rest_of_line ();
1462 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1463 There are five syntaxes:
1465 The first (used on Solaris) is
1467 The second (used on UnixWare) is
1469 The third (reportedly to be used on Irix 6.0) is
1471 The fourth (used on NetBSD/Arm and Linux/ARM) is
1473 The fifth (used on SVR4/860) is
1474 .type SYM,"function"
1478 obj_elf_type (ignore
)
1479 int ignore ATTRIBUTE_UNUSED
;
1484 const char *typename
;
1486 elf_symbol_type
*elfsym
;
1488 name
= input_line_pointer
;
1489 c
= get_symbol_end ();
1490 sym
= symbol_find_or_make (name
);
1491 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1492 *input_line_pointer
= c
;
1495 if (*input_line_pointer
== ',')
1496 ++input_line_pointer
;
1499 if ( *input_line_pointer
== '#'
1500 || *input_line_pointer
== '@'
1501 || *input_line_pointer
== '"'
1502 || *input_line_pointer
== '%')
1503 ++input_line_pointer
;
1505 typename
= input_line_pointer
;
1506 c
= get_symbol_end ();
1509 if (strcmp (typename
, "function") == 0
1510 || strcmp (typename
, "STT_FUNC") == 0)
1511 type
= BSF_FUNCTION
;
1512 else if (strcmp (typename
, "object") == 0
1513 || strcmp (typename
, "STT_OBJECT") == 0)
1515 #ifdef md_elf_symbol_type
1516 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1520 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1522 *input_line_pointer
= c
;
1524 if (*input_line_pointer
== '"')
1525 ++input_line_pointer
;
1527 elfsym
->symbol
.flags
|= type
;
1529 demand_empty_rest_of_line ();
1533 obj_elf_ident (ignore
)
1534 int ignore ATTRIBUTE_UNUSED
;
1536 static segT comment_section
;
1537 segT old_section
= now_seg
;
1538 int old_subsection
= now_subseg
;
1540 #ifdef md_flush_pending_output
1541 md_flush_pending_output ();
1544 if (!comment_section
)
1547 comment_section
= subseg_new (".comment", 0);
1548 bfd_set_section_flags (stdoutput
, comment_section
,
1549 SEC_READONLY
| SEC_HAS_CONTENTS
);
1554 subseg_set (comment_section
, 0);
1556 subseg_set (old_section
, old_subsection
);
1559 #ifdef INIT_STAB_SECTION
1561 /* The first entry in a .stabs section is special. */
1564 obj_elf_init_stab_section (seg
)
1570 unsigned int stroff
;
1572 /* Force the section to align to a longword boundary. Without this,
1573 UnixWare ar crashes. */
1574 bfd_set_section_alignment (stdoutput
, seg
, 2);
1576 /* Make space for this first symbol. */
1580 as_where (&file
, (unsigned int *) NULL
);
1581 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1582 strcpy (stabstr_name
, segment_name (seg
));
1583 strcat (stabstr_name
, "str");
1584 stroff
= get_stab_string_offset (file
, stabstr_name
);
1586 md_number_to_chars (p
, stroff
, 4);
1587 seg_info (seg
)->stabu
.p
= p
;
1592 /* Fill in the counts in the first entry in a .stabs section. */
1595 adjust_stab_sections (abfd
, sec
, xxx
)
1598 PTR xxx ATTRIBUTE_UNUSED
;
1605 if (strncmp (".stab", sec
->name
, 5))
1607 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1610 name
= (char *) alloca (strlen (sec
->name
) + 4);
1611 strcpy (name
, sec
->name
);
1612 strcat (name
, "str");
1613 strsec
= bfd_get_section_by_name (abfd
, name
);
1615 strsz
= bfd_section_size (abfd
, strsec
);
1618 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1620 p
= seg_info (sec
)->stabu
.p
;
1623 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1624 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1627 #ifdef NEED_ECOFF_DEBUG
1629 /* This function is called by the ECOFF code. It is supposed to
1630 record the external symbol information so that the backend can
1631 write it out correctly. The ELF backend doesn't actually handle
1632 this at the moment, so we do it ourselves. We save the information
1636 elf_ecoff_set_ext (sym
, ext
)
1638 struct ecoff_extr
*ext
;
1640 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1643 /* This function is called by bfd_ecoff_debug_externals. It is
1644 supposed to *EXT to the external symbol information, and return
1645 whether the symbol should be used at all. */
1648 elf_get_extr (sym
, ext
)
1652 if (sym
->udata
.p
== NULL
)
1654 *ext
= *(EXTR
*) sym
->udata
.p
;
1658 /* This function is called by bfd_ecoff_debug_externals. It has
1659 nothing to do for ELF. */
1663 elf_set_index (sym
, indx
)
1664 asymbol
*sym ATTRIBUTE_UNUSED
;
1665 bfd_size_type indx ATTRIBUTE_UNUSED
;
1669 #endif /* NEED_ECOFF_DEBUG */
1672 elf_frob_symbol (symp
, puntp
)
1676 struct elf_obj_sy
*sy_obj
;
1678 #ifdef NEED_ECOFF_DEBUG
1679 if (ECOFF_DEBUGGING
)
1680 ecoff_frob_symbol (symp
);
1683 sy_obj
= symbol_get_obj (symp
);
1685 if (sy_obj
->size
!= NULL
)
1687 switch (sy_obj
->size
->X_op
)
1691 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1692 + sy_obj
->size
->X_add_number
1693 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1697 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1698 + sy_obj
->size
->X_add_number
));
1701 as_bad (_(".size expression too complicated to fix up"));
1704 free (sy_obj
->size
);
1705 sy_obj
->size
= NULL
;
1708 if (sy_obj
->versioned_name
!= NULL
)
1712 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1715 /* This symbol was given a new name with the .symver directive.
1717 If this is an external reference, just rename the symbol to
1718 include the version string. This will make the relocs be
1719 against the correct versioned symbol.
1721 If this is a definition, add an alias. FIXME: Using an alias
1722 will permit the debugging information to refer to the right
1723 symbol. However, it's not clear whether it is the best
1726 if (! S_IS_DEFINED (symp
))
1728 /* Verify that the name isn't using the @@ syntax--this is
1729 reserved for definitions of the default version to link
1731 if (p
[1] == ELF_VER_CHR
)
1733 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1734 sy_obj
->versioned_name
);
1737 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1741 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1745 /* The @@@ syntax is a special case. It renames the
1746 symbol name to versioned_name with one `@' removed. */
1747 l
= strlen (&p
[3]) + 1;
1748 memmove (&p
[2], &p
[3], l
);
1749 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1755 /* FIXME: Creating a new symbol here is risky. We're
1756 in the final loop over the symbol table. We can
1757 get away with it only because the symbol goes to
1758 the end of the list, where the loop will still see
1759 it. It would probably be better to do this in
1760 obj_frob_file_before_adjust. */
1762 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1764 /* Now we act as though we saw symp2 = sym. */
1766 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1768 /* Subtracting out the frag address here is a hack
1769 because we are in the middle of the final loop. */
1772 - symbol_get_frag (symp
)->fr_address
));
1774 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1776 /* This will copy over the size information. */
1777 copy_symbol_attributes (symp2
, symp
);
1779 if (S_IS_WEAK (symp
))
1782 if (S_IS_EXTERNAL (symp
))
1783 S_SET_EXTERNAL (symp2
);
1788 /* Double check weak symbols. */
1789 if (S_IS_WEAK (symp
))
1791 if (S_IS_COMMON (symp
))
1792 as_bad (_("Symbol `%s' can not be both weak and common"),
1797 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1798 any undefined non-function symbol to STT_OBJECT. We try to be
1799 compatible, since newer Irix 5 and 6 linkers care. However, we
1800 only set undefined symbols to be STT_OBJECT if we are on Irix,
1801 because that is the only time gcc will generate the necessary
1802 .global directives to mark functions. */
1804 if (S_IS_COMMON (symp
))
1805 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1807 if (strstr (TARGET_OS
, "irix") != NULL
1808 && ! S_IS_DEFINED (symp
)
1809 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1810 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1814 /* If TC_PPC is defined, we used to force the type of a symbol to be
1815 BSF_OBJECT if it was otherwise unset. This was required by some
1816 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1817 that this is no longer needed, so it is now commented out. */
1818 if ((symbol_get_bfdsym (symp
)->flags
1819 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1820 && S_IS_DEFINED (symp
))
1821 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1828 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1830 #ifdef elf_tc_final_processing
1831 elf_tc_final_processing ();
1835 /* It removes any unneeded versioned symbols from the symbol table. */
1838 elf_frob_file_before_adjust ()
1844 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1845 if (symbol_get_obj (symp
)->versioned_name
)
1847 if (!S_IS_DEFINED (symp
))
1851 /* The @@@ syntax is a special case. If the symbol is
1852 not defined, 2 `@'s will be removed from the
1855 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1858 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1860 size_t l
= strlen (&p
[3]) + 1;
1861 memmove (&p
[1], &p
[3], l
);
1863 if (symbol_used_p (symp
) == 0
1864 && symbol_used_in_reloc_p (symp
) == 0)
1865 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1871 /* It is required that we let write_relocs have the opportunity to
1872 optimize away fixups before output has begun, since it is possible
1873 to eliminate all fixups for a section and thus we never should
1874 have generated the relocation section. */
1877 elf_frob_file_after_relocs ()
1879 #ifdef NEED_ECOFF_DEBUG
1880 if (ECOFF_DEBUGGING
)
1881 /* Generate the ECOFF debugging information. */
1883 const struct ecoff_debug_swap
*debug_swap
;
1884 struct ecoff_debug_info debug
;
1889 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1890 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1891 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1893 /* Set up the pointers in debug. */
1894 #define SET(ptr, offset, type) \
1895 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1897 SET (line
, cbLineOffset
, unsigned char *);
1898 SET (external_dnr
, cbDnOffset
, PTR
);
1899 SET (external_pdr
, cbPdOffset
, PTR
);
1900 SET (external_sym
, cbSymOffset
, PTR
);
1901 SET (external_opt
, cbOptOffset
, PTR
);
1902 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1903 SET (ss
, cbSsOffset
, char *);
1904 SET (external_fdr
, cbFdOffset
, PTR
);
1905 SET (external_rfd
, cbRfdOffset
, PTR
);
1906 /* ssext and external_ext are set up just below. */
1910 /* Set up the external symbols. */
1911 debug
.ssext
= debug
.ssext_end
= NULL
;
1912 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1913 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1914 elf_get_extr
, elf_set_index
))
1915 as_fatal (_("Failed to set up debugging information: %s"),
1916 bfd_errmsg (bfd_get_error ()));
1918 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1919 assert (sec
!= NULL
);
1921 know (stdoutput
->output_has_begun
== false);
1923 /* We set the size of the section, call bfd_set_section_contents
1924 to force the ELF backend to allocate a file position, and then
1925 write out the data. FIXME: Is this really the best way to do
1927 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1929 /* Pass BUF to bfd_set_section_contents because this will
1930 eventually become a call to fwrite, and ISO C prohibits
1931 passing a NULL pointer to a stdio function even if the
1932 pointer will not be used. */
1933 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
1934 (file_ptr
) 0, (bfd_size_type
) 0))
1935 as_fatal (_("Can't start writing .mdebug section: %s"),
1936 bfd_errmsg (bfd_get_error ()));
1938 know (stdoutput
->output_has_begun
== true);
1939 know (sec
->filepos
!= 0);
1941 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1943 as_fatal (_("Could not write .mdebug section: %s"),
1944 bfd_errmsg (bfd_get_error ()));
1946 #endif /* NEED_ECOFF_DEBUG */
1951 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1952 SCO specific identifier in the .notes section to satisfy the SCO
1955 This looks more complicated than it really is. As opposed to the
1956 "obvious" solution, this should handle the cross dev cases
1957 correctly. (i.e, hosting on a 64 bit big endian processor, but
1958 generating SCO Elf code) Efficiency isn't a concern, as there
1959 should be exactly one of these sections per object module.
1961 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1964 int_32 namesz = 4 ; Name size
1965 int_32 descsz = 12 ; Descriptive information
1967 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1968 int_32 version = (major ver # << 16) | version of tools ;
1969 int_32 source = (tool_id << 16 ) | 1 ;
1970 int_32 info = 0 ; These are set by the SCO tools, but we
1971 don't know enough about the source
1972 environment to set them. SCO ld currently
1973 ignores them, and recommends we set them
1976 #define SCO_MAJOR_VERSION 0x1
1977 #define SCO_MINOR_VERSION 0x1
1987 asection
*seg
= now_seg
;
1988 subsegT subseg
= now_subseg
;
1989 Elf_Internal_Note i_note
;
1990 Elf_External_Note e_note
;
1991 asection
*note_secp
= (asection
*) NULL
;
1994 /* create the .note section */
1996 note_secp
= subseg_new (".note", 0);
1997 bfd_set_section_flags (stdoutput
,
1999 SEC_HAS_CONTENTS
| SEC_READONLY
);
2001 /* process the version string */
2004 i_note
.descsz
= 12; /* 12 descriptive bytes */
2005 i_note
.type
= NT_VERSION
; /* Contains a version string */
2007 p
= frag_more (sizeof (i_note
.namesz
));
2008 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2010 p
= frag_more (sizeof (i_note
.descsz
));
2011 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2013 p
= frag_more (sizeof (i_note
.type
));
2014 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2019 /* Note: this is the version number of the ELF we're representing */
2021 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2023 /* Here, we pick a magic number for ourselves (yes, I "registered"
2024 it with SCO. The bottom bit shows that we are compat with the
2027 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2029 /* If we knew (or cared) what the source language options were, we'd
2030 fill them in here. SCO has given us permission to ignore these
2031 and just set them to zero. */
2033 md_number_to_chars (p
, 0x0000, 4);
2035 frag_align (2, 0, 0);
2037 /* We probably can't restore the current segment, for there likely
2040 subseg_set (seg
, subseg
);
2044 #endif /* SCO_ELF */
2047 elf_separate_stab_sections ()
2049 #ifdef NEED_ECOFF_DEBUG
2050 return (!ECOFF_DEBUGGING
);
2057 elf_init_stab_section (seg
)
2060 #ifdef NEED_ECOFF_DEBUG
2061 if (!ECOFF_DEBUGGING
)
2063 obj_elf_init_stab_section (seg
);
2066 const struct format_ops elf_format_ops
=
2068 bfd_target_elf_flavour
,
2069 0, /* dfl_leading_underscore */
2070 1, /* emit_section_symbols */
2075 elf_frob_file_before_adjust
,
2076 elf_frob_file_after_relocs
,
2077 elf_s_get_size
, elf_s_set_size
,
2078 elf_s_get_align
, elf_s_set_align
,
2085 elf_copy_symbol_attributes
,
2086 #ifdef NEED_ECOFF_DEBUG
2087 ecoff_generate_asm_lineno
,
2090 0, /* generate_asm_lineno */
2091 0, /* process_stab */
2093 elf_separate_stab_sections
,
2094 elf_init_stab_section
,
2095 elf_sec_sym_ok_for_reloc
,
2097 #ifdef NEED_ECOFF_DEBUG
2100 0, /* ecoff_set_ext */
2102 elf_obj_read_begin_hook
,
2103 elf_obj_symbol_new_hook