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