1 /* ELF object file format
2 Copyright (C) 1992, 93-98, 1999 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 #define OBJ_HEADER "obj-elf.h"
26 #ifndef ECOFF_DEBUGGING
27 #define ECOFF_DEBUGGING 0
29 #define NEED_ECOFF_DEBUG
32 #ifdef NEED_ECOFF_DEBUG
37 #include "elf/alpha.h"
48 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
49 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
50 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
51 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
52 static void elf_copy_symbol_attributes
PARAMS ((symbolS
*, symbolS
*));
53 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
54 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
56 #ifdef NEED_ECOFF_DEBUG
57 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
58 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
61 static void obj_elf_line
PARAMS ((int));
62 void obj_elf_version
PARAMS ((int));
63 static void obj_elf_size
PARAMS ((int));
64 static void obj_elf_type
PARAMS ((int));
65 static void obj_elf_ident
PARAMS ((int));
66 static void obj_elf_weak
PARAMS ((int));
67 static void obj_elf_local
PARAMS ((int));
68 static void obj_elf_common
PARAMS ((int));
69 static void obj_elf_symver
PARAMS ((int));
70 static void obj_elf_vtable_inherit
PARAMS ((int));
71 static void obj_elf_vtable_entry
PARAMS ((int));
72 static void obj_elf_data
PARAMS ((int));
73 static void obj_elf_text
PARAMS ((int));
74 static void obj_elf_subsection
PARAMS ((int));
75 static void obj_elf_popsection
PARAMS ((int));
77 static const pseudo_typeS elf_pseudo_table
[] =
79 {"comm", obj_elf_common
, 0},
80 {"common", obj_elf_common
, 0},
81 {"ident", obj_elf_ident
, 0},
82 {"local", obj_elf_local
, 0},
83 {"previous", obj_elf_previous
, 0},
84 {"section", obj_elf_section
, 0},
85 {"section.s", obj_elf_section
, 0},
86 {"sect", obj_elf_section
, 0},
87 {"sect.s", obj_elf_section
, 0},
88 {"pushsection", obj_elf_section
, 1},
89 {"popsection", obj_elf_popsection
, 0},
90 {"size", obj_elf_size
, 0},
91 {"type", obj_elf_type
, 0},
92 {"version", obj_elf_version
, 0},
93 {"weak", obj_elf_weak
, 0},
95 /* These are used for stabs-in-elf configurations. */
96 {"line", obj_elf_line
, 0},
98 /* This is a GNU extension to handle symbol versions. */
99 {"symver", obj_elf_symver
, 0},
101 /* A GNU extension to change subsection only. */
102 {"subsection", obj_elf_subsection
, 0},
104 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
105 {"vtable_inherit", obj_elf_vtable_inherit
, 0},
106 {"vtable_entry", obj_elf_vtable_entry
, 0},
108 /* These are used for dwarf. */
113 /* We need to trap the section changing calls to handle .previous. */
114 {"data", obj_elf_data
, 0},
115 {"text", obj_elf_text
, 0},
121 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
123 #ifdef NEED_ECOFF_DEBUG
124 /* COFF style debugging information for ECOFF. .ln is not used; .loc
126 { "def", ecoff_directive_def
, 0 },
127 { "dim", ecoff_directive_dim
, 0 },
128 { "endef", ecoff_directive_endef
, 0 },
129 { "file", ecoff_directive_file
, 0 },
130 { "scl", ecoff_directive_scl
, 0 },
131 { "tag", ecoff_directive_tag
, 0 },
132 { "val", ecoff_directive_val
, 0 },
134 /* COFF debugging requires pseudo-ops .size and .type, but ELF
135 already has meanings for those. We use .esize and .etype
136 instead. These are only generated by gcc anyhow. */
137 { "esize", ecoff_directive_size
, 0 },
138 { "etype", ecoff_directive_type
, 0 },
140 /* ECOFF specific debugging information. */
141 { "begin", ecoff_directive_begin
, 0 },
142 { "bend", ecoff_directive_bend
, 0 },
143 { "end", ecoff_directive_end
, 0 },
144 { "ent", ecoff_directive_ent
, 0 },
145 { "fmask", ecoff_directive_fmask
, 0 },
146 { "frame", ecoff_directive_frame
, 0 },
147 { "loc", ecoff_directive_loc
, 0 },
148 { "mask", ecoff_directive_mask
, 0 },
150 /* Other ECOFF directives. */
151 { "extern", ecoff_directive_extern
, 0 },
153 /* These are used on Irix. I don't know how to implement them. */
154 { "alias", s_ignore
, 0 },
155 { "bgnb", s_ignore
, 0 },
156 { "endb", s_ignore
, 0 },
157 { "lab", s_ignore
, 0 },
158 { "noalias", s_ignore
, 0 },
159 { "verstamp", s_ignore
, 0 },
160 { "vreg", s_ignore
, 0 },
163 {NULL
} /* end sentinel */
167 #include "aout/aout64.h"
169 /* This is called when the assembler starts. */
174 /* Add symbols for the known sections to the symbol table. */
175 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
176 TEXT_SECTION_NAME
)));
177 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
178 DATA_SECTION_NAME
)));
179 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
186 pop_insert (elf_pseudo_table
);
188 pop_insert (ecoff_debug_pseudo_table
);
195 return S_GET_SIZE (sym
);
199 elf_s_set_size (sym
, sz
)
203 S_SET_SIZE (sym
, sz
);
207 elf_s_get_align (sym
)
210 return S_GET_ALIGN (sym
);
214 elf_s_set_align (sym
, align
)
218 S_SET_ALIGN (sym
, align
);
222 elf_copy_symbol_attributes (dest
, src
)
225 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
229 elf_sec_sym_ok_for_reloc (sec
)
232 return obj_sec_sym_ok_for_reloc (sec
);
241 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
242 symbol_set_frag (sym
, &zero_address_frag
);
243 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
245 if (symbol_rootP
!= sym
)
247 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
248 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
250 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
254 #ifdef NEED_ECOFF_DEBUG
260 obj_elf_common (ignore
)
270 name
= input_line_pointer
;
271 c
= get_symbol_end ();
272 /* just after name is now '\0' */
273 p
= input_line_pointer
;
276 if (*input_line_pointer
!= ',')
278 as_bad (_("Expected comma after symbol-name"));
279 ignore_rest_of_line ();
282 input_line_pointer
++; /* skip ',' */
283 if ((temp
= get_absolute_expression ()) < 0)
285 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
286 ignore_rest_of_line ();
291 symbolP
= symbol_find_or_make (name
);
293 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
295 as_bad (_("Ignoring attempt to re-define symbol"));
296 ignore_rest_of_line ();
299 if (S_GET_VALUE (symbolP
) != 0)
301 if (S_GET_VALUE (symbolP
) != size
)
303 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
304 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
307 know (symbolP
->sy_frag
== &zero_address_frag
);
308 if (*input_line_pointer
!= ',')
313 input_line_pointer
++;
316 if (! have_align
|| *input_line_pointer
!= '"')
322 temp
= get_absolute_expression ();
326 as_warn (_("Common alignment negative; 0 assumed"));
329 if (symbol_get_obj (symbolP
)->local
)
338 old_subsec
= now_subseg
;
341 /* convert to a power of 2 alignment */
342 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
345 as_bad (_("Common alignment not a power of 2"));
346 ignore_rest_of_line ();
352 record_alignment (bss_section
, align
);
353 subseg_set (bss_section
, 0);
355 frag_align (align
, 0, 0);
356 if (S_GET_SEGMENT (symbolP
) == bss_section
)
357 symbol_get_frag (symbolP
)->fr_symbol
= 0;
358 symbol_set_frag (symbolP
, frag_now
);
359 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
360 (offsetT
) size
, (char *) 0);
362 S_SET_SIZE (symbolP
, size
);
363 S_SET_SEGMENT (symbolP
, bss_section
);
364 S_CLEAR_EXTERNAL (symbolP
);
365 subseg_set (old_sec
, old_subsec
);
370 S_SET_VALUE (symbolP
, (valueT
) size
);
371 S_SET_ALIGN (symbolP
, temp
);
372 S_SET_EXTERNAL (symbolP
);
373 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
378 input_line_pointer
++;
379 /* @@ Some use the dot, some don't. Can we get some consistency?? */
380 if (*input_line_pointer
== '.')
381 input_line_pointer
++;
382 /* @@ Some say data, some say bss. */
383 if (strncmp (input_line_pointer
, "bss\"", 4)
384 && strncmp (input_line_pointer
, "data\"", 5))
386 while (*--input_line_pointer
!= '"')
388 input_line_pointer
--;
389 goto bad_common_segment
;
391 while (*input_line_pointer
++ != '"')
393 goto allocate_common
;
396 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
398 demand_empty_rest_of_line ();
403 p
= input_line_pointer
;
404 while (*p
&& *p
!= '\n')
408 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
410 input_line_pointer
= p
;
411 ignore_rest_of_line ();
417 obj_elf_local (ignore
)
426 name
= input_line_pointer
;
427 c
= get_symbol_end ();
428 symbolP
= symbol_find_or_make (name
);
429 *input_line_pointer
= c
;
431 S_CLEAR_EXTERNAL (symbolP
);
432 symbol_get_obj (symbolP
)->local
= 1;
435 input_line_pointer
++;
437 if (*input_line_pointer
== '\n')
442 demand_empty_rest_of_line ();
446 obj_elf_weak (ignore
)
455 name
= input_line_pointer
;
456 c
= get_symbol_end ();
457 symbolP
= symbol_find_or_make (name
);
458 *input_line_pointer
= c
;
460 S_SET_WEAK (symbolP
);
461 symbol_get_obj (symbolP
)->local
= 1;
464 input_line_pointer
++;
466 if (*input_line_pointer
== '\n')
471 demand_empty_rest_of_line ();
474 static segT previous_section
;
475 static int previous_subsection
;
479 struct section_stack
*next
;
481 int subseg
, prev_subseg
;
484 static struct section_stack
*section_stack
;
487 /* Handle the .section pseudo-op. This code supports two different
490 The first is found on Solaris, and looks like
491 .section ".sec1",#alloc,#execinstr,#write
492 Here the names after '#' are the SHF_* flags to turn on for the
493 section. I'm not sure how it determines the SHT_* type (BFD
494 doesn't really give us control over the type, anyhow).
496 The second format is found on UnixWare, and probably most SVR4
497 machines, and looks like
498 .section .sec1,"a",@progbits
499 The quoted string may contain any combination of a, w, x, and
500 represents the SHF_* flags to turn on for the section. The string
501 beginning with '@' can be progbits or nobits. There should be
502 other possibilities, but I don't know what they are. In any case,
503 BFD doesn't really let us set the section type. */
505 /* Certain named sections have particular defined types, listed on p.
507 struct special_section
514 static struct special_section
const special_sections
[] =
516 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
517 { ".comment", SHT_PROGBITS
, 0 },
518 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
519 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
520 { ".debug", SHT_PROGBITS
, 0 },
521 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
522 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
523 { ".line", SHT_PROGBITS
, 0 },
524 { ".note", SHT_NOTE
, 0 },
525 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
526 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
527 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
529 #ifdef ELF_TC_SPECIAL_SECTIONS
530 ELF_TC_SPECIAL_SECTIONS
534 /* The following section names are special, but they can not
535 reasonably appear in assembler code. Some of the attributes are
536 processor dependent. */
537 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
538 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
539 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
540 { ".got", SHT_PROGBITS
, 0 },
541 { ".hash", SHT_HASH
, SHF_ALLOC
},
542 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
543 { ".plt", SHT_PROGBITS
, 0 },
544 { ".shstrtab",SHT_STRTAB
, 0 },
545 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
546 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
553 obj_elf_change_section (name
, type
, attr
, push
)
555 int type
, attr
, push
;
560 #ifdef md_flush_pending_output
561 md_flush_pending_output ();
564 /* Switch to the section, creating it if necessary. */
567 struct section_stack
*elt
;
568 elt
= xmalloc (sizeof (struct section_stack
));
569 elt
->next
= section_stack
;
571 elt
->prev_seg
= previous_section
;
572 elt
->subseg
= now_subseg
;
573 elt
->prev_subseg
= previous_subsection
;
576 previous_section
= now_seg
;
577 previous_subsection
= now_subseg
;
579 new_sec
= bfd_get_section_by_name (stdoutput
, name
) == NULL
;
580 sec
= subseg_new (name
, 0);
588 /* See if this is one of the special sections. */
589 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
590 if (strcmp (name
, special_sections
[i
].name
) == 0)
592 if (type
== SHT_NULL
)
593 type
= special_sections
[i
].type
;
594 else if (type
!= special_sections
[i
].type
)
595 as_warn (_("Setting incorrect section type for %s"), name
);
597 if ((attr
&~ special_sections
[i
].attributes
) != 0)
599 /* As a GNU extension, we permit a .note section to be
600 allocatable. If the linker sees an allocateable .note
601 section, it will create a PT_NOTE segment in the output
603 if (strcmp (name
, ".note") != 0
604 || attr
!= SHF_ALLOC
)
605 as_warn (_("Setting incorrect section attributes for %s"),
608 attr
|= special_sections
[i
].attributes
;
612 /* Convert ELF type and flags to BFD flags. */
614 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
615 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
616 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
617 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
618 #ifdef md_elf_section_flags
619 flags
= md_elf_section_flags (flags
, attr
, type
);
622 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
623 if (type
== SHT_NOBITS
)
624 seg_info (sec
)->bss
= 1;
626 bfd_set_section_flags (stdoutput
, sec
, flags
);
628 /* Add a symbol for this section to the symbol table. */
629 secsym
= symbol_find (name
);
631 symbol_set_bfdsym (secsym
, sec
->symbol
);
633 symbol_table_insert (section_symbol (sec
));
636 #ifdef md_elf_section_change_hook
637 md_elf_section_change_hook ();
642 obj_elf_parse_section_letters (str
, len
)
659 attr
|= SHF_EXECINSTR
;
663 char *bad_msg
= _("Unrecognized .section attribute: want a,w,x");
664 #ifdef md_elf_section_letter
665 int md_attr
= md_elf_section_letter (*str
, &bad_msg
);
684 obj_elf_section_word (str
, len
)
688 if (len
== 5 && strncmp (str
, "write", 5) == 0)
690 if (len
== 5 && strncmp (str
, "alloc", 5) == 0)
692 if (len
== 9 && strncmp (str
, "execinstr", 9) == 0)
693 return SHF_EXECINSTR
;
695 #ifdef md_elf_section_word
697 int md_attr
= md_elf_section_word (str
, len
);
703 as_warn (_("Unrecognized section attribute"));
708 obj_elf_section_type (str
, len
)
712 if (len
== 8 && strncmp (str
, "progbits", 8) == 0)
714 if (len
== 6 && strncmp (str
, "nobits", 6) == 0)
717 #ifdef md_elf_section_type
719 int md_type
= md_elf_section_type (str
, len
);
725 as_warn (_("Unrecognized section type"));
730 obj_elf_section (push
)
733 char *name
, *beg
, *end
;
734 int type
, attr
, dummy
;
740 #ifdef md_flush_pending_output
741 md_flush_pending_output ();
744 previous_section
= now_seg
;
745 previous_subsection
= now_subseg
;
747 s_mri_sect (&mri_type
);
749 #ifdef md_elf_section_change_hook
750 md_elf_section_change_hook ();
756 /* Get name of section. */
758 if (*input_line_pointer
== '"')
760 name
= demand_copy_C_string (&dummy
);
763 ignore_rest_of_line ();
769 end
= input_line_pointer
;
770 while (0 == strchr ("\n\t,; ", *end
))
772 if (end
== input_line_pointer
)
774 as_warn (_("Missing section name"));
775 ignore_rest_of_line ();
779 name
= xmalloc (end
- input_line_pointer
+ 1);
780 memcpy (name
, input_line_pointer
, end
- input_line_pointer
);
781 name
[end
- input_line_pointer
] = '\0';
782 input_line_pointer
= end
;
789 if (*input_line_pointer
== ',')
791 /* Skip the comma. */
792 ++input_line_pointer
;
795 if (*input_line_pointer
== '"')
797 beg
= demand_copy_C_string (&dummy
);
800 ignore_rest_of_line ();
803 attr
|= obj_elf_parse_section_letters (beg
, strlen (beg
));
806 if (*input_line_pointer
== ',')
809 ++input_line_pointer
;
811 c
= *input_line_pointer
;
814 beg
= demand_copy_C_string (&dummy
);
817 ignore_rest_of_line ();
820 type
= obj_elf_section_type (beg
, strlen (beg
));
822 else if (c
== '@' || c
== '%')
824 beg
= ++input_line_pointer
;
825 c
= get_symbol_end ();
826 *input_line_pointer
= c
;
827 type
= obj_elf_section_type (beg
, input_line_pointer
- beg
);
838 if (*input_line_pointer
!= '#')
840 as_warn (_("Bad .section directive - character following name is not '#'"));
841 ignore_rest_of_line ();
844 beg
= ++input_line_pointer
;
845 c
= get_symbol_end ();
846 *input_line_pointer
= c
;
848 attr
|= obj_elf_section_word (beg
, input_line_pointer
- beg
);
852 while (*input_line_pointer
++ == ',');
853 --input_line_pointer
;
857 demand_empty_rest_of_line ();
859 obj_elf_change_section (name
, type
, attr
, push
);
862 /* Change to the .data section. */
868 #ifdef md_flush_pending_output
869 md_flush_pending_output ();
872 previous_section
= now_seg
;
873 previous_subsection
= now_subseg
;
876 #ifdef md_elf_section_change_hook
877 md_elf_section_change_hook ();
881 /* Change to the .text section. */
887 #ifdef md_flush_pending_output
888 md_flush_pending_output ();
891 previous_section
= now_seg
;
892 previous_subsection
= now_subseg
;
895 #ifdef md_elf_section_change_hook
896 md_elf_section_change_hook ();
901 obj_elf_subsection (ignore
)
906 #ifdef md_flush_pending_output
907 md_flush_pending_output ();
910 previous_section
= now_seg
;
911 previous_subsection
= now_subseg
;
913 temp
= get_absolute_expression ();
914 subseg_set (now_seg
, (subsegT
) temp
);
915 demand_empty_rest_of_line ();
917 #ifdef md_elf_section_change_hook
918 md_elf_section_change_hook ();
922 /* This can be called from the processor backends if they change
926 obj_elf_section_change_hook ()
928 previous_section
= now_seg
;
929 previous_subsection
= now_subseg
;
933 obj_elf_previous (ignore
)
939 if (previous_section
== 0)
941 as_bad (_(".previous without corresponding .section; ignored"));
945 #ifdef md_flush_pending_output
946 md_flush_pending_output ();
949 new_section
= previous_section
;
950 new_subsection
= previous_subsection
;
951 previous_section
= now_seg
;
952 previous_subsection
= now_subseg
;
953 subseg_set (new_section
, new_subsection
);
955 #ifdef md_elf_section_change_hook
956 md_elf_section_change_hook ();
961 obj_elf_popsection (xxx
)
964 struct section_stack
*top
= section_stack
;
968 as_bad (_(".popsection without corresponding .pushsection; ignored"));
972 #ifdef md_flush_pending_output
973 md_flush_pending_output ();
976 section_stack
= top
->next
;
977 previous_section
= top
->prev_seg
;
978 previous_subsection
= top
->prev_subseg
;
979 subseg_set (top
->seg
, top
->subseg
);
982 #ifdef md_elf_section_change_hook
983 md_elf_section_change_hook ();
988 obj_elf_line (ignore
)
991 /* Assume delimiter is part of expression. BSD4.2 as fails with
992 delightful bug, so we are not being incompatible here. */
993 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
994 demand_empty_rest_of_line ();
997 /* This handles the .symver pseudo-op, which is used to specify a
998 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
999 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1000 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1001 with the same value as the symbol NAME. */
1004 obj_elf_symver (ignore
)
1011 name
= input_line_pointer
;
1012 c
= get_symbol_end ();
1014 sym
= symbol_find_or_make (name
);
1016 *input_line_pointer
= c
;
1018 if (symbol_get_obj (sym
)->versioned_name
!= NULL
)
1020 as_bad (_("multiple .symver directives for symbol `%s'"),
1022 ignore_rest_of_line ();
1027 if (*input_line_pointer
!= ',')
1029 as_bad (_("expected comma after name in .symver"));
1030 ignore_rest_of_line ();
1034 ++input_line_pointer
;
1035 name
= input_line_pointer
;
1038 c
= get_symbol_end ();
1039 if (c
!= ELF_VER_CHR
)
1041 *input_line_pointer
++ = c
;
1044 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
1046 *input_line_pointer
= c
;
1048 if (strchr (symbol_get_obj (sym
)->versioned_name
, ELF_VER_CHR
) == NULL
)
1050 as_bad (_("missing version name in `%s' for symbol `%s'"),
1051 symbol_get_obj (sym
)->versioned_name
, S_GET_NAME (sym
));
1052 ignore_rest_of_line ();
1056 demand_empty_rest_of_line ();
1059 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1060 to the linker the hierarchy in which a particular table resides. The
1061 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1064 obj_elf_vtable_inherit (ignore
)
1066 char *cname
, *pname
;
1067 symbolS
*csym
, *psym
;
1070 if (*input_line_pointer
== '#')
1071 ++input_line_pointer
;
1073 cname
= input_line_pointer
;
1074 c
= get_symbol_end ();
1075 csym
= symbol_find (cname
);
1077 /* GCFIXME: should check that we don't have two .vtable_inherits for
1078 the same child symbol. Also, we can currently only do this if the
1079 child symbol is already exists and is placed in a fragment. */
1081 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1083 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1088 *input_line_pointer
= c
;
1091 if (*input_line_pointer
!= ',')
1093 as_bad ("expected comma after name in .vtable_inherit");
1094 ignore_rest_of_line ();
1098 ++input_line_pointer
;
1101 if (*input_line_pointer
== '#')
1102 ++input_line_pointer
;
1104 if (input_line_pointer
[0] == '0'
1105 && (input_line_pointer
[1] == '\0'
1106 || isspace ((unsigned char) input_line_pointer
[1])))
1108 psym
= section_symbol (absolute_section
);
1109 ++input_line_pointer
;
1113 pname
= input_line_pointer
;
1114 c
= get_symbol_end ();
1115 psym
= symbol_find_or_make (pname
);
1116 *input_line_pointer
= c
;
1119 demand_empty_rest_of_line ();
1124 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1125 fix_new (symbol_get_frag (csym
),
1126 symbol_get_value_expression (csym
)->X_add_number
, 0, psym
, 0, 0,
1127 BFD_RELOC_VTABLE_INHERIT
);
1130 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1131 to the linker that a vtable slot was used. The syntax is
1132 ".vtable_entry tablename, offset". */
1135 obj_elf_vtable_entry (ignore
)
1142 if (*input_line_pointer
== '#')
1143 ++input_line_pointer
;
1145 name
= input_line_pointer
;
1146 c
= get_symbol_end ();
1147 sym
= symbol_find_or_make (name
);
1148 *input_line_pointer
= c
;
1151 if (*input_line_pointer
!= ',')
1153 as_bad ("expected comma after name in .vtable_entry");
1154 ignore_rest_of_line ();
1158 ++input_line_pointer
;
1159 if (*input_line_pointer
== '#')
1160 ++input_line_pointer
;
1162 offset
= get_absolute_expression ();
1164 fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1165 BFD_RELOC_VTABLE_ENTRY
);
1167 demand_empty_rest_of_line ();
1171 obj_read_begin_hook ()
1173 #ifdef NEED_ECOFF_DEBUG
1174 if (ECOFF_DEBUGGING
)
1175 ecoff_read_begin_hook ();
1180 obj_symbol_new_hook (symbolP
)
1183 struct elf_obj_sy
*sy_obj
;
1185 sy_obj
= symbol_get_obj (symbolP
);
1186 sy_obj
->size
= NULL
;
1187 sy_obj
->versioned_name
= NULL
;
1189 #ifdef NEED_ECOFF_DEBUG
1190 if (ECOFF_DEBUGGING
)
1191 ecoff_symbol_new_hook (symbolP
);
1196 obj_elf_version (ignore
)
1203 asection
*seg
= now_seg
;
1204 subsegT subseg
= now_subseg
;
1205 Elf_Internal_Note i_note
;
1206 Elf_External_Note e_note
;
1207 asection
*note_secp
= (asection
*) NULL
;
1211 if (*input_line_pointer
== '\"')
1213 ++input_line_pointer
; /* -> 1st char of string. */
1214 name
= input_line_pointer
;
1216 while (is_a_char (c
= next_char_of_string ()))
1218 c
= *input_line_pointer
;
1219 *input_line_pointer
= '\0';
1220 *(input_line_pointer
- 1) = '\0';
1221 *input_line_pointer
= c
;
1223 /* create the .note section */
1225 note_secp
= subseg_new (".note", 0);
1226 bfd_set_section_flags (stdoutput
,
1228 SEC_HAS_CONTENTS
| SEC_READONLY
);
1230 /* process the version string */
1232 len
= strlen (name
);
1234 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1235 i_note
.descsz
= 0; /* no description */
1236 i_note
.type
= NT_VERSION
;
1237 p
= frag_more (sizeof (e_note
.namesz
));
1238 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1239 p
= frag_more (sizeof (e_note
.descsz
));
1240 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1241 p
= frag_more (sizeof (e_note
.type
));
1242 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1244 for (i
= 0; i
< len
; i
++)
1248 FRAG_APPEND_1_CHAR (ch
);
1251 frag_align (2, 0, 0);
1253 subseg_set (seg
, subseg
);
1257 as_bad (_("Expected quoted string"));
1259 demand_empty_rest_of_line ();
1263 obj_elf_size (ignore
)
1266 char *name
= input_line_pointer
;
1267 char c
= get_symbol_end ();
1272 p
= input_line_pointer
;
1275 if (*input_line_pointer
!= ',')
1278 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1280 ignore_rest_of_line ();
1283 input_line_pointer
++;
1285 if (exp
.X_op
== O_absent
)
1287 as_bad (_("missing expression in .size directive"));
1288 exp
.X_op
= O_constant
;
1289 exp
.X_add_number
= 0;
1292 sym
= symbol_find_or_make (name
);
1294 if (exp
.X_op
== O_constant
)
1295 S_SET_SIZE (sym
, exp
.X_add_number
);
1298 symbol_get_obj (sym
)->size
=
1299 (expressionS
*) xmalloc (sizeof (expressionS
));
1300 *symbol_get_obj (sym
)->size
= exp
;
1302 demand_empty_rest_of_line ();
1305 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1306 There are four syntaxes:
1308 The first (used on Solaris) is
1310 The second (used on UnixWare) is
1312 The third (reportedly to be used on Irix 6.0) is
1314 The fourth (used on NetBSD/Arm and Linux/ARM) is
1319 obj_elf_type (ignore
)
1325 const char *typename
;
1328 name
= input_line_pointer
;
1329 c
= get_symbol_end ();
1330 sym
= symbol_find_or_make (name
);
1331 *input_line_pointer
= c
;
1334 if (*input_line_pointer
== ',')
1335 ++input_line_pointer
;
1338 if ( *input_line_pointer
== '#'
1339 || *input_line_pointer
== '@'
1340 || *input_line_pointer
== '%')
1341 ++input_line_pointer
;
1343 typename
= input_line_pointer
;
1344 c
= get_symbol_end ();
1347 if (strcmp (typename
, "function") == 0
1348 || strcmp (typename
, "STT_FUNC") == 0)
1349 type
= BSF_FUNCTION
;
1350 else if (strcmp (typename
, "object") == 0
1351 || strcmp (typename
, "STT_OBJECT") == 0)
1354 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1356 *input_line_pointer
= c
;
1358 symbol_get_bfdsym (sym
)->flags
|= type
;
1360 demand_empty_rest_of_line ();
1364 obj_elf_ident (ignore
)
1367 static segT comment_section
;
1368 segT old_section
= now_seg
;
1369 int old_subsection
= now_subseg
;
1371 if (!comment_section
)
1374 comment_section
= subseg_new (".comment", 0);
1375 bfd_set_section_flags (stdoutput
, comment_section
,
1376 SEC_READONLY
| SEC_HAS_CONTENTS
);
1381 subseg_set (comment_section
, 0);
1383 subseg_set (old_section
, old_subsection
);
1386 #ifdef INIT_STAB_SECTION
1388 /* The first entry in a .stabs section is special. */
1391 obj_elf_init_stab_section (seg
)
1397 unsigned int stroff
;
1399 /* Force the section to align to a longword boundary. Without this,
1400 UnixWare ar crashes. */
1401 bfd_set_section_alignment (stdoutput
, seg
, 2);
1403 /* Make space for this first symbol. */
1407 as_where (&file
, (unsigned int *) NULL
);
1408 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1409 strcpy (stabstr_name
, segment_name (seg
));
1410 strcat (stabstr_name
, "str");
1411 stroff
= get_stab_string_offset (file
, stabstr_name
);
1413 md_number_to_chars (p
, stroff
, 4);
1414 seg_info (seg
)->stabu
.p
= p
;
1419 /* Fill in the counts in the first entry in a .stabs section. */
1422 adjust_stab_sections (abfd
, sec
, xxx
)
1432 if (strncmp (".stab", sec
->name
, 5))
1434 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1437 name
= (char *) alloca (strlen (sec
->name
) + 4);
1438 strcpy (name
, sec
->name
);
1439 strcat (name
, "str");
1440 strsec
= bfd_get_section_by_name (abfd
, name
);
1442 strsz
= bfd_section_size (abfd
, strsec
);
1445 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1447 p
= seg_info (sec
)->stabu
.p
;
1450 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1451 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1454 #ifdef NEED_ECOFF_DEBUG
1456 /* This function is called by the ECOFF code. It is supposed to
1457 record the external symbol information so that the backend can
1458 write it out correctly. The ELF backend doesn't actually handle
1459 this at the moment, so we do it ourselves. We save the information
1463 elf_ecoff_set_ext (sym
, ext
)
1465 struct ecoff_extr
*ext
;
1467 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1470 /* This function is called by bfd_ecoff_debug_externals. It is
1471 supposed to *EXT to the external symbol information, and return
1472 whether the symbol should be used at all. */
1475 elf_get_extr (sym
, ext
)
1479 if (sym
->udata
.p
== NULL
)
1481 *ext
= *(EXTR
*) sym
->udata
.p
;
1485 /* This function is called by bfd_ecoff_debug_externals. It has
1486 nothing to do for ELF. */
1490 elf_set_index (sym
, indx
)
1496 #endif /* NEED_ECOFF_DEBUG */
1499 elf_frob_symbol (symp
, puntp
)
1503 struct elf_obj_sy
*sy_obj
;
1505 #ifdef NEED_ECOFF_DEBUG
1506 if (ECOFF_DEBUGGING
)
1507 ecoff_frob_symbol (symp
);
1510 sy_obj
= symbol_get_obj (symp
);
1512 if (sy_obj
->size
!= NULL
)
1514 switch (sy_obj
->size
->X_op
)
1518 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1519 + sy_obj
->size
->X_add_number
1520 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1524 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1525 + sy_obj
->size
->X_add_number
));
1528 as_bad (_(".size expression too complicated to fix up"));
1531 free (sy_obj
->size
);
1532 sy_obj
->size
= NULL
;
1535 if (sy_obj
->versioned_name
!= NULL
)
1537 /* This symbol was given a new name with the .symver directive.
1539 If this is an external reference, just rename the symbol to
1540 include the version string. This will make the relocs be
1541 against the correct versioned symbol.
1543 If this is a definition, add an alias. FIXME: Using an alias
1544 will permit the debugging information to refer to the right
1545 symbol. However, it's not clear whether it is the best
1548 if (! S_IS_DEFINED (symp
))
1552 /* Verify that the name isn't using the @@ syntax--this is
1553 reserved for definitions of the default version to link
1555 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1557 if (p
[1] == ELF_VER_CHR
)
1559 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1560 sy_obj
->versioned_name
);
1563 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1569 /* FIXME: Creating a new symbol here is risky. We're in the
1570 final loop over the symbol table. We can get away with
1571 it only because the symbol goes to the end of the list,
1572 where the loop will still see it. It would probably be
1573 better to do this in obj_frob_file_before_adjust. */
1575 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1577 /* Now we act as though we saw symp2 = sym. */
1579 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1581 /* Subtracting out the frag address here is a hack because
1582 we are in the middle of the final loop. */
1585 - symbol_get_frag (symp
)->fr_address
));
1587 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1589 /* This will copy over the size information. */
1590 copy_symbol_attributes (symp2
, symp
);
1592 if (S_IS_WEAK (symp
))
1595 if (S_IS_EXTERNAL (symp
))
1596 S_SET_EXTERNAL (symp2
);
1600 /* Double check weak symbols. */
1601 if (S_IS_WEAK (symp
))
1603 if (S_IS_COMMON (symp
))
1604 as_bad (_("Symbol `%s' can not be both weak and common"),
1609 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1610 any undefined non-function symbol to STT_OBJECT. We try to be
1611 compatible, since newer Irix 5 and 6 linkers care. However, we
1612 only set undefined symbols to be STT_OBJECT if we are on Irix,
1613 because that is the only time gcc will generate the necessary
1614 .global directives to mark functions. */
1616 if (S_IS_COMMON (symp
))
1617 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1619 if (strstr (TARGET_OS
, "irix") != NULL
1620 && ! S_IS_DEFINED (symp
)
1621 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1622 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1626 /* Frob the PowerPC, so that the symbol always has object type
1627 if it is not some other type. VxWorks needs this. */
1628 if ((symbol_get_bfdsym (symp
)->flags
1629 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1630 && S_IS_DEFINED (symp
))
1631 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1638 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1640 #ifdef elf_tc_final_processing
1641 elf_tc_final_processing ();
1645 /* It is required that we let write_relocs have the opportunity to
1646 optimize away fixups before output has begun, since it is possible
1647 to eliminate all fixups for a section and thus we never should
1648 have generated the relocation section. */
1651 elf_frob_file_after_relocs ()
1653 #ifdef NEED_ECOFF_DEBUG
1654 if (ECOFF_DEBUGGING
)
1655 /* Generate the ECOFF debugging information. */
1657 const struct ecoff_debug_swap
*debug_swap
;
1658 struct ecoff_debug_info debug
;
1663 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1664 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1665 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1667 /* Set up the pointers in debug. */
1668 #define SET(ptr, offset, type) \
1669 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1671 SET (line
, cbLineOffset
, unsigned char *);
1672 SET (external_dnr
, cbDnOffset
, PTR
);
1673 SET (external_pdr
, cbPdOffset
, PTR
);
1674 SET (external_sym
, cbSymOffset
, PTR
);
1675 SET (external_opt
, cbOptOffset
, PTR
);
1676 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1677 SET (ss
, cbSsOffset
, char *);
1678 SET (external_fdr
, cbFdOffset
, PTR
);
1679 SET (external_rfd
, cbRfdOffset
, PTR
);
1680 /* ssext and external_ext are set up just below. */
1684 /* Set up the external symbols. */
1685 debug
.ssext
= debug
.ssext_end
= NULL
;
1686 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1687 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1688 elf_get_extr
, elf_set_index
))
1689 as_fatal (_("Failed to set up debugging information: %s"),
1690 bfd_errmsg (bfd_get_error ()));
1692 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1693 assert (sec
!= NULL
);
1695 know (stdoutput
->output_has_begun
== false);
1697 /* We set the size of the section, call bfd_set_section_contents
1698 to force the ELF backend to allocate a file position, and then
1699 write out the data. FIXME: Is this really the best way to do
1701 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1703 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1704 (file_ptr
) 0, (bfd_size_type
) 0))
1705 as_fatal (_("Can't start writing .mdebug section: %s"),
1706 bfd_errmsg (bfd_get_error ()));
1708 know (stdoutput
->output_has_begun
== true);
1709 know (sec
->filepos
!= 0);
1711 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1713 as_fatal (_("Could not write .mdebug section: %s"),
1714 bfd_errmsg (bfd_get_error ()));
1716 #endif /* NEED_ECOFF_DEBUG */
1721 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1722 SCO specific identifier in the .notes section to satisfy the SCO
1725 This looks more complicated than it really is. As opposed to the
1726 "obvious" solution, this should handle the cross dev cases
1727 correctly. (i.e, hosting on a 64 bit big endian processor, but
1728 generating SCO Elf code) Efficiency isn't a concern, as there
1729 should be exactly one of these sections per object module.
1731 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1734 int_32 namesz = 4 ; Name size
1735 int_32 descsz = 12 ; Descriptive information
1737 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1738 int_32 version = (major ver # << 16) | version of tools ;
1739 int_32 source = (tool_id << 16 ) | 1 ;
1740 int_32 info = 0 ; These are set by the SCO tools, but we
1741 don't know enough about the source
1742 environment to set them. SCO ld currently
1743 ignores them, and recommends we set them
1746 #define SCO_MAJOR_VERSION 0x1
1747 #define SCO_MINOR_VERSION 0x1
1757 asection
*seg
= now_seg
;
1758 subsegT subseg
= now_subseg
;
1759 Elf_Internal_Note i_note
;
1760 Elf_External_Note e_note
;
1761 asection
*note_secp
= (asection
*) NULL
;
1764 /* create the .note section */
1766 note_secp
= subseg_new (".note", 0);
1767 bfd_set_section_flags (stdoutput
,
1769 SEC_HAS_CONTENTS
| SEC_READONLY
);
1771 /* process the version string */
1774 i_note
.descsz
= 12; /* 12 descriptive bytes */
1775 i_note
.type
= NT_VERSION
; /* Contains a version string */
1777 p
= frag_more (sizeof (i_note
.namesz
));
1778 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1780 p
= frag_more (sizeof (i_note
.descsz
));
1781 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1783 p
= frag_more (sizeof (i_note
.type
));
1784 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1789 /* Note: this is the version number of the ELF we're representing */
1791 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1793 /* Here, we pick a magic number for ourselves (yes, I "registered"
1794 it with SCO. The bottom bit shows that we are compat with the
1797 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1799 /* If we knew (or cared) what the source language options were, we'd
1800 fill them in here. SCO has given us permission to ignore these
1801 and just set them to zero. */
1803 md_number_to_chars (p
, 0x0000, 4);
1805 frag_align (2, 0, 0);
1807 /* We probably can't restore the current segment, for there likely
1810 subseg_set (seg
, subseg
);
1814 #endif /* SCO_ELF */
1816 const struct format_ops elf_format_ops
=
1818 bfd_target_elf_flavour
,
1823 elf_frob_file_after_relocs
,
1824 elf_s_get_size
, elf_s_set_size
,
1825 elf_s_get_align
, elf_s_set_align
,
1826 elf_copy_symbol_attributes
,
1827 #ifdef NEED_ECOFF_DEBUG
1828 ecoff_generate_asm_lineno
,
1832 0, /* process_stab */
1834 elf_sec_sym_ok_for_reloc
,
1836 #ifdef NEED_ECOFF_DEBUG
1841 obj_read_begin_hook
,
1842 obj_symbol_new_hook
,