X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=blobdiff_plain;f=gcc%2Fmips-tfile.c;h=25f732a296642d2b7846a3cc170ff97bf977e0cd;hp=0f72aee7c0e26fec26b3cc7a55a455318144c156;hb=071be23809d255227730595ebfae85181b744ac8;hpb=805e22b2051e9c6a75377ea6599654d7415da483 diff --git a/gcc/mips-tfile.c b/gcc/mips-tfile.c index 0f72aee7c0e..25f732a2966 100644 --- a/gcc/mips-tfile.c +++ b/gcc/mips-tfile.c @@ -1,16 +1,17 @@ -/* Update the symbol table (the .T file) in a MIPS object to +/* Update the symbol table (the .T file) in a ECOFF object to contain debugging information specified by the GNU compiler in the form of comments (the mips assembler does not support assembly access to debug information). - Copyright (C) 1991, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001 + Copyright (C) 1991, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. Contributed by Michael Meissner (meissner@cygnus.com). - + This file is part of GCC. GCC 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 +Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY @@ -19,9 +20,8 @@ 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 GCC; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ +along with GCC; see the file COPYING3. If not see +. */ /* Here is a brief description of the MIPS ECOFF symbol table. The @@ -57,7 +57,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA The auxiliary table is a series of 32 bit integers, that are referenced as needed from the local symbol table. Unlike standard - COFF, the aux. information does not follow the symbol that uses + COFF, the aux. information does not follow the symbol that uses it, but rather is a separate table. In theory, this would allow the MIPS compilers to collapse duplicate aux. entries, but I've not noticed this happening with the 1.31 compiler suite. The different @@ -98,31 +98,31 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA array, pointer, function, etc. qualifiers. The current base types that I have documentation for are: - btNil -- undefined + btNil -- undefined btAdr -- address - integer same size as ptr - btChar -- character - btUChar -- unsigned character - btShort -- short - btUShort -- unsigned short - btInt -- int - btUInt -- unsigned int - btLong -- long - btULong -- unsigned long - btFloat -- float (real) - btDouble -- Double (real) - btStruct -- Structure (Record) - btUnion -- Union (variant) - btEnum -- Enumerated - btTypedef -- defined via a typedef isymRef - btRange -- subrange of int - btSet -- pascal sets - btComplex -- fortran complex - btDComplex -- fortran double complex - btIndirect -- forward or unnamed typedef - btFixedDec -- Fixed Decimal - btFloatDec -- Float Decimal - btString -- Varying Length Character String - btBit -- Aligned Bit String + btChar -- character + btUChar -- unsigned character + btShort -- short + btUShort -- unsigned short + btInt -- int + btUInt -- unsigned int + btLong -- long + btULong -- unsigned long + btFloat -- float (real) + btDouble -- Double (real) + btStruct -- Structure (Record) + btUnion -- Union (variant) + btEnum -- Enumerated + btTypedef -- defined via a typedef isymRef + btRange -- subrange of int + btSet -- pascal sets + btComplex -- fortran complex + btDComplex -- fortran double complex + btIndirect -- forward or unnamed typedef + btFixedDec -- Fixed Decimal + btFloatDec -- Float Decimal + btString -- Varying Length Character String + btBit -- Aligned Bit String btPicture -- Picture btVoid -- Void (MIPS cc revision >= 2.00) @@ -130,12 +130,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA current type qualifier fields I have documentation for are: - tqNil -- no more qualifiers - tqPtr -- pointer - tqProc -- procedure - tqArray -- array - tqFar -- 8086 far pointers - tqVol -- volatile + tqNil -- no more qualifiers + tqPtr -- pointer + tqProc -- procedure + tqArray -- array + tqFar -- 8086 far pointers + tqVol -- volatile The dense number table is used in the front ends, and disappears by @@ -163,7 +163,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA Each file table has offsets for where the line numbers, local strings, local symbols, and procedure table starts from within the - global tables, and the indexs are reset to 0 for each of those + global tables, and the indices are reset to 0 for each of those tables for the file. The procedure table contains the binary equivalents of the .ent @@ -244,7 +244,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA } Mips-tdump produces the following information: - + Global file header: magic number 0x162 # sections 2 @@ -253,12 +253,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA symbolic header size 96 optional header 56 flags 0x0 - + Symbolic header, magic number = 0x7009, vstamp = 1.31: - + Info Offset Number Bytes ==== ====== ====== ===== - + Line numbers 380 4 4 [13] Dense numbers 0 0 0 Procedures Tables 384 1 52 @@ -270,14 +270,14 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA File Tables 1008 2 144 Relative Files 0 0 0 External Symbols 1152 20 320 - + File #0, "hello2.c" - + Name index = 1 Readin = No Merge = No Endian = LITTLE Debug level = G2 Language = C Adr = 0x00000000 - + Info Start Number Size Offset ==== ===== ====== ==== ====== Local strings 0 15 15 784 @@ -287,7 +287,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA Procedures 0 1 52 384 Auxiliary symbols 0 14 56 628 Relative Files 0 0 0 0 - + There are 6 local symbols, starting at 436 Symbol# 0: "hello2.c" @@ -602,86 +602,40 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "config.h" #include "system.h" -#include "coretypes.h" -#include "tm.h" #include "version.h" #include "intl.h" -#ifndef __SABER__ -#define saber_stop() -#endif +/* Include getopt.h for the sake of getopt_long. */ +#include "getopt.h" -#ifndef __LINE__ -#define __LINE__ 0 -#endif +/* Macros for mips-tfile.c to encapsulate stabs in ECOFF, and for + mips-tdump.c to print them out. -/* Due to size_t being defined in sys/types.h and different - in stddef.h, we have to do this by hand..... Note, these - types are correct for MIPS based systems, and may not be - correct for other systems. Ultrix 4.0 and Silicon Graphics - have this fixed, but since the following is correct, and - the fact that including stddef.h gets you GCC's version - instead of the standard one it's not worth it to fix it. */ + These must match the corresponding definitions in gdb/mipsread.c. + Unfortunately, gcc and gdb do not currently share any directories. */ -#if defined(__OSF1__) || defined(__OSF__) || defined(__osf__) -#define Size_t long unsigned int -#else -#define Size_t unsigned int -#endif -#define Ptrdiff_t long +#define CODE_MASK 0x8F300 +#define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK) +#define MIPS_MARK_STAB(code) ((code)+CODE_MASK) +#define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK) /* The following might be called from obstack or malloc, so they can't be static. */ -extern void pfatal_with_name - PARAMS ((const char *)) ATTRIBUTE_NORETURN; -extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN; - void botch PARAMS ((const char *)) ATTRIBUTE_NORETURN; - -extern void fatal PARAMS ((const char *format, ...)) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; -extern void error PARAMS ((const char *format, ...)) ATTRIBUTE_PRINTF_1; - -#ifndef MIPS_DEBUGGING_INFO - -static int line_number; -static int cur_line_start; -static int debug; -static int had_errors; -static const char *progname; -static const char *input_name; - -int -main () -{ - fprintf (stderr, "Mips-tfile should only be run on a MIPS computer!\n"); - exit (1); -} +extern void pfatal_with_name (const char *) ATTRIBUTE_NORETURN; +extern void botch (const char *) ATTRIBUTE_NORETURN; -#else /* MIPS_DEBUGGING defined */ +extern void fatal (const char *format, ...) ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN; +extern void error (const char *format, ...) ATTRIBUTE_PRINTF_1; /* The local and global symbols have a field index, so undo any defines of index -> strchr. */ #undef index -#include - -#ifndef CROSS_COMPILE #include -#else -#include "mips/a.out.h" -#endif /* CROSS_COMPILE */ - #include "gstab.h" -#define STAB_CODE_TYPE enum __stab_debug_code - -#ifndef MALLOC_CHECK -#ifdef __SABER__ -#define MALLOC_CHECK -#endif -#endif - #define IS_ASM_IDENT(ch) \ (ISIDNUM (ch) || (ch) == '.' || (ch) == '$') @@ -736,7 +690,7 @@ typedef enum st { st_StaticProc = stStaticProc, /* load time only static procs */ st_Constant = stConstant, /* const */ st_Str = stStr, /* string */ - st_Number = stNumber, /* pure number (ie. 4 NOR 2+2) */ + st_Number = stNumber, /* pure number (i.e. 4 NOR 2+2) */ st_Expr = stExpr, /* 2+2 vs. 4 */ st_Type = stType, /* post-coercion SER */ st_Max = stMax /* max type+1 */ @@ -895,16 +849,13 @@ enum alloc_type { pages. On systems with a BSD malloc that define USE_MALLOC, the MAX_CLUSTER_PAGES should be 1 less than a power of two, since malloc adds its overhead, and rounds up to the next power of 2. Pages are - linked together via a linked list. - - If PAGE_SIZE is > 4096, the string length in the shash_t structure - can't be represented (assuming there are strings > 4096 bytes). */ + linked together via a linked list. */ #ifndef PAGE_SIZE -#define PAGE_SIZE 4096 /* size of varray pages */ +#define PAGE_SIZE 32768 /* size of varray pages */ #endif -#define PAGE_USIZE ((Size_t) PAGE_SIZE) +#define PAGE_USIZE ((size_t) PAGE_SIZE) #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */ @@ -950,6 +901,13 @@ typedef struct varray { OBJECTS_PER_PAGE (type), /* objects_last_page */ \ } +#define INITIALIZE_VARRAY(x,type) \ +do { \ + (x)->object_size = sizeof (type); \ + (x)->objects_per_page = OBJECTS_PER_PAGE (type); \ + (x)->objects_last_page = OBJECTS_PER_PAGE (type); \ +} while (0) + /* Master type for indexes within the symbol table. */ typedef unsigned long symint_t; @@ -1008,9 +966,7 @@ typedef union small_free { /* String hash table support. The size of the hash table must fit within a page. */ -#ifndef SHASH_SIZE -#define SHASH_SIZE 1009 -#endif +#define SHASH_SIZE 511 #define HASH_LEN_MAX ((1 << 12) - 1) /* Max length we can store */ @@ -1032,9 +988,7 @@ typedef struct shash { Because unique types which are hashed are fewer in number than strings, we use a smaller hash value. */ -#ifndef THASH_SIZE -#define THASH_SIZE 113 -#endif +#define THASH_SIZE 55 typedef struct thash { struct thash *next; /* next hash value */ @@ -1066,90 +1020,8 @@ typedef struct efdr { } efdr_t; /* Pre-initialized extended file structure. */ -static efdr_t init_file = -{ - { /* FDR structure */ -#ifdef __alpha - 0, /* adr: memory address of beginning of file */ - 0, /* cbLineOffset: byte offset from header for this file ln's */ - 0, /* cbLine: size of lines for this file */ - 0, /* cbSs: number of bytes in the ss */ - 0, /* rss: file name (of source, if known) */ - 0, /* issBase: file's string space */ - 0, /* isymBase: beginning of symbols */ - 0, /* csym: count file's of symbols */ - 0, /* ilineBase: file's line symbols */ - 0, /* cline: count of file's line symbols */ - 0, /* ioptBase: file's optimization entries */ - 0, /* copt: count of file's optimization entries */ - 0, /* ipdFirst: start of procedures for this file */ - 0, /* cpd: count of procedures for this file */ - 0, /* iauxBase: file's auxiliary entries */ - 0, /* caux: count of file's auxiliary entries */ - 0, /* rfdBase: index into the file indirect table */ - 0, /* crfd: count file indirect entries */ - langC, /* lang: language for this file */ - 1, /* fMerge: whether this file can be merged */ - 0, /* fReadin: true if read in (not just created) */ -#ifdef HOST_WORDS_BIG_ENDIAN - 1, /* fBigendian: if 1, compiled on big endian machine */ -#else - 0, /* fBigendian: if 1, compiled on big endian machine */ -#endif - 0, /* fTrim: whether the symbol table was trimmed */ - GLEVEL_2, /* glevel: level this file was compiled with */ - 0, /* reserved: reserved for future use */ -#else - 0, /* adr: memory address of beginning of file */ - 0, /* rss: file name (of source, if known) */ - 0, /* issBase: file's string space */ - 0, /* cbSs: number of bytes in the ss */ - 0, /* isymBase: beginning of symbols */ - 0, /* csym: count file's of symbols */ - 0, /* ilineBase: file's line symbols */ - 0, /* cline: count of file's line symbols */ - 0, /* ioptBase: file's optimization entries */ - 0, /* copt: count of file's optimization entries */ - 0, /* ipdFirst: start of procedures for this file */ - 0, /* cpd: count of procedures for this file */ - 0, /* iauxBase: file's auxiliary entries */ - 0, /* caux: count of file's auxiliary entries */ - 0, /* rfdBase: index into the file indirect table */ - 0, /* crfd: count file indirect entries */ - langC, /* lang: language for this file */ - 1, /* fMerge: whether this file can be merged */ - 0, /* fReadin: true if read in (not just created) */ -#ifdef HOST_WORDS_BIG_ENDIAN - 1, /* fBigendian: if 1, compiled on big endian machine */ -#else - 0, /* fBigendian: if 1, compiled on big endian machine */ -#endif - GLEVEL_2, /* glevel: level this file was compiled with */ - 0, /* reserved: reserved for future use */ - 0, /* cbLineOffset: byte offset from header for this file ln's */ - 0, /* cbLine: size of lines for this file */ -#endif - }, - - (FDR *) 0, /* orig_fdr: original file header pointer */ - (char *) 0, /* name: pointer to filename */ - 0, /* name_len: length of filename */ - 0, /* void_type: ptr to aux node for void type */ - 0, /* int_type: ptr to aux node for int type */ - (scope_t *) 0, /* cur_scope: current scope being processed */ - 0, /* file_index: current file # */ - 0, /* nested_scopes: # nested scopes */ - INIT_VARRAY (char), /* strings: local string varray */ - INIT_VARRAY (SYMR), /* symbols: local symbols varray */ - INIT_VARRAY (PDR), /* procs: procedure varray */ - INIT_VARRAY (AUXU), /* aux_syms: auxiliary symbols varray */ - - (struct efdr *) 0, /* next_file: next file structure */ - - (shash_t **) 0, /* shash_head: string hash table */ - { 0 }, /* thash_head: type hash table */ -}; - +static int init_file_initialized = 0; +static efdr_t init_file; static efdr_t *first_file; /* first file descriptor */ static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */ @@ -1570,11 +1442,11 @@ static SYMR *cur_oproc_begin = (SYMR *) 0; /* original proc. sym begin info * static SYMR *cur_oproc_end = (SYMR *) 0; /* original proc. sym end info */ static PDR *cur_oproc_ptr = (PDR *) 0; /* current original procedure*/ static thead_t *cur_tag_head = (thead_t *) 0;/* current tag head */ -static long file_offset = 0; /* current file offset */ -static long max_file_offset = 0; /* maximum file offset */ +static unsigned long file_offset = 0; /* current file offset */ +static unsigned long max_file_offset = 0; /* maximum file offset */ static FILE *object_stream = (FILE *) 0; /* file desc. to output .o */ static FILE *obj_in_stream = (FILE *) 0; /* file desc. to input .o */ -static char *progname = (char *) 0; /* program name for errors */ +static const char *progname = (const char *) 0;/* program name for errors */ static const char *input_name = "stdin"; /* name of input file */ static char *object_name = (char *) 0; /* tmp. name of object file */ static char *obj_in_name = (char *) 0; /* name of input object file */ @@ -1583,8 +1455,9 @@ static char *cur_line_ptr = (char *) 0; /* ptr within current line */ static unsigned cur_line_nbytes = 0; /* # bytes for current line */ static unsigned cur_line_alloc = 0; /* # bytes total in buffer */ static long line_number = 0; /* current input line number */ -static int debug = 0; /* trace functions */ -static int version = 0; /* print version # */ +static int debug = 0; /* trace functions */ +static int version = 0; /* print version # */ +static int verbose = 0; static int had_errors = 0; /* != 0 if errors were found */ static int rename_output = 0; /* != 0 if rename output file*/ static int delete_input = 0; /* != 0 if delete input after done */ @@ -1601,111 +1474,64 @@ static const char stabs_symbol[] = STABS_SYMBOL; /* Forward reference for functions. See the definition for more details. */ -#ifndef STATIC -#define STATIC static -#endif - -STATIC int out_of_bounds PARAMS ((symint_t, symint_t, const char *, int)); - -STATIC shash_t *hash_string PARAMS ((const char *, - Ptrdiff_t, - shash_t **, - symint_t *)); - -STATIC symint_t add_string PARAMS ((varray_t *, - shash_t **, - const char *, - const char *, - shash_t **)); - -STATIC symint_t add_local_symbol - PARAMS ((const char *, - const char *, - st_t, - sc_t, - symint_t, - symint_t)); - -STATIC symint_t add_ext_symbol PARAMS ((EXTR *, - int)); - -STATIC symint_t add_aux_sym_symint - PARAMS ((symint_t)); - -STATIC symint_t add_aux_sym_rndx - PARAMS ((int, symint_t)); - -STATIC symint_t add_aux_sym_tir PARAMS ((type_info_t *, - hash_state_t, - thash_t **)); - -STATIC tag_t * get_tag PARAMS ((const char *, - const char *, - symint_t, - bt_t)); - -STATIC void add_unknown_tag PARAMS ((tag_t *)); - -STATIC void add_procedure PARAMS ((const char *, - const char *)); - -STATIC void add_file PARAMS ((const char *, - const char *)); - -STATIC void add_bytes PARAMS ((varray_t *, - char *, - Size_t)); - -STATIC void add_varray_page PARAMS ((varray_t *)); - -STATIC void update_headers PARAMS ((void)); - -STATIC void write_varray PARAMS ((varray_t *, off_t, const char *)); -STATIC void write_object PARAMS ((void)); -STATIC const char *st_to_string PARAMS ((st_t)); -STATIC const char *sc_to_string PARAMS ((sc_t)); -STATIC char *read_line PARAMS ((void)); -STATIC void parse_input PARAMS ((void)); -STATIC void mark_stabs PARAMS ((const char *)); -STATIC void parse_begin PARAMS ((const char *)); -STATIC void parse_bend PARAMS ((const char *)); -STATIC void parse_def PARAMS ((const char *)); -STATIC void parse_end PARAMS ((const char *)); -STATIC void parse_ent PARAMS ((const char *)); -STATIC void parse_file PARAMS ((const char *)); -STATIC void parse_stabs_common - PARAMS ((const char *, const char *, const char *)); -STATIC void parse_stabs PARAMS ((const char *)); -STATIC void parse_stabn PARAMS ((const char *)); -STATIC page_t *read_seek PARAMS ((Size_t, off_t, const char *)); -STATIC void copy_object PARAMS ((void)); - -STATIC void catch_signal PARAMS ((int)) ATTRIBUTE_NORETURN; -STATIC page_t *allocate_page PARAMS ((void)); - -STATIC page_t *allocate_multiple_pages - PARAMS ((Size_t)); - -STATIC void free_multiple_pages - PARAMS ((page_t *, Size_t)); +static int out_of_bounds (symint_t, symint_t, const char *, int); +static shash_t *hash_string (const char *, ptrdiff_t, shash_t **, symint_t *); +static symint_t add_string (varray_t *, shash_t **, const char *, const char *, + shash_t **); +static symint_t add_local_symbol (const char *, const char *, st_t, sc_t, + symint_t, symint_t); +static symint_t add_ext_symbol (EXTR *, int); +static symint_t add_aux_sym_symint (symint_t); +static symint_t add_aux_sym_rndx (int, symint_t); +static symint_t add_aux_sym_tir (type_info_t *, hash_state_t, thash_t **); +static tag_t * get_tag (const char *, const char *, symint_t, bt_t); +static void add_unknown_tag (tag_t *); +static void add_procedure (const char *, const char *); +static void initialize_init_file (void); +static void add_file (const char *, const char *); +static void add_bytes (varray_t *, char *, size_t); +static void add_varray_page (varray_t *); +static void update_headers (void); +static void write_varray (varray_t *, off_t, const char *); +static void write_object (void); +static const char *st_to_string (st_t); +static const char *sc_to_string (sc_t); +static char *read_line (void); +static void parse_input (void); +static void mark_stabs (const char *); +static void parse_begin (const char *); +static void parse_bend (const char *); +static void parse_def (const char *); +static void parse_end (const char *); +static void parse_ent (const char *); +static void parse_file (const char *); +static void parse_stabs_common (const char *, const char *, const char *); +static void parse_stabs (const char *); +static void parse_stabn (const char *); +static page_t *read_seek (size_t, off_t, const char *); +static void copy_object (void); + +static void catch_signal (int) ATTRIBUTE_NORETURN; +static page_t *allocate_page (void); +static page_t *allocate_multiple_pages (size_t); +static void free_multiple_pages (page_t *, size_t); #ifndef MALLOC_CHECK -STATIC page_t *allocate_cluster - PARAMS ((Size_t)); +static page_t *allocate_cluster (size_t); #endif -STATIC forward_t *allocate_forward PARAMS ((void)); -STATIC scope_t *allocate_scope PARAMS ((void)); -STATIC shash_t *allocate_shash PARAMS ((void)); -STATIC tag_t *allocate_tag PARAMS ((void)); -STATIC thash_t *allocate_thash PARAMS ((void)); -STATIC thead_t *allocate_thead PARAMS ((void)); -STATIC vlinks_t *allocate_vlinks PARAMS ((void)); +static forward_t *allocate_forward (void); +static scope_t *allocate_scope (void); +static shash_t *allocate_shash (void); +static tag_t *allocate_tag (void); +static thash_t *allocate_thash (void); +static thead_t *allocate_thead (void); +static vlinks_t *allocate_vlinks (void); -STATIC void free_forward PARAMS ((forward_t *)); -STATIC void free_scope PARAMS ((scope_t *)); -STATIC void free_tag PARAMS ((tag_t *)); -STATIC void free_thead PARAMS ((thead_t *)); +static void free_forward (forward_t *); +static void free_scope (scope_t *); +static void free_tag (tag_t *); +static void free_thead (thead_t *); extern char *optarg; extern int optind; @@ -1719,7 +1545,7 @@ extern int opterr; typedef struct _pseudo_ops { const char *const name; /* pseudo-op in ascii */ const int len; /* length of name to compare */ - void (*const func) PARAMS ((const char *)); /* function to handle line */ + void (*const func) (const char *); /* function to handle line */ } pseudo_ops_t; static const pseudo_ops_t pseudo_ops[] = { @@ -1737,17 +1563,25 @@ static const pseudo_ops_t pseudo_ops[] = { }; +/* Command line options for getopt_long. */ + +static const struct option options[] = +{ + { "version", 0, 0, 'V' }, + { "verbose", 0, 0, 'v' }, + { 0, 0, 0, 0 } +}; + /* Add a page to a varray object. */ -STATIC void -add_varray_page (vp) - varray_t *vp; /* varray to add page to */ +static void +add_varray_page (varray_t *vp) { vlinks_t *new_links = allocate_vlinks (); #ifdef MALLOC_CHECK if (vp->object_size > 1) - new_links->datum = (page_t *) xcalloc (1, vp->object_size); + new_links->datum = xcalloc (1, vp->object_size); else #endif new_links->datum = allocate_page (); @@ -1773,15 +1607,12 @@ add_varray_page (vp) #define HASHBITS 30 -STATIC shash_t * -hash_string (text, hash_len, hash_tbl, ret_hash_index) - const char *text; /* ptr to text to hash */ - Ptrdiff_t hash_len; /* length of the text */ - shash_t **hash_tbl; /* hash table */ - symint_t *ret_hash_index; /* ptr to store hash index */ +static shash_t * +hash_string (const char *text, ptrdiff_t hash_len, shash_t **hash_tbl, + symint_t *ret_hash_index) { unsigned long hi; - Ptrdiff_t i; + ptrdiff_t i; shash_t *ptr; int first_ch = *text; @@ -1806,22 +1637,21 @@ hash_string (text, hash_len, hash_tbl, ret_hash_index) /* Add a string (and null pad) to one of the string tables. A - consequence of hashing strings, is that we don't let strings - cross page boundaries. The extra nulls will be ignored. */ - -STATIC symint_t -add_string (vp, hash_tbl, start, end_p1, ret_hash) - varray_t *vp; /* string virtual array */ - shash_t **hash_tbl; /* ptr to hash table */ - const char *start; /* 1st byte in string */ - const char *end_p1; /* 1st byte after string */ - shash_t **ret_hash; /* return hash pointer */ + consequence of hashing strings, is that we don't let strings cross + page boundaries. The extra nulls will be ignored. VP is a string + virtual array, HASH_TBL a pointer to the hash table, the string + starts at START and the position one byte after the string is given + with END_P1, the resulting hash pointer is returned in RET_HASH. */ + +static symint_t +add_string (varray_t *vp, shash_t **hash_tbl, const char *start, + const char *end_p1, shash_t **ret_hash) { - Ptrdiff_t len = end_p1 - start; + ptrdiff_t len = end_p1 - start; shash_t *hash_ptr; symint_t hi; - if (len >= (Ptrdiff_t) PAGE_USIZE) + if (len >= (ptrdiff_t) PAGE_USIZE) fatal ("string too big (%ld bytes)", (long) len); hash_ptr = hash_string (start, len, hash_tbl, &hi); @@ -1860,16 +1690,14 @@ add_string (vp, hash_tbl, start, end_p1, ret_hash) } -/* Add a local symbol. */ - -STATIC symint_t -add_local_symbol (str_start, str_end_p1, type, storage, value, indx) - const char *str_start; /* first byte in string */ - const char *str_end_p1; /* first byte after string */ - st_t type; /* symbol type */ - sc_t storage; /* storage class */ - symint_t value; /* value of symbol */ - symint_t indx; /* index to local/aux. syms */ +/* Add a local symbol. The symbol string starts at STR_START and the + first byte after it is marked by STR_END_P1. The symbol has type + TYPE and storage class STORAGE and value VALUE. INDX is an index + to local/aux. symbols. */ + +static symint_t +add_local_symbol (const char *str_start, const char *str_end_p1, st_t type, + sc_t storage, symint_t value, symint_t indx) { symint_t ret; SYMR *psym; @@ -2029,7 +1857,7 @@ add_local_symbol (str_start, str_end_p1, type, storage, value, indx) st_str, (int) (str_end_p1 - str_start), str_start); else { - Size_t len = strlen (st_str); + size_t len = strlen (st_str); fprintf (stderr, " st= %.*s\n", (int) (len-1), st_str); } } @@ -2038,12 +1866,11 @@ add_local_symbol (str_start, str_end_p1, type, storage, value, indx) } -/* Add an external symbol. */ +/* Add an external symbol with symbol pointer ESYM and file index + IFD. */ -STATIC symint_t -add_ext_symbol (esym, ifd) - EXTR *esym; /* symbol pointer */ - int ifd; /* file index */ +static symint_t +add_ext_symbol (EXTR *esym, int ifd) { const char *str_start; /* first byte in string */ const char *str_end_p1; /* first byte after string */ @@ -2057,8 +1884,8 @@ add_ext_symbol (esym, ifd) if (debug > 1) { long value = esym->asym.value; - const char *sc_str = sc_to_string (esym->asym.sc); - const char *st_str = st_to_string (esym->asym.st); + const char *sc_str = sc_to_string ((sc_t) esym->asym.sc); + const char *st_str = st_to_string ((st_t) esym->asym.st); fprintf (stderr, "\tesym\tv= %10ld, ifd= %2d, sc= %-12s", @@ -2094,9 +1921,8 @@ add_ext_symbol (esym, ifd) /* Add an auxiliary symbol (passing a symint). */ -STATIC symint_t -add_aux_sym_symint (aux_word) - symint_t aux_word; /* auxiliary information word */ +static symint_t +add_aux_sym_symint (symint_t aux_word) { AUXU *aux_ptr; efdr_t *file_ptr = cur_file_ptr; @@ -2114,10 +1940,8 @@ add_aux_sym_symint (aux_word) /* Add an auxiliary symbol (passing a file/symbol index combo). */ -STATIC symint_t -add_aux_sym_rndx (file_index, sym_index) - int file_index; - symint_t sym_index; +static symint_t +add_aux_sym_rndx (int file_index, symint_t sym_index) { AUXU *aux_ptr; efdr_t *file_ptr = cur_file_ptr; @@ -2137,11 +1961,8 @@ add_aux_sym_rndx (file_index, sym_index) /* Add an auxiliary symbol (passing the basic type and possibly type qualifiers). */ -STATIC symint_t -add_aux_sym_tir (t, state, hash_tbl) - type_info_t *t; /* current type information */ - hash_state_t state; /* whether to hash type or not */ - thash_t **hash_tbl; /* pointer to hash table to use */ +static symint_t +add_aux_sym_tir (type_info_t *t, hash_state_t state, thash_t **hash_tbl) { AUXU *aux_ptr; efdr_t *file_ptr = cur_file_ptr; @@ -2225,7 +2046,7 @@ add_aux_sym_tir (t, state, hash_tbl) ret = vp->num_allocated++; /* Add bitfield length if it exists. - + NOTE: Mips documentation claims bitfield goes at the end of the AUX record, but the DECstation compiler emits it here. (This would only make a difference for enum bitfields.) @@ -2299,12 +2120,12 @@ add_aux_sym_tir (t, state, hash_tbl) /* Add a tag to the tag table (unless it already exists). */ -STATIC tag_t * -get_tag (tag_start, tag_end_p1, indx, basic_type) - const char *tag_start; /* 1st byte of tag name */ - const char *tag_end_p1; /* 1st byte after tag name */ - symint_t indx; /* index of tag start block */ - bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */ +static tag_t * +get_tag (const char *tag_start, /* 1st byte of tag name */ + const char *tag_end_p1, /* 1st byte after tag name */ + symint_t indx, /* index of tag start block */ + bt_t basic_type) /* bt_Struct, bt_Union, or bt_Enum */ + { shash_t *hash_ptr; tag_t *tag_ptr; @@ -2351,9 +2172,8 @@ get_tag (tag_start, tag_end_p1, indx, basic_type) /* Add an unknown {struct, union, enum} tag. */ -STATIC void -add_unknown_tag (ptag) - tag_t *ptag; /* pointer to tag information */ +static void +add_unknown_tag (tag_t *ptag) { shash_t *hash_ptr = ptag->hash_ptr; char *name_start = hash_ptr->string; @@ -2411,10 +2231,9 @@ add_unknown_tag (ptag) this is the current procedure. If the assembler created a PDR for this procedure, use that to initialize the current PDR. */ -STATIC void -add_procedure (func_start, func_end_p1) - const char *func_start; /* 1st byte of func name */ - const char *func_end_p1; /* 1st byte after func name */ +static void +add_procedure (const char *func_start, /* 1st byte of func name */ + const char *func_end_p1) /* 1st byte after func name */ { PDR *new_proc_ptr; efdr_t *file_ptr = cur_file_ptr; @@ -2473,18 +2292,53 @@ add_procedure (func_start, func_end_p1) } +/* Initialize the init_file structure. */ + +static void +initialize_init_file (void) +{ + union { + unsigned char c[4]; + int i; + } endian_test; + + memset (&init_file, 0, sizeof (init_file)); + + init_file.fdr.lang = langC; + init_file.fdr.fMerge = 1; + init_file.fdr.glevel = GLEVEL_2; + + /* mips-tfile doesn't attempt to perform byte swapping and always writes + out integers in its native ordering. For cross-compilers, this need + not be the same as either the host or the target. The simplest thing + to do is skip the configury and perform an introspective test. */ + /* ??? Despite the name, mips-tfile is currently only used on alpha/Tru64 + and would/may require significant work to be used in cross-compiler + configurations, so we could simply admit defeat and hard code this as + little-endian, i.e. init_file.fdr.fBigendian = 0. */ + endian_test.i = 1; + if (endian_test.c[3]) + init_file.fdr.fBigendian = 1; + + INITIALIZE_VARRAY (&init_file.strings, char); + INITIALIZE_VARRAY (&init_file.symbols, SYMR); + INITIALIZE_VARRAY (&init_file.procs, PDR); + INITIALIZE_VARRAY (&init_file.aux_syms, AUXU); + + init_file_initialized = 1; +} + /* Add a new filename, and set up all of the file relative virtual arrays (strings, symbols, aux syms, etc.). Record where the current file structure lives. */ -STATIC void -add_file (file_start, file_end_p1) - const char *file_start; /* first byte in string */ - const char *file_end_p1; /* first byte after string */ +static void +add_file (const char *file_start, /* first byte in string */ + const char *file_end_p1) /* first byte after string */ { static char zero_bytes[2] = { '\0', '\0' }; - Ptrdiff_t len = file_end_p1 - file_start; + ptrdiff_t len = file_end_p1 - file_start; int first_ch = *file_start; efdr_t *file_ptr; @@ -2511,6 +2365,9 @@ add_file (file_start, file_end_p1) if (file_desc.objects_last_page == file_desc.objects_per_page) add_varray_page (&file_desc); + if (! init_file_initialized) + initialize_init_file (); + file_ptr = cur_file_ptr = &file_desc.last->datum->file[ file_desc.objects_last_page++ ]; *file_ptr = init_file; @@ -2557,14 +2414,13 @@ add_file (file_start, file_end_p1) /* Add a stream of random bytes to a varray. */ -STATIC void -add_bytes (vp, input_ptr, nitems) - varray_t *vp; /* virtual array to add too */ - char *input_ptr; /* start of the bytes */ - Size_t nitems; /* # items to move */ +static void +add_bytes (varray_t *vp, /* virtual array to add too */ + char *input_ptr, /* start of the bytes */ + size_t nitems) /* # items to move */ { - Size_t move_items; - Size_t move_bytes; + size_t move_items; + size_t move_bytes; char *ptr; while (nitems > 0) @@ -2596,9 +2452,8 @@ add_bytes (vp, input_ptr, nitems) /* Convert storage class to string. */ -STATIC const char * -sc_to_string (storage_class) - sc_t storage_class; +static const char * +sc_to_string (sc_t storage_class) { switch (storage_class) { @@ -2634,9 +2489,8 @@ sc_to_string (storage_class) /* Convert symbol type to string. */ -STATIC const char * -st_to_string (symbol_type) - st_t symbol_type; +static const char * +st_to_string (st_t symbol_type) { switch (symbol_type) { @@ -2671,8 +2525,8 @@ st_to_string (symbol_type) (which is grows if the line is too big). We split lines at the semi-colon, and return each logical line independently. */ -STATIC char * -read_line () +static char * +read_line (void) { static int line_split_p = 0; int string_p = 0; @@ -2747,9 +2601,8 @@ read_line () /* Parse #.begin directives which have a label as the first argument which gives the location of the start of the block. */ -STATIC void -parse_begin (start) - const char *start; /* start of directive */ +static void +parse_begin (const char *start) { const char *end_p1; /* end of label */ int ch; @@ -2799,9 +2652,8 @@ parse_begin (start) /* Parse #.bend directives which have a label as the first argument which gives the location of the end of the block. */ -STATIC void -parse_bend (start) - const char *start; /* start of directive */ +static void +parse_bend (const char *start) { const char *end_p1; /* end of label */ int ch; @@ -2858,9 +2710,8 @@ parse_bend (start) .dim specify an array dimension .tag specify a tag for a struct, union, or enum. */ -STATIC void -parse_def (name_start) - const char *name_start; /* start of directive */ +static void +parse_def (const char *name_start) { const char *dir_start; /* start of current directive*/ const char *dir_end_p1; /* end+1 of current directive*/ @@ -2881,7 +2732,7 @@ parse_def (name_start) symint_t temp_array[ N_TQ ]; int arg_was_number; int ch, i; - Ptrdiff_t len; + ptrdiff_t len; static int inside_enumeration = 0; /* is this an enumeration? */ @@ -2902,7 +2753,6 @@ parse_def (name_start) if (ch == '\0') { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -2916,7 +2766,6 @@ parse_def (name_start) if (ch != '.') { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -2925,7 +2774,7 @@ parse_def (name_start) && memcmp (dir_start, ".endef", sizeof (".endef")-1) == 0) break; - /* Pick up the subdirective now */ + /* Pick up the subdirective now. */ for (dir_end_p1 = dir_start+1; (ch = *dir_end_p1) != ' ' && ch != '\t'; dir_end_p1++) @@ -2933,7 +2782,6 @@ parse_def (name_start) if (ch == '\0' || ISSPACE (ch)) { error_line = __LINE__; - saber_stop (); goto bomb_out; } } @@ -2950,14 +2798,14 @@ parse_def (name_start) { int ch2; arg_number = strtol (arg_start, (char **) &arg_end_p1, 0); - if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',') + /* It's only a number if followed by ';' or ','. */ + if (arg_end_p1 != arg_start && (((ch2 = *arg_end_p1) == ';') || ch2 == ',')) arg_was_number++; } else if (ch == '\0' || ISSPACE (ch)) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -2972,7 +2820,6 @@ parse_def (name_start) if (ch == '\0') { error_line = __LINE__; - saber_stop (); goto bomb_out; } } @@ -2983,7 +2830,6 @@ parse_def (name_start) { default: error_line = __LINE__; - saber_stop (); goto bomb_out; case 'd': @@ -3006,13 +2852,12 @@ parse_def (name_start) { int ch2; arg_number = strtol (arg_start, (char **) &arg_end_p1, 0); - if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',') + if (arg_end_p1 != arg_start && (((ch2 = *arg_end_p1) == ';') || ch2 == ',')) arg_was_number++; if (t_ptr == &temp_array[0]) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3026,7 +2871,6 @@ parse_def (name_start) if (t.num_dims >= N_TQ-1) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3037,7 +2881,6 @@ parse_def (name_start) else { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3080,13 +2923,12 @@ parse_def (name_start) { int ch2; arg_number = strtol (arg_start, (char **) &arg_end_p1, 0); - if (arg_end_p1 != arg_start || (ch2 = *arg_end_p1 != ';') || ch2 != ',') + if (arg_end_p1 != arg_start && (((ch2 = *arg_end_p1) == ';') || ch2 == ',')) arg_was_number++; if (t_ptr == &temp_array[0]) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3100,7 +2942,6 @@ parse_def (name_start) if (t.num_sizes >= N_TQ-1) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3112,7 +2953,6 @@ parse_def (name_start) else { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3161,7 +3001,6 @@ parse_def (name_start) else { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3179,7 +3018,7 @@ parse_def (name_start) class, symbol type, etc. */ else { - shash_t *orig_hash_ptr; /* hash within orig sym table*/ + shash_t *orig_hash_ptr; /* hash within orig sym table*/ shash_t *ext_hash_ptr; /* hash within ext. sym table*/ ext_hash_ptr = hash_string (arg_start, @@ -3222,7 +3061,6 @@ parse_def (name_start) else { error_line = __LINE__; - saber_stop (); goto bomb_out; } } @@ -3250,7 +3088,6 @@ parse_def (name_start) if (num_real_sizes != 1 || diff < 0) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3339,7 +3176,6 @@ parse_def (name_start) if (t.num_sizes - t.num_dims - t.extra_sizes != 1) { error_line = __LINE__; - saber_stop (); goto bomb_out; } @@ -3386,7 +3222,7 @@ parse_def (name_start) value, indx); - /* deal with struct, union, and enum tags. */ + /* Deal with struct, union, and enum tags. */ if (symbol_type == st_Block) { /* Create or update the tag information. */ @@ -3433,9 +3269,8 @@ bomb_out: /* Parse .end directives. */ -STATIC void -parse_end (start) - const char *start; /* start of directive */ +static void +parse_end (const char *start) { const char *start_func, *end_func_p1; int ch; @@ -3496,9 +3331,8 @@ parse_end (start) /* Parse .ent directives. */ -STATIC void -parse_ent (start) - const char *start; /* start of directive */ +static void +parse_ent (const char *start) { const char *start_func, *end_func_p1; int ch; @@ -3534,9 +3368,8 @@ parse_ent (start) /* Parse .file directives. */ -STATIC void -parse_file (start) - const char *start; /* start of directive */ +static void +parse_file (const char *start) { char *p; char *start_name, *end_name_p1; @@ -3563,8 +3396,7 @@ parse_file (start) /* Make sure the @stabs symbol is emitted. */ static void -mark_stabs (start) - const char *start ATTRIBUTE_UNUSED; /* Start of directive (ignored) */ +mark_stabs (const char *start ATTRIBUTE_UNUSED) { if (!stabs_seen) { @@ -3572,7 +3404,8 @@ mark_stabs (start) stabs_seen = 1; (void) add_local_symbol (stabs_symbol, stabs_symbol + sizeof (stabs_symbol), - stNil, scInfo, -1, MIPS_MARK_STAB (0)); + (st_t) stNil, (sc_t) scInfo, -1, + MIPS_MARK_STAB (0)); } } @@ -3607,11 +3440,10 @@ mark_stabs (start) 0 a zero or a line number value a numeric value or an address. */ -STATIC void -parse_stabs_common (string_start, string_end, rest) - const char *string_start; /* start of string or NULL */ - const char *string_end; /* end+1 of string or NULL */ - const char *rest; /* rest of the directive. */ +static void +parse_stabs_common (const char *string_start, /* start of string or NULL */ + const char *string_end, /* end+1 of string or NULL */ + const char *rest) /* rest of the directive. */ { efdr_t *save_file_ptr = cur_file_ptr; symint_t code; @@ -3766,8 +3598,8 @@ parse_stabs_common (string_start, string_end, rest) /* Traditionally, N_LBRAC and N_RBRAC are *not* relocated. */ if (code == (int) N_LBRAC || code == (int) N_RBRAC) { - sc = scNil; - st = stNil; + sc = (sc_t) scNil; + st = (st_t) stNil; } else { @@ -3806,9 +3638,8 @@ parse_stabs_common (string_start, string_end, rest) } -STATIC void -parse_stabs (start) - const char *start; /* start of directive */ +static void +parse_stabs (const char *start) { const char *end = strchr (start+1, '"'); @@ -3822,9 +3653,8 @@ parse_stabs (start) } -STATIC void -parse_stabn (start) - const char *start; /* start of directive */ +static void +parse_stabn (const char *start) { parse_stabs_common ((const char *) 0, (const char *) 0, start); } @@ -3833,11 +3663,11 @@ parse_stabn (start) /* Parse the input file, and write the lines to the output file if needed. */ -STATIC void -parse_input () +static void +parse_input (void) { char *p; - Size_t i; + size_t i; thead_t *ptag_head; tag_t *ptag; tag_t *ptag_next; @@ -3854,7 +3684,7 @@ parse_input () while ((p = read_line ()) != (char *) 0) { - /* Skip leading blanks */ + /* Skip leading blanks. */ while (ISSPACE ((unsigned char)*p)) p++; @@ -3896,8 +3726,8 @@ parse_input () /* Update the global headers with the final offsets in preparation to write out the .T file. */ -STATIC void -update_headers () +static void +update_headers (void) { symint_t i; efdr_t *file_ptr; @@ -3944,16 +3774,16 @@ update_headers () if ((st_t) sym->st == st_Static) { char *str = ORIG_LSTRS (fd_ptr->issBase + sym->iss); - Size_t len = strlen (str); + size_t len = strlen (str); shash_t *hash_ptr; /* Ignore internal labels. */ if (str[0] == '$' && str[1] == 'L') continue; hash_ptr = hash_string (str, - (Ptrdiff_t) len, + (ptrdiff_t) len, &file_ptr->shash_head[0], - (symint_t *) 0); + (symint_t *) 0); if (hash_ptr == (shash_t *) 0) { (void) add_local_symbol (str, str + len, @@ -3985,9 +3815,8 @@ update_headers () symbolic_header.issMax += file_ptr->fdr.cbSs; } -#ifndef ALIGN_SYMTABLE_OFFSET -#define ALIGN_SYMTABLE_OFFSET(OFFSET) (OFFSET) -#endif +/* Align ecoff symbol tables to avoid OSF1/1.3 nm complaints. */ +#define ALIGN_SYMTABLE_OFFSET(OFFSET) (((OFFSET) + 7) & ~7) file_offset = ALIGN_SYMTABLE_OFFSET (file_offset); i = WORD_ALIGN (symbolic_header.cbLine); /* line numbers */ @@ -4082,11 +3911,10 @@ update_headers () /* Write out a varray at a given location. */ -STATIC void -write_varray (vp, offset, str) - varray_t *vp; /* virtual array */ - off_t offset; /* offset to write varray to */ - const char *str; /* string to print out when tracing */ +static void +write_varray (varray_t *vp, /* virtual array */ + off_t offset, /* offset to write varray to */ + const char *str) /* string to print out when tracing */ { int num_write, sys_write; vlinks_t *ptr; @@ -4095,14 +3923,12 @@ write_varray (vp, offset, str) return; if (debug) - { - fputs ("\twarray\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) vp); - fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n", - (unsigned long) offset, vp->num_allocated * vp->object_size, str); - } - - if (file_offset != offset + fprintf (stderr, "\twarray\tvp = " HOST_PTR_PRINTF + ", offset = %7lu, size = %7lu, %s\n", + (void *) vp, (unsigned long) offset, + vp->num_allocated * vp->object_size, str); + + if (file_offset != (unsigned long) offset && fseek (object_stream, (long) offset, SEEK_SET) < 0) pfatal_with_name (object_name); @@ -4112,7 +3938,7 @@ write_varray (vp, offset, str) ? vp->objects_last_page * vp->object_size : vp->objects_per_page * vp->object_size; - sys_write = fwrite ((PTR) ptr->datum, 1, num_write, object_stream); + sys_write = fwrite (ptr->datum, 1, num_write, object_stream); if (sys_write <= 0) pfatal_with_name (object_name); @@ -4129,22 +3955,20 @@ write_varray (vp, offset, str) /* Write out the symbol table in the object file. */ -STATIC void -write_object () +static void +write_object (void) { int sys_write; efdr_t *file_ptr; off_t offset; if (debug) - { - fputs ("\n\twrite\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) &symbolic_header); - fprintf (stderr, ", offset = %7u, size = %7lu, %s\n", - 0, (unsigned long) sizeof (symbolic_header), "symbolic header"); - } + fprintf (stderr, "\n\twrite\tvp = " HOST_PTR_PRINTF + ", offset = %7u, size = %7lu, %s\n", + (void *) &symbolic_header, 0, + (unsigned long) sizeof (symbolic_header), "symbolic header"); - sys_write = fwrite ((PTR) &symbolic_header, + sys_write = fwrite (&symbolic_header, 1, sizeof (symbolic_header), object_stream); @@ -4165,20 +3989,17 @@ write_object () { long sys_write; - if (file_offset != symbolic_header.cbLineOffset + if (file_offset != (unsigned long) symbolic_header.cbLineOffset && fseek (object_stream, symbolic_header.cbLineOffset, SEEK_SET) != 0) pfatal_with_name (object_name); if (debug) - { - fputs ("\twrite\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) &orig_linenum); - fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n", - (long) symbolic_header.cbLineOffset, - (long) symbolic_header.cbLine, "Line numbers"); - } + fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF + ", offset = %7lu, size = %7lu, %s\n", + (void *) &orig_linenum, (long) symbolic_header.cbLineOffset, + (long) symbolic_header.cbLine, "Line numbers"); - sys_write = fwrite ((PTR) orig_linenum, + sys_write = fwrite (orig_linenum, 1, symbolic_header.cbLine, object_stream); @@ -4200,20 +4021,17 @@ write_object () long sys_write; long num_write = symbolic_header.ioptMax * sizeof (OPTR); - if (file_offset != symbolic_header.cbOptOffset + if (file_offset != (unsigned long) symbolic_header.cbOptOffset && fseek (object_stream, symbolic_header.cbOptOffset, SEEK_SET) != 0) pfatal_with_name (object_name); if (debug) - { - fputs ("\twrite\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) &orig_opt_syms); - fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n", - (long) symbolic_header.cbOptOffset, - num_write, "Optimizer symbols"); - } + fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF + ", offset = %7lu, size = %7lu, %s\n", + (void *) &orig_opt_syms, (long) symbolic_header.cbOptOffset, + num_write, "Optimizer symbols"); - sys_write = fwrite ((PTR) orig_opt_syms, + sys_write = fwrite (orig_opt_syms, 1, num_write, object_stream); @@ -4287,7 +4105,7 @@ write_object () if (symbolic_header.ifdMax > 0) /* file tables */ { offset = symbolic_header.cbFdOffset; - if (file_offset != offset + if (file_offset != (unsigned long) offset && fseek (object_stream, (long) offset, SEEK_SET) < 0) pfatal_with_name (object_name); @@ -4297,13 +4115,10 @@ write_object () file_ptr = file_ptr->next_file) { if (debug) - { - fputs ("\twrite\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) &file_ptr->fdr); - fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n", - file_offset, (unsigned long) sizeof (FDR), - "File header"); - } + fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF + ", offset = %7lu, size = %7lu, %s\n", + (void *) &file_ptr->fdr, file_offset, + (unsigned long) sizeof (FDR), "File header"); sys_write = fwrite (&file_ptr->fdr, 1, @@ -4328,18 +4143,15 @@ write_object () long sys_write; symint_t num_write = symbolic_header.crfd * sizeof (symint_t); - if (file_offset != symbolic_header.cbRfdOffset + if (file_offset != (unsigned long) symbolic_header.cbRfdOffset && fseek (object_stream, symbolic_header.cbRfdOffset, SEEK_SET) != 0) pfatal_with_name (object_name); if (debug) - { - fputs ("\twrite\tvp = ", stderr); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) &orig_rfds); - fprintf (stderr, ", offset = %7lu, size = %7lu, %s\n", - (long) symbolic_header.cbRfdOffset, - num_write, "Relative file descriptors"); - } + fprintf (stderr, "\twrite\tvp = " HOST_PTR_PRINTF + ", offset = %7lu, size = %7lu, %s\n", + (void *) &orig_rfds, (long) symbolic_header.cbRfdOffset, + num_write, "Relative file descriptors"); sys_write = fwrite (orig_rfds, 1, @@ -4368,11 +4180,10 @@ write_object () /* Read some bytes at a specified location, and return a pointer. */ -STATIC page_t * -read_seek (size, offset, str) - Size_t size; /* # bytes to read */ - off_t offset; /* offset to read at */ - const char *str; /* name for tracing */ +static page_t * +read_seek (size_t size, /* # bytes to read */ + off_t offset, /* offset to read at */ + const char *str) /* name for tracing */ { page_t *ptr; long sys_read = 0; @@ -4388,12 +4199,12 @@ read_seek (size, offset, str) #ifndef MALLOC_CHECK ptr = allocate_multiple_pages ((size + PAGE_USIZE - 1) / PAGE_USIZE); #else - ptr = (page_t *) xcalloc (1, size); + ptr = xcalloc (1, size); #endif /* If we need to seek, and the distance is nearby, just do some reads, to speed things up. */ - if (file_offset != offset) + if (file_offset != (unsigned long) offset) { symint_t difference = offset - file_offset; @@ -4415,7 +4226,7 @@ read_seek (size, offset, str) pfatal_with_name (obj_in_name); } - sys_read = fread ((PTR) ptr, 1, size, obj_in_stream); + sys_read = fread (ptr, 1, size, obj_in_stream); if (sys_read <= 0) pfatal_with_name (obj_in_name); @@ -4438,8 +4249,8 @@ read_seek (size, offset, str) if it is different from the input object file), and remove the old symbol table. */ -STATIC void -copy_object () +static void +copy_object (void) { char buffer[ PAGE_SIZE ]; int sys_read; @@ -4458,7 +4269,7 @@ copy_object () || fseek (obj_in_stream, 0L, SEEK_SET) != 0) pfatal_with_name (obj_in_name); - sys_read = fread ((PTR) &orig_file_header, + sys_read = fread (&orig_file_header, 1, sizeof (struct filehdr), obj_in_stream); @@ -4485,7 +4296,7 @@ copy_object () if (fseek (obj_in_stream, (long) orig_file_header.f_symptr, SEEK_SET) != 0) pfatal_with_name (input_name); - sys_read = fread ((PTR) &orig_sym_hdr, + sys_read = fread (&orig_sym_hdr, 1, sizeof (orig_sym_hdr), obj_in_stream); @@ -4501,7 +4312,7 @@ copy_object () /* Read in each of the sections if they exist in the object file. - We read things in in the order the mips assembler creates the + We read things in the order the mips assembler creates the sections, so in theory no extra seeks are done. For simplicity sake, round each read up to a page boundary, @@ -4510,68 +4321,68 @@ copy_object () file_offset = orig_file_header.f_symptr + sizeof (struct filehdr); if (orig_sym_hdr.cbLine > 0) /* line numbers */ - orig_linenum = (char *) read_seek ((Size_t) orig_sym_hdr.cbLine, + orig_linenum = (char *) read_seek (orig_sym_hdr.cbLine, orig_sym_hdr.cbLineOffset, "Line numbers"); if (orig_sym_hdr.ipdMax > 0) /* procedure tables */ - orig_procs = (PDR *) read_seek ((Size_t) orig_sym_hdr.ipdMax * sizeof (PDR), + orig_procs = (PDR *) read_seek (orig_sym_hdr.ipdMax * sizeof (PDR), orig_sym_hdr.cbPdOffset, "Procedure tables"); if (orig_sym_hdr.isymMax > 0) /* local symbols */ - orig_local_syms = (SYMR *) read_seek ((Size_t) orig_sym_hdr.isymMax * sizeof (SYMR), + orig_local_syms = (SYMR *) read_seek (orig_sym_hdr.isymMax * sizeof (SYMR), orig_sym_hdr.cbSymOffset, "Local symbols"); if (orig_sym_hdr.iauxMax > 0) /* aux symbols */ - orig_aux_syms = (AUXU *) read_seek ((Size_t) orig_sym_hdr.iauxMax * sizeof (AUXU), + orig_aux_syms = (AUXU *) read_seek (orig_sym_hdr.iauxMax * sizeof (AUXU), orig_sym_hdr.cbAuxOffset, "Aux. symbols"); if (orig_sym_hdr.issMax > 0) /* local strings */ - orig_local_strs = (char *) read_seek ((Size_t) orig_sym_hdr.issMax, + orig_local_strs = (char *) read_seek (orig_sym_hdr.issMax, orig_sym_hdr.cbSsOffset, "Local strings"); if (orig_sym_hdr.issExtMax > 0) /* external strings */ - orig_ext_strs = (char *) read_seek ((Size_t) orig_sym_hdr.issExtMax, + orig_ext_strs = (char *) read_seek (orig_sym_hdr.issExtMax, orig_sym_hdr.cbSsExtOffset, "External strings"); if (orig_sym_hdr.ifdMax > 0) /* file tables */ - orig_files = (FDR *) read_seek ((Size_t) orig_sym_hdr.ifdMax * sizeof (FDR), + orig_files = (FDR *) read_seek (orig_sym_hdr.ifdMax * sizeof (FDR), orig_sym_hdr.cbFdOffset, "File tables"); if (orig_sym_hdr.crfd > 0) /* relative file descriptors */ - orig_rfds = (symint_t *) read_seek ((Size_t) orig_sym_hdr.crfd * sizeof (symint_t), + orig_rfds = (symint_t *) read_seek (orig_sym_hdr.crfd * sizeof (symint_t), orig_sym_hdr.cbRfdOffset, "Relative file descriptors"); if (orig_sym_hdr.issExtMax > 0) /* external symbols */ - orig_ext_syms = (EXTR *) read_seek ((Size_t) orig_sym_hdr.iextMax * sizeof (EXTR), + orig_ext_syms = (EXTR *) read_seek (orig_sym_hdr.iextMax * sizeof (EXTR), orig_sym_hdr.cbExtOffset, "External symbols"); if (orig_sym_hdr.idnMax > 0) /* dense numbers */ { - orig_dense = (DNR *) read_seek ((Size_t) orig_sym_hdr.idnMax * sizeof (DNR), + orig_dense = (DNR *) read_seek (orig_sym_hdr.idnMax * sizeof (DNR), orig_sym_hdr.cbDnOffset, "Dense numbers"); - add_bytes (&dense_num, (char *) orig_dense, (Size_t) orig_sym_hdr.idnMax); + add_bytes (&dense_num, (char *) orig_dense, orig_sym_hdr.idnMax); } if (orig_sym_hdr.ioptMax > 0) /* opt symbols */ - orig_opt_syms = (OPTR *) read_seek ((Size_t) orig_sym_hdr.ioptMax * sizeof (OPTR), + orig_opt_syms = (OPTR *) read_seek (orig_sym_hdr.ioptMax * sizeof (OPTR), orig_sym_hdr.cbOptOffset, "Optimizer symbols"); - /* Abort if the symbol table is not last. */ - if (max_file_offset != stat_buf.st_size) + /* The symbol table should be last. */ + if (max_file_offset != (unsigned long) stat_buf.st_size) fatal ("symbol table is not last (symbol table ends at %ld, .o ends at %ld", max_file_offset, (long) stat_buf.st_size); @@ -4625,7 +4436,7 @@ copy_object () for (es = 0; es < orig_sym_hdr.iextMax; es++) { EXTR *eptr = orig_ext_syms + es; - unsigned ifd = eptr->ifd; + int ifd = eptr->ifd; (void) add_ext_symbol (eptr, ((long) ifd < orig_sym_hdr.ifdMax) ? remap_file_number[ ifd ] : ifd ); @@ -4686,9 +4497,9 @@ copy_object () { auto symint_t hash_index; char *str = ORIG_LSTRS (fd_ptr->issBase + sym->iss); - Size_t len = strlen (str); + size_t len = strlen (str); shash_t *shash_ptr = hash_string (str, - (Ptrdiff_t) len, + (ptrdiff_t) len, &orig_str_hash[0], &hash_index); @@ -4716,9 +4527,9 @@ copy_object () if (*str != '\0') { - Size_t len = strlen (str); + size_t len = strlen (str); shash_t *shash_ptr = hash_string (str, - (Ptrdiff_t) len, + (ptrdiff_t) len, &orig_str_hash[0], (symint_t *) 0); @@ -4746,9 +4557,9 @@ copy_object () { SYMR *proc_sym = ORIG_LSYMS (fd_ptr->isymBase + proc->isym); char *str = ORIG_LSTRS (fd_ptr->issBase + proc_sym->iss); - Size_t len = strlen (str); + size_t len = strlen (str); shash_t *shash_ptr = hash_string (str, - (Ptrdiff_t) len, + (ptrdiff_t) len, &orig_str_hash[0], (symint_t *) 0); @@ -4783,7 +4594,7 @@ copy_object () num_write = (remaining <= (int) sizeof (buffer)) ? remaining : (int) sizeof (buffer); - sys_read = fread ((PTR) buffer, 1, num_write, obj_in_stream); + sys_read = fread (buffer, 1, num_write, obj_in_stream); if (sys_read <= 0) pfatal_with_name (obj_in_name); @@ -4808,26 +4619,23 @@ copy_object () /* Ye olde main program. */ -extern int main PARAMS ((int, char **)); +extern int main (int, char **); int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { int iflag = 0; - char *p = strrchr (argv[0], '/'); char *num_end; int option; int i; - progname = (p != 0) ? p+1 : argv[0]; + progname = lbasename (argv[0]); (void) signal (SIGSEGV, catch_signal); (void) signal (SIGBUS, catch_signal); (void) signal (SIGABRT, catch_signal); -#if !defined(__SABER__) && !defined(lint) +#ifndef lint if (sizeof (efdr_t) > PAGE_USIZE) fatal ("efdr_t has a sizeof %d bytes, when it should be less than %d", (int) sizeof (efdr_t), @@ -4856,7 +4664,7 @@ main (argc, argv) void_type_info = type_info_init; void_type_info.basic_type = bt_Void; - while ((option = getopt (argc, argv, "d:i:I:o:v")) != EOF) + while ((option = getopt_long (argc, argv, "d:i:I:o:v", options, NULL)) != -1) switch (option) { default: @@ -4876,7 +4684,7 @@ main (argc, argv) else rename_output = 1; - /* fall through to 'i' case. */ + /* Fall through to 'i' case. */ case 'i': if (obj_in_name == (char *) 0) @@ -4896,10 +4704,24 @@ main (argc, argv) break; case 'v': + verbose++; + break; + + case 'V': version++; break; } + if (version) + { + printf (_("mips-tfile %s%s\n"), pkgversion_string, version_string); + fputs ("Copyright (C) 2012 Free Software Foundation, Inc.\n", stdout); + fputs (_("This is free software; see the source for copying conditions. There is NO\n\ +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), + stdout); + exit (0); + } + if (obj_in_name == (char *) 0 && optind <= argc - 2) obj_in_name = argv[--argc]; @@ -4915,7 +4737,13 @@ main (argc, argv) delete_input = 1; } - if (object_name == (char *) 0 || had_errors || optind != argc - 1) + if (optind != argc - 1) + had_errors++; + + if (verbose || had_errors) + fprintf (stderr, _("mips-tfile (GCC) %s\n"), version_string); + + if (object_name == (char *) 0 || had_errors) { fprintf (stderr, _("Calling Sequence:\n")); fprintf (stderr, _("\tmips-tfile [-d ] [-v] [-i ] -o (or)\n")); @@ -4930,16 +4758,6 @@ main (argc, argv) return 1; } - - if (version) - { - fprintf (stderr, _("mips-tfile version %s"), version_string); -#ifdef TARGET_VERSION - TARGET_VERSION; -#endif - fputc ('\n', stderr); - } - if (obj_in_name == (char *) 0) obj_in_name = object_name; @@ -5029,9 +4847,8 @@ main (argc, argv) /* Catch a signal and exit without dumping core. */ -STATIC void -catch_signal (signum) - int signum; +static void +catch_signal (int signum) { (void) signal (signum, SIG_DFL); /* just in case... */ fatal ("%s", strsignal (signum)); @@ -5041,8 +4858,7 @@ catch_signal (signum) Also include a system error message based on `errno'. */ void -pfatal_with_name (msg) - const char *msg; +pfatal_with_name (const char *msg) { int save_errno = errno; /* just in case.... */ if (line_number > 0) @@ -5060,16 +4876,15 @@ pfatal_with_name (msg) } -/* Procedure to abort with an out of bounds error message. It has +/* Procedure to die with an out of bounds error message. It has type int, so it can be used with an ?: expression within the ORIG_xxx macros, but the function never returns. */ static int -out_of_bounds (indx, max, str, prog_line) - symint_t indx; /* index that is out of bounds */ - symint_t max; /* maximum index */ - const char *str; /* string to print out */ - int prog_line; /* line number within mips-tfile.c */ +out_of_bounds (symint_t indx, /* index that is out of bounds */ + symint_t max, /* maximum index */ + const char *str, /* string to print out */ + int prog_line) /* line number within mips-tfile.c */ { if (indx < max) /* just in case */ return 0; @@ -5089,11 +4904,10 @@ out_of_bounds (indx, max, str, prog_line) #ifndef MALLOC_CHECK #ifdef USE_MALLOC -STATIC page_t * -allocate_cluster (npages) - Size_t npages; +static page_t * +allocate_cluster (size_t npages) { - page_t *value = (page_t *) xcalloc (npages, PAGE_USIZE); + page_t *value = xcalloc (npages, PAGE_USIZE); if (debug > 3) fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value); @@ -5103,9 +4917,8 @@ allocate_cluster (npages) #else /* USE_MALLOC */ -STATIC page_t * -allocate_cluster (npages) - Size_t npages; +static page_t * +allocate_cluster (size_t npages) { page_t *ptr = (page_t *) sbrk (0); /* current sbreak */ unsigned long offset = ((unsigned long) ptr) & (PAGE_SIZE - 1); @@ -5122,12 +4935,8 @@ allocate_cluster (npages) pfatal_with_name ("allocate_cluster"); if (debug > 3) - { - fprintf (stderr, "\talloc\tnpages = %lu, value = ", - (unsigned long) npages); - fprintf (stderr, HOST_PTR_PRINTF, (PTR) ptr); - fputs ("\n", stderr); - } + fprintf (stderr, "\talloc\tnpages = %lu, value = " HOST_PTR_PRINTF "\n", + (unsigned long) npages, (void *) ptr); return ptr; } @@ -5143,9 +4952,8 @@ static unsigned pages_left = 0; /* Allocate some pages (which is initialized to 0). */ -STATIC page_t * -allocate_multiple_pages (npages) - Size_t npages; +static page_t * +allocate_multiple_pages (size_t npages) { #ifndef MALLOC_CHECK if (pages_left == 0 && npages < MAX_CLUSTER_PAGES) @@ -5165,7 +4973,7 @@ allocate_multiple_pages (npages) return allocate_cluster (npages); #else /* MALLOC_CHECK */ - return (page_t *) xcalloc (npages, PAGE_SIZE); + return xcalloc (npages, PAGE_SIZE); #endif /* MALLOC_CHECK */ } @@ -5173,10 +4981,8 @@ allocate_multiple_pages (npages) /* Release some pages. */ -STATIC void -free_multiple_pages (page_ptr, npages) - page_t *page_ptr; - Size_t npages; +static void +free_multiple_pages (page_t *page_ptr, size_t npages) { #ifndef MALLOC_CHECK if (pages_left == 0) @@ -5196,7 +5002,7 @@ free_multiple_pages (page_ptr, npages) the free pages is done right after an allocate. */ #else /* MALLOC_CHECK */ - free ((char *) page_ptr); + free (page_ptr); #endif /* MALLOC_CHECK */ } @@ -5204,8 +5010,8 @@ free_multiple_pages (page_ptr, npages) /* Allocate one page (which is initialized to 0). */ -STATIC page_t * -allocate_page () +static page_t * +allocate_page (void) { #ifndef MALLOC_CHECK if (pages_left == 0) @@ -5218,7 +5024,7 @@ allocate_page () return cluster_ptr++; #else /* MALLOC_CHECK */ - return (page_t *) xcalloc (1, PAGE_SIZE); + return xcalloc (1, PAGE_SIZE); #endif /* MALLOC_CHECK */ } @@ -5226,8 +5032,8 @@ allocate_page () /* Allocate scoping information. */ -STATIC scope_t * -allocate_scope () +static scope_t * +allocate_scope (void) { scope_t *ptr; static scope_t initial_scope; @@ -5254,7 +5060,7 @@ allocate_scope () } #else - ptr = (scope_t *) xmalloc (sizeof (scope_t)); + ptr = xmalloc (sizeof (scope_t)); #endif @@ -5265,9 +5071,8 @@ allocate_scope () /* Free scoping information. */ -STATIC void -free_scope (ptr) - scope_t *ptr; +static void +free_scope (scope_t *ptr) { alloc_counts[ (int) alloc_type_scope ].total_free++; @@ -5276,7 +5081,7 @@ free_scope (ptr) alloc_counts[ (int) alloc_type_scope ].free_list.f_scope = ptr; #else - free ((PTR) ptr); + free (ptr); #endif } @@ -5284,8 +5089,8 @@ free_scope (ptr) /* Allocate links for pages in a virtual array. */ -STATIC vlinks_t * -allocate_vlinks () +static vlinks_t * +allocate_vlinks (void) { vlinks_t *ptr; static vlinks_t initial_vlinks; @@ -5305,7 +5110,7 @@ allocate_vlinks () alloc_counts[ (int) alloc_type_vlinks ].unallocated = unallocated; #else - ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t)); + ptr = xmalloc (sizeof (vlinks_t)); #endif @@ -5317,8 +5122,8 @@ allocate_vlinks () /* Allocate string hash buckets. */ -STATIC shash_t * -allocate_shash () +static shash_t * +allocate_shash (void) { shash_t *ptr; static shash_t initial_shash; @@ -5338,7 +5143,7 @@ allocate_shash () alloc_counts[ (int) alloc_type_shash ].unallocated = unallocated; #else - ptr = (shash_t *) xmalloc (sizeof (shash_t)); + ptr = xmalloc (sizeof (shash_t)); #endif @@ -5350,8 +5155,8 @@ allocate_shash () /* Allocate type hash buckets. */ -STATIC thash_t * -allocate_thash () +static thash_t * +allocate_thash (void) { thash_t *ptr; static thash_t initial_thash; @@ -5371,7 +5176,7 @@ allocate_thash () alloc_counts[ (int) alloc_type_thash ].unallocated = unallocated; #else - ptr = (thash_t *) xmalloc (sizeof (thash_t)); + ptr = xmalloc (sizeof (thash_t)); #endif @@ -5383,8 +5188,8 @@ allocate_thash () /* Allocate structure, union, or enum tag information. */ -STATIC tag_t * -allocate_tag () +static tag_t * +allocate_tag (void) { tag_t *ptr; static tag_t initial_tag; @@ -5411,7 +5216,7 @@ allocate_tag () } #else - ptr = (tag_t *) xmalloc (sizeof (tag_t)); + ptr = xmalloc (sizeof (tag_t)); #endif @@ -5422,9 +5227,8 @@ allocate_tag () /* Free scoping information. */ -STATIC void -free_tag (ptr) - tag_t *ptr; +static void +free_tag (tag_t *ptr) { alloc_counts[ (int) alloc_type_tag ].total_free++; @@ -5433,7 +5237,7 @@ free_tag (ptr) alloc_counts[ (int) alloc_type_tag ].free_list.f_tag = ptr; #else - free ((PTR) ptr); + free (ptr); #endif } @@ -5441,8 +5245,8 @@ free_tag (ptr) /* Allocate forward reference to a yet unknown tag. */ -STATIC forward_t * -allocate_forward () +static forward_t * +allocate_forward (void) { forward_t *ptr; static forward_t initial_forward; @@ -5469,7 +5273,7 @@ allocate_forward () } #else - ptr = (forward_t *) xmalloc (sizeof (forward_t)); + ptr = xmalloc (sizeof (forward_t)); #endif @@ -5480,9 +5284,8 @@ allocate_forward () /* Free scoping information. */ -STATIC void -free_forward (ptr) - forward_t *ptr; +static void +free_forward (forward_t *ptr) { alloc_counts[ (int) alloc_type_forward ].total_free++; @@ -5491,7 +5294,7 @@ free_forward (ptr) alloc_counts[ (int) alloc_type_forward ].free_list.f_forward = ptr; #else - free ((PTR) ptr); + free (ptr); #endif } @@ -5499,8 +5302,8 @@ free_forward (ptr) /* Allocate head of type hash list. */ -STATIC thead_t * -allocate_thead () +static thead_t * +allocate_thead (void) { thead_t *ptr; static thead_t initial_thead; @@ -5527,7 +5330,7 @@ allocate_thead () } #else - ptr = (thead_t *) xmalloc (sizeof (thead_t)); + ptr = xmalloc (sizeof (thead_t)); #endif @@ -5538,9 +5341,8 @@ allocate_thead () /* Free scoping information. */ -STATIC void -free_thead (ptr) - thead_t *ptr; +static void +free_thead (thead_t *ptr) { alloc_counts[ (int) alloc_type_thead ].total_free++; @@ -5549,22 +5351,19 @@ free_thead (ptr) alloc_counts[ (int) alloc_type_thead ].free_list.f_thead = ptr; #else - free ((PTR) ptr); + free (ptr); #endif } - -#endif /* MIPS_DEBUGGING_INFO */ - -/* Output an error message and exit */ +/* Output an error message and exit. */ -/*VARARGS*/ void -fatal VPARAMS ((const char *format, ...)) +fatal (const char *format, ...) { - VA_OPEN (ap, format); - VA_FIXEDARG (ap, const char *, format); + va_list ap; + + va_start (ap, format); if (line_number > 0) fprintf (stderr, "%s, %s:%ld ", progname, input_name, line_number); @@ -5572,21 +5371,20 @@ fatal VPARAMS ((const char *format, ...)) fprintf (stderr, "%s:", progname); vfprintf (stderr, format, ap); - VA_CLOSE (ap); + va_end (ap); fprintf (stderr, "\n"); if (line_number > 0) fprintf (stderr, "line:\t%s\n", cur_line_start); - saber_stop (); exit (1); } -/*VARARGS*/ void -error VPARAMS ((const char *format, ...)) +error (const char *format, ...) { - VA_OPEN (ap, format); - VA_FIXEDARG (ap, char *, format); + va_list ap; + + va_start (ap, format); if (line_number > 0) fprintf (stderr, "%s, %s:%ld ", progname, input_name, line_number); @@ -5599,18 +5397,15 @@ error VPARAMS ((const char *format, ...)) fprintf (stderr, "line:\t%s\n", cur_line_start); had_errors++; - VA_CLOSE (ap); - - saber_stop (); + va_end (ap); } -/* More 'friendly' abort that prints the line and file. - config.h can #define abort fancy_abort if you like that sort of thing. */ +/* More 'friendly' abort that prints the line and file. */ void -fancy_abort () +fancy_abort (const char *file, int line, const char *func) { - fatal ("internal abort"); + fatal ("abort in %s, at %s:%d", func, file, line); } @@ -5618,8 +5413,7 @@ fancy_abort () it calls this function to report clobberage. */ void -botch (s) - const char *s; +botch (const char *s) { fatal ("%s", s); }