From a5d1b3b53e1db512253b2036c841645ff45df311 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 18 Jul 2007 11:23:37 +0000 Subject: [PATCH] * elf-bfd.h (struct sym_sec_cache): Delete "sec". Add "shndx". * elf.c (bfd_section_from_r_symndx): Don't cache bfd section of symbol. Instead cache ELF section index. Remove redundant checks of st_shndx. --- bfd/ChangeLog | 7 +++++++ bfd/elf-bfd.h | 2 +- bfd/elf.c | 49 ++++++++++++++++++++++++------------------------- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6f8051c6dc1..eb639c4b4f7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2007-07-18 Alan Modra + + * elf-bfd.h (struct sym_sec_cache): Delete "sec". Add "shndx". + * elf.c (bfd_section_from_r_symndx): Don't cache bfd section of + symbol. Instead cache ELF section index. Remove redundant + checks of st_shndx. + 2007-07-15 Mike Frysinger * trad-core.c (NBPG): If not defined, set to getpagesize(). diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 572e89b3d56..5db52f3c9fc 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -423,7 +423,7 @@ struct sym_sec_cache { bfd *abfd; unsigned long indx[LOCAL_SYM_CACHE_SIZE]; - asection *sec[LOCAL_SYM_CACHE_SIZE]; + unsigned int shndx[LOCAL_SYM_CACHE_SIZE]; }; /* Constant information held for an ELF backend. */ diff --git a/bfd/elf.c b/bfd/elf.c index 9fb5f24c3b6..cf7436f59ae 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -2273,36 +2273,35 @@ bfd_section_from_r_symndx (bfd *abfd, asection *sec, unsigned long r_symndx) { - Elf_Internal_Shdr *symtab_hdr; - unsigned char esym[sizeof (Elf64_External_Sym)]; - Elf_External_Sym_Shndx eshndx; - Elf_Internal_Sym isym; unsigned int ent = r_symndx % LOCAL_SYM_CACHE_SIZE; + asection *s; - if (cache->abfd == abfd && cache->indx[ent] == r_symndx) - return cache->sec[ent]; + if (cache->abfd != abfd || cache->indx[ent] != r_symndx) + { + Elf_Internal_Shdr *symtab_hdr; + unsigned char esym[sizeof (Elf64_External_Sym)]; + Elf_External_Sym_Shndx eshndx; + Elf_Internal_Sym isym; - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx, - &isym, esym, &eshndx) == NULL) - return NULL; + symtab_hdr = &elf_tdata (abfd)->symtab_hdr; + if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx, + &isym, esym, &eshndx) == NULL) + return NULL; - if (cache->abfd != abfd) - { - memset (cache->indx, -1, sizeof (cache->indx)); - cache->abfd = abfd; - } - cache->indx[ent] = r_symndx; - cache->sec[ent] = sec; - if ((isym.st_shndx != SHN_UNDEF && isym.st_shndx < SHN_LORESERVE) - || isym.st_shndx > SHN_HIRESERVE) - { - asection *s; - s = bfd_section_from_elf_index (abfd, isym.st_shndx); - if (s != NULL) - cache->sec[ent] = s; + if (cache->abfd != abfd) + { + memset (cache->indx, -1, sizeof (cache->indx)); + cache->abfd = abfd; + } + cache->indx[ent] = r_symndx; + cache->shndx[ent] = isym.st_shndx; } - return cache->sec[ent]; + + s = bfd_section_from_elf_index (abfd, cache->shndx[ent]); + if (s != NULL) + return s; + + return sec; } /* Given an ELF section number, retrieve the corresponding BFD -- 2.30.2