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