#include "sysdep.h"
#include "libbfd.h"
#include "obstack.h"
-#include "elf-common.h"
-#include "elf-internal.h"
-#include "elf-external.h"
+#include "elf/common.h"
+#include "elf/internal.h"
+#include "elf/external.h"
#ifdef HAVE_PROCFS /* Some core file support requires host /proc files */
#include <sys/procfs.h>
in the bfd structure. This information is different for ELF core files
and other ELF files. */
-typedef struct
+typedef struct elf_core_tdata_struct
{
void *prstatus; /* The raw /proc prstatus structure */
void *prpsinfo; /* The raw /proc prpsinfo structure */
} elf_core_tdata;
-#define core_prpsinfo(bfd) (((elf_core_tdata *)((bfd)->tdata))->prpsinfo)
-#define core_prstatus(bfd) (((elf_core_tdata *)((bfd)->tdata))->prstatus)
+#define core_prpsinfo(bfd) (((bfd)->tdata.elf_core_data))->prpsinfo)
+#define core_prpstatus(bfd) (((bfd)->tdata.elf_core_data))->prpstatus)
-typedef struct
+
+typedef struct elf_obj_tdata_struct
{
file_ptr symtab_filepos; /* Offset to start of ELF symtab section */
long symtab_filesz; /* Size of ELF symtab section */
long strtab_filesz; /* Size of ELF string tbl section */
} elf_obj_tdata;
-#define elf_tdata(bfd) ((elf_obj_tdata *) ((bfd) -> tdata))
+#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
#define elf_symtab_filepos(bfd) (elf_tdata(bfd) -> symtab_filepos)
#define elf_symtab_filesz(bfd) (elf_tdata(bfd) -> symtab_filesz)
#define elf_strtab_filepos(bfd) (elf_tdata(bfd) -> strtab_filepos)
}
-/* Translate an ELF header in external format into an ELF header in internal
- format. */
+/* Translate an ELF file header in external format into an ELF file header in
+ internal format. */
static void
DEFUN(elf_swap_ehdr_in,(abfd, src, dst),
Elf_External_Ehdr *src AND
Elf_Internal_Ehdr *dst)
{
- bcopy (src -> e_ident, dst -> e_ident, EI_NIDENT);
+ memcpy (dst -> e_ident, src -> e_ident, EI_NIDENT);
dst -> e_type = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_type);
dst -> e_machine = bfd_h_get_16 (abfd, (bfd_byte *) src -> e_machine);
dst -> e_version = bfd_h_get_32 (abfd, (bfd_byte *) src -> e_version);
name = hdr -> sh_name ? shstrtab + hdr -> sh_name : "unnamed";
newsect = bfd_make_section (abfd, name);
newsect -> vma = hdr -> sh_addr;
- newsect -> size = hdr -> sh_size;
+ newsect -> _raw_size = hdr -> sh_size;
if (!(hdr -> sh_type == SHT_NOBITS))
{
newsect -> filepos = hdr -> sh_offset;
{
newsect -> flags |= SEC_CODE; /* FIXME: may only contain SOME code */
}
+ else
+ {
+ newsect -> flags |= SEC_DATA;
+ }
if (hdr -> sh_type == SHT_SYMTAB)
{
abfd -> flags |= HAS_SYMS;
(void) strcpy (name, namebuf);
newsect = bfd_make_section (abfd, name);
newsect -> vma = hdr -> p_vaddr;
- newsect -> size = hdr -> p_filesz;
+ newsect -> _raw_size = hdr -> p_filesz;
newsect -> filepos = hdr -> p_offset;
newsect -> flags |= SEC_HAS_CONTENTS;
if (hdr -> p_type == PT_LOAD)
(void) strcpy (name, namebuf);
newsect = bfd_make_section (abfd, name);
newsect -> vma = hdr -> p_vaddr + hdr -> p_filesz;
- newsect -> size = hdr -> p_memsz - hdr -> p_filesz;
+ newsect -> _raw_size = hdr -> p_memsz - hdr -> p_filesz;
if (hdr -> p_type == PT_LOAD)
{
newsect -> flags |= SEC_ALLOC;
newsect -> alignment_power = 2;
if ((core_prstatus (abfd) = bfd_alloc (abfd, descsz)) != NULL)
{
- bcopy (descdata, core_prstatus (abfd), descsz);
+ memcpy (core_prstatus (abfd), descdata, descsz);
}
}
}
DEFUN(elf_core_file_failing_command, (abfd),
bfd *abfd)
{
-#if HAVE_PROCFS
+#ifdef HAVE_PROCFS
if (core_prpsinfo (abfd))
{
prpsinfo_t *p = core_prpsinfo (abfd);
DEFUN(elf_core_file_failing_signal, (abfd),
bfd *abfd)
{
-#if HAVE_PROCFS
+#ifdef HAVE_PROCFS
if (core_prstatus (abfd))
{
return (((prstatus_t *)(core_prstatus (abfd))) -> pr_cursig);
bfd *core_bfd AND
bfd *exec_bfd)
{
+#ifdef HAVE_PROCFS
char *corename;
char *execname;
+#endif
/* First, xvecs must match since both are ELF files for the same target. */
return (false);
}
-#if HAVE_PROCFS
+#ifdef HAVE_PROCFS
/* If no prpsinfo, just return true. Otherwise, grab the last component
of the exec'd pathname from the prpsinfo. */
asection *newsect;
if (hdr -> p_filesz > 0
- && (buf = malloc (hdr -> p_filesz)) != NULL
+ && (buf = (char *)malloc(hdr -> p_filesz)) != NULL
&& bfd_seek (abfd, hdr -> p_offset, SEEK_SET) != -1L
&& bfd_read ((PTR) buf, hdr -> p_filesz, 1, abfd) == hdr -> p_filesz)
{
if (sectname != NULL)
{
newsect = bfd_make_section (abfd, sectname);
- newsect -> size = i_note.descsz;
+ newsect -> _raw_size = i_note.descsz;
newsect -> filepos = filepos;
newsect -> flags = SEC_ALLOC | SEC_HAS_CONTENTS;
newsect -> alignment_power = 2;
{
free (buf);
}
+ return true;
+
}
+/* Read a specified number of bytes at a specified offset in an ELF
+ file, into a newly allocated buffer, and return a pointer to the
+ buffer. */
+
+static char *
+DEFUN(elf_read, (abfd, offset, size),
+ bfd *abfd AND
+ long offset AND
+ int size)
+{
+ char *buf;
+
+ if ((buf = bfd_alloc (abfd, size)) == NULL)
+ {
+ bfd_error = no_memory;
+ return (NULL);
+ }
+ if (bfd_seek (abfd, offset, SEEK_SET) == -1)
+ {
+ bfd_error = system_call_error;
+ return (NULL);
+ }
+ if (bfd_read ((PTR) buf, size, 1, abfd) != size)
+ {
+ bfd_error = system_call_error;
+ return (NULL);
+ }
+ return (buf);
+}
+
/* Begin processing a given object.
First we validate the file by reading in the ELF header and checking
int shindex;
char *shstrtab; /* Internal copy of section header stringtab */
int shstrtabsize; /* Size of section header string table */
+ Elf_Off offset; /* Temp place to stash file offsets */
/* Read in the ELF header in external format. */
break;
case ELFDATA2LSB: /* Little-endian */
abfd->xvec = &elf_little_vec;
+ break;
case ELFDATANONE: /* No data encoding specified */
default: /* Unknown data encoding specified */
goto wrong;
/* Allocate an instance of the elf_obj_tdata structure and hook it up to
the tdata pointer in the bfd. */
- if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_obj_tdata))) == NULL)
+ if ((abfd -> tdata.elf_obj_data =
+ (elf_obj_tdata*) bfd_zalloc (abfd, sizeof (elf_obj_tdata)))
+ == NULL)
{
bfd_error = no_memory;
return (NULL);
will need the base pointer to this table later. */
shstrtabsize = i_shdr[i_ehdr.e_shstrndx].sh_size;
- if ((shstrtab = bfd_alloc (abfd, shstrtabsize)) == NULL)
- {
- bfd_error = no_memory;
- return (NULL);
- }
- if (bfd_seek (abfd, i_shdr[i_ehdr.e_shstrndx].sh_offset, SEEK_SET) == -1)
+ offset = i_shdr[i_ehdr.e_shstrndx].sh_offset;
+ if ((shstrtab = elf_read (abfd, offset, shstrtabsize)) == NULL)
{
- bfd_error = system_call_error;
return (NULL);
}
- if (bfd_read ((PTR) shstrtab, shstrtabsize, 1, abfd) != shstrtabsize)
- {
- bfd_error = system_call_error;
- return (NULL);
- }
-
+
/* Once all of the section headers have been read and converted, we
can start processing them. Note that the first section header is
a dummy placeholder entry, so we ignore it.
}
}
+ /* Remember the entry point specified in the ELF file header. */
+
+ bfd_get_start_address (abfd) = i_ehdr.e_entry;
+
return (abfd->xvec);
}
break;
case ELFDATA2LSB: /* Little-endian */
abfd->xvec = &elf_little_vec;
+ break;
case ELFDATANONE: /* No data encoding specified */
default: /* Unknown data encoding specified */
goto wrong;
/* Allocate an instance of the elf_core_tdata structure and hook it up to
the tdata pointer in the bfd. */
- if ((abfd -> tdata = bfd_zalloc (abfd, sizeof (elf_core_tdata))) == NULL)
+ if ((abfd -> tdata.elf_core_data =
+ (elf_core_tdata *) bfd_zalloc (abfd, sizeof (elf_core_tdata)))
+ == NULL)
{
bfd_error = no_memory;
return (NULL);
}
}
+ /* Remember the entry point specified in the ELF file header. */
+
+ bfd_get_start_address (abfd) = i_ehdr.e_entry;
+
return (abfd->xvec);
}
long as the bfd is in use, since we will end up setting up pointers
into it for the names of all the symbols. */
- if (bfd_seek (abfd, elf_strtab_filepos (abfd), SEEK_SET) == -1)
- {
- bfd_error = system_call_error;
- return (false);
- }
- if ((strtab = bfd_alloc (abfd, elf_strtab_filesz (abfd))) == NULL)
+ strtab = elf_read (abfd, elf_strtab_filepos(abfd), elf_strtab_filesz(abfd));
+ if (strtab == NULL)
{
- bfd_error = system_call_error;
- return (false);
- }
- if (bfd_read ((PTR) strtab, elf_strtab_filesz (abfd), 1, abfd) !=
- elf_strtab_filesz (abfd))
- {
- bfd_error = system_call_error;
return (false);
}
}
else if (i_sym.st_shndx == SHN_ABS)
{
- sym -> flags |= BSF_ABSOLUTE;
+/* sym -> flags |= BSF_ABSOLUTE; OBSOLETE */
}
else if (i_sym.st_shndx == SHN_COMMON)
{
- sym -> flags |= BSF_FORT_COMM;
+ sym -> section = &bfd_com_section;
}
switch (ELF_ST_BIND (i_sym.st_info))
{
#define elf_bfd_debug_info_start bfd_void
#define elf_bfd_debug_info_end bfd_void
#define elf_bfd_debug_info_accumulate (PROTO(void,(*),(bfd*, struct sec *))) bfd_void
+#define elf_bfd_get_relocated_section_contents \
+ bfd_generic_get_relocated_section_contents
bfd_target elf_big_vec =
{