1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2000
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 void elf_copy_symbol_attributes
PARAMS ((symbolS
*, symbolS
*));
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_symver
PARAMS ((int));
78 static void obj_elf_subsection
PARAMS ((int));
79 static void obj_elf_popsection
PARAMS ((int));
81 static const pseudo_typeS elf_pseudo_table
[] =
83 {"comm", obj_elf_common
, 0},
84 {"common", obj_elf_common
, 1},
85 {"ident", obj_elf_ident
, 0},
86 {"local", obj_elf_local
, 0},
87 {"previous", obj_elf_previous
, 0},
88 {"section", obj_elf_section
, 0},
89 {"section.s", obj_elf_section
, 0},
90 {"sect", obj_elf_section
, 0},
91 {"sect.s", obj_elf_section
, 0},
92 {"pushsection", obj_elf_section
, 1},
93 {"popsection", obj_elf_popsection
, 0},
94 {"size", obj_elf_size
, 0},
95 {"type", obj_elf_type
, 0},
96 {"version", obj_elf_version
, 0},
97 {"weak", obj_elf_weak
, 0},
99 /* These define symbol visibility. */
100 {"internal", obj_elf_visibility
, STV_INTERNAL
},
101 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
102 {"protected", obj_elf_visibility
, STV_PROTECTED
},
104 /* These are used for stabs-in-elf configurations. */
105 {"line", obj_elf_line
, 0},
107 /* This is a GNU extension to handle symbol versions. */
108 {"symver", obj_elf_symver
, 0},
110 /* A GNU extension to change subsection only. */
111 {"subsection", obj_elf_subsection
, 0},
113 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
114 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
115 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
117 /* These are used for dwarf. */
122 /* We need to trap the section changing calls to handle .previous. */
123 {"data", obj_elf_data
, 0},
124 {"text", obj_elf_text
, 0},
130 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
132 #ifdef NEED_ECOFF_DEBUG
133 /* COFF style debugging information for ECOFF. .ln is not used; .loc
135 { "def", ecoff_directive_def
, 0 },
136 { "dim", ecoff_directive_dim
, 0 },
137 { "endef", ecoff_directive_endef
, 0 },
138 { "file", ecoff_directive_file
, 0 },
139 { "scl", ecoff_directive_scl
, 0 },
140 { "tag", ecoff_directive_tag
, 0 },
141 { "val", ecoff_directive_val
, 0 },
143 /* COFF debugging requires pseudo-ops .size and .type, but ELF
144 already has meanings for those. We use .esize and .etype
145 instead. These are only generated by gcc anyhow. */
146 { "esize", ecoff_directive_size
, 0 },
147 { "etype", ecoff_directive_type
, 0 },
149 /* ECOFF specific debugging information. */
150 { "begin", ecoff_directive_begin
, 0 },
151 { "bend", ecoff_directive_bend
, 0 },
152 { "end", ecoff_directive_end
, 0 },
153 { "ent", ecoff_directive_ent
, 0 },
154 { "fmask", ecoff_directive_fmask
, 0 },
155 { "frame", ecoff_directive_frame
, 0 },
156 { "loc", ecoff_directive_loc
, 0 },
157 { "mask", ecoff_directive_mask
, 0 },
159 /* Other ECOFF directives. */
160 { "extern", ecoff_directive_extern
, 0 },
162 /* These are used on Irix. I don't know how to implement them. */
163 { "alias", s_ignore
, 0 },
164 { "bgnb", s_ignore
, 0 },
165 { "endb", s_ignore
, 0 },
166 { "lab", s_ignore
, 0 },
167 { "noalias", s_ignore
, 0 },
168 { "verstamp", s_ignore
, 0 },
169 { "vreg", s_ignore
, 0 },
172 {NULL
, NULL
, 0} /* end sentinel */
176 #include "aout/aout64.h"
178 /* This is called when the assembler starts. */
183 /* Add symbols for the known sections to the symbol table. */
184 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
185 TEXT_SECTION_NAME
)));
186 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
187 DATA_SECTION_NAME
)));
188 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
195 pop_insert (elf_pseudo_table
);
197 pop_insert (ecoff_debug_pseudo_table
);
204 return S_GET_SIZE (sym
);
208 elf_s_set_size (sym
, sz
)
212 S_SET_SIZE (sym
, sz
);
216 elf_s_get_align (sym
)
219 return S_GET_ALIGN (sym
);
223 elf_s_set_align (sym
, align
)
227 S_SET_ALIGN (sym
, align
);
231 elf_s_get_other (sym
)
234 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
238 elf_s_set_other (sym
, other
)
242 S_SET_OTHER (sym
, other
);
246 elf_copy_symbol_attributes (dest
, src
)
249 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
253 elf_sec_sym_ok_for_reloc (sec
)
256 return obj_sec_sym_ok_for_reloc (sec
);
265 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
266 symbol_set_frag (sym
, &zero_address_frag
);
267 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
269 if (symbol_rootP
!= sym
)
271 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
272 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
274 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
278 #ifdef NEED_ECOFF_DEBUG
284 obj_elf_common (is_common
)
294 if (flag_mri
&& is_common
)
300 name
= input_line_pointer
;
301 c
= get_symbol_end ();
302 /* just after name is now '\0' */
303 p
= input_line_pointer
;
306 if (*input_line_pointer
!= ',')
308 as_bad (_("Expected comma after symbol-name"));
309 ignore_rest_of_line ();
312 input_line_pointer
++; /* skip ',' */
313 if ((temp
= get_absolute_expression ()) < 0)
315 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
316 ignore_rest_of_line ();
321 symbolP
= symbol_find_or_make (name
);
323 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
325 as_bad (_("Ignoring attempt to re-define symbol"));
326 ignore_rest_of_line ();
329 if (S_GET_VALUE (symbolP
) != 0)
331 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
333 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
334 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
337 know (symbolP
->sy_frag
== &zero_address_frag
);
338 if (*input_line_pointer
!= ',')
343 input_line_pointer
++;
346 if (! have_align
|| *input_line_pointer
!= '"')
352 temp
= get_absolute_expression ();
356 as_warn (_("Common alignment negative; 0 assumed"));
359 if (symbol_get_obj (symbolP
)->local
)
368 old_subsec
= now_subseg
;
371 /* convert to a power of 2 alignment */
372 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
375 as_bad (_("Common alignment not a power of 2"));
376 ignore_rest_of_line ();
382 record_alignment (bss_section
, align
);
383 subseg_set (bss_section
, 0);
385 frag_align (align
, 0, 0);
386 if (S_GET_SEGMENT (symbolP
) == bss_section
)
387 symbol_get_frag (symbolP
)->fr_symbol
= 0;
388 symbol_set_frag (symbolP
, frag_now
);
389 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
390 (offsetT
) size
, (char *) 0);
392 S_SET_SIZE (symbolP
, size
);
393 S_SET_SEGMENT (symbolP
, bss_section
);
394 S_CLEAR_EXTERNAL (symbolP
);
395 subseg_set (old_sec
, old_subsec
);
400 S_SET_VALUE (symbolP
, (valueT
) size
);
401 S_SET_ALIGN (symbolP
, temp
);
402 S_SET_EXTERNAL (symbolP
);
403 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
408 input_line_pointer
++;
409 /* @@ Some use the dot, some don't. Can we get some consistency?? */
410 if (*input_line_pointer
== '.')
411 input_line_pointer
++;
412 /* @@ Some say data, some say bss. */
413 if (strncmp (input_line_pointer
, "bss\"", 4)
414 && strncmp (input_line_pointer
, "data\"", 5))
416 while (*--input_line_pointer
!= '"')
418 input_line_pointer
--;
419 goto bad_common_segment
;
421 while (*input_line_pointer
++ != '"')
423 goto allocate_common
;
426 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
428 demand_empty_rest_of_line ();
433 p
= input_line_pointer
;
434 while (*p
&& *p
!= '\n')
438 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
440 input_line_pointer
= p
;
441 ignore_rest_of_line ();
447 obj_elf_local (ignore
)
448 int ignore ATTRIBUTE_UNUSED
;
456 name
= input_line_pointer
;
457 c
= get_symbol_end ();
458 symbolP
= symbol_find_or_make (name
);
459 *input_line_pointer
= c
;
461 S_CLEAR_EXTERNAL (symbolP
);
462 symbol_get_obj (symbolP
)->local
= 1;
465 input_line_pointer
++;
467 if (*input_line_pointer
== '\n')
472 demand_empty_rest_of_line ();
476 obj_elf_weak (ignore
)
477 int ignore ATTRIBUTE_UNUSED
;
485 name
= input_line_pointer
;
486 c
= get_symbol_end ();
487 symbolP
= symbol_find_or_make (name
);
488 *input_line_pointer
= c
;
490 S_SET_WEAK (symbolP
);
491 symbol_get_obj (symbolP
)->local
= 1;
494 input_line_pointer
++;
496 if (*input_line_pointer
== '\n')
501 demand_empty_rest_of_line ();
505 obj_elf_visibility (visibility
)
512 elf_symbol_type
*elfsym
;
516 name
= input_line_pointer
;
517 c
= get_symbol_end ();
518 symbolP
= symbol_find_or_make (name
);
519 *input_line_pointer
= c
;
523 bfdsym
= symbol_get_bfdsym (symbolP
);
524 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
528 elfsym
->internal_elf_sym
.st_other
= visibility
;
532 input_line_pointer
++;
536 if (*input_line_pointer
== '\n')
542 demand_empty_rest_of_line ();
545 static segT previous_section
;
546 static int previous_subsection
;
550 struct section_stack
*next
;
552 int subseg
, prev_subseg
;
555 static struct section_stack
*section_stack
;
557 /* Handle the .section pseudo-op. This code supports two different
560 The first is found on Solaris, and looks like
561 .section ".sec1",#alloc,#execinstr,#write
562 Here the names after '#' are the SHF_* flags to turn on for the
563 section. I'm not sure how it determines the SHT_* type (BFD
564 doesn't really give us control over the type, anyhow).
566 The second format is found on UnixWare, and probably most SVR4
567 machines, and looks like
568 .section .sec1,"a",@progbits
569 The quoted string may contain any combination of a, w, x, and
570 represents the SHF_* flags to turn on for the section. The string
571 beginning with '@' can be progbits or nobits. There should be
572 other possibilities, but I don't know what they are. In any case,
573 BFD doesn't really let us set the section type. */
575 /* Certain named sections have particular defined types, listed on p.
577 struct special_section
584 static struct special_section
const special_sections
[] =
586 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
587 { ".comment", SHT_PROGBITS
, 0 },
588 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
589 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
590 { ".debug", SHT_PROGBITS
, 0 },
591 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
592 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
593 { ".line", SHT_PROGBITS
, 0 },
594 { ".note", SHT_NOTE
, 0 },
595 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
596 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
597 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
599 #ifdef ELF_TC_SPECIAL_SECTIONS
600 ELF_TC_SPECIAL_SECTIONS
604 /* The following section names are special, but they can not
605 reasonably appear in assembler code. Some of the attributes are
606 processor dependent. */
607 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
608 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
609 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
610 { ".got", SHT_PROGBITS
, 0 },
611 { ".hash", SHT_HASH
, SHF_ALLOC
},
612 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
613 { ".plt", SHT_PROGBITS
, 0 },
614 { ".shstrtab",SHT_STRTAB
, 0 },
615 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
616 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
623 obj_elf_change_section (name
, type
, attr
, push
)
625 int type
, attr
, push
;
632 #ifdef md_flush_pending_output
633 md_flush_pending_output ();
636 /* Switch to the section, creating it if necessary. */
639 struct section_stack
*elt
;
640 elt
= xmalloc (sizeof (struct section_stack
));
641 elt
->next
= section_stack
;
643 elt
->prev_seg
= previous_section
;
644 elt
->subseg
= now_subseg
;
645 elt
->prev_subseg
= previous_subsection
;
648 previous_section
= now_seg
;
649 previous_subsection
= now_subseg
;
651 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
652 sec
= subseg_new (name
, 0);
654 /* See if this is one of the special sections. */
655 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
656 if (strcmp (name
, special_sections
[i
].name
) == 0)
658 if (type
== SHT_NULL
)
659 type
= special_sections
[i
].type
;
660 else if (type
!= special_sections
[i
].type
)
664 as_warn (_("Setting incorrect section type for %s"), name
);
668 as_warn (_("Ignoring incorrect section type for %s"), name
);
669 type
= special_sections
[i
].type
;
672 if ((attr
&~ special_sections
[i
].attributes
) != 0
675 /* As a GNU extension, we permit a .note section to be
676 allocatable. If the linker sees an allocateable .note
677 section, it will create a PT_NOTE segment in the output
679 if (strcmp (name
, ".note") != 0
680 || attr
!= SHF_ALLOC
)
681 as_warn (_("Setting incorrect section attributes for %s"),
684 attr
|= special_sections
[i
].attributes
;
688 /* Convert ELF type and flags to BFD flags. */
690 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
691 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
692 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
693 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
694 #ifdef md_elf_section_flags
695 flags
= md_elf_section_flags (flags
, attr
, type
);
702 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
703 if (type
== SHT_NOBITS
)
704 seg_info (sec
)->bss
= 1;
706 bfd_set_section_flags (stdoutput
, sec
, flags
);
708 /* Add a symbol for this section to the symbol table. */
709 secsym
= symbol_find (name
);
711 symbol_set_bfdsym (secsym
, sec
->symbol
);
713 symbol_table_insert (section_symbol (sec
));
717 /* If section attributes are specified the second time we see a
718 particular section, then check that they are the same as we
719 saw the first time. */
720 if ((old_sec
->flags
^ flags
)
721 & (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
722 | SEC_EXCLUDE
| SEC_SORT_ENTRIES
))
723 as_warn (_("Ignoring changed section attributes for %s"), name
);
726 #ifdef md_elf_section_change_hook
727 md_elf_section_change_hook ();
732 obj_elf_parse_section_letters (str
, len
)
749 attr
|= SHF_EXECINSTR
;
753 char *bad_msg
= _("Unrecognized .section attribute: want a,w,x");
754 #ifdef md_elf_section_letter
755 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
761 as_warn ("%s", bad_msg
);
774 obj_elf_section_word (str
, len
)
778 if (len
== 5 && strncmp (str
, "write", 5) == 0)
780 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
782 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
783 return SHF_EXECINSTR
;
785 #ifdef md_elf_section_word
787 int md_attr
= md_elf_section_word (str
, len
);
793 as_warn (_("Unrecognized section attribute"));
798 obj_elf_section_type (str
, len
)
802 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
804 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
807 #ifdef md_elf_section_type
809 int md_type
= md_elf_section_type (str
, len
);
815 as_warn (_("Unrecognized section type"));
820 obj_elf_section (push
)
823 char *name
, *beg
, *end
;
824 int type
, attr
, dummy
;
831 #ifdef md_flush_pending_output
832 md_flush_pending_output ();
835 previous_section
= now_seg
;
836 previous_subsection
= now_subseg
;
838 s_mri_sect (&mri_type
);
840 #ifdef md_elf_section_change_hook
841 md_elf_section_change_hook ();
846 #endif /* ! defined (TC_I370) */
848 /* Get name of section. */
850 if (*input_line_pointer
== '"')
852 name
= demand_copy_C_string (&dummy
);
855 ignore_rest_of_line ();
861 end
= input_line_pointer
;
862 while (0 == strchr ("\n\t,; ", *end
))
864 if (end
== input_line_pointer
)
866 as_warn (_("Missing section name"));
867 ignore_rest_of_line ();
871 name
= xmalloc (end
- input_line_pointer
+ 1);
872 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
873 name
[end
- input_line_pointer
] = '\0';
874 input_line_pointer
= end
;
881 if (*input_line_pointer
== ',')
883 /* Skip the comma. */
884 ++input_line_pointer
;
887 if (*input_line_pointer
== '"')
889 beg
= demand_copy_C_string (&dummy
);
892 ignore_rest_of_line ();
895 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
898 if (*input_line_pointer
== ',')
901 ++input_line_pointer
;
903 c
= *input_line_pointer
;
906 beg
= demand_copy_C_string (&dummy
);
909 ignore_rest_of_line ();
912 type
= obj_elf_section_type (beg
, strlen (beg
));
914 else if (c
== '@' || c
== '%')
916 beg
= ++input_line_pointer
;
917 c
= get_symbol_end ();
918 *input_line_pointer
= c
;
919 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
930 if (*input_line_pointer
!= '#')
932 as_warn (_("Bad .section directive - character following name is not '#'"));
933 ignore_rest_of_line ();
936 beg
= ++input_line_pointer
;
937 c
= get_symbol_end ();
938 *input_line_pointer
= c
;
940 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
944 while (*input_line_pointer
++ == ',');
945 --input_line_pointer
;
949 demand_empty_rest_of_line ();
951 obj_elf_change_section (name
, type
, attr
, push
);
954 /* Change to the .data section. */
960 #ifdef md_flush_pending_output
961 md_flush_pending_output ();
964 previous_section
= now_seg
;
965 previous_subsection
= now_subseg
;
968 #ifdef md_elf_section_change_hook
969 md_elf_section_change_hook ();
973 /* Change to the .text section. */
979 #ifdef md_flush_pending_output
980 md_flush_pending_output ();
983 previous_section
= now_seg
;
984 previous_subsection
= now_subseg
;
987 #ifdef md_elf_section_change_hook
988 md_elf_section_change_hook ();
993 obj_elf_subsection (ignore
)
994 int ignore ATTRIBUTE_UNUSED
;
998 #ifdef md_flush_pending_output
999 md_flush_pending_output ();
1002 previous_section
= now_seg
;
1003 previous_subsection
= now_subseg
;
1005 temp
= get_absolute_expression ();
1006 subseg_set (now_seg
, (subsegT
) temp
);
1007 demand_empty_rest_of_line ();
1009 #ifdef md_elf_section_change_hook
1010 md_elf_section_change_hook ();
1014 /* This can be called from the processor backends if they change
1018 obj_elf_section_change_hook ()
1020 previous_section
= now_seg
;
1021 previous_subsection
= now_subseg
;
1025 obj_elf_previous (ignore
)
1026 int ignore ATTRIBUTE_UNUSED
;
1031 if (previous_section
== 0)
1033 as_bad (_(".previous without corresponding .section; ignored"));
1037 #ifdef md_flush_pending_output
1038 md_flush_pending_output ();
1041 new_section
= previous_section
;
1042 new_subsection
= previous_subsection
;
1043 previous_section
= now_seg
;
1044 previous_subsection
= now_subseg
;
1045 subseg_set (new_section
, new_subsection
);
1047 #ifdef md_elf_section_change_hook
1048 md_elf_section_change_hook ();
1053 obj_elf_popsection (xxx
)
1054 int xxx ATTRIBUTE_UNUSED
;
1056 struct section_stack
*top
= section_stack
;
1060 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1064 #ifdef md_flush_pending_output
1065 md_flush_pending_output ();
1068 section_stack
= top
->next
;
1069 previous_section
= top
->prev_seg
;
1070 previous_subsection
= top
->prev_subseg
;
1071 subseg_set (top
->seg
, top
->subseg
);
1074 #ifdef md_elf_section_change_hook
1075 md_elf_section_change_hook ();
1080 obj_elf_line (ignore
)
1081 int ignore ATTRIBUTE_UNUSED
;
1083 /* Assume delimiter is part of expression. BSD4.2 as fails with
1084 delightful bug, so we are not being incompatible here. */
1085 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1086 demand_empty_rest_of_line ();
1089 /* This handles the .symver pseudo-op, which is used to specify a
1090 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1091 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1092 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1093 with the same value as the symbol NAME. */
1096 obj_elf_symver (ignore
)
1097 int ignore ATTRIBUTE_UNUSED
;
1103 name
= input_line_pointer
;
1104 c
= get_symbol_end ();
1106 sym
= symbol_find_or_make (name
);
1108 *input_line_pointer
= c
;
1111 if (*input_line_pointer
!= ',')
1113 as_bad (_("expected comma after name in .symver"));
1114 ignore_rest_of_line ();
1118 ++input_line_pointer
;
1119 name
= input_line_pointer
;
1122 c
= get_symbol_end ();
1123 if (c
!= ELF_VER_CHR
)
1125 *input_line_pointer
++ = c
;
1128 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1132 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1134 *input_line_pointer
= c
;
1136 p
= strchr (symbol_get_obj (sym
)->versioned_name
, ELF_VER_CHR
);
1138 rp
= strrchr (p
, ELF_VER_CHR
);
1139 if (!p
|| p
[1] == '\0' || rp
[1] == '\0')
1141 as_bad (_("missing version name in `%s' for symbol `%s'"),
1142 symbol_get_obj (sym
)->versioned_name
,
1144 ignore_rest_of_line ();
1150 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1152 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1153 name
, symbol_get_obj (sym
)->versioned_name
,
1155 ignore_rest_of_line ();
1159 *input_line_pointer
= c
;
1162 demand_empty_rest_of_line ();
1165 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1166 to the linker the hierarchy in which a particular table resides. The
1167 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1170 obj_elf_vtable_inherit (ignore
)
1171 int ignore ATTRIBUTE_UNUSED
;
1173 char *cname
, *pname
;
1174 symbolS
*csym
, *psym
;
1177 if (*input_line_pointer
== '#')
1178 ++input_line_pointer
;
1180 cname
= input_line_pointer
;
1181 c
= get_symbol_end ();
1182 csym
= symbol_find (cname
);
1184 /* GCFIXME: should check that we don't have two .vtable_inherits for
1185 the same child symbol. Also, we can currently only do this if the
1186 child symbol is already exists and is placed in a fragment. */
1188 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1190 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1195 *input_line_pointer
= c
;
1198 if (*input_line_pointer
!= ',')
1200 as_bad ("expected comma after name in .vtable_inherit");
1201 ignore_rest_of_line ();
1205 ++input_line_pointer
;
1208 if (*input_line_pointer
== '#')
1209 ++input_line_pointer
;
1211 if (input_line_pointer
[0] == '0'
1212 && (input_line_pointer
[1] == '\0'
1213 || isspace ((unsigned char) input_line_pointer
[1])))
1215 psym
= section_symbol (absolute_section
);
1216 ++input_line_pointer
;
1220 pname
= input_line_pointer
;
1221 c
= get_symbol_end ();
1222 psym
= symbol_find_or_make (pname
);
1223 *input_line_pointer
= c
;
1226 demand_empty_rest_of_line ();
1231 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1232 return fix_new (symbol_get_frag (csym
),
1233 symbol_get_value_expression (csym
)->X_add_number
,
1234 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1237 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1238 to the linker that a vtable slot was used. The syntax is
1239 ".vtable_entry tablename, offset". */
1242 obj_elf_vtable_entry (ignore
)
1243 int ignore ATTRIBUTE_UNUSED
;
1250 if (*input_line_pointer
== '#')
1251 ++input_line_pointer
;
1253 name
= input_line_pointer
;
1254 c
= get_symbol_end ();
1255 sym
= symbol_find_or_make (name
);
1256 *input_line_pointer
= c
;
1259 if (*input_line_pointer
!= ',')
1261 as_bad ("expected comma after name in .vtable_entry");
1262 ignore_rest_of_line ();
1266 ++input_line_pointer
;
1267 if (*input_line_pointer
== '#')
1268 ++input_line_pointer
;
1270 offset
= get_absolute_expression ();
1272 demand_empty_rest_of_line ();
1274 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1275 BFD_RELOC_VTABLE_ENTRY
);
1279 elf_obj_read_begin_hook ()
1281 #ifdef NEED_ECOFF_DEBUG
1282 if (ECOFF_DEBUGGING
)
1283 ecoff_read_begin_hook ();
1288 elf_obj_symbol_new_hook (symbolP
)
1291 struct elf_obj_sy
*sy_obj
;
1293 sy_obj
= symbol_get_obj (symbolP
);
1294 sy_obj
->size
= NULL
;
1295 sy_obj
->versioned_name
= NULL
;
1297 #ifdef NEED_ECOFF_DEBUG
1298 if (ECOFF_DEBUGGING
)
1299 ecoff_symbol_new_hook (symbolP
);
1304 obj_elf_version (ignore
)
1305 int ignore ATTRIBUTE_UNUSED
;
1311 asection
*seg
= now_seg
;
1312 subsegT subseg
= now_subseg
;
1313 Elf_Internal_Note i_note
;
1314 Elf_External_Note e_note
;
1315 asection
*note_secp
= (asection
*) NULL
;
1319 if (*input_line_pointer
== '\"')
1321 ++input_line_pointer
; /* -> 1st char of string. */
1322 name
= input_line_pointer
;
1324 while (is_a_char (c
= next_char_of_string ()))
1326 c
= *input_line_pointer
;
1327 *input_line_pointer
= '\0';
1328 *(input_line_pointer
- 1) = '\0';
1329 *input_line_pointer
= c
;
1331 /* create the .note section */
1333 note_secp
= subseg_new (".note", 0);
1334 bfd_set_section_flags (stdoutput
,
1336 SEC_HAS_CONTENTS
| SEC_READONLY
);
1338 /* process the version string */
1340 len
= strlen (name
);
1342 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1343 i_note
.descsz
= 0; /* no description */
1344 i_note
.type
= NT_VERSION
;
1345 p
= frag_more (sizeof (e_note
.namesz
));
1346 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1347 p
= frag_more (sizeof (e_note
.descsz
));
1348 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1349 p
= frag_more (sizeof (e_note
.type
));
1350 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1352 for (i
= 0; i
< len
; i
++)
1356 FRAG_APPEND_1_CHAR (ch
);
1359 frag_align (2, 0, 0);
1361 subseg_set (seg
, subseg
);
1365 as_bad (_("Expected quoted string"));
1367 demand_empty_rest_of_line ();
1371 obj_elf_size (ignore
)
1372 int ignore ATTRIBUTE_UNUSED
;
1374 char *name
= input_line_pointer
;
1375 char c
= get_symbol_end ();
1380 p
= input_line_pointer
;
1383 if (*input_line_pointer
!= ',')
1386 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1388 ignore_rest_of_line ();
1391 input_line_pointer
++;
1393 if (exp
.X_op
== O_absent
)
1395 as_bad (_("missing expression in .size directive"));
1396 exp
.X_op
= O_constant
;
1397 exp
.X_add_number
= 0;
1400 sym
= symbol_find_or_make (name
);
1402 if (exp
.X_op
== O_constant
)
1403 S_SET_SIZE (sym
, exp
.X_add_number
);
1406 symbol_get_obj (sym
)->size
=
1407 (expressionS
*) xmalloc (sizeof (expressionS
));
1408 *symbol_get_obj (sym
)->size
= exp
;
1410 demand_empty_rest_of_line ();
1413 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1414 There are five syntaxes:
1416 The first (used on Solaris) is
1418 The second (used on UnixWare) is
1420 The third (reportedly to be used on Irix 6.0) is
1422 The fourth (used on NetBSD/Arm and Linux/ARM) is
1424 The fifth (used on SVR4/860) is
1425 .type SYM,"function"
1429 obj_elf_type (ignore
)
1430 int ignore ATTRIBUTE_UNUSED
;
1435 const char *typename
;
1437 elf_symbol_type
*elfsym
;
1439 name
= input_line_pointer
;
1440 c
= get_symbol_end ();
1441 sym
= symbol_find_or_make (name
);
1442 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1443 *input_line_pointer
= c
;
1446 if (*input_line_pointer
== ',')
1447 ++input_line_pointer
;
1450 if ( *input_line_pointer
== '#'
1451 || *input_line_pointer
== '@'
1452 || *input_line_pointer
== '"'
1453 || *input_line_pointer
== '%')
1454 ++input_line_pointer
;
1456 typename
= input_line_pointer
;
1457 c
= get_symbol_end ();
1460 if (strcmp (typename
, "function") == 0
1461 || strcmp (typename
, "STT_FUNC") == 0)
1462 type
= BSF_FUNCTION
;
1463 else if (strcmp (typename
, "object") == 0
1464 || strcmp (typename
, "STT_OBJECT") == 0)
1466 #ifdef md_elf_symbol_type
1467 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1471 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1473 *input_line_pointer
= c
;
1475 if (*input_line_pointer
== '"')
1476 ++input_line_pointer
;
1478 elfsym
->symbol
.flags
|= type
;
1480 demand_empty_rest_of_line ();
1484 obj_elf_ident (ignore
)
1485 int ignore ATTRIBUTE_UNUSED
;
1487 static segT comment_section
;
1488 segT old_section
= now_seg
;
1489 int old_subsection
= now_subseg
;
1491 #ifdef md_flush_pending_output
1492 md_flush_pending_output ();
1495 if (!comment_section
)
1498 comment_section
= subseg_new (".comment", 0);
1499 bfd_set_section_flags (stdoutput
, comment_section
,
1500 SEC_READONLY
| SEC_HAS_CONTENTS
);
1505 subseg_set (comment_section
, 0);
1507 subseg_set (old_section
, old_subsection
);
1510 #ifdef INIT_STAB_SECTION
1512 /* The first entry in a .stabs section is special. */
1515 obj_elf_init_stab_section (seg
)
1521 unsigned int stroff
;
1523 /* Force the section to align to a longword boundary. Without this,
1524 UnixWare ar crashes. */
1525 bfd_set_section_alignment (stdoutput
, seg
, 2);
1527 /* Make space for this first symbol. */
1531 as_where (&file
, (unsigned int *) NULL
);
1532 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1533 strcpy (stabstr_name
, segment_name (seg
));
1534 strcat (stabstr_name
, "str");
1535 stroff
= get_stab_string_offset (file
, stabstr_name
);
1537 md_number_to_chars (p
, stroff
, 4);
1538 seg_info (seg
)->stabu
.p
= p
;
1543 /* Fill in the counts in the first entry in a .stabs section. */
1546 adjust_stab_sections (abfd
, sec
, xxx
)
1549 PTR xxx ATTRIBUTE_UNUSED
;
1556 if (strncmp (".stab", sec
->name
, 5))
1558 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1561 name
= (char *) alloca (strlen (sec
->name
) + 4);
1562 strcpy (name
, sec
->name
);
1563 strcat (name
, "str");
1564 strsec
= bfd_get_section_by_name (abfd
, name
);
1566 strsz
= bfd_section_size (abfd
, strsec
);
1569 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1571 p
= seg_info (sec
)->stabu
.p
;
1574 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1575 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1578 #ifdef NEED_ECOFF_DEBUG
1580 /* This function is called by the ECOFF code. It is supposed to
1581 record the external symbol information so that the backend can
1582 write it out correctly. The ELF backend doesn't actually handle
1583 this at the moment, so we do it ourselves. We save the information
1587 elf_ecoff_set_ext (sym
, ext
)
1589 struct ecoff_extr
*ext
;
1591 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1594 /* This function is called by bfd_ecoff_debug_externals. It is
1595 supposed to *EXT to the external symbol information, and return
1596 whether the symbol should be used at all. */
1599 elf_get_extr (sym
, ext
)
1603 if (sym
->udata
.p
== NULL
)
1605 *ext
= *(EXTR
*) sym
->udata
.p
;
1609 /* This function is called by bfd_ecoff_debug_externals. It has
1610 nothing to do for ELF. */
1614 elf_set_index (sym
, indx
)
1615 asymbol
*sym ATTRIBUTE_UNUSED
;
1616 bfd_size_type indx ATTRIBUTE_UNUSED
;
1620 #endif /* NEED_ECOFF_DEBUG */
1623 elf_frob_symbol (symp
, puntp
)
1627 struct elf_obj_sy
*sy_obj
;
1629 #ifdef NEED_ECOFF_DEBUG
1630 if (ECOFF_DEBUGGING
)
1631 ecoff_frob_symbol (symp
);
1634 sy_obj
= symbol_get_obj (symp
);
1636 if (sy_obj
->size
!= NULL
)
1638 switch (sy_obj
->size
->X_op
)
1642 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1643 + sy_obj
->size
->X_add_number
1644 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1648 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1649 + sy_obj
->size
->X_add_number
));
1652 as_bad (_(".size expression too complicated to fix up"));
1655 free (sy_obj
->size
);
1656 sy_obj
->size
= NULL
;
1659 if (sy_obj
->versioned_name
!= NULL
)
1663 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1666 /* This symbol was given a new name with the .symver directive.
1668 If this is an external reference, just rename the symbol to
1669 include the version string. This will make the relocs be
1670 against the correct versioned symbol.
1672 If this is a definition, add an alias. FIXME: Using an alias
1673 will permit the debugging information to refer to the right
1674 symbol. However, it's not clear whether it is the best
1677 if (! S_IS_DEFINED (symp
))
1679 /* Verify that the name isn't using the @@ syntax--this is
1680 reserved for definitions of the default version to link
1682 if (p
[1] == ELF_VER_CHR
)
1684 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1685 sy_obj
->versioned_name
);
1688 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1692 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1696 /* The @@@ syntax is a special case. It renames the
1697 symbol name to versioned_name with one `@' removed. */
1698 l
= strlen (&p
[3]) + 1;
1699 memmove (&p
[2], &p
[3], l
);
1700 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1706 /* FIXME: Creating a new symbol here is risky. We're
1707 in the final loop over the symbol table. We can
1708 get away with it only because the symbol goes to
1709 the end of the list, where the loop will still see
1710 it. It would probably be better to do this in
1711 obj_frob_file_before_adjust. */
1713 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1715 /* Now we act as though we saw symp2 = sym. */
1717 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1719 /* Subtracting out the frag address here is a hack
1720 because we are in the middle of the final loop. */
1723 - symbol_get_frag (symp
)->fr_address
));
1725 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1727 /* This will copy over the size information. */
1728 copy_symbol_attributes (symp2
, symp
);
1730 if (S_IS_WEAK (symp
))
1733 if (S_IS_EXTERNAL (symp
))
1734 S_SET_EXTERNAL (symp2
);
1739 /* Double check weak symbols. */
1740 if (S_IS_WEAK (symp
))
1742 if (S_IS_COMMON (symp
))
1743 as_bad (_("Symbol `%s' can not be both weak and common"),
1748 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1749 any undefined non-function symbol to STT_OBJECT. We try to be
1750 compatible, since newer Irix 5 and 6 linkers care. However, we
1751 only set undefined symbols to be STT_OBJECT if we are on Irix,
1752 because that is the only time gcc will generate the necessary
1753 .global directives to mark functions. */
1755 if (S_IS_COMMON (symp
))
1756 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1758 if (strstr (TARGET_OS
, "irix") != NULL
1759 && ! S_IS_DEFINED (symp
)
1760 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1761 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1765 /* If TC_PPC is defined, we used to force the type of a symbol to be
1766 BSF_OBJECT if it was otherwise unset. This was required by some
1767 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1768 that this is no longer needed, so it is now commented out. */
1769 if ((symbol_get_bfdsym (symp
)->flags
1770 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1771 && S_IS_DEFINED (symp
))
1772 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1779 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1781 #ifdef elf_tc_final_processing
1782 elf_tc_final_processing ();
1786 /* It removes any unneeded versioned symbols from the symbol table. */
1789 elf_frob_file_before_adjust ()
1795 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1796 if (symbol_get_obj (symp
)->versioned_name
)
1798 if (!S_IS_DEFINED (symp
))
1802 /* The @@@ syntax is a special case. If the symbol is
1803 not defined, 2 `@'s will be removed from the
1806 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1809 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1811 size_t l
= strlen (&p
[3]) + 1;
1812 memmove (&p
[1], &p
[3], l
);
1814 if (symbol_used_p (symp
) == 0
1815 && symbol_used_in_reloc_p (symp
) == 0)
1816 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1822 /* It is required that we let write_relocs have the opportunity to
1823 optimize away fixups before output has begun, since it is possible
1824 to eliminate all fixups for a section and thus we never should
1825 have generated the relocation section. */
1828 elf_frob_file_after_relocs ()
1830 #ifdef NEED_ECOFF_DEBUG
1831 if (ECOFF_DEBUGGING
)
1832 /* Generate the ECOFF debugging information. */
1834 const struct ecoff_debug_swap
*debug_swap
;
1835 struct ecoff_debug_info debug
;
1840 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1841 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1842 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1844 /* Set up the pointers in debug. */
1845 #define SET(ptr, offset, type) \
1846 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1848 SET (line
, cbLineOffset
, unsigned char *);
1849 SET (external_dnr
, cbDnOffset
, PTR
);
1850 SET (external_pdr
, cbPdOffset
, PTR
);
1851 SET (external_sym
, cbSymOffset
, PTR
);
1852 SET (external_opt
, cbOptOffset
, PTR
);
1853 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1854 SET (ss
, cbSsOffset
, char *);
1855 SET (external_fdr
, cbFdOffset
, PTR
);
1856 SET (external_rfd
, cbRfdOffset
, PTR
);
1857 /* ssext and external_ext are set up just below. */
1861 /* Set up the external symbols. */
1862 debug
.ssext
= debug
.ssext_end
= NULL
;
1863 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1864 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1865 elf_get_extr
, elf_set_index
))
1866 as_fatal (_("Failed to set up debugging information: %s"),
1867 bfd_errmsg (bfd_get_error ()));
1869 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1870 assert (sec
!= NULL
);
1872 know (stdoutput
->output_has_begun
== false);
1874 /* We set the size of the section, call bfd_set_section_contents
1875 to force the ELF backend to allocate a file position, and then
1876 write out the data. FIXME: Is this really the best way to do
1878 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1880 /* Pass BUF to bfd_set_section_contents because this will
1881 eventually become a call to fwrite, and ISO C prohibits
1882 passing a NULL pointer to a stdio function even if the
1883 pointer will not be used. */
1884 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
1885 (file_ptr
) 0, (bfd_size_type
) 0))
1886 as_fatal (_("Can't start writing .mdebug section: %s"),
1887 bfd_errmsg (bfd_get_error ()));
1889 know (stdoutput
->output_has_begun
== true);
1890 know (sec
->filepos
!= 0);
1892 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1894 as_fatal (_("Could not write .mdebug section: %s"),
1895 bfd_errmsg (bfd_get_error ()));
1897 #endif /* NEED_ECOFF_DEBUG */
1902 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1903 SCO specific identifier in the .notes section to satisfy the SCO
1906 This looks more complicated than it really is. As opposed to the
1907 "obvious" solution, this should handle the cross dev cases
1908 correctly. (i.e, hosting on a 64 bit big endian processor, but
1909 generating SCO Elf code) Efficiency isn't a concern, as there
1910 should be exactly one of these sections per object module.
1912 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1915 int_32 namesz = 4 ; Name size
1916 int_32 descsz = 12 ; Descriptive information
1918 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1919 int_32 version = (major ver # << 16) | version of tools ;
1920 int_32 source = (tool_id << 16 ) | 1 ;
1921 int_32 info = 0 ; These are set by the SCO tools, but we
1922 don't know enough about the source
1923 environment to set them. SCO ld currently
1924 ignores them, and recommends we set them
1927 #define SCO_MAJOR_VERSION 0x1
1928 #define SCO_MINOR_VERSION 0x1
1938 asection
*seg
= now_seg
;
1939 subsegT subseg
= now_subseg
;
1940 Elf_Internal_Note i_note
;
1941 Elf_External_Note e_note
;
1942 asection
*note_secp
= (asection
*) NULL
;
1945 /* create the .note section */
1947 note_secp
= subseg_new (".note", 0);
1948 bfd_set_section_flags (stdoutput
,
1950 SEC_HAS_CONTENTS
| SEC_READONLY
);
1952 /* process the version string */
1955 i_note
.descsz
= 12; /* 12 descriptive bytes */
1956 i_note
.type
= NT_VERSION
; /* Contains a version string */
1958 p
= frag_more (sizeof (i_note
.namesz
));
1959 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1961 p
= frag_more (sizeof (i_note
.descsz
));
1962 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1964 p
= frag_more (sizeof (i_note
.type
));
1965 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1970 /* Note: this is the version number of the ELF we're representing */
1972 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1974 /* Here, we pick a magic number for ourselves (yes, I "registered"
1975 it with SCO. The bottom bit shows that we are compat with the
1978 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1980 /* If we knew (or cared) what the source language options were, we'd
1981 fill them in here. SCO has given us permission to ignore these
1982 and just set them to zero. */
1984 md_number_to_chars (p
, 0x0000, 4);
1986 frag_align (2, 0, 0);
1988 /* We probably can't restore the current segment, for there likely
1991 subseg_set (seg
, subseg
);
1995 #endif /* SCO_ELF */
1998 elf_separate_stab_sections ()
2000 #ifdef NEED_ECOFF_DEBUG
2001 return (!ECOFF_DEBUGGING
);
2008 elf_init_stab_section (seg
)
2011 #ifdef NEED_ECOFF_DEBUG
2012 if (!ECOFF_DEBUGGING
)
2014 obj_elf_init_stab_section (seg
);
2017 const struct format_ops elf_format_ops
=
2019 bfd_target_elf_flavour
,
2020 0, /* dfl_leading_underscore */
2021 1, /* emit_section_symbols */
2026 elf_frob_file_before_adjust
,
2027 elf_frob_file_after_relocs
,
2028 elf_s_get_size
, elf_s_set_size
,
2029 elf_s_get_align
, elf_s_set_align
,
2036 elf_copy_symbol_attributes
,
2037 #ifdef NEED_ECOFF_DEBUG
2038 ecoff_generate_asm_lineno
,
2041 0, /* generate_asm_lineno */
2042 0, /* process_stab */
2044 elf_separate_stab_sections
,
2045 elf_init_stab_section
,
2046 elf_sec_sym_ok_for_reloc
,
2048 #ifdef NEED_ECOFF_DEBUG
2051 0, /* ecoff_set_ext */
2053 elf_obj_read_begin_hook
,
2054 elf_obj_symbol_new_hook