Add partial support for ELF format corefiles. Still needs code to extract
[binutils-gdb.git] / bfd / elf.c
1 /* ELF support for BFD.
2 Copyright (C) 1991 Free Software Foundation, Inc.
3
4 Written by Fred Fish @ Cygnus Support, from information published
5 in "UNIX System V Release 4, Programmers Guide: ANSI C and
6 Programming Support Tools".
7
8 This file is part of BFD, the Binary File Descriptor library.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23
24
25 /****************************************
26
27 WARNING
28
29 This is only a partial ELF implementation,
30 incorporating only those parts that are
31 required to get gdb up and running. It is
32 expected that it will be expanded to a full
33 ELF implementation at some future date.
34
35 Unimplemented stubs call abort() to ensure
36 that they get proper attention if they are
37 ever called. The stubs are here since
38 this version was hacked from the COFF
39 version, and thus they will probably
40 go away or get expanded appropriately in a
41 future version.
42
43 fnf@cygnus.com
44
45 *****************************************/
46
47
48 /* Problems and other issues to resolve.
49
50 (1) BFD expects there to be some fixed number of "sections" in
51 the object file. I.E. there is a "section_count" variable in the
52 bfd structure which contains the number of sections. However, ELF
53 supports multiple "views" of a file. In particular, with current
54 implementations, executable files typically have two tables, a
55 program header table and a section header table, both of which
56 partition the executable.
57
58 In ELF-speak, the "linking view" of the file uses the section header
59 table to access "sections" within the file, and the "execution view"
60 uses the program header table to access "segments" within the file.
61 "Segments" typically may contain all the data from one or more
62 "sections".
63
64 Note that the section header table is optional in ELF executables,
65 but it is this information that is most useful to gdb. If the
66 section header table is missing, then gdb should probably try
67 to make do with the program header table. (FIXME)
68
69 */
70
71 #include "bfd.h"
72 #include "sysdep.h"
73 #include "libbfd.h"
74 #include "obstack.h"
75 #include "elf-common.h"
76 #include "elf-internal.h"
77 #include "elf-external.h"
78
79 /* Forward data declarations */
80 extern bfd_target elf_little_vec, elf_big_vec;
81
82 /* Translate an ELF header in external format into an ELF header in internal
83 format. */
84
85 static void
86 DEFUN(bfd_swap_ehdr_in,(abfd, src, dst),
87 bfd *abfd AND
88 Elf_External_Ehdr *src AND
89 Elf_Internal_Ehdr *dst)
90 {
91 bcopy (src -> e_ident, dst -> e_ident, EI_NIDENT);
92 dst -> e_type = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_type);
93 dst -> e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_machine);
94 dst -> e_version = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_version);
95 dst -> e_entry = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_entry);
96 dst -> e_phoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_phoff);
97 dst -> e_shoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_shoff);
98 dst -> e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_flags);
99 dst -> e_ehsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_ehsize);
100 dst -> e_phentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phentsize);
101 dst -> e_phnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phnum);
102 dst -> e_shentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shentsize);
103 dst -> e_shnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shnum);
104 dst -> e_shstrndx = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shstrndx);
105 }
106
107
108 /* Translate an ELF section header table entry in external format into an
109 ELF section header table entry in internal format. */
110
111 static void
112 DEFUN(bfd_swap_shdr_in,(abfd, src, dst),
113 bfd *abfd AND
114 Elf_External_Shdr *src AND
115 Elf_Internal_Shdr *dst)
116 {
117 dst -> sh_name = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_name);
118 dst -> sh_type = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_type);
119 dst -> sh_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_flags);
120 dst -> sh_addr = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_addr);
121 dst -> sh_offset = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_offset);
122 dst -> sh_size = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_size);
123 dst -> sh_link = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_link);
124 dst -> sh_info = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_info);
125 dst -> sh_addralign = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_addralign);
126 dst -> sh_entsize = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_entsize);
127 }
128
129
130 /* Translate an ELF program header table entry in external format into an
131 ELF program header table entry in internal format. */
132
133 static void
134 DEFUN(bfd_swap_phdr_in,(abfd, src, dst),
135 bfd *abfd AND
136 Elf_External_Phdr *src AND
137 Elf_Internal_Phdr *dst)
138 {
139 dst -> p_type = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_type);
140 dst -> p_offset = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_offset);
141 dst -> p_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_vaddr);
142 dst -> p_paddr = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_paddr);
143 dst -> p_filesz = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_filesz);
144 dst -> p_memsz = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_memsz);
145 dst -> p_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_flags);
146 dst -> p_align = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_align);
147 }
148
149
150 /* Create a new bfd section from an ELF section header. */
151
152 static boolean
153 DEFUN(bfd_section_from_shdr, (abfd, hdr, shstrtab),
154 bfd *abfd AND
155 Elf_Internal_Shdr *hdr AND
156 char *shstrtab)
157 {
158 asection *newsect;
159 char *name;
160
161 name = hdr -> sh_name ? shstrtab + hdr -> sh_name : "unnamed";
162 newsect = bfd_make_section (abfd, name);
163 newsect -> vma = hdr -> sh_addr;
164 newsect -> size = hdr -> sh_size;
165 if (!(hdr -> sh_type == SHT_NOBITS))
166 {
167 newsect -> filepos = hdr -> sh_offset;
168 newsect -> flags |= SEC_HAS_CONTENTS;
169 }
170 if (hdr -> sh_flags & SHF_ALLOC)
171 {
172 newsect -> flags |= SEC_ALLOC;
173 if (hdr -> sh_type != SHT_NOBITS)
174 {
175 newsect -> flags |= SEC_LOAD;
176 }
177 }
178 if (!(hdr -> sh_flags & SHF_WRITE))
179 {
180 newsect -> flags |= SEC_READONLY;
181 }
182 if (hdr -> sh_flags & SHF_EXECINSTR)
183 {
184 newsect -> flags |= SEC_CODE; /* FIXME: may only contain SOME code */
185 }
186 if (hdr -> sh_type == SHT_SYMTAB)
187 {
188 abfd -> flags |= HAS_SYMS;
189 }
190
191 return (true);
192 }
193
194 /* Create a new bfd section from an ELF program header.
195
196 Since program segments have no names, we generate a synthetic name
197 of the form segment<NUM>, where NUM is generally the index in the
198 program header table. For segments that are split (see below) we
199 generate the names segment<NUM>a and segment<NUM>b.
200
201 Note that some program segments may have a file size that is different than
202 (less than) the memory size. All this means is that at execution the
203 system must allocate the amount of memory specified by the memory size,
204 but only initialize it with the first "file size" bytes read from the
205 file. This would occur for example, with program segments consisting
206 of combined data+bss.
207
208 To handle the above situation, this routine generates TWO bfd sections
209 for the single program segment. The first has the length specified by
210 the file size of the segment, and the second has the length specified
211 by the difference between the two sizes. In effect, the segment is split
212 into it's initialized and uninitialized parts.
213
214 */
215
216 static boolean
217 DEFUN(bfd_section_from_phdr, (abfd, hdr, index),
218 bfd *abfd AND
219 Elf_Internal_Phdr *hdr AND
220 int index)
221 {
222 asection *newsect;
223 char *name;
224 char namebuf[64];
225 int split;
226
227 split = ((hdr -> p_memsz > 0) &&
228 (hdr -> p_filesz > 0) &&
229 (hdr -> p_memsz > hdr -> p_filesz));
230 sprintf (namebuf, split ? "segment%da" : "segment%d", index);
231 name = bfd_alloc (abfd, strlen (namebuf) + 1);
232 (void) strcpy (name, namebuf);
233 newsect = bfd_make_section (abfd, name);
234 newsect -> vma = hdr -> p_vaddr;
235 newsect -> size = hdr -> p_filesz;
236 newsect -> filepos = hdr -> p_offset;
237 newsect -> flags |= SEC_HAS_CONTENTS;
238 if (hdr -> p_type == PT_LOAD)
239 {
240 newsect -> flags |= SEC_ALLOC;
241 newsect -> flags |= SEC_LOAD;
242 if (hdr -> p_flags & PF_X)
243 {
244 /* FIXME: all we known is that it has execute PERMISSION,
245 may be data. */
246 newsect -> flags |= SEC_CODE;
247 }
248 }
249 if (!(hdr -> p_flags & PF_W))
250 {
251 newsect -> flags |= SEC_READONLY;
252 }
253
254 if (split)
255 {
256 sprintf (namebuf, "segment%db", index);
257 name = bfd_alloc (abfd, strlen (namebuf) + 1);
258 (void) strcpy (name, namebuf);
259 newsect = bfd_make_section (abfd, name);
260 newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz;
261 newsect -> size = hdr -> p_memsz - hdr -> p_filesz;
262 if (hdr -> p_type == PT_LOAD)
263 {
264 newsect -> flags |= SEC_ALLOC;
265 if (hdr -> p_flags & PF_X)
266 {
267 newsect -> flags |= SEC_CODE;
268 }
269 }
270 if (!(hdr -> p_flags & PF_W))
271 {
272 newsect -> flags |= SEC_READONLY;
273 }
274 }
275
276 return (true);
277 }
278
279 /* Begin processing a given object.
280
281 First we validate the file by reading in the ELF header and checking
282 the magic number.
283
284 */
285
286 static bfd_target *
287 DEFUN (elf_object_p, (abfd), bfd *abfd)
288 {
289 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
290 Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
291 Elf_External_Shdr *x_shdr; /* Section header table, external form */
292 Elf_Internal_Shdr *i_shdr; /* Section header table, internal form */
293 int shindex;
294 char *shstrtab; /* Internal copy of section header stringtab */
295 int shstrtabsize; /* Size of section header string table */
296
297 /* Read in the ELF header in external format. */
298
299 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
300 {
301 bfd_error = system_call_error;
302 return (NULL);
303 }
304
305 /* Now check to see if we have a valid ELF file, and one that BFD can
306 make use of. The magic number must match, the address size ('class')
307 and byte-swapping must match our XVEC entry, and it must have a
308 section header table (FIXME: See comments re sections at top of this
309 file). */
310
311 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
312 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
313 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
314 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
315 {
316 wrong:
317 bfd_error = wrong_format;
318 return (NULL);
319 }
320
321 /* FIXME, Check EI_VERSION here ! */
322
323 switch (x_ehdr.e_ident[EI_CLASS]) {
324 case ELFCLASSNONE: /* address size not specified */
325 goto wrong; /* No support if can't tell address size */
326 case ELFCLASS32: /* 32-bit addresses */
327 break;
328 case ELFCLASS64: /* 64-bit addresses */
329 goto wrong; /* FIXME: 64 bits not yet supported */
330 default:
331 goto wrong; /* No support if unknown address class */
332 }
333
334 /* Switch xvec to match the specified byte order. */
335 switch (x_ehdr.e_ident[EI_DATA]) {
336 case ELFDATA2MSB: /* Big-endian */
337 abfd->xvec = &elf_big_vec;
338 break;
339 case ELFDATA2LSB: /* Little-endian */
340 abfd->xvec = &elf_little_vec;
341 case ELFDATANONE: /* No data encoding specified */
342 default: /* Unknown data encoding specified */
343 goto wrong;
344 }
345
346 /* Now that we know the byte order, swap in the rest of the header */
347 bfd_swap_ehdr_in (abfd, &x_ehdr, &i_ehdr);
348
349 /* If there is no section header table, we're hosed. */
350 if (i_ehdr.e_shoff == 0)
351 goto wrong;
352
353 if (i_ehdr.e_type == ET_EXEC || i_ehdr.e_type == ET_DYN)
354 {
355 abfd -> flags |= EXEC_P;
356 }
357
358 /* Allocate space for copies of the section header table in external
359 and internal form, seek to the section header table in the file,
360 read it in, and convert it to internal form. As a simple sanity
361 check, verify that the what BFD thinks is the size of each section
362 header table entry actually matches the size recorded in the file. */
363
364 if (i_ehdr.e_shentsize != sizeof (*x_shdr))
365 goto wrong;
366 if ((x_shdr = (Elf_External_Shdr *)
367 bfd_alloc (abfd, sizeof (*x_shdr) * i_ehdr.e_shnum)) == NULL)
368 {
369 bfd_error = no_memory;
370 return (NULL);
371 }
372 if ((i_shdr = (Elf_Internal_Shdr *)
373 bfd_alloc (abfd, sizeof (*i_shdr) * i_ehdr.e_shnum)) == NULL)
374 {
375 bfd_error = no_memory;
376 return (NULL);
377 }
378 if (bfd_seek (abfd, i_ehdr.e_shoff, SEEK_SET) == -1)
379 {
380 bfd_error = system_call_error;
381 return (NULL);
382 }
383 for (shindex = 0; shindex < i_ehdr.e_shnum; shindex++)
384 {
385 if (bfd_read ((PTR) (x_shdr + shindex), sizeof (*x_shdr), 1, abfd)
386 != sizeof (*x_shdr))
387 {
388 bfd_error = system_call_error;
389 return (NULL);
390 }
391 bfd_swap_shdr_in (abfd, x_shdr + shindex, i_shdr + shindex);
392 }
393
394 /* Read in the string table containing the names of the sections. We
395 will need the base pointer to this table later. */
396
397 shstrtabsize = i_shdr[i_ehdr.e_shstrndx].sh_size;
398 if ((shstrtab = bfd_alloc (abfd, shstrtabsize)) == NULL)
399 {
400 bfd_error = no_memory;
401 return (NULL);
402 }
403 if (bfd_seek (abfd, i_shdr[i_ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1)
404 {
405 bfd_error = system_call_error;
406 return (NULL);
407 }
408 if (bfd_read ((PTR) shstrtab, shstrtabsize, 1, abfd) != shstrtabsize)
409 {
410 bfd_error = system_call_error;
411 return (NULL);
412 }
413
414 /* Once all of the section headers have been read and converted, we
415 can start processing them. */
416
417 for (shindex = 0; shindex < i_ehdr.e_shnum; shindex++)
418 {
419 bfd_section_from_shdr (abfd, i_shdr + shindex, shstrtab);
420 }
421
422 return (abfd->xvec);
423 }
424
425 /* Core files are simply standard ELF formatted files that partition
426 the file using the execution view of the file (program header table)
427 rather than the linking view. In fact, there is no section header
428 table in a core file.
429 */
430
431 static bfd_target *
432 DEFUN (elf_core_file_p, (abfd), bfd *abfd)
433 {
434 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
435 Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
436 Elf_External_Phdr *x_phdr; /* Program header table, external form */
437 Elf_Internal_Phdr *i_phdr; /* Program header table, internal form */
438 int phindex;
439
440 /* Read in the ELF header in external format. */
441
442 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
443 {
444 bfd_error = system_call_error;
445 return (NULL);
446 }
447
448 /* Now check to see if we have a valid ELF file, and one that BFD can
449 make use of. The magic number must match, the address size ('class')
450 and byte-swapping must match our XVEC entry, and it must have a
451 program header table (FIXME: See comments re segments at top of this
452 file). */
453
454 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
455 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
456 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
457 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
458 {
459 wrong:
460 bfd_error = wrong_format;
461 return (NULL);
462 }
463
464 /* FIXME, Check EI_VERSION here ! */
465
466 switch (x_ehdr.e_ident[EI_CLASS]) {
467 case ELFCLASSNONE: /* address size not specified */
468 goto wrong; /* No support if can't tell address size */
469 case ELFCLASS32: /* 32-bit addresses */
470 break;
471 case ELFCLASS64: /* 64-bit addresses */
472 goto wrong; /* FIXME: 64 bits not yet supported */
473 default:
474 goto wrong; /* No support if unknown address class */
475 }
476
477 /* Switch xvec to match the specified byte order. */
478 switch (x_ehdr.e_ident[EI_DATA]) {
479 case ELFDATA2MSB: /* Big-endian */
480 abfd->xvec = &elf_big_vec;
481 break;
482 case ELFDATA2LSB: /* Little-endian */
483 abfd->xvec = &elf_little_vec;
484 case ELFDATANONE: /* No data encoding specified */
485 default: /* Unknown data encoding specified */
486 goto wrong;
487 }
488
489 /* Now that we know the byte order, swap in the rest of the header */
490 bfd_swap_ehdr_in (abfd, &x_ehdr, &i_ehdr);
491
492 /* If there is no program header, or the type is not a core file, then
493 we are hosed. */
494 if (i_ehdr.e_phoff == 0 || i_ehdr.e_type != ET_CORE)
495 goto wrong;
496
497 /* Allocate space for copies of the program header table in external
498 and internal form, seek to the program header table in the file,
499 read it in, and convert it to internal form. As a simple sanity
500 check, verify that the what BFD thinks is the size of each program
501 header table entry actually matches the size recorded in the file. */
502
503 if (i_ehdr.e_phentsize != sizeof (*x_phdr))
504 goto wrong;
505 if ((x_phdr = (Elf_External_Phdr *)
506 bfd_alloc (abfd, sizeof (*x_phdr) * i_ehdr.e_phnum)) == NULL)
507 {
508 bfd_error = no_memory;
509 return (NULL);
510 }
511 if ((i_phdr = (Elf_Internal_Phdr *)
512 bfd_alloc (abfd, sizeof (*i_phdr) * i_ehdr.e_phnum)) == NULL)
513 {
514 bfd_error = no_memory;
515 return (NULL);
516 }
517 if (bfd_seek (abfd, i_ehdr.e_phoff, SEEK_SET) == -1)
518 {
519 bfd_error = system_call_error;
520 return (NULL);
521 }
522 for (phindex = 0; phindex < i_ehdr.e_phnum; phindex++)
523 {
524 if (bfd_read ((PTR) (x_phdr + phindex), sizeof (*x_phdr), 1, abfd)
525 != sizeof (*x_phdr))
526 {
527 bfd_error = system_call_error;
528 return (NULL);
529 }
530 bfd_swap_phdr_in (abfd, x_phdr + phindex, i_phdr + phindex);
531 }
532
533 /* Once all of the program headers have been read and converted, we
534 can start processing them. */
535
536 for (phindex = 0; phindex < i_ehdr.e_phnum; phindex++)
537 {
538 bfd_section_from_phdr (abfd, i_phdr + phindex, phindex);
539 }
540
541 return (abfd->xvec);
542 }
543
544 static boolean
545 DEFUN (elf_mkobject, (abfd), bfd *abfd)
546 {
547 fprintf (stderr, "elf_mkobject unimplemented\n");
548 fflush (stderr);
549 abort ();
550 return (false);
551 }
552
553 static boolean
554 DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
555 {
556 fprintf (stderr, "elf_write_object_contents unimplemented\n");
557 fflush (stderr);
558 abort ();
559 return (false);
560 }
561
562 static unsigned int
563 elf_get_symtab_upper_bound(abfd)
564 bfd *abfd;
565 {
566 fprintf (stderr, "elf_get_symtab_upper_bound unimplemented\n");
567 fflush (stderr);
568 abort ();
569 return (0);
570 }
571
572 static unsigned int
573 elf_get_reloc_upper_bound (abfd, asect)
574 bfd *abfd;
575 sec_ptr asect;
576 {
577 fprintf (stderr, "elf_get_reloc_upper_bound unimplemented\n");
578 fflush (stderr);
579 abort ();
580 return (0);
581 }
582
583 static unsigned int
584 elf_canonicalize_reloc (abfd, section, relptr, symbols)
585 bfd *abfd;
586 sec_ptr section;
587 arelent **relptr;
588 asymbol **symbols;
589 {
590 fprintf (stderr, "elf_canonicalize_reloc unimplemented\n");
591 fflush (stderr);
592 abort ();
593 return (0);
594 }
595
596 static unsigned int
597 elf_get_symtab (abfd, alocation)
598 bfd *abfd;
599 asymbol **alocation;
600 {
601 fprintf (stderr, "elf_get_symtab unimplemented\n");
602 fflush (stderr);
603 abort ();
604 return (0);
605 }
606
607 static asymbol *
608 elf_make_empty_symbol(abfd)
609 bfd *abfd;
610 {
611 fprintf (stderr, "elf_make_empty_symbol unimplemented\n");
612 fflush (stderr);
613 abort ();
614 return (NULL);
615 }
616
617 static void
618 DEFUN (elf_print_symbol,(ignore_abfd, filep, symbol, how),
619 bfd *ignore_abfd AND
620 PTR filep AND
621 asymbol *symbol AND
622 bfd_print_symbol_type how)
623 {
624 fprintf (stderr, "elf_print_symbol unimplemented\n");
625 fflush (stderr);
626 abort ();
627 }
628
629 static alent *
630 DEFUN (elf_get_lineno,(ignore_abfd, symbol),
631 bfd *ignore_abfd AND
632 asymbol *symbol)
633 {
634 fprintf (stderr, "elf_get_lineno unimplemented\n");
635 fflush (stderr);
636 abort ();
637 return (NULL);
638 }
639
640 static boolean
641 DEFUN (elf_set_arch_mach,(abfd, arch, machine),
642 bfd *abfd AND
643 enum bfd_architecture arch AND
644 unsigned long machine)
645 {
646 fprintf (stderr, "elf_set_arch_mach unimplemented\n");
647 fflush (stderr);
648 /* Allow any architecture to be supported by the elf backend */
649 return bfd_default_set_arch_mach(abfd, arch, machine);
650 }
651
652 static boolean
653 DEFUN (elf_find_nearest_line,(abfd,
654 section,
655 symbols,
656 offset,
657 filename_ptr,
658 functionname_ptr,
659 line_ptr),
660 bfd *abfd AND
661 asection *section AND
662 asymbol **symbols AND
663 bfd_vma offset AND
664 CONST char **filename_ptr AND
665 CONST char **functionname_ptr AND
666 unsigned int *line_ptr)
667 {
668 fprintf (stderr, "elf_find_nearest_line unimplemented\n");
669 fflush (stderr);
670 abort ();
671 return (false);
672 }
673
674 static int
675 DEFUN (elf_sizeof_headers, (abfd, reloc),
676 bfd *abfd AND
677 boolean reloc)
678 {
679 fprintf (stderr, "elf_sizeof_headers unimplemented\n");
680 fflush (stderr);
681 abort ();
682 return (0);
683 }
684 \f
685 /* This structure contains everything that BFD knows about a target.
686 It includes things like its byte order, name, what routines to call
687 to do various operations, etc. Every BFD points to a target structure
688 with its "xvec" member.
689
690 There are two such structures here: one for big-endian machines and
691 one for little-endian machines. */
692
693 #define elf_core_file_failing_command _bfd_dummy_core_file_failing_command
694 #define elf_core_file_failing_signal _bfd_dummy_core_file_failing_signal
695 #define elf_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
696
697 /* Archives are generic or unimplemented. */
698 #define elf_slurp_armap bfd_false
699 #define elf_slurp_extended_name_table _bfd_slurp_extended_name_table
700 #define elf_truncate_arname bfd_dont_truncate_arname
701 #define elf_openr_next_archived_file bfd_generic_openr_next_archived_file
702 #define elf_generic_stat_arch_elt bfd_generic_stat_arch_elt
703 #define elf_write_armap (PROTO (boolean, (*), \
704 (bfd *arch, unsigned int elength, struct orl *map, int orl_count, \
705 int stridx))) bfd_false
706
707 /* Ordinary section reading and writing */
708 #define elf_new_section_hook _bfd_dummy_new_section_hook
709 #define elf_get_section_contents bfd_generic_get_section_contents
710 #define elf_set_section_contents bfd_generic_set_section_contents
711 #define elf_close_and_cleanup bfd_generic_close_and_cleanup
712
713 #define elf_bfd_debug_info_start bfd_void
714 #define elf_bfd_debug_info_end bfd_void
715 #define elf_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
716
717 bfd_target elf_big_vec =
718 {
719 /* name: identify kind of target */
720 "elf-big",
721
722 /* flavour: general indication about file */
723 bfd_target_elf_flavour,
724
725 /* byteorder_big_p: data is big endian */
726 true,
727
728 /* header_byteorder_big_p: header is also big endian */
729 true,
730
731 /* object_flags: mask of all file flags */
732 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
733 DYNAMIC | WP_TEXT),
734
735 /* section_flags: mask of all section flags */
736 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
737 SEC_DATA),
738
739 /* ar_pad_char: pad character for filenames within an archive header
740 FIXME: this really has nothing to do with ELF, this is a characteristic
741 of the archiver and/or os and should be independently tunable */
742 '/',
743
744 /* ar_max_namelen: maximum number of characters in an archive header
745 FIXME: this really has nothing to do with ELF, this is a characteristic
746 of the archiver and should be independently tunable. This value is
747 a WAG (wild a** guess) */
748 15,
749
750 /* align_power_min: minimum alignment restriction for any section
751 FIXME: this value may be target machine dependent */
752 3,
753
754 /* Routines to byte-swap various sized integers from the data sections */
755 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
756
757 /* Routines to byte-swap various sized integers from the file headers */
758 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
759
760 /* bfd_check_format: check the format of a file being read */
761 { _bfd_dummy_target, /* unknown format */
762 elf_object_p, /* assembler/linker output (object file) */
763 bfd_generic_archive_p, /* an archive */
764 elf_core_file_p /* a core file */
765 },
766
767 /* bfd_set_format: set the format of a file being written */
768 { bfd_false,
769 elf_mkobject,
770 _bfd_generic_mkarchive,
771 bfd_false
772 },
773
774 /* bfd_write_contents: write cached information into a file being written */
775 { bfd_false,
776 elf_write_object_contents,
777 _bfd_write_archive_contents,
778 bfd_false
779 },
780
781 /* Initialize a jump table with the standard macro. All names start
782 with "elf" */
783 JUMP_TABLE(elf),
784
785 /* SWAP_TABLE */
786 NULL, NULL, NULL
787 };
788
789 bfd_target elf_little_vec =
790 {
791 /* name: identify kind of target */
792 "elf-little",
793
794 /* flavour: general indication about file */
795 bfd_target_elf_flavour,
796
797 /* byteorder_big_p: data is big endian */
798 false, /* Nope -- this one's little endian */
799
800 /* header_byteorder_big_p: header is also big endian */
801 false, /* Nope -- this one's little endian */
802
803 /* object_flags: mask of all file flags */
804 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
805 DYNAMIC | WP_TEXT),
806
807 /* section_flags: mask of all section flags */
808 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
809 SEC_DATA),
810
811 /* ar_pad_char: pad character for filenames within an archive header
812 FIXME: this really has nothing to do with ELF, this is a characteristic
813 of the archiver and/or os and should be independently tunable */
814 '/',
815
816 /* ar_max_namelen: maximum number of characters in an archive header
817 FIXME: this really has nothing to do with ELF, this is a characteristic
818 of the archiver and should be independently tunable. This value is
819 a WAG (wild a** guess) */
820 15,
821
822 /* align_power_min: minimum alignment restriction for any section
823 FIXME: this value may be target machine dependent */
824 3,
825
826 /* Routines to byte-swap various sized integers from the data sections */
827 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
828
829 /* Routines to byte-swap various sized integers from the file headers */
830 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
831
832 /* bfd_check_format: check the format of a file being read */
833 { _bfd_dummy_target, /* unknown format */
834 elf_object_p, /* assembler/linker output (object file) */
835 bfd_generic_archive_p, /* an archive */
836 elf_core_file_p /* a core file */
837 },
838
839 /* bfd_set_format: set the format of a file being written */
840 { bfd_false,
841 elf_mkobject,
842 _bfd_generic_mkarchive,
843 bfd_false
844 },
845
846 /* bfd_write_contents: write cached information into a file being written */
847 { bfd_false,
848 elf_write_object_contents,
849 _bfd_write_archive_contents,
850 bfd_false
851 },
852
853 /* Initialize a jump table with the standard macro. All names start
854 with "elf" */
855 JUMP_TABLE(elf),
856
857 /* SWAP_TABLE */
858 NULL, NULL, NULL
859 };