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"
24 #include "safe-ctype.h"
28 #ifndef ECOFF_DEBUGGING
29 #define ECOFF_DEBUGGING 0
31 #define NEED_ECOFF_DEBUG
34 #ifdef NEED_ECOFF_DEBUG
39 #include "elf/alpha.h"
54 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
55 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
56 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
57 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
58 static void elf_s_set_other
PARAMS ((symbolS
*, int));
59 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
60 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
61 static int elf_separate_stab_sections
PARAMS ((void));
62 static void elf_init_stab_section
PARAMS ((segT
));
64 #ifdef NEED_ECOFF_DEBUG
65 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
66 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
69 static void obj_elf_line
PARAMS ((int));
70 void obj_elf_version
PARAMS ((int));
71 static void obj_elf_size
PARAMS ((int));
72 static void obj_elf_type
PARAMS ((int));
73 static void obj_elf_ident
PARAMS ((int));
74 static void obj_elf_weak
PARAMS ((int));
75 static void obj_elf_local
PARAMS ((int));
76 static void obj_elf_visibility
PARAMS ((int));
77 static void obj_elf_change_section
PARAMS ((char *, int, int, int, int));
78 static int obj_elf_parse_section_letters
PARAMS ((char *, size_t));
79 static int obj_elf_section_word
PARAMS ((char *, size_t));
80 static int obj_elf_section_type
PARAMS ((char *, size_t));
81 static void obj_elf_symver
PARAMS ((int));
82 static void obj_elf_subsection
PARAMS ((int));
83 static void obj_elf_popsection
PARAMS ((int));
85 static const pseudo_typeS elf_pseudo_table
[] =
87 {"comm", obj_elf_common
, 0},
88 {"common", obj_elf_common
, 1},
89 {"ident", obj_elf_ident
, 0},
90 {"local", obj_elf_local
, 0},
91 {"previous", obj_elf_previous
, 0},
92 {"section", obj_elf_section
, 0},
93 {"section.s", obj_elf_section
, 0},
94 {"sect", obj_elf_section
, 0},
95 {"sect.s", obj_elf_section
, 0},
96 {"pushsection", obj_elf_section
, 1},
97 {"popsection", obj_elf_popsection
, 0},
98 {"size", obj_elf_size
, 0},
99 {"type", obj_elf_type
, 0},
100 {"version", obj_elf_version
, 0},
101 {"weak", obj_elf_weak
, 0},
103 /* These define symbol visibility. */
104 {"internal", obj_elf_visibility
, STV_INTERNAL
},
105 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
106 {"protected", obj_elf_visibility
, STV_PROTECTED
},
108 /* These are used for stabs-in-elf configurations. */
109 {"line", obj_elf_line
, 0},
111 /* This is a GNU extension to handle symbol versions. */
112 {"symver", obj_elf_symver
, 0},
114 /* A GNU extension to change subsection only. */
115 {"subsection", obj_elf_subsection
, 0},
117 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
118 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
119 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
121 /* These are used for dwarf. */
126 /* We need to trap the section changing calls to handle .previous. */
127 {"data", obj_elf_data
, 0},
128 {"text", obj_elf_text
, 0},
134 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
136 #ifdef NEED_ECOFF_DEBUG
137 /* COFF style debugging information for ECOFF. .ln is not used; .loc
139 { "def", ecoff_directive_def
, 0 },
140 { "dim", ecoff_directive_dim
, 0 },
141 { "endef", ecoff_directive_endef
, 0 },
142 { "file", ecoff_directive_file
, 0 },
143 { "scl", ecoff_directive_scl
, 0 },
144 { "tag", ecoff_directive_tag
, 0 },
145 { "val", ecoff_directive_val
, 0 },
147 /* COFF debugging requires pseudo-ops .size and .type, but ELF
148 already has meanings for those. We use .esize and .etype
149 instead. These are only generated by gcc anyhow. */
150 { "esize", ecoff_directive_size
, 0 },
151 { "etype", ecoff_directive_type
, 0 },
153 /* ECOFF specific debugging information. */
154 { "begin", ecoff_directive_begin
, 0 },
155 { "bend", ecoff_directive_bend
, 0 },
156 { "end", ecoff_directive_end
, 0 },
157 { "ent", ecoff_directive_ent
, 0 },
158 { "fmask", ecoff_directive_fmask
, 0 },
159 { "frame", ecoff_directive_frame
, 0 },
160 { "loc", ecoff_directive_loc
, 0 },
161 { "mask", ecoff_directive_mask
, 0 },
163 /* Other ECOFF directives. */
164 { "extern", ecoff_directive_extern
, 0 },
166 /* These are used on Irix. I don't know how to implement them. */
167 { "alias", s_ignore
, 0 },
168 { "bgnb", s_ignore
, 0 },
169 { "endb", s_ignore
, 0 },
170 { "lab", s_ignore
, 0 },
171 { "noalias", s_ignore
, 0 },
172 { "verstamp", s_ignore
, 0 },
173 { "vreg", s_ignore
, 0 },
176 {NULL
, NULL
, 0} /* end sentinel */
180 #include "aout/aout64.h"
182 /* This is called when the assembler starts. */
187 /* Add symbols for the known sections to the symbol table. */
188 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
189 TEXT_SECTION_NAME
)));
190 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
191 DATA_SECTION_NAME
)));
192 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
199 pop_insert (elf_pseudo_table
);
201 pop_insert (ecoff_debug_pseudo_table
);
208 return S_GET_SIZE (sym
);
212 elf_s_set_size (sym
, sz
)
216 S_SET_SIZE (sym
, sz
);
220 elf_s_get_align (sym
)
223 return S_GET_ALIGN (sym
);
227 elf_s_set_align (sym
, align
)
231 S_SET_ALIGN (sym
, align
);
235 elf_s_get_other (sym
)
238 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
242 elf_s_set_other (sym
, other
)
246 S_SET_OTHER (sym
, other
);
250 elf_sec_sym_ok_for_reloc (sec
)
253 return obj_sec_sym_ok_for_reloc (sec
);
262 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
263 symbol_set_frag (sym
, &zero_address_frag
);
264 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
266 if (symbol_rootP
!= sym
)
268 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
269 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
271 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
275 #ifdef NEED_ECOFF_DEBUG
281 obj_elf_common (is_common
)
291 if (flag_mri
&& is_common
)
297 name
= input_line_pointer
;
298 c
= get_symbol_end ();
299 /* just after name is now '\0' */
300 p
= input_line_pointer
;
303 if (*input_line_pointer
!= ',')
305 as_bad (_("Expected comma after symbol-name"));
306 ignore_rest_of_line ();
309 input_line_pointer
++; /* skip ',' */
310 if ((temp
= get_absolute_expression ()) < 0)
312 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
313 ignore_rest_of_line ();
318 symbolP
= symbol_find_or_make (name
);
320 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
322 as_bad (_("Ignoring attempt to re-define symbol"));
323 ignore_rest_of_line ();
326 if (S_GET_VALUE (symbolP
) != 0)
328 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
330 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
331 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
334 know (symbolP
->sy_frag
== &zero_address_frag
);
335 if (*input_line_pointer
!= ',')
340 input_line_pointer
++;
343 if (! have_align
|| *input_line_pointer
!= '"')
349 temp
= get_absolute_expression ();
353 as_warn (_("Common alignment negative; 0 assumed"));
356 if (symbol_get_obj (symbolP
)->local
)
365 old_subsec
= now_subseg
;
368 /* convert to a power of 2 alignment */
369 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
372 as_bad (_("Common alignment not a power of 2"));
373 ignore_rest_of_line ();
379 record_alignment (bss_section
, align
);
380 subseg_set (bss_section
, 0);
382 frag_align (align
, 0, 0);
383 if (S_GET_SEGMENT (symbolP
) == bss_section
)
384 symbol_get_frag (symbolP
)->fr_symbol
= 0;
385 symbol_set_frag (symbolP
, frag_now
);
386 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
387 (offsetT
) size
, (char *) 0);
389 S_SET_SIZE (symbolP
, size
);
390 S_SET_SEGMENT (symbolP
, bss_section
);
391 S_CLEAR_EXTERNAL (symbolP
);
392 subseg_set (old_sec
, old_subsec
);
397 S_SET_VALUE (symbolP
, (valueT
) size
);
398 S_SET_ALIGN (symbolP
, temp
);
399 S_SET_EXTERNAL (symbolP
);
400 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
405 input_line_pointer
++;
406 /* @@ Some use the dot, some don't. Can we get some consistency?? */
407 if (*input_line_pointer
== '.')
408 input_line_pointer
++;
409 /* @@ Some say data, some say bss. */
410 if (strncmp (input_line_pointer
, "bss\"", 4)
411 && strncmp (input_line_pointer
, "data\"", 5))
413 while (*--input_line_pointer
!= '"')
415 input_line_pointer
--;
416 goto bad_common_segment
;
418 while (*input_line_pointer
++ != '"')
420 goto allocate_common
;
423 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
425 demand_empty_rest_of_line ();
430 p
= input_line_pointer
;
431 while (*p
&& *p
!= '\n')
435 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
437 input_line_pointer
= p
;
438 ignore_rest_of_line ();
444 obj_elf_local (ignore
)
445 int ignore ATTRIBUTE_UNUSED
;
453 name
= input_line_pointer
;
454 c
= get_symbol_end ();
455 symbolP
= symbol_find_or_make (name
);
456 *input_line_pointer
= c
;
458 S_CLEAR_EXTERNAL (symbolP
);
459 symbol_get_obj (symbolP
)->local
= 1;
462 input_line_pointer
++;
464 if (*input_line_pointer
== '\n')
469 demand_empty_rest_of_line ();
473 obj_elf_weak (ignore
)
474 int ignore ATTRIBUTE_UNUSED
;
482 name
= input_line_pointer
;
483 c
= get_symbol_end ();
484 symbolP
= symbol_find_or_make (name
);
485 *input_line_pointer
= c
;
487 S_SET_WEAK (symbolP
);
488 symbol_get_obj (symbolP
)->local
= 1;
491 input_line_pointer
++;
493 if (*input_line_pointer
== '\n')
498 demand_empty_rest_of_line ();
502 obj_elf_visibility (visibility
)
509 elf_symbol_type
*elfsym
;
513 name
= input_line_pointer
;
514 c
= get_symbol_end ();
515 symbolP
= symbol_find_or_make (name
);
516 *input_line_pointer
= c
;
520 bfdsym
= symbol_get_bfdsym (symbolP
);
521 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
525 elfsym
->internal_elf_sym
.st_other
= visibility
;
529 input_line_pointer
++;
533 if (*input_line_pointer
== '\n')
539 demand_empty_rest_of_line ();
542 static segT previous_section
;
543 static int previous_subsection
;
547 struct section_stack
*next
;
549 int subseg
, prev_subseg
;
552 static struct section_stack
*section_stack
;
554 /* Handle the .section pseudo-op. This code supports two different
557 The first is found on Solaris, and looks like
558 .section ".sec1",#alloc,#execinstr,#write
559 Here the names after '#' are the SHF_* flags to turn on for the
560 section. I'm not sure how it determines the SHT_* type (BFD
561 doesn't really give us control over the type, anyhow).
563 The second format is found on UnixWare, and probably most SVR4
564 machines, and looks like
565 .section .sec1,"a",@progbits
566 The quoted string may contain any combination of a, w, x, and
567 represents the SHF_* flags to turn on for the section. The string
568 beginning with '@' can be progbits or nobits. There should be
569 other possibilities, but I don't know what they are. In any case,
570 BFD doesn't really let us set the section type. */
572 /* Certain named sections have particular defined types, listed on p.
574 struct special_section
581 static struct special_section
const special_sections
[] =
583 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
584 { ".comment", SHT_PROGBITS
, 0 },
585 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
586 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
587 { ".debug", SHT_PROGBITS
, 0 },
588 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
589 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
590 { ".line", SHT_PROGBITS
, 0 },
591 { ".note", SHT_NOTE
, 0 },
592 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
593 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
594 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
596 #ifdef ELF_TC_SPECIAL_SECTIONS
597 ELF_TC_SPECIAL_SECTIONS
601 /* The following section names are special, but they can not
602 reasonably appear in assembler code. Some of the attributes are
603 processor dependent. */
604 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
605 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
606 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
607 { ".got", SHT_PROGBITS
, 0 },
608 { ".hash", SHT_HASH
, SHF_ALLOC
},
609 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
610 { ".plt", SHT_PROGBITS
, 0 },
611 { ".shstrtab",SHT_STRTAB
, 0 },
612 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
613 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
620 obj_elf_change_section (name
, type
, attr
, entsize
, push
)
622 int type
, attr
, entsize
, push
;
629 #ifdef md_flush_pending_output
630 md_flush_pending_output ();
633 /* Switch to the section, creating it if necessary. */
636 struct section_stack
*elt
;
637 elt
= xmalloc (sizeof (struct section_stack
));
638 elt
->next
= section_stack
;
640 elt
->prev_seg
= previous_section
;
641 elt
->subseg
= now_subseg
;
642 elt
->prev_subseg
= previous_subsection
;
645 previous_section
= now_seg
;
646 previous_subsection
= now_subseg
;
648 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
649 sec
= subseg_new (name
, 0);
651 /* See if this is one of the special sections. */
652 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
653 if (strcmp (name
, special_sections
[i
].name
) == 0)
655 if (type
== SHT_NULL
)
656 type
= special_sections
[i
].type
;
657 else if (type
!= special_sections
[i
].type
)
661 as_warn (_("Setting incorrect section type for %s"), name
);
665 as_warn (_("Ignoring incorrect section type for %s"), name
);
666 type
= special_sections
[i
].type
;
669 if ((attr
&~ special_sections
[i
].attributes
) != 0
672 /* As a GNU extension, we permit a .note section to be
673 allocatable. If the linker sees an allocateable .note
674 section, it will create a PT_NOTE segment in the output
676 if (strcmp (name
, ".note") != 0
677 || attr
!= SHF_ALLOC
)
678 as_warn (_("Setting incorrect section attributes for %s"),
681 attr
|= special_sections
[i
].attributes
;
685 /* Convert ELF type and flags to BFD flags. */
687 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
688 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
689 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
690 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
691 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
692 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0));
693 #ifdef md_elf_section_flags
694 flags
= md_elf_section_flags (flags
, attr
, type
);
701 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
702 if (type
== SHT_NOBITS
)
703 seg_info (sec
)->bss
= 1;
705 bfd_set_section_flags (stdoutput
, sec
, flags
);
706 if (flags
& SEC_MERGE
)
707 sec
->entsize
= entsize
;
709 /* Add a symbol for this section to the symbol table. */
710 secsym
= symbol_find (name
);
712 symbol_set_bfdsym (secsym
, sec
->symbol
);
714 symbol_table_insert (section_symbol (sec
));
718 /* If section attributes are specified the second time we see a
719 particular section, then check that they are the same as we
720 saw the first time. */
721 if ((old_sec
->flags
^ flags
)
722 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
723 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
| SEC_MERGE
| SEC_STRINGS
))
724 as_warn (_("Ignoring changed section attributes for %s"), name
);
725 else if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= (unsigned) entsize
)
726 as_warn (_("Ignoring changed section entity size for %s"), name
);
729 #ifdef md_elf_section_change_hook
730 md_elf_section_change_hook ();
735 obj_elf_parse_section_letters (str
, len
)
752 attr
|= SHF_EXECINSTR
;
762 char *bad_msg
= _("Unrecognized .section attribute: want a,w,x,M,S");
763 #ifdef md_elf_section_letter
764 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
770 as_warn ("%s", bad_msg
);
783 obj_elf_section_word (str
, len
)
787 if (len
== 5 && strncmp (str
, "write", 5) == 0)
789 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
791 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
792 return SHF_EXECINSTR
;
794 #ifdef md_elf_section_word
796 int md_attr
= md_elf_section_word (str
, len
);
802 as_warn (_("Unrecognized section attribute"));
807 obj_elf_section_type (str
, len
)
811 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
813 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
816 #ifdef md_elf_section_type
818 int md_type
= md_elf_section_type (str
, len
);
824 as_warn (_("Unrecognized section type"));
829 obj_elf_section (push
)
832 char *name
, *beg
, *end
;
833 int type
, attr
, dummy
;
841 #ifdef md_flush_pending_output
842 md_flush_pending_output ();
845 previous_section
= now_seg
;
846 previous_subsection
= now_subseg
;
848 s_mri_sect (&mri_type
);
850 #ifdef md_elf_section_change_hook
851 md_elf_section_change_hook ();
856 #endif /* ! defined (TC_I370) */
858 /* Get name of section. */
860 if (*input_line_pointer
== '"')
862 name
= demand_copy_C_string (&dummy
);
865 ignore_rest_of_line ();
871 end
= input_line_pointer
;
872 while (0 == strchr ("\n\t,; ", *end
))
874 if (end
== input_line_pointer
)
876 as_warn (_("Missing section name"));
877 ignore_rest_of_line ();
881 name
= xmalloc (end
- input_line_pointer
+ 1);
882 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
883 name
[end
- input_line_pointer
] = '\0';
884 input_line_pointer
= end
;
892 if (*input_line_pointer
== ',')
894 /* Skip the comma. */
895 ++input_line_pointer
;
898 if (*input_line_pointer
== '"')
900 beg
= demand_copy_C_string (&dummy
);
903 ignore_rest_of_line ();
906 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
909 if (*input_line_pointer
== ',')
912 ++input_line_pointer
;
914 c
= *input_line_pointer
;
917 beg
= demand_copy_C_string (&dummy
);
920 ignore_rest_of_line ();
923 type
= obj_elf_section_type (beg
, strlen (beg
));
925 else if (c
== '@' || c
== '%')
927 beg
= ++input_line_pointer
;
928 c
= get_symbol_end ();
929 *input_line_pointer
= c
;
930 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
935 if ((attr
& SHF_MERGE
) && *input_line_pointer
== ',')
937 ++input_line_pointer
;
939 entsize
= get_absolute_expression ();
942 as_warn (_("Bad .section directive - invalid merge entity size"));
955 if (*input_line_pointer
!= '#')
957 as_warn (_("Bad .section directive - character following name is not '#'"));
958 ignore_rest_of_line ();
961 beg
= ++input_line_pointer
;
962 c
= get_symbol_end ();
963 *input_line_pointer
= c
;
965 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
969 while (*input_line_pointer
++ == ',');
970 --input_line_pointer
;
974 demand_empty_rest_of_line ();
976 if ((attr
& SHF_MERGE
) && entsize
== 0)
978 as_warn (_("Entity size for SHF_MERGE not specified.\nSpecify entity size as 4th argument"));
982 obj_elf_change_section (name
, type
, attr
, entsize
, push
);
985 /* Change to the .data section. */
991 #ifdef md_flush_pending_output
992 md_flush_pending_output ();
995 previous_section
= now_seg
;
996 previous_subsection
= now_subseg
;
999 #ifdef md_elf_section_change_hook
1000 md_elf_section_change_hook ();
1004 /* Change to the .text section. */
1010 #ifdef md_flush_pending_output
1011 md_flush_pending_output ();
1014 previous_section
= now_seg
;
1015 previous_subsection
= now_subseg
;
1018 #ifdef md_elf_section_change_hook
1019 md_elf_section_change_hook ();
1024 obj_elf_subsection (ignore
)
1025 int ignore ATTRIBUTE_UNUSED
;
1029 #ifdef md_flush_pending_output
1030 md_flush_pending_output ();
1033 previous_section
= now_seg
;
1034 previous_subsection
= now_subseg
;
1036 temp
= get_absolute_expression ();
1037 subseg_set (now_seg
, (subsegT
) temp
);
1038 demand_empty_rest_of_line ();
1040 #ifdef md_elf_section_change_hook
1041 md_elf_section_change_hook ();
1045 /* This can be called from the processor backends if they change
1049 obj_elf_section_change_hook ()
1051 previous_section
= now_seg
;
1052 previous_subsection
= now_subseg
;
1056 obj_elf_previous (ignore
)
1057 int ignore ATTRIBUTE_UNUSED
;
1062 if (previous_section
== 0)
1064 as_bad (_(".previous without corresponding .section; ignored"));
1068 #ifdef md_flush_pending_output
1069 md_flush_pending_output ();
1072 new_section
= previous_section
;
1073 new_subsection
= previous_subsection
;
1074 previous_section
= now_seg
;
1075 previous_subsection
= now_subseg
;
1076 subseg_set (new_section
, new_subsection
);
1078 #ifdef md_elf_section_change_hook
1079 md_elf_section_change_hook ();
1084 obj_elf_popsection (xxx
)
1085 int xxx ATTRIBUTE_UNUSED
;
1087 struct section_stack
*top
= section_stack
;
1091 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1095 #ifdef md_flush_pending_output
1096 md_flush_pending_output ();
1099 section_stack
= top
->next
;
1100 previous_section
= top
->prev_seg
;
1101 previous_subsection
= top
->prev_subseg
;
1102 subseg_set (top
->seg
, top
->subseg
);
1105 #ifdef md_elf_section_change_hook
1106 md_elf_section_change_hook ();
1111 obj_elf_line (ignore
)
1112 int ignore ATTRIBUTE_UNUSED
;
1114 /* Assume delimiter is part of expression. BSD4.2 as fails with
1115 delightful bug, so we are not being incompatible here. */
1116 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1117 demand_empty_rest_of_line ();
1120 /* This handles the .symver pseudo-op, which is used to specify a
1121 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1122 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1123 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1124 with the same value as the symbol NAME. */
1127 obj_elf_symver (ignore
)
1128 int ignore ATTRIBUTE_UNUSED
;
1135 name
= input_line_pointer
;
1136 c
= get_symbol_end ();
1138 sym
= symbol_find_or_make (name
);
1140 *input_line_pointer
= c
;
1143 if (*input_line_pointer
!= ',')
1145 as_bad (_("expected comma after name in .symver"));
1146 ignore_rest_of_line ();
1150 ++input_line_pointer
;
1151 name
= input_line_pointer
;
1153 /* Temporarily include '@' in symbol names. */
1154 old_lexat
= lex_type
[(unsigned char) '@'];
1155 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1156 c
= get_symbol_end ();
1157 lex_type
[(unsigned char) '@'] = old_lexat
;
1159 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1161 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1163 *input_line_pointer
= c
;
1165 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1166 ELF_VER_CHR
) == NULL
)
1168 as_bad (_("missing version name in `%s' for symbol `%s'"),
1169 symbol_get_obj (sym
)->versioned_name
,
1171 ignore_rest_of_line ();
1177 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1179 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1180 name
, symbol_get_obj (sym
)->versioned_name
,
1182 ignore_rest_of_line ();
1186 *input_line_pointer
= c
;
1189 demand_empty_rest_of_line ();
1192 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1193 to the linker the hierarchy in which a particular table resides. The
1194 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1197 obj_elf_vtable_inherit (ignore
)
1198 int ignore ATTRIBUTE_UNUSED
;
1200 char *cname
, *pname
;
1201 symbolS
*csym
, *psym
;
1204 if (*input_line_pointer
== '#')
1205 ++input_line_pointer
;
1207 cname
= input_line_pointer
;
1208 c
= get_symbol_end ();
1209 csym
= symbol_find (cname
);
1211 /* GCFIXME: should check that we don't have two .vtable_inherits for
1212 the same child symbol. Also, we can currently only do this if the
1213 child symbol is already exists and is placed in a fragment. */
1215 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1217 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1222 *input_line_pointer
= c
;
1225 if (*input_line_pointer
!= ',')
1227 as_bad ("expected comma after name in .vtable_inherit");
1228 ignore_rest_of_line ();
1232 ++input_line_pointer
;
1235 if (*input_line_pointer
== '#')
1236 ++input_line_pointer
;
1238 if (input_line_pointer
[0] == '0'
1239 && (input_line_pointer
[1] == '\0'
1240 || ISSPACE (input_line_pointer
[1])))
1242 psym
= section_symbol (absolute_section
);
1243 ++input_line_pointer
;
1247 pname
= input_line_pointer
;
1248 c
= get_symbol_end ();
1249 psym
= symbol_find_or_make (pname
);
1250 *input_line_pointer
= c
;
1253 demand_empty_rest_of_line ();
1258 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1259 return fix_new (symbol_get_frag (csym
),
1260 symbol_get_value_expression (csym
)->X_add_number
,
1261 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1264 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1265 to the linker that a vtable slot was used. The syntax is
1266 ".vtable_entry tablename, offset". */
1269 obj_elf_vtable_entry (ignore
)
1270 int ignore ATTRIBUTE_UNUSED
;
1277 if (*input_line_pointer
== '#')
1278 ++input_line_pointer
;
1280 name
= input_line_pointer
;
1281 c
= get_symbol_end ();
1282 sym
= symbol_find_or_make (name
);
1283 *input_line_pointer
= c
;
1286 if (*input_line_pointer
!= ',')
1288 as_bad ("expected comma after name in .vtable_entry");
1289 ignore_rest_of_line ();
1293 ++input_line_pointer
;
1294 if (*input_line_pointer
== '#')
1295 ++input_line_pointer
;
1297 offset
= get_absolute_expression ();
1299 demand_empty_rest_of_line ();
1301 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1302 BFD_RELOC_VTABLE_ENTRY
);
1306 elf_obj_read_begin_hook ()
1308 #ifdef NEED_ECOFF_DEBUG
1309 if (ECOFF_DEBUGGING
)
1310 ecoff_read_begin_hook ();
1315 elf_obj_symbol_new_hook (symbolP
)
1318 struct elf_obj_sy
*sy_obj
;
1320 sy_obj
= symbol_get_obj (symbolP
);
1321 sy_obj
->size
= NULL
;
1322 sy_obj
->versioned_name
= NULL
;
1324 #ifdef NEED_ECOFF_DEBUG
1325 if (ECOFF_DEBUGGING
)
1326 ecoff_symbol_new_hook (symbolP
);
1330 /* When setting one symbol equal to another, by default we probably
1331 want them to have the same "size", whatever it means in the current
1335 elf_copy_symbol_attributes (dest
, src
)
1336 symbolS
*dest
, *src
;
1338 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1339 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1342 if (destelf
->size
== NULL
)
1344 (expressionS
*) xmalloc (sizeof (expressionS
));
1345 *destelf
->size
= *srcelf
->size
;
1349 if (destelf
->size
!= NULL
)
1350 free (destelf
->size
);
1351 destelf
->size
= NULL
;
1353 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1354 S_SET_OTHER (dest
, S_GET_OTHER (src
));
1358 obj_elf_version (ignore
)
1359 int ignore ATTRIBUTE_UNUSED
;
1365 asection
*seg
= now_seg
;
1366 subsegT subseg
= now_subseg
;
1367 Elf_Internal_Note i_note
;
1368 Elf_External_Note e_note
;
1369 asection
*note_secp
= (asection
*) NULL
;
1373 if (*input_line_pointer
== '\"')
1375 ++input_line_pointer
; /* -> 1st char of string. */
1376 name
= input_line_pointer
;
1378 while (is_a_char (c
= next_char_of_string ()))
1380 c
= *input_line_pointer
;
1381 *input_line_pointer
= '\0';
1382 *(input_line_pointer
- 1) = '\0';
1383 *input_line_pointer
= c
;
1385 /* create the .note section */
1387 note_secp
= subseg_new (".note", 0);
1388 bfd_set_section_flags (stdoutput
,
1390 SEC_HAS_CONTENTS
| SEC_READONLY
);
1392 /* process the version string */
1394 len
= strlen (name
);
1396 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1397 i_note
.descsz
= 0; /* no description */
1398 i_note
.type
= NT_VERSION
;
1399 p
= frag_more (sizeof (e_note
.namesz
));
1400 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1401 p
= frag_more (sizeof (e_note
.descsz
));
1402 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1403 p
= frag_more (sizeof (e_note
.type
));
1404 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1406 for (i
= 0; i
< len
; i
++)
1410 FRAG_APPEND_1_CHAR (ch
);
1413 frag_align (2, 0, 0);
1415 subseg_set (seg
, subseg
);
1419 as_bad (_("Expected quoted string"));
1421 demand_empty_rest_of_line ();
1425 obj_elf_size (ignore
)
1426 int ignore ATTRIBUTE_UNUSED
;
1428 char *name
= input_line_pointer
;
1429 char c
= get_symbol_end ();
1434 p
= input_line_pointer
;
1437 if (*input_line_pointer
!= ',')
1440 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1442 ignore_rest_of_line ();
1445 input_line_pointer
++;
1447 if (exp
.X_op
== O_absent
)
1449 as_bad (_("missing expression in .size directive"));
1450 exp
.X_op
= O_constant
;
1451 exp
.X_add_number
= 0;
1454 sym
= symbol_find_or_make (name
);
1456 if (exp
.X_op
== O_constant
)
1458 S_SET_SIZE (sym
, exp
.X_add_number
);
1459 if (symbol_get_obj (sym
)->size
)
1461 xfree (symbol_get_obj (sym
)->size
);
1462 symbol_get_obj (sym
)->size
= NULL
;
1467 symbol_get_obj (sym
)->size
=
1468 (expressionS
*) xmalloc (sizeof (expressionS
));
1469 *symbol_get_obj (sym
)->size
= exp
;
1471 demand_empty_rest_of_line ();
1474 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1475 There are five syntaxes:
1477 The first (used on Solaris) is
1479 The second (used on UnixWare) is
1481 The third (reportedly to be used on Irix 6.0) is
1483 The fourth (used on NetBSD/Arm and Linux/ARM) is
1485 The fifth (used on SVR4/860) is
1486 .type SYM,"function"
1490 obj_elf_type (ignore
)
1491 int ignore ATTRIBUTE_UNUSED
;
1496 const char *typename
;
1498 elf_symbol_type
*elfsym
;
1500 name
= input_line_pointer
;
1501 c
= get_symbol_end ();
1502 sym
= symbol_find_or_make (name
);
1503 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1504 *input_line_pointer
= c
;
1507 if (*input_line_pointer
== ',')
1508 ++input_line_pointer
;
1511 if ( *input_line_pointer
== '#'
1512 || *input_line_pointer
== '@'
1513 || *input_line_pointer
== '"'
1514 || *input_line_pointer
== '%')
1515 ++input_line_pointer
;
1517 typename
= input_line_pointer
;
1518 c
= get_symbol_end ();
1521 if (strcmp (typename
, "function") == 0
1522 || strcmp (typename
, "STT_FUNC") == 0)
1523 type
= BSF_FUNCTION
;
1524 else if (strcmp (typename
, "object") == 0
1525 || strcmp (typename
, "STT_OBJECT") == 0)
1527 #ifdef md_elf_symbol_type
1528 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1532 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1534 *input_line_pointer
= c
;
1536 if (*input_line_pointer
== '"')
1537 ++input_line_pointer
;
1539 elfsym
->symbol
.flags
|= type
;
1541 demand_empty_rest_of_line ();
1545 obj_elf_ident (ignore
)
1546 int ignore ATTRIBUTE_UNUSED
;
1548 static segT comment_section
;
1549 segT old_section
= now_seg
;
1550 int old_subsection
= now_subseg
;
1552 #ifdef md_flush_pending_output
1553 md_flush_pending_output ();
1556 if (!comment_section
)
1559 comment_section
= subseg_new (".comment", 0);
1560 bfd_set_section_flags (stdoutput
, comment_section
,
1561 SEC_READONLY
| SEC_HAS_CONTENTS
);
1566 subseg_set (comment_section
, 0);
1568 subseg_set (old_section
, old_subsection
);
1571 #ifdef INIT_STAB_SECTION
1573 /* The first entry in a .stabs section is special. */
1576 obj_elf_init_stab_section (seg
)
1582 unsigned int stroff
;
1584 /* Force the section to align to a longword boundary. Without this,
1585 UnixWare ar crashes. */
1586 bfd_set_section_alignment (stdoutput
, seg
, 2);
1588 /* Make space for this first symbol. */
1592 as_where (&file
, (unsigned int *) NULL
);
1593 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1594 strcpy (stabstr_name
, segment_name (seg
));
1595 strcat (stabstr_name
, "str");
1596 stroff
= get_stab_string_offset (file
, stabstr_name
);
1598 md_number_to_chars (p
, stroff
, 4);
1599 seg_info (seg
)->stabu
.p
= p
;
1604 /* Fill in the counts in the first entry in a .stabs section. */
1607 adjust_stab_sections (abfd
, sec
, xxx
)
1610 PTR xxx ATTRIBUTE_UNUSED
;
1617 if (strncmp (".stab", sec
->name
, 5))
1619 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1622 name
= (char *) alloca (strlen (sec
->name
) + 4);
1623 strcpy (name
, sec
->name
);
1624 strcat (name
, "str");
1625 strsec
= bfd_get_section_by_name (abfd
, name
);
1627 strsz
= bfd_section_size (abfd
, strsec
);
1630 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1632 p
= seg_info (sec
)->stabu
.p
;
1635 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1636 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1639 #ifdef NEED_ECOFF_DEBUG
1641 /* This function is called by the ECOFF code. It is supposed to
1642 record the external symbol information so that the backend can
1643 write it out correctly. The ELF backend doesn't actually handle
1644 this at the moment, so we do it ourselves. We save the information
1648 elf_ecoff_set_ext (sym
, ext
)
1650 struct ecoff_extr
*ext
;
1652 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1655 /* This function is called by bfd_ecoff_debug_externals. It is
1656 supposed to *EXT to the external symbol information, and return
1657 whether the symbol should be used at all. */
1660 elf_get_extr (sym
, ext
)
1664 if (sym
->udata
.p
== NULL
)
1666 *ext
= *(EXTR
*) sym
->udata
.p
;
1670 /* This function is called by bfd_ecoff_debug_externals. It has
1671 nothing to do for ELF. */
1675 elf_set_index (sym
, indx
)
1676 asymbol
*sym ATTRIBUTE_UNUSED
;
1677 bfd_size_type indx ATTRIBUTE_UNUSED
;
1681 #endif /* NEED_ECOFF_DEBUG */
1684 elf_frob_symbol (symp
, puntp
)
1688 struct elf_obj_sy
*sy_obj
;
1690 #ifdef NEED_ECOFF_DEBUG
1691 if (ECOFF_DEBUGGING
)
1692 ecoff_frob_symbol (symp
);
1695 sy_obj
= symbol_get_obj (symp
);
1697 if (sy_obj
->size
!= NULL
)
1699 switch (sy_obj
->size
->X_op
)
1703 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1704 + sy_obj
->size
->X_add_number
1705 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1709 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1710 + sy_obj
->size
->X_add_number
));
1713 as_bad (_(".size expression too complicated to fix up"));
1716 free (sy_obj
->size
);
1717 sy_obj
->size
= NULL
;
1720 if (sy_obj
->versioned_name
!= NULL
)
1724 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1727 /* This symbol was given a new name with the .symver directive.
1729 If this is an external reference, just rename the symbol to
1730 include the version string. This will make the relocs be
1731 against the correct versioned symbol.
1733 If this is a definition, add an alias. FIXME: Using an alias
1734 will permit the debugging information to refer to the right
1735 symbol. However, it's not clear whether it is the best
1738 if (! S_IS_DEFINED (symp
))
1740 /* Verify that the name isn't using the @@ syntax--this is
1741 reserved for definitions of the default version to link
1743 if (p
[1] == ELF_VER_CHR
)
1745 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1746 sy_obj
->versioned_name
);
1749 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1753 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1757 /* The @@@ syntax is a special case. It renames the
1758 symbol name to versioned_name with one `@' removed. */
1759 l
= strlen (&p
[3]) + 1;
1760 memmove (&p
[2], &p
[3], l
);
1761 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1767 /* FIXME: Creating a new symbol here is risky. We're
1768 in the final loop over the symbol table. We can
1769 get away with it only because the symbol goes to
1770 the end of the list, where the loop will still see
1771 it. It would probably be better to do this in
1772 obj_frob_file_before_adjust. */
1774 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1776 /* Now we act as though we saw symp2 = sym. */
1778 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1780 /* Subtracting out the frag address here is a hack
1781 because we are in the middle of the final loop. */
1784 - symbol_get_frag (symp
)->fr_address
));
1786 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1788 /* This will copy over the size information. */
1789 copy_symbol_attributes (symp2
, symp
);
1791 if (S_IS_WEAK (symp
))
1794 if (S_IS_EXTERNAL (symp
))
1795 S_SET_EXTERNAL (symp2
);
1800 /* Double check weak symbols. */
1801 if (S_IS_WEAK (symp
))
1803 if (S_IS_COMMON (symp
))
1804 as_bad (_("Symbol `%s' can not be both weak and common"),
1809 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1810 any undefined non-function symbol to STT_OBJECT. We try to be
1811 compatible, since newer Irix 5 and 6 linkers care. However, we
1812 only set undefined symbols to be STT_OBJECT if we are on Irix,
1813 because that is the only time gcc will generate the necessary
1814 .global directives to mark functions. */
1816 if (S_IS_COMMON (symp
))
1817 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1819 if (strstr (TARGET_OS
, "irix") != NULL
1820 && ! S_IS_DEFINED (symp
)
1821 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1822 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1826 /* If TC_PPC is defined, we used to force the type of a symbol to be
1827 BSF_OBJECT if it was otherwise unset. This was required by some
1828 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1829 that this is no longer needed, so it is now commented out. */
1830 if ((symbol_get_bfdsym (symp
)->flags
1831 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1832 && S_IS_DEFINED (symp
))
1833 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1840 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1842 #ifdef elf_tc_final_processing
1843 elf_tc_final_processing ();
1847 /* It removes any unneeded versioned symbols from the symbol table. */
1850 elf_frob_file_before_adjust ()
1856 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1857 if (symbol_get_obj (symp
)->versioned_name
)
1859 if (!S_IS_DEFINED (symp
))
1863 /* The @@@ syntax is a special case. If the symbol is
1864 not defined, 2 `@'s will be removed from the
1867 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1870 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1872 size_t l
= strlen (&p
[3]) + 1;
1873 memmove (&p
[1], &p
[3], l
);
1875 if (symbol_used_p (symp
) == 0
1876 && symbol_used_in_reloc_p (symp
) == 0)
1877 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1883 /* It is required that we let write_relocs have the opportunity to
1884 optimize away fixups before output has begun, since it is possible
1885 to eliminate all fixups for a section and thus we never should
1886 have generated the relocation section. */
1889 elf_frob_file_after_relocs ()
1891 #ifdef NEED_ECOFF_DEBUG
1892 if (ECOFF_DEBUGGING
)
1893 /* Generate the ECOFF debugging information. */
1895 const struct ecoff_debug_swap
*debug_swap
;
1896 struct ecoff_debug_info debug
;
1901 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1902 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1903 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1905 /* Set up the pointers in debug. */
1906 #define SET(ptr, offset, type) \
1907 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1909 SET (line
, cbLineOffset
, unsigned char *);
1910 SET (external_dnr
, cbDnOffset
, PTR
);
1911 SET (external_pdr
, cbPdOffset
, PTR
);
1912 SET (external_sym
, cbSymOffset
, PTR
);
1913 SET (external_opt
, cbOptOffset
, PTR
);
1914 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1915 SET (ss
, cbSsOffset
, char *);
1916 SET (external_fdr
, cbFdOffset
, PTR
);
1917 SET (external_rfd
, cbRfdOffset
, PTR
);
1918 /* ssext and external_ext are set up just below. */
1922 /* Set up the external symbols. */
1923 debug
.ssext
= debug
.ssext_end
= NULL
;
1924 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1925 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1926 elf_get_extr
, elf_set_index
))
1927 as_fatal (_("Failed to set up debugging information: %s"),
1928 bfd_errmsg (bfd_get_error ()));
1930 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1931 assert (sec
!= NULL
);
1933 know (stdoutput
->output_has_begun
== false);
1935 /* We set the size of the section, call bfd_set_section_contents
1936 to force the ELF backend to allocate a file position, and then
1937 write out the data. FIXME: Is this really the best way to do
1939 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1941 /* Pass BUF to bfd_set_section_contents because this will
1942 eventually become a call to fwrite, and ISO C prohibits
1943 passing a NULL pointer to a stdio function even if the
1944 pointer will not be used. */
1945 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
1946 (file_ptr
) 0, (bfd_size_type
) 0))
1947 as_fatal (_("Can't start writing .mdebug section: %s"),
1948 bfd_errmsg (bfd_get_error ()));
1950 know (stdoutput
->output_has_begun
== true);
1951 know (sec
->filepos
!= 0);
1953 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1955 as_fatal (_("Could not write .mdebug section: %s"),
1956 bfd_errmsg (bfd_get_error ()));
1958 #endif /* NEED_ECOFF_DEBUG */
1963 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1964 SCO specific identifier in the .notes section to satisfy the SCO
1967 This looks more complicated than it really is. As opposed to the
1968 "obvious" solution, this should handle the cross dev cases
1969 correctly. (i.e, hosting on a 64 bit big endian processor, but
1970 generating SCO Elf code) Efficiency isn't a concern, as there
1971 should be exactly one of these sections per object module.
1973 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1976 int_32 namesz = 4 ; Name size
1977 int_32 descsz = 12 ; Descriptive information
1979 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1980 int_32 version = (major ver # << 16) | version of tools ;
1981 int_32 source = (tool_id << 16 ) | 1 ;
1982 int_32 info = 0 ; These are set by the SCO tools, but we
1983 don't know enough about the source
1984 environment to set them. SCO ld currently
1985 ignores them, and recommends we set them
1988 #define SCO_MAJOR_VERSION 0x1
1989 #define SCO_MINOR_VERSION 0x1
1999 asection
*seg
= now_seg
;
2000 subsegT subseg
= now_subseg
;
2001 Elf_Internal_Note i_note
;
2002 Elf_External_Note e_note
;
2003 asection
*note_secp
= (asection
*) NULL
;
2006 /* create the .note section */
2008 note_secp
= subseg_new (".note", 0);
2009 bfd_set_section_flags (stdoutput
,
2011 SEC_HAS_CONTENTS
| SEC_READONLY
);
2013 /* process the version string */
2016 i_note
.descsz
= 12; /* 12 descriptive bytes */
2017 i_note
.type
= NT_VERSION
; /* Contains a version string */
2019 p
= frag_more (sizeof (i_note
.namesz
));
2020 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2022 p
= frag_more (sizeof (i_note
.descsz
));
2023 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2025 p
= frag_more (sizeof (i_note
.type
));
2026 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2031 /* Note: this is the version number of the ELF we're representing */
2033 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2035 /* Here, we pick a magic number for ourselves (yes, I "registered"
2036 it with SCO. The bottom bit shows that we are compat with the
2039 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2041 /* If we knew (or cared) what the source language options were, we'd
2042 fill them in here. SCO has given us permission to ignore these
2043 and just set them to zero. */
2045 md_number_to_chars (p
, 0x0000, 4);
2047 frag_align (2, 0, 0);
2049 /* We probably can't restore the current segment, for there likely
2052 subseg_set (seg
, subseg
);
2056 #endif /* SCO_ELF */
2059 elf_separate_stab_sections ()
2061 #ifdef NEED_ECOFF_DEBUG
2062 return (!ECOFF_DEBUGGING
);
2069 elf_init_stab_section (seg
)
2072 #ifdef NEED_ECOFF_DEBUG
2073 if (!ECOFF_DEBUGGING
)
2075 obj_elf_init_stab_section (seg
);
2078 const struct format_ops elf_format_ops
=
2080 bfd_target_elf_flavour
,
2081 0, /* dfl_leading_underscore */
2082 1, /* emit_section_symbols */
2087 elf_frob_file_before_adjust
,
2088 elf_frob_file_after_relocs
,
2089 elf_s_get_size
, elf_s_set_size
,
2090 elf_s_get_align
, elf_s_set_align
,
2097 elf_copy_symbol_attributes
,
2098 #ifdef NEED_ECOFF_DEBUG
2099 ecoff_generate_asm_lineno
,
2102 0, /* generate_asm_lineno */
2103 0, /* process_stab */
2105 elf_separate_stab_sections
,
2106 elf_init_stab_section
,
2107 elf_sec_sym_ok_for_reloc
,
2109 #ifdef NEED_ECOFF_DEBUG
2112 0, /* ecoff_set_ext */
2114 elf_obj_read_begin_hook
,
2115 elf_obj_symbol_new_hook