fc3921d2200708dd4d38437f639d27d09ccc4878
[binutils-gdb.git] / gas / config / obj-elf.c
1 /* ELF object file format
2 Copyright (C) 1992, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
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.
10
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.
15
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. */
20
21 #define OBJ_HEADER "obj-elf.h"
22 #include "as.h"
23 #include "subsegs.h"
24 #include "obstack.h"
25
26 #ifndef ECOFF_DEBUGGING
27 #define ECOFF_DEBUGGING 0
28 #else
29 #define NEED_ECOFF_DEBUG
30 #endif
31
32 #ifdef NEED_ECOFF_DEBUG
33 #include "ecoff.h"
34 #endif
35
36 #ifdef TC_MIPS
37 #include "elf/mips.h"
38 #endif
39
40 #ifdef TC_PPC
41 #include "elf/ppc.h"
42 #endif
43
44 static bfd_vma elf_s_get_size PARAMS ((symbolS *));
45 static void elf_s_set_size PARAMS ((symbolS *, bfd_vma));
46 static bfd_vma elf_s_get_align PARAMS ((symbolS *));
47 static void elf_s_set_align PARAMS ((symbolS *, bfd_vma));
48 static void elf_copy_symbol_attributes PARAMS ((symbolS *, symbolS *));
49 static int elf_sec_sym_ok_for_reloc PARAMS ((asection *));
50 static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));
51
52 #ifdef NEED_ECOFF_DEBUG
53 static boolean elf_get_extr PARAMS ((asymbol *, EXTR *));
54 static void elf_set_index PARAMS ((asymbol *, bfd_size_type));
55 #endif
56
57 static void obj_elf_line PARAMS ((int));
58 void obj_elf_version PARAMS ((int));
59 static void obj_elf_size PARAMS ((int));
60 static void obj_elf_type PARAMS ((int));
61 static void obj_elf_ident PARAMS ((int));
62 static void obj_elf_weak PARAMS ((int));
63 static void obj_elf_local PARAMS ((int));
64 static void obj_elf_common PARAMS ((int));
65 static void obj_elf_symver PARAMS ((int));
66 static void obj_elf_data PARAMS ((int));
67 static void obj_elf_text PARAMS ((int));
68 static void obj_elf_subsection PARAMS ((int));
69
70 static const pseudo_typeS elf_pseudo_table[] =
71 {
72 {"comm", obj_elf_common, 0},
73 {"ident", obj_elf_ident, 0},
74 {"local", obj_elf_local, 0},
75 {"previous", obj_elf_previous, 0},
76 {"section", obj_elf_section, 0},
77 {"section.s", obj_elf_section, 0},
78 {"sect", obj_elf_section, 0},
79 {"sect.s", obj_elf_section, 0},
80 {"size", obj_elf_size, 0},
81 {"type", obj_elf_type, 0},
82 {"version", obj_elf_version, 0},
83 {"weak", obj_elf_weak, 0},
84
85 /* These are used for stabs-in-elf configurations. */
86 {"line", obj_elf_line, 0},
87
88 /* This is a GNU extension to handle symbol versions. */
89 {"symver", obj_elf_symver, 0},
90
91 /* A GNU extension to change subsection only. */
92 {"subsection", obj_elf_subsection, 0},
93
94 /* These are used for dwarf. */
95 {"2byte", cons, 2},
96 {"4byte", cons, 4},
97 {"8byte", cons, 8},
98
99 /* We need to trap the section changing calls to handle .previous. */
100 {"data", obj_elf_data, 0},
101 {"text", obj_elf_text, 0},
102
103 /* End sentinel. */
104 {NULL},
105 };
106
107 static const pseudo_typeS ecoff_debug_pseudo_table[] =
108 {
109 #ifdef NEED_ECOFF_DEBUG
110 /* COFF style debugging information for ECOFF. .ln is not used; .loc
111 is used instead. */
112 { "def", ecoff_directive_def, 0 },
113 { "dim", ecoff_directive_dim, 0 },
114 { "endef", ecoff_directive_endef, 0 },
115 { "file", ecoff_directive_file, 0 },
116 { "scl", ecoff_directive_scl, 0 },
117 { "tag", ecoff_directive_tag, 0 },
118 { "val", ecoff_directive_val, 0 },
119
120 /* COFF debugging requires pseudo-ops .size and .type, but ELF
121 already has meanings for those. We use .esize and .etype
122 instead. These are only generated by gcc anyhow. */
123 { "esize", ecoff_directive_size, 0 },
124 { "etype", ecoff_directive_type, 0 },
125
126 /* ECOFF specific debugging information. */
127 { "begin", ecoff_directive_begin, 0 },
128 { "bend", ecoff_directive_bend, 0 },
129 { "end", ecoff_directive_end, 0 },
130 { "ent", ecoff_directive_ent, 0 },
131 { "fmask", ecoff_directive_fmask, 0 },
132 { "frame", ecoff_directive_frame, 0 },
133 { "loc", ecoff_directive_loc, 0 },
134 { "mask", ecoff_directive_mask, 0 },
135
136 /* Other ECOFF directives. */
137 { "extern", ecoff_directive_extern, 0 },
138
139 /* These are used on Irix. I don't know how to implement them. */
140 { "alias", s_ignore, 0 },
141 { "bgnb", s_ignore, 0 },
142 { "endb", s_ignore, 0 },
143 { "lab", s_ignore, 0 },
144 { "noalias", s_ignore, 0 },
145 { "verstamp", s_ignore, 0 },
146 { "vreg", s_ignore, 0 },
147 #endif
148
149 {NULL} /* end sentinel */
150 };
151
152 #undef NO_RELOC
153 #include "aout/aout64.h"
154
155 /* This is called when the assembler starts. */
156
157 void
158 elf_begin ()
159 {
160 /* Add symbols for the known sections to the symbol table. */
161 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
162 TEXT_SECTION_NAME)));
163 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
164 DATA_SECTION_NAME)));
165 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
166 BSS_SECTION_NAME)));
167 }
168
169 void
170 elf_pop_insert ()
171 {
172 pop_insert (elf_pseudo_table);
173 if (ECOFF_DEBUGGING)
174 pop_insert (ecoff_debug_pseudo_table);
175 }
176
177 static bfd_vma
178 elf_s_get_size (sym)
179 symbolS *sym;
180 {
181 return S_GET_SIZE (sym);
182 }
183
184 static void
185 elf_s_set_size (sym, sz)
186 symbolS *sym;
187 bfd_vma sz;
188 {
189 S_SET_SIZE (sym, sz);
190 }
191
192 static bfd_vma
193 elf_s_get_align (sym)
194 symbolS *sym;
195 {
196 return S_GET_ALIGN (sym);
197 }
198
199 static void
200 elf_s_set_align (sym, align)
201 symbolS *sym;
202 bfd_vma align;
203 {
204 S_SET_ALIGN (sym, align);
205 }
206
207 static void
208 elf_copy_symbol_attributes (dest, src)
209 symbolS *dest, *src;
210 {
211 OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);
212 }
213
214 static int
215 elf_sec_sym_ok_for_reloc (sec)
216 asection *sec;
217 {
218 return obj_sec_sym_ok_for_reloc (sec);
219 }
220
221 void
222 elf_file_symbol (s)
223 char *s;
224 {
225 symbolS *sym;
226
227 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
228 sym->sy_frag = &zero_address_frag;
229 sym->bsym->flags |= BSF_FILE;
230
231 if (symbol_rootP != sym)
232 {
233 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
234 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
235 #ifdef DEBUG
236 verify_symbol_chain (symbol_rootP, symbol_lastP);
237 #endif
238 }
239
240 #ifdef NEED_ECOFF_DEBUG
241 ecoff_new_file (s);
242 #endif
243 }
244
245 static void
246 obj_elf_common (ignore)
247 int ignore;
248 {
249 char *name;
250 char c;
251 char *p;
252 int temp, size;
253 symbolS *symbolP;
254 int have_align;
255
256 name = input_line_pointer;
257 c = get_symbol_end ();
258 /* just after name is now '\0' */
259 p = input_line_pointer;
260 *p = c;
261 SKIP_WHITESPACE ();
262 if (*input_line_pointer != ',')
263 {
264 as_bad ("Expected comma after symbol-name");
265 ignore_rest_of_line ();
266 return;
267 }
268 input_line_pointer++; /* skip ',' */
269 if ((temp = get_absolute_expression ()) < 0)
270 {
271 as_bad (".COMMon length (%d.) <0! Ignored.", temp);
272 ignore_rest_of_line ();
273 return;
274 }
275 size = temp;
276 *p = 0;
277 symbolP = symbol_find_or_make (name);
278 *p = c;
279 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
280 {
281 as_bad ("Ignoring attempt to re-define symbol");
282 ignore_rest_of_line ();
283 return;
284 }
285 if (S_GET_VALUE (symbolP) != 0)
286 {
287 if (S_GET_VALUE (symbolP) != size)
288 {
289 as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
290 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
291 }
292 }
293 know (symbolP->sy_frag == &zero_address_frag);
294 if (*input_line_pointer != ',')
295 have_align = 0;
296 else
297 {
298 have_align = 1;
299 input_line_pointer++;
300 SKIP_WHITESPACE ();
301 }
302 if (! have_align || *input_line_pointer != '"')
303 {
304 if (! have_align)
305 temp = 0;
306 else
307 {
308 temp = get_absolute_expression ();
309 if (temp < 0)
310 {
311 temp = 0;
312 as_warn ("Common alignment negative; 0 assumed");
313 }
314 }
315 if (symbolP->local)
316 {
317 segT old_sec;
318 int old_subsec;
319 char *pfrag;
320 int align;
321
322 /* allocate_bss: */
323 old_sec = now_seg;
324 old_subsec = now_subseg;
325 if (temp)
326 {
327 /* convert to a power of 2 alignment */
328 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
329 if (temp != 1)
330 {
331 as_bad ("Common alignment not a power of 2");
332 ignore_rest_of_line ();
333 return;
334 }
335 }
336 else
337 align = 0;
338 record_alignment (bss_section, align);
339 subseg_set (bss_section, 0);
340 if (align)
341 frag_align (align, 0, 0);
342 if (S_GET_SEGMENT (symbolP) == bss_section)
343 symbolP->sy_frag->fr_symbol = 0;
344 symbolP->sy_frag = frag_now;
345 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
346 (offsetT) size, (char *) 0);
347 *pfrag = 0;
348 S_SET_SIZE (symbolP, size);
349 S_SET_SEGMENT (symbolP, bss_section);
350 S_CLEAR_EXTERNAL (symbolP);
351 subseg_set (old_sec, old_subsec);
352 }
353 else
354 {
355 allocate_common:
356 S_SET_VALUE (symbolP, (valueT) size);
357 S_SET_ALIGN (symbolP, temp);
358 S_SET_EXTERNAL (symbolP);
359 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
360 }
361 }
362 else
363 {
364 input_line_pointer++;
365 /* @@ Some use the dot, some don't. Can we get some consistency?? */
366 if (*input_line_pointer == '.')
367 input_line_pointer++;
368 /* @@ Some say data, some say bss. */
369 if (strncmp (input_line_pointer, "bss\"", 4)
370 && strncmp (input_line_pointer, "data\"", 5))
371 {
372 while (*--input_line_pointer != '"')
373 ;
374 input_line_pointer--;
375 goto bad_common_segment;
376 }
377 while (*input_line_pointer++ != '"')
378 ;
379 goto allocate_common;
380 }
381
382 symbolP->bsym->flags |= BSF_OBJECT;
383
384 demand_empty_rest_of_line ();
385 return;
386
387 {
388 bad_common_segment:
389 p = input_line_pointer;
390 while (*p && *p != '\n')
391 p++;
392 c = *p;
393 *p = '\0';
394 as_bad ("bad .common segment %s", input_line_pointer + 1);
395 *p = c;
396 input_line_pointer = p;
397 ignore_rest_of_line ();
398 return;
399 }
400 }
401
402 static void
403 obj_elf_local (ignore)
404 int ignore;
405 {
406 char *name;
407 int c;
408 symbolS *symbolP;
409
410 do
411 {
412 name = input_line_pointer;
413 c = get_symbol_end ();
414 symbolP = symbol_find_or_make (name);
415 *input_line_pointer = c;
416 SKIP_WHITESPACE ();
417 S_CLEAR_EXTERNAL (symbolP);
418 symbolP->local = 1;
419 if (c == ',')
420 {
421 input_line_pointer++;
422 SKIP_WHITESPACE ();
423 if (*input_line_pointer == '\n')
424 c = '\n';
425 }
426 }
427 while (c == ',');
428 demand_empty_rest_of_line ();
429 }
430
431 static void
432 obj_elf_weak (ignore)
433 int ignore;
434 {
435 char *name;
436 int c;
437 symbolS *symbolP;
438
439 do
440 {
441 name = input_line_pointer;
442 c = get_symbol_end ();
443 symbolP = symbol_find_or_make (name);
444 *input_line_pointer = c;
445 SKIP_WHITESPACE ();
446 S_SET_WEAK (symbolP);
447 symbolP->local = 1;
448 if (c == ',')
449 {
450 input_line_pointer++;
451 SKIP_WHITESPACE ();
452 if (*input_line_pointer == '\n')
453 c = '\n';
454 }
455 }
456 while (c == ',');
457 demand_empty_rest_of_line ();
458 }
459
460 static segT previous_section;
461 static int previous_subsection;
462
463 /* Handle the .section pseudo-op. This code supports two different
464 syntaxes.
465
466 The first is found on Solaris, and looks like
467 .section ".sec1",#alloc,#execinstr,#write
468 Here the names after '#' are the SHF_* flags to turn on for the
469 section. I'm not sure how it determines the SHT_* type (BFD
470 doesn't really give us control over the type, anyhow).
471
472 The second format is found on UnixWare, and probably most SVR4
473 machines, and looks like
474 .section .sec1,"a",@progbits
475 The quoted string may contain any combination of a, w, x, and
476 represents the SHF_* flags to turn on for the section. The string
477 beginning with '@' can be progbits or nobits. There should be
478 other possibilities, but I don't know what they are. In any case,
479 BFD doesn't really let us set the section type. */
480
481 /* Certain named sections have particular defined types, listed on p.
482 4-19 of the ABI. */
483 struct special_section
484 {
485 const char *name;
486 int type;
487 int attributes;
488 };
489
490 static struct special_section special_sections[] =
491 {
492 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
493 { ".comment", SHT_PROGBITS, 0 },
494 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
495 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
496 { ".debug", SHT_PROGBITS, 0 },
497 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
498 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
499 { ".line", SHT_PROGBITS, 0 },
500 { ".note", SHT_NOTE, 0 },
501 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
502 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
503 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
504
505 #ifdef ELF_TC_SPECIAL_SECTIONS
506 ELF_TC_SPECIAL_SECTIONS
507 #endif
508
509 #if 0
510 /* The following section names are special, but they can not
511 reasonably appear in assembler code. Some of the attributes are
512 processor dependent. */
513 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
514 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
515 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
516 { ".got", SHT_PROGBITS, 0 },
517 { ".hash", SHT_HASH, SHF_ALLOC },
518 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
519 { ".plt", SHT_PROGBITS, 0 },
520 { ".shstrtab",SHT_STRTAB, 0 },
521 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
522 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
523 #endif
524
525 { NULL, 0, 0 }
526 };
527
528 void
529 obj_elf_section (xxx)
530 int xxx;
531 {
532 char *string;
533 int new_sec;
534 segT sec;
535 int type, attr;
536 int i;
537 flagword flags;
538 symbolS *secsym;
539
540 #ifdef md_flush_pending_output
541 md_flush_pending_output ();
542 #endif
543
544 if (flag_mri)
545 {
546 char mri_type;
547
548 previous_section = now_seg;
549 previous_subsection = now_subseg;
550
551 s_mri_sect (&mri_type);
552
553 #ifdef md_elf_section_change_hook
554 md_elf_section_change_hook ();
555 #endif
556
557 return;
558 }
559
560 /* Get name of section. */
561 SKIP_WHITESPACE ();
562 if (*input_line_pointer == '"')
563 {
564 string = demand_copy_C_string (&xxx);
565 if (string == NULL)
566 {
567 ignore_rest_of_line ();
568 return;
569 }
570 }
571 else
572 {
573 char *p = input_line_pointer;
574 char c;
575 while (0 == strchr ("\n\t,; ", *p))
576 p++;
577 if (p == input_line_pointer)
578 {
579 as_warn ("Missing section name");
580 ignore_rest_of_line ();
581 return;
582 }
583 c = *p;
584 *p = 0;
585 string = xmalloc ((unsigned long) (p - input_line_pointer + 1));
586 strcpy (string, input_line_pointer);
587 *p = c;
588 input_line_pointer = p;
589 }
590
591 /* Switch to the section, creating it if necessary. */
592 previous_section = now_seg;
593 previous_subsection = now_subseg;
594
595 new_sec = bfd_get_section_by_name (stdoutput, string) == NULL;
596 sec = subseg_new (string, 0);
597
598 /* If this section already existed, we don't bother to change the
599 flag values. */
600 if (! new_sec)
601 {
602 while (! is_end_of_line[(unsigned char) *input_line_pointer])
603 ++input_line_pointer;
604 ++input_line_pointer;
605
606 #ifdef md_elf_section_change_hook
607 md_elf_section_change_hook ();
608 #endif
609
610 return;
611 }
612
613 SKIP_WHITESPACE ();
614
615 type = SHT_NULL;
616 attr = 0;
617
618 if (*input_line_pointer == ',')
619 {
620 /* Skip the comma. */
621 ++input_line_pointer;
622
623 SKIP_WHITESPACE ();
624
625 if (*input_line_pointer == '"')
626 {
627 /* Pick up a string with a combination of a, w, x. */
628 ++input_line_pointer;
629 while (*input_line_pointer != '"')
630 {
631 switch (*input_line_pointer)
632 {
633 case 'a':
634 attr |= SHF_ALLOC;
635 break;
636 case 'w':
637 attr |= SHF_WRITE;
638 break;
639 case 'x':
640 attr |= SHF_EXECINSTR;
641 break;
642 default:
643 {
644 char *bad_msg = "Bad .section directive: want a,w,x in string";
645 #ifdef md_elf_section_letter
646 int md_attr = md_elf_section_letter (*input_line_pointer, &bad_msg);
647 if (md_attr)
648 attr |= md_attr;
649 else
650 #endif
651 {
652 as_warn (bad_msg);
653 ignore_rest_of_line ();
654 return;
655 }
656 }
657 }
658 ++input_line_pointer;
659 }
660
661 /* Skip the closing quote. */
662 ++input_line_pointer;
663
664 SKIP_WHITESPACE ();
665 if (*input_line_pointer == ',')
666 {
667 ++input_line_pointer;
668 SKIP_WHITESPACE ();
669 if (*input_line_pointer == '@')
670 {
671 ++input_line_pointer;
672 if (strncmp (input_line_pointer, "progbits",
673 sizeof "progbits" - 1) == 0)
674 {
675 type = SHT_PROGBITS;
676 input_line_pointer += sizeof "progbits" - 1;
677 }
678 else if (strncmp (input_line_pointer, "nobits",
679 sizeof "nobits" - 1) == 0)
680 {
681 type = SHT_NOBITS;
682 input_line_pointer += sizeof "nobits" - 1;
683 }
684 else
685 {
686 #ifdef md_elf_section_type
687 int md_type = md_elf_section_type (&input_line_pointer);
688 if (md_type)
689 type = md_type;
690 else
691 #endif
692 {
693 as_warn ("Unrecognized section type");
694 ignore_rest_of_line ();
695 }
696 }
697 }
698 }
699 }
700 else
701 {
702 do
703 {
704 SKIP_WHITESPACE ();
705 if (*input_line_pointer != '#')
706 {
707 as_warn ("Bad .section directive - character following name is not '#'");
708 ignore_rest_of_line ();
709 return;
710 }
711 ++input_line_pointer;
712 if (strncmp (input_line_pointer, "write",
713 sizeof "write" - 1) == 0)
714 {
715 attr |= SHF_WRITE;
716 input_line_pointer += sizeof "write" - 1;
717 }
718 else if (strncmp (input_line_pointer, "alloc",
719 sizeof "alloc" - 1) == 0)
720 {
721 attr |= SHF_ALLOC;
722 input_line_pointer += sizeof "alloc" - 1;
723 }
724 else if (strncmp (input_line_pointer, "execinstr",
725 sizeof "execinstr" - 1) == 0)
726 {
727 attr |= SHF_EXECINSTR;
728 input_line_pointer += sizeof "execinstr" - 1;
729 }
730 else
731 {
732 #ifdef md_elf_section_word
733 int md_attr = md_elf_section_word (&input_line_pointer);
734 if (md_attr)
735 attr |= md_attr;
736 else
737 #endif
738 {
739 as_warn ("Unrecognized section attribute");
740 ignore_rest_of_line ();
741 return;
742 }
743 }
744 SKIP_WHITESPACE ();
745 }
746 while (*input_line_pointer++ == ',');
747 --input_line_pointer;
748 }
749 }
750
751 /* See if this is one of the special sections. */
752 for (i = 0; special_sections[i].name != NULL; i++)
753 {
754 if (string[1] == special_sections[i].name[1]
755 && strcmp (string, special_sections[i].name) == 0)
756 {
757 if (type == SHT_NULL)
758 type = special_sections[i].type;
759 else if (type != special_sections[i].type)
760 as_warn ("Setting incorrect section type for %s", string);
761
762 if ((attr &~ special_sections[i].attributes) != 0)
763 {
764 /* As a GNU extension, we permit a .note section to be
765 allocatable. If the linker sees an allocateable
766 .note section, it will create a PT_NOTE segment in
767 the output file. */
768 if (strcmp (string, ".note") != 0
769 || attr != SHF_ALLOC)
770 as_warn ("Setting incorrect section attributes for %s",
771 string);
772 }
773 attr |= special_sections[i].attributes;
774
775 break;
776 }
777 }
778
779 flags = (SEC_RELOC
780 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
781 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
782 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
783 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0));
784 if (special_sections[i].name == NULL)
785 {
786 if (type == SHT_PROGBITS)
787 flags |= SEC_ALLOC | SEC_LOAD;
788 else if (type == SHT_NOBITS)
789 {
790 flags |= SEC_ALLOC;
791 flags &=~ SEC_LOAD;
792 }
793
794 #ifdef md_elf_section_flags
795 flags = md_elf_section_flags (flags, attr, type);
796 #endif
797 }
798
799 bfd_set_section_flags (stdoutput, sec, flags);
800
801 /* Add a symbol for this section to the symbol table. */
802 secsym = symbol_find (string);
803 if (secsym != NULL)
804 secsym->bsym = sec->symbol;
805 else
806 symbol_table_insert (section_symbol (sec));
807
808 #ifdef md_elf_section_change_hook
809 md_elf_section_change_hook ();
810 #endif
811
812 demand_empty_rest_of_line ();
813 }
814
815 /* Change to the .data section. */
816
817 static void
818 obj_elf_data (i)
819 int i;
820 {
821 #ifdef md_flush_pending_output
822 md_flush_pending_output ();
823 #endif
824
825 previous_section = now_seg;
826 previous_subsection = now_subseg;
827 s_data (i);
828
829 #ifdef md_elf_section_change_hook
830 md_elf_section_change_hook ();
831 #endif
832 }
833
834 /* Change to the .text section. */
835
836 static void
837 obj_elf_text (i)
838 int i;
839 {
840 #ifdef md_flush_pending_output
841 md_flush_pending_output ();
842 #endif
843
844 previous_section = now_seg;
845 previous_subsection = now_subseg;
846 s_text (i);
847
848 #ifdef md_elf_section_change_hook
849 md_elf_section_change_hook ();
850 #endif
851 }
852
853 static void
854 obj_elf_subsection (ignore)
855 int ignore;
856 {
857 register int temp;
858
859 #ifdef md_flush_pending_output
860 md_flush_pending_output ();
861 #endif
862
863 previous_section = now_seg;
864 previous_subsection = now_subseg;
865
866 temp = get_absolute_expression ();
867 subseg_set (now_seg, (subsegT) temp);
868 demand_empty_rest_of_line ();
869
870 #ifdef md_elf_section_change_hook
871 md_elf_section_change_hook ();
872 #endif
873 }
874
875 /* This can be called from the processor backends if they change
876 sections. */
877
878 void
879 obj_elf_section_change_hook ()
880 {
881 previous_section = now_seg;
882 previous_subsection = now_subseg;
883 }
884
885 void
886 obj_elf_previous (ignore)
887 int ignore;
888 {
889 if (previous_section == 0)
890 {
891 as_bad (".previous without corresponding .section; ignored");
892 return;
893 }
894
895 #ifdef md_flush_pending_output
896 md_flush_pending_output ();
897 #endif
898
899 subseg_set (previous_section, previous_subsection);
900 previous_section = 0;
901
902 #ifdef md_elf_section_change_hook
903 md_elf_section_change_hook ();
904 #endif
905 }
906
907 static void
908 obj_elf_line (ignore)
909 int ignore;
910 {
911 /* Assume delimiter is part of expression. BSD4.2 as fails with
912 delightful bug, so we are not being incompatible here. */
913 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
914 demand_empty_rest_of_line ();
915 }
916
917 /* This handle the .symver pseudo-op, which is used to specify a
918 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
919 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
920 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
921 with the same value as the symbol NAME. */
922
923 static void
924 obj_elf_symver (ignore)
925 int ignore;
926 {
927 char *name;
928 char c;
929 symbolS *sym;
930
931 name = input_line_pointer;
932 c = get_symbol_end ();
933
934 sym = symbol_find_or_make (name);
935
936 *input_line_pointer = c;
937
938 if (sym->sy_obj.versioned_name != NULL)
939 {
940 as_bad ("multiple .symver directives for symbol `%s'",
941 S_GET_NAME (sym));
942 ignore_rest_of_line ();
943 return;
944 }
945
946 SKIP_WHITESPACE ();
947 if (*input_line_pointer != ',')
948 {
949 as_bad ("expected comma after name in .symver");
950 ignore_rest_of_line ();
951 return;
952 }
953
954 ++input_line_pointer;
955 name = input_line_pointer;
956 while (1)
957 {
958 c = get_symbol_end ();
959 if (c != ELF_VER_CHR)
960 break;
961 *input_line_pointer++ = c;
962 }
963
964 sym->sy_obj.versioned_name = xstrdup (name);
965
966 *input_line_pointer = c;
967
968 if (strchr (sym->sy_obj.versioned_name, ELF_VER_CHR) == NULL)
969 {
970 as_bad ("missing version name in `%s' for symbol `%s'",
971 sym->sy_obj.versioned_name, S_GET_NAME (sym));
972 ignore_rest_of_line ();
973 return;
974 }
975
976 demand_empty_rest_of_line ();
977 }
978
979 void
980 obj_read_begin_hook ()
981 {
982 #ifdef NEED_ECOFF_DEBUG
983 if (ECOFF_DEBUGGING)
984 ecoff_read_begin_hook ();
985 #endif
986 }
987
988 void
989 obj_symbol_new_hook (symbolP)
990 symbolS *symbolP;
991 {
992 symbolP->sy_obj.size = NULL;
993 symbolP->sy_obj.versioned_name = NULL;
994
995 #ifdef NEED_ECOFF_DEBUG
996 if (ECOFF_DEBUGGING)
997 ecoff_symbol_new_hook (symbolP);
998 #endif
999 }
1000
1001 void
1002 obj_elf_version (ignore)
1003 int ignore;
1004 {
1005 char *name;
1006 unsigned int c;
1007 char ch;
1008 char *p;
1009 asection *seg = now_seg;
1010 subsegT subseg = now_subseg;
1011 Elf_Internal_Note i_note;
1012 Elf_External_Note e_note;
1013 asection *note_secp = (asection *) NULL;
1014 int i, len;
1015
1016 SKIP_WHITESPACE ();
1017 if (*input_line_pointer == '\"')
1018 {
1019 ++input_line_pointer; /* -> 1st char of string. */
1020 name = input_line_pointer;
1021
1022 while (is_a_char (c = next_char_of_string ()))
1023 ;
1024 c = *input_line_pointer;
1025 *input_line_pointer = '\0';
1026 *(input_line_pointer - 1) = '\0';
1027 *input_line_pointer = c;
1028
1029 /* create the .note section */
1030
1031 note_secp = subseg_new (".note", 0);
1032 bfd_set_section_flags (stdoutput,
1033 note_secp,
1034 SEC_HAS_CONTENTS | SEC_READONLY);
1035
1036 /* process the version string */
1037
1038 len = strlen (name);
1039
1040 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1041 i_note.descsz = 0; /* no description */
1042 i_note.type = NT_VERSION;
1043 p = frag_more (sizeof (e_note.namesz));
1044 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1045 p = frag_more (sizeof (e_note.descsz));
1046 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1047 p = frag_more (sizeof (e_note.type));
1048 md_number_to_chars (p, (valueT) i_note.type, 4);
1049
1050 for (i = 0; i < len; i++)
1051 {
1052 ch = *(name + i);
1053 {
1054 FRAG_APPEND_1_CHAR (ch);
1055 }
1056 }
1057 frag_align (2, 0, 0);
1058
1059 subseg_set (seg, subseg);
1060 }
1061 else
1062 {
1063 as_bad ("Expected quoted string");
1064 }
1065 demand_empty_rest_of_line ();
1066 }
1067
1068 static void
1069 obj_elf_size (ignore)
1070 int ignore;
1071 {
1072 char *name = input_line_pointer;
1073 char c = get_symbol_end ();
1074 char *p;
1075 expressionS exp;
1076 symbolS *sym;
1077
1078 p = input_line_pointer;
1079 *p = c;
1080 SKIP_WHITESPACE ();
1081 if (*input_line_pointer != ',')
1082 {
1083 *p = 0;
1084 as_bad ("expected comma after name `%s' in .size directive", name);
1085 *p = c;
1086 ignore_rest_of_line ();
1087 return;
1088 }
1089 input_line_pointer++;
1090 expression (&exp);
1091 if (exp.X_op == O_absent)
1092 {
1093 as_bad ("missing expression in .size directive");
1094 exp.X_op = O_constant;
1095 exp.X_add_number = 0;
1096 }
1097 *p = 0;
1098 sym = symbol_find_or_make (name);
1099 *p = c;
1100 if (exp.X_op == O_constant)
1101 S_SET_SIZE (sym, exp.X_add_number);
1102 else
1103 {
1104 sym->sy_obj.size = (expressionS *) xmalloc (sizeof (expressionS));
1105 *sym->sy_obj.size = exp;
1106 }
1107 demand_empty_rest_of_line ();
1108 }
1109
1110 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1111 There are three syntaxes. The first (used on Solaris) is
1112 .type SYM,#function
1113 The second (used on UnixWare) is
1114 .type SYM,@function
1115 The third (reportedly to be used on Irix 6.0) is
1116 .type SYM STT_FUNC
1117 */
1118
1119 static void
1120 obj_elf_type (ignore)
1121 int ignore;
1122 {
1123 char *name;
1124 char c;
1125 int type;
1126 const char *typename;
1127 symbolS *sym;
1128
1129 name = input_line_pointer;
1130 c = get_symbol_end ();
1131 sym = symbol_find_or_make (name);
1132 *input_line_pointer = c;
1133
1134 SKIP_WHITESPACE ();
1135 if (*input_line_pointer == ',')
1136 ++input_line_pointer;
1137
1138 SKIP_WHITESPACE ();
1139 if (*input_line_pointer == '#' || *input_line_pointer == '@')
1140 ++input_line_pointer;
1141
1142 typename = input_line_pointer;
1143 c = get_symbol_end ();
1144
1145 type = 0;
1146 if (strcmp (typename, "function") == 0
1147 || strcmp (typename, "STT_FUNC") == 0)
1148 type = BSF_FUNCTION;
1149 else if (strcmp (typename, "object") == 0
1150 || strcmp (typename, "STT_OBJECT") == 0)
1151 type = BSF_OBJECT;
1152 else
1153 as_bad ("ignoring unrecognized symbol type \"%s\"", typename);
1154
1155 *input_line_pointer = c;
1156
1157 sym->bsym->flags |= type;
1158
1159 demand_empty_rest_of_line ();
1160 }
1161
1162 static void
1163 obj_elf_ident (ignore)
1164 int ignore;
1165 {
1166 static segT comment_section;
1167 segT old_section = now_seg;
1168 int old_subsection = now_subseg;
1169
1170 if (!comment_section)
1171 {
1172 char *p;
1173 comment_section = subseg_new (".comment", 0);
1174 bfd_set_section_flags (stdoutput, comment_section,
1175 SEC_READONLY | SEC_HAS_CONTENTS);
1176 p = frag_more (1);
1177 *p = 0;
1178 }
1179 else
1180 subseg_set (comment_section, 0);
1181 stringer (1);
1182 subseg_set (old_section, old_subsection);
1183 }
1184
1185 #ifdef INIT_STAB_SECTION
1186
1187 /* The first entry in a .stabs section is special. */
1188
1189 void
1190 obj_elf_init_stab_section (seg)
1191 segT seg;
1192 {
1193 char *file;
1194 char *p;
1195 char *stabstr_name;
1196 unsigned int stroff;
1197
1198 /* Force the section to align to a longword boundary. Without this,
1199 UnixWare ar crashes. */
1200 bfd_set_section_alignment (stdoutput, seg, 2);
1201
1202 /* Make space for this first symbol. */
1203 p = frag_more (12);
1204 /* Zero it out. */
1205 memset (p, 0, 12);
1206 as_where (&file, (unsigned int *) NULL);
1207 stabstr_name = (char *) alloca (strlen (segment_name (seg)) + 4);
1208 strcpy (stabstr_name, segment_name (seg));
1209 strcat (stabstr_name, "str");
1210 stroff = get_stab_string_offset (file, stabstr_name);
1211 know (stroff == 1);
1212 md_number_to_chars (p, stroff, 4);
1213 seg_info (seg)->stabu.p = p;
1214 }
1215
1216 #endif
1217
1218 /* Fill in the counts in the first entry in a .stabs section. */
1219
1220 static void
1221 adjust_stab_sections (abfd, sec, xxx)
1222 bfd *abfd;
1223 asection *sec;
1224 PTR xxx;
1225 {
1226 char *name;
1227 asection *strsec;
1228 char *p;
1229 int strsz, nsyms;
1230
1231 if (strncmp (".stab", sec->name, 5))
1232 return;
1233 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1234 return;
1235
1236 name = (char *) alloca (strlen (sec->name) + 4);
1237 strcpy (name, sec->name);
1238 strcat (name, "str");
1239 strsec = bfd_get_section_by_name (abfd, name);
1240 if (strsec)
1241 strsz = bfd_section_size (abfd, strsec);
1242 else
1243 strsz = 0;
1244 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1245
1246 p = seg_info (sec)->stabu.p;
1247 assert (p != 0);
1248
1249 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1250 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1251 }
1252
1253 #ifdef NEED_ECOFF_DEBUG
1254
1255 /* This function is called by the ECOFF code. It is supposed to
1256 record the external symbol information so that the backend can
1257 write it out correctly. The ELF backend doesn't actually handle
1258 this at the moment, so we do it ourselves. We save the information
1259 in the symbol. */
1260
1261 void
1262 elf_ecoff_set_ext (sym, ext)
1263 symbolS *sym;
1264 struct ecoff_extr *ext;
1265 {
1266 sym->bsym->udata.p = (PTR) ext;
1267 }
1268
1269 /* This function is called by bfd_ecoff_debug_externals. It is
1270 supposed to *EXT to the external symbol information, and return
1271 whether the symbol should be used at all. */
1272
1273 static boolean
1274 elf_get_extr (sym, ext)
1275 asymbol *sym;
1276 EXTR *ext;
1277 {
1278 if (sym->udata.p == NULL)
1279 return false;
1280 *ext = *(EXTR *) sym->udata.p;
1281 return true;
1282 }
1283
1284 /* This function is called by bfd_ecoff_debug_externals. It has
1285 nothing to do for ELF. */
1286
1287 /*ARGSUSED*/
1288 static void
1289 elf_set_index (sym, indx)
1290 asymbol *sym;
1291 bfd_size_type indx;
1292 {
1293 }
1294
1295 #endif /* NEED_ECOFF_DEBUG */
1296
1297 void
1298 elf_frob_symbol (symp, puntp)
1299 symbolS *symp;
1300 int *puntp;
1301 {
1302 #ifdef NEED_ECOFF_DEBUG
1303 if (ECOFF_DEBUGGING)
1304 ecoff_frob_symbol (symp);
1305 #endif
1306
1307 if (symp->sy_obj.size != NULL)
1308 {
1309 switch (symp->sy_obj.size->X_op)
1310 {
1311 case O_subtract:
1312 S_SET_SIZE (symp,
1313 (S_GET_VALUE (symp->sy_obj.size->X_add_symbol)
1314 + symp->sy_obj.size->X_add_number
1315 - S_GET_VALUE (symp->sy_obj.size->X_op_symbol)));
1316 break;
1317 case O_constant:
1318 S_SET_SIZE (symp,
1319 (S_GET_VALUE (symp->sy_obj.size->X_add_symbol)
1320 + symp->sy_obj.size->X_add_number));
1321 break;
1322 default:
1323 as_bad (".size expression too complicated to fix up");
1324 break;
1325 }
1326 free (symp->sy_obj.size);
1327 symp->sy_obj.size = NULL;
1328 }
1329
1330 if (symp->sy_obj.versioned_name != NULL)
1331 {
1332 /* This symbol was given a new name with the .symver directive.
1333
1334 If this is an external reference, just rename the symbol to
1335 include the version string. This will make the relocs be
1336 against the correct versioned symbol.
1337
1338 If this is a definition, add an alias. FIXME: Using an alias
1339 will permit the debugging information to refer to the right
1340 symbol. However, it's not clear whether it is the best
1341 approach. */
1342
1343 if (! S_IS_DEFINED (symp))
1344 {
1345 char *p;
1346
1347 /* Verify that the name isn't using the @@ syntax--this is
1348 reserved for definitions of the default version to link
1349 against. */
1350 p = strchr (symp->sy_obj.versioned_name, ELF_VER_CHR);
1351 know (p != NULL);
1352 if (p[1] == ELF_VER_CHR)
1353 {
1354 as_bad ("invalid attempt to declare external version name as default in symbol `%s'",
1355 symp->sy_obj.versioned_name);
1356 *puntp = true;
1357 }
1358 S_SET_NAME (symp, symp->sy_obj.versioned_name);
1359 }
1360 else
1361 {
1362 symbolS *symp2;
1363
1364 /* FIXME: Creating a new symbol here is risky. We're in the
1365 final loop over the symbol table. We can get away with
1366 it only because the symbol goes to the end of the list,
1367 where the loop will still see it. It would probably be
1368 better to do this in obj_frob_file_before_adjust. */
1369
1370 symp2 = symbol_find_or_make (symp->sy_obj.versioned_name);
1371
1372 /* Now we act as though we saw symp2 = sym. */
1373
1374 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1375
1376 /* Subtracting out the frag address here is a hack because
1377 we are in the middle of the final loop. */
1378 S_SET_VALUE (symp2, S_GET_VALUE (symp) - symp->sy_frag->fr_address);
1379
1380 symp2->sy_frag = symp->sy_frag;
1381
1382 /* This will copy over the size information. */
1383 copy_symbol_attributes (symp2, symp);
1384
1385 if (S_IS_WEAK (symp))
1386 S_SET_WEAK (symp2);
1387
1388 if (S_IS_EXTERNAL (symp))
1389 S_SET_EXTERNAL (symp2);
1390 }
1391 }
1392
1393 /* Double check weak symbols. */
1394 if (symp->bsym->flags & BSF_WEAK)
1395 {
1396 if (S_IS_COMMON (symp))
1397 as_bad ("Symbol `%s' can not be both weak and common",
1398 S_GET_NAME (symp));
1399 }
1400
1401 #ifdef TC_MIPS
1402 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1403 any undefined non-function symbol to STT_OBJECT. We try to be
1404 compatible, since newer Irix 5 and 6 linkers care. However, we
1405 only set undefined symbols to be STT_OBJECT if we are on Irix,
1406 because that is the only time gcc will generate the necessary
1407 .global directives to mark functions. */
1408
1409 if (S_IS_COMMON (symp))
1410 symp->bsym->flags |= BSF_OBJECT;
1411
1412 if (strstr (TARGET_OS, "irix") != NULL
1413 && (! S_IS_DEFINED (symp) && ((symp->bsym->flags & BSF_FUNCTION) == 0)))
1414 symp->bsym->flags |= BSF_OBJECT;
1415 #endif
1416
1417 #ifdef TC_PPC
1418 /* Frob the PowerPC, so that the symbol always has object type
1419 if it is not some other type. VxWorks needs this. */
1420 if ((symp->bsym->flags & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1421 && S_IS_DEFINED (symp))
1422 symp->bsym->flags |= BSF_OBJECT;
1423 #endif
1424 }
1425
1426 void
1427 elf_frob_file ()
1428 {
1429 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
1430
1431 #ifdef elf_tc_final_processing
1432 elf_tc_final_processing ();
1433 #endif
1434 }
1435
1436 /* It is required that we let write_relocs have the opportunity to
1437 optimize away fixups before output has begun, since it is possible
1438 to eliminate all fixups for a section and thus we never should
1439 have generated the relocation section. */
1440
1441 void
1442 elf_frob_file_after_relocs ()
1443 {
1444 #ifdef NEED_ECOFF_DEBUG
1445 if (ECOFF_DEBUGGING)
1446 /* Generate the ECOFF debugging information. */
1447 {
1448 const struct ecoff_debug_swap *debug_swap;
1449 struct ecoff_debug_info debug;
1450 char *buf;
1451 asection *sec;
1452
1453 debug_swap
1454 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
1455 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
1456 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
1457
1458 /* Set up the pointers in debug. */
1459 #define SET(ptr, offset, type) \
1460 debug.ptr = (type) (buf + debug.symbolic_header.offset)
1461
1462 SET (line, cbLineOffset, unsigned char *);
1463 SET (external_dnr, cbDnOffset, PTR);
1464 SET (external_pdr, cbPdOffset, PTR);
1465 SET (external_sym, cbSymOffset, PTR);
1466 SET (external_opt, cbOptOffset, PTR);
1467 SET (external_aux, cbAuxOffset, union aux_ext *);
1468 SET (ss, cbSsOffset, char *);
1469 SET (external_fdr, cbFdOffset, PTR);
1470 SET (external_rfd, cbRfdOffset, PTR);
1471 /* ssext and external_ext are set up just below. */
1472
1473 #undef SET
1474
1475 /* Set up the external symbols. */
1476 debug.ssext = debug.ssext_end = NULL;
1477 debug.external_ext = debug.external_ext_end = NULL;
1478 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, true,
1479 elf_get_extr, elf_set_index))
1480 as_fatal ("Failed to set up debugging information: %s",
1481 bfd_errmsg (bfd_get_error ()));
1482
1483 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
1484 assert (sec != NULL);
1485
1486 know (stdoutput->output_has_begun == false);
1487
1488 /* We set the size of the section, call bfd_set_section_contents
1489 to force the ELF backend to allocate a file position, and then
1490 write out the data. FIXME: Is this really the best way to do
1491 this? */
1492 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
1493
1494 if (! bfd_set_section_contents (stdoutput, sec, (PTR) NULL,
1495 (file_ptr) 0, (bfd_size_type) 0))
1496 as_fatal ("Can't start writing .mdebug section: %s",
1497 bfd_errmsg (bfd_get_error ()));
1498
1499 know (stdoutput->output_has_begun == true);
1500 know (sec->filepos != 0);
1501
1502 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
1503 sec->filepos))
1504 as_fatal ("Could not write .mdebug section: %s",
1505 bfd_errmsg (bfd_get_error ()));
1506 }
1507 #endif /* NEED_ECOFF_DEBUG */
1508 }
1509
1510 #ifdef SCO_ELF
1511
1512 /* Heavily plagarized from obj_elf_version. The idea is to emit the
1513 SCO specific identifier in the .notes section to satisfy the SCO
1514 linker.
1515
1516 This looks more complicated than it really is. As opposed to the
1517 "obvious" solution, this should handle the cross dev cases
1518 correctly. (i.e, hosting on a 64 bit big endian processor, but
1519 generating SCO Elf code) Efficiency isn't a concern, as there
1520 should be exactly one of these sections per object module.
1521
1522 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
1523 .note section.
1524
1525 int_32 namesz = 4 ; Name size
1526 int_32 descsz = 12 ; Descriptive information
1527 int_32 type = 1 ;
1528 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
1529 int_32 version = (major ver # << 16) | version of tools ;
1530 int_32 source = (tool_id << 16 ) | 1 ;
1531 int_32 info = 0 ; These are set by the SCO tools, but we
1532 don't know enough about the source
1533 environment to set them. SCO ld currently
1534 ignores them, and recommends we set them
1535 to zero. */
1536
1537 #define SCO_MAJOR_VERSION 0x1
1538 #define SCO_MINOR_VERSION 0x1
1539
1540 void
1541 sco_id ()
1542 {
1543
1544 char *name;
1545 unsigned int c;
1546 char ch;
1547 char *p;
1548 asection *seg = now_seg;
1549 subsegT subseg = now_subseg;
1550 Elf_Internal_Note i_note;
1551 Elf_External_Note e_note;
1552 asection *note_secp = (asection *) NULL;
1553 int i, len;
1554
1555 /* create the .note section */
1556
1557 note_secp = subseg_new (".note", 0);
1558 bfd_set_section_flags (stdoutput,
1559 note_secp,
1560 SEC_HAS_CONTENTS | SEC_READONLY);
1561
1562 /* process the version string */
1563
1564 i_note.namesz = 4;
1565 i_note.descsz = 12; /* 12 descriptive bytes */
1566 i_note.type = NT_VERSION; /* Contains a version string */
1567
1568 p = frag_more (sizeof (i_note.namesz));
1569 md_number_to_chars (p, (valueT) i_note.namesz, 4);
1570
1571 p = frag_more (sizeof (i_note.descsz));
1572 md_number_to_chars (p, (valueT) i_note.descsz, 4);
1573
1574 p = frag_more (sizeof (i_note.type));
1575 md_number_to_chars (p, (valueT) i_note.type, 4);
1576
1577 p = frag_more (4);
1578 strcpy (p, "SCO");
1579
1580 /* Note: this is the version number of the ELF we're representing */
1581 p = frag_more (4);
1582 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
1583
1584 /* Here, we pick a magic number for ourselves (yes, I "registered"
1585 it with SCO. The bottom bit shows that we are compat with the
1586 SCO ABI. */
1587 p = frag_more (4);
1588 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
1589
1590 /* If we knew (or cared) what the source language options were, we'd
1591 fill them in here. SCO has given us permission to ignore these
1592 and just set them to zero. */
1593 p = frag_more (4);
1594 md_number_to_chars (p, 0x0000, 4);
1595
1596 frag_align (2, 0, 0);
1597
1598 /* We probably can't restore the current segment, for there likely
1599 isn't one yet... */
1600 if (seg && subseg)
1601 subseg_set (seg, subseg);
1602
1603 }
1604
1605 #endif /* SCO_ELF */
1606
1607 const struct format_ops elf_format_ops =
1608 {
1609 bfd_target_elf_flavour,
1610 0,
1611 1,
1612 elf_frob_symbol,
1613 elf_frob_file,
1614 elf_frob_file_after_relocs,
1615 elf_s_get_size, elf_s_set_size,
1616 elf_s_get_align, elf_s_set_align,
1617 elf_copy_symbol_attributes,
1618 #ifdef NEED_ECOFF_DEBUG
1619 ecoff_generate_asm_lineno,
1620 ecoff_stab,
1621 #else
1622 0,
1623 0, /* process_stab */
1624 #endif
1625 elf_sec_sym_ok_for_reloc,
1626 elf_pop_insert,
1627 #ifdef NEED_ECOFF_DEBUG
1628 elf_ecoff_set_ext,
1629 #else
1630 0,
1631 #endif
1632 obj_read_begin_hook,
1633 obj_symbol_new_hook,
1634 };