From 4c45e5c9ceb986f7d84ad09586d3bdf521140083 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 22 Apr 2004 14:45:32 +0000 Subject: [PATCH] bfd/ * bfd.c (bfd_get_synthetic_symtab): Define. * targets.c (BFD_JUMP_TABLE_DYNAMIC): Add NAME##_get_synthetic_symtab. (struct bfd_target): Add _bfd_get_synthetic_symtab. * libbfd-in.h (_bfd_nodynamic_get_synthetic_symtab): Define. * elf-bfd.h (struct elf_backend_data): Add plt_sym_val and relplt_name fields. (_bfd_elf_get_synthetic_symtab): New prototype. * elfcode.h (elf_get_synthetic_symtab): Define. * elf.c (_bfd_elf_get_synthetic_symtab): New function. * elfxx-target.h (bfd_elfNN_get_synthetic_symtab): Define. (elf_backend_plt_sym_val, elf_backend_relplt_name): Define. (elfNN_bed): Add elf_backend_plt_sym_val and elf_backend_relplt_name. * bfd-in2.h: Rebuilt. * libbfd.h: Rebuilt. * elf32-i386.c (elf_i386_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf64-x86-64.c (elf64_x86_64_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf32-s390.c (elf_s390_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf64-s390.c (elf_s390_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf32-sparc (elf32_sparc_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf64-sparc.c (sparc64_elf_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * elf32-ppc.c (ppc_elf_plt_sym_val): New function. (elf_backend_plt_sym_val): Define. * aout-target.h (MY_get_synthetic_symtab): Define. * aout-tic30.c (MY_get_synthetic_symtab): Define. * coff-rs6000.c (rs6000coff_vec): Add _bfd_nodynamic_get_synthetic_symtab. (pmac_xcoff_vec): Likewise. * coff64-rs6000.c (rs6000coff64_vec): Add _bfd_nodynamic_get_synthetic_symtab. (aix5coff64_vec): Likewise. * sunos.c (MY_get_synthetic_symtab): Define. * vms.c (vms_get_synthetic_symtab): Define. binutils/ * objdump.c (synthsyms, synthcount): New variables. (disassemble_data): Use dynsyms for stripped binaries or libraries. Add synthetized symbols. (dump_bfd): For disassemble, initialize dynsyms always and also synthsyms. Free synthsyms and clear {sym,dynsym,synth}count before returning. --- bfd/ChangeLog | 42 +++++++++++++++++++++++++ bfd/aout-target.h | 4 +++ bfd/aout-tic30.c | 4 +++ bfd/bfd-in2.h | 7 +++++ bfd/bfd.c | 3 ++ bfd/coff-rs6000.c | 2 ++ bfd/coff64-rs6000.c | 2 ++ bfd/elf-bfd.h | 9 ++++++ bfd/elf.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ bfd/elf32-i386.c | 12 +++++++ bfd/elf32-ppc.c | 12 +++++++ bfd/elf32-s390.c | 12 +++++++ bfd/elf32-sparc.c | 12 +++++++ bfd/elf64-s390.c | 12 +++++++ bfd/elf64-sparc.c | 20 ++++++++++++ bfd/elf64-x86-64.c | 10 ++++++ bfd/elfcode.h | 2 ++ bfd/elfxx-target.h | 11 +++++++ bfd/libbfd-in.h | 2 ++ bfd/libbfd.h | 2 ++ bfd/sunos.c | 1 + bfd/targets.c | 4 +++ bfd/vms.c | 1 + binutils/ChangeLog | 9 ++++++ binutils/objdump.c | 39 ++++++++++++++++++++--- 25 files changed, 305 insertions(+), 5 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 00cc69237c3..8ab0844e40c 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,45 @@ +2004-04-22 Jakub Jelinek + + * bfd.c (bfd_get_synthetic_symtab): Define. + * targets.c (BFD_JUMP_TABLE_DYNAMIC): Add + NAME##_get_synthetic_symtab. + (struct bfd_target): Add _bfd_get_synthetic_symtab. + * libbfd-in.h (_bfd_nodynamic_get_synthetic_symtab): Define. + * elf-bfd.h (struct elf_backend_data): Add plt_sym_val and + relplt_name fields. + (_bfd_elf_get_synthetic_symtab): New prototype. + * elfcode.h (elf_get_synthetic_symtab): Define. + * elf.c (_bfd_elf_get_synthetic_symtab): New function. + * elfxx-target.h (bfd_elfNN_get_synthetic_symtab): Define. + (elf_backend_plt_sym_val, elf_backend_relplt_name): Define. + (elfNN_bed): Add elf_backend_plt_sym_val and elf_backend_relplt_name. + * bfd-in2.h: Rebuilt. + * libbfd.h: Rebuilt. + * elf32-i386.c (elf_i386_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf64-x86-64.c (elf64_x86_64_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf32-s390.c (elf_s390_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf64-s390.c (elf_s390_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf32-sparc (elf32_sparc_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf64-sparc.c (sparc64_elf_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * elf32-ppc.c (ppc_elf_plt_sym_val): New function. + (elf_backend_plt_sym_val): Define. + * aout-target.h (MY_get_synthetic_symtab): Define. + * aout-tic30.c (MY_get_synthetic_symtab): Define. + * coff-rs6000.c (rs6000coff_vec): Add + _bfd_nodynamic_get_synthetic_symtab. + (pmac_xcoff_vec): Likewise. + * coff64-rs6000.c (rs6000coff64_vec): Add + _bfd_nodynamic_get_synthetic_symtab. + (aix5coff64_vec): Likewise. + * sunos.c (MY_get_synthetic_symtab): Define. + * vms.c (vms_get_synthetic_symtab): Define. + 2004-04-22 Nick Clifton * bfd.c (bfd_archive_filename): Return NULL on NULL input. diff --git a/bfd/aout-target.h b/bfd/aout-target.h index d8cad54708d..dece83cf263 100644 --- a/bfd/aout-target.h +++ b/bfd/aout-target.h @@ -584,6 +584,10 @@ MY_bfd_final_link (abfd, info) #define MY_canonicalize_dynamic_symtab \ _bfd_nodynamic_canonicalize_dynamic_symtab #endif +#ifndef MY_get_synthetic_symtab +#define MY_get_synthetic_symtab \ + _bfd_nodynamic_get_synthetic_symtab +#endif #ifndef MY_get_dynamic_reloc_upper_bound #define MY_get_dynamic_reloc_upper_bound \ _bfd_nodynamic_get_dynamic_reloc_upper_bound diff --git a/bfd/aout-tic30.c b/bfd/aout-tic30.c index 1f37b995d7b..96f35dce9e4 100644 --- a/bfd/aout-tic30.c +++ b/bfd/aout-tic30.c @@ -1040,6 +1040,10 @@ tic30_aout_set_arch_mach (abfd, arch, machine) #define MY_canonicalize_dynamic_symtab \ _bfd_nodynamic_canonicalize_dynamic_symtab #endif +#ifndef MY_get_synthetic_symtab +#define MY_get_synthetic_symtab \ + _bfd_nodynamic_get_synthetic_symtab +#endif #ifndef MY_get_dynamic_reloc_upper_bound #define MY_get_dynamic_reloc_upper_bound \ _bfd_nodynamic_get_dynamic_reloc_upper_bound diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 4907f11ccaa..4f4c6704f64 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -4012,6 +4012,9 @@ bfd_boolean bfd_set_private_flags (bfd *abfd, flagword flags); #define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \ BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols)) +#define bfd_get_synthetic_symtab(abfd, dynsyms, ret) \ + BFD_SEND (abfd, _bfd_get_synthetic_symtab, (abfd, dynsyms, ret)) + #define bfd_get_dynamic_reloc_upper_bound(abfd) \ BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd)) @@ -4393,6 +4396,7 @@ typedef struct bfd_target #define BFD_JUMP_TABLE_DYNAMIC(NAME) \ NAME##_get_dynamic_symtab_upper_bound, \ NAME##_canonicalize_dynamic_symtab, \ + NAME##_get_synthetic_symtab, \ NAME##_get_dynamic_reloc_upper_bound, \ NAME##_canonicalize_dynamic_reloc @@ -4401,6 +4405,9 @@ typedef struct bfd_target /* Read in the dynamic symbols. */ long (*_bfd_canonicalize_dynamic_symtab) (bfd *, struct bfd_symbol **); + /* Create synthetized symbols. */ + long (*_bfd_get_synthetic_symtab) + (bfd *, struct bfd_symbol **, struct bfd_symbol **); /* Get the amount of memory required to hold the dynamic relocs. */ long (*_bfd_get_dynamic_reloc_upper_bound) (bfd *); /* Read in the dynamic relocs. */ diff --git a/bfd/bfd.c b/bfd/bfd.c index f8ed3407637..c8a60f20d01 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -1111,6 +1111,9 @@ DESCRIPTION .#define bfd_canonicalize_dynamic_symtab(abfd, asymbols) \ . BFD_SEND (abfd, _bfd_canonicalize_dynamic_symtab, (abfd, asymbols)) . +.#define bfd_get_synthetic_symtab(abfd, dynsyms, ret) \ +. BFD_SEND (abfd, _bfd_get_synthetic_symtab, (abfd, dynsyms, ret)) +. .#define bfd_get_dynamic_reloc_upper_bound(abfd) \ . BFD_SEND (abfd, _bfd_get_dynamic_reloc_upper_bound, (abfd)) . diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 56e34e2d720..bcd89dd2f03 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -4201,6 +4201,7 @@ const bfd_target rs6000coff_vec = /* Dynamic */ _bfd_xcoff_get_dynamic_symtab_upper_bound, _bfd_xcoff_canonicalize_dynamic_symtab, + _bfd_nodynamic_get_synthetic_symtab, _bfd_xcoff_get_dynamic_reloc_upper_bound, _bfd_xcoff_canonicalize_dynamic_reloc, @@ -4443,6 +4444,7 @@ const bfd_target pmac_xcoff_vec = /* Dynamic */ _bfd_xcoff_get_dynamic_symtab_upper_bound, _bfd_xcoff_canonicalize_dynamic_symtab, + _bfd_nodynamic_get_synthetic_symtab, _bfd_xcoff_get_dynamic_reloc_upper_bound, _bfd_xcoff_canonicalize_dynamic_reloc, diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c index ec9c6953478..14e4c2782bc 100644 --- a/bfd/coff64-rs6000.c +++ b/bfd/coff64-rs6000.c @@ -2742,6 +2742,7 @@ const bfd_target rs6000coff64_vec = /* Dynamic */ _bfd_xcoff_get_dynamic_symtab_upper_bound, _bfd_xcoff_canonicalize_dynamic_symtab, + _bfd_nodynamic_get_synthetic_symtab, _bfd_xcoff_get_dynamic_reloc_upper_bound, _bfd_xcoff_canonicalize_dynamic_reloc, @@ -2985,6 +2986,7 @@ const bfd_target aix5coff64_vec = /* Dynamic */ _bfd_xcoff_get_dynamic_symtab_upper_bound, _bfd_xcoff_canonicalize_dynamic_symtab, + _bfd_nodynamic_get_synthetic_symtab, _bfd_xcoff_get_dynamic_reloc_upper_bound, _bfd_xcoff_canonicalize_dynamic_reloc, diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 110dd696c54..cfc42ac9a6b 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -902,6 +902,13 @@ struct elf_backend_data (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, int (*target_read_memory) (bfd_vma vma, char *myaddr, int len)); + /* This function is used by `_bfd_elf_get_synthetic_symtab'; + see elf.c. */ + bfd_vma (*plt_sym_val) (bfd_vma, const asection *, const arelent *); + + /* Name of the PLT relocation section. */ + const char *relplt_name; + /* Alternate EM_xxxx machine codes for this backend. */ int elf_machine_alt1; int elf_machine_alt2; @@ -1385,6 +1392,8 @@ extern long _bfd_elf_get_dynamic_symtab_upper_bound (bfd *); extern long _bfd_elf_canonicalize_dynamic_symtab (bfd *, asymbol **); +extern long _bfd_elf_get_synthetic_symtab + (bfd *, asymbol **, asymbol **); extern long _bfd_elf_get_reloc_upper_bound (bfd *, sec_ptr); extern long _bfd_elf_canonicalize_reloc diff --git a/bfd/elf.c b/bfd/elf.c index 2fcfa980ed0..d05a3df50c2 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -7513,3 +7513,79 @@ bfd_elf_bfd_from_remote_memory return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory) (templ, ehdr_vma, loadbasep, target_read_memory); } + +long +_bfd_elf_get_synthetic_symtab (bfd *abfd, asymbol **dynsyms, asymbol **ret) +{ + const struct elf_backend_data *bed = get_elf_backend_data (abfd); + asection *relplt; + asymbol *s; + const char *relplt_name; + bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean); + arelent *p; + long count, i, n; + size_t size; + Elf_Internal_Shdr *hdr; + char *names; + asection *plt; + + *ret = NULL; + if (!bed->plt_sym_val) + return 0; + + relplt_name = bed->relplt_name; + if (relplt_name == NULL) + relplt_name = bed->default_use_rela_p ? ".rela.plt" : ".rel.plt"; + relplt = bfd_get_section_by_name (abfd, relplt_name); + if (relplt == NULL) + return 0; + + hdr = &elf_section_data (relplt)->this_hdr; + if (hdr->sh_link != elf_dynsymtab (abfd) + || (hdr->sh_type != SHT_REL && hdr->sh_type != SHT_RELA)) + return 0; + + plt = bfd_get_section_by_name (abfd, ".plt"); + if (plt == NULL) + return 0; + + slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table; + if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE)) + return -1; + + count = relplt->_raw_size / hdr->sh_entsize; + size = count * sizeof (asymbol); + p = relplt->relocation; + for (i = 0; i < count; i++, s++, p++) + size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt"); + + s = *ret = bfd_malloc (size); + if (s == NULL) + return -1; + + names = (char *) (s + count); + p = relplt->relocation; + n = 0; + for (i = 0; i < count; i++, s++, p++) + { + size_t len; + bfd_vma addr; + + addr = bed->plt_sym_val (i, plt, p); + if (addr == (bfd_vma) -1) + continue; + + *s = **p->sym_ptr_ptr; + s->section = plt; + s->value = addr - plt->vma; + s->name = names; + len = strlen ((*p->sym_ptr_ptr)->name); + memcpy (names, (*p->sym_ptr_ptr)->name, len); + names += len; + memcpy (names, "@plt", sizeof ("@plt")); + names += sizeof ("@plt"); + ++n; + } + + return n; +} diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 7b173e4485c..a53d93ecc1d 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3248,6 +3248,17 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, return TRUE; } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +elf_i386_plt_sym_val (bfd_vma i, const asection *plt, + const arelent *rel ATTRIBUTE_UNUSED) +{ + return plt->vma + (i + 1) * PLT_ENTRY_SIZE; +} + + #define TARGET_LITTLE_SYM bfd_elf32_i386_vec #define TARGET_LITTLE_NAME "elf32-i386" #define ELF_ARCH bfd_arch_i386 @@ -3285,6 +3296,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, #define elf_backend_reloc_type_class elf_i386_reloc_type_class #define elf_backend_relocate_section elf_i386_relocate_section #define elf_backend_size_dynamic_sections elf_i386_size_dynamic_sections +#define elf_backend_plt_sym_val elf_i386_plt_sym_val #include "elf32-target.h" diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index 4eb08ad3e67..bdd3450f4ab 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -6128,6 +6128,17 @@ ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) apuinfo_list_finish (); } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, + const asection *plt ATTRIBUTE_UNUSED, + const arelent *rel) +{ + return rel->address; +} + /* Add extra PPC sections -- Note, for now, make .sbss2 and .PPC.EMB.sbss0 a normal section, and not a bss section so that the linker doesn't crater when trying to make more than @@ -6205,5 +6216,6 @@ static struct bfd_elf_special_section const ppc_elf_special_sections[]= #define elf_backend_final_write_processing ppc_elf_final_write_processing #define elf_backend_write_section ppc_elf_write_section #define elf_backend_special_sections ppc_elf_special_sections +#define elf_backend_plt_sym_val ppc_elf_plt_sym_val #include "elf32-target.h" diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index 074c1089342..fb8758b37cc 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -3457,6 +3457,17 @@ elf_s390_grok_prstatus (abfd, note) raw_size, note->descpos + offset); } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +elf_s390_plt_sym_val (bfd_vma i, const asection *plt, + const arelent *rel ATTRIBUTE_UNUSED) +{ + return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE; +} + + #define TARGET_BIG_SYM bfd_elf32_s390_vec #define TARGET_BIG_NAME "elf32-s390" #define ELF_ARCH bfd_arch_s390 @@ -3491,6 +3502,7 @@ elf_s390_grok_prstatus (abfd, note) #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections #define elf_backend_reloc_type_class elf_s390_reloc_type_class #define elf_backend_grok_prstatus elf_s390_grok_prstatus +#define elf_backend_plt_sym_val elf_s390_plt_sym_val #define bfd_elf32_mkobject elf_s390_mkobject #define elf_backend_object_p elf_s390_object_p diff --git a/bfd/elf32-sparc.c b/bfd/elf32-sparc.c index 6e1c40b98c1..3809567627a 100644 --- a/bfd/elf32-sparc.c +++ b/bfd/elf32-sparc.c @@ -3432,6 +3432,17 @@ elf32_sparc_reloc_type_class (rela) return reloc_class_normal; } } + +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +elf32_sparc_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED, + const asection *plt ATTRIBUTE_UNUSED, + const arelent *rel) +{ + return rel->address; +} #define TARGET_BIG_SYM bfd_elf32_sparc_vec #define TARGET_BIG_NAME "elf32-sparc" @@ -3470,6 +3481,7 @@ elf32_sparc_reloc_type_class (rela) #define elf_backend_gc_sweep_hook elf32_sparc_gc_sweep_hook #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class +#define elf_backend_plt_sym_val elf32_sparc_plt_sym_val #define elf_backend_can_gc_sections 1 #define elf_backend_can_refcount 1 diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index 63a261a8e88..63e995070a9 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -3369,6 +3369,17 @@ elf_s390_finish_dynamic_sections (output_bfd, info) return TRUE; } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +elf_s390_plt_sym_val (bfd_vma i, const asection *plt, + const arelent *rel ATTRIBUTE_UNUSED) +{ + return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE; +} + + /* Why was the hash table entry size definition changed from ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and this is the only reason for the s390_elf64_size_info structure. */ @@ -3438,6 +3449,7 @@ const struct elf_size_info s390_elf64_size_info = #define elf_backend_relocate_section elf_s390_relocate_section #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections #define elf_backend_reloc_type_class elf_s390_reloc_type_class +#define elf_backend_plt_sym_val elf_s390_plt_sym_val #define bfd_elf64_mkobject elf_s390_mkobject #define elf_backend_object_p elf_s390_object_p diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c index 4f2832512a1..886cb4d7ae0 100644 --- a/bfd/elf64-sparc.c +++ b/bfd/elf64-sparc.c @@ -3107,6 +3107,24 @@ sparc64_elf_object_p (abfd) return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach); } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +sparc64_elf_plt_sym_val (bfd_vma i, const asection *plt, + const arelent *rel) +{ + bfd_vma j; + + i += PLT_HEADER_SIZE / PLT_ENTRY_SIZE; + if (i < LARGE_PLT_THRESHOLD) + return plt->vma + i * PLT_ENTRY_SIZE; + + j = (i - LARGE_PLT_THRESHOLD) % 160; + i -= j; + return plt->vma + i * PLT_ENTRY_SIZE + j * 4 * 6; +} + /* Relocations in the 64 bit SPARC ELF ABI are more complex than in standard ELF, because R_SPARC_OLO10 has secondary addend in ELF64_R_TYPE_DATA field. This structure is used to redirect the @@ -3206,6 +3224,8 @@ const struct elf_size_info sparc64_elf_size_info = sparc64_elf_merge_private_bfd_data #define elf_backend_fake_sections \ sparc64_elf_fake_sections +#define elf_backend_plt_sym_val \ + sparc64_elf_plt_sym_val #define elf_backend_size_info \ sparc64_elf_size_info diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index a1d62501f96..360d8590d01 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2750,6 +2750,15 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf return TRUE; } +/* Return address for Ith PLT stub in section PLT, for relocation REL + or (bfd_vma) -1 if it should not be included. */ + +static bfd_vma +elf64_x86_64_plt_sym_val (bfd_vma i, const asection *plt, + const arelent *rel ATTRIBUTE_UNUSED) +{ + return plt->vma + (i + 1) * PLT_ENTRY_SIZE; +} #define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec #define TARGET_LITTLE_NAME "elf64-x86-64" @@ -2784,6 +2793,7 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class #define elf_backend_relocate_section elf64_x86_64_relocate_section #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections +#define elf_backend_plt_sym_val elf64_x86_64_plt_sym_val #define elf_backend_object_p elf64_x86_64_elf_object_p #define bfd_elf64_mkobject elf64_x86_64_mkobject diff --git a/bfd/elfcode.h b/bfd/elfcode.h index bc69d48db4d..0c7be886d32 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -105,6 +105,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define elf_canonicalize_symtab NAME(bfd_elf,canonicalize_symtab) #define elf_canonicalize_dynamic_symtab \ NAME(bfd_elf,canonicalize_dynamic_symtab) +#define elf_get_synthetic_symtab \ + NAME(bfd_elf,get_synthetic_symtab) #define elf_make_empty_symbol NAME(bfd_elf,make_empty_symbol) #define elf_get_symbol_info NAME(bfd_elf,get_symbol_info) #define elf_get_lineno NAME(bfd_elf,get_lineno) diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index e250a97da7a..5d8af449f07 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -34,6 +34,8 @@ #define bfd_elfNN_canonicalize_dynamic_symtab \ _bfd_elf_canonicalize_dynamic_symtab +#define bfd_elfNN_get_synthetic_symtab \ + _bfd_elf_get_synthetic_symtab #ifndef bfd_elfNN_canonicalize_reloc #define bfd_elfNN_canonicalize_reloc _bfd_elf_canonicalize_reloc #endif @@ -443,6 +445,13 @@ #define elf_backend_rela_normal 0 #endif +#ifndef elf_backend_plt_sym_val +#define elf_backend_plt_sym_val NULL +#endif +#ifndef elf_backend_relplt_name +#define elf_backend_relplt_name NULL +#endif + #ifndef ELF_MACHINE_ALT1 #define ELF_MACHINE_ALT1 0 #endif @@ -524,6 +533,8 @@ static const struct elf_backend_data elfNN_bed = elf_backend_mips_rtype_to_howto, elf_backend_ecoff_debug_swap, elf_backend_bfd_from_remote_memory, + elf_backend_plt_sym_val, + elf_backend_relplt_name, ELF_MACHINE_ALT1, ELF_MACHINE_ALT2, &elf_backend_size_info, diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h index 10cafefd6ed..5dd9a717626 100644 --- a/bfd/libbfd-in.h +++ b/bfd/libbfd-in.h @@ -378,6 +378,8 @@ extern bfd_boolean _bfd_generic_set_section_contents #define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_n1 #define _bfd_nodynamic_canonicalize_dynamic_symtab \ ((long (*) (bfd *, asymbol **)) _bfd_n1) +#define _bfd_nodynamic_get_synthetic_symtab \ + ((long (*) (bfd *, asymbol **, asymbol **)) _bfd_n1) #define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_n1 #define _bfd_nodynamic_canonicalize_dynamic_reloc \ ((long (*) (bfd *, arelent **, asymbol **)) _bfd_n1) diff --git a/bfd/libbfd.h b/bfd/libbfd.h index b4bc9f88f6b..448b8b25ea6 100644 --- a/bfd/libbfd.h +++ b/bfd/libbfd.h @@ -383,6 +383,8 @@ extern bfd_boolean _bfd_generic_set_section_contents #define _bfd_nodynamic_get_dynamic_symtab_upper_bound _bfd_n1 #define _bfd_nodynamic_canonicalize_dynamic_symtab \ ((long (*) (bfd *, asymbol **)) _bfd_n1) +#define _bfd_nodynamic_get_synthetic_symtab \ + ((long (*) (bfd *, asymbol **, asymbol **)) _bfd_n1) #define _bfd_nodynamic_get_dynamic_reloc_upper_bound _bfd_n1 #define _bfd_nodynamic_canonicalize_dynamic_reloc \ ((long (*) (bfd *, arelent **, asymbol **)) _bfd_n1) diff --git a/bfd/sunos.c b/bfd/sunos.c index 5b1b18b9d76..4d5099a40ad 100644 --- a/bfd/sunos.c +++ b/bfd/sunos.c @@ -73,6 +73,7 @@ static bfd_boolean sunos_finish_dynamic_link #define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound #define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab +#define MY_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab #define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound #define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc #define MY_bfd_link_hash_table_create sunos_link_hash_table_create diff --git a/bfd/targets.c b/bfd/targets.c index 256a2af642a..353e8c2214d 100644 --- a/bfd/targets.c +++ b/bfd/targets.c @@ -450,6 +450,7 @@ BFD_JUMP_TABLE macros. .#define BFD_JUMP_TABLE_DYNAMIC(NAME) \ . NAME##_get_dynamic_symtab_upper_bound, \ . NAME##_canonicalize_dynamic_symtab, \ +. NAME##_get_synthetic_symtab, \ . NAME##_get_dynamic_reloc_upper_bound, \ . NAME##_canonicalize_dynamic_reloc . @@ -458,6 +459,9 @@ BFD_JUMP_TABLE macros. . {* Read in the dynamic symbols. *} . long (*_bfd_canonicalize_dynamic_symtab) . (bfd *, struct bfd_symbol **); +. {* Create synthetized symbols. *} +. long (*_bfd_get_synthetic_symtab) +. (bfd *, struct bfd_symbol **, struct bfd_symbol **); . {* Get the amount of memory required to hold the dynamic relocs. *} . long (*_bfd_get_dynamic_reloc_upper_bound) (bfd *); . {* Read in the dynamic relocs. *} diff --git a/bfd/vms.c b/bfd/vms.c index a55b94b0989..62972b680fe 100644 --- a/bfd/vms.c +++ b/bfd/vms.c @@ -154,6 +154,7 @@ static long vms_get_dynamic_symtab_upper_bound PARAMS ((bfd *abfd)); static long vms_canonicalize_dynamic_symtab PARAMS ((bfd *abfd, asymbol **symbols)); +#define vms_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab static long vms_get_dynamic_reloc_upper_bound PARAMS ((bfd *abfd)); static long vms_canonicalize_dynamic_reloc diff --git a/binutils/ChangeLog b/binutils/ChangeLog index bb90e5ba2d1..e654faad9a1 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,12 @@ +2004-04-22 Jakub Jelinek + + * objdump.c (synthsyms, synthcount): New variables. + (disassemble_data): Use dynsyms for stripped binaries or libraries. + Add synthetized symbols. + (dump_bfd): For disassemble, initialize dynsyms always and + also synthsyms. Free synthsyms and clear {sym,dynsym,synth}count + before returning. + 2004-04-14 Alan Modra * strings.c (print_strings): Cast file_off to unsigned long in diff --git a/binutils/objdump.c b/binutils/objdump.c index 1e9d97058ba..1b89fa96489 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1,6 +1,6 @@ /* objdump.c -- dump information about an object file. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003 + 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Binutils. @@ -153,6 +153,10 @@ static long sorted_symcount = 0; /* The dynamic symbol table. */ static asymbol **dynsyms; +/* The synthetic symbol table. */ +static asymbol *synthsyms; +static long synthcount = 0; + /* Number of symbols in `dynsyms'. */ static long dynsymcount = 0; @@ -1775,6 +1779,7 @@ disassemble_data (bfd *abfd) { struct disassemble_info disasm_info; struct objdump_disasm_info aux; + long i; print_files = NULL; prev_functionname = NULL; @@ -1782,10 +1787,18 @@ disassemble_data (bfd *abfd) /* We make a copy of syms to sort. We don't want to sort syms because that will screw up the relocs. */ - sorted_syms = xmalloc (symcount * sizeof (asymbol *)); - memcpy (sorted_syms, syms, symcount * sizeof (asymbol *)); + sorted_symcount = symcount ? symcount : dynsymcount; + sorted_syms = xmalloc ((sorted_symcount + synthcount) * sizeof (asymbol *)); + memcpy (sorted_syms, symcount ? syms : dynsyms, + sorted_symcount * sizeof (asymbol *)); - sorted_symcount = remove_useless_symbols (sorted_syms, symcount); + sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount); + + for (i = 0; i < synthcount; ++i) + { + sorted_syms[sorted_symcount] = synthsyms + i; + ++sorted_symcount; + } /* Sort the symbols into section and symbol order. */ qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols); @@ -2545,8 +2558,14 @@ dump_bfd (bfd *abfd) if (dump_symtab || dump_reloc_info || disassemble || dump_debugging) syms = slurp_symtab (abfd); - if (dump_dynamic_symtab || dump_dynamic_reloc_info) + if (dump_dynamic_symtab || dump_dynamic_reloc_info + || (disassemble && bfd_get_dynamic_symtab_upper_bound (abfd) > 0)) dynsyms = slurp_dynamic_symtab (abfd); + if (disassemble && dynsymcount > 0) + { + synthcount = bfd_get_synthetic_symtab (abfd, dynsyms, &synthsyms); + if (synthcount < 0) synthcount = 0; + } if (dump_symtab) dump_symbols (abfd, FALSE); @@ -2591,6 +2610,16 @@ dump_bfd (bfd *abfd) free (dynsyms); dynsyms = NULL; } + + if (synthsyms) + { + free (synthsyms); + synthsyms = NULL; + } + + symcount = 0; + dynsymcount = 0; + synthcount = 0; } static void -- 2.30.2