Assign correct reloc value to size 1 fixes.
[binutils.git] / gas / config / obj-elf.c
blob21fd0fa22411c5d5676eaec1db264a992f0feb1c
1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2,
10 or (at your option) any later version.
12 GAS is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #define OBJ_HEADER "obj-elf.h"
23 #include "as.h"
24 #include "subsegs.h"
25 #include "obstack.h"
27 #ifndef ECOFF_DEBUGGING
28 #define ECOFF_DEBUGGING 0
29 #else
30 #define NEED_ECOFF_DEBUG
31 #endif
33 #ifdef NEED_ECOFF_DEBUG
34 #include "ecoff.h"
35 #endif
37 #ifdef TC_ALPHA
38 #include "elf/alpha.h"
39 #endif
41 #ifdef TC_MIPS
42 #include "elf/mips.h"
43 #endif
45 #ifdef TC_PPC
46 #include "elf/ppc.h"
47 #endif
49 #ifdef TC_I370
50 #include "elf/i370.h"
51 #endif
53 static bfd_vma elf_s_get_size PARAMS ((symbolS *));
54 static void elf_s_set_size PARAMS ((symbolS *, bfd_vma));
55 static bfd_vma elf_s_get_align PARAMS ((symbolS *));
56 static void elf_s_set_align PARAMS ((symbolS *, bfd_vma));
57 static void elf_copy_symbol_attributes PARAMS ((symbolS *, symbolS *));
58 static int elf_sec_sym_ok_for_reloc PARAMS ((asection *));
59 static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));
61 #ifdef NEED_ECOFF_DEBUG
62 static boolean elf_get_extr PARAMS ((asymbol *, EXTR *));
63 static void elf_set_index PARAMS ((asymbol *, bfd_size_type));
64 #endif
66 static void obj_elf_line PARAMS ((int));
67 void obj_elf_version PARAMS ((int));
68 static void obj_elf_size PARAMS ((int));
69 static void obj_elf_type PARAMS ((int));
70 static void obj_elf_ident PARAMS ((int));
71 static void obj_elf_weak PARAMS ((int));
72 static void obj_elf_local PARAMS ((int));
73 static void obj_elf_visibility PARAMS ((int));
74 static void obj_elf_symver PARAMS ((int));
75 static void obj_elf_vtable_inherit PARAMS ((int));
76 static void obj_elf_vtable_entry PARAMS ((int));
77 static void obj_elf_subsection PARAMS ((int));
78 static void obj_elf_popsection PARAMS ((int));
80 static const pseudo_typeS elf_pseudo_table[] =
82 {"comm", obj_elf_common, 0},
83 {"common", obj_elf_common, 1},
84 {"ident", obj_elf_ident, 0},
85 {"local", obj_elf_local, 0},
86 {"previous", obj_elf_previous, 0},
87 {"section", obj_elf_section, 0},
88 {"section.s", obj_elf_section, 0},
89 {"sect", obj_elf_section, 0},
90 {"sect.s", obj_elf_section, 0},
91 {"pushsection", obj_elf_section, 1},
92 {"popsection", obj_elf_popsection, 0},
93 {"size", obj_elf_size, 0},
94 {"type", obj_elf_type, 0},
95 {"version", obj_elf_version, 0},
96 {"weak", obj_elf_weak, 0},
98 /* These define symbol visibility. */
99 {"internal", obj_elf_visibility, STV_INTERNAL},
100 {"hidden", obj_elf_visibility, STV_HIDDEN},
101 {"protected", obj_elf_visibility, STV_PROTECTED},
103 /* These are used for stabs-in-elf configurations. */
104 {"line", obj_elf_line, 0},
106 /* This is a GNU extension to handle symbol versions. */
107 {"symver", obj_elf_symver, 0},
109 /* A GNU extension to change subsection only. */
110 {"subsection", obj_elf_subsection, 0},
112 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
113 {"vtable_inherit", obj_elf_vtable_inherit, 0},
114 {"vtable_entry", obj_elf_vtable_entry, 0},
116 /* These are used for dwarf. */
117 {"2byte", cons, 2},
118 {"4byte", cons, 4},
119 {"8byte", cons, 8},
121 /* We need to trap the section changing calls to handle .previous. */
122 {"data", obj_elf_data, 0},
123 {"text", obj_elf_text, 0},
125 /* End sentinel. */
126 {NULL, NULL, 0},
129 static const pseudo_typeS ecoff_debug_pseudo_table[] =
131 #ifdef NEED_ECOFF_DEBUG
132 /* COFF style debugging information for ECOFF. .ln is not used; .loc
133 is used instead. */
134 { "def", ecoff_directive_def, 0 },
135 { "dim", ecoff_directive_dim, 0 },
136 { "endef", ecoff_directive_endef, 0 },
137 { "file", ecoff_directive_file, 0 },
138 { "scl", ecoff_directive_scl, 0 },
139 { "tag", ecoff_directive_tag, 0 },
140 { "val", ecoff_directive_val, 0 },
142 /* COFF debugging requires pseudo-ops .size and .type, but ELF
143 already has meanings for those. We use .esize and .etype
144 instead. These are only generated by gcc anyhow. */
145 { "esize", ecoff_directive_size, 0 },
146 { "etype", ecoff_directive_type, 0 },
148 /* ECOFF specific debugging information. */
149 { "begin", ecoff_directive_begin, 0 },
150 { "bend", ecoff_directive_bend, 0 },
151 { "end", ecoff_directive_end, 0 },
152 { "ent", ecoff_directive_ent, 0 },
153 { "fmask", ecoff_directive_fmask, 0 },
154 { "frame", ecoff_directive_frame, 0 },
155 { "loc", ecoff_directive_loc, 0 },
156 { "mask", ecoff_directive_mask, 0 },
158 /* Other ECOFF directives. */
159 { "extern", ecoff_directive_extern, 0 },
161 /* These are used on Irix. I don't know how to implement them. */
162 { "alias", s_ignore, 0 },
163 { "bgnb", s_ignore, 0 },
164 { "endb", s_ignore, 0 },
165 { "lab", s_ignore, 0 },
166 { "noalias", s_ignore, 0 },
167 { "verstamp", s_ignore, 0 },
168 { "vreg", s_ignore, 0 },
169 #endif
171 {NULL, NULL, 0} /* end sentinel */
174 #undef NO_RELOC
175 #include "aout/aout64.h"
177 /* This is called when the assembler starts. */
179 void
180 elf_begin ()
182 /* Add symbols for the known sections to the symbol table. */
183 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
184 TEXT_SECTION_NAME)));
185 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
186 DATA_SECTION_NAME)));
187 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
188 BSS_SECTION_NAME)));
191 void
192 elf_pop_insert ()
194 pop_insert (elf_pseudo_table);
195 if (ECOFF_DEBUGGING)
196 pop_insert (ecoff_debug_pseudo_table);
199 static bfd_vma
200 elf_s_get_size (sym)
201 symbolS *sym;
203 return S_GET_SIZE (sym);
206 static void
207 elf_s_set_size (sym, sz)
208 symbolS *sym;
209 bfd_vma sz;
211 S_SET_SIZE (sym, sz);
214 static bfd_vma
215 elf_s_get_align (sym)
216 symbolS *sym;
218 return S_GET_ALIGN (sym);
221 static void
222 elf_s_set_align (sym, align)
223 symbolS *sym;
224 bfd_vma align;
226 S_SET_ALIGN (sym, align);
230 elf_s_get_other (sym)
231 symbolS *sym;
233 return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
236 static void
237 elf_copy_symbol_attributes (dest, src)
238 symbolS *dest, *src;
240 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
243 static int
244 elf_sec_sym_ok_for_reloc (sec)
245 asection *sec;
247 return obj_sec_sym_ok_for_reloc (sec);
250 void
251 elf_file_symbol (s)
252 char *s;
254 symbolS *sym;
256 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
257 symbol_set_frag (sym, &zero_address_frag);
258 symbol_get_bfdsym (sym)->flags |= BSF_FILE;
260 if (symbol_rootP != sym)
262 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
263 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
264 #ifdef DEBUG
265 verify_symbol_chain (symbol_rootP, symbol_lastP);
266 #endif
269 #ifdef NEED_ECOFF_DEBUG
270 ecoff_new_file (s);
271 #endif
274 void
275 obj_elf_common (is_common)
276 int is_common;
278 char *name;
279 char c;
280 char *p;
281 int temp, size;
282 symbolS *symbolP;
283 int have_align;
285 if (flag_mri && is_common)
287 s_mri_common (0);
288 return;
291 name = input_line_pointer;
292 c = get_symbol_end ();
293 /* just after name is now '\0' */
294 p = input_line_pointer;
295 *p = c;
296 SKIP_WHITESPACE ();
297 if (*input_line_pointer != ',')
299 as_bad (_("Expected comma after symbol-name"));
300 ignore_rest_of_line ();
301 return;
303 input_line_pointer++; /* skip ',' */
304 if ((temp = get_absolute_expression ()) < 0)
306 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp);
307 ignore_rest_of_line ();
308 return;
310 size = temp;
311 *p = 0;
312 symbolP = symbol_find_or_make (name);
313 *p = c;
314 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
316 as_bad (_("Ignoring attempt to re-define symbol"));
317 ignore_rest_of_line ();
318 return;
320 if (S_GET_VALUE (symbolP) != 0)
322 if (S_GET_VALUE (symbolP) != (valueT) size)
324 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
325 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
328 know (symbolP->sy_frag == &zero_address_frag);
329 if (*input_line_pointer != ',')
330 have_align = 0;
331 else
333 have_align = 1;
334 input_line_pointer++;
335 SKIP_WHITESPACE ();
337 if (! have_align || *input_line_pointer != '"')
339 if (! have_align)
340 temp = 0;
341 else
343 temp = get_absolute_expression ();
344 if (temp < 0)
346 temp = 0;
347 as_warn (_("Common alignment negative; 0 assumed"));
350 if (symbol_get_obj (symbolP)->local)
352 segT old_sec;
353 int old_subsec;
354 char *pfrag;
355 int align;
357 /* allocate_bss: */
358 old_sec = now_seg;
359 old_subsec = now_subseg;
360 if (temp)
362 /* convert to a power of 2 alignment */
363 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
364 if (temp != 1)
366 as_bad (_("Common alignment not a power of 2"));
367 ignore_rest_of_line ();
368 return;
371 else
372 align = 0;
373 record_alignment (bss_section, align);
374 subseg_set (bss_section, 0);
375 if (align)
376 frag_align (align, 0, 0);
377 if (S_GET_SEGMENT (symbolP) == bss_section)
378 symbol_get_frag (symbolP)->fr_symbol = 0;
379 symbol_set_frag (symbolP, frag_now);
380 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
381 (offsetT) size, (char *) 0);
382 *pfrag = 0;
383 S_SET_SIZE (symbolP, size);
384 S_SET_SEGMENT (symbolP, bss_section);
385 S_CLEAR_EXTERNAL (symbolP);
386 subseg_set (old_sec, old_subsec);
388 else
390 allocate_common:
391 S_SET_VALUE (symbolP, (valueT) size);
392 S_SET_ALIGN (symbolP, temp);
393 S_SET_EXTERNAL (symbolP);
394 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
397 else
399 input_line_pointer++;
400 /* @@ Some use the dot, some don't. Can we get some consistency?? */
401 if (*input_line_pointer == '.')
402 input_line_pointer++;
403 /* @@ Some say data, some say bss. */
404 if (strncmp (input_line_pointer, "bss\"", 4)
405 && strncmp (input_line_pointer, "data\"", 5))
407 while (*--input_line_pointer != '"')
409 input_line_pointer--;
410 goto bad_common_segment;
412 while (*input_line_pointer++ != '"')
414 goto allocate_common;
417 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
419 demand_empty_rest_of_line ();
420 return;
423 bad_common_segment:
424 p = input_line_pointer;
425 while (*p && *p != '\n')
426 p++;
427 c = *p;
428 *p = '\0';
429 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
430 *p = c;
431 input_line_pointer = p;
432 ignore_rest_of_line ();
433 return;
437 static void
438 obj_elf_local (ignore)
439 int ignore ATTRIBUTE_UNUSED;
441 char *name;
442 int c;
443 symbolS *symbolP;
447 name = input_line_pointer;
448 c = get_symbol_end ();
449 symbolP = symbol_find_or_make (name);
450 *input_line_pointer = c;
451 SKIP_WHITESPACE ();
452 S_CLEAR_EXTERNAL (symbolP);
453 symbol_get_obj (symbolP)->local = 1;
454 if (c == ',')
456 input_line_pointer++;
457 SKIP_WHITESPACE ();
458 if (*input_line_pointer == '\n')
459 c = '\n';
462 while (c == ',');
463 demand_empty_rest_of_line ();
466 static void
467 obj_elf_weak (ignore)
468 int ignore ATTRIBUTE_UNUSED;
470 char *name;
471 int c;
472 symbolS *symbolP;
476 name = input_line_pointer;
477 c = get_symbol_end ();
478 symbolP = symbol_find_or_make (name);
479 *input_line_pointer = c;
480 SKIP_WHITESPACE ();
481 S_SET_WEAK (symbolP);
482 symbol_get_obj (symbolP)->local = 1;
483 if (c == ',')
485 input_line_pointer++;
486 SKIP_WHITESPACE ();
487 if (*input_line_pointer == '\n')
488 c = '\n';
491 while (c == ',');
492 demand_empty_rest_of_line ();
495 static void
496 obj_elf_visibility (visibility)
497 int visibility;
499 char *name;
500 int c;
501 symbolS *symbolP;
502 asymbol *bfdsym;
503 elf_symbol_type *elfsym;
507 name = input_line_pointer;
508 c = get_symbol_end ();
509 symbolP = symbol_find_or_make (name);
510 *input_line_pointer = c;
512 SKIP_WHITESPACE ();
514 bfdsym = symbol_get_bfdsym (symbolP);
515 elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
517 assert (elfsym);
519 elfsym->internal_elf_sym.st_other = visibility;
521 if (c == ',')
523 input_line_pointer ++;
525 SKIP_WHITESPACE ();
527 if (*input_line_pointer == '\n')
528 c = '\n';
531 while (c == ',');
533 demand_empty_rest_of_line ();
537 static segT previous_section;
538 static int previous_subsection;
540 struct section_stack
542 struct section_stack *next;
543 segT seg, prev_seg;
544 int subseg, prev_subseg;
547 static struct section_stack *section_stack;
550 /* Handle the .section pseudo-op. This code supports two different
551 syntaxes.
553 The first is found on Solaris, and looks like
554 .section ".sec1",#alloc,#execinstr,#write
555 Here the names after '#' are the SHF_* flags to turn on for the
556 section. I'm not sure how it determines the SHT_* type (BFD
557 doesn't really give us control over the type, anyhow).
559 The second format is found on UnixWare, and probably most SVR4
560 machines, and looks like
561 .section .sec1,"a",@progbits
562 The quoted string may contain any combination of a, w, x, and
563 represents the SHF_* flags to turn on for the section. The string
564 beginning with '@' can be progbits or nobits. There should be
565 other possibilities, but I don't know what they are. In any case,
566 BFD doesn't really let us set the section type. */
568 /* Certain named sections have particular defined types, listed on p.
569 4-19 of the ABI. */
570 struct special_section
572 const char *name;
573 int type;
574 int attributes;
577 static struct special_section const special_sections[] =
579 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
580 { ".comment", SHT_PROGBITS, 0 },
581 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
582 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
583 { ".debug", SHT_PROGBITS, 0 },
584 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
585 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
586 { ".line", SHT_PROGBITS, 0 },
587 { ".note", SHT_NOTE, 0 },
588 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
589 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
590 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
592 #ifdef ELF_TC_SPECIAL_SECTIONS
593 ELF_TC_SPECIAL_SECTIONS
594 #endif
596 #if 0
597 /* The following section names are special, but they can not
598 reasonably appear in assembler code. Some of the attributes are
599 processor dependent. */
600 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
601 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
602 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
603 { ".got", SHT_PROGBITS, 0 },
604 { ".hash", SHT_HASH, SHF_ALLOC },
605 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
606 { ".plt", SHT_PROGBITS, 0 },
607 { ".shstrtab",SHT_STRTAB, 0 },
608 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
609 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
610 #endif
612 { NULL, 0, 0 }
615 void
616 obj_elf_change_section (name, type, attr, push)
617 char *name;
618 int type, attr, push;
620 int new_sec;
621 segT sec;
623 #ifdef md_flush_pending_output
624 md_flush_pending_output ();
625 #endif
627 /* Switch to the section, creating it if necessary. */
628 if (push)
630 struct section_stack *elt;
631 elt = xmalloc (sizeof (struct section_stack));
632 elt->next = section_stack;
633 elt->seg = now_seg;
634 elt->prev_seg = previous_section;
635 elt->subseg = now_subseg;
636 elt->prev_subseg = previous_subsection;
637 section_stack = elt;
639 previous_section = now_seg;
640 previous_subsection = now_subseg;
642 new_sec = bfd_get_section_by_name (stdoutput, name) == NULL;
643 sec = subseg_new (name, 0);
645 if (new_sec)
647 flagword flags;
648 symbolS *secsym;
649 int i;
651 /* See if this is one of the special sections. */
652 for (i = 0; special_sections[i].name != NULL; i++)
653 if (strcmp (name, special_sections[i].name) == 0)
655 if (type == SHT_NULL)
656 type = special_sections[i].type;
657 else if (type != special_sections[i].type)
658 as_warn (_("Setting incorrect section type for %s"), name);
660 if ((attr &~ special_sections[i].attributes) != 0)
662 /* As a GNU extension, we permit a .note section to be
663 allocatable. If the linker sees an allocateable .note
664 section, it will create a PT_NOTE segment in the output
665 file. */
666 if (strcmp (name, ".note") != 0
667 || attr != SHF_ALLOC)
668 as_warn (_("Setting incorrect section attributes for %s"),
669 name);
671 attr |= special_sections[i].attributes;
672 break;
675 /* Convert ELF type and flags to BFD flags. */
676 flags = (SEC_RELOC
677 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
678 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
679 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
680 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0));
681 #ifdef md_elf_section_flags
682 flags = md_elf_section_flags (flags, attr, type);
683 #endif
685 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
686 if (type == SHT_NOBITS)
687 seg_info (sec)->bss = 1;
689 bfd_set_section_flags (stdoutput, sec, flags);
691 /* Add a symbol for this section to the symbol table. */
692 secsym = symbol_find (name);
693 if (secsym != NULL)
694 symbol_set_bfdsym (secsym, sec->symbol);
695 else
696 symbol_table_insert (section_symbol (sec));
699 #ifdef md_elf_section_change_hook
700 md_elf_section_change_hook ();
701 #endif
705 obj_elf_parse_section_letters (str, len)
706 char *str;
707 size_t len;
709 int attr = 0;
711 while (len > 0)
713 switch (*str)
715 case 'a':
716 attr |= SHF_ALLOC;
717 break;
718 case 'w':
719 attr |= SHF_WRITE;
720 break;
721 case 'x':
722 attr |= SHF_EXECINSTR;
723 break;
724 default:
726 char *bad_msg = _("Unrecognized .section attribute: want a,w,x");
727 #ifdef md_elf_section_letter
728 int md_attr = md_elf_section_letter (*str, &bad_msg);
729 if (md_attr >= 0)
730 attr |= md_attr;
731 else
732 #endif
734 as_warn ("%s", bad_msg);
735 attr = -1;
738 break;
740 str++, len--;
743 return attr;
747 obj_elf_section_word (str, len)
748 char *str;
749 size_t len;
751 if (len == 5 && strncmp (str, "write", 5) == 0)
752 return SHF_WRITE;
753 if (len == 5 && strncmp (str, "alloc", 5) == 0)
754 return SHF_ALLOC;
755 if (len == 9 && strncmp (str, "execinstr", 9) == 0)
756 return SHF_EXECINSTR;
758 #ifdef md_elf_section_word
760 int md_attr = md_elf_section_word (str, len);
761 if (md_attr >= 0)
762 return md_attr;
764 #endif
766 as_warn (_("Unrecognized section attribute"));
767 return 0;
771 obj_elf_section_type (str, len)
772 char *str;
773 size_t len;
775 if (len == 8 && strncmp (str, "progbits", 8) == 0)
776 return SHT_PROGBITS;
777 if (len == 6 && strncmp (str, "nobits", 6) == 0)
778 return SHT_NOBITS;
780 #ifdef md_elf_section_type
782 int md_type = md_elf_section_type (str, len);
783 if (md_type >= 0)
784 return md_type;
786 #endif
788 as_warn (_("Unrecognized section type"));
789 return 0;
792 void
793 obj_elf_section (push)
794 int push;
796 char *name, *beg, *end;
797 int type, attr, dummy;
799 #ifndef TC_I370
800 if (flag_mri)
802 char mri_type;
804 #ifdef md_flush_pending_output
805 md_flush_pending_output ();
806 #endif
808 previous_section = now_seg;
809 previous_subsection = now_subseg;
811 s_mri_sect (&mri_type);
813 #ifdef md_elf_section_change_hook
814 md_elf_section_change_hook ();
815 #endif
817 return;
819 #endif /* ! defined (TC_I370) */
821 /* Get name of section. */
822 SKIP_WHITESPACE ();
823 if (*input_line_pointer == '"')
825 name = demand_copy_C_string (&dummy);
826 if (name == NULL)
828 ignore_rest_of_line ();
829 return;
832 else
834 end = input_line_pointer;
835 while (0 == strchr ("\n\t,; ", *end))
836 end++;
837 if (end == input_line_pointer)
839 as_warn (_("Missing section name"));
840 ignore_rest_of_line ();
841 return;
844 name = xmalloc (end - input_line_pointer + 1);
845 memcpy (name, input_line_pointer, end - input_line_pointer);
846 name[end - input_line_pointer] = '\0';
847 input_line_pointer = end;
849 SKIP_WHITESPACE ();
851 type = SHT_NULL;
852 attr = 0;
854 if (*input_line_pointer == ',')
856 /* Skip the comma. */
857 ++input_line_pointer;
858 SKIP_WHITESPACE ();
860 if (*input_line_pointer == '"')
862 beg = demand_copy_C_string (&dummy);
863 if (beg == NULL)
865 ignore_rest_of_line ();
866 return;
868 attr |= obj_elf_parse_section_letters (beg, strlen (beg));
870 SKIP_WHITESPACE ();
871 if (*input_line_pointer == ',')
873 char c;
874 ++input_line_pointer;
875 SKIP_WHITESPACE ();
876 c = *input_line_pointer;
877 if (c == '"')
879 beg = demand_copy_C_string (&dummy);
880 if (beg == NULL)
882 ignore_rest_of_line ();
883 return;
885 type = obj_elf_section_type (beg, strlen (beg));
887 else if (c == '@' || c == '%')
889 beg = ++input_line_pointer;
890 c = get_symbol_end ();
891 *input_line_pointer = c;
892 type = obj_elf_section_type (beg, input_line_pointer - beg);
896 else
900 char c;
902 SKIP_WHITESPACE ();
903 if (*input_line_pointer != '#')
905 as_warn (_("Bad .section directive - character following name is not '#'"));
906 ignore_rest_of_line ();
907 return;
909 beg = ++input_line_pointer;
910 c = get_symbol_end ();
911 *input_line_pointer = c;
913 attr |= obj_elf_section_word (beg, input_line_pointer - beg);
915 SKIP_WHITESPACE ();
917 while (*input_line_pointer++ == ',');
918 --input_line_pointer;
922 demand_empty_rest_of_line ();
924 obj_elf_change_section (name, type, attr, push);
927 /* Change to the .data section. */
929 void
930 obj_elf_data (i)
931 int i;
933 #ifdef md_flush_pending_output
934 md_flush_pending_output ();
935 #endif
937 previous_section = now_seg;
938 previous_subsection = now_subseg;
939 s_data (i);
941 #ifdef md_elf_section_change_hook
942 md_elf_section_change_hook ();
943 #endif
946 /* Change to the .text section. */
948 void
949 obj_elf_text (i)
950 int i;
952 #ifdef md_flush_pending_output
953 md_flush_pending_output ();
954 #endif
956 previous_section = now_seg;
957 previous_subsection = now_subseg;
958 s_text (i);
960 #ifdef md_elf_section_change_hook
961 md_elf_section_change_hook ();
962 #endif
965 static void
966 obj_elf_subsection (ignore)
967 int ignore ATTRIBUTE_UNUSED;
969 register int temp;
971 #ifdef md_flush_pending_output
972 md_flush_pending_output ();
973 #endif
975 previous_section = now_seg;
976 previous_subsection = now_subseg;
978 temp = get_absolute_expression ();
979 subseg_set (now_seg, (subsegT) temp);
980 demand_empty_rest_of_line ();
982 #ifdef md_elf_section_change_hook
983 md_elf_section_change_hook ();
984 #endif
987 /* This can be called from the processor backends if they change
988 sections. */
990 void
991 obj_elf_section_change_hook ()
993 previous_section = now_seg;
994 previous_subsection = now_subseg;
997 void
998 obj_elf_previous (ignore)
999 int ignore ATTRIBUTE_UNUSED;
1001 segT new_section;
1002 int new_subsection;
1004 if (previous_section == 0)
1006 as_bad (_(".previous without corresponding .section; ignored"));
1007 return;
1010 #ifdef md_flush_pending_output
1011 md_flush_pending_output ();
1012 #endif
1014 new_section = previous_section;
1015 new_subsection = previous_subsection;
1016 previous_section = now_seg;
1017 previous_subsection = now_subseg;
1018 subseg_set (new_section, new_subsection);
1020 #ifdef md_elf_section_change_hook
1021 md_elf_section_change_hook ();
1022 #endif
1025 static void
1026 obj_elf_popsection (xxx)
1027 int xxx ATTRIBUTE_UNUSED;
1029 struct section_stack *top = section_stack;
1031 if (top == NULL)
1033 as_bad (_(".popsection without corresponding .pushsection; ignored"));
1034 return;
1037 #ifdef md_flush_pending_output
1038 md_flush_pending_output ();
1039 #endif
1041 section_stack = top->next;
1042 previous_section = top->prev_seg;
1043 previous_subsection = top->prev_subseg;
1044 subseg_set (top->seg, top->subseg);
1045 free (top);
1047 #ifdef md_elf_section_change_hook
1048 md_elf_section_change_hook ();
1049 #endif
1052 static void
1053 obj_elf_line (ignore)
1054 int ignore ATTRIBUTE_UNUSED;
1056 /* Assume delimiter is part of expression. BSD4.2 as fails with
1057 delightful bug, so we are not being incompatible here. */
1058 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
1059 demand_empty_rest_of_line ();
1062 /* This handles the .symver pseudo-op, which is used to specify a
1063 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1064 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1065 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1066 with the same value as the symbol NAME. */
1068 static void
1069 obj_elf_symver (ignore)
1070 int ignore ATTRIBUTE_UNUSED;
1072 char *name;
1073 char c;
1074 symbolS *sym;
1076 name = input_line_pointer;
1077 c = get_symbol_end ();
1079 sym = symbol_find_or_make (name);
1081 *input_line_pointer = c;
1083 if (symbol_get_obj (sym)->versioned_name != NULL)
1085 as_bad (_("multiple .symver directives for symbol `%s'"),
1086 S_GET_NAME (sym));
1087 ignore_rest_of_line ();
1088 return;
1091 SKIP_WHITESPACE ();
1092 if (*input_line_pointer != ',')
1094 as_bad (_("expected comma after name in .symver"));
1095 ignore_rest_of_line ();
1096 return;
1099 ++input_line_pointer;
1100 name = input_line_pointer;
1101 while (1)
1103 c = get_symbol_end ();
1104 if (c != ELF_VER_CHR)
1105 break;
1106 *input_line_pointer++ = c;
1109 symbol_get_obj (sym)->versioned_name = xstrdup (name);
1111 *input_line_pointer = c;
1113 if (strchr (symbol_get_obj (sym)->versioned_name, ELF_VER_CHR) == NULL)
1115 as_bad (_("missing version name in `%s' for symbol `%s'"),
1116 symbol_get_obj (sym)->versioned_name, S_GET_NAME (sym));
1117 ignore_rest_of_line ();
1118 return;
1121 demand_empty_rest_of_line ();
1124 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1125 to the linker the hierarchy in which a particular table resides. The
1126 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1128 static void
1129 obj_elf_vtable_inherit (ignore)
1130 int ignore ATTRIBUTE_UNUSED;
1132 char *cname, *pname;
1133 symbolS *csym, *psym;
1134 char c, bad = 0;
1136 if (*input_line_pointer == '#')
1137 ++input_line_pointer;
1139 cname = input_line_pointer;
1140 c = get_symbol_end ();
1141 csym = symbol_find (cname);
1143 /* GCFIXME: should check that we don't have two .vtable_inherits for
1144 the same child symbol. Also, we can currently only do this if the
1145 child symbol is already exists and is placed in a fragment. */
1147 if (csym == NULL || symbol_get_frag (csym) == NULL)
1149 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1150 cname);
1151 bad = 1;
1154 *input_line_pointer = c;
1156 SKIP_WHITESPACE ();
1157 if (*input_line_pointer != ',')
1159 as_bad ("expected comma after name in .vtable_inherit");
1160 ignore_rest_of_line ();
1161 return;
1164 ++input_line_pointer;
1165 SKIP_WHITESPACE ();
1167 if (*input_line_pointer == '#')
1168 ++input_line_pointer;
1170 if (input_line_pointer[0] == '0'
1171 && (input_line_pointer[1] == '\0'
1172 || isspace ((unsigned char) input_line_pointer[1])))
1174 psym = section_symbol (absolute_section);
1175 ++input_line_pointer;
1177 else
1179 pname = input_line_pointer;
1180 c = get_symbol_end ();
1181 psym = symbol_find_or_make (pname);
1182 *input_line_pointer = c;
1185 demand_empty_rest_of_line ();
1187 if (bad)
1188 return;
1190 assert (symbol_get_value_expression (csym)->X_op == O_constant);
1191 fix_new (symbol_get_frag (csym),
1192 symbol_get_value_expression (csym)->X_add_number, 0, psym, 0, 0,
1193 BFD_RELOC_VTABLE_INHERIT);
1196 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1197 to the linker that a vtable slot was used. The syntax is
1198 ".vtable_entry tablename, offset". */
1200 static void
1201 obj_elf_vtable_entry (ignore)
1202 int ignore ATTRIBUTE_UNUSED;
1204 char *name;
1205 symbolS *sym;
1206 offsetT offset;
1207 char c;
1209 if (*input_line_pointer == '#')
1210 ++input_line_pointer;
1212 name = input_line_pointer;
1213 c = get_symbol_end ();
1214 sym = symbol_find_or_make (name);
1215 *input_line_pointer = c;
1217 SKIP_WHITESPACE ();
1218 if (*input_line_pointer != ',')
1220 as_bad ("expected comma after name in .vtable_entry");
1221 ignore_rest_of_line ();
1222 return;
1225 ++input_line_pointer;
1226 if (*input_line_pointer == '#')
1227 ++input_line_pointer;
1229 offset = get_absolute_expression ();
1231 fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
1232 BFD_RELOC_VTABLE_ENTRY);
1234 demand_empty_rest_of_line ();
1237 void
1238 elf_obj_read_begin_hook ()
1240 #ifdef NEED_ECOFF_DEBUG
1241 if (ECOFF_DEBUGGING)
1242 ecoff_read_begin_hook ();
1243 #endif
1246 void
1247 elf_obj_symbol_new_hook (symbolP)
1248 symbolS *symbolP;
1250 struct elf_obj_sy *sy_obj;
1252 sy_obj = symbol_get_obj (symbolP);
1253 sy_obj->size = NULL;
1254 sy_obj->versioned_name = NULL;
1256 #ifdef NEED_ECOFF_DEBUG
1257 if (ECOFF_DEBUGGING)
1258 ecoff_symbol_new_hook (symbolP);
1259 #endif
1262 void
1263 obj_elf_version (ignore)
1264 int ignore ATTRIBUTE_UNUSED;
1266 char *name;
1267 unsigned int c;
1268 char ch;
1269 char *p;
1270 asection *seg = now_seg;
1271 subsegT subseg = now_subseg;
1272 Elf_Internal_Note i_note;
1273 Elf_External_Note e_note;
1274 asection *note_secp = (asection *) NULL;
1275 int i, len;
1277 SKIP_WHITESPACE ();
1278 if (*input_line_pointer == '\"')
1280 ++input_line_pointer; /* -> 1st char of string. */
1281 name = input_line_pointer;
1283 while (is_a_char (c = next_char_of_string ()))
1285 c = *input_line_pointer;
1286 *input_line_pointer = '\0';
1287 *(input_line_pointer - 1) = '\0';
1288 *input_line_pointer = c;
1290 /* create the .note section */
1292 note_secp = subseg_new (".note", 0);
1293 bfd_set_section_flags (stdoutput,
1294 note_secp,
1295 SEC_HAS_CONTENTS | SEC_READONLY);
1297 /* process the version string */
1299 len = strlen (name);
1301 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1302 i_note.descsz = 0; /* no description */
1303 i_note.type = NT_VERSION;
1304 p = frag_more (sizeof (e_note.namesz));
1305 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1306 p = frag_more (sizeof (e_note.descsz));
1307 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1308 p = frag_more (sizeof (e_note.type));
1309 md_number_to_chars (p, (valueT) i_note.type, 4);
1311 for (i = 0; i < len; i++)
1313 ch = *(name + i);
1315 FRAG_APPEND_1_CHAR (ch);
1318 frag_align (2, 0, 0);
1320 subseg_set (seg, subseg);
1322 else
1324 as_bad (_("Expected quoted string"));
1326 demand_empty_rest_of_line ();
1329 static void
1330 obj_elf_size (ignore)
1331 int ignore ATTRIBUTE_UNUSED;
1333 char *name = input_line_pointer;
1334 char c = get_symbol_end ();
1335 char *p;
1336 expressionS exp;
1337 symbolS *sym;
1339 p = input_line_pointer;
1340 *p = c;
1341 SKIP_WHITESPACE ();
1342 if (*input_line_pointer != ',')
1344 *p = 0;
1345 as_bad (_("expected comma after name `%s' in .size directive"), name);
1346 *p = c;
1347 ignore_rest_of_line ();
1348 return;
1350 input_line_pointer++;
1351 expression (&exp);
1352 if (exp.X_op == O_absent)
1354 as_bad (_("missing expression in .size directive"));
1355 exp.X_op = O_constant;
1356 exp.X_add_number = 0;
1358 *p = 0;
1359 sym = symbol_find_or_make (name);
1360 *p = c;
1361 if (exp.X_op == O_constant)
1362 S_SET_SIZE (sym, exp.X_add_number);
1363 else
1365 symbol_get_obj (sym)->size =
1366 (expressionS *) xmalloc (sizeof (expressionS));
1367 *symbol_get_obj (sym)->size = exp;
1369 demand_empty_rest_of_line ();
1372 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1373 There are four syntaxes:
1375 The first (used on Solaris) is
1376 .type SYM,#function
1377 The second (used on UnixWare) is
1378 .type SYM,@function
1379 The third (reportedly to be used on Irix 6.0) is
1380 .type SYM STT_FUNC
1381 The fourth (used on NetBSD/Arm and Linux/ARM) is
1382 .type SYM,%function
1385 static void
1386 obj_elf_type (ignore)
1387 int ignore ATTRIBUTE_UNUSED;
1389 char *name;
1390 char c;
1391 int type;
1392 const char *typename;
1393 symbolS *sym;
1395 name = input_line_pointer;
1396 c = get_symbol_end ();
1397 sym = symbol_find_or_make (name);
1398 *input_line_pointer = c;
1400 SKIP_WHITESPACE ();
1401 if (*input_line_pointer == ',')
1402 ++input_line_pointer;
1404 SKIP_WHITESPACE ();
1405 if ( *input_line_pointer == '#'
1406 || *input_line_pointer == '@'
1407 || *input_line_pointer == '%')
1408 ++input_line_pointer;
1410 typename = input_line_pointer;
1411 c = get_symbol_end ();
1413 type = 0;
1414 if (strcmp (typename, "function") == 0
1415 || strcmp (typename, "STT_FUNC") == 0)
1416 type = BSF_FUNCTION;
1417 else if (strcmp (typename, "object") == 0
1418 || strcmp (typename, "STT_OBJECT") == 0)
1419 type = BSF_OBJECT;
1420 else
1421 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename);
1423 *input_line_pointer = c;
1425 symbol_get_bfdsym (sym)->flags |= type;
1427 demand_empty_rest_of_line ();
1430 static void
1431 obj_elf_ident (ignore)
1432 int ignore ATTRIBUTE_UNUSED;
1434 static segT comment_section;
1435 segT old_section = now_seg;
1436 int old_subsection = now_subseg;
1438 #ifdef md_flush_pending_output
1439 md_flush_pending_output ();
1440 #endif
1442 if (!comment_section)
1444 char *p;
1445 comment_section = subseg_new (".comment", 0);
1446 bfd_set_section_flags (stdoutput, comment_section,
1447 SEC_READONLY | SEC_HAS_CONTENTS);
1448 p = frag_more (1);
1449 *p = 0;
1451 else
1452 subseg_set (comment_section, 0);
1453 stringer (1);
1454 subseg_set (old_section, old_subsection);
1457 #ifdef INIT_STAB_SECTION
1459 /* The first entry in a .stabs section is special. */
1461 void
1462 obj_elf_init_stab_section (seg)
1463 segT seg;
1465 char *file;
1466 char *p;
1467 char *stabstr_name;
1468 unsigned int stroff;
1470 /* Force the section to align to a longword boundary. Without this,
1471 UnixWare ar crashes. */
1472 bfd_set_section_alignment (stdoutput, seg, 2);
1474 /* Make space for this first symbol. */
1475 p = frag_more (12);
1476 /* Zero it out. */
1477 memset (p, 0, 12);
1478 as_where (&file, (unsigned int *) NULL);
1479 stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4);
1480 strcpy (stabstr_name, segment_name (seg));
1481 strcat (stabstr_name, "str");
1482 stroff = get_stab_string_offset (file, stabstr_name);
1483 know (stroff == 1);
1484 md_number_to_chars (p, stroff, 4);
1485 seg_info (seg)->stabu.p = p;
1488 #endif
1490 /* Fill in the counts in the first entry in a .stabs section. */
1492 static void
1493 adjust_stab_sections (abfd, sec, xxx)
1494 bfd *abfd;
1495 asection *sec;
1496 PTR xxx ATTRIBUTE_UNUSED;
1498 char *name;
1499 asection *strsec;
1500 char *p;
1501 int strsz, nsyms;
1503 if (strncmp (".stab", sec->name, 5))
1504 return;
1505 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1506 return;
1508 name = (char *) alloca (strlen (sec->name) + 4);
1509 strcpy (name, sec->name);
1510 strcat (name, "str");
1511 strsec = bfd_get_section_by_name (abfd, name);
1512 if (strsec)
1513 strsz = bfd_section_size (abfd, strsec);
1514 else
1515 strsz = 0;
1516 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1518 p = seg_info (sec)->stabu.p;
1519 assert (p != 0);
1521 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1522 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1525 #ifdef NEED_ECOFF_DEBUG
1527 /* This function is called by the ECOFF code. It is supposed to
1528 record the external symbol information so that the backend can
1529 write it out correctly. The ELF backend doesn't actually handle
1530 this at the moment, so we do it ourselves. We save the information
1531 in the symbol. */
1533 void
1534 elf_ecoff_set_ext (sym, ext)
1535 symbolS *sym;
1536 struct ecoff_extr *ext;
1538 symbol_get_bfdsym (sym)->udata.p = (PTR) ext;
1541 /* This function is called by bfd_ecoff_debug_externals. It is
1542 supposed to *EXT to the external symbol information, and return
1543 whether the symbol should be used at all. */
1545 static boolean
1546 elf_get_extr (sym, ext)
1547 asymbol *sym;
1548 EXTR *ext;
1550 if (sym->udata.p == NULL)
1551 return false;
1552 *ext = *(EXTR *) sym->udata.p;
1553 return true;
1556 /* This function is called by bfd_ecoff_debug_externals. It has
1557 nothing to do for ELF. */
1559 /*ARGSUSED*/
1560 static void
1561 elf_set_index (sym, indx)
1562 asymbol *sym ATTRIBUTE_UNUSED;
1563 bfd_size_type indx ATTRIBUTE_UNUSED;
1567 #endif /* NEED_ECOFF_DEBUG */
1569 void
1570 elf_frob_symbol (symp, puntp)
1571 symbolS *symp;
1572 int *puntp;
1574 struct elf_obj_sy *sy_obj;
1576 #ifdef NEED_ECOFF_DEBUG
1577 if (ECOFF_DEBUGGING)
1578 ecoff_frob_symbol (symp);
1579 #endif
1581 sy_obj = symbol_get_obj (symp);
1583 if (sy_obj->size != NULL)
1585 switch (sy_obj->size->X_op)
1587 case O_subtract:
1588 S_SET_SIZE (symp,
1589 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1590 + sy_obj->size->X_add_number
1591 - S_GET_VALUE (sy_obj->size->X_op_symbol)));
1592 break;
1593 case O_constant:
1594 S_SET_SIZE (symp,
1595 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1596 + sy_obj->size->X_add_number));
1597 break;
1598 default:
1599 as_bad (_(".size expression too complicated to fix up"));
1600 break;
1602 free (sy_obj->size);
1603 sy_obj->size = NULL;
1606 if (sy_obj->versioned_name != NULL)
1608 /* This symbol was given a new name with the .symver directive.
1610 If this is an external reference, just rename the symbol to
1611 include the version string. This will make the relocs be
1612 against the correct versioned symbol.
1614 If this is a definition, add an alias. FIXME: Using an alias
1615 will permit the debugging information to refer to the right
1616 symbol. However, it's not clear whether it is the best
1617 approach. */
1619 if (! S_IS_DEFINED (symp))
1621 char *p;
1623 /* Verify that the name isn't using the @@ syntax--this is
1624 reserved for definitions of the default version to link
1625 against. */
1626 p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
1627 know (p != NULL);
1628 if (p[1] == ELF_VER_CHR)
1630 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1631 sy_obj->versioned_name);
1632 *puntp = true;
1634 S_SET_NAME (symp, sy_obj->versioned_name);
1636 else
1638 symbolS *symp2;
1640 /* FIXME: Creating a new symbol here is risky. We're in the
1641 final loop over the symbol table. We can get away with
1642 it only because the symbol goes to the end of the list,
1643 where the loop will still see it. It would probably be
1644 better to do this in obj_frob_file_before_adjust. */
1646 symp2 = symbol_find_or_make (sy_obj->versioned_name);
1648 /* Now we act as though we saw symp2 = sym. */
1650 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1652 /* Subtracting out the frag address here is a hack because
1653 we are in the middle of the final loop. */
1654 S_SET_VALUE (symp2,
1655 (S_GET_VALUE (symp)
1656 - symbol_get_frag (symp)->fr_address));
1658 symbol_set_frag (symp2, symbol_get_frag (symp));
1660 /* This will copy over the size information. */
1661 copy_symbol_attributes (symp2, symp);
1663 if (S_IS_WEAK (symp))
1664 S_SET_WEAK (symp2);
1666 if (S_IS_EXTERNAL (symp))
1667 S_SET_EXTERNAL (symp2);
1671 /* Double check weak symbols. */
1672 if (S_IS_WEAK (symp))
1674 if (S_IS_COMMON (symp))
1675 as_bad (_("Symbol `%s' can not be both weak and common"),
1676 S_GET_NAME (symp));
1679 #ifdef TC_MIPS
1680 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1681 any undefined non-function symbol to STT_OBJECT. We try to be
1682 compatible, since newer Irix 5 and 6 linkers care. However, we
1683 only set undefined symbols to be STT_OBJECT if we are on Irix,
1684 because that is the only time gcc will generate the necessary
1685 .global directives to mark functions. */
1687 if (S_IS_COMMON (symp))
1688 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1690 if (strstr (TARGET_OS, "irix") != NULL
1691 && ! S_IS_DEFINED (symp)
1692 && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
1693 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1694 #endif
1696 #if 0 /* TC_PPC */
1697 /* If TC_PPC is defined, we used to force the type of a symbol to be
1698 BSF_OBJECT if it was otherwise unset. This was required by some
1699 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1700 that this is no longer needed, so it is now commented out. */
1701 if ((symbol_get_bfdsym (symp)->flags
1702 & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1703 && S_IS_DEFINED (symp))
1704 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1705 #endif
1708 void
1709 elf_frob_file ()
1711 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
1713 #ifdef elf_tc_final_processing
1714 elf_tc_final_processing ();
1715 #endif
1718 /* It is required that we let write_relocs have the opportunity to
1719 optimize away fixups before output has begun, since it is possible
1720 to eliminate all fixups for a section and thus we never should
1721 have generated the relocation section. */
1723 void
1724 elf_frob_file_after_relocs ()
1726 #ifdef NEED_ECOFF_DEBUG
1727 if (ECOFF_DEBUGGING)
1728 /* Generate the ECOFF debugging information. */
1730 const struct ecoff_debug_swap *debug_swap;
1731 struct ecoff_debug_info debug;
1732 char *buf;
1733 asection *sec;
1735 debug_swap
1736 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
1737 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
1738 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
1740 /* Set up the pointers in debug. */
1741 #define SET(ptr, offset, type) \
1742 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1744 SET (line, cbLineOffset, unsigned char *);
1745 SET (external_dnr, cbDnOffset, PTR);
1746 SET (external_pdr, cbPdOffset, PTR);
1747 SET (external_sym, cbSymOffset, PTR);
1748 SET (external_opt, cbOptOffset, PTR);
1749 SET (external_aux, cbAuxOffset, union aux_ext *);
1750 SET (ss, cbSsOffset, char *);
1751 SET (external_fdr, cbFdOffset, PTR);
1752 SET (external_rfd, cbRfdOffset, PTR);
1753 /* ssext and external_ext are set up just below. */
1755 #undef SET
1757 /* Set up the external symbols. */
1758 debug.ssext = debug.ssext_end = NULL;
1759 debug.external_ext = debug.external_ext_end = NULL;
1760 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true,
1761 elf_get_extr, elf_set_index))
1762 as_fatal (_("Failed to set up debugging information: %s"),
1763 bfd_errmsg (bfd_get_error ()));
1765 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
1766 assert (sec != NULL);
1768 know (stdoutput->output_has_begun == false);
1770 /* We set the size of the section, call bfd_set_section_contents
1771 to force the ELF backend to allocate a file position, and then
1772 write out the data. FIXME: Is this really the best way to do
1773 this? */
1774 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
1776 /* Pass BUF to bfd_set_section_contents because this will
1777 eventually become a call to fwrite, and ISO C prohibits
1778 passing a NULL pointer to a stdio function even if the
1779 pointer will not be used. */
1780 if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf,
1781 (file_ptr) 0, (bfd_size_type) 0))
1782 as_fatal (_("Can't start writing .mdebug section: %s"),
1783 bfd_errmsg (bfd_get_error ()));
1785 know (stdoutput->output_has_begun == true);
1786 know (sec->filepos != 0);
1788 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
1789 sec->filepos))
1790 as_fatal (_("Could not write .mdebug section: %s"),
1791 bfd_errmsg (bfd_get_error ()));
1793 #endif /* NEED_ECOFF_DEBUG */
1796 #ifdef SCO_ELF
1798 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1799 SCO specific identifier in the .notes section to satisfy the SCO
1800 linker.
1802 This looks more complicated than it really is. As opposed to the
1803 "obvious" solution, this should handle the cross dev cases
1804 correctly. (i.e, hosting on a 64 bit big endian processor, but
1805 generating SCO Elf code) Efficiency isn't a concern, as there
1806 should be exactly one of these sections per object module.
1808 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1809 .note section.
1811 int_32 namesz = 4 ; Name size
1812 int_32 descsz = 12 ; Descriptive information
1813 int_32 type = 1 ;
1814 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1815 int_32 version = (major ver # << 16) | version of tools ;
1816 int_32 source = (tool_id << 16 ) | 1 ;
1817 int_32 info = 0 ; These are set by the SCO tools, but we
1818 don't know enough about the source
1819 environment to set them. SCO ld currently
1820 ignores them, and recommends we set them
1821 to zero. */
1823 #define SCO_MAJOR_VERSION 0x1
1824 #define SCO_MINOR_VERSION 0x1
1826 void
1827 sco_id ()
1830 char *name;
1831 unsigned int c;
1832 char ch;
1833 char *p;
1834 asection *seg = now_seg;
1835 subsegT subseg = now_subseg;
1836 Elf_Internal_Note i_note;
1837 Elf_External_Note e_note;
1838 asection *note_secp = (asection *) NULL;
1839 int i, len;
1841 /* create the .note section */
1843 note_secp = subseg_new (".note", 0);
1844 bfd_set_section_flags (stdoutput,
1845 note_secp,
1846 SEC_HAS_CONTENTS | SEC_READONLY);
1848 /* process the version string */
1850 i_note.namesz = 4;
1851 i_note.descsz = 12; /* 12 descriptive bytes */
1852 i_note.type = NT_VERSION; /* Contains a version string */
1854 p = frag_more (sizeof (i_note.namesz));
1855 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1857 p = frag_more (sizeof (i_note.descsz));
1858 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1860 p = frag_more (sizeof (i_note.type));
1861 md_number_to_chars (p, (valueT) i_note.type, 4);
1863 p = frag_more (4);
1864 strcpy (p, "SCO");
1866 /* Note: this is the version number of the ELF we're representing */
1867 p = frag_more (4);
1868 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
1870 /* Here, we pick a magic number for ourselves (yes, I "registered"
1871 it with SCO. The bottom bit shows that we are compat with the
1872 SCO ABI. */
1873 p = frag_more (4);
1874 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
1876 /* If we knew (or cared) what the source language options were, we'd
1877 fill them in here. SCO has given us permission to ignore these
1878 and just set them to zero. */
1879 p = frag_more (4);
1880 md_number_to_chars (p, 0x0000, 4);
1882 frag_align (2, 0, 0);
1884 /* We probably can't restore the current segment, for there likely
1885 isn't one yet... */
1886 if (seg && subseg)
1887 subseg_set (seg, subseg);
1891 #endif /* SCO_ELF */
1893 const struct format_ops elf_format_ops =
1895 bfd_target_elf_flavour,
1896 0, /* dfl_leading_underscore */
1897 1, /* emit_section_symbols */
1898 elf_frob_symbol,
1899 elf_frob_file,
1900 elf_frob_file_after_relocs,
1901 elf_s_get_size, elf_s_set_size,
1902 elf_s_get_align, elf_s_set_align,
1903 elf_s_get_other,
1904 0, /* s_get_desc */
1905 elf_copy_symbol_attributes,
1906 #ifdef NEED_ECOFF_DEBUG
1907 ecoff_generate_asm_lineno,
1908 ecoff_stab,
1909 #else
1910 0, /* generate_asm_lineno */
1911 0, /* process_stab */
1912 #endif
1913 elf_sec_sym_ok_for_reloc,
1914 elf_pop_insert,
1915 #ifdef NEED_ECOFF_DEBUG
1916 elf_ecoff_set_ext,
1917 #else
1918 0, /* ecoff_set_ext */
1919 #endif
1920 elf_obj_read_begin_hook,
1921 elf_obj_symbol_new_hook,