Fix as_perror() so that errno is not corrupted.
+2003-12-19 Nick Clifton <nickc@redhat.com>
+ Andreas Schwab <schwab@suse.de>
+
+ * messages.c (as_perror): Save errno around library calls.
+ * input-file.c [BFD_ASSEMBLER]: Set the BFD error to
+ bfd_error_system_call before each call to as_perror.
+ (input_file_open): Simplify the error reporting code to just use
+ as_perror().
+ * output-file.c (output_file_create) [BFD_ASSEMBLER]: Set the BFD
+ error to bfd_error_system_call before calling as_perror.
+ (output_file_close) [BFD_ASSEMBLER]: Likewise.
+ (output_file_append) [BFD_ASSEMBLER]: Likewise.
+ * listing.c (listing_print) [BFD_ASSEMBLER]: Likewise.
+
2003-12-19 Kazuhiro Inaoka <inaoka.kazuhiro@renesas.com>
Add m32r-linux and PIC support. Add new ABI that uses RELA.
if (f_in == NULL || ferror (f_in))
{
- switch (errno)
- {
- case ENOENT:
- as_bad (_("%s: no such file"), filename);
- break;
- case EISDIR:
- as_bad (_("%s: is a directory"), filename);
- break;
- default:
- as_bad (_("can't open %s for reading"), file_name);
- as_perror ("%s", file_name);
- }
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("Can't open %s for reading"), file_name);
if (f_in)
{
size = fread (buf, sizeof (char), buflen, f_in);
if (size < 0)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Can't read from %s"), file_name);
size = 0;
}
size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
if (size < 0)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Can't read from %s"), file_name);
size = 0;
}
else
{
if (fclose (f_in))
- as_perror (_("Can't close %s"), file_name);
+ {
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("Can't close %s"), file_name);
+ }
f_in = (FILE *) 0;
return_value = 0;
}
/* listing.c - maintain assembly listings
Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
- 2001, 2002
+ 2001, 2002, 2003
Free Software Foundation, Inc.
-This file is part of GAS, the GNU Assembler.
+ This file is part of GAS, the GNU Assembler.
-GAS is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+ GAS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
-GAS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ GAS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with GAS; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with GAS; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
-/*
- Contributed by Steve Chamberlain <sac@cygnus.com>
+/* Contributed by Steve Chamberlain <sac@cygnus.com>
A listing page looks like:
LISTING_LHS_CONT_LINES Max number of lines to use up for a continuation
LISTING_RHS_WIDTH Number of chars from the input file to print
- on a line
-*/
+ on a line. */
#include "as.h"
#include "obstack.h"
#endif
/* This structure remembers which .s were used. */
-typedef struct file_info_struct {
+typedef struct file_info_struct
+{
struct file_info_struct * next;
char * filename;
long pos;
/* This structure remembers which line from which file goes into which
frag. */
-struct list_info_struct {
+struct list_info_struct
+{
/* Frag which this line of source is nearest to. */
fragS *frag;
/* The actual line in the source file. */
unsigned int line;
+
/* Pointer to the file info struct for the file which this line
belongs to. */
file_info_type *file;
/* Pointer to the file info struct for the high level language
source line that belongs here. */
file_info_type *hll_file;
+
/* High level language source line. */
unsigned int hll_line;
/* Pointer to any error message associated with this line. */
char *message;
- enum {
- EDICT_NONE,
- EDICT_SBTTL,
- EDICT_TITLE,
- EDICT_NOLIST,
- EDICT_LIST,
- EDICT_NOLIST_NEXT,
- EDICT_EJECT
- } edict;
+ enum
+ {
+ EDICT_NONE,
+ EDICT_SBTTL,
+ EDICT_TITLE,
+ EDICT_NOLIST,
+ EDICT_LIST,
+ EDICT_NOLIST_NEXT,
+ EDICT_EJECT
+ } edict;
char *edict_arg;
/* Nonzero if this line is to be omitted because it contains
static char *data_buffer;
/* Prototypes. */
-static void listing_message (const char *name, const char *message);
-static file_info_type *file_info (const char *file_name);
+static void listing_message (const char *, const char *);
+static file_info_type *file_info (const char *);
static void new_frag (void);
-static char *buffer_line (file_info_type *file, char *line, unsigned int size);
-static void listing_page (list_info_type *list);
-static unsigned int calc_hex (list_info_type *list);
-static void print_lines (list_info_type *, unsigned int,
- char *, unsigned int);
+static char *buffer_line (file_info_type *, char *, unsigned int);
+static void listing_page (list_info_type *);
+static unsigned int calc_hex (list_info_type *);
+static void print_lines (list_info_type *, unsigned int, char *, unsigned int);
static void list_symbol_table (void);
-static void print_source (file_info_type *current_file, list_info_type *list,
- char *buffer, unsigned int width);
+static void print_source (file_info_type *, list_info_type *, char *, unsigned int);
static int debugging_pseudo (list_info_type *, const char *);
-static void listing_listing (char *name);
+static void listing_listing (char *);
static void
listing_message (const char *name, const char *message)
}
/* Make new entry. */
-
- p = (file_info_type *) xmalloc (sizeof (file_info_type));
+ p = xmalloc (sizeof (file_info_type));
p->next = file_info_head;
file_info_head = p;
p->filename = xstrdup (file_name);
static void
new_frag (void)
{
-
frag_wane (frag_now);
frag_new (0);
-
}
void
}
else
{
- new = (list_info_type *) xmalloc (sizeof (list_info_type));
+ new = xmalloc (sizeof (list_info_type));
new->line_contents = ps;
}
&& data_buffer_size < MAX_BYTES - 3)
{
if (address == ~(unsigned int) 0)
- {
- address = frag_ptr->fr_address / OCTETS_PER_BYTE;
- }
+ address = frag_ptr->fr_address / OCTETS_PER_BYTE;
sprintf (data_buffer + data_buffer_size,
"%02X",
&& data_buffer_size < MAX_BYTES - 3)
{
if (address == ~(unsigned int) 0)
- {
- address = frag_ptr->fr_address / OCTETS_PER_BYTE;
- }
+ address = frag_ptr->fr_address / OCTETS_PER_BYTE;
+
sprintf (data_buffer + data_buffer_size,
"%02X",
(frag_ptr->fr_literal[var_rep_idx]) & 0xff);
&& !current_file->at_end)
{
char *p = buffer_line (current_file, buffer, width);
+
fprintf (list_file, "%4u:%-13s **** %s\n", current_file->linenum,
current_file->filename, p);
on_page++;
return 1;
if (strncmp (line, "tag", 3) == 0)
return 1;
-
if (strncmp (line, "stabs", 5) == 0)
return 1;
if (strncmp (line, "stabn", 5) == 0)
if (list->next)
list->frag = list->next->frag;
list = list->next;
-
}
list = head->next;
message = 0;
if (list->hll_file)
- {
- current_hll_file = list->hll_file;
- }
+ current_hll_file = list->hll_file;
if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
- {
- print_source (current_hll_file, list, buffer, width);
- }
+ print_source (current_hll_file, list, buffer, width);
if (list->line_contents)
{
if (!((listing & LISTING_NODEBUG)
&& debugging_pseudo (list, list->line_contents)))
- {
- print_lines (list,
- list->file->linenum == 0 ? list->line : list->file->linenum,
- list->line_contents, calc_hex (list));
- }
+ print_lines (list,
+ list->file->linenum == 0 ? list->line : list->file->linenum,
+ list->line_contents, calc_hex (list));
+
free (list->line_contents);
list->line_contents = NULL;
}
}
if (list->edict == EDICT_EJECT)
- {
- eject = 1;
- }
+ eject = 1;
}
if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
using_stdout = 0;
else
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("can't open list file: %s"), name);
list_file = stdout;
using_stdout = 1;
}
if (listing & LISTING_NOFORM)
- {
- paper_height = 0;
- }
+ paper_height = 0;
if (listing & LISTING_LISTING)
- {
- listing_listing (name);
- }
+ listing_listing (name);
if (listing & LISTING_SYMBOLS)
- {
- list_symbol_table ();
- }
+ list_symbol_table ();
if (! using_stdout)
{
if (fclose (list_file) == EOF)
- as_perror (_("error closing list file: %s"), name);
+ {
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
+ as_perror (_("error closing list file: %s"), name);
+ }
}
if (last_open_file)
- {
- fclose (last_open_file);
- }
+ fclose (last_open_file);
}
void
void
listing_file (const char *name)
{
-
}
void
listing_newline (char *name)
{
-
}
void
listing_source_line (unsigned int n)
{
-
}
void
listing_source_file (const char *n)
{
-
}
#endif
/* messages.c - error reporter -
- Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001
+ Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2003
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
static void as_bad_internal (char *, unsigned int, char *);
/* Despite the rest of the comments in this file, (FIXME-SOON),
- * here is the current scheme for error messages etc:
- *
- * as_fatal() is used when gas is quite confused and
- * continuing the assembly is pointless. In this case we
- * exit immediately with error status.
- *
- * as_bad() is used to mark errors that result in what we
- * presume to be a useless object file. Say, we ignored
- * something that might have been vital. If we see any of
- * these, assembly will continue to the end of the source,
- * no object file will be produced, and we will terminate
- * with error status. The new option, -Z, tells us to
- * produce an object file anyway but we still exit with
- * error status. The assumption here is that you don't want
- * this object file but we could be wrong.
- *
- * as_warn() is used when we have an error from which we
- * have a plausible error recovery. eg, masking the top
- * bits of a constant that is longer than will fit in the
- * destination. In this case we will continue to assemble
- * the source, although we may have made a bad assumption,
- * and we will produce an object file and return normal exit
- * status (ie, no error). The new option -X tells us to
- * treat all as_warn() errors as as_bad() errors. That is,
- * no object file will be produced and we will exit with
- * error status. The idea here is that we don't kill an
- * entire make because of an error that we knew how to
- * correct. On the other hand, sometimes you might want to
- * stop the make at these points.
- *
- * as_tsktsk() is used when we see a minor error for which
- * our error recovery action is almost certainly correct.
- * In this case, we print a message and then assembly
- * continues as though no error occurred.
- */
+ here is the current scheme for error messages etc:
+
+ as_fatal() is used when gas is quite confused and
+ continuing the assembly is pointless. In this case we
+ exit immediately with error status.
+
+ as_bad() is used to mark errors that result in what we
+ presume to be a useless object file. Say, we ignored
+ something that might have been vital. If we see any of
+ these, assembly will continue to the end of the source,
+ no object file will be produced, and we will terminate
+ with error status. The new option, -Z, tells us to
+ produce an object file anyway but we still exit with
+ error status. The assumption here is that you don't want
+ this object file but we could be wrong.
+
+ as_warn() is used when we have an error from which we
+ have a plausible error recovery. eg, masking the top
+ bits of a constant that is longer than will fit in the
+ destination. In this case we will continue to assemble
+ the source, although we may have made a bad assumption,
+ and we will produce an object file and return normal exit
+ status (ie, no error). The new option -X tells us to
+ treat all as_warn() errors as as_bad() errors. That is,
+ no object file will be produced and we will exit with
+ error status. The idea here is that we don't kill an
+ entire make because of an error that we knew how to
+ correct. On the other hand, sometimes you might want to
+ stop the make at these points.
+
+ as_tsktsk() is used when we see a minor error for which
+ our error recovery action is almost certainly correct.
+ In this case, we print a message and then assembly
+ continues as though no error occurred. */
static void
identify (char *file)
{
static int identified;
+
if (identified)
return;
identified++;
int
had_warnings (void)
{
- return (warning_count);
+ return warning_count;
}
/* Nonzero if we've hit a 'bad error', and should not write an obj file,
int
had_errors (void)
{
- return (error_count);
+ return error_count;
}
/* Print the current location to stderr. */
const char *filename)
{
const char *errtxt;
+ int saved_errno = errno;
as_show_where ();
fprintf (stderr, gripe, filename);
+ errno = saved_errno;
#ifdef BFD_ASSEMBLER
errtxt = bfd_errmsg (bfd_get_error ());
#else
/* output-file.c - Deal with the output file
- Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001
+ Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2001, 2003
Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
#ifndef BFD_ASSEMBLER
void
-output_file_append (where, length, filename)
- char *where ATTRIBUTE_UNUSED;
- long length ATTRIBUTE_UNUSED;
- char *filename ATTRIBUTE_UNUSED;
+output_file_append (char *where ATTRIBUTE_UNUSED,
+ long length ATTRIBUTE_UNUSED,
+ char *filename ATTRIBUTE_UNUSED)
{
abort ();
}
static FILE *stdoutput;
void
-output_file_create (name)
- char *name;
+output_file_create (char *name)
{
if (name[0] == '-' && name[1] == '\0')
{
stdoutput = fopen (name, FOPEN_WB);
if (stdoutput == NULL)
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("FATAL: can't create %s"), name);
exit (EXIT_FAILURE);
}
}
void
-output_file_close (filename)
- char *filename;
+output_file_close (char *filename)
{
if (EOF == fclose (stdoutput))
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("FATAL: can't close %s"), filename);
exit (EXIT_FAILURE);
}
}
void
-output_file_append (where, length, filename)
- char * where;
- long length;
- char * filename;
+output_file_append (char * where, long length, char * filename)
{
for (; length; length--, where++)
{
(void) putc (*where, stdoutput);
if (ferror (stdoutput))
- /* if ( EOF == (putc( *where, stdoutput )) ) */
{
+#ifdef BFD_ASSEMBLER
+ bfd_set_error (bfd_error_system_call);
+#endif
as_perror (_("Failed to emit an object byte"), filename);
as_fatal (_("can't continue"));
}