1 /* ECOFF object file format.
2 Copyright (C) 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support.
4 This file was put together by Ian Lance Taylor <ian@cygnus.com>. A
5 good deal of it comes directly from mips-tfile.c, by Michael
6 Meissner <meissner@osf.org>.
8 This file is part of GAS.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "coff/internal.h"
27 #include "coff/symconst.h"
28 #include "coff/ecoff.h"
29 #include "aout/stab_gnu.h"
30 #include "../bfd/libcoff.h"
31 #include "../bfd/libecoff.h"
35 /* Why isn't this in coff/sym.h? */
36 #define ST_RFDESCAPE 0xfff
38 /* Why isn't this in listing.h? */
41 /* The ECOFF file format uses COFF style sections, but with a unique
42 debugging format. We just build generic BFD sections since BFD
43 knows how to write them out. The debugging format, however, we
44 must construct here; all BFD knows at the moment is to write it out
45 as a large block of data.
47 We support both COFF style debugging and stabs debugging (the stabs
48 symbols are encapsulated in COFF symbols). This should let us
49 handle anything the compiler might throw at us. Parsing the COFF
50 and stabs debugging information is similar to work done by COFF and
51 a.out targets, but since the result is completely different the
52 code is not shared. */
54 /* Here is a brief description of the MIPS ECOFF symbol table, by
55 Michael Meissner. The MIPS symbol table has the following pieces:
61 +-- Dense number table
69 +-- Relative file descriptors
81 The symbolic header points to each of the other tables, and also
82 contains the number of entries. It also contains a magic number
83 and MIPS compiler version number, such as 2.0.
85 The auxiliary table is a series of 32 bit integers, that are
86 referenced as needed from the local symbol table. Unlike standard
87 COFF, the aux. information does not follow the symbol that uses
88 it, but rather is a separate table. In theory, this would allow
89 the MIPS compilers to collapse duplicate aux. entries, but I've not
90 noticed this happening with the 1.31 compiler suite. The different
91 types of aux. entries are:
93 1) dnLow: Low bound on array dimension.
95 2) dnHigh: High bound on array dimension.
97 3) isym: Index to the local symbol which is the start of the
98 function for the end of function first aux. entry.
100 4) width: Width of structures and bitfields.
102 5) count: Count of ranges for variant part.
104 6) rndx: A relative index into the symbol table. The relative
105 index field has two parts: rfd which is a pointer into the
106 relative file index table or ST_RFDESCAPE which says the next
107 aux. entry is the file number, and index: which is the pointer
108 into the local symbol within a given file table. This is for
109 things like references to types defined in another file.
111 7) Type information: This is like the COFF type bits, except it
112 is 32 bits instead of 16; they still have room to add new
113 basic types; and they can handle more than 6 levels of array,
114 pointer, function, etc. Each type information field contains
115 the following structure members:
117 a) fBitfield: a bit that says this is a bitfield, and the
118 size in bits follows as the next aux. entry.
120 b) continued: a bit that says the next aux. entry is a
121 continuation of the current type information (in case
122 there are more than 6 levels of array/ptr/function).
124 c) bt: an integer containing the base type before adding
125 array, pointer, function, etc. qualifiers. The
126 current base types that I have documentation for are:
129 btAdr -- address - integer same size as ptr
131 btUChar -- unsigned character
133 btUShort -- unsigned short
135 btUInt -- unsigned int
137 btULong -- unsigned long
138 btFloat -- float (real)
139 btDouble -- Double (real)
140 btStruct -- Structure (Record)
141 btUnion -- Union (variant)
143 btTypedef -- defined via a typedef isymRef
144 btRange -- subrange of int
146 btComplex -- fortran complex
147 btDComplex -- fortran double complex
148 btIndirect -- forward or unnamed typedef
149 btFixedDec -- Fixed Decimal
150 btFloatDec -- Float Decimal
151 btString -- Varying Length Character String
152 btBit -- Aligned Bit String
154 btVoid -- Void (MIPS cc revision >= 2.00)
156 d) tq0 - tq5: type qualifier fields as needed. The
157 current type qualifier fields I have documentation for
160 tqNil -- no more qualifiers
164 tqFar -- 8086 far pointers
168 The dense number table is used in the front ends, and disappears by
169 the time the .o is created.
171 With the 1.31 compiler suite, the optimization symbols don't seem
172 to be used as far as I can tell.
174 The linker is the first entity that creates the relative file
175 descriptor table, and I believe it is used so that the individual
176 file table pointers don't have to be rewritten when the objects are
177 merged together into the program file.
179 Unlike COFF, the basic symbol & string tables are split into
180 external and local symbols/strings. The relocation information
181 only goes off of the external symbol table, and the debug
182 information only goes off of the internal symbol table. The
183 external symbols can have links to an appropriate file index and
184 symbol within the file to give it the appropriate type information.
185 Because of this, the external symbols are actually larger than the
186 internal symbols (to contain the link information), and contain the
187 local symbol structure as a member, though this member is not the
188 first member of the external symbol structure (!). I suspect this
189 split is to make strip easier to deal with.
191 Each file table has offsets for where the line numbers, local
192 strings, local symbols, and procedure table starts from within the
193 global tables, and the indexs are reset to 0 for each of those
196 The procedure table contains the binary equivalents of the .ent
197 (start of the function address), .frame (what register is the
198 virtual frame pointer, constant offset from the register to obtain
199 the VFP, and what register holds the return address), .mask/.fmask
200 (bitmask of saved registers, and where the first register is stored
201 relative to the VFP) assembler directives. It also contains the
202 low and high bounds of the line numbers if debugging is turned on.
204 The line number table is a compressed form of the normal COFF line
205 table. Each line number entry is either 1 or 3 bytes long, and
206 contains a signed delta from the previous line, and an unsigned
207 count of the number of instructions this statement takes.
209 The local symbol table contains the following fields:
211 1) iss: index to the local string table giving the name of the
214 2) value: value of the symbol (address, register number, etc.).
216 3) st: symbol type. The current symbol types are:
218 stNil -- Nuthin' special
219 stGlobal -- external symbol
221 stParam -- procedure argument
222 stLocal -- local variable
224 stProc -- External Procedure
225 stBlock -- beginning of block
226 stEnd -- end (of anything)
227 stMember -- member (of anything)
228 stTypedef -- type definition
230 stRegReloc -- register relocation
231 stForward -- forwarding address
232 stStaticProc -- Static procedure
235 4) sc: storage class. The current storage classes are:
237 scText -- text symbol
238 scData -- initialized data symbol
239 scBss -- un-initialized data symbol
240 scRegister -- value of symbol is register number
241 scAbs -- value of symbol is absolute
242 scUndefined -- who knows?
243 scCdbLocal -- variable's value is IN se->va.??
244 scBits -- this is a bit field
245 scCdbSystem -- value is IN debugger's address space
246 scRegImage -- register value saved on stack
247 scInfo -- symbol contains debugger information
248 scUserStruct -- addr in struct user for current process
249 scSData -- load time only small data
250 scSBss -- load time only small common
251 scRData -- load time only read only data
252 scVar -- Var parameter (fortranpascal)
253 scCommon -- common variable
254 scSCommon -- small common
255 scVarRegister -- Var parameter in a register
256 scVariant -- Variant record
257 scSUndefined -- small undefined(external) data
258 scInit -- .init section symbol
260 5) index: pointer to a local symbol or aux. entry.
264 For the following program:
269 printf("Hello World!\n");
273 Mips-tdump produces the following information:
278 timestamp 645311799, Wed Jun 13 17:16:39 1990
279 symbolic header offset 284
280 symbolic header size 96
284 Symbolic header, magic number = 0x7009, vstamp = 1.31:
286 Info Offset Number Bytes
287 ==== ====== ====== =====
289 Line numbers 380 4 4 [13]
291 Procedures Tables 384 1 52
292 Local Symbols 436 16 192
293 Optimization Symbols 0 0 0
294 Auxiliary Symbols 628 39 156
295 Local Strings 784 80 80
296 External Strings 864 144 144
297 File Tables 1008 2 144
299 External Symbols 1152 20 320
303 Name index = 1 Readin = No
304 Merge = No Endian = LITTLE
305 Debug level = G2 Language = C
308 Info Start Number Size Offset
309 ==== ===== ====== ==== ======
310 Local strings 0 15 15 784
311 Local symbols 0 6 72 436
312 Line numbers 0 13 13 380
313 Optimization symbols 0 0 0 0
314 Procedures 0 1 52 384
315 Auxiliary symbols 0 14 56 628
316 Relative Files 0 0 0 0
318 There are 6 local symbols, starting at 436
320 Symbol# 0: "hello2.c"
323 Storage class = Text Index = 6
324 Symbol type = File Value = 0
330 Storage class = Text Index = 12
331 Symbol type = Proc Value = 0
336 Storage class = Text Index = 4
337 Symbol type = Block Value = 8
342 Storage class = Text Index = 2
343 Symbol type = End Value = 28
348 Storage class = Text Index = 1
349 Symbol type = End Value = 52
351 Symbol# 5: "hello2.c"
354 Storage class = Text Index = 0
355 Symbol type = End Value = 0
357 There are 14 auxiliary table entries, starting at 628.
359 * #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
360 * #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
361 * #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0]
362 * #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0]
363 * #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
364 * #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0]
365 * #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0]
366 * #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0]
367 * #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0]
368 * #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0]
369 * #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0]
370 * #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0]
371 #12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0]
372 #13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
374 There are 1 procedure descriptor entries, starting at 0.
376 Procedure descriptor 0:
377 Name index = 10 Name = "main"
378 .mask 0x80000000,-4 .fmask 0x00000000,0
380 Opt. start = -1 Symbols start = 1
381 First line # = 3 Last line # = 6
382 Line Offset = 0 Address = 0x00000000
384 There are 4 bytes holding line numbers, starting at 380.
385 Line 3, delta 0, count 2
386 Line 4, delta 1, count 3
387 Line 5, delta 1, count 2
388 Line 6, delta 1, count 6
390 File #1, "/usr/include/stdio.h"
392 Name index = 1 Readin = No
393 Merge = Yes Endian = LITTLE
394 Debug level = G2 Language = C
397 Info Start Number Size Offset
398 ==== ===== ====== ==== ======
399 Local strings 15 65 65 799
400 Local symbols 6 10 120 508
401 Line numbers 0 0 0 380
402 Optimization symbols 0 0 0 0
404 Auxiliary symbols 14 25 100 684
405 Relative Files 0 0 0 0
407 There are 10 local symbols, starting at 442
409 Symbol# 0: "/usr/include/stdio.h"
412 Storage class = Text Index = 10
413 Symbol type = File Value = 0
418 Storage class = Info Index = 9
419 Symbol type = Block Value = 20
424 Storage class = Info Index = 4
425 Symbol type = Member Value = 0
430 Storage class = Info Index = 15
431 Symbol type = Member Value = 32
436 Storage class = Info Index = 16
437 Symbol type = Member Value = 64
442 Storage class = Info Index = 4
443 Symbol type = Member Value = 96
448 Storage class = Info Index = 3
449 Symbol type = Member Value = 128
454 Storage class = Info Index = 2
455 Symbol type = Member Value = 144
460 Storage class = Info Index = 1
461 Symbol type = End Value = 0
463 Symbol# 9: "/usr/include/stdio.h"
466 Storage class = Text Index = 0
467 Symbol type = End Value = 0
469 There are 25 auxiliary table entries, starting at 642.
471 * #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
472 #15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
473 #16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
474 * #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0]
475 * #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1]
476 * #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
477 * #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4]
478 * #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
479 * #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
480 * #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0]
481 * #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0]
482 * #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
483 * #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
484 * #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
485 * #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
486 * #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
487 * #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
488 * #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
489 * #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
490 * #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
491 * #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
492 * #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
493 * #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
494 * #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
495 * #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
497 There are 0 procedure descriptor entries, starting at 1.
499 There are 20 external symbols, starting at 1152
502 Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
503 String index = 0 Ifd = 1
504 Storage class = Nil Index = 17
505 Symbol type = Global Value = 60
508 String index = 5 Ifd = 1
509 Storage class = Nil Index = 1048575
510 Symbol type = Proc Value = 0
513 String index = 11 Ifd = 1
514 Storage class = Nil Index = 1048575
515 Symbol type = Proc Value = 0
518 String index = 18 Ifd = 1
519 Storage class = Nil Index = 1048575
520 Symbol type = Proc Value = 0
523 String index = 26 Ifd = 1
524 Storage class = Nil Index = 1048575
525 Symbol type = Proc Value = 0
528 String index = 32 Ifd = 1
529 Storage class = Nil Index = 1048575
530 Symbol type = Proc Value = 0
533 String index = 40 Ifd = 1
534 Storage class = Nil Index = 1048575
535 Symbol type = Proc Value = 0
538 String index = 46 Ifd = 1
539 Storage class = Nil Index = 1048575
540 Symbol type = Proc Value = 0
543 String index = 53 Ifd = 1
544 Storage class = Nil Index = 1048575
545 Symbol type = Proc Value = 0
547 Symbol# 9: "setbuffer"
548 String index = 60 Ifd = 1
549 Storage class = Nil Index = 1048575
550 Symbol type = Proc Value = 0
552 Symbol# 10: "setlinebuf"
553 String index = 70 Ifd = 1
554 Storage class = Nil Index = 1048575
555 Symbol type = Proc Value = 0
558 String index = 81 Ifd = 1
559 Storage class = Nil Index = 1048575
560 Symbol type = Proc Value = 0
563 String index = 87 Ifd = 1
564 Storage class = Nil Index = 1048575
565 Symbol type = Proc Value = 0
567 Symbol# 13: "ctermid"
568 String index = 92 Ifd = 1
569 Storage class = Nil Index = 1048575
570 Symbol type = Proc Value = 0
572 Symbol# 14: "cuserid"
573 String index = 100 Ifd = 1
574 Storage class = Nil Index = 1048575
575 Symbol type = Proc Value = 0
577 Symbol# 15: "tempnam"
578 String index = 108 Ifd = 1
579 Storage class = Nil Index = 1048575
580 Symbol type = Proc Value = 0
583 String index = 116 Ifd = 1
584 Storage class = Nil Index = 1048575
585 Symbol type = Proc Value = 0
587 Symbol# 17: "sprintf"
588 String index = 123 Ifd = 1
589 Storage class = Nil Index = 1048575
590 Symbol type = Proc Value = 0
594 String index = 131 Ifd = 0
595 Storage class = Text Index = 1
596 Symbol type = Proc Value = 0
599 String index = 136 Ifd = 0
600 Storage class = Undefined Index = 1048575
601 Symbol type = Proc Value = 0
603 The following auxiliary table entries were unused:
607 #3 16 0x00000010 short
609 #5 32 0x00000020 long
610 #6 40 0x00000028 float
611 #7 44 0x0000002c double
612 #8 12 0x0000000c unsigned char
613 #9 20 0x00000014 unsigned short
614 #10 28 0x0000001c unsigned int
615 #11 36 0x00000024 unsigned long
616 #14 0 0x00000000 void
617 #15 24 0x00000018 int
618 #19 32 0x00000020 long
619 #20 40 0x00000028 float
620 #21 44 0x0000002c double
621 #22 12 0x0000000c unsigned char
622 #23 20 0x00000014 unsigned short
623 #24 28 0x0000001c unsigned int
624 #25 36 0x00000024 unsigned long
625 #26 48 0x00000030 struct no name { ifd = -1, index = 1048575 }
628 /* Redefinition of of storage classes as an enumeration for better
632 sc_Nil
= scNil
, /* no storage class */
633 sc_Text
= scText
, /* text symbol */
634 sc_Data
= scData
, /* initialized data symbol */
635 sc_Bss
= scBss
, /* un-initialized data symbol */
636 sc_Register
= scRegister
, /* value of symbol is register number */
637 sc_Abs
= scAbs
, /* value of symbol is absolute */
638 sc_Undefined
= scUndefined
, /* who knows? */
639 sc_CdbLocal
= scCdbLocal
, /* variable's value is IN se->va.?? */
640 sc_Bits
= scBits
, /* this is a bit field */
641 sc_CdbSystem
= scCdbSystem
, /* value is IN CDB's address space */
642 sc_RegImage
= scRegImage
, /* register value saved on stack */
643 sc_Info
= scInfo
, /* symbol contains debugger information */
644 sc_UserStruct
= scUserStruct
, /* addr in struct user for current process */
645 sc_SData
= scSData
, /* load time only small data */
646 sc_SBss
= scSBss
, /* load time only small common */
647 sc_RData
= scRData
, /* load time only read only data */
648 sc_Var
= scVar
, /* Var parameter (fortran,pascal) */
649 sc_Common
= scCommon
, /* common variable */
650 sc_SCommon
= scSCommon
, /* small common */
651 sc_VarRegister
= scVarRegister
, /* Var parameter in a register */
652 sc_Variant
= scVariant
, /* Variant record */
653 sc_SUndefined
= scSUndefined
, /* small undefined(external) data */
654 sc_Init
= scInit
, /* .init section symbol */
655 sc_Max
= scMax
/* Max storage class+1 */
658 /* Redefinition of symbol type. */
661 st_Nil
= stNil
, /* Nuthin' special */
662 st_Global
= stGlobal
, /* external symbol */
663 st_Static
= stStatic
, /* static */
664 st_Param
= stParam
, /* procedure argument */
665 st_Local
= stLocal
, /* local variable */
666 st_Label
= stLabel
, /* label */
667 st_Proc
= stProc
, /* " " Procedure */
668 st_Block
= stBlock
, /* beginning of block */
669 st_End
= stEnd
, /* end (of anything) */
670 st_Member
= stMember
, /* member (of anything - struct/union/enum */
671 st_Typedef
= stTypedef
, /* type definition */
672 st_File
= stFile
, /* file name */
673 st_RegReloc
= stRegReloc
, /* register relocation */
674 st_Forward
= stForward
, /* forwarding address */
675 st_StaticProc
= stStaticProc
, /* load time only static procs */
676 st_Constant
= stConstant
, /* const */
677 st_Str
= stStr
, /* string */
678 st_Number
= stNumber
, /* pure number (ie. 4 NOR 2+2) */
679 st_Expr
= stExpr
, /* 2+2 vs. 4 */
680 st_Type
= stType
, /* post-coercion SER */
681 st_Max
= stMax
/* max type+1 */
684 /* Redefinition of type qualifiers. */
687 tq_Nil
= tqNil
, /* bt is what you see */
688 tq_Ptr
= tqPtr
, /* pointer */
689 tq_Proc
= tqProc
, /* procedure */
690 tq_Array
= tqArray
, /* duh */
691 tq_Far
= tqFar
, /* longer addressing - 8086/8 land */
692 tq_Vol
= tqVol
, /* volatile */
693 tq_Max
= tqMax
/* Max type qualifier+1 */
696 /* Redefinition of basic types. */
699 bt_Nil
= btNil
, /* undefined */
700 bt_Adr
= btAdr
, /* address - integer same size as pointer */
701 bt_Char
= btChar
, /* character */
702 bt_UChar
= btUChar
, /* unsigned character */
703 bt_Short
= btShort
, /* short */
704 bt_UShort
= btUShort
, /* unsigned short */
705 bt_Int
= btInt
, /* int */
706 bt_UInt
= btUInt
, /* unsigned int */
707 bt_Long
= btLong
, /* long */
708 bt_ULong
= btULong
, /* unsigned long */
709 bt_Float
= btFloat
, /* float (real) */
710 bt_Double
= btDouble
, /* Double (real) */
711 bt_Struct
= btStruct
, /* Structure (Record) */
712 bt_Union
= btUnion
, /* Union (variant) */
713 bt_Enum
= btEnum
, /* Enumerated */
714 bt_Typedef
= btTypedef
, /* defined via a typedef, isymRef points */
715 bt_Range
= btRange
, /* subrange of int */
716 bt_Set
= btSet
, /* pascal sets */
717 bt_Complex
= btComplex
, /* fortran complex */
718 bt_DComplex
= btDComplex
, /* fortran double complex */
719 bt_Indirect
= btIndirect
, /* forward or unnamed typedef */
720 bt_FixedDec
= btFixedDec
, /* Fixed Decimal */
721 bt_FloatDec
= btFloatDec
, /* Float Decimal */
722 bt_String
= btString
, /* Varying Length Character String */
723 bt_Bit
= btBit
, /* Aligned Bit String */
724 bt_Picture
= btPicture
, /* Picture */
725 bt_Void
= btVoid
, /* Void */
726 bt_Max
= btMax
/* Max basic type+1 */
731 /* States for whether to hash type or not. */
732 typedef enum hash_state
{
733 hash_no
= 0, /* don't hash type */
734 hash_yes
= 1, /* ok to hash type, or use previous hash */
735 hash_record
= 2 /* ok to record hash, but don't use prev. */
738 /* Types of different sized allocation requests. */
740 alloc_type_none
, /* dummy value */
741 alloc_type_scope
, /* nested scopes linked list */
742 alloc_type_vlinks
, /* glue linking pages in varray */
743 alloc_type_shash
, /* string hash element */
744 alloc_type_thash
, /* type hash element */
745 alloc_type_tag
, /* struct/union/tag element */
746 alloc_type_forward
, /* element to hold unknown tag */
747 alloc_type_thead
, /* head of type hash list */
748 alloc_type_varray
, /* general varray allocation */
749 alloc_type_lineno
, /* line number list */
750 alloc_type_last
/* last+1 element for array bounds */
753 /* Types of auxiliary type information. */
755 aux_tir
, /* TIR type information */
756 aux_rndx
, /* relative index into symbol table */
757 aux_dnLow
, /* low dimension */
758 aux_dnHigh
, /* high dimension */
759 aux_isym
, /* symbol table index (end of proc) */
760 aux_iss
, /* index into string space (not used) */
761 aux_width
, /* width for non-default sized struc fields */
762 aux_count
/* count of ranges for variant arm */
765 /* Structures to provide n-number of virtual arrays, each of which can
766 grow linearly, and which are written in the object file as
767 sequential pages. On systems with a BSD malloc, the
768 MAX_CLUSTER_PAGES should be 1 less than a power of two, since
769 malloc adds it's overhead, and rounds up to the next power of 2.
770 Pages are linked together via a linked list.
772 If PAGE_SIZE is > 4096, the string length in the shash_t structure
773 can't be represented (assuming there are strings > 4096 bytes). */
776 #define PAGE_SIZE 4096 /* size of varray pages */
779 #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
782 #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
783 #define MAX_CLUSTER_PAGES 63
787 /* Linked list connecting separate page allocations. */
788 typedef struct vlinks
{
789 struct vlinks
*prev
; /* previous set of pages */
790 struct vlinks
*next
; /* next set of pages */
791 union page
*datum
; /* start of page */
792 unsigned long start_index
; /* starting index # of page */
796 /* Virtual array header. */
797 typedef struct varray
{
798 vlinks_t
*first
; /* first page link */
799 vlinks_t
*last
; /* last page link */
800 unsigned long num_allocated
; /* # objects allocated */
801 unsigned short object_size
; /* size in bytes of each object */
802 unsigned short objects_per_page
; /* # objects that can fit on a page */
803 unsigned short objects_last_page
; /* # objects allocated on last page */
807 #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
809 #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
812 #define INIT_VARRAY(type) { /* macro to initialize a varray */ \
813 (vlinks_t *)0, /* first */ \
814 (vlinks_t *)0, /* last */ \
815 0, /* num_allocated */ \
816 sizeof (type), /* object_size */ \
817 OBJECTS_PER_PAGE (type), /* objects_per_page */ \
818 OBJECTS_PER_PAGE (type), /* objects_last_page */ \
822 /* Master type for indexes within the symbol table. */
823 typedef unsigned long symint_t
;
826 /* Linked list support for nested scopes (file, block, structure, etc.). */
827 typedef struct scope
{
828 struct scope
*prev
; /* previous scope level */
829 struct scope
*free
; /* free list pointer */
830 struct localsym
*lsym
; /* pointer to local symbol node */
831 st_t type
; /* type of the node */
835 /* For a local symbol we store a gas symbol as well as the debugging
836 information we generate. The gas symbol will be NULL if this is
837 only a debugging symbol. */
838 typedef struct localsym
{
839 const char *name
; /* symbol name */
840 symbolS
*as_sym
; /* symbol as seen by gas */
841 struct efdr
*file_ptr
; /* file pointer */
842 struct ecoff_proc
*proc_ptr
; /* proc pointer */
843 struct localsym
*begin_ptr
; /* symbol at start of block */
844 struct ecoff_aux
*index_ptr
; /* index value to be filled in */
845 struct forward
*forward_ref
; /* forward references to this symbol */
846 long sym_index
; /* final symbol index */
847 SYMR ecoff_sym
; /* ECOFF debugging symbol */
851 /* For aux information we keep the type and the data. */
852 typedef struct ecoff_aux
{
853 enum aux_type type
; /* aux type */
854 AUXU data
; /* aux data */
857 /* For a procedure we store the gas symbol as well as the PDR
858 debugging information. */
859 typedef struct ecoff_proc
{
860 localsym_t
*sym
; /* associated symbol */
861 PDR pdr
; /* ECOFF debugging info */
864 /* Number of proc_t structures allocated. */
865 static unsigned long proc_cnt
;
868 /* Forward reference list for tags referenced, but not yet defined. */
869 typedef struct forward
{
870 struct forward
*next
; /* next forward reference */
871 struct forward
*free
; /* free list pointer */
872 aux_t
*ifd_ptr
; /* pointer to store file index */
873 aux_t
*index_ptr
; /* pointer to store symbol index */
877 /* Linked list support for tags. The first tag in the list is always
878 the current tag for that block. */
880 struct tag
*free
; /* free list pointer */
881 struct shash
*hash_ptr
; /* pointer to the hash table head */
882 struct tag
*same_name
; /* tag with same name in outer scope */
883 struct tag
*same_block
; /* next tag defined in the same block. */
884 struct forward
*forward_ref
; /* list of forward references */
885 bt_t basic_type
; /* bt_Struct, bt_Union, or bt_Enum */
886 symint_t ifd
; /* file # tag defined in */
887 localsym_t
*sym
; /* file's local symbols */
891 /* Head of a block's linked list of tags. */
892 typedef struct thead
{
893 struct thead
*prev
; /* previous block */
894 struct thead
*free
; /* free list pointer */
895 struct tag
*first_tag
; /* first tag in block defined */
899 /* Union containing pointers to each the small structures which are freed up. */
900 typedef union small_free
{
901 scope_t
*f_scope
; /* scope structure */
902 thead_t
*f_thead
; /* tag head structure */
903 tag_t
*f_tag
; /* tag element structure */
904 forward_t
*f_forward
; /* forward tag reference */
908 /* String hash table entry. */
910 typedef struct shash
{
911 char *string
; /* string we are hashing */
912 symint_t indx
; /* index within string table */
913 EXTR
*esym_ptr
; /* global symbol pointer */
914 localsym_t
*sym_ptr
; /* local symbol pointer */
915 localsym_t
*end_ptr
; /* symbol pointer to end block */
916 tag_t
*tag_ptr
; /* tag pointer */
917 proc_t
*proc_ptr
; /* procedure descriptor pointer */
921 /* Type hash table support. The size of the hash table must fit
922 within a page with the other extended file descriptor information.
923 Because unique types which are hashed are fewer in number than
924 strings, we use a smaller hash value. */
929 #define THASH_SIZE 113
932 typedef struct thash
{
933 struct thash
*next
; /* next hash value */
934 AUXU type
; /* type we are hashing */
935 symint_t indx
; /* index within string table */
939 /* Extended file descriptor that contains all of the support necessary
940 to add things to each file separately. */
941 typedef struct efdr
{
942 FDR fdr
; /* File header to be written out */
943 FDR
*orig_fdr
; /* original file header */
944 char *name
; /* filename */
945 symint_t void_type
; /* aux. pointer to 'void' type */
946 symint_t int_type
; /* aux. pointer to 'int' type */
947 scope_t
*cur_scope
; /* current nested scopes */
948 symint_t file_index
; /* current file number */
949 int nested_scopes
; /* # nested scopes */
950 varray_t strings
; /* local strings */
951 varray_t symbols
; /* local symbols */
952 varray_t procs
; /* procedures */
953 varray_t aux_syms
; /* auxiliary symbols */
954 struct efdr
*next_file
; /* next file descriptor */
955 /* string/type hash tables */
956 struct hash_control
*str_hash
; /* string hash table */
957 thash_t
*thash_head
[THASH_SIZE
];
960 /* Pre-initialized extended file structure. */
961 static const efdr_t init_file
=
963 { /* FDR structure */
964 0, /* adr: memory address of beginning of file */
965 0, /* rss: file name (of source, if known) */
966 0, /* issBase: file's string space */
967 0, /* cbSs: number of bytes in the ss */
968 0, /* isymBase: beginning of symbols */
969 0, /* csym: count file's of symbols */
970 0, /* ilineBase: file's line symbols */
971 0, /* cline: count of file's line symbols */
972 0, /* ioptBase: file's optimization entries */
973 0, /* copt: count of file's optimization entries */
974 0, /* ipdFirst: start of procedures for this file */
975 0, /* cpd: count of procedures for this file */
976 0, /* iauxBase: file's auxiliary entries */
977 0, /* caux: count of file's auxiliary entries */
978 0, /* rfdBase: index into the file indirect table */
979 0, /* crfd: count file indirect entries */
980 langC
, /* lang: language for this file */
981 0, /* fMerge: whether this file can be merged */
982 0, /* fReadin: true if read in (not just created) */
983 #ifdef TARGET_BYTES_BIG_ENDIAN
984 1, /* fBigendian: if 1, compiled on big endian machine */
986 0, /* fBigendian: if 1, compiled on big endian machine */
988 GLEVEL_2
, /* glevel: level this file was compiled with */
989 0, /* reserved: reserved for future use */
990 0, /* cbLineOffset: byte offset from header for this file ln's */
991 0, /* cbLine: size of lines for this file */
994 (FDR
*)0, /* orig_fdr: original file header pointer */
995 (char *)0, /* name: pointer to filename */
996 0, /* void_type: ptr to aux node for void type */
997 0, /* int_type: ptr to aux node for int type */
998 (scope_t
*)0, /* cur_scope: current scope being processed */
999 0, /* file_index: current file # */
1000 0, /* nested_scopes: # nested scopes */
1001 INIT_VARRAY (char), /* strings: local string varray */
1002 INIT_VARRAY (localsym_t
), /* symbols: local symbols varray */
1003 INIT_VARRAY (proc_t
), /* procs: procedure varray */
1004 INIT_VARRAY (aux_t
), /* aux_syms: auxiliary symbols varray */
1006 (struct efdr
*)0, /* next_file: next file structure */
1008 (struct hash_control
*)0, /* str_hash: string hash table */
1009 { 0 }, /* thash_head: type hash table */
1013 static efdr_t
*first_file
; /* first file descriptor */
1014 static efdr_t
**last_file_ptr
= &first_file
; /* file descriptor tail */
1017 /* Line number information is kept in a list until the assembly is
1019 typedef struct lineno_list
{
1020 struct lineno_list
*next
; /* next element in list */
1021 efdr_t
*file
; /* file this line is in */
1022 proc_t
*proc
; /* procedure this line is in */
1023 fragS
*frag
; /* fragment this line number is in */
1024 unsigned long paddr
; /* offset within fragment */
1025 long lineno
; /* actual line number */
1028 static lineno_list_t
*first_lineno
;
1029 static lineno_list_t
**last_lineno_ptr
= &first_lineno
;
1031 /* Sometimes there will be some .loc statements before a .ent. We
1032 keep them in this list so that we can fill in the procedure pointer
1033 after we see the .ent. */
1034 static lineno_list_t
*noproc_lineno
;
1036 /* Union of various things that are held in pages. */
1037 typedef union page
{
1038 char byte
[ PAGE_SIZE
];
1039 unsigned char ubyte
[ PAGE_SIZE
];
1040 efdr_t file
[ PAGE_SIZE
/ sizeof (efdr_t
) ];
1041 FDR ofile
[ PAGE_SIZE
/ sizeof (FDR
) ];
1042 proc_t proc
[ PAGE_SIZE
/ sizeof (proc_t
) ];
1043 localsym_t sym
[ PAGE_SIZE
/ sizeof (localsym_t
) ];
1044 aux_t aux
[ PAGE_SIZE
/ sizeof (aux_t
) ];
1045 DNR dense
[ PAGE_SIZE
/ sizeof (DNR
) ];
1046 scope_t scope
[ PAGE_SIZE
/ sizeof (scope_t
) ];
1047 vlinks_t vlinks
[ PAGE_SIZE
/ sizeof (vlinks_t
) ];
1048 shash_t shash
[ PAGE_SIZE
/ sizeof (shash_t
) ];
1049 thash_t thash
[ PAGE_SIZE
/ sizeof (thash_t
) ];
1050 tag_t tag
[ PAGE_SIZE
/ sizeof (tag_t
) ];
1051 forward_t forward
[ PAGE_SIZE
/ sizeof (forward_t
) ];
1052 thead_t thead
[ PAGE_SIZE
/ sizeof (thead_t
) ];
1053 lineno_list_t lineno
[ PAGE_SIZE
/ sizeof (lineno_list_t
) ];
1057 /* Structure holding allocation information for small sized structures. */
1058 typedef struct alloc_info
{
1059 char *alloc_name
; /* name of this allocation type (must be first) */
1060 page_t
*cur_page
; /* current page being allocated from */
1061 small_free_t free_list
; /* current free list if any */
1062 int unallocated
; /* number of elements unallocated on page */
1063 int total_alloc
; /* total number of allocations */
1064 int total_free
; /* total number of frees */
1065 int total_pages
; /* total number of pages allocated */
1069 /* Type information collected together. */
1070 typedef struct type_info
{
1071 bt_t basic_type
; /* basic type */
1072 int orig_type
; /* original COFF-based type */
1073 int num_tq
; /* # type qualifiers */
1074 int num_dims
; /* # dimensions */
1075 int num_sizes
; /* # sizes */
1076 int extra_sizes
; /* # extra sizes not tied with dims */
1077 tag_t
* tag_ptr
; /* tag pointer */
1078 int bitfield
; /* symbol is a bitfield */
1079 tq_t type_qualifiers
[N_TQ
]; /* type qualifiers (ptr, func, array)*/
1080 symint_t dimensions
[N_TQ
]; /* dimensions for each array */
1081 symint_t sizes
[N_TQ
+2]; /* sizes of each array slice + size of
1082 struct/union/enum + bitfield size */
1085 /* Pre-initialized type_info struct. */
1086 static const type_info_t type_info_init
= {
1087 bt_Nil
, /* basic type */
1088 T_NULL
, /* original COFF-based type */
1089 0, /* # type qualifiers */
1090 0, /* # dimensions */
1092 0, /* sizes not tied with dims */
1093 NULL
, /* ptr to tag */
1095 { /* type qualifiers */
1123 /* Global hash table for the tags table and global table for file
1126 static varray_t file_desc
= INIT_VARRAY (efdr_t
);
1128 static struct hash_control
*tag_hash
;
1130 /* Static types for int and void. Also, remember the last function's
1131 type (which is set up when we encounter the declaration for the
1132 function, and used when the end block for the function is emitted. */
1134 static type_info_t int_type_info
;
1135 static type_info_t void_type_info
;
1136 static type_info_t last_func_type_info
;
1137 static symbolS
*last_func_sym_value
;
1140 /* Convert COFF basic type to ECOFF basic type. The T_NULL type
1141 really should use bt_Void, but this causes the current ecoff GDB to
1142 issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
1143 2.0) doesn't understand it, even though the compiler generates it.
1144 Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
1145 suite, but for now go with what works.
1147 It would make sense for the .type and .scl directives to use the
1148 ECOFF numbers directly, rather than using the COFF numbers and
1149 mapping them. Unfortunately, this is historically what mips-tfile
1150 expects, and changing gcc now would be a considerable pain (the
1151 native compiler generates debugging information internally, rather
1152 than via the assembler, so it will never use .type or .scl). */
1154 static const bt_t map_coff_types
[] = {
1155 bt_Nil
, /* T_NULL */
1157 bt_Char
, /* T_CHAR */
1158 bt_Short
, /* T_SHORT */
1160 bt_Long
, /* T_LONG */
1161 bt_Float
, /* T_FLOAT */
1162 bt_Double
, /* T_DOUBLE */
1163 bt_Struct
, /* T_STRUCT */
1164 bt_Union
, /* T_UNION */
1165 bt_Enum
, /* T_ENUM */
1166 bt_Enum
, /* T_MOE */
1167 bt_UChar
, /* T_UCHAR */
1168 bt_UShort
, /* T_USHORT */
1169 bt_UInt
, /* T_UINT */
1170 bt_ULong
/* T_ULONG */
1173 /* Convert COFF storage class to ECOFF storage class. */
1174 static const sc_t map_coff_storage
[] = {
1175 sc_Nil
, /* 0: C_NULL */
1176 sc_Abs
, /* 1: C_AUTO auto var */
1177 sc_Undefined
, /* 2: C_EXT external */
1178 sc_Data
, /* 3: C_STAT static */
1179 sc_Register
, /* 4: C_REG register */
1180 sc_Undefined
, /* 5: C_EXTDEF ??? */
1181 sc_Text
, /* 6: C_LABEL label */
1182 sc_Text
, /* 7: C_ULABEL user label */
1183 sc_Info
, /* 8: C_MOS member of struct */
1184 sc_Abs
, /* 9: C_ARG argument */
1185 sc_Info
, /* 10: C_STRTAG struct tag */
1186 sc_Info
, /* 11: C_MOU member of union */
1187 sc_Info
, /* 12: C_UNTAG union tag */
1188 sc_Info
, /* 13: C_TPDEF typedef */
1189 sc_Data
, /* 14: C_USTATIC ??? */
1190 sc_Info
, /* 15: C_ENTAG enum tag */
1191 sc_Info
, /* 16: C_MOE member of enum */
1192 sc_Register
, /* 17: C_REGPARM register parameter */
1193 sc_Bits
, /* 18; C_FIELD bitfield */
1275 sc_Text
, /* 100: C_BLOCK block start/end */
1276 sc_Text
, /* 101: C_FCN function start/end */
1277 sc_Info
, /* 102: C_EOS end of struct/union/enum */
1278 sc_Nil
, /* 103: C_FILE file start */
1279 sc_Nil
, /* 104: C_LINE line number */
1280 sc_Nil
, /* 105: C_ALIAS combined type info */
1281 sc_Nil
, /* 106: C_HIDDEN ??? */
1284 /* Convert COFF storage class to ECOFF symbol type. */
1285 static const st_t map_coff_sym_type
[] = {
1286 st_Nil
, /* 0: C_NULL */
1287 st_Local
, /* 1: C_AUTO auto var */
1288 st_Global
, /* 2: C_EXT external */
1289 st_Static
, /* 3: C_STAT static */
1290 st_Local
, /* 4: C_REG register */
1291 st_Global
, /* 5: C_EXTDEF ??? */
1292 st_Label
, /* 6: C_LABEL label */
1293 st_Label
, /* 7: C_ULABEL user label */
1294 st_Member
, /* 8: C_MOS member of struct */
1295 st_Param
, /* 9: C_ARG argument */
1296 st_Block
, /* 10: C_STRTAG struct tag */
1297 st_Member
, /* 11: C_MOU member of union */
1298 st_Block
, /* 12: C_UNTAG union tag */
1299 st_Typedef
, /* 13: C_TPDEF typedef */
1300 st_Static
, /* 14: C_USTATIC ??? */
1301 st_Block
, /* 15: C_ENTAG enum tag */
1302 st_Member
, /* 16: C_MOE member of enum */
1303 st_Param
, /* 17: C_REGPARM register parameter */
1304 st_Member
, /* 18; C_FIELD bitfield */
1386 st_Block
, /* 100: C_BLOCK block start/end */
1387 st_Proc
, /* 101: C_FCN function start/end */
1388 st_End
, /* 102: C_EOS end of struct/union/enum */
1389 st_File
, /* 103: C_FILE file start */
1390 st_Nil
, /* 104: C_LINE line number */
1391 st_Nil
, /* 105: C_ALIAS combined type info */
1392 st_Nil
, /* 106: C_HIDDEN ??? */
1396 /* Keep track of different sized allocation requests. */
1397 static alloc_info_t alloc_counts
[ (int)alloc_type_last
];
1399 /* Various statics. */
1400 static efdr_t
*cur_file_ptr
= (efdr_t
*) 0; /* current file desc. header */
1401 static proc_t
*cur_proc_ptr
= (proc_t
*) 0; /* current procedure header */
1402 static thead_t
*top_tag_head
= (thead_t
*) 0; /* top level tag head */
1403 static thead_t
*cur_tag_head
= (thead_t
*) 0; /* current tag head */
1405 static int debug
= 0; /* trace functions */
1407 static int stabs_seen
= 0; /* != 0 if stabs have been seen */
1410 /* Pseudo symbol to use when putting stabs into the symbol table. */
1411 #ifndef STABS_SYMBOL
1412 #define STABS_SYMBOL "@stabs"
1415 static char stabs_symbol
[] = STABS_SYMBOL
;
1417 /* Prototypes for functions defined in this file. */
1419 static void add_varray_page
PARAMS ((varray_t
*vp
));
1420 static symint_t add_string
PARAMS ((varray_t
*vp
,
1421 struct hash_control
*hash_tbl
,
1423 shash_t
**ret_hash
));
1424 static localsym_t
*add_ecoff_symbol
PARAMS ((const char *str
, st_t type
,
1425 sc_t storage
, symbolS
*sym
,
1428 static symint_t add_aux_sym_symint
PARAMS ((symint_t aux_word
));
1429 static symint_t add_aux_sym_rndx
PARAMS ((int file_index
,
1430 symint_t sym_index
));
1431 static symint_t add_aux_sym_tir
PARAMS ((type_info_t
*t
,
1433 thash_t
**hash_tbl
));
1434 static tag_t
*get_tag
PARAMS ((const char *tag
, localsym_t
*sym
,
1436 static void add_unknown_tag
PARAMS ((tag_t
*ptag
));
1437 static void add_procedure
PARAMS ((char *func
));
1438 static void add_file
PARAMS ((const char *file_name
, int indx
));
1440 static char *sc_to_string
PARAMS ((sc_t storage_class
));
1441 static char *st_to_string
PARAMS ((st_t symbol_type
));
1443 static void obj_ecoff_def
PARAMS ((int));
1444 static void obj_ecoff_dim
PARAMS ((int));
1445 static void obj_ecoff_endef
PARAMS ((int));
1446 static void obj_ecoff_file
PARAMS ((int));
1447 static void obj_ecoff_scl
PARAMS ((int));
1448 static void obj_ecoff_size
PARAMS ((int));
1449 static void obj_ecoff_tag
PARAMS ((int));
1450 static void obj_ecoff_type
PARAMS ((int));
1451 static void obj_ecoff_val
PARAMS ((int));
1452 static void obj_ecoff_ent
PARAMS ((int));
1453 static void obj_ecoff_begin
PARAMS ((int));
1454 static void obj_ecoff_bend
PARAMS ((int));
1455 static void obj_ecoff_end
PARAMS ((int));
1456 static void obj_ecoff_fmask
PARAMS ((int));
1457 static void obj_ecoff_frame
PARAMS ((int));
1458 static void obj_ecoff_loc
PARAMS ((int));
1459 static void obj_ecoff_mask
PARAMS ((int));
1460 static void mark_stabs
PARAMS ((int));
1461 static char *ecoff_add_bytes
PARAMS ((char **buf
, char **bufend
,
1462 char *bufptr
, unsigned long need
));
1463 static unsigned long ecoff_padding_adjust
PARAMS ((char **buf
,
1465 unsigned long offset
,
1467 static unsigned long ecoff_build_lineno
PARAMS ((char **buf
, char **bufend
,
1468 unsigned long offset
,
1470 static unsigned long ecoff_build_symbols
PARAMS ((char **buf
, char **bufend
,
1471 unsigned long offset
,
1474 unsigned long *extoffset
,
1475 varray_t
*ext_strings
,
1476 struct hash_control
*));
1477 static unsigned long ecoff_build_procs
PARAMS ((char **buf
, char **bufend
,
1478 unsigned long offset
));
1479 static unsigned long ecoff_build_aux
PARAMS ((char **buf
, char **bufend
,
1480 unsigned long offset
));
1481 static unsigned long ecoff_build_strings
PARAMS ((char **buf
, char **bufend
,
1482 unsigned long offset
,
1484 static unsigned long ecoff_build_ss
PARAMS ((char **buf
, char **bufend
,
1485 unsigned long offset
));
1486 static unsigned long ecoff_build_fdr
PARAMS ((char **buf
, char **bufend
,
1487 unsigned long offset
));
1488 static page_t
*allocate_cluster
PARAMS ((unsigned long npages
));
1489 static page_t
*allocate_page
PARAMS ((void));
1490 static scope_t
*allocate_scope
PARAMS ((void));
1491 static void free_scope
PARAMS ((scope_t
*ptr
));
1492 static vlinks_t
*allocate_vlinks
PARAMS ((void));
1493 static shash_t
*allocate_shash
PARAMS ((void));
1494 static thash_t
*allocate_thash
PARAMS ((void));
1495 static tag_t
*allocate_tag
PARAMS ((void));
1496 static void free_tag
PARAMS ((tag_t
*ptr
));
1497 static forward_t
*allocate_forward
PARAMS ((void));
1498 static thead_t
*allocate_thead
PARAMS ((void));
1499 static void free_thead
PARAMS ((thead_t
*ptr
));
1500 static lineno_list_t
*allocate_lineno_list
PARAMS ((void));
1502 /* Why isn't this in some header file somewhere? In fact, is it even
1504 #define SKIP_WHITESPACES() \
1507 while (*input_line_pointer == ' ' \
1508 || *input_line_pointer == '\t') \
1509 ++input_line_pointer; \
1513 /* These are the pseudo-ops we support in this file. Only those
1514 relating to debugging information are supported here.
1516 The following pseudo-ops from the Kane and Heinrich MIPS book
1517 should be defined here, but are currently unsupported: .aent,
1518 .bgnb, .endb, .verstamp, .vreg.
1520 The following pseudo-ops from the Kane and Heinrich MIPS book are
1521 MIPS CPU specific, and should be defined by tc-mips.c: .alias,
1522 .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option,
1523 .rdata, .sdata, .set.
1525 The following pseudo-ops from the Kane and Heinrich MIPS book are
1526 not MIPS CPU specific, but are also not ECOFF specific. I have
1527 only listed the ones which are not already in read.c. It's not
1528 completely clear where these should be defined, but tc-mips.c is
1529 probably the most reasonable place: .asciiz, .asm0, .endr, .err,
1530 .half, .lab, .repeat, .struct, .weakext. */
1532 const pseudo_typeS obj_pseudo_table
[] =
1534 /* COFF style debugging information. .ln is not used; .loc is used
1536 { "def", obj_ecoff_def
, 0 },
1537 { "dim", obj_ecoff_dim
, 0 },
1538 { "endef", obj_ecoff_endef
, 0 },
1539 { "file", obj_ecoff_file
, 0 },
1540 { "scl", obj_ecoff_scl
, 0 },
1541 { "size", obj_ecoff_size
, 0 },
1542 { "tag", obj_ecoff_tag
, 0 },
1543 { "type", obj_ecoff_type
, 0 },
1544 { "val", obj_ecoff_val
, 0 },
1546 /* ECOFF specific debugging information. */
1547 { "begin", obj_ecoff_begin
, 0 },
1548 { "bend", obj_ecoff_bend
, 0 },
1549 { "end", obj_ecoff_end
, 0 },
1550 { "ent", obj_ecoff_ent
, 0 },
1551 { "fmask", obj_ecoff_fmask
, 0 },
1552 { "frame", obj_ecoff_frame
, 0 },
1553 { "loc", obj_ecoff_loc
, 0 },
1554 { "mask", obj_ecoff_mask
, 0 },
1560 /* This function is called when the assembler starts up. */
1563 obj_read_begin_hook ()
1565 tag_hash
= hash_new ();
1566 top_tag_head
= allocate_thead ();
1567 top_tag_head
->first_tag
= (tag_t
*) NULL
;
1568 top_tag_head
->free
= (thead_t
*) NULL
;
1569 top_tag_head
->prev
= cur_tag_head
;
1570 cur_tag_head
= top_tag_head
;
1573 /* This function is called when a symbol is created. */
1576 obj_symbol_new_hook (symbolP
)
1579 if (cur_file_ptr
== (efdr_t
*) NULL
)
1580 add_file ((const char *) NULL
, 0);
1581 symbolP
->ecoff_file
= cur_file_ptr
;
1582 symbolP
->ecoff_symbol
= 0;
1583 symbolP
->ecoff_undefined
= 0;
1586 /* Add a page to a varray object. */
1589 add_varray_page (vp
)
1590 varray_t
*vp
; /* varray to add page to */
1592 vlinks_t
*new_links
= allocate_vlinks ();
1595 if (vp
->object_size
> 1)
1596 new_links
->datum
= (page_t
*) xcalloc (1, vp
->object_size
);
1599 new_links
->datum
= allocate_page ();
1601 alloc_counts
[(int)alloc_type_varray
].total_alloc
++;
1602 alloc_counts
[(int)alloc_type_varray
].total_pages
++;
1604 new_links
->start_index
= vp
->num_allocated
;
1605 vp
->objects_last_page
= 0;
1607 if (vp
->first
== (vlinks_t
*) NULL
) /* first allocation? */
1608 vp
->first
= vp
->last
= new_links
;
1610 { /* 2nd or greater allocation */
1611 new_links
->prev
= vp
->last
;
1612 vp
->last
->next
= new_links
;
1613 vp
->last
= new_links
;
1617 /* Add a string (and null pad) to one of the string tables. */
1620 add_string (vp
, hash_tbl
, str
, ret_hash
)
1621 varray_t
*vp
; /* string obstack */
1622 struct hash_control
*hash_tbl
; /* ptr to hash table */
1623 const char *str
; /* string */
1624 shash_t
**ret_hash
; /* return hash pointer */
1626 register unsigned long len
= strlen (str
);
1627 register shash_t
*hash_ptr
;
1629 if (len
>= PAGE_USIZE
)
1630 as_fatal ("String too big (%lu bytes)", len
);
1632 hash_ptr
= (shash_t
*) hash_find (hash_tbl
, str
);
1633 if (hash_ptr
== (shash_t
*) NULL
)
1635 register const char *err
;
1637 if (vp
->objects_last_page
+ len
>= PAGE_USIZE
)
1640 ((vp
->num_allocated
+ PAGE_USIZE
- 1) / PAGE_USIZE
) * PAGE_USIZE
;
1641 add_varray_page (vp
);
1644 hash_ptr
= allocate_shash ();
1645 hash_ptr
->indx
= vp
->num_allocated
;
1647 hash_ptr
->string
= &vp
->last
->datum
->byte
[vp
->objects_last_page
];
1649 vp
->objects_last_page
+= len
+ 1;
1650 vp
->num_allocated
+= len
+ 1;
1652 strcpy (hash_ptr
->string
, str
);
1654 err
= hash_insert (hash_tbl
, str
, (char *) hash_ptr
);
1656 as_fatal ("Inserting \"%s\" into string hash table: %s",
1660 if (ret_hash
!= (shash_t
**) NULL
)
1661 *ret_hash
= hash_ptr
;
1663 return hash_ptr
->indx
;
1666 /* Add debugging information for a symbol. */
1669 add_ecoff_symbol (str
, type
, storage
, sym_value
, value
, indx
)
1670 const char *str
; /* symbol name */
1671 st_t type
; /* symbol type */
1672 sc_t storage
; /* storage class */
1673 symbolS
*sym_value
; /* associated symbol. */
1674 symint_t value
; /* value of symbol */
1675 symint_t indx
; /* index to local/aux. syms */
1678 register scope_t
*pscope
;
1679 register thead_t
*ptag_head
;
1680 register tag_t
*ptag
;
1681 register tag_t
*ptag_next
;
1682 register varray_t
*vp
;
1683 register int scope_delta
= 0;
1684 shash_t
*hash_ptr
= (shash_t
*) NULL
;
1686 if (cur_file_ptr
== (efdr_t
*) NULL
)
1687 as_fatal ("no current file pointer");
1689 vp
= &cur_file_ptr
->symbols
;
1691 if (vp
->objects_last_page
== vp
->objects_per_page
)
1692 add_varray_page (vp
);
1694 psym
= &vp
->last
->datum
->sym
[ vp
->objects_last_page
++ ];
1696 if (str
== (const char *) NULL
&& sym_value
!= (symbolS
*) NULL
)
1697 psym
->name
= S_GET_NAME (sym_value
);
1700 psym
->as_sym
= sym_value
;
1701 if (sym_value
!= (symbolS
*) NULL
)
1702 sym_value
->ecoff_symbol
= 1;
1703 psym
->file_ptr
= cur_file_ptr
;
1704 psym
->proc_ptr
= cur_proc_ptr
;
1705 psym
->begin_ptr
= (localsym_t
*) NULL
;
1706 psym
->index_ptr
= (aux_t
*) NULL
;
1707 psym
->forward_ref
= (forward_t
*) NULL
;
1708 psym
->sym_index
= -1;
1709 psym
->ecoff_sym
.value
= value
;
1710 psym
->ecoff_sym
.st
= (unsigned) type
;
1711 psym
->ecoff_sym
.sc
= (unsigned) storage
;
1712 psym
->ecoff_sym
.index
= indx
;
1714 /* If there is an associated symbol, we wait until the end of the
1715 assembly before deciding where to put the name (it may be just an
1716 external symbol). Otherwise, this is just a debugging symbol and
1717 the name should go with the current file. */
1718 if (sym_value
== (symbolS
*) NULL
)
1719 psym
->ecoff_sym
.iss
= ((str
== (const char *) NULL
)
1721 : add_string (&cur_file_ptr
->strings
,
1722 cur_file_ptr
->str_hash
,
1726 ++vp
->num_allocated
;
1728 if (ECOFF_IS_STAB (&psym
->ecoff_sym
))
1731 /* Save the symbol within the hash table if this is a static
1732 item, and it has a name. */
1733 if (hash_ptr
!= (shash_t
*) NULL
1734 && (type
== st_Global
|| type
== st_Static
|| type
== st_Label
1735 || type
== st_Proc
|| type
== st_StaticProc
))
1736 hash_ptr
->sym_ptr
= psym
;
1738 /* push or pop a scope if appropriate. */
1744 case st_File
: /* beginning of file */
1745 case st_Proc
: /* procedure */
1746 case st_StaticProc
: /* static procedure */
1747 case st_Block
: /* begin scope */
1748 pscope
= allocate_scope ();
1749 pscope
->prev
= cur_file_ptr
->cur_scope
;
1750 pscope
->lsym
= psym
;
1751 pscope
->type
= type
;
1752 cur_file_ptr
->cur_scope
= pscope
;
1754 if (type
!= st_File
)
1757 /* For every block type except file, struct, union, or
1758 enumeration blocks, push a level on the tag stack. We omit
1759 file types, so that tags can span file boundaries. */
1760 if (type
!= st_File
&& storage
!= sc_Info
)
1762 ptag_head
= allocate_thead ();
1763 ptag_head
->first_tag
= 0;
1764 ptag_head
->prev
= cur_tag_head
;
1765 cur_tag_head
= ptag_head
;
1770 pscope
= cur_file_ptr
->cur_scope
;
1771 if (pscope
== (scope_t
*) NULL
)
1772 as_fatal ("too many st_End's");
1775 st_t begin_type
= (st_t
) pscope
->lsym
->ecoff_sym
.st
;
1777 psym
->begin_ptr
= pscope
->lsym
;
1779 if (begin_type
!= st_File
)
1782 /* Except for file, structure, union, or enumeration end
1783 blocks remove all tags created within this scope. */
1784 if (begin_type
!= st_File
&& storage
!= sc_Info
)
1786 ptag_head
= cur_tag_head
;
1787 cur_tag_head
= ptag_head
->prev
;
1789 for (ptag
= ptag_head
->first_tag
;
1790 ptag
!= (tag_t
*) NULL
;
1793 if (ptag
->forward_ref
!= (forward_t
*) NULL
)
1794 add_unknown_tag (ptag
);
1796 ptag_next
= ptag
->same_block
;
1797 ptag
->hash_ptr
->tag_ptr
= ptag
->same_name
;
1801 free_thead (ptag_head
);
1804 cur_file_ptr
->cur_scope
= pscope
->prev
;
1806 /* block begin gets next sym #. This is set when we know
1807 the symbol index value. */
1809 /* Functions push two or more aux words as follows:
1810 1st word: index+1 of the end symbol (filled in later).
1811 2nd word: type of the function (plus any aux words needed).
1812 Also, tie the external pointer back to the function begin symbol. */
1813 if (begin_type
!= st_File
&& begin_type
!= st_Block
)
1816 varray_t
*svp
= &cur_file_ptr
->aux_syms
;
1818 pscope
->lsym
->ecoff_sym
.index
= add_aux_sym_symint (0);
1819 pscope
->lsym
->index_ptr
=
1820 &svp
->last
->datum
->aux
[svp
->objects_last_page
- 1];
1821 ty
= add_aux_sym_tir (&last_func_type_info
,
1823 &cur_file_ptr
->thash_head
[0]);
1825 if (last_func_sym_value != (symbolS *) NULL)
1827 last_func_sym_value->ifd = cur_file_ptr->file_index;
1828 last_func_sym_value->index = ty;
1833 free_scope (pscope
);
1837 cur_file_ptr
->nested_scopes
+= scope_delta
;
1840 if (debug
&& type
!= st_File
1841 && (debug
> 2 || type
== st_Block
|| type
== st_End
1842 || type
== st_Proc
|| type
== st_StaticProc
))
1844 char *sc_str
= sc_to_string (storage
);
1845 char *st_str
= st_to_string (type
);
1846 int depth
= cur_file_ptr
->nested_scopes
+ (scope_delta
< 0);
1849 "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
1850 value
, depth
, sc_str
);
1852 if (str_start
&& str_end_p1
- str_start
> 0)
1853 fprintf (stderr
, " st= %-11s name= %.*s\n", st_str
, str_end_p1
- str_start
, str_start
);
1856 unsigned long len
= strlen (st_str
);
1857 fprintf (stderr
, " st= %.*s\n", len
-1, st_str
);
1865 /* Add an auxiliary symbol (passing a symint). This is actually used
1866 for integral aux types, not just symints. */
1869 add_aux_sym_symint (aux_word
)
1870 symint_t aux_word
; /* auxiliary information word */
1872 register varray_t
*vp
;
1873 register aux_t
*aux_ptr
;
1875 if (cur_file_ptr
== (efdr_t
*) NULL
)
1876 as_fatal ("no current file pointer");
1878 vp
= &cur_file_ptr
->aux_syms
;
1880 if (vp
->objects_last_page
== vp
->objects_per_page
)
1881 add_varray_page (vp
);
1883 aux_ptr
= &vp
->last
->datum
->aux
[vp
->objects_last_page
++];
1884 aux_ptr
->type
= aux_isym
;
1885 aux_ptr
->data
.isym
= aux_word
;
1887 return vp
->num_allocated
++;
1891 /* Add an auxiliary symbol (passing a file/symbol index combo). */
1894 add_aux_sym_rndx (file_index
, sym_index
)
1898 register varray_t
*vp
;
1899 register aux_t
*aux_ptr
;
1901 if (cur_file_ptr
== (efdr_t
*) NULL
)
1902 as_fatal ("no current file pointer");
1904 vp
= &cur_file_ptr
->aux_syms
;
1906 if (vp
->objects_last_page
== vp
->objects_per_page
)
1907 add_varray_page (vp
);
1909 aux_ptr
= &vp
->last
->datum
->aux
[vp
->objects_last_page
++];
1910 aux_ptr
->type
= aux_rndx
;
1911 aux_ptr
->data
.rndx
.rfd
= file_index
;
1912 aux_ptr
->data
.rndx
.index
= sym_index
;
1914 return vp
->num_allocated
++;
1917 /* Add an auxiliary symbol (passing the basic type and possibly
1918 type qualifiers). */
1921 add_aux_sym_tir (t
, state
, hash_tbl
)
1922 type_info_t
*t
; /* current type information */
1923 hash_state_t state
; /* whether to hash type or not */
1924 thash_t
**hash_tbl
; /* pointer to hash table to use */
1926 register varray_t
*vp
;
1927 register aux_t
*aux_ptr
;
1928 static AUXU init_aux
;
1933 if (cur_file_ptr
== (efdr_t
*) NULL
)
1934 as_fatal ("no current file pointer");
1936 vp
= &cur_file_ptr
->aux_syms
;
1939 aux
.ti
.bt
= (int) t
->basic_type
;
1940 aux
.ti
.continued
= 0;
1941 aux
.ti
.fBitfield
= t
->bitfield
;
1943 aux
.ti
.tq0
= (int) t
->type_qualifiers
[0];
1944 aux
.ti
.tq1
= (int) t
->type_qualifiers
[1];
1945 aux
.ti
.tq2
= (int) t
->type_qualifiers
[2];
1946 aux
.ti
.tq3
= (int) t
->type_qualifiers
[3];
1947 aux
.ti
.tq4
= (int) t
->type_qualifiers
[4];
1948 aux
.ti
.tq5
= (int) t
->type_qualifiers
[5];
1951 /* For anything that adds additional information, we must not hash,
1952 so check here, and reset our state. */
1954 if (state
!= hash_no
1955 && (t
->type_qualifiers
[0] == tq_Array
1956 || t
->type_qualifiers
[1] == tq_Array
1957 || t
->type_qualifiers
[2] == tq_Array
1958 || t
->type_qualifiers
[3] == tq_Array
1959 || t
->type_qualifiers
[4] == tq_Array
1960 || t
->type_qualifiers
[5] == tq_Array
1961 || t
->basic_type
== bt_Struct
1962 || t
->basic_type
== bt_Union
1963 || t
->basic_type
== bt_Enum
1965 || t
->num_dims
> 0))
1968 /* See if we can hash this type, and save some space, but some types
1969 can't be hashed (because they contain arrays or continuations),
1970 and others can be put into the hash list, but cannot use existing
1971 types because other aux entries precede this one. */
1973 if (state
!= hash_no
)
1975 register thash_t
*hash_ptr
;
1976 register symint_t hi
;
1978 hi
= aux
.isym
& ((1 << HASHBITS
) - 1);
1981 for (hash_ptr
= hash_tbl
[hi
];
1982 hash_ptr
!= (thash_t
*)0;
1983 hash_ptr
= hash_ptr
->next
)
1985 if (aux
.isym
== hash_ptr
->type
.isym
)
1989 if (hash_ptr
!= (thash_t
*) NULL
&& state
== hash_yes
)
1990 return hash_ptr
->indx
;
1992 if (hash_ptr
== (thash_t
*) NULL
)
1994 hash_ptr
= allocate_thash ();
1995 hash_ptr
->next
= hash_tbl
[hi
];
1996 hash_ptr
->type
= aux
;
1997 hash_ptr
->indx
= vp
->num_allocated
;
1998 hash_tbl
[hi
] = hash_ptr
;
2002 /* Everything is set up, add the aux symbol. */
2003 if (vp
->objects_last_page
== vp
->objects_per_page
)
2004 add_varray_page (vp
);
2006 aux_ptr
= &vp
->last
->datum
->aux
[ vp
->objects_last_page
++ ];
2007 aux_ptr
->type
= aux_tir
;
2008 aux_ptr
->data
= aux
;
2010 ret
= vp
->num_allocated
++;
2012 /* Add bitfield length if it exists.
2014 NOTE: Mips documentation claims bitfield goes at the end of the
2015 AUX record, but the DECstation compiler emits it here.
2016 (This would only make a difference for enum bitfields.)
2018 Also note: We use the last size given since gcc may emit 2
2019 for an enum bitfield. */
2022 (void) add_aux_sym_symint ((symint_t
)t
->sizes
[t
->num_sizes
-1]);
2025 /* Add tag information if needed. Structure, union, and enum
2026 references add 2 aux symbols: a [file index, symbol index]
2027 pointer to the structure type, and the current file index. */
2029 if (t
->basic_type
== bt_Struct
2030 || t
->basic_type
== bt_Union
2031 || t
->basic_type
== bt_Enum
)
2033 register symint_t file_index
= t
->tag_ptr
->ifd
;
2034 register localsym_t
*sym
= t
->tag_ptr
->sym
;
2035 register forward_t
*forward_ref
= allocate_forward ();
2037 if (sym
!= (localsym_t
*) NULL
)
2039 forward_ref
->next
= sym
->forward_ref
;
2040 sym
->forward_ref
= forward_ref
;
2044 forward_ref
->next
= t
->tag_ptr
->forward_ref
;
2045 t
->tag_ptr
->forward_ref
= forward_ref
;
2048 (void) add_aux_sym_rndx (ST_RFDESCAPE
, indexNil
);
2049 forward_ref
->index_ptr
2050 = &vp
->last
->datum
->aux
[ vp
->objects_last_page
- 1];
2052 (void) add_aux_sym_symint (file_index
);
2053 forward_ref
->ifd_ptr
2054 = &vp
->last
->datum
->aux
[ vp
->objects_last_page
- 1];
2057 /* Add information about array bounds if they exist. */
2058 for (i
= 0; i
< t
->num_dims
; i
++)
2060 (void) add_aux_sym_rndx (ST_RFDESCAPE
,
2061 cur_file_ptr
->int_type
);
2063 (void) add_aux_sym_symint (cur_file_ptr
->file_index
); /* file index*/
2064 (void) add_aux_sym_symint ((symint_t
) 0); /* low bound */
2065 (void) add_aux_sym_symint (t
->dimensions
[i
] - 1); /* high bound*/
2066 (void) add_aux_sym_symint ((t
->dimensions
[i
] == 0) /* stride */
2068 : (t
->sizes
[i
] * 8) / t
->dimensions
[i
]);
2071 /* NOTE: Mips documentation claims that the bitfield width goes here.
2072 But it needs to be emitted earlier. */
2077 /* Add a tag to the tag table (unless it already exists). */
2080 get_tag (tag
, sym
, basic_type
)
2081 const char *tag
; /* tag name */
2082 localsym_t
*sym
; /* tag start block */
2083 bt_t basic_type
; /* bt_Struct, bt_Union, or bt_Enum */
2089 if (cur_file_ptr
== (efdr_t
*) NULL
)
2090 as_fatal ("no current file pointer");
2092 hash_ptr
= (shash_t
*) hash_find (tag_hash
, tag
);
2094 if (hash_ptr
!= (shash_t
*) NULL
2095 && hash_ptr
->tag_ptr
!= (tag_t
*) NULL
)
2097 tag_ptr
= hash_ptr
->tag_ptr
;
2098 if (sym
!= (localsym_t
*) NULL
)
2100 tag_ptr
->basic_type
= basic_type
;
2101 tag_ptr
->ifd
= cur_file_ptr
->file_index
;
2107 if (hash_ptr
== (shash_t
*) NULL
)
2111 perm
= xmalloc ((unsigned long) (strlen (tag
) + 1));
2113 hash_ptr
= allocate_shash ();
2114 err
= hash_insert (tag_hash
, perm
, (char *) hash_ptr
);
2116 as_fatal ("Inserting \"%s\" into tag hash table: %s",
2118 hash_ptr
->string
= perm
;
2121 tag_ptr
= allocate_tag ();
2122 tag_ptr
->forward_ref
= (forward_t
*) NULL
;
2123 tag_ptr
->hash_ptr
= hash_ptr
;
2124 tag_ptr
->same_name
= hash_ptr
->tag_ptr
;
2125 tag_ptr
->basic_type
= basic_type
;
2127 tag_ptr
->ifd
= ((sym
== (localsym_t
*) NULL
)
2129 : cur_file_ptr
->file_index
);
2130 tag_ptr
->same_block
= cur_tag_head
->first_tag
;
2132 cur_tag_head
->first_tag
= tag_ptr
;
2133 hash_ptr
->tag_ptr
= tag_ptr
;
2138 /* Add an unknown {struct, union, enum} tag. */
2141 add_unknown_tag (ptag
)
2142 tag_t
*ptag
; /* pointer to tag information */
2144 shash_t
*hash_ptr
= ptag
->hash_ptr
;
2145 char *name
= hash_ptr
->string
;
2152 char *agg_type
= "{unknown aggregate type}";
2153 switch (ptag
->basic_type
)
2155 case bt_Struct
: agg_type
= "struct"; break;
2156 case bt_Union
: agg_type
= "union"; break;
2157 case bt_Enum
: agg_type
= "enum"; break;
2161 fprintf (stderr
, "unknown %s %.*s found\n", agg_type
,
2162 hash_ptr
->len
, name_start
);
2166 sym
= add_ecoff_symbol (name
,
2173 (void) add_ecoff_symbol (name
,
2180 for (pf
= &sym
->forward_ref
; *pf
!= (forward_t
*) NULL
; pf
= &(*pf
)->next
)
2182 *pf
= ptag
->forward_ref
;
2185 /* Add a procedure to the current file's list of procedures, and record
2186 this is the current procedure. */
2189 add_procedure (func
)
2190 char *func
; /* func name */
2192 register varray_t
*vp
;
2193 register proc_t
*new_proc_ptr
;
2197 fputc ('\n', stderr
);
2200 if (cur_file_ptr
== (efdr_t
*) NULL
)
2201 as_fatal ("no current file pointer");
2203 vp
= &cur_file_ptr
->procs
;
2205 if (vp
->objects_last_page
== vp
->objects_per_page
)
2206 add_varray_page (vp
);
2208 cur_proc_ptr
= new_proc_ptr
= &vp
->last
->datum
->proc
[vp
->objects_last_page
++];
2210 vp
->num_allocated
++;
2212 new_proc_ptr
->pdr
.isym
= -1;
2213 new_proc_ptr
->pdr
.iline
= -1;
2214 new_proc_ptr
->pdr
.lnLow
= -1;
2215 new_proc_ptr
->pdr
.lnHigh
= -1;
2217 /* Push the start of the function. */
2218 new_proc_ptr
->sym
= add_ecoff_symbol ((const char *) NULL
, st_Proc
, sc_Text
,
2219 symbol_find_or_make (func
),
2220 (symint_t
) 0, (symint_t
) 0);
2224 /* Fill in the linenos preceding the .ent, if any. */
2225 if (noproc_lineno
!= (lineno_list_t
*) NULL
)
2229 for (l
= noproc_lineno
; l
!= (lineno_list_t
*) NULL
; l
= l
->next
)
2230 l
->proc
= new_proc_ptr
;
2231 *last_lineno_ptr
= noproc_lineno
;
2232 while (*last_lineno_ptr
!= NULL
)
2233 last_lineno_ptr
= &(*last_lineno_ptr
)->next
;
2234 noproc_lineno
= (lineno_list_t
*) NULL
;
2238 /* Add a new filename, and set up all of the file relative
2239 virtual arrays (strings, symbols, aux syms, etc.). Record
2240 where the current file structure lives. */
2243 add_file (file_name
, indx
)
2244 const char *file_name
; /* file name */
2247 register int first_ch
;
2248 register efdr_t
*fil_ptr
;
2252 fprintf (stderr
, "\tfile\t%.*s\n", len
, file_start
);
2255 /* If the file name is NULL, then no .file symbol appeared, and we
2256 want to use the actual file name. Unfortunately, we don't have a
2257 clean way to access it. */
2258 if (file_name
== (const char *) NULL
)
2260 extern char *logical_input_file
;
2261 extern char *physical_input_file
;
2263 if (first_file
!= (efdr_t
*) NULL
)
2264 as_fatal ("fake .file after real one");
2265 file_name
= logical_input_file
;
2266 if (file_name
== (const char *) NULL
)
2268 file_name
= physical_input_file
;
2269 if (file_name
== (const char *) NULL
)
2270 file_name
= "UNKNOWN";
2276 listing_source_file (file_name
);
2279 /* If we're creating stabs, then we don't actually make a new FDR.
2280 Instead, we just create a stabs symbol. */
2283 (void) add_ecoff_symbol (file_name
, st_Nil
, sc_Nil
,
2284 symbol_new ("L0\001", now_seg
,
2285 (valueT
) frag_now_fix (),
2287 0, ECOFF_MARK_STAB (N_SOL
));
2291 first_ch
= *file_name
;
2293 /* See if the file has already been created. */
2294 for (fil_ptr
= first_file
;
2295 fil_ptr
!= (efdr_t
*) NULL
;
2296 fil_ptr
= fil_ptr
->next_file
)
2298 if (first_ch
== fil_ptr
->name
[0]
2299 && strcmp (file_name
, fil_ptr
->name
) == 0)
2301 cur_file_ptr
= fil_ptr
;
2306 /* If this is a new file, create it. */
2307 if (fil_ptr
== (efdr_t
*) NULL
)
2309 if (file_desc
.objects_last_page
== file_desc
.objects_per_page
)
2310 add_varray_page (&file_desc
);
2312 fil_ptr
= cur_file_ptr
=
2313 &file_desc
.last
->datum
->file
[file_desc
.objects_last_page
++];
2314 *fil_ptr
= init_file
;
2316 fil_ptr
->file_index
= indx
;
2317 ++file_desc
.num_allocated
;
2319 /* Allocate the string hash table. */
2320 fil_ptr
->str_hash
= hash_new ();
2322 /* Make sure 0 byte in string table is null */
2323 add_string (&fil_ptr
->strings
,
2328 if (strlen (file_name
) > PAGE_USIZE
- 2)
2329 as_fatal ("Filename goes over one page boundary.");
2331 /* Push the start of the filename. We assume that the filename
2332 will be stored at string offset 1. */
2333 (void) add_ecoff_symbol (file_name
, st_File
, sc_Text
,
2335 (symint_t
) 0, (symint_t
) 0);
2336 fil_ptr
->fdr
.rss
= 1;
2337 fil_ptr
->name
= &fil_ptr
->strings
.last
->datum
->byte
[1];
2339 /* Update the linked list of file descriptors. */
2340 *last_file_ptr
= fil_ptr
;
2341 last_file_ptr
= &fil_ptr
->next_file
;
2343 /* Add void & int types to the file (void should be first to catch
2344 errant 0's within the index fields). */
2345 fil_ptr
->void_type
= add_aux_sym_tir (&void_type_info
,
2347 &cur_file_ptr
->thash_head
[0]);
2349 fil_ptr
->int_type
= add_aux_sym_tir (&int_type_info
,
2351 &cur_file_ptr
->thash_head
[0]);
2357 /* Convert storage class to string. */
2360 sc_to_string(storage_class
)
2363 switch(storage_class
)
2365 case sc_Nil
: return "Nil,";
2366 case sc_Text
: return "Text,";
2367 case sc_Data
: return "Data,";
2368 case sc_Bss
: return "Bss,";
2369 case sc_Register
: return "Register,";
2370 case sc_Abs
: return "Abs,";
2371 case sc_Undefined
: return "Undefined,";
2372 case sc_CdbLocal
: return "CdbLocal,";
2373 case sc_Bits
: return "Bits,";
2374 case sc_CdbSystem
: return "CdbSystem,";
2375 case sc_RegImage
: return "RegImage,";
2376 case sc_Info
: return "Info,";
2377 case sc_UserStruct
: return "UserStruct,";
2378 case sc_SData
: return "SData,";
2379 case sc_SBss
: return "SBss,";
2380 case sc_RData
: return "RData,";
2381 case sc_Var
: return "Var,";
2382 case sc_Common
: return "Common,";
2383 case sc_SCommon
: return "SCommon,";
2384 case sc_VarRegister
: return "VarRegister,";
2385 case sc_Variant
: return "Variant,";
2386 case sc_SUndefined
: return "SUndefined,";
2387 case sc_Init
: return "Init,";
2388 case sc_Max
: return "Max,";
2398 /* Convert symbol type to string. */
2401 st_to_string(symbol_type
)
2406 case st_Nil
: return "Nil,";
2407 case st_Global
: return "Global,";
2408 case st_Static
: return "Static,";
2409 case st_Param
: return "Param,";
2410 case st_Local
: return "Local,";
2411 case st_Label
: return "Label,";
2412 case st_Proc
: return "Proc,";
2413 case st_Block
: return "Block,";
2414 case st_End
: return "End,";
2415 case st_Member
: return "Member,";
2416 case st_Typedef
: return "Typedef,";
2417 case st_File
: return "File,";
2418 case st_RegReloc
: return "RegReloc,";
2419 case st_Forward
: return "Forward,";
2420 case st_StaticProc
: return "StaticProc,";
2421 case st_Constant
: return "Constant,";
2422 case st_Str
: return "String,";
2423 case st_Number
: return "Number,";
2424 case st_Expr
: return "Expr,";
2425 case st_Type
: return "Type,";
2426 case st_Max
: return "Max,";
2434 /* Parse .begin directives which have a label as the first argument
2435 which gives the location of the start of the block. */
2438 obj_ecoff_begin (ignore
)
2444 if (cur_file_ptr
== (efdr_t
*) NULL
)
2446 as_warn (".begin directive without a preceding .file directive");
2447 demand_empty_rest_of_line ();
2451 if (cur_proc_ptr
== (proc_t
*) NULL
)
2453 as_warn (".begin directive without a preceding .ent directive");
2454 demand_empty_rest_of_line ();
2458 name
= input_line_pointer
;
2459 name_end
= get_symbol_end ();
2461 (void) add_ecoff_symbol ((const char *) NULL
, st_Block
, sc_Text
,
2462 symbol_find_or_make (name
),
2463 (symint_t
) 0, (symint_t
) 0);
2465 *input_line_pointer
= name_end
;
2467 /* The line number follows, but we don't use it. */
2468 (void) get_absolute_expression ();
2469 demand_empty_rest_of_line ();
2472 /* Parse .bend directives which have a label as the first argument
2473 which gives the location of the end of the block. */
2476 obj_ecoff_bend (ignore
)
2483 if (cur_file_ptr
== (efdr_t
*) NULL
)
2485 as_warn (".bend directive without a preceding .file directive");
2486 demand_empty_rest_of_line ();
2490 if (cur_proc_ptr
== (proc_t
*) NULL
)
2492 as_warn (".bend directive without a preceding .ent directive");
2493 demand_empty_rest_of_line ();
2497 name
= input_line_pointer
;
2498 name_end
= get_symbol_end ();
2500 /* The value is the distance between the .bend directive and the
2501 corresponding symbol. We fill in the offset when we write out
2503 endsym
= symbol_find (name
);
2504 if (endsym
== (symbolS
*) NULL
)
2505 as_warn (".bend directive names unknown symbol");
2507 (void) add_ecoff_symbol ((const char *) NULL
, st_End
, sc_Text
, endsym
,
2508 (symint_t
) 0, (symint_t
) 0);
2510 *input_line_pointer
= name_end
;
2512 /* The line number follows, but we don't use it. */
2513 (void) get_absolute_expression ();
2514 demand_empty_rest_of_line ();
2517 /* COFF debugging information is provided as a series of directives
2518 (.def, .scl, etc.). We build up information as we read the
2519 directives in the following static variables, and file it away when
2520 we reach the .endef directive. */
2521 static char *coff_sym_name
;
2522 static type_info_t coff_type
;
2523 static sc_t coff_storage_class
;
2524 static st_t coff_symbol_typ
;
2525 static int coff_is_function
;
2526 static char *coff_tag
;
2527 static valueT coff_value
;
2528 symbolS
*coff_sym_value
;
2529 static int coff_inside_enumeration
;
2531 /* Handle a .def directive: start defining a symbol. */
2534 obj_ecoff_def (ignore
)
2540 SKIP_WHITESPACES ();
2542 name
= input_line_pointer
;
2543 name_end
= get_symbol_end ();
2545 if (coff_sym_name
!= (char *) NULL
)
2546 as_warn (".def pseudo-op used inside of .def/.endef; ignored");
2547 else if (*name
== '\0')
2548 as_warn ("Empty symbol name in .def; ignored");
2551 if (coff_sym_name
!= (char *) NULL
)
2552 free (coff_sym_name
);
2553 if (coff_tag
!= (char *) NULL
)
2555 coff_sym_name
= (char *) xmalloc ((unsigned long) (strlen (name
) + 1));
2556 strcpy (coff_sym_name
, name
);
2557 coff_type
= type_info_init
;
2558 coff_storage_class
= sc_Nil
;
2559 coff_symbol_typ
= st_Nil
;
2560 coff_is_function
= 0;
2561 coff_tag
= (char *) NULL
;
2563 coff_sym_value
= (symbolS
*) NULL
;
2566 *input_line_pointer
= name_end
;
2568 demand_empty_rest_of_line ();
2571 /* Handle a .dim directive, used to give dimensions for an array. The
2572 arguments are comma separated numbers. mips-tfile assumes that
2573 there will not be more than 6 dimensions, and gdb won't read any
2574 more than that anyhow, so I will also make that assumption. */
2577 obj_ecoff_dim (ignore
)
2583 if (coff_sym_name
== (char *) NULL
)
2585 as_warn (".dim pseudo-op used outside of .def/.endef; ignored");
2586 demand_empty_rest_of_line ();
2590 for (i
= 0; i
< N_TQ
; i
++)
2592 SKIP_WHITESPACES ();
2593 dimens
[i
] = get_absolute_expression ();
2594 if (*input_line_pointer
== ',')
2595 ++input_line_pointer
;
2598 if (*input_line_pointer
!= '\n'
2599 && *input_line_pointer
!= ';')
2600 as_warn ("Badly formed .dim directive");
2608 /* The dimensions are stored away in reverse order. */
2611 if (coff_type
.num_dims
>= N_TQ
)
2613 as_warn ("Too many .dim entries");
2616 coff_type
.dimensions
[coff_type
.num_dims
] = dimens
[i
];
2617 ++coff_type
.num_dims
;
2620 demand_empty_rest_of_line ();
2623 /* Handle a .scl directive, which sets the COFF storage class of the
2627 obj_ecoff_scl (ignore
)
2632 if (coff_sym_name
== (char *) NULL
)
2634 as_warn (".scl pseudo-op used outside of .def/.endef; ignored");
2635 demand_empty_rest_of_line ();
2639 val
= get_absolute_expression ();
2641 coff_symbol_typ
= map_coff_sym_type
[val
];
2642 coff_storage_class
= map_coff_storage
[val
];
2644 demand_empty_rest_of_line ();
2647 /* Handle a .size directive. For some reason mips-tfile.c thinks that
2648 .size can have multiple arguments. We humor it, although gcc will
2649 never generate more than one argument. */
2652 obj_ecoff_size (ignore
)
2658 if (coff_sym_name
== (char *) NULL
)
2660 as_warn (".size pseudo-op used outside of .def/.endef; ignored");
2661 demand_empty_rest_of_line ();
2665 for (i
= 0; i
< N_TQ
; i
++)
2667 SKIP_WHITESPACES ();
2668 sizes
[i
] = get_absolute_expression ();
2669 if (*input_line_pointer
== ',')
2670 ++input_line_pointer
;
2673 if (*input_line_pointer
!= '\n'
2674 && *input_line_pointer
!= ';')
2675 as_warn ("Badly formed .size directive");
2683 /* The sizes are stored away in reverse order. */
2686 if (coff_type
.num_sizes
>= N_TQ
)
2688 as_warn ("Too many .size entries");
2691 coff_type
.sizes
[coff_type
.num_sizes
] = sizes
[i
];
2692 ++coff_type
.num_sizes
;
2695 demand_empty_rest_of_line ();
2698 /* Handle the .type directive, which gives the COFF type of the
2702 obj_ecoff_type (ignore
)
2709 if (coff_sym_name
== (char *) NULL
)
2711 as_warn (".type pseudo-op used outside of .def/.endef; ignored");
2712 demand_empty_rest_of_line ();
2716 val
= get_absolute_expression ();
2718 coff_type
.orig_type
= BTYPE (val
);
2719 coff_type
.basic_type
= map_coff_types
[coff_type
.orig_type
];
2721 tq_ptr
= &coff_type
.type_qualifiers
[N_TQ
];
2722 while (val
&~ N_BTMASK
)
2724 if (tq_ptr
== &coff_type
.type_qualifiers
[0])
2726 as_warn ("Too derived values in .type argument");
2731 else if (ISFCN (val
))
2732 *--tq_ptr
= tq_Proc
;
2733 else if (ISARY (val
))
2734 *--tq_ptr
= tq_Array
;
2736 as_fatal ("Unrecognized .type argument");
2741 tq_shft
= &coff_type
.type_qualifiers
[0];
2742 while (tq_ptr
!= &coff_type
.type_qualifiers
[N_TQ
])
2743 *tq_shft
++ = *tq_ptr
++;
2745 if (tq_shft
!= &coff_type
.type_qualifiers
[0] && tq_shft
[-1] == tq_Proc
)
2747 /* If this is a function, ignore it, so that we don't get two
2748 entries (one from the .ent, and one for the .def that
2749 precedes it). Save the type information so that the end
2750 block can properly add it after the begin block index. For
2751 MIPS knows what reason, we must strip off the function type
2753 coff_is_function
= 1;
2754 tq_shft
[-1] = tq_Nil
;
2757 while (tq_shft
!= &coff_type
.type_qualifiers
[N_TQ
])
2758 *tq_shft
++ = tq_Nil
;
2760 demand_empty_rest_of_line ();
2763 /* Handle the .tag directive, which gives the name of a structure,
2767 obj_ecoff_tag (ignore
)
2773 if (coff_sym_name
== (char *) NULL
)
2775 as_warn (".tag pseudo-op used outside of .def/.endef; ignored");
2776 demand_empty_rest_of_line ();
2780 name
= input_line_pointer
;
2781 name_end
= get_symbol_end ();
2783 coff_tag
= (char *) xmalloc ((unsigned long) (strlen (name
) + 1));
2784 strcpy (coff_tag
, name
);
2786 *input_line_pointer
= name_end
;
2788 demand_empty_rest_of_line ();
2791 /* Handle the .val directive, which gives the value of the symbol. It
2792 may be the name of a static or global symbol. */
2795 obj_ecoff_val (ignore
)
2798 if (coff_sym_name
== (char *) NULL
)
2800 as_warn (".val pseudo-op used outside of .def/.endef; ignored");
2801 demand_empty_rest_of_line ();
2805 if (! is_name_beginner ((unsigned char) *input_line_pointer
))
2806 coff_value
= get_absolute_expression ();
2812 name
= input_line_pointer
;
2813 name_end
= get_symbol_end ();
2815 if (strcmp (name
, ".") == 0)
2816 as_warn ("`.val .' not supported");
2818 coff_sym_value
= symbol_find_or_make (name
);
2820 *input_line_pointer
= name_end
;
2822 /* FIXME: gcc can generate address expressions here in unusual
2823 cases (search for "obscure" in sdbout.c), although this is
2824 very unlikely for a MIPS chip. */
2827 demand_empty_rest_of_line ();
2830 /* Handle the .endef directive, which terminates processing of COFF
2831 debugging information for a symbol. */
2834 obj_ecoff_endef (ignore
)
2841 demand_empty_rest_of_line ();
2843 if (coff_sym_name
== (char *) NULL
)
2845 as_warn (".endef pseudo-op used before .def; ignored");
2849 name
= coff_sym_name
;
2850 coff_sym_name
= (char *) NULL
;
2852 /* If the symbol is a static or external, we have already gotten the
2853 appropriate type and class, so make sure we don't override those
2854 values. This is needed because there are some type and classes
2855 that are not in COFF, such as short data, etc. */
2856 if (coff_sym_value
!= (symbolS
*) NULL
)
2858 coff_symbol_typ
= st_Nil
;
2859 coff_storage_class
= sc_Nil
;
2862 coff_type
.extra_sizes
= coff_tag
!= (char *) NULL
;
2863 if (coff_type
.num_dims
> 0)
2865 int diff
= coff_type
.num_dims
- coff_type
.num_sizes
;
2866 int i
= coff_type
.num_dims
- 1;
2869 if (coff_type
.num_sizes
!= 1 || diff
< 0)
2871 as_warn ("Bad COFF debugging info");
2875 /* If this is an array, make sure the same number of dimensions
2876 and sizes were passed, creating extra sizes for multiply
2877 dimensioned arrays if not passed. */
2878 coff_type
.extra_sizes
= 0;
2881 j
= (sizeof (coff_type
.sizes
) / sizeof (coff_type
.sizes
[0])) - 1;
2884 coff_type
.sizes
[j
] = (((j
- diff
) >= 0)
2885 ? coff_type
.sizes
[j
- diff
]
2890 coff_type
.num_sizes
= i
+ 1;
2891 for (i
--; i
>= 0; i
--)
2892 coff_type
.sizes
[i
] = (coff_type
.sizes
[i
+ 1]
2893 / coff_type
.dimensions
[i
+ 1]);
2896 else if (coff_symbol_typ
== st_Member
2897 && coff_type
.num_sizes
- coff_type
.extra_sizes
== 1)
2899 /* Is this a bitfield? This is indicated by a structure memeber
2900 having a size field that isn't an array. */
2901 coff_type
.bitfield
= 1;
2904 /* Except for enumeration members & begin/ending of scopes, put the
2905 type word in the aux. symbol table. */
2906 if (coff_symbol_typ
== st_Block
|| coff_symbol_typ
== st_End
)
2908 else if (coff_inside_enumeration
)
2909 indx
= cur_file_ptr
->void_type
;
2912 if (coff_type
.basic_type
== bt_Struct
2913 || coff_type
.basic_type
== bt_Union
2914 || coff_type
.basic_type
== bt_Enum
)
2916 if (coff_tag
== (char *) NULL
)
2918 as_warn ("No tag specified for %s", name
);
2922 coff_type
.tag_ptr
= get_tag (coff_tag
, (localsym_t
*) NULL
,
2923 coff_type
.basic_type
);
2926 if (coff_is_function
)
2928 last_func_type_info
= coff_type
;
2929 last_func_sym_value
= coff_sym_value
;
2933 indx
= add_aux_sym_tir (&coff_type
,
2935 &cur_file_ptr
->thash_head
[0]);
2938 /* Do any last minute adjustments that are necessary. */
2939 switch (coff_symbol_typ
)
2944 /* For the beginning of structs, unions, and enumerations, the
2945 size info needs to be passed in the value field. */
2947 if (coff_type
.num_sizes
- coff_type
.num_dims
- coff_type
.extra_sizes
2950 as_warn ("Bad COFF debugging information");
2954 coff_value
= coff_type
.sizes
[0];
2956 coff_inside_enumeration
= (coff_type
.orig_type
== T_ENUM
);
2959 /* For the end of structs, unions, and enumerations, omit the
2960 name which is always ".eos". This needs to be done last, so
2961 that any error reporting above gives the correct name. */
2964 name
= (char *) NULL
;
2966 coff_inside_enumeration
= 0;
2969 /* Members of structures and unions that aren't bitfields, need
2970 to adjust the value from a byte offset to a bit offset.
2971 Members of enumerations do not have the value adjusted, and
2972 can be distinguished by indx == indexNil. For enumerations,
2973 update the maximum enumeration value. */
2975 if (! coff_type
.bitfield
&& ! coff_inside_enumeration
)
2981 /* Add the symbol. */
2982 sym
= add_ecoff_symbol (name
,
2986 (symint_t
) coff_value
,
2989 /* deal with struct, union, and enum tags. */
2990 if (coff_symbol_typ
== st_Block
)
2992 /* Create or update the tag information. */
2993 tag_t
*tag_ptr
= get_tag (name
,
2995 coff_type
.basic_type
);
2998 /* Remember any forward references. */
2999 for (pf
= &sym
->forward_ref
;
3000 *pf
!= (forward_t
*) NULL
;
3003 *pf
= tag_ptr
->forward_ref
;
3004 tag_ptr
->forward_ref
= (forward_t
*) NULL
;
3008 /* Parse .end directives. */
3011 obj_ecoff_end (ignore
)
3019 if (cur_file_ptr
== (efdr_t
*) NULL
)
3021 as_warn (".end directive without a preceding .file directive");
3022 demand_empty_rest_of_line ();
3026 if (cur_proc_ptr
== (proc_t
*) NULL
)
3028 as_warn (".end directive without a preceding .ent directive");
3029 demand_empty_rest_of_line ();
3033 name
= input_line_pointer
;
3034 name_end
= get_symbol_end ();
3037 if (! is_name_beginner (ch
))
3039 as_warn (".end directive has no name");
3040 *input_line_pointer
= name_end
;
3041 demand_empty_rest_of_line ();
3045 /* The value is the distance between the .end directive and the
3046 corresponding symbol. We create a fake symbol to hold the
3047 current location, and put in the offset when we write out the
3049 ent
= symbol_find (name
);
3050 if (ent
== (symbolS
*) NULL
)
3051 as_warn (".end directive names unknown symbol");
3053 (void) add_ecoff_symbol ((const char *) NULL
, st_End
, sc_Text
,
3054 symbol_new ("L0\001", now_seg
,
3055 (valueT
) frag_now_fix (),
3057 (symint_t
) 0, (symint_t
) 0);
3059 cur_proc_ptr
= (proc_t
*) NULL
;
3061 *input_line_pointer
= name_end
;
3062 demand_empty_rest_of_line ();
3065 /* Parse .ent directives. */
3068 obj_ecoff_ent (ignore
)
3075 if (cur_file_ptr
== (efdr_t
*) NULL
)
3076 add_file ((const char *) NULL
, 0);
3078 if (cur_proc_ptr
!= (proc_t
*) NULL
)
3080 as_warn ("second .ent directive found before .end directive");
3081 demand_empty_rest_of_line ();
3085 name
= input_line_pointer
;
3086 name_end
= get_symbol_end ();
3089 if (! is_name_beginner (ch
))
3091 as_warn (".ent directive has no name");
3092 *input_line_pointer
= name_end
;
3093 demand_empty_rest_of_line ();
3097 add_procedure (name
);
3099 *input_line_pointer
= name_end
;
3100 demand_empty_rest_of_line ();
3103 /* Parse .file directives. */
3106 obj_ecoff_file (ignore
)
3113 if (cur_proc_ptr
!= (proc_t
*) NULL
)
3115 as_warn ("No way to handle .file within .ent/.end section");
3116 demand_empty_rest_of_line ();
3120 indx
= (int) get_absolute_expression ();
3122 /* FIXME: we don't have to save the name here. */
3123 name
= demand_copy_C_string (&len
);
3125 add_file (name
, indx
- 1);
3127 demand_empty_rest_of_line ();
3130 /* Parse .fmask directives. */
3133 obj_ecoff_fmask (ignore
)
3138 if (cur_proc_ptr
== (proc_t
*) NULL
)
3140 as_warn (".fmask outside of .ent");
3141 demand_empty_rest_of_line ();
3145 if (get_absolute_expression_and_terminator (&val
) != ',')
3147 as_warn ("Bad .fmask directive");
3148 --input_line_pointer
;
3149 demand_empty_rest_of_line ();
3153 cur_proc_ptr
->pdr
.fregmask
= val
;
3154 cur_proc_ptr
->pdr
.fregoffset
= get_absolute_expression ();
3156 demand_empty_rest_of_line ();
3159 /* Parse .frame directives. */
3162 obj_ecoff_frame (ignore
)
3167 if (cur_proc_ptr
== (proc_t
*) NULL
)
3169 as_warn (".frame outside of .ent");
3170 demand_empty_rest_of_line ();
3174 cur_proc_ptr
->pdr
.framereg
= tc_get_register ();
3177 if (*input_line_pointer
++ != ','
3178 || get_absolute_expression_and_terminator (&val
) != ',')
3180 as_warn ("Bad .frame directive");
3181 --input_line_pointer
;
3182 demand_empty_rest_of_line ();
3186 cur_proc_ptr
->pdr
.frameoffset
= val
;
3188 cur_proc_ptr
->pdr
.pcreg
= tc_get_register ();
3190 demand_empty_rest_of_line ();
3193 /* Parse .mask directives. */
3196 obj_ecoff_mask (ignore
)
3201 if (cur_proc_ptr
== (proc_t
*) NULL
)
3203 as_warn (".mask outside of .ent");
3204 demand_empty_rest_of_line ();
3208 if (get_absolute_expression_and_terminator (&val
) != ',')
3210 as_warn ("Bad .mask directive");
3211 --input_line_pointer
;
3212 demand_empty_rest_of_line ();
3216 cur_proc_ptr
->pdr
.regmask
= val
;
3217 cur_proc_ptr
->pdr
.regoffset
= get_absolute_expression ();
3219 demand_empty_rest_of_line ();
3222 /* Parse .loc directives. */
3225 obj_ecoff_loc (ignore
)
3228 lineno_list_t
*list
;
3231 if (cur_file_ptr
== (efdr_t
*) NULL
)
3233 as_warn (".loc before .file");
3234 demand_empty_rest_of_line ();
3238 if (now_seg
!= text_section
)
3240 as_warn (".loc outside of .text");
3241 demand_empty_rest_of_line ();
3245 /* Skip the file number. */
3247 get_absolute_expression ();
3250 lineno
= get_absolute_expression ();
3254 listing_source_line (lineno
);
3257 /* If we're building stabs, then output a special label rather than
3258 ECOFF line number info. */
3261 (void) add_ecoff_symbol ((char *) NULL
, st_Label
, sc_Text
,
3262 symbol_new ("L0\001", now_seg
,
3263 (valueT
) frag_now_fix (),
3269 list
= allocate_lineno_list ();
3271 list
->next
= (lineno_list_t
*) NULL
;
3272 list
->file
= cur_file_ptr
;
3273 list
->proc
= cur_proc_ptr
;
3274 list
->frag
= frag_now
;
3275 list
->paddr
= frag_now_fix ();
3276 list
->lineno
= lineno
;
3278 /* A .loc directive will sometimes appear before a .ent directive,
3279 which means that cur_proc_ptr will be NULL here. Arrange to
3281 if (cur_proc_ptr
== (proc_t
*) NULL
)
3285 pl
= &noproc_lineno
;
3286 while (*pl
!= (lineno_list_t
*) NULL
)
3292 *last_lineno_ptr
= list
;
3293 last_lineno_ptr
= &list
->next
;
3297 /* Make sure the @stabs symbol is emitted. */
3305 /* Add a dummy @stabs dymbol. */
3307 (void) add_ecoff_symbol (stabs_symbol
, stNil
, scInfo
,
3309 (symint_t
) -1, ECOFF_MARK_STAB (0));
3313 /* Handle .stabs directives. The actual parsing routine is done by a
3314 generic routine. This routine is called via OBJ_PROCESS_STAB.
3315 When this is called, input_line_pointer will be pointing at the
3316 value field of the stab.
3318 .stabs directives have five fields:
3319 "string" a string, encoding the type information.
3320 code a numeric code, defined in <stab.h>
3322 desc a zero or line number
3323 value a numeric value or an address.
3325 If the value is relocatable, we transform this into:
3326 iss points as an index into string space
3327 value value from lookup of the name
3328 st st from lookup of the name
3329 sc sc from lookup of the name
3330 index code|CODE_MASK
3332 If the value is not relocatable, we transform this into:
3333 iss points as an index into string space
3337 index code|CODE_MASK
3339 .stabn directives have four fields (string is null):
3340 code a numeric code, defined in <stab.h>
3342 desc a zero or a line number
3343 value a numeric value or an address. */
3346 ecoff_stab (what
, string
, type
, other
, desc
)
3353 efdr_t
*save_file_ptr
= cur_file_ptr
;
3360 /* We don't handle .stabd. */
3361 if (what
!= 's' && what
!= 'n')
3363 as_bad (".stab%c is not supported", what
);
3367 /* A .stabn uses a null name, not an empty string. */
3371 /* We ignore the other field. */
3373 as_warn (".stab%c: ignoring non-zero other field", what
);
3375 /* Make sure we have a current file. */
3376 if (cur_file_ptr
== (efdr_t
*) NULL
)
3378 add_file ((const char *) NULL
, 0);
3379 save_file_ptr
= cur_file_ptr
;
3382 /* For stabs in ECOFF, the first symbol must be @stabs. This is a
3384 if (stabs_seen
== 0)
3387 /* Line number stabs are handled differently, since they have two
3388 values, the line number and the address of the label. We use the
3389 index field (aka desc) to hold the line number, and the value
3390 field to hold the address. The symbol type is st_Label, which
3391 should be different from the other stabs, so that gdb can
3393 if (type
== N_SLINE
)
3401 listing_source_line ((unsigned int) desc
);
3404 dummy_symr
.index
= desc
;
3405 if (dummy_symr
.index
!= desc
)
3407 as_warn ("Line number (%d) for .stab%c directive cannot fit in index field (20 bits)",
3412 name
= input_line_pointer
;
3413 name_end
= get_symbol_end ();
3415 sym
= symbol_find_or_make (name
);
3416 *input_line_pointer
= name_end
;
3426 if (listing
&& (type
== N_SO
|| type
== N_SOL
))
3427 listing_source_file (string
);
3430 if (isdigit (*input_line_pointer
)
3431 || *input_line_pointer
== '-'
3432 || *input_line_pointer
== '+')
3436 sym
= (symbolS
*) NULL
;
3437 value
= get_absolute_expression ();
3439 else if (! is_name_beginner ((unsigned char) *input_line_pointer
))
3441 as_warn ("Illegal .stab%c directive, bad character", what
);
3449 name
= input_line_pointer
;
3450 name_end
= get_symbol_end ();
3452 sym
= symbol_find_or_make (name
);
3458 *input_line_pointer
= name_end
;
3459 if (name_end
== '+' || name_end
== '-')
3461 ++input_line_pointer
;
3462 value
= get_absolute_expression ();
3463 if (name_end
== '-')
3468 indx
= ECOFF_MARK_STAB (type
);
3471 (void) add_ecoff_symbol (string
, st
, sc
, sym
, value
, indx
);
3473 /* Restore normal file type. */
3474 cur_file_ptr
= save_file_ptr
;
3477 /* Add bytes to the symbolic information buffer. */
3480 ecoff_add_bytes (buf
, bufend
, bufptr
, need
)
3490 need
-= *bufend
- bufptr
;
3491 if (need
< PAGE_SIZE
)
3493 want
= (*bufend
- *buf
) + need
;
3494 *buf
= xrealloc (*buf
, want
);
3495 *bufend
= *buf
+ want
;
3499 /* Adjust the symbolic information buffer to the alignment required
3500 for the ECOFF target debugging information. */
3502 static unsigned long
3503 ecoff_padding_adjust (buf
, bufend
, offset
, bufptrptr
)
3506 unsigned long offset
;
3509 bfd_size_type align
;
3511 align
= ecoff_backend (stdoutput
)->debug_align
;
3512 if ((offset
& (align
- 1)) != 0)
3516 add
= align
- (offset
& (align
- 1));
3517 if (*bufend
- (*buf
+ offset
) < add
)
3518 (void) ecoff_add_bytes (buf
, bufend
, *buf
+ offset
, add
);
3519 memset (*buf
+ offset
, 0, add
);
3521 if (bufptrptr
!= (char **) NULL
)
3522 *bufptrptr
= *buf
+ offset
;
3528 /* Build the line number information. */
3530 static unsigned long
3531 ecoff_build_lineno (buf
, bufend
, offset
, linecntptr
)
3534 unsigned long offset
;
3538 register lineno_list_t
*l
;
3539 lineno_list_t
*last
;
3546 if (linecntptr
!= (long *) NULL
)
3549 bufptr
= *buf
+ offset
;
3551 file
= (efdr_t
*) NULL
;
3552 proc
= (proc_t
*) NULL
;
3553 last
= (lineno_list_t
*) NULL
;
3557 for (l
= first_lineno
; l
!= (lineno_list_t
*) NULL
; l
= l
->next
)
3562 /* Get the offset to the memory address of the next line number
3563 (in words). Do this first, so that we can skip ahead to the
3564 next useful line number entry. */
3565 if (l
->next
== (lineno_list_t
*) NULL
)
3569 count
= ((l
->next
->frag
->fr_address
+ l
->next
->paddr
3570 - (l
->frag
->fr_address
+ l
->paddr
))
3574 /* Don't change last, so we still get the right delta. */
3579 if (l
->file
!= file
|| l
->proc
!= proc
)
3581 if (l
->proc
!= proc
&& proc
!= (proc_t
*) NULL
)
3582 proc
->pdr
.lnHigh
= last
->lineno
;
3583 if (l
->file
!= file
&& file
!= (efdr_t
*) NULL
)
3585 file
->fdr
.cbLine
= c
- file
->fdr
.cbLineOffset
;
3586 /* The cline field is ill-documented. This is a guess
3587 at the right value. */
3588 file
->fdr
.cline
= totcount
+ count
;
3589 if (linecntptr
!= (long *) NULL
)
3590 *linecntptr
+= totcount
+ count
;
3594 if (l
->file
!= file
)
3597 file
->fdr
.ilineBase
= iline
;
3598 file
->fdr
.cbLineOffset
= c
;
3600 if (l
->proc
!= proc
)
3603 if (proc
!= (proc_t
*) NULL
)
3605 proc
->pdr
.lnLow
= l
->lineno
;
3606 proc
->pdr
.cbLineOffset
= c
- file
->fdr
.cbLineOffset
;
3607 /* The iline field is ill-documented. This is a
3608 guess at the right value. */
3609 proc
->pdr
.iline
= totcount
;
3613 last
= (lineno_list_t
*) NULL
;
3618 /* Get the offset to this line number. */
3619 if (last
== (lineno_list_t
*) NULL
)
3622 delta
= l
->lineno
- last
->lineno
;
3624 /* Put in the offset to this line number. */
3629 /* 1 is added to each count read. */
3631 /* We can only adjust the word count by up to 15 words at a
3643 if (delta
>= -7 && delta
<= 7)
3645 if (bufptr
>= *bufend
)
3646 bufptr
= ecoff_add_bytes (buf
, bufend
, bufptr
, (long) 1);
3647 *bufptr
++ = setcount
+ (delta
<< 4);
3655 if (*bufend
- bufptr
< 3)
3656 bufptr
= ecoff_add_bytes (buf
, bufend
, bufptr
, (long) 3);
3657 *bufptr
++ = setcount
+ (8 << 4);
3658 if (delta
< -0x8000)
3663 else if (delta
> 0x7fff)
3673 *bufptr
++ = set
>> 8;
3674 *bufptr
++ = set
& 0xffff;
3679 /* Finish adjusting the count. */
3682 if (bufptr
>= *bufend
)
3683 bufptr
= ecoff_add_bytes (buf
, bufend
, bufptr
, (long) 1);
3684 /* 1 is added to each count read. */
3703 if (proc
!= (proc_t
*) NULL
)
3704 proc
->pdr
.lnHigh
= last
->lineno
;
3705 if (file
!= (efdr_t
*) NULL
)
3707 file
->fdr
.cbLine
= c
- file
->fdr
.cbLineOffset
;
3708 file
->fdr
.cline
= totcount
;
3711 if (linecntptr
!= (long *) NULL
)
3712 *linecntptr
+= totcount
;
3714 c
= ecoff_padding_adjust (buf
, bufend
, c
, &bufptr
);
3719 /* Build and swap out the symbols. */
3721 static unsigned long
3722 ecoff_build_symbols (buf
,
3732 unsigned long offset
;
3735 unsigned long *extoffset
;
3736 varray_t
*ext_strings
;
3737 struct hash_control
*ext_str_hash
;
3739 const bfd_size_type external_sym_size
=
3740 ecoff_backend (stdoutput
)->external_sym_size
;
3741 const bfd_size_type external_ext_size
=
3742 ecoff_backend (stdoutput
)->external_ext_size
;
3743 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
3744 = ecoff_backend (stdoutput
)->swap_sym_out
;
3745 void (* const swap_ext_out
) PARAMS ((bfd
*, const EXTR
*, PTR
))
3746 = ecoff_backend (stdoutput
)->swap_ext_out
;
3751 vlinks_t
*file_link
;
3753 sym_out
= *buf
+ offset
;
3754 ext_out
= *extbuf
+ *extoffset
;
3759 /* The symbols are stored by file. */
3760 for (file_link
= file_desc
.first
;
3761 file_link
!= (vlinks_t
*) NULL
;
3762 file_link
= file_link
->next
)
3769 if (file_link
->next
== (vlinks_t
*) NULL
)
3770 fil_cnt
= file_desc
.objects_last_page
;
3772 fil_cnt
= file_desc
.objects_per_page
;
3773 fil_ptr
= file_link
->datum
->file
;
3774 fil_end
= fil_ptr
+ fil_cnt
;
3775 for (; fil_ptr
< fil_end
; fil_ptr
++)
3779 fil_ptr
->fdr
.isymBase
= isym
;
3781 for (sym_link
= fil_ptr
->symbols
.first
;
3782 sym_link
!= (vlinks_t
*) NULL
;
3783 sym_link
= sym_link
->next
)
3786 localsym_t
*sym_ptr
;
3787 localsym_t
*sym_end
;
3789 if (sym_link
->next
== (vlinks_t
*) NULL
)
3790 sym_cnt
= fil_ptr
->symbols
.objects_last_page
;
3792 sym_cnt
= fil_ptr
->symbols
.objects_per_page
;
3793 sym_ptr
= sym_link
->datum
->sym
;
3794 sym_end
= sym_ptr
+ sym_cnt
;
3795 for (; sym_ptr
< sym_end
; sym_ptr
++)
3801 know (sym_ptr
->file_ptr
== fil_ptr
);
3803 /* If there is no associated gas symbol, then this
3804 is a pure debugging symbol. We have already
3805 added the name (if any) to fil_ptr->strings.
3806 Otherwise we must decide whether this is an
3807 external or a local symbol (actually, it may be
3808 both if the local provides additional debugging
3809 information for the external). */
3811 as_sym
= sym_ptr
->as_sym
;
3812 if (as_sym
!= (symbolS
*) NULL
)
3816 /* The value of a block start symbol is the
3817 offset from the start of the procedure. For
3818 other symbols we just use the gas value (but
3819 we must offset it by the vma of the section,
3820 just as BFD does, because BFD will not see
3822 if (sym_ptr
->ecoff_sym
.st
== (int) st_Block
3823 && sym_ptr
->ecoff_sym
.sc
== (int) sc_Text
)
3827 know (sym_ptr
->proc_ptr
!= (proc_t
*) NULL
);
3828 begin_sym
= sym_ptr
->proc_ptr
->sym
->as_sym
;
3829 if (S_GET_SEGMENT (as_sym
)
3830 != S_GET_SEGMENT (begin_sym
))
3831 as_warn (".begin/.bend in different segments");
3832 sym_ptr
->ecoff_sym
.value
=
3833 S_GET_VALUE (as_sym
) - S_GET_VALUE (begin_sym
);
3836 sym_ptr
->ecoff_sym
.value
=
3837 (S_GET_VALUE (as_sym
)
3838 + bfd_get_section_vma (stdoutput
,
3839 S_GET_SEGMENT (as_sym
)));
3841 /* Set st_Proc to st_StaticProc for local
3843 if (sym_ptr
->ecoff_sym
.st
== st_Proc
3844 && S_IS_DEFINED (as_sym
)
3845 && ! S_IS_EXTERNAL (as_sym
))
3846 sym_ptr
->ecoff_sym
.st
= st_StaticProc
;
3848 /* Get the type and storage class based on where
3849 the symbol actually wound up. Traditionally,
3850 N_LBRAC and N_RBRAC are *not* relocated. */
3851 indx
= sym_ptr
->ecoff_sym
.index
;
3852 if (sym_ptr
->ecoff_sym
.st
== st_Nil
3853 && sym_ptr
->ecoff_sym
.sc
== sc_Nil
3854 && (! ECOFF_IS_STAB (&sym_ptr
->ecoff_sym
)
3855 || ((ECOFF_UNMARK_STAB (indx
) != N_LBRAC
)
3856 && (ECOFF_UNMARK_STAB (indx
) != N_RBRAC
))))
3859 const char *segname
;
3863 seg
= S_GET_SEGMENT (as_sym
);
3864 segname
= segment_name (seg
);
3866 if (S_IS_EXTERNAL (as_sym
)
3867 || ! S_IS_DEFINED (as_sym
))
3869 else if (seg
== text_section
)
3874 if (! S_IS_DEFINED (as_sym
)
3875 || as_sym
->ecoff_undefined
)
3877 if (S_GET_VALUE (as_sym
) > 0
3878 && (S_GET_VALUE (as_sym
)
3879 <= bfd_get_gp_size (stdoutput
)))
3884 else if (S_IS_COMMON (as_sym
))
3886 if (S_GET_VALUE (as_sym
) > 0
3887 && (S_GET_VALUE (as_sym
)
3888 <= bfd_get_gp_size (stdoutput
)))
3893 else if (seg
== text_section
)
3895 else if (seg
== data_section
)
3897 else if (strcmp (segname
, ".rdata") == 0)
3899 else if (strcmp (segname
, ".sdata") == 0)
3901 else if (seg
== bss_section
)
3903 else if (strcmp (segname
, ".sbss") == 0)
3905 else if (seg
== &bfd_abs_section
)
3910 sym_ptr
->ecoff_sym
.st
= (int) st
;
3911 sym_ptr
->ecoff_sym
.sc
= (int) sc
;
3914 /* This is just an external symbol if it is
3915 outside a procedure and it has a type.
3916 FIXME: g++ will generate symbols which have
3917 different names in the debugging information
3918 than the actual symbol. Should we handle
3920 if ((S_IS_EXTERNAL (as_sym
)
3921 || ! S_IS_DEFINED (as_sym
))
3922 && sym_ptr
->proc_ptr
== (proc_t
*) NULL
3923 && sym_ptr
->ecoff_sym
.st
!= (int) st_Nil
3924 && ! ECOFF_IS_STAB (&sym_ptr
->ecoff_sym
))
3927 /* If an st_end symbol has an associated gas
3928 symbol, then it is a local label created for
3929 a .bend or .end directive. Stabs line
3930 numbers will have \001 in the names. */
3932 && sym_ptr
->ecoff_sym
.st
!= st_End
3933 && strchr (sym_ptr
->name
, '\001') == 0)
3934 sym_ptr
->ecoff_sym
.iss
=
3935 add_string (&fil_ptr
->strings
,
3941 /* We now know the index of this symbol; fill in
3942 locations that have been waiting for that
3944 if (sym_ptr
->begin_ptr
!= (localsym_t
*) NULL
)
3946 localsym_t
*begin_ptr
;
3950 begin_ptr
= sym_ptr
->begin_ptr
;
3951 know (begin_ptr
->sym_index
!= -1);
3952 sym_ptr
->ecoff_sym
.index
= begin_ptr
->sym_index
;
3953 if (sym_ptr
->ecoff_sym
.sc
!= (int) sc_Info
)
3954 sym_ptr
->ecoff_sym
.iss
= begin_ptr
->ecoff_sym
.iss
;
3956 begin_type
= begin_ptr
->ecoff_sym
.st
;
3957 if (begin_type
== st_File
3958 || begin_type
== st_Block
)
3960 begin_ptr
->ecoff_sym
.index
= isym
- ifilesym
+ 1;
3961 (*swap_sym_out
) (stdoutput
,
3962 &begin_ptr
->ecoff_sym
,
3965 + (begin_ptr
->sym_index
3966 * external_sym_size
)));
3970 know (begin_ptr
->index_ptr
!= (aux_t
*) NULL
);
3971 begin_ptr
->index_ptr
->data
.isym
=
3972 isym
- ifilesym
+ 1;
3975 /* The value of the symbol marking the end of a
3976 procedure is the size of the procedure. The
3977 value of the symbol marking the end of a
3978 block is the offset from the start of the
3979 procedure to the block. */
3980 if (begin_type
== st_Proc
)
3982 know (as_sym
!= (symbolS
*) NULL
);
3983 know (begin_ptr
->as_sym
!= (symbolS
*) NULL
);
3984 if (S_GET_SEGMENT (as_sym
)
3985 != S_GET_SEGMENT (begin_ptr
->as_sym
))
3986 as_warn (".begin/.bend in different segments");
3987 sym_ptr
->ecoff_sym
.value
=
3988 (S_GET_VALUE (as_sym
)
3989 - S_GET_VALUE (begin_ptr
->as_sym
));
3991 else if (begin_type
== st_Block
3992 && sym_ptr
->ecoff_sym
.sc
!= (int) sc_Info
)
3996 know (as_sym
!= (symbolS
*) NULL
);
3997 know (sym_ptr
->proc_ptr
!= (proc_t
*) NULL
);
3998 begin_sym
= sym_ptr
->proc_ptr
->sym
->as_sym
;
3999 if (S_GET_SEGMENT (as_sym
)
4000 != S_GET_SEGMENT (begin_sym
))
4001 as_warn (".begin/.bend in different segments");
4002 sym_ptr
->ecoff_sym
.value
=
4003 S_GET_VALUE (as_sym
) - S_GET_VALUE (begin_sym
);
4007 for (f
= sym_ptr
->forward_ref
;
4008 f
!= (forward_t
*) NULL
;
4012 f
->ifd_ptr
->data
.isym
= fil_ptr
->file_index
;
4013 f
->index_ptr
->data
.rndx
.index
= isym
- ifilesym
;
4018 if (*bufend
- sym_out
< external_sym_size
)
4019 sym_out
= ecoff_add_bytes (buf
, bufend
,
4022 (*swap_sym_out
) (stdoutput
, &sym_ptr
->ecoff_sym
,
4024 sym_out
+= external_sym_size
;
4026 sym_ptr
->sym_index
= isym
;
4028 if (sym_ptr
->proc_ptr
!= (proc_t
*) NULL
4029 && sym_ptr
->proc_ptr
->sym
== sym_ptr
)
4030 sym_ptr
->proc_ptr
->pdr
.isym
= isym
- ifilesym
;
4035 /* If this is an external symbol, swap it out. */
4036 if (as_sym
!= (symbolS
*) NULL
4037 && (S_IS_EXTERNAL (as_sym
)
4038 || ! S_IS_DEFINED (as_sym
))
4039 && ! ECOFF_IS_STAB (&sym_ptr
->ecoff_sym
))
4043 memset (&ext
, 0, sizeof ext
);
4044 ext
.asym
= sym_ptr
->ecoff_sym
;
4045 if (sym_ptr
->ecoff_sym
.st
== st_Proc
4046 || sym_ptr
->ecoff_sym
.st
== st_StaticProc
)
4049 ext
.asym
.index
= isym
- ifilesym
- 1;
4051 ext
.ifd
= fil_ptr
->file_index
;
4052 ext
.asym
.iss
= add_string (ext_strings
,
4054 S_GET_NAME (as_sym
),
4056 if (*extbufend
- ext_out
< external_ext_size
)
4057 ext_out
= ecoff_add_bytes (extbuf
, extbufend
,
4060 (*swap_ext_out
) (stdoutput
, &ext
, ext_out
);
4061 ecoff_set_sym_index (as_sym
->bsym
, iext
);
4062 ext_out
+= external_ext_size
;
4067 fil_ptr
->fdr
.csym
= isym
- fil_ptr
->fdr
.isymBase
;
4071 *extoffset
+= iext
* external_ext_size
;
4072 return offset
+ isym
* external_sym_size
;
4075 /* Swap out the procedure information. */
4077 static unsigned long
4078 ecoff_build_procs (buf
, bufend
, offset
)
4081 unsigned long offset
;
4083 const bfd_size_type external_pdr_size
4084 = ecoff_backend (stdoutput
)->external_pdr_size
;
4085 void (* const swap_pdr_out
) PARAMS ((bfd
*, const PDR
*, PTR
))
4086 = ecoff_backend (stdoutput
)->swap_pdr_out
;
4090 vlinks_t
*file_link
;
4092 pdr_out
= *buf
+ offset
;
4097 /* The procedures are stored by file. */
4098 for (file_link
= file_desc
.first
;
4099 file_link
!= (vlinks_t
*) NULL
;
4100 file_link
= file_link
->next
)
4106 if (file_link
->next
== (vlinks_t
*) NULL
)
4107 fil_cnt
= file_desc
.objects_last_page
;
4109 fil_cnt
= file_desc
.objects_per_page
;
4110 fil_ptr
= file_link
->datum
->file
;
4111 fil_end
= fil_ptr
+ fil_cnt
;
4112 for (; fil_ptr
< fil_end
; fil_ptr
++)
4114 vlinks_t
*proc_link
;
4117 fil_ptr
->fdr
.ipdFirst
= iproc
;
4119 for (proc_link
= fil_ptr
->procs
.first
;
4120 proc_link
!= (vlinks_t
*) NULL
;
4121 proc_link
= proc_link
->next
)
4127 if (proc_link
->next
== (vlinks_t
*) NULL
)
4128 prc_cnt
= fil_ptr
->procs
.objects_last_page
;
4130 prc_cnt
= fil_ptr
->procs
.objects_per_page
;
4131 proc_ptr
= proc_link
->datum
->proc
;
4132 proc_end
= proc_ptr
+ prc_cnt
;
4133 for (; proc_ptr
< proc_end
; proc_ptr
++)
4138 adr_sym
= proc_ptr
->sym
->as_sym
;
4139 adr
= (S_GET_VALUE (adr_sym
)
4140 + bfd_get_section_vma (stdoutput
,
4141 S_GET_SEGMENT (adr_sym
)));
4147 fil_ptr
->fdr
.adr
= adr
;
4150 proc_ptr
->pdr
.adr
= adr
- fil_ptr
->fdr
.adr
;
4151 if (*bufend
- pdr_out
< external_pdr_size
)
4152 pdr_out
= ecoff_add_bytes (buf
, bufend
,
4155 (*swap_pdr_out
) (stdoutput
, &proc_ptr
->pdr
, pdr_out
);
4156 pdr_out
+= external_pdr_size
;
4160 fil_ptr
->fdr
.cpd
= iproc
- fil_ptr
->fdr
.ipdFirst
;
4164 return offset
+ iproc
* external_pdr_size
;
4167 /* Swap out the aux information. */
4169 static unsigned long
4170 ecoff_build_aux (buf
, bufend
, offset
)
4173 unsigned long offset
;
4176 union aux_ext
*aux_out
;
4178 vlinks_t
*file_link
;
4180 bigendian
= stdoutput
->xvec
->header_byteorder_big_p
;
4182 aux_out
= (union aux_ext
*) (*buf
+ offset
);
4186 /* The aux entries are stored by file. */
4187 for (file_link
= file_desc
.first
;
4188 file_link
!= (vlinks_t
*) NULL
;
4189 file_link
= file_link
->next
)
4195 if (file_link
->next
== (vlinks_t
*) NULL
)
4196 fil_cnt
= file_desc
.objects_last_page
;
4198 fil_cnt
= file_desc
.objects_per_page
;
4199 fil_ptr
= file_link
->datum
->file
;
4200 fil_end
= fil_ptr
+ fil_cnt
;
4201 for (; fil_ptr
< fil_end
; fil_ptr
++)
4205 fil_ptr
->fdr
.fBigendian
= bigendian
;
4206 fil_ptr
->fdr
.iauxBase
= iaux
;
4207 for (aux_link
= fil_ptr
->aux_syms
.first
;
4208 aux_link
!= (vlinks_t
*) NULL
;
4209 aux_link
= aux_link
->next
)
4215 if (aux_link
->next
== (vlinks_t
*) NULL
)
4216 aux_cnt
= fil_ptr
->aux_syms
.objects_last_page
;
4218 aux_cnt
= fil_ptr
->aux_syms
.objects_per_page
;
4219 aux_ptr
= aux_link
->datum
->aux
;
4220 aux_end
= aux_ptr
+ aux_cnt
;
4221 for (; aux_ptr
< aux_end
; aux_ptr
++)
4223 if (*bufend
- (char *) aux_out
< sizeof (union aux_ext
))
4224 aux_out
= ((union aux_ext
*)
4225 ecoff_add_bytes (buf
, bufend
,
4227 sizeof (union aux_ext
)));
4228 switch (aux_ptr
->type
)
4231 ecoff_swap_tir_out (bigendian
, &aux_ptr
->data
.ti
,
4235 ecoff_swap_rndx_out (bigendian
, &aux_ptr
->data
.rndx
,
4239 AUX_PUT_DNLOW (bigendian
, aux_ptr
->data
.dnLow
,
4243 AUX_PUT_DNHIGH (bigendian
, aux_ptr
->data
.dnHigh
,
4247 AUX_PUT_ISYM (bigendian
, aux_ptr
->data
.isym
,
4251 AUX_PUT_ISS (bigendian
, aux_ptr
->data
.iss
,
4255 AUX_PUT_WIDTH (bigendian
, aux_ptr
->data
.width
,
4259 AUX_PUT_COUNT (bigendian
, aux_ptr
->data
.count
,
4268 fil_ptr
->fdr
.caux
= iaux
- fil_ptr
->fdr
.iauxBase
;
4272 return offset
+ iaux
* sizeof (union aux_ext
);
4275 /* Copy out the strings from a varray_t. This returns the number of
4276 bytes copied, rather than the new offset. */
4278 static unsigned long
4279 ecoff_build_strings (buf
, bufend
, offset
, vp
)
4282 unsigned long offset
;
4289 str_out
= *buf
+ offset
;
4293 for (str_link
= vp
->first
;
4294 str_link
!= (vlinks_t
*) NULL
;
4295 str_link
= str_link
->next
)
4297 unsigned long str_cnt
;
4299 if (str_link
->next
== (vlinks_t
*) NULL
)
4300 str_cnt
= vp
->objects_last_page
;
4302 str_cnt
= vp
->objects_per_page
;
4304 if (*bufend
- str_out
< str_cnt
)
4305 str_out
= ecoff_add_bytes (buf
, bufend
, str_out
, str_cnt
);
4307 memcpy (str_out
, str_link
->datum
->byte
, str_cnt
);
4315 /* Dump out the local strings. */
4317 static unsigned long
4318 ecoff_build_ss (buf
, bufend
, offset
)
4321 unsigned long offset
;
4324 vlinks_t
*file_link
;
4328 for (file_link
= file_desc
.first
;
4329 file_link
!= (vlinks_t
*) NULL
;
4330 file_link
= file_link
->next
)
4336 if (file_link
->next
== (vlinks_t
*) NULL
)
4337 fil_cnt
= file_desc
.objects_last_page
;
4339 fil_cnt
= file_desc
.objects_per_page
;
4340 fil_ptr
= file_link
->datum
->file
;
4341 fil_end
= fil_ptr
+ fil_cnt
;
4342 for (; fil_ptr
< fil_end
; fil_ptr
++)
4346 fil_ptr
->fdr
.issBase
= iss
;
4347 ss_cnt
= ecoff_build_strings (buf
, bufend
, offset
+ iss
,
4349 fil_ptr
->fdr
.cbSs
= ss_cnt
;
4354 return ecoff_padding_adjust (buf
, bufend
, offset
+ iss
, (char **) NULL
);
4357 /* Swap out the file descriptors. */
4359 static unsigned long
4360 ecoff_build_fdr (buf
, bufend
, offset
)
4363 unsigned long offset
;
4365 const bfd_size_type external_fdr_size
4366 = ecoff_backend (stdoutput
)->external_fdr_size
;
4367 void (* const swap_fdr_out
) PARAMS ((bfd
*, const FDR
*, PTR
))
4368 = ecoff_backend (stdoutput
)->swap_fdr_out
;
4371 vlinks_t
*file_link
;
4375 fdr_out
= *buf
+ offset
;
4377 for (file_link
= file_desc
.first
;
4378 file_link
!= (vlinks_t
*) NULL
;
4379 file_link
= file_link
->next
)
4385 if (file_link
->next
== (vlinks_t
*) NULL
)
4386 fil_cnt
= file_desc
.objects_last_page
;
4388 fil_cnt
= file_desc
.objects_per_page
;
4389 fil_ptr
= file_link
->datum
->file
;
4390 fil_end
= fil_ptr
+ fil_cnt
;
4391 for (; fil_ptr
< fil_end
; fil_ptr
++)
4393 if (*bufend
- fdr_out
< external_fdr_size
)
4394 fdr_out
= ecoff_add_bytes (buf
, bufend
, fdr_out
,
4396 (*swap_fdr_out
) (stdoutput
, &fil_ptr
->fdr
, fdr_out
);
4397 fdr_out
+= external_fdr_size
;
4402 return offset
+ ifile
* external_fdr_size
;
4405 /* Swap out the symbols and debugging information for BFD. */
4410 const struct ecoff_backend_data
* const backend
= ecoff_backend (stdoutput
);
4411 const bfd_size_type external_pdr_size
= backend
->external_pdr_size
;
4416 efdr_t
*hold_file_ptr
;
4417 proc_t
* hold_proc_ptr
;
4424 unsigned long offset
;
4427 unsigned long extoffset
;
4428 varray_t ext_strings
;
4429 static varray_t init_ext_strings
= INIT_VARRAY (char);
4430 struct hash_control
*ext_str_hash
;
4433 /* Make sure we have a file. */
4434 if (first_file
== (efdr_t
*) NULL
)
4435 add_file ((const char *) NULL
, 0);
4437 /* Handle any top level tags. */
4438 for (ptag
= top_tag_head
->first_tag
;
4439 ptag
!= (tag_t
*) NULL
;
4442 if (ptag
->forward_ref
!= (forward_t
*) NULL
)
4443 add_unknown_tag (ptag
);
4445 ptag_next
= ptag
->same_block
;
4446 ptag
->hash_ptr
->tag_ptr
= ptag
->same_name
;
4450 free_thead (top_tag_head
);
4452 /* Output an ending symbol for all the files. We have to do this
4453 here for the last file, so we may as well do it for all of the
4456 for (fil_ptr
= first_file
;
4457 fil_ptr
!= (efdr_t
*) NULL
;
4458 fil_ptr
= fil_ptr
->next_file
)
4460 cur_file_ptr
= fil_ptr
;
4461 while (cur_file_ptr
->cur_scope
->prev
!= (scope_t
*) NULL
)
4463 cur_file_ptr
->cur_scope
= cur_file_ptr
->cur_scope
->prev
;
4466 as_warn ("Missing .end or .bend at end of file");
4470 (void) add_ecoff_symbol ((const char *) NULL
,
4477 /* Set the section VMA values. */
4479 for (sec
= stdoutput
->sections
; sec
!= (asection
*) NULL
; sec
= sec
->next
)
4481 bfd_set_section_vma (stdoutput
, sec
, addr
);
4482 addr
+= bfd_section_size (stdoutput
, sec
);
4485 /* Look through the symbols. Add debugging information for each
4486 symbol that has not already received it. */
4487 hold_file_ptr
= cur_file_ptr
;
4488 hold_proc_ptr
= cur_proc_ptr
;
4489 cur_proc_ptr
= (proc_t
*) NULL
;
4490 for (sym
= symbol_rootP
; sym
!= (symbolS
*) NULL
; sym
= symbol_next (sym
))
4492 if (sym
->ecoff_symbol
4493 || sym
->ecoff_file
== (efdr_t
*) NULL
4494 || (sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
4497 cur_file_ptr
= sym
->ecoff_file
;
4498 add_ecoff_symbol ((const char *) NULL
, st_Nil
, sc_Nil
, sym
,
4499 S_GET_VALUE (sym
), indexNil
);
4501 cur_proc_ptr
= hold_proc_ptr
;
4502 cur_file_ptr
= hold_file_ptr
;
4504 /* Build the symbolic information. */
4505 hdr
= &ecoff_data (stdoutput
)->symbolic_header
;
4507 buf
= xmalloc (PAGE_SIZE
);
4508 bufend
= buf
+ PAGE_SIZE
;
4510 /* Build the line number information. */
4511 hdr
->cbLineOffset
= offset
;
4512 offset
= ecoff_build_lineno (&buf
, &bufend
, offset
, &hdr
->ilineMax
);
4513 hdr
->cbLine
= offset
- hdr
->cbLineOffset
;
4515 /* We don't use dense numbers at all. */
4517 hdr
->cbDnOffset
= 0;
4519 /* We can't build the PDR table until we have built the symbols,
4520 because a PDR contains a symbol index. However, we set aside
4521 space at this point. */
4522 hdr
->ipdMax
= proc_cnt
;
4523 hdr
->cbPdOffset
= offset
;
4524 if (bufend
- (buf
+ offset
) < proc_cnt
* external_pdr_size
)
4525 (void) ecoff_add_bytes (&buf
, &bufend
, buf
+ offset
,
4526 proc_cnt
* external_pdr_size
);
4527 offset
+= proc_cnt
* external_pdr_size
;
4529 /* Build the symbols. It's convenient to build both the local and
4530 external symbols at the same time. We can put the local symbols
4531 directly into the buffer, but we have to hold the external
4532 symbols apart until we know where they are going to go. */
4533 extbuf
= xmalloc (PAGE_SIZE
);
4534 extbufend
= extbuf
+ PAGE_SIZE
;
4536 ext_strings
= init_ext_strings
;
4537 ext_str_hash
= hash_new ();
4538 hdr
->cbSymOffset
= offset
;
4539 offset
= ecoff_build_symbols (&buf
, &bufend
, offset
,
4540 &extbuf
, &extbufend
, &extoffset
,
4541 &ext_strings
, ext_str_hash
);
4542 hdr
->isymMax
= (offset
- hdr
->cbSymOffset
) / backend
->external_sym_size
;
4544 /* Building the symbols initializes the symbol index in the PDR's.
4545 Now we can swap out the PDR's. */
4546 (void) ecoff_build_procs (&buf
, &bufend
, hdr
->cbPdOffset
);
4548 /* We don't use optimization symbols. */
4550 hdr
->cbOptOffset
= 0;
4552 /* Swap out the auxiliary type information. */
4553 hdr
->cbAuxOffset
= offset
;
4554 offset
= ecoff_build_aux (&buf
, &bufend
, offset
);
4555 hdr
->iauxMax
= (offset
- hdr
->cbAuxOffset
) / sizeof (union aux_ext
);
4557 /* Copy out the local strings. */
4558 hdr
->cbSsOffset
= offset
;
4559 offset
= ecoff_build_ss (&buf
, &bufend
, offset
);
4560 hdr
->issMax
= offset
- hdr
->cbSsOffset
;
4562 /* Copy out the external strings. */
4563 hdr
->cbSsExtOffset
= offset
;
4564 offset
+= ecoff_build_strings (&buf
, &bufend
, offset
, &ext_strings
);
4565 offset
= ecoff_padding_adjust (&buf
, &bufend
, offset
, (char **) NULL
);
4566 hdr
->issExtMax
= offset
- hdr
->cbSsExtOffset
;
4568 /* We don't use relative file descriptors. */
4570 hdr
->cbRfdOffset
= 0;
4572 /* Swap out the file descriptors. */
4573 hdr
->cbFdOffset
= offset
;
4574 offset
= ecoff_build_fdr (&buf
, &bufend
, offset
);
4575 hdr
->ifdMax
= (offset
- hdr
->cbFdOffset
) / backend
->external_fdr_size
;
4577 /* Copy out the external symbols. */
4578 hdr
->cbExtOffset
= offset
;
4579 if (bufend
- (buf
+ offset
) < extoffset
)
4580 (void) ecoff_add_bytes (&buf
, &bufend
, buf
+ offset
, extoffset
);
4581 memcpy (buf
+ offset
, extbuf
, extoffset
);
4582 offset
+= extoffset
;
4583 hdr
->iextMax
= (offset
- hdr
->cbExtOffset
) / backend
->external_ext_size
;
4585 know ((offset
& (backend
->debug_align
- 1)) == 0);
4587 /* That completes the symbolic debugging information. We must now
4588 finish up the symbolic header and the ecoff_tdata structure. */
4590 #define SET(ptr, count, type, size) \
4591 ecoff_data (stdoutput)->ptr = (type) set; \
4592 set += hdr->count * size
4594 SET (line
, cbLine
, unsigned char *, sizeof (unsigned char));
4595 SET (external_dnr
, idnMax
, PTR
, backend
->external_dnr_size
);
4596 SET (external_pdr
, ipdMax
, PTR
, backend
->external_pdr_size
);
4597 SET (external_sym
, isymMax
, PTR
, backend
->external_sym_size
);
4598 SET (external_opt
, ioptMax
, PTR
, backend
->external_opt_size
);
4599 SET (external_aux
, iauxMax
, union aux_ext
*, sizeof (union aux_ext
));
4600 SET (ss
, issMax
, char *, sizeof (char));
4601 SET (ssext
, issExtMax
, char *, sizeof (char));
4602 SET (external_rfd
, crfd
, PTR
, backend
->external_rfd_size
);
4603 SET (external_fdr
, ifdMax
, PTR
, backend
->external_fdr_size
);
4604 SET (external_ext
, iextMax
, PTR
, backend
->external_ext_size
);
4608 /* Fill in the register masks. */
4611 struct ecoff_reginfo s
;
4613 regsec
= bfd_make_section (stdoutput
, REGINFO
);
4614 know (regsec
!= NULL
);
4616 if (bfd_get_section_contents (stdoutput
, regsec
, (PTR
) &s
,
4617 (file_ptr
) 0, sizeof s
) == false)
4618 as_fatal ("Can't read REGINFO section");
4621 /* Fill in the MIPS register masks. It's probably not worth
4622 setting up a generic interface for this. */
4623 s
.gprmask
= mips_gprmask
;
4624 s
.cprmask
[0] = mips_cprmask
[0];
4625 s
.cprmask
[1] = mips_cprmask
[1];
4626 s
.cprmask
[2] = mips_cprmask
[2];
4627 s
.cprmask
[3] = mips_cprmask
[3];
4630 if (bfd_set_section_contents (stdoutput
, regsec
, (PTR
) &s
,
4631 (file_ptr
) 0, sizeof s
) == false)
4632 as_fatal ("Can't write REGINFO section");
4635 ecoff_data (stdoutput
)->raw_size
= offset
;
4636 ecoff_data (stdoutput
)->raw_syments
= buf
;
4638 hdr
->magic
= magicSym
;
4639 /* FIXME: what should hdr->vstamp be? */
4641 bfd_set_symtab (stdoutput
, bfd_get_outsymbols (stdoutput
),
4642 (unsigned int) (hdr
->isymMax
+ hdr
->iextMax
));
4645 /* Allocate a cluster of pages. */
4647 #ifndef MALLOC_CHECK
4650 allocate_cluster (npages
)
4651 unsigned long npages
;
4653 register page_t
*value
= (page_t
*) xmalloc (npages
* PAGE_USIZE
);
4657 fprintf (stderr
, "\talloc\tnpages = %d, value = 0x%.8x\n", npages
, value
);
4660 memset (value
, 0, npages
* PAGE_USIZE
);
4666 static page_t
*cluster_ptr
= NULL
;
4667 static unsigned long pages_left
= 0;
4669 #endif /* MALLOC_CHECK */
4671 /* Allocate one page (which is initialized to 0). */
4676 #ifndef MALLOC_CHECK
4678 if (pages_left
== 0)
4680 pages_left
= MAX_CLUSTER_PAGES
;
4681 cluster_ptr
= allocate_cluster (pages_left
);
4685 return cluster_ptr
++;
4687 #else /* MALLOC_CHECK */
4691 ptr
= xmalloc (PAGE_USIZE
);
4692 memset (ptr
, 0, PAGE_USIZE
);
4695 #endif /* MALLOC_CHECK */
4698 /* Allocate scoping information. */
4703 register scope_t
*ptr
;
4704 static scope_t initial_scope
;
4706 #ifndef MALLOC_CHECK
4708 ptr
= alloc_counts
[(int)alloc_type_scope
].free_list
.f_scope
;
4709 if (ptr
!= (scope_t
*) NULL
)
4710 alloc_counts
[ (int)alloc_type_scope
].free_list
.f_scope
= ptr
->free
;
4713 register int unallocated
= alloc_counts
[(int)alloc_type_scope
].unallocated
;
4714 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_scope
].cur_page
;
4716 if (unallocated
== 0)
4718 unallocated
= PAGE_SIZE
/ sizeof (scope_t
);
4719 alloc_counts
[(int)alloc_type_scope
].cur_page
= cur_page
= allocate_page ();
4720 alloc_counts
[(int)alloc_type_scope
].total_pages
++;
4723 ptr
= &cur_page
->scope
[--unallocated
];
4724 alloc_counts
[(int)alloc_type_scope
].unallocated
= unallocated
;
4729 ptr
= (scope_t
*) xmalloc (sizeof (scope_t
));
4733 alloc_counts
[(int)alloc_type_scope
].total_alloc
++;
4734 *ptr
= initial_scope
;
4738 /* Free scoping information. */
4744 alloc_counts
[(int)alloc_type_scope
].total_free
++;
4746 #ifndef MALLOC_CHECK
4747 ptr
->free
= alloc_counts
[(int)alloc_type_scope
].free_list
.f_scope
;
4748 alloc_counts
[(int)alloc_type_scope
].free_list
.f_scope
= ptr
;
4754 /* Allocate links for pages in a virtual array. */
4759 register vlinks_t
*ptr
;
4760 static vlinks_t initial_vlinks
;
4762 #ifndef MALLOC_CHECK
4764 register int unallocated
= alloc_counts
[(int)alloc_type_vlinks
].unallocated
;
4765 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_vlinks
].cur_page
;
4767 if (unallocated
== 0)
4769 unallocated
= PAGE_SIZE
/ sizeof (vlinks_t
);
4770 alloc_counts
[(int)alloc_type_vlinks
].cur_page
= cur_page
= allocate_page ();
4771 alloc_counts
[(int)alloc_type_vlinks
].total_pages
++;
4774 ptr
= &cur_page
->vlinks
[--unallocated
];
4775 alloc_counts
[(int)alloc_type_vlinks
].unallocated
= unallocated
;
4779 ptr
= (vlinks_t
*) xmalloc (sizeof (vlinks_t
));
4783 alloc_counts
[(int)alloc_type_vlinks
].total_alloc
++;
4784 *ptr
= initial_vlinks
;
4788 /* Allocate string hash buckets. */
4793 register shash_t
*ptr
;
4794 static shash_t initial_shash
;
4796 #ifndef MALLOC_CHECK
4798 register int unallocated
= alloc_counts
[(int)alloc_type_shash
].unallocated
;
4799 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_shash
].cur_page
;
4801 if (unallocated
== 0)
4803 unallocated
= PAGE_SIZE
/ sizeof (shash_t
);
4804 alloc_counts
[(int)alloc_type_shash
].cur_page
= cur_page
= allocate_page ();
4805 alloc_counts
[(int)alloc_type_shash
].total_pages
++;
4808 ptr
= &cur_page
->shash
[--unallocated
];
4809 alloc_counts
[(int)alloc_type_shash
].unallocated
= unallocated
;
4813 ptr
= (shash_t
*) xmalloc (sizeof (shash_t
));
4817 alloc_counts
[(int)alloc_type_shash
].total_alloc
++;
4818 *ptr
= initial_shash
;
4822 /* Allocate type hash buckets. */
4827 register thash_t
*ptr
;
4828 static thash_t initial_thash
;
4830 #ifndef MALLOC_CHECK
4832 register int unallocated
= alloc_counts
[(int)alloc_type_thash
].unallocated
;
4833 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_thash
].cur_page
;
4835 if (unallocated
== 0)
4837 unallocated
= PAGE_SIZE
/ sizeof (thash_t
);
4838 alloc_counts
[(int)alloc_type_thash
].cur_page
= cur_page
= allocate_page ();
4839 alloc_counts
[(int)alloc_type_thash
].total_pages
++;
4842 ptr
= &cur_page
->thash
[--unallocated
];
4843 alloc_counts
[(int)alloc_type_thash
].unallocated
= unallocated
;
4847 ptr
= (thash_t
*) xmalloc (sizeof (thash_t
));
4851 alloc_counts
[(int)alloc_type_thash
].total_alloc
++;
4852 *ptr
= initial_thash
;
4856 /* Allocate structure, union, or enum tag information. */
4861 register tag_t
*ptr
;
4862 static tag_t initial_tag
;
4864 #ifndef MALLOC_CHECK
4866 ptr
= alloc_counts
[(int)alloc_type_tag
].free_list
.f_tag
;
4867 if (ptr
!= (tag_t
*) NULL
)
4868 alloc_counts
[(int)alloc_type_tag
].free_list
.f_tag
= ptr
->free
;
4871 register int unallocated
= alloc_counts
[(int)alloc_type_tag
].unallocated
;
4872 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_tag
].cur_page
;
4874 if (unallocated
== 0)
4876 unallocated
= PAGE_SIZE
/ sizeof (tag_t
);
4877 alloc_counts
[(int)alloc_type_tag
].cur_page
= cur_page
= allocate_page ();
4878 alloc_counts
[(int)alloc_type_tag
].total_pages
++;
4881 ptr
= &cur_page
->tag
[--unallocated
];
4882 alloc_counts
[(int)alloc_type_tag
].unallocated
= unallocated
;
4887 ptr
= (tag_t
*) xmalloc (sizeof (tag_t
));
4891 alloc_counts
[(int)alloc_type_tag
].total_alloc
++;
4896 /* Free scoping information. */
4902 alloc_counts
[(int)alloc_type_tag
].total_free
++;
4904 #ifndef MALLOC_CHECK
4905 ptr
->free
= alloc_counts
[(int)alloc_type_tag
].free_list
.f_tag
;
4906 alloc_counts
[(int)alloc_type_tag
].free_list
.f_tag
= ptr
;
4912 /* Allocate forward reference to a yet unknown tag. */
4917 register forward_t
*ptr
;
4918 static forward_t initial_forward
;
4920 #ifndef MALLOC_CHECK
4922 register int unallocated
= alloc_counts
[(int)alloc_type_forward
].unallocated
;
4923 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_forward
].cur_page
;
4925 if (unallocated
== 0)
4927 unallocated
= PAGE_SIZE
/ sizeof (forward_t
);
4928 alloc_counts
[(int)alloc_type_forward
].cur_page
= cur_page
= allocate_page ();
4929 alloc_counts
[(int)alloc_type_forward
].total_pages
++;
4932 ptr
= &cur_page
->forward
[--unallocated
];
4933 alloc_counts
[(int)alloc_type_forward
].unallocated
= unallocated
;
4937 ptr
= (forward_t
*) xmalloc (sizeof (forward_t
));
4941 alloc_counts
[(int)alloc_type_forward
].total_alloc
++;
4942 *ptr
= initial_forward
;
4946 /* Allocate head of type hash list. */
4951 register thead_t
*ptr
;
4952 static thead_t initial_thead
;
4954 #ifndef MALLOC_CHECK
4956 ptr
= alloc_counts
[(int)alloc_type_thead
].free_list
.f_thead
;
4957 if (ptr
!= (thead_t
*) NULL
)
4958 alloc_counts
[ (int)alloc_type_thead
].free_list
.f_thead
= ptr
->free
;
4961 register int unallocated
= alloc_counts
[(int)alloc_type_thead
].unallocated
;
4962 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_thead
].cur_page
;
4964 if (unallocated
== 0)
4966 unallocated
= PAGE_SIZE
/ sizeof (thead_t
);
4967 alloc_counts
[(int)alloc_type_thead
].cur_page
= cur_page
= allocate_page ();
4968 alloc_counts
[(int)alloc_type_thead
].total_pages
++;
4971 ptr
= &cur_page
->thead
[--unallocated
];
4972 alloc_counts
[(int)alloc_type_thead
].unallocated
= unallocated
;
4977 ptr
= (thead_t
*) xmalloc (sizeof (thead_t
));
4981 alloc_counts
[(int)alloc_type_thead
].total_alloc
++;
4982 *ptr
= initial_thead
;
4986 /* Free scoping information. */
4992 alloc_counts
[(int)alloc_type_thead
].total_free
++;
4994 #ifndef MALLOC_CHECK
4995 ptr
->free
= (thead_t
*) alloc_counts
[(int)alloc_type_thead
].free_list
.f_thead
;
4996 alloc_counts
[(int)alloc_type_thead
].free_list
.f_thead
= ptr
;
5002 static lineno_list_t
*
5003 allocate_lineno_list ()
5005 register lineno_list_t
*ptr
;
5006 static lineno_list_t initial_lineno_list
;
5008 #ifndef MALLOC_CHECK
5010 register int unallocated
= alloc_counts
[(int)alloc_type_lineno
].unallocated
;
5011 register page_t
*cur_page
= alloc_counts
[(int)alloc_type_lineno
].cur_page
;
5013 if (unallocated
== 0)
5015 unallocated
= PAGE_SIZE
/ sizeof (lineno_list_t
);
5016 alloc_counts
[(int)alloc_type_lineno
].cur_page
= cur_page
= allocate_page ();
5017 alloc_counts
[(int)alloc_type_lineno
].total_pages
++;
5020 ptr
= &cur_page
->lineno
[--unallocated
];
5021 alloc_counts
[(int)alloc_type_lineno
].unallocated
= unallocated
;
5025 ptr
= (lineno_list_t
*) xmalloc (sizeof (lineno_list_t
));
5029 alloc_counts
[(int)alloc_type_lineno
].total_alloc
++;
5030 *ptr
= initial_lineno_list
;