[AArch64] Remove some dead code from elf64_aarch64_check_relocs.

Message ID 517930D7.9090907@linaro.org
State Accepted
Headers show

Commit Message

Will Newton April 25, 2013, 1:34 p.m.
This code was inherited from the ARM backend, but will never be hit due to the more restrictive test above.

bfd/ChangeLog:

2013-04-25  Will Newton  <will.newton@linaro.org>

	* elf64-aarch64.c (elf64_aarch64_check_relocs): Remove dead code.
---
 bfd/elf64-aarch64.c | 16 +---------------
 1 file changed, 1 insertion(+), 15 deletions(-)

Comments

Yufeng Zhang April 25, 2013, 4:17 p.m. | #1
On 04/25/13 14:34, Will Newton wrote:
>
> This code was inherited from the ARM backend, but will never be hit due to the more restrictive test above.

Looks OK to me (but I cannot approve it).

Just curious that how you spotted this piece of dead code; are you 
running any static code analyzer on bfd?

Thanks,
Yufeng
Will Newton April 25, 2013, 4:36 p.m. | #2
On 25 April 2013 17:17, Yufeng Zhang <Yufeng.Zhang@arm.com> wrote:
> On 04/25/13 14:34, Will Newton wrote:
>>
>>
>> This code was inherited from the ARM backend, but will never be hit due to
>> the more restrictive test above.
>
>
> Looks OK to me (but I cannot approve it).
>
> Just curious that how you spotted this piece of dead code; are you running
> any static code analyzer on bfd?

Hi Yufeng,

No, I'm implementing support for GNU indirect functions for AArch64,
and this code is on one of the paths that needs modifying so I
happened to notice it.

--
Will Newton
Toolchain Working Group, Linaro
Marcus Shawcroft April 26, 2013, 7:44 a.m. | #3
Looks OK to me.
/Marcus

On 25 April 2013 14:34, Will Newton <will.newton@linaro.org> wrote:
>
> This code was inherited from the ARM backend, but will never be hit due to the more restrictive test above.
>
> bfd/ChangeLog:
>
> 2013-04-25  Will Newton  <will.newton@linaro.org>
>
>         * elf64-aarch64.c (elf64_aarch64_check_relocs): Remove dead code.
> ---
>  bfd/elf64-aarch64.c | 16 +---------------
>  1 file changed, 1 insertion(+), 15 deletions(-)
>
> diff --git a/bfd/elf64-aarch64.c b/bfd/elf64-aarch64.c
> index 540b275..9a6d8b4 100644
> --- a/bfd/elf64-aarch64.c
> +++ b/bfd/elf64-aarch64.c
> @@ -5141,8 +5141,6 @@ elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
>
>    struct elf64_aarch64_link_hash_table *htab;
>
> -  unsigned long nsyms;
> -
>    if (info->relocatable)
>      return TRUE;
>
> @@ -5153,7 +5151,6 @@ elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
>
>    symtab_hdr = &elf_symtab_hdr (abfd);
>    sym_hashes = elf_sym_hashes (abfd);
> -  nsyms = NUM_SHDR_ENTRIES (symtab_hdr);
>
>    rel_end = relocs + sec->reloc_count;
>    for (rel = relocs; rel < rel_end; rel++)
> @@ -5172,18 +5169,7 @@ elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
>           return FALSE;
>         }
>
> -      if (r_symndx >= nsyms
> -         /* PR 9934: It is possible to have relocations that do not
> -            refer to symbols, thus it is also possible to have an
> -            object file containing relocations but no symbol table.  */
> -         && (r_symndx > 0 || nsyms > 0))
> -       {
> -         (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
> -                                r_symndx);
> -         return FALSE;
> -       }
> -
> -      if (nsyms == 0 || r_symndx < symtab_hdr->sh_info)
> +      if (r_symndx < symtab_hdr->sh_info)
>         h = NULL;
>        else
>         {
> --
> 1.8.1.4
>
Will Newton April 26, 2013, 9:21 a.m. | #4
On 26 April 2013 08:44, Marcus Shawcroft <marcus.shawcroft@gmail.com> wrote:
> Looks OK to me.
> /Marcus

Thanks, committed.

Patch

diff --git a/bfd/elf64-aarch64.c b/bfd/elf64-aarch64.c
index 540b275..9a6d8b4 100644
--- a/bfd/elf64-aarch64.c
+++ b/bfd/elf64-aarch64.c
@@ -5141,8 +5141,6 @@  elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,

   struct elf64_aarch64_link_hash_table *htab;

-  unsigned long nsyms;
-
   if (info->relocatable)
     return TRUE;

@@ -5153,7 +5151,6 @@  elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,

   symtab_hdr = &elf_symtab_hdr (abfd);
   sym_hashes = elf_sym_hashes (abfd);
-  nsyms = NUM_SHDR_ENTRIES (symtab_hdr);

   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
@@ -5172,18 +5169,7 @@  elf64_aarch64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	  return FALSE;
 	}

-      if (r_symndx >= nsyms
-	  /* PR 9934: It is possible to have relocations that do not
-	     refer to symbols, thus it is also possible to have an
-	     object file containing relocations but no symbol table.  */
-	  && (r_symndx > 0 || nsyms > 0))
-	{
-	  (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
-				 r_symndx);
-	  return FALSE;
-	}
-
-      if (nsyms == 0 || r_symndx < symtab_hdr->sh_info)
+      if (r_symndx < symtab_hdr->sh_info)
 	h = NULL;
       else
 	{