public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/lto-plugin-cleanup)] Enable migration to C++.
@ 2022-01-06 11:22 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2022-01-06 11:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:61e9768a902922cd1fa136670e11dac92ae428d7

commit 61e9768a902922cd1fa136670e11dac92ae428d7
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Jan 5 14:00:15 2022 +0100

    Enable migration to C++.
    
    lto-plugin/ChangeLog:
    
            * lto-plugin.c (translate): Use XRESIZEVEC and correct
            signed/unsigned integer types.
            (free_1): Likewise.
            (dump_symtab): Likewise.
            (finish_conflict_resolution): Likewise.
            (add_output_files): Likewise.
            (resolve_conflicts): Likewise.
            (process_symtab): Likewise.
            (process_symtab_extension): Likewise.
            (claim_file_handler): Likewise.
            (process_option): Likewise.
            (onload): Likewise.

Diff:
---
 lto-plugin/lto-plugin.c | 55 +++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 0147b1b9667..51e0b4ded43 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -185,7 +185,7 @@ static char **output_files = NULL;
 static unsigned int num_output_files = 0;
 
 static char **lto_wrapper_argv;
-static int lto_wrapper_num_args;
+static unsigned lto_wrapper_num_args;
 
 static char **pass_through_items = NULL;
 static unsigned int num_pass_through_items;
@@ -363,9 +363,9 @@ translate (char *data, char *end, struct plugin_symtab *out)
      the algorithm is O(1) now. */
 
   len = (end - data)/8 + out->nsyms + 1;
