public inbox for gdb-testers@sourceware.org
help / color / mirror / Atom feed
From: gdb-buildbot@sergiodj.net
To: gdb-testers@sourceware.org
Subject: [binutils-gdb] remove more xmalloc in bfd
Date: Sun, 20 Oct 2019 15:53:00 -0000	[thread overview]
Message-ID: <9a73315161bc07d958060847ae01996312e1b30f@gdb-build> (raw)

*** TEST RESULTS FOR COMMIT 9a73315161bc07d958060847ae01996312e1b30f ***

commit 9a73315161bc07d958060847ae01996312e1b30f
Author:     Alan Modra <amodra@gmail.com>
AuthorDate: Tue Oct 15 15:57:35 2019 +1030
Commit:     Alan Modra <amodra@gmail.com>
CommitDate: Tue Oct 15 16:50:32 2019 +1030

    remove more xmalloc in bfd
    
    Also fixes m68hc1x printf arguments which would have bombed when
    compiling on a 32-bit host with --enable-64-bit-bfd.
    
    bfd/
            PR 24955
            * elf32-arm.c (set_cmse_veneer_addr_from_implib): Use bfd_malloc
            rather than xmalloc.
            * elf32-m68hc1x.c (reloc_warning): New function.
            (elf32_m68hc11_relocate_section): Use it here.  Cast bfd_vma values
            corresponding to %lx in format strings.
            * elf32-nds32.c (nds32_insertion_sort): Use a stack temporary.
    gas/
            * config/tc-nds32.c (nds32_set_section_relocs): Use relocs and n
            parameters rather than equivalent sec->orelocation and
            sec->reloc_count.  Don't sort for n <= 1.  Tidy.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 40ddfa14d5..72fb5eea97 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,13 @@
+2019-10-15  Alan Modra  <amodra@gmail.com>
+
+	PR 24955
+	* elf32-arm.c (set_cmse_veneer_addr_from_implib): Use bfd_malloc
+	rather than xmalloc.
+	* elf32-m68hc1x.c (reloc_warning): New function.
+	(elf32_m68hc11_relocate_section): Use it here.  Cast bfd_vma values
+	corresponding to %lx in format strings.
+	* elf32-nds32.c (nds32_insertion_sort): Use a stack temporary.
+
 2019-10-15  Alan Modra  <amodra@gmail.com>
 
 	PR 25100
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 9837350d06..3aa7de8fee 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -6255,7 +6255,10 @@ set_cmse_veneer_addr_from_implib (struct bfd_link_info *info,
     return FALSE;
 
   /* Read in the input secure gateway import library's symbol table.  */
-  sympp = (asymbol **) xmalloc (symsize);
+  sympp = (asymbol **) bfd_malloc (symsize);
+  if (sympp == NULL)
+    return FALSE;
+
   symcount = bfd_canonicalize_symtab (in_implib_bfd, sympp);
   if (symcount < 0)
     {
diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c
index 8739ca86c1..915f3b7a9a 100644
--- a/bfd/elf32-m68hc1x.c
+++ b/bfd/elf32-m68hc1x.c
@@ -899,6 +899,29 @@ elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info,
   return TRUE;
 }
 
+static bfd_boolean
+reloc_warning (struct bfd_link_info *info, const char *name, bfd *input_bfd,
+	       asection *input_section, const Elf_Internal_Rela *rel,
+	       const char *fmt, ...)
+{
+  va_list ap;
+  char *buf;
+  int ret;
+
+  va_start (ap, fmt);
+  ret = vasprintf (&buf, fmt, ap);
+  va_end (ap);
+  if (ret < 0)
+    {
+      bfd_set_error (bfd_error_no_memory);
+      return FALSE;
+    }
+  info->callbacks->warning (info, buf, name, input_bfd, input_section,
+			    rel->r_offset);
+  free (buf);
+  return TRUE;
+}
+
 /* Relocate a 68hc11/68hc12 ELF section.  */
 bfd_boolean
 elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
@@ -951,8 +974,7 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
       bfd_boolean is_section_symbol = FALSE;
       struct elf_link_hash_entry *h;
       bfd_vma val;
-      const char * msg;
-      char * buf;
+      const char *msg;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
       r_type = ELF32_R_TYPE (rel->r_info);
@@ -1108,17 +1130,13 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 	  break;
 
 	case R_M68HC11_16:
-	  /* Get virtual address of instruction having the relocation.  */
 	  if (is_far)
 	    {
 	      msg = _("reference to the far symbol `%s' using a wrong "
 		      "relocation may result in incorrect execution");
-	      buf = xmalloc (strlen (msg) + strlen (name) + 10);
-	      sprintf (buf, msg, name);
-
-	      (*info->callbacks->warning)
-		(info, buf, name, input_bfd, NULL, rel->r_offset);
-	      free (buf);
+	      if (!reloc_warning (info, name, input_bfd, input_section, rel,
+				  msg, name))
+		return FALSE;
 	    }
 
 	  /* Get virtual address of instruction having the relocation.  */
@@ -1149,30 +1167,28 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 			  "(0xE000-0xFFFF), therefore you must manually offset "
 			  "the address, and possibly manage the page, in your "
 			  "code.");
