aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfcode.h
diff options
context:
space:
mode:
Diffstat (limited to 'bfd/elfcode.h')
-rw-r--r--bfd/elfcode.h287
1 files changed, 147 insertions, 140 deletions
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index d9f3e05..6e3c2c9 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -185,16 +185,16 @@ static char *elf_symbol_flags PARAMS ((flagword));
/* Should perhaps use put_offset, put_word, etc. For now, the two versions
can be handled by explicitly specifying 32 bits or "the long type". */
#if ARCH_SIZE == 64
-#define put_word bfd_h_put_64
-#define put_signed_word bfd_h_put_signed_64
-#define get_word bfd_h_get_64
-#define get_signed_word bfd_h_get_signed_64
+#define H_PUT_WORD H_PUT_64
+#define H_PUT_SIGNED_WORD H_PUT_S64
+#define H_GET_WORD H_GET_64
+#define H_GET_SIGNED_WORD H_GET_S64
#endif
#if ARCH_SIZE == 32
-#define put_word bfd_h_put_32
-#define put_signed_word bfd_h_put_signed_32
-#define get_word bfd_h_get_32
-#define get_signed_word bfd_h_get_signed_32
+#define H_PUT_WORD H_PUT_32
+#define H_PUT_SIGNED_WORD H_PUT_S32
+#define H_GET_WORD H_GET_32
+#define H_GET_SIGNED_WORD H_GET_S32
#endif
/* Translate an ELF symbol in external format into an ELF symbol in internal
@@ -208,15 +208,15 @@ elf_swap_symbol_in (abfd, src, dst)
{
int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
- dst->st_name = bfd_h_get_32 (abfd, (bfd_byte *) src->st_name);
+ dst->st_name = H_GET_32 (abfd, src->st_name);
if (signed_vma)
- dst->st_value = get_signed_word (abfd, (bfd_byte *) src->st_value);
+ dst->st_value = H_GET_SIGNED_WORD (abfd, src->st_value);
else
- dst->st_value = get_word (abfd, (bfd_byte *) src->st_value);
- dst->st_size = get_word (abfd, (bfd_byte *) src->st_size);
- dst->st_info = bfd_h_get_8 (abfd, (bfd_byte *) src->st_info);
- dst->st_other = bfd_h_get_8 (abfd, (bfd_byte *) src->st_other);
- dst->st_shndx = bfd_h_get_16 (abfd, (bfd_byte *) src->st_shndx);
+ dst->st_value = H_GET_WORD (abfd, src->st_value);
+ dst->st_size = H_GET_WORD (abfd, src->st_size);
+ dst->st_info = H_GET_8 (abfd, src->st_info);
+ dst->st_other = H_GET_8 (abfd, src->st_other);
+ dst->st_shndx = H_GET_16 (abfd, src->st_shndx);
}
/* Translate an ELF symbol in internal format into an ELF symbol in external
@@ -229,12 +229,12 @@ elf_swap_symbol_out (abfd, src, cdst)
PTR cdst;
{
Elf_External_Sym *dst = (Elf_External_Sym *) cdst;
- bfd_h_put_32 (abfd, src->st_name, dst->st_name);
- put_word (abfd, src->st_value, dst->st_value);
- put_word (abfd, src->st_size, dst->st_size);
- bfd_h_put_8 (abfd, src->st_info, dst->st_info);
- bfd_h_put_8 (abfd, src->st_other, dst->st_other);
- bfd_h_put_16 (abfd, src->st_shndx, dst->st_shndx);
+ H_PUT_32 (abfd, src->st_name, dst->st_name);
+ H_PUT_WORD (abfd, src->st_value, dst->st_value);
+ H_PUT_WORD (abfd, src->st_size, dst->st_size);
+ H_PUT_8 (abfd, src->st_info, dst->st_info);
+ H_PUT_8 (abfd, src->st_other, dst->st_other);
+ H_PUT_16 (abfd, src->st_shndx, dst->st_shndx);
}
/* Translate an ELF file header in external format into an ELF file header in
@@ -248,22 +248,22 @@ elf_swap_ehdr_in (abfd, src, dst)
{
int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
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);
+ dst->e_type = H_GET_16 (abfd, src->e_type);
+ dst->e_machine = H_GET_16 (abfd, src->e_machine);
+ dst->e_version = H_GET_32 (abfd, src->e_version);
if (signed_vma)
- dst->e_entry = get_signed_word (abfd, (bfd_byte *) src->e_entry);
+ dst->e_entry = H_GET_SIGNED_WORD (abfd, src->e_entry);
else
- dst->e_entry = get_word (abfd, (bfd_byte *) src->e_entry);
- dst->e_phoff = get_word (abfd, (bfd_byte *) src->e_phoff);
- dst->e_shoff = get_word (abfd, (bfd_byte *) src->e_shoff);
- dst->e_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->e_flags);
- dst->e_ehsize = bfd_h_get_16 (abfd, (bfd_byte *) src->e_ehsize);
- dst->e_phentsize = bfd_h_get_16 (abfd, (bfd_byte *) src->e_phentsize);
- dst->e_phnum = bfd_h_get_16 (abfd, (bfd_byte *) src->e_phnum);
- dst->e_shentsize = bfd_h_get_16 (abfd, (bfd_byte *) src->e_shentsize);
- dst->e_shnum = bfd_h_get_16 (abfd, (bfd_byte *) src->e_shnum);
- dst->e_shstrndx = bfd_h_get_16 (abfd, (bfd_byte *) src->e_shstrndx);
+ dst->e_entry = H_GET_WORD (abfd, src->e_entry);
+ dst->e_phoff = H_GET_WORD (abfd, src->e_phoff);
+ dst->e_shoff = H_GET_WORD (abfd, src->e_shoff);
+ dst->e_flags = H_GET_32 (abfd, src->e_flags);
+ dst->e_ehsize = H_GET_16 (abfd, src->e_ehsize);
+ dst->e_phentsize = H_GET_16 (abfd, src->e_phentsize);
+ dst->e_phnum = H_GET_16 (abfd, src->e_phnum);
+ dst->e_shentsize = H_GET_16 (abfd, src->e_shentsize);
+ dst->e_shnum = H_GET_16 (abfd, src->e_shnum);
+ dst->e_shstrndx = H_GET_16 (abfd, src->e_shstrndx);
}
/* Translate an ELF file header in internal format into an ELF file header in
@@ -278,22 +278,22 @@ elf_swap_ehdr_out (abfd, src, dst)
int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
/* note that all elements of dst are *arrays of unsigned char* already... */
- bfd_h_put_16 (abfd, src->e_type, dst->e_type);
- bfd_h_put_16 (abfd, src->e_machine, dst->e_machine);
- bfd_h_put_32 (abfd, src->e_version, dst->e_version);
+ H_PUT_16 (abfd, src->e_type, dst->e_type);
+ H_PUT_16 (abfd, src->e_machine, dst->e_machine);
+ H_PUT_32 (abfd, src->e_version, dst->e_version);
if (signed_vma)
- put_signed_word (abfd, src->e_entry, dst->e_entry);
+ H_PUT_SIGNED_WORD (abfd, src->e_entry, dst->e_entry);
else
- put_word (abfd, src->e_entry, dst->e_entry);
- put_word (abfd, src->e_phoff, dst->e_phoff);
- put_word (abfd, src->e_shoff, dst->e_shoff);
- bfd_h_put_32 (abfd, src->e_flags, dst->e_flags);
- bfd_h_put_16 (abfd, src->e_ehsize, dst->e_ehsize);
- bfd_h_put_16 (abfd, src->e_phentsize, dst->e_phentsize);
- bfd_h_put_16 (abfd, src->e_phnum, dst->e_phnum);
- bfd_h_put_16 (abfd, src->e_shentsize, dst->e_shentsize);
- bfd_h_put_16 (abfd, src->e_shnum, dst->e_shnum);
- bfd_h_put_16 (abfd, src->e_shstrndx, dst->e_shstrndx);
+ H_PUT_WORD (abfd, src->e_entry, dst->e_entry);
+ H_PUT_WORD (abfd, src->e_phoff, dst->e_phoff);
+ H_PUT_WORD (abfd, src->e_shoff, dst->e_shoff);
+ H_PUT_32 (abfd, src->e_flags, dst->e_flags);
+ H_PUT_16 (abfd, src->e_ehsize, dst->e_ehsize);
+ H_PUT_16 (abfd, src->e_phentsize, dst->e_phentsize);
+ H_PUT_16 (abfd, src->e_phnum, dst->e_phnum);
+ H_PUT_16 (abfd, src->e_shentsize, dst->e_shentsize);
+ H_PUT_16 (abfd, src->e_shnum, dst->e_shnum);
+ H_PUT_16 (abfd, src->e_shstrndx, dst->e_shstrndx);
}
/* Translate an ELF section header table entry in external format into an
@@ -307,19 +307,19 @@ elf_swap_shdr_in (abfd, src, dst)
{
int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
- dst->sh_name = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_name);
- dst->sh_type = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_type);
- dst->sh_flags = get_word (abfd, (bfd_byte *) src->sh_flags);
+ dst->sh_name = H_GET_32 (abfd, src->sh_name);
+ dst->sh_type = H_GET_32 (abfd, src->sh_type);
+ dst->sh_flags = H_GET_WORD (abfd, src->sh_flags);
if (signed_vma)
- dst->sh_addr = get_signed_word (abfd, (bfd_byte *) src->sh_addr);
+ dst->sh_addr = H_GET_SIGNED_WORD (abfd, src->sh_addr);
else
- dst->sh_addr = get_word (abfd, (bfd_byte *) src->sh_addr);
- dst->sh_offset = get_word (abfd, (bfd_byte *) src->sh_offset);
- dst->sh_size = get_word (abfd, (bfd_byte *) src->sh_size);
- dst->sh_link = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_link);
- dst->sh_info = bfd_h_get_32 (abfd, (bfd_byte *) src->sh_info);
- dst->sh_addralign = get_word (abfd, (bfd_byte *) src->sh_addralign);
- dst->sh_entsize = get_word (abfd, (bfd_byte *) src->sh_entsize);
+ dst->sh_addr = H_GET_WORD (abfd, src->sh_addr);
+ dst->sh_offset = H_GET_WORD (abfd, src->sh_offset);
+ dst->sh_size = H_GET_WORD (abfd, src->sh_size);
+ dst->sh_link = H_GET_32 (abfd, src->sh_link);
+ dst->sh_info = H_GET_32 (abfd, src->sh_info);
+ dst->sh_addralign = H_GET_WORD (abfd, src->sh_addralign);
+ dst->sh_entsize = H_GET_WORD (abfd, src->sh_entsize);
dst->bfd_section = NULL;
dst->contents = NULL;
}
@@ -334,16 +334,16 @@ elf_swap_shdr_out (abfd, src, dst)
Elf_External_Shdr *dst;
{
/* note that all elements of dst are *arrays of unsigned char* already... */
- bfd_h_put_32 (abfd, src->sh_name, dst->sh_name);
- bfd_h_put_32 (abfd, src->sh_type, dst->sh_type);
- put_word (abfd, src->sh_flags, dst->sh_flags);
- put_word (abfd, src->sh_addr, dst->sh_addr);
- put_word (abfd, src->sh_offset, dst->sh_offset);
- put_word (abfd, src->sh_size, dst->sh_size);
- bfd_h_put_32 (abfd, src->sh_link, dst->sh_link);
- bfd_h_put_32 (abfd, src->sh_info, dst->sh_info);
- put_word (abfd, src->sh_addralign, dst->sh_addralign);
- put_word (abfd, src->sh_entsize, dst->sh_entsize);
+ H_PUT_32 (abfd, src->sh_name, dst->sh_name);
+ H_PUT_32 (abfd, src->sh_type, dst->sh_type);
+ H_PUT_WORD (abfd, src->sh_flags, dst->sh_flags);
+ H_PUT_WORD (abfd, src->sh_addr, dst->sh_addr);
+ H_PUT_WORD (abfd, src->sh_offset, dst->sh_offset);
+ H_PUT_WORD (abfd, src->sh_size, dst->sh_size);
+ H_PUT_32 (abfd, src->sh_link, dst->sh_link);
+ H_PUT_32 (abfd, src->sh_info, dst->sh_info);
+ H_PUT_WORD (abfd, src->sh_addralign, dst->sh_addralign);
+ H_PUT_WORD (abfd, src->sh_entsize, dst->sh_entsize);
}
/* Translate an ELF program header table entry in external format into an
@@ -357,22 +357,22 @@ elf_swap_phdr_in (abfd, src, dst)
{
int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
- dst->p_type = bfd_h_get_32 (abfd, (bfd_byte *) src->p_type);
- dst->p_flags = bfd_h_get_32 (abfd, (bfd_byte *) src->p_flags);
- dst->p_offset = get_word (abfd, (bfd_byte *) src->p_offset);
+ dst->p_type = H_GET_32 (abfd, src->p_type);
+ dst->p_flags = H_GET_32 (abfd, src->p_flags);
+ dst->p_offset = H_GET_WORD (abfd, src->p_offset);
if (signed_vma)
{
- dst->p_vaddr = get_signed_word (abfd, (bfd_byte *) src->p_vaddr);
- dst->p_paddr = get_signed_word (abfd, (bfd_byte *) src->p_paddr);
+ dst->p_vaddr = H_GET_SIGNED_WORD (abfd, src->p_vaddr);
+ dst->p_paddr = H_GET_SIGNED_WORD (abfd, src->p_paddr);
}
else
{
- dst->p_vaddr = get_word (abfd, (bfd_byte *) src->p_vaddr);
- dst->p_paddr = get_word (abfd, (bfd_byte *) src->p_paddr);
+ dst->p_vaddr = H_GET_WORD (abfd, src->p_vaddr);
+ dst->p_paddr = H_GET_WORD (abfd, src->p_paddr);
}
- dst->p_filesz = get_word (abfd, (bfd_byte *) src->p_filesz);
- dst->p_memsz = get_word (abfd, (bfd_byte *) src->p_memsz);
- dst->p_align = get_word (abfd, (bfd_byte *) src->p_align);
+ dst->p_filesz = H_GET_WORD (abfd, src->p_filesz);
+ dst->p_memsz = H_GET_WORD (abfd, src->p_memsz);
+ dst->p_align = H_GET_WORD (abfd, src->p_align);
}
void
@@ -382,14 +382,14 @@ elf_swap_phdr_out (abfd, src, dst)
Elf_External_Phdr *dst;
{
/* note that all elements of dst are *arrays of unsigned char* already... */
- bfd_h_put_32 (abfd, src->p_type, dst->p_type);
- put_word (abfd, src->p_offset, dst->p_offset);
- put_word (abfd, src->p_vaddr, dst->p_vaddr);
- put_word (abfd, src->p_paddr, dst->p_paddr);
- put_word (abfd, src->p_filesz, dst->p_filesz);
- put_word (abfd, src->p_memsz, dst->p_memsz);
- bfd_h_put_32 (abfd, src->p_flags, dst->p_flags);
- put_word (abfd, src->p_align, dst->p_align);
+ H_PUT_32 (abfd, src->p_type, dst->p_type);
+ H_PUT_WORD (abfd, src->p_offset, dst->p_offset);
+ H_PUT_WORD (abfd, src->p_vaddr, dst->p_vaddr);
+ H_PUT_WORD (abfd, src->p_paddr, dst->p_paddr);
+ H_PUT_WORD (abfd, src->p_filesz, dst->p_filesz);
+ H_PUT_WORD (abfd, src->p_memsz, dst->p_memsz);
+ H_PUT_32 (abfd, src->p_flags, dst->p_flags);
+ H_PUT_WORD (abfd, src->p_align, dst->p_align);
}
/* Translate an ELF reloc from external format to internal format. */
@@ -399,8 +399,8 @@ elf_swap_reloc_in (abfd, src, dst)
const Elf_External_Rel *src;
Elf_Internal_Rel *dst;
{
- dst->r_offset = get_word (abfd, (bfd_byte *) src->r_offset);
- dst->r_info = get_word (abfd, (bfd_byte *) src->r_info);
+ dst->r_offset = H_GET_WORD (abfd, src->r_offset);
+ dst->r_info = H_GET_WORD (abfd, src->r_info);
}
INLINE void
@@ -409,9 +409,9 @@ elf_swap_reloca_in (abfd, src, dst)
const Elf_External_Rela *src;
Elf_Internal_Rela *dst;
{
- dst->r_offset = get_word (abfd, (bfd_byte *) src->r_offset);
- dst->r_info = get_word (abfd, (bfd_byte *) src->r_info);
- dst->r_addend = get_signed_word (abfd, (bfd_byte *) src->r_addend);
+ dst->r_offset = H_GET_WORD (abfd, src->r_offset);
+ dst->r_info = H_GET_WORD (abfd, src->r_info);
+ dst->r_addend = H_GET_SIGNED_WORD (abfd, src->r_addend);
}
/* Translate an ELF reloc from internal format to external format. */
@@ -421,8 +421,8 @@ elf_swap_reloc_out (abfd, src, dst)
const Elf_Internal_Rel *src;
Elf_External_Rel *dst;
{
- put_word (abfd, src->r_offset, dst->r_offset);
- put_word (abfd, src->r_info, dst->r_info);
+ H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
+ H_PUT_WORD (abfd, src->r_info, dst->r_info);
}
INLINE void
@@ -431,9 +431,9 @@ elf_swap_reloca_out (abfd, src, dst)
const Elf_Internal_Rela *src;
Elf_External_Rela *dst;
{
- put_word (abfd, src->r_offset, dst->r_offset);
- put_word (abfd, src->r_info, dst->r_info);
- put_signed_word (abfd, src->r_addend, dst->r_addend);
+ H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
+ H_PUT_WORD (abfd, src->r_info, dst->r_info);
+ H_PUT_SIGNED_WORD (abfd, src->r_addend, dst->r_addend);
}
INLINE void
@@ -444,8 +444,8 @@ elf_swap_dyn_in (abfd, p, dst)
{
const Elf_External_Dyn *src = (const Elf_External_Dyn *) p;
- dst->d_tag = get_word (abfd, src->d_tag);
- dst->d_un.d_val = get_word (abfd, src->d_un.d_val);
+ dst->d_tag = H_GET_WORD (abfd, src->d_tag);
+ dst->d_un.d_val = H_GET_WORD (abfd, src->d_un.d_val);
}
INLINE void
@@ -456,8 +456,8 @@ elf_swap_dyn_out (abfd, src, p)
{
Elf_External_Dyn *dst = (Elf_External_Dyn *) p;
- put_word (abfd, src->d_tag, dst->d_tag);
- put_word (abfd, src->d_un.d_val, dst->d_un.d_val);
+ H_PUT_WORD (abfd, src->d_tag, dst->d_tag);
+ H_PUT_WORD (abfd, src->d_un.d_val, dst->d_un.d_val);
}
/* ELF .o/exec file reading */
@@ -503,6 +503,7 @@ elf_object_p (abfd)
unsigned long previous_mach = bfd_get_mach (abfd);
struct elf_obj_tdata *new_tdata = NULL;
asection *s;
+ bfd_size_type amt;
/* Clear section information, since there might be a recognized bfd that
we now check if we can replace, and we don't want to append to it. */
@@ -511,7 +512,8 @@ elf_object_p (abfd)
/* Read in the ELF header in external format. */
- if (bfd_read ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd) != sizeof (x_ehdr))
+ if (bfd_bread ((PTR) & x_ehdr, (bfd_size_type) sizeof (x_ehdr), abfd)
+ != sizeof (x_ehdr))
{
if (bfd_get_error () != bfd_error_system_call)
goto got_wrong_format_error;
@@ -549,8 +551,8 @@ elf_object_p (abfd)
/* Allocate an instance of the elf_obj_tdata structure and hook it up to
the tdata pointer in the bfd. */
- new_tdata = ((struct elf_obj_tdata *)
- bfd_zalloc (abfd, sizeof (struct elf_obj_tdata)));
+ amt = sizeof (struct elf_obj_tdata);
+ new_tdata = (struct elf_obj_tdata *) bfd_zalloc (abfd, amt);
if (new_tdata == NULL)
goto got_no_match;
elf_tdata (abfd) = new_tdata;
@@ -632,18 +634,18 @@ elf_object_p (abfd)
/* Allocate space for a copy of the section header table in
internal form, seek to the section header table in the file,
read it in, and convert it to internal form. */
- i_shdrp = ((Elf_Internal_Shdr *)
- bfd_alloc (abfd, sizeof (*i_shdrp) * i_ehdrp->e_shnum));
- elf_elfsections (abfd) = ((Elf_Internal_Shdr **)
- bfd_alloc (abfd,
- sizeof (i_shdrp) * i_ehdrp->e_shnum));
+ amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum;
+ i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
+ amt = sizeof (i_shdrp) * i_ehdrp->e_shnum;
+ elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt);
if (!i_shdrp || !elf_elfsections (abfd))
goto got_no_match;
- if (bfd_seek (abfd, i_ehdrp->e_shoff, SEEK_SET) != 0)
+ if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0)
goto got_no_match;
for (shindex = 0; shindex < i_ehdrp->e_shnum; shindex++)
{
- if (bfd_read ((PTR) & x_shdr, sizeof x_shdr, 1, abfd) != sizeof (x_shdr))
+ if (bfd_bread ((PTR) & x_shdr, (bfd_size_type) sizeof x_shdr, abfd)
+ != sizeof (x_shdr))
goto got_no_match;
elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex);
elf_elfsections (abfd)[shindex] = i_shdrp + shindex;
@@ -671,20 +673,18 @@ elf_object_p (abfd)
Elf_Internal_Phdr *i_phdr;
unsigned int i;
- elf_tdata (abfd)->phdr = ((Elf_Internal_Phdr *)
- bfd_alloc (abfd,
- (i_ehdrp->e_phnum
- * sizeof (Elf_Internal_Phdr))));
+ amt = i_ehdrp->e_phnum * sizeof (Elf_Internal_Phdr);
+ elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
if (elf_tdata (abfd)->phdr == NULL)
goto got_no_match;
- if (bfd_seek (abfd, i_ehdrp->e_phoff, SEEK_SET) != 0)
+ if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)
goto got_no_match;
i_phdr = elf_tdata (abfd)->phdr;
for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
{
Elf_External_Phdr x_phdr;
- if (bfd_read ((PTR) &x_phdr, sizeof x_phdr, 1, abfd)
+ if (bfd_bread ((PTR) &x_phdr, (bfd_size_type) sizeof x_phdr, abfd)
!= sizeof x_phdr)
goto got_no_match;
elf_swap_phdr_in (abfd, &x_phdr, i_phdr);
@@ -936,14 +936,14 @@ int
elf_write_out_phdrs (abfd, phdr, count)
bfd *abfd;
const Elf_Internal_Phdr *phdr;
- int count;
+ unsigned int count;
{
while (count--)
{
Elf_External_Phdr extphdr;
elf_swap_phdr_out (abfd, phdr, &extphdr);
- if (bfd_write (&extphdr, sizeof (Elf_External_Phdr), 1, abfd)
- != sizeof (Elf_External_Phdr))
+ if (bfd_bwrite (&extphdr, (bfd_size_type) sizeof (Elf_External_Phdr),
+ abfd) != sizeof (Elf_External_Phdr))
return -1;
phdr++;
}
@@ -961,6 +961,7 @@ elf_write_shdrs_and_ehdr (abfd)
Elf_External_Shdr *x_shdrp; /* Section header table, external form */
Elf_Internal_Shdr **i_shdrp; /* Section header table, internal form */
unsigned int count;
+ bfd_size_type amt;
i_ehdrp = elf_elfheader (abfd);
i_shdrp = elf_elfsections (abfd);
@@ -971,14 +972,14 @@ elf_write_shdrs_and_ehdr (abfd)
elf_debug_file (i_ehdrp);
#endif
elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr);
+ amt = sizeof (x_ehdr);
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
- || (bfd_write ((PTR) & x_ehdr, sizeof (x_ehdr), 1, abfd)
- != sizeof (x_ehdr)))
+ || bfd_bwrite ((PTR) & x_ehdr, amt, abfd) != amt)
return false;
/* at this point we've concocted all the ELF sections... */
- x_shdrp = (Elf_External_Shdr *)
- bfd_alloc (abfd, sizeof (*x_shdrp) * (i_ehdrp->e_shnum));
+ amt = sizeof (*x_shdrp) * i_ehdrp->e_shnum;
+ x_shdrp = (Elf_External_Shdr *) bfd_alloc (abfd, amt);
if (!x_shdrp)
return false;
@@ -989,9 +990,10 @@ elf_write_shdrs_and_ehdr (abfd)
#endif
elf_swap_shdr_out (abfd, i_shdrp[count], x_shdrp + count);
}
+ amt = i_ehdrp->e_shnum;
+ amt *= sizeof (*x_shdrp);
if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0
- || (bfd_write ((PTR) x_shdrp, sizeof (*x_shdrp), i_ehdrp->e_shnum, abfd)
- != sizeof (*x_shdrp) * i_ehdrp->e_shnum))
+ || bfd_bwrite ((PTR) x_shdrp, amt, abfd) != amt)
return false;
/* need to dump the string table too... */
@@ -1013,6 +1015,7 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
Elf_Internal_Sym i_sym;
Elf_External_Sym *x_symp = NULL;
Elf_External_Versym *x_versymp = NULL;
+ bfd_size_type amt;
/* Read each raw ELF symbol, converting from external ELF form to
internal ELF form, and then using the information to create a
@@ -1046,7 +1049,7 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
}
}
- if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
+ if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0)
return -1;
symcount = hdr->sh_size / sizeof (Elf_External_Sym);
@@ -1057,22 +1060,26 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
{
unsigned long i;
- if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) == -1)
+ if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0)
return -1;
- symbase = ((elf_symbol_type *)
- bfd_zalloc (abfd, symcount * sizeof (elf_symbol_type)));
+ amt = symcount;
+ amt *= sizeof (elf_symbol_type);
+ symbase = (elf_symbol_type *) bfd_zalloc (abfd, amt);
if (symbase == (elf_symbol_type *) NULL)
return -1;
sym = symbase;
/* Temporarily allocate room for the raw ELF symbols. */
- x_symp = ((Elf_External_Sym *)
- bfd_malloc (symcount * sizeof (Elf_External_Sym)));
+ amt = symcount;
+ amt *= sizeof (Elf_External_Sym);
+ x_symp = (Elf_External_Sym *) bfd_malloc (amt);
if (x_symp == NULL && symcount != 0)
goto error_return;
- if (bfd_read ((PTR) x_symp, sizeof (Elf_External_Sym), symcount, abfd)
+ if (bfd_bread ((PTR) x_symp,
+ (bfd_size_type) (symcount * sizeof (Elf_External_Sym)),
+ abfd)
!= symcount * sizeof (Elf_External_Sym))
goto error_return;
@@ -1101,7 +1108,7 @@ elf_slurp_symbol_table (abfd, symptrs, dynamic)
if (x_versymp == NULL && verhdr->sh_size != 0)
goto error_return;
- if (bfd_read ((PTR) x_versymp, 1, verhdr->sh_size, abfd)
+ if (bfd_bread ((PTR) x_versymp, (bfd_size_type) verhdr->sh_size, abfd)
!= verhdr->sh_size)
goto error_return;
}
@@ -1271,12 +1278,12 @@ elf_slurp_reloc_table_from_section (abfd, asect, rel_hdr, reloc_count,
unsigned int i;
int entsize;
- allocated = (PTR) bfd_malloc ((size_t) rel_hdr->sh_size);
+ allocated = (PTR) bfd_malloc (rel_hdr->sh_size);
if (allocated == NULL)
goto error_return;
if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
- || (bfd_read (allocated, 1, rel_hdr->sh_size, abfd)
+ || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
!= rel_hdr->sh_size))
goto error_return;
@@ -1362,6 +1369,7 @@ elf_slurp_reloc_table (abfd, asect, symbols, dynamic)
bfd_size_type reloc_count;
bfd_size_type reloc_count2;
arelent *relents;
+ bfd_size_type amt;
if (asect->relocation != NULL)
return true;
@@ -1397,9 +1405,8 @@ elf_slurp_reloc_table (abfd, asect, symbols, dynamic)
reloc_count2 = 0;
}
- relents = ((arelent *)
- bfd_alloc (abfd,
- (reloc_count + reloc_count2) * sizeof (arelent)));
+ amt = (reloc_count + reloc_count2) * sizeof (arelent);
+ relents = (arelent *) bfd_alloc (abfd, amt);
if (relents == NULL)
return false;