From 0b2f8d2edd598eb8f013e8b61fd49def1d908281 Mon Sep 17 00:00:00 2001 From: David MacKenzie Date: Sat, 5 Feb 1994 01:14:56 +0000 Subject: * ldmisc.c (ldmalloc, xmalloc, ldrealloc, xrealloc): Functions deleted; will use libiberty versions instead. * ldctor.c ldfile.c ldlang.c ldmain.c ldmisc.c ldmisc.h lexsup.c mri.c Makefile.in: Change callers. * ldmisc.c (vfinfo): Remove cleanup code. * ldmain.c (remove_output): Put it here (new function). (preserve_output): New function. (main): Register remove_output and preserve_output with atexit. * ldmain.c ldgram.y: Call xexit instead of exit. * ldmisc.h: Declare xexit. --- ld/ChangeLog | 14 ++++++++++++++ ld/Makefile.in | 2 +- ld/ldlang.c | 6 +++--- ld/ldmain.c | 50 ++++++++++++++++++++++++++++++++++++-------------- 4 files changed, 54 insertions(+), 18 deletions(-) (limited to 'ld') diff --git a/ld/ChangeLog b/ld/ChangeLog index e8b4128..1a7c1e7 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,17 @@ +Fri Feb 4 16:26:08 1994 David J. Mackenzie (djm@thepub.cygnus.com) + + * ldmisc.c (ldmalloc, xmalloc, ldrealloc, xrealloc): Functions + deleted; will use libiberty versions instead. + * ldctor.c ldfile.c ldlang.c ldmain.c ldmisc.c ldmisc.h lexsup.c + mri.c Makefile.in: Change callers. + + * ldmisc.c (vfinfo): Remove cleanup code. + * ldmain.c (remove_output): Put it here (new function). + (preserve_output): New function. + (main): Register remove_output and preserve_output with atexit. + * ldmain.c ldgram.y: Call xexit instead of exit. + * ldmisc.h: Declare xexit. + Fri Feb 4 15:19:01 1994 Steve Chamberlain (sac@cygnus.com) * Makefile.in: Lots of new H8/500 memory models. diff --git a/ld/Makefile.in b/ld/Makefile.in index 171721d..b2c168f 100644 --- a/ld/Makefile.in +++ b/ld/Makefile.in @@ -235,7 +235,7 @@ ldlex.c: ldlex.l $(LEX) -I -Cem $(srcdir)/ldlex.l -sed -e '/^int.*free();/d' \ -e '/^char.*malloc();/d' \ - -e 's/malloc/ldmalloc/g' \ + -e 's/malloc/xmalloc/g' \ < lex.yy.c > ldlex.c.new -rm lex.yy.c mv ldlex.c.new ./ldlex.c diff --git a/ld/ldlang.c b/ld/ldlang.c index 5b1958f..f967baa 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -1,5 +1,5 @@ /* Linker command language support. - Copyright 1991, 1992, 1993 Free Software Foundation, Inc. + Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc. This file is part of GLD, the Gnu Linker. @@ -44,7 +44,7 @@ static lang_statement_union_type *new_statement PARAMS ((enum statement_enum, /* LOCALS */ static struct obstack stat_obstack; -#define obstack_chunk_alloc ldmalloc +#define obstack_chunk_alloc xmalloc #define obstack_chunk_free free static CONST char *startup_file; static lang_statement_list_type input_file_chain; @@ -1777,7 +1777,7 @@ lang_size_sections (s, output_section_statement, prev, fill, dot, relax) unsigned int symsize; symsize = get_symtab_upper_bound (i->owner); - is->ifile->asymbols = (asymbol **) ldmalloc (symsize); + is->ifile->asymbols = (asymbol **) xmalloc (symsize); is->ifile->symbol_count = bfd_canonicalize_symtab (i->owner, is->ifile->asymbols); diff --git a/ld/ldmain.c b/ld/ldmain.c index 403d028..43a20c2 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -1,5 +1,5 @@ /* Main program of GNU linker. - Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc. + Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc. Written by Steve Chamberlain steve@cygnus.com This file is part of GLD, the Gnu Linker. @@ -132,7 +132,26 @@ static struct bfd_link_callbacks link_callbacks = struct bfd_link_info link_info; -extern int main PARAMS ((int, char **)); +static void +remove_output () +{ + if (output_filename) + { + if (output_bfd && output_bfd->iostream) + fclose((FILE *)(output_bfd->iostream)); + if (delete_output_file_on_failure) + unlink (output_filename); + } +} + +/* Prevent remove_output from doing anything. + Called after a successful link. */ + +static void +preserve_output () +{ + output_filename = NULL; +} int main (argc, argv) @@ -146,6 +165,8 @@ main (argc, argv) bfd_init (); + atexit (remove_output); + /* Initialize the data about options. */ trace_files = trace_file_tries = version_printed = false; write_map = false; @@ -195,7 +216,7 @@ main (argc, argv) { /* sizeof counts the terminating NUL. */ size_t size = strlen (s) + sizeof ("-T "); - char *buf = (char *) ldmalloc(size); + char *buf = (char *) xmalloc(size); sprintf (buf, "-T %s", s); parse_line (buf, 0); free (buf); @@ -213,7 +234,7 @@ main (argc, argv) if (lang_has_input_file == false) { if (version_printed) - exit (0); + xexit (0); einfo ("%P%F: no input files\n"); } @@ -283,7 +304,7 @@ main (argc, argv) fclose ((FILE *) (output_bfd->iostream)); unlink (output_filename); - exit (1); + xexit (1); } else { @@ -302,7 +323,8 @@ main (argc, argv) (long) (lim - (char *) &environ)); } - exit (0); + atexit (preserve_output); + xexit (0); return 0; } @@ -376,7 +398,7 @@ check_for_scripts_dir (dir) dirlen = strlen (dir); /* sizeof counts the terminating NUL. */ - buf = (char *) ldmalloc (dirlen + sizeof("/ldscripts")); + buf = (char *) xmalloc (dirlen + sizeof("/ldscripts")); sprintf (buf, "%s/ldscripts", dir); res = stat (buf, &s) == 0 && S_ISDIR (s.st_mode); @@ -410,14 +432,14 @@ set_scripts_dir () dirlen = end - program_name; /* Make a copy of program_name in dir. Leave room for later "/../lib". */ - dir = (char *) ldmalloc (dirlen + 8); + dir = (char *) xmalloc (dirlen + 8); strncpy (dir, program_name, dirlen); dir[dirlen] = '\0'; } else { dirlen = 1; - dir = (char *) ldmalloc (dirlen + 8); + dir = (char *) xmalloc (dirlen + 8); strcpy (dir, "."); } @@ -439,7 +461,7 @@ add_ysym (name) if (link_info.notice_hash == (struct bfd_hash_table *) NULL) { link_info.notice_hash = ((struct bfd_hash_table *) - ldmalloc (sizeof (struct bfd_hash_table))); + xmalloc (sizeof (struct bfd_hash_table))); if (! bfd_hash_table_init_n (link_info.notice_hash, bfd_hash_newfunc, 61)) @@ -474,12 +496,12 @@ add_keepsyms_file (filename) } link_info.keep_hash = ((struct bfd_hash_table *) - ldmalloc (sizeof (struct bfd_hash_table))); + xmalloc (sizeof (struct bfd_hash_table))); if (! bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc)) einfo ("%P%F: bfd_hash_table_init failed: %E\n"); bufsize = 100; - buf = (char *) ldmalloc (bufsize); + buf = (char *) xmalloc (bufsize); c = getc (file); while (c != EOF) @@ -498,7 +520,7 @@ add_keepsyms_file (filename) if (len >= bufsize) { bufsize *= 2; - buf = ldrealloc (buf, bufsize); + buf = xrealloc (buf, bufsize); } c = getc (file); } @@ -532,7 +554,7 @@ add_archive_element (info, abfd, name) lang_input_statement_type *input; input = ((lang_input_statement_type *) - ldmalloc ((bfd_size_type) sizeof (lang_input_statement_type))); + xmalloc ((bfd_size_type) sizeof (lang_input_statement_type))); input->filename = abfd->filename; input->local_sym_name = abfd->filename; input->the_bfd = abfd; -- cgit v1.1