]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gas/as.c
gas_init
[thirdparty/binutils-gdb.git] / gas / as.c
index 0995292d1c8e6b266a09cb025fe3ed9a436ae721..23240989301f626f5dfdfb40862f8da9ec700989 100644 (file)
--- a/gas/as.c
+++ b/gas/as.c
@@ -1314,10 +1314,10 @@ gas_early_init (int *argcp, char ***argvp)
 #endif
 }
 
-/* Init things that might depend on program args.  */
+/* The bulk of gas initialisation.  This is after args are parsed.  */
 
 static void
-gas_late_init (void)
+gas_init (void)
 {
   symbol_begin ();
   frag_init ();
@@ -1334,9 +1334,22 @@ gas_late_init (void)
 
   dwarf2_init ();
 
-  /* Somewhat arbitrary division into initialisation above that
-     doesn't need stdoutput open (even though it is open), and below
-     where things might be put on stdoutput memory, eg. symbols.  */
+  local_symbol_make (".gasversion.", absolute_section,
+                    &predefined_address_frag, BFD_VERSION / 10000UL);
+
+  /* Note: Put new initialisation calls that don't depend on stdoutput
+     being open above this point.  stdoutput must be open for anything
+     that might use stdoutput objalloc memory, eg. calling bfd_alloc
+     or creating global symbols (via bfd_make_empty_symbol).  */
+  xatexit (output_file_close);
+  output_file_create (out_file_name);
+  gas_assert (stdoutput != 0);
+
+  /* Must be called before output_file_close.  xexit calls the xatexit
+     list in reverse order.  */
+  if (flag_print_statistics)
+    xatexit (dump_statistics);
+
   PROGRESS (1);
 
   dot_symbol_init ();
@@ -1347,9 +1360,6 @@ gas_late_init (void)
 
   itbl_init ();
 
-  local_symbol_make (".gasversion.", absolute_section,
-                    &predefined_address_frag, BFD_VERSION / 10000UL);
-
   /* Now that we have fully initialized, and have created the output
      file, define any symbols requested by --defsym command line
      arguments.  */
@@ -1381,7 +1391,7 @@ main (int argc, char ** argv)
   gas_early_init (&argc, &argv);
   PROGRESS (1);
 
-  /* Call parse_args before gas_late_init so that switches like
+  /* Call parse_args before gas_init so that switches like
      --hash-size can be honored.  */
   parse_args (&argc, &argv);
 
@@ -1424,16 +1434,7 @@ main (int argc, char ** argv)
        }
     }
 
-  /* It has to be called after dump_statistics ().  */
-  xatexit (output_file_close);
-
-  if (flag_print_statistics)
-    xatexit (dump_statistics);
-
-  output_file_create (out_file_name);
-  gas_assert (stdoutput != 0);
-
-  gas_late_init ();
+  gas_init ();
 
   PROGRESS (1);