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