1 /* ECOFF debugging support.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Cygnus Support.
6 This file was put together by Ian Lance Taylor <ian@cygnus.com>. A
7 good deal of it comes directly from mips-tfile.c, by Michael
8 Meissner <meissner@osf.org>.
10 This file is part of GAS.
12 GAS is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GAS is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GAS; see the file COPYING. If not, write to the Free
24 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
29 /* This file is compiled conditionally for those targets which use
30 ECOFF debugging information (e.g., MIPS ELF, Alpha ECOFF). */
34 #ifdef ECOFF_DEBUGGING
36 #include "coff/internal.h"
37 #include "coff/symconst.h"
38 #include "aout/stab_gnu.h"
39 #include "filenames.h"
40 #include "safe-ctype.h"
42 /* Why isn't this in coff/sym.h? */
43 #define ST_RFDESCAPE 0xfff
45 /* This file constructs the information used by the ECOFF debugging
46 format. It just builds a large block of data.
48 We support both ECOFF style debugging and stabs debugging (the
49 stabs symbols are encapsulated in ECOFF symbols). This should let
50 us handle anything the compiler might throw at us. */
52 /* Here is a brief description of the MIPS ECOFF symbol table, by
53 Michael Meissner. The MIPS symbol table has the following pieces:
59 +-- Dense number table
67 +-- Relative file descriptors
79 The symbolic header points to each of the other tables, and also
80 contains the number of entries. It also contains a magic number
81 and MIPS compiler version number, such as 2.0.
83 The auxiliary table is a series of 32 bit integers, that are
84 referenced as needed from the local symbol table. Unlike standard
85 COFF, the aux. information does not follow the symbol that uses
86 it, but rather is a separate table. In theory, this would allow
87 the MIPS compilers to collapse duplicate aux. entries, but I've not
88 noticed this happening with the 1.31 compiler suite. The different
89 types of aux. entries are:
91 1) dnLow: Low bound on array dimension.
93 2) dnHigh: High bound on array dimension.
95 3) isym: Index to the local symbol which is the start of the
96 function for the end of function first aux. entry.
98 4) width: Width of structures and bitfields.
100 5) count: Count of ranges for variant part.
102 6) rndx: A relative index into the symbol table. The relative
103 index field has two parts: rfd which is a pointer into the
104 relative file index table or ST_RFDESCAPE which says the next
105 aux. entry is the file number, and index: which is the pointer
106 into the local symbol within a given file table. This is for
107 things like references to types defined in another file.
109 7) Type information: This is like the COFF type bits, except it
110 is 32 bits instead of 16; they still have room to add new
111 basic types; and they can handle more than 6 levels of array,
112 pointer, function, etc. Each type information field contains
113 the following structure members:
115 a) fBitfield: a bit that says this is a bitfield, and the
116 size in bits follows as the next aux. entry.
118 b) continued: a bit that says the next aux. entry is a
119 continuation of the current type information (in case
120 there are more than 6 levels of array/ptr/function).
122 c) bt: an integer containing the base type before adding
123 array, pointer, function, etc. qualifiers. The
124 current base types that I have documentation for are:
127 btAdr -- address - integer same size as ptr
129 btUChar -- unsigned character
131 btUShort -- unsigned short
133 btUInt -- unsigned int
135 btULong -- unsigned long
136 btFloat -- float (real)
137 btDouble -- Double (real)
138 btStruct -- Structure (Record)
139 btUnion -- Union (variant)
141 btTypedef -- defined via a typedef isymRef
142 btRange -- subrange of int
144 btComplex -- fortran complex
145 btDComplex -- fortran double complex
146 btIndirect -- forward or unnamed typedef
147 btFixedDec -- Fixed Decimal
148 btFloatDec -- Float Decimal
149 btString -- Varying Length Character String
150 btBit -- Aligned Bit String
152 btVoid -- Void (MIPS cc revision >= 2.00)
154 d) tq0 - tq5: type qualifier fields as needed. The
155 current type qualifier fields I have documentation for
158 tqNil -- no more qualifiers
162 tqFar -- 8086 far pointers
165 The dense number table is used in the front ends, and disappears by
166 the time the .o is created.
168 With the 1.31 compiler suite, the optimization symbols don't seem
169 to be used as far as I can tell.
171 The linker is the first entity that creates the relative file
172 descriptor table, and I believe it is used so that the individual
173 file table pointers don't have to be rewritten when the objects are
174 merged together into the program file.
176 Unlike COFF, the basic symbol & string tables are split into
177 external and local symbols/strings. The relocation information
178 only goes off of the external symbol table, and the debug
179 information only goes off of the internal symbol table. The
180 external symbols can have links to an appropriate file index and
181 symbol within the file to give it the appropriate type information.
182 Because of this, the external symbols are actually larger than the
183 internal symbols (to contain the link information), and contain the
184 local symbol structure as a member, though this member is not the
185 first member of the external symbol structure (!). I suspect this
186 split is to make strip easier to deal with.
188 Each file table has offsets for where the line numbers, local
189 strings, local symbols, and procedure table starts from within the
190 global tables, and the indexs are reset to 0 for each of those
193 The procedure table contains the binary equivalents of the .ent
194 (start of the function address), .frame (what register is the
195 virtual frame pointer, constant offset from the register to obtain
196 the VFP, and what register holds the return address), .mask/.fmask
197 (bitmask of saved registers, and where the first register is stored
198 relative to the VFP) assembler directives. It also contains the
199 low and high bounds of the line numbers if debugging is turned on.
201 The line number table is a compressed form of the normal COFF line
202 table. Each line number entry is either 1 or 3 bytes long, and
203 contains a signed delta from the previous line, and an unsigned
204 count of the number of instructions this statement takes.
206 The local symbol table contains the following fields:
208 1) iss: index to the local string table giving the name of the
211 2) value: value of the symbol (address, register number, etc.).
213 3) st: symbol type. The current symbol types are:
215 stNil -- Nuthin' special
216 stGlobal -- external symbol
218 stParam -- procedure argument
219 stLocal -- local variable
221 stProc -- External Procedure
222 stBlock -- beginning of block
223 stEnd -- end (of anything)
224 stMember -- member (of anything)
225 stTypedef -- type definition
227 stRegReloc -- register relocation
228 stForward -- forwarding address
229 stStaticProc -- Static procedure
232 4) sc: storage class. The current storage classes are:
234 scText -- text symbol
235 scData -- initialized data symbol
236 scBss -- un-initialized data symbol
237 scRegister -- value of symbol is register number
238 scAbs -- value of symbol is absolute
239 scUndefined -- who knows?
240 scCdbLocal -- variable's value is IN se->va.??
241 scBits -- this is a bit field
242 scCdbSystem -- value is IN debugger's address space
243 scRegImage -- register value saved on stack
244 scInfo -- symbol contains debugger information
245 scUserStruct -- addr in struct user for current process
246 scSData -- load time only small data
247 scSBss -- load time only small common
248 scRData -- load time only read only data
249 scVar -- Var parameter (fortranpascal)
250 scCommon -- common variable
251 scSCommon -- small common
252 scVarRegister -- Var parameter in a register
253 scVariant -- Variant record
254 scSUndefined -- small undefined(external) data
255 scInit -- .init section symbol
257 5) index: pointer to a local symbol or aux. entry.
259 For the following program:
264 printf("Hello World!\n");
268 Mips-tdump produces the following information:
273 timestamp 645311799, Wed Jun 13 17:16:39 1990
274 symbolic header offset 284
275 symbolic header size 96
279 Symbolic header, magic number = 0x7009, vstamp = 1.31:
281 Info Offset Number Bytes
282 ==== ====== ====== =====
284 Line numbers 380 4 4 [13]
286 Procedures Tables 384 1 52
287 Local Symbols 436 16 192
288 Optimization Symbols 0 0 0
289 Auxiliary Symbols 628 39 156
290 Local Strings 784 80 80
291 External Strings 864 144 144
292 File Tables 1008 2 144
294 External Symbols 1152 20 320
298 Name index = 1 Readin = No
299 Merge = No Endian = LITTLE
300 Debug level = G2 Language = C
303 Info Start Number Size Offset
304 ==== ===== ====== ==== ======
305 Local strings 0 15 15 784
306 Local symbols 0 6 72 436
307 Line numbers 0 13 13 380
308 Optimization symbols 0 0 0 0
309 Procedures 0 1 52 384
310 Auxiliary symbols 0 14 56 628
311 Relative Files 0 0 0 0
313 There are 6 local symbols, starting at 436
315 Symbol# 0: "hello2.c"
318 Storage class = Text Index = 6
319 Symbol type = File Value = 0
325 Storage class = Text Index = 12
326 Symbol type = Proc Value = 0
331 Storage class = Text Index = 4
332 Symbol type = Block Value = 8
337 Storage class = Text Index = 2
338 Symbol type = End Value = 28
343 Storage class = Text Index = 1
344 Symbol type = End Value = 52
346 Symbol# 5: "hello2.c"
349 Storage class = Text Index = 0
350 Symbol type = End Value = 0
352 There are 14 auxiliary table entries, starting at 628.
354 * #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
355 * #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
356 * #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0]
357 * #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0]
358 * #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
359 * #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0]
360 * #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0]
361 * #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0]
362 * #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0]
363 * #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0]
364 * #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0]
365 * #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0]
366 #12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0]
367 #13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0]
369 There are 1 procedure descriptor entries, starting at 0.
371 Procedure descriptor 0:
372 Name index = 10 Name = "main"
373 .mask 0x80000000,-4 .fmask 0x00000000,0
375 Opt. start = -1 Symbols start = 1
376 First line # = 3 Last line # = 6
377 Line Offset = 0 Address = 0x00000000
379 There are 4 bytes holding line numbers, starting at 380.
380 Line 3, delta 0, count 2
381 Line 4, delta 1, count 3
382 Line 5, delta 1, count 2
383 Line 6, delta 1, count 6
385 File #1, "/usr/include/stdio.h"
387 Name index = 1 Readin = No
388 Merge = Yes Endian = LITTLE
389 Debug level = G2 Language = C
392 Info Start Number Size Offset
393 ==== ===== ====== ==== ======
394 Local strings 15 65 65 799
395 Local symbols 6 10 120 508
396 Line numbers 0 0 0 380
397 Optimization symbols 0 0 0 0
399 Auxiliary symbols 14 25 100 684
400 Relative Files 0 0 0 0
402 There are 10 local symbols, starting at 442
404 Symbol# 0: "/usr/include/stdio.h"
407 Storage class = Text Index = 10
408 Symbol type = File Value = 0
413 Storage class = Info Index = 9
414 Symbol type = Block Value = 20
419 Storage class = Info Index = 4
420 Symbol type = Member Value = 0
425 Storage class = Info Index = 15
426 Symbol type = Member Value = 32
431 Storage class = Info Index = 16
432 Symbol type = Member Value = 64
437 Storage class = Info Index = 4
438 Symbol type = Member Value = 96
443 Storage class = Info Index = 3
444 Symbol type = Member Value = 128
449 Storage class = Info Index = 2
450 Symbol type = Member Value = 144
455 Storage class = Info Index = 1
456 Symbol type = End Value = 0
458 Symbol# 9: "/usr/include/stdio.h"
461 Storage class = Text Index = 0
462 Symbol type = End Value = 0
464 There are 25 auxiliary table entries, starting at 642.
466 * #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f]
467 #15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
468 #16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0]
469 * #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0]
470 * #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1]
471 * #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
472 * #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4]
473 * #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0]
474 * #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
475 * #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0]
476 * #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0]
477 * #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
478 * #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
479 * #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
480 * #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
481 * #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
482 * #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
483 * #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
484 * #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
485 * #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
486 * #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
487 * #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
488 * #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
489 * #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
490 * #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0]
492 There are 0 procedure descriptor entries, starting at 1.
494 There are 20 external symbols, starting at 1152
497 Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 }
498 String index = 0 Ifd = 1
499 Storage class = Nil Index = 17
500 Symbol type = Global Value = 60
503 String index = 5 Ifd = 1
504 Storage class = Nil Index = 1048575
505 Symbol type = Proc Value = 0
508 String index = 11 Ifd = 1
509 Storage class = Nil Index = 1048575
510 Symbol type = Proc Value = 0
513 String index = 18 Ifd = 1
514 Storage class = Nil Index = 1048575
515 Symbol type = Proc Value = 0
518 String index = 26 Ifd = 1
519 Storage class = Nil Index = 1048575
520 Symbol type = Proc Value = 0
523 String index = 32 Ifd = 1
524 Storage class = Nil Index = 1048575
525 Symbol type = Proc Value = 0
528 String index = 40 Ifd = 1
529 Storage class = Nil Index = 1048575
530 Symbol type = Proc Value = 0
533 String index = 46 Ifd = 1
534 Storage class = Nil Index = 1048575
535 Symbol type = Proc Value = 0
538 String index = 53 Ifd = 1
539 Storage class = Nil Index = 1048575
540 Symbol type = Proc Value = 0
542 Symbol# 9: "setbuffer"
543 String index = 60 Ifd = 1
544 Storage class = Nil Index = 1048575
545 Symbol type = Proc Value = 0
547 Symbol# 10: "setlinebuf"
548 String index = 70 Ifd = 1
549 Storage class = Nil Index = 1048575
550 Symbol type = Proc Value = 0
553 String index = 81 Ifd = 1
554 Storage class = Nil Index = 1048575
555 Symbol type = Proc Value = 0
558 String index = 87 Ifd = 1
559 Storage class = Nil Index = 1048575
560 Symbol type = Proc Value = 0
562 Symbol# 13: "ctermid"
563 String index = 92 Ifd = 1
564 Storage class = Nil Index = 1048575
565 Symbol type = Proc Value = 0
567 Symbol# 14: "cuserid"
568 String index = 100 Ifd = 1
569 Storage class = Nil Index = 1048575
570 Symbol type = Proc Value = 0
572 Symbol# 15: "tempnam"
573 String index = 108 Ifd = 1
574 Storage class = Nil Index = 1048575
575 Symbol type = Proc Value = 0
578 String index = 116 Ifd = 1
579 Storage class = Nil Index = 1048575
580 Symbol type = Proc Value = 0
582 Symbol# 17: "sprintf"
583 String index = 123 Ifd = 1
584 Storage class = Nil Index = 1048575
585 Symbol type = Proc Value = 0
589 String index = 131 Ifd = 0
590 Storage class = Text Index = 1
591 Symbol type = Proc Value = 0
594 String index = 136 Ifd = 0
595 Storage class = Undefined Index = 1048575
596 Symbol type = Proc Value = 0
598 The following auxiliary table entries were unused:
602 #3 16 0x00000010 short
604 #5 32 0x00000020 long
605 #6 40 0x00000028 float
606 #7 44 0x0000002c double
607 #8 12 0x0000000c unsigned char
608 #9 20 0x00000014 unsigned short
609 #10 28 0x0000001c unsigned int
610 #11 36 0x00000024 unsigned long
611 #14 0 0x00000000 void
612 #15 24 0x00000018 int
613 #19 32 0x00000020 long
614 #20 40 0x00000028 float
615 #21 44 0x0000002c double
616 #22 12 0x0000000c unsigned char
617 #23 20 0x00000014 unsigned short
618 #24 28 0x0000001c unsigned int
619 #25 36 0x00000024 unsigned long
620 #26 48 0x00000030 struct no name { ifd = -1, index = 1048575 }
623 /* Redefinition of of storage classes as an enumeration for better
627 sc_Nil = scNil, /* no storage class */
628 sc_Text = scText, /* text symbol */
629 sc_Data = scData, /* initialized data symbol */
630 sc_Bss = scBss, /* un-initialized data symbol */
631 sc_Register = scRegister, /* value of symbol is register number */
632 sc_Abs = scAbs, /* value of symbol is absolute */
633 sc_Undefined = scUndefined, /* who knows? */
634 sc_CdbLocal = scCdbLocal, /* variable's value is IN se->va.?? */
635 sc_Bits = scBits, /* this is a bit field */
636 sc_CdbSystem = scCdbSystem, /* value is IN CDB's address space */
637 sc_RegImage = scRegImage, /* register value saved on stack */
638 sc_Info = scInfo, /* symbol contains debugger information */
639 sc_UserStruct = scUserStruct, /* addr in struct user for current process */
640 sc_SData = scSData, /* load time only small data */
641 sc_SBss = scSBss, /* load time only small common */
642 sc_RData = scRData, /* load time only read only data */
643 sc_Var = scVar, /* Var parameter (fortran,pascal) */
644 sc_Common = scCommon, /* common variable */
645 sc_SCommon = scSCommon, /* small common */
646 sc_VarRegister = scVarRegister, /* Var parameter in a register */
647 sc_Variant = scVariant, /* Variant record */
648 sc_SUndefined = scSUndefined, /* small undefined(external) data */
649 sc_Init = scInit, /* .init section symbol */
650 sc_Max = scMax /* Max storage class+1 */
653 /* Redefinition of symbol type. */
656 st_Nil = stNil, /* Nuthin' special */
657 st_Global = stGlobal, /* external symbol */
658 st_Static = stStatic, /* static */
659 st_Param = stParam, /* procedure argument */
660 st_Local = stLocal, /* local variable */
661 st_Label = stLabel, /* label */
662 st_Proc = stProc, /* " " Procedure */
663 st_Block = stBlock, /* beginning of block */
664 st_End = stEnd, /* end (of anything) */
665 st_Member = stMember, /* member (of anything - struct/union/enum */
666 st_Typedef = stTypedef, /* type definition */
667 st_File = stFile, /* file name */
668 st_RegReloc = stRegReloc, /* register relocation */
669 st_Forward = stForward, /* forwarding address */
670 st_StaticProc = stStaticProc, /* load time only static procs */
671 st_Constant = stConstant, /* const */
672 st_Str = stStr, /* string */
673 st_Number = stNumber, /* pure number (ie. 4 NOR 2+2) */
674 st_Expr = stExpr, /* 2+2 vs. 4 */
675 st_Type = stType, /* post-coercion SER */
676 st_Max = stMax /* max type+1 */
679 /* Redefinition of type qualifiers. */
682 tq_Nil = tqNil, /* bt is what you see */
683 tq_Ptr = tqPtr, /* pointer */
684 tq_Proc = tqProc, /* procedure */
685 tq_Array = tqArray, /* duh */
686 tq_Far = tqFar, /* longer addressing - 8086/8 land */
687 tq_Vol = tqVol, /* volatile */
688 tq_Max = tqMax /* Max type qualifier+1 */
691 /* Redefinition of basic types. */
694 bt_Nil = btNil, /* undefined */
695 bt_Adr = btAdr, /* address - integer same size as pointer */
696 bt_Char = btChar, /* character */
697 bt_UChar = btUChar, /* unsigned character */
698 bt_Short = btShort, /* short */
699 bt_UShort = btUShort, /* unsigned short */
700 bt_Int = btInt, /* int */
701 bt_UInt = btUInt, /* unsigned int */
702 bt_Long = btLong, /* long */
703 bt_ULong = btULong, /* unsigned long */
704 bt_Float = btFloat, /* float (real) */
705 bt_Double = btDouble, /* Double (real) */
706 bt_Struct = btStruct, /* Structure (Record) */
707 bt_Union = btUnion, /* Union (variant) */
708 bt_Enum = btEnum, /* Enumerated */
709 bt_Typedef = btTypedef, /* defined via a typedef, isymRef points */
710 bt_Range = btRange, /* subrange of int */
711 bt_Set = btSet, /* pascal sets */
712 bt_Complex = btComplex, /* fortran complex */
713 bt_DComplex = btDComplex, /* fortran double complex */
714 bt_Indirect = btIndirect, /* forward or unnamed typedef */
715 bt_FixedDec = btFixedDec, /* Fixed Decimal */
716 bt_FloatDec = btFloatDec, /* Float Decimal */
717 bt_String = btString, /* Varying Length Character String */
718 bt_Bit = btBit, /* Aligned Bit String */
719 bt_Picture = btPicture, /* Picture */
720 bt_Void = btVoid, /* Void */
721 bt_Max = btMax /* Max basic type+1 */
726 /* States for whether to hash type or not. */
727 typedef enum hash_state {
728 hash_no = 0, /* Don't hash type */
729 hash_yes = 1, /* OK to hash type, or use previous hash */
730 hash_record = 2 /* OK to record hash, but don't use prev. */
733 /* Types of different sized allocation requests. */
735 alloc_type_none, /* dummy value */
736 alloc_type_scope, /* nested scopes linked list */
737 alloc_type_vlinks, /* glue linking pages in varray */
738 alloc_type_shash, /* string hash element */
739 alloc_type_thash, /* type hash element */
740 alloc_type_tag, /* struct/union/tag element */
741 alloc_type_forward, /* element to hold unknown tag */
742 alloc_type_thead, /* head of type hash list */
743 alloc_type_varray, /* general varray allocation */
744 alloc_type_lineno, /* line number list */
745 alloc_type_last /* last+1 element for array bounds */
748 /* Types of auxiliary type information. */
750 aux_tir, /* TIR type information */
751 aux_rndx, /* relative index into symbol table */
752 aux_dnLow, /* low dimension */
753 aux_dnHigh, /* high dimension */
754 aux_isym, /* symbol table index (end of proc) */
755 aux_iss, /* index into string space (not used) */
756 aux_width, /* width for non-default sized struc fields */
757 aux_count /* count of ranges for variant arm */
760 /* Structures to provide n-number of virtual arrays, each of which can
761 grow linearly, and which are written in the object file as
762 sequential pages. On systems with a BSD malloc, the
763 MAX_CLUSTER_PAGES should be 1 less than a power of two, since
764 malloc adds it's overhead, and rounds up to the next power of 2.
765 Pages are linked together via a linked list.
767 If PAGE_SIZE is > 4096, the string length in the shash_t structure
768 can't be represented (assuming there are strings > 4096 bytes). */
770 /* FIXME: Yes, there can be such strings while emitting C++ class debug
771 info. Templates are the offender here, the test case in question
772 having a mangled class name of
774 t7rb_tree4Z4xkeyZt4pair2ZC4xkeyZt7xsocket1Z4UserZt9select1st2Zt4pair\
775 2ZC4xkeyZt7xsocket1Z4UserZ4xkeyZt4less1Z4xkey
777 Repeat that a couple dozen times while listing the class members and
778 you've got strings over 4k. Hack around this for now by increasing
779 the page size. A proper solution would abandon this structure scheme
780 certainly for very large strings, and possibly entirely. */
783 #define PAGE_SIZE (8*1024) /* size of varray pages */
786 #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
788 #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
789 #define MAX_CLUSTER_PAGES 63
792 /* Linked list connecting separate page allocations. */
793 typedef struct vlinks {
794 struct vlinks *prev; /* previous set of pages */
795 struct vlinks *next; /* next set of pages */
796 union page *datum; /* start of page */
797 unsigned long start_index; /* starting index # of page */
800 /* Virtual array header. */
801 typedef struct varray {
802 vlinks_t *first; /* first page link */
803 vlinks_t *last; /* last page link */
804 unsigned long num_allocated; /* # objects allocated */
805 unsigned short object_size; /* size in bytes of each object */
806 unsigned short objects_per_page; /* # objects that can fit on a page */
807 unsigned short objects_last_page; /* # objects allocated on last page */
811 #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
813 #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
816 #define INIT_VARRAY(type) { /* macro to initialize a varray */ \
817 (vlinks_t *)0, /* first */ \
818 (vlinks_t *)0, /* last */ \
819 0, /* num_allocated */ \
820 sizeof (type), /* object_size */ \
821 OBJECTS_PER_PAGE (type), /* objects_per_page */ \
822 OBJECTS_PER_PAGE (type), /* objects_last_page */ \
825 /* Master type for indexes within the symbol table. */
826 typedef unsigned long symint_t;
828 /* Linked list support for nested scopes (file, block, structure, etc.). */
829 typedef struct scope {
830 struct scope *prev; /* previous scope level */
831 struct scope *free; /* free list pointer */
832 struct localsym *lsym; /* pointer to local symbol node */
833 st_t type; /* type of the node */
836 /* For a local symbol we store a gas symbol as well as the debugging
837 information we generate. The gas symbol will be NULL if this is
838 only a debugging symbol. */
839 typedef struct localsym {
840 const char *name; /* symbol name */
841 symbolS *as_sym; /* symbol as seen by gas */
842 bfd_vma addend; /* addend to as_sym value */
843 struct efdr *file_ptr; /* file pointer */
844 struct ecoff_proc *proc_ptr; /* proc pointer */
845 struct localsym *begin_ptr; /* symbol at start of block */
846 struct ecoff_aux *index_ptr; /* index value to be filled in */
847 struct forward *forward_ref; /* forward references to this symbol */
848 long sym_index; /* final symbol index */
849 EXTR ecoff_sym; /* ECOFF debugging symbol */
852 /* For aux information we keep the type and the data. */
853 typedef struct ecoff_aux {
854 enum aux_type type; /* aux type */
855 AUXU data; /* aux data */
858 /* For a procedure we store the gas symbol as well as the PDR
859 debugging information. */
860 typedef struct ecoff_proc {
861 localsym_t *sym; /* associated symbol */
862 PDR pdr; /* ECOFF debugging info */
865 /* Number of proc_t structures allocated. */
866 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 */
876 /* Linked list support for tags. The first tag in the list is always
877 the current tag for that block. */
879 struct tag *free; /* free list pointer */
880 struct shash *hash_ptr; /* pointer to the hash table head */
881 struct tag *same_name; /* tag with same name in outer scope */
882 struct tag *same_block; /* next tag defined in the same block. */
883 struct forward *forward_ref; /* list of forward references */
884 bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */
885 symint_t ifd; /* file # tag defined in */
886 localsym_t *sym; /* file's local symbols */
889 /* Head of a block's linked list of tags. */
890 typedef struct thead {
891 struct thead *prev; /* previous block */
892 struct thead *free; /* free list pointer */
893 struct tag *first_tag; /* first tag in block defined */
896 /* Union containing pointers to each the small structures which are freed up. */
897 typedef union small_free {
898 scope_t *f_scope; /* scope structure */
899 thead_t *f_thead; /* tag head structure */
900 tag_t *f_tag; /* tag element structure */
901 forward_t *f_forward; /* forward tag reference */
904 /* String hash table entry. */
906 typedef struct shash {
907 char *string; /* string we are hashing */
908 symint_t indx; /* index within string table */
909 EXTR *esym_ptr; /* global symbol pointer */
910 localsym_t *sym_ptr; /* local symbol pointer */
911 localsym_t *end_ptr; /* symbol pointer to end block */
912 tag_t *tag_ptr; /* tag pointer */
913 proc_t *proc_ptr; /* procedure descriptor pointer */
916 /* Type hash table support. The size of the hash table must fit
917 within a page with the other extended file descriptor information.
918 Because unique types which are hashed are fewer in number than
919 strings, we use a smaller hash value. */
924 #define THASH_SIZE 113
927 typedef struct thash {
928 struct thash *next; /* next hash value */
929 AUXU type; /* type we are hashing */
930 symint_t indx; /* index within string table */
933 /* Extended file descriptor that contains all of the support necessary
934 to add things to each file separately. */
935 typedef struct efdr {
936 FDR fdr; /* File header to be written out */
937 FDR *orig_fdr; /* original file header */
938 char *name; /* filename */
939 int fake; /* whether this is faked .file */
940 symint_t void_type; /* aux. pointer to 'void' type */
941 symint_t int_type; /* aux. pointer to 'int' type */
942 scope_t *cur_scope; /* current nested scopes */
943 symint_t file_index; /* current file number */
944 int nested_scopes; /* # nested scopes */
945 varray_t strings; /* local strings */
946 varray_t symbols; /* local symbols */
947 varray_t procs; /* procedures */
948 varray_t aux_syms; /* auxiliary symbols */
949 struct efdr *next_file; /* next file descriptor */
950 /* string/type hash tables */
951 struct hash_control *str_hash; /* string hash table */
952 thash_t *thash_head[THASH_SIZE];
955 /* Pre-initialized extended file structure. */
956 static const efdr_t init_file = {
957 { /* FDR structure */
958 0, /* adr: memory address of beginning of file */
959 0, /* rss: file name (of source, if known) */
960 0, /* issBase: file's string space */
961 0, /* cbSs: number of bytes in the ss */
962 0, /* isymBase: beginning of symbols */
963 0, /* csym: count file's of symbols */
964 0, /* ilineBase: file's line symbols */
965 0, /* cline: count of file's line symbols */
966 0, /* ioptBase: file's optimization entries */
967 0, /* copt: count of file's optimization entries */
968 0, /* ipdFirst: start of procedures for this file */
969 0, /* cpd: count of procedures for this file */
970 0, /* iauxBase: file's auxiliary entries */
971 0, /* caux: count of file's auxiliary entries */
972 0, /* rfdBase: index into the file indirect table */
973 0, /* crfd: count file indirect entries */
974 langC, /* lang: language for this file */
975 1, /* fMerge: whether this file can be merged */
976 0, /* fReadin: true if read in (not just created) */
977 TARGET_BYTES_BIG_ENDIAN, /* fBigendian: if 1, compiled on big endian machine */
978 GLEVEL_2, /* glevel: level this file was compiled with */
979 0, /* reserved: reserved for future use */
980 0, /* cbLineOffset: byte offset from header for this file ln's */
981 0, /* cbLine: size of lines for this file */
984 (FDR *)0, /* orig_fdr: original file header pointer */
985 (char *)0, /* name: pointer to filename */
986 0, /* fake: whether this is a faked .file */
987 0, /* void_type: ptr to aux node for void type */
988 0, /* int_type: ptr to aux node for int type */
989 (scope_t *)0, /* cur_scope: current scope being processed */
990 0, /* file_index: current file # */
991 0, /* nested_scopes: # nested scopes */
992 INIT_VARRAY (char), /* strings: local string varray */
993 INIT_VARRAY (localsym_t), /* symbols: local symbols varray */
994 INIT_VARRAY (proc_t), /* procs: procedure varray */
995 INIT_VARRAY (aux_t), /* aux_syms: auxiliary symbols varray */
997 (struct efdr *)0, /* next_file: next file structure */
999 (struct hash_control *)0, /* str_hash: string hash table */
1000 { 0 }, /* thash_head: type hash table */
1003 static efdr_t *first_file; /* first file descriptor */
1004 static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */
1006 /* Line number information is kept in a list until the assembly is
1008 typedef struct lineno_list {
1009 struct lineno_list *next; /* next element in list */
1010 efdr_t *file; /* file this line is in */
1011 proc_t *proc; /* procedure this line is in */
1012 fragS *frag; /* fragment this line number is in */
1013 unsigned long paddr; /* offset within fragment */
1014 long lineno; /* actual line number */
1017 static lineno_list_t *first_lineno;
1018 static lineno_list_t *last_lineno;
1019 static lineno_list_t **last_lineno_ptr = &first_lineno;
1021 /* Sometimes there will be some .loc statements before a .ent. We
1022 keep them in this list so that we can fill in the procedure pointer
1023 after we see the .ent. */
1024 static lineno_list_t *noproc_lineno;
1026 /* Union of various things that are held in pages. */
1027 typedef union page {
1028 char byte [ PAGE_SIZE ];
1029 unsigned char ubyte [ PAGE_SIZE ];
1030 efdr_t file [ PAGE_SIZE / sizeof (efdr_t) ];
1031 FDR ofile [ PAGE_SIZE / sizeof (FDR) ];
1032 proc_t proc [ PAGE_SIZE / sizeof (proc_t) ];
1033 localsym_t sym [ PAGE_SIZE / sizeof (localsym_t) ];
1034 aux_t aux [ PAGE_SIZE / sizeof (aux_t) ];
1035 DNR dense [ PAGE_SIZE / sizeof (DNR) ];
1036 scope_t scope [ PAGE_SIZE / sizeof (scope_t) ];
1037 vlinks_t vlinks [ PAGE_SIZE / sizeof (vlinks_t) ];
1038 shash_t shash [ PAGE_SIZE / sizeof (shash_t) ];
1039 thash_t thash [ PAGE_SIZE / sizeof (thash_t) ];
1040 tag_t tag [ PAGE_SIZE / sizeof (tag_t) ];
1041 forward_t forward [ PAGE_SIZE / sizeof (forward_t) ];
1042 thead_t thead [ PAGE_SIZE / sizeof (thead_t) ];
1043 lineno_list_t lineno [ PAGE_SIZE / sizeof (lineno_list_t) ];
1046 /* Structure holding allocation information for small sized structures. */
1047 typedef struct alloc_info {
1048 char *alloc_name; /* name of this allocation type (must be first) */
1049 page_type *cur_page; /* current page being allocated from */
1050 small_free_t free_list; /* current free list if any */
1051 int unallocated; /* number of elements unallocated on page */
1052 int total_alloc; /* total number of allocations */
1053 int total_free; /* total number of frees */
1054 int total_pages; /* total number of pages allocated */
1057 /* Type information collected together. */
1058 typedef struct type_info {
1059 bt_t basic_type; /* basic type */
1060 int orig_type; /* original COFF-based type */
1061 int num_tq; /* # type qualifiers */
1062 int num_dims; /* # dimensions */
1063 int num_sizes; /* # sizes */
1064 int extra_sizes; /* # extra sizes not tied with dims */
1065 tag_t * tag_ptr; /* tag pointer */
1066 int bitfield; /* symbol is a bitfield */
1067 tq_t type_qualifiers[N_TQ]; /* type qualifiers (ptr, func, array)*/
1068 symint_t dimensions [N_TQ]; /* dimensions for each array */
1069 symint_t sizes [N_TQ+2]; /* sizes of each array slice + size of
1070 struct/union/enum + bitfield size */
1073 /* Pre-initialized type_info struct. */
1074 static const type_info_t type_info_init = {
1075 bt_Nil, /* basic type */
1076 T_NULL, /* original COFF-based type */
1077 0, /* # type qualifiers */
1078 0, /* # dimensions */
1080 0, /* sizes not tied with dims */
1081 NULL, /* ptr to tag */
1083 { /* type qualifiers */
1111 /* Global hash table for the tags table and global table for file
1114 static varray_t file_desc = INIT_VARRAY (efdr_t);
1116 static struct hash_control *tag_hash;
1118 /* Static types for int and void. Also, remember the last function's
1119 type (which is set up when we encounter the declaration for the
1120 function, and used when the end block for the function is emitted. */
1122 static type_info_t int_type_info;
1123 static type_info_t void_type_info;
1124 static type_info_t last_func_type_info;
1125 static symbolS *last_func_sym_value;
1127 /* Convert COFF basic type to ECOFF basic type. The T_NULL type
1128 really should use bt_Void, but this causes the current ecoff GDB to
1129 issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS
1130 2.0) doesn't understand it, even though the compiler generates it.
1131 Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler
1132 suite, but for now go with what works.
1134 It would make sense for the .type and .scl directives to use the
1135 ECOFF numbers directly, rather than using the COFF numbers and
1136 mapping them. Unfortunately, this is historically what mips-tfile
1137 expects, and changing gcc now would be a considerable pain (the
1138 native compiler generates debugging information internally, rather
1139 than via the assembler, so it will never use .type or .scl). */
1141 static const bt_t map_coff_types[] = {
1142 bt_Nil, /* T_NULL */
1144 bt_Char, /* T_CHAR */
1145 bt_Short, /* T_SHORT */
1147 bt_Long, /* T_LONG */
1148 bt_Float, /* T_FLOAT */
1149 bt_Double, /* T_DOUBLE */
1150 bt_Struct, /* T_STRUCT */
1151 bt_Union, /* T_UNION */
1152 bt_Enum, /* T_ENUM */
1153 bt_Enum, /* T_MOE */
1154 bt_UChar, /* T_UCHAR */
1155 bt_UShort, /* T_USHORT */
1156 bt_UInt, /* T_UINT */
1157 bt_ULong /* T_ULONG */
1160 /* Convert COFF storage class to ECOFF storage class. */
1161 static const sc_t map_coff_storage[] = {
1162 sc_Nil, /* 0: C_NULL */
1163 sc_Abs, /* 1: C_AUTO auto var */
1164 sc_Undefined, /* 2: C_EXT external */
1165 sc_Data, /* 3: C_STAT static */
1166 sc_Register, /* 4: C_REG register */
1167 sc_Undefined, /* 5: C_EXTDEF ??? */
1168 sc_Text, /* 6: C_LABEL label */
1169 sc_Text, /* 7: C_ULABEL user label */
1170 sc_Info, /* 8: C_MOS member of struct */
1171 sc_Abs, /* 9: C_ARG argument */
1172 sc_Info, /* 10: C_STRTAG struct tag */
1173 sc_Info, /* 11: C_MOU member of union */
1174 sc_Info, /* 12: C_UNTAG union tag */
1175 sc_Info, /* 13: C_TPDEF typedef */
1176 sc_Data, /* 14: C_USTATIC ??? */
1177 sc_Info, /* 15: C_ENTAG enum tag */
1178 sc_Info, /* 16: C_MOE member of enum */
1179 sc_Register, /* 17: C_REGPARM register parameter */
1180 sc_Bits, /* 18; C_FIELD bitfield */
1262 sc_Text, /* 100: C_BLOCK block start/end */
1263 sc_Text, /* 101: C_FCN function start/end */
1264 sc_Info, /* 102: C_EOS end of struct/union/enum */
1265 sc_Nil, /* 103: C_FILE file start */
1266 sc_Nil, /* 104: C_LINE line number */
1267 sc_Nil, /* 105: C_ALIAS combined type info */
1268 sc_Nil, /* 106: C_HIDDEN ??? */
1271 /* Convert COFF storage class to ECOFF symbol type. */
1272 static const st_t map_coff_sym_type[] = {
1273 st_Nil, /* 0: C_NULL */
1274 st_Local, /* 1: C_AUTO auto var */
1275 st_Global, /* 2: C_EXT external */
1276 st_Static, /* 3: C_STAT static */
1277 st_Local, /* 4: C_REG register */
1278 st_Global, /* 5: C_EXTDEF ??? */
1279 st_Label, /* 6: C_LABEL label */
1280 st_Label, /* 7: C_ULABEL user label */
1281 st_Member, /* 8: C_MOS member of struct */
1282 st_Param, /* 9: C_ARG argument */
1283 st_Block, /* 10: C_STRTAG struct tag */
1284 st_Member, /* 11: C_MOU member of union */
1285 st_Block, /* 12: C_UNTAG union tag */
1286 st_Typedef, /* 13: C_TPDEF typedef */
1287 st_Static, /* 14: C_USTATIC ??? */
1288 st_Block, /* 15: C_ENTAG enum tag */
1289 st_Member, /* 16: C_MOE member of enum */
1290 st_Param, /* 17: C_REGPARM register parameter */
1291 st_Member, /* 18; C_FIELD bitfield */
1373 st_Block, /* 100: C_BLOCK block start/end */
1374 st_Proc, /* 101: C_FCN function start/end */
1375 st_End, /* 102: C_EOS end of struct/union/enum */
1376 st_File, /* 103: C_FILE file start */
1377 st_Nil, /* 104: C_LINE line number */
1378 st_Nil, /* 105: C_ALIAS combined type info */
1379 st_Nil, /* 106: C_HIDDEN ??? */
1382 /* Keep track of different sized allocation requests. */
1383 static alloc_info_t alloc_counts[(int) alloc_type_last];
1385 /* Record whether we have seen any debugging information. */
1386 int ecoff_debugging_seen = 0;
1388 /* Various statics. */
1389 static efdr_t *cur_file_ptr = (efdr_t *) 0; /* current file desc. header */
1390 static proc_t *cur_proc_ptr = (proc_t *) 0; /* current procedure header */
1391 static proc_t *first_proc_ptr = (proc_t *) 0; /* first procedure header */
1392 static thead_t *top_tag_head = (thead_t *) 0; /* top level tag head */
1393 static thead_t *cur_tag_head = (thead_t *) 0; /* current tag head */
1395 static int debug = 0; /* trace functions */
1397 static int stabs_seen = 0; /* != 0 if stabs have been seen */
1399 static int current_file_idx;
1400 static const char *current_stabs_filename;
1402 /* Pseudo symbol to use when putting stabs into the symbol table. */
1403 #ifndef STABS_SYMBOL
1404 #define STABS_SYMBOL "@stabs"
1407 static char stabs_symbol[] = STABS_SYMBOL;
1409 /* Prototypes for functions defined in this file. */
1411 static void add_varray_page (varray_t *vp);
1412 static symint_t add_string (varray_t *vp,
1413 struct hash_control *hash_tbl,
1415 shash_t **ret_hash);
1416 static localsym_t *add_ecoff_symbol (const char *str, st_t type,
1417 sc_t storage, symbolS *sym,
1418 bfd_vma addend, symint_t value,
1420 static symint_t add_aux_sym_symint (symint_t aux_word);
1421 static symint_t add_aux_sym_rndx (int file_index, symint_t sym_index);
1422 static symint_t add_aux_sym_tir (type_info_t *t,
1424 thash_t **hash_tbl);
1425 static tag_t *get_tag (const char *tag, localsym_t *sym, bt_t basic_type);
1426 static void add_unknown_tag (tag_t *ptag);
1427 static void add_procedure (char *func);
1428 static void add_file (const char *file_name, int indx, int fake);
1430 static char *sc_to_string (sc_t storage_class);
1431 static char *st_to_string (st_t symbol_type);
1433 static void mark_stabs (int);
1434 static char *ecoff_add_bytes (char **buf, char **bufend,
1435 char *bufptr, unsigned long need);
1436 static unsigned long ecoff_padding_adjust
1437 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1438 unsigned long offset, char **bufptrptr);
1439 static unsigned long ecoff_build_lineno
1440 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1441 unsigned long offset, long *linecntptr);
1442 static unsigned long ecoff_build_symbols
1443 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1444 unsigned long offset);
1445 static unsigned long ecoff_build_procs
1446 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1447 unsigned long offset);
1448 static unsigned long ecoff_build_aux
1449 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1450 unsigned long offset);
1451 static unsigned long ecoff_build_strings (char **buf, char **bufend,
1452 unsigned long offset,
1454 static unsigned long ecoff_build_ss
1455 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1456 unsigned long offset);
1457 static unsigned long ecoff_build_fdr
1458 (const struct ecoff_debug_swap *backend, char **buf, char **bufend,
1459 unsigned long offset);
1460 static void ecoff_setup_ext (void);
1461 static page_type *allocate_cluster (unsigned long npages);
1462 static page_type *allocate_page (void);
1463 static scope_t *allocate_scope (void);
1464 static void free_scope (scope_t *ptr);
1465 static vlinks_t *allocate_vlinks (void);
1466 static shash_t *allocate_shash (void);
1467 static thash_t *allocate_thash (void);
1468 static tag_t *allocate_tag (void);
1469 static void free_tag (tag_t *ptr);
1470 static forward_t *allocate_forward (void);
1471 static thead_t *allocate_thead (void);
1472 static void free_thead (thead_t *ptr);
1473 static lineno_list_t *allocate_lineno_list (void);
1475 /* This function should be called when the assembler starts up. */
1478 ecoff_read_begin_hook (void)
1480 tag_hash = hash_new ();
1481 top_tag_head = allocate_thead ();
1482 top_tag_head->first_tag = (tag_t *) NULL;
1483 top_tag_head->free = (thead_t *) NULL;
1484 top_tag_head->prev = cur_tag_head;
1485 cur_tag_head = top_tag_head;
1488 /* This function should be called when a symbol is created. */
1491 ecoff_symbol_new_hook (symbolS *symbolP)
1493 OBJ_SYMFIELD_TYPE *obj;
1495 /* Make sure that we have a file pointer, but only if we have seen a
1496 file. If we haven't seen a file, then this is a probably special
1497 symbol created by md_begin which may required special handling at
1498 some point. Creating a dummy file with a dummy name is certainly
1500 if (cur_file_ptr == (efdr_t *) NULL
1501 && seen_at_least_1_file ())
1502 add_file ((const char *) NULL, 0, 1);
1503 obj = symbol_get_obj (symbolP);
1504 obj->ecoff_file = cur_file_ptr;
1505 obj->ecoff_symbol = NULL;
1506 obj->ecoff_extern_size = 0;
1510 ecoff_symbol_clone_hook (symbolS *newsymP, symbolS *orgsymP)
1512 OBJ_SYMFIELD_TYPE *n, *o;
1514 n = symbol_get_obj (newsymP);
1515 o = symbol_get_obj (orgsymP);
1516 memcpy (n, o, sizeof *n);
1519 /* Add a page to a varray object. */
1522 add_varray_page (varray_t *vp /* varray to add page to */)
1524 vlinks_t *new_links = allocate_vlinks ();
1527 if (vp->object_size > 1)
1528 new_links->datum = (page_type *) xcalloc (1, vp->object_size);
1531 new_links->datum = allocate_page ();
1533 alloc_counts[(int) alloc_type_varray].total_alloc++;
1534 alloc_counts[(int) alloc_type_varray].total_pages++;
1536 new_links->start_index = vp->num_allocated;
1537 vp->objects_last_page = 0;
1539 if (vp->first == (vlinks_t *) NULL) /* first allocation? */
1540 vp->first = vp->last = new_links;
1542 { /* 2nd or greater allocation */
1543 new_links->prev = vp->last;
1544 vp->last->next = new_links;
1545 vp->last = new_links;
1549 /* Add a string (and null pad) to one of the string tables. */
1552 add_string (varray_t *vp, /* string obstack */
1553 struct hash_control *hash_tbl, /* ptr to hash table */
1554 const char *str, /* string */
1555 shash_t **ret_hash /* return hash pointer */)
1557 register unsigned long len = strlen (str);
1558 register shash_t *hash_ptr;
1560 if (len >= PAGE_USIZE)
1561 as_fatal (_("string too big (%lu bytes)"), len);
1563 hash_ptr = (shash_t *) hash_find (hash_tbl, str);
1564 if (hash_ptr == (shash_t *) NULL)
1566 register const char *err;
1568 if (vp->objects_last_page + len >= PAGE_USIZE)
1571 ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
1572 add_varray_page (vp);
1575 hash_ptr = allocate_shash ();
1576 hash_ptr->indx = vp->num_allocated;
1578 hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
1580 vp->objects_last_page += len + 1;
1581 vp->num_allocated += len + 1;
1583 strcpy (hash_ptr->string, str);
1585 err = hash_insert (hash_tbl, str, (char *) hash_ptr);
1587 as_fatal (_("inserting \"%s\" into string hash table: %s"),
1591 if (ret_hash != (shash_t **) NULL)
1592 *ret_hash = hash_ptr;
1594 return hash_ptr->indx;
1597 /* Add debugging information for a symbol. */
1600 add_ecoff_symbol (const char *str, /* symbol name */
1601 st_t type, /* symbol type */
1602 sc_t storage, /* storage class */
1603 symbolS *sym_value, /* associated symbol. */
1604 bfd_vma addend, /* addend to sym_value. */
1605 symint_t value, /* value of symbol */
1606 symint_t indx /* index to local/aux. syms */)
1609 register scope_t *pscope;
1610 register thead_t *ptag_head;
1611 register tag_t *ptag;
1612 register tag_t *ptag_next;
1613 register varray_t *vp;
1614 register int scope_delta = 0;
1615 shash_t *hash_ptr = (shash_t *) NULL;
1617 if (cur_file_ptr == (efdr_t *) NULL)
1618 as_fatal (_("no current file pointer"));
1620 vp = &cur_file_ptr->symbols;
1622 if (vp->objects_last_page == vp->objects_per_page)
1623 add_varray_page (vp);
1625 psym = &vp->last->datum->sym[vp->objects_last_page++];
1627 if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
1628 psym->name = S_GET_NAME (sym_value);
1631 psym->as_sym = sym_value;
1632 if (sym_value != (symbolS *) NULL)
1633 symbol_get_obj (sym_value)->ecoff_symbol = psym;
1634 psym->addend = addend;
1635 psym->file_ptr = cur_file_ptr;
1636 psym->proc_ptr = cur_proc_ptr;
1637 psym->begin_ptr = (localsym_t *) NULL;
1638 psym->index_ptr = (aux_t *) NULL;
1639 psym->forward_ref = (forward_t *) NULL;
1640 psym->sym_index = -1;
1641 memset (&psym->ecoff_sym, 0, sizeof (EXTR));
1642 psym->ecoff_sym.asym.value = value;
1643 psym->ecoff_sym.asym.st = (unsigned) type;
1644 psym->ecoff_sym.asym.sc = (unsigned) storage;
1645 psym->ecoff_sym.asym.index = indx;
1647 /* If there is an associated symbol, we wait until the end of the
1648 assembly before deciding where to put the name (it may be just an
1649 external symbol). Otherwise, this is just a debugging symbol and
1650 the name should go with the current file. */
1651 if (sym_value == (symbolS *) NULL)
1652 psym->ecoff_sym.asym.iss = ((str == (const char *) NULL)
1654 : add_string (&cur_file_ptr->strings,
1655 cur_file_ptr->str_hash,
1659 ++vp->num_allocated;
1661 if (ECOFF_IS_STAB (&psym->ecoff_sym.asym))
1664 /* Save the symbol within the hash table if this is a static
1665 item, and it has a name. */
1666 if (hash_ptr != (shash_t *) NULL
1667 && (type == st_Global || type == st_Static || type == st_Label
1668 || type == st_Proc || type == st_StaticProc))
1669 hash_ptr->sym_ptr = psym;
1671 /* push or pop a scope if appropriate. */
1677 case st_File: /* beginning of file */
1678 case st_Proc: /* procedure */
1679 case st_StaticProc: /* static procedure */
1680 case st_Block: /* begin scope */
1681 pscope = allocate_scope ();
1682 pscope->prev = cur_file_ptr->cur_scope;
1683 pscope->lsym = psym;
1684 pscope->type = type;
1685 cur_file_ptr->cur_scope = pscope;
1687 if (type != st_File)
1690 /* For every block type except file, struct, union, or
1691 enumeration blocks, push a level on the tag stack. We omit
1692 file types, so that tags can span file boundaries. */
1693 if (type != st_File && storage != sc_Info)
1695 ptag_head = allocate_thead ();
1696 ptag_head->first_tag = 0;
1697 ptag_head->prev = cur_tag_head;
1698 cur_tag_head = ptag_head;
1703 pscope = cur_file_ptr->cur_scope;
1704 if (pscope == (scope_t *) NULL)
1705 as_fatal (_("too many st_End's"));
1708 st_t begin_type = (st_t) pscope->lsym->ecoff_sym.asym.st;
1710 psym->begin_ptr = pscope->lsym;
1712 if (begin_type != st_File)
1715 /* Except for file, structure, union, or enumeration end
1716 blocks remove all tags created within this scope. */
1717 if (begin_type != st_File && storage != sc_Info)
1719 ptag_head = cur_tag_head;
1720 cur_tag_head = ptag_head->prev;
1722 for (ptag = ptag_head->first_tag;
1723 ptag != (tag_t *) NULL;
1726 if (ptag->forward_ref != (forward_t *) NULL)
1727 add_unknown_tag (ptag);
1729 ptag_next = ptag->same_block;
1730 ptag->hash_ptr->tag_ptr = ptag->same_name;
1734 free_thead (ptag_head);
1737 cur_file_ptr->cur_scope = pscope->prev;
1739 /* block begin gets next sym #. This is set when we know
1740 the symbol index value. */
1742 /* Functions push two or more aux words as follows:
1743 1st word: index+1 of the end symbol (filled in later).
1744 2nd word: type of the function (plus any aux words needed).
1745 Also, tie the external pointer back to the function begin symbol. */
1746 if (begin_type != st_File && begin_type != st_Block)
1749 varray_t *svp = &cur_file_ptr->aux_syms;
1751 pscope->lsym->ecoff_sym.asym.index = add_aux_sym_symint (0);
1752 pscope->lsym->index_ptr =
1753 &svp->last->datum->aux[svp->objects_last_page - 1];
1754 ty = add_aux_sym_tir (&last_func_type_info,
1756 &cur_file_ptr->thash_head[0]);
1758 /* This seems to be unnecessary. I'm not even sure what it is
1759 * intended to do. It's from mips-tfile.
1760 * if (last_func_sym_value != (symbolS *) NULL)
1762 * last_func_sym_value->ifd = cur_file_ptr->file_index;
1763 * last_func_sym_value->index = ty;
1768 free_scope (pscope);
1772 cur_file_ptr->nested_scopes += scope_delta;
1775 if (debug && type != st_File
1776 && (debug > 2 || type == st_Block || type == st_End
1777 || type == st_Proc || type == st_StaticProc))
1779 char *sc_str = sc_to_string (storage);
1780 char *st_str = st_to_string (type);
1781 int depth = cur_file_ptr->nested_scopes + (scope_delta < 0);
1784 "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
1785 value, depth, sc_str);
1787 if (str_start && str_end_p1 - str_start > 0)
1788 fprintf (stderr, " st= %-11s name= %.*s\n",
1789 st_str, str_end_p1 - str_start, str_start);
1792 unsigned long len = strlen (st_str);
1793 fprintf (stderr, " st= %.*s\n", len - 1, st_str);
1801 /* Add an auxiliary symbol (passing a symint). This is actually used
1802 for integral aux types, not just symints. */
1805 add_aux_sym_symint (symint_t aux_word /* auxiliary information word */)
1807 register varray_t *vp;
1808 register aux_t *aux_ptr;
1810 if (cur_file_ptr == (efdr_t *) NULL)
1811 as_fatal (_("no current file pointer"));
1813 vp = &cur_file_ptr->aux_syms;
1815 if (vp->objects_last_page == vp->objects_per_page)
1816 add_varray_page (vp);
1818 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1819 aux_ptr->type = aux_isym;
1820 aux_ptr->data.isym = aux_word;
1822 return vp->num_allocated++;
1825 /* Add an auxiliary symbol (passing a file/symbol index combo). */
1828 add_aux_sym_rndx (int file_index, symint_t sym_index)
1830 register varray_t *vp;
1831 register aux_t *aux_ptr;
1833 if (cur_file_ptr == (efdr_t *) NULL)
1834 as_fatal (_("no current file pointer"));
1836 vp = &cur_file_ptr->aux_syms;
1838 if (vp->objects_last_page == vp->objects_per_page)
1839 add_varray_page (vp);
1841 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1842 aux_ptr->type = aux_rndx;
1843 aux_ptr->data.rndx.rfd = file_index;
1844 aux_ptr->data.rndx.index = sym_index;
1846 return vp->num_allocated++;
1849 /* Add an auxiliary symbol (passing the basic type and possibly
1850 type qualifiers). */
1853 add_aux_sym_tir (type_info_t *t, /* current type information */
1854 hash_state_t state, /* whether to hash type or not */
1855 thash_t **hash_tbl /* pointer to hash table to use */)
1857 register varray_t *vp;
1858 register aux_t *aux_ptr;
1859 static AUXU init_aux;
1864 if (cur_file_ptr == (efdr_t *) NULL)
1865 as_fatal (_("no current file pointer"));
1867 vp = &cur_file_ptr->aux_syms;
1870 aux.ti.bt = (int) t->basic_type;
1871 aux.ti.continued = 0;
1872 aux.ti.fBitfield = t->bitfield;
1874 aux.ti.tq0 = (int) t->type_qualifiers[0];
1875 aux.ti.tq1 = (int) t->type_qualifiers[1];
1876 aux.ti.tq2 = (int) t->type_qualifiers[2];
1877 aux.ti.tq3 = (int) t->type_qualifiers[3];
1878 aux.ti.tq4 = (int) t->type_qualifiers[4];
1879 aux.ti.tq5 = (int) t->type_qualifiers[5];
1881 /* For anything that adds additional information, we must not hash,
1882 so check here, and reset our state. */
1884 if (state != hash_no
1885 && (t->type_qualifiers[0] == tq_Array
1886 || t->type_qualifiers[1] == tq_Array
1887 || t->type_qualifiers[2] == tq_Array
1888 || t->type_qualifiers[3] == tq_Array
1889 || t->type_qualifiers[4] == tq_Array
1890 || t->type_qualifiers[5] == tq_Array
1891 || t->basic_type == bt_Struct
1892 || t->basic_type == bt_Union
1893 || t->basic_type == bt_Enum
1895 || t->num_dims > 0))
1898 /* See if we can hash this type, and save some space, but some types
1899 can't be hashed (because they contain arrays or continuations),
1900 and others can be put into the hash list, but cannot use existing
1901 types because other aux entries precede this one. */
1903 if (state != hash_no)
1905 register thash_t *hash_ptr;
1906 register symint_t hi;
1908 hi = aux.isym & ((1 << HASHBITS) - 1);
1911 for (hash_ptr = hash_tbl[hi];
1912 hash_ptr != (thash_t *)0;
1913 hash_ptr = hash_ptr->next)
1915 if (aux.isym == hash_ptr->type.isym)
1919 if (hash_ptr != (thash_t *) NULL && state == hash_yes)
1920 return hash_ptr->indx;
1922 if (hash_ptr == (thash_t *) NULL)
1924 hash_ptr = allocate_thash ();
1925 hash_ptr->next = hash_tbl[hi];
1926 hash_ptr->type = aux;
1927 hash_ptr->indx = vp->num_allocated;
1928 hash_tbl[hi] = hash_ptr;
1932 /* Everything is set up, add the aux symbol. */
1933 if (vp->objects_last_page == vp->objects_per_page)
1934 add_varray_page (vp);
1936 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1937 aux_ptr->type = aux_tir;
1938 aux_ptr->data = aux;
1940 ret = vp->num_allocated++;
1942 /* Add bitfield length if it exists.
1944 NOTE: Mips documentation claims bitfield goes at the end of the
1945 AUX record, but the DECstation compiler emits it here.
1946 (This would only make a difference for enum bitfields.)
1948 Also note: We use the last size given since gcc may emit 2
1949 for an enum bitfield. */
1952 (void) add_aux_sym_symint ((symint_t) t->sizes[t->num_sizes - 1]);
1954 /* Add tag information if needed. Structure, union, and enum
1955 references add 2 aux symbols: a [file index, symbol index]
1956 pointer to the structure type, and the current file index. */
1958 if (t->basic_type == bt_Struct
1959 || t->basic_type == bt_Union
1960 || t->basic_type == bt_Enum)
1962 register symint_t file_index = t->tag_ptr->ifd;
1963 register localsym_t *sym = t->tag_ptr->sym;
1964 register forward_t *forward_ref = allocate_forward ();
1966 if (sym != (localsym_t *) NULL)
1968 forward_ref->next = sym->forward_ref;
1969 sym->forward_ref = forward_ref;
1973 forward_ref->next = t->tag_ptr->forward_ref;
1974 t->tag_ptr->forward_ref = forward_ref;
1977 (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
1978 forward_ref->index_ptr
1979 = &vp->last->datum->aux[vp->objects_last_page - 1];
1981 (void) add_aux_sym_symint (file_index);
1982 forward_ref->ifd_ptr
1983 = &vp->last->datum->aux[vp->objects_last_page - 1];
1986 /* Add information about array bounds if they exist. */
1987 for (i = 0; i < t->num_dims; i++)
1989 (void) add_aux_sym_rndx (ST_RFDESCAPE,
1990 cur_file_ptr->int_type);
1992 (void) add_aux_sym_symint (cur_file_ptr->file_index); /* file index*/
1993 (void) add_aux_sym_symint ((symint_t) 0); /* low bound */
1994 (void) add_aux_sym_symint (t->dimensions[i] - 1); /* high bound*/
1995 (void) add_aux_sym_symint ((t->dimensions[i] == 0) /* stride */
1997 : (t->sizes[i] * 8) / t->dimensions[i]);
2000 /* NOTE: Mips documentation claims that the bitfield width goes here.
2001 But it needs to be emitted earlier. */
2006 /* Add a tag to the tag table (unless it already exists). */
2009 get_tag (const char *tag, /* tag name */
2010 localsym_t *sym, /* tag start block */
2011 bt_t basic_type /* bt_Struct, bt_Union, or bt_Enum */)
2017 if (cur_file_ptr == (efdr_t *) NULL)
2018 as_fatal (_("no current file pointer"));
2020 hash_ptr = (shash_t *) hash_find (tag_hash, tag);
2022 if (hash_ptr != (shash_t *) NULL
2023 && hash_ptr->tag_ptr != (tag_t *) NULL)
2025 tag_ptr = hash_ptr->tag_ptr;
2026 if (sym != (localsym_t *) NULL)
2028 tag_ptr->basic_type = basic_type;
2029 tag_ptr->ifd = cur_file_ptr->file_index;
2035 if (hash_ptr == (shash_t *) NULL)
2039 perm = xstrdup (tag);
2040 hash_ptr = allocate_shash ();
2041 err = hash_insert (tag_hash, perm, (char *) hash_ptr);
2043 as_fatal (_("inserting \"%s\" into tag hash table: %s"),
2045 hash_ptr->string = perm;
2048 tag_ptr = allocate_tag ();
2049 tag_ptr->forward_ref = (forward_t *) NULL;
2050 tag_ptr->hash_ptr = hash_ptr;
2051 tag_ptr->same_name = hash_ptr->tag_ptr;
2052 tag_ptr->basic_type = basic_type;
2054 tag_ptr->ifd = ((sym == (localsym_t *) NULL)
2056 : cur_file_ptr->file_index);
2057 tag_ptr->same_block = cur_tag_head->first_tag;
2059 cur_tag_head->first_tag = tag_ptr;
2060 hash_ptr->tag_ptr = tag_ptr;
2065 /* Add an unknown {struct, union, enum} tag. */
2068 add_unknown_tag (tag_t *ptag /* pointer to tag information */)
2070 shash_t *hash_ptr = ptag->hash_ptr;
2071 char *name = hash_ptr->string;
2078 char *agg_type = "{unknown aggregate type}";
2079 switch (ptag->basic_type)
2081 case bt_Struct: agg_type = "struct"; break;
2082 case bt_Union: agg_type = "union"; break;
2083 case bt_Enum: agg_type = "enum"; break;
2087 fprintf (stderr, "unknown %s %.*s found\n", agg_type,
2088 hash_ptr->len, name_start);
2092 sym = add_ecoff_symbol (name,
2100 (void) add_ecoff_symbol (name,
2108 for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
2110 *pf = ptag->forward_ref;
2113 /* Add a procedure to the current file's list of procedures, and record
2114 this is the current procedure. */
2117 add_procedure (char *func /* func name */)
2119 register varray_t *vp;
2120 register proc_t *new_proc_ptr;
2125 fputc ('\n', stderr);
2128 if (cur_file_ptr == (efdr_t *) NULL)
2129 as_fatal (_("no current file pointer"));
2131 vp = &cur_file_ptr->procs;
2133 if (vp->objects_last_page == vp->objects_per_page)
2134 add_varray_page (vp);
2136 cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
2138 if (first_proc_ptr == (proc_t *) NULL)
2139 first_proc_ptr = new_proc_ptr;
2141 vp->num_allocated++;
2143 new_proc_ptr->pdr.isym = -1;
2144 new_proc_ptr->pdr.iline = -1;
2145 new_proc_ptr->pdr.lnLow = -1;
2146 new_proc_ptr->pdr.lnHigh = -1;
2148 /* Set the BSF_FUNCTION flag for the symbol. */
2149 sym = symbol_find_or_make (func);
2150 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
2152 /* Push the start of the function. */
2153 new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text,
2154 sym, (bfd_vma) 0, (symint_t) 0,
2159 /* Fill in the linenos preceding the .ent, if any. */
2160 if (noproc_lineno != (lineno_list_t *) NULL)
2164 for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next)
2165 l->proc = new_proc_ptr;
2166 *last_lineno_ptr = noproc_lineno;
2167 while (*last_lineno_ptr != NULL)
2169 last_lineno = *last_lineno_ptr;
2170 last_lineno_ptr = &last_lineno->next;
2172 noproc_lineno = (lineno_list_t *) NULL;
2177 ecoff_get_cur_proc_sym (void)
2179 return (cur_proc_ptr ? cur_proc_ptr->sym->as_sym : NULL);
2182 /* Add a new filename, and set up all of the file relative
2183 virtual arrays (strings, symbols, aux syms, etc.). Record
2184 where the current file structure lives. */
2187 add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
2189 register int first_ch;
2190 register efdr_t *fil_ptr;
2194 fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
2197 /* If the file name is NULL, then no .file symbol appeared, and we
2198 want to use the actual file name. */
2199 if (file_name == (const char *) NULL)
2203 if (first_file != (efdr_t *) NULL)
2204 as_fatal (_("fake .file after real one"));
2205 as_where (&file, (unsigned int *) NULL);
2206 file_name = (const char *) file;
2208 /* Automatically generate ECOFF debugging information, since I
2209 think that's what other ECOFF assemblers do. We don't do
2210 this if we see a .file directive with a string, since that
2211 implies that some sort of debugging information is being
2213 if (! symbol_table_frozen && debug_type == DEBUG_UNSPECIFIED)
2214 debug_type = DEBUG_ECOFF;
2216 else if (debug_type == DEBUG_UNSPECIFIED)
2217 debug_type = DEBUG_NONE;
2221 listing_source_file (file_name);
2224 current_stabs_filename = file_name;
2226 /* If we're creating stabs, then we don't actually make a new FDR.
2227 Instead, we just create a stabs symbol. */
2230 (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
2231 symbol_new ("L0\001", now_seg,
2232 (valueT) frag_now_fix (),
2234 (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
2238 first_ch = *file_name;
2240 /* FIXME: We can't safely merge files which have line number
2241 information (fMerge will be zero in this case). Otherwise, we
2242 get incorrect line number debugging info. See for instance
2243 ecoff_build_lineno, which will end up setting all file->fdr.*
2244 fields multiple times, resulting in incorrect debug info. In
2245 order to make this work right, all line number and symbol info
2246 for the same source file has to be adjacent in the object file,
2247 so that a single file descriptor can be used to point to them.
2248 This would require maintaining file specific lists of line
2249 numbers and symbols for each file, so that they can be merged
2250 together (or output together) when two .file pseudo-ops are
2251 merged into one file descriptor. */
2253 /* See if the file has already been created. */
2254 for (fil_ptr = first_file;
2255 fil_ptr != (efdr_t *) NULL;
2256 fil_ptr = fil_ptr->next_file)
2258 if (first_ch == fil_ptr->name[0]
2259 && filename_cmp (file_name, fil_ptr->name) == 0
2260 && fil_ptr->fdr.fMerge)
2262 cur_file_ptr = fil_ptr;
2264 cur_file_ptr->fake = 0;
2269 /* If this is a new file, create it. */
2270 if (fil_ptr == (efdr_t *) NULL)
2272 if (file_desc.objects_last_page == file_desc.objects_per_page)
2273 add_varray_page (&file_desc);
2275 fil_ptr = cur_file_ptr =
2276 &file_desc.last->datum->file[file_desc.objects_last_page++];
2277 *fil_ptr = init_file;
2279 fil_ptr->file_index = current_file_idx++;
2280 ++file_desc.num_allocated;
2282 fil_ptr->fake = fake;
2284 /* Allocate the string hash table. */
2285 fil_ptr->str_hash = hash_new ();
2287 /* Make sure 0 byte in string table is null */
2288 add_string (&fil_ptr->strings,
2293 if (strlen (file_name) > PAGE_USIZE - 2)
2294 as_fatal (_("filename goes over one page boundary"));
2296 /* Push the start of the filename. We assume that the filename
2297 will be stored at string offset 1. */
2298 (void) add_ecoff_symbol (file_name, st_File, sc_Text,
2299 (symbolS *) NULL, (bfd_vma) 0,
2300 (symint_t) 0, (symint_t) 0);
2301 fil_ptr->fdr.rss = 1;
2302 fil_ptr->name = &fil_ptr->strings.last->datum->byte[1];
2304 /* Update the linked list of file descriptors. */
2305 *last_file_ptr = fil_ptr;
2306 last_file_ptr = &fil_ptr->next_file;
2308 /* Add void & int types to the file (void should be first to catch
2309 errant 0's within the index fields). */
2310 fil_ptr->void_type = add_aux_sym_tir (&void_type_info,
2312 &cur_file_ptr->thash_head[0]);
2314 fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
2316 &cur_file_ptr->thash_head[0]);
2320 /* This function is called when the assembler notices a preprocessor
2321 directive switching to a new file. This will not happen in
2322 compiler output, only in hand coded assembler. */
2325 ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
2327 if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
2329 add_file (name, 0, 0);
2331 /* This is a hand coded assembler file, so automatically turn on
2332 debugging information. */
2333 if (debug_type == DEBUG_UNSPECIFIED)
2334 debug_type = DEBUG_ECOFF;
2339 /* Convert storage class to string. */
2342 sc_to_string (storage_class)
2345 switch (storage_class)
2347 case sc_Nil: return "Nil,";
2348 case sc_Text: return "Text,";
2349 case sc_Data: return "Data,";
2350 case sc_Bss: return "Bss,";
2351 case sc_Register: return "Register,";
2352 case sc_Abs: return "Abs,";
2353 case sc_Undefined: return "Undefined,";
2354 case sc_CdbLocal: return "CdbLocal,";
2355 case sc_Bits: return "Bits,";
2356 case sc_CdbSystem: return "CdbSystem,";
2357 case sc_RegImage: return "RegImage,";
2358 case sc_Info: return "Info,";
2359 case sc_UserStruct: return "UserStruct,";
2360 case sc_SData: return "SData,";
2361 case sc_SBss: return "SBss,";
2362 case sc_RData: return "RData,";
2363 case sc_Var: return "Var,";
2364 case sc_Common: return "Common,";
2365 case sc_SCommon: return "SCommon,";
2366 case sc_VarRegister: return "VarRegister,";
2367 case sc_Variant: return "Variant,";
2368 case sc_SUndefined: return "SUndefined,";
2369 case sc_Init: return "Init,";
2370 case sc_Max: return "Max,";
2380 /* Convert symbol type to string. */
2383 st_to_string (symbol_type)
2386 switch (symbol_type)
2388 case st_Nil: return "Nil,";
2389 case st_Global: return "Global,";
2390 case st_Static: return "Static,";
2391 case st_Param: return "Param,";
2392 case st_Local: return "Local,";
2393 case st_Label: return "Label,";
2394 case st_Proc: return "Proc,";
2395 case st_Block: return "Block,";
2396 case st_End: return "End,";
2397 case st_Member: return "Member,";
2398 case st_Typedef: return "Typedef,";
2399 case st_File: return "File,";
2400 case st_RegReloc: return "RegReloc,";
2401 case st_Forward: return "Forward,";
2402 case st_StaticProc: return "StaticProc,";
2403 case st_Constant: return "Constant,";
2404 case st_Str: return "String,";
2405 case st_Number: return "Number,";
2406 case st_Expr: return "Expr,";
2407 case st_Type: return "Type,";
2408 case st_Max: return "Max,";
2416 /* Parse .begin directives which have a label as the first argument
2417 which gives the location of the start of the block. */
2420 ecoff_directive_begin (int ignore ATTRIBUTE_UNUSED)
2425 if (cur_file_ptr == (efdr_t *) NULL)
2427 as_warn (_(".begin directive without a preceding .file directive"));
2428 demand_empty_rest_of_line ();
2432 if (cur_proc_ptr == (proc_t *) NULL)
2434 as_warn (_(".begin directive without a preceding .ent directive"));
2435 demand_empty_rest_of_line ();
2439 name = input_line_pointer;
2440 name_end = get_symbol_end ();
2442 (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text,
2443 symbol_find_or_make (name),
2444 (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
2446 *input_line_pointer = name_end;
2448 /* The line number follows, but we don't use it. */
2449 (void) get_absolute_expression ();
2450 demand_empty_rest_of_line ();
2453 /* Parse .bend directives which have a label as the first argument
2454 which gives the location of the end of the block. */
2457 ecoff_directive_bend (int ignore ATTRIBUTE_UNUSED)
2463 if (cur_file_ptr == (efdr_t *) NULL)
2465 as_warn (_(".bend directive without a preceding .file directive"));
2466 demand_empty_rest_of_line ();
2470 if (cur_proc_ptr == (proc_t *) NULL)
2472 as_warn (_(".bend directive without a preceding .ent directive"));
2473 demand_empty_rest_of_line ();
2477 name = input_line_pointer;
2478 name_end = get_symbol_end ();
2480 /* The value is the distance between the .bend directive and the
2481 corresponding symbol. We fill in the offset when we write out
2483 endsym = symbol_find (name);
2484 if (endsym == (symbolS *) NULL)
2485 as_warn (_(".bend directive names unknown symbol"));
2487 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
2488 (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
2490 *input_line_pointer = name_end;
2492 /* The line number follows, but we don't use it. */
2493 (void) get_absolute_expression ();
2494 demand_empty_rest_of_line ();
2497 /* COFF debugging information is provided as a series of directives
2498 (.def, .scl, etc.). We build up information as we read the
2499 directives in the following static variables, and file it away when
2500 we reach the .endef directive. */
2501 static char *coff_sym_name;
2502 static type_info_t coff_type;
2503 static sc_t coff_storage_class;
2504 static st_t coff_symbol_typ;
2505 static int coff_is_function;
2506 static char *coff_tag;
2507 static valueT coff_value;
2508 static symbolS *coff_sym_value;
2509 static bfd_vma coff_sym_addend;
2510 static int coff_inside_enumeration;
2512 /* Handle a .def directive: start defining a symbol. */
2515 ecoff_directive_def (int ignore ATTRIBUTE_UNUSED)
2520 ecoff_debugging_seen = 1;
2524 name = input_line_pointer;
2525 name_end = get_symbol_end ();
2527 if (coff_sym_name != (char *) NULL)
2528 as_warn (_(".def pseudo-op used inside of .def/.endef; ignored"));
2529 else if (*name == '\0')
2530 as_warn (_("empty symbol name in .def; ignored"));
2533 if (coff_sym_name != (char *) NULL)
2534 free (coff_sym_name);
2535 if (coff_tag != (char *) NULL)
2538 coff_sym_name = xstrdup (name);
2539 coff_type = type_info_init;
2540 coff_storage_class = sc_Nil;
2541 coff_symbol_typ = st_Nil;
2542 coff_is_function = 0;
2543 coff_tag = (char *) NULL;
2545 coff_sym_value = (symbolS *) NULL;
2546 coff_sym_addend = 0;
2549 *input_line_pointer = name_end;
2551 demand_empty_rest_of_line ();
2554 /* Handle a .dim directive, used to give dimensions for an array. The
2555 arguments are comma separated numbers. mips-tfile assumes that
2556 there will not be more than 6 dimensions, and gdb won't read any
2557 more than that anyhow, so I will also make that assumption. */
2560 ecoff_directive_dim (int ignore ATTRIBUTE_UNUSED)
2565 if (coff_sym_name == (char *) NULL)
2567 as_warn (_(".dim pseudo-op used outside of .def/.endef; ignored"));
2568 demand_empty_rest_of_line ();
2572 for (i = 0; i < N_TQ; i++)
2575 dimens[i] = get_absolute_expression ();
2576 if (*input_line_pointer == ',')
2577 ++input_line_pointer;
2580 if (*input_line_pointer != '\n'
2581 && *input_line_pointer != ';')
2582 as_warn (_("badly formed .dim directive"));
2590 /* The dimensions are stored away in reverse order. */
2593 if (coff_type.num_dims >= N_TQ)
2595 as_warn (_("too many .dim entries"));
2598 coff_type.dimensions[coff_type.num_dims] = dimens[i];
2599 ++coff_type.num_dims;
2602 demand_empty_rest_of_line ();
2605 /* Handle a .scl directive, which sets the COFF storage class of the
2609 ecoff_directive_scl (int ignore ATTRIBUTE_UNUSED)
2613 if (coff_sym_name == (char *) NULL)
2615 as_warn (_(".scl pseudo-op used outside of .def/.endef; ignored"));
2616 demand_empty_rest_of_line ();
2620 val = get_absolute_expression ();
2622 coff_symbol_typ = map_coff_sym_type[val];
2623 coff_storage_class = map_coff_storage[val];
2625 demand_empty_rest_of_line ();
2628 /* Handle a .size directive. For some reason mips-tfile.c thinks that
2629 .size can have multiple arguments. We humor it, although gcc will
2630 never generate more than one argument. */
2633 ecoff_directive_size (int ignore ATTRIBUTE_UNUSED)
2638 if (coff_sym_name == (char *) NULL)
2640 as_warn (_(".size pseudo-op used outside of .def/.endef; ignored"));
2641 demand_empty_rest_of_line ();
2645 for (i = 0; i < N_TQ; i++)
2648 sizes[i] = get_absolute_expression ();
2649 if (*input_line_pointer == ',')
2650 ++input_line_pointer;
2653 if (*input_line_pointer != '\n'
2654 && *input_line_pointer != ';')
2655 as_warn (_("badly formed .size directive"));
2663 /* The sizes are stored away in reverse order. */
2666 if (coff_type.num_sizes >= N_TQ)
2668 as_warn (_("too many .size entries"));
2671 coff_type.sizes[coff_type.num_sizes] = sizes[i];
2672 ++coff_type.num_sizes;
2675 demand_empty_rest_of_line ();
2678 /* Handle the .type directive, which gives the COFF type of the
2682 ecoff_directive_type (int ignore ATTRIBUTE_UNUSED)
2688 if (coff_sym_name == (char *) NULL)
2690 as_warn (_(".type pseudo-op used outside of .def/.endef; ignored"));
2691 demand_empty_rest_of_line ();
2695 val = get_absolute_expression ();
2697 coff_type.orig_type = BTYPE (val);
2698 coff_type.basic_type = map_coff_types[coff_type.orig_type];
2700 tq_ptr = &coff_type.type_qualifiers[N_TQ];
2701 while (val & ~N_BTMASK)
2703 if (tq_ptr == &coff_type.type_qualifiers[0])
2705 /* FIXME: We could handle this by setting the continued bit.
2706 There would still be a limit: the .type argument can not
2708 as_warn (_("the type of %s is too complex; it will be simplified"),
2714 else if (ISFCN (val))
2715 *--tq_ptr = tq_Proc;
2716 else if (ISARY (val))
2717 *--tq_ptr = tq_Array;
2719 as_fatal (_("Unrecognized .type argument"));
2724 tq_shft = &coff_type.type_qualifiers[0];
2725 while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
2726 *tq_shft++ = *tq_ptr++;
2728 if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
2730 /* If this is a function, ignore it, so that we don't get two
2731 entries (one from the .ent, and one for the .def that
2732 precedes it). Save the type information so that the end
2733 block can properly add it after the begin block index. For
2734 MIPS knows what reason, we must strip off the function type
2736 coff_is_function = 1;
2737 tq_shft[-1] = tq_Nil;
2740 while (tq_shft != &coff_type.type_qualifiers[N_TQ])
2741 *tq_shft++ = tq_Nil;
2743 demand_empty_rest_of_line ();
2746 /* Handle the .tag directive, which gives the name of a structure,
2750 ecoff_directive_tag (int ignore ATTRIBUTE_UNUSED)
2755 if (coff_sym_name == (char *) NULL)
2757 as_warn (_(".tag pseudo-op used outside of .def/.endef; ignored"));
2758 demand_empty_rest_of_line ();
2762 name = input_line_pointer;
2763 name_end = get_symbol_end ();
2765 coff_tag = xstrdup (name);
2767 *input_line_pointer = name_end;
2769 demand_empty_rest_of_line ();
2772 /* Handle the .val directive, which gives the value of the symbol. It
2773 may be the name of a static or global symbol. */
2776 ecoff_directive_val (int ignore ATTRIBUTE_UNUSED)
2780 if (coff_sym_name == (char *) NULL)
2782 as_warn (_(".val pseudo-op used outside of .def/.endef; ignored"));
2783 demand_empty_rest_of_line ();
2788 if (exp.X_op != O_constant && exp.X_op != O_symbol)
2790 as_bad (_(".val expression is too complex"));
2791 demand_empty_rest_of_line ();
2795 if (exp.X_op == O_constant)
2796 coff_value = exp.X_add_number;
2799 coff_sym_value = exp.X_add_symbol;
2800 coff_sym_addend = exp.X_add_number;
2803 demand_empty_rest_of_line ();
2806 /* Handle the .endef directive, which terminates processing of COFF
2807 debugging information for a symbol. */
2810 ecoff_directive_endef (int ignore ATTRIBUTE_UNUSED)
2816 demand_empty_rest_of_line ();
2818 if (coff_sym_name == (char *) NULL)
2820 as_warn (_(".endef pseudo-op used before .def; ignored"));
2824 name = coff_sym_name;
2825 coff_sym_name = (char *) NULL;
2827 /* If the symbol is a static or external, we have already gotten the
2828 appropriate type and class, so make sure we don't override those
2829 values. This is needed because there are some type and classes
2830 that are not in COFF, such as short data, etc. */
2831 if (coff_sym_value != (symbolS *) NULL)
2833 coff_symbol_typ = st_Nil;
2834 coff_storage_class = sc_Nil;
2837 coff_type.extra_sizes = coff_tag != (char *) NULL;
2838 if (coff_type.num_dims > 0)
2840 int diff = coff_type.num_dims - coff_type.num_sizes;
2841 int i = coff_type.num_dims - 1;
2844 if (coff_type.num_sizes != 1 || diff < 0)
2846 as_warn (_("bad COFF debugging information"));
2850 /* If this is an array, make sure the same number of dimensions
2851 and sizes were passed, creating extra sizes for multiply
2852 dimensioned arrays if not passed. */
2853 coff_type.extra_sizes = 0;
2856 j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
2859 coff_type.sizes[j] = (((j - diff) >= 0)
2860 ? coff_type.sizes[j - diff]
2865 coff_type.num_sizes = i + 1;
2866 for (i--; i >= 0; i--)
2867 coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
2869 : (coff_type.sizes[i + 1]
2870 / coff_type.dimensions[i + 1]));
2873 else if (coff_symbol_typ == st_Member
2874 && coff_type.num_sizes - coff_type.extra_sizes == 1)
2876 /* Is this a bitfield? This is indicated by a structure member
2877 having a size field that isn't an array. */
2878 coff_type.bitfield = 1;
2881 /* Except for enumeration members & begin/ending of scopes, put the
2882 type word in the aux. symbol table. */
2883 if (coff_symbol_typ == st_Block || coff_symbol_typ == st_End)
2885 else if (coff_inside_enumeration)
2886 indx = cur_file_ptr->void_type;
2889 if (coff_type.basic_type == bt_Struct
2890 || coff_type.basic_type == bt_Union
2891 || coff_type.basic_type == bt_Enum)
2893 if (coff_tag == (char *) NULL)
2895 as_warn (_("no tag specified for %s"), name);
2899 coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
2900 coff_type.basic_type);
2903 if (coff_is_function)
2905 last_func_type_info = coff_type;
2906 last_func_sym_value = coff_sym_value;
2910 indx = add_aux_sym_tir (&coff_type,
2912 &cur_file_ptr->thash_head[0]);
2915 /* Do any last minute adjustments that are necessary. */
2916 switch (coff_symbol_typ)
2921 /* For the beginning of structs, unions, and enumerations, the
2922 size info needs to be passed in the value field. */
2924 if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
2927 as_warn (_("bad COFF debugging information"));
2931 coff_value = coff_type.sizes[0];
2933 coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
2936 /* For the end of structs, unions, and enumerations, omit the
2937 name which is always ".eos". This needs to be done last, so
2938 that any error reporting above gives the correct name. */
2941 name = (char *) NULL;
2943 coff_inside_enumeration = 0;
2946 /* Members of structures and unions that aren't bitfields, need
2947 to adjust the value from a byte offset to a bit offset.
2948 Members of enumerations do not have the value adjusted, and
2949 can be distinguished by indx == indexNil. For enumerations,
2950 update the maximum enumeration value. */
2952 if (! coff_type.bitfield && ! coff_inside_enumeration)
2958 /* Add the symbol. */
2959 sym = add_ecoff_symbol (name,
2964 (symint_t) coff_value,
2967 /* deal with struct, union, and enum tags. */
2968 if (coff_symbol_typ == st_Block)
2970 /* Create or update the tag information. */
2971 tag_t *tag_ptr = get_tag (name,
2973 coff_type.basic_type);
2976 /* Remember any forward references. */
2977 for (pf = &sym->forward_ref;
2978 *pf != (forward_t *) NULL;
2981 *pf = tag_ptr->forward_ref;
2982 tag_ptr->forward_ref = (forward_t *) NULL;
2986 /* Parse .end directives. */
2989 ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
2995 if (cur_file_ptr == (efdr_t *) NULL)
2997 as_warn (_(".end directive without a preceding .file directive"));
2998 demand_empty_rest_of_line ();
3002 if (cur_proc_ptr == (proc_t *) NULL)
3004 as_warn (_(".end directive without a preceding .ent directive"));
3005 demand_empty_rest_of_line ();
3009 name = input_line_pointer;
3010 name_end = get_symbol_end ();
3012 if (name == input_line_pointer)
3014 as_warn (_(".end directive has no name"));
3015 *input_line_pointer = name_end;
3016 demand_empty_rest_of_line ();
3020 /* The value is the distance between the .end directive and the
3021 corresponding symbol. We create a fake symbol to hold the
3022 current location, and put in the offset when we write out the
3024 ent = symbol_find (name);
3025 if (ent == (symbolS *) NULL)
3026 as_warn (_(".end directive names unknown symbol"));
3028 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
3029 symbol_new ("L0\001", now_seg,
3030 (valueT) frag_now_fix (),
3032 (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
3034 cur_proc_ptr = (proc_t *) NULL;
3036 *input_line_pointer = name_end;
3037 demand_empty_rest_of_line ();
3040 /* Parse .ent directives. */
3043 ecoff_directive_ent (int ignore ATTRIBUTE_UNUSED)
3048 if (cur_file_ptr == (efdr_t *) NULL)
3049 add_file ((const char *) NULL, 0, 1);
3051 if (cur_proc_ptr != (proc_t *) NULL)
3053 as_warn (_("second .ent directive found before .end directive"));
3054 demand_empty_rest_of_line ();
3058 name = input_line_pointer;
3059 name_end = get_symbol_end ();
3061 if (name == input_line_pointer)
3063 as_warn (_(".ent directive has no name"));
3064 *input_line_pointer = name_end;
3065 demand_empty_rest_of_line ();
3069 add_procedure (name);
3071 *input_line_pointer = name_end;
3073 /* The .ent directive is sometimes followed by a number. I'm not
3074 really sure what the number means. I don't see any way to store
3075 the information in the PDR. The Irix 4 assembler seems to ignore
3078 if (*input_line_pointer == ',')
3080 ++input_line_pointer;
3083 if (ISDIGIT (*input_line_pointer)
3084 || *input_line_pointer == '-')
3085 (void) get_absolute_expression ();
3087 demand_empty_rest_of_line ();
3090 /* Parse .extern directives. */
3093 ecoff_directive_extern (int ignore ATTRIBUTE_UNUSED)
3100 name = input_line_pointer;
3101 c = get_symbol_end ();
3102 symbolp = symbol_find_or_make (name);
3103 *input_line_pointer = c;
3105 S_SET_EXTERNAL (symbolp);
3107 if (*input_line_pointer == ',')
3108 ++input_line_pointer;
3109 size = get_absolute_expression ();
3111 symbol_get_obj (symbolp)->ecoff_extern_size = size;
3114 /* Parse .file directives. */
3117 ecoff_directive_file (int ignore ATTRIBUTE_UNUSED)
3123 if (cur_proc_ptr != (proc_t *) NULL)
3125 as_warn (_("no way to handle .file within .ent/.end section"));
3126 demand_empty_rest_of_line ();
3130 indx = (int) get_absolute_expression ();
3132 /* FIXME: we don't have to save the name here. */
3133 name = demand_copy_C_string (&len);
3135 add_file (name, indx - 1, 0);
3137 demand_empty_rest_of_line ();
3140 /* Parse .fmask directives. */
3143 ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
3147 if (cur_proc_ptr == (proc_t *) NULL)
3149 as_warn (_(".fmask outside of .ent"));
3150 demand_empty_rest_of_line ();
3154 if (get_absolute_expression_and_terminator (&val) != ',')
3156 as_warn (_("bad .fmask directive"));
3157 --input_line_pointer;
3158 demand_empty_rest_of_line ();
3162 cur_proc_ptr->pdr.fregmask = val;
3163 cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
3165 demand_empty_rest_of_line ();
3168 /* Parse .frame directives. */
3171 ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
3175 if (cur_proc_ptr == (proc_t *) NULL)
3177 as_warn (_(".frame outside of .ent"));
3178 demand_empty_rest_of_line ();
3182 cur_proc_ptr->pdr.framereg = tc_get_register (1);
3185 if (*input_line_pointer++ != ','
3186 || get_absolute_expression_and_terminator (&val) != ',')
3188 as_warn (_("bad .frame directive"));
3189 --input_line_pointer;
3190 demand_empty_rest_of_line ();
3194 cur_proc_ptr->pdr.frameoffset = val;
3196 cur_proc_ptr->pdr.pcreg = tc_get_register (0);
3198 /* Alpha-OSF1 adds "the offset of saved $a0 from $sp", according to
3199 Sandro. I don't yet know where this value should be stored, if
3200 anywhere. Don't call demand_empty_rest_of_line (). */
3204 /* Parse .mask directives. */
3207 ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
3211 if (cur_proc_ptr == (proc_t *) NULL)
3213 as_warn (_(".mask outside of .ent"));
3214 demand_empty_rest_of_line ();
3218 if (get_absolute_expression_and_terminator (&val) != ',')
3220 as_warn (_("bad .mask directive"));
3221 --input_line_pointer;
3222 demand_empty_rest_of_line ();
3226 cur_proc_ptr->pdr.regmask = val;
3227 cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
3229 demand_empty_rest_of_line ();
3232 /* Parse .loc directives. */
3235 ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
3237 lineno_list_t *list;
3240 if (cur_file_ptr == (efdr_t *) NULL)
3242 as_warn (_(".loc before .file"));
3243 demand_empty_rest_of_line ();
3247 if (now_seg != text_section)
3249 as_warn (_(".loc outside of .text"));
3250 demand_empty_rest_of_line ();
3254 /* Skip the file number. */
3256 get_absolute_expression ();
3259 lineno = get_absolute_expression ();
3263 listing_source_line (lineno);
3266 /* If we're building stabs, then output a special label rather than
3267 ECOFF line number info. */
3270 (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
3271 symbol_new ("L0\001", now_seg,
3272 (valueT) frag_now_fix (),
3274 (bfd_vma) 0, 0, lineno);
3278 list = allocate_lineno_list ();
3280 list->next = (lineno_list_t *) NULL;
3281 list->file = cur_file_ptr;
3282 list->proc = cur_proc_ptr;
3283 list->frag = frag_now;
3284 list->paddr = frag_now_fix ();
3285 list->lineno = lineno;
3287 /* We don't want to merge files which have line numbers. */
3288 cur_file_ptr->fdr.fMerge = 0;
3290 /* A .loc directive will sometimes appear before a .ent directive,
3291 which means that cur_proc_ptr will be NULL here. Arrange to
3293 if (cur_proc_ptr == (proc_t *) NULL)
3297 pl = &noproc_lineno;
3298 while (*pl != (lineno_list_t *) NULL)
3305 *last_lineno_ptr = list;
3306 last_lineno_ptr = &list->next;
3310 /* The MIPS assembler sometimes inserts nop instructions in the
3311 instruction stream. When this happens, we must patch up the .loc
3312 information so that it points to the instruction after the nop. */
3315 ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
3317 if (last_lineno != NULL
3318 && last_lineno->frag == old_frag
3319 && last_lineno->paddr == old_frag_offset)
3321 last_lineno->frag = frag_now;
3322 last_lineno->paddr = frag_now_fix ();
3326 /* Make sure the @stabs symbol is emitted. */
3329 mark_stabs (int ignore ATTRIBUTE_UNUSED)
3333 /* Add a dummy @stabs dymbol. */
3335 (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info,
3337 (bfd_vma) 0, (symint_t) -1,
3338 ECOFF_MARK_STAB (0));
3342 /* Parse .weakext directives. */
3344 /* For TC_MIPS use the version in tc-mips.c. */
3346 ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
3353 name = input_line_pointer;
3354 c = get_symbol_end ();
3355 symbolP = symbol_find_or_make (name);
3356 *input_line_pointer = c;
3360 if (*input_line_pointer == ',')
3362 if (S_IS_DEFINED (symbolP))
3364 as_bad (_("symbol `%s' is already defined"),
3365 S_GET_NAME (symbolP));
3366 ignore_rest_of_line ();
3370 ++input_line_pointer;
3372 if (! is_end_of_line[(unsigned char) *input_line_pointer])
3375 if (exp.X_op != O_symbol)
3377 as_bad (_("bad .weakext directive"));
3378 ignore_rest_of_line ();
3381 symbol_set_value_expression (symbolP, &exp);
3385 S_SET_WEAK (symbolP);
3387 demand_empty_rest_of_line ();
3389 #endif /* not TC_MIPS */
3391 /* Handle .stabs directives. The actual parsing routine is done by a
3392 generic routine. This routine is called via OBJ_PROCESS_STAB.
3393 When this is called, input_line_pointer will be pointing at the
3394 value field of the stab.
3396 .stabs directives have five fields:
3397 "string" a string, encoding the type information.
3398 code a numeric code, defined in <stab.h>
3400 desc a zero or line number
3401 value a numeric value or an address.
3403 If the value is relocatable, we transform this into:
3404 iss points as an index into string space
3405 value value from lookup of the name
3406 st st from lookup of the name
3407 sc sc from lookup of the name
3408 index code|CODE_MASK
3410 If the value is not relocatable, we transform this into:
3411 iss points as an index into string space
3415 index code|CODE_MASK
3417 .stabn directives have four fields (string is null):
3418 code a numeric code, defined in <stab.h>
3420 desc a zero or a line number
3421 value a numeric value or an address. */
3424 ecoff_stab (segT sec ATTRIBUTE_UNUSED,
3431 efdr_t *save_file_ptr = cur_file_ptr;
3438 localsym_t *hold = NULL;
3440 ecoff_debugging_seen = 1;
3442 /* We don't handle .stabd. */
3443 if (what != 's' && what != 'n')
3445 as_bad (_(".stab%c is not supported"), what);
3449 /* A .stabn uses a null name, not an empty string. */
3453 /* We ignore the other field. */
3455 as_warn (_(".stab%c: ignoring non-zero other field"), what);
3457 /* Make sure we have a current file. */
3458 if (cur_file_ptr == (efdr_t *) NULL)
3460 add_file ((const char *) NULL, 0, 1);
3461 save_file_ptr = cur_file_ptr;
3464 /* For stabs in ECOFF, the first symbol must be @stabs. This is a
3466 if (stabs_seen == 0)
3469 /* Line number stabs are handled differently, since they have two
3470 values, the line number and the address of the label. We use the
3471 index field (aka desc) to hold the line number, and the value
3472 field to hold the address. The symbol type is st_Label, which
3473 should be different from the other stabs, so that gdb can
3475 if (type == N_SLINE)
3483 listing_source_line ((unsigned int) desc);
3486 dummy_symr.index = desc;
3487 if (dummy_symr.index != desc)
3489 as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
3494 name = input_line_pointer;
3495 name_end = get_symbol_end ();
3497 sym = symbol_find_or_make (name);
3498 *input_line_pointer = name_end;
3509 if (listing && (type == N_SO || type == N_SOL))
3510 listing_source_file (string);
3513 if (ISDIGIT (*input_line_pointer)
3514 || *input_line_pointer == '-'
3515 || *input_line_pointer == '+')
3519 sym = (symbolS *) NULL;
3520 value = get_absolute_expression ();
3523 else if (! is_name_beginner ((unsigned char) *input_line_pointer))
3525 as_warn (_("illegal .stab%c directive, bad character"), what);
3536 if (exp.X_op == O_constant)
3539 value = exp.X_add_number;
3542 else if (exp.X_op == O_symbol)
3544 sym = exp.X_add_symbol;
3546 addend = exp.X_add_number;
3550 sym = make_expr_symbol (&exp);
3556 indx = ECOFF_MARK_STAB (type);
3559 /* Don't store the stabs symbol we are creating as the type of the
3560 ECOFF symbol. We want to compute the type of the ECOFF symbol
3562 if (sym != (symbolS *) NULL)
3563 hold = symbol_get_obj (sym)->ecoff_symbol;
3565 (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
3567 if (sym != (symbolS *) NULL)
3568 symbol_get_obj (sym)->ecoff_symbol = hold;
3570 /* Restore normal file type. */
3571 cur_file_ptr = save_file_ptr;
3574 /* Frob an ECOFF symbol. Small common symbols go into a special
3575 .scommon section rather than bfd_com_section. */
3578 ecoff_frob_symbol (symbolS *sym)
3580 if (S_IS_COMMON (sym)
3581 && S_GET_VALUE (sym) > 0
3582 && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
3584 static asection scom_section;
3585 static asymbol scom_symbol;
3587 /* We must construct a fake section similar to bfd_com_section
3588 but with the name .scommon. */
3589 if (scom_section.name == NULL)
3591 scom_section = *bfd_com_section_ptr;
3592 scom_section.name = ".scommon";
3593 scom_section.output_section = &scom_section;
3594 scom_section.symbol = &scom_symbol;
3595 scom_section.symbol_ptr_ptr = &scom_section.symbol;
3596 scom_symbol = *bfd_com_section_ptr->symbol;
3597 scom_symbol.name = ".scommon";
3598 scom_symbol.section = &scom_section;
3600 S_SET_SEGMENT (sym, &scom_section);
3603 /* Double check weak symbols. */
3604 if (S_IS_WEAK (sym))
3606 if (S_IS_COMMON (sym))
3607 as_bad (_("symbol `%s' can not be both weak and common"),
3612 /* Add bytes to the symbolic information buffer. */
3615 ecoff_add_bytes (char **buf,
3624 need -= *bufend - bufptr;
3625 if (need < PAGE_SIZE)
3627 want = (*bufend - *buf) + need;
3628 *buf = (char *) xrealloc (*buf, want);
3629 *bufend = *buf + want;
3633 /* Adjust the symbolic information buffer to the alignment required
3634 for the ECOFF target debugging information. */
3636 static unsigned long
3637 ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
3640 unsigned long offset,
3643 bfd_size_type align;
3645 align = backend->debug_align;
3646 if ((offset & (align - 1)) != 0)
3650 add = align - (offset & (align - 1));
3651 if ((unsigned long) (*bufend - (*buf + offset)) < add)
3652 (void) ecoff_add_bytes (buf, bufend, *buf + offset, add);
3653 memset (*buf + offset, 0, add);
3655 if (bufptrptr != (char **) NULL)
3656 *bufptrptr = *buf + offset;
3662 /* Build the line number information. */
3664 static unsigned long
3665 ecoff_build_lineno (const struct ecoff_debug_swap *backend,
3668 unsigned long offset,
3672 register lineno_list_t *l;
3673 lineno_list_t *last;
3679 lineno_list_t first;
3680 lineno_list_t *local_first_lineno = first_lineno;
3682 if (linecntptr != (long *) NULL)
3685 bufptr = *buf + offset;
3687 file = (efdr_t *) NULL;
3688 proc = (proc_t *) NULL;
3689 last = (lineno_list_t *) NULL;
3694 /* FIXME? Now that MIPS embedded-PIC is gone, it may be safe to
3695 remove this code. */
3696 /* For some reason the address of the first procedure is ignored
3697 when reading line numbers. This doesn't matter if the address of
3698 the first procedure is 0, but when gcc is generating MIPS
3699 embedded PIC code, it will put strings in the .text section
3700 before the first procedure. We cope by inserting a dummy line if
3701 the address of the first procedure is not 0. Hopefully this
3702 won't screw things up too badly.
3704 Don't do this for ECOFF assembly source line numbers. They work
3705 without this extra attention. */
3706 if (debug_type != DEBUG_ECOFF
3707 && first_proc_ptr != (proc_t *) NULL
3708 && local_first_lineno != (lineno_list_t *) NULL
3709 && ((S_GET_VALUE (first_proc_ptr->sym->as_sym)
3710 + bfd_get_section_vma (stdoutput,
3711 S_GET_SEGMENT (first_proc_ptr->sym->as_sym)))
3714 first.file = local_first_lineno->file;
3715 first.proc = local_first_lineno->proc;
3716 first.frag = &zero_address_frag;
3720 first.next = local_first_lineno;
3721 local_first_lineno = &first;
3724 for (l = local_first_lineno; l != (lineno_list_t *) NULL; l = l->next)
3729 /* Get the offset to the memory address of the next line number
3730 (in words). Do this first, so that we can skip ahead to the
3731 next useful line number entry. */
3732 if (l->next == (lineno_list_t *) NULL)
3734 /* We want a count of zero, but it will be decremented
3735 before it is used. */
3738 else if (l->next->frag->fr_address + l->next->paddr
3739 > l->frag->fr_address + l->paddr)
3741 count = ((l->next->frag->fr_address + l->next->paddr
3742 - (l->frag->fr_address + l->paddr))
3747 /* Don't change last, so we still get the right delta. */
3751 if (l->file != file || l->proc != proc)
3753 if (l->proc != proc && proc != (proc_t *) NULL)
3754 proc->pdr.lnHigh = last->lineno;
3755 if (l->file != file && file != (efdr_t *) NULL)
3757 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3758 file->fdr.cline = totcount + count;
3759 if (linecntptr != (long *) NULL)
3760 *linecntptr += totcount + count;
3764 if (l->file != file)
3766 efdr_t *last_file = file;
3769 if (last_file != (efdr_t *) NULL)
3771 = last_file->fdr.ilineBase + last_file->fdr.cline;
3773 file->fdr.ilineBase = 0;
3774 file->fdr.cbLineOffset = c;
3776 if (l->proc != proc)
3779 if (proc != (proc_t *) NULL)
3781 proc->pdr.lnLow = l->lineno;
3782 proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
3783 proc->pdr.iline = totcount;
3787 last = (lineno_list_t *) NULL;
3792 /* Get the offset to this line number. */
3793 if (last == (lineno_list_t *) NULL)
3796 delta = l->lineno - last->lineno;
3798 /* Put in the offset to this line number. */
3803 /* 1 is added to each count read. */
3805 /* We can only adjust the word count by up to 15 words at a
3817 if (delta >= -7 && delta <= 7)
3819 if (bufptr >= *bufend)
3820 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3821 *bufptr++ = setcount + (delta << 4);
3829 if (*bufend - bufptr < 3)
3830 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
3831 *bufptr++ = setcount + (8 << 4);
3832 if (delta < -0x8000)
3837 else if (delta > 0x7fff)
3847 *bufptr++ = set >> 8;
3848 *bufptr++ = set & 0xffff;
3853 /* Finish adjusting the count. */
3856 if (bufptr >= *bufend)
3857 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3858 /* 1 is added to each count read. */
3877 if (proc != (proc_t *) NULL)
3878 proc->pdr.lnHigh = last->lineno;
3879 if (file != (efdr_t *) NULL)
3881 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3882 file->fdr.cline = totcount;
3885 if (linecntptr != (long *) NULL)
3886 *linecntptr += totcount;
3888 c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
3893 /* Build and swap out the symbols. */
3895 static unsigned long
3896 ecoff_build_symbols (const struct ecoff_debug_swap *backend,
3899 unsigned long offset)
3901 const bfd_size_type external_sym_size = backend->external_sym_size;
3902 void (* const swap_sym_out) (bfd *, const SYMR *, void *)
3903 = backend->swap_sym_out;
3906 vlinks_t *file_link;
3908 sym_out = *buf + offset;
3912 /* The symbols are stored by file. */
3913 for (file_link = file_desc.first;
3914 file_link != (vlinks_t *) NULL;
3915 file_link = file_link->next)
3922 if (file_link->next == (vlinks_t *) NULL)
3923 fil_cnt = file_desc.objects_last_page;
3925 fil_cnt = file_desc.objects_per_page;
3926 fil_ptr = file_link->datum->file;
3927 fil_end = fil_ptr + fil_cnt;
3928 for (; fil_ptr < fil_end; fil_ptr++)
3932 fil_ptr->fdr.isymBase = isym;
3934 for (sym_link = fil_ptr->symbols.first;
3935 sym_link != (vlinks_t *) NULL;
3936 sym_link = sym_link->next)
3939 localsym_t *sym_ptr;
3940 localsym_t *sym_end;
3942 if (sym_link->next == (vlinks_t *) NULL)
3943 sym_cnt = fil_ptr->symbols.objects_last_page;
3945 sym_cnt = fil_ptr->symbols.objects_per_page;
3946 sym_ptr = sym_link->datum->sym;
3947 sym_end = sym_ptr + sym_cnt;
3948 for (; sym_ptr < sym_end; sym_ptr++)
3954 know (sym_ptr->file_ptr == fil_ptr);
3956 /* If there is no associated gas symbol, then this
3957 is a pure debugging symbol. We have already
3958 added the name (if any) to fil_ptr->strings.
3959 Otherwise we must decide whether this is an
3960 external or a local symbol (actually, it may be
3961 both if the local provides additional debugging
3962 information for the external). */
3964 as_sym = sym_ptr->as_sym;
3965 if (as_sym != (symbolS *) NULL)
3969 /* The value of a block start symbol is the
3970 offset from the start of the procedure. For
3971 other symbols we just use the gas value (but
3972 we must offset it by the vma of the section,
3973 just as BFD does, because BFD will not see
3975 if (sym_ptr->ecoff_sym.asym.st == (int) st_Block
3976 && sym_ptr->ecoff_sym.asym.sc == (int) sc_Text)
3980 know (sym_ptr->proc_ptr != (proc_t *) NULL);
3981 begin_sym = sym_ptr->proc_ptr->sym->as_sym;
3982 if (S_GET_SEGMENT (as_sym)
3983 != S_GET_SEGMENT (begin_sym))
3984 as_warn (_(".begin/.bend in different segments"));
3985 sym_ptr->ecoff_sym.asym.value =
3986 S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
3989 sym_ptr->ecoff_sym.asym.value =
3990 (S_GET_VALUE (as_sym)
3991 + bfd_get_section_vma (stdoutput,
3992 S_GET_SEGMENT (as_sym))
3995 sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
3997 /* Set st_Proc to st_StaticProc for local
3999 if (sym_ptr->ecoff_sym.asym.st == st_Proc
4000 && S_IS_DEFINED (as_sym)
4001 && ! S_IS_EXTERNAL (as_sym)
4002 && ! S_IS_WEAK (as_sym))
4003 sym_ptr->ecoff_sym.asym.st = st_StaticProc;
4005 /* Get the type and storage class based on where
4006 the symbol actually wound up. Traditionally,
4007 N_LBRAC and N_RBRAC are *not* relocated. */
4008 indx = sym_ptr->ecoff_sym.asym.index;
4009 if (sym_ptr->ecoff_sym.asym.st == st_Nil
4010 && sym_ptr->ecoff_sym.asym.sc == sc_Nil
4011 && (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
4012 || ((ECOFF_UNMARK_STAB (indx) != N_LBRAC)
4013 && (ECOFF_UNMARK_STAB (indx) != N_RBRAC))))
4016 const char *segname;
4020 seg = S_GET_SEGMENT (as_sym);
4021 segname = segment_name (seg);
4023 if (! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym)
4024 && (S_IS_EXTERNAL (as_sym)
4025 || S_IS_WEAK (as_sym)
4026 || ! S_IS_DEFINED (as_sym)))
4028 if ((symbol_get_bfdsym (as_sym)->flags
4029 & BSF_FUNCTION) != 0)
4034 else if (seg == text_section)
4039 if (! S_IS_DEFINED (as_sym))
4043 s = symbol_get_obj (as_sym)->ecoff_extern_size;
4045 || s > bfd_get_gp_size (stdoutput))
4050 sym_ptr->ecoff_sym.asym.value = s;
4053 S_SET_SIZE (as_sym, s);
4056 else if (S_IS_COMMON (as_sym))
4058 if (S_GET_VALUE (as_sym) > 0
4059 && (S_GET_VALUE (as_sym)
4060 <= bfd_get_gp_size (stdoutput)))
4065 else if (seg == text_section)
4067 else if (seg == data_section)
4069 else if (strcmp (segname, ".rdata") == 0
4070 || strcmp (segname, ".rodata") == 0)
4072 else if (strcmp (segname, ".sdata") == 0)
4074 else if (seg == bss_section)
4076 else if (strcmp (segname, ".sbss") == 0)
4078 else if (seg == bfd_abs_section_ptr)
4082 /* This must be a user named section.
4083 This is not possible in ECOFF, but it
4088 sym_ptr->ecoff_sym.asym.st = (int) st;
4089 sym_ptr->ecoff_sym.asym.sc = (int) sc;
4092 /* This is just an external symbol if it is
4093 outside a procedure and it has a type.
4094 FIXME: g++ will generate symbols which have
4095 different names in the debugging information
4096 than the actual symbol. Should we handle
4098 if ((S_IS_EXTERNAL (as_sym)
4099 || S_IS_WEAK (as_sym)
4100 || ! S_IS_DEFINED (as_sym))
4101 && sym_ptr->proc_ptr == (proc_t *) NULL
4102 && sym_ptr->ecoff_sym.asym.st != (int) st_Nil
4103 && ! ECOFF_IS_STAB (&sym_ptr->ecoff_sym.asym))
4106 /* This is just an external symbol if it is a
4108 if (S_IS_COMMON (as_sym))
4111 /* If an st_end symbol has an associated gas
4112 symbol, then it is a local label created for
4113 a .bend or .end directive. Stabs line
4114 numbers will have \001 in the names. */
4116 && sym_ptr->ecoff_sym.asym.st != st_End
4117 && strchr (sym_ptr->name, '\001') == 0)
4118 sym_ptr->ecoff_sym.asym.iss =
4119 add_string (&fil_ptr->strings,
4125 /* We now know the index of this symbol; fill in
4126 locations that have been waiting for that
4128 if (sym_ptr->begin_ptr != (localsym_t *) NULL)
4130 localsym_t *begin_ptr;
4134 begin_ptr = sym_ptr->begin_ptr;
4135 know (begin_ptr->sym_index != -1);
4136 sym_ptr->ecoff_sym.asym.index = begin_ptr->sym_index;
4137 if (sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
4138 sym_ptr->ecoff_sym.asym.iss =
4139 begin_ptr->ecoff_sym.asym.iss;
4141 begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
4142 if (begin_type == st_File
4143 || begin_type == st_Block)
4145 begin_ptr->ecoff_sym.asym.index =
4146 isym - ifilesym + 1;
4147 (*swap_sym_out) (stdoutput,
4148 &begin_ptr->ecoff_sym.asym,
4151 + (begin_ptr->sym_index
4152 * external_sym_size)));
4156 know (begin_ptr->index_ptr != (aux_t *) NULL);
4157 begin_ptr->index_ptr->data.isym =
4158 isym - ifilesym + 1;
4161 /* The value of the symbol marking the end of a
4162 procedure is the size of the procedure. The
4163 value of the symbol marking the end of a
4164 block is the offset from the start of the
4165 procedure to the block. */
4166 if (begin_type == st_Proc
4167 || begin_type == st_StaticProc)
4169 know (as_sym != (symbolS *) NULL);
4170 know (begin_ptr->as_sym != (symbolS *) NULL);
4171 if (S_GET_SEGMENT (as_sym)
4172 != S_GET_SEGMENT (begin_ptr->as_sym))
4173 as_warn (_(".begin/.bend in different segments"));
4174 sym_ptr->ecoff_sym.asym.value =
4175 (S_GET_VALUE (as_sym)
4176 - S_GET_VALUE (begin_ptr->as_sym));
4178 /* If the size is odd, this is probably a
4179 mips16 function; force it to be even. */
4180 if ((sym_ptr->ecoff_sym.asym.value & 1) != 0)
4181 ++sym_ptr->ecoff_sym.asym.value;
4184 S_SET_SIZE (begin_ptr->as_sym,
4185 sym_ptr->ecoff_sym.asym.value);
4188 else if (begin_type == st_Block
4189 && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
4193 know (as_sym != (symbolS *) NULL);
4194 know (sym_ptr->proc_ptr != (proc_t *) NULL);
4195 begin_sym = sym_ptr->proc_ptr->sym->as_sym;
4196 if (S_GET_SEGMENT (as_sym)
4197 != S_GET_SEGMENT (begin_sym))
4198 as_warn (_(".begin/.bend in different segments"));
4199 sym_ptr->ecoff_sym.asym.value =
4200 S_GET_VALUE (as_sym) - S_GET_VALUE (begin_sym);
4204 for (f = sym_ptr->forward_ref;
4205 f != (forward_t *) NULL;
4209 f->ifd_ptr->data.isym = fil_ptr->file_index;
4210 f->index_ptr->data.rndx.index = isym - ifilesym;
4215 if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
4216 sym_out = ecoff_add_bytes (buf, bufend,
4219 (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
4221 sym_out += external_sym_size;
4223 sym_ptr->sym_index = isym;
4225 if (sym_ptr->proc_ptr != (proc_t *) NULL
4226 && sym_ptr->proc_ptr->sym == sym_ptr)
4227 sym_ptr->proc_ptr->pdr.isym = isym - ifilesym;
4232 /* Record the local symbol index and file number in
4233 case this is an external symbol. Note that this
4234 destroys the asym.index field. */
4235 if (as_sym != (symbolS *) NULL
4236 && symbol_get_obj (as_sym)->ecoff_symbol == sym_ptr)
4238 if ((sym_ptr->ecoff_sym.asym.st == st_Proc
4239 || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
4241 sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
4242 sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
4244 /* Don't try to merge an FDR which has an
4245 external symbol attached to it. */
4246 if (S_IS_EXTERNAL (as_sym) || S_IS_WEAK (as_sym))
4247 fil_ptr->fdr.fMerge = 0;
4251 fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
4255 return offset + isym * external_sym_size;
4258 /* Swap out the procedure information. */
4260 static unsigned long
4261 ecoff_build_procs (const struct ecoff_debug_swap *backend,
4264 unsigned long offset)
4266 const bfd_size_type external_pdr_size = backend->external_pdr_size;
4267 void (* const swap_pdr_out) (bfd *, const PDR *, void *)
4268 = backend->swap_pdr_out;
4271 vlinks_t *file_link;
4273 pdr_out = *buf + offset;
4277 /* The procedures are stored by file. */
4278 for (file_link = file_desc.first;
4279 file_link != (vlinks_t *) NULL;
4280 file_link = file_link->next)
4286 if (file_link->next == (vlinks_t *) NULL)
4287 fil_cnt = file_desc.objects_last_page;
4289 fil_cnt = file_desc.objects_per_page;
4290 fil_ptr = file_link->datum->file;
4291 fil_end = fil_ptr + fil_cnt;
4292 for (; fil_ptr < fil_end; fil_ptr++)
4294 vlinks_t *proc_link;
4297 fil_ptr->fdr.ipdFirst = iproc;
4299 for (proc_link = fil_ptr->procs.first;
4300 proc_link != (vlinks_t *) NULL;
4301 proc_link = proc_link->next)
4307 if (proc_link->next == (vlinks_t *) NULL)
4308 prc_cnt = fil_ptr->procs.objects_last_page;
4310 prc_cnt = fil_ptr->procs.objects_per_page;
4311 proc_ptr = proc_link->datum->proc;
4312 proc_end = proc_ptr + prc_cnt;
4313 for (; proc_ptr < proc_end; proc_ptr++)
4318 adr_sym = proc_ptr->sym->as_sym;
4319 adr = (S_GET_VALUE (adr_sym)
4320 + bfd_get_section_vma (stdoutput,
4321 S_GET_SEGMENT (adr_sym)));
4324 /* This code used to force the adr of the very
4325 first fdr to be 0. However, the native tools
4326 don't do that, and I can't remember why it
4327 used to work that way, so I took it out. */
4328 fil_ptr->fdr.adr = adr;
4331 proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr;
4332 if ((bfd_size_type)(*bufend - pdr_out) < external_pdr_size)
4333 pdr_out = ecoff_add_bytes (buf, bufend,
4336 (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
4337 pdr_out += external_pdr_size;
4341 fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
4345 return offset + iproc * external_pdr_size;
4348 /* Swap out the aux information. */
4350 static unsigned long
4351 ecoff_build_aux (const struct ecoff_debug_swap *backend,
4354 unsigned long offset)
4357 union aux_ext *aux_out;
4359 vlinks_t *file_link;
4361 bigendian = bfd_big_endian (stdoutput);
4363 aux_out = (union aux_ext *) (*buf + offset);
4367 /* The aux entries are stored by file. */
4368 for (file_link = file_desc.first;
4369 file_link != (vlinks_t *) NULL;
4370 file_link = file_link->next)
4376 if (file_link->next == (vlinks_t *) NULL)
4377 fil_cnt = file_desc.objects_last_page;
4379 fil_cnt = file_desc.objects_per_page;
4380 fil_ptr = file_link->datum->file;
4381 fil_end = fil_ptr + fil_cnt;
4382 for (; fil_ptr < fil_end; fil_ptr++)
4386 fil_ptr->fdr.fBigendian = bigendian;
4387 fil_ptr->fdr.iauxBase = iaux;
4388 for (aux_link = fil_ptr->aux_syms.first;
4389 aux_link != (vlinks_t *) NULL;
4390 aux_link = aux_link->next)
4396 if (aux_link->next == (vlinks_t *) NULL)
4397 aux_cnt = fil_ptr->aux_syms.objects_last_page;
4399 aux_cnt = fil_ptr->aux_syms.objects_per_page;
4400 aux_ptr = aux_link->datum->aux;
4401 aux_end = aux_ptr + aux_cnt;
4402 for (; aux_ptr < aux_end; aux_ptr++)
4404 if ((unsigned long) (*bufend - (char *) aux_out)
4405 < sizeof (union aux_ext))
4406 aux_out = ((union aux_ext *)
4407 ecoff_add_bytes (buf, bufend,
4409 sizeof (union aux_ext)));
4410 switch (aux_ptr->type)
4413 (*backend->swap_tir_out) (bigendian,
4418 (*backend->swap_rndx_out) (bigendian,
4419 &aux_ptr->data.rndx,
4423 AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
4427 AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
4431 AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
4435 AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
4439 AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
4443 AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
4452 fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
4456 return ecoff_padding_adjust (backend, buf, bufend,
4457 offset + iaux * sizeof (union aux_ext),
4461 /* Copy out the strings from a varray_t. This returns the number of
4462 bytes copied, rather than the new offset. */
4464 static unsigned long
4465 ecoff_build_strings (char **buf,
4467 unsigned long offset,
4474 str_out = *buf + offset;
4478 for (str_link = vp->first;
4479 str_link != (vlinks_t *) NULL;
4480 str_link = str_link->next)
4482 unsigned long str_cnt;
4484 if (str_link->next == (vlinks_t *) NULL)
4485 str_cnt = vp->objects_last_page;
4487 str_cnt = vp->objects_per_page;
4489 if ((unsigned long)(*bufend - str_out) < str_cnt)
4490 str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
4492 memcpy (str_out, str_link->datum->byte, str_cnt);
4500 /* Dump out the local strings. */
4502 static unsigned long
4503 ecoff_build_ss (const struct ecoff_debug_swap *backend,
4506 unsigned long offset)
4509 vlinks_t *file_link;
4513 for (file_link = file_desc.first;
4514 file_link != (vlinks_t *) NULL;
4515 file_link = file_link->next)
4521 if (file_link->next == (vlinks_t *) NULL)
4522 fil_cnt = file_desc.objects_last_page;
4524 fil_cnt = file_desc.objects_per_page;
4525 fil_ptr = file_link->datum->file;
4526 fil_end = fil_ptr + fil_cnt;
4527 for (; fil_ptr < fil_end; fil_ptr++)
4531 fil_ptr->fdr.issBase = iss;
4532 ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
4534 fil_ptr->fdr.cbSs = ss_cnt;
4539 return ecoff_padding_adjust (backend, buf, bufend, offset + iss,
4543 /* Swap out the file descriptors. */
4545 static unsigned long
4546 ecoff_build_fdr (const struct ecoff_debug_swap *backend,
4549 unsigned long offset)
4551 const bfd_size_type external_fdr_size = backend->external_fdr_size;
4552 void (* const swap_fdr_out) (bfd *, const FDR *, void *)
4553 = backend->swap_fdr_out;
4556 vlinks_t *file_link;
4560 fdr_out = *buf + offset;
4562 for (file_link = file_desc.first;
4563 file_link != (vlinks_t *) NULL;
4564 file_link = file_link->next)
4570 if (file_link->next == (vlinks_t *) NULL)
4571 fil_cnt = file_desc.objects_last_page;
4573 fil_cnt = file_desc.objects_per_page;
4574 fil_ptr = file_link->datum->file;
4575 fil_end = fil_ptr + fil_cnt;
4576 for (; fil_ptr < fil_end; fil_ptr++)
4578 if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
4579 fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
4581 (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
4582 fdr_out += external_fdr_size;
4587 return offset + ifile * external_fdr_size;
4590 /* Set up the external symbols. These are supposed to be handled by
4591 the backend. This routine just gets the right information and
4592 calls a backend function to deal with it. */
4595 ecoff_setup_ext (void)
4597 register symbolS *sym;
4599 for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
4601 if (symbol_get_obj (sym)->ecoff_symbol == NULL)
4604 /* If this is a local symbol, then force the fields to zero. */
4605 if (! S_IS_EXTERNAL (sym)
4606 && ! S_IS_WEAK (sym)
4607 && S_IS_DEFINED (sym))
4609 struct localsym *lsym;
4611 lsym = symbol_get_obj (sym)->ecoff_symbol;
4612 lsym->ecoff_sym.asym.value = 0;
4613 lsym->ecoff_sym.asym.st = (int) st_Nil;
4614 lsym->ecoff_sym.asym.sc = (int) sc_Nil;
4615 lsym->ecoff_sym.asym.index = indexNil;
4618 obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
4622 /* Build the ECOFF debugging information. */
4625 ecoff_build_debug (HDRR *hdr,
4627 const struct ecoff_debug_swap *backend)
4629 const bfd_size_type external_pdr_size = backend->external_pdr_size;
4634 efdr_t *hold_file_ptr;
4635 proc_t *hold_proc_ptr;
4639 unsigned long offset;
4641 /* Make sure we have a file. */
4642 if (first_file == (efdr_t *) NULL)
4643 add_file ((const char *) NULL, 0, 1);
4645 /* Handle any top level tags. */
4646 for (ptag = top_tag_head->first_tag;
4647 ptag != (tag_t *) NULL;
4650 if (ptag->forward_ref != (forward_t *) NULL)
4651 add_unknown_tag (ptag);
4653 ptag_next = ptag->same_block;
4654 ptag->hash_ptr->tag_ptr = ptag->same_name;
4658 free_thead (top_tag_head);
4660 /* Look through the symbols. Add debugging information for each
4661 symbol that has not already received it. */
4662 hold_file_ptr = cur_file_ptr;
4663 hold_proc_ptr = cur_proc_ptr;
4664 cur_proc_ptr = (proc_t *) NULL;
4665 for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
4667 if (symbol_get_obj (sym)->ecoff_symbol != NULL
4668 || symbol_get_obj (sym)->ecoff_file == (efdr_t *) NULL
4669 || (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0)
4672 cur_file_ptr = symbol_get_obj (sym)->ecoff_file;
4673 add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym,
4674 (bfd_vma) 0, S_GET_VALUE (sym), indexNil);
4676 cur_proc_ptr = hold_proc_ptr;
4677 cur_file_ptr = hold_file_ptr;
4679 /* Output an ending symbol for all the files. We have to do this
4680 here for the last file, so we may as well do it for all of the
4683 for (fil_ptr = first_file;
4684 fil_ptr != (efdr_t *) NULL;
4685 fil_ptr = fil_ptr->next_file)
4687 cur_file_ptr = fil_ptr;
4688 while (cur_file_ptr->cur_scope != (scope_t *) NULL
4689 && cur_file_ptr->cur_scope->prev != (scope_t *) NULL)
4691 cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
4692 if (! end_warning && ! cur_file_ptr->fake)
4694 as_warn (_("missing .end or .bend at end of file"));
4698 if (cur_file_ptr->cur_scope != (scope_t *) NULL)
4699 (void) add_ecoff_symbol ((const char *) NULL,
4707 /* Build the symbolic information. */
4709 buf = (char *) xmalloc (PAGE_SIZE);
4710 bufend = buf + PAGE_SIZE;
4712 /* Build the line number information. */
4713 hdr->cbLineOffset = offset;
4714 offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
4716 hdr->cbLine = offset - hdr->cbLineOffset;
4718 /* We don't use dense numbers at all. */
4720 hdr->cbDnOffset = 0;
4722 /* We can't build the PDR table until we have built the symbols,
4723 because a PDR contains a symbol index. However, we set aside
4724 space at this point. */
4725 hdr->ipdMax = proc_cnt;
4726 hdr->cbPdOffset = offset;
4727 if ((bfd_size_type)(bufend - (buf + offset)) < proc_cnt * external_pdr_size)
4728 (void) ecoff_add_bytes (&buf, &bufend, buf + offset,
4729 proc_cnt * external_pdr_size);
4730 offset += proc_cnt * external_pdr_size;
4732 /* Build the local symbols. */
4733 hdr->cbSymOffset = offset;
4734 offset = ecoff_build_symbols (backend, &buf, &bufend, offset);
4735 hdr->isymMax = (offset - hdr->cbSymOffset) / backend->external_sym_size;
4737 /* Building the symbols initializes the symbol index in the PDR's.
4738 Now we can swap out the PDR's. */
4739 (void) ecoff_build_procs (backend, &buf, &bufend, hdr->cbPdOffset);
4741 /* We don't use optimization symbols. */
4743 hdr->cbOptOffset = 0;
4745 /* Swap out the auxiliary type information. */
4746 hdr->cbAuxOffset = offset;
4747 offset = ecoff_build_aux (backend, &buf, &bufend, offset);
4748 hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext);
4750 /* Copy out the local strings. */
4751 hdr->cbSsOffset = offset;
4752 offset = ecoff_build_ss (backend, &buf, &bufend, offset);
4753 hdr->issMax = offset - hdr->cbSsOffset;
4755 /* We don't use relative file descriptors. */
4757 hdr->cbRfdOffset = 0;
4759 /* Swap out the file descriptors. */
4760 hdr->cbFdOffset = offset;
4761 offset = ecoff_build_fdr (backend, &buf, &bufend, offset);
4762 hdr->ifdMax = (offset - hdr->cbFdOffset) / backend->external_fdr_size;
4764 /* Set up the external symbols, which are handled by the BFD back
4767 hdr->cbSsExtOffset = 0;
4769 hdr->cbExtOffset = 0;
4772 know ((offset & (backend->debug_align - 1)) == 0);
4774 /* FIXME: This value should be determined from the .verstamp directive,
4775 with reasonable defaults in config files. */
4777 hdr->vstamp = 0x030b;
4779 hdr->vstamp = 0x020b;
4786 /* Allocate a cluster of pages. */
4788 #ifndef MALLOC_CHECK
4791 allocate_cluster (unsigned long npages)
4793 register page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
4797 fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
4800 memset (value, 0, npages * PAGE_USIZE);
4805 static page_type *cluster_ptr = NULL;
4806 static unsigned long pages_left = 0;
4808 #endif /* MALLOC_CHECK */
4810 /* Allocate one page (which is initialized to 0). */
4813 allocate_page (void)
4815 #ifndef MALLOC_CHECK
4817 if (pages_left == 0)
4819 pages_left = MAX_CLUSTER_PAGES;
4820 cluster_ptr = allocate_cluster (pages_left);
4824 return cluster_ptr++;
4826 #else /* MALLOC_CHECK */
4830 ptr = xmalloc (PAGE_USIZE);
4831 memset (ptr, 0, PAGE_USIZE);
4834 #endif /* MALLOC_CHECK */
4837 /* Allocate scoping information. */
4840 allocate_scope (void)
4842 register scope_t *ptr;
4843 static scope_t initial_scope;
4845 #ifndef MALLOC_CHECK
4847 ptr = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
4848 if (ptr != (scope_t *) NULL)
4849 alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr->free;
4852 register int unallocated = alloc_counts[(int) alloc_type_scope].unallocated;
4853 register page_type *cur_page = alloc_counts[(int) alloc_type_scope].cur_page;
4855 if (unallocated == 0)
4857 unallocated = PAGE_SIZE / sizeof (scope_t);
4858 alloc_counts[(int) alloc_type_scope].cur_page = cur_page = allocate_page ();
4859 alloc_counts[(int) alloc_type_scope].total_pages++;
4862 ptr = &cur_page->scope[--unallocated];
4863 alloc_counts[(int) alloc_type_scope].unallocated = unallocated;
4868 ptr = (scope_t *) xmalloc (sizeof (scope_t));
4872 alloc_counts[(int) alloc_type_scope].total_alloc++;
4873 *ptr = initial_scope;
4877 /* Free scoping information. */
4880 free_scope (scope_t *ptr)
4882 alloc_counts[(int) alloc_type_scope].total_free++;
4884 #ifndef MALLOC_CHECK
4885 ptr->free = alloc_counts[(int) alloc_type_scope].free_list.f_scope;
4886 alloc_counts[(int) alloc_type_scope].free_list.f_scope = ptr;
4888 free ((void *) ptr);
4892 /* Allocate links for pages in a virtual array. */
4895 allocate_vlinks (void)
4897 register vlinks_t *ptr;
4898 static vlinks_t initial_vlinks;
4900 #ifndef MALLOC_CHECK
4902 register int unallocated = alloc_counts[(int) alloc_type_vlinks].unallocated;
4903 register page_type *cur_page = alloc_counts[(int) alloc_type_vlinks].cur_page;
4905 if (unallocated == 0)
4907 unallocated = PAGE_SIZE / sizeof (vlinks_t);
4908 alloc_counts[(int) alloc_type_vlinks].cur_page = cur_page = allocate_page ();
4909 alloc_counts[(int) alloc_type_vlinks].total_pages++;
4912 ptr = &cur_page->vlinks[--unallocated];
4913 alloc_counts[(int) alloc_type_vlinks].unallocated = unallocated;
4917 ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t));
4921 alloc_counts[(int) alloc_type_vlinks].total_alloc++;
4922 *ptr = initial_vlinks;
4926 /* Allocate string hash buckets. */
4929 allocate_shash (void)
4931 register shash_t *ptr;
4932 static shash_t initial_shash;
4934 #ifndef MALLOC_CHECK
4936 register int unallocated = alloc_counts[(int) alloc_type_shash].unallocated;
4937 register page_type *cur_page = alloc_counts[(int) alloc_type_shash].cur_page;
4939 if (unallocated == 0)
4941 unallocated = PAGE_SIZE / sizeof (shash_t);
4942 alloc_counts[(int) alloc_type_shash].cur_page = cur_page = allocate_page ();
4943 alloc_counts[(int) alloc_type_shash].total_pages++;
4946 ptr = &cur_page->shash[--unallocated];
4947 alloc_counts[(int) alloc_type_shash].unallocated = unallocated;
4951 ptr = (shash_t *) xmalloc (sizeof (shash_t));
4955 alloc_counts[(int) alloc_type_shash].total_alloc++;
4956 *ptr = initial_shash;
4960 /* Allocate type hash buckets. */
4963 allocate_thash (void)
4965 register thash_t *ptr;
4966 static thash_t initial_thash;
4968 #ifndef MALLOC_CHECK
4970 register int unallocated = alloc_counts[(int) alloc_type_thash].unallocated;
4971 register page_type *cur_page = alloc_counts[(int) alloc_type_thash].cur_page;
4973 if (unallocated == 0)
4975 unallocated = PAGE_SIZE / sizeof (thash_t);
4976 alloc_counts[(int) alloc_type_thash].cur_page = cur_page = allocate_page ();
4977 alloc_counts[(int) alloc_type_thash].total_pages++;
4980 ptr = &cur_page->thash[--unallocated];
4981 alloc_counts[(int) alloc_type_thash].unallocated = unallocated;
4985 ptr = (thash_t *) xmalloc (sizeof (thash_t));
4989 alloc_counts[(int) alloc_type_thash].total_alloc++;
4990 *ptr = initial_thash;
4994 /* Allocate structure, union, or enum tag information. */
4999 register tag_t *ptr;
5000 static tag_t initial_tag;
5002 #ifndef MALLOC_CHECK
5004 ptr = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
5005 if (ptr != (tag_t *) NULL)
5006 alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr->free;
5009 register int unallocated = alloc_counts[(int) alloc_type_tag].unallocated;
5010 register page_type *cur_page = alloc_counts[(int) alloc_type_tag].cur_page;
5012 if (unallocated == 0)
5014 unallocated = PAGE_SIZE / sizeof (tag_t);
5015 alloc_counts[(int) alloc_type_tag].cur_page = cur_page = allocate_page ();
5016 alloc_counts[(int) alloc_type_tag].total_pages++;
5019 ptr = &cur_page->tag[--unallocated];
5020 alloc_counts[(int) alloc_type_tag].unallocated = unallocated;
5025 ptr = (tag_t *) xmalloc (sizeof (tag_t));
5029 alloc_counts[(int) alloc_type_tag].total_alloc++;
5034 /* Free scoping information. */
5037 free_tag (tag_t *ptr)
5039 alloc_counts[(int) alloc_type_tag].total_free++;
5041 #ifndef MALLOC_CHECK
5042 ptr->free = alloc_counts[(int) alloc_type_tag].free_list.f_tag;
5043 alloc_counts[(int) alloc_type_tag].free_list.f_tag = ptr;
5049 /* Allocate forward reference to a yet unknown tag. */
5052 allocate_forward (void)
5054 register forward_t *ptr;
5055 static forward_t initial_forward;
5057 #ifndef MALLOC_CHECK
5059 register int unallocated = alloc_counts[(int) alloc_type_forward].unallocated;
5060 register page_type *cur_page = alloc_counts[(int) alloc_type_forward].cur_page;
5062 if (unallocated == 0)
5064 unallocated = PAGE_SIZE / sizeof (forward_t);
5065 alloc_counts[(int) alloc_type_forward].cur_page = cur_page = allocate_page ();
5066 alloc_counts[(int) alloc_type_forward].total_pages++;
5069 ptr = &cur_page->forward[--unallocated];
5070 alloc_counts[(int) alloc_type_forward].unallocated = unallocated;
5074 ptr = (forward_t *) xmalloc (sizeof (forward_t));
5078 alloc_counts[(int) alloc_type_forward].total_alloc++;
5079 *ptr = initial_forward;
5083 /* Allocate head of type hash list. */
5086 allocate_thead (void)
5088 register thead_t *ptr;
5089 static thead_t initial_thead;
5091 #ifndef MALLOC_CHECK
5093 ptr = alloc_counts[(int) alloc_type_thead].free_list.f_thead;
5094 if (ptr != (thead_t *) NULL)
5095 alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr->free;
5098 register int unallocated = alloc_counts[(int) alloc_type_thead].unallocated;
5099 register page_type *cur_page = alloc_counts[(int) alloc_type_thead].cur_page;
5101 if (unallocated == 0)
5103 unallocated = PAGE_SIZE / sizeof (thead_t);
5104 alloc_counts[(int) alloc_type_thead].cur_page = cur_page = allocate_page ();
5105 alloc_counts[(int) alloc_type_thead].total_pages++;
5108 ptr = &cur_page->thead[--unallocated];
5109 alloc_counts[(int) alloc_type_thead].unallocated = unallocated;
5114 ptr = (thead_t *) xmalloc (sizeof (thead_t));
5118 alloc_counts[(int) alloc_type_thead].total_alloc++;
5119 *ptr = initial_thead;
5123 /* Free scoping information. */
5126 free_thead (thead_t *ptr)
5128 alloc_counts[(int) alloc_type_thead].total_free++;
5130 #ifndef MALLOC_CHECK
5131 ptr->free = (thead_t *) alloc_counts[(int) alloc_type_thead].free_list.f_thead;
5132 alloc_counts[(int) alloc_type_thead].free_list.f_thead = ptr;
5138 static lineno_list_t *
5139 allocate_lineno_list (void)
5141 register lineno_list_t *ptr;
5142 static lineno_list_t initial_lineno_list;
5144 #ifndef MALLOC_CHECK
5146 register int unallocated = alloc_counts[(int) alloc_type_lineno].unallocated;
5147 register page_type *cur_page = alloc_counts[(int) alloc_type_lineno].cur_page;
5149 if (unallocated == 0)
5151 unallocated = PAGE_SIZE / sizeof (lineno_list_t);
5152 alloc_counts[(int) alloc_type_lineno].cur_page = cur_page = allocate_page ();
5153 alloc_counts[(int) alloc_type_lineno].total_pages++;
5156 ptr = &cur_page->lineno[--unallocated];
5157 alloc_counts[(int) alloc_type_lineno].unallocated = unallocated;
5161 ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t));
5165 alloc_counts[(int) alloc_type_lineno].total_alloc++;
5166 *ptr = initial_lineno_list;
5171 ecoff_set_gp_prolog_size (int sz)
5173 if (cur_proc_ptr == 0)
5176 cur_proc_ptr->pdr.gp_prologue = sz;
5177 if (cur_proc_ptr->pdr.gp_prologue != sz)
5179 as_warn (_("GP prologue size exceeds field size, using 0 instead"));
5180 cur_proc_ptr->pdr.gp_prologue = 0;
5183 cur_proc_ptr->pdr.gp_used = 1;
5187 ecoff_no_current_file (void)
5189 return cur_file_ptr == (efdr_t *) NULL;
5193 ecoff_generate_asm_lineno (void)
5195 unsigned int lineno;
5197 lineno_list_t *list;
5199 as_where (&filename, &lineno);
5201 if (current_stabs_filename == (char *) NULL
5202 || filename_cmp (current_stabs_filename, filename))
5203 add_file (filename, 0, 1);
5205 list = allocate_lineno_list ();
5207 list->next = (lineno_list_t *) NULL;
5208 list->file = cur_file_ptr;
5209 list->proc = cur_proc_ptr;
5210 list->frag = frag_now;
5211 list->paddr = frag_now_fix ();
5212 list->lineno = lineno;
5214 /* We don't want to merge files which have line numbers. */
5215 cur_file_ptr->fdr.fMerge = 0;
5217 /* A .loc directive will sometimes appear before a .ent directive,
5218 which means that cur_proc_ptr will be NULL here. Arrange to
5220 if (cur_proc_ptr == (proc_t *) NULL)
5224 pl = &noproc_lineno;
5225 while (*pl != (lineno_list_t *) NULL)
5232 *last_lineno_ptr = list;
5233 last_lineno_ptr = &list->next;
5240 ecoff_generate_asm_lineno (void)
5244 #endif /* ECOFF_DEBUGGING */