This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] [ARC] Fix local got entry list.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0f2064107ba373ddcffb30afc55ac08b40c0585e

commit 0f2064107ba373ddcffb30afc55ac08b40c0585e
Author: Claudiu Zissulescu <claziss@gmail.com>
Date:   Fri Nov 9 13:14:00 2018 +0200

    [ARC] Fix local got entry list.
    
    Fix a memory leak appearing when the local got entry list was constructed.
    
    bfd/
    xxxx-xx-xx  Claudiu Zissulescu  <claziss@synopsys.com>
    
    	* arc-got.h (arc_get_local_got_ents): Revamp it; use
    	elf_local_got_ents to store the local got list.
    	(get_got_entry_list_for_symbo): Restructure it.
    	* elf32-arc.c (elf_arc_relocate_section): Correct the call to
    	get_got_entry_list_for_symbol.

Diff:
---
 bfd/ChangeLog   |  8 ++++++++
 bfd/arc-got.h   | 33 +++++++++++++++------------------
 bfd/elf32-arc.c |  2 +-
 3 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f0b36de..cce5968 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2018-11-09  Claudiu Zissulescu  <claziss@synopsys.com>
+
+	* arc-got.h (arc_get_local_got_ents): Revamp it; use
+	elf_local_got_ents to store the local got list.
+	(get_got_entry_list_for_symbo): Restructure it.
+	* elf32-arc.c (elf_arc_relocate_section): Correct the call to
+	get_got_entry_list_for_symbol.
+
 2018-11-07  Nick Clifton  <nickc@redhat.com>
 
 	* po/fr.po: Updated French translation.
diff --git a/bfd/arc-got.h b/bfd/arc-got.h
index 07722fd..69e9aa3 100644
--- a/bfd/arc-got.h
+++ b/bfd/arc-got.h
@@ -54,27 +54,26 @@ struct got_entry
   enum tls_got_entries existing_entries;
 };
 
+/* Return the local got list, if not defined, create an empty one.  */
+
 static struct got_entry **
 arc_get_local_got_ents (bfd * abfd)
 {
-  static struct got_entry **local_got_ents = NULL;
-
-  if (local_got_ents == NULL)
+  if (elf_local_got_ents (abfd) == NULL)
     {
-      size_t	   size;
-      Elf_Internal_Shdr *symtab_hdr = &((elf_tdata (abfd))->symtab_hdr);
-
-      size = symtab_hdr->sh_info * sizeof (bfd_vma);
-      local_got_ents = (struct got_entry **)
-	bfd_alloc (abfd, sizeof (struct got_entry *) * size);
-      if (local_got_ents == NULL)
-	return FALSE;
-
-      memset (local_got_ents, 0, sizeof (struct got_entry *) * size);
-      elf_local_got_ents (abfd) = local_got_ents;
+      bfd_size_type amt = (elf_tdata (abfd)->symtab_hdr.sh_info
+			   * sizeof (*elf_local_got_ents (abfd)));
+      elf_local_got_ents (abfd) = bfd_zmalloc (amt);
+      if (elf_local_got_ents (abfd) == NULL)
+	{
+	  _bfd_error_handler (_("%pB: cannot allocate memory for local "
+				"GOT entries"), abfd);
+	  bfd_set_error (bfd_error_bad_value);
+	  return NULL;
+	}
     }
 
-  return local_got_ents;
+  return elf_local_got_ents (abfd);
 }
 
 static struct got_entry *
@@ -167,9 +166,7 @@ get_got_entry_list_for_symbol (bfd *abfd,
     }
   else
     {
-      struct got_entry **local_got_ents
-	= arc_get_local_got_ents (abfd);
-      return &local_got_ents[r_symndx];
+      return arc_get_local_got_ents (abfd) + r_symndx;
     }
 }
 
diff --git a/bfd/elf32-arc.c b/bfd/elf32-arc.c
index 30f47a5..668642c 100644
--- a/bfd/elf32-arc.c
+++ b/bfd/elf32-arc.c
@@ -1740,7 +1740,7 @@ elf_arc_relocate_section (bfd *			  output_bfd,
 	  reloc_data.should_relocate = TRUE;
 
 	  struct got_entry **list
-	    = get_got_entry_list_for_symbol (output_bfd, r_symndx, h);
+	    = get_got_entry_list_for_symbol (input_bfd, r_symndx, h);
 
 	  reloc_data.got_offset_value
 	    = relocate_fix_got_relocs_for_got_info (list,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]