Initial revision
[binutils.git] / gas / config / obj-elf.c
blobf50c4b7257aacfa3942c10d7990274c4a38809d5
1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999 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
19 02111-1307, USA. */
21 #define OBJ_HEADER "obj-elf.h"
22 #include "as.h"
23 #include "subsegs.h"
24 #include "obstack.h"
26 #ifndef ECOFF_DEBUGGING
27 #define ECOFF_DEBUGGING 0
28 #else
29 #define NEED_ECOFF_DEBUG
30 #endif
32 #ifdef NEED_ECOFF_DEBUG
33 #include "ecoff.h"
34 #endif
36 #ifdef TC_ALPHA
37 #include "elf/alpha.h"
38 #endif
40 #ifdef TC_MIPS
41 #include "elf/mips.h"
42 #endif
44 #ifdef TC_PPC
45 #include "elf/ppc.h"
46 #endif
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));
59 #endif
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_vtable_inherit PARAMS ((int));
71 static void obj_elf_vtable_entry PARAMS ((int));
72 static void obj_elf_data PARAMS ((int));
73 static void obj_elf_text PARAMS ((int));
74 static void obj_elf_subsection PARAMS ((int));
76 static const pseudo_typeS elf_pseudo_table[] =
78 {"comm", obj_elf_common, 0},
79 {"ident", obj_elf_ident, 0},
80 {"local", obj_elf_local, 0},
81 {"previous", obj_elf_previous, 0},
82 {"section", obj_elf_section, 0},
83 {"section.s", obj_elf_section, 0},
84 {"sect", obj_elf_section, 0},
85 {"sect.s", obj_elf_section, 0},
86 {"size", obj_elf_size, 0},
87 {"type", obj_elf_type, 0},
88 {"version", obj_elf_version, 0},
89 {"weak", obj_elf_weak, 0},
91 /* These are used for stabs-in-elf configurations. */
92 {"line", obj_elf_line, 0},
94 /* This is a GNU extension to handle symbol versions. */
95 {"symver", obj_elf_symver, 0},
97 /* A GNU extension to change subsection only. */
98 {"subsection", obj_elf_subsection, 0},
100 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
101 {"vtable_inherit", obj_elf_vtable_inherit, 0},
102 {"vtable_entry", obj_elf_vtable_entry, 0},
104 /* These are used for dwarf. */
105 {"2byte", cons, 2},
106 {"4byte", cons, 4},
107 {"8byte", cons, 8},
109 /* We need to trap the section changing calls to handle .previous. */
110 {"data", obj_elf_data, 0},
111 {"text", obj_elf_text, 0},
113 /* End sentinel. */
114 {NULL},
117 static const pseudo_typeS ecoff_debug_pseudo_table[] =
119 #ifdef NEED_ECOFF_DEBUG
120 /* COFF style debugging information for ECOFF. .ln is not used; .loc
121 is used instead. */
122 { "def", ecoff_directive_def, 0 },
123 { "dim", ecoff_directive_dim, 0 },
124 { "endef", ecoff_directive_endef, 0 },
125 { "file", ecoff_directive_file, 0 },
126 { "scl", ecoff_directive_scl, 0 },
127 { "tag", ecoff_directive_tag, 0 },
128 { "val", ecoff_directive_val, 0 },
130 /* COFF debugging requires pseudo-ops .size and .type, but ELF
131 already has meanings for those. We use .esize and .etype
132 instead. These are only generated by gcc anyhow. */
133 { "esize", ecoff_directive_size, 0 },
134 { "etype", ecoff_directive_type, 0 },
136 /* ECOFF specific debugging information. */
137 { "begin", ecoff_directive_begin, 0 },
138 { "bend", ecoff_directive_bend, 0 },
139 { "end", ecoff_directive_end, 0 },
140 { "ent", ecoff_directive_ent, 0 },
141 { "fmask", ecoff_directive_fmask, 0 },
142 { "frame", ecoff_directive_frame, 0 },
143 { "loc", ecoff_directive_loc, 0 },
144 { "mask", ecoff_directive_mask, 0 },
146 /* Other ECOFF directives. */
147 { "extern", ecoff_directive_extern, 0 },
149 /* These are used on Irix. I don't know how to implement them. */
150 { "alias", s_ignore, 0 },
151 { "bgnb", s_ignore, 0 },
152 { "endb", s_ignore, 0 },
153 { "lab", s_ignore, 0 },
154 { "noalias", s_ignore, 0 },
155 { "verstamp", s_ignore, 0 },
156 { "vreg", s_ignore, 0 },
157 #endif
159 {NULL} /* end sentinel */
162 #undef NO_RELOC
163 #include "aout/aout64.h"
165 /* This is called when the assembler starts. */
167 void
168 elf_begin ()
170 /* Add symbols for the known sections to the symbol table. */
171 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
172 TEXT_SECTION_NAME)));
173 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
174 DATA_SECTION_NAME)));
175 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
176 BSS_SECTION_NAME)));
179 void
180 elf_pop_insert ()
182 pop_insert (elf_pseudo_table);
183 if (ECOFF_DEBUGGING)
184 pop_insert (ecoff_debug_pseudo_table);
187 static bfd_vma
188 elf_s_get_size (sym)
189 symbolS *sym;
191 return S_GET_SIZE (sym);
194 static void
195 elf_s_set_size (sym, sz)
196 symbolS *sym;
197 bfd_vma sz;
199 S_SET_SIZE (sym, sz);
202 static bfd_vma
203 elf_s_get_align (sym)
204 symbolS *sym;
206 return S_GET_ALIGN (sym);
209 static void
210 elf_s_set_align (sym, align)
211 symbolS *sym;
212 bfd_vma align;
214 S_SET_ALIGN (sym, align);
217 static void
218 elf_copy_symbol_attributes (dest, src)
219 symbolS *dest, *src;
221 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
224 static int
225 elf_sec_sym_ok_for_reloc (sec)
226 asection *sec;
228 return obj_sec_sym_ok_for_reloc (sec);
231 void
232 elf_file_symbol (s)
233 char *s;
235 symbolS *sym;
237 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
238 sym->sy_frag = &zero_address_frag;
239 sym->bsym->flags |= BSF_FILE;
241 if (symbol_rootP != sym)
243 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
244 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
245 #ifdef DEBUG
246 verify_symbol_chain (symbol_rootP, symbol_lastP);
247 #endif
250 #ifdef NEED_ECOFF_DEBUG
251 ecoff_new_file (s);
252 #endif
255 static void
256 obj_elf_common (ignore)
257 int ignore;
259 char *name;
260 char c;
261 char *p;
262 int temp, size;
263 symbolS *symbolP;
264 int have_align;
266 name = input_line_pointer;
267 c = get_symbol_end ();
268 /* just after name is now '\0' */
269 p = input_line_pointer;
270 *p = c;
271 SKIP_WHITESPACE ();
272 if (*input_line_pointer != ',')
274 as_bad (_("Expected comma after symbol-name"));
275 ignore_rest_of_line ();
276 return;
278 input_line_pointer++; /* skip ',' */
279 if ((temp = get_absolute_expression ()) < 0)
281 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp);
282 ignore_rest_of_line ();
283 return;
285 size = temp;
286 *p = 0;
287 symbolP = symbol_find_or_make (name);
288 *p = c;
289 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
291 as_bad (_("Ignoring attempt to re-define symbol"));
292 ignore_rest_of_line ();
293 return;
295 if (S_GET_VALUE (symbolP) != 0)
297 if (S_GET_VALUE (symbolP) != size)
299 as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),
300 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
303 know (symbolP->sy_frag == &zero_address_frag);
304 if (*input_line_pointer != ',')
305 have_align = 0;
306 else
308 have_align = 1;
309 input_line_pointer++;
310 SKIP_WHITESPACE ();
312 if (! have_align || *input_line_pointer != '"')
314 if (! have_align)
315 temp = 0;
316 else
318 temp = get_absolute_expression ();
319 if (temp < 0)
321 temp = 0;
322 as_warn (_("Common alignment negative; 0 assumed"));
325 if (symbolP->local)
327 segT old_sec;
328 int old_subsec;
329 char *pfrag;
330 int align;
332 /* allocate_bss: */
333 old_sec = now_seg;
334 old_subsec = now_subseg;
335 if (temp)
337 /* convert to a power of 2 alignment */
338 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
339 if (temp != 1)
341 as_bad (_("Common alignment not a power of 2"));
342 ignore_rest_of_line ();
343 return;
346 else
347 align = 0;
348 record_alignment (bss_section, align);
349 subseg_set (bss_section, 0);
350 if (align)
351 frag_align (align, 0, 0);
352 if (S_GET_SEGMENT (symbolP) == bss_section)
353 symbolP->sy_frag->fr_symbol = 0;
354 symbolP->sy_frag = frag_now;
355 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
356 (offsetT) size, (char *) 0);
357 *pfrag = 0;
358 S_SET_SIZE (symbolP, size);
359 S_SET_SEGMENT (symbolP, bss_section);
360 S_CLEAR_EXTERNAL (symbolP);
361 subseg_set (old_sec, old_subsec);
363 else
365 allocate_common:
366 S_SET_VALUE (symbolP, (valueT) size);
367 S_SET_ALIGN (symbolP, temp);
368 S_SET_EXTERNAL (symbolP);
369 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
372 else
374 input_line_pointer++;
375 /* @@ Some use the dot, some don't. Can we get some consistency?? */
376 if (*input_line_pointer == '.')
377 input_line_pointer++;
378 /* @@ Some say data, some say bss. */
379 if (strncmp (input_line_pointer, "bss\"", 4)
380 && strncmp (input_line_pointer, "data\"", 5))
382 while (*--input_line_pointer != '"')
384 input_line_pointer--;
385 goto bad_common_segment;
387 while (*input_line_pointer++ != '"')
389 goto allocate_common;
392 symbolP->bsym->flags |= BSF_OBJECT;
394 demand_empty_rest_of_line ();
395 return;
398 bad_common_segment:
399 p = input_line_pointer;
400 while (*p && *p != '\n')
401 p++;
402 c = *p;
403 *p = '\0';
404 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
405 *p = c;
406 input_line_pointer = p;
407 ignore_rest_of_line ();
408 return;
412 static void
413 obj_elf_local (ignore)
414 int ignore;
416 char *name;
417 int c;
418 symbolS *symbolP;
422 name = input_line_pointer;
423 c = get_symbol_end ();
424 symbolP = symbol_find_or_make (name);
425 *input_line_pointer = c;
426 SKIP_WHITESPACE ();
427 S_CLEAR_EXTERNAL (symbolP);
428 symbolP->local = 1;
429 if (c == ',')
431 input_line_pointer++;
432 SKIP_WHITESPACE ();
433 if (*input_line_pointer == '\n')
434 c = '\n';
437 while (c == ',');
438 demand_empty_rest_of_line ();
441 static void
442 obj_elf_weak (ignore)
443 int ignore;
445 char *name;
446 int c;
447 symbolS *symbolP;
451 name = input_line_pointer;
452 c = get_symbol_end ();
453 symbolP = symbol_find_or_make (name);
454 *input_line_pointer = c;
455 SKIP_WHITESPACE ();
456 S_SET_WEAK (symbolP);
457 symbolP->local = 1;
458 if (c == ',')
460 input_line_pointer++;
461 SKIP_WHITESPACE ();
462 if (*input_line_pointer == '\n')
463 c = '\n';
466 while (c == ',');
467 demand_empty_rest_of_line ();
470 static segT previous_section;
471 static int previous_subsection;
473 /* Handle the .section pseudo-op. This code supports two different
474 syntaxes.
476 The first is found on Solaris, and looks like
477 .section ".sec1",#alloc,#execinstr,#write
478 Here the names after '#' are the SHF_* flags to turn on for the
479 section. I'm not sure how it determines the SHT_* type (BFD
480 doesn't really give us control over the type, anyhow).
482 The second format is found on UnixWare, and probably most SVR4
483 machines, and looks like
484 .section .sec1,"a",@progbits
485 The quoted string may contain any combination of a, w, x, and
486 represents the SHF_* flags to turn on for the section. The string
487 beginning with '@' can be progbits or nobits. There should be
488 other possibilities, but I don't know what they are. In any case,
489 BFD doesn't really let us set the section type. */
491 /* Certain named sections have particular defined types, listed on p.
492 4-19 of the ABI. */
493 struct special_section
495 const char *name;
496 int type;
497 int attributes;
500 static struct special_section special_sections[] =
502 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
503 { ".comment", SHT_PROGBITS, 0 },
504 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
505 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
506 { ".debug", SHT_PROGBITS, 0 },
507 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
508 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
509 { ".line", SHT_PROGBITS, 0 },
510 { ".note", SHT_NOTE, 0 },
511 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
512 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
513 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
515 #ifdef ELF_TC_SPECIAL_SECTIONS
516 ELF_TC_SPECIAL_SECTIONS
517 #endif
519 #if 0
520 /* The following section names are special, but they can not
521 reasonably appear in assembler code. Some of the attributes are
522 processor dependent. */
523 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
524 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
525 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
526 { ".got", SHT_PROGBITS, 0 },
527 { ".hash", SHT_HASH, SHF_ALLOC },
528 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
529 { ".plt", SHT_PROGBITS, 0 },
530 { ".shstrtab",SHT_STRTAB, 0 },
531 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
532 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
533 #endif
535 { NULL, 0, 0 }
538 void
539 obj_elf_section (xxx)
540 int xxx;
542 char *string;
543 int new_sec;
544 segT sec;
545 int type, attr;
546 int i;
547 flagword flags;
548 symbolS *secsym;
550 #ifdef md_flush_pending_output
551 md_flush_pending_output ();
552 #endif
554 if (flag_mri)
556 char mri_type;
558 previous_section = now_seg;
559 previous_subsection = now_subseg;
561 s_mri_sect (&mri_type);
563 #ifdef md_elf_section_change_hook
564 md_elf_section_change_hook ();
565 #endif
567 return;
570 /* Get name of section. */
571 SKIP_WHITESPACE ();
572 if (*input_line_pointer == '"')
574 string = demand_copy_C_string (&xxx);
575 if (string == NULL)
577 ignore_rest_of_line ();
578 return;
581 else
583 char *p = input_line_pointer;
584 char c;
585 while (0 == strchr ("\n\t,; ", *p))
586 p++;
587 if (p == input_line_pointer)
589 as_warn (_("Missing section name"));
590 ignore_rest_of_line ();
591 return;
593 c = *p;
594 *p = 0;
595 string = xmalloc ((unsigned long) (p - input_line_pointer + 1));
596 strcpy (string, input_line_pointer);
597 *p = c;
598 input_line_pointer = p;
601 /* Switch to the section, creating it if necessary. */
602 previous_section = now_seg;
603 previous_subsection = now_subseg;
605 new_sec = bfd_get_section_by_name (stdoutput, string) == NULL;
606 sec = subseg_new (string, 0);
608 /* If this section already existed, we don't bother to change the
609 flag values. */
610 if (! new_sec)
612 while (! is_end_of_line[(unsigned char) *input_line_pointer])
613 ++input_line_pointer;
614 ++input_line_pointer;
616 #ifdef md_elf_section_change_hook
617 md_elf_section_change_hook ();
618 #endif
620 return;
623 SKIP_WHITESPACE ();
625 type = SHT_NULL;
626 attr = 0;
628 if (*input_line_pointer == ',')
630 /* Skip the comma. */
631 ++input_line_pointer;
633 SKIP_WHITESPACE ();
635 if (*input_line_pointer == '"')
637 /* Pick up a string with a combination of a, w, x. */
638 ++input_line_pointer;
639 while (*input_line_pointer != '"')
641 switch (*input_line_pointer)
643 case 'a':
644 attr |= SHF_ALLOC;
645 break;
646 case 'w':
647 attr |= SHF_WRITE;
648 break;
649 case 'x':
650 attr |= SHF_EXECINSTR;
651 break;
652 default:
654 char *bad_msg = _("Bad .section directive: want a,w,x in string");
655 #ifdef md_elf_section_letter
656 int md_attr = md_elf_section_letter (*input_line_pointer, &bad_msg);
657 if (md_attr)
658 attr |= md_attr;
659 else
660 #endif
662 as_warn (bad_msg);
663 ignore_rest_of_line ();
664 return;
668 ++input_line_pointer;
671 /* Skip the closing quote. */
672 ++input_line_pointer;
674 SKIP_WHITESPACE ();
675 if (*input_line_pointer == ',')
677 ++input_line_pointer;
678 SKIP_WHITESPACE ();
679 if (*input_line_pointer == '@' || *input_line_pointer == '%')
681 ++input_line_pointer;
682 if (strncmp (input_line_pointer, "progbits",
683 sizeof "progbits" - 1) == 0)
685 type = SHT_PROGBITS;
686 input_line_pointer += sizeof "progbits" - 1;
688 else if (strncmp (input_line_pointer, "nobits",
689 sizeof "nobits" - 1) == 0)
691 type = SHT_NOBITS;
692 input_line_pointer += sizeof "nobits" - 1;
694 else
696 #ifdef md_elf_section_type
697 int md_type = md_elf_section_type (&input_line_pointer);
698 if (md_type)
699 type = md_type;
700 else
701 #endif
703 as_warn (_("Unrecognized section type"));
704 ignore_rest_of_line ();
710 else
714 SKIP_WHITESPACE ();
715 if (*input_line_pointer != '#')
717 as_warn (_("Bad .section directive - character following name is not '#'"));
718 ignore_rest_of_line ();
719 return;
721 ++input_line_pointer;
722 if (strncmp (input_line_pointer, "write",
723 sizeof "write" - 1) == 0)
725 attr |= SHF_WRITE;
726 input_line_pointer += sizeof "write" - 1;
728 else if (strncmp (input_line_pointer, "alloc",
729 sizeof "alloc" - 1) == 0)
731 attr |= SHF_ALLOC;
732 input_line_pointer += sizeof "alloc" - 1;
734 else if (strncmp (input_line_pointer, "execinstr",
735 sizeof "execinstr" - 1) == 0)
737 attr |= SHF_EXECINSTR;
738 input_line_pointer += sizeof "execinstr" - 1;
740 else
742 #ifdef md_elf_section_word
743 int md_attr = md_elf_section_word (&input_line_pointer);
744 if (md_attr)
745 attr |= md_attr;
746 else
747 #endif
749 as_warn (_("Unrecognized section attribute"));
750 ignore_rest_of_line ();
751 return;
754 SKIP_WHITESPACE ();
756 while (*input_line_pointer++ == ',');
757 --input_line_pointer;
761 /* See if this is one of the special sections. */
762 for (i = 0; special_sections[i].name != NULL; i++)
764 if (string[1] == special_sections[i].name[1]
765 && strcmp (string, special_sections[i].name) == 0)
767 if (type == SHT_NULL)
768 type = special_sections[i].type;
769 else if (type != special_sections[i].type)
770 as_warn (_("Setting incorrect section type for %s"), string);
772 if ((attr &~ special_sections[i].attributes) != 0)
774 /* As a GNU extension, we permit a .note section to be
775 allocatable. If the linker sees an allocateable
776 .note section, it will create a PT_NOTE segment in
777 the output file. */
778 if (strcmp (string, ".note") != 0
779 || attr != SHF_ALLOC)
780 as_warn (_("Setting incorrect section attributes for %s"),
781 string);
783 attr |= special_sections[i].attributes;
785 break;
789 flags = (SEC_RELOC
790 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
791 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
792 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
793 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0));
794 if (special_sections[i].name == NULL)
796 if (type == SHT_PROGBITS)
797 flags |= SEC_ALLOC | SEC_LOAD;
798 else if (type == SHT_NOBITS)
800 flags |= SEC_ALLOC;
801 flags &=~ SEC_LOAD;
804 #ifdef md_elf_section_flags
805 flags = md_elf_section_flags (flags, attr, type);
806 #endif
809 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
810 if (type == SHT_NOBITS)
811 seg_info (sec)->bss = 1;
813 bfd_set_section_flags (stdoutput, sec, flags);
815 /* Add a symbol for this section to the symbol table. */
816 secsym = symbol_find (string);
817 if (secsym != NULL)
818 secsym->bsym = sec->symbol;
819 else
820 symbol_table_insert (section_symbol (sec));
822 #ifdef md_elf_section_change_hook
823 md_elf_section_change_hook ();
824 #endif
826 demand_empty_rest_of_line ();
829 /* Change to the .data section. */
831 static void
832 obj_elf_data (i)
833 int i;
835 #ifdef md_flush_pending_output
836 md_flush_pending_output ();
837 #endif
839 previous_section = now_seg;
840 previous_subsection = now_subseg;
841 s_data (i);
843 #ifdef md_elf_section_change_hook
844 md_elf_section_change_hook ();
845 #endif
848 /* Change to the .text section. */
850 static void
851 obj_elf_text (i)
852 int i;
854 #ifdef md_flush_pending_output
855 md_flush_pending_output ();
856 #endif
858 previous_section = now_seg;
859 previous_subsection = now_subseg;
860 s_text (i);
862 #ifdef md_elf_section_change_hook
863 md_elf_section_change_hook ();
864 #endif
867 static void
868 obj_elf_subsection (ignore)
869 int ignore;
871 register int temp;
873 #ifdef md_flush_pending_output
874 md_flush_pending_output ();
875 #endif
877 previous_section = now_seg;
878 previous_subsection = now_subseg;
880 temp = get_absolute_expression ();
881 subseg_set (now_seg, (subsegT) temp);
882 demand_empty_rest_of_line ();
884 #ifdef md_elf_section_change_hook
885 md_elf_section_change_hook ();
886 #endif
889 /* This can be called from the processor backends if they change
890 sections. */
892 void
893 obj_elf_section_change_hook ()
895 previous_section = now_seg;
896 previous_subsection = now_subseg;
899 void
900 obj_elf_previous (ignore)
901 int ignore;
903 if (previous_section == 0)
905 as_bad (_(".previous without corresponding .section; ignored"));
906 return;
909 #ifdef md_flush_pending_output
910 md_flush_pending_output ();
911 #endif
913 subseg_set (previous_section, previous_subsection);
914 previous_section = 0;
916 #ifdef md_elf_section_change_hook
917 md_elf_section_change_hook ();
918 #endif
921 static void
922 obj_elf_line (ignore)
923 int ignore;
925 /* Assume delimiter is part of expression. BSD4.2 as fails with
926 delightful bug, so we are not being incompatible here. */
927 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
928 demand_empty_rest_of_line ();
931 /* This handles the .symver pseudo-op, which is used to specify a
932 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
933 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
934 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
935 with the same value as the symbol NAME. */
937 static void
938 obj_elf_symver (ignore)
939 int ignore;
941 char *name;
942 char c;
943 symbolS *sym;
945 name = input_line_pointer;
946 c = get_symbol_end ();
948 sym = symbol_find_or_make (name);
950 *input_line_pointer = c;
952 if (sym->sy_obj.versioned_name != NULL)
954 as_bad (_("multiple .symver directives for symbol `%s'"),
955 S_GET_NAME (sym));
956 ignore_rest_of_line ();
957 return;
960 SKIP_WHITESPACE ();
961 if (*input_line_pointer != ',')
963 as_bad (_("expected comma after name in .symver"));
964 ignore_rest_of_line ();
965 return;
968 ++input_line_pointer;
969 name = input_line_pointer;
970 while (1)
972 c = get_symbol_end ();
973 if (c != ELF_VER_CHR)
974 break;
975 *input_line_pointer++ = c;
978 sym->sy_obj.versioned_name = xstrdup (name);
980 *input_line_pointer = c;
982 if (strchr (sym->sy_obj.versioned_name, ELF_VER_CHR) == NULL)
984 as_bad (_("missing version name in `%s' for symbol `%s'"),
985 sym->sy_obj.versioned_name, S_GET_NAME (sym));
986 ignore_rest_of_line ();
987 return;
990 demand_empty_rest_of_line ();
993 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
994 to the linker the hierarchy in which a particular table resides. The
995 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
997 static void
998 obj_elf_vtable_inherit (ignore)
1000 char *cname, *pname;
1001 symbolS *csym, *psym;
1002 char c, bad = 0;
1004 if (*input_line_pointer == '#')
1005 ++input_line_pointer;
1007 cname = input_line_pointer;
1008 c = get_symbol_end ();
1009 csym = symbol_find (cname);
1011 /* GCFIXME: should check that we don't have two .vtable_inherits for
1012 the same child symbol. Also, we can currently only do this if the
1013 child symbol is already exists and is placed in a fragment. */
1015 if (csym == NULL || csym->sy_frag == NULL)
1017 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1018 cname);
1019 bad = 1;
1022 *input_line_pointer = c;
1024 SKIP_WHITESPACE ();
1025 if (*input_line_pointer != ',')
1027 as_bad ("expected comma after name in .vtable_inherit");
1028 ignore_rest_of_line ();
1029 return;
1032 ++input_line_pointer;
1033 SKIP_WHITESPACE ();
1035 if (*input_line_pointer == '#')
1036 ++input_line_pointer;
1038 if (input_line_pointer[0] == '0'
1039 && (input_line_pointer[1] == '\0'
1040 || isspace(input_line_pointer[1])))
1042 psym = section_symbol (absolute_section);
1043 ++input_line_pointer;
1045 else
1047 pname = input_line_pointer;
1048 c = get_symbol_end ();
1049 psym = symbol_find_or_make (pname);
1050 *input_line_pointer = c;
1053 demand_empty_rest_of_line ();
1055 if (bad)
1056 return;
1058 assert (csym->sy_value.X_op == O_constant);
1059 fix_new (csym->sy_frag, csym->sy_value.X_add_number, 0, psym, 0, 0,
1060 BFD_RELOC_VTABLE_INHERIT);
1063 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1064 to the linker that a vtable slot was used. The syntax is
1065 ".vtable_entry tablename, offset". */
1067 static void
1068 obj_elf_vtable_entry (ignore)
1070 char *name;
1071 symbolS *sym;
1072 offsetT offset;
1073 char c;
1075 if (*input_line_pointer == '#')
1076 ++input_line_pointer;
1078 name = input_line_pointer;
1079 c = get_symbol_end ();
1080 sym = symbol_find_or_make (name);
1081 *input_line_pointer = c;
1083 SKIP_WHITESPACE ();
1084 if (*input_line_pointer != ',')
1086 as_bad ("expected comma after name in .vtable_entry");
1087 ignore_rest_of_line ();
1088 return;
1091 ++input_line_pointer;
1092 if (*input_line_pointer == '#')
1093 ++input_line_pointer;
1095 offset = get_absolute_expression ();
1097 fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
1098 BFD_RELOC_VTABLE_ENTRY);
1100 demand_empty_rest_of_line ();
1103 void
1104 obj_read_begin_hook ()
1106 #ifdef NEED_ECOFF_DEBUG
1107 if (ECOFF_DEBUGGING)
1108 ecoff_read_begin_hook ();
1109 #endif
1112 void
1113 obj_symbol_new_hook (symbolP)
1114 symbolS *symbolP;
1116 symbolP->sy_obj.size = NULL;
1117 symbolP->sy_obj.versioned_name = NULL;
1119 #ifdef NEED_ECOFF_DEBUG
1120 if (ECOFF_DEBUGGING)
1121 ecoff_symbol_new_hook (symbolP);
1122 #endif
1125 void
1126 obj_elf_version (ignore)
1127 int ignore;
1129 char *name;
1130 unsigned int c;
1131 char ch;
1132 char *p;
1133 asection *seg = now_seg;
1134 subsegT subseg = now_subseg;
1135 Elf_Internal_Note i_note;
1136 Elf_External_Note e_note;
1137 asection *note_secp = (asection *) NULL;
1138 int i, len;
1140 SKIP_WHITESPACE ();
1141 if (*input_line_pointer == '\"')
1143 ++input_line_pointer; /* -> 1st char of string. */
1144 name = input_line_pointer;
1146 while (is_a_char (c = next_char_of_string ()))
1148 c = *input_line_pointer;
1149 *input_line_pointer = '\0';
1150 *(input_line_pointer - 1) = '\0';
1151 *input_line_pointer = c;
1153 /* create the .note section */
1155 note_secp = subseg_new (".note", 0);
1156 bfd_set_section_flags (stdoutput,
1157 note_secp,
1158 SEC_HAS_CONTENTS | SEC_READONLY);
1160 /* process the version string */
1162 len = strlen (name);
1164 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1165 i_note.descsz = 0; /* no description */
1166 i_note.type = NT_VERSION;
1167 p = frag_more (sizeof (e_note.namesz));
1168 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1169 p = frag_more (sizeof (e_note.descsz));
1170 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1171 p = frag_more (sizeof (e_note.type));
1172 md_number_to_chars (p, (valueT) i_note.type, 4);
1174 for (i = 0; i < len; i++)
1176 ch = *(name + i);
1178 FRAG_APPEND_1_CHAR (ch);
1181 frag_align (2, 0, 0);
1183 subseg_set (seg, subseg);
1185 else
1187 as_bad (_("Expected quoted string"));
1189 demand_empty_rest_of_line ();
1192 static void
1193 obj_elf_size (ignore)
1194 int ignore;
1196 char *name = input_line_pointer;
1197 char c = get_symbol_end ();
1198 char *p;
1199 expressionS exp;
1200 symbolS *sym;
1202 p = input_line_pointer;
1203 *p = c;
1204 SKIP_WHITESPACE ();
1205 if (*input_line_pointer != ',')
1207 *p = 0;
1208 as_bad (_("expected comma after name `%s' in .size directive"), name);
1209 *p = c;
1210 ignore_rest_of_line ();
1211 return;
1213 input_line_pointer++;
1214 expression (&exp);
1215 if (exp.X_op == O_absent)
1217 as_bad (_("missing expression in .size directive"));
1218 exp.X_op = O_constant;
1219 exp.X_add_number = 0;
1221 *p = 0;
1222 sym = symbol_find_or_make (name);
1223 *p = c;
1224 if (exp.X_op == O_constant)
1225 S_SET_SIZE (sym, exp.X_add_number);
1226 else
1228 sym->sy_obj.size = (expressionS *) xmalloc (sizeof (expressionS));
1229 *sym->sy_obj.size = exp;
1231 demand_empty_rest_of_line ();
1234 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1235 There are four syntaxes:
1237 The first (used on Solaris) is
1238 .type SYM,#function
1239 The second (used on UnixWare) is
1240 .type SYM,@function
1241 The third (reportedly to be used on Irix 6.0) is
1242 .type SYM STT_FUNC
1243 The fourth (used on NetBSD/Arm and Linux/ARM) is
1244 .type SYM,%function
1247 static void
1248 obj_elf_type (ignore)
1249 int ignore;
1251 char *name;
1252 char c;
1253 int type;
1254 const char *typename;
1255 symbolS *sym;
1257 name = input_line_pointer;
1258 c = get_symbol_end ();
1259 sym = symbol_find_or_make (name);
1260 *input_line_pointer = c;
1262 SKIP_WHITESPACE ();
1263 if (*input_line_pointer == ',')
1264 ++input_line_pointer;
1266 SKIP_WHITESPACE ();
1267 if ( *input_line_pointer == '#'
1268 || *input_line_pointer == '@'
1269 || *input_line_pointer == '%')
1270 ++input_line_pointer;
1272 typename = input_line_pointer;
1273 c = get_symbol_end ();
1275 type = 0;
1276 if (strcmp (typename, "function") == 0
1277 || strcmp (typename, "STT_FUNC") == 0)
1278 type = BSF_FUNCTION;
1279 else if (strcmp (typename, "object") == 0
1280 || strcmp (typename, "STT_OBJECT") == 0)
1281 type = BSF_OBJECT;
1282 else
1283 as_bad (_("ignoring unrecognized symbol type \"%s\""), typename);
1285 *input_line_pointer = c;
1287 sym->bsym->flags |= type;
1289 demand_empty_rest_of_line ();
1292 static void
1293 obj_elf_ident (ignore)
1294 int ignore;
1296 static segT comment_section;
1297 segT old_section = now_seg;
1298 int old_subsection = now_subseg;
1300 if (!comment_section)
1302 char *p;
1303 comment_section = subseg_new (".comment", 0);
1304 bfd_set_section_flags (stdoutput, comment_section,
1305 SEC_READONLY | SEC_HAS_CONTENTS);
1306 p = frag_more (1);
1307 *p = 0;
1309 else
1310 subseg_set (comment_section, 0);
1311 stringer (1);
1312 subseg_set (old_section, old_subsection);
1315 #ifdef INIT_STAB_SECTION
1317 /* The first entry in a .stabs section is special. */
1319 void
1320 obj_elf_init_stab_section (seg)
1321 segT seg;
1323 char *file;
1324 char *p;
1325 char *stabstr_name;
1326 unsigned int stroff;
1328 /* Force the section to align to a longword boundary. Without this,
1329 UnixWare ar crashes. */
1330 bfd_set_section_alignment (stdoutput, seg, 2);
1332 /* Make space for this first symbol. */
1333 p = frag_more (12);
1334 /* Zero it out. */
1335 memset (p, 0, 12);
1336 as_where (&file, (unsigned int *) NULL);
1337 stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4);
1338 strcpy (stabstr_name, segment_name (seg));
1339 strcat (stabstr_name, "str");
1340 stroff = get_stab_string_offset (file, stabstr_name);
1341 know (stroff == 1);
1342 md_number_to_chars (p, stroff, 4);
1343 seg_info (seg)->stabu.p = p;
1346 #endif
1348 /* Fill in the counts in the first entry in a .stabs section. */
1350 static void
1351 adjust_stab_sections (abfd, sec, xxx)
1352 bfd *abfd;
1353 asection *sec;
1354 PTR xxx;
1356 char *name;
1357 asection *strsec;
1358 char *p;
1359 int strsz, nsyms;
1361 if (strncmp (".stab", sec->name, 5))
1362 return;
1363 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1364 return;
1366 name = (char *) alloca (strlen (sec->name) + 4);
1367 strcpy (name, sec->name);
1368 strcat (name, "str");
1369 strsec = bfd_get_section_by_name (abfd, name);
1370 if (strsec)
1371 strsz = bfd_section_size (abfd, strsec);
1372 else
1373 strsz = 0;
1374 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1376 p = seg_info (sec)->stabu.p;
1377 assert (p != 0);
1379 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1380 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1383 #ifdef NEED_ECOFF_DEBUG
1385 /* This function is called by the ECOFF code. It is supposed to
1386 record the external symbol information so that the backend can
1387 write it out correctly. The ELF backend doesn't actually handle
1388 this at the moment, so we do it ourselves. We save the information
1389 in the symbol. */
1391 void
1392 elf_ecoff_set_ext (sym, ext)
1393 symbolS *sym;
1394 struct ecoff_extr *ext;
1396 sym->bsym->udata.p = (PTR) ext;
1399 /* This function is called by bfd_ecoff_debug_externals. It is
1400 supposed to *EXT to the external symbol information, and return
1401 whether the symbol should be used at all. */
1403 static boolean
1404 elf_get_extr (sym, ext)
1405 asymbol *sym;
1406 EXTR *ext;
1408 if (sym->udata.p == NULL)
1409 return false;
1410 *ext = *(EXTR *) sym->udata.p;
1411 return true;
1414 /* This function is called by bfd_ecoff_debug_externals. It has
1415 nothing to do for ELF. */
1417 /*ARGSUSED*/
1418 static void
1419 elf_set_index (sym, indx)
1420 asymbol *sym;
1421 bfd_size_type indx;
1425 #endif /* NEED_ECOFF_DEBUG */
1427 void
1428 elf_frob_symbol (symp, puntp)
1429 symbolS *symp;
1430 int *puntp;
1432 #ifdef NEED_ECOFF_DEBUG
1433 if (ECOFF_DEBUGGING)
1434 ecoff_frob_symbol (symp);
1435 #endif
1437 if (symp->sy_obj.size != NULL)
1439 switch (symp->sy_obj.size->X_op)
1441 case O_subtract:
1442 S_SET_SIZE (symp,
1443 (S_GET_VALUE (symp->sy_obj.size->X_add_symbol)
1444 + symp->sy_obj.size->X_add_number
1445 - S_GET_VALUE (symp->sy_obj.size->X_op_symbol)));
1446 break;
1447 case O_constant:
1448 S_SET_SIZE (symp,
1449 (S_GET_VALUE (symp->sy_obj.size->X_add_symbol)
1450 + symp->sy_obj.size->X_add_number));
1451 break;
1452 default:
1453 as_bad (_(".size expression too complicated to fix up"));
1454 break;
1456 free (symp->sy_obj.size);
1457 symp->sy_obj.size = NULL;
1460 if (symp->sy_obj.versioned_name != NULL)
1462 /* This symbol was given a new name with the .symver directive.
1464 If this is an external reference, just rename the symbol to
1465 include the version string. This will make the relocs be
1466 against the correct versioned symbol.
1468 If this is a definition, add an alias. FIXME: Using an alias
1469 will permit the debugging information to refer to the right
1470 symbol. However, it's not clear whether it is the best
1471 approach. */
1473 if (! S_IS_DEFINED (symp))
1475 char *p;
1477 /* Verify that the name isn't using the @@ syntax--this is
1478 reserved for definitions of the default version to link
1479 against. */
1480 p = strchr (symp->sy_obj.versioned_name, ELF_VER_CHR);
1481 know (p != NULL);
1482 if (p[1] == ELF_VER_CHR)
1484 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1485 symp->sy_obj.versioned_name);
1486 *puntp = true;
1488 S_SET_NAME (symp, symp->sy_obj.versioned_name);
1490 else
1492 symbolS *symp2;
1494 /* FIXME: Creating a new symbol here is risky. We're in the
1495 final loop over the symbol table. We can get away with
1496 it only because the symbol goes to the end of the list,
1497 where the loop will still see it. It would probably be
1498 better to do this in obj_frob_file_before_adjust. */
1500 symp2 = symbol_find_or_make (symp->sy_obj.versioned_name);
1502 /* Now we act as though we saw symp2 = sym. */
1504 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1506 /* Subtracting out the frag address here is a hack because
1507 we are in the middle of the final loop. */
1508 S_SET_VALUE (symp2, S_GET_VALUE (symp) - symp->sy_frag->fr_address);
1510 symp2->sy_frag = symp->sy_frag;
1512 /* This will copy over the size information. */
1513 copy_symbol_attributes (symp2, symp);
1515 if (S_IS_WEAK (symp))
1516 S_SET_WEAK (symp2);
1518 if (S_IS_EXTERNAL (symp))
1519 S_SET_EXTERNAL (symp2);
1523 /* Double check weak symbols. */
1524 if (symp->bsym->flags & BSF_WEAK)
1526 if (S_IS_COMMON (symp))
1527 as_bad (_("Symbol `%s' can not be both weak and common"),
1528 S_GET_NAME (symp));
1531 #ifdef TC_MIPS
1532 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1533 any undefined non-function symbol to STT_OBJECT. We try to be
1534 compatible, since newer Irix 5 and 6 linkers care. However, we
1535 only set undefined symbols to be STT_OBJECT if we are on Irix,
1536 because that is the only time gcc will generate the necessary
1537 .global directives to mark functions. */
1539 if (S_IS_COMMON (symp))
1540 symp->bsym->flags |= BSF_OBJECT;
1542 if (strstr (TARGET_OS, "irix") != NULL
1543 && (! S_IS_DEFINED (symp) && ((symp->bsym->flags & BSF_FUNCTION) == 0)))
1544 symp->bsym->flags |= BSF_OBJECT;
1545 #endif
1547 #ifdef TC_PPC
1548 /* Frob the PowerPC, so that the symbol always has object type
1549 if it is not some other type. VxWorks needs this. */
1550 if ((symp->bsym->flags & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1551 && S_IS_DEFINED (symp))
1552 symp->bsym->flags |= BSF_OBJECT;
1553 #endif
1556 void
1557 elf_frob_file ()
1559 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
1561 #ifdef elf_tc_final_processing
1562 elf_tc_final_processing ();
1563 #endif
1566 /* It is required that we let write_relocs have the opportunity to
1567 optimize away fixups before output has begun, since it is possible
1568 to eliminate all fixups for a section and thus we never should
1569 have generated the relocation section. */
1571 void
1572 elf_frob_file_after_relocs ()
1574 #ifdef NEED_ECOFF_DEBUG
1575 if (ECOFF_DEBUGGING)
1576 /* Generate the ECOFF debugging information. */
1578 const struct ecoff_debug_swap *debug_swap;
1579 struct ecoff_debug_info debug;
1580 char *buf;
1581 asection *sec;
1583 debug_swap
1584 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
1585 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
1586 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
1588 /* Set up the pointers in debug. */
1589 #define SET(ptr, offset, type) \
1590 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1592 SET (line, cbLineOffset, unsigned char *);
1593 SET (external_dnr, cbDnOffset, PTR);
1594 SET (external_pdr, cbPdOffset, PTR);
1595 SET (external_sym, cbSymOffset, PTR);
1596 SET (external_opt, cbOptOffset, PTR);
1597 SET (external_aux, cbAuxOffset, union aux_ext *);
1598 SET (ss, cbSsOffset, char *);
1599 SET (external_fdr, cbFdOffset, PTR);
1600 SET (external_rfd, cbRfdOffset, PTR);
1601 /* ssext and external_ext are set up just below. */
1603 #undef SET
1605 /* Set up the external symbols. */
1606 debug.ssext = debug.ssext_end = NULL;
1607 debug.external_ext = debug.external_ext_end = NULL;
1608 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true,
1609 elf_get_extr, elf_set_index))
1610 as_fatal (_("Failed to set up debugging information: %s"),
1611 bfd_errmsg (bfd_get_error ()));
1613 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
1614 assert (sec != NULL);
1616 know (stdoutput->output_has_begun == false);
1618 /* We set the size of the section, call bfd_set_section_contents
1619 to force the ELF backend to allocate a file position, and then
1620 write out the data. FIXME: Is this really the best way to do
1621 this? */
1622 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
1624 if (! bfd_set_section_contents (stdoutput, sec, (PTR) NULL,
1625 (file_ptr) 0, (bfd_size_type) 0))
1626 as_fatal (_("Can't start writing .mdebug section: %s"),
1627 bfd_errmsg (bfd_get_error ()));
1629 know (stdoutput->output_has_begun == true);
1630 know (sec->filepos != 0);
1632 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
1633 sec->filepos))
1634 as_fatal (_("Could not write .mdebug section: %s"),
1635 bfd_errmsg (bfd_get_error ()));
1637 #endif /* NEED_ECOFF_DEBUG */
1640 #ifdef SCO_ELF
1642 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1643 SCO specific identifier in the .notes section to satisfy the SCO
1644 linker.
1646 This looks more complicated than it really is. As opposed to the
1647 "obvious" solution, this should handle the cross dev cases
1648 correctly. (i.e, hosting on a 64 bit big endian processor, but
1649 generating SCO Elf code) Efficiency isn't a concern, as there
1650 should be exactly one of these sections per object module.
1652 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1653 .note section.
1655 int_32 namesz = 4 ; Name size
1656 int_32 descsz = 12 ; Descriptive information
1657 int_32 type = 1 ;
1658 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1659 int_32 version = (major ver # << 16) | version of tools ;
1660 int_32 source = (tool_id << 16 ) | 1 ;
1661 int_32 info = 0 ; These are set by the SCO tools, but we
1662 don't know enough about the source
1663 environment to set them. SCO ld currently
1664 ignores them, and recommends we set them
1665 to zero. */
1667 #define SCO_MAJOR_VERSION 0x1
1668 #define SCO_MINOR_VERSION 0x1
1670 void
1671 sco_id ()
1674 char *name;
1675 unsigned int c;
1676 char ch;
1677 char *p;
1678 asection *seg = now_seg;
1679 subsegT subseg = now_subseg;
1680 Elf_Internal_Note i_note;
1681 Elf_External_Note e_note;
1682 asection *note_secp = (asection *) NULL;
1683 int i, len;
1685 /* create the .note section */
1687 note_secp = subseg_new (".note", 0);
1688 bfd_set_section_flags (stdoutput,
1689 note_secp,
1690 SEC_HAS_CONTENTS | SEC_READONLY);
1692 /* process the version string */
1694 i_note.namesz = 4;
1695 i_note.descsz = 12; /* 12 descriptive bytes */
1696 i_note.type = NT_VERSION; /* Contains a version string */
1698 p = frag_more (sizeof (i_note.namesz));
1699 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1701 p = frag_more (sizeof (i_note.descsz));
1702 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1704 p = frag_more (sizeof (i_note.type));
1705 md_number_to_chars (p, (valueT) i_note.type, 4);
1707 p = frag_more (4);
1708 strcpy (p, "SCO");
1710 /* Note: this is the version number of the ELF we're representing */
1711 p = frag_more (4);
1712 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
1714 /* Here, we pick a magic number for ourselves (yes, I "registered"
1715 it with SCO. The bottom bit shows that we are compat with the
1716 SCO ABI. */
1717 p = frag_more (4);
1718 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
1720 /* If we knew (or cared) what the source language options were, we'd
1721 fill them in here. SCO has given us permission to ignore these
1722 and just set them to zero. */
1723 p = frag_more (4);
1724 md_number_to_chars (p, 0x0000, 4);
1726 frag_align (2, 0, 0);
1728 /* We probably can't restore the current segment, for there likely
1729 isn't one yet... */
1730 if (seg && subseg)
1731 subseg_set (seg, subseg);
1735 #endif /* SCO_ELF */
1737 const struct format_ops elf_format_ops =
1739 bfd_target_elf_flavour,
1742 elf_frob_symbol,
1743 elf_frob_file,
1744 elf_frob_file_after_relocs,
1745 elf_s_get_size, elf_s_set_size,
1746 elf_s_get_align, elf_s_set_align,
1747 elf_copy_symbol_attributes,
1748 #ifdef NEED_ECOFF_DEBUG
1749 ecoff_generate_asm_lineno,
1750 ecoff_stab,
1751 #else
1753 0, /* process_stab */
1754 #endif
1755 elf_sec_sym_ok_for_reloc,
1756 elf_pop_insert,
1757 #ifdef NEED_ECOFF_DEBUG
1758 elf_ecoff_set_ext,
1759 #else
1761 #endif
1762 obj_read_begin_hook,
1763 obj_symbol_new_hook,