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