public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gas: set up notes obstack earlier
@ 2022-07-09 12:36 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2022-07-09 12:36 UTC (permalink / raw)
  To: bfd-cvs

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

commit af3d7ab74f0aff2eb2af68d0d1df2e27e5757ecd
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jul 7 13:32:30 2022 +0930

    gas: set up notes obstack earlier
    
    So that the notes obstack can be used for persistent storage in
    parse_args.
    
            * as.c (parse_args): Use notes_alloc and notes_strdup.
            (free_notes): New function.
            (main): Init notes obstack, and arrange to be freed on exit.
            * read.c (read_begin): Don't init notes obstack.
            (read_end): Free cond_obstack.
            * subsegs.c (subsegs_end): Don't free cond_obstack or notes.

Diff:
---
 gas/as.c      | 20 ++++++++++++++------
 gas/read.c    |  4 +---
 gas/subsegs.c |  2 --
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/gas/as.c b/gas/as.c
index 8b2b3e8d33f..2b8886e8b54 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -588,7 +588,7 @@ parse_args (int * pargc, char *** pargv)
   old_argv = *pargv;
 
   /* Initialize a new argv that contains no options.  */
-  new_argv = XNEWVEC (char *, old_argc + 1);
+  new_argv = notes_alloc (sizeof (char *) * (old_argc + 1));
   new_argv[0] = old_argv[0];
   new_argc = 1;
   new_argv[new_argc] = NULL;
@@ -996,7 +996,7 @@ This program has absolutely no warranty.\n"));
  	case OPTION_AL:
 	  listing |= LISTING_LISTING;
 	  if (optarg)
-	    listing_filename = xstrdup (optarg);
+	    listing_filename = notes_strdup (optarg);
 	  break;
 
  	case OPTION_ALTERNATE:
@@ -1050,7 +1050,7 @@ This program has absolutely no warranty.\n"));
 		      listing |= LISTING_SYMBOLS;
 		      break;
 		    case '=':
-		      listing_filename = xstrdup (optarg + 1);
+		      listing_filename = notes_strdup (optarg + 1);
 		      optarg += strlen (listing_filename);
 		      break;
 		    default:
@@ -1076,14 +1076,14 @@ This program has absolutely no warranty.\n"));
 
 	case 'I':
 	  {			/* Include file directory.  */
-	    char *temp = xstrdup (optarg);
+	    char *temp = notes_strdup (optarg);
 
 	    add_include_dir (temp);
 	    break;
 	  }
 
 	case 'o':
-	  out_file_name = xstrdup (optarg);
+	  out_file_name = notes_strdup (optarg);
 	  break;
 
 	case 'w':
@@ -1231,7 +1231,12 @@ perform_an_assembly_pass (int argc, char ** argv)
   if (!saw_a_file)
     read_a_source_file ("");
 }
-\f
+
+static void
+free_notes (void)
+{
+  _obstack_free (&notes, NULL);
+}
 
 int
 main (int argc, char ** argv)
@@ -1280,6 +1285,9 @@ main (int argc, char ** argv)
   select_emulation_mode (argc, argv);
 #endif
 
+  obstack_begin (&notes, chunksize);
+  xatexit (free_notes);
+
   PROGRESS (1);
   /* Call parse_args before any of the init/begin functions
      so that switches like --hash-size can be honored.  */
diff --git a/gas/read.c b/gas/read.c
index edf3f2a7881..6f3a51df761 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -261,9 +261,6 @@ read_begin (void)
   pobegin ();
   obj_read_begin_hook ();
 
-  /* Something close -- but not too close -- to a multiple of 1024.
-     The debugging malloc I'm using has 24 bytes of overhead.  */
-  obstack_begin (&notes, chunksize);
   obstack_begin (&cond_obstack, chunksize);
 
 #ifndef tc_line_separator_chars
@@ -282,6 +279,7 @@ void
 read_end (void)
 {
   poend ();
+  _obstack_free (&cond_obstack, NULL);
 }
 \f
 #ifndef TC_ADDRESS_BYTES
diff --git a/gas/subsegs.c b/gas/subsegs.c
index 1776511a9b8..b1a85d3d6c7 100644
--- a/gas/subsegs.c
+++ b/gas/subsegs.c
@@ -50,8 +50,6 @@ subsegs_end (struct obstack **obs)
   for (; *obs; obs++)
     _obstack_free (*obs, NULL);
   _obstack_free (&frchains, NULL);
-  _obstack_free (&cond_obstack, NULL);
-  _obstack_free (&notes, NULL);
 }
 \f
 static void


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-09 12:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-09 12:36 [binutils-gdb] gas: set up notes obstack earlier Alan Modra

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