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_change_section
PARAMS ((char *, int, int, int, int));
77 static int obj_elf_parse_section_letters
PARAMS ((char *, size_t));
78 static int obj_elf_section_word
PARAMS ((char *, size_t));
79 static int obj_elf_section_type
PARAMS ((char *, size_t));
80 static void obj_elf_symver
PARAMS ((int));
81 static void obj_elf_subsection
PARAMS ((int));
82 static void obj_elf_popsection
PARAMS ((int));
84 static const pseudo_typeS elf_pseudo_table
[] =
86 {"comm", obj_elf_common
, 0},
87 {"common", obj_elf_common
, 1},
88 {"ident", obj_elf_ident
, 0},
89 {"local", obj_elf_local
, 0},
90 {"previous", obj_elf_previous
, 0},
91 {"section", obj_elf_section
, 0},
92 {"section.s", obj_elf_section
, 0},
93 {"sect", obj_elf_section
, 0},
94 {"sect.s", obj_elf_section
, 0},
95 {"pushsection", obj_elf_section
, 1},
96 {"popsection", obj_elf_popsection
, 0},
97 {"size", obj_elf_size
, 0},
98 {"type", obj_elf_type
, 0},
99 {"version", obj_elf_version
, 0},
100 {"weak", obj_elf_weak
, 0},
102 /* These define symbol visibility. */
103 {"internal", obj_elf_visibility
, STV_INTERNAL
},
104 {"hidden", obj_elf_visibility
, STV_HIDDEN
},
105 {"protected", obj_elf_visibility
, STV_PROTECTED
},
107 /* These are used for stabs-in-elf configurations. */
108 {"line", obj_elf_line
, 0},
110 /* This is a GNU extension to handle symbol versions. */
111 {"symver", obj_elf_symver
, 0},
113 /* A GNU extension to change subsection only. */
114 {"subsection", obj_elf_subsection
, 0},
116 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
117 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit
, 0},
118 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry
, 0},
120 /* These are used for dwarf. */
125 /* We need to trap the section changing calls to handle .previous. */
126 {"data", obj_elf_data
, 0},
127 {"text", obj_elf_text
, 0},
133 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
135 #ifdef NEED_ECOFF_DEBUG
136 /* COFF style debugging information for ECOFF. .ln is not used; .loc
138 { "def", ecoff_directive_def
, 0 },
139 { "dim", ecoff_directive_dim
, 0 },
140 { "endef", ecoff_directive_endef
, 0 },
141 { "file", ecoff_directive_file
, 0 },
142 { "scl", ecoff_directive_scl
, 0 },
143 { "tag", ecoff_directive_tag
, 0 },
144 { "val", ecoff_directive_val
, 0 },
146 /* COFF debugging requires pseudo-ops .size and .type, but ELF
147 already has meanings for those. We use .esize and .etype
148 instead. These are only generated by gcc anyhow. */
149 { "esize", ecoff_directive_size
, 0 },
150 { "etype", ecoff_directive_type
, 0 },
152 /* ECOFF specific debugging information. */
153 { "begin", ecoff_directive_begin
, 0 },
154 { "bend", ecoff_directive_bend
, 0 },
155 { "end", ecoff_directive_end
, 0 },
156 { "ent", ecoff_directive_ent
, 0 },
157 { "fmask", ecoff_directive_fmask
, 0 },
158 { "frame", ecoff_directive_frame
, 0 },
159 { "loc", ecoff_directive_loc
, 0 },
160 { "mask", ecoff_directive_mask
, 0 },
162 /* Other ECOFF directives. */
163 { "extern", ecoff_directive_extern
, 0 },
165 /* These are used on Irix. I don't know how to implement them. */
166 { "alias", s_ignore
, 0 },
167 { "bgnb", s_ignore
, 0 },
168 { "endb", s_ignore
, 0 },
169 { "lab", s_ignore
, 0 },
170 { "noalias", s_ignore
, 0 },
171 { "verstamp", s_ignore
, 0 },
172 { "vreg", s_ignore
, 0 },
175 {NULL
, NULL
, 0} /* end sentinel */
179 #include "aout/aout64.h"
181 /* This is called when the assembler starts. */
186 /* Add symbols for the known sections to the symbol table. */
187 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
188 TEXT_SECTION_NAME
)));
189 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
190 DATA_SECTION_NAME
)));
191 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
198 pop_insert (elf_pseudo_table
);
200 pop_insert (ecoff_debug_pseudo_table
);
207 return S_GET_SIZE (sym
);
211 elf_s_set_size (sym
, sz
)
215 S_SET_SIZE (sym
, sz
);
219 elf_s_get_align (sym
)
222 return S_GET_ALIGN (sym
);
226 elf_s_set_align (sym
, align
)
230 S_SET_ALIGN (sym
, align
);
234 elf_s_get_other (sym
)
237 return elf_symbol (symbol_get_bfdsym (sym
))->internal_elf_sym
.st_other
;
241 elf_s_set_other (sym
, other
)
245 S_SET_OTHER (sym
, other
);
249 elf_sec_sym_ok_for_reloc (sec
)
252 return obj_sec_sym_ok_for_reloc (sec
);
261 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
262 symbol_set_frag (sym
, &zero_address_frag
);
263 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
265 if (symbol_rootP
!= sym
)
267 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
268 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
270 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
274 #ifdef NEED_ECOFF_DEBUG
280 obj_elf_common (is_common
)
290 if (flag_mri
&& is_common
)
296 name
= input_line_pointer
;
297 c
= get_symbol_end ();
298 /* just after name is now '\0' */
299 p
= input_line_pointer
;
302 if (*input_line_pointer
!= ',')
304 as_bad (_("Expected comma after symbol-name"));
305 ignore_rest_of_line ();
308 input_line_pointer
++; /* skip ',' */
309 if ((temp
= get_absolute_expression ()) < 0)
311 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
312 ignore_rest_of_line ();
317 symbolP
= symbol_find_or_make (name
);
319 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
321 as_bad (_("Ignoring attempt to re-define symbol"));
322 ignore_rest_of_line ();
325 if (S_GET_VALUE (symbolP
) != 0)
327 if (S_GET_VALUE (symbolP
) != (valueT
) size
)
329 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
330 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
333 know (symbolP
->sy_frag
== &zero_address_frag
);
334 if (*input_line_pointer
!= ',')
339 input_line_pointer
++;
342 if (! have_align
|| *input_line_pointer
!= '"')
348 temp
= get_absolute_expression ();
352 as_warn (_("Common alignment negative; 0 assumed"));
355 if (symbol_get_obj (symbolP
)->local
)
364 old_subsec
= now_subseg
;
367 /* convert to a power of 2 alignment */
368 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
371 as_bad (_("Common alignment not a power of 2"));
372 ignore_rest_of_line ();
378 record_alignment (bss_section
, align
);
379 subseg_set (bss_section
, 0);
381 frag_align (align
, 0, 0);
382 if (S_GET_SEGMENT (symbolP
) == bss_section
)
383 symbol_get_frag (symbolP
)->fr_symbol
= 0;
384 symbol_set_frag (symbolP
, frag_now
);
385 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
386 (offsetT
) size
, (char *) 0);
388 S_SET_SIZE (symbolP
, size
);
389 S_SET_SEGMENT (symbolP
, bss_section
);
390 S_CLEAR_EXTERNAL (symbolP
);
391 subseg_set (old_sec
, old_subsec
);
396 S_SET_VALUE (symbolP
, (valueT
) size
);
397 S_SET_ALIGN (symbolP
, temp
);
398 S_SET_EXTERNAL (symbolP
);
399 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
404 input_line_pointer
++;
405 /* @@ Some use the dot, some don't. Can we get some consistency?? */
406 if (*input_line_pointer
== '.')
407 input_line_pointer
++;
408 /* @@ Some say data, some say bss. */
409 if (strncmp (input_line_pointer
, "bss\"", 4)
410 && strncmp (input_line_pointer
, "data\"", 5))
412 while (*--input_line_pointer
!= '"')
414 input_line_pointer
--;
415 goto bad_common_segment
;
417 while (*input_line_pointer
++ != '"')
419 goto allocate_common
;
422 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
424 demand_empty_rest_of_line ();
429 p
= input_line_pointer
;
430 while (*p
&& *p
!= '\n')
434 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
436 input_line_pointer
= p
;
437 ignore_rest_of_line ();
443 obj_elf_local (ignore
)
444 int ignore ATTRIBUTE_UNUSED
;
452 name
= input_line_pointer
;
453 c
= get_symbol_end ();
454 symbolP
= symbol_find_or_make (name
);
455 *input_line_pointer
= c
;
457 S_CLEAR_EXTERNAL (symbolP
);
458 symbol_get_obj (symbolP
)->local
= 1;
461 input_line_pointer
++;
463 if (*input_line_pointer
== '\n')
468 demand_empty_rest_of_line ();
472 obj_elf_weak (ignore
)
473 int ignore ATTRIBUTE_UNUSED
;
481 name
= input_line_pointer
;
482 c
= get_symbol_end ();
483 symbolP
= symbol_find_or_make (name
);
484 *input_line_pointer
= c
;
486 S_SET_WEAK (symbolP
);
487 symbol_get_obj (symbolP
)->local
= 1;
490 input_line_pointer
++;
492 if (*input_line_pointer
== '\n')
497 demand_empty_rest_of_line ();
501 obj_elf_visibility (visibility
)
508 elf_symbol_type
*elfsym
;
512 name
= input_line_pointer
;
513 c
= get_symbol_end ();
514 symbolP
= symbol_find_or_make (name
);
515 *input_line_pointer
= c
;
519 bfdsym
= symbol_get_bfdsym (symbolP
);
520 elfsym
= elf_symbol_from (bfd_asymbol_bfd (bfdsym
), bfdsym
);
524 elfsym
->internal_elf_sym
.st_other
= visibility
;
528 input_line_pointer
++;
532 if (*input_line_pointer
== '\n')
538 demand_empty_rest_of_line ();
541 static segT previous_section
;
542 static int previous_subsection
;
546 struct section_stack
*next
;
548 int subseg
, prev_subseg
;
551 static struct section_stack
*section_stack
;
553 /* Handle the .section pseudo-op. This code supports two different
556 The first is found on Solaris, and looks like
557 .section ".sec1",#alloc,#execinstr,#write
558 Here the names after '#' are the SHF_* flags to turn on for the
559 section. I'm not sure how it determines the SHT_* type (BFD
560 doesn't really give us control over the type, anyhow).
562 The second format is found on UnixWare, and probably most SVR4
563 machines, and looks like
564 .section .sec1,"a",@progbits
565 The quoted string may contain any combination of a, w, x, and
566 represents the SHF_* flags to turn on for the section. The string
567 beginning with '@' can be progbits or nobits. There should be
568 other possibilities, but I don't know what they are. In any case,
569 BFD doesn't really let us set the section type. */
571 /* Certain named sections have particular defined types, listed on p.
573 struct special_section
580 static struct special_section
const special_sections
[] =
582 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
583 { ".comment", SHT_PROGBITS
, 0 },
584 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
585 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
586 { ".debug", SHT_PROGBITS
, 0 },
587 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
588 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
589 { ".line", SHT_PROGBITS
, 0 },
590 { ".note", SHT_NOTE
, 0 },
591 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
592 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
593 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
595 #ifdef ELF_TC_SPECIAL_SECTIONS
596 ELF_TC_SPECIAL_SECTIONS
600 /* The following section names are special, but they can not
601 reasonably appear in assembler code. Some of the attributes are
602 processor dependent. */
603 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
604 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
605 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
606 { ".got", SHT_PROGBITS
, 0 },
607 { ".hash", SHT_HASH
, SHF_ALLOC
},
608 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
609 { ".plt", SHT_PROGBITS
, 0 },
610 { ".shstrtab",SHT_STRTAB
, 0 },
611 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
612 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
619 obj_elf_change_section (name
, type
, attr
, entsize
, push
)
621 int type
, attr
, entsize
, push
;
628 #ifdef md_flush_pending_output
629 md_flush_pending_output ();
632 /* Switch to the section, creating it if necessary. */
635 struct section_stack
*elt
;
636 elt
= xmalloc (sizeof (struct section_stack
));
637 elt
->next
= section_stack
;
639 elt
->prev_seg
= previous_section
;
640 elt
->subseg
= now_subseg
;
641 elt
->prev_subseg
= previous_subsection
;
644 previous_section
= now_seg
;
645 previous_subsection
= now_subseg
;
647 old_sec
= bfd_get_section_by_name (stdoutput
, name
);
648 sec
= subseg_new (name
, 0);
650 /* See if this is one of the special sections. */
651 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
652 if (strcmp (name
, special_sections
[i
].name
) == 0)
654 if (type
== SHT_NULL
)
655 type
= special_sections
[i
].type
;
656 else if (type
!= special_sections
[i
].type
)
660 as_warn (_("Setting incorrect section type for %s"), name
);
664 as_warn (_("Ignoring incorrect section type for %s"), name
);
665 type
= special_sections
[i
].type
;
668 if ((attr
&~ special_sections
[i
].attributes
) != 0
671 /* As a GNU extension, we permit a .note section to be
672 allocatable. If the linker sees an allocateable .note
673 section, it will create a PT_NOTE segment in the output
675 if (strcmp (name
, ".note") != 0
676 || attr
!= SHF_ALLOC
)
677 as_warn (_("Setting incorrect section attributes for %s"),
680 attr
|= special_sections
[i
].attributes
;
684 /* Convert ELF type and flags to BFD flags. */
686 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
687 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
688 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
689 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0)
690 | ((attr
& SHF_MERGE
) ? SEC_MERGE
: 0)
691 | ((attr
& SHF_STRINGS
) ? SEC_STRINGS
: 0));
692 #ifdef md_elf_section_flags
693 flags
= md_elf_section_flags (flags
, attr
, type
);
700 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
701 if (type
== SHT_NOBITS
)
702 seg_info (sec
)->bss
= 1;
704 bfd_set_section_flags (stdoutput
, sec
, flags
);
705 if (flags
& SEC_MERGE
)
706 sec
->entsize
= entsize
;
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
| SEC_MERGE
| SEC_STRINGS
))
723 as_warn (_("Ignoring changed section attributes for %s"), name
);
724 else if ((flags
& SEC_MERGE
) && old_sec
->entsize
!= entsize
)
725 as_warn (_("Ignoring changed section entity size for %s"), name
);
728 #ifdef md_elf_section_change_hook
729 md_elf_section_change_hook ();
734 obj_elf_parse_section_letters (str
, len
)
751 attr
|= SHF_EXECINSTR
;
761 char *bad_msg
= _("Unrecognized .section attribute: want a,m,s,w,x");
762 #ifdef md_elf_section_letter
763 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
769 as_warn ("%s", bad_msg
);
782 obj_elf_section_word (str
, len
)
786 if (len
== 5 && strncmp (str
, "write", 5) == 0)
788 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
790 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
791 return SHF_EXECINSTR
;
793 #ifdef md_elf_section_word
795 int md_attr
= md_elf_section_word (str
, len
);
801 as_warn (_("Unrecognized section attribute"));
806 obj_elf_section_type (str
, len
)
810 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
812 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
815 #ifdef md_elf_section_type
817 int md_type
= md_elf_section_type (str
, len
);
823 as_warn (_("Unrecognized section type"));
828 obj_elf_section (push
)
831 char *name
, *beg
, *end
;
832 int type
, attr
, dummy
;
840 #ifdef md_flush_pending_output
841 md_flush_pending_output ();
844 previous_section
= now_seg
;
845 previous_subsection
= now_subseg
;
847 s_mri_sect (&mri_type
);
849 #ifdef md_elf_section_change_hook
850 md_elf_section_change_hook ();
855 #endif /* ! defined (TC_I370) */
857 /* Get name of section. */
859 if (*input_line_pointer
== '"')
861 name
= demand_copy_C_string (&dummy
);
864 ignore_rest_of_line ();
870 end
= input_line_pointer
;
871 while (0 == strchr ("\n\t,; ", *end
))
873 if (end
== input_line_pointer
)
875 as_warn (_("Missing section name"));
876 ignore_rest_of_line ();
880 name
= xmalloc (end
- input_line_pointer
+ 1);
881 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
882 name
[end
- input_line_pointer
] = '\0';
883 input_line_pointer
= end
;
891 if (*input_line_pointer
== ',')
893 /* Skip the comma. */
894 ++input_line_pointer
;
897 if (*input_line_pointer
== '"')
899 beg
= demand_copy_C_string (&dummy
);
902 ignore_rest_of_line ();
905 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
908 if (*input_line_pointer
== ',')
911 ++input_line_pointer
;
913 c
= *input_line_pointer
;
916 beg
= demand_copy_C_string (&dummy
);
919 ignore_rest_of_line ();
922 type
= obj_elf_section_type (beg
, strlen (beg
));
924 else if (c
== '@' || c
== '%')
926 beg
= ++input_line_pointer
;
927 c
= get_symbol_end ();
928 *input_line_pointer
= c
;
929 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
934 if ((attr
& SHF_MERGE
) && *input_line_pointer
== ',')
936 ++input_line_pointer
;
938 entsize
= get_absolute_expression ();
941 as_warn (_("Bad .section directive - invalid merge entity size"));
954 if (*input_line_pointer
!= '#')
956 as_warn (_("Bad .section directive - character following name is not '#'"));
957 ignore_rest_of_line ();
960 beg
= ++input_line_pointer
;
961 c
= get_symbol_end ();
962 *input_line_pointer
= c
;
964 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
968 while (*input_line_pointer
++ == ',');
969 --input_line_pointer
;
973 demand_empty_rest_of_line ();
975 if ((attr
& SHF_MERGE
) && entsize
== 0)
977 as_warn (_("Entity size for SHF_MERGE not specified.\nSpecify entity size as 4th argument"));
981 obj_elf_change_section (name
, type
, attr
, entsize
, push
);
984 /* Change to the .data section. */
990 #ifdef md_flush_pending_output
991 md_flush_pending_output ();
994 previous_section
= now_seg
;
995 previous_subsection
= now_subseg
;
998 #ifdef md_elf_section_change_hook
999 md_elf_section_change_hook ();
1003 /* Change to the .text section. */
1009 #ifdef md_flush_pending_output
1010 md_flush_pending_output ();
1013 previous_section
= now_seg
;
1014 previous_subsection
= now_subseg
;
1017 #ifdef md_elf_section_change_hook
1018 md_elf_section_change_hook ();
1023 obj_elf_subsection (ignore
)
1024 int ignore ATTRIBUTE_UNUSED
;
1028 #ifdef md_flush_pending_output
1029 md_flush_pending_output ();
1032 previous_section
= now_seg
;
1033 previous_subsection
= now_subseg
;
1035 temp
= get_absolute_expression ();
1036 subseg_set (now_seg
, (subsegT
) temp
);
1037 demand_empty_rest_of_line ();
1039 #ifdef md_elf_section_change_hook
1040 md_elf_section_change_hook ();
1044 /* This can be called from the processor backends if they change
1048 obj_elf_section_change_hook ()
1050 previous_section
= now_seg
;
1051 previous_subsection
= now_subseg
;
1055 obj_elf_previous (ignore
)
1056 int ignore ATTRIBUTE_UNUSED
;
1061 if (previous_section
== 0)
1063 as_bad (_(".previous without corresponding .section; ignored"));
1067 #ifdef md_flush_pending_output
1068 md_flush_pending_output ();
1071 new_section
= previous_section
;
1072 new_subsection
= previous_subsection
;
1073 previous_section
= now_seg
;
1074 previous_subsection
= now_subseg
;
1075 subseg_set (new_section
, new_subsection
);
1077 #ifdef md_elf_section_change_hook
1078 md_elf_section_change_hook ();
1083 obj_elf_popsection (xxx
)
1084 int xxx ATTRIBUTE_UNUSED
;
1086 struct section_stack
*top
= section_stack
;
1090 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1094 #ifdef md_flush_pending_output
1095 md_flush_pending_output ();
1098 section_stack
= top
->next
;
1099 previous_section
= top
->prev_seg
;
1100 previous_subsection
= top
->prev_subseg
;
1101 subseg_set (top
->seg
, top
->subseg
);
1104 #ifdef md_elf_section_change_hook
1105 md_elf_section_change_hook ();
1110 obj_elf_line (ignore
)
1111 int ignore ATTRIBUTE_UNUSED
;
1113 /* Assume delimiter is part of expression. BSD4.2 as fails with
1114 delightful bug, so we are not being incompatible here. */
1115 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
1116 demand_empty_rest_of_line ();
1119 /* This handles the .symver pseudo-op, which is used to specify a
1120 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1121 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1122 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1123 with the same value as the symbol NAME. */
1126 obj_elf_symver (ignore
)
1127 int ignore ATTRIBUTE_UNUSED
;
1134 name
= input_line_pointer
;
1135 c
= get_symbol_end ();
1137 sym
= symbol_find_or_make (name
);
1139 *input_line_pointer
= c
;
1142 if (*input_line_pointer
!= ',')
1144 as_bad (_("expected comma after name in .symver"));
1145 ignore_rest_of_line ();
1149 ++input_line_pointer
;
1150 name
= input_line_pointer
;
1152 /* Temporarily include '@' in symbol names. */
1153 old_lexat
= lex_type
[(unsigned char) '@'];
1154 lex_type
[(unsigned char) '@'] |= LEX_NAME
;
1155 c
= get_symbol_end ();
1156 lex_type
[(unsigned char) '@'] = old_lexat
;
1158 if (symbol_get_obj (sym
)->versioned_name
== NULL
)
1160 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1162 *input_line_pointer
= c
;
1164 if (strchr (symbol_get_obj (sym
)->versioned_name
,
1165 ELF_VER_CHR
) == NULL
)
1167 as_bad (_("missing version name in `%s' for symbol `%s'"),
1168 symbol_get_obj (sym
)->versioned_name
,
1170 ignore_rest_of_line ();
1176 if (strcmp (symbol_get_obj (sym
)->versioned_name
, name
))
1178 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1179 name
, symbol_get_obj (sym
)->versioned_name
,
1181 ignore_rest_of_line ();
1185 *input_line_pointer
= c
;
1188 demand_empty_rest_of_line ();
1191 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1192 to the linker the hierarchy in which a particular table resides. The
1193 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1196 obj_elf_vtable_inherit (ignore
)
1197 int ignore ATTRIBUTE_UNUSED
;
1199 char *cname
, *pname
;
1200 symbolS
*csym
, *psym
;
1203 if (*input_line_pointer
== '#')
1204 ++input_line_pointer
;
1206 cname
= input_line_pointer
;
1207 c
= get_symbol_end ();
1208 csym
= symbol_find (cname
);
1210 /* GCFIXME: should check that we don't have two .vtable_inherits for
1211 the same child symbol. Also, we can currently only do this if the
1212 child symbol is already exists and is placed in a fragment. */
1214 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1216 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1221 *input_line_pointer
= c
;
1224 if (*input_line_pointer
!= ',')
1226 as_bad ("expected comma after name in .vtable_inherit");
1227 ignore_rest_of_line ();
1231 ++input_line_pointer
;
1234 if (*input_line_pointer
== '#')
1235 ++input_line_pointer
;
1237 if (input_line_pointer
[0] == '0'
1238 && (input_line_pointer
[1] == '\0'
1239 || isspace ((unsigned char) input_line_pointer
[1])))
1241 psym
= section_symbol (absolute_section
);
1242 ++input_line_pointer
;
1246 pname
= input_line_pointer
;
1247 c
= get_symbol_end ();
1248 psym
= symbol_find_or_make (pname
);
1249 *input_line_pointer
= c
;
1252 demand_empty_rest_of_line ();
1257 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1258 return fix_new (symbol_get_frag (csym
),
1259 symbol_get_value_expression (csym
)->X_add_number
,
1260 0, psym
, 0, 0, BFD_RELOC_VTABLE_INHERIT
);
1263 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1264 to the linker that a vtable slot was used. The syntax is
1265 ".vtable_entry tablename, offset". */
1268 obj_elf_vtable_entry (ignore
)
1269 int ignore ATTRIBUTE_UNUSED
;
1276 if (*input_line_pointer
== '#')
1277 ++input_line_pointer
;
1279 name
= input_line_pointer
;
1280 c
= get_symbol_end ();
1281 sym
= symbol_find_or_make (name
);
1282 *input_line_pointer
= c
;
1285 if (*input_line_pointer
!= ',')
1287 as_bad ("expected comma after name in .vtable_entry");
1288 ignore_rest_of_line ();
1292 ++input_line_pointer
;
1293 if (*input_line_pointer
== '#')
1294 ++input_line_pointer
;
1296 offset
= get_absolute_expression ();
1298 demand_empty_rest_of_line ();
1300 return fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1301 BFD_RELOC_VTABLE_ENTRY
);
1305 elf_obj_read_begin_hook ()
1307 #ifdef NEED_ECOFF_DEBUG
1308 if (ECOFF_DEBUGGING
)
1309 ecoff_read_begin_hook ();
1314 elf_obj_symbol_new_hook (symbolP
)
1317 struct elf_obj_sy
*sy_obj
;
1319 sy_obj
= symbol_get_obj (symbolP
);
1320 sy_obj
->size
= NULL
;
1321 sy_obj
->versioned_name
= NULL
;
1323 #ifdef NEED_ECOFF_DEBUG
1324 if (ECOFF_DEBUGGING
)
1325 ecoff_symbol_new_hook (symbolP
);
1329 /* When setting one symbol equal to another, by default we probably
1330 want them to have the same "size", whatever it means in the current
1334 elf_copy_symbol_attributes (dest
, src
)
1335 symbolS
*dest
, *src
;
1337 struct elf_obj_sy
*srcelf
= symbol_get_obj (src
);
1338 struct elf_obj_sy
*destelf
= symbol_get_obj (dest
);
1341 if (destelf
->size
== NULL
)
1343 (expressionS
*) xmalloc (sizeof (expressionS
));
1344 *destelf
->size
= *srcelf
->size
;
1348 if (destelf
->size
!= NULL
)
1349 free (destelf
->size
);
1350 destelf
->size
= NULL
;
1352 S_SET_SIZE (dest
, S_GET_SIZE (src
));
1353 S_SET_OTHER (dest
, S_GET_OTHER (src
));
1357 obj_elf_version (ignore
)
1358 int ignore ATTRIBUTE_UNUSED
;
1364 asection
*seg
= now_seg
;
1365 subsegT subseg
= now_subseg
;
1366 Elf_Internal_Note i_note
;
1367 Elf_External_Note e_note
;
1368 asection
*note_secp
= (asection
*) NULL
;
1372 if (*input_line_pointer
== '\"')
1374 ++input_line_pointer
; /* -> 1st char of string. */
1375 name
= input_line_pointer
;
1377 while (is_a_char (c
= next_char_of_string ()))
1379 c
= *input_line_pointer
;
1380 *input_line_pointer
= '\0';
1381 *(input_line_pointer
- 1) = '\0';
1382 *input_line_pointer
= c
;
1384 /* create the .note section */
1386 note_secp
= subseg_new (".note", 0);
1387 bfd_set_section_flags (stdoutput
,
1389 SEC_HAS_CONTENTS
| SEC_READONLY
);
1391 /* process the version string */
1393 len
= strlen (name
);
1395 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1396 i_note
.descsz
= 0; /* no description */
1397 i_note
.type
= NT_VERSION
;
1398 p
= frag_more (sizeof (e_note
.namesz
));
1399 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1400 p
= frag_more (sizeof (e_note
.descsz
));
1401 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1402 p
= frag_more (sizeof (e_note
.type
));
1403 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1405 for (i
= 0; i
< len
; i
++)
1409 FRAG_APPEND_1_CHAR (ch
);
1412 frag_align (2, 0, 0);
1414 subseg_set (seg
, subseg
);
1418 as_bad (_("Expected quoted string"));
1420 demand_empty_rest_of_line ();
1424 obj_elf_size (ignore
)
1425 int ignore ATTRIBUTE_UNUSED
;
1427 char *name
= input_line_pointer
;
1428 char c
= get_symbol_end ();
1433 p
= input_line_pointer
;
1436 if (*input_line_pointer
!= ',')
1439 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1441 ignore_rest_of_line ();
1444 input_line_pointer
++;
1446 if (exp
.X_op
== O_absent
)
1448 as_bad (_("missing expression in .size directive"));
1449 exp
.X_op
= O_constant
;
1450 exp
.X_add_number
= 0;
1453 sym
= symbol_find_or_make (name
);
1455 if (exp
.X_op
== O_constant
)
1456 S_SET_SIZE (sym
, exp
.X_add_number
);
1459 symbol_get_obj (sym
)->size
=
1460 (expressionS
*) xmalloc (sizeof (expressionS
));
1461 *symbol_get_obj (sym
)->size
= exp
;
1463 demand_empty_rest_of_line ();
1466 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1467 There are five syntaxes:
1469 The first (used on Solaris) is
1471 The second (used on UnixWare) is
1473 The third (reportedly to be used on Irix 6.0) is
1475 The fourth (used on NetBSD/Arm and Linux/ARM) is
1477 The fifth (used on SVR4/860) is
1478 .type SYM,"function"
1482 obj_elf_type (ignore
)
1483 int ignore ATTRIBUTE_UNUSED
;
1488 const char *typename
;
1490 elf_symbol_type
*elfsym
;
1492 name
= input_line_pointer
;
1493 c
= get_symbol_end ();
1494 sym
= symbol_find_or_make (name
);
1495 elfsym
= (elf_symbol_type
*) symbol_get_bfdsym (sym
);
1496 *input_line_pointer
= c
;
1499 if (*input_line_pointer
== ',')
1500 ++input_line_pointer
;
1503 if ( *input_line_pointer
== '#'
1504 || *input_line_pointer
== '@'
1505 || *input_line_pointer
== '"'
1506 || *input_line_pointer
== '%')
1507 ++input_line_pointer
;
1509 typename
= input_line_pointer
;
1510 c
= get_symbol_end ();
1513 if (strcmp (typename
, "function") == 0
1514 || strcmp (typename
, "STT_FUNC") == 0)
1515 type
= BSF_FUNCTION
;
1516 else if (strcmp (typename
, "object") == 0
1517 || strcmp (typename
, "STT_OBJECT") == 0)
1519 #ifdef md_elf_symbol_type
1520 else if ((type
= md_elf_symbol_type (typename
, sym
, elfsym
)) != -1)
1524 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1526 *input_line_pointer
= c
;
1528 if (*input_line_pointer
== '"')
1529 ++input_line_pointer
;
1531 elfsym
->symbol
.flags
|= type
;
1533 demand_empty_rest_of_line ();
1537 obj_elf_ident (ignore
)
1538 int ignore ATTRIBUTE_UNUSED
;
1540 static segT comment_section
;
1541 segT old_section
= now_seg
;
1542 int old_subsection
= now_subseg
;
1544 #ifdef md_flush_pending_output
1545 md_flush_pending_output ();
1548 if (!comment_section
)
1551 comment_section
= subseg_new (".comment", 0);
1552 bfd_set_section_flags (stdoutput
, comment_section
,
1553 SEC_READONLY
| SEC_HAS_CONTENTS
);
1558 subseg_set (comment_section
, 0);
1560 subseg_set (old_section
, old_subsection
);
1563 #ifdef INIT_STAB_SECTION
1565 /* The first entry in a .stabs section is special. */
1568 obj_elf_init_stab_section (seg
)
1574 unsigned int stroff
;
1576 /* Force the section to align to a longword boundary. Without this,
1577 UnixWare ar crashes. */
1578 bfd_set_section_alignment (stdoutput
, seg
, 2);
1580 /* Make space for this first symbol. */
1584 as_where (&file
, (unsigned int *) NULL
);
1585 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1586 strcpy (stabstr_name
, segment_name (seg
));
1587 strcat (stabstr_name
, "str");
1588 stroff
= get_stab_string_offset (file
, stabstr_name
);
1590 md_number_to_chars (p
, stroff
, 4);
1591 seg_info (seg
)->stabu
.p
= p
;
1596 /* Fill in the counts in the first entry in a .stabs section. */
1599 adjust_stab_sections (abfd
, sec
, xxx
)
1602 PTR xxx ATTRIBUTE_UNUSED
;
1609 if (strncmp (".stab", sec
->name
, 5))
1611 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1614 name
= (char *) alloca (strlen (sec
->name
) + 4);
1615 strcpy (name
, sec
->name
);
1616 strcat (name
, "str");
1617 strsec
= bfd_get_section_by_name (abfd
, name
);
1619 strsz
= bfd_section_size (abfd
, strsec
);
1622 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1624 p
= seg_info (sec
)->stabu
.p
;
1627 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1628 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1631 #ifdef NEED_ECOFF_DEBUG
1633 /* This function is called by the ECOFF code. It is supposed to
1634 record the external symbol information so that the backend can
1635 write it out correctly. The ELF backend doesn't actually handle
1636 this at the moment, so we do it ourselves. We save the information
1640 elf_ecoff_set_ext (sym
, ext
)
1642 struct ecoff_extr
*ext
;
1644 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1647 /* This function is called by bfd_ecoff_debug_externals. It is
1648 supposed to *EXT to the external symbol information, and return
1649 whether the symbol should be used at all. */
1652 elf_get_extr (sym
, ext
)
1656 if (sym
->udata
.p
== NULL
)
1658 *ext
= *(EXTR
*) sym
->udata
.p
;
1662 /* This function is called by bfd_ecoff_debug_externals. It has
1663 nothing to do for ELF. */
1667 elf_set_index (sym
, indx
)
1668 asymbol
*sym ATTRIBUTE_UNUSED
;
1669 bfd_size_type indx ATTRIBUTE_UNUSED
;
1673 #endif /* NEED_ECOFF_DEBUG */
1676 elf_frob_symbol (symp
, puntp
)
1680 struct elf_obj_sy
*sy_obj
;
1682 #ifdef NEED_ECOFF_DEBUG
1683 if (ECOFF_DEBUGGING
)
1684 ecoff_frob_symbol (symp
);
1687 sy_obj
= symbol_get_obj (symp
);
1689 if (sy_obj
->size
!= NULL
)
1691 switch (sy_obj
->size
->X_op
)
1695 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1696 + sy_obj
->size
->X_add_number
1697 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1701 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1702 + sy_obj
->size
->X_add_number
));
1705 as_bad (_(".size expression too complicated to fix up"));
1708 free (sy_obj
->size
);
1709 sy_obj
->size
= NULL
;
1712 if (sy_obj
->versioned_name
!= NULL
)
1716 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1719 /* This symbol was given a new name with the .symver directive.
1721 If this is an external reference, just rename the symbol to
1722 include the version string. This will make the relocs be
1723 against the correct versioned symbol.
1725 If this is a definition, add an alias. FIXME: Using an alias
1726 will permit the debugging information to refer to the right
1727 symbol. However, it's not clear whether it is the best
1730 if (! S_IS_DEFINED (symp
))
1732 /* Verify that the name isn't using the @@ syntax--this is
1733 reserved for definitions of the default version to link
1735 if (p
[1] == ELF_VER_CHR
)
1737 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1738 sy_obj
->versioned_name
);
1741 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1745 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1749 /* The @@@ syntax is a special case. It renames the
1750 symbol name to versioned_name with one `@' removed. */
1751 l
= strlen (&p
[3]) + 1;
1752 memmove (&p
[2], &p
[3], l
);
1753 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1759 /* FIXME: Creating a new symbol here is risky. We're
1760 in the final loop over the symbol table. We can
1761 get away with it only because the symbol goes to
1762 the end of the list, where the loop will still see
1763 it. It would probably be better to do this in
1764 obj_frob_file_before_adjust. */
1766 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1768 /* Now we act as though we saw symp2 = sym. */
1770 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1772 /* Subtracting out the frag address here is a hack
1773 because we are in the middle of the final loop. */
1776 - symbol_get_frag (symp
)->fr_address
));
1778 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1780 /* This will copy over the size information. */
1781 copy_symbol_attributes (symp2
, symp
);
1783 if (S_IS_WEAK (symp
))
1786 if (S_IS_EXTERNAL (symp
))
1787 S_SET_EXTERNAL (symp2
);
1792 /* Double check weak symbols. */
1793 if (S_IS_WEAK (symp
))
1795 if (S_IS_COMMON (symp
))
1796 as_bad (_("Symbol `%s' can not be both weak and common"),
1801 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1802 any undefined non-function symbol to STT_OBJECT. We try to be
1803 compatible, since newer Irix 5 and 6 linkers care. However, we
1804 only set undefined symbols to be STT_OBJECT if we are on Irix,
1805 because that is the only time gcc will generate the necessary
1806 .global directives to mark functions. */
1808 if (S_IS_COMMON (symp
))
1809 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1811 if (strstr (TARGET_OS
, "irix") != NULL
1812 && ! S_IS_DEFINED (symp
)
1813 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1814 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1818 /* If TC_PPC is defined, we used to force the type of a symbol to be
1819 BSF_OBJECT if it was otherwise unset. This was required by some
1820 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1821 that this is no longer needed, so it is now commented out. */
1822 if ((symbol_get_bfdsym (symp
)->flags
1823 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1824 && S_IS_DEFINED (symp
))
1825 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1832 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1834 #ifdef elf_tc_final_processing
1835 elf_tc_final_processing ();
1839 /* It removes any unneeded versioned symbols from the symbol table. */
1842 elf_frob_file_before_adjust ()
1848 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1849 if (symbol_get_obj (symp
)->versioned_name
)
1851 if (!S_IS_DEFINED (symp
))
1855 /* The @@@ syntax is a special case. If the symbol is
1856 not defined, 2 `@'s will be removed from the
1859 p
= strchr (symbol_get_obj (symp
)->versioned_name
,
1862 if (p
[1] == ELF_VER_CHR
&& p
[2] == ELF_VER_CHR
)
1864 size_t l
= strlen (&p
[3]) + 1;
1865 memmove (&p
[1], &p
[3], l
);
1867 if (symbol_used_p (symp
) == 0
1868 && symbol_used_in_reloc_p (symp
) == 0)
1869 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1875 /* It is required that we let write_relocs have the opportunity to
1876 optimize away fixups before output has begun, since it is possible
1877 to eliminate all fixups for a section and thus we never should
1878 have generated the relocation section. */
1881 elf_frob_file_after_relocs ()
1883 #ifdef NEED_ECOFF_DEBUG
1884 if (ECOFF_DEBUGGING
)
1885 /* Generate the ECOFF debugging information. */
1887 const struct ecoff_debug_swap
*debug_swap
;
1888 struct ecoff_debug_info debug
;
1893 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1894 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1895 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1897 /* Set up the pointers in debug. */
1898 #define SET(ptr, offset, type) \
1899 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1901 SET (line
, cbLineOffset
, unsigned char *);
1902 SET (external_dnr
, cbDnOffset
, PTR
);
1903 SET (external_pdr
, cbPdOffset
, PTR
);
1904 SET (external_sym
, cbSymOffset
, PTR
);
1905 SET (external_opt
, cbOptOffset
, PTR
);
1906 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1907 SET (ss
, cbSsOffset
, char *);
1908 SET (external_fdr
, cbFdOffset
, PTR
);
1909 SET (external_rfd
, cbRfdOffset
, PTR
);
1910 /* ssext and external_ext are set up just below. */
1914 /* Set up the external symbols. */
1915 debug
.ssext
= debug
.ssext_end
= NULL
;
1916 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1917 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1918 elf_get_extr
, elf_set_index
))
1919 as_fatal (_("Failed to set up debugging information: %s"),
1920 bfd_errmsg (bfd_get_error ()));
1922 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1923 assert (sec
!= NULL
);
1925 know (stdoutput
->output_has_begun
== false);
1927 /* We set the size of the section, call bfd_set_section_contents
1928 to force the ELF backend to allocate a file position, and then
1929 write out the data. FIXME: Is this really the best way to do
1931 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1933 /* Pass BUF to bfd_set_section_contents because this will
1934 eventually become a call to fwrite, and ISO C prohibits
1935 passing a NULL pointer to a stdio function even if the
1936 pointer will not be used. */
1937 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) buf
,
1938 (file_ptr
) 0, (bfd_size_type
) 0))
1939 as_fatal (_("Can't start writing .mdebug section: %s"),
1940 bfd_errmsg (bfd_get_error ()));
1942 know (stdoutput
->output_has_begun
== true);
1943 know (sec
->filepos
!= 0);
1945 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1947 as_fatal (_("Could not write .mdebug section: %s"),
1948 bfd_errmsg (bfd_get_error ()));
1950 #endif /* NEED_ECOFF_DEBUG */
1955 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1956 SCO specific identifier in the .notes section to satisfy the SCO
1959 This looks more complicated than it really is. As opposed to the
1960 "obvious" solution, this should handle the cross dev cases
1961 correctly. (i.e, hosting on a 64 bit big endian processor, but
1962 generating SCO Elf code) Efficiency isn't a concern, as there
1963 should be exactly one of these sections per object module.
1965 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1968 int_32 namesz = 4 ; Name size
1969 int_32 descsz = 12 ; Descriptive information
1971 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1972 int_32 version = (major ver # << 16) | version of tools ;
1973 int_32 source = (tool_id << 16 ) | 1 ;
1974 int_32 info = 0 ; These are set by the SCO tools, but we
1975 don't know enough about the source
1976 environment to set them. SCO ld currently
1977 ignores them, and recommends we set them
1980 #define SCO_MAJOR_VERSION 0x1
1981 #define SCO_MINOR_VERSION 0x1
1991 asection
*seg
= now_seg
;
1992 subsegT subseg
= now_subseg
;
1993 Elf_Internal_Note i_note
;
1994 Elf_External_Note e_note
;
1995 asection
*note_secp
= (asection
*) NULL
;
1998 /* create the .note section */
2000 note_secp
= subseg_new (".note", 0);
2001 bfd_set_section_flags (stdoutput
,
2003 SEC_HAS_CONTENTS
| SEC_READONLY
);
2005 /* process the version string */
2008 i_note
.descsz
= 12; /* 12 descriptive bytes */
2009 i_note
.type
= NT_VERSION
; /* Contains a version string */
2011 p
= frag_more (sizeof (i_note
.namesz
));
2012 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
2014 p
= frag_more (sizeof (i_note
.descsz
));
2015 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
2017 p
= frag_more (sizeof (i_note
.type
));
2018 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
2023 /* Note: this is the version number of the ELF we're representing */
2025 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
2027 /* Here, we pick a magic number for ourselves (yes, I "registered"
2028 it with SCO. The bottom bit shows that we are compat with the
2031 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
2033 /* If we knew (or cared) what the source language options were, we'd
2034 fill them in here. SCO has given us permission to ignore these
2035 and just set them to zero. */
2037 md_number_to_chars (p
, 0x0000, 4);
2039 frag_align (2, 0, 0);
2041 /* We probably can't restore the current segment, for there likely
2044 subseg_set (seg
, subseg
);
2048 #endif /* SCO_ELF */
2051 elf_separate_stab_sections ()
2053 #ifdef NEED_ECOFF_DEBUG
2054 return (!ECOFF_DEBUGGING
);
2061 elf_init_stab_section (seg
)
2064 #ifdef NEED_ECOFF_DEBUG
2065 if (!ECOFF_DEBUGGING
)
2067 obj_elf_init_stab_section (seg
);
2070 const struct format_ops elf_format_ops
=
2072 bfd_target_elf_flavour
,
2073 0, /* dfl_leading_underscore */
2074 1, /* emit_section_symbols */
2079 elf_frob_file_before_adjust
,
2080 elf_frob_file_after_relocs
,
2081 elf_s_get_size
, elf_s_set_size
,
2082 elf_s_get_align
, elf_s_set_align
,
2089 elf_copy_symbol_attributes
,
2090 #ifdef NEED_ECOFF_DEBUG
2091 ecoff_generate_asm_lineno
,
2094 0, /* generate_asm_lineno */
2095 0, /* process_stab */
2097 elf_separate_stab_sections
,
2098 elf_init_stab_section
,
2099 elf_sec_sym_ok_for_reloc
,
2101 #ifdef NEED_ECOFF_DEBUG
2104 0, /* ecoff_set_ext */
2106 elf_obj_read_begin_hook
,
2107 elf_obj_symbol_new_hook