X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felfcode.h;h=e1f58016740e21ce5b450b253357ba19af0476f3;hb=377caf49a5881bb23084de3e9bcaa1812327119f;hp=189807c00a9bcb5f150414c2da5bb369b19b923f;hpb=cd123cb70c845b890eed231a84e6e84c92c2ef92;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 189807c00a..e1f5801674 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -122,6 +122,7 @@ #define elf_find_section NAME(bfd_elf,find_section) #define elf_write_shdrs_and_ehdr NAME(bfd_elf,write_shdrs_and_ehdr) #define elf_write_out_phdrs NAME(bfd_elf,write_out_phdrs) +#define elf_checksum_contents NAME(bfd_elf,checksum_contents) #define elf_write_relocs NAME(bfd_elf,write_relocs) #define elf_slurp_reloc_table NAME(bfd_elf,slurp_reloc_table) @@ -471,7 +472,7 @@ valid_section_index_p (unsigned index, unsigned num_sections) /* Note: We allow SHN_UNDEF as a valid section index. */ if (index < SHN_LORESERVE || index > SHN_HIRESERVE) return index < num_sections; - + /* We disallow the use of reserved indcies, except for those with OS or Application specific meaning. The test make use of the knowledge that: @@ -604,7 +605,7 @@ elf_object_p (bfd *abfd) if ((*target_ptr)->flavour != bfd_target_elf_flavour) continue; - back = (const struct elf_backend_data *) (*target_ptr)->backend_data; + back = xvec_get_elf_backend_data (*target_ptr); if (back->elf_machine_code == i_ehdrp->e_machine || (back->elf_machine_alt1 != 0 && back->elf_machine_alt1 == i_ehdrp->e_machine) @@ -657,7 +658,7 @@ elf_object_p (bfd *abfd) != target->header_byteorder)) continue; - back = (const struct elf_backend_data *) (*target_ptr)->backend_data; + back = xvec_get_elf_backend_data (*target_ptr); if (back->elf_osabi == i_ehdrp->e_ident[EI_OSABI] && (back->elf_machine_code == i_ehdrp->e_machine || (back->elf_machine_alt1 != 0 @@ -1105,6 +1106,53 @@ elf_write_shdrs_and_ehdr (bfd *abfd) return TRUE; } +bfd_boolean +elf_checksum_contents (bfd *abfd, + void (*process) (const void *, size_t, void *), + void *arg) +{ + Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); + Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd); + Elf_Internal_Phdr *i_phdrp = elf_tdata (abfd)->phdr; + unsigned int count, num; + + { + Elf_External_Ehdr x_ehdr; + Elf_Internal_Ehdr i_ehdr; + + i_ehdr = *i_ehdrp; + i_ehdr.e_phoff = i_ehdr.e_shoff = 0; + elf_swap_ehdr_out (abfd, &i_ehdr, &x_ehdr); + (*process) (&x_ehdr, sizeof x_ehdr, arg); + } + + num = i_ehdrp->e_phnum; + for (count = 0; count < num; count++) + { + Elf_External_Phdr x_phdr; + elf_swap_phdr_out (abfd, &i_phdrp[count], &x_phdr); + (*process) (&x_phdr, sizeof x_phdr, arg); + } + + num = elf_numsections (abfd); + for (count = 0; count < num; count++) + { + Elf_Internal_Shdr i_shdr; + Elf_External_Shdr x_shdr; + + i_shdr = *i_shdrp[count]; + i_shdr.sh_offset = 0; + + elf_swap_shdr_out (abfd, &i_shdr, &x_shdr); + (*process) (&x_shdr, sizeof x_shdr, arg); + + if (i_shdr.contents) + (*process) (i_shdr.contents, i_shdr.sh_size, arg); + } + + return TRUE; +} + long elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic) { @@ -1587,6 +1635,7 @@ NAME(_bfd_elf,bfd_from_remote_memory) int err; unsigned int i; bfd_vma loadbase; + bfd_boolean loadbase_set; /* Read in the ELF header in external format. */ err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr, sizeof x_ehdr); @@ -1663,13 +1712,11 @@ NAME(_bfd_elf,bfd_from_remote_memory) contents_size = 0; last_phdr = NULL; loadbase = ehdr_vma; + loadbase_set = FALSE; for (i = 0; i < i_ehdr.e_phnum; ++i) { elf_swap_phdr_in (templ, &x_phdrs[i], &i_phdrs[i]); - /* IA-64 vDSO may have two mappings for one segment, where one mapping - is executable only, and one is read only. We must not use the - executable one. */ - if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R)) + if (i_phdrs[i].p_type == PT_LOAD) { bfd_vma segment_end; segment_end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz @@ -1677,8 +1724,14 @@ NAME(_bfd_elf,bfd_from_remote_memory) if (segment_end > (bfd_vma) contents_size) contents_size = segment_end; - if ((i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0) - loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align); + /* LOADADDR is the `Base address' from the gELF specification: + `lowest p_vaddr value for a PT_LOAD segment' is P_VADDR from the + first PT_LOAD as PT_LOADs are ordered by P_VADDR. */ + if (!loadbase_set && (i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0) + { + loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align); + loadbase_set = TRUE; + } last_phdr = &i_phdrs[i]; } @@ -1716,10 +1769,7 @@ NAME(_bfd_elf,bfd_from_remote_memory) } for (i = 0; i < i_ehdr.e_phnum; ++i) - /* IA-64 vDSO may have two mappings for one segment, where one mapping - is executable only, and one is read only. We must not use the - executable one. */ - if (i_phdrs[i].p_type == PT_LOAD && (i_phdrs[i].p_flags & PF_R)) + if (i_phdrs[i].p_type == PT_LOAD) { bfd_vma start = i_phdrs[i].p_offset & -i_phdrs[i].p_align; bfd_vma end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz @@ -1803,6 +1853,7 @@ const struct elf_size_info NAME(_bfd_elf,size_info) = { ELFCLASS, EV_CURRENT, elf_write_out_phdrs, elf_write_shdrs_and_ehdr, + elf_checksum_contents, elf_write_relocs, elf_swap_symbol_in, elf_swap_symbol_out,