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
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_data
PARAMS ((int));
71 static void obj_elf_text
PARAMS ((int));
72 static void obj_elf_subsection
PARAMS ((int));
74 static const pseudo_typeS elf_pseudo_table
[] =
76 {"comm", obj_elf_common
, 0},
77 {"ident", obj_elf_ident
, 0},
78 {"local", obj_elf_local
, 0},
79 {"previous", obj_elf_previous
, 0},
80 {"section", obj_elf_section
, 0},
81 {"section.s", obj_elf_section
, 0},
82 {"sect", obj_elf_section
, 0},
83 {"sect.s", obj_elf_section
, 0},
84 {"size", obj_elf_size
, 0},
85 {"type", obj_elf_type
, 0},
86 {"version", obj_elf_version
, 0},
87 {"weak", obj_elf_weak
, 0},
89 /* These are used for stabs-in-elf configurations. */
90 {"line", obj_elf_line
, 0},
92 /* This is a GNU extension to handle symbol versions. */
93 {"symver", obj_elf_symver
, 0},
95 /* A GNU extension to change subsection only. */
96 {"subsection", obj_elf_subsection
, 0},
98 /* These are used for dwarf. */
103 /* We need to trap the section changing calls to handle .previous. */
104 {"data", obj_elf_data
, 0},
105 {"text", obj_elf_text
, 0},
111 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
113 #ifdef NEED_ECOFF_DEBUG
114 /* COFF style debugging information for ECOFF. .ln is not used; .loc
116 { "def", ecoff_directive_def
, 0 },
117 { "dim", ecoff_directive_dim
, 0 },
118 { "endef", ecoff_directive_endef
, 0 },
119 { "file", ecoff_directive_file
, 0 },
120 { "scl", ecoff_directive_scl
, 0 },
121 { "tag", ecoff_directive_tag
, 0 },
122 { "val", ecoff_directive_val
, 0 },
124 /* COFF debugging requires pseudo-ops .size and .type, but ELF
125 already has meanings for those. We use .esize and .etype
126 instead. These are only generated by gcc anyhow. */
127 { "esize", ecoff_directive_size
, 0 },
128 { "etype", ecoff_directive_type
, 0 },
130 /* ECOFF specific debugging information. */
131 { "begin", ecoff_directive_begin
, 0 },
132 { "bend", ecoff_directive_bend
, 0 },
133 { "end", ecoff_directive_end
, 0 },
134 { "ent", ecoff_directive_ent
, 0 },
135 { "fmask", ecoff_directive_fmask
, 0 },
136 { "frame", ecoff_directive_frame
, 0 },
137 { "loc", ecoff_directive_loc
, 0 },
138 { "mask", ecoff_directive_mask
, 0 },
140 /* Other ECOFF directives. */
141 { "extern", ecoff_directive_extern
, 0 },
143 /* These are used on Irix. I don't know how to implement them. */
144 { "alias", s_ignore
, 0 },
145 { "bgnb", s_ignore
, 0 },
146 { "endb", s_ignore
, 0 },
147 { "lab", s_ignore
, 0 },
148 { "noalias", s_ignore
, 0 },
149 { "verstamp", s_ignore
, 0 },
150 { "vreg", s_ignore
, 0 },
153 {NULL
} /* end sentinel */
157 #include "aout/aout64.h"
159 /* This is called when the assembler starts. */
164 /* Add symbols for the known sections to the symbol table. */
165 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
166 TEXT_SECTION_NAME
)));
167 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
168 DATA_SECTION_NAME
)));
169 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
176 pop_insert (elf_pseudo_table
);
178 pop_insert (ecoff_debug_pseudo_table
);
185 return S_GET_SIZE (sym
);
189 elf_s_set_size (sym
, sz
)
193 S_SET_SIZE (sym
, sz
);
197 elf_s_get_align (sym
)
200 return S_GET_ALIGN (sym
);
204 elf_s_set_align (sym
, align
)
208 S_SET_ALIGN (sym
, align
);
212 elf_copy_symbol_attributes (dest
, src
)
215 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
219 elf_sec_sym_ok_for_reloc (sec
)
222 return obj_sec_sym_ok_for_reloc (sec
);
231 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
232 sym
->sy_frag
= &zero_address_frag
;
233 sym
->bsym
->flags
|= BSF_FILE
;
235 if (symbol_rootP
!= sym
)
237 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
238 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
240 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
244 #ifdef NEED_ECOFF_DEBUG
250 obj_elf_common (ignore
)
260 name
= input_line_pointer
;
261 c
= get_symbol_end ();
262 /* just after name is now '\0' */
263 p
= input_line_pointer
;
266 if (*input_line_pointer
!= ',')
268 as_bad ("Expected comma after symbol-name");
269 ignore_rest_of_line ();
272 input_line_pointer
++; /* skip ',' */
273 if ((temp
= get_absolute_expression ()) < 0)
275 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
276 ignore_rest_of_line ();
281 symbolP
= symbol_find_or_make (name
);
283 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
285 as_bad ("Ignoring attempt to re-define symbol");
286 ignore_rest_of_line ();
289 if (S_GET_VALUE (symbolP
) != 0)
291 if (S_GET_VALUE (symbolP
) != size
)
293 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
294 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
297 know (symbolP
->sy_frag
== &zero_address_frag
);
298 if (*input_line_pointer
!= ',')
303 input_line_pointer
++;
306 if (! have_align
|| *input_line_pointer
!= '"')
312 temp
= get_absolute_expression ();
316 as_warn ("Common alignment negative; 0 assumed");
328 old_subsec
= now_subseg
;
331 /* convert to a power of 2 alignment */
332 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
335 as_bad ("Common alignment not a power of 2");
336 ignore_rest_of_line ();
342 record_alignment (bss_section
, align
);
343 subseg_set (bss_section
, 0);
345 frag_align (align
, 0, 0);
346 if (S_GET_SEGMENT (symbolP
) == bss_section
)
347 symbolP
->sy_frag
->fr_symbol
= 0;
348 symbolP
->sy_frag
= frag_now
;
349 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
,
350 (offsetT
) size
, (char *) 0);
352 S_SET_SIZE (symbolP
, size
);
353 S_SET_SEGMENT (symbolP
, bss_section
);
354 S_CLEAR_EXTERNAL (symbolP
);
355 subseg_set (old_sec
, old_subsec
);
360 S_SET_VALUE (symbolP
, (valueT
) size
);
361 S_SET_ALIGN (symbolP
, temp
);
362 S_SET_EXTERNAL (symbolP
);
363 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
368 input_line_pointer
++;
369 /* @@ Some use the dot, some don't. Can we get some consistency?? */
370 if (*input_line_pointer
== '.')
371 input_line_pointer
++;
372 /* @@ Some say data, some say bss. */
373 if (strncmp (input_line_pointer
, "bss\"", 4)
374 && strncmp (input_line_pointer
, "data\"", 5))
376 while (*--input_line_pointer
!= '"')
378 input_line_pointer
--;
379 goto bad_common_segment
;
381 while (*input_line_pointer
++ != '"')
383 goto allocate_common
;
386 symbolP
->bsym
->flags
|= BSF_OBJECT
;
388 demand_empty_rest_of_line ();
393 p
= input_line_pointer
;
394 while (*p
&& *p
!= '\n')
398 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
400 input_line_pointer
= p
;
401 ignore_rest_of_line ();
407 obj_elf_local (ignore
)
416 name
= input_line_pointer
;
417 c
= get_symbol_end ();
418 symbolP
= symbol_find_or_make (name
);
419 *input_line_pointer
= c
;
421 S_CLEAR_EXTERNAL (symbolP
);
425 input_line_pointer
++;
427 if (*input_line_pointer
== '\n')
432 demand_empty_rest_of_line ();
436 obj_elf_weak (ignore
)
445 name
= input_line_pointer
;
446 c
= get_symbol_end ();
447 symbolP
= symbol_find_or_make (name
);
448 *input_line_pointer
= c
;
450 S_SET_WEAK (symbolP
);
454 input_line_pointer
++;
456 if (*input_line_pointer
== '\n')
461 demand_empty_rest_of_line ();
464 static segT previous_section
;
465 static int previous_subsection
;
467 /* Handle the .section pseudo-op. This code supports two different
470 The first is found on Solaris, and looks like
471 .section ".sec1",#alloc,#execinstr,#write
472 Here the names after '#' are the SHF_* flags to turn on for the
473 section. I'm not sure how it determines the SHT_* type (BFD
474 doesn't really give us control over the type, anyhow).
476 The second format is found on UnixWare, and probably most SVR4
477 machines, and looks like
478 .section .sec1,"a",@progbits
479 The quoted string may contain any combination of a, w, x, and
480 represents the SHF_* flags to turn on for the section. The string
481 beginning with '@' can be progbits or nobits. There should be
482 other possibilities, but I don't know what they are. In any case,
483 BFD doesn't really let us set the section type. */
485 /* Certain named sections have particular defined types, listed on p.
487 struct special_section
494 static struct special_section special_sections
[] =
496 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
497 { ".comment", SHT_PROGBITS
, 0 },
498 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
499 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
500 { ".debug", SHT_PROGBITS
, 0 },
501 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
502 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
503 { ".line", SHT_PROGBITS
, 0 },
504 { ".note", SHT_NOTE
, 0 },
505 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
506 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
507 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
509 #ifdef ELF_TC_SPECIAL_SECTIONS
510 ELF_TC_SPECIAL_SECTIONS
514 /* The following section names are special, but they can not
515 reasonably appear in assembler code. Some of the attributes are
516 processor dependent. */
517 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
518 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
519 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
520 { ".got", SHT_PROGBITS
, 0 },
521 { ".hash", SHT_HASH
, SHF_ALLOC
},
522 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
523 { ".plt", SHT_PROGBITS
, 0 },
524 { ".shstrtab",SHT_STRTAB
, 0 },
525 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
526 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
533 obj_elf_section (xxx
)
544 #ifdef md_flush_pending_output
545 md_flush_pending_output ();
552 previous_section
= now_seg
;
553 previous_subsection
= now_subseg
;
555 s_mri_sect (&mri_type
);
557 #ifdef md_elf_section_change_hook
558 md_elf_section_change_hook ();
564 /* Get name of section. */
566 if (*input_line_pointer
== '"')
568 string
= demand_copy_C_string (&xxx
);
571 ignore_rest_of_line ();
577 char *p
= input_line_pointer
;
579 while (0 == strchr ("\n\t,; ", *p
))
581 if (p
== input_line_pointer
)
583 as_warn ("Missing section name");
584 ignore_rest_of_line ();
589 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
590 strcpy (string
, input_line_pointer
);
592 input_line_pointer
= p
;
595 /* Switch to the section, creating it if necessary. */
596 previous_section
= now_seg
;
597 previous_subsection
= now_subseg
;
599 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
600 sec
= subseg_new (string
, 0);
602 /* If this section already existed, we don't bother to change the
606 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
607 ++input_line_pointer
;
608 ++input_line_pointer
;
610 #ifdef md_elf_section_change_hook
611 md_elf_section_change_hook ();
622 if (*input_line_pointer
== ',')
624 /* Skip the comma. */
625 ++input_line_pointer
;
629 if (*input_line_pointer
== '"')
631 /* Pick up a string with a combination of a, w, x. */
632 ++input_line_pointer
;
633 while (*input_line_pointer
!= '"')
635 switch (*input_line_pointer
)
644 attr
|= SHF_EXECINSTR
;
648 char *bad_msg
= "Bad .section directive: want a,w,x in string";
649 #ifdef md_elf_section_letter
650 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
657 ignore_rest_of_line ();
662 ++input_line_pointer
;
665 /* Skip the closing quote. */
666 ++input_line_pointer
;
669 if (*input_line_pointer
== ',')
671 ++input_line_pointer
;
673 if (*input_line_pointer
== '@')
675 ++input_line_pointer
;
676 if (strncmp (input_line_pointer
, "progbits",
677 sizeof "progbits" - 1) == 0)
680 input_line_pointer
+= sizeof "progbits" - 1;
682 else if (strncmp (input_line_pointer
, "nobits",
683 sizeof "nobits" - 1) == 0)
686 input_line_pointer
+= sizeof "nobits" - 1;
690 #ifdef md_elf_section_type
691 int md_type
= md_elf_section_type (&input_line_pointer
);
697 as_warn ("Unrecognized section type");
698 ignore_rest_of_line ();
709 if (*input_line_pointer
!= '#')
711 as_warn ("Bad .section directive - character following name is not '#'");
712 ignore_rest_of_line ();
715 ++input_line_pointer
;
716 if (strncmp (input_line_pointer
, "write",
717 sizeof "write" - 1) == 0)
720 input_line_pointer
+= sizeof "write" - 1;
722 else if (strncmp (input_line_pointer
, "alloc",
723 sizeof "alloc" - 1) == 0)
726 input_line_pointer
+= sizeof "alloc" - 1;
728 else if (strncmp (input_line_pointer
, "execinstr",
729 sizeof "execinstr" - 1) == 0)
731 attr
|= SHF_EXECINSTR
;
732 input_line_pointer
+= sizeof "execinstr" - 1;
736 #ifdef md_elf_section_word
737 int md_attr
= md_elf_section_word (&input_line_pointer
);
743 as_warn ("Unrecognized section attribute");
744 ignore_rest_of_line ();
750 while (*input_line_pointer
++ == ',');
751 --input_line_pointer
;
755 /* See if this is one of the special sections. */
756 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
758 if (string
[1] == special_sections
[i
].name
[1]
759 && strcmp (string
, special_sections
[i
].name
) == 0)
761 if (type
== SHT_NULL
)
762 type
= special_sections
[i
].type
;
763 else if (type
!= special_sections
[i
].type
)
764 as_warn ("Setting incorrect section type for %s", string
);
766 if ((attr
&~ special_sections
[i
].attributes
) != 0)
768 /* As a GNU extension, we permit a .note section to be
769 allocatable. If the linker sees an allocateable
770 .note section, it will create a PT_NOTE segment in
772 if (strcmp (string
, ".note") != 0
773 || attr
!= SHF_ALLOC
)
774 as_warn ("Setting incorrect section attributes for %s",
777 attr
|= special_sections
[i
].attributes
;
784 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
785 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
786 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
787 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
788 if (special_sections
[i
].name
== NULL
)
790 if (type
== SHT_PROGBITS
)
791 flags
|= SEC_ALLOC
| SEC_LOAD
;
792 else if (type
== SHT_NOBITS
)
798 #ifdef md_elf_section_flags
799 flags
= md_elf_section_flags (flags
, attr
, type
);
803 bfd_set_section_flags (stdoutput
, sec
, flags
);
805 /* Add a symbol for this section to the symbol table. */
806 secsym
= symbol_find (string
);
808 secsym
->bsym
= sec
->symbol
;
810 symbol_table_insert (section_symbol (sec
));
812 #ifdef md_elf_section_change_hook
813 md_elf_section_change_hook ();
816 demand_empty_rest_of_line ();
819 /* Change to the .data section. */
825 #ifdef md_flush_pending_output
826 md_flush_pending_output ();
829 previous_section
= now_seg
;
830 previous_subsection
= now_subseg
;
833 #ifdef md_elf_section_change_hook
834 md_elf_section_change_hook ();
838 /* Change to the .text section. */
844 #ifdef md_flush_pending_output
845 md_flush_pending_output ();
848 previous_section
= now_seg
;
849 previous_subsection
= now_subseg
;
852 #ifdef md_elf_section_change_hook
853 md_elf_section_change_hook ();
858 obj_elf_subsection (ignore
)
863 #ifdef md_flush_pending_output
864 md_flush_pending_output ();
867 previous_section
= now_seg
;
868 previous_subsection
= now_subseg
;
870 temp
= get_absolute_expression ();
871 subseg_set (now_seg
, (subsegT
) temp
);
872 demand_empty_rest_of_line ();
874 #ifdef md_elf_section_change_hook
875 md_elf_section_change_hook ();
879 /* This can be called from the processor backends if they change
883 obj_elf_section_change_hook ()
885 previous_section
= now_seg
;
886 previous_subsection
= now_subseg
;
890 obj_elf_previous (ignore
)
893 if (previous_section
== 0)
895 as_bad (".previous without corresponding .section; ignored");
899 #ifdef md_flush_pending_output
900 md_flush_pending_output ();
903 subseg_set (previous_section
, previous_subsection
);
904 previous_section
= 0;
906 #ifdef md_elf_section_change_hook
907 md_elf_section_change_hook ();
912 obj_elf_line (ignore
)
915 /* Assume delimiter is part of expression. BSD4.2 as fails with
916 delightful bug, so we are not being incompatible here. */
917 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
918 demand_empty_rest_of_line ();
921 /* This handle the .symver pseudo-op, which is used to specify a
922 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
923 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
924 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
925 with the same value as the symbol NAME. */
928 obj_elf_symver (ignore
)
935 name
= input_line_pointer
;
936 c
= get_symbol_end ();
938 sym
= symbol_find_or_make (name
);
940 *input_line_pointer
= c
;
942 if (sym
->sy_obj
.versioned_name
!= NULL
)
944 as_bad ("multiple .symver directives for symbol `%s'",
946 ignore_rest_of_line ();
951 if (*input_line_pointer
!= ',')
953 as_bad ("expected comma after name in .symver");
954 ignore_rest_of_line ();
958 ++input_line_pointer
;
959 name
= input_line_pointer
;
962 c
= get_symbol_end ();
963 if (c
!= ELF_VER_CHR
)
965 *input_line_pointer
++ = c
;
968 sym
->sy_obj
.versioned_name
= xstrdup (name
);
970 *input_line_pointer
= c
;
972 if (strchr (sym
->sy_obj
.versioned_name
, ELF_VER_CHR
) == NULL
)
974 as_bad ("missing version name in `%s' for symbol `%s'",
975 sym
->sy_obj
.versioned_name
, S_GET_NAME (sym
));
976 ignore_rest_of_line ();
980 demand_empty_rest_of_line ();
984 obj_read_begin_hook ()
986 #ifdef NEED_ECOFF_DEBUG
988 ecoff_read_begin_hook ();
993 obj_symbol_new_hook (symbolP
)
996 symbolP
->sy_obj
.size
= NULL
;
997 symbolP
->sy_obj
.versioned_name
= NULL
;
999 #ifdef NEED_ECOFF_DEBUG
1000 if (ECOFF_DEBUGGING
)
1001 ecoff_symbol_new_hook (symbolP
);
1006 obj_elf_version (ignore
)
1013 asection
*seg
= now_seg
;
1014 subsegT subseg
= now_subseg
;
1015 Elf_Internal_Note i_note
;
1016 Elf_External_Note e_note
;
1017 asection
*note_secp
= (asection
*) NULL
;
1021 if (*input_line_pointer
== '\"')
1023 ++input_line_pointer
; /* -> 1st char of string. */
1024 name
= input_line_pointer
;
1026 while (is_a_char (c
= next_char_of_string ()))
1028 c
= *input_line_pointer
;
1029 *input_line_pointer
= '\0';
1030 *(input_line_pointer
- 1) = '\0';
1031 *input_line_pointer
= c
;
1033 /* create the .note section */
1035 note_secp
= subseg_new (".note", 0);
1036 bfd_set_section_flags (stdoutput
,
1038 SEC_HAS_CONTENTS
| SEC_READONLY
);
1040 /* process the version string */
1042 len
= strlen (name
);
1044 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
1045 i_note
.descsz
= 0; /* no description */
1046 i_note
.type
= NT_VERSION
;
1047 p
= frag_more (sizeof (e_note
.namesz
));
1048 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1049 p
= frag_more (sizeof (e_note
.descsz
));
1050 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1051 p
= frag_more (sizeof (e_note
.type
));
1052 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1054 for (i
= 0; i
< len
; i
++)
1058 FRAG_APPEND_1_CHAR (ch
);
1061 frag_align (2, 0, 0);
1063 subseg_set (seg
, subseg
);
1067 as_bad ("Expected quoted string");
1069 demand_empty_rest_of_line ();
1073 obj_elf_size (ignore
)
1076 char *name
= input_line_pointer
;
1077 char c
= get_symbol_end ();
1082 p
= input_line_pointer
;
1085 if (*input_line_pointer
!= ',')
1088 as_bad ("expected comma after name `%s' in .size directive", name
);
1090 ignore_rest_of_line ();
1093 input_line_pointer
++;
1095 if (exp
.X_op
== O_absent
)
1097 as_bad ("missing expression in .size directive");
1098 exp
.X_op
= O_constant
;
1099 exp
.X_add_number
= 0;
1102 sym
= symbol_find_or_make (name
);
1104 if (exp
.X_op
== O_constant
)
1105 S_SET_SIZE (sym
, exp
.X_add_number
);
1108 sym
->sy_obj
.size
= (expressionS
*) xmalloc (sizeof (expressionS
));
1109 *sym
->sy_obj
.size
= exp
;
1111 demand_empty_rest_of_line ();
1114 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1115 There are three syntaxes. The first (used on Solaris) is
1117 The second (used on UnixWare) is
1119 The third (reportedly to be used on Irix 6.0) is
1124 obj_elf_type (ignore
)
1130 const char *typename
;
1133 name
= input_line_pointer
;
1134 c
= get_symbol_end ();
1135 sym
= symbol_find_or_make (name
);
1136 *input_line_pointer
= c
;
1139 if (*input_line_pointer
== ',')
1140 ++input_line_pointer
;
1143 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
1144 ++input_line_pointer
;
1146 typename
= input_line_pointer
;
1147 c
= get_symbol_end ();
1150 if (strcmp (typename
, "function") == 0
1151 || strcmp (typename
, "STT_FUNC") == 0)
1152 type
= BSF_FUNCTION
;
1153 else if (strcmp (typename
, "object") == 0
1154 || strcmp (typename
, "STT_OBJECT") == 0)
1157 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
1159 *input_line_pointer
= c
;
1161 sym
->bsym
->flags
|= type
;
1163 demand_empty_rest_of_line ();
1167 obj_elf_ident (ignore
)
1170 static segT comment_section
;
1171 segT old_section
= now_seg
;
1172 int old_subsection
= now_subseg
;
1174 if (!comment_section
)
1177 comment_section
= subseg_new (".comment", 0);
1178 bfd_set_section_flags (stdoutput
, comment_section
,
1179 SEC_READONLY
| SEC_HAS_CONTENTS
);
1184 subseg_set (comment_section
, 0);
1186 subseg_set (old_section
, old_subsection
);
1189 #ifdef INIT_STAB_SECTION
1191 /* The first entry in a .stabs section is special. */
1194 obj_elf_init_stab_section (seg
)
1200 unsigned int stroff
;
1202 /* Force the section to align to a longword boundary. Without this,
1203 UnixWare ar crashes. */
1204 bfd_set_section_alignment (stdoutput
, seg
, 2);
1206 /* Make space for this first symbol. */
1210 as_where (&file
, (unsigned int *) NULL
);
1211 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1212 strcpy (stabstr_name
, segment_name (seg
));
1213 strcat (stabstr_name
, "str");
1214 stroff
= get_stab_string_offset (file
, stabstr_name
);
1216 md_number_to_chars (p
, stroff
, 4);
1217 seg_info (seg
)->stabu
.p
= p
;
1222 /* Fill in the counts in the first entry in a .stabs section. */
1225 adjust_stab_sections (abfd
, sec
, xxx
)
1235 if (strncmp (".stab", sec
->name
, 5))
1237 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1240 name
= (char *) alloca (strlen (sec
->name
) + 4);
1241 strcpy (name
, sec
->name
);
1242 strcat (name
, "str");
1243 strsec
= bfd_get_section_by_name (abfd
, name
);
1245 strsz
= bfd_section_size (abfd
, strsec
);
1248 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1250 p
= seg_info (sec
)->stabu
.p
;
1253 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1254 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1257 #ifdef NEED_ECOFF_DEBUG
1259 /* This function is called by the ECOFF code. It is supposed to
1260 record the external symbol information so that the backend can
1261 write it out correctly. The ELF backend doesn't actually handle
1262 this at the moment, so we do it ourselves. We save the information
1266 elf_ecoff_set_ext (sym
, ext
)
1268 struct ecoff_extr
*ext
;
1270 sym
->bsym
->udata
.p
= (PTR
) ext
;
1273 /* This function is called by bfd_ecoff_debug_externals. It is
1274 supposed to *EXT to the external symbol information, and return
1275 whether the symbol should be used at all. */
1278 elf_get_extr (sym
, ext
)
1282 if (sym
->udata
.p
== NULL
)
1284 *ext
= *(EXTR
*) sym
->udata
.p
;
1288 /* This function is called by bfd_ecoff_debug_externals. It has
1289 nothing to do for ELF. */
1293 elf_set_index (sym
, indx
)
1299 #endif /* NEED_ECOFF_DEBUG */
1302 elf_frob_symbol (symp
, puntp
)
1306 #ifdef NEED_ECOFF_DEBUG
1307 if (ECOFF_DEBUGGING
)
1308 ecoff_frob_symbol (symp
);
1311 if (symp
->sy_obj
.size
!= NULL
)
1313 switch (symp
->sy_obj
.size
->X_op
)
1317 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1318 + symp
->sy_obj
.size
->X_add_number
1319 - S_GET_VALUE (symp
->sy_obj
.size
->X_op_symbol
)));
1323 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1324 + symp
->sy_obj
.size
->X_add_number
));
1327 as_bad (".size expression too complicated to fix up");
1330 free (symp
->sy_obj
.size
);
1331 symp
->sy_obj
.size
= NULL
;
1334 if (symp
->sy_obj
.versioned_name
!= NULL
)
1336 /* This symbol was given a new name with the .symver directive.
1338 If this is an external reference, just rename the symbol to
1339 include the version string. This will make the relocs be
1340 against the correct versioned symbol.
1342 If this is a definition, add an alias. FIXME: Using an alias
1343 will permit the debugging information to refer to the right
1344 symbol. However, it's not clear whether it is the best
1347 if (! S_IS_DEFINED (symp
))
1351 /* Verify that the name isn't using the @@ syntax--this is
1352 reserved for definitions of the default version to link
1354 p
= strchr (symp
->sy_obj
.versioned_name
, ELF_VER_CHR
);
1356 if (p
[1] == ELF_VER_CHR
)
1358 as_bad ("invalid attempt to declare external version name as default in symbol `%s'",
1359 symp
->sy_obj
.versioned_name
);
1362 S_SET_NAME (symp
, symp
->sy_obj
.versioned_name
);
1368 /* FIXME: Creating a new symbol here is risky. We're in the
1369 final loop over the symbol table. We can get away with
1370 it only because the symbol goes to the end of the list,
1371 where the loop will still see it. It would probably be
1372 better to do this in obj_frob_file_before_adjust. */
1374 symp2
= symbol_find_or_make (symp
->sy_obj
.versioned_name
);
1376 /* Now we act as though we saw symp2 = sym. */
1378 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1380 /* Subtracting out the frag address here is a hack because
1381 we are in the middle of the final loop. */
1382 S_SET_VALUE (symp2
, S_GET_VALUE (symp
) - symp
->sy_frag
->fr_address
);
1384 symp2
->sy_frag
= symp
->sy_frag
;
1386 /* This will copy over the size information. */
1387 copy_symbol_attributes (symp2
, symp
);
1389 if (S_IS_WEAK (symp
))
1392 if (S_IS_EXTERNAL (symp
))
1393 S_SET_EXTERNAL (symp2
);
1397 /* Double check weak symbols. */
1398 if (symp
->bsym
->flags
& BSF_WEAK
)
1400 if (S_IS_COMMON (symp
))
1401 as_bad ("Symbol `%s' can not be both weak and common",
1406 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1407 any undefined non-function symbol to STT_OBJECT. We try to be
1408 compatible, since newer Irix 5 and 6 linkers care. However, we
1409 only set undefined symbols to be STT_OBJECT if we are on Irix,
1410 because that is the only time gcc will generate the necessary
1411 .global directives to mark functions. */
1413 if (S_IS_COMMON (symp
))
1414 symp
->bsym
->flags
|= BSF_OBJECT
;
1416 if (strstr (TARGET_OS
, "irix") != NULL
1417 && (! S_IS_DEFINED (symp
) && ((symp
->bsym
->flags
& BSF_FUNCTION
) == 0)))
1418 symp
->bsym
->flags
|= BSF_OBJECT
;
1422 /* Frob the PowerPC, so that the symbol always has object type
1423 if it is not some other type. VxWorks needs this. */
1424 if ((symp
->bsym
->flags
& (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1425 && S_IS_DEFINED (symp
))
1426 symp
->bsym
->flags
|= BSF_OBJECT
;
1433 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1435 #ifdef elf_tc_final_processing
1436 elf_tc_final_processing ();
1440 /* It is required that we let write_relocs have the opportunity to
1441 optimize away fixups before output has begun, since it is possible
1442 to eliminate all fixups for a section and thus we never should
1443 have generated the relocation section. */
1446 elf_frob_file_after_relocs ()
1448 #ifdef NEED_ECOFF_DEBUG
1449 if (ECOFF_DEBUGGING
)
1450 /* Generate the ECOFF debugging information. */
1452 const struct ecoff_debug_swap
*debug_swap
;
1453 struct ecoff_debug_info debug
;
1458 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1459 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1460 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1462 /* Set up the pointers in debug. */
1463 #define SET(ptr, offset, type) \
1464 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1466 SET (line
, cbLineOffset
, unsigned char *);
1467 SET (external_dnr
, cbDnOffset
, PTR
);
1468 SET (external_pdr
, cbPdOffset
, PTR
);
1469 SET (external_sym
, cbSymOffset
, PTR
);
1470 SET (external_opt
, cbOptOffset
, PTR
);
1471 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1472 SET (ss
, cbSsOffset
, char *);
1473 SET (external_fdr
, cbFdOffset
, PTR
);
1474 SET (external_rfd
, cbRfdOffset
, PTR
);
1475 /* ssext and external_ext are set up just below. */
1479 /* Set up the external symbols. */
1480 debug
.ssext
= debug
.ssext_end
= NULL
;
1481 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1482 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1483 elf_get_extr
, elf_set_index
))
1484 as_fatal ("Failed to set up debugging information: %s",
1485 bfd_errmsg (bfd_get_error ()));
1487 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1488 assert (sec
!= NULL
);
1490 know (stdoutput
->output_has_begun
== false);
1492 /* We set the size of the section, call bfd_set_section_contents
1493 to force the ELF backend to allocate a file position, and then
1494 write out the data. FIXME: Is this really the best way to do
1496 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1498 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1499 (file_ptr
) 0, (bfd_size_type
) 0))
1500 as_fatal ("Can't start writing .mdebug section: %s",
1501 bfd_errmsg (bfd_get_error ()));
1503 know (stdoutput
->output_has_begun
== true);
1504 know (sec
->filepos
!= 0);
1506 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1508 as_fatal ("Could not write .mdebug section: %s",
1509 bfd_errmsg (bfd_get_error ()));
1511 #endif /* NEED_ECOFF_DEBUG */
1516 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1517 SCO specific identifier in the .notes section to satisfy the SCO
1520 This looks more complicated than it really is. As opposed to the
1521 "obvious" solution, this should handle the cross dev cases
1522 correctly. (i.e, hosting on a 64 bit big endian processor, but
1523 generating SCO Elf code) Efficiency isn't a concern, as there
1524 should be exactly one of these sections per object module.
1526 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1529 int_32 namesz = 4 ; Name size
1530 int_32 descsz = 12 ; Descriptive information
1532 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1533 int_32 version = (major ver # << 16) | version of tools ;
1534 int_32 source = (tool_id << 16 ) | 1 ;
1535 int_32 info = 0 ; These are set by the SCO tools, but we
1536 don't know enough about the source
1537 environment to set them. SCO ld currently
1538 ignores them, and recommends we set them
1541 #define SCO_MAJOR_VERSION 0x1
1542 #define SCO_MINOR_VERSION 0x1
1552 asection
*seg
= now_seg
;
1553 subsegT subseg
= now_subseg
;
1554 Elf_Internal_Note i_note
;
1555 Elf_External_Note e_note
;
1556 asection
*note_secp
= (asection
*) NULL
;
1559 /* create the .note section */
1561 note_secp
= subseg_new (".note", 0);
1562 bfd_set_section_flags (stdoutput
,
1564 SEC_HAS_CONTENTS
| SEC_READONLY
);
1566 /* process the version string */
1569 i_note
.descsz
= 12; /* 12 descriptive bytes */
1570 i_note
.type
= NT_VERSION
; /* Contains a version string */
1572 p
= frag_more (sizeof (i_note
.namesz
));
1573 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1575 p
= frag_more (sizeof (i_note
.descsz
));
1576 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1578 p
= frag_more (sizeof (i_note
.type
));
1579 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1584 /* Note: this is the version number of the ELF we're representing */
1586 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1588 /* Here, we pick a magic number for ourselves (yes, I "registered"
1589 it with SCO. The bottom bit shows that we are compat with the
1592 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1594 /* If we knew (or cared) what the source language options were, we'd
1595 fill them in here. SCO has given us permission to ignore these
1596 and just set them to zero. */
1598 md_number_to_chars (p
, 0x0000, 4);
1600 frag_align (2, 0, 0);
1602 /* We probably can't restore the current segment, for there likely
1605 subseg_set (seg
, subseg
);
1609 #endif /* SCO_ELF */
1611 const struct format_ops elf_format_ops
=
1613 bfd_target_elf_flavour
,
1618 elf_frob_file_after_relocs
,
1619 elf_s_get_size
, elf_s_set_size
,
1620 elf_s_get_align
, elf_s_set_align
,
1621 elf_copy_symbol_attributes
,
1622 #ifdef NEED_ECOFF_DEBUG
1623 ecoff_generate_asm_lineno
,
1627 0, /* process_stab */
1629 elf_sec_sym_ok_for_reloc
,
1631 #ifdef NEED_ECOFF_DEBUG
1636 obj_read_begin_hook
,
1637 obj_symbol_new_hook
,