From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id B49113858D33; Thu, 16 Feb 2023 11:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B49113858D33 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] gas_init X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: c84b3d7eaa3aec024ff2482e3a1fea0e89d01839 X-Git-Newrev: 7f27b6b18a0b72372128b2f49f743084776f1c54 Message-Id: <20230216112437.B49113858D33@sourceware.org> Date: Thu, 16 Feb 2023 11:24:37 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Feb 2023 11:24:37 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7f27b6b18a0b= 72372128b2f49f743084776f1c54 commit 7f27b6b18a0b72372128b2f49f743084776f1c54 Author: Alan Modra Date: Thu Feb 16 09:28:29 2023 +1030 gas_init =20 Rename gas_late_init to plain gas_init, to reinforce the idea that this is where the bulk of gas initialisation belongs. Also reorder some initialisation. =20 * as.c (gas_init): Rename from gas_late_init. Open output file and arrange for dump_statistics to be called here rather than in main. Create .gasversion. local symbol earlier, because we can. Diff: --- gas/as.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/gas/as.c b/gas/as.c index 0995292d1c8..23240989301 100644 --- a/gas/as.c +++ b/gas/as.c @@ -1314,10 +1314,10 @@ gas_early_init (int *argcp, char ***argvp) #endif } =20 -/* Init things that might depend on program args. */ +/* The bulk of gas initialisation. This is after args are parsed. */ =20 static void -gas_late_init (void) +gas_init (void) { symbol_begin (); frag_init (); @@ -1334,9 +1334,22 @@ gas_late_init (void) =20 dwarf2_init (); =20 - /* 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 !=3D 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); =20 dot_symbol_init (); @@ -1347,9 +1360,6 @@ gas_late_init (void) =20 itbl_init (); =20 - 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); =20 - /* 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); =20 @@ -1424,16 +1434,7 @@ main (int argc, char ** argv) } } =20 - /* 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 !=3D 0); - - gas_late_init (); + gas_init (); =20 PROGRESS (1);