/* Update the symbol table (the .T file) in a MIPS 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).
Contributed by: Michael Meissner, meissner@osf.org
Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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)
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Here is a brief description of the MIPS ECOFF symbol table. The
MIPS symbol table has the following pieces:
+-- Relative file descriptors
The symbolic header points to each of the other tables, and also
contains the number of entries. It also contains a magic number
and MIPS compiler version number, such as 2.0.
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
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
types of aux. entries are:
1) dnLow: Low bound on array dimension.
2) dnHigh: High bound on array dimension.
3) isym: Index to the local symbol which is the start of the
function for the end of function first aux. entry.
4) width: Width of structures and bitfields.
5) count: Count of ranges for variant part.
6) rndx: A relative index into the symbol table. The relative
index field has two parts: rfd which is a pointer into the
relative file index table or ST_RFDESCAPE which says the next
aux. entry is the file number, and index: which is the pointer
into the local symbol within a given file table. This is for
things like references to types defined in another file.
7) Type information: This is like the COFF type bits, except it
is 32 bits instead of 16; they still have room to add new
basic types; and they can handle more than 6 levels of array,
pointer, function, etc. Each type information field contains
the following structure members:
a) fBitfield: a bit that says this is a bitfield, and the
size in bits follows as the next aux. entry.
b) continued: a bit that says the next aux. entry is a
continuation of the current type information (in case
there are more than 6 levels of array/ptr/function).
c) bt: an integer containing the base type before adding
array, pointer, function, etc. qualifiers. The
current base types that I have documentation for are:
btAdr -- address - integer same size as ptr
btUChar -- unsigned character
btUShort -- unsigned short
btDouble -- Double (real)
btStruct -- Structure (Record)
btUnion -- Union (variant)
btTypedef -- defined via a typedef isymRef
btRange -- subrange of int
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
btVoid -- Void (MIPS cc revision >= 2.00)
d) tq0 - tq5: type qualifier fields as needed. The
current type qualifier fields I have documentation for
tqNil -- no more qualifiers
tqFar -- 8086 far pointers
The dense number table is used in the front ends, and disappears by
the time the .o is created.
With the 1.31 compiler suite, the optimization symbols don't seem
to be used as far as I can tell.
The linker is the first entity that creates the relative file
descriptor table, and I believe it is used so that the individual
file table pointers don't have to be rewritten when the objects are
merged together into the program file.
Unlike COFF, the basic symbol & string tables are split into
external and local symbols/strings. The relocation information
only goes off of the external symbol table, and the debug
information only goes off of the internal symbol table. The
external symbols can have links to an appropriate file index and
symbol within the file to give it the appropriate type information.
Because of this, the external symbols are actually larger than the
internal symbols (to contain the link information), and contain the
local symbol structure as a member, though this member is not the
first member of the external symbol structure (!). I suspect this
split is to make strip easier to deal with.
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
The procedure table contains the binary equivalents of the .ent
(start of the function address), .frame (what register is the
virtual frame pointer, constant offset from the register to obtain
the VFP, and what register holds the return address), .mask/.fmask
(bitmask of saved registers, and where the first register is stored
relative to the VFP) assembler directives. It also contains the
low and high bounds of the line numbers if debugging is turned on.
The line number table is a compressed form of the normal COFF line
table. Each line number entry is either 1 or 3 bytes long, and
contains a signed delta from the previous line, and an unsigned
count of the number of instructions this statement takes.
The local symbol table contains the following fields:
1) iss: index to the local string table giving the name of the
2) value: value of the symbol (address, register number, etc.).
3) st: symbol type. The current symbol types are:
stGlobal -- external symbol
stParam -- procedure argument
stLocal -- local variable
stProc -- External Procedure
stBlock -- beginning of block
stEnd -- end (of anything)
stMember -- member (of anything)
stTypedef -- type definition
stRegReloc -- register relocation
stForward -- forwarding address
stStaticProc -- Static procedure
4) sc: storage class. The current storage classes are:
scData -- initialized data symbol
scBss -- un-initialized data symbol
scRegister -- value of symbol is register number
scAbs -- value of symbol is absolute
scUndefined -- who knows?
scCdbLocal -- variable's value is IN se->va.??
scBits -- this is a bit field
scCdbSystem -- value is IN debugger's address space
scRegImage -- register value saved on stack
scInfo -- symbol contains debugger information
scUserStruct -- addr in struct user for current process
scSData -- load time only small data
scSBss -- load time only small common
scRData -- load time only read only data
scVar -- Var parameter (fortranpascal)
scCommon -- common variable
scSCommon -- small common
scVarRegister -- Var parameter in a register
scVariant -- Variant record
scSUndefined -- small undefined(external) data
scInit -- .init section symbol
5) index: pointer to a local symbol or aux. entry.
For the following program:
printf("Hello World!\n");
Mips-tdump produces the following information:
timestamp 645311799, Wed Jun 13 17:16:39 1990
symbolic header offset 284
Symbolic header, magic number = 0x7009, vstamp = 1.31:
Line numbers 380 4 4 [13]
Procedures Tables 384 1 52
Optimization Symbols 0 0 0
Auxiliary Symbols 628 39 156
External Strings 864 144 144
External Symbols 1152 20 320
Name index = 1 Readin = No
Merge = No Endian = LITTLE
Debug level = G2 Language = C
Info Start Number Size Offset
==== ===== ====== ==== ======
Local strings 0 15 15 784
Optimization symbols 0 0 0 0
Auxiliary symbols 0 14 56 628
There are 6 local symbols, starting at 436
Storage class = Text Index = 6
Symbol type = File Value = 0
Storage class = Text Index = 12
Symbol type = Proc Value = 0
Storage class = Text Index = 4
Symbol type = Block Value = 8
Storage class = Text Index = 2
Symbol type = End Value = 28
Storage class = Text Index = 1
Symbol type = End Value = 52
Storage class = Text Index = 0
Symbol type = End Value = 0
There are 14 auxiliary table entries, starting at 628.
* #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
* #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0]
* #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0]
* #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
* #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0]
* #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0]
* #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0]
* #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0]
* #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0]
* #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0]
* #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0]
#12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0]
#13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
There are 1 procedure descriptor entries, starting at 0.
Name index = 10 Name = "main"
.mask 0x80000000,-4 .fmask 0x00000000,0
Opt. start = -1 Symbols start = 1
First line # = 3 Last line # = 6
Line Offset = 0 Address = 0x00000000
There are 4 bytes holding line numbers, starting at 380.
File #1, "/usr/include/stdio.h"
Name index = 1 Readin = No
Merge = Yes Endian = LITTLE
Debug level = G2 Language = C
Info Start Number Size Offset
==== ===== ====== ==== ======
Local strings 15 65 65 799
Local symbols 6 10 120 508
Optimization symbols 0 0 0 0
Auxiliary symbols 14 25 100 684
There are 10 local symbols, starting at 442
Symbol# 0: "/usr/include/stdio.h"
Storage class = Text Index = 10
Symbol type = File Value = 0
Storage class = Info Index = 9
Symbol type = Block Value = 20
Storage class = Info Index = 4
Symbol type = Member Value = 0
Storage class = Info Index = 15
Symbol type = Member Value = 32
Storage class = Info Index = 16
Symbol type = Member Value = 64
Storage class = Info Index = 4
Symbol type = Member Value = 96
Storage class = Info Index = 3
Symbol type = Member Value = 128
Storage class = Info Index = 2
Symbol type = Member Value = 144
Storage class = Info Index = 1
Symbol type = End Value = 0
Symbol# 9: "/usr/include/stdio.h"
Storage class = Text Index = 0
Symbol type = End Value = 0
There are 25 auxiliary table entries, starting at 642.
* #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
#15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
#16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
* #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0]
* #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1]
* #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
* #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4]
* #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
* #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0]
* #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0]
* #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
* #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
There are 0 procedure descriptor entries, starting at 1.
There are 20 external symbols, starting at 1152
Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
Storage class = Nil Index = 17
Symbol type = Global Value = 60
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 11 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 18 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 26 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 32 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 40 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 46 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 53 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 60 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 70 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 81 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 87 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 92 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 100 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 108 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 116 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 123 Ifd = 1
Storage class = Nil Index = 1048575
Symbol type = Proc Value = 0
String index = 131 Ifd = 0
Storage class = Text Index = 1
Symbol type = Proc Value = 0
String index = 136 Ifd = 0
Storage class = Undefined Index = 1048575
Symbol type = Proc Value = 0
The following auxiliary table entries were unused:
#8 12 0x0000000c unsigned char
#9 20 0x00000014 unsigned short
#10 28 0x0000001c unsigned int
#11 36 0x00000024 unsigned long
#22 12 0x0000000c unsigned char
#23 20 0x00000014 unsigned short
#24 28 0x0000001c unsigned int
#25 36 0x00000024 unsigned long
#26 48 0x00000030 struct no name { ifd = -1, index = 1048575 }
typedef const void *CPTR_T
;
#if defined(_STDIO_H_) || defined(__STDIO_H__) /* Ultrix 4.0, SGI */
typedef char *PTR_T
; /* Ultrix 3.1 */
/* Do 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. */
#if defined(__OSF1__) || defined(__OSF__) || defined(__osf__)
#define Size_t long unsigned int
#define Size_t unsigned int
/* The following might be called from obstack or malloc,
so they can't be static. */
extern void pfatal_with_name
extern void fancy_abort
__proto((void));
void botch
__proto((const char *));
extern PTR_T xmalloc
__proto((Size_t
));
extern PTR_T xcalloc
__proto((Size_t
, Size_t
));
extern PTR_T xrealloc
__proto((PTR_T
, Size_t
));
extern void xfree
__proto((PTR_T
));
extern void fatal(); /* can't use prototypes here */
#ifndef MIPS_DEBUGGING_INFO
static int cur_line_start
;
fprintf (stderr
, "Mips-tfile should only be run on a MIPS computer!\n");
#else /* MIPS_DEBUGGING defined */
/* The local and global symbols have a field index, so undo any defines
of index -> strchr and rindex -> strrchr. */
#define ST_RFDESCAPE 0xfff
#if defined (USG) || defined (NO_STAB_H)
#include "gstab.h" /* If doing DBX on sysV, use our own stab.h. */
#include <stab.h> /* On BSD, use the system's stab.h. */
#define STAB_CODE_TYPE enum __stab_debug_code
#define STAB_CODE_TYPE int
extern int errno
; /* MIPS errno.h doesn't declare this */
#define IS_ASM_IDENT(ch) \
(isalnum (ch) || (ch) == '_' || (ch) == '.' || (ch) == '$')
/* Redefinition of of storage classes as an enumeration for better
sc_Nil
= scNil
, /* no storage class */
sc_Text
= scText
, /* text symbol */
sc_Data
= scData
, /* initialized data symbol */
sc_Bss
= scBss
, /* un-initialized data symbol */
sc_Register
= scRegister
, /* value of symbol is register number */
sc_Abs
= scAbs
, /* value of symbol is absolute */
sc_Undefined
= scUndefined
, /* who knows? */
sc_CdbLocal
= scCdbLocal
, /* variable's value is IN se->va.?? */
sc_Bits
= scBits
, /* this is a bit field */
sc_CdbSystem
= scCdbSystem
, /* value is IN CDB's address space */
sc_RegImage
= scRegImage
, /* register value saved on stack */
sc_Info
= scInfo
, /* symbol contains debugger information */
sc_UserStruct
= scUserStruct
, /* addr in struct user for current process */
sc_SData
= scSData
, /* load time only small data */
sc_SBss
= scSBss
, /* load time only small common */
sc_RData
= scRData
, /* load time only read only data */
sc_Var
= scVar
, /* Var parameter (fortran,pascal) */
sc_Common
= scCommon
, /* common variable */
sc_SCommon
= scSCommon
, /* small common */
sc_VarRegister
= scVarRegister
, /* Var parameter in a register */
sc_Variant
= scVariant
, /* Variant record */
sc_SUndefined
= scSUndefined
, /* small undefined(external) data */
sc_Init
= scInit
, /* .init section symbol */
sc_Max
= scMax
/* Max storage class+1 */
/* Redefinition of symbol type. */
st_Nil
= stNil
, /* Nuthin' special */
st_Global
= stGlobal
, /* external symbol */
st_Static
= stStatic
, /* static */
st_Param
= stParam
, /* procedure argument */
st_Local
= stLocal
, /* local variable */
st_Label
= stLabel
, /* label */
st_Proc
= stProc
, /* " " Procedure */
st_Block
= stBlock
, /* beginning of block */
st_End
= stEnd
, /* end (of anything) */
st_Member
= stMember
, /* member (of anything - struct/union/enum */
st_Typedef
= stTypedef
, /* type definition */
st_File
= stFile
, /* file name */
st_RegReloc
= stRegReloc
, /* register relocation */
st_Forward
= stForward
, /* forwarding address */
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_Expr
= stExpr
, /* 2+2 vs. 4 */
st_Type
= stType
, /* post-coercion SER */
st_Max
= stMax
/* max type+1 */
/* Redefinition of type qualifiers. */
tq_Nil
= tqNil
, /* bt is what you see */
tq_Ptr
= tqPtr
, /* pointer */
tq_Proc
= tqProc
, /* procedure */
tq_Array
= tqArray
, /* duh */
tq_Far
= tqFar
, /* longer addressing - 8086/8 land */
tq_Vol
= tqVol
, /* volatile */
tq_Max
= tqMax
/* Max type qualifier+1 */
/* Redefinition of basic types. */
bt_Nil
= btNil
, /* undefined */
bt_Adr
= btAdr
, /* address - integer same size as pointer */
bt_Char
= btChar
, /* character */
bt_UChar
= btUChar
, /* unsigned character */
bt_Short
= btShort
, /* short */
bt_UShort
= btUShort
, /* unsigned short */
bt_Int
= btInt
, /* int */
bt_UInt
= btUInt
, /* unsigned int */
bt_Long
= btLong
, /* long */
bt_ULong
= btULong
, /* unsigned long */
bt_Float
= btFloat
, /* float (real) */
bt_Double
= btDouble
, /* Double (real) */
bt_Struct
= btStruct
, /* Structure (Record) */
bt_Union
= btUnion
, /* Union (variant) */
bt_Enum
= btEnum
, /* Enumerated */
bt_Typedef
= btTypedef
, /* defined via a typedef, isymRef points */
bt_Range
= btRange
, /* subrange of int */
bt_Set
= btSet
, /* pascal sets */
bt_Complex
= btComplex
, /* fortran complex */
bt_DComplex
= btDComplex
, /* fortran double complex */
bt_Indirect
= btIndirect
, /* forward or unnamed typedef */
bt_FixedDec
= btFixedDec
, /* Fixed Decimal */
bt_FloatDec
= btFloatDec
, /* Float Decimal */
bt_String
= btString
, /* Varying Length Character String */
bt_Bit
= btBit
, /* Aligned Bit String */
bt_Picture
= btPicture
, /* Picture */
bt_Void
= btVoid
, /* Void */
bt_Max
= btMax
/* Max basic type+1 */
/* Basic COFF storage classes. */
/* Regular COFF fundamental type. */
/* Regular COFF derived types. */
#define N_BTMASK 017 /* bitmask to isolate basic type */
#define N_TMASK 003 /* bitmask to isolate derived type */
#define N_BT_SHIFT 4 /* # bits to shift past basic type */
#define N_TQ_SHIFT 2 /* # bits to shift derived types */
#define N_TQ 6 /* # of type qualifiers */
/* States for whether to hash type or not. */
typedef enum hash_state
{
hash_no
= 0, /* don't hash type */
hash_yes
= 1, /* ok to hash type, or use previous hash */
hash_record
= 2 /* ok to record hash, but don't use prev. */
/* Types of different sized allocation requests. */
alloc_type_none
, /* dummy value */
alloc_type_scope
, /* nested scopes linked list */
alloc_type_vlinks
, /* glue linking pages in varray */
alloc_type_shash
, /* string hash element */
alloc_type_thash
, /* type hash element */
alloc_type_tag
, /* struct/union/tag element */
alloc_type_forward
, /* element to hold unknown tag */
alloc_type_thead
, /* head of type hash list */
alloc_type_varray
, /* general varray allocation */
alloc_type_last
/* last+1 element for array bounds */
#define WORD_ALIGN(x) (((x) + 3) & ~3)
#define DWORD_ALIGN(x) (((x) + 7) & ~7)
/* Structures to provide n-number of virtual arrays, each of which can
grow linearly, and which are written in the object file as sequential
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 it's 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). */
#define PAGE_SIZE 4096 /* size of varray pages */
#define PAGE_USIZE ((Size_t)PAGE_SIZE)
#ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
#ifndef USE_MALLOC /* in one memory request */
#define MAX_CLUSTER_PAGES 64
#define MAX_CLUSTER_PAGES 63
/* Linked list connecting separate page allocations. */
struct vlinks
*prev
; /* previous set of pages */
struct vlinks
*next
; /* next set of pages */
union page
*datum
; /* start of page */
unsigned long start_index
; /* starting index # of page */
/* Virtual array header. */
vlinks_t
*first
; /* first page link */
vlinks_t
*last
; /* last page link */
unsigned long num_allocated
; /* # objects allocated */
unsigned short object_size
; /* size in bytes of each object */
unsigned short objects_per_page
; /* # objects that can fit on a page */
unsigned short objects_last_page
; /* # objects allocated on last page */
#define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
#define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
#define INIT_VARRAY(type) { /* macro to initialize a varray */ \
(vlinks_t *)0, /* first */ \
(vlinks_t *)0, /* last */ \
sizeof (type), /* object_size */ \
OBJECTS_PER_PAGE (type), /* objects_per_page */ \
OBJECTS_PER_PAGE (type), /* objects_last_page */ \
/* Master type for indexes within the symbol table. */
typedef unsigned long symint_t
;
/* Linked list support for nested scopes (file, block, structure, etc.). */
struct scope
*prev
; /* previous scope level */
struct scope
*free
; /* free list pointer */
SYMR
*lsym
; /* pointer to local symbol node */
symint_t lnumber
; /* lsym index */
st_t type
; /* type of the node */
/* Forward reference list for tags referenced, but not yet defined. */
struct forward
*next
; /* next forward reference */
struct forward
*free
; /* free list pointer */
AUXU
*ifd_ptr
; /* pointer to store file index */
AUXU
*index_ptr
; /* pointer to store symbol index */
AUXU
*type_ptr
; /* pointer to munge type info */
/* Linked list support for tags. The first tag in the list is always
the current tag for that block. */
struct tag
*free
; /* free list pointer */
struct shash
*hash_ptr
; /* pointer to the hash table head */
struct tag
*same_name
; /* tag with same name in outer scope */
struct tag
*same_block
; /* next tag defined in the same block. */
struct forward
*forward_ref
; /* list of forward references */
bt_t basic_type
; /* bt_Struct, bt_Union, or bt_Enum */
symint_t ifd
; /* file # tag defined in */
symint_t indx
; /* index within file's local symbols */
/* Head of a block's linked list of tags. */
struct thead
*prev
; /* previous block */
struct thead
*free
; /* free list pointer */
struct tag
*first_tag
; /* first tag in block defined */
/* Union containing pointers to each the small structures which are freed up. */
typedef union small_free
{
scope_t
*f_scope
; /* scope structure */
thead_t
*f_thead
; /* tag head structure */
tag_t
*f_tag
; /* tag element structure */
forward_t
*f_forward
; /* forward tag reference */
/* String hash table support. The size of the hash table must fit
#define HASH_LEN_MAX ((1 << 12) - 1) /* Max length we can store */
struct shash
*next
; /* next hash value */
char *string
; /* string we are hashing */
symint_t len
; /* string length */
symint_t indx
; /* index within string table */
EXTR
*esym_ptr
; /* global symbol pointer */
SYMR
*sym_ptr
; /* local symbol pointer */
SYMR
*end_ptr
; /* symbol pointer to end block */
tag_t
*tag_ptr
; /* tag pointer */
PDR
*proc_ptr
; /* procedure descriptor pointer */
/* Type hash table support. The size of the hash table must fit
within a page with the other extended file descriptor information.
Because unique types which are hashed are fewer in number than
strings, we use a smaller hash value. */
struct thash
*next
; /* next hash value */
AUXU type
; /* type we are hashing */
symint_t indx
; /* index within string table */
/* Extended file descriptor that contains all of the support necessary
to add things to each file separately. */
FDR fdr
; /* File header to be written out */
FDR
*orig_fdr
; /* original file header */
char *name
; /* filename */
int name_len
; /* length of the filename */
symint_t void_type
; /* aux. pointer to 'void' type */
symint_t int_type
; /* aux. pointer to 'int' type */
scope_t
*cur_scope
; /* current nested scopes */
symint_t file_index
; /* current file number */
int nested_scopes
; /* # nested scopes */
varray_t strings
; /* local strings */
varray_t symbols
; /* local symbols */
varray_t procs
; /* procedures */
varray_t aux_syms
; /* auxiliary symbols */
struct efdr
*next_file
; /* next file descriptor */
/* string/type hash tables */
shash_t
**shash_head
; /* string hash table */
thash_t
*thash_head
[THASH_SIZE
];
/* Pre-initialized extended file structure. */
static efdr_t init_file
=
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) */
1, /* fBigendian: if 1, compiled on big endian machine */
0, /* fBigendian: if 1, compiled on big endian machine */
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 */
(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 efdr_t
*first_file
; /* first file descriptor */
static efdr_t
**last_file_ptr
= &first_file
; /* file descriptor tail */
/* Union of various things that are held in pages. */
unsigned char ubyte
[ PAGE_SIZE
];
efdr_t file
[ PAGE_SIZE
/ sizeof (efdr_t
) ];
FDR ofile
[ PAGE_SIZE
/ sizeof (FDR
) ];
PDR proc
[ PAGE_SIZE
/ sizeof (PDR
) ];
SYMR sym
[ PAGE_SIZE
/ sizeof (SYMR
) ];
EXTR esym
[ PAGE_SIZE
/ sizeof (EXTR
) ];
AUXU aux
[ PAGE_SIZE
/ sizeof (AUXU
) ];
DNR dense
[ PAGE_SIZE
/ sizeof (DNR
) ];
scope_t scope
[ PAGE_SIZE
/ sizeof (scope_t
) ];
vlinks_t vlinks
[ PAGE_SIZE
/ sizeof (vlinks_t
) ];
shash_t shash
[ PAGE_SIZE
/ sizeof (shash_t
) ];
thash_t thash
[ PAGE_SIZE
/ sizeof (thash_t
) ];
tag_t tag
[ PAGE_SIZE
/ sizeof (tag_t
) ];
forward_t forward
[ PAGE_SIZE
/ sizeof (forward_t
) ];
thead_t thead
[ PAGE_SIZE
/ sizeof (thead_t
) ];
/* Structure holding allocation information for small sized structures. */
typedef struct alloc_info
{
char *alloc_name
; /* name of this allocation type (must be first) */
page_t
*cur_page
; /* current page being allocated from */
small_free_t free_list
; /* current free list if any */
int unallocated
; /* number of elements unallocated on page */
int total_alloc
; /* total number of allocations */
int total_free
; /* total number of frees */
int total_pages
; /* total number of pages allocated */
/* Type information collected together. */
typedef struct type_info
{
bt_t basic_type
; /* basic type */
coff_type_t orig_type
; /* original COFF-based type */
int num_tq
; /* # type qualifiers */
int num_dims
; /* # dimensions */
int num_sizes
; /* # sizes */
int extra_sizes
; /* # extra sizes not tied with dims */
tag_t
* tag_ptr
; /* tag pointer */
int bitfield
; /* symbol is a bitfield */
int unknown_tag
; /* this is an unknown tag */
tq_t type_qualifiers
[N_TQ
]; /* type qualifiers (ptr, func, array)*/
symint_t dimensions
[N_TQ
]; /* dimensions for each array */
symint_t sizes
[N_TQ
+2]; /* sizes of each array slice + size of
struct/union/enum + bitfield size */
/* Pre-initialized type_info struct. */
static type_info_t type_info_init
= {
T_NULL
, /* original COFF-based type */
0, /* # type qualifiers */
0, /* sizes not tied with dims */
/* Global virtual arrays & hash table for external strings as well as
for the tags table and global tables for file descriptors, and
static varray_t file_desc
= INIT_VARRAY (efdr_t
);
static varray_t dense_num
= INIT_VARRAY (DNR
);
static varray_t tag_strings
= INIT_VARRAY (char);
static varray_t ext_strings
= INIT_VARRAY (char);
static varray_t ext_symbols
= INIT_VARRAY (EXTR
);
static shash_t
*orig_str_hash
[SHASH_SIZE
];
static shash_t
*ext_str_hash
[SHASH_SIZE
];
static shash_t
*tag_hash
[SHASH_SIZE
];
/* Static types for int and void. Also, remember the last function's
type (which is set up when we encounter the declaration for the
function, and used when the end block for the function is emitted. */
static type_info_t int_type_info
;
static type_info_t void_type_info
;
static type_info_t last_func_type_info
;
static EXTR
*last_func_eptr
;
/* Convert COFF basic type to ECOFF basic type. The T_NULL type
really should use bt_Void, but this causes the current ecoff GDB to
issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
2.0) doesn't understand it, even though the compiler generates it.
Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
suite, but for now go with what works. */
static bt_t map_coff_types
[ (int)T_MAX
] = {
bt_Double
, /* T_DOUBLE */
bt_Struct
, /* T_STRUCT */
bt_UShort
, /* T_USHORT */
/* Convert COFF storage class to ECOFF storage class. */
static sc_t map_coff_storage
[ (int)C_MAX
] = {
sc_Abs
, /* 1: C_AUTO auto var */
sc_Undefined
, /* 2: C_EXT external */
sc_Data
, /* 3: C_STAT static */
sc_Register
, /* 4: C_REG register */
sc_Undefined
, /* 5: C_EXTDEF ??? */
sc_Text
, /* 6: C_LABEL label */
sc_Text
, /* 7: C_ULABEL user label */
sc_Info
, /* 8: C_MOS member of struct */
sc_Abs
, /* 9: C_ARG argument */
sc_Info
, /* 10: C_STRTAG struct tag */
sc_Info
, /* 11: C_MOU member of union */
sc_Info
, /* 12: C_UNTAG union tag */
sc_Info
, /* 13: C_TPDEF typedef */
sc_Data
, /* 14: C_USTATIC ??? */
sc_Info
, /* 15: C_ENTAG enum tag */
sc_Info
, /* 16: C_MOE member of enum */
sc_Register
, /* 17: C_REGPARM register parameter */
sc_Bits
, /* 18; C_FIELD bitfield */
sc_Text
, /* 100: C_BLOCK block start/end */
sc_Text
, /* 101: C_FCN function start/end */
sc_Info
, /* 102: C_EOS end of struct/union/enum */
sc_Nil
, /* 103: C_FILE file start */
sc_Nil
, /* 104: C_LINE line number */
sc_Nil
, /* 105: C_ALIAS combined type info */
sc_Nil
, /* 106: C_HIDDEN ??? */
/* Convert COFF storage class to ECOFF symbol type. */
static st_t map_coff_sym_type
[ (int)C_MAX
] = {
st_Local
, /* 1: C_AUTO auto var */
st_Global
, /* 2: C_EXT external */
st_Static
, /* 3: C_STAT static */
st_Local
, /* 4: C_REG register */
st_Global
, /* 5: C_EXTDEF ??? */
st_Label
, /* 6: C_LABEL label */
st_Label
, /* 7: C_ULABEL user label */
st_Member
, /* 8: C_MOS member of struct */
st_Param
, /* 9: C_ARG argument */
st_Block
, /* 10: C_STRTAG struct tag */
st_Member
, /* 11: C_MOU member of union */
st_Block
, /* 12: C_UNTAG union tag */
st_Typedef
, /* 13: C_TPDEF typedef */
st_Static
, /* 14: C_USTATIC ??? */
st_Block
, /* 15: C_ENTAG enum tag */
st_Member
, /* 16: C_MOE member of enum */
st_Param
, /* 17: C_REGPARM register parameter */
st_Member
, /* 18; C_FIELD bitfield */
st_Block
, /* 100: C_BLOCK block start/end */
st_Proc
, /* 101: C_FCN function start/end */
st_End
, /* 102: C_EOS end of struct/union/enum */
st_File
, /* 103: C_FILE file start */
st_Nil
, /* 104: C_LINE line number */
st_Nil
, /* 105: C_ALIAS combined type info */
st_Nil
, /* 106: C_HIDDEN ??? */
/* Map COFF derived types to ECOFF type qualifiers. */
static tq_t map_coff_derived_type
[ (int)DT_MAX
] = {
tq_Nil
, /* 0: DT_NON no more qualifiers */
tq_Ptr
, /* 1: DT_PTR pointer */
tq_Proc
, /* 2: DT_FCN function */
tq_Array
, /* 3: DT_ARY array */
/* Keep track of different sized allocation requests. */
static alloc_info_t alloc_counts
[ (int)alloc_type_last
];
/* Pointers and such to the original symbol table that is read in. */
static struct filehdr orig_file_header
; /* global object file header */
static HDRR orig_sym_hdr
; /* symbolic header on input */
static char *orig_linenum
; /* line numbers */
static DNR
*orig_dense
; /* dense numbers */
static PDR
*orig_procs
; /* procedures */
static SYMR
*orig_local_syms
; /* local symbols */
static OPTR
*orig_opt_syms
; /* optimization symbols */
static AUXU
*orig_aux_syms
; /* auxiliary symbols */
static char *orig_local_strs
; /* local strings */
static char *orig_ext_strs
; /* external strings */
static FDR
*orig_files
; /* file descriptors */
static symint_t
*orig_rfds
; /* relative file desc's */
static EXTR
*orig_ext_syms
; /* external symbols */
/* Macros to convert an index into a given object within the original
#define CHECK(num,max,str) \
(((unsigned long)num > (unsigned long)max) ? out_of_bounds (num, max, str, __LINE__) : 0)
#define ORIG_LINENUM(indx) (CHECK ((indx), orig_sym_hdr.cbLine, "line#"), (indx) + orig_linenum)
#define ORIG_DENSE(indx) (CHECK ((indx), orig_sym_hdr.idnMax, "dense"), (indx) + orig_dense)
#define ORIG_PROCS(indx) (CHECK ((indx), orig_sym_hdr.ipdMax, "procs"), (indx) + orig_procs)
#define ORIG_FILES(indx) (CHECK ((indx), orig_sym_hdr.ifdMax, "funcs"), (indx) + orig_files)
#define ORIG_LSYMS(indx) (CHECK ((indx), orig_sym_hdr.isymMax, "lsyms"), (indx) + orig_local_syms)
#define ORIG_LSTRS(indx) (CHECK ((indx), orig_sym_hdr.issMax, "lstrs"), (indx) + orig_local_strs)
#define ORIG_ESYMS(indx) (CHECK ((indx), orig_sym_hdr.iextMax, "esyms"), (indx) + orig_ext_syms)
#define ORIG_ESTRS(indx) (CHECK ((indx), orig_sym_hdr.issExtMax, "estrs"), (indx) + orig_ext_strs)
#define ORIG_OPT(indx) (CHECK ((indx), orig_sym_hdr.ioptMax, "opt"), (indx) + orig_opt_syms)
#define ORIG_AUX(indx) (CHECK ((indx), orig_sym_hdr.iauxMax, "aux"), (indx) + orig_aux_syms)
#define ORIG_RFDS(indx) (CHECK ((indx), orig_sym_hdr.crfd, "rfds"), (indx) + orig_rfds)
/* Various other statics. */
static HDRR symbolic_header
; /* symbolic header */
static efdr_t
*cur_file_ptr
= (efdr_t
*) 0; /* current file desc. header */
static PDR
*cur_proc_ptr
= (PDR
*) 0; /* current procedure header */
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 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 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 */
static char *cur_line_start
= (char *)0; /* current line read in */
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 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 */
static int stabs_seen
= 0; /* != 0 if stabs have been seen */
/* Pseudo symbol to use when putting stabs into the symbol table. */
#define STABS_SYMBOL "@stabs"
static char stabs_symbol
[] = STABS_SYMBOL
;
/* Forward reference for functions. See the definition for more details. */
STATIC
int out_of_bounds
__proto((symint_t
, symint_t
, const char *, int));
STATIC shash_t
*hash_string
__proto((const char *,
STATIC symint_t add_string
__proto((varray_t
*,
STATIC symint_t add_local_symbol
STATIC symint_t add_ext_symbol
__proto((const char *,
STATIC symint_t add_aux_sym_symint
STATIC symint_t add_aux_sym_rndx
__proto((int, symint_t
));
STATIC symint_t add_aux_sym_tir
__proto((type_info_t
*,
STATIC tag_t
* get_tag
__proto((const char *,
STATIC
void add_unknown_tag
__proto((tag_t
*));
STATIC
void add_procedure
__proto((const char *,
STATIC
void add_file
__proto((const char *,
STATIC
void add_bytes
__proto((varray_t
*,
STATIC
void add_varray_page
__proto((varray_t
*));
STATIC
void update_headers
__proto((void));
STATIC
void write_varray
__proto((varray_t
*, off_t
, const char *));
STATIC
void write_object
__proto((void));
STATIC
char *st_to_string
__proto((st_t
));
STATIC
char *sc_to_string
__proto((sc_t
));
STATIC
char *read_line
__proto((void));
STATIC
void parse_input
__proto((void));
STATIC
void mark_stabs
__proto((const char *));
STATIC
void parse_begin
__proto((const char *));
STATIC
void parse_bend
__proto((const char *));
STATIC
void parse_def
__proto((const char *));
STATIC
void parse_end
__proto((const char *));
STATIC
void parse_ent
__proto((const char *));
STATIC
void parse_file
__proto((const char *));
STATIC
void parse_stabs_common
__proto((const char *, const char *, const char *));
STATIC
void parse_stabs
__proto((const char *));
STATIC
void parse_stabn
__proto((const char *));
STATIC page_t
*read_seek
__proto((Size_t
, off_t
, const char *));
STATIC
void copy_object
__proto((void));
STATIC
void catch_signal
__proto((int));
STATIC page_t
*allocate_page
__proto((void));
STATIC page_t
*allocate_multiple_pages
STATIC
void free_multiple_pages
__proto((page_t
*, Size_t
));
STATIC page_t
*allocate_cluster
STATIC forward_t
*allocate_forward
__proto((void));
STATIC scope_t
*allocate_scope
__proto((void));
STATIC shash_t
*allocate_shash
__proto((void));
STATIC tag_t
*allocate_tag
__proto((void));
STATIC thash_t
*allocate_thash
__proto((void));
STATIC thead_t
*allocate_thead
__proto((void));
STATIC vlinks_t
*allocate_vlinks
__proto((void));
STATIC
void free_forward
__proto((forward_t
*));
STATIC
void free_scope
__proto((scope_t
*));
STATIC
void free_tag
__proto((tag_t
*));
STATIC
void free_thead
__proto((thead_t
*));
STATIC
char *local_index
__proto((const char *, int));
STATIC
char *local_rindex
__proto((const char *, int));
extern char *sbrk
__proto((int));
extern PTR_T malloc
__proto((Size_t
));
extern PTR_T calloc
__proto((Size_t
, Size_t
));
extern PTR_T realloc
__proto((PTR_T
, Size_t
));
extern void free
__proto((PTR_T
));
extern char *mktemp
__proto((char *));
extern long strtol
__proto((const char *, char **, int));
extern char *version_string
;
extern char *sys_siglist
[NSIG
+ 1];
#ifndef SEEK_SET /* Symbolic constants for the "fseek" function: */
#define SEEK_SET 0 /* Set file pointer to offset */
#define SEEK_CUR 1 /* Set file pointer to its current value plus offset */
#define SEEK_END 2 /* Set file pointer to the size of the file plus offset */
/* List of assembler pseudo ops and beginning sequences that need
special actions. Someday, this should be a hash table, and such,
but for now a linear list of names and calls to memcmp will
typedef struct _pseudo_ops
{
const char *name
; /* pseudo-op in ascii */
int len
; /* length of name to compare */
void (*func
) __proto((const char *)); /* function to handle line */
static pseudo_ops_t pseudo_ops
[] = {
{ "#.def", sizeof("#.def")-1, parse_def
},
{ "#.begin", sizeof("#.begin")-1, parse_begin
},
{ "#.bend", sizeof("#.bend")-1, parse_bend
},
{ ".end", sizeof(".end")-1, parse_end
},
{ ".ent", sizeof(".ent")-1, parse_ent
},
{ ".file", sizeof(".file")-1, parse_file
},
{ "#.stabs", sizeof("#.stabs")-1, parse_stabs
},
{ "#.stabn", sizeof("#.stabn")-1, parse_stabn
},
{ ".stabs", sizeof(".stabs")-1, parse_stabs
},
{ ".stabn", sizeof(".stabn")-1, parse_stabn
},
{ "#@stabs", sizeof("#@stabs")-1, mark_stabs
},
/* Add a page to a varray object. */
varray_t
*vp
; /* varray to add page to */
vlinks_t
*new_links
= allocate_vlinks ();
new_links
->datum
= (page_t
*) xcalloc (1, vp
->object_size
);
new_links
->datum
= allocate_page ();
alloc_counts
[ (int)alloc_type_varray
].total_alloc
++;
alloc_counts
[ (int)alloc_type_varray
].total_pages
++;
new_links
->start_index
= vp
->num_allocated
;
vp
->objects_last_page
= 0;
if (vp
->first
== (vlinks_t
*)0) /* first allocation? */
vp
->first
= vp
->last
= new_links
;
{ /* 2nd or greater allocation */
new_links
->prev
= vp
->last
;
vp
->last
->next
= new_links
;
/* Compute hash code (from tree.c) */
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 */
register unsigned long hi
;
register int first_ch
= *text
;
for (i
= 0; i
< hash_len
; i
++)
hi
= ((hi
& 0x003fffff) * 613) + (text
[i
] & 0xff);
hi
&= (1 << HASHBITS
) - 1;
if (ret_hash_index
!= (symint_t
*)0)
for (ptr
= hash_tbl
[hi
]; ptr
!= (shash_t
*)0; ptr
= ptr
->next
)
&& first_ch
== ptr
->string
[0]
&& memcmp ((CPTR_T
) text
, (CPTR_T
) ptr
->string
, hash_len
) == 0)
/* 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. */
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 */
register Ptrdiff_t len
= end_p1
- start
;
register shash_t
*hash_ptr
;
fatal ("String too big (%ld bytes)", (long) len
);
hash_ptr
= hash_string (start
, len
, hash_tbl
, &hi
);
if (hash_ptr
== (shash_t
*)0)
if (vp
->objects_last_page
+ len
>= PAGE_USIZE
)
((vp
->num_allocated
+ PAGE_USIZE
- 1) / PAGE_USIZE
) * PAGE_USIZE
;
hash_ptr
= allocate_shash ();
hash_ptr
->next
= hash_tbl
[hi
];
hash_ptr
->indx
= vp
->num_allocated
;
hash_ptr
->string
= p
= & vp
->last
->datum
->byte
[ vp
->objects_last_page
];
vp
->objects_last_page
+= len
+1;
vp
->num_allocated
+= len
+1;
if (ret_hash
!= (shash_t
**)0)
/* Add a local symbol. */
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 */
register scope_t
*pscope
;
register thead_t
*ptag_head
;
register tag_t
*ptag_next
;
register varray_t
*vp
= &cur_file_ptr
->symbols
;
register int scope_delta
= 0;
shash_t
*hash_ptr
= (shash_t
*)0;
if (vp
->objects_last_page
== vp
->objects_per_page
)
psym
= &vp
->last
->datum
->sym
[ vp
->objects_last_page
++ ];
psym
->st
= (unsigned) type
;
psym
->sc
= (unsigned) storage
;
psym
->iss
= (str_start
== (const char *)0)
: add_string (&cur_file_ptr
->strings
,
&cur_file_ptr
->shash_head
[0],
ret
= vp
->num_allocated
++;
/* Save the symbol within the hash table if this is a static
item, and it has a name. */
if (hash_ptr
!= (shash_t
*)0
&& (type
== st_Global
|| type
== st_Static
|| type
== st_Label
|| type
== st_Proc
|| type
== st_StaticProc
))
hash_ptr
->sym_ptr
= psym
;
/* push or pop a scope if appropriate. */
case st_File
: /* beginning of file */
case st_Proc
: /* procedure */
case st_StaticProc
: /* static procedure */
case st_Block
: /* begin scope */
pscope
= allocate_scope ();
pscope
->prev
= cur_file_ptr
->cur_scope
;
cur_file_ptr
->cur_scope
= pscope
;
/* For every block type except file, struct, union, or
enumeration blocks, push a level on the tag stack. We omit
file types, so that tags can span file boundaries. */
if (type
!= st_File
&& storage
!= sc_Info
)
ptag_head
= allocate_thead ();
ptag_head
->first_tag
= 0;
ptag_head
->prev
= cur_tag_head
;
cur_tag_head
= ptag_head
;
pscope
= cur_file_ptr
->cur_scope
;
if (pscope
== (scope_t
*)0)
error ("internal error, too many st_End's");
st_t begin_type
= (st_t
) pscope
->lsym
->st
;
if (begin_type
!= st_File
)
/* Except for file, structure, union, or enumeration end
blocks remove all tags created within this scope. */
if (begin_type
!= st_File
&& storage
!= sc_Info
)
ptag_head
= cur_tag_head
;
cur_tag_head
= ptag_head
->prev
;
for (ptag
= ptag_head
->first_tag
;
if (ptag
->forward_ref
!= (forward_t
*)0)
ptag_next
= ptag
->same_block
;
ptag
->hash_ptr
->tag_ptr
= ptag
->same_name
;
cur_file_ptr
->cur_scope
= pscope
->prev
;
psym
->index
= pscope
->lnumber
; /* blk end gets begin sym # */
psym
->iss
= pscope
->lsym
->iss
; /* blk end gets same name */
if (begin_type
== st_File
|| begin_type
== st_Block
)
pscope
->lsym
->index
= ret
+1; /* block begin gets next sym # */
/* Functions push two or more aux words as follows:
1st word: index+1 of the end symbol
2nd word: type of the function (plus any aux words needed).
Also, tie the external pointer back to the function begin symbol. */
pscope
->lsym
->index
= add_aux_sym_symint (ret
+1);
type
= add_aux_sym_tir (&last_func_type_info
,
&cur_file_ptr
->thash_head
[0]);
last_func_eptr
->ifd
= cur_file_ptr
->file_index
;
last_func_eptr
->asym
.index
= type
;
cur_file_ptr
->nested_scopes
+= scope_delta
;
if (debug
&& type
!= st_File
&& (debug
> 2 || type
== st_Block
|| type
== st_End
|| type
== st_Proc
|| type
== st_StaticProc
))
char *sc_str
= sc_to_string (storage
);
char *st_str
= st_to_string (type
);
int depth
= cur_file_ptr
->nested_scopes
+ (scope_delta
< 0);
"\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
if (str_start
&& str_end_p1
- str_start
> 0)
fprintf (stderr
, " st= %-11s name= %.*s\n", st_str
, str_end_p1
- str_start
, str_start
);
Size_t len
= strlen (st_str
);
fprintf (stderr
, " st= %.*s\n", len
-1, st_str
);
/* Add an external symbol. */
add_ext_symbol (str_start
, str_end_p1
, type
, storage
, value
, indx
, ifd
)
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 */
long value
; /* value of symbol */
symint_t indx
; /* index to local/aux. syms */
int ifd
; /* file index */
register varray_t
*vp
= &ext_symbols
;
shash_t
*hash_ptr
= (shash_t
*)0;
char *sc_str
= sc_to_string (storage
);
char *st_str
= st_to_string (type
);
"\tesym\tv= %10ld, ifd= %2d, sc= %-12s",
if (str_start
&& str_end_p1
- str_start
> 0)
fprintf (stderr
, " st= %-11s name= %.*s\n", st_str
, str_end_p1
- str_start
, str_start
);
fprintf (stderr
, " st= %s\n", st_str
);
if (vp
->objects_last_page
== vp
->objects_per_page
)
psym
= &vp
->last
->datum
->esym
[ vp
->objects_last_page
++ ];
psym
->asym
.value
= value
;
psym
->asym
.st
= (unsigned) type
;
psym
->asym
.sc
= (unsigned) storage
;
psym
->asym
.iss
= (str_start
== (const char *)0)
: add_string (&ext_strings
,
hash_ptr
->esym_ptr
= psym
;
return vp
->num_allocated
++;
/* Add an auxiliary symbol (passing a symint). */
add_aux_sym_symint (aux_word
)
symint_t aux_word
; /* auxiliary information word */
register efdr_t
*file_ptr
= cur_file_ptr
;
register varray_t
*vp
= &file_ptr
->aux_syms
;
if (vp
->objects_last_page
== vp
->objects_per_page
)
aux_ptr
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
++ ];
aux_ptr
->isym
= aux_word
;
return vp
->num_allocated
++;
/* Add an auxiliary symbol (passing a file/symbol index combo). */
add_aux_sym_rndx (file_index
, sym_index
)
register efdr_t
*file_ptr
= cur_file_ptr
;
register varray_t
*vp
= &file_ptr
->aux_syms
;
if (vp
->objects_last_page
== vp
->objects_per_page
)
aux_ptr
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
++ ];
aux_ptr
->rndx
.rfd
= file_index
;
aux_ptr
->rndx
.index
= sym_index
;
return vp
->num_allocated
++;
/* Add an auxiliary symbol (passing the basic type and possibly
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 */
register efdr_t
*file_ptr
= cur_file_ptr
;
register varray_t
*vp
= &file_ptr
->aux_syms
;
aux
.ti
.bt
= (int) t
->basic_type
;
aux
.ti
.fBitfield
= t
->bitfield
;
aux
.ti
.tq0
= (int) t
->type_qualifiers
[0];
aux
.ti
.tq1
= (int) t
->type_qualifiers
[1];
aux
.ti
.tq2
= (int) t
->type_qualifiers
[2];
aux
.ti
.tq3
= (int) t
->type_qualifiers
[3];
aux
.ti
.tq4
= (int) t
->type_qualifiers
[4];
aux
.ti
.tq5
= (int) t
->type_qualifiers
[5];
/* For anything that adds additional information, we must not hash,
so check here, and reset our state. */
&& (t
->type_qualifiers
[0] == tq_Array
|| t
->type_qualifiers
[1] == tq_Array
|| t
->type_qualifiers
[2] == tq_Array
|| t
->type_qualifiers
[3] == tq_Array
|| t
->type_qualifiers
[4] == tq_Array
|| t
->type_qualifiers
[5] == tq_Array
|| t
->basic_type
== bt_Struct
|| t
->basic_type
== bt_Union
|| t
->basic_type
== bt_Enum
/* See if we can hash this type, and save some space, but some types
can't be hashed (because they contain arrays or continuations),
and others can be put into the hash list, but cannot use existing
types because other aux entries precede this one. */
register thash_t
*hash_ptr
;
hi
= aux
.isym
& ((1 << HASHBITS
) - 1);
for (hash_ptr
= hash_tbl
[hi
];
hash_ptr
!= (thash_t
*)0;
hash_ptr
= hash_ptr
->next
)
if (aux
.isym
== hash_ptr
->type
.isym
)
if (hash_ptr
!= (thash_t
*)0 && state
== hash_yes
)
if (hash_ptr
== (thash_t
*)0)
hash_ptr
= allocate_thash ();
hash_ptr
->next
= hash_tbl
[hi
];
hash_ptr
->indx
= vp
->num_allocated
;
/* Everything is set up, add the aux symbol. */
if (vp
->objects_last_page
== vp
->objects_per_page
)
aux_ptr
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
++ ];
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.)
Also note: We use the last size given since gcc may emit 2
(void) add_aux_sym_symint ((symint_t
)t
->sizes
[t
->num_sizes
-1]);
/* Add tag information if needed. Structure, union, and enum
references add 2 aux symbols: a [file index, symbol index]
pointer to the structure type, and the current file index. */
if (t
->basic_type
== bt_Struct
|| t
->basic_type
== bt_Union
|| t
->basic_type
== bt_Enum
)
register symint_t file_index
= t
->tag_ptr
->ifd
;
register symint_t sym_index
= t
->tag_ptr
->indx
;
(void) add_aux_sym_rndx (ST_RFDESCAPE
, sym_index
);
(void) add_aux_sym_symint ((symint_t
)-1);
else if (sym_index
!= indexNil
)
(void) add_aux_sym_rndx (ST_RFDESCAPE
, sym_index
);
(void) add_aux_sym_symint (file_index
);
register forward_t
*forward_ref
= allocate_forward ();
forward_ref
->type_ptr
= aux_ptr
;
forward_ref
->next
= t
->tag_ptr
->forward_ref
;
t
->tag_ptr
->forward_ref
= forward_ref
;
(void) add_aux_sym_rndx (ST_RFDESCAPE
, sym_index
);
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
- 1];
(void) add_aux_sym_symint (file_index
);
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
- 1];
/* Add information about array bounds if they exist. */
for (i
= 0; i
< t
->num_dims
; i
++)
(void) add_aux_sym_rndx (ST_RFDESCAPE
,
(void) add_aux_sym_symint (cur_file_ptr
->file_index
); /* file index*/
(void) add_aux_sym_symint ((symint_t
)0); /* low bound */
(void) add_aux_sym_symint (t
->dimensions
[i
] - 1); /* high bound*/
(void) add_aux_sym_symint ((t
->dimensions
[i
] == 0) /* stride */
: (t
->sizes
[i
] * 8) / t
->dimensions
[i
]);
/* NOTE: Mips documentation claism that the bitfield width goes here.
But it needs to be emitted earlier. */
/* Add a tag to the tag table (unless it already exists). */
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 */
hash_ptr
= hash_string (tag_start
,
if (hash_ptr
!= (shash_t
*)0
&& hash_ptr
->tag_ptr
!= (tag_t
*)0)
tag_ptr
= hash_ptr
->tag_ptr
;
tag_ptr
->basic_type
= basic_type
;
tag_ptr
->ifd
= cur_file_ptr
->file_index
;
(void) add_string (&tag_strings
,
tag_ptr
= allocate_tag ();
tag_ptr
->forward_ref
= (forward_t
*) 0;
tag_ptr
->hash_ptr
= hash_ptr
;
tag_ptr
->same_name
= hash_ptr
->tag_ptr
;
tag_ptr
->basic_type
= basic_type
;
tag_ptr
->ifd
= (indx
== indexNil
) ? -1 : cur_file_ptr
->file_index
;
tag_ptr
->same_block
= cur_tag_head
->first_tag
;
cur_tag_head
->first_tag
= tag_ptr
;
hash_ptr
->tag_ptr
= tag_ptr
;
/* Add an unknown {struct, union, enum} tag. */
tag_t
*ptag
; /* pointer to tag information */
shash_t
*hash_ptr
= ptag
->hash_ptr
;
char *name_start
= hash_ptr
->string
;
char *name_end_p1
= name_start
+ hash_ptr
->len
;
forward_t
*f_next
= ptag
->forward_ref
;
int file_index
= cur_file_ptr
->file_index
;
char *agg_type
= "{unknown aggregate type}";
switch (ptag
->basic_type
)
case bt_Struct
: agg_type
= "struct"; break;
case bt_Union
: agg_type
= "union"; break;
case bt_Enum
: agg_type
= "enum"; break;
fprintf (stderr
, "unknown %s %.*s found\n", agg_type
,
hash_ptr
->len
, name_start
);
sym_index
= add_local_symbol (name_start
,
(void) add_local_symbol (name_start
,
while (f_next
!= (forward_t
*)0)
f_cur
->ifd_ptr
->isym
= file_index
;
f_cur
->index_ptr
->rndx
.index
= sym_index
;
/* Add a procedure to the current file's list of procedures, and record
this is the current procedure. If the assembler created a PDR for
this procedure, use that to initialize the current PDR. */
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 */
register PDR
*new_proc_ptr
;
register efdr_t
*file_ptr
= cur_file_ptr
;
register varray_t
*vp
= &file_ptr
->procs
;
register symint_t value
= 0;
register st_t proc_type
= st_Proc
;
register shash_t
*shash_ptr
= hash_string (func_start
,
func_end_p1
- func_start
,
if (vp
->objects_last_page
== vp
->objects_per_page
)
cur_proc_ptr
= new_proc_ptr
= &vp
->last
->datum
->proc
[ vp
->objects_last_page
++ ];
/* Did the assembler create this procedure? If so, get the PDR information. */
cur_oproc_ptr
= (PDR
*)0;
if (shash_ptr
!= (shash_t
*)0)
register PDR
*old_proc_ptr
= shash_ptr
->proc_ptr
;
register SYMR
*sym_ptr
= shash_ptr
->sym_ptr
;
if (old_proc_ptr
!= (PDR
*)0
&& ((st_t
)sym_ptr
->st
== st_Proc
|| (st_t
)sym_ptr
->st
== st_StaticProc
))
cur_oproc_begin
= sym_ptr
;
cur_oproc_end
= shash_ptr
->end_ptr
;
cur_oproc_ptr
= old_proc_ptr
;
proc_type
= (st_t
)sym_ptr
->st
;
*new_proc_ptr
= *old_proc_ptr
; /* initialize */
if (cur_oproc_ptr
== (PDR
*)0)
error ("Did not find a PDR block for %.*s", func_end_p1
- func_start
, func_start
);
/* Determine the start of symbols. */
new_proc_ptr
->isym
= file_ptr
->symbols
.num_allocated
;
/* Push the start of the function. */
(void) add_local_symbol (func_start
, func_end_p1
,
/* 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. */
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 char zero_bytes
[2] = { '\0', '\0' };
register Ptrdiff_t len
= file_end_p1
- file_start
;
register int first_ch
= *file_start
;
register efdr_t
*file_ptr
;
fprintf (stderr
, "\tfile\t%.*s\n", len
, file_start
);
/* See if the file has already been created. */
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
if (first_ch
== file_ptr
->name
[0]
&& file_ptr
->name
[len
] == '\0'
&& memcmp ((CPTR_T
) file_start
, (CPTR_T
) file_ptr
->name
, len
) == 0)
/* If this is a new file, create it. */
if (file_ptr
== (efdr_t
*)0)
if (file_desc
.objects_last_page
== file_desc
.objects_per_page
)
add_varray_page (&file_desc
);
file_ptr
= cur_file_ptr
=
&file_desc
.last
->datum
->file
[ file_desc
.objects_last_page
++ ];
file_ptr
->file_index
= file_desc
.num_allocated
++;
/* Allocate the string hash table. */
file_ptr
->shash_head
= (shash_t
**) allocate_page ();
/* Make sure 0 byte in string table is null */
add_string (&file_ptr
->strings
,
&file_ptr
->shash_head
[0],
if (file_end_p1
- file_start
> PAGE_USIZE
-2)
fatal ("Filename goes over one page boundary.");
/* Push the start of the filename. We assume that the filename
will be stored at string offset 1. */
(void) add_local_symbol (file_start
, file_end_p1
, st_File
, sc_Text
,
(symint_t
)0, (symint_t
)0);
file_ptr
->name
= &file_ptr
->strings
.last
->datum
->byte
[1];
file_ptr
->name_len
= file_end_p1
- file_start
;
/* Update the linked list of file descriptors. */
*last_file_ptr
= file_ptr
;
last_file_ptr
= &file_ptr
->next_file
;
/* Add void & int types to the file (void should be first to catch
errant 0's within the index fields). */
file_ptr
->void_type
= add_aux_sym_tir (&void_type_info
,
&cur_file_ptr
->thash_head
[0]);
file_ptr
->int_type
= add_aux_sym_tir (&int_type_info
,
&cur_file_ptr
->thash_head
[0]);
/* Add a stream of random bytes to a varray. */
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 */
register Size_t move_items
;
register Size_t move_bytes
;
if (vp
->objects_last_page
>= vp
->objects_per_page
)
ptr
= &vp
->last
->datum
->byte
[ vp
->objects_last_page
* vp
->object_size
];
move_items
= vp
->objects_per_page
- vp
->objects_last_page
;
move_bytes
= move_items
* vp
->object_size
;
(void) memcpy ((PTR_T
) ptr
, (CPTR_T
) input_ptr
, move_bytes
);
/* Convert storage class to string. */
sc_to_string(storage_class
)
case sc_Nil
: return "Nil,";
case sc_Text
: return "Text,";
case sc_Data
: return "Data,";
case sc_Bss
: return "Bss,";
case sc_Register
: return "Register,";
case sc_Abs
: return "Abs,";
case sc_Undefined
: return "Undefined,";
case sc_CdbLocal
: return "CdbLocal,";
case sc_Bits
: return "Bits,";
case sc_CdbSystem
: return "CdbSystem,";
case sc_RegImage
: return "RegImage,";
case sc_Info
: return "Info,";
case sc_UserStruct
: return "UserStruct,";
case sc_SData
: return "SData,";
case sc_SBss
: return "SBss,";
case sc_RData
: return "RData,";
case sc_Var
: return "Var,";
case sc_Common
: return "Common,";
case sc_SCommon
: return "SCommon,";
case sc_VarRegister
: return "VarRegister,";
case sc_Variant
: return "Variant,";
case sc_SUndefined
: return "SUndefined,";
case sc_Init
: return "Init,";
case sc_Max
: return "Max,";
/* Convert symbol type to string. */
st_to_string(symbol_type
)
case st_Nil
: return "Nil,";
case st_Global
: return "Global,";
case st_Static
: return "Static,";
case st_Param
: return "Param,";
case st_Local
: return "Local,";
case st_Label
: return "Label,";
case st_Proc
: return "Proc,";
case st_Block
: return "Block,";
case st_End
: return "End,";
case st_Member
: return "Member,";
case st_Typedef
: return "Typedef,";
case st_File
: return "File,";
case st_RegReloc
: return "RegReloc,";
case st_Forward
: return "Forward,";
case st_StaticProc
: return "StaticProc,";
case st_Constant
: return "Constant,";
case st_Str
: return "String,";
case st_Number
: return "Number,";
case st_Expr
: return "Expr,";
case st_Type
: return "Type,";
case st_Max
: return "Max,";
/* Read a line from standard input, and return the start of the buffer
(which is grows if the line is too big). We split lines at the
semi-colon, and return each logical line independently. */
read_line
__proto((void))
static int line_split_p
= 0;
register int string_p
= 0;
register int comment_p
= 0;
if (cur_line_start
== (char *)0)
{ /* allocate initial page */
cur_line_start
= (char *) allocate_page ();
cur_line_alloc
= PAGE_SIZE
;
for (ptr
= cur_line_start
; (ch
= getchar ()) != EOF
; *ptr
++ = ch
)
if (++cur_line_nbytes
>= cur_line_alloc
-1)
register int num_pages
= cur_line_alloc
/ PAGE_SIZE
;
register char *old_buffer
= cur_line_start
;
cur_line_alloc
+= PAGE_SIZE
;
cur_line_start
= (char *) allocate_multiple_pages (num_pages
+1);
memcpy (cur_line_start
, old_buffer
, num_pages
* PAGE_SIZE
);
ptr
= cur_line_start
+ cur_line_nbytes
- 1;
cur_line_ptr
= cur_line_start
;
error ("Null character found in input");
else if (ch
== ';' && !string_p
)
cur_line_ptr
= cur_line_start
;
pfatal_with_name (input_name
);
cur_line_ptr
= (char *)0;
/* Parse #.begin directives which have a label as the first argument
which gives the location of the start of the block. */
const char *start
; /* start of directive */
const char *end_p1
; /* end of label */
shash_t
*hash_ptr
; /* hash pointer to lookup label */
if (cur_file_ptr
== (efdr_t
*)0)
error ("#.begin directive without a preceding .file directive");
if (cur_proc_ptr
== (PDR
*)0)
error ("#.begin directive without a preceding .ent directive");
for (end_p1
= start
; (ch
= *end_p1
) != '\0' && !isspace (ch
); end_p1
++)
hash_ptr
= hash_string (start
,
if (hash_ptr
== (shash_t
*)0)
error ("Label %.*s not found for #.begin", end_p1
- start
, start
);
if (cur_oproc_begin
== (SYMR
*)0)
error ("Procedure table %.*s not found for #.begin", end_p1
- start
, start
);
(void) add_local_symbol ((const char *)0, (const char *)0,
(symint_t
)hash_ptr
->sym_ptr
->value
- cur_oproc_begin
->value
,
/* Parse #.bend directives which have a label as the first argument
which gives the location of the end of the block. */
const char *start
; /* start of directive */
const char *end_p1
; /* end of label */
shash_t
*hash_ptr
; /* hash pointer to lookup label */
if (cur_file_ptr
== (efdr_t
*)0)
error ("#.begin directive without a preceding .file directive");
if (cur_proc_ptr
== (PDR
*)0)
error ("#.bend directive without a preceding .ent directive");
for (end_p1
= start
; (ch
= *end_p1
) != '\0' && !isspace (ch
); end_p1
++)
hash_ptr
= hash_string (start
,
if (hash_ptr
== (shash_t
*)0)
error ("Label %.*s not found for #.bend", end_p1
- start
, start
);
if (cur_oproc_begin
== (SYMR
*)0)
error ("Procedure table %.*s not found for #.bend", end_p1
- start
, start
);
(void) add_local_symbol ((const char *)0, (const char *)0,
(symint_t
)hash_ptr
->sym_ptr
->value
- cur_oproc_begin
->value
,
/* Parse #.def directives, which are contain standard COFF subdirectives
to describe the debugging format. These subdirectives include:
.scl specify storage class
.endef specify end of COFF directives
.size specify the size of an array
.dim specify an array dimension
.tag specify a tag for a struct, union, or enum. */
const char *name_start
; /* start of directive */
const char *dir_start
; /* start of current directive*/
const char *dir_end_p1
; /* end+1 of current directive*/
const char *arg_start
; /* start of current argument */
const char *arg_end_p1
; /* end+1 of current argument */
const char *name_end_p1
; /* end+1 of label */
const char *tag_start
= (const char *)0; /* start of tag name */
const char *tag_end_p1
= (const char *)0; /* end+1 of tag name */
sc_t storage_class
= sc_Nil
;
st_t symbol_type
= st_Nil
;
EXTR
*eptr
= (EXTR
*)0; /* ext. sym equivalent to def*/
int is_function
= 0; /* != 0 if function */
symint_t indx
= cur_file_ptr
->void_type
;
symint_t temp_array
[ N_TQ
];
static int inside_enumeration
= 0; /* is this an enumeration? */
/* Initialize the type information. */
/* Search for the end of the name being defined. */
/* Allow spaces and such in names for G++ templates, which produce stabs
#.def SMANIP<long unsigned int>; .scl 10; .type 0x8; .size 8; .endef */
for (name_end_p1
= name_start
; (ch
= *name_end_p1
) != ';' && ch
!= '\0'; name_end_p1
++)
/* Parse the remaining subdirectives now. */
dir_start
= name_end_p1
+1;
while ((ch
= *dir_start
) == ' ' || ch
== '\t')
&& memcmp (dir_start
, ".endef", sizeof (".endef")-1) == 0)
/* Pick up the subdirective now */
for (dir_end_p1
= dir_start
+1;
(ch
= *dir_end_p1
) != ' ' && ch
!= '\t';
if (ch
== '\0' || isspace (ch
))
/* Pick up the subdirective argument now. */
arg_was_number
= arg_number
= 0;
arg_end_p1
= (const char *)0;
arg_start
= dir_end_p1
+1;
while (ch
== ' ' || ch
== '\t')
if (isdigit (ch
) || ch
== '-' || ch
== '+')
arg_number
= strtol (arg_start
, (char **) &arg_end_p1
, 0);
if (arg_end_p1
!= arg_start
|| (ch2
= *arg_end_p1
!= ';') || ch2
!= ',')
else if (ch
== '\0' || isspace (ch
))
/* Allow spaces and such in names for G++ templates. */
for (arg_end_p1
= arg_start
+1;
(ch
= *arg_end_p1
) != ';' && ch
!= '\0';
/* Classify the directives now. */
len
= dir_end_p1
- dir_start
;
if (len
== sizeof (".dim")-1
&& memcmp (dir_start
, ".dim", sizeof (".dim")-1) == 0
symint_t
*t_ptr
= &temp_array
[ N_TQ
-1 ];
while (*arg_end_p1
== ',' && arg_was_number
)
arg_start
= arg_end_p1
+1;
while (ch
== ' ' || ch
== '\t')
if (isdigit (ch
) || ch
== '-' || ch
== '+')
arg_number
= strtol (arg_start
, (char **) &arg_end_p1
, 0);
if (arg_end_p1
!= arg_start
|| (ch2
= *arg_end_p1
!= ';') || ch2
!= ',')
if (t_ptr
== &temp_array
[0])
/* Reverse order of dimensions. */
while (t_ptr
<= &temp_array
[ N_TQ
-1 ])
if (t
.num_dims
>= N_TQ
-1)
t
.dimensions
[ t
.num_dims
++ ] = *t_ptr
++;
if (len
== sizeof (".scl")-1
&& memcmp (dir_start
, ".scl", sizeof (".scl")-1) == 0
&& arg_number
< ((symint_t
) C_MAX
))
/* If the symbol is a static or external, we have
already gotten the appropriate type and class, so
make sure we don't override those values. This is
needed because there are some type and classes that
are not in COFF, such as short data, etc. */
if (symbol_type
== st_Nil
)
symbol_type
= map_coff_sym_type
[arg_number
];
storage_class
= map_coff_storage
[arg_number
];
else if (len
== sizeof (".size")-1
&& memcmp (dir_start
, ".size", sizeof (".size")-1) == 0
symint_t
*t_ptr
= &temp_array
[ N_TQ
-1 ];
while (*arg_end_p1
== ',' && arg_was_number
)
arg_start
= arg_end_p1
+1;
while (ch
== ' ' || ch
== '\t')
if (isdigit (ch
) || ch
== '-' || ch
== '+')
arg_number
= strtol (arg_start
, (char **) &arg_end_p1
, 0);
if (arg_end_p1
!= arg_start
|| (ch2
= *arg_end_p1
!= ';') || ch2
!= ',')
if (t_ptr
== &temp_array
[0])
/* Reverse order of sizes. */
while (t_ptr
<= &temp_array
[ N_TQ
-1 ])
if (t
.num_sizes
>= N_TQ
-1)
t
.sizes
[ t
.num_sizes
++ ] = *t_ptr
++;
if (len
== sizeof (".type")-1
&& memcmp (dir_start
, ".type", sizeof (".type")-1) == 0
tq_t
*tq_ptr
= &t
.type_qualifiers
[0];
t
.orig_type
= (coff_type_t
) (arg_number
& N_BTMASK
);
t
.basic_type
= map_coff_types
[(int)t
.orig_type
];
for (i
= N_TQ
-1; i
>= 0; i
--)
int dt
= (arg_number
>> ((i
* N_TQ_SHIFT
) + N_BT_SHIFT
)
*tq_ptr
++ = map_coff_derived_type
[dt
];
/* If this is a function, ignore it, so that we don't get
two entries (one from the .ent, and one for the .def
that precedes it). Save the type information so that
the end block can properly add it after the begin block
index. For MIPS knows what reason, we must strip off
the function type at this point. */
if (tq_ptr
!= &t
.type_qualifiers
[0] && tq_ptr
[-1] == tq_Proc
)
else if (len
== sizeof (".tag")-1
&& memcmp (dir_start
, ".tag", sizeof (".tag")-1) == 0)
if (len
== sizeof (".val")-1
&& memcmp (dir_start
, ".val", sizeof (".val")-1) == 0)
/* If the value is not an integer value, it must be the
name of a static or global item. Look up the name in
the original symbol table to pick up the storage
class, symbol type, etc. */
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
,
if (ext_hash_ptr
!= (shash_t
*)0
&& ext_hash_ptr
->esym_ptr
!= (EXTR
*)0)
eptr
= ext_hash_ptr
->esym_ptr
;
orig_hash_ptr
= hash_string (arg_start
,
if ((orig_hash_ptr
== (shash_t
*)0
|| orig_hash_ptr
->sym_ptr
== (SYMR
*)0)
fprintf (stderr
, "warning, %.*s not found in original or external symbol tables, value defaults to 0\n",
SYMR
*ptr
= (orig_hash_ptr
!= (shash_t
*)0
&& orig_hash_ptr
->sym_ptr
!= (SYMR
*)0)
symbol_type
= (st_t
) ptr
->st
;
storage_class
= (sc_t
) ptr
->sc
;
/* Set up to find next directive. */
dir_start
= arg_end_p1
+ 1;
t
.extra_sizes
= (tag_start
!= (char *)0);
int diff
= t
.num_dims
- t
.num_sizes
;
if (t
.num_sizes
!= 1 || diff
< 0)
/* If this is an array, make sure the same number of dimensions
and sizes were passed, creating extra sizes for multiply
dimensioned arrays if not passed. */
for (j
= (sizeof (t
.sizes
) / sizeof (t
.sizes
[0])) - 1; j
>= 0; j
--)
t
.sizes
[ j
] = ((j
-diff
) >= 0) ? t
.sizes
[ j
-diff
] : 0;
t
.sizes
[ i
] = t
.sizes
[ i
+1 ] / t
.dimensions
[ i
+1 ];
else if (symbol_type
== st_Member
&& t
.num_sizes
- t
.extra_sizes
== 1)
{ /* Is this a bitfield? This is indicated by a structure memeber
having a size field that isn't an array. */
/* Except for enumeration members & begin/ending of scopes, put the
type word in the aux. symbol table. */
if (symbol_type
== st_Block
|| symbol_type
== st_End
)
else if (inside_enumeration
)
indx
= cur_file_ptr
->void_type
;
if (t
.basic_type
== bt_Struct
|| t
.basic_type
== bt_Union
|| t
.basic_type
== bt_Enum
)
if (tag_start
== (char *)0)
error ("No tag specified for %.*s",
name_end_p1
- name_start
,
t
.tag_ptr
= get_tag (tag_start
, tag_end_p1
, (symint_t
)indexNil
,
indx
= add_aux_sym_tir (&t
,
&cur_file_ptr
->thash_head
[0]);
/* If this is an external or static symbol, update the appropriate
&& (eptr
->asym
.index
== indexNil
|| cur_proc_ptr
== (PDR
*)0))
eptr
->ifd
= cur_file_ptr
->file_index
;
/* Do any last minute adjustments that are necessary. */
/* For the beginning of structs, unions, and enumerations, the
size info needs to be passed in the value field. */
if (t
.num_sizes
- t
.num_dims
- t
.extra_sizes
!= 1)
inside_enumeration
= (t
.orig_type
== T_ENUM
);
/* For the end of structs, unions, and enumerations, omit the
name which is always ".eos". This needs to be done last, so
that any error reporting above gives the correct name. */
name_start
= name_end_p1
= (const char *)0;
value
= inside_enumeration
= 0;
/* Members of structures and unions that aren't bitfields, need
to adjust the value from a byte offset to a bit offset.
Members of enumerations do not have the value adjusted, and
can be distinguished by indx == indexNil. For enumerations,
update the maximum enumeration value. */
if (!t
.bitfield
&& !inside_enumeration
)
/* Add the symbol, except for global symbols outside of functions,
for which the external symbol table is fine enough. */
|| eptr
->asym
.st
== (int)st_Nil
|| cur_proc_ptr
!= (PDR
*)0)
symint_t isym
= add_local_symbol (name_start
, name_end_p1
,
symbol_type
, storage_class
,
/* deal with struct, union, and enum tags. */
if (symbol_type
== st_Block
)
/* Create or update the tag information. */
tag_t
*tag_ptr
= get_tag (name_start
,
/* If there are any forward references, fill in the appropriate
file and symbol indexes. */
symint_t file_index
= cur_file_ptr
->file_index
;
forward_t
*f_next
= tag_ptr
->forward_ref
;
while (f_next
!= (forward_t
*)0)
f_cur
->ifd_ptr
->isym
= file_index
;
f_cur
->index_ptr
->rndx
.index
= isym
;
tag_ptr
->forward_ref
= (forward_t
*)0;
/* Error return, issue message. */
error ("compiler error, badly formed #.def (internal line # = %d)", error_line
);
error ("compiler error, badly formed #.def");
/* Parse .end directives. */
const char *start
; /* start of directive */
register const char *start_func
, *end_func_p1
;
if (cur_file_ptr
== (efdr_t
*)0)
error (".end directive without a preceding .file directive");
if (cur_proc_ptr
== (PDR
*)0)
error (".end directive without a preceding .ent directive");
/* Get the function name, skipping whitespace. */
for (start_func
= start
; isspace (*start_func
); start_func
++)
error (".end directive has no name");
for (end_func_p1
= start_func
; IS_ASM_IDENT (ch
); ch
= *++end_func_p1
)
/* Get the value field for creating the end from the original object
file (which we find by locating the procedure start, and using the
pointer to the end+1 block and backing up. The index points to a
two word aux. symbol, whose first word is the index of the end
symbol, and the second word is the type of the function return
orig_fdr
= cur_file_ptr
->orig_fdr
;
if (orig_fdr
!= (FDR
*)0 && cur_oproc_end
!= (SYMR
*)0)
value
= cur_oproc_end
->value
;
error ("Cannot find .end block for %.*s", end_func_p1
- start_func
, start_func
);
(void) add_local_symbol (start_func
, end_func_p1
,
cur_proc_ptr
= cur_oproc_ptr
= (PDR
*)0;
/* Parse .ent directives. */
const char *start
; /* start of directive */
register const char *start_func
, *end_func_p1
;
if (cur_file_ptr
== (efdr_t
*)0)
error (".ent directive without a preceding .file directive");
if (cur_proc_ptr
!= (PDR
*)0)
error ("second .ent directive found before .end directive");
for (start_func
= start
; isspace (*start_func
); start_func
++)
error (".ent directive has no name");
for (end_func_p1
= start_func
; IS_ASM_IDENT (ch
); ch
= *++end_func_p1
)
(void) add_procedure (start_func
, end_func_p1
);
/* Parse .file directives. */
const char *start
; /* start of directive */
register char *start_name
, *end_name_p1
;
(void) strtol (start
, &p
, 0);
|| (start_name
= local_index (p
, '"')) == (char *)0
|| (end_name_p1
= local_rindex (++start_name
, '"')) == (char *)0)
error ("Illegal .file directive");
if (cur_proc_ptr
!= (PDR
*)0)
error ("No way to handle .file within .ent/.end section");
add_file (start_name
, end_name_p1
);
/* Make sure the @stabs symbol is emitted. */
const char *start
; /* Start of directive (ignored) */
/* Add a dummy @stabs dymbol. */
(void) add_local_symbol (stabs_symbol
,
stabs_symbol
+ sizeof (stabs_symbol
),
stNil
, scInfo
, -1, MIPS_MARK_STAB(0));
/* Parse .stabs directives.
.stabs directives have five fields:
"string" a string, encoding the type information.
code a numeric code, defined in <stab.h>
value a numeric value or an address.
If the value is relocatable, we transform this into:
iss points as an index into string space
value value from lookup of the name
st st from lookup of the name
sc sc from lookup of the name
If the value is not relocatable, we transform this into:
iss points as an index into string space
.stabn directives have four fields (string is null):
code a numeric code, defined in <stab.h>
0 a zero or a line number
value a numeric value or an address. */
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. */
efdr_t
*save_file_ptr
= cur_file_ptr
;
/* Read code from stabs. */
error ("Illegal .stabs/.stabn directive, code is non-numeric");
code
= strtol (rest
, &p
, 0);
/* Line number stabs are handled differently, since they have two values,
the line number and the address of the label. We use the index field
(aka code) to hold the line number, and the value field to hold the
address. The symbol type is st_Label, which should be different from
the other stabs, so that gdb can recognize it. */
if (code
== (int)N_SLINE
)
SYMR
*sym_ptr
, dummy_symr
;
if (p
[0] != ',' || p
[1] != '0' || p
[2] != ',' || !isdigit (p
[3]))
error ("Illegal line number .stabs/.stabn directive");
code
= strtol (p
+3, &p
, 0);
if (p
[-1] != ',' || isdigit (ch
) || !IS_ASM_IDENT (ch
))
error ("Illegal line number .stabs/.stabn directive");
if (dummy_symr
.index
!= code
)
error ("Line number (%d) for .stabs/.stabn directive cannot fit in index field (20 bits)",
shash_ptr
= hash_string (p
,
if (shash_ptr
== (shash_t
*)0
|| (sym_ptr
= shash_ptr
->sym_ptr
) == (SYMR
*)0)
error ("Illegal .stabs/.stabn directive, value not found");
if ((st_t
) sym_ptr
->st
!= st_Label
)
error ("Illegal line number .stabs/.stabn directive");
if (p
[0] != ',' || p
[1] != '0' || p
[2] != ',' || p
[3] != '0' || p
[4] != ',')
error ("Illegal .stabs/.stabn directive, mandatory 0 isn't");
if (!IS_ASM_IDENT (ch
) && ch
!= '-')
error ("Illegal .stabs/.stabn directive, bad character");
if (isdigit (ch
) || ch
== '-')
value
= strtol (p
, &p
, 0);
error ("Illegal .stabs/.stabn directive, stuff after numeric value");
else if (!IS_ASM_IDENT (ch
))
error ("Illegal .stabs/.stabn directive, bad character");
const char *start
, *end_p1
;
if ((end_p1
= strchr (start
, '+')) == (char *)0)
if ((end_p1
= strchr (start
, '-')) == (char *)0)
end_p1
= start
+ strlen(start
) - 1;
shash_ptr
= hash_string (start
,
if (shash_ptr
== (shash_t
*)0
|| (sym_ptr
= shash_ptr
->sym_ptr
) == (SYMR
*)0)
shash_ptr
= hash_string (start
,
if (shash_ptr
== (shash_t
*)0
|| shash_ptr
->esym_ptr
== (EXTR
*)0)
error ("Illegal .stabs/.stabn directive, value not found");
sym_ptr
= &(shash_ptr
->esym_ptr
->asym
);
/* Traditionally, N_LBRAC and N_RBRAC are *not* relocated. */
if (code
== (int)N_LBRAC
|| code
== (int)N_RBRAC
)
if (((!isdigit (*end_p1
)) && (*end_p1
!= '-'))
|| ((ch
!= '+') && (ch
!= '-')))
error ("Illegal .stabs/.stabn directive, badly formed value");
value
+= strtol (end_p1
, &p
, 0);
value
-= strtol (end_p1
, &p
, 0);
error ("Illegal .stabs/.stabn directive, stuff after numeric value");
code
= MIPS_MARK_STAB(code
);
(void) add_local_symbol (string_start
, string_end
, st
, sc
, value
, code
);
/* Restore normal file type. */
cur_file_ptr
= save_file_ptr
;
const char *start
; /* start of directive */
const char *end
= local_index (start
+1, '"');
if (*start
!= '"' || end
== (const char *)0 || end
[1] != ',')
error ("Illegal .stabs directive, no string");
parse_stabs_common (start
+1, end
, end
+2);
const char *start
; /* start of directive */
parse_stabs_common ((const char *)0, (const char *)0, start
);
/* Parse the input file, and write the lines to the output file
parse_input
__proto((void))
register thead_t
*ptag_head
;
register tag_t
*ptag_next
;
fprintf (stderr
, "\tinput\n");
/* Add a dummy scope block around the entire compilation unit for
structures defined outside of blocks. */
ptag_head
= allocate_thead ();
ptag_head
->first_tag
= 0;
ptag_head
->prev
= cur_tag_head
;
cur_tag_head
= ptag_head
;
while ((p
= read_line ()) != (char *)0)
/* Skip leading blanks */
/* See if it's a directive we handle. If so, dispatch handler. */
for (i
= 0; i
< sizeof (pseudo_ops
) / sizeof (pseudo_ops
[0]); i
++)
if (memcmp (p
, pseudo_ops
[i
].name
, pseudo_ops
[i
].len
) == 0
&& isspace (p
[pseudo_ops
[i
].len
]))
p
+= pseudo_ops
[i
].len
; /* skip to first argument */
(*pseudo_ops
[i
].func
)( p
);
/* Process any tags at global level. */
ptag_head
= cur_tag_head
;
cur_tag_head
= ptag_head
->prev
;
for (ptag
= ptag_head
->first_tag
;
if (ptag
->forward_ref
!= (forward_t
*)0)
ptag_next
= ptag
->same_block
;
ptag
->hash_ptr
->tag_ptr
= ptag
->same_name
;
/* Update the global headers with the final offsets in preparation
to write out the .T file. */
update_headers
__proto((void))
register efdr_t
*file_ptr
;
/* Set up the symbolic header. */
file_offset
= sizeof (symbolic_header
) + orig_file_header
.f_symptr
;
symbolic_header
.magic
= orig_sym_hdr
.magic
;
symbolic_header
.vstamp
= orig_sym_hdr
.vstamp
;
/* Set up global counts. */
symbolic_header
.issExtMax
= ext_strings
.num_allocated
;
symbolic_header
.idnMax
= dense_num
.num_allocated
;
symbolic_header
.ifdMax
= file_desc
.num_allocated
;
symbolic_header
.iextMax
= ext_symbols
.num_allocated
;
symbolic_header
.ilineMax
= orig_sym_hdr
.ilineMax
;
symbolic_header
.ioptMax
= orig_sym_hdr
.ioptMax
;
symbolic_header
.cbLine
= orig_sym_hdr
.cbLine
;
symbolic_header
.crfd
= orig_sym_hdr
.crfd
;
/* Loop through each file, figuring out how many local syms,
line numbers, etc. there are. Also, put out end symbol
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
(void) add_local_symbol ((const char *)0, (const char *)0,
file_ptr
->fdr
.cpd
= file_ptr
->procs
.num_allocated
;
file_ptr
->fdr
.ipdFirst
= symbolic_header
.ipdMax
;
symbolic_header
.ipdMax
+= file_ptr
->fdr
.cpd
;
file_ptr
->fdr
.csym
= file_ptr
->symbols
.num_allocated
;
file_ptr
->fdr
.isymBase
= symbolic_header
.isymMax
;
symbolic_header
.isymMax
+= file_ptr
->fdr
.csym
;
file_ptr
->fdr
.caux
= file_ptr
->aux_syms
.num_allocated
;
file_ptr
->fdr
.iauxBase
= symbolic_header
.iauxMax
;
symbolic_header
.iauxMax
+= file_ptr
->fdr
.caux
;
file_ptr
->fdr
.cbSs
= file_ptr
->strings
.num_allocated
;
file_ptr
->fdr
.issBase
= symbolic_header
.issMax
;
symbolic_header
.issMax
+= file_ptr
->fdr
.cbSs
;
i
= WORD_ALIGN (symbolic_header
.cbLine
); /* line numbers */
symbolic_header
.cbLineOffset
= file_offset
;
i
= symbolic_header
.ioptMax
; /* optimization symbols */
symbolic_header
.cbOptOffset
= file_offset
;
file_offset
+= i
* sizeof (OPTR
);
i
= symbolic_header
.idnMax
; /* dense numbers */
symbolic_header
.cbDnOffset
= file_offset
;
file_offset
+= i
* sizeof (DNR
);
i
= symbolic_header
.ipdMax
; /* procedure tables */
symbolic_header
.cbPdOffset
= file_offset
;
file_offset
+= i
* sizeof (PDR
);
i
= symbolic_header
.isymMax
; /* local symbols */
symbolic_header
.cbSymOffset
= file_offset
;
file_offset
+= i
* sizeof (SYMR
);
i
= symbolic_header
.iauxMax
; /* aux syms. */
symbolic_header
.cbAuxOffset
= file_offset
;
file_offset
+= i
* sizeof (TIR
);
i
= WORD_ALIGN (symbolic_header
.issMax
); /* local strings */
symbolic_header
.cbSsOffset
= file_offset
;
i
= WORD_ALIGN (symbolic_header
.issExtMax
); /* external strings */
symbolic_header
.cbSsExtOffset
= file_offset
;
i
= symbolic_header
.ifdMax
; /* file tables */
symbolic_header
.cbFdOffset
= file_offset
;
file_offset
+= i
* sizeof (FDR
);
i
= symbolic_header
.crfd
; /* relative file descriptors */
symbolic_header
.cbRfdOffset
= file_offset
;
file_offset
+= i
* sizeof (symint_t
);
i
= symbolic_header
.iextMax
; /* external symbols */
symbolic_header
.cbExtOffset
= file_offset
;
file_offset
+= i
* sizeof (EXTR
);
/* Write out a varray at a given location. */
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 */
int num_write
, sys_write
;
if (vp
->num_allocated
== 0)
fprintf (stderr
, "\twarray\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
vp
, offset
, vp
->num_allocated
* vp
->object_size
, str
);
if (file_offset
!= offset
&& fseek (object_stream
, (long)offset
, SEEK_SET
) < 0)
pfatal_with_name (object_name
);
for (ptr
= vp
->first
; ptr
!= (vlinks_t
*)0; ptr
= ptr
->next
)
num_write
= (ptr
->next
== (vlinks_t
*)0)
? vp
->objects_last_page
* vp
->object_size
: vp
->objects_per_page
* vp
->object_size
;
sys_write
= fwrite ((PTR_T
) ptr
->datum
, 1, num_write
, object_stream
);
pfatal_with_name (object_name
);
else if (sys_write
!= num_write
)
fatal ("Wrote %d bytes to %s, system returned %d",
file_offset
+= num_write
;
/* Write out the symbol table in the object file. */
write_object
__proto((void))
fprintf (stderr
, "\n\twrite\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
(PTR_T
*) &symbolic_header
, 0, sizeof (symbolic_header
),
sys_write
= fwrite ((PTR_T
) &symbolic_header
,
sizeof (symbolic_header
),
pfatal_with_name (object_name
);
else if (sys_write
!= sizeof (symbolic_header
))
fatal ("Wrote %d bytes to %s, system returned %d",
sizeof (symbolic_header
),
file_offset
= sizeof (symbolic_header
) + orig_file_header
.f_symptr
;
if (symbolic_header
.cbLine
> 0) /* line numbers */
if (file_offset
!= symbolic_header
.cbLineOffset
&& fseek (object_stream
, symbolic_header
.cbLineOffset
, SEEK_SET
) != 0)
pfatal_with_name (object_name
);
fprintf (stderr
, "\twrite\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
(PTR_T
*) &orig_linenum
, symbolic_header
.cbLineOffset
,
symbolic_header
.cbLine
, "Line numbers");
sys_write
= fwrite ((PTR_T
) orig_linenum
,
pfatal_with_name (object_name
);
else if (sys_write
!= symbolic_header
.cbLine
)
fatal ("Wrote %d bytes to %s, system returned %d",
file_offset
= symbolic_header
.cbLineOffset
+ symbolic_header
.cbLine
;
if (symbolic_header
.ioptMax
> 0) /* optimization symbols */
long num_write
= symbolic_header
.ioptMax
* sizeof (OPTR
);
if (file_offset
!= symbolic_header
.cbOptOffset
&& fseek (object_stream
, symbolic_header
.cbOptOffset
, SEEK_SET
) != 0)
pfatal_with_name (object_name
);
fprintf (stderr
, "\twrite\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
(PTR_T
*) &orig_opt_syms
, symbolic_header
.cbOptOffset
,
num_write
, "Optimizer symbols");
sys_write
= fwrite ((PTR_T
) orig_opt_syms
,
pfatal_with_name (object_name
);
else if (sys_write
!= num_write
)
fatal ("Wrote %d bytes to %s, system returned %d",
file_offset
= symbolic_header
.cbOptOffset
+ num_write
;
if (symbolic_header
.idnMax
> 0) /* dense numbers */
write_varray (&dense_num
, (off_t
)symbolic_header
.cbDnOffset
, "Dense numbers");
if (symbolic_header
.ipdMax
> 0) /* procedure tables */
offset
= symbolic_header
.cbPdOffset
;
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
write_varray (&file_ptr
->procs
, offset
, "Procedure tables");
if (symbolic_header
.isymMax
> 0) /* local symbols */
offset
= symbolic_header
.cbSymOffset
;
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
write_varray (&file_ptr
->symbols
, offset
, "Local symbols");
if (symbolic_header
.iauxMax
> 0) /* aux symbols */
offset
= symbolic_header
.cbAuxOffset
;
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
write_varray (&file_ptr
->aux_syms
, offset
, "Aux. symbols");
if (symbolic_header
.issMax
> 0) /* local strings */
offset
= symbolic_header
.cbSsOffset
;
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
write_varray (&file_ptr
->strings
, offset
, "Local strings");
if (symbolic_header
.issExtMax
> 0) /* external strings */
write_varray (&ext_strings
, symbolic_header
.cbSsExtOffset
, "External strings");
if (symbolic_header
.ifdMax
> 0) /* file tables */
offset
= symbolic_header
.cbFdOffset
;
if (file_offset
!= offset
&& fseek (object_stream
, (long)offset
, SEEK_SET
) < 0)
pfatal_with_name (object_name
);
for (file_ptr
= first_file
;
file_ptr
= file_ptr
->next_file
)
fprintf (stderr
, "\twrite\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
(PTR_T
*) &file_ptr
->fdr
, file_offset
, sizeof (FDR
), "File header");
sys_write
= fwrite (&file_ptr
->fdr
,
pfatal_with_name (object_name
);
else if (sys_write
!= sizeof (FDR
))
fatal ("Wrote %d bytes to %s, system returned %d",
file_offset
= offset
+= sizeof (FDR
);
if (symbolic_header
.crfd
> 0) /* relative file descriptors */
symint_t num_write
= symbolic_header
.crfd
* sizeof (symint_t
);
if (file_offset
!= symbolic_header
.cbRfdOffset
&& fseek (object_stream
, symbolic_header
.cbRfdOffset
, SEEK_SET
) != 0)
pfatal_with_name (object_name
);
fprintf (stderr
, "\twrite\tvp = 0x%.8x, offset = %7u, size = %7u, %s\n",
(PTR_T
*) &orig_rfds
, symbolic_header
.cbRfdOffset
,
num_write
, "Relative file descriptors");
sys_write
= fwrite (orig_rfds
,
pfatal_with_name (object_name
);
else if (sys_write
!= num_write
)
fatal ("Wrote %d bytes to %s, system returned %d",
file_offset
= symbolic_header
.cbRfdOffset
+ num_write
;
if (symbolic_header
.issExtMax
> 0) /* external symbols */
write_varray (&ext_symbols
, (off_t
)symbolic_header
.cbExtOffset
, "External symbols");
if (fclose (object_stream
) != 0)
pfatal_with_name (object_name
);
/* Read some bytes at a specified location, and return a pointer. */
read_seek (size
, offset
, str
)
Size_t size
; /* # bytes to read */
off_t offset
; /* offset to read at */
const char *str
; /* name for tracing */
if (size
== 0) /* nothing to read */
fprintf (stderr
, "\trseek\tsize = %7u, offset = %7u, currently at %7u, %s\n",
size
, offset
, file_offset
, str
);
ptr
= allocate_multiple_pages ((size
+ PAGE_USIZE
- 1) / PAGE_USIZE
);
ptr
= (page_t
*) xcalloc (1, size
);
/* If we need to seek, and the distance is nearby, just do some reads,
if (file_offset
!= offset
)
symint_t difference
= offset
- file_offset
;
sys_read
= fread (small_buffer
, 1, difference
, obj_in_stream
);
pfatal_with_name (obj_in_name
);
if (sys_read
!= difference
)
fatal ("Wanted to read %d bytes from %s, system returned %d",
else if (fseek (obj_in_stream
, offset
, SEEK_SET
) < 0)
pfatal_with_name (obj_in_name
);
sys_read
= fread ((PTR_T
)ptr
, 1, size
, obj_in_stream
);
pfatal_with_name (obj_in_name
);
fatal ("Wanted to read %d bytes from %s, system returned %d",
file_offset
= offset
+ size
;
if (file_offset
> max_file_offset
)
max_file_offset
= file_offset
;
/* Read the existing object file (and copy to the output object file
if it is different from the input object file), and remove the old
copy_object
__proto((void))
char buffer
[ PAGE_SIZE
];
register int delete_ifd
= 0;
register int *remap_file_number
;
fprintf (stderr
, "\tcopy\n");
if (fstat (fileno (obj_in_stream
), &stat_buf
) != 0
|| fseek (obj_in_stream
, 0L, SEEK_SET
) != 0)
pfatal_with_name (obj_in_name
);
sys_read
= fread ((PTR_T
) &orig_file_header
,
pfatal_with_name (obj_in_name
);
else if (sys_read
== 0 && feof (obj_in_stream
))
return; /* create a .T file sans file header */
else if (sys_read
< sizeof (struct filehdr
))
fatal ("Wanted to read %d bytes from %s, system returned %d",
if (orig_file_header
.f_nsyms
!= sizeof (HDRR
))
fatal ("%s symbolic header wrong size (%d bytes, should be %d)",
input_name
, orig_file_header
.f_nsyms
, sizeof (HDRR
));
/* Read in the current symbolic header. */
if (fseek (obj_in_stream
, (long) orig_file_header
.f_symptr
, SEEK_SET
) != 0)
pfatal_with_name (input_name
);
sys_read
= fread ((PTR_T
) &orig_sym_hdr
,
pfatal_with_name (object_name
);
else if (sys_read
< sizeof (struct filehdr
))
fatal ("Wanted to read %d bytes from %s, system returned %d",
/* 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
sections, so in theory no extra seeks are done.
For simplicity sake, round each read up to a page boundary,
we may want to revisit this later.... */
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_sym_hdr
.cbLineOffset
,
if (orig_sym_hdr
.ipdMax
> 0) /* procedure tables */
orig_procs
= (PDR
*) read_seek ((Size_t
)orig_sym_hdr
.ipdMax
* sizeof (PDR
),
if (orig_sym_hdr
.isymMax
> 0) /* local symbols */
orig_local_syms
= (SYMR
*) read_seek ((Size_t
)orig_sym_hdr
.isymMax
* sizeof (SYMR
),
orig_sym_hdr
.cbSymOffset
,
if (orig_sym_hdr
.iauxMax
> 0) /* aux symbols */
orig_aux_syms
= (AUXU
*) read_seek ((Size_t
)orig_sym_hdr
.iauxMax
* sizeof (AUXU
),
orig_sym_hdr
.cbAuxOffset
,
if (orig_sym_hdr
.issMax
> 0) /* local strings */
orig_local_strs
= (char *) read_seek ((Size_t
)orig_sym_hdr
.issMax
,
if (orig_sym_hdr
.issExtMax
> 0) /* external strings */
orig_ext_strs
= (char *) read_seek ((Size_t
)orig_sym_hdr
.issExtMax
,
orig_sym_hdr
.cbSsExtOffset
,
if (orig_sym_hdr
.ifdMax
> 0) /* file tables */
orig_files
= (FDR
*) read_seek ((Size_t
)orig_sym_hdr
.ifdMax
* sizeof (FDR
),
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_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_sym_hdr
.cbExtOffset
,
if (orig_sym_hdr
.idnMax
> 0) /* dense numbers */
orig_dense
= (DNR
*) read_seek ((Size_t
)orig_sym_hdr
.idnMax
* sizeof (DNR
),
add_bytes (&dense_num
, (char *) orig_dense
, (Size_t
)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_sym_hdr
.cbOptOffset
,
/* Abort if the symbol table is not last. */
if (max_file_offset
!= stat_buf
.st_size
)
fatal ("Symbol table is not last (symbol table ends at %ld, .o ends at %ld",
/* If the first original file descriptor is a dummy which the assembler
put out, but there are no symbols in it, skip it now. */
if (orig_sym_hdr
.ifdMax
> 1
&& orig_files
->caux
== 0)
char *filename
= orig_local_strs
+ (orig_files
->issBase
+ orig_files
->rss
);
char *suffix
= local_rindex (filename
, '.');
if (suffix
!= (char *)0 && strcmp (suffix
, ".s") == 0)
/* Create array to map original file numbers to the new file numbers
(in case there are duplicate filenames, we collapse them into one
file section, the MIPS assembler may or may not collapse them). */
remap_file_number
= (int *) alloca (sizeof (int) * orig_sym_hdr
.ifdMax
);
for (fd
= delete_ifd
; fd
< orig_sym_hdr
.ifdMax
; fd
++)
register FDR
*fd_ptr
= ORIG_FILES (fd
);
register char *filename
= ORIG_LSTRS (fd_ptr
->issBase
+ fd_ptr
->rss
);
/* file support itself. */
add_file (filename
, filename
+ strlen (filename
));
remap_file_number
[fd
] = cur_file_ptr
->file_index
;
if (delete_ifd
> 0) /* just in case */
remap_file_number
[0] = remap_file_number
[1];
/* Loop, adding each of the external symbols. These must be in
order or otherwise we would have to change the relocation
entries. We don't just call add_bytes, because we need to have
the names put into the external hash table. We set the type to
'void' for now, and parse_def will fill in the correct type if it
is in the symbol table. We must add the external symbols before
the locals, since the locals do lookups against the externals. */
fprintf (stderr
, "\tehash\n");
for (es
= 0; es
< orig_sym_hdr
.iextMax
; es
++)
register EXTR
*eptr
= orig_ext_syms
+ es
;
register char *ename
= ORIG_ESTRS (eptr
->asym
.iss
);
register unsigned ifd
= eptr
->ifd
;
(void) add_ext_symbol (ename
,
(symint_t
)((eptr
->asym
.index
== indexNil
) ? indexNil
: 0),
(ifd
< orig_sym_hdr
.ifdMax
) ? remap_file_number
[ ifd
] : ifd
);
/* For each of the files in the object file, copy the symbols, and such
into the varrays for the new object file. */
for (fd
= delete_ifd
; fd
< orig_sym_hdr
.ifdMax
; fd
++)
register FDR
*fd_ptr
= ORIG_FILES (fd
);
register char *filename
= ORIG_LSTRS (fd_ptr
->issBase
+ fd_ptr
->rss
);
register SYMR
*sym_start
;
register SYMR
*sym_end_p1
;
register PDR
*proc_start
;
register PDR
*proc_end_p1
;
/* file support itself. */
add_file (filename
, filename
+ strlen (filename
));
cur_file_ptr
->orig_fdr
= fd_ptr
;
/* Copy stuff that's just passed through (such as line #'s) */
cur_file_ptr
->fdr
.adr
= fd_ptr
->adr
;
cur_file_ptr
->fdr
.ilineBase
= fd_ptr
->ilineBase
;
cur_file_ptr
->fdr
.cline
= fd_ptr
->cline
;
cur_file_ptr
->fdr
.rfdBase
= fd_ptr
->rfdBase
;
cur_file_ptr
->fdr
.crfd
= fd_ptr
->crfd
;
cur_file_ptr
->fdr
.cbLineOffset
= fd_ptr
->cbLineOffset
;
cur_file_ptr
->fdr
.cbLine
= fd_ptr
->cbLine
;
cur_file_ptr
->fdr
.fMerge
= fd_ptr
->fMerge
;
cur_file_ptr
->fdr
.fReadin
= fd_ptr
->fReadin
;
cur_file_ptr
->fdr
.glevel
= fd_ptr
->glevel
;
fprintf (stderr
, "\thash\tstart, filename %s\n", filename
);
/* For each of the static and global symbols defined, add them
to the hash table of original symbols, so we can look up
sym_start
= ORIG_LSYMS (fd_ptr
->isymBase
);
sym_end_p1
= sym_start
+ fd_ptr
->csym
;
for (sym
= sym_start
; sym
< sym_end_p1
; sym
++)
auto symint_t hash_index
;
register char *str
= ORIG_LSTRS (fd_ptr
->issBase
+ sym
->iss
);
register Size_t len
= strlen (str
);
register shash_t
*shash_ptr
= hash_string (str
,
if (shash_ptr
!= (shash_t
*)0)
error ("internal error, %s is already in original symbol table", str
);
shash_ptr
= allocate_shash ();
shash_ptr
->next
= orig_str_hash
[hash_index
];
orig_str_hash
[hash_index
] = shash_ptr
;
shash_ptr
->indx
= indexNil
;
shash_ptr
->sym_ptr
= sym
;
if ((sc_t
) sym
->sc
== sc_Text
)
register char *str
= ORIG_LSTRS (fd_ptr
->issBase
+ sym
->iss
);
register Size_t len
= strlen (str
);
register shash_t
*shash_ptr
= hash_string (str
,
if (shash_ptr
!= (shash_t
*)0)
shash_ptr
->end_ptr
= sym
;
fprintf (stderr
, "\thash\tdone, filename %s\n", filename
);
fprintf (stderr
, "\tproc\tstart, filename %s\n", filename
);
/* Go through each of the procedures in this file, and add the
procedure pointer to the hash entry for the given name. */
proc_start
= ORIG_PROCS (fd_ptr
->ipdFirst
);
proc_end_p1
= proc_start
+ fd_ptr
->cpd
;
for (proc
= proc_start
; proc
< proc_end_p1
; proc
++)
register SYMR
*proc_sym
= ORIG_LSYMS (fd_ptr
->isymBase
+ proc
->isym
);
register char *str
= ORIG_LSTRS (fd_ptr
->issBase
+ proc_sym
->iss
);
register Size_t len
= strlen (str
);
register shash_t
*shash_ptr
= hash_string (str
,
if (shash_ptr
== (shash_t
*)0)
error ("internal error, function %s is not in original symbol table", str
);
shash_ptr
->proc_ptr
= proc
;
fprintf (stderr
, "\tproc\tdone, filename %s\n", filename
);
cur_file_ptr
= first_file
;
/* Copy all of the object file up to the symbol table. Originally
we were going to use ftruncate, but that doesn't seem to work
if (fseek (obj_in_stream
, (long)0, SEEK_SET
) != 0)
pfatal_with_name (obj_in_name
);
if (fseek (object_stream
, (long)0, SEEK_SET
) != 0)
pfatal_with_name (object_name
);
for (remaining
= orig_file_header
.f_symptr
;
num_write
= (remaining
<= sizeof (buffer
)) ? remaining
: sizeof (buffer
);
sys_read
= fread ((PTR_T
) buffer
, 1, num_write
, obj_in_stream
);
pfatal_with_name (obj_in_name
);
else if (sys_read
!= num_write
)
fatal ("Wanted to read %d bytes from %s, system returned %d",
sys_write
= fwrite (buffer
, 1, num_write
, object_stream
);
pfatal_with_name (object_name
);
else if (sys_write
!= num_write
)
fatal ("Wrote %d bytes to %s, system returned %d",
/* Ye olde main program. */
char *p
= local_rindex (argv
[0], '/');
progname
= (p
!= 0) ? p
+1 : argv
[0];
(void) signal (SIGSEGV
, catch_signal
);
(void) signal (SIGBUS
, catch_signal
);
(void) signal (SIGABRT
, catch_signal
);
#if !defined(__SABER__) && !defined(lint)
if (sizeof (efdr_t
) > PAGE_USIZE
)
fatal ("Efdr_t has a sizeof %d bytes, when it should be less than %d",
if (sizeof (page_t
) != PAGE_USIZE
)
fatal ("Page_t has a sizeof %d bytes, when it should be %d",
alloc_counts
[ alloc_type_none
].alloc_name
= "none";
alloc_counts
[ alloc_type_scope
].alloc_name
= "scope";
alloc_counts
[ alloc_type_vlinks
].alloc_name
= "vlinks";
alloc_counts
[ alloc_type_shash
].alloc_name
= "shash";
alloc_counts
[ alloc_type_thash
].alloc_name
= "thash";
alloc_counts
[ alloc_type_tag
].alloc_name
= "tag";
alloc_counts
[ alloc_type_forward
].alloc_name
= "forward";
alloc_counts
[ alloc_type_thead
].alloc_name
= "thead";
alloc_counts
[ alloc_type_varray
].alloc_name
= "varray";
int_type_info
= type_info_init
;
int_type_info
.basic_type
= bt_Int
;
void_type_info
= type_info_init
;
void_type_info
.basic_type
= bt_Void
;
while ((option
= getopt (argc
, argv
, "d:i:I:o:v")) != EOF
)
debug
= strtol (optarg
, &num_end
, 0);
if ((unsigned)debug
> 4 || num_end
== optarg
)
if (rename_output
|| obj_in_name
!= (char *)0)
/* fall through to 'i' case. */
if (obj_in_name
== (char *)0)
if (object_name
== (char *)0)
if (obj_in_name
== (char *)0 && optind
<= argc
- 2)
obj_in_name
= argv
[--argc
];
if (object_name
== (char *)0 && optind
<= argc
- 2)
object_name
= argv
[--argc
];
/* If there is an output name, but no input name use
the same file for both, deleting the name between
opening it for input and opening it for output. */
if (obj_in_name
== (char *)0 && object_name
!= (char *)0)
obj_in_name
= object_name
;
if (object_name
== (char *)0 || had_errors
|| optind
!= argc
- 1)
fprintf (stderr
, "Calling Sequence:\n");
fprintf (stderr
, "\tmips-tfile [-d <num>] [-v] [-i <o-in-file>] -o <o-out-file> <s-file> (or)\n");
fprintf (stderr
, "\tmips-tfile [-d <num>] [-v] [-I <o-in-file>] -o <o-out-file> <s-file> (or)\n");
fprintf (stderr
, "\tmips-tfile [-d <num>] [-v] <s-file> <o-in-file> <o-out-file>\n");
fprintf (stderr
, "Debug levels are:\n");
fprintf (stderr
, " 1\tGeneral debug + trace functions/blocks.\n");
fprintf (stderr
, " 2\tDebug level 1 + trace externals.\n");
fprintf (stderr
, " 3\tDebug level 2 + trace all symbols.\n");
fprintf (stderr
, " 4\tDebug level 3 + trace memory allocations.\n");
fprintf (stderr
, "mips-tfile version %s", version_string
);
if (obj_in_name
== (char *)0)
obj_in_name
= object_name
;
if (rename_output
&& rename (object_name
, obj_in_name
) != 0)
char *buffer
= (char *) allocate_multiple_pages (4);
/* Rename failed, copy input file */
in_fd
= open (object_name
, O_RDONLY
, 0666);
pfatal_with_name (object_name
);
out_fd
= open (obj_in_name
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0666);
pfatal_with_name (obj_in_name
);
while ((len
= read (in_fd
, buffer
, 4*PAGE_SIZE
)) > 0)
len2
= write (out_fd
, buffer
, len
);
pfatal_with_name (object_name
);
fatal ("wrote %d bytes to %s, expected to write %d", len2
, obj_in_name
, len
);
free_multiple_pages ((page_t
*)buffer
, 4);
pfatal_with_name (object_name
);
pfatal_with_name (object_name
);
pfatal_with_name (obj_in_name
);
/* Must open input before output, since the output may be the same file, and
we need to get the input handle before truncating it. */
obj_in_stream
= fopen (obj_in_name
, "r");
if (obj_in_stream
== (FILE *)0)
pfatal_with_name (obj_in_name
);
if (delete_input
&& unlink (obj_in_name
) != 0)
pfatal_with_name (obj_in_name
);
object_stream
= fopen (object_name
, "w");
if (object_stream
== (FILE *)0)
pfatal_with_name (object_name
);
if (strcmp (argv
[optind
], "-") != 0)
input_name
= argv
[optind
];
if (freopen (argv
[optind
], "r", stdin
) != stdin
)
pfatal_with_name (argv
[optind
]);
copy_object (); /* scan & copy object file */
parse_input (); /* scan all of input */
update_headers (); /* write out tfile */
fprintf (stderr
, "\n\tAllocation summary:\n\n");
for (i
= (int)alloc_type_none
; i
< (int)alloc_type_last
; i
++)
if (alloc_counts
[i
].total_alloc
)
"\t%s\t%5d allocation(s), %5d free(s), %2d page(s)\n",
alloc_counts
[i
].alloc_name
,
alloc_counts
[i
].total_alloc
,
alloc_counts
[i
].total_free
,
alloc_counts
[i
].total_pages
);
return (had_errors
) ? 1 : 0;
/* Catch a signal and exit without dumping core. */
(void) signal (signum
, SIG_DFL
); /* just in case... */
fatal (sys_siglist
[signum
]);
/* Print a fatal error message. NAME is the text.
Also include a system error message based on `errno'. */
int save_errno
= errno
; /* just in case.... */
fprintf (stderr
, "%s, %s:%ld ", progname
, input_name
, line_number
);
fprintf (stderr
, "%s:", progname
);
fprintf (stderr
, "[errno = 0] %s\n", msg
);
/* Procedure to abort 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. */
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 */
if (indx
< max
) /* just in case */
fprintf (stderr
, "%s, %s:%ld index %u is out of bounds for %s, max is %u, mips-tfile.c line# %d\n",
progname
, input_name
, line_number
, indx
, str
, max
, prog_line
);
return 0; /* turn off warning messages */
/* Allocate a cluster of pages. USE_MALLOC says that malloc does not
like sbrk's behind it's back (or sbrk isn't available). If we use
sbrk, we assume it gives us zeroed pages. */
allocate_cluster (npages
)
register page_t
*value
= (page_t
*) calloc (npages
, PAGE_USIZE
);
fatal ("Virtual memory exhausted.");
fprintf (stderr
, "\talloc\tnpages = %d, value = 0x%.8x\n", npages
, value
);
allocate_cluster (npages
)
register page_t
*ptr
= (page_t
*) sbrk (0); /* current sbreak */
unsigned long offset
= ((unsigned long) ptr
) & (PAGE_SIZE
- 1);
if (offset
!= 0) /* align to a page boundary */
if (sbrk (PAGE_USIZE
- offset
) == (char *)-1)
pfatal_with_name ("allocate_cluster");
ptr
= (page_t
*) (((char *)ptr
) + PAGE_SIZE
- offset
);
if (sbrk (npages
* PAGE_USIZE
) == (char *)-1)
pfatal_with_name ("allocate_cluster");
fprintf (stderr
, "\talloc\tnpages = %d, value = 0x%.8x\n", npages
, ptr
);
static page_t
*cluster_ptr
= NULL
;
static unsigned pages_left
= 0;
#endif /* MALLOC_CHECK */
/* Allocate some pages (which is initialized to 0). */
allocate_multiple_pages (npages
)
if (pages_left
== 0 && npages
< MAX_CLUSTER_PAGES
)
pages_left
= MAX_CLUSTER_PAGES
;
cluster_ptr
= allocate_cluster (MAX_CLUSTER_PAGES
);
if (npages
<= pages_left
)
page_t
*ptr
= cluster_ptr
;
return allocate_cluster (npages
);
return (page_t
*) xcalloc (npages
, PAGE_SIZE
);
#endif /* MALLOC_CHECK */
/* Release some pages. */
free_multiple_pages (page_ptr
, npages
)
else if ((page_ptr
+ npages
) == cluster_ptr
)
/* otherwise the page is not freed. If more than call is
done, we probably should worry about it, but at present,
the free pages is done right after an allocate. */
free ((char *) page_ptr
);
#endif /* MALLOC_CHECK */
/* Allocate one page (which is initialized to 0). */
allocate_page
__proto((void))
pages_left
= MAX_CLUSTER_PAGES
;
cluster_ptr
= allocate_cluster (MAX_CLUSTER_PAGES
);
return (page_t
*) xcalloc (1, PAGE_SIZE
);
#endif /* MALLOC_CHECK */
/* Allocate scoping information. */
allocate_scope
__proto((void))
static scope_t initial_scope
;
ptr
= alloc_counts
[ (int)alloc_type_scope
].free_list
.f_scope
;
alloc_counts
[ (int)alloc_type_scope
].free_list
.f_scope
= ptr
->free
;
register int unallocated
= alloc_counts
[ (int)alloc_type_scope
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_scope
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (scope_t
);
alloc_counts
[ (int)alloc_type_scope
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_scope
].total_pages
++;
ptr
= &cur_page
->scope
[ --unallocated
];
alloc_counts
[ (int)alloc_type_scope
].unallocated
= unallocated
;
ptr
= (scope_t
*) xmalloc (sizeof (scope_t
));
alloc_counts
[ (int)alloc_type_scope
].total_alloc
++;
/* Free scoping information. */
alloc_counts
[ (int)alloc_type_scope
].total_free
++;
ptr
->free
= alloc_counts
[ (int)alloc_type_scope
].free_list
.f_scope
;
alloc_counts
[ (int)alloc_type_scope
].free_list
.f_scope
= ptr
;
/* Allocate links for pages in a virtual array. */
allocate_vlinks
__proto((void))
static vlinks_t initial_vlinks
;
register int unallocated
= alloc_counts
[ (int)alloc_type_vlinks
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_vlinks
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (vlinks_t
);
alloc_counts
[ (int)alloc_type_vlinks
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_vlinks
].total_pages
++;
ptr
= &cur_page
->vlinks
[ --unallocated
];
alloc_counts
[ (int)alloc_type_vlinks
].unallocated
= unallocated
;
ptr
= (vlinks_t
*) xmalloc (sizeof (vlinks_t
));
alloc_counts
[ (int)alloc_type_vlinks
].total_alloc
++;
/* Allocate string hash buckets. */
allocate_shash
__proto((void))
static shash_t initial_shash
;
register int unallocated
= alloc_counts
[ (int)alloc_type_shash
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_shash
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (shash_t
);
alloc_counts
[ (int)alloc_type_shash
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_shash
].total_pages
++;
ptr
= &cur_page
->shash
[ --unallocated
];
alloc_counts
[ (int)alloc_type_shash
].unallocated
= unallocated
;
ptr
= (shash_t
*) xmalloc (sizeof (shash_t
));
alloc_counts
[ (int)alloc_type_shash
].total_alloc
++;
/* Allocate type hash buckets. */
allocate_thash
__proto((void))
static thash_t initial_thash
;
register int unallocated
= alloc_counts
[ (int)alloc_type_thash
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_thash
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (thash_t
);
alloc_counts
[ (int)alloc_type_thash
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_thash
].total_pages
++;
ptr
= &cur_page
->thash
[ --unallocated
];
alloc_counts
[ (int)alloc_type_thash
].unallocated
= unallocated
;
ptr
= (thash_t
*) xmalloc (sizeof (thash_t
));
alloc_counts
[ (int)alloc_type_thash
].total_alloc
++;
/* Allocate structure, union, or enum tag information. */
allocate_tag
__proto((void))
static tag_t initial_tag
;
ptr
= alloc_counts
[ (int)alloc_type_tag
].free_list
.f_tag
;
alloc_counts
[ (int)alloc_type_tag
].free_list
.f_tag
= ptr
->free
;
register int unallocated
= alloc_counts
[ (int)alloc_type_tag
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_tag
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (tag_t
);
alloc_counts
[ (int)alloc_type_tag
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_tag
].total_pages
++;
ptr
= &cur_page
->tag
[ --unallocated
];
alloc_counts
[ (int)alloc_type_tag
].unallocated
= unallocated
;
ptr
= (tag_t
*) xmalloc (sizeof (tag_t
));
alloc_counts
[ (int)alloc_type_tag
].total_alloc
++;
/* Free scoping information. */
alloc_counts
[ (int)alloc_type_tag
].total_free
++;
ptr
->free
= alloc_counts
[ (int)alloc_type_tag
].free_list
.f_tag
;
alloc_counts
[ (int)alloc_type_tag
].free_list
.f_tag
= ptr
;
/* Allocate forward reference to a yet unknown tag. */
allocate_forward
__proto((void))
static forward_t initial_forward
;
ptr
= alloc_counts
[ (int)alloc_type_forward
].free_list
.f_forward
;
if (ptr
!= (forward_t
*)0)
alloc_counts
[ (int)alloc_type_forward
].free_list
.f_forward
= ptr
->free
;
register int unallocated
= alloc_counts
[ (int)alloc_type_forward
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_forward
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (forward_t
);
alloc_counts
[ (int)alloc_type_forward
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_forward
].total_pages
++;
ptr
= &cur_page
->forward
[ --unallocated
];
alloc_counts
[ (int)alloc_type_forward
].unallocated
= unallocated
;
ptr
= (forward_t
*) xmalloc (sizeof (forward_t
));
alloc_counts
[ (int)alloc_type_forward
].total_alloc
++;
/* Free scoping information. */
alloc_counts
[ (int)alloc_type_forward
].total_free
++;
ptr
->free
= alloc_counts
[ (int)alloc_type_forward
].free_list
.f_forward
;
alloc_counts
[ (int)alloc_type_forward
].free_list
.f_forward
= ptr
;
/* Allocate head of type hash list. */
allocate_thead
__proto((void))
static thead_t initial_thead
;
ptr
= alloc_counts
[ (int)alloc_type_thead
].free_list
.f_thead
;
alloc_counts
[ (int)alloc_type_thead
].free_list
.f_thead
= ptr
->free
;
register int unallocated
= alloc_counts
[ (int)alloc_type_thead
].unallocated
;
register page_t
*cur_page
= alloc_counts
[ (int)alloc_type_thead
].cur_page
;
unallocated
= PAGE_SIZE
/ sizeof (thead_t
);
alloc_counts
[ (int)alloc_type_thead
].cur_page
= cur_page
= allocate_page ();
alloc_counts
[ (int)alloc_type_thead
].total_pages
++;
ptr
= &cur_page
->thead
[ --unallocated
];
alloc_counts
[ (int)alloc_type_thead
].unallocated
= unallocated
;
ptr
= (thead_t
*) xmalloc (sizeof (thead_t
));
alloc_counts
[ (int)alloc_type_thead
].total_alloc
++;
/* Free scoping information. */
alloc_counts
[ (int)alloc_type_thead
].total_free
++;
ptr
->free
= (thead_t
*) alloc_counts
[ (int)alloc_type_thead
].free_list
.f_thead
;
alloc_counts
[ (int)alloc_type_thead
].free_list
.f_thead
= ptr
;
#endif /* MIPS_DEBUGGING_INFO */
/* Output an error message and exit */
fprintf (stderr
, "%s, %s:%ld ", progname
, input_name
, line_number
);
fprintf (stderr
, "%s:", progname
);
format
= va_arg (ap
, char *);
vfprintf (stderr
, format
, ap
);
fprintf (stderr
, "line:\t%s\n", cur_line_start
);
fprintf (stderr
, "%s, %s:%ld ", progname
, input_name
, line_number
);
fprintf (stderr
, "%s:", progname
);
format
= va_arg (ap
, char *);
vfprintf (stderr
, format
, ap
);
fprintf (stderr
, "line:\t%s\n", cur_line_start
);
/* More 'friendly' abort that prints the line and file.
config.h can #define abort fancy_abort if you like that sort of thing. */
fatal ("Internal abort.");
/* When `malloc.c' is compiled with `rcheck' defined,
it calls this function to report clobberage. */
/* Same as `malloc' but report error if no memory available. */
register PTR_T value
= malloc (size
);
fatal ("Virtual memory exhausted.");
fprintf (stderr
, "\tmalloc\tptr = 0x%.8x, size = %10u\n", value
, size
);
/* Same as `calloc' but report error if no memory available. */
register PTR_T value
= calloc (size1
, size2
);
fatal ("Virtual memory exhausted.");
fprintf (stderr
, "\tcalloc\tptr = 0x%.8x, size1 = %10u, size2 = %10u [%u]\n",
value
, size1
, size2
, size1
+size2
);
/* Same as `realloc' but report error if no memory available. */
register PTR_T result
= realloc (ptr
, size
);
fatal ("Virtual memory exhausted.");
fprintf (stderr
, "\trealloc\tptr = 0x%.8x, size = %10u, orig = 0x%.8x\n",
fprintf (stderr
, "\tfree\tptr = 0x%.8x\n", ptr
);
/* Define our own index/rindex, since the local and global symbol
structures as defined by MIPS has an 'index' field. */
local_index (str
, sentinel
)
for ( ; (ch
= *str
) != sentinel
; str
++)
local_rindex (str
, sentinel
)
const char *ret
= (const char *)0;
for ( ; (ch
= *str
) != '\0'; str
++)