* config/obj-elf.c (special_sections): Work around HP's incorrect usage
[binutils-gdb.git] / gas / config / obj-elf.c
1 /* ELF object file format
2 Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
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.
11
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.
16
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. */
21
22 #define OBJ_HEADER "obj-elf.h"
23 #include "as.h"
24 #include "safe-ctype.h"
25 #include "subsegs.h"
26 #include "obstack.h"
27 #include "struc-symbol.h"
28
29 #ifndef ECOFF_DEBUGGING
30 #define ECOFF_DEBUGGING 0
31 #else
32 #define NEED_ECOFF_DEBUG
33 #endif
34
35 #ifdef NEED_ECOFF_DEBUG
36 #include "ecoff.h"
37 #endif
38
39 #ifdef TC_ALPHA
40 #include "elf/alpha.h"
41 #endif
42
43 #ifdef TC_MIPS
44 #include "elf/mips.h"
45 #endif
46
47 #ifdef TC_PPC
48 #include "elf/ppc.h"
49 #endif
50
51 #ifdef TC_I370
52 #include "elf/i370.h"
53 #endif
54
55 static bfd_vma elf_s_get_size PARAMS ((symbolS *));
56 static void elf_s_set_size PARAMS ((symbolS *, bfd_vma));
57 static bfd_vma elf_s_get_align PARAMS ((symbolS *));
58 static void elf_s_set_align PARAMS ((symbolS *, bfd_vma));
59 static void elf_s_set_other PARAMS ((symbolS *, int));
60 static int elf_sec_sym_ok_for_reloc PARAMS ((asection *));
61 static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));
62 static void build_group_lists PARAMS ((bfd *, asection *, PTR));
63 static int elf_separate_stab_sections PARAMS ((void));
64 static void elf_init_stab_section PARAMS ((segT));
65 static symbolS *elf_common PARAMS ((int));
66
67 #ifdef NEED_ECOFF_DEBUG
68 static bfd_boolean elf_get_extr PARAMS ((asymbol *, EXTR *));
69 static void elf_set_index PARAMS ((asymbol *, bfd_size_type));
70 #endif
71
72 static void obj_elf_line PARAMS ((int));
73 void obj_elf_version PARAMS ((int));
74 static void obj_elf_size PARAMS ((int));
75 static void obj_elf_type PARAMS ((int));
76 static void obj_elf_ident PARAMS ((int));
77 static void obj_elf_weak PARAMS ((int));
78 static void obj_elf_local PARAMS ((int));
79 static void obj_elf_visibility PARAMS ((int));
80 static int obj_elf_parse_section_letters PARAMS ((char *, size_t));
81 static int obj_elf_section_word PARAMS ((char *, size_t));
82 static char *obj_elf_section_name PARAMS ((void));
83 static int obj_elf_section_type PARAMS ((char *, size_t));
84 static void obj_elf_symver PARAMS ((int));
85 static void obj_elf_subsection PARAMS ((int));
86 static void obj_elf_popsection PARAMS ((int));
87 static void obj_elf_tls_common PARAMS ((int));
88
89 static const pseudo_typeS elf_pseudo_table[] =
90 {
91 {"comm", obj_elf_common, 0},
92 {"common", obj_elf_common, 1},
93 {"ident", obj_elf_ident, 0},
94 {"local", obj_elf_local, 0},
95 {"previous", obj_elf_previous, 0},
96 {"section", obj_elf_section, 0},
97 {"section.s", obj_elf_section, 0},
98 {"sect", obj_elf_section, 0},
99 {"sect.s", obj_elf_section, 0},
100 {"pushsection", obj_elf_section, 1},
101 {"popsection", obj_elf_popsection, 0},
102 {"size", obj_elf_size, 0},
103 {"type", obj_elf_type, 0},
104 {"version", obj_elf_version, 0},
105 {"weak", obj_elf_weak, 0},
106
107 /* These define symbol visibility. */
108 {"internal", obj_elf_visibility, STV_INTERNAL},
109 {"hidden", obj_elf_visibility, STV_HIDDEN},
110 {"protected", obj_elf_visibility, STV_PROTECTED},
111
112 /* These are used for stabs-in-elf configurations. */
113 {"line", obj_elf_line, 0},
114
115 /* This is a GNU extension to handle symbol versions. */
116 {"symver", obj_elf_symver, 0},
117
118 /* A GNU extension to change subsection only. */
119 {"subsection", obj_elf_subsection, 0},
120
121 /* These are GNU extensions to aid in garbage collecting C++ vtables. */
122 {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit, 0},
123 {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry, 0},
124
125 /* These are used for dwarf. */
126 {"2byte", cons, 2},
127 {"4byte", cons, 4},
128 {"8byte", cons, 8},
129
130 /* We need to trap the section changing calls to handle .previous. */
131 {"data", obj_elf_data, 0},
132 {"text", obj_elf_text, 0},
133
134 {"tls_common", obj_elf_tls_common, 0},
135
136 /* End sentinel. */
137 {NULL, NULL, 0},
138 };
139
140 static const pseudo_typeS ecoff_debug_pseudo_table[] =
141 {
142 #ifdef NEED_ECOFF_DEBUG
143 /* COFF style debugging information for ECOFF. .ln is not used; .loc
144 is used instead. */
145 { "def", ecoff_directive_def, 0 },
146 { "dim", ecoff_directive_dim, 0 },
147 { "endef", ecoff_directive_endef, 0 },
148 { "file", ecoff_directive_file, 0 },
149 { "scl", ecoff_directive_scl, 0 },
150 { "tag", ecoff_directive_tag, 0 },
151 { "val", ecoff_directive_val, 0 },
152
153 /* COFF debugging requires pseudo-ops .size and .type, but ELF
154 already has meanings for those. We use .esize and .etype
155 instead. These are only generated by gcc anyhow. */
156 { "esize", ecoff_directive_size, 0 },
157 { "etype", ecoff_directive_type, 0 },
158
159 /* ECOFF specific debugging information. */
160 { "begin", ecoff_directive_begin, 0 },
161 { "bend", ecoff_directive_bend, 0 },
162 { "end", ecoff_directive_end, 0 },
163 { "ent", ecoff_directive_ent, 0 },
164 { "fmask", ecoff_directive_fmask, 0 },
165 { "frame", ecoff_directive_frame, 0 },
166 { "loc", ecoff_directive_loc, 0 },
167 { "mask", ecoff_directive_mask, 0 },
168
169 /* Other ECOFF directives. */
170 { "extern", ecoff_directive_extern, 0 },
171
172 /* These are used on Irix. I don't know how to implement them. */
173 { "alias", s_ignore, 0 },
174 { "bgnb", s_ignore, 0 },
175 { "endb", s_ignore, 0 },
176 { "lab", s_ignore, 0 },
177 { "noalias", s_ignore, 0 },
178 { "verstamp", s_ignore, 0 },
179 { "vreg", s_ignore, 0 },
180 #endif
181
182 {NULL, NULL, 0} /* end sentinel */
183 };
184
185 #undef NO_RELOC
186 #include "aout/aout64.h"
187
188 /* This is called when the assembler starts. */
189
190 void
191 elf_begin ()
192 {
193 /* Add symbols for the known sections to the symbol table. */
194 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
195 TEXT_SECTION_NAME)));
196 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
197 DATA_SECTION_NAME)));
198 symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,
199 BSS_SECTION_NAME)));
200 }
201
202 void
203 elf_pop_insert ()
204 {
205 pop_insert (elf_pseudo_table);
206 if (ECOFF_DEBUGGING)
207 pop_insert (ecoff_debug_pseudo_table);
208 }
209
210 static bfd_vma
211 elf_s_get_size (sym)
212 symbolS *sym;
213 {
214 return S_GET_SIZE (sym);
215 }
216
217 static void
218 elf_s_set_size (sym, sz)
219 symbolS *sym;
220 bfd_vma sz;
221 {
222 S_SET_SIZE (sym, sz);
223 }
224
225 static bfd_vma
226 elf_s_get_align (sym)
227 symbolS *sym;
228 {
229 return S_GET_ALIGN (sym);
230 }
231
232 static void
233 elf_s_set_align (sym, align)
234 symbolS *sym;
235 bfd_vma align;
236 {
237 S_SET_ALIGN (sym, align);
238 }
239
240 int
241 elf_s_get_other (sym)
242 symbolS *sym;
243 {
244 return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;
245 }
246
247 static void
248 elf_s_set_other (sym, other)
249 symbolS *sym;
250 int other;
251 {
252 S_SET_OTHER (sym, other);
253 }
254
255 static int
256 elf_sec_sym_ok_for_reloc (sec)
257 asection *sec;
258 {
259 return obj_sec_sym_ok_for_reloc (sec);
260 }
261
262 void
263 elf_file_symbol (s)
264 const char *s;
265 {
266 symbolS *sym;
267
268 sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);
269 symbol_set_frag (sym, &zero_address_frag);
270 symbol_get_bfdsym (sym)->flags |= BSF_FILE;
271
272 if (symbol_rootP != sym)
273 {
274 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
275 symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);
276 #ifdef DEBUG
277 verify_symbol_chain (symbol_rootP, symbol_lastP);
278 #endif
279 }
280
281 #ifdef NEED_ECOFF_DEBUG
282 ecoff_new_file (s);
283 #endif
284 }
285
286 static symbolS *
287 elf_common (is_common)
288 int is_common;
289 {
290 char *name;
291 char c;
292 char *p;
293 int temp, size;
294 symbolS *symbolP;
295 int have_align;
296
297 if (flag_mri && is_common)
298 {
299 s_mri_common (0);
300 return NULL;
301 }
302
303 name = input_line_pointer;
304 c = get_symbol_end ();
305 /* just after name is now '\0' */
306 p = input_line_pointer;
307 *p = c;
308 SKIP_WHITESPACE ();
309 if (*input_line_pointer != ',')
310 {
311 as_bad (_("expected comma after symbol-name"));
312 ignore_rest_of_line ();
313 return NULL;
314 }
315 input_line_pointer++; /* skip ',' */
316 if ((temp = get_absolute_expression ()) < 0)
317 {
318 as_bad (_(".COMMon length (%d.) <0! Ignored."), temp);
319 ignore_rest_of_line ();
320 return NULL;
321 }
322 size = temp;
323 *p = 0;
324 symbolP = symbol_find_or_make (name);
325 *p = c;
326 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
327 {
328 as_bad (_("symbol `%s' is already defined"), S_GET_NAME (symbolP));
329 ignore_rest_of_line ();
330 return NULL;
331 }
332 if (S_GET_VALUE (symbolP) != 0)
333 {
334 if (S_GET_VALUE (symbolP) != (valueT) size)
335 {
336 as_warn (_("length of .comm \"%s\" is already %ld; not changed to %d"),
337 S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
338 }
339 }
340 know (symbolP->sy_frag == &zero_address_frag);
341 if (*input_line_pointer != ',')
342 have_align = 0;
343 else
344 {
345 have_align = 1;
346 input_line_pointer++;
347 SKIP_WHITESPACE ();
348 }
349 if (! have_align || *input_line_pointer != '"')
350 {
351 if (! have_align)
352 temp = 0;
353 else
354 {
355 temp = get_absolute_expression ();
356 if (temp < 0)
357 {
358 temp = 0;
359 as_warn (_("common alignment negative; 0 assumed"));
360 }
361 }
362 if (symbol_get_obj (symbolP)->local)
363 {
364 segT old_sec;
365 int old_subsec;
366 char *pfrag;
367 int align;
368
369 /* allocate_bss: */
370 old_sec = now_seg;
371 old_subsec = now_subseg;
372 if (temp)
373 {
374 /* convert to a power of 2 alignment */
375 for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);
376 if (temp != 1)
377 {
378 as_bad (_("common alignment not a power of 2"));
379 ignore_rest_of_line ();
380 return NULL;
381 }
382 }
383 else
384 align = 0;
385 record_alignment (bss_section, align);
386 subseg_set (bss_section, 0);
387 if (align)
388 frag_align (align, 0, 0);
389 if (S_GET_SEGMENT (symbolP) == bss_section)
390 symbol_get_frag (symbolP)->fr_symbol = 0;
391 symbol_set_frag (symbolP, frag_now);
392 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,
393 (offsetT) size, (char *) 0);
394 *pfrag = 0;
395 S_SET_SIZE (symbolP, size);
396 S_SET_SEGMENT (symbolP, bss_section);
397 S_CLEAR_EXTERNAL (symbolP);
398 subseg_set (old_sec, old_subsec);
399 }
400 else
401 {
402 allocate_common:
403 S_SET_VALUE (symbolP, (valueT) size);
404 S_SET_ALIGN (symbolP, temp);
405 S_SET_EXTERNAL (symbolP);
406 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
407 }
408 }
409 else
410 {
411 input_line_pointer++;
412 /* @@ Some use the dot, some don't. Can we get some consistency?? */
413 if (*input_line_pointer == '.')
414 input_line_pointer++;
415 /* @@ Some say data, some say bss. */
416 if (strncmp (input_line_pointer, "bss\"", 4)
417 && strncmp (input_line_pointer, "data\"", 5))
418 {
419 while (*--input_line_pointer != '"')
420 ;
421 input_line_pointer--;
422 goto bad_common_segment;
423 }
424 while (*input_line_pointer++ != '"')
425 ;
426 goto allocate_common;
427 }
428
429 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
430
431 demand_empty_rest_of_line ();
432 return symbolP;
433
434 {
435 bad_common_segment:
436 p = input_line_pointer;
437 while (*p && *p != '\n')
438 p++;
439 c = *p;
440 *p = '\0';
441 as_bad (_("bad .common segment %s"), input_line_pointer + 1);
442 *p = c;
443 input_line_pointer = p;
444 ignore_rest_of_line ();
445 return NULL;
446 }
447 }
448
449 void
450 obj_elf_common (is_common)
451 int is_common;
452 {
453 elf_common (is_common);
454 }
455
456 static void
457 obj_elf_tls_common (ignore)
458 int ignore ATTRIBUTE_UNUSED;
459 {
460 symbolS *symbolP = elf_common (0);
461
462 if (symbolP)
463 symbol_get_bfdsym (symbolP)->flags |= BSF_THREAD_LOCAL;
464 }
465
466 static void
467 obj_elf_local (ignore)
468 int ignore ATTRIBUTE_UNUSED;
469 {
470 char *name;
471 int c;
472 symbolS *symbolP;
473
474 do
475 {
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_CLEAR_EXTERNAL (symbolP);
482 symbol_get_obj (symbolP)->local = 1;
483 if (c == ',')
484 {
485 input_line_pointer++;
486 SKIP_WHITESPACE ();
487 if (*input_line_pointer == '\n')
488 c = '\n';
489 }
490 }
491 while (c == ',');
492 demand_empty_rest_of_line ();
493 }
494
495 static void
496 obj_elf_weak (ignore)
497 int ignore ATTRIBUTE_UNUSED;
498 {
499 char *name;
500 int c;
501 symbolS *symbolP;
502
503 do
504 {
505 name = input_line_pointer;
506 c = get_symbol_end ();
507 symbolP = symbol_find_or_make (name);
508 *input_line_pointer = c;
509 SKIP_WHITESPACE ();
510 S_SET_WEAK (symbolP);
511 symbol_get_obj (symbolP)->local = 1;
512 if (c == ',')
513 {
514 input_line_pointer++;
515 SKIP_WHITESPACE ();
516 if (*input_line_pointer == '\n')
517 c = '\n';
518 }
519 }
520 while (c == ',');
521 demand_empty_rest_of_line ();
522 }
523
524 static void
525 obj_elf_visibility (visibility)
526 int visibility;
527 {
528 char *name;
529 int c;
530 symbolS *symbolP;
531 asymbol *bfdsym;
532 elf_symbol_type *elfsym;
533
534 do
535 {
536 name = input_line_pointer;
537 c = get_symbol_end ();
538 symbolP = symbol_find_or_make (name);
539 *input_line_pointer = c;
540
541 SKIP_WHITESPACE ();
542
543 bfdsym = symbol_get_bfdsym (symbolP);
544 elfsym = elf_symbol_from (bfd_asymbol_bfd (bfdsym), bfdsym);
545
546 assert (elfsym);
547
548 elfsym->internal_elf_sym.st_other &= ~3;
549 elfsym->internal_elf_sym.st_other |= visibility;
550
551 if (c == ',')
552 {
553 input_line_pointer ++;
554
555 SKIP_WHITESPACE ();
556
557 if (*input_line_pointer == '\n')
558 c = '\n';
559 }
560 }
561 while (c == ',');
562
563 demand_empty_rest_of_line ();
564 }
565
566 static segT previous_section;
567 static int previous_subsection;
568
569 struct section_stack
570 {
571 struct section_stack *next;
572 segT seg, prev_seg;
573 int subseg, prev_subseg;
574 };
575
576 static struct section_stack *section_stack;
577
578 /* Handle the .section pseudo-op. This code supports two different
579 syntaxes.
580
581 The first is found on Solaris, and looks like
582 .section ".sec1",#alloc,#execinstr,#write
583 Here the names after '#' are the SHF_* flags to turn on for the
584 section. I'm not sure how it determines the SHT_* type (BFD
585 doesn't really give us control over the type, anyhow).
586
587 The second format is found on UnixWare, and probably most SVR4
588 machines, and looks like
589 .section .sec1,"a",@progbits
590 The quoted string may contain any combination of a, w, x, and
591 represents the SHF_* flags to turn on for the section. The string
592 beginning with '@' can be progbits or nobits. There should be
593 other possibilities, but I don't know what they are. In any case,
594 BFD doesn't really let us set the section type. */
595
596 /* Certain named sections have particular defined types, listed on p.
597 4-19 of the ABI. */
598 struct special_section
599 {
600 const char *name;
601 int type;
602 int attributes;
603 };
604
605 static struct special_section const special_sections[] =
606 {
607 { ".bss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
608 { ".comment", SHT_PROGBITS, 0 },
609 { ".data", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
610 { ".data1", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
611 { ".debug", SHT_PROGBITS, 0 },
612 #if defined (TC_HPPA) && !defined (TE_LINUX) && TARGET_ARCH_SIZE == 64
613 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
614 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
615 #else
616 { ".fini", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
617 { ".init", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
618 #endif
619 { ".line", SHT_PROGBITS, 0 },
620 { ".note", SHT_NOTE, 0 },
621 { ".rodata", SHT_PROGBITS, SHF_ALLOC },
622 { ".rodata1", SHT_PROGBITS, SHF_ALLOC },
623 { ".tbss", SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_TLS },
624 { ".tdata", SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_TLS },
625 { ".text", SHT_PROGBITS, SHF_ALLOC + SHF_EXECINSTR },
626 { ".init_array",SHT_INIT_ARRAY, SHF_ALLOC + SHF_WRITE },
627 { ".fini_array",SHT_FINI_ARRAY, SHF_ALLOC + SHF_WRITE },
628 { ".preinit_array",SHT_PREINIT_ARRAY, SHF_ALLOC + SHF_WRITE },
629
630 #ifdef ELF_TC_SPECIAL_SECTIONS
631 ELF_TC_SPECIAL_SECTIONS
632 #endif
633
634 #if 0
635 /* The following section names are special, but they can not
636 reasonably appear in assembler code. Some of the attributes are
637 processor dependent. */
638 { ".dynamic", SHT_DYNAMIC, SHF_ALLOC /* + SHF_WRITE */ },
639 { ".dynstr", SHT_STRTAB, SHF_ALLOC },
640 { ".dynsym", SHT_DYNSYM, SHF_ALLOC },
641 { ".got", SHT_PROGBITS, 0 },
642 { ".hash", SHT_HASH, SHF_ALLOC },
643 { ".interp", SHT_PROGBITS, /* SHF_ALLOC */ },
644 { ".plt", SHT_PROGBITS, 0 },
645 { ".shstrtab",SHT_STRTAB, 0 },
646 { ".strtab", SHT_STRTAB, /* SHF_ALLOC */ },
647 { ".symtab", SHT_SYMTAB, /* SHF_ALLOC */ },
648 #endif
649
650 { NULL, 0, 0 }
651 };
652
653 void
654 obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push)
655 const char *name;
656 int type;
657 int attr;
658 int entsize;
659 const char *group_name;
660 int linkonce;
661 int push;
662 {
663 asection *old_sec;
664 segT sec;
665 flagword flags;
666 int i;
667
668 #ifdef md_flush_pending_output
669 md_flush_pending_output ();
670 #endif
671
672 /* Switch to the section, creating it if necessary. */
673 if (push)
674 {
675 struct section_stack *elt;
676 elt = xmalloc (sizeof (struct section_stack));
677 elt->next = section_stack;
678 elt->seg = now_seg;
679 elt->prev_seg = previous_section;
680 elt->subseg = now_subseg;
681 elt->prev_subseg = previous_subsection;
682 section_stack = elt;
683 }
684 previous_section = now_seg;
685 previous_subsection = now_subseg;
686
687 old_sec = bfd_get_section_by_name (stdoutput, name);
688 sec = subseg_new (name, 0);
689
690 /* See if this is one of the special sections. */
691 for (i = 0; special_sections[i].name != NULL; i++)
692 if (strcmp (name, special_sections[i].name) == 0)
693 {
694 if (type == SHT_NULL)
695 type = special_sections[i].type;
696 else if (type != special_sections[i].type)
697 {
698 if (old_sec == NULL
699 /* FIXME: gcc, as of 2002-10-22, will emit
700
701 .section .init_array,"aw",@progbits
702
703 for __attribute__ ((section (".init_array"))).
704 "@progbits" is incorrect. */
705 && special_sections[i].type != SHT_INIT_ARRAY
706 && special_sections[i].type != SHT_FINI_ARRAY
707 && special_sections[i].type != SHT_PREINIT_ARRAY)
708 {
709 as_warn (_("setting incorrect section type for %s"), name);
710 }
711 else
712 {
713 as_warn (_("ignoring incorrect section type for %s"), name);
714 type = special_sections[i].type;
715 }
716 }
717 if ((attr &~ special_sections[i].attributes) != 0
718 && old_sec == NULL)
719 {
720 /* As a GNU extension, we permit a .note section to be
721 allocatable. If the linker sees an allocateable .note
722 section, it will create a PT_NOTE segment in the output
723 file. */
724 if (strcmp (name, ".note") != 0
725 || attr != SHF_ALLOC)
726 as_warn (_("setting incorrect section attributes for %s"),
727 name);
728 }
729 attr |= special_sections[i].attributes;
730 break;
731 }
732
733 /* Convert ELF type and flags to BFD flags. */
734 flags = (SEC_RELOC
735 | ((attr & SHF_WRITE) ? 0 : SEC_READONLY)
736 | ((attr & SHF_ALLOC) ? SEC_ALLOC : 0)
737 | (((attr & SHF_ALLOC) && type != SHT_NOBITS) ? SEC_LOAD : 0)
738 | ((attr & SHF_EXECINSTR) ? SEC_CODE : 0)
739 | ((attr & SHF_MERGE) ? SEC_MERGE : 0)
740 | ((attr & SHF_STRINGS) ? SEC_STRINGS : 0)
741 | ((attr & SHF_TLS) ? SEC_THREAD_LOCAL : 0));
742 #ifdef md_elf_section_flags
743 flags = md_elf_section_flags (flags, attr, type);
744 #endif
745
746 if (old_sec == NULL)
747 {
748 symbolS *secsym;
749
750 /* Prevent SEC_HAS_CONTENTS from being inadvertently set. */
751 if (type == SHT_NOBITS)
752 seg_info (sec)->bss = 1;
753
754 bfd_set_section_flags (stdoutput, sec, flags);
755 if (flags & SEC_MERGE)
756 sec->entsize = entsize;
757 elf_group_name (sec) = group_name;
758 elf_linkonce_p (sec) = linkonce;
759
760 /* Add a symbol for this section to the symbol table. */
761 secsym = symbol_find (name);
762 if (secsym != NULL)
763 symbol_set_bfdsym (secsym, sec->symbol);
764 else
765 symbol_table_insert (section_symbol (sec));
766 }
767 else if (attr != 0)
768 {
769 /* If section attributes are specified the second time we see a
770 particular section, then check that they are the same as we
771 saw the first time. */
772 if (((old_sec->flags ^ flags)
773 & (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
774 | SEC_EXCLUDE | SEC_SORT_ENTRIES | SEC_MERGE | SEC_STRINGS
775 | SEC_THREAD_LOCAL))
776 || linkonce != elf_linkonce_p (sec))
777 as_warn (_("ignoring changed section attributes for %s"), name);
778 if ((flags & SEC_MERGE) && old_sec->entsize != (unsigned) entsize)
779 as_warn (_("ignoring changed section entity size for %s"), name);
780 if ((attr & SHF_GROUP) != 0
781 && strcmp (elf_group_name (old_sec), group_name) != 0)
782 as_warn (_("ignoring new section group for %s"), name);
783 }
784
785 #ifdef md_elf_section_change_hook
786 md_elf_section_change_hook ();
787 #endif
788 }
789
790 static int
791 obj_elf_parse_section_letters (str, len)
792 char *str;
793 size_t len;
794 {
795 int attr = 0;
796
797 while (len > 0)
798 {
799 switch (*str)
800 {
801 case 'a':
802 attr |= SHF_ALLOC;
803 break;
804 case 'w':
805 attr |= SHF_WRITE;
806 break;
807 case 'x':
808 attr |= SHF_EXECINSTR;
809 break;
810 case 'M':
811 attr |= SHF_MERGE;
812 break;
813 case 'S':
814 attr |= SHF_STRINGS;
815 break;
816 case 'G':
817 attr |= SHF_GROUP;
818 break;
819 case 'T':
820 attr |= SHF_TLS;
821 break;
822 /* Compatibility. */
823 case 'm':
824 if (*(str - 1) == 'a')
825 {
826 attr |= SHF_MERGE;
827 if (len > 1 && str[1] == 's')
828 {
829 attr |= SHF_STRINGS;
830 str++, len--;
831 }
832 break;
833 }
834 default:
835 {
836 char *bad_msg = _("unrecognized .section attribute: want a,w,x,M,S,G,T");
837 #ifdef md_elf_section_letter
838 int md_attr = md_elf_section_letter (*str, &bad_msg);
839 if (md_attr >= 0)
840 attr |= md_attr;
841 else
842 #endif
843 {
844 as_warn ("%s", bad_msg);
845 attr = -1;
846 }
847 }
848 break;
849 }
850 str++, len--;
851 }
852
853 return attr;
854 }
855
856 static int
857 obj_elf_section_word (str, len)
858 char *str;
859 size_t len;
860 {
861 if (len == 5 && strncmp (str, "write", 5) == 0)
862 return SHF_WRITE;
863 if (len == 5 && strncmp (str, "alloc", 5) == 0)
864 return SHF_ALLOC;
865 if (len == 9 && strncmp (str, "execinstr", 9) == 0)
866 return SHF_EXECINSTR;
867
868 #ifdef md_elf_section_word
869 {
870 int md_attr = md_elf_section_word (str, len);
871 if (md_attr >= 0)
872 return md_attr;
873 }
874 #endif
875
876 as_warn (_("unrecognized section attribute"));
877 return 0;
878 }
879
880 static int
881 obj_elf_section_type (str, len)
882 char *str;
883 size_t len;
884 {
885 if (len == 8 && strncmp (str, "progbits", 8) == 0)
886 return SHT_PROGBITS;
887 if (len == 6 && strncmp (str, "nobits", 6) == 0)
888 return SHT_NOBITS;
889
890 #ifdef md_elf_section_type
891 {
892 int md_type = md_elf_section_type (str, len);
893 if (md_type >= 0)
894 return md_type;
895 }
896 #endif
897
898 as_warn (_("unrecognized section type"));
899 return 0;
900 }
901
902 /* Get name of section. */
903 static char *
904 obj_elf_section_name ()
905 {
906 char *name;
907
908 SKIP_WHITESPACE ();
909 if (*input_line_pointer == '"')
910 {
911 int dummy;
912
913 name = demand_copy_C_string (&dummy);
914 if (name == NULL)
915 {
916 ignore_rest_of_line ();
917 return NULL;
918 }
919 }
920 else
921 {
922 char *end = input_line_pointer;
923
924 while (0 == strchr ("\n\t,; ", *end))
925 end++;
926 if (end == input_line_pointer)
927 {
928 as_warn (_("missing name"));
929 ignore_rest_of_line ();
930 return NULL;
931 }
932
933 name = xmalloc (end - input_line_pointer + 1);
934 memcpy (name, input_line_pointer, end - input_line_pointer);
935 name[end - input_line_pointer] = '\0';
936 input_line_pointer = end;
937 }
938 SKIP_WHITESPACE ();
939 return name;
940 }
941
942 void
943 obj_elf_section (push)
944 int push;
945 {
946 char *name, *group_name, *beg;
947 int type, attr, dummy;
948 int entsize;
949 int linkonce;
950
951 #ifndef TC_I370
952 if (flag_mri)
953 {
954 char mri_type;
955
956 #ifdef md_flush_pending_output
957 md_flush_pending_output ();
958 #endif
959
960 previous_section = now_seg;
961 previous_subsection = now_subseg;
962
963 s_mri_sect (&mri_type);
964
965 #ifdef md_elf_section_change_hook
966 md_elf_section_change_hook ();
967 #endif
968
969 return;
970 }
971 #endif /* ! defined (TC_I370) */
972
973 name = obj_elf_section_name ();
974 if (name == NULL)
975 return;
976 type = SHT_NULL;
977 attr = 0;
978 group_name = NULL;
979 entsize = 0;
980 linkonce = 0;
981
982 if (*input_line_pointer == ',')
983 {
984 /* Skip the comma. */
985 ++input_line_pointer;
986 SKIP_WHITESPACE ();
987
988 if (*input_line_pointer == '"')
989 {
990 beg = demand_copy_C_string (&dummy);
991 if (beg == NULL)
992 {
993 ignore_rest_of_line ();
994 return;
995 }
996 attr |= obj_elf_parse_section_letters (beg, strlen (beg));
997
998 SKIP_WHITESPACE ();
999 if (*input_line_pointer == ',')
1000 {
1001 char c;
1002 char *save = input_line_pointer;
1003
1004 ++input_line_pointer;
1005 SKIP_WHITESPACE ();
1006 c = *input_line_pointer;
1007 if (c == '"')
1008 {
1009 beg = demand_copy_C_string (&dummy);
1010 if (beg == NULL)
1011 {
1012 ignore_rest_of_line ();
1013 return;
1014 }
1015 type = obj_elf_section_type (beg, strlen (beg));
1016 }
1017 else if (c == '@' || c == '%')
1018 {
1019 beg = ++input_line_pointer;
1020 c = get_symbol_end ();
1021 *input_line_pointer = c;
1022 type = obj_elf_section_type (beg, input_line_pointer - beg);
1023 }
1024 else
1025 input_line_pointer = save;
1026 }
1027
1028 SKIP_WHITESPACE ();
1029 if ((attr & SHF_MERGE) != 0 && *input_line_pointer == ',')
1030 {
1031 ++input_line_pointer;
1032 SKIP_WHITESPACE ();
1033 entsize = get_absolute_expression ();
1034 SKIP_WHITESPACE ();
1035 if (entsize < 0)
1036 {
1037 as_warn (_("invalid merge entity size"));
1038 attr &= ~SHF_MERGE;
1039 entsize = 0;
1040 }
1041 }
1042 else if ((attr & SHF_MERGE) != 0)
1043 {
1044 as_warn (_("entity size for SHF_MERGE not specified"));
1045 attr &= ~SHF_MERGE;
1046 }
1047
1048 if ((attr & SHF_GROUP) != 0 && *input_line_pointer == ',')
1049 {
1050 ++input_line_pointer;
1051 group_name = obj_elf_section_name ();
1052 if (group_name == NULL)
1053 attr &= ~SHF_GROUP;
1054 else if (strncmp (input_line_pointer, ",comdat", 7) == 0)
1055 {
1056 input_line_pointer += 7;
1057 linkonce = 1;
1058 }
1059 else if (strncmp (name, ".gnu.linkonce", 13) == 0)
1060 linkonce = 1;
1061 }
1062 else if ((attr & SHF_GROUP) != 0)
1063 {
1064 as_warn (_("group name for SHF_GROUP not specified"));
1065 attr &= ~SHF_GROUP;
1066 }
1067 }
1068 else
1069 {
1070 do
1071 {
1072 char c;
1073
1074 SKIP_WHITESPACE ();
1075 if (*input_line_pointer != '#')
1076 {
1077 as_warn (_("character following name is not '#'"));
1078 ignore_rest_of_line ();
1079 return;
1080 }
1081 beg = ++input_line_pointer;
1082 c = get_symbol_end ();
1083 *input_line_pointer = c;
1084
1085 attr |= obj_elf_section_word (beg, input_line_pointer - beg);
1086
1087 SKIP_WHITESPACE ();
1088 }
1089 while (*input_line_pointer++ == ',');
1090 --input_line_pointer;
1091 }
1092 }
1093
1094 demand_empty_rest_of_line ();
1095
1096 obj_elf_change_section (name, type, attr, entsize, group_name, linkonce, push);
1097 }
1098
1099 /* Change to the .data section. */
1100
1101 void
1102 obj_elf_data (i)
1103 int i;
1104 {
1105 #ifdef md_flush_pending_output
1106 md_flush_pending_output ();
1107 #endif
1108
1109 previous_section = now_seg;
1110 previous_subsection = now_subseg;
1111 s_data (i);
1112
1113 #ifdef md_elf_section_change_hook
1114 md_elf_section_change_hook ();
1115 #endif
1116 }
1117
1118 /* Change to the .text section. */
1119
1120 void
1121 obj_elf_text (i)
1122 int i;
1123 {
1124 #ifdef md_flush_pending_output
1125 md_flush_pending_output ();
1126 #endif
1127
1128 previous_section = now_seg;
1129 previous_subsection = now_subseg;
1130 s_text (i);
1131
1132 #ifdef md_elf_section_change_hook
1133 md_elf_section_change_hook ();
1134 #endif
1135 }
1136
1137 static void
1138 obj_elf_subsection (ignore)
1139 int ignore ATTRIBUTE_UNUSED;
1140 {
1141 register int temp;
1142
1143 #ifdef md_flush_pending_output
1144 md_flush_pending_output ();
1145 #endif
1146
1147 previous_section = now_seg;
1148 previous_subsection = now_subseg;
1149
1150 temp = get_absolute_expression ();
1151 subseg_set (now_seg, (subsegT) temp);
1152 demand_empty_rest_of_line ();
1153
1154 #ifdef md_elf_section_change_hook
1155 md_elf_section_change_hook ();
1156 #endif
1157 }
1158
1159 /* This can be called from the processor backends if they change
1160 sections. */
1161
1162 void
1163 obj_elf_section_change_hook ()
1164 {
1165 previous_section = now_seg;
1166 previous_subsection = now_subseg;
1167 }
1168
1169 void
1170 obj_elf_previous (ignore)
1171 int ignore ATTRIBUTE_UNUSED;
1172 {
1173 segT new_section;
1174 int new_subsection;
1175
1176 if (previous_section == 0)
1177 {
1178 as_warn (_(".previous without corresponding .section; ignored"));
1179 return;
1180 }
1181
1182 #ifdef md_flush_pending_output
1183 md_flush_pending_output ();
1184 #endif
1185
1186 new_section = previous_section;
1187 new_subsection = previous_subsection;
1188 previous_section = now_seg;
1189 previous_subsection = now_subseg;
1190 subseg_set (new_section, new_subsection);
1191
1192 #ifdef md_elf_section_change_hook
1193 md_elf_section_change_hook ();
1194 #endif
1195 }
1196
1197 static void
1198 obj_elf_popsection (xxx)
1199 int xxx ATTRIBUTE_UNUSED;
1200 {
1201 struct section_stack *top = section_stack;
1202
1203 if (top == NULL)
1204 {
1205 as_warn (_(".popsection without corresponding .pushsection; ignored"));
1206 return;
1207 }
1208
1209 #ifdef md_flush_pending_output
1210 md_flush_pending_output ();
1211 #endif
1212
1213 section_stack = top->next;
1214 previous_section = top->prev_seg;
1215 previous_subsection = top->prev_subseg;
1216 subseg_set (top->seg, top->subseg);
1217 free (top);
1218
1219 #ifdef md_elf_section_change_hook
1220 md_elf_section_change_hook ();
1221 #endif
1222 }
1223
1224 static void
1225 obj_elf_line (ignore)
1226 int ignore ATTRIBUTE_UNUSED;
1227 {
1228 /* Assume delimiter is part of expression. BSD4.2 as fails with
1229 delightful bug, so we are not being incompatible here. */
1230 new_logical_line ((char *) NULL, (int) (get_absolute_expression ()));
1231 demand_empty_rest_of_line ();
1232 }
1233
1234 /* This handles the .symver pseudo-op, which is used to specify a
1235 symbol version. The syntax is ``.symver NAME,SYMVERNAME''.
1236 SYMVERNAME may contain ELF_VER_CHR ('@') characters. This
1237 pseudo-op causes the assembler to emit a symbol named SYMVERNAME
1238 with the same value as the symbol NAME. */
1239
1240 static void
1241 obj_elf_symver (ignore)
1242 int ignore ATTRIBUTE_UNUSED;
1243 {
1244 char *name;
1245 char c;
1246 char old_lexat;
1247 symbolS *sym;
1248
1249 name = input_line_pointer;
1250 c = get_symbol_end ();
1251
1252 sym = symbol_find_or_make (name);
1253
1254 *input_line_pointer = c;
1255
1256 SKIP_WHITESPACE ();
1257 if (*input_line_pointer != ',')
1258 {
1259 as_bad (_("expected comma after name in .symver"));
1260 ignore_rest_of_line ();
1261 return;
1262 }
1263
1264 ++input_line_pointer;
1265 name = input_line_pointer;
1266
1267 /* Temporarily include '@' in symbol names. */
1268 old_lexat = lex_type[(unsigned char) '@'];
1269 lex_type[(unsigned char) '@'] |= LEX_NAME;
1270 c = get_symbol_end ();
1271 lex_type[(unsigned char) '@'] = old_lexat;
1272
1273 if (symbol_get_obj (sym)->versioned_name == NULL)
1274 {
1275 symbol_get_obj (sym)->versioned_name = xstrdup (name);
1276
1277 *input_line_pointer = c;
1278
1279 if (strchr (symbol_get_obj (sym)->versioned_name,
1280 ELF_VER_CHR) == NULL)
1281 {
1282 as_bad (_("missing version name in `%s' for symbol `%s'"),
1283 symbol_get_obj (sym)->versioned_name,
1284 S_GET_NAME (sym));
1285 ignore_rest_of_line ();
1286 return;
1287 }
1288 }
1289 else
1290 {
1291 if (strcmp (symbol_get_obj (sym)->versioned_name, name))
1292 {
1293 as_bad (_("multiple versions [`%s'|`%s'] for symbol `%s'"),
1294 name, symbol_get_obj (sym)->versioned_name,
1295 S_GET_NAME (sym));
1296 ignore_rest_of_line ();
1297 return;
1298 }
1299
1300 *input_line_pointer = c;
1301 }
1302
1303 demand_empty_rest_of_line ();
1304 }
1305
1306 /* This handles the .vtable_inherit pseudo-op, which is used to indicate
1307 to the linker the hierarchy in which a particular table resides. The
1308 syntax is ".vtable_inherit CHILDNAME, PARENTNAME". */
1309
1310 struct fix *
1311 obj_elf_vtable_inherit (ignore)
1312 int ignore ATTRIBUTE_UNUSED;
1313 {
1314 char *cname, *pname;
1315 symbolS *csym, *psym;
1316 char c, bad = 0;
1317
1318 if (*input_line_pointer == '#')
1319 ++input_line_pointer;
1320
1321 cname = input_line_pointer;
1322 c = get_symbol_end ();
1323 csym = symbol_find (cname);
1324
1325 /* GCFIXME: should check that we don't have two .vtable_inherits for
1326 the same child symbol. Also, we can currently only do this if the
1327 child symbol is already exists and is placed in a fragment. */
1328
1329 if (csym == NULL || symbol_get_frag (csym) == NULL)
1330 {
1331 as_bad ("expected `%s' to have already been set for .vtable_inherit",
1332 cname);
1333 bad = 1;
1334 }
1335
1336 *input_line_pointer = c;
1337
1338 SKIP_WHITESPACE ();
1339 if (*input_line_pointer != ',')
1340 {
1341 as_bad ("expected comma after name in .vtable_inherit");
1342 ignore_rest_of_line ();
1343 return NULL;
1344 }
1345
1346 ++input_line_pointer;
1347 SKIP_WHITESPACE ();
1348
1349 if (*input_line_pointer == '#')
1350 ++input_line_pointer;
1351
1352 if (input_line_pointer[0] == '0'
1353 && (input_line_pointer[1] == '\0'
1354 || ISSPACE (input_line_pointer[1])))
1355 {
1356 psym = section_symbol (absolute_section);
1357 ++input_line_pointer;
1358 }
1359 else
1360 {
1361 pname = input_line_pointer;
1362 c = get_symbol_end ();
1363 psym = symbol_find_or_make (pname);
1364 *input_line_pointer = c;
1365 }
1366
1367 demand_empty_rest_of_line ();
1368
1369 if (bad)
1370 return NULL;
1371
1372 assert (symbol_get_value_expression (csym)->X_op == O_constant);
1373 return fix_new (symbol_get_frag (csym),
1374 symbol_get_value_expression (csym)->X_add_number,
1375 0, psym, 0, 0, BFD_RELOC_VTABLE_INHERIT);
1376 }
1377
1378 /* This handles the .vtable_entry pseudo-op, which is used to indicate
1379 to the linker that a vtable slot was used. The syntax is
1380 ".vtable_entry tablename, offset". */
1381
1382 struct fix *
1383 obj_elf_vtable_entry (ignore)
1384 int ignore ATTRIBUTE_UNUSED;
1385 {
1386 char *name;
1387 symbolS *sym;
1388 offsetT offset;
1389 char c;
1390
1391 if (*input_line_pointer == '#')
1392 ++input_line_pointer;
1393
1394 name = input_line_pointer;
1395 c = get_symbol_end ();
1396 sym = symbol_find_or_make (name);
1397 *input_line_pointer = c;
1398
1399 SKIP_WHITESPACE ();
1400 if (*input_line_pointer != ',')
1401 {
1402 as_bad ("expected comma after name in .vtable_entry");
1403 ignore_rest_of_line ();
1404 return NULL;
1405 }
1406
1407 ++input_line_pointer;
1408 if (*input_line_pointer == '#')
1409 ++input_line_pointer;
1410
1411 offset = get_absolute_expression ();
1412
1413 demand_empty_rest_of_line ();
1414
1415 return fix_new (frag_now, frag_now_fix (), 0, sym, offset, 0,
1416 BFD_RELOC_VTABLE_ENTRY);
1417 }
1418
1419 void
1420 elf_obj_read_begin_hook ()
1421 {
1422 #ifdef NEED_ECOFF_DEBUG
1423 if (ECOFF_DEBUGGING)
1424 ecoff_read_begin_hook ();
1425 #endif
1426 }
1427
1428 void
1429 elf_obj_symbol_new_hook (symbolP)
1430 symbolS *symbolP;
1431 {
1432 struct elf_obj_sy *sy_obj;
1433
1434 sy_obj = symbol_get_obj (symbolP);
1435 sy_obj->size = NULL;
1436 sy_obj->versioned_name = NULL;
1437
1438 #ifdef NEED_ECOFF_DEBUG
1439 if (ECOFF_DEBUGGING)
1440 ecoff_symbol_new_hook (symbolP);
1441 #endif
1442 }
1443
1444 /* When setting one symbol equal to another, by default we probably
1445 want them to have the same "size", whatever it means in the current
1446 context. */
1447
1448 void
1449 elf_copy_symbol_attributes (dest, src)
1450 symbolS *dest, *src;
1451 {
1452 struct elf_obj_sy *srcelf = symbol_get_obj (src);
1453 struct elf_obj_sy *destelf = symbol_get_obj (dest);
1454 if (srcelf->size)
1455 {
1456 if (destelf->size == NULL)
1457 destelf->size =
1458 (expressionS *) xmalloc (sizeof (expressionS));
1459 *destelf->size = *srcelf->size;
1460 }
1461 else
1462 {
1463 if (destelf->size != NULL)
1464 free (destelf->size);
1465 destelf->size = NULL;
1466 }
1467 S_SET_SIZE (dest, S_GET_SIZE (src));
1468 /* Don't copy visibility. */
1469 S_SET_OTHER (dest, (ELF_ST_VISIBILITY (S_GET_OTHER (dest))
1470 | (S_GET_OTHER (src) & ~ELF_ST_VISIBILITY (-1))));
1471 }
1472
1473 void
1474 obj_elf_version (ignore)
1475 int ignore ATTRIBUTE_UNUSED;
1476 {
1477 char *name;
1478 unsigned int c;
1479 char *p;
1480 asection *seg = now_seg;
1481 subsegT subseg = now_subseg;
1482 Elf_Internal_Note i_note;
1483 Elf_External_Note e_note;
1484 asection *note_secp = (asection *) NULL;
1485 int len;
1486
1487 SKIP_WHITESPACE ();
1488 if (*input_line_pointer == '\"')
1489 {
1490 ++input_line_pointer; /* -> 1st char of string. */
1491 name = input_line_pointer;
1492
1493 while (is_a_char (c = next_char_of_string ()))
1494 ;
1495 c = *input_line_pointer;
1496 *input_line_pointer = '\0';
1497 *(input_line_pointer - 1) = '\0';
1498 *input_line_pointer = c;
1499
1500 /* create the .note section */
1501
1502 note_secp = subseg_new (".note", 0);
1503 bfd_set_section_flags (stdoutput,
1504 note_secp,
1505 SEC_HAS_CONTENTS | SEC_READONLY);
1506
1507 /* process the version string */
1508
1509 len = strlen (name);
1510
1511 i_note.namesz = ((len + 1) + 3) & ~3; /* round this to word boundary */
1512 i_note.descsz = 0; /* no description */
1513 i_note.type = NT_VERSION;
1514 p = frag_more (sizeof (e_note.namesz));
1515 md_number_to_chars (p, (valueT) i_note.namesz, sizeof (e_note.namesz));
1516 p = frag_more (sizeof (e_note.descsz));
1517 md_number_to_chars (p, (valueT) i_note.descsz, sizeof (e_note.descsz));
1518 p = frag_more (sizeof (e_note.type));
1519 md_number_to_chars (p, (valueT) i_note.type, sizeof (e_note.type));
1520 p = frag_more (len + 1);
1521 strcpy (p, name);
1522
1523 frag_align (2, 0, 0);
1524
1525 subseg_set (seg, subseg);
1526 }
1527 else
1528 {
1529 as_bad (_("expected quoted string"));
1530 }
1531 demand_empty_rest_of_line ();
1532 }
1533
1534 static void
1535 obj_elf_size (ignore)
1536 int ignore ATTRIBUTE_UNUSED;
1537 {
1538 char *name = input_line_pointer;
1539 char c = get_symbol_end ();
1540 char *p;
1541 expressionS exp;
1542 symbolS *sym;
1543
1544 p = input_line_pointer;
1545 *p = c;
1546 SKIP_WHITESPACE ();
1547 if (*input_line_pointer != ',')
1548 {
1549 *p = 0;
1550 as_bad (_("expected comma after name `%s' in .size directive"), name);
1551 *p = c;
1552 ignore_rest_of_line ();
1553 return;
1554 }
1555 input_line_pointer++;
1556 expression (&exp);
1557 if (exp.X_op == O_absent)
1558 {
1559 as_bad (_("missing expression in .size directive"));
1560 exp.X_op = O_constant;
1561 exp.X_add_number = 0;
1562 }
1563 *p = 0;
1564 sym = symbol_find_or_make (name);
1565 *p = c;
1566 if (exp.X_op == O_constant)
1567 {
1568 S_SET_SIZE (sym, exp.X_add_number);
1569 if (symbol_get_obj (sym)->size)
1570 {
1571 xfree (symbol_get_obj (sym)->size);
1572 symbol_get_obj (sym)->size = NULL;
1573 }
1574 }
1575 else
1576 {
1577 symbol_get_obj (sym)->size =
1578 (expressionS *) xmalloc (sizeof (expressionS));
1579 *symbol_get_obj (sym)->size = exp;
1580 }
1581 demand_empty_rest_of_line ();
1582 }
1583
1584 /* Handle the ELF .type pseudo-op. This sets the type of a symbol.
1585 There are five syntaxes:
1586
1587 The first (used on Solaris) is
1588 .type SYM,#function
1589 The second (used on UnixWare) is
1590 .type SYM,@function
1591 The third (reportedly to be used on Irix 6.0) is
1592 .type SYM STT_FUNC
1593 The fourth (used on NetBSD/Arm and Linux/ARM) is
1594 .type SYM,%function
1595 The fifth (used on SVR4/860) is
1596 .type SYM,"function"
1597 */
1598
1599 static void
1600 obj_elf_type (ignore)
1601 int ignore ATTRIBUTE_UNUSED;
1602 {
1603 char *name;
1604 char c;
1605 int type;
1606 const char *typename;
1607 symbolS *sym;
1608 elf_symbol_type *elfsym;
1609
1610 name = input_line_pointer;
1611 c = get_symbol_end ();
1612 sym = symbol_find_or_make (name);
1613 elfsym = (elf_symbol_type *) symbol_get_bfdsym (sym);
1614 *input_line_pointer = c;
1615
1616 SKIP_WHITESPACE ();
1617 if (*input_line_pointer == ',')
1618 ++input_line_pointer;
1619
1620 SKIP_WHITESPACE ();
1621 if ( *input_line_pointer == '#'
1622 || *input_line_pointer == '@'
1623 || *input_line_pointer == '"'
1624 || *input_line_pointer == '%')
1625 ++input_line_pointer;
1626
1627 typename = input_line_pointer;
1628 c = get_symbol_end ();
1629
1630 type = 0;
1631 if (strcmp (typename, "function") == 0
1632 || strcmp (typename, "STT_FUNC") == 0)
1633 type = BSF_FUNCTION;
1634 else if (strcmp (typename, "object") == 0
1635 || strcmp (typename, "STT_OBJECT") == 0)
1636 type = BSF_OBJECT;
1637 #ifdef md_elf_symbol_type
1638 else if ((type = md_elf_symbol_type (typename, sym, elfsym)) != -1)
1639 ;
1640 #endif
1641 else
1642 as_bad (_("unrecognized symbol type \"%s\""), typename);
1643
1644 *input_line_pointer = c;
1645
1646 if (*input_line_pointer == '"')
1647 ++input_line_pointer;
1648
1649 elfsym->symbol.flags |= type;
1650
1651 demand_empty_rest_of_line ();
1652 }
1653
1654 static void
1655 obj_elf_ident (ignore)
1656 int ignore ATTRIBUTE_UNUSED;
1657 {
1658 static segT comment_section;
1659 segT old_section = now_seg;
1660 int old_subsection = now_subseg;
1661
1662 #ifdef md_flush_pending_output
1663 md_flush_pending_output ();
1664 #endif
1665
1666 if (!comment_section)
1667 {
1668 char *p;
1669 comment_section = subseg_new (".comment", 0);
1670 bfd_set_section_flags (stdoutput, comment_section,
1671 SEC_READONLY | SEC_HAS_CONTENTS);
1672 p = frag_more (1);
1673 *p = 0;
1674 }
1675 else
1676 subseg_set (comment_section, 0);
1677 stringer (1);
1678 subseg_set (old_section, old_subsection);
1679 }
1680
1681 #ifdef INIT_STAB_SECTION
1682
1683 /* The first entry in a .stabs section is special. */
1684
1685 void
1686 obj_elf_init_stab_section (seg)
1687 segT seg;
1688 {
1689 char *file;
1690 char *p;
1691 char *stabstr_name;
1692 unsigned int stroff;
1693
1694 /* Force the section to align to a longword boundary. Without this,
1695 UnixWare ar crashes. */
1696 bfd_set_section_alignment (stdoutput, seg, 2);
1697
1698 /* Make space for this first symbol. */
1699 p = frag_more (12);
1700 /* Zero it out. */
1701 memset (p, 0, 12);
1702 as_where (&file, (unsigned int *) NULL);
1703 stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4);
1704 strcpy (stabstr_name, segment_name (seg));
1705 strcat (stabstr_name, "str");
1706 stroff = get_stab_string_offset (file, stabstr_name);
1707 know (stroff == 1);
1708 md_number_to_chars (p, stroff, 4);
1709 seg_info (seg)->stabu.p = p;
1710 }
1711
1712 #endif
1713
1714 /* Fill in the counts in the first entry in a .stabs section. */
1715
1716 static void
1717 adjust_stab_sections (abfd, sec, xxx)
1718 bfd *abfd;
1719 asection *sec;
1720 PTR xxx ATTRIBUTE_UNUSED;
1721 {
1722 char *name;
1723 asection *strsec;
1724 char *p;
1725 int strsz, nsyms;
1726
1727 if (strncmp (".stab", sec->name, 5))
1728 return;
1729 if (!strcmp ("str", sec->name + strlen (sec->name) - 3))
1730 return;
1731
1732 name = (char *) alloca (strlen (sec->name) + 4);
1733 strcpy (name, sec->name);
1734 strcat (name, "str");
1735 strsec = bfd_get_section_by_name (abfd, name);
1736 if (strsec)
1737 strsz = bfd_section_size (abfd, strsec);
1738 else
1739 strsz = 0;
1740 nsyms = bfd_section_size (abfd, sec) / 12 - 1;
1741
1742 p = seg_info (sec)->stabu.p;
1743 assert (p != 0);
1744
1745 bfd_h_put_16 (abfd, (bfd_vma) nsyms, (bfd_byte *) p + 6);
1746 bfd_h_put_32 (abfd, (bfd_vma) strsz, (bfd_byte *) p + 8);
1747 }
1748
1749 #ifdef NEED_ECOFF_DEBUG
1750
1751 /* This function is called by the ECOFF code. It is supposed to
1752 record the external symbol information so that the backend can
1753 write it out correctly. The ELF backend doesn't actually handle
1754 this at the moment, so we do it ourselves. We save the information
1755 in the symbol. */
1756
1757 void
1758 elf_ecoff_set_ext (sym, ext)
1759 symbolS *sym;
1760 struct ecoff_extr *ext;
1761 {
1762 symbol_get_bfdsym (sym)->udata.p = (PTR) ext;
1763 }
1764
1765 /* This function is called by bfd_ecoff_debug_externals. It is
1766 supposed to *EXT to the external symbol information, and return
1767 whether the symbol should be used at all. */
1768
1769 static bfd_boolean
1770 elf_get_extr (sym, ext)
1771 asymbol *sym;
1772 EXTR *ext;
1773 {
1774 if (sym->udata.p == NULL)
1775 return FALSE;
1776 *ext = *(EXTR *) sym->udata.p;
1777 return TRUE;
1778 }
1779
1780 /* This function is called by bfd_ecoff_debug_externals. It has
1781 nothing to do for ELF. */
1782
1783 /*ARGSUSED*/
1784 static void
1785 elf_set_index (sym, indx)
1786 asymbol *sym ATTRIBUTE_UNUSED;
1787 bfd_size_type indx ATTRIBUTE_UNUSED;
1788 {
1789 }
1790
1791 #endif /* NEED_ECOFF_DEBUG */
1792
1793 void
1794 elf_frob_symbol (symp, puntp)
1795 symbolS *symp;
1796 int *puntp;
1797 {
1798 struct elf_obj_sy *sy_obj;
1799
1800 #ifdef NEED_ECOFF_DEBUG
1801 if (ECOFF_DEBUGGING)
1802 ecoff_frob_symbol (symp);
1803 #endif
1804
1805 sy_obj = symbol_get_obj (symp);
1806
1807 if (sy_obj->size != NULL)
1808 {
1809 switch (sy_obj->size->X_op)
1810 {
1811 case O_subtract:
1812 S_SET_SIZE (symp,
1813 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1814 + sy_obj->size->X_add_number
1815 - S_GET_VALUE (sy_obj->size->X_op_symbol)));
1816 break;
1817 case O_constant:
1818 S_SET_SIZE (symp,
1819 (S_GET_VALUE (sy_obj->size->X_add_symbol)
1820 + sy_obj->size->X_add_number));
1821 break;
1822 default:
1823 as_bad (_(".size expression too complicated to fix up"));
1824 break;
1825 }
1826 free (sy_obj->size);
1827 sy_obj->size = NULL;
1828 }
1829
1830 if (sy_obj->versioned_name != NULL)
1831 {
1832 char *p;
1833
1834 p = strchr (sy_obj->versioned_name, ELF_VER_CHR);
1835 know (p != NULL);
1836
1837 /* This symbol was given a new name with the .symver directive.
1838
1839 If this is an external reference, just rename the symbol to
1840 include the version string. This will make the relocs be
1841 against the correct versioned symbol.
1842
1843 If this is a definition, add an alias. FIXME: Using an alias
1844 will permit the debugging information to refer to the right
1845 symbol. However, it's not clear whether it is the best
1846 approach. */
1847
1848 if (! S_IS_DEFINED (symp))
1849 {
1850 /* Verify that the name isn't using the @@ syntax--this is
1851 reserved for definitions of the default version to link
1852 against. */
1853 if (p[1] == ELF_VER_CHR)
1854 {
1855 as_bad (_("invalid attempt to declare external version name as default in symbol `%s'"),
1856 sy_obj->versioned_name);
1857 *puntp = TRUE;
1858 }
1859 S_SET_NAME (symp, sy_obj->versioned_name);
1860 }
1861 else
1862 {
1863 if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR)
1864 {
1865 size_t l;
1866
1867 /* The @@@ syntax is a special case. It renames the
1868 symbol name to versioned_name with one `@' removed. */
1869 l = strlen (&p[3]) + 1;
1870 memmove (&p [2], &p[3], l);
1871 S_SET_NAME (symp, sy_obj->versioned_name);
1872 }
1873 else
1874 {
1875 symbolS *symp2;
1876
1877 /* FIXME: Creating a new symbol here is risky. We're
1878 in the final loop over the symbol table. We can
1879 get away with it only because the symbol goes to
1880 the end of the list, where the loop will still see
1881 it. It would probably be better to do this in
1882 obj_frob_file_before_adjust. */
1883
1884 symp2 = symbol_find_or_make (sy_obj->versioned_name);
1885
1886 /* Now we act as though we saw symp2 = sym. */
1887
1888 S_SET_SEGMENT (symp2, S_GET_SEGMENT (symp));
1889
1890 /* Subtracting out the frag address here is a hack
1891 because we are in the middle of the final loop. */
1892 S_SET_VALUE (symp2,
1893 (S_GET_VALUE (symp)
1894 - symbol_get_frag (symp)->fr_address));
1895
1896 symbol_set_frag (symp2, symbol_get_frag (symp));
1897
1898 /* This will copy over the size information. */
1899 copy_symbol_attributes (symp2, symp);
1900
1901 S_SET_OTHER (symp2, S_GET_OTHER (symp));
1902
1903 if (S_IS_WEAK (symp))
1904 S_SET_WEAK (symp2);
1905
1906 if (S_IS_EXTERNAL (symp))
1907 S_SET_EXTERNAL (symp2);
1908 }
1909 }
1910 }
1911
1912 /* Double check weak symbols. */
1913 if (S_IS_WEAK (symp))
1914 {
1915 if (S_IS_COMMON (symp))
1916 as_bad (_("symbol `%s' can not be both weak and common"),
1917 S_GET_NAME (symp));
1918 }
1919
1920 #ifdef TC_MIPS
1921 /* The Irix 5 and 6 assemblers set the type of any common symbol and
1922 any undefined non-function symbol to STT_OBJECT. We try to be
1923 compatible, since newer Irix 5 and 6 linkers care. However, we
1924 only set undefined symbols to be STT_OBJECT if we are on Irix,
1925 because that is the only time gcc will generate the necessary
1926 .global directives to mark functions. */
1927
1928 if (S_IS_COMMON (symp))
1929 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1930
1931 if (strstr (TARGET_OS, "irix") != NULL
1932 && ! S_IS_DEFINED (symp)
1933 && (symbol_get_bfdsym (symp)->flags & BSF_FUNCTION) == 0)
1934 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1935 #endif
1936
1937 #if 0 /* TC_PPC */
1938 /* If TC_PPC is defined, we used to force the type of a symbol to be
1939 BSF_OBJECT if it was otherwise unset. This was required by some
1940 version of VxWorks. Thomas de Lellis <tdel@windriver.com> says
1941 that this is no longer needed, so it is now commented out. */
1942 if ((symbol_get_bfdsym (symp)->flags
1943 & (BSF_FUNCTION | BSF_FILE | BSF_SECTION_SYM)) == 0
1944 && S_IS_DEFINED (symp))
1945 symbol_get_bfdsym (symp)->flags |= BSF_OBJECT;
1946 #endif
1947 }
1948
1949 struct group_list
1950 {
1951 asection **head; /* Section lists. */
1952 unsigned int *elt_count; /* Number of sections in each list. */
1953 unsigned int num_group; /* Number of lists. */
1954 };
1955
1956 /* Called via bfd_map_over_sections. If SEC is a member of a group,
1957 add it to a list of sections belonging to the group. INF is a
1958 pointer to a struct group_list, which is where we store the head of
1959 each list. */
1960
1961 static void
1962 build_group_lists (abfd, sec, inf)
1963 bfd *abfd ATTRIBUTE_UNUSED;
1964 asection *sec;
1965 PTR inf;
1966 {
1967 struct group_list *list = (struct group_list *) inf;
1968 const char *group_name = elf_group_name (sec);
1969 unsigned int i;
1970
1971 if (group_name == NULL)
1972 return;
1973
1974 /* If this group already has a list, add the section to the head of
1975 the list. */
1976 for (i = 0; i < list->num_group; i++)
1977 {
1978 if (strcmp (group_name, elf_group_name (list->head[i])) == 0)
1979 {
1980 elf_next_in_group (sec) = list->head[i];
1981 list->head[i] = sec;
1982 list->elt_count[i] += 1;
1983 return;
1984 }
1985 }
1986
1987 /* New group. Make the arrays bigger in chunks to minimize calls to
1988 realloc. */
1989 i = list->num_group;
1990 if ((i & 127) == 0)
1991 {
1992 unsigned int newsize = i + 128;
1993 list->head = xrealloc (list->head, newsize * sizeof (*list->head));
1994 list->elt_count = xrealloc (list->elt_count,
1995 newsize * sizeof (*list->elt_count));
1996 }
1997 list->head[i] = sec;
1998 list->elt_count[i] = 1;
1999 list->num_group += 1;
2000 }
2001
2002 void
2003 elf_frob_file ()
2004 {
2005 struct group_list list;
2006 unsigned int i;
2007
2008 bfd_map_over_sections (stdoutput, adjust_stab_sections, (PTR) 0);
2009
2010 /* Go find section groups. */
2011 list.num_group = 0;
2012 list.head = NULL;
2013 list.elt_count = NULL;
2014 bfd_map_over_sections (stdoutput, build_group_lists, (PTR) &list);
2015
2016 /* Make the SHT_GROUP sections that describe each section group. We
2017 can't set up the section contents here yet, because elf section
2018 indices have yet to be calculated. elf.c:set_group_contents does
2019 the rest of the work. */
2020 for (i = 0; i < list.num_group; i++)
2021 {
2022 const char *group_name = elf_group_name (list.head[i]);
2023 const char *sec_name;
2024 asection *s;
2025 flagword flags;
2026 struct symbol *sy;
2027 int has_sym;
2028
2029 flags = SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_GROUP;
2030 for (s = list.head[i]; s != NULL; s = elf_next_in_group (s))
2031 if (elf_linkonce_p (s) != ((flags & SEC_LINK_ONCE) != 0))
2032 {
2033 flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
2034 if (s != list.head[i])
2035 {
2036 as_warn (_("assuming all members of group `%s' are COMDAT"),
2037 group_name);
2038 break;
2039 }
2040 }
2041
2042 sec_name = group_name;
2043 sy = symbol_find_exact (group_name);
2044 has_sym = 0;
2045 if (sy != NULL
2046 && (sy == symbol_lastP
2047 || (sy->sy_next != NULL
2048 && sy->sy_next->sy_previous == sy)))
2049 {
2050 has_sym = 1;
2051 sec_name = ".group";
2052 }
2053 s = subseg_force_new (sec_name, 0);
2054 if (s == NULL
2055 || !bfd_set_section_flags (stdoutput, s, flags)
2056 || !bfd_set_section_alignment (stdoutput, s, 2))
2057 {
2058 as_fatal (_("can't create group: %s"),
2059 bfd_errmsg (bfd_get_error ()));
2060 }
2061
2062 /* Pass a pointer to the first section in this group. */
2063 elf_next_in_group (s) = list.head[i];
2064 if (has_sym)
2065 elf_group_id (s) = sy->bsym;
2066
2067 s->_raw_size = 4 * (list.elt_count[i] + 1);
2068 s->contents = frag_more (s->_raw_size);
2069 frag_now->fr_fix = frag_now_fix_octets ();
2070 }
2071
2072 #ifdef elf_tc_final_processing
2073 elf_tc_final_processing ();
2074 #endif
2075 }
2076
2077 /* It removes any unneeded versioned symbols from the symbol table. */
2078
2079 void
2080 elf_frob_file_before_adjust ()
2081 {
2082 if (symbol_rootP)
2083 {
2084 symbolS *symp;
2085
2086 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
2087 if (!S_IS_DEFINED (symp))
2088 {
2089 if (symbol_get_obj (symp)->versioned_name)
2090 {
2091 char *p;
2092
2093 /* The @@@ syntax is a special case. If the symbol is
2094 not defined, 2 `@'s will be removed from the
2095 versioned_name. */
2096
2097 p = strchr (symbol_get_obj (symp)->versioned_name,
2098 ELF_VER_CHR);
2099 know (p != NULL);
2100 if (p [1] == ELF_VER_CHR && p [2] == ELF_VER_CHR)
2101 {
2102 size_t l = strlen (&p[3]) + 1;
2103 memmove (&p [1], &p[3], l);
2104 }
2105 if (symbol_used_p (symp) == 0
2106 && symbol_used_in_reloc_p (symp) == 0)
2107 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2108 }
2109
2110 /* If there was .weak foo, but foo was neither defined nor
2111 used anywhere, remove it. */
2112
2113 else if (S_IS_WEAK (symp)
2114 && symbol_used_p (symp) == 0
2115 && symbol_used_in_reloc_p (symp) == 0)
2116 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2117 }
2118 }
2119 }
2120
2121 /* It is required that we let write_relocs have the opportunity to
2122 optimize away fixups before output has begun, since it is possible
2123 to eliminate all fixups for a section and thus we never should
2124 have generated the relocation section. */
2125
2126 void
2127 elf_frob_file_after_relocs ()
2128 {
2129 #ifdef NEED_ECOFF_DEBUG
2130 if (ECOFF_DEBUGGING)
2131 /* Generate the ECOFF debugging information. */
2132 {
2133 const struct ecoff_debug_swap *debug_swap;
2134 struct ecoff_debug_info debug;
2135 char *buf;
2136 asection *sec;
2137
2138 debug_swap
2139 = get_elf_backend_data (stdoutput)->elf_backend_ecoff_debug_swap;
2140 know (debug_swap != (const struct ecoff_debug_swap *) NULL);
2141 ecoff_build_debug (&debug.symbolic_header, &buf, debug_swap);
2142
2143 /* Set up the pointers in debug. */
2144 #define SET(ptr, offset, type) \
2145 debug.ptr = (type) (buf + debug.symbolic_header.offset)
2146
2147 SET (line, cbLineOffset, unsigned char *);
2148 SET (external_dnr, cbDnOffset, PTR);
2149 SET (external_pdr, cbPdOffset, PTR);
2150 SET (external_sym, cbSymOffset, PTR);
2151 SET (external_opt, cbOptOffset, PTR);
2152 SET (external_aux, cbAuxOffset, union aux_ext *);
2153 SET (ss, cbSsOffset, char *);
2154 SET (external_fdr, cbFdOffset, PTR);
2155 SET (external_rfd, cbRfdOffset, PTR);
2156 /* ssext and external_ext are set up just below. */
2157
2158 #undef SET
2159
2160 /* Set up the external symbols. */
2161 debug.ssext = debug.ssext_end = NULL;
2162 debug.external_ext = debug.external_ext_end = NULL;
2163 if (! bfd_ecoff_debug_externals (stdoutput, &debug, debug_swap, TRUE,
2164 elf_get_extr, elf_set_index))
2165 as_fatal (_("failed to set up debugging information: %s"),
2166 bfd_errmsg (bfd_get_error ()));
2167
2168 sec = bfd_get_section_by_name (stdoutput, ".mdebug");
2169 assert (sec != NULL);
2170
2171 know (!stdoutput->output_has_begun);
2172
2173 /* We set the size of the section, call bfd_set_section_contents
2174 to force the ELF backend to allocate a file position, and then
2175 write out the data. FIXME: Is this really the best way to do
2176 this? */
2177 sec->_raw_size = bfd_ecoff_debug_size (stdoutput, &debug, debug_swap);
2178
2179 /* Pass BUF to bfd_set_section_contents because this will
2180 eventually become a call to fwrite, and ISO C prohibits
2181 passing a NULL pointer to a stdio function even if the
2182 pointer will not be used. */
2183 if (! bfd_set_section_contents (stdoutput, sec, (PTR) buf,
2184 (file_ptr) 0, (bfd_size_type) 0))
2185 as_fatal (_("can't start writing .mdebug section: %s"),
2186 bfd_errmsg (bfd_get_error ()));
2187
2188 know (stdoutput->output_has_begun);
2189 know (sec->filepos != 0);
2190
2191 if (! bfd_ecoff_write_debug (stdoutput, &debug, debug_swap,
2192 sec->filepos))
2193 as_fatal (_("could not write .mdebug section: %s"),
2194 bfd_errmsg (bfd_get_error ()));
2195 }
2196 #endif /* NEED_ECOFF_DEBUG */
2197 }
2198
2199 #ifdef SCO_ELF
2200
2201 /* Heavily plagarized from obj_elf_version. The idea is to emit the
2202 SCO specific identifier in the .notes section to satisfy the SCO
2203 linker.
2204
2205 This looks more complicated than it really is. As opposed to the
2206 "obvious" solution, this should handle the cross dev cases
2207 correctly. (i.e, hosting on a 64 bit big endian processor, but
2208 generating SCO Elf code) Efficiency isn't a concern, as there
2209 should be exactly one of these sections per object module.
2210
2211 SCO OpenServer 5 identifies it's ELF modules with a standard ELF
2212 .note section.
2213
2214 int_32 namesz = 4 ; Name size
2215 int_32 descsz = 12 ; Descriptive information
2216 int_32 type = 1 ;
2217 char name[4] = "SCO" ; Originator name ALWAYS SCO + NULL
2218 int_32 version = (major ver # << 16) | version of tools ;
2219 int_32 source = (tool_id << 16 ) | 1 ;
2220 int_32 info = 0 ; These are set by the SCO tools, but we
2221 don't know enough about the source
2222 environment to set them. SCO ld currently
2223 ignores them, and recommends we set them
2224 to zero. */
2225
2226 #define SCO_MAJOR_VERSION 0x1
2227 #define SCO_MINOR_VERSION 0x1
2228
2229 void
2230 sco_id ()
2231 {
2232
2233 char *name;
2234 unsigned int c;
2235 char ch;
2236 char *p;
2237 asection *seg = now_seg;
2238 subsegT subseg = now_subseg;
2239 Elf_Internal_Note i_note;
2240 Elf_External_Note e_note;
2241 asection *note_secp = (asection *) NULL;
2242 int i, len;
2243
2244 /* create the .note section */
2245
2246 note_secp = subseg_new (".note", 0);
2247 bfd_set_section_flags (stdoutput,
2248 note_secp,
2249 SEC_HAS_CONTENTS | SEC_READONLY);
2250
2251 /* process the version string */
2252
2253 i_note.namesz = 4;
2254 i_note.descsz = 12; /* 12 descriptive bytes */
2255 i_note.type = NT_VERSION; /* Contains a version string */
2256
2257 p = frag_more (sizeof (i_note.namesz));
2258 md_number_to_chars (p, (valueT) i_note.namesz, 4);
2259
2260 p = frag_more (sizeof (i_note.descsz));
2261 md_number_to_chars (p, (valueT) i_note.descsz, 4);
2262
2263 p = frag_more (sizeof (i_note.type));
2264 md_number_to_chars (p, (valueT) i_note.type, 4);
2265
2266 p = frag_more (4);
2267 strcpy (p, "SCO");
2268
2269 /* Note: this is the version number of the ELF we're representing */
2270 p = frag_more (4);
2271 md_number_to_chars (p, (SCO_MAJOR_VERSION << 16) | (SCO_MINOR_VERSION), 4);
2272
2273 /* Here, we pick a magic number for ourselves (yes, I "registered"
2274 it with SCO. The bottom bit shows that we are compat with the
2275 SCO ABI. */
2276 p = frag_more (4);
2277 md_number_to_chars (p, 0x4c520000 | 0x0001, 4);
2278
2279 /* If we knew (or cared) what the source language options were, we'd
2280 fill them in here. SCO has given us permission to ignore these
2281 and just set them to zero. */
2282 p = frag_more (4);
2283 md_number_to_chars (p, 0x0000, 4);
2284
2285 frag_align (2, 0, 0);
2286
2287 /* We probably can't restore the current segment, for there likely
2288 isn't one yet... */
2289 if (seg && subseg)
2290 subseg_set (seg, subseg);
2291
2292 }
2293
2294 #endif /* SCO_ELF */
2295
2296 static int
2297 elf_separate_stab_sections ()
2298 {
2299 #ifdef NEED_ECOFF_DEBUG
2300 return (!ECOFF_DEBUGGING);
2301 #else
2302 return 1;
2303 #endif
2304 }
2305
2306 static void
2307 elf_init_stab_section (seg)
2308 segT seg;
2309 {
2310 #ifdef NEED_ECOFF_DEBUG
2311 if (!ECOFF_DEBUGGING)
2312 #endif
2313 obj_elf_init_stab_section (seg);
2314 }
2315
2316 const struct format_ops elf_format_ops =
2317 {
2318 bfd_target_elf_flavour,
2319 0, /* dfl_leading_underscore */
2320 1, /* emit_section_symbols */
2321 elf_begin,
2322 elf_file_symbol,
2323 elf_frob_symbol,
2324 elf_frob_file,
2325 elf_frob_file_before_adjust,
2326 0, /* obj_frob_file_before_fix */
2327 elf_frob_file_after_relocs,
2328 elf_s_get_size, elf_s_set_size,
2329 elf_s_get_align, elf_s_set_align,
2330 elf_s_get_other,
2331 elf_s_set_other,
2332 0, /* s_get_desc */
2333 0, /* s_set_desc */
2334 0, /* s_get_type */
2335 0, /* s_set_type */
2336 elf_copy_symbol_attributes,
2337 #ifdef NEED_ECOFF_DEBUG
2338 ecoff_generate_asm_lineno,
2339 ecoff_stab,
2340 #else
2341 0, /* generate_asm_lineno */
2342 0, /* process_stab */
2343 #endif
2344 elf_separate_stab_sections,
2345 elf_init_stab_section,
2346 elf_sec_sym_ok_for_reloc,
2347 elf_pop_insert,
2348 #ifdef NEED_ECOFF_DEBUG
2349 elf_ecoff_set_ext,
2350 #else
2351 0, /* ecoff_set_ext */
2352 #endif
2353 elf_obj_read_begin_hook,
2354 elf_obj_symbol_new_hook
2355 };