-		  buf = xmalloc (strlen (msg) + 128);
-		  sprintf (buf, msg, phys_addr);
-		  (*info->callbacks->warning) (info, buf, name, input_bfd,
-					       input_section, insn_addr);
-		  free (buf);
+		  if (!reloc_warning (info, name, input_bfd, input_section, rel,
+				      msg, (long) phys_addr))
+		    return FALSE;
 		  break;
 		}
 	    }
 
 	  if (m68hc11_addr_is_banked (pinfo, relocation + rel->r_addend)
 	      && m68hc11_addr_is_banked (pinfo, insn_addr)
-	      && phys_page != insn_page && !(e_flags & E_M68HC11_NO_BANK_WARNING))
+	      && phys_page != insn_page
+	      && !(e_flags & E_M68HC11_NO_BANK_WARNING))
 	    {
 	      /* xgettext:c-format */
-	      msg = _("banked address [%lx:%04lx] (%lx) is not in the same bank "
-		      "as current banked address [%lx:%04lx] (%lx)");
-	      buf = xmalloc (strlen (msg) + 128);
-	      sprintf (buf, msg, phys_page, phys_addr,
-		       (long) (relocation + rel->r_addend),
-		       insn_page, m68hc11_phys_addr (pinfo, insn_addr),
-		       (long) (insn_addr));
-	      (*info->callbacks->warning) (info, buf, name, input_bfd,
-					   input_section, rel->r_offset);
-	      free (buf);
+	      msg = _("banked address [%lx:%04lx] (%lx) is not in the same "
+		      "bank as current banked address [%lx:%04lx] (%lx)");
+	      if (!reloc_warning (info, name, input_bfd, input_section, rel,
+				  msg, (long) phys_page, (long) phys_addr,
+				  (long) (relocation + rel->r_addend),
+				  (long) insn_page,
+				  (long) m68hc11_phys_addr (pinfo, insn_addr),
+				  (long) insn_addr))
+		return FALSE;
 	      break;
 	    }
 
@@ -1181,11 +1197,10 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 	      /* xgettext:c-format */
 	      msg = _("reference to a banked address [%lx:%04lx] in the "
 		      "normal address space at %04lx");
-	      buf = xmalloc (strlen (msg) + 128);
-	      sprintf (buf, msg, phys_page, phys_addr, insn_addr);
-	      (*info->callbacks->warning) (info, buf, name, input_bfd,
-					   input_section, insn_addr);
-	      free (buf);
+	      if (!reloc_warning (info, name, input_bfd, input_section, rel,
+				  msg, (long) phys_page, (long) phys_addr,
+				  (long) insn_addr))
+		return FALSE;
 	      relocation = phys_addr;
 	      break;
 	    }
