1 /* ELF executable support for BFD.
2 Copyright 1991, 1992, 1993 Free Software Foundation, Inc.
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". Sufficient support for gdb.
8 Rewritten by Mark Eichin @ Cygnus Support, from information
9 published in "System V Application Binary Interface", chapters 4
10 and 5, as well as the various "Processor Supplement" documents
11 derived from it. Added support for assembler and other object file
14 This file is part of BFD, the Binary File Descriptor library.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /****************************************
35 This is only a partial ELF implementation,
36 incorporating only those parts that are
37 required to get gdb up and running. It is
38 expected that it will be expanded to a full
39 ELF implementation at some future date.
41 Unimplemented stubs call abort() to ensure
42 that they get proper attention if they are
43 ever called. The stubs are here since
44 this version was hacked from the COFF
45 version, and thus they will probably
46 go away or get expanded appropriately in a
51 *****************************************/
54 /* Problems and other issues to resolve.
56 (1) BFD expects there to be some fixed number of "sections" in
57 the object file. I.E. there is a "section_count" variable in the
58 bfd structure which contains the number of sections. However, ELF
59 supports multiple "views" of a file. In particular, with current
60 implementations, executable files typically have two tables, a
61 program header table and a section header table, both of which
62 partition the executable.
64 In ELF-speak, the "linking view" of the file uses the section header
65 table to access "sections" within the file, and the "execution view"
66 uses the program header table to access "segments" within the file.
67 "Segments" typically may contain all the data from one or more
70 Note that the section header table is optional in ELF executables,
71 but it is this information that is most useful to gdb. If the
72 section header table is missing, then gdb should probably try
73 to make do with the program header table. (FIXME)
77 #include <string.h> /* For strrchr and friends */
83 #ifdef HAVE_PROCFS /* Some core file support requires host /proc files */
84 #include <sys/procfs.h>
86 #define bfd_prstatus(abfd, descdata, descsz, filepos) /* Define away */
87 #define bfd_fpregset(abfd, descdata, descsz, filepos) /* Define away */
88 #define bfd_prpsinfo(abfd, descdata, descsz, filepos) /* Define away */
91 /* Forward declarations of static functions */
94 elf_read PARAMS ((bfd *, long, int));
97 section_from_elf_index PARAMS ((bfd *, int));
100 elf_section_from_bfd_section PARAMS ((bfd *, struct sec *));
103 elf_slurp_symbol_table PARAMS ((bfd *, asymbol **));
106 elf_get_str_section PARAMS ((bfd *, unsigned int));
108 /* Forward data declarations */
110 extern bfd_target elf_little_vec, elf_big_vec;
112 /* Currently the elf_symbol_type struct just contains the generic bfd
120 /* Some private data is stashed away for future use using the tdata pointer
121 in the bfd structure. */
125 Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */
126 Elf_Internal_Shdr *elf_sect_ptr;
127 struct strtab *strtab_ptr;
129 void *prstatus; /* The raw /proc prstatus structure */
130 void *prpsinfo; /* The raw /proc prpsinfo structure */
133 #define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
134 #define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header)
135 #define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr)
136 #define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr)
137 #define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section)
138 #define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo)
139 #define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus)
141 /* Translate an ELF symbol in external format into an ELF symbol in internal
145 DEFUN(elf_swap_symbol_in,(abfd, src, dst),
147 Elf_External_Sym *src AND
148 Elf_Internal_Sym *dst)
150 dst -> st_name = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_name);
151 dst -> st_value = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_value);
152 dst -> st_size = bfd_h_get_32 (abfd, (bfd_byte *) src -> st_size);
153 dst -> st_info = bfd_h_get_8 (abfd, (bfd_byte *) src -> st_info);
154 dst -> st_other = bfd_h_get_8 (abfd, (bfd_byte *) src -> st_other);
155 dst -> st_shndx = bfd_h_get_16 (abfd, (bfd_byte *) src -> st_shndx);
158 /* Translate an ELF symbol in internal format into an ELF symbol in external
162 DEFUN(elf_swap_symbol_out,(abfd, src, dst),
164 Elf_Internal_Sym *src AND
165 Elf_External_Sym *dst)
167 bfd_h_put_32 (abfd, src->st_name, dst->st_name);
168 bfd_h_put_32 (abfd, src->st_value, dst->st_value);
169 bfd_h_put_32 (abfd, src->st_size, dst->st_size);
170 bfd_h_put_8 (abfd, src->st_info, dst->st_info);
171 bfd_h_put_8 (abfd, src->st_other, dst->st_other);
172 bfd_h_put_16 (abfd, src->st_shndx, dst->st_shndx);
176 /* Translate an ELF file header in external format into an ELF file header in
180 DEFUN(elf_swap_ehdr_in,(abfd, src, dst),
182 Elf_External_Ehdr *src AND
183 Elf_Internal_Ehdr *dst)
185 memcpy (dst -> e_ident, src -> e_ident, EI_NIDENT);
186 dst -> e_type = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_type);
187 dst -> e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_machine);
188 dst -> e_version = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_version);
189 dst -> e_entry = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_entry);
190 dst -> e_phoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_phoff);
191 dst -> e_shoff = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_shoff);
192 dst -> e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_flags);
193 dst -> e_ehsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_ehsize);
194 dst -> e_phentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phentsize);
195 dst -> e_phnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_phnum);
196 dst -> e_shentsize = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shentsize);
197 dst -> e_shnum = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shnum);
198 dst -> e_shstrndx = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_shstrndx);
201 /* Translate an ELF file header in internal format into an ELF file header in
205 DEFUN(elf_swap_ehdr_out,(abfd, src, dst),
207 Elf_Internal_Ehdr *src AND
208 Elf_External_Ehdr *dst)
210 memcpy (dst -> e_ident, src -> e_ident, EI_NIDENT);
211 /* note that all elements of dst are *arrays of unsigned char* already... */
212 bfd_h_put_16 (abfd, src->e_type, dst->e_type);
213 bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
214 bfd_h_put_32 (abfd, src->e_version, dst->e_version);
215 bfd_h_put_32 (abfd, src->e_entry, dst->e_entry);
216 bfd_h_put_32 (abfd, src->e_phoff, dst->e_phoff);
217 bfd_h_put_32 (abfd, src->e_shoff, dst->e_shoff);
218 bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
219 bfd_h_put_16 (abfd, src->e_ehsize, dst->e_ehsize);
220 bfd_h_put_16 (abfd, src->e_phentsize, dst->e_phentsize);
221 bfd_h_put_16 (abfd, src->e_phnum, dst->e_phnum);
222 bfd_h_put_16 (abfd, src->e_shentsize, dst->e_shentsize);
223 bfd_h_put_16 (abfd, src->e_shnum, dst->e_shnum);
224 bfd_h_put_16 (abfd, src->e_shstrndx, dst->e_shstrndx);
228 /* Translate an ELF section header table entry in external format into an
229 ELF section header table entry in internal format. */
232 DEFUN(elf_swap_shdr_in,(abfd, src, dst),
234 Elf_External_Shdr *src AND
235 Elf_Internal_Shdr *dst)
237 dst->sh_name = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_name);
238 dst->sh_type = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_type);
239 dst->sh_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_flags);
240 dst->sh_addr = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_addr);
241 dst->sh_offset = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_offset);
242 dst->sh_size = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_size);
243 dst->sh_link = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_link);
244 dst->sh_info = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_info);
245 dst->sh_addralign = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_addralign);
246 dst->sh_entsize = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_entsize);
247 /* we haven't done any processing on it yet, so... */
248 dst->rawdata = (void*)0;
251 /* Translate an ELF section header table entry in internal format into an
252 ELF section header table entry in external format. */
255 DEFUN(elf_swap_shdr_out,(abfd, src, dst),
257 Elf_Internal_Shdr *src AND
258 Elf_External_Shdr *dst)
260 /* note that all elements of dst are *arrays of unsigned char* already... */
261 bfd_h_put_32 (abfd, src->sh_name, dst->sh_name);
262 bfd_h_put_32 (abfd, src->sh_type, dst->sh_type);
263 bfd_h_put_32 (abfd, src->sh_flags, dst->sh_flags);
264 bfd_h_put_32 (abfd, src->sh_addr, dst->sh_addr);
265 bfd_h_put_32 (abfd, src->sh_offset, dst->sh_offset);
266 bfd_h_put_32 (abfd, src->sh_size, dst->sh_size);
267 bfd_h_put_32 (abfd, src->sh_link, dst->sh_link);
268 bfd_h_put_32 (abfd, src->sh_info, dst->sh_info);
269 bfd_h_put_32 (abfd, src->sh_addralign, dst->sh_addralign);
270 bfd_h_put_32 (abfd, src->sh_entsize, dst->sh_entsize);
274 /* Translate an ELF program header table entry in external format into an
275 ELF program header table entry in internal format. */
278 DEFUN(elf_swap_phdr_in,(abfd, src, dst),
280 Elf_External_Phdr *src AND
281 Elf_Internal_Phdr *dst)
283 dst->p_type = bfd_h_get_32 (abfd, (bfd_byte *) src->p_type);
284 dst->p_offset = bfd_h_get_32 (abfd, (bfd_byte *) src->p_offset);
285 dst->p_vaddr = bfd_h_get_32 (abfd, (bfd_byte *) src->p_vaddr);
286 dst->p_paddr = bfd_h_get_32 (abfd, (bfd_byte *) src->p_paddr);
287 dst->p_filesz = bfd_h_get_32 (abfd, (bfd_byte *) src->p_filesz);
288 dst->p_memsz = bfd_h_get_32 (abfd, (bfd_byte *) src->p_memsz);
289 dst->p_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->p_flags);
290 dst->p_align = bfd_h_get_32 (abfd, (bfd_byte *) src->p_align);
294 /* Translate an ELF reloc from external format to internal format. */
296 DEFUN(elf_swap_reloc_in,(abfd, src, dst),
298 Elf_External_Rel *src AND
299 Elf_Internal_Rel *dst)
301 dst->r_offset = bfd_h_get_32 (abfd, (bfd_byte *) src->r_offset);
302 dst->r_info = bfd_h_get_32 (abfd, (bfd_byte *) src->r_info);
306 DEFUN(elf_swap_reloca_in,(abfd, src, dst),
308 Elf_External_Rela *src AND
309 Elf_Internal_Rela *dst)
311 dst->r_offset = bfd_h_get_32 (abfd, (bfd_byte *) src->r_offset);
312 dst->r_info = bfd_h_get_32 (abfd, (bfd_byte *) src->r_info);
313 dst->r_addend = bfd_h_get_32 (abfd, (bfd_byte *) src->r_addend);
316 /* Translate an ELF reloc from internal format to external format. */
318 DEFUN(elf_swap_reloc_out,(abfd, src, dst),
320 Elf_Internal_Rel *src AND
321 Elf_External_Rel *dst)
323 bfd_h_put_32 (abfd, src->r_offset, dst->r_offset);
324 bfd_h_put_32 (abfd, src->r_info, dst->r_info);
328 DEFUN(elf_swap_reloca_out,(abfd, src, dst),
330 Elf_Internal_Rela *src AND
331 Elf_External_Rela *dst)
333 bfd_h_put_32 (abfd, src->r_offset, dst->r_offset);
334 bfd_h_put_32 (abfd, src->r_info, dst->r_info);
335 bfd_h_put_32 (abfd, src->r_addend, dst->r_addend);
343 struct elf_internal_shdr *bfd_elf_find_section (bfd *abfd, char *name);
346 Helper functions for GDB to locate the string tables.
347 Since BFD hides string tables from callers, GDB needs to use an
348 internal hook to find them. Sun's .stabstr, in particular,
349 isn't even pointed to by the .stab section, so ordinary
350 mechanisms wouldn't work to find it, even if we had some.
353 struct elf_internal_shdr *
354 DEFUN(bfd_elf_find_section, (abfd, name),
358 Elf_Internal_Shdr *i_shdrp;
359 Elf_Internal_Shdr *gotit = NULL;
364 i_shdrp = elf_elfsections (abfd);
367 shstrtab = elf_get_str_section (abfd, elf_elfheader (abfd)->e_shstrndx);
368 if (shstrtab != NULL)
370 max = elf_elfheader (abfd)->e_shnum;
371 for (i = 1; i < max; i++)
373 if (!strcmp (&shstrtab[i_shdrp[i].sh_name], name))
383 /* End of GDB support. */
386 DEFUN(elf_get_str_section, (abfd, shindex),
388 unsigned int shindex)
390 Elf_Internal_Shdr *i_shdrp;
391 char *shstrtab = NULL;
393 unsigned int shstrtabsize;
395 i_shdrp = elf_elfsections (abfd);
398 shstrtab = i_shdrp[shindex].rawdata;
399 if (shstrtab == NULL)
401 /* No cached one, attempt to read, and cache what we read. */
402 offset = i_shdrp[shindex].sh_offset;
403 shstrtabsize = i_shdrp[shindex].sh_size;
404 shstrtab = elf_read (abfd, offset, shstrtabsize);
405 i_shdrp[shindex].rawdata = (void*) shstrtab;
412 DEFUN(elf_string_from_elf_section, (abfd, shindex, strindex),
414 unsigned int shindex AND
415 unsigned int strindex)
417 Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
418 Elf_Internal_Shdr *hdr = i_shdrp + shindex;
422 if (elf_get_str_section (abfd, shindex) == NULL)
427 return ((char*)hdr->rawdata)+strindex;
430 #define elf_string_from_elf_strtab(abfd, strindex) \
431 elf_string_from_elf_section (abfd, elf_elfheader(abfd)->e_shstrndx, strindex)
433 /* Create a new bfd section from an ELF section header. */
436 DEFUN(bfd_section_from_shdr, (abfd, shindex),
438 unsigned int shindex)
440 Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
441 Elf_Internal_Shdr *hdr = i_shdrp + shindex;
445 name = hdr->sh_name ?
446 elf_string_from_elf_strtab (abfd, hdr->sh_name) : "unnamed";
448 switch(hdr->sh_type) {
451 /* inactive section. Throw it away. */
456 /* Bits that get saved. This one is real. */
459 newsect = bfd_make_section (abfd, name);
462 newsect->vma = hdr->sh_addr;
463 newsect->_raw_size = hdr->sh_size;
464 newsect->filepos = hdr->sh_offset; /* so we can read back the bits */
465 newsect->flags |= SEC_HAS_CONTENTS;
467 if (hdr->sh_flags & SHF_ALLOC)
469 newsect->flags |= SEC_ALLOC;
470 if (hdr->sh_type != SHT_NOBITS)
471 newsect->flags |= SEC_LOAD;
474 if (!(hdr->sh_flags & SHF_WRITE))
475 newsect->flags |= SEC_READONLY;
477 if (hdr->sh_flags & SHF_EXECINSTR)
478 newsect->flags |= SEC_CODE; /* FIXME: may only contain SOME code */
480 newsect->flags |= SEC_DATA;
482 hdr->rawdata = (void*)newsect;
488 case SHT_SYMTAB: /* A symbol table */
489 BFD_ASSERT (hdr->sh_entsize == sizeof (Elf_External_Sym));
490 elf_onesymtab (abfd) = shindex;
491 abfd->flags |= HAS_SYMS;
494 case SHT_STRTAB: /* A string table */
499 /* *these* do a lot of work -- but build no sections! */
500 /* the spec says there can be multiple strtabs, but only one symtab */
501 /* but there can be lots of REL* sections. */
502 /* FIXME: The above statement is wrong! There are typically at least
503 two symbol tables in a dynamically linked executable, ".dynsym"
504 which is the dynamic linkage symbol table and ".symtab", which is
505 the "traditional" symbol table. -fnf */
508 asection *target_sect;
510 bfd_section_from_shdr (abfd, hdr->sh_link); /* symbol table */
511 bfd_section_from_shdr (abfd, hdr->sh_info); /* target */
512 target_sect = section_from_elf_index (abfd, hdr->sh_info);
513 if (target_sect == NULL)
517 /* FIXME: We are only prepared to read one symbol table, so
518 do NOT read the dynamic symbol table since it is only a
519 subset of the full symbol table. Also see comment above. -fnf */
520 if (!elf_slurp_symbol_table(abfd, i_shdrp + hdr->sh_link))
524 target_sect->reloc_count = hdr->sh_size / hdr->sh_entsize;
525 target_sect->flags |= SEC_RELOC;
526 target_sect->relocation = 0;
527 target_sect->rel_filepos = hdr->sh_offset;
534 case SHT_DYNSYM: /* could treat this like symtab... */
536 fprintf(stderr, "Dynamic Linking sections not yet supported.\n");
543 fprintf(stderr, "Note Sections not yet supported.\n");
550 fprintf(stderr, "SHLIB Sections not supported (and non conforming.)\n");
571 static struct strtab *
572 DEFUN(bfd_new_strtab, (abfd),
577 ss = (struct strtab *) bfd_xmalloc(sizeof(struct strtab));
578 ss->tab = bfd_xmalloc(1);
579 BFD_ASSERT(ss->tab != 0);
588 DEFUN(bfd_add_to_strtab, (abfd, ss, str),
590 struct strtab *ss AND
593 /* should search first, but for now: */
594 /* include the trailing NUL */
595 int ln = strlen(str)+1;
597 /* should this be using obstacks? */
598 ss->tab = realloc(ss->tab, ss->length + ln);
600 BFD_ASSERT(ss->tab != 0);
601 strcpy(ss->tab + ss->length, str);
605 return ss->length - ln;
609 DEFUN(bfd_add_2_to_strtab, (abfd, ss, str, str2),
611 struct strtab *ss AND
615 /* should search first, but for now: */
616 /* include the trailing NUL */
617 int ln = strlen(str)+strlen(str2)+1;
619 /* should this be using obstacks? */
621 ss->tab = realloc(ss->tab, ss->length + ln);
623 ss->tab = bfd_xmalloc(ln);
625 BFD_ASSERT(ss->tab != 0);
626 strcpy(ss->tab + ss->length, str);
627 strcpy(ss->tab + ss->length + strlen(str), str2);
631 return ss->length - ln;
634 /* Create a new ELF section from a bfd section. */
637 DEFUN(bfd_shdr_from_section, (abfd, hdr, shstrtab, indx),
639 Elf_Internal_Shdr *hdr AND
640 struct strtab *shstrtab AND
646 /* figure out out to write the section name from the bfd section name. MWE */
648 sect = abfd->sections;
649 for (ndx = indx; --ndx; )
653 hdr[indx].sh_name = bfd_add_to_strtab(abfd, shstrtab,
654 bfd_section_name(abfd, sect));
655 hdr[indx].sh_addr = sect->vma;
656 hdr[indx].sh_size = sect->_raw_size;
657 hdr[indx].sh_flags = 0;
658 /* these need to be preserved on */
659 hdr[indx].sh_link = 0;
660 hdr[indx].sh_info = 0;
661 hdr[indx].sh_addralign = 0;
662 hdr[indx].sh_entsize = 0;
664 hdr[indx].sh_type = 0;
665 if (sect->flags & SEC_RELOC) {
666 hdr[indx].sh_type = SHT_RELA; /* FIXME -- sparc specific */
669 if (sect->flags & SEC_HAS_CONTENTS)
671 hdr[indx].sh_offset = sect->filepos;
672 hdr[indx].sh_size = sect->_raw_size;
674 if (sect->flags & SEC_ALLOC)
676 hdr[indx].sh_flags |= SHF_ALLOC;
677 if (sect->flags & SEC_LOAD)
679 /* do something with sh_type ? */
682 if (!(sect->flags & SEC_READONLY))
683 hdr[indx].sh_flags |= SHF_WRITE;
685 if (sect->flags & SEC_CODE)
686 hdr[indx].sh_flags |= SHF_EXECINSTR;
691 /* Create a new bfd section from an ELF program header.
693 Since program segments have no names, we generate a synthetic name
694 of the form segment<NUM>, where NUM is generally the index in the
695 program header table. For segments that are split (see below) we
696 generate the names segment<NUM>a and segment<NUM>b.
698 Note that some program segments may have a file size that is different than
699 (less than) the memory size. All this means is that at execution the
700 system must allocate the amount of memory specified by the memory size,
701 but only initialize it with the first "file size" bytes read from the
702 file. This would occur for example, with program segments consisting
703 of combined data+bss.
705 To handle the above situation, this routine generates TWO bfd sections
706 for the single program segment. The first has the length specified by
707 the file size of the segment, and the second has the length specified
708 by the difference between the two sizes. In effect, the segment is split
709 into it's initialized and uninitialized parts.
714 DEFUN(bfd_section_from_phdr, (abfd, hdr, index),
716 Elf_Internal_Phdr *hdr AND
724 split = ((hdr -> p_memsz > 0) &&
725 (hdr -> p_filesz > 0) &&
726 (hdr -> p_memsz > hdr -> p_filesz));
727 sprintf (namebuf, split ? "segment%da" : "segment%d", index);
728 name = bfd_alloc (abfd, strlen (namebuf) + 1);
729 strcpy (name, namebuf);
730 newsect = bfd_make_section (abfd, name);
731 newsect -> vma = hdr -> p_vaddr;
732 newsect -> _raw_size = hdr -> p_filesz;
733 newsect -> filepos = hdr -> p_offset;
734 newsect -> flags |= SEC_HAS_CONTENTS;
735 if (hdr -> p_type == PT_LOAD)
737 newsect -> flags |= SEC_ALLOC;
738 newsect -> flags |= SEC_LOAD;
739 if (hdr -> p_flags & PF_X)
741 /* FIXME: all we known is that it has execute PERMISSION,
743 newsect -> flags |= SEC_CODE;
746 if (!(hdr -> p_flags & PF_W))
748 newsect -> flags |= SEC_READONLY;
753 sprintf (namebuf, "segment%db", index);
754 name = bfd_alloc (abfd, strlen (namebuf) + 1);
755 strcpy (name, namebuf);
756 newsect = bfd_make_section (abfd, name);
757 newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz;
758 newsect -> _raw_size = hdr -> p_memsz - hdr -> p_filesz;
759 if (hdr -> p_type == PT_LOAD)
761 newsect -> flags |= SEC_ALLOC;
762 if (hdr -> p_flags & PF_X)
763 newsect -> flags |= SEC_CODE;
765 if (!(hdr -> p_flags & PF_W))
766 newsect -> flags |= SEC_READONLY;
775 DEFUN(bfd_prstatus,(abfd, descdata, descsz, filepos),
782 prstatus_t *status = (prstatus_t *)0;
784 if (descsz == sizeof (prstatus_t))
786 newsect = bfd_make_section (abfd, ".reg");
787 newsect -> _raw_size = sizeof (status->pr_reg);
788 newsect -> filepos = filepos + (long) &status->pr_reg;
789 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
790 newsect -> alignment_power = 2;
791 if ((core_prstatus (abfd) = bfd_alloc (abfd, descsz)) != NULL)
793 memcpy (core_prstatus (abfd), descdata, descsz);
798 /* Stash a copy of the prpsinfo structure away for future use. */
801 DEFUN(bfd_prpsinfo,(abfd, descdata, descsz, filepos),
809 if (descsz == sizeof (prpsinfo_t))
811 if ((core_prpsinfo (abfd) = bfd_alloc (abfd, descsz)) != NULL)
813 memcpy (core_prpsinfo (abfd), descdata, descsz);
819 DEFUN(bfd_fpregset,(abfd, descdata, descsz, filepos),
827 newsect = bfd_make_section (abfd, ".reg2");
828 newsect -> _raw_size = descsz;
829 newsect -> filepos = filepos;
830 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
831 newsect -> alignment_power = 2;
834 #endif /* HAVE_PROCFS */
836 /* Return a pointer to the args (including the command name) that were
837 seen by the program that generated the core dump. Note that for
838 some reason, a spurious space is tacked onto the end of the args
839 in some (at least one anyway) implementations, so strip it off if
843 DEFUN(elf_core_file_failing_command, (abfd),
847 if (core_prpsinfo (abfd))
849 prpsinfo_t *p = core_prpsinfo (abfd);
850 char *scan = p -> pr_psargs;
853 if ((scan > p -> pr_psargs) && (*scan == ' '))
857 return (p -> pr_psargs);
863 /* Return the number of the signal that caused the core dump. Presumably,
864 since we have a core file, we got a signal of some kind, so don't bother
865 checking the other process status fields, just return the signal number.
869 DEFUN(elf_core_file_failing_signal, (abfd),
873 if (core_prstatus (abfd))
875 return (((prstatus_t *)(core_prstatus (abfd))) -> pr_cursig);
881 /* Check to see if the core file could reasonably be expected to have
882 come for the current executable file. Note that by default we return
883 true unless we find something that indicates that there might be a
888 DEFUN(elf_core_file_matches_executable_p, (core_bfd, exec_bfd),
897 /* First, xvecs must match since both are ELF files for the same target. */
899 if (core_bfd->xvec != exec_bfd->xvec)
901 bfd_error = system_call_error;
907 /* If no prpsinfo, just return true. Otherwise, grab the last component
908 of the exec'd pathname from the prpsinfo. */
910 if (core_prpsinfo (core_bfd))
912 corename = (((struct prpsinfo *) core_prpsinfo (core_bfd)) -> pr_fname);
919 /* Find the last component of the executable pathname. */
921 if ((execname = strrchr (exec_bfd -> filename, '/')) != NULL)
927 execname = (char *) exec_bfd -> filename;
930 /* See if they match */
932 return (strcmp (execname, corename) ? false : true);
938 #endif /* HAVE_PROCFS */
941 /* ELF core files contain a segment of type PT_NOTE, that holds much of
942 the information that would normally be available from the /proc interface
943 for the process, at the time the process dumped core. Currently this
944 includes copies of the prstatus, prpsinfo, and fpregset structures.
946 Since these structures are potentially machine dependent in size and
947 ordering, bfd provides two levels of support for them. The first level,
948 available on all machines since it does not require that the host
949 have /proc support or the relevant include files, is to create a bfd
950 section for each of the prstatus, prpsinfo, and fpregset structures,
951 without any interpretation of their contents. With just this support,
952 the bfd client will have to interpret the structures itself. Even with
953 /proc support, it might want these full structures for it's own reasons.
955 In the second level of support, where HAVE_PROCFS is defined, bfd will
956 pick apart the structures to gather some additional information that
957 clients may want, such as the general register set, the name of the
958 exec'ed file and its arguments, the signal (if any) that caused the
964 DEFUN(elf_corefile_note, (abfd, hdr),
966 Elf_Internal_Phdr *hdr)
968 Elf_External_Note *x_note_p; /* Elf note, external form */
969 Elf_Internal_Note i_note; /* Elf note, internal form */
970 char *buf = NULL; /* Entire note segment contents */
971 char *namedata; /* Name portion of the note */
972 char *descdata; /* Descriptor portion of the note */
973 char *sectname; /* Name to use for new section */
974 long filepos; /* File offset to descriptor data */
977 if (hdr -> p_filesz > 0
978 && (buf = (char *) bfd_xmalloc (hdr -> p_filesz)) != NULL
979 && bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1
980 && bfd_read ((PTR) buf, hdr -> p_filesz, 1, abfd) == hdr -> p_filesz)
982 x_note_p = (Elf_External_Note *) buf;
983 while ((char *) x_note_p < (buf + hdr -> p_filesz))
985 i_note.namesz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> namesz);
986 i_note.descsz = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> descsz);
987 i_note.type = bfd_h_get_32 (abfd, (bfd_byte *) x_note_p -> type);
988 namedata = x_note_p -> name;
989 descdata = namedata + BFD_ALIGN (i_note.namesz, 4);
990 filepos = hdr -> p_offset + (descdata - buf);
991 switch (i_note.type) {
993 /* process descdata as prstatus info */
994 bfd_prstatus (abfd, descdata, i_note.descsz, filepos);
995 sectname = ".prstatus";
998 /* process descdata as fpregset info */
999 bfd_fpregset (abfd, descdata, i_note.descsz, filepos);
1000 sectname = ".fpregset";
1003 /* process descdata as prpsinfo */
1004 bfd_prpsinfo (abfd, descdata, i_note.descsz, filepos);
1005 sectname = ".prpsinfo";
1008 /* Unknown descriptor, just ignore it. */
1012 if (sectname != NULL)
1014 newsect = bfd_make_section (abfd, sectname);
1015 newsect -> _raw_size = i_note.descsz;
1016 newsect -> filepos = filepos;
1017 newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
1018 newsect -> alignment_power = 2;
1020 x_note_p = (Elf_External_Note *)
1021 (descdata + BFD_ALIGN (i_note.descsz, 4));
1033 /* Read a specified number of bytes at a specified offset in an ELF
1034 file, into a newly allocated buffer, and return a pointer to the
1038 DEFUN(elf_read, (abfd, offset, size),
1045 if ((buf = bfd_alloc (abfd, size)) == NULL)
1047 bfd_error = no_memory;
1050 if (bfd_seek (abfd, offset, SEEK_SET) == -1)
1052 bfd_error = system_call_error;
1055 if (bfd_read ((PTR) buf, size, 1, abfd) != size)
1057 bfd_error = system_call_error;
1063 /* Begin processing a given object.
1065 First we validate the file by reading in the ELF header and checking
1071 DEFUN (elf_object_p, (abfd), bfd *abfd)
1073 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
1074 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
1075 Elf_External_Shdr x_shdr; /* Section header table entry, external form */
1076 Elf_Internal_Shdr *i_shdrp; /* Section header table, internal form */
1078 char *shstrtab; /* Internal copy of section header stringtab */
1079 struct elf_backend_data *ebd; /* Use to get ELF_ARCH stored in xvec */
1081 /* Read in the ELF header in external format. */
1083 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
1085 bfd_error = system_call_error;
1089 /* Now check to see if we have a valid ELF file, and one that BFD can
1090 make use of. The magic number must match, the address size ('class')
1091 and byte-swapping must match our XVEC entry, and it must have a
1092 section header table (FIXME: See comments re sections at top of this
1095 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
1096 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
1097 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
1098 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
1101 bfd_error = wrong_format;
1105 /* FIXME, Check EI_VERSION here ! */
1107 switch (x_ehdr.e_ident[EI_CLASS])
1109 case ELFCLASSNONE: /* address size not specified */
1110 goto wrong; /* No support if can't tell address size */
1111 case ELFCLASS32: /* 32-bit addresses */
1113 case ELFCLASS64: /* 64-bit addresses */
1114 goto wrong; /* FIXME: 64 bits not yet supported */
1116 goto wrong; /* No support if unknown address class */
1119 /* Switch xvec to match the specified byte order. */
1120 switch (x_ehdr.e_ident[EI_DATA])
1122 case ELFDATA2MSB: /* Big-endian */
1123 if (!abfd->xvec->header_byteorder_big_p)
1126 case ELFDATA2LSB: /* Little-endian */
1127 if (abfd->xvec->header_byteorder_big_p)
1130 case ELFDATANONE: /* No data encoding specified */
1131 default: /* Unknown data encoding specified */
1135 /* Allocate an instance of the elf_obj_tdata structure and hook it up to
1136 the tdata pointer in the bfd. */
1138 if (NULL == (elf_tdata (abfd) = (struct elf_obj_tdata *)
1139 bfd_zalloc (abfd, sizeof (struct elf_obj_tdata))))
1141 bfd_error = no_memory;
1145 /* FIXME: Any `wrong' exits below here will leak memory (tdata). */
1147 /* Now that we know the byte order, swap in the rest of the header */
1148 i_ehdrp = elf_elfheader (abfd);
1149 elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
1151 /* If there is no section header table, we're hosed. */
1152 if (i_ehdrp->e_shoff == 0)
1155 if (i_ehdrp->e_type == ET_EXEC || i_ehdrp->e_type == ET_DYN)
1156 abfd -> flags |= EXEC_P;
1158 /* Retrieve the architecture information from the xvec and verify
1159 that it matches the machine info stored in the ELF header.
1160 This allows us to resolve ambiguous formats that might not
1161 otherwise be distinguishable. */
1163 ebd = (struct elf_backend_data *) (abfd->xvec->backend_data);
1164 switch (i_ehdrp->e_machine)
1167 case EM_M32: /* or should this be bfd_arch_obscure? */
1168 if (ebd -> arch != bfd_arch_unknown)
1170 bfd_default_set_arch_mach(abfd, bfd_arch_unknown, 0);
1173 if (ebd -> arch != bfd_arch_sparc)
1175 bfd_default_set_arch_mach(abfd, bfd_arch_sparc, 0);
1178 if (ebd -> arch != bfd_arch_i386)
1180 bfd_default_set_arch_mach(abfd, bfd_arch_i386, 0);
1183 if (ebd -> arch != bfd_arch_m68k)
1185 bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0);
1188 if (ebd -> arch != bfd_arch_m88k)
1190 bfd_default_set_arch_mach(abfd, bfd_arch_m88k, 0);
1193 if (ebd -> arch != bfd_arch_i860)
1195 bfd_default_set_arch_mach(abfd, bfd_arch_i860, 0);
1198 if (ebd -> arch != bfd_arch_mips)
1200 bfd_default_set_arch_mach(abfd, bfd_arch_mips, 0);
1206 /* Allocate space for a copy of the section header table in
1207 internal form, seek to the section header table in the file,
1208 read it in, and convert it to internal form. As a simple sanity
1209 check, verify that the what BFD thinks is the size of each section
1210 header table entry actually matches the size recorded in the file. */
1212 if (i_ehdrp->e_shentsize != sizeof (x_shdr))
1214 i_shdrp = (Elf_Internal_Shdr *)
1215 bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum);
1218 bfd_error = no_memory;
1221 if (bfd_seek (abfd, i_ehdrp->e_shoff, SEEK_SET) == -1)
1223 bfd_error = system_call_error;
1226 for (shindex = 0; shindex < i_ehdrp->e_shnum; shindex++)
1228 if (bfd_read ((PTR) &x_shdr, sizeof x_shdr, 1, abfd)
1231 bfd_error = system_call_error;
1234 elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex);
1237 elf_elfsections (abfd) = i_shdrp;
1239 /* Read in the string table containing the names of the sections. We
1240 will need the base pointer to this table later. */
1241 /* We read this inline now, so that we don't have to go through
1242 bfd_section_from_shdr with it (since this particular strtab is
1243 used to find all of the ELF section names.) */
1245 shstrtab = elf_get_str_section (abfd, i_ehdrp->e_shstrndx);
1249 /* Once all of the section headers have been read and converted, we
1250 can start processing them. Note that the first section header is
1251 a dummy placeholder entry, so we ignore it.
1253 We also watch for the symbol table section and remember the file
1254 offset and section size for both the symbol table section and the
1255 associated string table section. */
1257 for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
1259 bfd_section_from_shdr (abfd, shindex);
1262 /* Remember the entry point specified in the ELF file header. */
1264 bfd_get_start_address (abfd) = i_ehdrp->e_entry;
1266 return (abfd->xvec);
1269 /* Core files are simply standard ELF formatted files that partition
1270 the file using the execution view of the file (program header table)
1271 rather than the linking view. In fact, there is no section header
1272 table in a core file.
1274 The process status information (including the contents of the general
1275 register set) and the floating point register set are stored in a
1276 segment of type PT_NOTE. We handcraft a couple of extra bfd sections
1277 that allow standard bfd access to the general registers (.reg) and the
1278 floating point registers (.reg2).
1283 DEFUN (elf_core_file_p, (abfd), bfd *abfd)
1285 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
1286 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
1287 Elf_External_Phdr x_phdr; /* Program header table entry, external form */
1288 Elf_Internal_Phdr *i_phdrp; /* Program header table, internal form */
1289 unsigned int phindex;
1291 /* Read in the ELF header in external format. */
1293 if (bfd_read ((PTR) &x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
1295 bfd_error = system_call_error;
1299 /* Now check to see if we have a valid ELF file, and one that BFD can
1300 make use of. The magic number must match, the address size ('class')
1301 and byte-swapping must match our XVEC entry, and it must have a
1302 program header table (FIXME: See comments re segments at top of this
1305 if (x_ehdr.e_ident[EI_MAG0] != ELFMAG0 ||
1306 x_ehdr.e_ident[EI_MAG1] != ELFMAG1 ||
1307 x_ehdr.e_ident[EI_MAG2] != ELFMAG2 ||
1308 x_ehdr.e_ident[EI_MAG3] != ELFMAG3)
1311 bfd_error = wrong_format;
1315 /* FIXME, Check EI_VERSION here ! */
1317 switch (x_ehdr.e_ident[EI_CLASS])
1319 case ELFCLASSNONE: /* address size not specified */
1320 goto wrong; /* No support if can't tell address size */
1321 case ELFCLASS32: /* 32-bit addresses */
1323 case ELFCLASS64: /* 64-bit addresses */
1324 goto wrong; /* FIXME: 64 bits not yet supported */
1326 goto wrong; /* No support if unknown address class */
1329 /* Switch xvec to match the specified byte order. */
1330 switch (x_ehdr.e_ident[EI_DATA])
1332 case ELFDATA2MSB: /* Big-endian */
1333 if (abfd->xvec->byteorder_big_p == false)
1336 case ELFDATA2LSB: /* Little-endian */
1337 if (abfd->xvec->byteorder_big_p == true)
1340 case ELFDATANONE: /* No data encoding specified */
1341 default: /* Unknown data encoding specified */
1345 /* Allocate an instance of the elf_obj_tdata structure and hook it up to
1346 the tdata pointer in the bfd. */
1349 (struct elf_obj_tdata *) bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));
1350 if (elf_tdata (abfd) == NULL)
1352 bfd_error = no_memory;
1356 /* FIXME, `wrong' returns from this point onward, leak memory. */
1358 /* Now that we know the byte order, swap in the rest of the header */
1359 i_ehdrp = elf_elfheader (abfd);
1360 elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
1362 /* If there is no program header, or the type is not a core file, then
1364 if (i_ehdrp->e_phoff == 0 || i_ehdrp->e_type != ET_CORE)
1367 /* Allocate space for a copy of the program header table in
1368 internal form, seek to the program header table in the file,
1369 read it in, and convert it to internal form. As a simple sanity
1370 check, verify that the what BFD thinks is the size of each program
1371 header table entry actually matches the size recorded in the file. */
1373 if (i_ehdrp->e_phentsize != sizeof (x_phdr))
1375 i_phdrp = (Elf_Internal_Phdr *)
1376 bfd_alloc (abfd, sizeof (*i_phdrp) * i_ehdrp->e_phnum);
1379 bfd_error = no_memory;
1382 if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) == -1)
1384 bfd_error = system_call_error;
1387 for (phindex = 0; phindex < i_ehdrp->e_phnum; phindex++)
1389 if (bfd_read ((PTR) &x_phdr, sizeof (x_phdr), 1, abfd)
1392 bfd_error = system_call_error;
1395 elf_swap_phdr_in (abfd, &x_phdr, i_phdrp + phindex);
1398 /* Once all of the program headers have been read and converted, we
1399 can start processing them. */
1401 for (phindex = 0; phindex < i_ehdrp->e_phnum; phindex++)
1403 bfd_section_from_phdr (abfd, i_phdrp + phindex, phindex);
1404 if ((i_phdrp + phindex) -> p_type == PT_NOTE)
1406 elf_corefile_note (abfd, i_phdrp + phindex);
1410 /* Remember the entry point specified in the ELF file header. */
1412 bfd_get_start_address (abfd) = i_ehdrp->e_entry;
1414 return (abfd->xvec);
1418 DEFUN (elf_mkobject, (abfd), bfd *abfd)
1420 /* this just does initialization */
1421 /* coff_mkobject zalloc's space for tdata.coff_obj_data ... */
1422 elf_tdata(abfd) = (struct elf_obj_tdata *)
1423 bfd_zalloc (abfd, sizeof(struct elf_obj_tdata));
1424 if (elf_tdata(abfd) == 0) {
1425 bfd_error = no_memory;
1428 /* since everything is done at close time, do we need any
1435 Create ELF output from BFD sections.
1437 Essentially, just create the section header and forget about the program
1442 /* lacking nested functions and nested types, set up for mapping over
1443 BFD sections to produce ELF sections */
1446 Elf_Internal_Ehdr *i_ehdr;
1447 Elf_Internal_Shdr *i_shdrp;
1448 struct strtab *shstrtab;
1455 DEFUN (elf_make_sections, (abfd, asect, obj),
1460 elf_sect_thunk *thunk = (elf_sect_thunk*)obj;
1461 /* most of what is in bfd_shdr_from_section goes in here... */
1462 /* and all of these sections generate at *least* one ELF section. */
1466 /* check if we're making a PROGBITS section... */
1467 /* if ((asect->flags & SEC_ALLOC) && (asect->flags & SEC_LOAD)) */
1468 /* this was too strict... what *do* we want to check here? */
1471 Elf_Internal_Shdr *this_hdr;
1472 this_section = elf_section_from_bfd_section (abfd, asect);
1473 this_hdr = &thunk->i_shdrp[this_section];
1475 this_hdr->sh_addr = asect->vma;
1476 this_hdr->sh_size = asect->_raw_size;
1477 /* contents already set by elf_set_section_contents */
1479 if (asect->flags & SEC_RELOC)
1481 /* emit a reloc section, and thus strtab and symtab... */
1482 Elf_Internal_Shdr *rela_hdr;
1483 Elf_Internal_Shdr *symtab_hdr;
1484 Elf_External_Rela *outbound_relocs;
1487 symtab_hdr = &thunk->i_shdrp[thunk->symtab_section];
1489 if (thunk->symtab_section == this_section + 1)
1490 rela_section = thunk->symtab_section + 2; /* symtab + symstrtab */
1492 rela_section = this_section + 1;
1493 rela_hdr = &thunk->i_shdrp[rela_section];
1494 rela_hdr->sh_type = SHT_RELA;
1495 rela_hdr->sh_link = thunk->symtab_section;
1496 rela_hdr->sh_info = this_section;
1497 rela_hdr->sh_entsize = sizeof (Elf_External_Rela);
1498 /* orelocation has the data, reloc_count has the count... */
1499 rela_hdr->sh_size = rela_hdr->sh_entsize * asect->reloc_count;
1500 outbound_relocs = (Elf_External_Rela *)
1501 bfd_alloc(abfd, asect->reloc_count * sizeof(Elf_External_Rela));
1502 for (idx = 0; idx < asect->reloc_count; idx++)
1504 Elf_Internal_Rela dst;
1506 Elf_External_Rela *src;
1508 ptr = asect->orelocation[idx];
1509 src = outbound_relocs + idx;
1510 if (asect->flags & SEC_RELOC)
1511 dst.r_offset = ptr->address - asect->vma;
1513 dst.r_offset = ptr->address;
1515 dst.r_info = ELF_R_INFO(1 /*ptr->sym_ptr_ptr*/, /* needs index into symtab (FIXME) */
1518 dst.r_addend = ptr->addend;
1519 elf_swap_reloca_out(abfd, &dst, src);
1521 rela_hdr->contents = (void*)outbound_relocs;
1527 DEFUN (elf_fake_sections, (abfd, asect, obj),
1532 elf_sect_thunk *thunk = (elf_sect_thunk*)obj;
1533 /* most of what is in bfd_shdr_from_section goes in here... */
1534 /* and all of these sections generate at *least* one ELF section. */
1537 /* check if we're making a PROGBITS section... */
1538 /* if ((asect->flags & SEC_ALLOC) && (asect->flags & SEC_LOAD)) */
1539 /* this was too strict... what *do* we want to check here? */
1542 Elf_Internal_Shdr *this_hdr;
1543 this_section = thunk->i_ehdr->e_shnum++;
1544 this_hdr = &thunk->i_shdrp[this_section];
1546 bfd_add_to_strtab (abfd, thunk->shstrtab, asect->name);
1547 /* we need to log the type *now* so that elf_section_from_bfd_section
1548 can find us... have to set rawdata too. */
1549 this_hdr->rawdata = (void*)asect;
1550 if ((asect->flags & SEC_ALLOC) && (asect->flags & SEC_LOAD))
1551 this_hdr->sh_type = SHT_PROGBITS;
1553 /* what *do* we put here? */
1554 this_hdr->sh_type = SHT_PROGBITS;
1557 if (asect->flags & SEC_RELOC)
1559 /* emit a reloc section, and thus strtab and symtab... */
1560 Elf_Internal_Shdr *rela_hdr;
1561 Elf_Internal_Shdr *symtab_hdr;
1562 Elf_Internal_Shdr *symstrtab_hdr;
1564 int symstrtab_section;
1566 /* note that only one symtab is used, so just remember it
1568 if (! thunk->symtab_section)
1570 thunk->symtab_section = thunk->i_ehdr->e_shnum++;
1571 symtab_hdr = &thunk->i_shdrp[thunk->symtab_section];
1572 symtab_hdr->sh_name =
1573 bfd_add_to_strtab (abfd, thunk->shstrtab, ".symtab");
1574 symtab_hdr->sh_type = SHT_SYMTAB;
1575 symtab_hdr->sh_entsize = sizeof (Elf_External_Sym);
1577 symstrtab_section = thunk->i_ehdr->e_shnum++;
1578 BFD_ASSERT(symstrtab_section == thunk->symtab_section+1);
1579 symstrtab_hdr = &thunk->i_shdrp[symstrtab_section];
1580 symtab_hdr->sh_link = symstrtab_section;
1581 symstrtab_hdr->sh_name =
1582 bfd_add_to_strtab (abfd, thunk->shstrtab, ".strtab");
1583 symstrtab_hdr->sh_type = SHT_STRTAB;
1585 symtab_hdr->contents = 0;
1586 symstrtab_hdr->contents = 0;
1587 symstrtab_hdr->sh_size = 0;
1590 symtab_hdr = &thunk->i_shdrp[thunk->symtab_section];
1592 rela_section = thunk->i_ehdr->e_shnum++;
1593 rela_hdr = &thunk->i_shdrp[rela_section];
1595 bfd_add_2_to_strtab (abfd, thunk->shstrtab, ".rela", asect->name);
1596 rela_hdr->sh_type = SHT_RELA;
1597 rela_hdr->sh_link = thunk->symtab_section;
1598 rela_hdr->sh_info = this_section;
1599 rela_hdr->sh_entsize = sizeof (Elf_External_Rela);
1606 DEFUN (elf_compute_section_file_positions, (abfd), bfd *abfd)
1608 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
1609 Elf_Internal_Shdr *i_shdrp; /* Section header table, internal form */
1610 struct strtab *shstrtab;
1611 int count, maxsections;
1614 if (! elf_shstrtab (abfd)) {
1615 i_ehdrp = elf_elfheader (abfd); /* build new header in tdata memory */
1616 shstrtab = bfd_new_strtab(abfd);
1618 i_ehdrp->e_ident[EI_MAG0] = ELFMAG0;
1619 i_ehdrp->e_ident[EI_MAG1] = ELFMAG1;
1620 i_ehdrp->e_ident[EI_MAG2] = ELFMAG2;
1621 i_ehdrp->e_ident[EI_MAG3] = ELFMAG3;
1623 i_ehdrp->e_ident[EI_CLASS] = ELFCLASS32; /* FIXME: find out from bfd */
1624 i_ehdrp->e_ident[EI_DATA] =
1625 abfd->xvec->byteorder_big_p ? ELFDATA2MSB : ELFDATA2LSB;
1626 i_ehdrp->e_ident[EI_VERSION] = EV_CURRENT;
1628 for(count = EI_PAD; count < EI_NIDENT; count ++)
1629 i_ehdrp->e_ident[count] = 0;
1631 i_ehdrp->e_type = (abfd->flags & EXEC_P)? ET_EXEC : ET_REL;
1632 switch(bfd_get_arch(abfd))
1634 case bfd_arch_unknown:
1635 i_ehdrp->e_machine = EM_NONE;
1637 case bfd_arch_sparc:
1638 i_ehdrp->e_machine = EM_SPARC;
1641 i_ehdrp->e_machine = EM_386;
1644 i_ehdrp->e_machine = EM_68K;
1647 i_ehdrp->e_machine = EM_88K;
1650 i_ehdrp->e_machine = EM_860;
1652 case bfd_arch_mips: /* MIPS Rxxxx */
1653 i_ehdrp->e_machine = EM_MIPS; /* only MIPS R3000 */
1655 /* also note that EM_M32, AT&T WE32100 is unknown to bfd */
1657 i_ehdrp->e_machine = EM_NONE;
1659 i_ehdrp->e_version = EV_CURRENT;
1660 i_ehdrp->e_ehsize = sizeof(Elf_External_Ehdr);
1662 /* no program header, for now. */
1663 i_ehdrp->e_phoff = 0;
1664 i_ehdrp->e_phentsize = 0;
1665 i_ehdrp->e_phnum = 0;
1667 /* each bfd section is section header entry */
1668 i_ehdrp->e_entry = bfd_get_start_address (abfd);
1669 i_ehdrp->e_shentsize = sizeof (Elf_External_Shdr);
1671 /* figure at most each section can have a rel, strtab, symtab */
1672 maxsections = 4*bfd_count_sections(abfd)+2;
1674 i_ehdrp->e_shoff = i_ehdrp->e_ehsize;
1676 /* and we'll just have to fix up the offsets later. */
1677 /* outbase += i_ehdr.e_shentsize * i_ehdr.e_shnum; */
1679 i_shdrp = (Elf_Internal_Shdr *)
1680 bfd_alloc (abfd, sizeof (*i_shdrp) * maxsections);
1683 bfd_error = no_memory;
1686 for (count=0; count < maxsections; count++)
1688 i_shdrp[count].rawdata = 0;
1689 i_shdrp[count].contents = 0;
1693 i_shdrp[0].sh_name = 0;
1694 i_shdrp[0].sh_type = SHT_NULL;
1695 i_shdrp[0].sh_flags = 0;
1696 i_shdrp[0].sh_addr = 0;
1697 i_shdrp[0].sh_offset = 0;
1698 i_shdrp[0].sh_size = 0;
1699 i_shdrp[0].sh_link = SHN_UNDEF;
1700 i_shdrp[0].sh_info = 0;
1701 i_shdrp[0].sh_addralign = 0;
1702 i_shdrp[0].sh_entsize = 0;
1704 i_ehdrp->e_shnum = 1;
1706 elf_elfsections (abfd) = i_shdrp;
1707 elf_shstrtab (abfd) = shstrtab;
1709 est.i_ehdr = elf_elfheader(abfd);
1710 est.i_shdrp = elf_elfsections(abfd);
1711 est.shstrtab = elf_shstrtab(abfd);
1712 est.symtab_section = 0; /* elf_fake_sections fils it in */
1714 bfd_map_over_sections(abfd, elf_fake_sections, &est);
1715 elf_onesymtab (abfd) = est.symtab_section;
1720 DEFUN (elf_write_object_contents, (abfd), bfd *abfd)
1722 Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
1723 Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
1724 Elf_External_Shdr *x_shdrp; /* Section header table, external form */
1725 Elf_Internal_Shdr *i_shdrp; /* Section header table, internal form */
1731 struct strtab *shstrtab;
1733 if(abfd->output_has_begun == false)
1734 elf_compute_section_file_positions(abfd);
1736 i_ehdrp = elf_elfheader (abfd);
1737 i_shdrp = elf_elfsections (abfd);
1738 shstrtab = elf_shstrtab (abfd);
1740 est.i_ehdr = i_ehdrp;
1741 est.i_shdrp = i_shdrp;
1742 est.shstrtab = shstrtab;
1743 est.symtab_section = elf_onesymtab (abfd); /* filled in by elf_fake */
1745 bfd_map_over_sections(abfd, elf_make_sections, &est);
1747 /* dump out the one symtab */
1749 int symcount = bfd_get_symcount (abfd);
1750 asymbol ** syms = bfd_get_outsymbols (abfd);
1751 struct strtab * stt = bfd_new_strtab (abfd);
1752 Elf_Internal_Shdr *symtab_hdr;
1753 Elf_Internal_Shdr *symstrtab_hdr;
1754 int symstrtab_section;
1755 Elf_External_Sym *outbound_syms;
1758 symtab_hdr = &i_shdrp[est.symtab_section];
1759 symtab_hdr->sh_type = SHT_SYMTAB;
1760 symtab_hdr->sh_entsize = sizeof (Elf_External_Sym);
1761 symtab_hdr->sh_size = symtab_hdr->sh_entsize * symcount;
1763 /* see assert in elf_fake_sections that supports this: */
1764 symstrtab_section = est.symtab_section+1;
1765 symstrtab_hdr = &i_shdrp[symstrtab_section];
1766 symtab_hdr->sh_link = symstrtab_section;
1767 symstrtab_hdr->sh_type = SHT_STRTAB;
1769 outbound_syms = (Elf_External_Sym*)
1770 bfd_alloc(abfd, (1+symcount) * sizeof(Elf_External_Sym));
1771 /* now generate the data (for "contents") */
1772 for (idx = 0; idx < symcount; idx++)
1774 Elf_Internal_Sym sym;
1775 sym.st_name = bfd_add_to_strtab (abfd, stt, syms[idx]->name);
1776 sym.st_value = syms[idx]->value;
1777 sym.st_size = 0; /* we should recover this (FIXME) */
1778 if (syms[idx]->flags & BSF_WEAK)
1779 sym.st_info = ELF_ST_INFO(STB_WEAK, STT_OBJECT);
1780 else if (syms[idx]->flags & BSF_LOCAL)
1781 sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_OBJECT);
1782 else if (syms[idx]->flags & BSF_GLOBAL)
1783 sym.st_info = ELF_ST_INFO(STB_GLOBAL, STT_OBJECT);
1784 else if (syms[idx]->flags & BSF_SECTION_SYM)
1785 sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_SECTION);
1786 else if (syms[idx]->flags & BSF_FILE)
1787 sym.st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE);
1790 if (syms[idx]->section)
1792 elf_section_from_bfd_section(abfd,
1793 syms[idx]->section->output_section);
1795 sym.st_shndx = SHN_UNDEF;
1797 elf_swap_symbol_out (abfd, &sym, outbound_syms+idx+1);
1800 /* fill in 0th symbol */
1801 Elf_Internal_Sym sym;
1807 sym.st_shndx = SHN_UNDEF;
1808 elf_swap_symbol_out (abfd, &sym, outbound_syms);
1810 symtab_hdr->contents = (void*)outbound_syms;
1811 symstrtab_hdr->contents = (void*)stt->tab;
1812 symstrtab_hdr->sh_size = stt->length;
1815 /* put the strtab out too... */
1817 Elf_Internal_Shdr *this_hdr;
1820 this_section = i_ehdrp->e_shnum++;
1821 i_ehdrp->e_shstrndx = this_section;
1822 this_hdr = &i_shdrp[this_section];
1823 this_hdr->sh_name = bfd_add_to_strtab (abfd, shstrtab, ".shstrtab");
1824 this_hdr->sh_type = SHT_STRTAB;
1825 this_hdr->sh_size = shstrtab->length;
1826 this_hdr->contents = (void*)shstrtab->tab;
1829 outbase = i_ehdrp->e_ehsize;
1831 /* swap the header before spitting it out... */
1832 elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr);
1833 bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
1834 bfd_write ((PTR) &x_ehdr, sizeof(x_ehdr), 1, abfd);
1836 outbase += i_ehdrp->e_shentsize * i_ehdrp->e_shnum;
1838 /* now we fix up the offsets... */
1839 for (count = 1; count < i_ehdrp->e_shnum; count ++)
1841 i_shdrp[count].sh_offset = outbase;
1842 outbase += i_shdrp[count].sh_size;
1845 /* at this point we've concocted all the ELF sections... */
1846 x_shdrp = (Elf_External_Shdr *)
1847 bfd_alloc (abfd, sizeof (*x_shdrp) * (i_ehdrp->e_shnum));
1850 bfd_error = no_memory;
1854 for (count = 0; count < i_ehdrp->e_shnum; count ++)
1856 elf_swap_shdr_out (abfd, i_shdrp+count, x_shdrp+count);
1858 bfd_write ((PTR) x_shdrp, sizeof(*x_shdrp), i_ehdrp->e_shnum, abfd);
1859 /* need to dump the string table too... */
1861 /* after writing the headers, we need to write the sections too... */
1862 nsect = abfd->sections;
1863 for (count = 0; count < i_ehdrp->e_shnum; count ++)
1865 if(i_shdrp[count].contents)
1867 bfd_seek (abfd, i_shdrp[count].sh_offset, SEEK_SET);
1868 bfd_write (i_shdrp[count].contents, i_shdrp[count].sh_size, 1, abfd);
1872 /* sample use of bfd:
1873 * bfd_seek (abfd, (file_ptr) 0, SEEK_SET);
1874 * bfd_write ((PTR) &exec_bytes, 1, EXEC_BYTES_SIZE, abfd);
1875 * if (bfd_seek(abfd, scn_base, SEEK_SET) != 0)
1877 * old = bfd_tell(abfd);
1884 /* Given an index of a section, retrieve a pointer to it. Note
1885 that for our purposes, sections are indexed by {1, 2, ...} with
1886 0 being an illegal index. */
1888 /* In the original, each ELF section went into exactly one BFD
1889 section. This doesn't really make sense, so we need a real mapping.
1890 The mapping has to hide in the Elf_Internal_Shdr since asection
1891 doesn't have anything like a tdata field... */
1894 DEFUN (section_from_elf_index, (abfd, index),
1898 Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
1899 Elf_Internal_Shdr *hdr = i_shdrp + index;
1901 switch (hdr->sh_type)
1903 /* ELF sections that map to BFD sections */
1907 bfd_section_from_shdr (abfd, index);
1908 return (struct sec *)hdr->rawdata;
1911 return (struct sec *)&bfd_abs_section;
1915 /* given a section, search the header to find them... */
1917 DEFUN (elf_section_from_bfd_section, (abfd, asect),
1921 Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
1923 Elf_Internal_Shdr *hdr;
1924 int maxindex = elf_elfheader (abfd)->e_shnum;
1926 for(index = 0; index < maxindex; index++) {
1927 hdr = &i_shdrp[index];
1928 switch (hdr->sh_type)
1930 /* ELF sections that map to BFD sections */
1935 if (((struct sec *)(hdr->rawdata)) == asect)
1947 DEFUN (elf_slurp_symbol_table, (abfd, symptrs),
1949 asymbol **symptrs) /* Buffer for generated bfd symbols */
1951 Elf_Internal_Shdr *i_shdrp = elf_elfsections (abfd);
1952 Elf_Internal_Shdr *hdr = i_shdrp + elf_onesymtab (abfd);
1953 int symcount; /* Number of external ELF symbols */
1955 asymbol *sym; /* Pointer to current bfd symbol */
1956 asymbol *symbase; /* Buffer for generated bfd symbols */
1957 Elf_Internal_Sym i_sym;
1958 Elf_External_Sym *x_symp;
1960 /* this is only valid because there is only one symtab... */
1961 /* FIXME: This is incorrect, there may also be a dynamic symbol
1962 table which is a subset of the full symbol table. We either need
1963 to be prepared to read both (and merge them) or ensure that we
1964 only read the full symbol table. Currently we only get called to
1965 read the full symbol table. -fnf */
1966 if (bfd_get_outsymbols (abfd) != NULL)
1971 /* Read each raw ELF symbol, converting from external ELF form to
1972 internal ELF form, and then using the information to create a
1973 canonical bfd symbol table entry.
1975 Note that we allocate the initial bfd canonical symbol buffer
1976 based on a one-to-one mapping of the ELF symbols to canonical
1977 symbols. We actually use all the ELF symbols, so there will be no
1978 space left over at the end. When we have all the symbols, we
1979 build the caller's pointer vector. */
1981 if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
1983 bfd_error = system_call_error;
1987 symcount = hdr->sh_size / sizeof (Elf_External_Sym);
1988 symbase = (asymbol *) bfd_zalloc (abfd, symcount * sizeof (asymbol));
1991 /* Temporarily allocate room for the raw ELF symbols. */
1992 x_symp = (Elf_External_Sym *) bfd_xmalloc (symcount * sizeof (Elf_External_Sym));
1994 if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)
1995 != symcount * sizeof (Elf_External_Sym))
1998 bfd_error = system_call_error;
2001 /* Skip first symbol, which is a null dummy. */
2002 for (i = 1; i < symcount; i++)
2004 elf_swap_symbol_in (abfd, x_symp + i, &i_sym);
2005 sym -> the_bfd = abfd;
2006 if (i_sym.st_name > 0)
2007 sym -> name = elf_string_from_elf_section(abfd, hdr->sh_link,
2010 sym -> name = "unnamed"; /* perhaps should include the number? */
2011 sym -> value = i_sym.st_value;
2012 /* FIXME -- this is almost certainly bogus. It's from Pace Willisson's
2013 hasty Solaris support, to pass the sizes of object files or functions
2014 down into GDB via the back door, to circumvent some other kludge in
2015 how Sun hacked stabs. -- gnu@cygnus.com */
2016 sym -> udata = (PTR)i_sym.st_size;
2017 /* FIXME -- end of bogosity. */
2018 if (i_sym.st_shndx > 0 && i_sym.st_shndx < SHN_LORESERV)
2020 sym -> section = section_from_elf_index (abfd, i_sym.st_shndx);
2022 else if (i_sym.st_shndx == SHN_ABS)
2024 sym -> section = &bfd_abs_section;
2026 else if (i_sym.st_shndx == SHN_COMMON)
2028 sym -> section = &bfd_com_section;
2030 else if (i_sym.st_shndx == SHN_UNDEF)
2032 sym -> section = &bfd_und_section;
2035 sym -> section = &bfd_abs_section;
2037 switch (ELF_ST_BIND (i_sym.st_info))
2040 sym -> flags |= BSF_LOCAL;
2043 sym -> flags |= (BSF_GLOBAL | BSF_EXPORT);
2046 sym -> flags |= BSF_WEAK;
2050 switch (ELF_ST_TYPE (i_sym.st_info))
2053 sym->flags |= BSF_SECTION_SYM | BSF_DEBUGGING;
2056 sym->flags |= BSF_FILE | BSF_DEBUGGING;
2062 /* We rely on the zalloc to clear out the final symbol entry. */
2064 /* We're now done with the raw symbols. */
2067 bfd_get_symcount(abfd) = symcount = sym - symbase;
2069 /* Fill in the user's symbol pointer vector if needed. */
2073 while (symcount-- > 0)
2077 *symptrs = 0; /* Final null pointer */
2083 /* Return the number of bytes required to hold the symtab vector.
2085 Note that we base it on the count plus 1, since we will null terminate
2086 the vector allocated based on this size. However, the ELF symbol table
2087 always has a dummy entry as symbol #0, so it ends up even. */
2090 DEFUN (elf_get_symtab_upper_bound, (abfd), bfd *abfd)
2092 unsigned int symcount;
2093 unsigned int symtab_size = 0;
2094 Elf_Internal_Shdr *i_shdrp;
2095 Elf_Internal_Shdr *hdr;
2097 i_shdrp = elf_elfsections (abfd);
2098 if (i_shdrp != NULL)
2100 hdr = i_shdrp + elf_onesymtab (abfd);
2101 symcount = hdr->sh_size / sizeof (Elf_External_Sym);
2102 symtab_size = (symcount - 1 + 1) * (sizeof (asymbol));
2104 return (symtab_size);
2108 This function return the number of bytes required to store the
2109 relocation information associated with section <<sect>>
2110 attached to bfd <<abfd>>
2114 elf_get_reloc_upper_bound (abfd, asect)
2118 if (asect->flags & SEC_RELOC)
2120 /* either rel or rela */
2121 return asect->_raw_size;
2128 DEFUN(elf_slurp_reloca_table,(abfd, asect, symbols),
2133 Elf_External_Rela *native_relocs;
2134 arelent *reloc_cache;
2139 if (asect->relocation)
2141 if (asect->reloc_count == 0)
2143 if (asect->flags & SEC_CONSTRUCTOR)
2146 bfd_seek (abfd, asect->rel_filepos, SEEK_SET);
2147 native_relocs = (Elf_External_Rela *)
2148 bfd_alloc(abfd, asect->reloc_count * sizeof(Elf_External_Rela));
2149 bfd_read ((PTR) native_relocs,
2150 sizeof(Elf_External_Rela), asect->reloc_count, abfd);
2152 reloc_cache = (arelent *)
2153 bfd_alloc(abfd, (size_t) (asect->reloc_count * sizeof(arelent)));
2155 if (! reloc_cache) {
2156 bfd_error = no_memory;
2160 for (idx = 0; idx < asect->reloc_count; idx ++)
2162 #ifdef RELOC_PROCESSING
2163 /* sparc, 68k, 88k, 860 use rela only. */
2164 /* 386 and we32000 use rel only... fix it for them later. */
2165 Elf_Internal_Rela dst;
2166 Elf_External_Rela *src;
2168 cache_ptr = reloc_cache + idx;
2169 src = native_relocs + idx;
2170 elf_swap_reloca_in(abfd, src, &dst);
2172 RELOC_PROCESSING(cache_ptr, &dst, symbols, abfd, asect);
2174 Elf_Internal_Rela dst;
2175 Elf_External_Rela *src;
2177 cache_ptr = reloc_cache + idx;
2178 src = native_relocs + idx;
2180 elf_swap_reloca_in(abfd, src, &dst);
2182 if(asect->flags & SEC_RELOC)
2184 /* relocatable, so the offset is off of the section */
2185 cache_ptr->address = dst.r_offset + asect->vma;
2189 /* non-relocatable, so the offset a virtual address */
2190 cache_ptr->address = dst.r_offset;
2192 /* ELF_R_SYM(dst.r_info) is the symbol table offset... */
2193 cache_ptr->sym_ptr_ptr = symbols + ELF_R_SYM(dst.r_info);
2194 cache_ptr->addend = dst.r_addend;
2196 /* Fill in the cache_ptr->howto field from dst.r_type */
2198 struct elf_backend_data *ebd;
2199 ebd = (struct elf_backend_data *) (abfd->xvec->backend_data);
2200 (*ebd->elf_info_to_howto)(abfd, cache_ptr, &dst);
2205 asect->relocation = reloc_cache;
2211 elf_canonicalize_reloc (abfd, section, relptr, symbols)
2217 arelent *tblptr = section->relocation;
2218 unsigned int count = 0;
2220 /* snarfed from coffcode.h */
2221 /* FIXME: this could be reloc... */
2222 elf_slurp_reloca_table(abfd, section, symbols);
2224 tblptr = section->relocation;
2228 for (; count++ < section->reloc_count;)
2229 *relptr++ = tblptr++;
2232 return section->reloc_count;
2236 DEFUN (elf_get_symtab, (abfd, alocation),
2238 asymbol **alocation)
2241 if (!elf_slurp_symbol_table (abfd, alocation))
2244 return (bfd_get_symcount (abfd));
2248 DEFUN (elf_make_empty_symbol, (abfd),
2251 elf_symbol_type *newsym;
2253 newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof (elf_symbol_type));
2256 bfd_error = no_memory;
2261 newsym -> symbol.the_bfd = abfd;
2262 return (&newsym -> symbol);
2267 DEFUN (elf_print_symbol,(ignore_abfd, filep, symbol, how),
2268 bfd *ignore_abfd AND
2271 bfd_print_symbol_type how)
2273 FILE *file = (FILE *)filep;
2276 case bfd_print_symbol_name:
2277 fprintf(file, "%s", symbol->name);
2279 case bfd_print_symbol_more:
2280 fprintf(file, "elf %lx %lx",
2284 case bfd_print_symbol_nm:
2285 case bfd_print_symbol_all:
2287 CONST char *section_name;
2288 section_name = symbol->section? symbol->section->name : "(*none*)";
2289 bfd_print_symbol_vandf((PTR) file, symbol);
2290 fprintf(file, " %s\t%s",
2300 DEFUN (elf_get_lineno,(ignore_abfd, symbol),
2301 bfd *ignore_abfd AND
2304 fprintf (stderr, "elf_get_lineno unimplemented\n");
2311 DEFUN (elf_set_arch_mach,(abfd, arch, machine),
2313 enum bfd_architecture arch AND
2314 unsigned long machine)
2316 /* Allow any architecture to be supported by the elf backend */
2319 case bfd_arch_unknown: /* EM_NONE */
2320 case bfd_arch_sparc: /* EM_SPARC */
2321 case bfd_arch_i386: /* EM_386 */
2322 case bfd_arch_m68k: /* EM_68K */
2323 case bfd_arch_m88k: /* EM_88K */
2324 case bfd_arch_i860: /* EM_860 */
2325 case bfd_arch_mips: /* EM_MIPS (MIPS R3000) */
2326 return bfd_default_set_arch_mach(abfd, arch, machine);
2333 DEFUN (elf_find_nearest_line,(abfd,
2341 asection *section AND
2342 asymbol **symbols AND
2344 CONST char **filename_ptr AND
2345 CONST char **functionname_ptr AND
2346 unsigned int *line_ptr)
2348 fprintf (stderr, "elf_find_nearest_line unimplemented\n");
2355 DEFUN (elf_sizeof_headers, (abfd, reloc),
2359 fprintf (stderr, "elf_sizeof_headers unimplemented\n");
2366 DEFUN(elf_set_section_contents, (abfd, section, location, offset, count),
2371 bfd_size_type count)
2375 if (abfd->output_has_begun == false) /* set by bfd.c handler? */
2377 /* do setup calculations (FIXME) */
2378 elf_compute_section_file_positions(abfd);
2381 if(bfd_seek (abfd, (file_ptr)section->filepos + offset, SEEK_SET) == -1)
2383 if(bfd_write (location, (bfd_size_type)1, count, abfd) != count)
2386 /* we really just need to save the contents away... */
2387 dest_sect = elf_section_from_bfd_section(abfd, section);
2391 /* FIXME: allocate in set_section_size, then copy in here... */
2392 contents = (void*)bfd_alloc(abfd, count);
2393 BFD_ASSERT(contents);
2394 memcpy(contents, location, count);
2395 elf_elfsections (abfd)[dest_sect].contents = contents;
2401 DEFUN (elf_no_info_to_howto, (abfd, cache_ptr, dst),
2403 arelent *cache_ptr AND
2404 Elf_Internal_Rela *dst)