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 #ifdef NEED_ECOFF_DEBUG
45 static boolean elf_get_extr
PARAMS ((asymbol
*, EXTR
*));
46 static void elf_set_index
PARAMS ((asymbol
*, bfd_size_type
));
49 static void obj_elf_line
PARAMS ((int));
50 void obj_elf_version
PARAMS ((int));
51 static void obj_elf_size
PARAMS ((int));
52 static void obj_elf_type
PARAMS ((int));
53 static void obj_elf_ident
PARAMS ((int));
54 static void obj_elf_weak
PARAMS ((int));
55 static void obj_elf_local
PARAMS ((int));
56 static void obj_elf_common
PARAMS ((int));
57 static void obj_elf_symver
PARAMS ((int));
58 static void obj_elf_data
PARAMS ((int));
59 static void obj_elf_text
PARAMS ((int));
61 static const pseudo_typeS elf_pseudo_table
[] =
63 {"comm", obj_elf_common
, 0},
64 {"ident", obj_elf_ident
, 0},
65 {"local", obj_elf_local
, 0},
66 {"previous", obj_elf_previous
, 0},
67 {"section", obj_elf_section
, 0},
68 {"section.s", obj_elf_section
, 0},
69 {"sect", obj_elf_section
, 0},
70 {"sect.s", obj_elf_section
, 0},
71 {"size", obj_elf_size
, 0},
72 {"type", obj_elf_type
, 0},
73 {"version", obj_elf_version
, 0},
74 {"weak", obj_elf_weak
, 0},
76 /* These are used for stabs-in-elf configurations. */
77 {"line", obj_elf_line
, 0},
79 /* This is a GNU extension to handle symbol versions. */
80 {"symver", obj_elf_symver
, 0},
82 /* These are used for dwarf. */
87 /* We need to trap the section changing calls to handle .previous. */
88 {"data", obj_elf_data
, 0},
89 {"text", obj_elf_text
, 0},
95 static const pseudo_typeS ecoff_debug_pseudo_table
[] =
97 #ifdef NEED_ECOFF_DEBUG
98 /* COFF style debugging information for ECOFF. .ln is not used; .loc
100 { "def", ecoff_directive_def
, 0 },
101 { "dim", ecoff_directive_dim
, 0 },
102 { "endef", ecoff_directive_endef
, 0 },
103 { "file", ecoff_directive_file
, 0 },
104 { "scl", ecoff_directive_scl
, 0 },
105 { "tag", ecoff_directive_tag
, 0 },
106 { "val", ecoff_directive_val
, 0 },
108 /* COFF debugging requires pseudo-ops .size and .type, but ELF
109 already has meanings for those. We use .esize and .etype
110 instead. These are only generated by gcc anyhow. */
111 { "esize", ecoff_directive_size
, 0 },
112 { "etype", ecoff_directive_type
, 0 },
114 /* ECOFF specific debugging information. */
115 { "begin", ecoff_directive_begin
, 0 },
116 { "bend", ecoff_directive_bend
, 0 },
117 { "end", ecoff_directive_end
, 0 },
118 { "ent", ecoff_directive_ent
, 0 },
119 { "fmask", ecoff_directive_fmask
, 0 },
120 { "frame", ecoff_directive_frame
, 0 },
121 { "loc", ecoff_directive_loc
, 0 },
122 { "mask", ecoff_directive_mask
, 0 },
124 /* Other ECOFF directives. */
125 { "extern", ecoff_directive_extern
, 0 },
127 /* These are used on Irix. I don't know how to implement them. */
128 { "alias", s_ignore
, 0 },
129 { "bgnb", s_ignore
, 0 },
130 { "endb", s_ignore
, 0 },
131 { "lab", s_ignore
, 0 },
132 { "noalias", s_ignore
, 0 },
133 { "verstamp", s_ignore
, 0 },
134 { "vreg", s_ignore
, 0 },
137 {NULL
} /* end sentinel */
141 #include "aout/aout64.h"
143 /* This is called when the assembler starts. */
148 /* Add symbols for the known sections to the symbol table. */
149 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
151 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
153 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput
,
160 pop_insert (elf_pseudo_table
);
162 pop_insert (ecoff_debug_pseudo_table
);
169 return S_GET_SIZE (sym
);
173 elf_s_set_size (sym
, sz
)
177 S_SET_SIZE (sym
, sz
);
181 elf_s_get_align (sym
)
184 return S_GET_ALIGN (sym
);
188 elf_s_set_align (sym
, align
)
192 S_SET_ALIGN (sym
, align
);
196 elf_copy_symbol_attributes (dest
, src
)
199 OBJ_COPY_SYMBOL_ATTRIBUTES (dest
, src
);
203 elf_sec_sym_ok_for_reloc (sec
)
206 return obj_sec_sym_ok_for_reloc (sec
);
215 sym
= symbol_new (s
, absolute_section
, (valueT
) 0, (struct frag
*) 0);
216 sym
->sy_frag
= &zero_address_frag
;
217 sym
->bsym
->flags
|= BSF_FILE
;
219 if (symbol_rootP
!= sym
)
221 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
222 symbol_insert (sym
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
224 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
228 #ifdef NEED_ECOFF_DEBUG
234 obj_elf_common (ignore
)
244 name
= input_line_pointer
;
245 c
= get_symbol_end ();
246 /* just after name is now '\0' */
247 p
= input_line_pointer
;
250 if (*input_line_pointer
!= ',')
252 as_bad ("Expected comma after symbol-name");
253 ignore_rest_of_line ();
256 input_line_pointer
++; /* skip ',' */
257 if ((temp
= get_absolute_expression ()) < 0)
259 as_bad (".COMMon length (%d.) <0! Ignored.", temp
);
260 ignore_rest_of_line ();
265 symbolP
= symbol_find_or_make (name
);
267 if (S_IS_DEFINED (symbolP
))
269 as_bad ("Ignoring attempt to re-define symbol");
270 ignore_rest_of_line ();
273 if (S_GET_VALUE (symbolP
) != 0)
275 if (S_GET_VALUE (symbolP
) != size
)
277 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
278 S_GET_NAME (symbolP
), (long) S_GET_VALUE (symbolP
), size
);
281 know (symbolP
->sy_frag
== &zero_address_frag
);
282 if (*input_line_pointer
!= ',')
287 input_line_pointer
++;
290 if (! have_align
|| *input_line_pointer
!= '"')
296 temp
= get_absolute_expression ();
300 as_warn ("Common alignment negative; 0 assumed");
312 old_subsec
= now_subseg
;
315 /* convert to a power of 2 alignment */
316 for (align
= 0; (temp
& 1) == 0; temp
>>= 1, ++align
);
319 as_bad ("Common alignment not a power of 2");
320 ignore_rest_of_line ();
326 record_alignment (bss_section
, align
);
327 subseg_set (bss_section
, 0);
329 frag_align (align
, 0, 0);
330 if (S_GET_SEGMENT (symbolP
) == bss_section
)
331 symbolP
->sy_frag
->fr_symbol
= 0;
332 symbolP
->sy_frag
= frag_now
;
333 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
336 S_SET_SIZE (symbolP
, size
);
337 S_SET_SEGMENT (symbolP
, bss_section
);
338 S_CLEAR_EXTERNAL (symbolP
);
339 subseg_set (old_sec
, old_subsec
);
344 S_SET_VALUE (symbolP
, (valueT
) size
);
345 S_SET_ALIGN (symbolP
, temp
);
346 S_SET_EXTERNAL (symbolP
);
347 /* should be common, but this is how gas does it for now */
348 S_SET_SEGMENT (symbolP
, bfd_und_section_ptr
);
353 input_line_pointer
++;
354 /* @@ Some use the dot, some don't. Can we get some consistency?? */
355 if (*input_line_pointer
== '.')
356 input_line_pointer
++;
357 /* @@ Some say data, some say bss. */
358 if (strncmp (input_line_pointer
, "bss\"", 4)
359 && strncmp (input_line_pointer
, "data\"", 5))
361 while (*--input_line_pointer
!= '"')
363 input_line_pointer
--;
364 goto bad_common_segment
;
366 while (*input_line_pointer
++ != '"')
368 goto allocate_common
;
371 symbolP
->bsym
->flags
|= BSF_OBJECT
;
373 demand_empty_rest_of_line ();
378 p
= input_line_pointer
;
379 while (*p
&& *p
!= '\n')
383 as_bad ("bad .common segment %s", input_line_pointer
+ 1);
385 input_line_pointer
= p
;
386 ignore_rest_of_line ();
392 obj_elf_local (ignore
)
401 name
= input_line_pointer
;
402 c
= get_symbol_end ();
403 symbolP
= symbol_find_or_make (name
);
404 *input_line_pointer
= c
;
406 S_CLEAR_EXTERNAL (symbolP
);
410 input_line_pointer
++;
412 if (*input_line_pointer
== '\n')
417 demand_empty_rest_of_line ();
421 obj_elf_weak (ignore
)
430 name
= input_line_pointer
;
431 c
= get_symbol_end ();
432 symbolP
= symbol_find_or_make (name
);
433 *input_line_pointer
= c
;
435 S_SET_WEAK (symbolP
);
439 input_line_pointer
++;
441 if (*input_line_pointer
== '\n')
446 demand_empty_rest_of_line ();
449 static segT previous_section
;
450 static int previous_subsection
;
452 /* Handle the .section pseudo-op. This code supports two different
455 The first is found on Solaris, and looks like
456 .section ".sec1",#alloc,#execinstr,#write
457 Here the names after '#' are the SHF_* flags to turn on for the
458 section. I'm not sure how it determines the SHT_* type (BFD
459 doesn't really give us control over the type, anyhow).
461 The second format is found on UnixWare, and probably most SVR4
462 machines, and looks like
463 .section .sec1,"a",@progbits
464 The quoted string may contain any combination of a, w, x, and
465 represents the SHF_* flags to turn on for the section. The string
466 beginning with '@' can be progbits or nobits. There should be
467 other possibilities, but I don't know what they are. In any case,
468 BFD doesn't really let us set the section type. */
470 /* Certain named sections have particular defined types, listed on p.
472 struct special_section
479 static struct special_section special_sections
[] =
481 { ".bss", SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
482 { ".comment", SHT_PROGBITS
, 0 },
483 { ".data", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
484 { ".data1", SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
485 { ".debug", SHT_PROGBITS
, 0 },
486 { ".fini", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
487 { ".init", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
488 { ".line", SHT_PROGBITS
, 0 },
489 { ".note", SHT_NOTE
, 0 },
490 { ".rodata", SHT_PROGBITS
, SHF_ALLOC
},
491 { ".rodata1", SHT_PROGBITS
, SHF_ALLOC
},
492 { ".text", SHT_PROGBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
494 #ifdef ELF_TC_SPECIAL_SECTIONS
495 ELF_TC_SPECIAL_SECTIONS
499 /* The following section names are special, but they can not
500 reasonably appear in assembler code. Some of the attributes are
501 processor dependent. */
502 { ".dynamic", SHT_DYNAMIC
, SHF_ALLOC
/* + SHF_WRITE */ },
503 { ".dynstr", SHT_STRTAB
, SHF_ALLOC
},
504 { ".dynsym", SHT_DYNSYM
, SHF_ALLOC
},
505 { ".got", SHT_PROGBITS
, 0 },
506 { ".hash", SHT_HASH
, SHF_ALLOC
},
507 { ".interp", SHT_PROGBITS
, /* SHF_ALLOC */ },
508 { ".plt", SHT_PROGBITS
, 0 },
509 { ".shstrtab",SHT_STRTAB
, 0 },
510 { ".strtab", SHT_STRTAB
, /* SHF_ALLOC */ },
511 { ".symtab", SHT_SYMTAB
, /* SHF_ALLOC */ },
518 obj_elf_section (xxx
)
529 #ifdef md_flush_pending_output
530 md_flush_pending_output ();
537 previous_section
= now_seg
;
538 previous_subsection
= now_subseg
;
540 s_mri_sect (&mri_type
);
542 #ifdef md_elf_section_change_hook
543 md_elf_section_change_hook ();
549 /* Get name of section. */
551 if (*input_line_pointer
== '"')
553 string
= demand_copy_C_string (&xxx
);
556 ignore_rest_of_line ();
562 char *p
= input_line_pointer
;
564 while (0 == strchr ("\n\t,; ", *p
))
566 if (p
== input_line_pointer
)
568 as_warn ("Missing section name");
569 ignore_rest_of_line ();
574 string
= xmalloc ((unsigned long) (p
- input_line_pointer
+ 1));
575 strcpy (string
, input_line_pointer
);
577 input_line_pointer
= p
;
580 /* Switch to the section, creating it if necessary. */
581 previous_section
= now_seg
;
582 previous_subsection
= now_subseg
;
584 new_sec
= bfd_get_section_by_name (stdoutput
, string
) == NULL
;
585 sec
= subseg_new (string
, 0);
587 /* If this section already existed, we don't bother to change the
591 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
592 ++input_line_pointer
;
593 ++input_line_pointer
;
595 #ifdef md_elf_section_change_hook
596 md_elf_section_change_hook ();
607 if (*input_line_pointer
== ',')
609 /* Skip the comma. */
610 ++input_line_pointer
;
613 if (*input_line_pointer
== '"')
615 /* Pick up a string with a combination of a, w, x. */
616 ++input_line_pointer
;
617 while (*input_line_pointer
!= '"')
619 switch (*input_line_pointer
)
628 attr
|= SHF_EXECINSTR
;
632 char *bad_msg
= "Bad .section directive: want a,w,x in string";
633 #ifdef md_elf_section_letter
634 int md_attr
= md_elf_section_letter (*input_line_pointer
, &bad_msg
);
641 ignore_rest_of_line ();
646 ++input_line_pointer
;
649 /* Skip the closing quote. */
650 ++input_line_pointer
;
653 if (*input_line_pointer
== ',')
655 ++input_line_pointer
;
657 if (*input_line_pointer
== '@')
659 ++input_line_pointer
;
660 if (strncmp (input_line_pointer
, "progbits",
661 sizeof "progbits" - 1) == 0)
664 input_line_pointer
+= sizeof "progbits" - 1;
666 else if (strncmp (input_line_pointer
, "nobits",
667 sizeof "nobits" - 1) == 0)
670 input_line_pointer
+= sizeof "nobits" - 1;
674 #ifdef md_elf_section_type
675 int md_type
= md_elf_section_type (&input_line_pointer
);
681 as_warn ("Unrecognized section type");
682 ignore_rest_of_line ();
693 if (*input_line_pointer
!= '#')
695 as_warn ("Bad .section directive");
696 ignore_rest_of_line ();
699 ++input_line_pointer
;
700 if (strncmp (input_line_pointer
, "write",
701 sizeof "write" - 1) == 0)
704 input_line_pointer
+= sizeof "write" - 1;
706 else if (strncmp (input_line_pointer
, "alloc",
707 sizeof "alloc" - 1) == 0)
710 input_line_pointer
+= sizeof "alloc" - 1;
712 else if (strncmp (input_line_pointer
, "execinstr",
713 sizeof "execinstr" - 1) == 0)
715 attr
|= SHF_EXECINSTR
;
716 input_line_pointer
+= sizeof "execinstr" - 1;
720 #ifdef md_elf_section_word
721 int md_attr
= md_elf_section_word (&input_line_pointer
);
727 as_warn ("Unrecognized section attribute");
728 ignore_rest_of_line ();
734 while (*input_line_pointer
++ == ',');
735 --input_line_pointer
;
739 /* See if this is one of the special sections. */
740 for (i
= 0; special_sections
[i
].name
!= NULL
; i
++)
742 if (string
[1] == special_sections
[i
].name
[1]
743 && strcmp (string
, special_sections
[i
].name
) == 0)
745 if (type
== SHT_NULL
)
746 type
= special_sections
[i
].type
;
747 else if (type
!= special_sections
[i
].type
)
748 as_warn ("Setting incorrect section type for %s", string
);
750 if ((attr
&~ special_sections
[i
].attributes
) != 0)
752 /* As a GNU extension, we permit a .note section to be
753 allocatable. If the linker sees an allocateable
754 .note section, it will create a PT_NOTE segment in
756 if (strcmp (string
, ".note") != 0
757 || attr
!= SHF_ALLOC
)
758 as_warn ("Setting incorrect section attributes for %s",
761 attr
|= special_sections
[i
].attributes
;
768 | ((attr
& SHF_WRITE
) ? 0 : SEC_READONLY
)
769 | ((attr
& SHF_ALLOC
) ? SEC_ALLOC
: 0)
770 | (((attr
& SHF_ALLOC
) && type
!= SHT_NOBITS
) ? SEC_LOAD
: 0)
771 | ((attr
& SHF_EXECINSTR
) ? SEC_CODE
: 0));
772 if (special_sections
[i
].name
== NULL
)
774 if (type
== SHT_PROGBITS
)
775 flags
|= SEC_ALLOC
| SEC_LOAD
;
776 else if (type
== SHT_NOBITS
)
782 #ifdef md_elf_section_flags
783 flags
= md_elf_section_flags (flags
, attr
, type
);
787 bfd_set_section_flags (stdoutput
, sec
, flags
);
789 /* Add a symbol for this section to the symbol table. */
790 secsym
= symbol_find (string
);
792 secsym
->bsym
= sec
->symbol
;
794 symbol_table_insert (section_symbol (sec
));
796 #ifdef md_elf_section_change_hook
797 md_elf_section_change_hook ();
800 demand_empty_rest_of_line ();
803 /* Change to the .data section. */
809 previous_section
= now_seg
;
810 previous_subsection
= now_subseg
;
814 /* Change to the .text section. */
820 previous_section
= now_seg
;
821 previous_subsection
= now_subseg
;
826 obj_elf_previous (ignore
)
829 if (previous_section
== 0)
831 as_bad (".previous without corresponding .section; ignored");
834 subseg_set (previous_section
, previous_subsection
);
835 previous_section
= 0;
839 obj_elf_line (ignore
)
842 /* Assume delimiter is part of expression. BSD4.2 as fails with
843 delightful bug, so we are not being incompatible here. */
844 new_logical_line ((char *) NULL
, (int) (get_absolute_expression ()));
845 demand_empty_rest_of_line ();
848 /* This handle the .symver pseudo-op, which is used to specify a
849 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
850 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
851 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
852 with the same value as the symbol NAME. */
855 obj_elf_symver (ignore
)
862 name
= input_line_pointer
;
863 c
= get_symbol_end ();
865 sym
= symbol_find_or_make (name
);
867 *input_line_pointer
= c
;
869 if (*input_line_pointer
!= ',')
871 as_bad ("expected comma after name in .symver");
872 ignore_rest_of_line ();
876 ++input_line_pointer
;
877 name
= input_line_pointer
;
880 c
= get_symbol_end ();
881 if (c
!= ELF_VER_CHR
)
883 *input_line_pointer
++ = c
;
886 sym
->sy_obj
.versioned_name
= xstrdup (name
);
888 *input_line_pointer
= c
;
890 demand_empty_rest_of_line ();
894 obj_read_begin_hook ()
896 #ifdef NEED_ECOFF_DEBUG
898 ecoff_read_begin_hook ();
903 obj_symbol_new_hook (symbolP
)
906 symbolP
->sy_obj
.size
= NULL
;
907 symbolP
->sy_obj
.versioned_name
= NULL
;
909 #ifdef NEED_ECOFF_DEBUG
911 ecoff_symbol_new_hook (symbolP
);
916 obj_elf_version (ignore
)
923 asection
*seg
= now_seg
;
924 subsegT subseg
= now_subseg
;
925 Elf_Internal_Note i_note
;
926 Elf_External_Note e_note
;
927 asection
*note_secp
= (asection
*) NULL
;
931 if (*input_line_pointer
== '\"')
933 ++input_line_pointer
; /* -> 1st char of string. */
934 name
= input_line_pointer
;
936 while (is_a_char (c
= next_char_of_string ()))
938 c
= *input_line_pointer
;
939 *input_line_pointer
= '\0';
940 *(input_line_pointer
- 1) = '\0';
941 *input_line_pointer
= c
;
943 /* create the .note section */
945 note_secp
= subseg_new (".note", 0);
946 bfd_set_section_flags (stdoutput
,
948 SEC_HAS_CONTENTS
| SEC_READONLY
);
950 /* process the version string */
954 i_note
.namesz
= ((len
+ 1) + 3) & ~3; /* round this to word boundary */
955 i_note
.descsz
= 0; /* no description */
956 i_note
.type
= NT_VERSION
;
957 p
= frag_more (sizeof (e_note
.namesz
));
958 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
959 p
= frag_more (sizeof (e_note
.descsz
));
960 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
961 p
= frag_more (sizeof (e_note
.type
));
962 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
964 for (i
= 0; i
< len
; i
++)
968 FRAG_APPEND_1_CHAR (ch
);
971 frag_align (2, 0, 0);
973 subseg_set (seg
, subseg
);
977 as_bad ("Expected quoted string");
979 demand_empty_rest_of_line ();
983 obj_elf_size (ignore
)
986 char *name
= input_line_pointer
;
987 char c
= get_symbol_end ();
992 p
= input_line_pointer
;
995 if (*input_line_pointer
!= ',')
998 as_bad ("expected comma after name `%s' in .size directive", name
);
1000 ignore_rest_of_line ();
1003 input_line_pointer
++;
1005 if (exp
.X_op
== O_absent
)
1007 as_bad ("missing expression in .size directive");
1008 exp
.X_op
= O_constant
;
1009 exp
.X_add_number
= 0;
1012 sym
= symbol_find_or_make (name
);
1014 if (exp
.X_op
== O_constant
)
1015 S_SET_SIZE (sym
, exp
.X_add_number
);
1018 sym
->sy_obj
.size
= (expressionS
*) xmalloc (sizeof (expressionS
));
1019 *sym
->sy_obj
.size
= exp
;
1021 demand_empty_rest_of_line ();
1024 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1025 There are three syntaxes. The first (used on Solaris) is
1027 The second (used on UnixWare) is
1029 The third (reportedly to be used on Irix 6.0) is
1034 obj_elf_type (ignore
)
1040 const char *typename
;
1043 name
= input_line_pointer
;
1044 c
= get_symbol_end ();
1045 sym
= symbol_find_or_make (name
);
1046 *input_line_pointer
= c
;
1049 if (*input_line_pointer
== ',')
1050 ++input_line_pointer
;
1053 if (*input_line_pointer
== '#' || *input_line_pointer
== '@')
1054 ++input_line_pointer
;
1056 typename
= input_line_pointer
;
1057 c
= get_symbol_end ();
1060 if (strcmp (typename
, "function") == 0
1061 || strcmp (typename
, "STT_FUNC") == 0)
1062 type
= BSF_FUNCTION
;
1063 else if (strcmp (typename
, "object") == 0
1064 || strcmp (typename
, "STT_OBJECT") == 0)
1067 as_bad ("ignoring unrecognized symbol type \"%s\"", typename
);
1069 *input_line_pointer
= c
;
1071 sym
->bsym
->flags
|= type
;
1073 demand_empty_rest_of_line ();
1077 obj_elf_ident (ignore
)
1080 static segT comment_section
;
1081 segT old_section
= now_seg
;
1082 int old_subsection
= now_subseg
;
1084 if (!comment_section
)
1087 comment_section
= subseg_new (".comment", 0);
1088 bfd_set_section_flags (stdoutput
, comment_section
,
1089 SEC_READONLY
| SEC_HAS_CONTENTS
);
1094 subseg_set (comment_section
, 0);
1096 subseg_set (old_section
, old_subsection
);
1099 #ifdef INIT_STAB_SECTION
1101 /* The first entry in a .stabs section is special. */
1104 obj_elf_init_stab_section (seg
)
1110 unsigned int stroff
;
1112 /* Force the section to align to a longword boundary. Without this,
1113 UnixWare ar crashes. */
1114 bfd_set_section_alignment (stdoutput
, seg
, 2);
1116 /* Make space for this first symbol. */
1120 as_where (&file
, (unsigned int *) NULL
);
1121 stabstr_name
= (char *) alloca (strlen (segment_name (seg
)) + 4);
1122 strcpy (stabstr_name
, segment_name (seg
));
1123 strcat (stabstr_name
, "str");
1124 stroff
= get_stab_string_offset (file
, stabstr_name
);
1126 md_number_to_chars (p
, stroff
, 4);
1127 seg_info (seg
)->stabu
.p
= p
;
1132 /* Fill in the counts in the first entry in a .stabs section. */
1135 adjust_stab_sections (abfd
, sec
, xxx
)
1145 if (strncmp (".stab", sec
->name
, 5))
1147 if (!strcmp ("str", sec
->name
+ strlen (sec
->name
) - 3))
1150 name
= (char *) alloca (strlen (sec
->name
) + 4);
1151 strcpy (name
, sec
->name
);
1152 strcat (name
, "str");
1153 strsec
= bfd_get_section_by_name (abfd
, name
);
1155 strsz
= bfd_section_size (abfd
, strsec
);
1158 nsyms
= bfd_section_size (abfd
, sec
) / 12 - 1;
1160 p
= seg_info (sec
)->stabu
.p
;
1163 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
1164 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
1167 #ifdef NEED_ECOFF_DEBUG
1169 /* This function is called by the ECOFF code. It is supposed to
1170 record the external symbol information so that the backend can
1171 write it out correctly. The ELF backend doesn't actually handle
1172 this at the moment, so we do it ourselves. We save the information
1176 elf_ecoff_set_ext (sym
, ext
)
1178 struct ecoff_extr
*ext
;
1180 sym
->bsym
->udata
.p
= (PTR
) ext
;
1183 /* This function is called by bfd_ecoff_debug_externals. It is
1184 supposed to *EXT to the external symbol information, and return
1185 whether the symbol should be used at all. */
1188 elf_get_extr (sym
, ext
)
1192 if (sym
->udata
.p
== NULL
)
1194 *ext
= *(EXTR
*) sym
->udata
.p
;
1198 /* This function is called by bfd_ecoff_debug_externals. It has
1199 nothing to do for ELF. */
1203 elf_set_index (sym
, indx
)
1209 #endif /* NEED_ECOFF_DEBUG */
1212 elf_frob_symbol (symp
, puntp
)
1216 #ifdef NEED_ECOFF_DEBUG
1217 if (ECOFF_DEBUGGING
)
1218 ecoff_frob_symbol (symp
);
1221 if (symp
->sy_obj
.size
!= NULL
)
1223 switch (symp
->sy_obj
.size
->X_op
)
1227 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1228 + symp
->sy_obj
.size
->X_add_number
1229 - S_GET_VALUE (symp
->sy_obj
.size
->X_op_symbol
)));
1233 (S_GET_VALUE (symp
->sy_obj
.size
->X_add_symbol
)
1234 + symp
->sy_obj
.size
->X_add_number
));
1237 as_bad (".size expression too complicated to fix up");
1240 free (symp
->sy_obj
.size
);
1241 symp
->sy_obj
.size
= NULL
;
1244 if (symp
->sy_obj
.versioned_name
!= NULL
)
1246 /* This symbol was given a new name with the .symver directive.
1248 If this is an external reference, just rename the symbol to
1249 include the version string. This will make the relocs be
1250 against the correct versioned symbol.
1252 If this is a definition, add an alias. FIXME: Using an alias
1253 will permit the debugging information to refer to the right
1254 symbol. However, it's not clear whether it is the best
1257 if (! S_IS_DEFINED (symp
))
1258 S_SET_NAME (symp
, symp
->sy_obj
.versioned_name
);
1263 /* FIXME: Creating a new symbol here is risky. We're in the
1264 final loop over the symbol table. We can get away with
1265 it only because the symbol goes to the end of the list,
1266 where the loop will still see it. It would probably be
1267 better to do this in obj_frob_file_before_adjust. */
1269 symp2
= symbol_find_or_make (symp
->sy_obj
.versioned_name
);
1271 /* Now we act as though we saw symp2 = sym. */
1273 S_SET_SEGMENT (symp2
, S_GET_SEGMENT (symp
));
1275 /* Subtracting out the frag address here is a hack because
1276 we are in the middle of the final loop. */
1277 S_SET_VALUE (symp2
, S_GET_VALUE (symp
) - symp
->sy_frag
->fr_address
);
1279 symp2
->sy_frag
= symp
->sy_frag
;
1281 /* This will copy over the size information. */
1282 copy_symbol_attributes (symp2
, symp
);
1284 if (S_IS_WEAK (symp
))
1287 if (S_IS_EXTERNAL (symp
))
1288 S_SET_EXTERNAL (symp2
);
1292 /* Double check weak symbols. */
1293 if (symp
->bsym
->flags
& BSF_WEAK
)
1295 if (S_IS_COMMON (symp
))
1296 as_bad ("Symbol `%s' can not be both weak and common",
1301 /* The Irix 5 assembler appears to set the type of any common symbol
1302 to STT_OBJECT. We try to be compatible, since the Irix 5 linker
1303 apparently sometimes cares. FIXME: What about Irix 6? */
1304 if (S_IS_COMMON (symp
))
1305 symp
->bsym
->flags
|= BSF_OBJECT
;
1309 /* Frob the PowerPC, so that the symbol always has object type
1310 if it is not some other type. VxWorks needs this. */
1311 if ((symp
->bsym
->flags
& (BSF_FUNCTION
| BSF_FILE
| BSF_SECTION_SYM
)) == 0
1312 && S_IS_DEFINED (symp
))
1313 symp
->bsym
->flags
|= BSF_OBJECT
;
1320 bfd_map_over_sections (stdoutput
, adjust_stab_sections
, (PTR
) 0);
1322 #ifdef elf_tc_final_processing
1323 elf_tc_final_processing ();
1327 /* It is required that we let write_relocs have the opportunity to
1328 optimize away fixups before output has begun, since it is possible
1329 to eliminate all fixups for a section and thus we never should
1330 have generated the relocation section. */
1333 elf_frob_file_after_relocs ()
1335 #ifdef NEED_ECOFF_DEBUG
1336 if (ECOFF_DEBUGGING
)
1337 /* Generate the ECOFF debugging information. */
1339 const struct ecoff_debug_swap
*debug_swap
;
1340 struct ecoff_debug_info debug
;
1345 = get_elf_backend_data (stdoutput
)->elf_backend_ecoff_debug_swap
;
1346 know (debug_swap
!= (const struct ecoff_debug_swap
*) NULL
);
1347 ecoff_build_debug (&debug
.symbolic_header
, &buf
, debug_swap
);
1349 /* Set up the pointers in debug. */
1350 #define SET(ptr, offset, type) \
1351 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1353 SET (line
, cbLineOffset
, unsigned char *);
1354 SET (external_dnr
, cbDnOffset
, PTR
);
1355 SET (external_pdr
, cbPdOffset
, PTR
);
1356 SET (external_sym
, cbSymOffset
, PTR
);
1357 SET (external_opt
, cbOptOffset
, PTR
);
1358 SET (external_aux
, cbAuxOffset
, union aux_ext
*);
1359 SET (ss
, cbSsOffset
, char *);
1360 SET (external_fdr
, cbFdOffset
, PTR
);
1361 SET (external_rfd
, cbRfdOffset
, PTR
);
1362 /* ssext and external_ext are set up just below. */
1366 /* Set up the external symbols. */
1367 debug
.ssext
= debug
.ssext_end
= NULL
;
1368 debug
.external_ext
= debug
.external_ext_end
= NULL
;
1369 if (! bfd_ecoff_debug_externals (stdoutput
, &debug
, debug_swap
, true,
1370 elf_get_extr
, elf_set_index
))
1371 as_fatal ("Failed to set up debugging information: %s",
1372 bfd_errmsg (bfd_get_error ()));
1374 sec
= bfd_get_section_by_name (stdoutput
, ".mdebug");
1375 assert (sec
!= NULL
);
1377 know (stdoutput
->output_has_begun
== false);
1379 /* We set the size of the section, call bfd_set_section_contents
1380 to force the ELF backend to allocate a file position, and then
1381 write out the data. FIXME: Is this really the best way to do
1383 sec
->_raw_size
= bfd_ecoff_debug_size (stdoutput
, &debug
, debug_swap
);
1385 if (! bfd_set_section_contents (stdoutput
, sec
, (PTR
) NULL
,
1386 (file_ptr
) 0, (bfd_size_type
) 0))
1387 as_fatal ("Can't start writing .mdebug section: %s",
1388 bfd_errmsg (bfd_get_error ()));
1390 know (stdoutput
->output_has_begun
== true);
1391 know (sec
->filepos
!= 0);
1393 if (! bfd_ecoff_write_debug (stdoutput
, &debug
, debug_swap
,
1395 as_fatal ("Could not write .mdebug section: %s",
1396 bfd_errmsg (bfd_get_error ()));
1398 #endif /* NEED_ECOFF_DEBUG */
1403 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1404 SCO specific identifier in the .notes section to satisfy the SCO
1407 This looks more complicated than it really is. As opposed to the
1408 "obvious" solution, this should handle the cross dev cases
1409 correctly. (i.e, hosting on a 64 bit big endian processor, but
1410 generating SCO Elf code) Efficiency isn't a concern, as there
1411 should be exactly one of these sections per object module.
1413 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1416 int_32 namesz = 4 ; Name size
1417 int_32 descsz = 12 ; Descriptive information
1419 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1420 int_32 version = (major ver # << 16) | version of tools ;
1421 int_32 source = (tool_id << 16 ) | 1 ;
1422 int_32 info = 0 ; These are set by the SCO tools, but we
1423 don't know enough about the source
1424 environment to set them. SCO ld currently
1425 ignores them, and recommends we set them
1428 #define SCO_MAJOR_VERSION 0x1
1429 #define SCO_MINOR_VERSION 0x1
1439 asection
*seg
= now_seg
;
1440 subsegT subseg
= now_subseg
;
1441 Elf_Internal_Note i_note
;
1442 Elf_External_Note e_note
;
1443 asection
*note_secp
= (asection
*) NULL
;
1446 /* create the .note section */
1448 note_secp
= subseg_new (".note", 0);
1449 bfd_set_section_flags (stdoutput
,
1451 SEC_HAS_CONTENTS
| SEC_READONLY
);
1453 /* process the version string */
1456 i_note
.descsz
= 12; /* 12 descriptive bytes */
1457 i_note
.type
= NT_VERSION
; /* Contains a version string */
1459 p
= frag_more (sizeof (i_note
.namesz
));
1460 md_number_to_chars (p
, (valueT
) i_note
.namesz
, 4);
1462 p
= frag_more (sizeof (i_note
.descsz
));
1463 md_number_to_chars (p
, (valueT
) i_note
.descsz
, 4);
1465 p
= frag_more (sizeof (i_note
.type
));
1466 md_number_to_chars (p
, (valueT
) i_note
.type
, 4);
1471 /* Note: this is the version number of the ELF we're representing */
1473 md_number_to_chars (p
, (SCO_MAJOR_VERSION
<< 16) | (SCO_MINOR_VERSION
), 4);
1475 /* Here, we pick a magic number for ourselves (yes, I "registered"
1476 it with SCO. The bottom bit shows that we are compat with the
1479 md_number_to_chars (p
, 0x4c520000 | 0x0001, 4);
1481 /* If we knew (or cared) what the source language options were, we'd
1482 fill them in here. SCO has given us permission to ignore these
1483 and just set them to zero. */
1485 md_number_to_chars (p
, 0x0000, 4);
1487 frag_align (2, 0, 0);
1489 /* We probably can't restore the current segment, for there likely
1492 subseg_set (seg
, subseg
);
1496 #endif /* SCO_ELF */
1498 const struct format_ops elf_format_ops
=
1500 bfd_target_elf_flavour
,
1505 elf_frob_file_after_relocs
,
1506 elf_s_get_size
, elf_s_set_size
,
1507 elf_s_get_align
, elf_s_set_align
,
1508 elf_copy_symbol_attributes
,
1509 #ifdef NEED_ECOFF_DEBUG
1510 ecoff_generate_asm_lineno
,
1514 0, /* process_stab */
1516 elf_sec_sym_ok_for_reloc
,
1518 #ifdef NEED_ECOFF_DEBUG
1523 obj_read_begin_hook
,
1524 obj_symbol_new_hook
,