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