@@ -1216,18 +1231,12 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED,
 		relocation += 0xC000;
 	      else
 		{
-		  /* Get virtual address of instruction having the relocation.  */
-		  insn_addr = input_section->output_section->vma
-		      + input_section->output_offset + rel->r_offset;
-
 		  msg = _("S12 address (%lx) is not within shared RAM"
-		      "(0x2000-0x4000), therefore you must manually "
-		      "offset the address in your code");
-		  buf = xmalloc (strlen (msg) + 128);
-		  sprintf (buf, msg, phys_addr);
-		  (*info->callbacks->warning) (info, buf, name, input_bfd,
-					       input_section, insn_addr);
-		  free (buf);
+			  "(0x2000-0x4000), therefore you must manually "
+			  "offset the address in your code");
+		  if (!reloc_warning (info, name, input_bfd, input_section, rel,
+				      msg, (long) phys_addr))
+		    return FALSE;
 		  break;
 		}
 	    }
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 013355a490..482fb290d1 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -2526,7 +2526,9 @@ nds32_insertion_sort (void *base, size_t nmemb, size_t size,
 {
   char *ptr = (char *) base;
   int i, j;
-  char *tmp = xmalloc (size);
+  char tmp[sizeof (Elf_Internal_Rela)];
+
+  BFD_ASSERT (size <= sizeof (tmp));
 
   /* If i is less than j, i is inserted before j.
 
@@ -2550,7 +2552,6 @@ nds32_insertion_sort (void *base, size_t nmemb, size_t size,
       memmove (ptr + (j + 1) * size, ptr + j * size, (i - j) * size);
       memcpy (ptr + j * size, tmp, size);
     }
-  free (tmp);
 }
 
 /* Sort relocation by r_offset.
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 3a1183b374..33cc6ffc9a 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@
+2019-10-15  Alan Modra  <amodra@gmail.com>
+
+	* config/tc-nds32.c (nds32_set_section_relocs): Use relocs and n
+	parameters rather than equivalent sec->orelocation and
+	sec->reloc_count.  Don't sort for n <= 1.  Tidy.
+
 2019-10-09  Nick Clifton  <nickc@redhat.com>
 
 	PR 25041
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c
index 36ed58a453..a75dd9ada9 100644
--- a/gas/config/tc-nds32.c
+++ b/gas/config/tc-nds32.c
@@ -7565,13 +7565,13 @@ compar_relent (const void *lhs, const void *rhs)
    relocation.  */
 
 void
-nds32_set_section_relocs (asection *sec, arelent ** relocs ATTRIBUTE_UNUSED,
-			  unsigned int n ATTRIBUTE_UNUSED)
+nds32_set_section_relocs (asection *sec ATTRIBUTE_UNUSED,
+			  arelent **relocs, unsigned int n)
 {
-  bfd *abfd ATTRIBUTE_UNUSED = sec->owner;
-  if (bfd_section_flags (sec) & (flagword) SEC_RELOC)
-    nds32_insertion_sort (sec->orelocation, sec->reloc_count,
-			  sizeof (arelent**), compar_relent);
+  if (n <= 1)
+    return;
+
+  nds32_insertion_sort (relocs, n, sizeof (*relocs), compar_relent);
 }
 
 long


             reply	other threads:[~2019-10-20 15:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-20 15:53 gdb-buildbot [this message]
2019-10-20 15:53 ` Failures on Ubuntu-Aarch64-m64, branch master gdb-buildbot
2019-10-20 17:22 ` Failures on Ubuntu-Aarch64-native-extended-gdbserver-m64, " gdb-buildbot
2019-10-20 18:04 ` Failures on Ubuntu-Aarch64-native-gdbserver-m64, " gdb-buildbot
2019-10-28 22:31 ` Failures on Fedora-x86_64-cc-with-index, " gdb-buildbot
2019-10-28 22:31 ` Failures on Fedora-x86_64-m32, " gdb-buildbot
2019-10-28 23:19 ` Failures on Fedora-x86_64-m64, " gdb-buildbot
2019-10-29  0:11 ` Failures on Fedora-x86_64-native-gdbserver-m32, " gdb-buildbot
2019-10-29  0:13 ` Failures on Fedora-x86_64-native-extended-gdbserver-m64, " gdb-buildbot
2019-10-29  1:03 ` Failures on Fedora-x86_64-native-gdbserver-m64, " gdb-buildbot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a73315161bc07d958060847ae01996312e1b30f@gdb-build \
    --to=gdb-buildbot@sergiodj.net \
    --cc=gdb-testers@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).