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