1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 1997 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
44 static bfd_vma elf_s_get_size
PARAMS ((symbolS
*));
45 static void elf_s_set_size
PARAMS ((symbolS
*, bfd_vma
));
46 static bfd_vma elf_s_get_align
PARAMS ((symbolS
*));
47 static void elf_s_set_align
PARAMS ((symbolS
*, bfd_vma
));
48 static void elf_copy_symbol_attributes
PARAMS ((symbolS
*, symbolS
*));
49 static int elf_sec_sym_ok_for_reloc
PARAMS ((asection
*));
50 static void adjust_stab_sections
PARAMS ((bfd
*, asection
*, PTR
));
52 #ifdef NEED_ECOFF_DEBUG
53 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
54 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
57 static void obj_elf_line
PARAMS ((int));
58 void obj_elf_version
PARAMS ((int));
59 static void obj_elf_size
PARAMS ((int));
60 static void obj_elf_type
PARAMS ((int));
61 static void obj_elf_ident
PARAMS ((int));
62 static void obj_elf_weak
PARAMS ((int));
63 static void obj_elf_local
PARAMS ((int));
64 static void obj_elf_common
PARAMS ((int));
65 static void obj_elf_symver
PARAMS ((int));
66 static void obj_elf_data
PARAMS ((int));
67 static void obj_elf_text
PARAMS ((int));
68 static void obj_elf_subsection
PARAMS ((int));
70 static const pseudo_typeS elf_pseudo_table
[] =
72 {"comm", obj_elf_common
, 0},
73 {"ident", obj_elf_ident
, 0},
74 {"local", obj_elf_local
, 0},
75 {"previous", obj_elf_previous
, 0},
76 {"section", obj_elf_section
, 0},
77 {"section.s", obj_elf_section
, 0},
78 {"sect", obj_elf_section
, 0},
79 {"sect.s", obj_elf_section
, 0},
80 {"size", obj_elf_size
, 0},
81 {"type", obj_elf_type
, 0},
82 {"version", obj_elf_version
, 0},
83 {"weak", obj_elf_weak
, 0},
85 /* These are used for stabs-in-elf configurations. */
86 {"line", obj_elf_line
, 0},
88 /* This is a GNU extension to handle symbol versions. */
89 {"symver", obj_elf_symver
, 0},
91 /* A GNU extension to change subsection only. */
92 {"subsection", obj_elf_subsection
, 0},
94 /* These are used for dwarf. */
99 /* We need to trap the section changing calls to handle .previous. */
100 {"data", obj_elf_data
, 0},
101 {"text", obj_elf_text
, 0},
107 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
109 #ifdef NEED_ECOFF_DEBUG
110 /* COFF style debugging information for ECOFF. .ln is not used; .loc
112 { "def", ecoff_directive_def
, 0 },
113 { "dim", ecoff_directive_dim
, 0 },
114 { "endef", ecoff_directive_endef
, 0 },
115 { "file", ecoff_directive_file
, 0 },
116 { "scl", ecoff_directive_scl
, 0 },
117 { "tag", ecoff_directive_tag
, 0 },
118 { "val", ecoff_directive_val
, 0 },
120 /* COFF debugging requires pseudo-ops .size and .type, but ELF
121 already has meanings for those. We use .esize and .etype
122 instead. These are only generated by gcc anyhow. */
123 { "esize", ecoff_directive_size
, 0 },
124 { "etype", ecoff_directive_type
, 0 },
126 /* ECOFF specific debugging information. */
127 { "begin", ecoff_directive_begin
, 0 },
128 { "bend", ecoff_directive_bend
, 0 },
129 { "end", ecoff_directive_end
, 0 },
130 { "ent", ecoff_directive_ent
, 0 },
131 { "fmask", ecoff_directive_fmask
, 0 },
132 { "frame", ecoff_directive_frame
, 0 },
133 { "loc", ecoff_directive_loc
, 0 },
134 { "mask", ecoff_directive_mask
, 0 },
136 /* Other ECOFF directives. */
137 { "extern", ecoff_directive_extern
, 0 },
139 /* These are used on Irix. I don't know how to implement them. */
140 { "alias", s_ignore
, 0 },
141 { "bgnb", s_ignore
, 0 },
142 { "endb", s_ignore
, 0 },
143 { "lab", s_ignore
, 0 },
144 { "noalias", s_ignore
, 0 },
145 { "verstamp", s_ignore
, 0 },
146 { "vreg", s_ignore
, 0 },
149 {NULL
} /* end sentinel */
153 #include "aout/aout64.h"
155 /* This is called when the assembler starts. */
160 /* Add symbols for the known sections to the symbol table. */
161 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
162 TEXT_SECTION_NAME
)));
163 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
164 DATA_SECTION_NAME
)));
165 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
172 pop_insert (elf_pseudo_table
);
174 pop_insert (ecoff_debug_pseudo_table
);
181 return S_GET_SIZE (sym
);
185 elf_s_set_size (sym
, sz
)
189 S_SET_SIZE (sym
, sz
);
193 elf_s_get_align (sym
)
196 return S_GET_ALIGN (sym
);
200 elf_s_set_align (sym
, align
)
204 S_SET_ALIGN (sym
, align
);
208 elf_copy_symbol_attributes (dest
, src
)
211 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
215 elf_sec_sym_ok_for_reloc (sec
)
218 return obj_sec_sym_ok_for_reloc (sec
);
227 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
228 sym
->sy_frag
= &zero_address_frag
;
229 sym
->bsym
->flags
|= BSF_FILE
;
231 if (symbol_rootP
!= sym
)
233 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
234 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
236 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
240 #ifdef NEED_ECOFF_DEBUG
246 obj_elf_common (ignore
)
256 name
= input_line_pointer
;
257 c
= get_symbol_end ();
258 /* just after name is now '\0' */
259 p
= input_line_pointer
;
262 if (*input_line_pointer
!= ',')
264 as_bad ("Expected comma after symbol-name");
265 ignore_rest_of_line ();
268 input_line_pointer
++; /* skip ',' */
269 if ((temp
= get_absolute_expression ()) < 0)
271 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
272 ignore_rest_of_line ();
277 symbolP
= symbol_find_or_make (name
);
279 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
281 as_bad ("Ignoring attempt to re-define symbol");
282 ignore_rest_of_line ();
285 if (S_GET_VALUE (symbolP
) != 0)
287 if (S_GET_VALUE (symbolP
) != size
)
289 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
290 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
293 know (symbolP
->sy_frag
== &zero_address_frag
);
294 if (*input_line_pointer
!= ',')
299 input_line_pointer
++;
302 if (! have_align
|| *input_line_pointer
!= '"')
308 temp
= get_absolute_expression ();
312 as_warn ("Common alignment negative; 0 assumed");
324 old_subsec
= now_subseg
;
327 /* convert to a power of 2 alignment */
328 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
331 as_bad ("Common alignment not a power of 2");
332 ignore_rest_of_line ();
338 record_alignment (bss_section
, align
);
339 subseg_set (bss_section
, 0);
341 frag_align (align
, 0, 0);
342 if (S_GET_SEGMENT (symbolP
) == bss_section
)
343 symbolP
->sy_frag
->fr_symbol
= 0;
344 symbolP
->sy_frag
= frag_now
;
345 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
346 (offsetT
) size
, (char *) 0);
348 S_SET_SIZE (symbolP
, size
);
349 S_SET_SEGMENT (symbolP
, bss_section
);
350 S_CLEAR_EXTERNAL (symbolP
);
351 subseg_set (old_sec
, old_subsec
);
356 S_SET_VALUE (symbolP
, (valueT
) size
);
357 S_SET_ALIGN (symbolP
, temp
);
358 S_SET_EXTERNAL (symbolP
);
359 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
364 input_line_pointer
++;
365 /* @@ Some use the dot, some don't. Can we get some consistency?? */
366 if (*input_line_pointer
== '.')
367 input_line_pointer
++;
368 /* @@ Some say data, some say bss. */
369 if (strncmp (input_line_pointer
, "bss\"", 4)
370 && strncmp (input_line_pointer
, "data\"", 5))
372 while (*--input_line_pointer
!= '"')
374 input_line_pointer
--;
375 goto bad_common_segment
;
377 while (*input_line_pointer
++ != '"')
379 goto allocate_common
;
382 symbolP
->bsym
->flags
|= BSF_OBJECT
;
384 demand_empty_rest_of_line ();
389 p
= input_line_pointer
;
390 while (*p
&& *p
!= '\n')
394 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
396 input_line_pointer
= p
;
397 ignore_rest_of_line ();
403 obj_elf_local (ignore
)
412 name
= input_line_pointer
;
413 c
= get_symbol_end ();
414 symbolP
= symbol_find_or_make (name
);
415 *input_line_pointer
= c
;
417 S_CLEAR_EXTERNAL (symbolP
);
421 input_line_pointer
++;
423 if (*input_line_pointer
== '\n')
428 demand_empty_rest_of_line ();
432 obj_elf_weak (ignore
)
441 name
= input_line_pointer
;
442 c
= get_symbol_end ();
443 symbolP
= symbol_find_or_make (name
);
444 *input_line_pointer
= c
;
446 S_SET_WEAK (symbolP
);
450 input_line_pointer
++;
452 if (*input_line_pointer
== '\n')
457 demand_empty_rest_of_line ();
460 static segT previous_section
;
461 static int previous_subsection
;
463 /* Handle the .section pseudo-op. This code supports two different
466 The first is found on Solaris, and looks like
467 .section ".sec1",#alloc,#execinstr,#write
468 Here the names after '#' are the SHF_* flags to turn on for the
469 section. I'm not sure how it determines the SHT_* type (BFD
470 doesn't really give us control over the type, anyhow).
472 The second format is found on UnixWare, and probably most SVR4
473 machines, and looks like
474 .section .sec1,"a",@progbits
475 The quoted string may contain any combination of a, w, x, and
476 represents the SHF_* flags to turn on for the section. The string
477 beginning with '@' can be progbits or nobits. There should be
478 other possibilities, but I don't know what they are. In any case,
479 BFD doesn't really let us set the section type. */
481 /* Certain named sections have particular defined types, listed on p.
483 struct special_section
490 static struct special_section special_sections
[] =
492 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
493 { ".comment", SHT_PROGBITS
, 0 },
494 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
495 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
496 { ".debug", SHT_PROGBITS
, 0 },
497 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
498 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
499 { ".line", SHT_PROGBITS
, 0 },
500 { ".note", SHT_NOTE
, 0 },
501 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
502 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
503 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
505 #ifdef ELF_TC_SPECIAL_SECTIONS
506 ELF_TC_SPECIAL_SECTIONS
510 /* The following section names are special, but they can not
511 reasonably appear in assembler code. Some of the attributes are
512 processor dependent. */
513 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
514 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
515 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
516 { ".got", SHT_PROGBITS
, 0 },
517 { ".hash", SHT_HASH
, SHF_ALLOC
},
518 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
519 { ".plt", SHT_PROGBITS
, 0 },
520 { ".shstrtab",SHT_STRTAB
, 0 },
521 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
522 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
529 obj_elf_section (xxx
)
540 #ifdef md_flush_pending_output
541 md_flush_pending_output ();
548 previous_section
= now_seg
;
549 previous_subsection
= now_subseg
;
551 s_mri_sect (&mri_type
);
553 #ifdef md_elf_section_change_hook
554 md_elf_section_change_hook ();
560 /* Get name of section. */
562 if (*input_line_pointer
== '"')
564 string
= demand_copy_C_string (&xxx
);
567 ignore_rest_of_line ();
573 char *p
= input_line_pointer
;
575 while (0 == strchr ("\n\t,; ", *p
))
577 if (p
== input_line_pointer
)
579 as_warn ("Missing section name");
580 ignore_rest_of_line ();
585 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
586 strcpy (string
, input_line_pointer
);
588 input_line_pointer
= p
;
591 /* Switch to the section, creating it if necessary. */
592 previous_section
= now_seg
;
593 previous_subsection
= now_subseg
;
595 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
596 sec
= subseg_new (string
, 0);
598 /* If this section already existed, we don't bother to change the
602 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
603 ++input_line_pointer
;
604 ++input_line_pointer
;
606 #ifdef md_elf_section_change_hook
607 md_elf_section_change_hook ();
618 if (*input_line_pointer
== ',')
620 /* Skip the comma. */
621 ++input_line_pointer
;
625 if (*input_line_pointer
== '"')
627 /* Pick up a string with a combination of a, w, x. */
628 ++input_line_pointer
;
629 while (*input_line_pointer
!= '"')
631 switch (*input_line_pointer
)
640 attr
|= SHF_EXECINSTR
;
644 char *bad_msg
= "Bad .section directive: want a,w,x in string";
645 #ifdef md_elf_section_letter
646 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
653 ignore_rest_of_line ();
658 ++input_line_pointer
;
661 /* Skip the closing quote. */
662 ++input_line_pointer
;
665 if (*input_line_pointer
== ',')
667 ++input_line_pointer
;
669 if (*input_line_pointer
== '@')
671 ++input_line_pointer
;
672 if (strncmp (input_line_pointer
, "progbits",
673 sizeof "progbits" - 1) == 0)
676 input_line_pointer
+= sizeof "progbits" - 1;
678 else if (strncmp (input_line_pointer
, "nobits",
679 sizeof "nobits" - 1) == 0)
682 input_line_pointer
+= sizeof "nobits" - 1;
686 #ifdef md_elf_section_type
687 int md_type
= md_elf_section_type (&input_line_pointer
);
693 as_warn ("Unrecognized section type");
694 ignore_rest_of_line ();
705 if (*input_line_pointer
!= '#')
707 as_warn ("Bad .section directive - character following name is not '#'");
708 ignore_rest_of_line ();
711 ++input_line_pointer
;
712 if (strncmp (input_line_pointer
, "write",
713 sizeof "write" - 1) == 0)
716 input_line_pointer
+= sizeof "write" - 1;
718 else if (strncmp (input_line_pointer
, "alloc",
719 sizeof "alloc" - 1) == 0)
722 input_line_pointer
+= sizeof "alloc" - 1;
724 else if (strncmp (input_line_pointer
, "execinstr",
725 sizeof "execinstr" - 1) == 0)
727 attr
|= SHF_EXECINSTR
;
728 input_line_pointer
+= sizeof "execinstr" - 1;
732 #ifdef md_elf_section_word
733 int md_attr
= md_elf_section_word (&input_line_pointer
);
739 as_warn ("Unrecognized section attribute");
740 ignore_rest_of_line ();
746 while (*input_line_pointer
++ == ',');
747 --input_line_pointer
;
751 /* See if this is one of the special sections. */
752 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
754 if (string
[1] == special_sections
[i
].name
[1]
755 && strcmp (string
, special_sections
[i
].name
) == 0)
757 if (type
== SHT_NULL
)
758 type
= special_sections
[i
].type
;
759 else if (type
!= special_sections
[i
].type
)
760 as_warn ("Setting incorrect section type for %s", string
);
762 if ((attr
&~ special_sections
[i
].attributes
) != 0)
764 /* As a GNU extension, we permit a .note section to be
765 allocatable. If the linker sees an allocateable
766 .note section, it will create a PT_NOTE segment in
768 if (strcmp (string
, ".note") != 0
769 || attr
!= SHF_ALLOC
)
770 as_warn ("Setting incorrect section attributes for %s",
773 attr
|= special_sections
[i
].attributes
;
780 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
781 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
782 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
783 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
784 if (special_sections
[i
].name
== NULL
)
786 if (type
== SHT_PROGBITS
)
787 flags
|= SEC_ALLOC
| SEC_LOAD
;
788 else if (type
== SHT_NOBITS
)
794 #ifdef md_elf_section_flags
795 flags
= md_elf_section_flags (flags
, attr
, type
);
799 bfd_set_section_flags (stdoutput
, sec
, flags
);
801 /* Add a symbol for this section to the symbol table. */
802 secsym
= symbol_find (string
);
804 secsym
->bsym
= sec
->symbol
;
806 symbol_table_insert (section_symbol (sec
));
808 #ifdef md_elf_section_change_hook
809 md_elf_section_change_hook ();
812 demand_empty_rest_of_line ();
815 /* Change to the .data section. */
821 #ifdef md_flush_pending_output
822 md_flush_pending_output ();
825 previous_section
= now_seg
;
826 previous_subsection
= now_subseg
;
829 #ifdef md_elf_section_change_hook
830 md_elf_section_change_hook ();
834 /* Change to the .text section. */
840 #ifdef md_flush_pending_output
841 md_flush_pending_output ();
844 previous_section
= now_seg
;
845 previous_subsection
= now_subseg
;
848 #ifdef md_elf_section_change_hook
849 md_elf_section_change_hook ();
854 obj_elf_subsection (ignore
)
859 #ifdef md_flush_pending_output
860 md_flush_pending_output ();
863 previous_section
= now_seg
;
864 previous_subsection
= now_subseg
;
866 temp
= get_absolute_expression ();
867 subseg_set (now_seg
, (subsegT
) temp
);
868 demand_empty_rest_of_line ();
870 #ifdef md_elf_section_change_hook
871 md_elf_section_change_hook ();
875 /* This can be called from the processor backends if they change
879 obj_elf_section_change_hook ()
881 previous_section
= now_seg
;
882 previous_subsection
= now_subseg
;
886 obj_elf_previous (ignore
)
889 if (previous_section
== 0)
891 as_bad (".previous without corresponding .section; ignored");
895 #ifdef md_flush_pending_output
896 md_flush_pending_output ();
899 subseg_set (previous_section
, previous_subsection
);
900 previous_section
= 0;
902 #ifdef md_elf_section_change_hook
903 md_elf_section_change_hook ();
908 obj_elf_line (ignore
)
911 /* Assume delimiter is part of expression. BSD4.2 as fails with
912 delightful bug, so we are not being incompatible here. */
913 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
914 demand_empty_rest_of_line ();
917 /* This handle the .symver pseudo-op, which is used to specify a
918 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
919 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
920 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
921 with the same value as the symbol NAME. */
924 obj_elf_symver (ignore
)
931 name
= input_line_pointer
;
932 c
= get_symbol_end ();
934 sym
= symbol_find_or_make (name
);
936 *input_line_pointer
= c
;
938 if (sym
->sy_obj
.versioned_name
!= NULL
)
940 as_bad ("multiple .symver directives for symbol `%s'",
942 ignore_rest_of_line ();
947 if (*input_line_pointer
!= ',')
949 as_bad ("expected comma after name in .symver");
950 ignore_rest_of_line ();
954 ++input_line_pointer
;
955 name
= input_line_pointer
;
958 c
= get_symbol_end ();
959 if (c
!= ELF_VER_CHR
)
961 *input_line_pointer
++ = c
;
964 sym
->sy_obj
.versioned_name
= xstrdup (name
);
966 *input_line_pointer
= c
;
968 if (strchr (sym
->sy_obj
.versioned_name
, ELF_VER_CHR
) == NULL
)
970 as_bad ("missing version name in `%s' for symbol `%s'",
971 sym
->sy_obj
.versioned_name
, S_GET_NAME (sym
));
972 ignore_rest_of_line ();
976 demand_empty_rest_of_line ();
980 obj_read_begin_hook ()
982 #ifdef NEED_ECOFF_DEBUG
984 ecoff_read_begin_hook ();
989 obj_symbol_new_hook (symbolP
)
992 symbolP
->sy_obj
.size
= NULL
;
993 symbolP
->sy_obj
.versioned_name
= NULL
;
995 #ifdef NEED_ECOFF_DEBUG
997 ecoff_symbol_new_hook (symbolP
);
1002 obj_elf_version (ignore
)
1009 asection
*seg
= now_seg
;
1010 subsegT subseg
= now_subseg
;
1011 Elf_Internal_Note i_note
;
1012 Elf_External_Note e_note
;
1013 asection
*note_secp
= (asection
*) NULL
;
1017 if (*input_line_pointer
== '\"')
1019 ++input_line_pointer
; /* -> 1st char of string. */
1020 name
= input_line_pointer
;
1022 while (is_a_char (c
= next_char_of_string ()))
1024 c
= *input_line_pointer
;
1025 *input_line_pointer
= '\0';
1026 *(input_line_pointer
- 1) = '\0';
1027 *input_line_pointer
= c
;
1029 /* create the .note section */
1031 note_secp
= subseg_new (".note", 0);
1032 bfd_set_section_flags (stdoutput
,
1034 SEC_HAS_CONTENTS
| SEC_READONLY
);
1036 /* process the version string */
1038 len
= strlen (name
);
1040 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1041 i_note
.descsz
= 0; /* no description */
1042 i_note
.type
= NT_VERSION
;
1043 p
= frag_more (sizeof (e_note
.namesz
));
1044 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1045 p
= frag_more (sizeof (e_note
.descsz
));
1046 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1047 p
= frag_more (sizeof (e_note
.type
));
1048 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1050 for (i
= 0; i
< len
; i
++)
1054 FRAG_APPEND_1_CHAR (ch
);
1057 frag_align (2, 0, 0);
1059 subseg_set (seg
, subseg
);
1063 as_bad ("Expected quoted string");
1065 demand_empty_rest_of_line ();
1069 obj_elf_size (ignore
)
1072 char *name
= input_line_pointer
;
1073 char c
= get_symbol_end ();
1078 p
= input_line_pointer
;
1081 if (*input_line_pointer
!= ',')
1084 as_bad ("expected comma after name `%s' in .size directive", name
);
1086 ignore_rest_of_line ();
1089 input_line_pointer
++;
1091 if (exp
.X_op
== O_absent
)
1093 as_bad ("missing expression in .size directive");
1094 exp
.X_op
= O_constant
;
1095 exp
.X_add_number
= 0;
1098 sym
= symbol_find_or_make (name
);
1100 if (exp
.X_op
== O_constant
)
1101 S_SET_SIZE (sym
, exp
.X_add_number
);
1104 sym
->sy_obj
.size
= (expressionS
*) xmalloc (sizeof (expressionS
));
1105 *sym
->sy_obj
.size
= exp
;
1107 demand_empty_rest_of_line ();
1110 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1111 There are three syntaxes. The first (used on Solaris) is
1113 The second (used on UnixWare) is
1115 The third (reportedly to be used on Irix 6.0) is
1120 obj_elf_type (ignore
)
1126 const char *typename
;
1129 name
= input_line_pointer
;
1130 c
= get_symbol_end ();
1131 sym
= symbol_find_or_make (name
);
1132 *input_line_pointer
= c
;
1135 if (*input_line_pointer
== ',')
1136 ++input_line_pointer
;
1139 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
1140 ++input_line_pointer
;
1142 typename
= input_line_pointer
;
1143 c
= get_symbol_end ();
1146 if (strcmp (typename
, "function") == 0
1147 || strcmp (typename
, "STT_FUNC") == 0)
1148 type
= BSF_FUNCTION
;
1149 else if (strcmp (typename
, "object") == 0
1150 || strcmp (typename
, "STT_OBJECT") == 0)
1153 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
1155 *input_line_pointer
= c
;
1157 sym
->bsym
->flags
|= type
;
1159 demand_empty_rest_of_line ();
1163 obj_elf_ident (ignore
)
1166 static segT comment_section
;
1167 segT old_section
= now_seg
;
1168 int old_subsection
= now_subseg
;
1170 if (!comment_section
)
1173 comment_section
= subseg_new (".comment", 0);
1174 bfd_set_section_flags (stdoutput
, comment_section
,
1175 SEC_READONLY
| SEC_HAS_CONTENTS
);
1180 subseg_set (comment_section
, 0);
1182 subseg_set (old_section
, old_subsection
);
1185 #ifdef INIT_STAB_SECTION
1187 /* The first entry in a .stabs section is special. */
1190 obj_elf_init_stab_section (seg
)
1196 unsigned int stroff
;
1198 /* Force the section to align to a longword boundary. Without this,
1199 UnixWare ar crashes. */
1200 bfd_set_section_alignment (stdoutput
, seg
, 2);
1202 /* Make space for this first symbol. */
1206 as_where (&file
, (unsigned int *) NULL
);
1207 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1208 strcpy (stabstr_name
, segment_name (seg
));
1209 strcat (stabstr_name
, "str");
1210 stroff
= get_stab_string_offset (file
, stabstr_name
);
1212 md_number_to_chars (p
, stroff
, 4);
1213 seg_info (seg
)->stabu
.p
= p
;
1218 /* Fill in the counts in the first entry in a .stabs section. */
1221 adjust_stab_sections (abfd
, sec
, xxx
)
1231 if (strncmp (".stab", sec
->name
, 5))
1233 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1236 name
= (char *) alloca (strlen (sec
->name
) + 4);
1237 strcpy (name
, sec
->name
);
1238 strcat (name
, "str");
1239 strsec
= bfd_get_section_by_name (abfd
, name
);
1241 strsz
= bfd_section_size (abfd
, strsec
);
1244 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1246 p
= seg_info (sec
)->stabu
.p
;
1249 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1250 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1253 #ifdef NEED_ECOFF_DEBUG
1255 /* This function is called by the ECOFF code. It is supposed to
1256 record the external symbol information so that the backend can
1257 write it out correctly. The ELF backend doesn't actually handle
1258 this at the moment, so we do it ourselves. We save the information
1262 elf_ecoff_set_ext (sym
, ext
)
1264 struct ecoff_extr
*ext
;
1266 sym
->bsym
->udata
.p
= (PTR
) ext
;
1269 /* This function is called by bfd_ecoff_debug_externals. It is
1270 supposed to *EXT to the external symbol information, and return
1271 whether the symbol should be used at all. */
1274 elf_get_extr (sym
, ext
)
1278 if (sym
->udata
.p
== NULL
)
1280 *ext
= *(EXTR
*) sym
->udata
.p
;
1284 /* This function is called by bfd_ecoff_debug_externals. It has
1285 nothing to do for ELF. */
1289 elf_set_index (sym
, indx
)
1295 #endif /* NEED_ECOFF_DEBUG */
1298 elf_frob_symbol (symp
, puntp
)
1302 #ifdef NEED_ECOFF_DEBUG
1303 if (ECOFF_DEBUGGING
)
1304 ecoff_frob_symbol (symp
);
1307 if (symp
->sy_obj
.size
!= NULL
)
1309 switch (symp
->sy_obj
.size
->X_op
)
1313 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1314 + symp
->sy_obj
.size
->X_add_number
1315 - S_GET_VALUE (symp
->sy_obj
.size
->X_op_symbol
)));
1319 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1320 + symp
->sy_obj
.size
->X_add_number
));
1323 as_bad (".size expression too complicated to fix up");
1326 free (symp
->sy_obj
.size
);
1327 symp
->sy_obj
.size
= NULL
;
1330 if (symp
->sy_obj
.versioned_name
!= NULL
)
1332 /* This symbol was given a new name with the .symver directive.
1334 If this is an external reference, just rename the symbol to
1335 include the version string. This will make the relocs be
1336 against the correct versioned symbol.
1338 If this is a definition, add an alias. FIXME: Using an alias
1339 will permit the debugging information to refer to the right
1340 symbol. However, it's not clear whether it is the best
1343 if (! S_IS_DEFINED (symp
))
1347 /* Verify that the name isn't using the @@ syntax--this is
1348 reserved for definitions of the default version to link
1350 p
= strchr (symp
->sy_obj
.versioned_name
, ELF_VER_CHR
);
1352 if (p
[1] == ELF_VER_CHR
)
1354 as_bad ("invalid attempt to declare external version name as default in symbol `%s'",
1355 symp
->sy_obj
.versioned_name
);
1358 S_SET_NAME (symp
, symp
->sy_obj
.versioned_name
);
1364 /* FIXME: Creating a new symbol here is risky. We're in the
1365 final loop over the symbol table. We can get away with
1366 it only because the symbol goes to the end of the list,
1367 where the loop will still see it. It would probably be
1368 better to do this in obj_frob_file_before_adjust. */
1370 symp2
= symbol_find_or_make (symp
->sy_obj
.versioned_name
);
1372 /* Now we act as though we saw symp2 = sym. */
1374 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1376 /* Subtracting out the frag address here is a hack because
1377 we are in the middle of the final loop. */
1378 S_SET_VALUE (symp2
, S_GET_VALUE (symp
) - symp
->sy_frag
->fr_address
);
1380 symp2
->sy_frag
= symp
->sy_frag
;
1382 /* This will copy over the size information. */
1383 copy_symbol_attributes (symp2
, symp
);
1385 if (S_IS_WEAK (symp
))
1388 if (S_IS_EXTERNAL (symp
))
1389 S_SET_EXTERNAL (symp2
);
1393 /* Double check weak symbols. */
1394 if (symp
->bsym
->flags
& BSF_WEAK
)
1396 if (S_IS_COMMON (symp
))
1397 as_bad ("Symbol `%s' can not be both weak and common",
1402 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1403 any undefined non-function symbol to STT_OBJECT. We try to be
1404 compatible, since newer Irix 5 and 6 linkers care. However, we
1405 only set undefined symbols to be STT_OBJECT if we are on Irix,
1406 because that is the only time gcc will generate the necessary
1407 .global directives to mark functions. */
1409 if (S_IS_COMMON (symp
))
1410 symp
->bsym
->flags
|= BSF_OBJECT
;
1412 if (strstr (TARGET_OS
, "irix") != NULL
1413 && (! S_IS_DEFINED (symp
) && ((symp
->bsym
->flags
& BSF_FUNCTION
) == 0)))
1414 symp
->bsym
->flags
|= BSF_OBJECT
;
1418 /* Frob the PowerPC, so that the symbol always has object type
1419 if it is not some other type. VxWorks needs this. */
1420 if ((symp
->bsym
->flags
& (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1421 && S_IS_DEFINED (symp
))
1422 symp
->bsym
->flags
|= BSF_OBJECT
;
1429 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1431 #ifdef elf_tc_final_processing
1432 elf_tc_final_processing ();
1436 /* It is required that we let write_relocs have the opportunity to
1437 optimize away fixups before output has begun, since it is possible
1438 to eliminate all fixups for a section and thus we never should
1439 have generated the relocation section. */
1442 elf_frob_file_after_relocs ()
1444 #ifdef NEED_ECOFF_DEBUG
1445 if (ECOFF_DEBUGGING
)
1446 /* Generate the ECOFF debugging information. */
1448 const struct ecoff_debug_swap
*debug_swap
;
1449 struct ecoff_debug_info debug
;
1454 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1455 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1456 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1458 /* Set up the pointers in debug. */
1459 #define SET(ptr, offset, type) \
1460 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1462 SET (line
, cbLineOffset
, unsigned char *);
1463 SET (external_dnr
, cbDnOffset
, PTR
);
1464 SET (external_pdr
, cbPdOffset
, PTR
);
1465 SET (external_sym
, cbSymOffset
, PTR
);
1466 SET (external_opt
, cbOptOffset
, PTR
);
1467 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1468 SET (ss
, cbSsOffset
, char *);
1469 SET (external_fdr
, cbFdOffset
, PTR
);
1470 SET (external_rfd
, cbRfdOffset
, PTR
);
1471 /* ssext and external_ext are set up just below. */
1475 /* Set up the external symbols. */
1476 debug
.ssext
= debug
.ssext_end
= NULL
;
1477 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1478 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1479 elf_get_extr
, elf_set_index
))
1480 as_fatal ("Failed to set up debugging information: %s",
1481 bfd_errmsg (bfd_get_error ()));
1483 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1484 assert (sec
!= NULL
);
1486 know (stdoutput
->output_has_begun
== false);
1488 /* We set the size of the section, call bfd_set_section_contents
1489 to force the ELF backend to allocate a file position, and then
1490 write out the data. FIXME: Is this really the best way to do
1492 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1494 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1495 (file_ptr
) 0, (bfd_size_type
) 0))
1496 as_fatal ("Can't start writing .mdebug section: %s",
1497 bfd_errmsg (bfd_get_error ()));
1499 know (stdoutput
->output_has_begun
== true);
1500 know (sec
->filepos
!= 0);
1502 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1504 as_fatal ("Could not write .mdebug section: %s",
1505 bfd_errmsg (bfd_get_error ()));
1507 #endif /* NEED_ECOFF_DEBUG */
1512 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1513 SCO specific identifier in the .notes section to satisfy the SCO
1516 This looks more complicated than it really is. As opposed to the
1517 "obvious" solution, this should handle the cross dev cases
1518 correctly. (i.e, hosting on a 64 bit big endian processor, but
1519 generating SCO Elf code) Efficiency isn't a concern, as there
1520 should be exactly one of these sections per object module.
1522 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1525 int_32 namesz = 4 ; Name size
1526 int_32 descsz = 12 ; Descriptive information
1528 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1529 int_32 version = (major ver # << 16) | version of tools ;
1530 int_32 source = (tool_id << 16 ) | 1 ;
1531 int_32 info = 0 ; These are set by the SCO tools, but we
1532 don't know enough about the source
1533 environment to set them. SCO ld currently
1534 ignores them, and recommends we set them
1537 #define SCO_MAJOR_VERSION 0x1
1538 #define SCO_MINOR_VERSION 0x1
1548 asection
*seg
= now_seg
;
1549 subsegT subseg
= now_subseg
;
1550 Elf_Internal_Note i_note
;
1551 Elf_External_Note e_note
;
1552 asection
*note_secp
= (asection
*) NULL
;
1555 /* create the .note section */
1557 note_secp
= subseg_new (".note", 0);
1558 bfd_set_section_flags (stdoutput
,
1560 SEC_HAS_CONTENTS
| SEC_READONLY
);
1562 /* process the version string */
1565 i_note
.descsz
= 12; /* 12 descriptive bytes */
1566 i_note
.type
= NT_VERSION
; /* Contains a version string */
1568 p
= frag_more (sizeof (i_note
.namesz
));
1569 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1571 p
= frag_more (sizeof (i_note
.descsz
));
1572 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1574 p
= frag_more (sizeof (i_note
.type
));
1575 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1580 /* Note: this is the version number of the ELF we're representing */
1582 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1584 /* Here, we pick a magic number for ourselves (yes, I "registered"
1585 it with SCO. The bottom bit shows that we are compat with the
1588 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1590 /* If we knew (or cared) what the source language options were, we'd
1591 fill them in here. SCO has given us permission to ignore these
1592 and just set them to zero. */
1594 md_number_to_chars (p
, 0x0000, 4);
1596 frag_align (2, 0, 0);
1598 /* We probably can't restore the current segment, for there likely
1601 subseg_set (seg
, subseg
);
1605 #endif /* SCO_ELF */
1607 const struct format_ops elf_format_ops
=
1609 bfd_target_elf_flavour
,
1614 elf_frob_file_after_relocs
,
1615 elf_s_get_size
, elf_s_set_size
,
1616 elf_s_get_align
, elf_s_set_align
,
1617 elf_copy_symbol_attributes
,
1618 #ifdef NEED_ECOFF_DEBUG
1619 ecoff_generate_asm_lineno
,
1623 0, /* process_stab */
1625 elf_sec_sym_ok_for_reloc
,
1627 #ifdef NEED_ECOFF_DEBUG
1632 obj_read_begin_hook
,
1633 obj_symbol_new_hook
,