1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999
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"
49 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
50 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
51 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
52 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
53 static void elf_copy_symbol_attributes
PARAMS ((symbolS
*, symbolS
*));
54 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
55 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
57 #ifdef NEED_ECOFF_DEBUG
58 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
59 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
62 static void obj_elf_line
PARAMS ((int));
63 void obj_elf_version
PARAMS ((int));
64 static void obj_elf_size
PARAMS ((int));
65 static void obj_elf_type
PARAMS ((int));
66 static void obj_elf_ident
PARAMS ((int));
67 static void obj_elf_weak
PARAMS ((int));
68 static void obj_elf_local
PARAMS ((int));
69 static void obj_elf_common
PARAMS ((int));
70 static void obj_elf_symver
PARAMS ((int));
71 static void obj_elf_vtable_inherit
PARAMS ((int));
72 static void obj_elf_vtable_entry
PARAMS ((int));
73 static void obj_elf_data
PARAMS ((int));
74 static void obj_elf_text
PARAMS ((int));
75 static void obj_elf_subsection
PARAMS ((int));
77 static const pseudo_typeS elf_pseudo_table
[] =
79 {"comm", obj_elf_common
, 0},
80 {"ident", obj_elf_ident
, 0},
81 {"local", obj_elf_local
, 0},
82 {"previous", obj_elf_previous
, 0},
83 {"section", obj_elf_section
, 0},
84 {"section.s", obj_elf_section
, 0},
85 {"sect", obj_elf_section
, 0},
86 {"sect.s", obj_elf_section
, 0},
87 {"size", obj_elf_size
, 0},
88 {"type", obj_elf_type
, 0},
89 {"version", obj_elf_version
, 0},
90 {"weak", obj_elf_weak
, 0},
92 /* These are used for stabs-in-elf configurations. */
93 {"line", obj_elf_line
, 0},
95 /* This is a GNU extension to handle symbol versions. */
96 {"symver", obj_elf_symver
, 0},
98 /* A GNU extension to change subsection only. */
99 {"subsection", obj_elf_subsection
, 0},
101 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
102 {"vtable_inherit", obj_elf_vtable_inherit
, 0},
103 {"vtable_entry", obj_elf_vtable_entry
, 0},
105 /* These are used for dwarf. */
110 /* We need to trap the section changing calls to handle .previous. */
111 {"data", obj_elf_data
, 0},
112 {"text", obj_elf_text
, 0},
118 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
120 #ifdef NEED_ECOFF_DEBUG
121 /* COFF style debugging information for ECOFF. .ln is not used; .loc
123 { "def", ecoff_directive_def
, 0 },
124 { "dim", ecoff_directive_dim
, 0 },
125 { "endef", ecoff_directive_endef
, 0 },
126 { "file", ecoff_directive_file
, 0 },
127 { "scl", ecoff_directive_scl
, 0 },
128 { "tag", ecoff_directive_tag
, 0 },
129 { "val", ecoff_directive_val
, 0 },
131 /* COFF debugging requires pseudo-ops .size and .type, but ELF
132 already has meanings for those. We use .esize and .etype
133 instead. These are only generated by gcc anyhow. */
134 { "esize", ecoff_directive_size
, 0 },
135 { "etype", ecoff_directive_type
, 0 },
137 /* ECOFF specific debugging information. */
138 { "begin", ecoff_directive_begin
, 0 },
139 { "bend", ecoff_directive_bend
, 0 },
140 { "end", ecoff_directive_end
, 0 },
141 { "ent", ecoff_directive_ent
, 0 },
142 { "fmask", ecoff_directive_fmask
, 0 },
143 { "frame", ecoff_directive_frame
, 0 },
144 { "loc", ecoff_directive_loc
, 0 },
145 { "mask", ecoff_directive_mask
, 0 },
147 /* Other ECOFF directives. */
148 { "extern", ecoff_directive_extern
, 0 },
150 /* These are used on Irix. I don't know how to implement them. */
151 { "alias", s_ignore
, 0 },
152 { "bgnb", s_ignore
, 0 },
153 { "endb", s_ignore
, 0 },
154 { "lab", s_ignore
, 0 },
155 { "noalias", s_ignore
, 0 },
156 { "verstamp", s_ignore
, 0 },
157 { "vreg", s_ignore
, 0 },
160 {NULL
} /* end sentinel */
164 #include "aout/aout64.h"
166 /* This is called when the assembler starts. */
171 /* Add symbols for the known sections to the symbol table. */
172 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
173 TEXT_SECTION_NAME
)));
174 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
175 DATA_SECTION_NAME
)));
176 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
183 pop_insert (elf_pseudo_table
);
185 pop_insert (ecoff_debug_pseudo_table
);
192 return S_GET_SIZE (sym
);
196 elf_s_set_size (sym
, sz
)
200 S_SET_SIZE (sym
, sz
);
204 elf_s_get_align (sym
)
207 return S_GET_ALIGN (sym
);
211 elf_s_set_align (sym
, align
)
215 S_SET_ALIGN (sym
, align
);
219 elf_copy_symbol_attributes (dest
, src
)
222 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
226 elf_sec_sym_ok_for_reloc (sec
)
229 return obj_sec_sym_ok_for_reloc (sec
);
238 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
239 symbol_set_frag (sym
, &zero_address_frag
);
240 symbol_get_bfdsym (sym
)->flags
|= BSF_FILE
;
242 if (symbol_rootP
!= sym
)
244 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
245 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
247 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
251 #ifdef NEED_ECOFF_DEBUG
257 obj_elf_common (ignore
)
267 name
= input_line_pointer
;
268 c
= get_symbol_end ();
269 /* just after name is now '\0' */
270 p
= input_line_pointer
;
273 if (*input_line_pointer
!= ',')
275 as_bad (_("Expected comma after symbol-name"));
276 ignore_rest_of_line ();
279 input_line_pointer
++; /* skip ',' */
280 if ((temp
= get_absolute_expression ()) < 0)
282 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp
);
283 ignore_rest_of_line ();
288 symbolP
= symbol_find_or_make (name
);
290 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
292 as_bad (_("Ignoring attempt to re-define symbol"));
293 ignore_rest_of_line ();
296 if (S_GET_VALUE (symbolP
) != 0)
298 if (S_GET_VALUE (symbolP
) != size
)
300 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
301 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
304 know (symbolP
->sy_frag
== &zero_address_frag
);
305 if (*input_line_pointer
!= ',')
310 input_line_pointer
++;
313 if (! have_align
|| *input_line_pointer
!= '"')
319 temp
= get_absolute_expression ();
323 as_warn (_("Common alignment negative; 0 assumed"));
326 if (symbol_get_obj (symbolP
)->local
)
335 old_subsec
= now_subseg
;
338 /* convert to a power of 2 alignment */
339 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
342 as_bad (_("Common alignment not a power of 2"));
343 ignore_rest_of_line ();
349 record_alignment (bss_section
, align
);
350 subseg_set (bss_section
, 0);
352 frag_align (align
, 0, 0);
353 if (S_GET_SEGMENT (symbolP
) == bss_section
)
354 symbol_get_frag (symbolP
)->fr_symbol
= 0;
355 symbol_set_frag (symbolP
, frag_now
);
356 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
357 (offsetT
) size
, (char *) 0);
359 S_SET_SIZE (symbolP
, size
);
360 S_SET_SEGMENT (symbolP
, bss_section
);
361 S_CLEAR_EXTERNAL (symbolP
);
362 subseg_set (old_sec
, old_subsec
);
367 S_SET_VALUE (symbolP
, (valueT
) size
);
368 S_SET_ALIGN (symbolP
, temp
);
369 S_SET_EXTERNAL (symbolP
);
370 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
375 input_line_pointer
++;
376 /* @@ Some use the dot, some don't. Can we get some consistency?? */
377 if (*input_line_pointer
== '.')
378 input_line_pointer
++;
379 /* @@ Some say data, some say bss. */
380 if (strncmp (input_line_pointer
, "bss\"", 4)
381 && strncmp (input_line_pointer
, "data\"", 5))
383 while (*--input_line_pointer
!= '"')
385 input_line_pointer
--;
386 goto bad_common_segment
;
388 while (*input_line_pointer
++ != '"')
390 goto allocate_common
;
393 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
395 demand_empty_rest_of_line ();
400 p
= input_line_pointer
;
401 while (*p
&& *p
!= '\n')
405 as_bad (_("bad .common segment %s"), input_line_pointer
+ 1);
407 input_line_pointer
= p
;
408 ignore_rest_of_line ();
414 obj_elf_local (ignore
)
423 name
= input_line_pointer
;
424 c
= get_symbol_end ();
425 symbolP
= symbol_find_or_make (name
);
426 *input_line_pointer
= c
;
428 S_CLEAR_EXTERNAL (symbolP
);
429 symbol_get_obj (symbolP
)->local
= 1;
432 input_line_pointer
++;
434 if (*input_line_pointer
== '\n')
439 demand_empty_rest_of_line ();
443 obj_elf_weak (ignore
)
452 name
= input_line_pointer
;
453 c
= get_symbol_end ();
454 symbolP
= symbol_find_or_make (name
);
455 *input_line_pointer
= c
;
457 S_SET_WEAK (symbolP
);
458 symbol_get_obj (symbolP
)->local
= 1;
461 input_line_pointer
++;
463 if (*input_line_pointer
== '\n')
468 demand_empty_rest_of_line ();
471 static segT previous_section
;
472 static int previous_subsection
;
474 /* Handle the .section pseudo-op. This code supports two different
477 The first is found on Solaris, and looks like
478 .section ".sec1",#alloc,#execinstr,#write
479 Here the names after '#' are the SHF_* flags to turn on for the
480 section. I'm not sure how it determines the SHT_* type (BFD
481 doesn't really give us control over the type, anyhow).
483 The second format is found on UnixWare, and probably most SVR4
484 machines, and looks like
485 .section .sec1,"a",@progbits
486 The quoted string may contain any combination of a, w, x, and
487 represents the SHF_* flags to turn on for the section. The string
488 beginning with '@' can be progbits or nobits. There should be
489 other possibilities, but I don't know what they are. In any case,
490 BFD doesn't really let us set the section type. */
492 /* Certain named sections have particular defined types, listed on p.
494 struct special_section
501 static struct special_section special_sections
[] =
503 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
504 { ".comment", SHT_PROGBITS
, 0 },
505 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
506 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
507 { ".debug", SHT_PROGBITS
, 0 },
508 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
509 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
510 { ".line", SHT_PROGBITS
, 0 },
511 { ".note", SHT_NOTE
, 0 },
512 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
513 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
514 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
516 #ifdef ELF_TC_SPECIAL_SECTIONS
517 ELF_TC_SPECIAL_SECTIONS
521 /* The following section names are special, but they can not
522 reasonably appear in assembler code. Some of the attributes are
523 processor dependent. */
524 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
525 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
526 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
527 { ".got", SHT_PROGBITS
, 0 },
528 { ".hash", SHT_HASH
, SHF_ALLOC
},
529 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
530 { ".plt", SHT_PROGBITS
, 0 },
531 { ".shstrtab",SHT_STRTAB
, 0 },
532 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
533 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
540 obj_elf_section (xxx
)
551 #ifdef md_flush_pending_output
552 md_flush_pending_output ();
559 previous_section
= now_seg
;
560 previous_subsection
= now_subseg
;
562 s_mri_sect (&mri_type
);
564 #ifdef md_elf_section_change_hook
565 md_elf_section_change_hook ();
571 /* Get name of section. */
573 if (*input_line_pointer
== '"')
575 string
= demand_copy_C_string (&xxx
);
578 ignore_rest_of_line ();
584 char *p
= input_line_pointer
;
586 while (0 == strchr ("\n\t,; ", *p
))
588 if (p
== input_line_pointer
)
590 as_warn (_("Missing section name"));
591 ignore_rest_of_line ();
596 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
597 strcpy (string
, input_line_pointer
);
599 input_line_pointer
= p
;
602 /* Switch to the section, creating it if necessary. */
603 previous_section
= now_seg
;
604 previous_subsection
= now_subseg
;
606 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
607 sec
= subseg_new (string
, 0);
609 /* If this section already existed, we don't bother to change the
613 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
614 ++input_line_pointer
;
615 ++input_line_pointer
;
617 #ifdef md_elf_section_change_hook
618 md_elf_section_change_hook ();
629 if (*input_line_pointer
== ',')
631 /* Skip the comma. */
632 ++input_line_pointer
;
636 if (*input_line_pointer
== '"')
638 /* Pick up a string with a combination of a, w, x. */
639 ++input_line_pointer
;
640 while (*input_line_pointer
!= '"')
642 switch (*input_line_pointer
)
651 attr
|= SHF_EXECINSTR
;
655 char *bad_msg
= _("Bad .section directive: want a,w,x in string");
656 #ifdef md_elf_section_letter
657 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
664 ignore_rest_of_line ();
669 ++input_line_pointer
;
672 /* Skip the closing quote. */
673 ++input_line_pointer
;
676 if (*input_line_pointer
== ',')
678 ++input_line_pointer
;
680 if (*input_line_pointer
== '@' || *input_line_pointer
== '%')
682 ++input_line_pointer
;
683 if (strncmp (input_line_pointer
, "progbits",
684 sizeof "progbits" - 1) == 0)
687 input_line_pointer
+= sizeof "progbits" - 1;
689 else if (strncmp (input_line_pointer
, "nobits",
690 sizeof "nobits" - 1) == 0)
693 input_line_pointer
+= sizeof "nobits" - 1;
697 #ifdef md_elf_section_type
698 int md_type
= md_elf_section_type (&input_line_pointer
);
704 as_warn (_("Unrecognized section type"));
705 ignore_rest_of_line ();
716 if (*input_line_pointer
!= '#')
718 as_warn (_("Bad .section directive - character following name is not '#'"));
719 ignore_rest_of_line ();
722 ++input_line_pointer
;
723 if (strncmp (input_line_pointer
, "write",
724 sizeof "write" - 1) == 0)
727 input_line_pointer
+= sizeof "write" - 1;
729 else if (strncmp (input_line_pointer
, "alloc",
730 sizeof "alloc" - 1) == 0)
733 input_line_pointer
+= sizeof "alloc" - 1;
735 else if (strncmp (input_line_pointer
, "execinstr",
736 sizeof "execinstr" - 1) == 0)
738 attr
|= SHF_EXECINSTR
;
739 input_line_pointer
+= sizeof "execinstr" - 1;
743 #ifdef md_elf_section_word
744 int md_attr
= md_elf_section_word (&input_line_pointer
);
750 as_warn (_("Unrecognized section attribute"));
751 ignore_rest_of_line ();
757 while (*input_line_pointer
++ == ',');
758 --input_line_pointer
;
762 /* See if this is one of the special sections. */
763 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
765 if (string
[1] == special_sections
[i
].name
[1]
766 && strcmp (string
, special_sections
[i
].name
) == 0)
768 if (type
== SHT_NULL
)
769 type
= special_sections
[i
].type
;
770 else if (type
!= special_sections
[i
].type
)
771 as_warn (_("Setting incorrect section type for %s"), string
);
773 if ((attr
&~ special_sections
[i
].attributes
) != 0)
775 /* As a GNU extension, we permit a .note section to be
776 allocatable. If the linker sees an allocateable
777 .note section, it will create a PT_NOTE segment in
779 if (strcmp (string
, ".note") != 0
780 || attr
!= SHF_ALLOC
)
781 as_warn (_("Setting incorrect section attributes for %s"),
784 attr
|= special_sections
[i
].attributes
;
791 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
792 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
793 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
794 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
795 if (special_sections
[i
].name
== NULL
)
797 if (type
== SHT_PROGBITS
)
798 flags
|= SEC_ALLOC
| SEC_LOAD
;
799 else if (type
== SHT_NOBITS
)
805 #ifdef md_elf_section_flags
806 flags
= md_elf_section_flags (flags
, attr
, type
);
810 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
811 if (type
== SHT_NOBITS
)
812 seg_info (sec
)->bss
= 1;
814 bfd_set_section_flags (stdoutput
, sec
, flags
);
816 /* Add a symbol for this section to the symbol table. */
817 secsym
= symbol_find (string
);
819 symbol_set_bfdsym (secsym
, sec
->symbol
);
821 symbol_table_insert (section_symbol (sec
));
823 #ifdef md_elf_section_change_hook
824 md_elf_section_change_hook ();
827 demand_empty_rest_of_line ();
830 /* Change to the .data section. */
836 #ifdef md_flush_pending_output
837 md_flush_pending_output ();
840 previous_section
= now_seg
;
841 previous_subsection
= now_subseg
;
844 #ifdef md_elf_section_change_hook
845 md_elf_section_change_hook ();
849 /* Change to the .text section. */
855 #ifdef md_flush_pending_output
856 md_flush_pending_output ();
859 previous_section
= now_seg
;
860 previous_subsection
= now_subseg
;
863 #ifdef md_elf_section_change_hook
864 md_elf_section_change_hook ();
869 obj_elf_subsection (ignore
)
874 #ifdef md_flush_pending_output
875 md_flush_pending_output ();
878 previous_section
= now_seg
;
879 previous_subsection
= now_subseg
;
881 temp
= get_absolute_expression ();
882 subseg_set (now_seg
, (subsegT
) temp
);
883 demand_empty_rest_of_line ();
885 #ifdef md_elf_section_change_hook
886 md_elf_section_change_hook ();
890 /* This can be called from the processor backends if they change
894 obj_elf_section_change_hook ()
896 previous_section
= now_seg
;
897 previous_subsection
= now_subseg
;
901 obj_elf_previous (ignore
)
904 if (previous_section
== 0)
906 as_bad (_(".previous without corresponding .section; ignored"));
910 #ifdef md_flush_pending_output
911 md_flush_pending_output ();
914 subseg_set (previous_section
, previous_subsection
);
915 previous_section
= 0;
917 #ifdef md_elf_section_change_hook
918 md_elf_section_change_hook ();
923 obj_elf_line (ignore
)
926 /* Assume delimiter is part of expression. BSD4.2 as fails with
927 delightful bug, so we are not being incompatible here. */
928 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
929 demand_empty_rest_of_line ();
932 /* This handles the .symver pseudo-op, which is used to specify a
933 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
934 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
935 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
936 with the same value as the symbol NAME. */
939 obj_elf_symver (ignore
)
946 name
= input_line_pointer
;
947 c
= get_symbol_end ();
949 sym
= symbol_find_or_make (name
);
951 *input_line_pointer
= c
;
953 if (symbol_get_obj (sym
)->versioned_name
!= NULL
)
955 as_bad (_("multiple .symver directives for symbol `%s'"),
957 ignore_rest_of_line ();
962 if (*input_line_pointer
!= ',')
964 as_bad (_("expected comma after name in .symver"));
965 ignore_rest_of_line ();
969 ++input_line_pointer
;
970 name
= input_line_pointer
;
973 c
= get_symbol_end ();
974 if (c
!= ELF_VER_CHR
)
976 *input_line_pointer
++ = c
;
979 symbol_get_obj (sym
)->versioned_name
= xstrdup (name
);
981 *input_line_pointer
= c
;
983 if (strchr (symbol_get_obj (sym
)->versioned_name
, ELF_VER_CHR
) == NULL
)
985 as_bad (_("missing version name in `%s' for symbol `%s'"),
986 symbol_get_obj (sym
)->versioned_name
, S_GET_NAME (sym
));
987 ignore_rest_of_line ();
991 demand_empty_rest_of_line ();
994 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
995 to the linker the hierarchy in which a particular table resides. The
996 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
999 obj_elf_vtable_inherit (ignore
)
1001 char *cname
, *pname
;
1002 symbolS
*csym
, *psym
;
1005 if (*input_line_pointer
== '#')
1006 ++input_line_pointer
;
1008 cname
= input_line_pointer
;
1009 c
= get_symbol_end ();
1010 csym
= symbol_find (cname
);
1012 /* GCFIXME: should check that we don't have two .vtable_inherits for
1013 the same child symbol. Also, we can currently only do this if the
1014 child symbol is already exists and is placed in a fragment. */
1016 if (csym
== NULL
|| symbol_get_frag (csym
) == NULL
)
1018 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1023 *input_line_pointer
= c
;
1026 if (*input_line_pointer
!= ',')
1028 as_bad ("expected comma after name in .vtable_inherit");
1029 ignore_rest_of_line ();
1033 ++input_line_pointer
;
1036 if (*input_line_pointer
== '#')
1037 ++input_line_pointer
;
1039 if (input_line_pointer
[0] == '0'
1040 && (input_line_pointer
[1] == '\0'
1041 || isspace ((unsigned char) input_line_pointer
[1])))
1043 psym
= section_symbol (absolute_section
);
1044 ++input_line_pointer
;
1048 pname
= input_line_pointer
;
1049 c
= get_symbol_end ();
1050 psym
= symbol_find_or_make (pname
);
1051 *input_line_pointer
= c
;
1054 demand_empty_rest_of_line ();
1059 assert (symbol_get_value_expression (csym
)->X_op
== O_constant
);
1060 fix_new (symbol_get_frag (csym
),
1061 symbol_get_value_expression (csym
)->X_add_number
, 0, psym
, 0, 0,
1062 BFD_RELOC_VTABLE_INHERIT
);
1065 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1066 to the linker that a vtable slot was used. The syntax is
1067 ".vtable_entry tablename, offset". */
1070 obj_elf_vtable_entry (ignore
)
1077 if (*input_line_pointer
== '#')
1078 ++input_line_pointer
;
1080 name
= input_line_pointer
;
1081 c
= get_symbol_end ();
1082 sym
= symbol_find_or_make (name
);
1083 *input_line_pointer
= c
;
1086 if (*input_line_pointer
!= ',')
1088 as_bad ("expected comma after name in .vtable_entry");
1089 ignore_rest_of_line ();
1093 ++input_line_pointer
;
1094 if (*input_line_pointer
== '#')
1095 ++input_line_pointer
;
1097 offset
= get_absolute_expression ();
1099 fix_new (frag_now
, frag_now_fix (), 0, sym
, offset
, 0,
1100 BFD_RELOC_VTABLE_ENTRY
);
1102 demand_empty_rest_of_line ();
1106 obj_read_begin_hook ()
1108 #ifdef NEED_ECOFF_DEBUG
1109 if (ECOFF_DEBUGGING
)
1110 ecoff_read_begin_hook ();
1115 obj_symbol_new_hook (symbolP
)
1118 struct elf_obj_sy
*sy_obj
;
1120 sy_obj
= symbol_get_obj (symbolP
);
1121 sy_obj
->size
= NULL
;
1122 sy_obj
->versioned_name
= NULL
;
1124 #ifdef NEED_ECOFF_DEBUG
1125 if (ECOFF_DEBUGGING
)
1126 ecoff_symbol_new_hook (symbolP
);
1131 obj_elf_version (ignore
)
1138 asection
*seg
= now_seg
;
1139 subsegT subseg
= now_subseg
;
1140 Elf_Internal_Note i_note
;
1141 Elf_External_Note e_note
;
1142 asection
*note_secp
= (asection
*) NULL
;
1146 if (*input_line_pointer
== '\"')
1148 ++input_line_pointer
; /* -> 1st char of string. */
1149 name
= input_line_pointer
;
1151 while (is_a_char (c
= next_char_of_string ()))
1153 c
= *input_line_pointer
;
1154 *input_line_pointer
= '\0';
1155 *(input_line_pointer
- 1) = '\0';
1156 *input_line_pointer
= c
;
1158 /* create the .note section */
1160 note_secp
= subseg_new (".note", 0);
1161 bfd_set_section_flags (stdoutput
,
1163 SEC_HAS_CONTENTS
| SEC_READONLY
);
1165 /* process the version string */
1167 len
= strlen (name
);
1169 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1170 i_note
.descsz
= 0; /* no description */
1171 i_note
.type
= NT_VERSION
;
1172 p
= frag_more (sizeof (e_note
.namesz
));
1173 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1174 p
= frag_more (sizeof (e_note
.descsz
));
1175 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1176 p
= frag_more (sizeof (e_note
.type
));
1177 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1179 for (i
= 0; i
< len
; i
++)
1183 FRAG_APPEND_1_CHAR (ch
);
1186 frag_align (2, 0, 0);
1188 subseg_set (seg
, subseg
);
1192 as_bad (_("Expected quoted string"));
1194 demand_empty_rest_of_line ();
1198 obj_elf_size (ignore
)
1201 char *name
= input_line_pointer
;
1202 char c
= get_symbol_end ();
1207 p
= input_line_pointer
;
1210 if (*input_line_pointer
!= ',')
1213 as_bad (_("expected comma after name `%s' in .size directive"), name
);
1215 ignore_rest_of_line ();
1218 input_line_pointer
++;
1220 if (exp
.X_op
== O_absent
)
1222 as_bad (_("missing expression in .size directive"));
1223 exp
.X_op
= O_constant
;
1224 exp
.X_add_number
= 0;
1227 sym
= symbol_find_or_make (name
);
1229 if (exp
.X_op
== O_constant
)
1230 S_SET_SIZE (sym
, exp
.X_add_number
);
1233 symbol_get_obj (sym
)->size
=
1234 (expressionS
*) xmalloc (sizeof (expressionS
));
1235 *symbol_get_obj (sym
)->size
= exp
;
1237 demand_empty_rest_of_line ();
1240 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1241 There are four syntaxes:
1243 The first (used on Solaris) is
1245 The second (used on UnixWare) is
1247 The third (reportedly to be used on Irix 6.0) is
1249 The fourth (used on NetBSD/Arm and Linux/ARM) is
1254 obj_elf_type (ignore
)
1260 const char *typename
;
1263 name
= input_line_pointer
;
1264 c
= get_symbol_end ();
1265 sym
= symbol_find_or_make (name
);
1266 *input_line_pointer
= c
;
1269 if (*input_line_pointer
== ',')
1270 ++input_line_pointer
;
1273 if ( *input_line_pointer
== '#'
1274 || *input_line_pointer
== '@'
1275 || *input_line_pointer
== '%')
1276 ++input_line_pointer
;
1278 typename
= input_line_pointer
;
1279 c
= get_symbol_end ();
1282 if (strcmp (typename
, "function") == 0
1283 || strcmp (typename
, "STT_FUNC") == 0)
1284 type
= BSF_FUNCTION
;
1285 else if (strcmp (typename
, "object") == 0
1286 || strcmp (typename
, "STT_OBJECT") == 0)
1289 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename
);
1291 *input_line_pointer
= c
;
1293 symbol_get_bfdsym (sym
)->flags
|= type
;
1295 demand_empty_rest_of_line ();
1299 obj_elf_ident (ignore
)
1302 static segT comment_section
;
1303 segT old_section
= now_seg
;
1304 int old_subsection
= now_subseg
;
1306 if (!comment_section
)
1309 comment_section
= subseg_new (".comment", 0);
1310 bfd_set_section_flags (stdoutput
, comment_section
,
1311 SEC_READONLY
| SEC_HAS_CONTENTS
);
1316 subseg_set (comment_section
, 0);
1318 subseg_set (old_section
, old_subsection
);
1321 #ifdef INIT_STAB_SECTION
1323 /* The first entry in a .stabs section is special. */
1326 obj_elf_init_stab_section (seg
)
1332 unsigned int stroff
;
1334 /* Force the section to align to a longword boundary. Without this,
1335 UnixWare ar crashes. */
1336 bfd_set_section_alignment (stdoutput
, seg
, 2);
1338 /* Make space for this first symbol. */
1342 as_where (&file
, (unsigned int *) NULL
);
1343 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1344 strcpy (stabstr_name
, segment_name (seg
));
1345 strcat (stabstr_name
, "str");
1346 stroff
= get_stab_string_offset (file
, stabstr_name
);
1348 md_number_to_chars (p
, stroff
, 4);
1349 seg_info (seg
)->stabu
.p
= p
;
1354 /* Fill in the counts in the first entry in a .stabs section. */
1357 adjust_stab_sections (abfd
, sec
, xxx
)
1367 if (strncmp (".stab", sec
->name
, 5))
1369 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1372 name
= (char *) alloca (strlen (sec
->name
) + 4);
1373 strcpy (name
, sec
->name
);
1374 strcat (name
, "str");
1375 strsec
= bfd_get_section_by_name (abfd
, name
);
1377 strsz
= bfd_section_size (abfd
, strsec
);
1380 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1382 p
= seg_info (sec
)->stabu
.p
;
1385 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1386 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1389 #ifdef NEED_ECOFF_DEBUG
1391 /* This function is called by the ECOFF code. It is supposed to
1392 record the external symbol information so that the backend can
1393 write it out correctly. The ELF backend doesn't actually handle
1394 this at the moment, so we do it ourselves. We save the information
1398 elf_ecoff_set_ext (sym
, ext
)
1400 struct ecoff_extr
*ext
;
1402 symbol_get_bfdsym (sym
)->udata
.p
= (PTR
) ext
;
1405 /* This function is called by bfd_ecoff_debug_externals. It is
1406 supposed to *EXT to the external symbol information, and return
1407 whether the symbol should be used at all. */
1410 elf_get_extr (sym
, ext
)
1414 if (sym
->udata
.p
== NULL
)
1416 *ext
= *(EXTR
*) sym
->udata
.p
;
1420 /* This function is called by bfd_ecoff_debug_externals. It has
1421 nothing to do for ELF. */
1425 elf_set_index (sym
, indx
)
1431 #endif /* NEED_ECOFF_DEBUG */
1434 elf_frob_symbol (symp
, puntp
)
1438 struct elf_obj_sy
*sy_obj
;
1440 #ifdef NEED_ECOFF_DEBUG
1441 if (ECOFF_DEBUGGING
)
1442 ecoff_frob_symbol (symp
);
1445 sy_obj
= symbol_get_obj (symp
);
1447 if (sy_obj
->size
!= NULL
)
1449 switch (sy_obj
->size
->X_op
)
1453 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1454 + sy_obj
->size
->X_add_number
1455 - S_GET_VALUE (sy_obj
->size
->X_op_symbol
)));
1459 (S_GET_VALUE (sy_obj
->size
->X_add_symbol
)
1460 + sy_obj
->size
->X_add_number
));
1463 as_bad (_(".size expression too complicated to fix up"));
1466 free (sy_obj
->size
);
1467 sy_obj
->size
= NULL
;
1470 if (sy_obj
->versioned_name
!= NULL
)
1472 /* This symbol was given a new name with the .symver directive.
1474 If this is an external reference, just rename the symbol to
1475 include the version string. This will make the relocs be
1476 against the correct versioned symbol.
1478 If this is a definition, add an alias. FIXME: Using an alias
1479 will permit the debugging information to refer to the right
1480 symbol. However, it's not clear whether it is the best
1483 if (! S_IS_DEFINED (symp
))
1487 /* Verify that the name isn't using the @@ syntax--this is
1488 reserved for definitions of the default version to link
1490 p
= strchr (sy_obj
->versioned_name
, ELF_VER_CHR
);
1492 if (p
[1] == ELF_VER_CHR
)
1494 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1495 sy_obj
->versioned_name
);
1498 S_SET_NAME (symp
, sy_obj
->versioned_name
);
1504 /* FIXME: Creating a new symbol here is risky. We're in the
1505 final loop over the symbol table. We can get away with
1506 it only because the symbol goes to the end of the list,
1507 where the loop will still see it. It would probably be
1508 better to do this in obj_frob_file_before_adjust. */
1510 symp2
= symbol_find_or_make (sy_obj
->versioned_name
);
1512 /* Now we act as though we saw symp2 = sym. */
1514 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1516 /* Subtracting out the frag address here is a hack because
1517 we are in the middle of the final loop. */
1520 - symbol_get_frag (symp
)->fr_address
));
1522 symbol_set_frag (symp2
, symbol_get_frag (symp
));
1524 /* This will copy over the size information. */
1525 copy_symbol_attributes (symp2
, symp
);
1527 if (S_IS_WEAK (symp
))
1530 if (S_IS_EXTERNAL (symp
))
1531 S_SET_EXTERNAL (symp2
);
1535 /* Double check weak symbols. */
1536 if (S_IS_WEAK (symp
))
1538 if (S_IS_COMMON (symp
))
1539 as_bad (_("Symbol `%s' can not be both weak and common"),
1544 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1545 any undefined non-function symbol to STT_OBJECT. We try to be
1546 compatible, since newer Irix 5 and 6 linkers care. However, we
1547 only set undefined symbols to be STT_OBJECT if we are on Irix,
1548 because that is the only time gcc will generate the necessary
1549 .global directives to mark functions. */
1551 if (S_IS_COMMON (symp
))
1552 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1554 if (strstr (TARGET_OS
, "irix") != NULL
1555 && ! S_IS_DEFINED (symp
)
1556 && (symbol_get_bfdsym (symp
)->flags
& BSF_FUNCTION
) == 0)
1557 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1561 /* Frob the PowerPC, so that the symbol always has object type
1562 if it is not some other type. VxWorks needs this. */
1563 if ((symbol_get_bfdsym (symp
)->flags
1564 & (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1565 && S_IS_DEFINED (symp
))
1566 symbol_get_bfdsym (symp
)->flags
|= BSF_OBJECT
;
1573 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1575 #ifdef elf_tc_final_processing
1576 elf_tc_final_processing ();
1580 /* It is required that we let write_relocs have the opportunity to
1581 optimize away fixups before output has begun, since it is possible
1582 to eliminate all fixups for a section and thus we never should
1583 have generated the relocation section. */
1586 elf_frob_file_after_relocs ()
1588 #ifdef NEED_ECOFF_DEBUG
1589 if (ECOFF_DEBUGGING
)
1590 /* Generate the ECOFF debugging information. */
1592 const struct ecoff_debug_swap
*debug_swap
;
1593 struct ecoff_debug_info debug
;
1598 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1599 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1600 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1602 /* Set up the pointers in debug. */
1603 #define SET(ptr, offset, type) \
1604 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1606 SET (line
, cbLineOffset
, unsigned char *);
1607 SET (external_dnr
, cbDnOffset
, PTR
);
1608 SET (external_pdr
, cbPdOffset
, PTR
);
1609 SET (external_sym
, cbSymOffset
, PTR
);
1610 SET (external_opt
, cbOptOffset
, PTR
);
1611 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1612 SET (ss
, cbSsOffset
, char *);
1613 SET (external_fdr
, cbFdOffset
, PTR
);
1614 SET (external_rfd
, cbRfdOffset
, PTR
);
1615 /* ssext and external_ext are set up just below. */
1619 /* Set up the external symbols. */
1620 debug
.ssext
= debug
.ssext_end
= NULL
;
1621 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1622 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1623 elf_get_extr
, elf_set_index
))
1624 as_fatal (_("Failed to set up debugging information: %s"),
1625 bfd_errmsg (bfd_get_error ()));
1627 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1628 assert (sec
!= NULL
);
1630 know (stdoutput
->output_has_begun
== false);
1632 /* We set the size of the section, call bfd_set_section_contents
1633 to force the ELF backend to allocate a file position, and then
1634 write out the data. FIXME: Is this really the best way to do
1636 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1638 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1639 (file_ptr
) 0, (bfd_size_type
) 0))
1640 as_fatal (_("Can't start writing .mdebug section: %s"),
1641 bfd_errmsg (bfd_get_error ()));
1643 know (stdoutput
->output_has_begun
== true);
1644 know (sec
->filepos
!= 0);
1646 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1648 as_fatal (_("Could not write .mdebug section: %s"),
1649 bfd_errmsg (bfd_get_error ()));
1651 #endif /* NEED_ECOFF_DEBUG */
1656 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1657 SCO specific identifier in the .notes section to satisfy the SCO
1660 This looks more complicated than it really is. As opposed to the
1661 "obvious" solution, this should handle the cross dev cases
1662 correctly. (i.e, hosting on a 64 bit big endian processor, but
1663 generating SCO Elf code) Efficiency isn't a concern, as there
1664 should be exactly one of these sections per object module.
1666 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1669 int_32 namesz = 4 ; Name size
1670 int_32 descsz = 12 ; Descriptive information
1672 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1673 int_32 version = (major ver # << 16) | version of tools ;
1674 int_32 source = (tool_id << 16 ) | 1 ;
1675 int_32 info = 0 ; These are set by the SCO tools, but we
1676 don't know enough about the source
1677 environment to set them. SCO ld currently
1678 ignores them, and recommends we set them
1681 #define SCO_MAJOR_VERSION 0x1
1682 #define SCO_MINOR_VERSION 0x1
1692 asection
*seg
= now_seg
;
1693 subsegT subseg
= now_subseg
;
1694 Elf_Internal_Note i_note
;
1695 Elf_External_Note e_note
;
1696 asection
*note_secp
= (asection
*) NULL
;
1699 /* create the .note section */
1701 note_secp
= subseg_new (".note", 0);
1702 bfd_set_section_flags (stdoutput
,
1704 SEC_HAS_CONTENTS
| SEC_READONLY
);
1706 /* process the version string */
1709 i_note
.descsz
= 12; /* 12 descriptive bytes */
1710 i_note
.type
= NT_VERSION
; /* Contains a version string */
1712 p
= frag_more (sizeof (i_note
.namesz
));
1713 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1715 p
= frag_more (sizeof (i_note
.descsz
));
1716 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1718 p
= frag_more (sizeof (i_note
.type
));
1719 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1724 /* Note: this is the version number of the ELF we're representing */
1726 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1728 /* Here, we pick a magic number for ourselves (yes, I "registered"
1729 it with SCO. The bottom bit shows that we are compat with the
1732 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1734 /* If we knew (or cared) what the source language options were, we'd
1735 fill them in here. SCO has given us permission to ignore these
1736 and just set them to zero. */
1738 md_number_to_chars (p
, 0x0000, 4);
1740 frag_align (2, 0, 0);
1742 /* We probably can't restore the current segment, for there likely
1745 subseg_set (seg
, subseg
);
1749 #endif /* SCO_ELF */
1751 const struct format_ops elf_format_ops
=
1753 bfd_target_elf_flavour
,
1758 elf_frob_file_after_relocs
,
1759 elf_s_get_size
, elf_s_set_size
,
1760 elf_s_get_align
, elf_s_set_align
,
1761 elf_copy_symbol_attributes
,
1762 #ifdef NEED_ECOFF_DEBUG
1763 ecoff_generate_asm_lineno
,
1767 0, /* process_stab */
1769 elf_sec_sym_ok_for_reloc
,
1771 #ifdef NEED_ECOFF_DEBUG
1776 obj_read_begin_hook
,
1777 obj_symbol_new_hook
,