-  syms = xrealloc (out->syms, len * sizeof (struct ld_plugin_symbol));
-  aux = xrealloc (out->aux, len * sizeof (struct sym_aux));
-  
+  syms = XRESIZEVEC (struct ld_plugin_symbol, out->syms, len);
+  aux = XRESIZEVEC (struct sym_aux, out->aux, len);
+
   for (n = out->nsyms; data < end; n++) 
     { 
       aux[n].id = out->id; 
@@ -414,13 +414,11 @@ parse_symtab_extension (char *data, char *end, struct plugin_symtab *out)
 static void
 free_1 (struct plugin_file_info *files, unsigned num_files)
 {
-  unsigned int i;
-  for (i = 0; i < num_files; i++)
+  for (unsigned i = 0; i < num_files; i++)
     {
       struct plugin_file_info *info = &files[i];
       struct plugin_symtab *symtab = &info->symtab;
-      unsigned int j;
-      for (j = 0; j < symtab->nsyms; j++)
+      for (int j = 0; j < symtab->nsyms; j++)
 	{
 	  struct ld_plugin_symbol *s = &symtab->syms[j];
 	  free (s->name);
@@ -470,9 +468,7 @@ free_2 (void)
 static void
 dump_symtab (FILE *f, struct plugin_symtab *symtab)
 {
-  unsigned j;
-
-  for (j = 0; j < symtab->nsyms; j++)
+  for (int j = 0; j < symtab->nsyms; j++)
     {
       uint32_t slot = symtab->aux[j].slot;
       unsigned int resolution = symtab->syms[j].resolution;
@@ -502,7 +498,7 @@ finish_conflict_resolution (struct plugin_symtab *symtab,
     { 
       char resolution = LDPR_UNKNOWN;
 
-      if (symtab->aux[i].next_conflict == -1)
+      if (symtab->aux[i].next_conflict == -1U)
 	continue;
 
       switch (symtab->syms[i].def) 
@@ -591,7 +587,7 @@ add_output_files (FILE *f)
   for (;;)
     {
       const unsigned piece = 32;
-      char *buf, *s = xmalloc (piece);
+      char *buf, *s = XNEWVEC (char, piece);
       size_t len;
 
       buf = s;
@@ -604,15 +600,14 @@ cont:
       len = strlen (s);
       if (s[len - 1] != '\n')
 	{
-	  s = xrealloc (s, len + piece);
+	  s = XRESIZEVEC (char, s, len + piece);
 	  buf = s + len;
 	  goto cont;
 	}
       s[len - 1] = '\0';
 
       num_output_files++;
-      output_files
-	= xrealloc (output_files, num_output_files * sizeof (char *));
+      output_files = XRESIZEVEC (char *, output_files, num_output_files);
       output_files[num_output_files - 1] = s;
       add_input_file (output_files[num_output_files - 1]);
     }
@@ -962,8 +957,8 @@ resolve_conflicts (struct plugin_symtab *t, struct plugin_symtab *conflicts)
   int outlen;
 
   outlen = t->nsyms;
-  conflicts->syms = xmalloc (sizeof (struct ld_plugin_symbol) * outlen);
-  conflicts->aux = xmalloc (sizeof (struct sym_aux) * outlen);
+  conflicts->syms = XNEWVEC (struct ld_plugin_symbol, outlen);
+  conflicts->aux = XNEWVEC (struct sym_aux, outlen);
 
   /* Move all duplicate symbols into the auxiliary conflicts table. */
   out = 0;
@@ -1027,7 +1022,7 @@ static int
 process_symtab (void *data, const char *name, off_t offset, off_t length)
 {
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
-  char *s;
+  const char *s;
   char *secdatastart, *secdata;
 
   if (!startswith (name, ".gnu.lto_.symtab"))
@@ -1036,7 +1031,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
   s = strrchr (name, '.');
   if (s)
     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
-  secdata = secdatastart = xmalloc (length);
+  secdata = secdatastart = XNEWVEC (char, length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET))
     goto err;
@@ -1079,7 +1074,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
 			  off_t length)
 {
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
-  char *s;
+  const char *s;
   char *secdatastart, *secdata;
 
   if (!startswith (name, ".gnu.lto_.ext_symtab"))
@@ -1088,7 +1083,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
   s = strrchr (name, '.');
   if (s)
     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
-  secdata = secdatastart = xmalloc (length);
+  secdata = secdatastart = XNEWVEC (char, length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET))
     goto err;
@@ -1231,9 +1226,8 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
       check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
 
       num_claimed_files++;
-      claimed_files =
-	xrealloc (claimed_files,
-		  num_claimed_files * sizeof (struct plugin_file_info));
+      claimed_files = XRESIZEVEC (struct plugin_file_info,
+				  claimed_files, num_claimed_files);
       claimed_files[num_claimed_files - 1] = lto_file;
 
       *claimed = 1;
@@ -1242,7 +1236,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
   if (offload_files == NULL)
     {
       /* Add dummy item to the start of the list.  */
-      offload_files = xmalloc (sizeof (struct plugin_offload_file));
+      offload_files = XNEW (struct plugin_offload_file);
       offload_files->name = NULL;
       offload_files->next = NULL;
       offload_files_last = offload_files;
@@ -1260,8 +1254,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
 	 order after recompilation and linking, otherwise host and target tables
 	 with addresses wouldn't match.  If a static library contains both LTO
 	 and non-LTO objects, ld and gold link them in a different order.  */
-      struct plugin_offload_file *ofld
-	= xmalloc (sizeof (struct plugin_offload_file));
+      struct plugin_offload_file *ofld = XNEW (struct plugin_offload_file);
       ofld->name = lto_file.name;
       ofld->next = NULL;
 
@@ -1338,8 +1331,8 @@ process_option (const char *option)
   else if (startswith (option, "-pass-through="))
     {
       num_pass_through_items++;
-      pass_through_items = xrealloc (pass_through_items,
-				     num_pass_through_items * sizeof (char *));
+      pass_through_items = XRESIZEVEC (char *, pass_through_items,
+				       num_pass_through_items);
       pass_through_items[num_pass_through_items - 1] =
           xstrdup (option + strlen ("-pass-through="));
     }
@@ -1512,7 +1505,7 @@ onload (struct ld_plugin_tv *tv)
 	     find an odd number of them), and it copies characters
 	     that are escaped or not otherwise skipped.  */
 	  int len = p - start - ticks - escapes + 1;
-	  char *q = xmalloc (len);
+	  char *q = XNEWVEC (char, len);
 	  link_output_name = q;
 	  int oddticks = (ticks % 2);
 	  ticks += oddticks;


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/marxin/heads/lto-plugin-cleanup)] Enable migration to C++.
@ 2022-01-05 13:02 Martin Liska
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Liska @ 2022-01-05 13:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:17de4d675005368d7e69615da22cd405542c4fe1

commit 17de4d675005368d7e69615da22cd405542c4fe1
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Jan 5 14:00:15 2022 +0100

    Enable migration to C++.
    
    lto-plugin/ChangeLog:
    
            * lto-plugin.c (translate): Use XRESIZEVEC and correct
            signed/unsigned integer types.
            (free_1): Likewise.
            (dump_symtab): Likewise.
            (finish_conflict_resolution): Likewise.
            (add_output_files): Likewise.
            (resolve_conflicts): Likewise.
            (process_symtab): Likewise.
            (process_symtab_extension): Likewise.
            (claim_file_handler): Likewise.
            (process_option): Likewise.
            (onload): Likewise.

Diff:
---
 lto-plugin/lto-plugin.c | 55 +++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 0147b1b9667..51e0b4ded43 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -185,7 +185,7 @@ static char **output_files = NULL;
 static unsigned int num_output_files = 0;
 
 static char **lto_wrapper_argv;
-static int lto_wrapper_num_args;
+static unsigned lto_wrapper_num_args;
 
 static char **pass_through_items = NULL;
 static unsigned int num_pass_through_items;
@@ -363,9 +363,9 @@ translate (char *data, char *end, struct plugin_symtab *out)
      the algorithm is O(1) now. */
 
   len = (end - data)/8 + out->nsyms + 1;
-  syms = xrealloc (out->syms, len * sizeof (struct ld_plugin_symbol));
-  aux = xrealloc (out->aux, len * sizeof (struct sym_aux));
-  
+  syms = XRESIZEVEC (struct ld_plugin_symbol, out->syms, len);
+  aux = XRESIZEVEC (struct sym_aux, out->aux, len);
+
   for (n = out->nsyms; data < end; n++) 
     { 
       aux[n].id = out->id; 
@@ -414,13 +414,11 @@ parse_symtab_extension (char *data, char *end, struct plugin_symtab *out)
 static void
 free_1 (struct plugin_file_info *files, unsigned num_files)
 {
-  unsigned int i;
-  for (i = 0; i < num_files; i++)
+  for (unsigned i = 0; i < num_files; i++)
     {
       struct plugin_file_info *info = &files[i];
       struct plugin_symtab *symtab = &info->symtab;
-      unsigned int j;
-      for (j = 0; j < symtab->nsyms; j++)
+      for (int j = 0; j < symtab->nsyms; j++)
 	{
 	  struct ld_plugin_symbol *s = &symtab->syms[j];
 	  free (s->name);
@@ -470,9 +468,7 @@ free_2 (void)
 static void
 dump_symtab (FILE *f, struct plugin_symtab *symtab)
 {
-  unsigned j;
-
-  for (j = 0; j < symtab->nsyms; j++)
+  for (int j = 0; j < symtab->nsyms; j++)
     {
       uint32_t slot = symtab->aux[j].slot;
       unsigned int resolution = symtab->syms[j].resolution;
@@ -502,7 +498,7 @@ finish_conflict_resolution (struct plugin_symtab *symtab,
     { 
       char resolution = LDPR_UNKNOWN;
 
-      if (symtab->aux[i].next_conflict == -1)
+      if (symtab->aux[i].next_conflict == -1U)
 	continue;
 
       switch (symtab->syms[i].def) 
@@ -591,7 +587,7 @@ add_output_files (FILE *f)
   for (;;)
     {
       const unsigned piece = 32;
-      char *buf, *s = xmalloc (piece);
+      char *buf, *s = XNEWVEC (char, piece);
       size_t len;
 
       buf = s;
@@ -604,15 +600,14 @@ cont:
       len = strlen (s);
       if (s[len - 1] != '\n')
 	{
-	  s = xrealloc (s, len + piece);
+	  s = XRESIZEVEC (char, s, len + piece);
 	  buf = s + len;
 	  goto cont;
 	}
       s[len - 1] = '\0';
 
       num_output_files++;
-      output_files
-	= xrealloc (output_files, num_output_files * sizeof (char *));
+      output_files = XRESIZEVEC (char *, output_files, num_output_files);
       output_files[num_output_files - 1] = s;
       add_input_file (output_files[num_output_files - 1]);
     }
@@ -962,8 +957,8 @@ resolve_conflicts (struct plugin_symtab *t, struct plugin_symtab *conflicts)
   int outlen;
 
   outlen = t->nsyms;
-  conflicts->syms = xmalloc (sizeof (struct ld_plugin_symbol) * outlen);
-  conflicts->aux = xmalloc (sizeof (struct sym_aux) * outlen);
+  conflicts->syms = XNEWVEC (struct ld_plugin_symbol, outlen);
+  conflicts->aux = XNEWVEC (struct sym_aux, outlen);
 
   /* Move all duplicate symbols into the auxiliary conflicts table. */
   out = 0;
@@ -1027,7 +1022,7 @@ static int
 process_symtab (void *data, const char *name, off_t offset, off_t length)
 {
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
-  char *s;
+  const char *s;
   char *secdatastart, *secdata;
 
   if (!startswith (name, ".gnu.lto_.symtab"))
@@ -1036,7 +1031,7 @@ process_symtab (void *data, const char *name, off_t offset, off_t length)
   s = strrchr (name, '.');
   if (s)
     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
-  secdata = secdatastart = xmalloc (length);
+  secdata = secdatastart = XNEWVEC (char, length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET))
     goto err;
@@ -1079,7 +1074,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
 			  off_t length)
 {
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
-  char *s;
+  const char *s;
   char *secdatastart, *secdata;
 
   if (!startswith (name, ".gnu.lto_.ext_symtab"))
@@ -1088,7 +1083,7 @@ process_symtab_extension (void *data, const char *name, off_t offset,
   s = strrchr (name, '.');
   if (s)
     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
-  secdata = secdatastart = xmalloc (length);
+  secdata = secdatastart = XNEWVEC (char, length);
   offset += obj->file->offset;
   if (offset != lseek (obj->file->fd, offset, SEEK_SET))
     goto err;
@@ -1231,9 +1226,8 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
       check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
 
       num_claimed_files++;
-      claimed_files =
-	xrealloc (claimed_files,
-		  num_claimed_files * sizeof (struct plugin_file_info));
+      claimed_files = XRESIZEVEC (struct plugin_file_info,
+				  claimed_files, num_claimed_files);
       claimed_files[num_claimed_files - 1] = lto_file;
 
       *claimed = 1;
@@ -1242,7 +1236,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
   if (offload_files == NULL)
     {
       /* Add dummy item to the start of the list.  */
-      offload_files = xmalloc (sizeof (struct plugin_offload_file));
+      offload_files = XNEW (struct plugin_offload_file);
       offload_files->name = NULL;
       offload_files->next = NULL;
       offload_files_last = offload_files;
@@ -1260,8 +1254,7 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
 	 order after recompilation and linking, otherwise host and target tables
 	 with addresses wouldn't match.  If a static library contains both LTO
 	 and non-LTO objects, ld and gold link them in a different order.  */
-      struct plugin_offload_file *ofld
-	= xmalloc (sizeof (struct plugin_offload_file));
+      struct plugin_offload_file *ofld = XNEW (struct plugin_offload_file);
       ofld->name = lto_file.name;
       ofld->next = NULL;
 
@@ -1338,8 +1331,8 @@ process_option (const char *option)
   else if (startswith (option, "-pass-through="))
     {
       num_pass_through_items++;
-      pass_through_items = xrealloc (pass_through_items,
-				     num_pass_through_items * sizeof (char *));
+      pass_through_items = XRESIZEVEC (char *, pass_through_items,
+				       num_pass_through_items);
       pass_through_items[num_pass_through_items - 1] =
           xstrdup (option + strlen ("-pass-through="));
     }
@@ -1512,7 +1505,7 @@ onload (struct ld_plugin_tv *tv)
 	     find an odd number of them), and it copies characters
 	     that are escaped or not otherwise skipped.  */
 	  int len = p - start - ticks - escapes + 1;
-	  char *q = xmalloc (len);
+	  char *q = XNEWVEC (char, len);
 	  link_output_name = q;
 	  int oddticks = (ticks % 2);
 	  ticks += oddticks;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-06 11:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 11:22 [gcc(refs/users/marxin/heads/lto-plugin-cleanup)] Enable migration to C++ Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2022-01-05 13:02 Martin Liska

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).