* hosts/h-*.h: Configure fopen using ../include/fopen-*.h
[deliverable/binutils-gdb.git] / bfd / elf.c
CommitLineData
9ce0058c
SC
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
8This file is part of BFD, the Binary File Descriptor library.
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
9ce0058c 71#include "bfd.h"
e0796d22 72#include "sysdep.h"
9ce0058c
SC
73#include "libbfd.h"
74#include "obstack.h"
c3eb25fc
SC
75#include "elf/common.h"
76#include "elf/internal.h"
77#include "elf/external.h"
9ce0058c 78
8c4a1ace
JG
79#ifdef HAVE_PROCFS /* Some core file support requires host /proc files */
80#include <sys/procfs.h>
81#else
82#define bfd_prstatus(abfd, descdata, descsz, filepos) /* Define away */
83#define bfd_fpregset(abfd, descdata, descsz, filepos) /* Define away */
84#define bfd_prpsinfo(abfd, descdata, descsz, filepos) /* Define away */
85#endif
86
9ce0058c 87/* Forward data declarations */
8c4a1ace 88
9ce0058c
SC
89extern bfd_target elf_little_vec, elf_big_vec;
90
8c4a1ace
JG
91/* Currently the elf_symbol_type struct just contains the generic bfd
92 symbol structure. */
93
94typedef struct
95{
96 asymbol symbol;
97} elf_symbol_type;
98
99/* Some private data is stashed away for future use using the tdata pointer
100 in the bfd structure. This information is different for ELF core files
101 and other ELF files. */
102
103typedef struct
104{
105 void *prstatus; /* The raw /proc prstatus structure */
106 void *prpsinfo; /* The raw /proc prpsinfo structure */
107} elf_core_tdata;
108
109#define core_prpsinfo(bfd) (((elf_core_tdata *)((bfd)->tdata))->prpsinfo)
110#define core_prstatus(bfd) (((elf_core_tdata *)((bfd)->tdata))->prstatus)
111
112typedef struct
113{
114 file_ptr symtab_filepos; /* Offset to start of ELF symtab section */
115 long symtab_filesz; /* Size of ELF symtab section */
116 file_ptr strtab_filepos; /* Offset to start of ELF string tbl section */
117 long strtab_filesz; /* Size of ELF string tbl section */
118} elf_obj_tdata;
119
120#define elf_tdata(bfd) ((elf_obj_tdata *) ((bfd) -> tdata))
121#define elf_symtab_filepos(bfd) (elf_tdata(bfd) -> symtab_filepos)
122#define elf_symtab_filesz(bfd) (elf_tdata(bfd) -> symtab_filesz)
123#define elf_strtab_filepos(bfd) (elf_tdata(bfd) -> strtab_filepos)
124#define elf_strtab_filesz(bfd) (elf_tdata(bfd) -> strtab_filesz)
125
126/* Translate an ELF symbol in external format into an ELF symbol in internal
127 format. */
128
129static void
130DEFUN(elf_swap_symbol_in,(abfd, src, dst),
131 bfd *abfd AND
132 Elf_External_Sym *src AND
133 Elf_Internal_Sym *dst)
134{
135 dst -> st_name = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_name);
136 dst -> st_value = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_value);
137 dst -> st_size = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_size);
138 dst -> st_info = bfd_h_get_8 (abfd, (bfd_byte *) src -> st_info);
139 dst -> st_other = bfd_h_get_8 (abfd, (bfd_byte *) src -> st_other);
140 dst -> st_shndx = bfd_h_get_16 (abfd, (bfd_byte *) src -> st_shndx);
141}
142
143
9ce0058c
SC
144/* Translate an ELF header in external format into an ELF header in internal
145 format. */
146
147static void
8c4a1ace 148DEFUN(elf_swap_ehdr_in,(abfd, src, dst),
9ce0058c
SC
149 bfd *abfd AND
150 Elf_External_Ehdr *src AND
151 Elf_Internal_Ehdr *dst)
152{
153 bcopy (src -> e_ident, dst -> e_ident, EI_NIDENT);
154 dst -> e_type = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_type);
155 dst -> e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_machine);
156 dst -> e_version = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_version);
157 dst -> e_entry = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_entry);
158 dst -> e_phoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_phoff);
159 dst -> e_shoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_shoff);
160 dst -> e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_flags);
161 dst -> e_ehsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_ehsize);
162 dst -> e_phentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phentsize);
163 dst -> e_phnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phnum);
164 dst -> e_shentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shentsize);
165 dst -> e_shnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shnum);
166 dst -> e_shstrndx = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shstrndx);
167}
168
169
170/* Translate an ELF section header table entry in external format into an
171 ELF section header table entry in internal format. */
172
173static void
8c4a1ace 174DEFUN(elf_swap_shdr_in,(abfd, src, dst),
9ce0058c
SC
175 bfd *abfd AND
176 Elf_External_Shdr *src AND
177 Elf_Internal_Shdr *dst)
178{
179 dst -> sh_name = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_name);
180 dst -> sh_type = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_type);
181 dst -> sh_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_flags);
182 dst -> sh_addr = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_addr);
183 dst -> sh_offset = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_offset);
184 dst -> sh_size = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_size);
185 dst -> sh_link = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_link);
186 dst -> sh_info = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_info);
187 dst -> sh_addralign = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_addralign);
188 dst -> sh_entsize = bfd_h_get_32 (abfd, (bfd_byte *) src -> sh_entsize);
189}
190
191
e0796d22
FF
192/* Translate an ELF program header table entry in external format into an
193 ELF program header table entry in internal format. */
194
195static void
8c4a1ace 196DEFUN(elf_swap_phdr_in,(abfd, src, dst),
e0796d22
FF
197 bfd *abfd AND
198 Elf_External_Phdr *src AND
199 Elf_Internal_Phdr *dst)
200{
201 dst -> p_type = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_type);
202 dst -> p_offset = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_offset);
203 dst -> p_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_vaddr);
204 dst -> p_paddr = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_paddr);
205 dst -> p_filesz = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_filesz);
206 dst -> p_memsz = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_memsz);
207 dst -> p_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_flags);
208 dst -> p_align = bfd_h_get_32 (abfd, (bfd_byte *) src -> p_align);
209}
210
211
9ce0058c
SC
212/* Create a new bfd section from an ELF section header. */
213
214static boolean
215DEFUN(bfd_section_from_shdr, (abfd, hdr, shstrtab),
216 bfd *abfd AND
217 Elf_Internal_Shdr *hdr AND
218 char *shstrtab)
219{
220 asection *newsect;
221 char *name;
222
223 name = hdr -> sh_name ? shstrtab + hdr -> sh_name : "unnamed";
224 newsect = bfd_make_section (abfd, name);
225 newsect -> vma = hdr -> sh_addr;
226 newsect -> size = hdr -> sh_size;
227 if (!(hdr -> sh_type == SHT_NOBITS))
228 {
229 newsect -> filepos = hdr -> sh_offset;
230 newsect -> flags |= SEC_HAS_CONTENTS;
231 }
232 if (hdr -> sh_flags & SHF_ALLOC)
233 {
234 newsect -> flags |= SEC_ALLOC;
235 if (hdr -> sh_type != SHT_NOBITS)
236 {
237 newsect -> flags |= SEC_LOAD;
238 }
239 }
240 if (!(hdr -> sh_flags & SHF_WRITE))
241 {
242 newsect -> flags |= SEC_READONLY;
243 }
244 if (hdr -> sh_flags & SHF_EXECINSTR)
245 {
246 newsect -> flags |= SEC_CODE; /* FIXME: may only contain SOME code */
247 }
248 if (hdr -> sh_type == SHT_SYMTAB)
249 {
250 abfd -> flags |= HAS_SYMS;
251 }
252
253 return (true);
254}
255
e0796d22
FF
256/* Create a new bfd section from an ELF program header.
257
258 Since program segments have no names, we generate a synthetic name
259 of the form segment<NUM>, where NUM is generally the index in the
260 program header table. For segments that are split (see below) we
261 generate the names segment<NUM>a and segment<NUM>b.
262
263 Note that some program segments may have a file size that is different than
264 (less than) the memory size. All this means is that at execution the
265 system must allocate the amount of memory specified by the memory size,
266 but only initialize it with the first "file size" bytes read from the
267 file. This would occur for example, with program segments consisting
268 of combined data+bss.
269
270 To handle the above situation, this routine generates TWO bfd sections
271 for the single program segment. The first has the length specified by
272 the file size of the segment, and the second has the length specified
273 by the difference between the two sizes. In effect, the segment is split
274 into it's initialized and uninitialized parts.
275
276 */
277
278static boolean
279DEFUN(bfd_section_from_phdr, (abfd, hdr, index),
280 bfd *abfd AND
281 Elf_Internal_Phdr *hdr AND
282 int index)
283{
284 asection *newsect;
285 char *name;
286 char namebuf[64];
287 int split;
288
289 split = ((hdr -> p_memsz > 0) &&
290 (hdr -> p_filesz > 0) &&
291 (hdr -> p_memsz > hdr -> p_filesz));
292 sprintf (namebuf, split ? "segment%da" : "segment%d", index);
293 name = bfd_alloc (abfd, strlen (namebuf) + 1);
294 (void) strcpy (name, namebuf);
295 newsect = bfd_make_section (abfd, name);
296 newsect -> vma = hdr -> p_vaddr;
297 newsect -> size = hdr -> p_filesz;
298 newsect -> filepos = hdr -> p_offset;
299 newsect -> flags |= SEC_HAS_CONTENTS;
300 if (hdr -> p_type == PT_LOAD)
301 {
302 newsect -> flags |= SEC_ALLOC;
303 newsect -> flags |= SEC_LOAD;
304 if (hdr -> p_flags & PF_X)
305 {
306 /* FIXME: all we known is that it has execute PERMISSION,
307 may be data. */
308 newsect -> flags |= SEC_CODE;
309 }
310 }
311 if (!(hdr -> p_flags & PF_W))
312 {
313 newsect -> flags |= SEC_READONLY;
314 }
315
316 if (split)
317 {
318 sprintf (namebuf, "segment%db", index);
319 name = bfd_alloc (abfd, strlen (namebuf) + 1);
320 (void) strcpy (name, namebuf);
321 newsect = bfd_make_section (abfd, name);
322 newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz;
323 newsect -> size = hdr -> p_memsz - hdr -> p_filesz;
324 if (hdr -> p_type == PT_LOAD)
325 {
326 newsect -> flags |= SEC_ALLOC;
327 if (hdr -> p_flags & PF_X)
328 {
329 newsect -> flags |= SEC_CODE;
330 }
331 }
332 if (!(hdr -> p_flags & PF_W))
333 {
334 newsect -> flags |= SEC_READONLY;
335 }
336 }
337
338 return (true);
339}
340
8c4a1ace
JG
341#ifdef HAVE_PROCFS
342
343static void
344DEFUN(bfd_prstatus,(abfd, descdata, descsz, filepos),
345 bfd *abfd AND
346 char *descdata AND
347 int descsz AND
348 long filepos)
349{
350 asection *newsect;
351
352 if (descsz == sizeof (prstatus_t))
353 {
354 newsect = bfd_make_section (abfd, ".reg");
355 newsect -> size = sizeof (gregset_t);
356 newsect -> filepos = filepos + (long) (((prstatus_t *)0) -> pr_reg);
357 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
358 newsect -> alignment_power = 2;
359 if ((core_prstatus (abfd) = bfd_alloc (abfd, descsz)) != NULL)
360 {
361 bcopy (descdata, core_prstatus (abfd), descsz);
362 }
363 }
364}
365
366/* Stash a copy of the prpsinfo structure away for future use. */
367
368static void
369DEFUN(bfd_prpsinfo,(abfd, descdata, descsz, filepos),
370 bfd *abfd AND
371 char *descdata AND
372 int descsz AND
373 long filepos)
374{
375 asection *newsect;
376
377 if (descsz == sizeof (prpsinfo_t))
378 {
379 if ((core_prpsinfo (abfd) = bfd_alloc (abfd, descsz)) != NULL)
380 {
381 bcopy (descdata, core_prpsinfo (abfd), descsz);
382 }
383 }
384}
385
386static void
387DEFUN(bfd_fpregset,(abfd, descdata, descsz, filepos),
388 bfd *abfd AND
389 char *descdata AND
390 int descsz AND
391 long filepos)
392{
393 asection *newsect;
394
395 if (descsz == sizeof (fpregset_t))
396 {
397 newsect = bfd_make_section (abfd, ".reg2");
398 newsect -> size = sizeof (fpregset_t);
399 newsect -> filepos = filepos;
400 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
401 newsect -> alignment_power = 2;
402 }
403}
404
405#endif /* HAVE_PROCFS */
406
407/* Return a pointer to the args (including the command name) that were
408 seen by the program that generated the core dump. Note that for
409 some reason, a spurious space is tacked onto the end of the args
410 in some (at least one anyway) implementations, so strip it off if
411 it exists. */
412
413char *
414DEFUN(elf_core_file_failing_command, (abfd),
415 bfd *abfd)
416{
417#if HAVE_PROCFS
418 if (core_prpsinfo (abfd))
419 {
420 prpsinfo_t *p = core_prpsinfo (abfd);
421 char *scan = p -> pr_psargs;
422 while (*scan++) {;}
423 scan -= 2;
424 if ((scan > p -> pr_psargs) && (*scan == ' '))
425 {
426 *scan = '\000';
427 }
428 return (p -> pr_psargs);
429 }
430#endif
431 return (NULL);
432}
433
434/* Return the number of the signal that caused the core dump. Presumably,
435 since we have a core file, we got a signal of some kind, so don't bother
436 checking the other process status fields, just return the signal number.
437 */
438
439static int
440DEFUN(elf_core_file_failing_signal, (abfd),
441 bfd *abfd)
442{
443#if HAVE_PROCFS
444 if (core_prstatus (abfd))
445 {
446 return (((prstatus_t *)(core_prstatus (abfd))) -> pr_cursig);
447 }
448#endif
449 return (-1);
450}
451
452/* Check to see if the core file could reasonably be expected to have
453 come for the current executable file. Note that by default we return
454 true unless we find something that indicates that there might be a
455 problem.
456 */
457
458static boolean
459DEFUN(elf_core_file_matches_executable_p, (core_bfd, exec_bfd),
460 bfd *core_bfd AND
461 bfd *exec_bfd)
462{
463 char *corename;
464 char *execname;
465
466 /* First, xvecs must match since both are ELF files for the same target. */
467
468 if (core_bfd->xvec != exec_bfd->xvec)
469 {
470 bfd_error = system_call_error;
471 return (false);
472 }
473
474#if HAVE_PROCFS
475
476 /* If no prpsinfo, just return true. Otherwise, grab the last component
477 of the exec'd pathname from the prpsinfo. */
478
479 if (core_prpsinfo (core_bfd))
480 {
481 corename = (((struct prpsinfo *) core_prpsinfo (core_bfd)) -> pr_fname);
482 }
483 else
484 {
485 return (true);
486 }
487
488 /* Find the last component of the executable pathname. */
489
490 if ((execname = strrchr (exec_bfd -> filename, '/')) != NULL)
491 {
492 execname++;
493 }
494 else
495 {
496 execname = (char *) exec_bfd -> filename;
497 }
498
499 /* See if they match */
500
501 return (strcmp (execname, corename) ? false : true);
502
503#else
504
505 return (true);
506
507#endif /* HAVE_PROCFS */
508}
509
510/* ELF core files contain a segment of type PT_NOTE, that holds much of
511 the information that would normally be available from the /proc interface
512 for the process, at the time the process dumped core. Currently this
513 includes copies of the prstatus, prpsinfo, and fpregset structures.
514
515 Since these structures are potentially machine dependent in size and
516 ordering, bfd provides two levels of support for them. The first level,
517 available on all machines since it does not require that the host
518 have /proc support or the relevant include files, is to create a bfd
519 section for each of the prstatus, prpsinfo, and fpregset structures,
520 without any interpretation of their contents. With just this support,
521 the bfd client will have to interpret the structures itself. Even with
522 /proc support, it might want these full structures for it's own reasons.
523
524 In the second level of support, where HAVE_PROCFS is defined, bfd will
525 pick apart the structures to gather some additional information that
526 clients may want, such as the general register set, the name of the
527 exec'ed file and its arguments, the signal (if any) that caused the
528 core dump, etc.
529
530 */
531
532static boolean
533DEFUN(elf_corefile_note, (abfd, hdr),
534 bfd *abfd AND
535 Elf_Internal_Phdr *hdr)
536{
537 Elf_External_Note *x_note_p; /* Elf note, external form */
538 Elf_Internal_Note i_note; /* Elf note, internal form */
539 char *buf = NULL; /* Entire note segment contents */
540 char *namedata; /* Name portion of the note */
541 char *descdata; /* Descriptor portion of the note */
542 char *sectname; /* Name to use for new section */
543 long filepos; /* File offset to descriptor data */
544 asection *newsect;
545
546 if (hdr -> p_filesz > 0
547 && (buf = malloc (hdr -> p_filesz)) != NULL
548 && bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1L
549 && bfd_read ((PTR) buf, hdr -> p_filesz, 1, abfd) == hdr -> p_filesz)
550 {
551 x_note_p = (Elf_External_Note *) buf;
552 while ((char *) x_note_p < (buf + hdr -> p_filesz))
553 {
554 i_note.namesz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> namesz);
555 i_note.descsz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> descsz);
556 i_note.type = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> type);
557 namedata = x_note_p -> name;
558 descdata = namedata + BFD_ALIGN (i_note.namesz, 4);
559 filepos = hdr -> p_offset + (descdata - buf);
560 switch (i_note.type) {
561 case NT_PRSTATUS:
562 /* process descdata as prstatus info */
563 bfd_prstatus (abfd, descdata, i_note.descsz, filepos);
564 sectname = ".prstatus";
565 break;
566 case NT_FPREGSET:
567 /* process descdata as fpregset info */
568 bfd_fpregset (abfd, descdata, i_note.descsz, filepos);
569 sectname = ".fpregset";
570 break;
571 case NT_PRPSINFO:
572 /* process descdata as prpsinfo */
573 bfd_prpsinfo (abfd, descdata, i_note.descsz, filepos);
574 sectname = ".prpsinfo";
575 break;
576 default:
577 /* Unknown descriptor, just ignore it. */
578 sectname = NULL;
579 break;
580 }
581 if (sectname != NULL)
582 {
583 newsect = bfd_make_section (abfd, sectname);
584 newsect -> size = i_note.descsz;
585 newsect -> filepos = filepos;
586 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
587 newsect -> alignment_power = 2;
588 }
589 x_note_p = (Elf_External_Note *)
590 (descdata + BFD_ALIGN (i_note.descsz, 4));
591 }
592 }
593 if (buf != NULL)
594 {
595 free (buf);
596 }
597}
598
599
9ce0058c
SC
600/* Begin processing a given object.
601
602 First we validate the file by reading in the ELF header and checking
603 the magic number.
604
605 */
606
607static bfd_target *
608DEFUN (elf_object_p, (abfd), bfd *abfd)
609{
610 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
611 Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
612 Elf_External_Shdr *x_shdr; /* Section header table, external form */
613 Elf_Internal_Shdr *i_shdr; /* Section header table, internal form */
614 int shindex;
615 char *shstrtab; /* Internal copy of section header stringtab */
616 int shstrtabsize; /* Size of section header string table */
617
618 /* Read in the ELF header in external format. */
619
620 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
621 {
622 bfd_error = system_call_error;
623 return (NULL);
624 }
625
626 /* Now check to see if we have a valid ELF file, and one that BFD can
627 make use of. The magic number must match, the address size ('class')
628 and byte-swapping must match our XVEC entry, and it must have a
629 section header table (FIXME: See comments re sections at top of this
630 file). */
631
632 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
633 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
634 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
635 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
636 {
637wrong:
638 bfd_error = wrong_format;
639 return (NULL);
640 }
641
642 /* FIXME, Check EI_VERSION here ! */
643
644 switch (x_ehdr.e_ident[EI_CLASS]) {
645 case ELFCLASSNONE: /* address size not specified */
646 goto wrong; /* No support if can't tell address size */
647 case ELFCLASS32: /* 32-bit addresses */
648 break;
649 case ELFCLASS64: /* 64-bit addresses */
650 goto wrong; /* FIXME: 64 bits not yet supported */
651 default:
652 goto wrong; /* No support if unknown address class */
653 }
654
655 /* Switch xvec to match the specified byte order. */
656 switch (x_ehdr.e_ident[EI_DATA]) {
657 case ELFDATA2MSB: /* Big-endian */
658 abfd->xvec = &elf_big_vec;
659 break;
660 case ELFDATA2LSB: /* Little-endian */
661 abfd->xvec = &elf_little_vec;
eb8983c9 662 break;
9ce0058c
SC
663 case ELFDATANONE: /* No data encoding specified */
664 default: /* Unknown data encoding specified */
665 goto wrong;
666 }
667
8c4a1ace
JG
668 /* Allocate an instance of the elf_obj_tdata structure and hook it up to
669 the tdata pointer in the bfd. */
670
671 if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_obj_tdata))) == NULL)
672 {
673 bfd_error = no_memory;
674 return (NULL);
675 }
676
9ce0058c 677 /* Now that we know the byte order, swap in the rest of the header */
8c4a1ace 678 elf_swap_ehdr_in (abfd, &x_ehdr, &i_ehdr);
e0796d22
FF
679
680 /* If there is no section header table, we're hosed. */
681 if (i_ehdr.e_shoff == 0)
9ce0058c
SC
682 goto wrong;
683
684 if (i_ehdr.e_type == ET_EXEC || i_ehdr.e_type == ET_DYN)
685 {
686 abfd -> flags |= EXEC_P;
687 }
688
689 /* Allocate space for copies of the section header table in external
690 and internal form, seek to the section header table in the file,
691 read it in, and convert it to internal form. As a simple sanity
692 check, verify that the what BFD thinks is the size of each section
693 header table entry actually matches the size recorded in the file. */
694
695 if (i_ehdr.e_shentsize != sizeof (*x_shdr))
696 goto wrong;
697 if ((x_shdr = (Elf_External_Shdr *)
698 bfd_alloc (abfd, sizeof (*x_shdr) * i_ehdr.e_shnum)) == NULL)
699 {
700 bfd_error = no_memory;
701 return (NULL);
702 }
703 if ((i_shdr = (Elf_Internal_Shdr *)
704 bfd_alloc (abfd, sizeof (*i_shdr) * i_ehdr.e_shnum)) == NULL)
705 {
706 bfd_error = no_memory;
707 return (NULL);
708 }
709 if (bfd_seek (abfd, i_ehdr.e_shoff, SEEK_SET) == -1)
710 {
711 bfd_error = system_call_error;
712 return (NULL);
713 }
714 for (shindex = 0; shindex < i_ehdr.e_shnum; shindex++)
715 {
716 if (bfd_read ((PTR) (x_shdr + shindex), sizeof (*x_shdr), 1, abfd)
717 != sizeof (*x_shdr))
718 {
719 bfd_error = system_call_error;
720 return (NULL);
721 }
8c4a1ace 722 elf_swap_shdr_in (abfd, x_shdr + shindex, i_shdr + shindex);
9ce0058c
SC
723 }
724
725 /* Read in the string table containing the names of the sections. We
726 will need the base pointer to this table later. */
727
728 shstrtabsize = i_shdr[i_ehdr.e_shstrndx].sh_size;
729 if ((shstrtab = bfd_alloc (abfd, shstrtabsize)) == NULL)
730 {
731 bfd_error = no_memory;
732 return (NULL);
733 }
734 if (bfd_seek (abfd, i_shdr[i_ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1)
735 {
736 bfd_error = system_call_error;
737 return (NULL);
738 }
739 if (bfd_read ((PTR) shstrtab, shstrtabsize, 1, abfd) != shstrtabsize)
740 {
741 bfd_error = system_call_error;
742 return (NULL);
743 }
744
745 /* Once all of the section headers have been read and converted, we
a6c1d731 746 can start processing them. Note that the first section header is
8c4a1ace
JG
747 a dummy placeholder entry, so we ignore it.
748
749 We also watch for the symbol table section and remember the file
750 offset and section size for both the symbol table section and the
751 associated string table section. */
9ce0058c 752
a6c1d731 753 for (shindex = 1; shindex < i_ehdr.e_shnum; shindex++)
9ce0058c 754 {
8c4a1ace
JG
755 Elf_Internal_Shdr *hdr = i_shdr + shindex;
756 bfd_section_from_shdr (abfd, hdr, shstrtab);
757 if (hdr -> sh_type == SHT_SYMTAB)
758 {
759 elf_symtab_filepos(abfd) = hdr -> sh_offset;
760 elf_symtab_filesz(abfd) = hdr -> sh_size;
761 elf_strtab_filepos(abfd) = (i_shdr + hdr -> sh_link) -> sh_offset;
762 elf_strtab_filesz(abfd) = (i_shdr + hdr -> sh_link) -> sh_size;
763 }
9ce0058c
SC
764 }
765
766 return (abfd->xvec);
767}
768
e0796d22
FF
769/* Core files are simply standard ELF formatted files that partition
770 the file using the execution view of the file (program header table)
771 rather than the linking view. In fact, there is no section header
772 table in a core file.
8c4a1ace
JG
773
774 The process status information (including the contents of the general
775 register set) and the floating point register set are stored in a
776 segment of type PT_NOTE. We handcraft a couple of extra bfd sections
777 that allow standard bfd access to the general registers (.reg) and the
778 floating point registers (.reg2).
779
e0796d22
FF
780 */
781
782static bfd_target *
783DEFUN (elf_core_file_p, (abfd), bfd *abfd)
784{
785 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
786 Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
787 Elf_External_Phdr *x_phdr; /* Program header table, external form */
788 Elf_Internal_Phdr *i_phdr; /* Program header table, internal form */
789 int phindex;
790
791 /* Read in the ELF header in external format. */
792
793 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
794 {
795 bfd_error = system_call_error;
796 return (NULL);
797 }
798
799 /* Now check to see if we have a valid ELF file, and one that BFD can
800 make use of. The magic number must match, the address size ('class')
801 and byte-swapping must match our XVEC entry, and it must have a
802 program header table (FIXME: See comments re segments at top of this
803 file). */
804
805 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
806 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
807 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
808 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
809 {
810wrong:
811 bfd_error = wrong_format;
812 return (NULL);
813 }
814
815 /* FIXME, Check EI_VERSION here ! */
816
817 switch (x_ehdr.e_ident[EI_CLASS]) {
818 case ELFCLASSNONE: /* address size not specified */
819 goto wrong; /* No support if can't tell address size */
820 case ELFCLASS32: /* 32-bit addresses */
821 break;
822 case ELFCLASS64: /* 64-bit addresses */
823 goto wrong; /* FIXME: 64 bits not yet supported */
824 default:
825 goto wrong; /* No support if unknown address class */
826 }
827
828 /* Switch xvec to match the specified byte order. */
829 switch (x_ehdr.e_ident[EI_DATA]) {
830 case ELFDATA2MSB: /* Big-endian */
831 abfd->xvec = &elf_big_vec;
832 break;
833 case ELFDATA2LSB: /* Little-endian */
834 abfd->xvec = &elf_little_vec;
eb8983c9 835 break;
e0796d22
FF
836 case ELFDATANONE: /* No data encoding specified */
837 default: /* Unknown data encoding specified */
838 goto wrong;
839 }
840
841 /* Now that we know the byte order, swap in the rest of the header */
8c4a1ace 842 elf_swap_ehdr_in (abfd, &x_ehdr, &i_ehdr);
e0796d22
FF
843
844 /* If there is no program header, or the type is not a core file, then
845 we are hosed. */
846 if (i_ehdr.e_phoff == 0 || i_ehdr.e_type != ET_CORE)
847 goto wrong;
848
8c4a1ace
JG
849 /* Allocate an instance of the elf_core_tdata structure and hook it up to
850 the tdata pointer in the bfd. */
851
852 if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_core_tdata))) == NULL)
853 {
854 bfd_error = no_memory;
855 return (NULL);
856 }
857
e0796d22
FF
858 /* Allocate space for copies of the program header table in external
859 and internal form, seek to the program header table in the file,
860 read it in, and convert it to internal form. As a simple sanity
861 check, verify that the what BFD thinks is the size of each program
862 header table entry actually matches the size recorded in the file. */
863
864 if (i_ehdr.e_phentsize != sizeof (*x_phdr))
865 goto wrong;
866 if ((x_phdr = (Elf_External_Phdr *)
867 bfd_alloc (abfd, sizeof (*x_phdr) * i_ehdr.e_phnum)) == NULL)
868 {
869 bfd_error = no_memory;
870 return (NULL);
871 }
872 if ((i_phdr = (Elf_Internal_Phdr *)
873 bfd_alloc (abfd, sizeof (*i_phdr) * i_ehdr.e_phnum)) == NULL)
874 {
875 bfd_error = no_memory;
876 return (NULL);
877 }
878 if (bfd_seek (abfd, i_ehdr.e_phoff, SEEK_SET) == -1)
879 {
880 bfd_error = system_call_error;
881 return (NULL);
882 }
883 for (phindex = 0; phindex < i_ehdr.e_phnum; phindex++)
884 {
885 if (bfd_read ((PTR) (x_phdr + phindex), sizeof (*x_phdr), 1, abfd)
886 != sizeof (*x_phdr))
887 {
888 bfd_error = system_call_error;
889 return (NULL);
890 }
8c4a1ace 891 elf_swap_phdr_in (abfd, x_phdr + phindex, i_phdr + phindex);
e0796d22
FF
892 }
893
894 /* Once all of the program headers have been read and converted, we
895 can start processing them. */
896
897 for (phindex = 0; phindex < i_ehdr.e_phnum; phindex++)
898 {
899 bfd_section_from_phdr (abfd, i_phdr + phindex, phindex);
8c4a1ace
JG
900 if ((i_phdr + phindex) -> p_type == PT_NOTE)
901 {
902 elf_corefile_note (abfd, i_phdr + phindex);
903 }
e0796d22
FF
904 }
905
906 return (abfd->xvec);
907}
908
9ce0058c
SC
909static boolean
910DEFUN (elf_mkobject, (abfd), bfd *abfd)
911{
912 fprintf (stderr, "elf_mkobject unimplemented\n");
913 fflush (stderr);
914 abort ();
915 return (false);
916}
917
918static boolean
919DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
920{
921 fprintf (stderr, "elf_write_object_contents unimplemented\n");
922 fflush (stderr);
923 abort ();
924 return (false);
925}
926
8c4a1ace
JG
927/* Given an index of a section, retrieve a pointer to it. Note
928 that for our purposes, sections are indexed by {1, 2, ...} with
929 0 being an illegal index. */
930
931static struct sec *
932DEFUN (section_from_bfd_index, (abfd, index),
933 bfd *abfd AND
934 int index)
935{
936 if (index > 0)
937 {
938 struct sec *answer = abfd -> sections;
939 while (--index > 0)
940 {
941 answer = answer -> next;
942 }
943 return (answer);
944 }
945 return (NULL);
946}
947
948static boolean
949DEFUN (elf_slurp_symbol_table, (abfd), bfd *abfd)
950{
951 int symcount; /* Number of external ELF symbols */
952 char *strtab; /* Buffer for raw ELF string table section */
953 asymbol *sym; /* Pointer to current bfd symbol */
954 asymbol *symbase; /* Buffer for generated bfd symbols */
955 asymbol **vec; /* Pointer to current bfd symbol pointer */
956 Elf_Internal_Sym i_sym;
957 Elf_External_Sym x_sym;
958
959 if (bfd_get_outsymbols (abfd) != NULL)
960 {
961 return (true);
962 }
963
964 /* Slurp in the string table. We will keep it around permanently, as
965 long as the bfd is in use, since we will end up setting up pointers
966 into it for the names of all the symbols. */
967
968 if (bfd_seek (abfd, elf_strtab_filepos (abfd), SEEK_SET) == -1)
969 {
970 bfd_error = system_call_error;
971 return (false);
972 }
973 if ((strtab = bfd_alloc (abfd, elf_strtab_filesz (abfd))) == NULL)
974 {
975 bfd_error = system_call_error;
976 return (false);
977 }
978 if (bfd_read ((PTR) strtab, elf_strtab_filesz (abfd), 1, abfd) !=
979 elf_strtab_filesz (abfd))
980 {
981 bfd_error = system_call_error;
982 return (false);
983 }
984
985 /* Read each raw ELF symbol, converting from external ELF form to
986 internal ELF form, and then using the information to create a
987 canonical bfd symbol table entry.
988
989 Note that be allocate the initial bfd canonical symbol buffer
990 based on a one-to-one mapping of the ELF symbols to canonical
991 symbols. However, it is likely that not all the ELF symbols will
992 be used, so there will be some space leftover at the end. Once
993 we know how many symbols we actual generate, we realloc the buffer
994 to the correct size and then build the pointer vector. */
995
996 if (bfd_seek (abfd, elf_symtab_filepos (abfd), SEEK_SET) == -1)
997 {
998 bfd_error = system_call_error;
999 return (false);
1000 }
1001
1002 symcount = elf_symtab_filesz(abfd) / sizeof (Elf_External_Sym);
1003 sym = symbase = (asymbol *) bfd_zalloc (abfd, symcount * sizeof (asymbol));
1004
1005 while (symcount-- > 0)
1006 {
1007 if (bfd_read ((PTR) &x_sym, sizeof (x_sym), 1, abfd) != sizeof (x_sym))
1008 {
1009 bfd_error = system_call_error;
1010 return (false);
1011 }
1012 elf_swap_symbol_in (abfd, &x_sym, &i_sym);
1013 if (i_sym.st_name > 0)
1014 {
1015 sym -> the_bfd = abfd;
1016 sym -> name = strtab + i_sym.st_name;
1017 sym -> value = i_sym.st_value;
1018 if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERV)
1019 {
1020 /* Note: This code depends upon there being an ordered
1021 one-for-one mapping of ELF sections to bfd sections. */
1022 sym -> section = section_from_bfd_index (abfd, i_sym.st_shndx);
1023 }
1024 else if (i_sym.st_shndx == SHN_ABS)
1025 {
1026 sym -> flags |= BSF_ABSOLUTE;
1027 }
1028 else if (i_sym.st_shndx == SHN_COMMON)
1029 {
1030 sym -> flags |= BSF_FORT_COMM;
1031 }
1032 switch (ELF_ST_BIND (i_sym.st_info))
1033 {
1034 case STB_LOCAL:
1035 sym -> flags |= BSF_LOCAL;
1036 break;
1037 case STB_GLOBAL:
1038 sym -> flags |= (BSF_GLOBAL | BSF_EXPORT);
1039 break;
1040 case STB_WEAK:
1041 sym -> flags |= BSF_WEAK;
1042 break;
1043 }
1044 sym++;
1045 }
1046 }
1047
1048 bfd_get_symcount(abfd) = symcount = sym - symbase;
1049 sym = symbase = (asymbol *)
1050 bfd_realloc (abfd, symbase, symcount * sizeof (asymbol));
1051 bfd_get_outsymbols(abfd) = vec = (asymbol **)
1052 bfd_alloc (abfd, symcount * sizeof (asymbol *));
1053
1054 while (symcount-- > 0)
1055 {
1056 *vec++ = sym++;
1057 }
1058
1059 return (true);
1060}
1061
1062/* Return the number of bytes required to hold the symtab vector.
1063
1064 Note that we base it on the count plus 1, since we will null terminate
1065 the vector allocated based on this size. */
1066
9ce0058c 1067static unsigned int
8c4a1ace 1068DEFUN (elf_get_symtab_upper_bound, (abfd), bfd *abfd)
9ce0058c 1069{
8c4a1ace
JG
1070 unsigned int symtab_size = 0;
1071
1072 if (elf_slurp_symbol_table (abfd))
1073 {
1074 symtab_size = (bfd_get_symcount (abfd) + 1) * (sizeof (asymbol));
1075 }
1076 return (symtab_size);
9ce0058c
SC
1077}
1078
1079static unsigned int
1080elf_get_reloc_upper_bound (abfd, asect)
1081bfd *abfd;
1082sec_ptr asect;
1083{
1084 fprintf (stderr, "elf_get_reloc_upper_bound unimplemented\n");
1085 fflush (stderr);
1086 abort ();
1087 return (0);
1088}
1089
1090static unsigned int
1091elf_canonicalize_reloc (abfd, section, relptr, symbols)
1092bfd *abfd;
1093sec_ptr section;
1094arelent **relptr;
1095asymbol **symbols;
1096{
1097 fprintf (stderr, "elf_canonicalize_reloc unimplemented\n");
1098 fflush (stderr);
1099 abort ();
1100 return (0);
1101}
1102
1103static unsigned int
8c4a1ace
JG
1104DEFUN (elf_get_symtab, (abfd, alocation),
1105 bfd *abfd AND
1106 asymbol **alocation)
9ce0058c 1107{
8c4a1ace
JG
1108 unsigned int symcount;
1109 asymbol **vec;
1110
1111 if (!elf_slurp_symbol_table (abfd))
1112 {
1113 return (0);
1114 }
1115 else
1116 {
1117 symcount = bfd_get_symcount (abfd);
1118 vec = bfd_get_outsymbols (abfd);
1119 while (symcount-- > 0)
1120 {
1121 *alocation++ = *vec++;
1122 }
1123 *alocation++ = NULL;
1124 return (bfd_get_symcount (abfd));
1125 }
9ce0058c
SC
1126}
1127
1128static asymbol *
1129elf_make_empty_symbol(abfd)
1130bfd *abfd;
1131{
1132 fprintf (stderr, "elf_make_empty_symbol unimplemented\n");
1133 fflush (stderr);
1134 abort ();
1135 return (NULL);
1136}
1137
1138static void
1139DEFUN (elf_print_symbol,(ignore_abfd, filep, symbol, how),
1140 bfd *ignore_abfd AND
1141 PTR filep AND
1142 asymbol *symbol AND
e0796d22 1143 bfd_print_symbol_type how)
9ce0058c
SC
1144{
1145 fprintf (stderr, "elf_print_symbol unimplemented\n");
1146 fflush (stderr);
1147 abort ();
1148}
1149
1150static alent *
1151DEFUN (elf_get_lineno,(ignore_abfd, symbol),
1152 bfd *ignore_abfd AND
1153 asymbol *symbol)
1154{
1155 fprintf (stderr, "elf_get_lineno unimplemented\n");
1156 fflush (stderr);
1157 abort ();
1158 return (NULL);
1159}
1160
1161static boolean
1162DEFUN (elf_set_arch_mach,(abfd, arch, machine),
1163 bfd *abfd AND
1164 enum bfd_architecture arch AND
1165 unsigned long machine)
1166{
1167 fprintf (stderr, "elf_set_arch_mach unimplemented\n");
1168 fflush (stderr);
1169 /* Allow any architecture to be supported by the elf backend */
1170 return bfd_default_set_arch_mach(abfd, arch, machine);
1171}
1172
1173static boolean
1174DEFUN (elf_find_nearest_line,(abfd,
1175 section,
1176 symbols,
1177 offset,
1178 filename_ptr,
1179 functionname_ptr,
1180 line_ptr),
1181 bfd *abfd AND
1182 asection *section AND
1183 asymbol **symbols AND
1184 bfd_vma offset AND
1185 CONST char **filename_ptr AND
1186 CONST char **functionname_ptr AND
1187 unsigned int *line_ptr)
1188{
1189 fprintf (stderr, "elf_find_nearest_line unimplemented\n");
1190 fflush (stderr);
1191 abort ();
1192 return (false);
1193}
1194
1195static int
1196DEFUN (elf_sizeof_headers, (abfd, reloc),
1197 bfd *abfd AND
1198 boolean reloc)
1199{
1200 fprintf (stderr, "elf_sizeof_headers unimplemented\n");
1201 fflush (stderr);
1202 abort ();
1203 return (0);
1204}
e0796d22 1205\f
9ce0058c
SC
1206/* This structure contains everything that BFD knows about a target.
1207 It includes things like its byte order, name, what routines to call
1208 to do various operations, etc. Every BFD points to a target structure
1209 with its "xvec" member.
1210
1211 There are two such structures here: one for big-endian machines and
1212 one for little-endian machines. */
1213
e0796d22
FF
1214/* Archives are generic or unimplemented. */
1215#define elf_slurp_armap bfd_false
1216#define elf_slurp_extended_name_table _bfd_slurp_extended_name_table
1217#define elf_truncate_arname bfd_dont_truncate_arname
1218#define elf_openr_next_archived_file bfd_generic_openr_next_archived_file
1219#define elf_generic_stat_arch_elt bfd_generic_stat_arch_elt
1220#define elf_write_armap (PROTO (boolean, (*), \
a6c1d731 1221 (bfd *arch, unsigned int elength, struct orl *map, unsigned int orl_count, \
e0796d22
FF
1222 int stridx))) bfd_false
1223
1224/* Ordinary section reading and writing */
1225#define elf_new_section_hook _bfd_dummy_new_section_hook
1226#define elf_get_section_contents bfd_generic_get_section_contents
1227#define elf_set_section_contents bfd_generic_set_section_contents
1228#define elf_close_and_cleanup bfd_generic_close_and_cleanup
1229
1230#define elf_bfd_debug_info_start bfd_void
1231#define elf_bfd_debug_info_end bfd_void
1232#define elf_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
1233
9ce0058c
SC
1234bfd_target elf_big_vec =
1235{
1236 /* name: identify kind of target */
1237 "elf-big",
1238
1239 /* flavour: general indication about file */
e0796d22 1240 bfd_target_elf_flavour,
9ce0058c
SC
1241
1242 /* byteorder_big_p: data is big endian */
1243 true,
1244
1245 /* header_byteorder_big_p: header is also big endian */
1246 true,
1247
1248 /* object_flags: mask of all file flags */
1249 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
1250 DYNAMIC | WP_TEXT),
1251
1252 /* section_flags: mask of all section flags */
1253 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
1254 SEC_DATA),
1255
1256 /* ar_pad_char: pad character for filenames within an archive header
1257 FIXME: this really has nothing to do with ELF, this is a characteristic
1258 of the archiver and/or os and should be independently tunable */
1259 '/',
1260
1261 /* ar_max_namelen: maximum number of characters in an archive header
1262 FIXME: this really has nothing to do with ELF, this is a characteristic
1263 of the archiver and should be independently tunable. This value is
1264 a WAG (wild a** guess) */
1265 15,
1266
1267 /* align_power_min: minimum alignment restriction for any section
1268 FIXME: this value may be target machine dependent */
1269 3,
1270
1271 /* Routines to byte-swap various sized integers from the data sections */
1272 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
1273
1274 /* Routines to byte-swap various sized integers from the file headers */
1275 _do_getb64, _do_putb64, _do_getb32, _do_putb32, _do_getb16, _do_putb16,
1276
1277 /* bfd_check_format: check the format of a file being read */
e0796d22
FF
1278 { _bfd_dummy_target, /* unknown format */
1279 elf_object_p, /* assembler/linker output (object file) */
1280 bfd_generic_archive_p, /* an archive */
1281 elf_core_file_p /* a core file */
9ce0058c
SC
1282 },
1283
1284 /* bfd_set_format: set the format of a file being written */
1285 { bfd_false,
1286 elf_mkobject,
1287 _bfd_generic_mkarchive,
1288 bfd_false
1289 },
1290
1291 /* bfd_write_contents: write cached information into a file being written */
1292 { bfd_false,
1293 elf_write_object_contents,
1294 _bfd_write_archive_contents,
1295 bfd_false
1296 },
1297
1298 /* Initialize a jump table with the standard macro. All names start
1299 with "elf" */
1300 JUMP_TABLE(elf),
1301
1302 /* SWAP_TABLE */
1303 NULL, NULL, NULL
1304};
1305
1306bfd_target elf_little_vec =
1307{
1308 /* name: identify kind of target */
1309 "elf-little",
1310
1311 /* flavour: general indication about file */
e0796d22 1312 bfd_target_elf_flavour,
9ce0058c
SC
1313
1314 /* byteorder_big_p: data is big endian */
1315 false, /* Nope -- this one's little endian */
1316
1317 /* header_byteorder_big_p: header is also big endian */
1318 false, /* Nope -- this one's little endian */
1319
1320 /* object_flags: mask of all file flags */
1321 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS |
1322 DYNAMIC | WP_TEXT),
1323
1324 /* section_flags: mask of all section flags */
1325 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY |
1326 SEC_DATA),
1327
1328 /* ar_pad_char: pad character for filenames within an archive header
1329 FIXME: this really has nothing to do with ELF, this is a characteristic
1330 of the archiver and/or os and should be independently tunable */
1331 '/',
1332
1333 /* ar_max_namelen: maximum number of characters in an archive header
1334 FIXME: this really has nothing to do with ELF, this is a characteristic
1335 of the archiver and should be independently tunable. This value is
1336 a WAG (wild a** guess) */
1337 15,
1338
1339 /* align_power_min: minimum alignment restriction for any section
1340 FIXME: this value may be target machine dependent */
1341 3,
1342
1343 /* Routines to byte-swap various sized integers from the data sections */
1344 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
1345
1346 /* Routines to byte-swap various sized integers from the file headers */
1347 _do_getl64, _do_putl64, _do_getl32, _do_putl32, _do_getl16, _do_putl16,
1348
1349 /* bfd_check_format: check the format of a file being read */
e0796d22
FF
1350 { _bfd_dummy_target, /* unknown format */
1351 elf_object_p, /* assembler/linker output (object file) */
1352 bfd_generic_archive_p, /* an archive */
1353 elf_core_file_p /* a core file */
9ce0058c
SC
1354 },
1355
1356 /* bfd_set_format: set the format of a file being written */
1357 { bfd_false,
1358 elf_mkobject,
1359 _bfd_generic_mkarchive,
1360 bfd_false
1361 },
1362
1363 /* bfd_write_contents: write cached information into a file being written */
1364 { bfd_false,
1365 elf_write_object_contents,
1366 _bfd_write_archive_contents,
1367 bfd_false
1368 },
1369
1370 /* Initialize a jump table with the standard macro. All names start
1371 with "elf" */
1372 JUMP_TABLE(elf),
1373
1374 /* SWAP_TABLE */
1375 NULL, NULL, NULL
1376};
This page took 0.093658 seconds and 4 git commands to generate.