From 02fcd12620bbd5305137708afb2a26607fe48a2b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 Jan 1996 19:13:49 +0000 Subject: [PATCH] * elf.c (_bfd_elf_print_private_bfd_data): Dump contents of dynamic section, if there is one. * elf-bfd.h (struct elf_size_info): Add swap_dyn_in field. (bfd_elf32_swap_dyn_in): Change type of second parameter to PTR. (bfd_elf64_swap_dyn_in): Likewise. * elfcode.h (elf_swap_dyn_in): Change type of second parameter to PTR. (NAME(_bfd_elf,size_info)): Initialize swap_dyn_in field. --- bfd/ChangeLog | 9 ++++ bfd/elf-bfd.h | 5 +- bfd/elf.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++------------ bfd/elfcode.h | 11 ++-- 4 files changed, 155 insertions(+), 40 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 25b9559..2dfb670 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,14 @@ Fri Jan 12 13:59:16 1996 Ian Lance Taylor + * elf.c (_bfd_elf_print_private_bfd_data): Dump contents of + dynamic section, if there is one. + * elf-bfd.h (struct elf_size_info): Add swap_dyn_in field. + (bfd_elf32_swap_dyn_in): Change type of second parameter to PTR. + (bfd_elf64_swap_dyn_in): Likewise. + * elfcode.h (elf_swap_dyn_in): Change type of second parameter to + PTR. + (NAME(_bfd_elf,size_info)): Initialize swap_dyn_in field. + * elf32-i386.c (elf_i386_size_dynamic_sections): Don't create a DT_TEXTREL entry because of .rel.plt. From Martin Pirker . diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 88e7858..ee4d46c 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -182,6 +182,7 @@ struct elf_size_info { void (*swap_symbol_out) PARAMS ((bfd *, Elf_Internal_Sym *, PTR)); boolean (*slurp_reloc_table) PARAMS ((bfd *, asection *, asymbol **)); long (*slurp_symbol_table) PARAMS ((bfd *, asymbol **, boolean)); + void (*swap_dyn_in) PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); }; #define elf_symbol_from(ABFD,S) \ @@ -687,7 +688,7 @@ extern void bfd_elf32_swap_phdr_in extern void bfd_elf32_swap_phdr_out PARAMS ((bfd *, Elf_Internal_Phdr *, Elf32_External_Phdr *)); extern void bfd_elf32_swap_dyn_in - PARAMS ((bfd *, const Elf32_External_Dyn *, Elf_Internal_Dyn *)); + PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); extern void bfd_elf32_swap_dyn_out PARAMS ((bfd *, const Elf_Internal_Dyn *, Elf32_External_Dyn *)); extern boolean bfd_elf32_add_dynamic_entry @@ -723,7 +724,7 @@ extern void bfd_elf64_swap_phdr_in extern void bfd_elf64_swap_phdr_out PARAMS ((bfd *, Elf_Internal_Phdr *, Elf64_External_Phdr *)); extern void bfd_elf64_swap_dyn_in - PARAMS ((bfd *, const Elf64_External_Dyn *, Elf_Internal_Dyn *)); + PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); extern void bfd_elf64_swap_dyn_out PARAMS ((bfd *, const Elf_Internal_Dyn *, Elf64_External_Dyn *)); extern boolean bfd_elf64_add_dynamic_entry diff --git a/bfd/elf.c b/bfd/elf.c index 05254ff..55e4530 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -335,50 +335,152 @@ _bfd_elf_print_private_bfd_data (abfd, farg) { FILE *f = (FILE *) farg; Elf_Internal_Phdr *p; - unsigned int i, c; + asection *s; + bfd_byte *dynbuf = NULL; p = elf_tdata (abfd)->phdr; - if (p == NULL) - return true; + if (p != NULL) + { + unsigned int i, c; + + fprintf (f, "\nProgram Header:\n"); + c = elf_elfheader (abfd)->e_phnum; + for (i = 0; i < c; i++, p++) + { + const char *s; + char buf[20]; + + switch (p->p_type) + { + case PT_NULL: s = "NULL"; break; + case PT_LOAD: s = "LOAD"; break; + case PT_DYNAMIC: s = "DYNAMIC"; break; + case PT_INTERP: s = "INTERP"; break; + case PT_NOTE: s = "NOTE"; break; + case PT_SHLIB: s = "SHLIB"; break; + case PT_PHDR: s = "PHDR"; break; + default: sprintf (buf, "0x%lx", p->p_type); s = buf; break; + } + fprintf (f, "%8s off 0x", s); + fprintf_vma (f, p->p_offset); + fprintf (f, " vaddr 0x"); + fprintf_vma (f, p->p_vaddr); + fprintf (f, " paddr 0x"); + fprintf_vma (f, p->p_paddr); + fprintf (f, " align 2**%u\n", bfd_log2 (p->p_align)); + fprintf (f, " filesz 0x"); + fprintf_vma (f, p->p_filesz); + fprintf (f, " memsz 0x"); + fprintf_vma (f, p->p_memsz); + fprintf (f, " flags %c%c%c", + (p->p_flags & PF_R) != 0 ? 'r' : '-', + (p->p_flags & PF_W) != 0 ? 'w' : '-', + (p->p_flags & PF_X) != 0 ? 'x' : '-'); + if ((p->p_flags &~ (PF_R | PF_W | PF_X)) != 0) + fprintf (f, " %lx", p->p_flags &~ (PF_R | PF_W | PF_X)); + fprintf (f, "\n"); + } + } - c = elf_elfheader (abfd)->e_phnum; - for (i = 0; i < c; i++, p++) + s = bfd_get_section_by_name (abfd, ".dynamic"); + if (s != NULL) { - const char *s; - char buf[20]; + int elfsec; + unsigned long link; + bfd_byte *extdyn, *extdynend; + size_t extdynsize; + void (*swap_dyn_in) PARAMS ((bfd *, const PTR, Elf_Internal_Dyn *)); + + fprintf (f, "\nDynamic Section:\n"); + + dynbuf = (bfd_byte *) bfd_malloc (s->_raw_size); + if (dynbuf == NULL) + goto error_return; + if (! bfd_get_section_contents (abfd, s, (PTR) dynbuf, (file_ptr) 0, + s->_raw_size)) + goto error_return; + + elfsec = _bfd_elf_section_from_bfd_section (abfd, s); + if (elfsec == -1) + goto error_return; + link = elf_elfsections (abfd)[elfsec]->sh_link; - switch (p->p_type) + extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn; + swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in; + + extdyn = dynbuf; + extdynend = extdyn + s->_raw_size; + for (; extdyn < extdynend; extdyn += extdynsize) { - case PT_NULL: s = "NULL"; break; - case PT_LOAD: s = "LOAD"; break; - case PT_DYNAMIC: s = "DYNAMIC"; break; - case PT_INTERP: s = "INTERP"; break; - case PT_NOTE: s = "NOTE"; break; - case PT_SHLIB: s = "SHLIB"; break; - case PT_PHDR: s = "PHDR"; break; - default: sprintf (buf, "0x%lx", p->p_type); s = buf; break; + Elf_Internal_Dyn dyn; + const char *name; + char ab[20]; + boolean stringp; + + (*swap_dyn_in) (abfd, (PTR) extdyn, &dyn); + + if (dyn.d_tag == DT_NULL) + break; + + stringp = false; + switch (dyn.d_tag) + { + default: + sprintf (ab, "0x%x", dyn.d_tag); + name = ab; + break; + + case DT_NEEDED: name = "NEEDED"; stringp = true; break; + case DT_PLTRELSZ: name = "PLTRELSZ"; break; + case DT_PLTGOT: name = "PLTGOT"; break; + case DT_HASH: name = "HASH"; break; + case DT_STRTAB: name = "STRTAB"; break; + case DT_SYMTAB: name = "SYMTAB"; break; + case DT_RELA: name = "RELA"; break; + case DT_RELASZ: name = "RELASZ"; break; + case DT_RELAENT: name = "RELAENT"; break; + case DT_STRSZ: name = "STRSZ"; break; + case DT_SYMENT: name = "SYMENT"; break; + case DT_INIT: name = "INIT"; break; + case DT_FINI: name = "FINI"; break; + case DT_SONAME: name = "SONAME"; stringp = true; break; + case DT_RPATH: name = "RPATH"; stringp = true; break; + case DT_SYMBOLIC: name = "SYMBOLIC"; break; + case DT_REL: name = "REL"; break; + case DT_RELSZ: name = "RELSZ"; break; + case DT_RELENT: name = "RELENT"; break; + case DT_PLTREL: name = "PLTREL"; break; + case DT_DEBUG: name = "DEBUG"; break; + case DT_TEXTREL: name = "TEXTREL"; break; + case DT_JMPREL: name = "JMPREL"; break; + } + + fprintf (f, " %-11s ", name); + if (! stringp) + fprintf (f, "0x%x", dyn.d_un.d_val); + else + { + const char *string; + + string = bfd_elf_string_from_elf_section (abfd, link, + dyn.d_un.d_val); + if (string == NULL) + goto error_return; + fprintf (f, "%s", string); + } + fprintf (f, "\n"); } - fprintf (f, "%8s off 0x", s); - fprintf_vma (f, p->p_offset); - fprintf (f, " vaddr 0x"); - fprintf_vma (f, p->p_vaddr); - fprintf (f, " paddr 0x"); - fprintf_vma (f, p->p_paddr); - fprintf (f, " align 2**%u\n", bfd_log2 (p->p_align)); - fprintf (f, " filesz 0x"); - fprintf_vma (f, p->p_filesz); - fprintf (f, " memsz 0x"); - fprintf_vma (f, p->p_memsz); - fprintf (f, " flags %c%c%c", - (p->p_flags & PF_R) != 0 ? 'r' : '-', - (p->p_flags & PF_W) != 0 ? 'w' : '-', - (p->p_flags & PF_X) != 0 ? 'x' : '-'); - if ((p->p_flags &~ (PF_R | PF_W | PF_X)) != 0) - fprintf (f, " %lx", p->p_flags &~ (PF_R | PF_W | PF_X)); - fprintf (f, "\n"); + + free (dynbuf); + dynbuf = NULL; } return true; + + error_return: + if (dynbuf != NULL) + free (dynbuf); + return false; } /* Display ELF-specific fields of a symbol. */ diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 2e35f90..48e6d0b 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -393,11 +393,13 @@ elf_swap_reloca_out (abfd, src, dst) } INLINE void -elf_swap_dyn_in (abfd, src, dst) +elf_swap_dyn_in (abfd, p, dst) bfd *abfd; - const Elf_External_Dyn *src; + const PTR p; Elf_Internal_Dyn *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); } @@ -477,11 +479,11 @@ elf_object_p (abfd) switch (x_ehdr.e_ident[EI_DATA]) { case ELFDATA2MSB: /* Big-endian */ - if (!abfd->xvec->header_byteorder_big_p) + if (! bfd_header_big_endian (abfd)) goto got_wrong_format_error; break; case ELFDATA2LSB: /* Little-endian */ - if (abfd->xvec->header_byteorder_big_p) + if (! bfd_header_little_endian (abfd)) goto got_wrong_format_error; break; case ELFDATANONE: /* No data encoding specified */ @@ -1269,4 +1271,5 @@ const struct elf_size_info NAME(_bfd_elf,size_info) = { elf_swap_symbol_out, elf_slurp_reloc_table, elf_slurp_symbol_table, + elf_swap_dyn_in }; -- 2.7.4