opcodes/
[deliverable/binutils-gdb.git] / gas / ecoff.c
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>.
9
10 This file is part of GAS.
11
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)
15 any later version.
16
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.
21
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
25 02110-1301, USA. */
26
27 #include "as.h"
28
29 /* This file is compiled conditionally for those targets which use
30 ECOFF debugging information (e.g., MIPS ELF, Alpha ECOFF). */
31
32 #include "ecoff.h"
33
34 #ifdef ECOFF_DEBUGGING
35
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"
41
42 /* Why isn't this in coff/sym.h? */
43 #define ST_RFDESCAPE 0xfff
44
45 /* This file constructs the information used by the ECOFF debugging
46 format. It just builds a large block of data.
47
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. */
51
52 /* Here is a brief description of the MIPS ECOFF symbol table, by
53 Michael Meissner. The MIPS symbol table has the following pieces:
54
55 Symbolic Header
56 |
57 +-- Auxiliary Symbols
58 |
59 +-- Dense number table
60 |
61 +-- Optimizer Symbols
62 |
63 +-- External Strings
64 |
65 +-- External Symbols
66 |
67 +-- Relative file descriptors
68 |
69 +-- File table
70 |
71 +-- Procedure table
72 |
73 +-- Line number table
74 |
75 +-- Local Strings
76 |
77 +-- Local Symbols
78
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.
82
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:
90
91 1) dnLow: Low bound on array dimension.
92
93 2) dnHigh: High bound on array dimension.
94
95 3) isym: Index to the local symbol which is the start of the
96 function for the end of function first aux. entry.
97
98 4) width: Width of structures and bitfields.
99
100 5) count: Count of ranges for variant part.
101
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.
108
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:
114
115 a) fBitfield: a bit that says this is a bitfield, and the
116 size in bits follows as the next aux. entry.
117
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).
121
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:
125
126 btNil -- undefined
127 btAdr -- address - integer same size as ptr
128 btChar -- character
129 btUChar -- unsigned character
130 btShort -- short
131 btUShort -- unsigned short
132 btInt -- int
133 btUInt -- unsigned int
134 btLong -- long
135 btULong -- unsigned long
136 btFloat -- float (real)
137 btDouble -- Double (real)
138 btStruct -- Structure (Record)
139 btUnion -- Union (variant)
140 btEnum -- Enumerated
141 btTypedef -- defined via a typedef isymRef
142 btRange -- subrange of int
143 btSet -- pascal sets
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
151 btPicture -- Picture
152 btVoid -- Void (MIPS cc revision >= 2.00)
153
154 d) tq0 - tq5: type qualifier fields as needed. The
155 current type qualifier fields I have documentation for
156 are:
157
158 tqNil -- no more qualifiers
159 tqPtr -- pointer
160 tqProc -- procedure
161 tqArray -- array
162 tqFar -- 8086 far pointers
163 tqVol -- volatile
164
165 The dense number table is used in the front ends, and disappears by
166 the time the .o is created.
167
168 With the 1.31 compiler suite, the optimization symbols don't seem
169 to be used as far as I can tell.
170
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.
175
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.
187
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
191 tables for the file.
192
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.
200
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.
205
206 The local symbol table contains the following fields:
207
208 1) iss: index to the local string table giving the name of the
209 symbol.
210
211 2) value: value of the symbol (address, register number, etc.).
212
213 3) st: symbol type. The current symbol types are:
214
215 stNil -- Nuthin' special
216 stGlobal -- external symbol
217 stStatic -- static
218 stParam -- procedure argument
219 stLocal -- local variable
220 stLabel -- label
221 stProc -- External Procedure
222 stBlock -- beginning of block
223 stEnd -- end (of anything)
224 stMember -- member (of anything)
225 stTypedef -- type definition
226 stFile -- file name
227 stRegReloc -- register relocation
228 stForward -- forwarding address
229 stStaticProc -- Static procedure
230 stConstant -- const
231
232 4) sc: storage class. The current storage classes are:
233
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
256
257 5) index: pointer to a local symbol or aux. entry.
258
259 For the following program:
260
261 #include <stdio.h>
262
263 main(){
264 printf("Hello World!\n");
265 return 0;
266 }
267
268 Mips-tdump produces the following information:
269
270 Global file header:
271 magic number 0x162
272 # sections 2
273 timestamp 645311799, Wed Jun 13 17:16:39 1990
274 symbolic header offset 284
275 symbolic header size 96
276 optional header 56
277 flags 0x0
278
279 Symbolic header, magic number = 0x7009, vstamp = 1.31:
280
281 Info Offset Number Bytes
282 ==== ====== ====== =====
283
284 Line numbers 380 4 4 [13]
285 Dense numbers 0 0 0
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
293 Relative Files 0 0 0
294 External Symbols 1152 20 320
295
296 File #0, "hello2.c"
297
298 Name index = 1 Readin = No
299 Merge = No Endian = LITTLE
300 Debug level = G2 Language = C
301 Adr = 0x00000000
302
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
312
313 There are 6 local symbols, starting at 436
314
315 Symbol# 0: "hello2.c"
316 End+1 symbol = 6
317 String index = 1
318 Storage class = Text Index = 6
319 Symbol type = File Value = 0
320
321 Symbol# 1: "main"
322 End+1 symbol = 5
323 Type = int
324 String index = 10
325 Storage class = Text Index = 12
326 Symbol type = Proc Value = 0
327
328 Symbol# 2: ""
329 End+1 symbol = 4
330 String index = 0
331 Storage class = Text Index = 4
332 Symbol type = Block Value = 8
333
334 Symbol# 3: ""
335 First symbol = 2
336 String index = 0
337 Storage class = Text Index = 2
338 Symbol type = End Value = 28
339
340 Symbol# 4: "main"
341 First symbol = 1
342 String index = 10
343 Storage class = Text Index = 1
344 Symbol type = End Value = 52
345
346 Symbol# 5: "hello2.c"
347 First symbol = 0
348 String index = 1
349 Storage class = Text Index = 0
350 Symbol type = End Value = 0
351
352 There are 14 auxiliary table entries, starting at 628.
353
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]
368
369 There are 1 procedure descriptor entries, starting at 0.
370
371 Procedure descriptor 0:
372 Name index = 10 Name = "main"
373 .mask 0x80000000,-4 .fmask 0x00000000,0
374 .frame $29,24,$31
375 Opt. start = -1 Symbols start = 1
376 First line # = 3 Last line # = 6
377 Line Offset = 0 Address = 0x00000000
378
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
384
385 File #1, "/usr/include/stdio.h"
386
387 Name index = 1 Readin = No
388 Merge = Yes Endian = LITTLE
389 Debug level = G2 Language = C
390 Adr = 0x00000000
391
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
398 Procedures 1 0 0 436
399 Auxiliary symbols 14 25 100 684
400 Relative Files 0 0 0 0
401
402 There are 10 local symbols, starting at 442
403
404 Symbol# 0: "/usr/include/stdio.h"
405 End+1 symbol = 10
406 String index = 1
407 Storage class = Text Index = 10
408 Symbol type = File Value = 0
409
410 Symbol# 1: "_iobuf"
411 End+1 symbol = 9
412 String index = 22
413 Storage class = Info Index = 9
414 Symbol type = Block Value = 20
415
416 Symbol# 2: "_cnt"
417 Type = int
418 String index = 29
419 Storage class = Info Index = 4
420 Symbol type = Member Value = 0
421
422 Symbol# 3: "_ptr"
423 Type = ptr to char
424 String index = 34
425 Storage class = Info Index = 15
426 Symbol type = Member Value = 32
427
428 Symbol# 4: "_base"
429 Type = ptr to char
430 String index = 39
431 Storage class = Info Index = 16
432 Symbol type = Member Value = 64
433
434 Symbol# 5: "_bufsiz"
435 Type = int
436 String index = 45
437 Storage class = Info Index = 4
438 Symbol type = Member Value = 96
439
440 Symbol# 6: "_flag"
441 Type = short
442 String index = 53
443 Storage class = Info Index = 3
444 Symbol type = Member Value = 128
445
446 Symbol# 7: "_file"
447 Type = char
448 String index = 59
449 Storage class = Info Index = 2
450 Symbol type = Member Value = 144
451
452 Symbol# 8: ""
453 First symbol = 1
454 String index = 0
455 Storage class = Info Index = 1
456 Symbol type = End Value = 0
457
458 Symbol# 9: "/usr/include/stdio.h"
459 First symbol = 0
460 String index = 1
461 Storage class = Text Index = 0
462 Symbol type = End Value = 0
463
464 There are 25 auxiliary table entries, starting at 642.
465
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]
491
492 There are 0 procedure descriptor entries, starting at 1.
493
494 There are 20 external symbols, starting at 1152
495
496 Symbol# 0: "_iob"
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
501
502 Symbol# 1: "fopen"
503 String index = 5 Ifd = 1
504 Storage class = Nil Index = 1048575
505 Symbol type = Proc Value = 0
506
507 Symbol# 2: "fdopen"
508 String index = 11 Ifd = 1
509 Storage class = Nil Index = 1048575
510 Symbol type = Proc Value = 0
511
512 Symbol# 3: "freopen"
513 String index = 18 Ifd = 1
514 Storage class = Nil Index = 1048575
515 Symbol type = Proc Value = 0
516
517 Symbol# 4: "popen"
518 String index = 26 Ifd = 1
519 Storage class = Nil Index = 1048575
520 Symbol type = Proc Value = 0
521
522 Symbol# 5: "tmpfile"
523 String index = 32 Ifd = 1
524 Storage class = Nil Index = 1048575
525 Symbol type = Proc Value = 0
526
527 Symbol# 6: "ftell"
528 String index = 40 Ifd = 1
529 Storage class = Nil Index = 1048575
530 Symbol type = Proc Value = 0
531
532 Symbol# 7: "rewind"
533 String index = 46 Ifd = 1
534 Storage class = Nil Index = 1048575
535 Symbol type = Proc Value = 0
536
537 Symbol# 8: "setbuf"
538 String index = 53 Ifd = 1
539 Storage class = Nil Index = 1048575
540 Symbol type = Proc Value = 0
541
542 Symbol# 9: "setbuffer"
543 String index = 60 Ifd = 1
544 Storage class = Nil Index = 1048575
545 Symbol type = Proc Value = 0
546
547 Symbol# 10: "setlinebuf"
548 String index = 70 Ifd = 1
549 Storage class = Nil Index = 1048575
550 Symbol type = Proc Value = 0
551
552 Symbol# 11: "fgets"
553 String index = 81 Ifd = 1
554 Storage class = Nil Index = 1048575
555 Symbol type = Proc Value = 0
556
557 Symbol# 12: "gets"
558 String index = 87 Ifd = 1
559 Storage class = Nil Index = 1048575
560 Symbol type = Proc Value = 0
561
562 Symbol# 13: "ctermid"
563 String index = 92 Ifd = 1
564 Storage class = Nil Index = 1048575
565 Symbol type = Proc Value = 0
566
567 Symbol# 14: "cuserid"
568 String index = 100 Ifd = 1
569 Storage class = Nil Index = 1048575
570 Symbol type = Proc Value = 0
571
572 Symbol# 15: "tempnam"
573 String index = 108 Ifd = 1
574 Storage class = Nil Index = 1048575
575 Symbol type = Proc Value = 0
576
577 Symbol# 16: "tmpnam"
578 String index = 116 Ifd = 1
579 Storage class = Nil Index = 1048575
580 Symbol type = Proc Value = 0
581
582 Symbol# 17: "sprintf"
583 String index = 123 Ifd = 1
584 Storage class = Nil Index = 1048575
585 Symbol type = Proc Value = 0
586
587 Symbol# 18: "main"
588 Type = int
589 String index = 131 Ifd = 0
590 Storage class = Text Index = 1
591 Symbol type = Proc Value = 0
592
593 Symbol# 19: "printf"
594 String index = 136 Ifd = 0
595 Storage class = Undefined Index = 1048575
596 Symbol type = Proc Value = 0
597
598 The following auxiliary table entries were unused:
599
600 #0 0 0x00000000 void
601 #2 8 0x00000008 char
602 #3 16 0x00000010 short
603 #4 24 0x00000018 int
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 }
621 */
622 \f
623 /* Redefinition of of storage classes as an enumeration for better
624 debugging. */
625
626 typedef enum sc {
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 */
651 } sc_t;
652
653 /* Redefinition of symbol type. */
654
655 typedef enum st {
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 */
677 } st_t;
678
679 /* Redefinition of type qualifiers. */
680
681 typedef enum tq {
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 */
689 } tq_t;
690
691 /* Redefinition of basic types. */
692
693 typedef enum bt {
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 */
722 } bt_t;
723
724 #define N_TQ itqMax
725
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. */
731 } hash_state_t;
732
733 /* Types of different sized allocation requests. */
734 enum alloc_type {
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 */
746 };
747
748 /* Types of auxiliary type information. */
749 enum aux_type {
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 */
758 };
759 \f
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.
766
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). */
769
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
773
774 t7rb_tree4Z4xkeyZt4pair2ZC4xkeyZt7xsocket1Z4UserZt9select1st2Zt4pair\
775 2ZC4xkeyZt7xsocket1Z4UserZ4xkeyZt4less1Z4xkey
776
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. */
781
782 #ifndef PAGE_SIZE
783 #define PAGE_SIZE (8*1024) /* size of varray pages */
784 #endif
785
786 #define PAGE_USIZE ((unsigned long) PAGE_SIZE)
787
788 #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */
789 #define MAX_CLUSTER_PAGES 63
790 #endif
791
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 */
798 } vlinks_t;
799
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 */
808 } varray_t;
809
810 #ifndef MALLOC_CHECK
811 #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type))
812 #else
813 #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE)
814 #endif
815
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 */ \
823 }
824
825 /* Master type for indexes within the symbol table. */
826 typedef unsigned long symint_t;
827
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 */
834 } scope_t;
835
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 */
850 } localsym_t;
851
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 */
856 } aux_t;
857
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 */
863 } proc_t;
864
865 /* Number of proc_t structures allocated. */
866 static unsigned long proc_cnt;
867
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 */
874 } forward_t;
875
876 /* Linked list support for tags. The first tag in the list is always
877 the current tag for that block. */
878 typedef struct tag {
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 */
887 } tag_t;
888
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 */
894 } thead_t;
895
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 */
902 } small_free_t;
903
904 /* String hash table entry. */
905
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 */
914 } shash_t;
915
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. */
920
921 #define HASHBITS 30
922
923 #ifndef THASH_SIZE
924 #define THASH_SIZE 113
925 #endif
926
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 */
931 } thash_t;
932
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];
953 } efdr_t;
954
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 */
982 },
983
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 */
996
997 (struct efdr *)0, /* next_file: next file structure */
998
999 (struct hash_control *)0, /* str_hash: string hash table */
1000 { 0 }, /* thash_head: type hash table */
1001 };
1002
1003 static efdr_t *first_file; /* first file descriptor */
1004 static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */
1005
1006 /* Line number information is kept in a list until the assembly is
1007 finished. */
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 */
1015 } lineno_list_t;
1016
1017 static lineno_list_t *first_lineno;
1018 static lineno_list_t *last_lineno;
1019 static lineno_list_t **last_lineno_ptr = &first_lineno;
1020
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;
1025
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) ];
1044 } page_type;
1045
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 */
1055 } alloc_info_t;
1056
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 */
1071 } type_info_t;
1072
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 */
1079 0, /* # sizes */
1080 0, /* sizes not tied with dims */
1081 NULL, /* ptr to tag */
1082 0, /* bitfield */
1083 { /* type qualifiers */
1084 tq_Nil,
1085 tq_Nil,
1086 tq_Nil,
1087 tq_Nil,
1088 tq_Nil,
1089 tq_Nil,
1090 },
1091 { /* dimensions */
1092 0,
1093 0,
1094 0,
1095 0,
1096 0,
1097 0
1098 },
1099 { /* sizes */
1100 0,
1101 0,
1102 0,
1103 0,
1104 0,
1105 0,
1106 0,
1107 0,
1108 },
1109 };
1110
1111 /* Global hash table for the tags table and global table for file
1112 descriptors. */
1113
1114 static varray_t file_desc = INIT_VARRAY (efdr_t);
1115
1116 static struct hash_control *tag_hash;
1117
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. */
1121
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;
1126
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.
1133
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). */
1140
1141 static const bt_t map_coff_types[] = {
1142 bt_Nil, /* T_NULL */
1143 bt_Nil, /* T_ARG */
1144 bt_Char, /* T_CHAR */
1145 bt_Short, /* T_SHORT */
1146 bt_Int, /* T_INT */
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 */
1158 };
1159
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 */
1181 sc_Nil, /* 19 */
1182 sc_Nil, /* 20 */
1183 sc_Nil, /* 21 */
1184 sc_Nil, /* 22 */
1185 sc_Nil, /* 23 */
1186 sc_Nil, /* 24 */
1187 sc_Nil, /* 25 */
1188 sc_Nil, /* 26 */
1189 sc_Nil, /* 27 */
1190 sc_Nil, /* 28 */
1191 sc_Nil, /* 29 */
1192 sc_Nil, /* 30 */
1193 sc_Nil, /* 31 */
1194 sc_Nil, /* 32 */
1195 sc_Nil, /* 33 */
1196 sc_Nil, /* 34 */
1197 sc_Nil, /* 35 */
1198 sc_Nil, /* 36 */
1199 sc_Nil, /* 37 */
1200 sc_Nil, /* 38 */
1201 sc_Nil, /* 39 */
1202 sc_Nil, /* 40 */
1203 sc_Nil, /* 41 */
1204 sc_Nil, /* 42 */
1205 sc_Nil, /* 43 */
1206 sc_Nil, /* 44 */
1207 sc_Nil, /* 45 */
1208 sc_Nil, /* 46 */
1209 sc_Nil, /* 47 */
1210 sc_Nil, /* 48 */
1211 sc_Nil, /* 49 */
1212 sc_Nil, /* 50 */
1213 sc_Nil, /* 51 */
1214 sc_Nil, /* 52 */
1215 sc_Nil, /* 53 */
1216 sc_Nil, /* 54 */
1217 sc_Nil, /* 55 */
1218 sc_Nil, /* 56 */
1219 sc_Nil, /* 57 */
1220 sc_Nil, /* 58 */
1221 sc_Nil, /* 59 */
1222 sc_Nil, /* 60 */
1223 sc_Nil, /* 61 */
1224 sc_Nil, /* 62 */
1225 sc_Nil, /* 63 */
1226 sc_Nil, /* 64 */
1227 sc_Nil, /* 65 */
1228 sc_Nil, /* 66 */
1229 sc_Nil, /* 67 */
1230 sc_Nil, /* 68 */
1231 sc_Nil, /* 69 */
1232 sc_Nil, /* 70 */
1233 sc_Nil, /* 71 */
1234 sc_Nil, /* 72 */
1235 sc_Nil, /* 73 */
1236 sc_Nil, /* 74 */
1237 sc_Nil, /* 75 */
1238 sc_Nil, /* 76 */
1239 sc_Nil, /* 77 */
1240 sc_Nil, /* 78 */
1241 sc_Nil, /* 79 */
1242 sc_Nil, /* 80 */
1243 sc_Nil, /* 81 */
1244 sc_Nil, /* 82 */
1245 sc_Nil, /* 83 */
1246 sc_Nil, /* 84 */
1247 sc_Nil, /* 85 */
1248 sc_Nil, /* 86 */
1249 sc_Nil, /* 87 */
1250 sc_Nil, /* 88 */
1251 sc_Nil, /* 89 */
1252 sc_Nil, /* 90 */
1253 sc_Nil, /* 91 */
1254 sc_Nil, /* 92 */
1255 sc_Nil, /* 93 */
1256 sc_Nil, /* 94 */
1257 sc_Nil, /* 95 */
1258 sc_Nil, /* 96 */
1259 sc_Nil, /* 97 */
1260 sc_Nil, /* 98 */
1261 sc_Nil, /* 99 */
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 ??? */
1269 };
1270
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 */
1292 st_Nil, /* 19 */
1293 st_Nil, /* 20 */
1294 st_Nil, /* 21 */
1295 st_Nil, /* 22 */
1296 st_Nil, /* 23 */
1297 st_Nil, /* 24 */
1298 st_Nil, /* 25 */
1299 st_Nil, /* 26 */
1300 st_Nil, /* 27 */
1301 st_Nil, /* 28 */
1302 st_Nil, /* 29 */
1303 st_Nil, /* 30 */
1304 st_Nil, /* 31 */
1305 st_Nil, /* 32 */
1306 st_Nil, /* 33 */
1307 st_Nil, /* 34 */
1308 st_Nil, /* 35 */
1309 st_Nil, /* 36 */
1310 st_Nil, /* 37 */
1311 st_Nil, /* 38 */
1312 st_Nil, /* 39 */
1313 st_Nil, /* 40 */
1314 st_Nil, /* 41 */
1315 st_Nil, /* 42 */
1316 st_Nil, /* 43 */
1317 st_Nil, /* 44 */
1318 st_Nil, /* 45 */
1319 st_Nil, /* 46 */
1320 st_Nil, /* 47 */
1321 st_Nil, /* 48 */
1322 st_Nil, /* 49 */
1323 st_Nil, /* 50 */
1324 st_Nil, /* 51 */
1325 st_Nil, /* 52 */
1326 st_Nil, /* 53 */
1327 st_Nil, /* 54 */
1328 st_Nil, /* 55 */
1329 st_Nil, /* 56 */
1330 st_Nil, /* 57 */
1331 st_Nil, /* 58 */
1332 st_Nil, /* 59 */
1333 st_Nil, /* 60 */
1334 st_Nil, /* 61 */
1335 st_Nil, /* 62 */
1336 st_Nil, /* 63 */
1337 st_Nil, /* 64 */
1338 st_Nil, /* 65 */
1339 st_Nil, /* 66 */
1340 st_Nil, /* 67 */
1341 st_Nil, /* 68 */
1342 st_Nil, /* 69 */
1343 st_Nil, /* 70 */
1344 st_Nil, /* 71 */
1345 st_Nil, /* 72 */
1346 st_Nil, /* 73 */
1347 st_Nil, /* 74 */
1348 st_Nil, /* 75 */
1349 st_Nil, /* 76 */
1350 st_Nil, /* 77 */
1351 st_Nil, /* 78 */
1352 st_Nil, /* 79 */
1353 st_Nil, /* 80 */
1354 st_Nil, /* 81 */
1355 st_Nil, /* 82 */
1356 st_Nil, /* 83 */
1357 st_Nil, /* 84 */
1358 st_Nil, /* 85 */
1359 st_Nil, /* 86 */
1360 st_Nil, /* 87 */
1361 st_Nil, /* 88 */
1362 st_Nil, /* 89 */
1363 st_Nil, /* 90 */
1364 st_Nil, /* 91 */
1365 st_Nil, /* 92 */
1366 st_Nil, /* 93 */
1367 st_Nil, /* 94 */
1368 st_Nil, /* 95 */
1369 st_Nil, /* 96 */
1370 st_Nil, /* 97 */
1371 st_Nil, /* 98 */
1372 st_Nil, /* 99 */
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 ??? */
1380 };
1381
1382 /* Keep track of different sized allocation requests. */
1383 static alloc_info_t alloc_counts[(int) alloc_type_last];
1384 \f
1385 /* Record whether we have seen any debugging information. */
1386 int ecoff_debugging_seen = 0;
1387
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 */
1394 #ifdef ECOFF_DEBUG
1395 static int debug = 0; /* trace functions */
1396 #endif
1397 static int stabs_seen = 0; /* != 0 if stabs have been seen */
1398
1399 static int current_file_idx;
1400 static const char *current_stabs_filename;
1401
1402 /* Pseudo symbol to use when putting stabs into the symbol table. */
1403 #ifndef STABS_SYMBOL
1404 #define STABS_SYMBOL "@stabs"
1405 #endif
1406
1407 static char stabs_symbol[] = STABS_SYMBOL;
1408 \f
1409 /* Prototypes for functions defined in this file. */
1410
1411 static void add_varray_page (varray_t *vp);
1412 static symint_t add_string (varray_t *vp,
1413 struct hash_control *hash_tbl,
1414 const char *str,
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,
1419 symint_t indx);
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,
1423 hash_state_t state,
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);
1429 #ifdef ECOFF_DEBUG
1430 static char *sc_to_string (sc_t storage_class);
1431 static char *st_to_string (st_t symbol_type);
1432 #endif
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,
1453 varray_t *vp);
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);
1474 \f
1475 /* This function should be called when the assembler starts up. */
1476
1477 void
1478 ecoff_read_begin_hook (void)
1479 {
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;
1486 }
1487
1488 /* This function should be called when a symbol is created. */
1489
1490 void
1491 ecoff_symbol_new_hook (symbolS *symbolP)
1492 {
1493 OBJ_SYMFIELD_TYPE *obj;
1494
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
1499 wrong. */
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;
1507 }
1508
1509 void
1510 ecoff_symbol_clone_hook (symbolS *newsymP, symbolS *orgsymP)
1511 {
1512 OBJ_SYMFIELD_TYPE *n, *o;
1513
1514 n = symbol_get_obj (newsymP);
1515 o = symbol_get_obj (orgsymP);
1516 memcpy (n, o, sizeof *n);
1517 }
1518 \f
1519 /* Add a page to a varray object. */
1520
1521 static void
1522 add_varray_page (varray_t *vp /* varray to add page to */)
1523 {
1524 vlinks_t *new_links = allocate_vlinks ();
1525
1526 #ifdef MALLOC_CHECK
1527 if (vp->object_size > 1)
1528 new_links->datum = (page_type *) xcalloc (1, vp->object_size);
1529 else
1530 #endif
1531 new_links->datum = allocate_page ();
1532
1533 alloc_counts[(int) alloc_type_varray].total_alloc++;
1534 alloc_counts[(int) alloc_type_varray].total_pages++;
1535
1536 new_links->start_index = vp->num_allocated;
1537 vp->objects_last_page = 0;
1538
1539 if (vp->first == (vlinks_t *) NULL) /* first allocation? */
1540 vp->first = vp->last = new_links;
1541 else
1542 { /* 2nd or greater allocation */
1543 new_links->prev = vp->last;
1544 vp->last->next = new_links;
1545 vp->last = new_links;
1546 }
1547 }
1548 \f
1549 /* Add a string (and null pad) to one of the string tables. */
1550
1551 static symint_t
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 */)
1556 {
1557 register unsigned long len = strlen (str);
1558 register shash_t *hash_ptr;
1559
1560 if (len >= PAGE_USIZE)
1561 as_fatal (_("string too big (%lu bytes)"), len);
1562
1563 hash_ptr = (shash_t *) hash_find (hash_tbl, str);
1564 if (hash_ptr == (shash_t *) NULL)
1565 {
1566 register const char *err;
1567
1568 if (vp->objects_last_page + len >= PAGE_USIZE)
1569 {
1570 vp->num_allocated =
1571 ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE;
1572 add_varray_page (vp);
1573 }
1574
1575 hash_ptr = allocate_shash ();
1576 hash_ptr->indx = vp->num_allocated;
1577
1578 hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page];
1579
1580 vp->objects_last_page += len + 1;
1581 vp->num_allocated += len + 1;
1582
1583 strcpy (hash_ptr->string, str);
1584
1585 err = hash_insert (hash_tbl, str, (char *) hash_ptr);
1586 if (err)
1587 as_fatal (_("inserting \"%s\" into string hash table: %s"),
1588 str, err);
1589 }
1590
1591 if (ret_hash != (shash_t **) NULL)
1592 *ret_hash = hash_ptr;
1593
1594 return hash_ptr->indx;
1595 }
1596 \f
1597 /* Add debugging information for a symbol. */
1598
1599 static localsym_t *
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 */)
1607 {
1608 localsym_t *psym;
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;
1616
1617 if (cur_file_ptr == (efdr_t *) NULL)
1618 as_fatal (_("no current file pointer"));
1619
1620 vp = &cur_file_ptr->symbols;
1621
1622 if (vp->objects_last_page == vp->objects_per_page)
1623 add_varray_page (vp);
1624
1625 psym = &vp->last->datum->sym[vp->objects_last_page++];
1626
1627 if (str == (const char *) NULL && sym_value != (symbolS *) NULL)
1628 psym->name = S_GET_NAME (sym_value);
1629 else
1630 psym->name = str;
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;
1646
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)
1653 ? 0
1654 : add_string (&cur_file_ptr->strings,
1655 cur_file_ptr->str_hash,
1656 str,
1657 &hash_ptr));
1658
1659 ++vp->num_allocated;
1660
1661 if (ECOFF_IS_STAB (&psym->ecoff_sym.asym))
1662 return psym;
1663
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;
1670
1671 /* push or pop a scope if appropriate. */
1672 switch (type)
1673 {
1674 default:
1675 break;
1676
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;
1686
1687 if (type != st_File)
1688 scope_delta = 1;
1689
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)
1694 {
1695 ptag_head = allocate_thead ();
1696 ptag_head->first_tag = 0;
1697 ptag_head->prev = cur_tag_head;
1698 cur_tag_head = ptag_head;
1699 }
1700 break;
1701
1702 case st_End:
1703 pscope = cur_file_ptr->cur_scope;
1704 if (pscope == (scope_t *) NULL)
1705 as_fatal (_("too many st_End's"));
1706 else
1707 {
1708 st_t begin_type = (st_t) pscope->lsym->ecoff_sym.asym.st;
1709
1710 psym->begin_ptr = pscope->lsym;
1711
1712 if (begin_type != st_File)
1713 scope_delta = -1;
1714
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)
1718 {
1719 ptag_head = cur_tag_head;
1720 cur_tag_head = ptag_head->prev;
1721
1722 for (ptag = ptag_head->first_tag;
1723 ptag != (tag_t *) NULL;
1724 ptag = ptag_next)
1725 {
1726 if (ptag->forward_ref != (forward_t *) NULL)
1727 add_unknown_tag (ptag);
1728
1729 ptag_next = ptag->same_block;
1730 ptag->hash_ptr->tag_ptr = ptag->same_name;
1731 free_tag (ptag);
1732 }
1733
1734 free_thead (ptag_head);
1735 }
1736
1737 cur_file_ptr->cur_scope = pscope->prev;
1738
1739 /* block begin gets next sym #. This is set when we know
1740 the symbol index value. */
1741
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)
1747 {
1748 symint_t ty;
1749 varray_t *svp = &cur_file_ptr->aux_syms;
1750
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,
1755 hash_no,
1756 &cur_file_ptr->thash_head[0]);
1757 (void) ty;
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)
1761 * {
1762 * last_func_sym_value->ifd = cur_file_ptr->file_index;
1763 * last_func_sym_value->index = ty;
1764 * }
1765 */
1766 }
1767
1768 free_scope (pscope);
1769 }
1770 }
1771
1772 cur_file_ptr->nested_scopes += scope_delta;
1773
1774 #ifdef ECOFF_DEBUG
1775 if (debug && type != st_File
1776 && (debug > 2 || type == st_Block || type == st_End
1777 || type == st_Proc || type == st_StaticProc))
1778 {
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);
1782
1783 fprintf (stderr,
1784 "\tlsym\tv= %10ld, depth= %2d, sc= %-12s",
1785 value, depth, sc_str);
1786
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);
1790 else
1791 {
1792 unsigned long len = strlen (st_str);
1793 fprintf (stderr, " st= %.*s\n", len - 1, st_str);
1794 }
1795 }
1796 #endif
1797
1798 return psym;
1799 }
1800 \f
1801 /* Add an auxiliary symbol (passing a symint). This is actually used
1802 for integral aux types, not just symints. */
1803
1804 static symint_t
1805 add_aux_sym_symint (symint_t aux_word /* auxiliary information word */)
1806 {
1807 register varray_t *vp;
1808 register aux_t *aux_ptr;
1809
1810 if (cur_file_ptr == (efdr_t *) NULL)
1811 as_fatal (_("no current file pointer"));
1812
1813 vp = &cur_file_ptr->aux_syms;
1814
1815 if (vp->objects_last_page == vp->objects_per_page)
1816 add_varray_page (vp);
1817
1818 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1819 aux_ptr->type = aux_isym;
1820 aux_ptr->data.isym = aux_word;
1821
1822 return vp->num_allocated++;
1823 }
1824
1825 /* Add an auxiliary symbol (passing a file/symbol index combo). */
1826
1827 static symint_t
1828 add_aux_sym_rndx (int file_index, symint_t sym_index)
1829 {
1830 register varray_t *vp;
1831 register aux_t *aux_ptr;
1832
1833 if (cur_file_ptr == (efdr_t *) NULL)
1834 as_fatal (_("no current file pointer"));
1835
1836 vp = &cur_file_ptr->aux_syms;
1837
1838 if (vp->objects_last_page == vp->objects_per_page)
1839 add_varray_page (vp);
1840
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;
1845
1846 return vp->num_allocated++;
1847 }
1848 \f
1849 /* Add an auxiliary symbol (passing the basic type and possibly
1850 type qualifiers). */
1851
1852 static symint_t
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 */)
1856 {
1857 register varray_t *vp;
1858 register aux_t *aux_ptr;
1859 static AUXU init_aux;
1860 symint_t ret;
1861 int i;
1862 AUXU aux;
1863
1864 if (cur_file_ptr == (efdr_t *) NULL)
1865 as_fatal (_("no current file pointer"));
1866
1867 vp = &cur_file_ptr->aux_syms;
1868
1869 aux = init_aux;
1870 aux.ti.bt = (int) t->basic_type;
1871 aux.ti.continued = 0;
1872 aux.ti.fBitfield = t->bitfield;
1873
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];
1880
1881 /* For anything that adds additional information, we must not hash,
1882 so check here, and reset our state. */
1883
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
1894 || t->bitfield
1895 || t->num_dims > 0))
1896 state = hash_no;
1897
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. */
1902
1903 if (state != hash_no)
1904 {
1905 register thash_t *hash_ptr;
1906 register symint_t hi;
1907
1908 hi = aux.isym & ((1 << HASHBITS) - 1);
1909 hi %= THASH_SIZE;
1910
1911 for (hash_ptr = hash_tbl[hi];
1912 hash_ptr != (thash_t *)0;
1913 hash_ptr = hash_ptr->next)
1914 {
1915 if (aux.isym == hash_ptr->type.isym)
1916 break;
1917 }
1918
1919 if (hash_ptr != (thash_t *) NULL && state == hash_yes)
1920 return hash_ptr->indx;
1921
1922 if (hash_ptr == (thash_t *) NULL)
1923 {
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;
1929 }
1930 }
1931
1932 /* Everything is set up, add the aux symbol. */
1933 if (vp->objects_last_page == vp->objects_per_page)
1934 add_varray_page (vp);
1935
1936 aux_ptr = &vp->last->datum->aux[vp->objects_last_page++];
1937 aux_ptr->type = aux_tir;
1938 aux_ptr->data = aux;
1939
1940 ret = vp->num_allocated++;
1941
1942 /* Add bitfield length if it exists.
1943
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.)
1947
1948 Also note: We use the last size given since gcc may emit 2
1949 for an enum bitfield. */
1950
1951 if (t->bitfield)
1952 (void) add_aux_sym_symint ((symint_t) t->sizes[t->num_sizes - 1]);
1953
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. */
1957
1958 if (t->basic_type == bt_Struct
1959 || t->basic_type == bt_Union
1960 || t->basic_type == bt_Enum)
1961 {
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 ();
1965
1966 if (sym != (localsym_t *) NULL)
1967 {
1968 forward_ref->next = sym->forward_ref;
1969 sym->forward_ref = forward_ref;
1970 }
1971 else
1972 {
1973 forward_ref->next = t->tag_ptr->forward_ref;
1974 t->tag_ptr->forward_ref = forward_ref;
1975 }
1976
1977 (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil);
1978 forward_ref->index_ptr
1979 = &vp->last->datum->aux[vp->objects_last_page - 1];
1980
1981 (void) add_aux_sym_symint (file_index);
1982 forward_ref->ifd_ptr
1983 = &vp->last->datum->aux[vp->objects_last_page - 1];
1984 }
1985
1986 /* Add information about array bounds if they exist. */
1987 for (i = 0; i < t->num_dims; i++)
1988 {
1989 (void) add_aux_sym_rndx (ST_RFDESCAPE,
1990 cur_file_ptr->int_type);
1991
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 */
1996 ? 0
1997 : (t->sizes[i] * 8) / t->dimensions[i]);
1998 };
1999
2000 /* NOTE: Mips documentation claims that the bitfield width goes here.
2001 But it needs to be emitted earlier. */
2002
2003 return ret;
2004 }
2005 \f
2006 /* Add a tag to the tag table (unless it already exists). */
2007
2008 static tag_t *
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 */)
2012 {
2013 shash_t *hash_ptr;
2014 const char *err;
2015 tag_t *tag_ptr;
2016
2017 if (cur_file_ptr == (efdr_t *) NULL)
2018 as_fatal (_("no current file pointer"));
2019
2020 hash_ptr = (shash_t *) hash_find (tag_hash, tag);
2021
2022 if (hash_ptr != (shash_t *) NULL
2023 && hash_ptr->tag_ptr != (tag_t *) NULL)
2024 {
2025 tag_ptr = hash_ptr->tag_ptr;
2026 if (sym != (localsym_t *) NULL)
2027 {
2028 tag_ptr->basic_type = basic_type;
2029 tag_ptr->ifd = cur_file_ptr->file_index;
2030 tag_ptr->sym = sym;
2031 }
2032 return tag_ptr;
2033 }
2034
2035 if (hash_ptr == (shash_t *) NULL)
2036 {
2037 char *perm;
2038
2039 perm = xstrdup (tag);
2040 hash_ptr = allocate_shash ();
2041 err = hash_insert (tag_hash, perm, (char *) hash_ptr);
2042 if (err)
2043 as_fatal (_("inserting \"%s\" into tag hash table: %s"),
2044 tag, err);
2045 hash_ptr->string = perm;
2046 }
2047
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;
2053 tag_ptr->sym = sym;
2054 tag_ptr->ifd = ((sym == (localsym_t *) NULL)
2055 ? (symint_t) -1
2056 : cur_file_ptr->file_index);
2057 tag_ptr->same_block = cur_tag_head->first_tag;
2058
2059 cur_tag_head->first_tag = tag_ptr;
2060 hash_ptr->tag_ptr = tag_ptr;
2061
2062 return tag_ptr;
2063 }
2064 \f
2065 /* Add an unknown {struct, union, enum} tag. */
2066
2067 static void
2068 add_unknown_tag (tag_t *ptag /* pointer to tag information */)
2069 {
2070 shash_t *hash_ptr = ptag->hash_ptr;
2071 char *name = hash_ptr->string;
2072 localsym_t *sym;
2073 forward_t **pf;
2074
2075 #ifdef ECOFF_DEBUG
2076 if (debug > 1)
2077 {
2078 char *agg_type = "{unknown aggregate type}";
2079 switch (ptag->basic_type)
2080 {
2081 case bt_Struct: agg_type = "struct"; break;
2082 case bt_Union: agg_type = "union"; break;
2083 case bt_Enum: agg_type = "enum"; break;
2084 default: break;
2085 }
2086
2087 fprintf (stderr, "unknown %s %.*s found\n", agg_type,
2088 hash_ptr->len, name_start);
2089 }
2090 #endif
2091
2092 sym = add_ecoff_symbol (name,
2093 st_Block,
2094 sc_Info,
2095 (symbolS *) NULL,
2096 (bfd_vma) 0,
2097 (symint_t) 0,
2098 (symint_t) 0);
2099
2100 (void) add_ecoff_symbol (name,
2101 st_End,
2102 sc_Info,
2103 (symbolS *) NULL,
2104 (bfd_vma) 0,
2105 (symint_t) 0,
2106 (symint_t) 0);
2107
2108 for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next)
2109 ;
2110 *pf = ptag->forward_ref;
2111 }
2112 \f
2113 /* Add a procedure to the current file's list of procedures, and record
2114 this is the current procedure. */
2115
2116 static void
2117 add_procedure (char *func /* func name */)
2118 {
2119 register varray_t *vp;
2120 register proc_t *new_proc_ptr;
2121 symbolS *sym;
2122
2123 #ifdef ECOFF_DEBUG
2124 if (debug)
2125 fputc ('\n', stderr);
2126 #endif
2127
2128 if (cur_file_ptr == (efdr_t *) NULL)
2129 as_fatal (_("no current file pointer"));
2130
2131 vp = &cur_file_ptr->procs;
2132
2133 if (vp->objects_last_page == vp->objects_per_page)
2134 add_varray_page (vp);
2135
2136 cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++];
2137
2138 if (first_proc_ptr == (proc_t *) NULL)
2139 first_proc_ptr = new_proc_ptr;
2140
2141 vp->num_allocated++;
2142
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;
2147
2148 /* Set the BSF_FUNCTION flag for the symbol. */
2149 sym = symbol_find_or_make (func);
2150 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
2151
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,
2155 (symint_t) 0);
2156
2157 ++proc_cnt;
2158
2159 /* Fill in the linenos preceding the .ent, if any. */
2160 if (noproc_lineno != (lineno_list_t *) NULL)
2161 {
2162 lineno_list_t *l;
2163
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)
2168 {
2169 last_lineno = *last_lineno_ptr;
2170 last_lineno_ptr = &last_lineno->next;
2171 }
2172 noproc_lineno = (lineno_list_t *) NULL;
2173 }
2174 }
2175
2176 symbolS *
2177 ecoff_get_cur_proc_sym (void)
2178 {
2179 return (cur_proc_ptr ? cur_proc_ptr->sym->as_sym : NULL);
2180 }
2181 \f
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. */
2185
2186 static void
2187 add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
2188 {
2189 register int first_ch;
2190 register efdr_t *fil_ptr;
2191
2192 #ifdef ECOFF_DEBUG
2193 if (debug)
2194 fprintf (stderr, "\tfile\t%.*s\n", len, file_start);
2195 #endif
2196
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)
2200 {
2201 char *file;
2202
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;
2207
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
2212 provided. */
2213 if (! symbol_table_frozen && debug_type == DEBUG_UNSPECIFIED)
2214 debug_type = DEBUG_ECOFF;
2215 }
2216 else if (debug_type == DEBUG_UNSPECIFIED)
2217 debug_type = DEBUG_NONE;
2218
2219 #ifndef NO_LISTING
2220 if (listing)
2221 listing_source_file (file_name);
2222 #endif
2223
2224 current_stabs_filename = file_name;
2225
2226 /* If we're creating stabs, then we don't actually make a new FDR.
2227 Instead, we just create a stabs symbol. */
2228 if (stabs_seen)
2229 {
2230 (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil,
2231 symbol_new ("L0\001", now_seg,
2232 (valueT) frag_now_fix (),
2233 frag_now),
2234 (bfd_vma) 0, 0, ECOFF_MARK_STAB (N_SOL));
2235 return;
2236 }
2237
2238 first_ch = *file_name;
2239
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. */
2252
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)
2257 {
2258 if (first_ch == fil_ptr->name[0]
2259 && filename_cmp (file_name, fil_ptr->name) == 0
2260 && fil_ptr->fdr.fMerge)
2261 {
2262 cur_file_ptr = fil_ptr;
2263 if (! fake)
2264 cur_file_ptr->fake = 0;
2265 break;
2266 }
2267 }
2268
2269 /* If this is a new file, create it. */
2270 if (fil_ptr == (efdr_t *) NULL)
2271 {
2272 if (file_desc.objects_last_page == file_desc.objects_per_page)
2273 add_varray_page (&file_desc);
2274
2275 fil_ptr = cur_file_ptr =
2276 &file_desc.last->datum->file[file_desc.objects_last_page++];
2277 *fil_ptr = init_file;
2278
2279 fil_ptr->file_index = current_file_idx++;
2280 ++file_desc.num_allocated;
2281
2282 fil_ptr->fake = fake;
2283
2284 /* Allocate the string hash table. */
2285 fil_ptr->str_hash = hash_new ();
2286
2287 /* Make sure 0 byte in string table is null */
2288 add_string (&fil_ptr->strings,
2289 fil_ptr->str_hash,
2290 "",
2291 (shash_t **)0);
2292
2293 if (strlen (file_name) > PAGE_USIZE - 2)
2294 as_fatal (_("filename goes over one page boundary"));
2295
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];
2303
2304 /* Update the linked list of file descriptors. */
2305 *last_file_ptr = fil_ptr;
2306 last_file_ptr = &fil_ptr->next_file;
2307
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,
2311 hash_yes,
2312 &cur_file_ptr->thash_head[0]);
2313
2314 fil_ptr->int_type = add_aux_sym_tir (&int_type_info,
2315 hash_yes,
2316 &cur_file_ptr->thash_head[0]);
2317 }
2318 }
2319
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. */
2323
2324 void
2325 ecoff_new_file (const char *name, int appfile ATTRIBUTE_UNUSED)
2326 {
2327 if (cur_file_ptr != NULL && filename_cmp (cur_file_ptr->name, name) == 0)
2328 return;
2329 add_file (name, 0, 0);
2330
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;
2335 }
2336 \f
2337 #ifdef ECOFF_DEBUG
2338
2339 /* Convert storage class to string. */
2340
2341 static char *
2342 sc_to_string (storage_class)
2343 sc_t storage_class;
2344 {
2345 switch (storage_class)
2346 {
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,";
2371 }
2372
2373 return "???,";
2374 }
2375
2376 #endif /* DEBUG */
2377 \f
2378 #ifdef ECOFF_DEBUG
2379
2380 /* Convert symbol type to string. */
2381
2382 static char *
2383 st_to_string (symbol_type)
2384 st_t symbol_type;
2385 {
2386 switch (symbol_type)
2387 {
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,";
2409 }
2410
2411 return "???,";
2412 }
2413
2414 #endif /* DEBUG */
2415 \f
2416 /* Parse .begin directives which have a label as the first argument
2417 which gives the location of the start of the block. */
2418
2419 void
2420 ecoff_directive_begin (int ignore ATTRIBUTE_UNUSED)
2421 {
2422 char *name;
2423 char name_end;
2424
2425 if (cur_file_ptr == (efdr_t *) NULL)
2426 {
2427 as_warn (_(".begin directive without a preceding .file directive"));
2428 demand_empty_rest_of_line ();
2429 return;
2430 }
2431
2432 if (cur_proc_ptr == (proc_t *) NULL)
2433 {
2434 as_warn (_(".begin directive without a preceding .ent directive"));
2435 demand_empty_rest_of_line ();
2436 return;
2437 }
2438
2439 name = input_line_pointer;
2440 name_end = get_symbol_end ();
2441
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);
2445
2446 *input_line_pointer = name_end;
2447
2448 /* The line number follows, but we don't use it. */
2449 (void) get_absolute_expression ();
2450 demand_empty_rest_of_line ();
2451 }
2452 \f
2453 /* Parse .bend directives which have a label as the first argument
2454 which gives the location of the end of the block. */
2455
2456 void
2457 ecoff_directive_bend (int ignore ATTRIBUTE_UNUSED)
2458 {
2459 char *name;
2460 char name_end;
2461 symbolS *endsym;
2462
2463 if (cur_file_ptr == (efdr_t *) NULL)
2464 {
2465 as_warn (_(".bend directive without a preceding .file directive"));
2466 demand_empty_rest_of_line ();
2467 return;
2468 }
2469
2470 if (cur_proc_ptr == (proc_t *) NULL)
2471 {
2472 as_warn (_(".bend directive without a preceding .ent directive"));
2473 demand_empty_rest_of_line ();
2474 return;
2475 }
2476
2477 name = input_line_pointer;
2478 name_end = get_symbol_end ();
2479
2480 /* The value is the distance between the .bend directive and the
2481 corresponding symbol. We fill in the offset when we write out
2482 the symbol. */
2483 endsym = symbol_find (name);
2484 if (endsym == (symbolS *) NULL)
2485 as_warn (_(".bend directive names unknown symbol"));
2486 else
2487 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym,
2488 (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
2489
2490 *input_line_pointer = name_end;
2491
2492 /* The line number follows, but we don't use it. */
2493 (void) get_absolute_expression ();
2494 demand_empty_rest_of_line ();
2495 }
2496 \f
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;
2511
2512 /* Handle a .def directive: start defining a symbol. */
2513
2514 void
2515 ecoff_directive_def (int ignore ATTRIBUTE_UNUSED)
2516 {
2517 char *name;
2518 char name_end;
2519
2520 ecoff_debugging_seen = 1;
2521
2522 SKIP_WHITESPACE ();
2523
2524 name = input_line_pointer;
2525 name_end = get_symbol_end ();
2526
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"));
2531 else
2532 {
2533 if (coff_sym_name != (char *) NULL)
2534 free (coff_sym_name);
2535 if (coff_tag != (char *) NULL)
2536 free (coff_tag);
2537
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;
2544 coff_value = 0;
2545 coff_sym_value = (symbolS *) NULL;
2546 coff_sym_addend = 0;
2547 }
2548
2549 *input_line_pointer = name_end;
2550
2551 demand_empty_rest_of_line ();
2552 }
2553
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. */
2558
2559 void
2560 ecoff_directive_dim (int ignore ATTRIBUTE_UNUSED)
2561 {
2562 int dimens[N_TQ];
2563 int i;
2564
2565 if (coff_sym_name == (char *) NULL)
2566 {
2567 as_warn (_(".dim pseudo-op used outside of .def/.endef; ignored"));
2568 demand_empty_rest_of_line ();
2569 return;
2570 }
2571
2572 for (i = 0; i < N_TQ; i++)
2573 {
2574 SKIP_WHITESPACE ();
2575 dimens[i] = get_absolute_expression ();
2576 if (*input_line_pointer == ',')
2577 ++input_line_pointer;
2578 else
2579 {
2580 if (*input_line_pointer != '\n'
2581 && *input_line_pointer != ';')
2582 as_warn (_("badly formed .dim directive"));
2583 break;
2584 }
2585 }
2586
2587 if (i == N_TQ)
2588 --i;
2589
2590 /* The dimensions are stored away in reverse order. */
2591 for (; i >= 0; i--)
2592 {
2593 if (coff_type.num_dims >= N_TQ)
2594 {
2595 as_warn (_("too many .dim entries"));
2596 break;
2597 }
2598 coff_type.dimensions[coff_type.num_dims] = dimens[i];
2599 ++coff_type.num_dims;
2600 }
2601
2602 demand_empty_rest_of_line ();
2603 }
2604
2605 /* Handle a .scl directive, which sets the COFF storage class of the
2606 symbol. */
2607
2608 void
2609 ecoff_directive_scl (int ignore ATTRIBUTE_UNUSED)
2610 {
2611 long val;
2612
2613 if (coff_sym_name == (char *) NULL)
2614 {
2615 as_warn (_(".scl pseudo-op used outside of .def/.endef; ignored"));
2616 demand_empty_rest_of_line ();
2617 return;
2618 }
2619
2620 val = get_absolute_expression ();
2621
2622 coff_symbol_typ = map_coff_sym_type[val];
2623 coff_storage_class = map_coff_storage[val];
2624
2625 demand_empty_rest_of_line ();
2626 }
2627
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. */
2631
2632 void
2633 ecoff_directive_size (int ignore ATTRIBUTE_UNUSED)
2634 {
2635 int sizes[N_TQ];
2636 int i;
2637
2638 if (coff_sym_name == (char *) NULL)
2639 {
2640 as_warn (_(".size pseudo-op used outside of .def/.endef; ignored"));
2641 demand_empty_rest_of_line ();
2642 return;
2643 }
2644
2645 for (i = 0; i < N_TQ; i++)
2646 {
2647 SKIP_WHITESPACE ();
2648 sizes[i] = get_absolute_expression ();
2649 if (*input_line_pointer == ',')
2650 ++input_line_pointer;
2651 else
2652 {
2653 if (*input_line_pointer != '\n'
2654 && *input_line_pointer != ';')
2655 as_warn (_("badly formed .size directive"));
2656 break;
2657 }
2658 }
2659
2660 if (i == N_TQ)
2661 --i;
2662
2663 /* The sizes are stored away in reverse order. */
2664 for (; i >= 0; i--)
2665 {
2666 if (coff_type.num_sizes >= N_TQ)
2667 {
2668 as_warn (_("too many .size entries"));
2669 break;
2670 }
2671 coff_type.sizes[coff_type.num_sizes] = sizes[i];
2672 ++coff_type.num_sizes;
2673 }
2674
2675 demand_empty_rest_of_line ();
2676 }
2677
2678 /* Handle the .type directive, which gives the COFF type of the
2679 symbol. */
2680
2681 void
2682 ecoff_directive_type (int ignore ATTRIBUTE_UNUSED)
2683 {
2684 long val;
2685 tq_t *tq_ptr;
2686 tq_t *tq_shft;
2687
2688 if (coff_sym_name == (char *) NULL)
2689 {
2690 as_warn (_(".type pseudo-op used outside of .def/.endef; ignored"));
2691 demand_empty_rest_of_line ();
2692 return;
2693 }
2694
2695 val = get_absolute_expression ();
2696
2697 coff_type.orig_type = BTYPE (val);
2698 coff_type.basic_type = map_coff_types[coff_type.orig_type];
2699
2700 tq_ptr = &coff_type.type_qualifiers[N_TQ];
2701 while (val & ~N_BTMASK)
2702 {
2703 if (tq_ptr == &coff_type.type_qualifiers[0])
2704 {
2705 /* FIXME: We could handle this by setting the continued bit.
2706 There would still be a limit: the .type argument can not
2707 be infinite. */
2708 as_warn (_("the type of %s is too complex; it will be simplified"),
2709 coff_sym_name);
2710 break;
2711 }
2712 if (ISPTR (val))
2713 *--tq_ptr = tq_Ptr;
2714 else if (ISFCN (val))
2715 *--tq_ptr = tq_Proc;
2716 else if (ISARY (val))
2717 *--tq_ptr = tq_Array;
2718 else
2719 as_fatal (_("Unrecognized .type argument"));
2720
2721 val = DECREF (val);
2722 }
2723
2724 tq_shft = &coff_type.type_qualifiers[0];
2725 while (tq_ptr != &coff_type.type_qualifiers[N_TQ])
2726 *tq_shft++ = *tq_ptr++;
2727
2728 if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc)
2729 {
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
2735 at this point. */
2736 coff_is_function = 1;
2737 tq_shft[-1] = tq_Nil;
2738 }
2739
2740 while (tq_shft != &coff_type.type_qualifiers[N_TQ])
2741 *tq_shft++ = tq_Nil;
2742
2743 demand_empty_rest_of_line ();
2744 }
2745
2746 /* Handle the .tag directive, which gives the name of a structure,
2747 union or enum. */
2748
2749 void
2750 ecoff_directive_tag (int ignore ATTRIBUTE_UNUSED)
2751 {
2752 char *name;
2753 char name_end;
2754
2755 if (coff_sym_name == (char *) NULL)
2756 {
2757 as_warn (_(".tag pseudo-op used outside of .def/.endef; ignored"));
2758 demand_empty_rest_of_line ();
2759 return;
2760 }
2761
2762 name = input_line_pointer;
2763 name_end = get_symbol_end ();
2764
2765 coff_tag = xstrdup (name);
2766
2767 *input_line_pointer = name_end;
2768
2769 demand_empty_rest_of_line ();
2770 }
2771
2772 /* Handle the .val directive, which gives the value of the symbol. It
2773 may be the name of a static or global symbol. */
2774
2775 void
2776 ecoff_directive_val (int ignore ATTRIBUTE_UNUSED)
2777 {
2778 expressionS exp;
2779
2780 if (coff_sym_name == (char *) NULL)
2781 {
2782 as_warn (_(".val pseudo-op used outside of .def/.endef; ignored"));
2783 demand_empty_rest_of_line ();
2784 return;
2785 }
2786
2787 expression (&exp);
2788 if (exp.X_op != O_constant && exp.X_op != O_symbol)
2789 {
2790 as_bad (_(".val expression is too complex"));
2791 demand_empty_rest_of_line ();
2792 return;
2793 }
2794
2795 if (exp.X_op == O_constant)
2796 coff_value = exp.X_add_number;
2797 else
2798 {
2799 coff_sym_value = exp.X_add_symbol;
2800 coff_sym_addend = exp.X_add_number;
2801 }
2802
2803 demand_empty_rest_of_line ();
2804 }
2805
2806 /* Handle the .endef directive, which terminates processing of COFF
2807 debugging information for a symbol. */
2808
2809 void
2810 ecoff_directive_endef (int ignore ATTRIBUTE_UNUSED)
2811 {
2812 char *name;
2813 symint_t indx;
2814 localsym_t *sym;
2815
2816 demand_empty_rest_of_line ();
2817
2818 if (coff_sym_name == (char *) NULL)
2819 {
2820 as_warn (_(".endef pseudo-op used before .def; ignored"));
2821 return;
2822 }
2823
2824 name = coff_sym_name;
2825 coff_sym_name = (char *) NULL;
2826
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)
2832 {
2833 coff_symbol_typ = st_Nil;
2834 coff_storage_class = sc_Nil;
2835 }
2836
2837 coff_type.extra_sizes = coff_tag != (char *) NULL;
2838 if (coff_type.num_dims > 0)
2839 {
2840 int diff = coff_type.num_dims - coff_type.num_sizes;
2841 int i = coff_type.num_dims - 1;
2842 int j;
2843
2844 if (coff_type.num_sizes != 1 || diff < 0)
2845 {
2846 as_warn (_("bad COFF debugging information"));
2847 return;
2848 }
2849
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;
2854 if (diff)
2855 {
2856 j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1;
2857 while (j >= 0)
2858 {
2859 coff_type.sizes[j] = (((j - diff) >= 0)
2860 ? coff_type.sizes[j - diff]
2861 : 0);
2862 j--;
2863 }
2864
2865 coff_type.num_sizes = i + 1;
2866 for (i--; i >= 0; i--)
2867 coff_type.sizes[i] = (coff_type.dimensions[i + 1] == 0
2868 ? 0
2869 : (coff_type.sizes[i + 1]
2870 / coff_type.dimensions[i + 1]));
2871 }
2872 }
2873 else if (coff_symbol_typ == st_Member
2874 && coff_type.num_sizes - coff_type.extra_sizes == 1)
2875 {
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;
2879 }
2880
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)
2884 indx = 0;
2885 else if (coff_inside_enumeration)
2886 indx = cur_file_ptr->void_type;
2887 else
2888 {
2889 if (coff_type.basic_type == bt_Struct
2890 || coff_type.basic_type == bt_Union
2891 || coff_type.basic_type == bt_Enum)
2892 {
2893 if (coff_tag == (char *) NULL)
2894 {
2895 as_warn (_("no tag specified for %s"), name);
2896 return;
2897 }
2898
2899 coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL,
2900 coff_type.basic_type);
2901 }
2902
2903 if (coff_is_function)
2904 {
2905 last_func_type_info = coff_type;
2906 last_func_sym_value = coff_sym_value;
2907 return;
2908 }
2909
2910 indx = add_aux_sym_tir (&coff_type,
2911 hash_yes,
2912 &cur_file_ptr->thash_head[0]);
2913 }
2914
2915 /* Do any last minute adjustments that are necessary. */
2916 switch (coff_symbol_typ)
2917 {
2918 default:
2919 break;
2920
2921 /* For the beginning of structs, unions, and enumerations, the
2922 size info needs to be passed in the value field. */
2923 case st_Block:
2924 if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes
2925 != 1)
2926 {
2927 as_warn (_("bad COFF debugging information"));
2928 return;
2929 }
2930 else
2931 coff_value = coff_type.sizes[0];
2932
2933 coff_inside_enumeration = (coff_type.orig_type == T_ENUM);
2934 break;
2935
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. */
2939 case st_End:
2940 free (name);
2941 name = (char *) NULL;
2942 coff_value = 0;
2943 coff_inside_enumeration = 0;
2944 break;
2945
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. */
2951 case st_Member:
2952 if (! coff_type.bitfield && ! coff_inside_enumeration)
2953 coff_value *= 8;
2954
2955 break;
2956 }
2957
2958 /* Add the symbol. */
2959 sym = add_ecoff_symbol (name,
2960 coff_symbol_typ,
2961 coff_storage_class,
2962 coff_sym_value,
2963 coff_sym_addend,
2964 (symint_t) coff_value,
2965 indx);
2966
2967 /* deal with struct, union, and enum tags. */
2968 if (coff_symbol_typ == st_Block)
2969 {
2970 /* Create or update the tag information. */
2971 tag_t *tag_ptr = get_tag (name,
2972 sym,
2973 coff_type.basic_type);
2974 forward_t **pf;
2975
2976 /* Remember any forward references. */
2977 for (pf = &sym->forward_ref;
2978 *pf != (forward_t *) NULL;
2979 pf = &(*pf)->next)
2980 ;
2981 *pf = tag_ptr->forward_ref;
2982 tag_ptr->forward_ref = (forward_t *) NULL;
2983 }
2984 }
2985 \f
2986 /* Parse .end directives. */
2987
2988 void
2989 ecoff_directive_end (int ignore ATTRIBUTE_UNUSED)
2990 {
2991 char *name;
2992 char name_end;
2993 symbolS *ent;
2994
2995 if (cur_file_ptr == (efdr_t *) NULL)
2996 {
2997 as_warn (_(".end directive without a preceding .file directive"));
2998 demand_empty_rest_of_line ();
2999 return;
3000 }
3001
3002 if (cur_proc_ptr == (proc_t *) NULL)
3003 {
3004 as_warn (_(".end directive without a preceding .ent directive"));
3005 demand_empty_rest_of_line ();
3006 return;
3007 }
3008
3009 name = input_line_pointer;
3010 name_end = get_symbol_end ();
3011
3012 if (name == input_line_pointer)
3013 {
3014 as_warn (_(".end directive has no name"));
3015 *input_line_pointer = name_end;
3016 demand_empty_rest_of_line ();
3017 return;
3018 }
3019
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
3023 symbol. */
3024 ent = symbol_find (name);
3025 if (ent == (symbolS *) NULL)
3026 as_warn (_(".end directive names unknown symbol"));
3027 else
3028 (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text,
3029 symbol_new ("L0\001", now_seg,
3030 (valueT) frag_now_fix (),
3031 frag_now),
3032 (bfd_vma) 0, (symint_t) 0, (symint_t) 0);
3033
3034 cur_proc_ptr = (proc_t *) NULL;
3035
3036 *input_line_pointer = name_end;
3037 demand_empty_rest_of_line ();
3038 }
3039 \f
3040 /* Parse .ent directives. */
3041
3042 void
3043 ecoff_directive_ent (int ignore ATTRIBUTE_UNUSED)
3044 {
3045 char *name;
3046 char name_end;
3047
3048 if (cur_file_ptr == (efdr_t *) NULL)
3049 add_file ((const char *) NULL, 0, 1);
3050
3051 if (cur_proc_ptr != (proc_t *) NULL)
3052 {
3053 as_warn (_("second .ent directive found before .end directive"));
3054 demand_empty_rest_of_line ();
3055 return;
3056 }
3057
3058 name = input_line_pointer;
3059 name_end = get_symbol_end ();
3060
3061 if (name == input_line_pointer)
3062 {
3063 as_warn (_(".ent directive has no name"));
3064 *input_line_pointer = name_end;
3065 demand_empty_rest_of_line ();
3066 return;
3067 }
3068
3069 add_procedure (name);
3070
3071 *input_line_pointer = name_end;
3072
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
3076 the information. */
3077 SKIP_WHITESPACE ();
3078 if (*input_line_pointer == ',')
3079 {
3080 ++input_line_pointer;
3081 SKIP_WHITESPACE ();
3082 }
3083 if (ISDIGIT (*input_line_pointer)
3084 || *input_line_pointer == '-')
3085 (void) get_absolute_expression ();
3086
3087 demand_empty_rest_of_line ();
3088 }
3089 \f
3090 /* Parse .extern directives. */
3091
3092 void
3093 ecoff_directive_extern (int ignore ATTRIBUTE_UNUSED)
3094 {
3095 char *name;
3096 int c;
3097 symbolS *symbolp;
3098 valueT size;
3099
3100 name = input_line_pointer;
3101 c = get_symbol_end ();
3102 symbolp = symbol_find_or_make (name);
3103 *input_line_pointer = c;
3104
3105 S_SET_EXTERNAL (symbolp);
3106
3107 if (*input_line_pointer == ',')
3108 ++input_line_pointer;
3109 size = get_absolute_expression ();
3110
3111 symbol_get_obj (symbolp)->ecoff_extern_size = size;
3112 }
3113 \f
3114 /* Parse .file directives. */
3115
3116 void
3117 ecoff_directive_file (int ignore ATTRIBUTE_UNUSED)
3118 {
3119 int indx;
3120 char *name;
3121 int len;
3122
3123 if (cur_proc_ptr != (proc_t *) NULL)
3124 {
3125 as_warn (_("no way to handle .file within .ent/.end section"));
3126 demand_empty_rest_of_line ();
3127 return;
3128 }
3129
3130 indx = (int) get_absolute_expression ();
3131
3132 /* FIXME: we don't have to save the name here. */
3133 name = demand_copy_C_string (&len);
3134
3135 add_file (name, indx - 1, 0);
3136
3137 demand_empty_rest_of_line ();
3138 }
3139 \f
3140 /* Parse .fmask directives. */
3141
3142 void
3143 ecoff_directive_fmask (int ignore ATTRIBUTE_UNUSED)
3144 {
3145 long val;
3146
3147 if (cur_proc_ptr == (proc_t *) NULL)
3148 {
3149 as_warn (_(".fmask outside of .ent"));
3150 demand_empty_rest_of_line ();
3151 return;
3152 }
3153
3154 if (get_absolute_expression_and_terminator (&val) != ',')
3155 {
3156 as_warn (_("bad .fmask directive"));
3157 --input_line_pointer;
3158 demand_empty_rest_of_line ();
3159 return;
3160 }
3161
3162 cur_proc_ptr->pdr.fregmask = val;
3163 cur_proc_ptr->pdr.fregoffset = get_absolute_expression ();
3164
3165 demand_empty_rest_of_line ();
3166 }
3167 \f
3168 /* Parse .frame directives. */
3169
3170 void
3171 ecoff_directive_frame (int ignore ATTRIBUTE_UNUSED)
3172 {
3173 long val;
3174
3175 if (cur_proc_ptr == (proc_t *) NULL)
3176 {
3177 as_warn (_(".frame outside of .ent"));
3178 demand_empty_rest_of_line ();
3179 return;
3180 }
3181
3182 cur_proc_ptr->pdr.framereg = tc_get_register (1);
3183
3184 SKIP_WHITESPACE ();
3185 if (*input_line_pointer++ != ','
3186 || get_absolute_expression_and_terminator (&val) != ',')
3187 {
3188 as_warn (_("bad .frame directive"));
3189 --input_line_pointer;
3190 demand_empty_rest_of_line ();
3191 return;
3192 }
3193
3194 cur_proc_ptr->pdr.frameoffset = val;
3195
3196 cur_proc_ptr->pdr.pcreg = tc_get_register (0);
3197
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 (). */
3201 s_ignore (42);
3202 }
3203 \f
3204 /* Parse .mask directives. */
3205
3206 void
3207 ecoff_directive_mask (int ignore ATTRIBUTE_UNUSED)
3208 {
3209 long val;
3210
3211 if (cur_proc_ptr == (proc_t *) NULL)
3212 {
3213 as_warn (_(".mask outside of .ent"));
3214 demand_empty_rest_of_line ();
3215 return;
3216 }
3217
3218 if (get_absolute_expression_and_terminator (&val) != ',')
3219 {
3220 as_warn (_("bad .mask directive"));
3221 --input_line_pointer;
3222 demand_empty_rest_of_line ();
3223 return;
3224 }
3225
3226 cur_proc_ptr->pdr.regmask = val;
3227 cur_proc_ptr->pdr.regoffset = get_absolute_expression ();
3228
3229 demand_empty_rest_of_line ();
3230 }
3231 \f
3232 /* Parse .loc directives. */
3233
3234 void
3235 ecoff_directive_loc (int ignore ATTRIBUTE_UNUSED)
3236 {
3237 lineno_list_t *list;
3238 symint_t lineno;
3239
3240 if (cur_file_ptr == (efdr_t *) NULL)
3241 {
3242 as_warn (_(".loc before .file"));
3243 demand_empty_rest_of_line ();
3244 return;
3245 }
3246
3247 if (now_seg != text_section)
3248 {
3249 as_warn (_(".loc outside of .text"));
3250 demand_empty_rest_of_line ();
3251 return;
3252 }
3253
3254 /* Skip the file number. */
3255 SKIP_WHITESPACE ();
3256 get_absolute_expression ();
3257 SKIP_WHITESPACE ();
3258
3259 lineno = get_absolute_expression ();
3260
3261 #ifndef NO_LISTING
3262 if (listing)
3263 listing_source_line (lineno);
3264 #endif
3265
3266 /* If we're building stabs, then output a special label rather than
3267 ECOFF line number info. */
3268 if (stabs_seen)
3269 {
3270 (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text,
3271 symbol_new ("L0\001", now_seg,
3272 (valueT) frag_now_fix (),
3273 frag_now),
3274 (bfd_vma) 0, 0, lineno);
3275 return;
3276 }
3277
3278 list = allocate_lineno_list ();
3279
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;
3286
3287 /* We don't want to merge files which have line numbers. */
3288 cur_file_ptr->fdr.fMerge = 0;
3289
3290 /* A .loc directive will sometimes appear before a .ent directive,
3291 which means that cur_proc_ptr will be NULL here. Arrange to
3292 patch this up. */
3293 if (cur_proc_ptr == (proc_t *) NULL)
3294 {
3295 lineno_list_t **pl;
3296
3297 pl = &noproc_lineno;
3298 while (*pl != (lineno_list_t *) NULL)
3299 pl = &(*pl)->next;
3300 *pl = list;
3301 }
3302 else
3303 {
3304 last_lineno = list;
3305 *last_lineno_ptr = list;
3306 last_lineno_ptr = &list->next;
3307 }
3308 }
3309
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. */
3313
3314 void
3315 ecoff_fix_loc (fragS *old_frag, unsigned long old_frag_offset)
3316 {
3317 if (last_lineno != NULL
3318 && last_lineno->frag == old_frag
3319 && last_lineno->paddr == old_frag_offset)
3320 {
3321 last_lineno->frag = frag_now;
3322 last_lineno->paddr = frag_now_fix ();
3323 }
3324 }
3325 \f
3326 /* Make sure the @stabs symbol is emitted. */
3327
3328 static void
3329 mark_stabs (int ignore ATTRIBUTE_UNUSED)
3330 {
3331 if (! stabs_seen)
3332 {
3333 /* Add a dummy @stabs dymbol. */
3334 stabs_seen = 1;
3335 (void) add_ecoff_symbol (stabs_symbol, st_Nil, sc_Info,
3336 (symbolS *) NULL,
3337 (bfd_vma) 0, (symint_t) -1,
3338 ECOFF_MARK_STAB (0));
3339 }
3340 }
3341 \f
3342 /* Parse .weakext directives. */
3343 #ifndef TC_MIPS
3344 /* For TC_MIPS use the version in tc-mips.c. */
3345 void
3346 ecoff_directive_weakext (int ignore ATTRIBUTE_UNUSED)
3347 {
3348 char *name;
3349 int c;
3350 symbolS *symbolP;
3351 expressionS exp;
3352
3353 name = input_line_pointer;
3354 c = get_symbol_end ();
3355 symbolP = symbol_find_or_make (name);
3356 *input_line_pointer = c;
3357
3358 SKIP_WHITESPACE ();
3359
3360 if (*input_line_pointer == ',')
3361 {
3362 if (S_IS_DEFINED (symbolP))
3363 {
3364 as_bad (_("symbol `%s' is already defined"),
3365 S_GET_NAME (symbolP));
3366 ignore_rest_of_line ();
3367 return;
3368 }
3369
3370 ++input_line_pointer;
3371 SKIP_WHITESPACE ();
3372 if (! is_end_of_line[(unsigned char) *input_line_pointer])
3373 {
3374 expression (&exp);
3375 if (exp.X_op != O_symbol)
3376 {
3377 as_bad (_("bad .weakext directive"));
3378 ignore_rest_of_line ();
3379 return;
3380 }
3381 symbol_set_value_expression (symbolP, &exp);
3382 }
3383 }
3384
3385 S_SET_WEAK (symbolP);
3386
3387 demand_empty_rest_of_line ();
3388 }
3389 #endif /* not TC_MIPS */
3390 \f
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.
3395
3396 .stabs directives have five fields:
3397 "string" a string, encoding the type information.
3398 code a numeric code, defined in <stab.h>
3399 0 a zero
3400 desc a zero or line number
3401 value a numeric value or an address.
3402
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
3409
3410 If the value is not relocatable, we transform this into:
3411 iss points as an index into string space
3412 value value
3413 st st_Nil
3414 sc sc_Nil
3415 index code|CODE_MASK
3416
3417 .stabn directives have four fields (string is null):
3418 code a numeric code, defined in <stab.h>
3419 0 a zero
3420 desc a zero or a line number
3421 value a numeric value or an address. */
3422
3423 void
3424 ecoff_stab (segT sec ATTRIBUTE_UNUSED,
3425 int what,
3426 const char *string,
3427 int type,
3428 int other,
3429 int desc)
3430 {
3431 efdr_t *save_file_ptr = cur_file_ptr;
3432 symbolS *sym;
3433 symint_t value;
3434 bfd_vma addend;
3435 st_t st;
3436 sc_t sc;
3437 symint_t indx;
3438 localsym_t *hold = NULL;
3439
3440 ecoff_debugging_seen = 1;
3441
3442 /* We don't handle .stabd. */
3443 if (what != 's' && what != 'n')
3444 {
3445 as_bad (_(".stab%c is not supported"), what);
3446 return;
3447 }
3448
3449 /* A .stabn uses a null name, not an empty string. */
3450 if (what == 'n')
3451 string = NULL;
3452
3453 /* We ignore the other field. */
3454 if (other != 0)
3455 as_warn (_(".stab%c: ignoring non-zero other field"), what);
3456
3457 /* Make sure we have a current file. */
3458 if (cur_file_ptr == (efdr_t *) NULL)
3459 {
3460 add_file ((const char *) NULL, 0, 1);
3461 save_file_ptr = cur_file_ptr;
3462 }
3463
3464 /* For stabs in ECOFF, the first symbol must be @stabs. This is a
3465 signal to gdb. */
3466 if (stabs_seen == 0)
3467 mark_stabs (0);
3468
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
3474 recognize it. */
3475 if (type == N_SLINE)
3476 {
3477 SYMR dummy_symr;
3478 char *name;
3479 char name_end;
3480
3481 #ifndef NO_LISTING
3482 if (listing)
3483 listing_source_line ((unsigned int) desc);
3484 #endif
3485
3486 dummy_symr.index = desc;
3487 if (dummy_symr.index != desc)
3488 {
3489 as_warn (_("line number (%d) for .stab%c directive cannot fit in index field (20 bits)"),
3490 desc, what);
3491 return;
3492 }
3493
3494 name = input_line_pointer;
3495 name_end = get_symbol_end ();
3496
3497 sym = symbol_find_or_make (name);
3498 *input_line_pointer = name_end;
3499
3500 value = 0;
3501 addend = 0;
3502 st = st_Label;
3503 sc = sc_Text;
3504 indx = desc;
3505 }
3506 else
3507 {
3508 #ifndef NO_LISTING
3509 if (listing && (type == N_SO || type == N_SOL))
3510 listing_source_file (string);
3511 #endif
3512
3513 if (ISDIGIT (*input_line_pointer)
3514 || *input_line_pointer == '-'
3515 || *input_line_pointer == '+')
3516 {
3517 st = st_Nil;
3518 sc = sc_Nil;
3519 sym = (symbolS *) NULL;
3520 value = get_absolute_expression ();
3521 addend = 0;
3522 }
3523 else if (! is_name_beginner ((unsigned char) *input_line_pointer))
3524 {
3525 as_warn (_("illegal .stab%c directive, bad character"), what);
3526 return;
3527 }
3528 else
3529 {
3530 expressionS exp;
3531
3532 sc = sc_Nil;
3533 st = st_Nil;
3534
3535 expression (&exp);
3536 if (exp.X_op == O_constant)
3537 {
3538 sym = NULL;
3539 value = exp.X_add_number;
3540 addend = 0;
3541 }
3542 else if (exp.X_op == O_symbol)
3543 {
3544 sym = exp.X_add_symbol;
3545 value = 0;
3546 addend = exp.X_add_number;
3547 }
3548 else
3549 {
3550 sym = make_expr_symbol (&exp);
3551 value = 0;
3552 addend = 0;
3553 }
3554 }
3555
3556 indx = ECOFF_MARK_STAB (type);
3557 }
3558
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
3561 independently. */
3562 if (sym != (symbolS *) NULL)
3563 hold = symbol_get_obj (sym)->ecoff_symbol;
3564
3565 (void) add_ecoff_symbol (string, st, sc, sym, addend, value, indx);
3566
3567 if (sym != (symbolS *) NULL)
3568 symbol_get_obj (sym)->ecoff_symbol = hold;
3569
3570 /* Restore normal file type. */
3571 cur_file_ptr = save_file_ptr;
3572 }
3573 \f
3574 /* Frob an ECOFF symbol. Small common symbols go into a special
3575 .scommon section rather than bfd_com_section. */
3576
3577 void
3578 ecoff_frob_symbol (symbolS *sym)
3579 {
3580 if (S_IS_COMMON (sym)
3581 && S_GET_VALUE (sym) > 0
3582 && S_GET_VALUE (sym) <= bfd_get_gp_size (stdoutput))
3583 {
3584 static asection scom_section;
3585 static asymbol scom_symbol;
3586
3587 /* We must construct a fake section similar to bfd_com_section
3588 but with the name .scommon. */
3589 if (scom_section.name == NULL)
3590 {
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;
3599 }
3600 S_SET_SEGMENT (sym, &scom_section);
3601 }
3602
3603 /* Double check weak symbols. */
3604 if (S_IS_WEAK (sym))
3605 {
3606 if (S_IS_COMMON (sym))
3607 as_bad (_("symbol `%s' can not be both weak and common"),
3608 S_GET_NAME (sym));
3609 }
3610 }
3611 \f
3612 /* Add bytes to the symbolic information buffer. */
3613
3614 static char *
3615 ecoff_add_bytes (char **buf,
3616 char **bufend,
3617 char *bufptr,
3618 unsigned long need)
3619 {
3620 unsigned long at;
3621 unsigned long want;
3622
3623 at = bufptr - *buf;
3624 need -= *bufend - bufptr;
3625 if (need < PAGE_SIZE)
3626 need = PAGE_SIZE;
3627 want = (*bufend - *buf) + need;
3628 *buf = (char *) xrealloc (*buf, want);
3629 *bufend = *buf + want;
3630 return *buf + at;
3631 }
3632
3633 /* Adjust the symbolic information buffer to the alignment required
3634 for the ECOFF target debugging information. */
3635
3636 static unsigned long
3637 ecoff_padding_adjust (const struct ecoff_debug_swap *backend,
3638 char **buf,
3639 char **bufend,
3640 unsigned long offset,
3641 char **bufptrptr)
3642 {
3643 bfd_size_type align;
3644
3645 align = backend->debug_align;
3646 if ((offset & (align - 1)) != 0)
3647 {
3648 unsigned long add;
3649
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);
3654 offset += add;
3655 if (bufptrptr != (char **) NULL)
3656 *bufptrptr = *buf + offset;
3657 }
3658
3659 return offset;
3660 }
3661
3662 /* Build the line number information. */
3663
3664 static unsigned long
3665 ecoff_build_lineno (const struct ecoff_debug_swap *backend,
3666 char **buf,
3667 char **bufend,
3668 unsigned long offset,
3669 long *linecntptr)
3670 {
3671 char *bufptr;
3672 register lineno_list_t *l;
3673 lineno_list_t *last;
3674 efdr_t *file;
3675 proc_t *proc;
3676 unsigned long c;
3677 long iline;
3678 long totcount;
3679 lineno_list_t first;
3680 lineno_list_t *local_first_lineno = first_lineno;
3681
3682 if (linecntptr != (long *) NULL)
3683 *linecntptr = 0;
3684
3685 bufptr = *buf + offset;
3686
3687 file = (efdr_t *) NULL;
3688 proc = (proc_t *) NULL;
3689 last = (lineno_list_t *) NULL;
3690 c = offset;
3691 iline = 0;
3692 totcount = 0;
3693
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.
3703
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)))
3712 != 0))
3713 {
3714 first.file = local_first_lineno->file;
3715 first.proc = local_first_lineno->proc;
3716 first.frag = &zero_address_frag;
3717 first.paddr = 0;
3718 first.lineno = 0;
3719
3720 first.next = local_first_lineno;
3721 local_first_lineno = &first;
3722 }
3723
3724 for (l = local_first_lineno; l != (lineno_list_t *) NULL; l = l->next)
3725 {
3726 long count;
3727 long delta;
3728
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)
3733 {
3734 /* We want a count of zero, but it will be decremented
3735 before it is used. */
3736 count = 1;
3737 }
3738 else if (l->next->frag->fr_address + l->next->paddr
3739 > l->frag->fr_address + l->paddr)
3740 {
3741 count = ((l->next->frag->fr_address + l->next->paddr
3742 - (l->frag->fr_address + l->paddr))
3743 >> 2);
3744 }
3745 else
3746 {
3747 /* Don't change last, so we still get the right delta. */
3748 continue;
3749 }
3750
3751 if (l->file != file || l->proc != proc)
3752 {
3753 if (l->proc != proc && proc != (proc_t *) NULL)
3754 proc->pdr.lnHigh = last->lineno;
3755 if (l->file != file && file != (efdr_t *) NULL)
3756 {
3757 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3758 file->fdr.cline = totcount + count;
3759 if (linecntptr != (long *) NULL)
3760 *linecntptr += totcount + count;
3761 totcount = 0;
3762 }
3763
3764 if (l->file != file)
3765 {
3766 efdr_t *last_file = file;
3767
3768 file = l->file;
3769 if (last_file != (efdr_t *) NULL)
3770 file->fdr.ilineBase
3771 = last_file->fdr.ilineBase + last_file->fdr.cline;
3772 else
3773 file->fdr.ilineBase = 0;
3774 file->fdr.cbLineOffset = c;
3775 }
3776 if (l->proc != proc)
3777 {
3778 proc = l->proc;
3779 if (proc != (proc_t *) NULL)
3780 {
3781 proc->pdr.lnLow = l->lineno;
3782 proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset;
3783 proc->pdr.iline = totcount;
3784 }
3785 }
3786
3787 last = (lineno_list_t *) NULL;
3788 }
3789
3790 totcount += count;
3791
3792 /* Get the offset to this line number. */
3793 if (last == (lineno_list_t *) NULL)
3794 delta = 0;
3795 else
3796 delta = l->lineno - last->lineno;
3797
3798 /* Put in the offset to this line number. */
3799 while (delta != 0)
3800 {
3801 int setcount;
3802
3803 /* 1 is added to each count read. */
3804 --count;
3805 /* We can only adjust the word count by up to 15 words at a
3806 time. */
3807 if (count <= 0x0f)
3808 {
3809 setcount = count;
3810 count = 0;
3811 }
3812 else
3813 {
3814 setcount = 0x0f;
3815 count -= 0x0f;
3816 }
3817 if (delta >= -7 && delta <= 7)
3818 {
3819 if (bufptr >= *bufend)
3820 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3821 *bufptr++ = setcount + (delta << 4);
3822 delta = 0;
3823 ++c;
3824 }
3825 else
3826 {
3827 int set;
3828
3829 if (*bufend - bufptr < 3)
3830 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3);
3831 *bufptr++ = setcount + (8 << 4);
3832 if (delta < -0x8000)
3833 {
3834 set = -0x8000;
3835 delta += 0x8000;
3836 }
3837 else if (delta > 0x7fff)
3838 {
3839 set = 0x7fff;
3840 delta -= 0x7fff;
3841 }
3842 else
3843 {
3844 set = delta;
3845 delta = 0;
3846 }
3847 *bufptr++ = set >> 8;
3848 *bufptr++ = set & 0xffff;
3849 c += 3;
3850 }
3851 }
3852
3853 /* Finish adjusting the count. */
3854 while (count > 0)
3855 {
3856 if (bufptr >= *bufend)
3857 bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1);
3858 /* 1 is added to each count read. */
3859 --count;
3860 if (count > 0x0f)
3861 {
3862 *bufptr++ = 0x0f;
3863 count -= 0x0f;
3864 }
3865 else
3866 {
3867 *bufptr++ = count;
3868 count = 0;
3869 }
3870 ++c;
3871 }
3872
3873 ++iline;
3874 last = l;
3875 }
3876
3877 if (proc != (proc_t *) NULL)
3878 proc->pdr.lnHigh = last->lineno;
3879 if (file != (efdr_t *) NULL)
3880 {
3881 file->fdr.cbLine = c - file->fdr.cbLineOffset;
3882 file->fdr.cline = totcount;
3883 }
3884
3885 if (linecntptr != (long *) NULL)
3886 *linecntptr += totcount;
3887
3888 c = ecoff_padding_adjust (backend, buf, bufend, c, &bufptr);
3889
3890 return c;
3891 }
3892
3893 /* Build and swap out the symbols. */
3894
3895 static unsigned long
3896 ecoff_build_symbols (const struct ecoff_debug_swap *backend,
3897 char **buf,
3898 char **bufend,
3899 unsigned long offset)
3900 {
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;
3904 char *sym_out;
3905 long isym;
3906 vlinks_t *file_link;
3907
3908 sym_out = *buf + offset;
3909
3910 isym = 0;
3911
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)
3916 {
3917 int ifilesym;
3918 int fil_cnt;
3919 efdr_t *fil_ptr;
3920 efdr_t *fil_end;
3921
3922 if (file_link->next == (vlinks_t *) NULL)
3923 fil_cnt = file_desc.objects_last_page;
3924 else
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++)
3929 {
3930 vlinks_t *sym_link;
3931
3932 fil_ptr->fdr.isymBase = isym;
3933 ifilesym = isym;
3934 for (sym_link = fil_ptr->symbols.first;
3935 sym_link != (vlinks_t *) NULL;
3936 sym_link = sym_link->next)
3937 {
3938 int sym_cnt;
3939 localsym_t *sym_ptr;
3940 localsym_t *sym_end;
3941
3942 if (sym_link->next == (vlinks_t *) NULL)
3943 sym_cnt = fil_ptr->symbols.objects_last_page;
3944 else
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++)
3949 {
3950 int local;
3951 symbolS *as_sym;
3952 forward_t *f;
3953
3954 know (sym_ptr->file_ptr == fil_ptr);
3955
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). */
3963 local = 1;
3964 as_sym = sym_ptr->as_sym;
3965 if (as_sym != (symbolS *) NULL)
3966 {
3967 symint_t indx;
3968
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
3974 this value). */
3975 if (sym_ptr->ecoff_sym.asym.st == (int) st_Block
3976 && sym_ptr->ecoff_sym.asym.sc == (int) sc_Text)
3977 {
3978 symbolS *begin_sym;
3979
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);
3987 }
3988 else
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))
3993 + sym_ptr->addend);
3994
3995 sym_ptr->ecoff_sym.weakext = S_IS_WEAK (as_sym);
3996
3997 /* Set st_Proc to st_StaticProc for local
3998 functions. */
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;
4004
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))))
4014 {
4015 segT seg;
4016 const char *segname;
4017 st_t st;
4018 sc_t sc;
4019
4020 seg = S_GET_SEGMENT (as_sym);
4021 segname = segment_name (seg);
4022
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)))
4027 {
4028 if ((symbol_get_bfdsym (as_sym)->flags
4029 & BSF_FUNCTION) != 0)
4030 st = st_Proc;
4031 else
4032 st = st_Global;
4033 }
4034 else if (seg == text_section)
4035 st = st_Label;
4036 else
4037 st = st_Static;
4038
4039 if (! S_IS_DEFINED (as_sym))
4040 {
4041 valueT s;
4042
4043 s = symbol_get_obj (as_sym)->ecoff_extern_size;
4044 if (s == 0
4045 || s > bfd_get_gp_size (stdoutput))
4046 sc = sc_Undefined;
4047 else
4048 {
4049 sc = sc_SUndefined;
4050 sym_ptr->ecoff_sym.asym.value = s;
4051 }
4052 #ifdef S_SET_SIZE
4053 S_SET_SIZE (as_sym, s);
4054 #endif
4055 }
4056 else if (S_IS_COMMON (as_sym))
4057 {
4058 if (S_GET_VALUE (as_sym) > 0
4059 && (S_GET_VALUE (as_sym)
4060 <= bfd_get_gp_size (stdoutput)))
4061 sc = sc_SCommon;
4062 else
4063 sc = sc_Common;
4064 }
4065 else if (seg == text_section)
4066 sc = sc_Text;
4067 else if (seg == data_section)
4068 sc = sc_Data;
4069 else if (strcmp (segname, ".rdata") == 0
4070 || strcmp (segname, ".rodata") == 0)
4071 sc = sc_RData;
4072 else if (strcmp (segname, ".sdata") == 0)
4073 sc = sc_SData;
4074 else if (seg == bss_section)
4075 sc = sc_Bss;
4076 else if (strcmp (segname, ".sbss") == 0)
4077 sc = sc_SBss;
4078 else if (seg == bfd_abs_section_ptr)
4079 sc = sc_Abs;
4080 else
4081 {
4082 /* This must be a user named section.
4083 This is not possible in ECOFF, but it
4084 is in ELF. */
4085 sc = sc_Data;
4086 }
4087
4088 sym_ptr->ecoff_sym.asym.st = (int) st;
4089 sym_ptr->ecoff_sym.asym.sc = (int) sc;
4090 }
4091
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
4097 them here? */
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))
4104 local = 0;
4105
4106 /* This is just an external symbol if it is a
4107 common symbol. */
4108 if (S_IS_COMMON (as_sym))
4109 local = 0;
4110
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. */
4115 if (local
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,
4120 fil_ptr->str_hash,
4121 sym_ptr->name,
4122 (shash_t **) NULL);
4123 }
4124
4125 /* We now know the index of this symbol; fill in
4126 locations that have been waiting for that
4127 information. */
4128 if (sym_ptr->begin_ptr != (localsym_t *) NULL)
4129 {
4130 localsym_t *begin_ptr;
4131 st_t begin_type;
4132
4133 know (local);
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;
4140
4141 begin_type = (st_t) begin_ptr->ecoff_sym.asym.st;
4142 if (begin_type == st_File
4143 || begin_type == st_Block)
4144 {
4145 begin_ptr->ecoff_sym.asym.index =
4146 isym - ifilesym + 1;
4147 (*swap_sym_out) (stdoutput,
4148 &begin_ptr->ecoff_sym.asym,
4149 (*buf
4150 + offset
4151 + (begin_ptr->sym_index
4152 * external_sym_size)));
4153 }
4154 else
4155 {
4156 know (begin_ptr->index_ptr != (aux_t *) NULL);
4157 begin_ptr->index_ptr->data.isym =
4158 isym - ifilesym + 1;
4159 }
4160
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)
4168 {
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));
4177
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;
4182
4183 #ifdef S_SET_SIZE
4184 S_SET_SIZE (begin_ptr->as_sym,
4185 sym_ptr->ecoff_sym.asym.value);
4186 #endif
4187 }
4188 else if (begin_type == st_Block
4189 && sym_ptr->ecoff_sym.asym.sc != (int) sc_Info)
4190 {
4191 symbolS *begin_sym;
4192
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);
4201 }
4202 }
4203
4204 for (f = sym_ptr->forward_ref;
4205 f != (forward_t *) NULL;
4206 f = f->next)
4207 {
4208 know (local);
4209 f->ifd_ptr->data.isym = fil_ptr->file_index;
4210 f->index_ptr->data.rndx.index = isym - ifilesym;
4211 }
4212
4213 if (local)
4214 {
4215 if ((bfd_size_type)(*bufend - sym_out) < external_sym_size)
4216 sym_out = ecoff_add_bytes (buf, bufend,
4217 sym_out,
4218 external_sym_size);
4219 (*swap_sym_out) (stdoutput, &sym_ptr->ecoff_sym.asym,
4220 sym_out);
4221 sym_out += external_sym_size;
4222
4223 sym_ptr->sym_index = isym;
4224
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;
4228
4229 ++isym;
4230 }
4231
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)
4237 {
4238 if ((sym_ptr->ecoff_sym.asym.st == st_Proc
4239 || sym_ptr->ecoff_sym.asym.st == st_StaticProc)
4240 && local)
4241 sym_ptr->ecoff_sym.asym.index = isym - ifilesym - 1;
4242 sym_ptr->ecoff_sym.ifd = fil_ptr->file_index;
4243
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;
4248 }
4249 }
4250 }
4251 fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase;
4252 }
4253 }
4254
4255 return offset + isym * external_sym_size;
4256 }
4257
4258 /* Swap out the procedure information. */
4259
4260 static unsigned long
4261 ecoff_build_procs (const struct ecoff_debug_swap *backend,
4262 char **buf,
4263 char **bufend,
4264 unsigned long offset)
4265 {
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;
4269 char *pdr_out;
4270 long iproc;
4271 vlinks_t *file_link;
4272
4273 pdr_out = *buf + offset;
4274
4275 iproc = 0;
4276
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)
4281 {
4282 int fil_cnt;
4283 efdr_t *fil_ptr;
4284 efdr_t *fil_end;
4285
4286 if (file_link->next == (vlinks_t *) NULL)
4287 fil_cnt = file_desc.objects_last_page;
4288 else
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++)
4293 {
4294 vlinks_t *proc_link;
4295 int first;
4296
4297 fil_ptr->fdr.ipdFirst = iproc;
4298 first = 1;
4299 for (proc_link = fil_ptr->procs.first;
4300 proc_link != (vlinks_t *) NULL;
4301 proc_link = proc_link->next)
4302 {
4303 int prc_cnt;
4304 proc_t *proc_ptr;
4305 proc_t *proc_end;
4306
4307 if (proc_link->next == (vlinks_t *) NULL)
4308 prc_cnt = fil_ptr->procs.objects_last_page;
4309 else
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++)
4314 {
4315 symbolS *adr_sym;
4316 unsigned long adr;
4317
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)));
4322 if (first)
4323 {
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;
4329 first = 0;
4330 }
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,
4334 pdr_out,
4335 external_pdr_size);
4336 (*swap_pdr_out) (stdoutput, &proc_ptr->pdr, pdr_out);
4337 pdr_out += external_pdr_size;
4338 ++iproc;
4339 }
4340 }
4341 fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst;
4342 }
4343 }
4344
4345 return offset + iproc * external_pdr_size;
4346 }
4347
4348 /* Swap out the aux information. */
4349
4350 static unsigned long
4351 ecoff_build_aux (const struct ecoff_debug_swap *backend,
4352 char **buf,
4353 char **bufend,
4354 unsigned long offset)
4355 {
4356 int bigendian;
4357 union aux_ext *aux_out;
4358 long iaux;
4359 vlinks_t *file_link;
4360
4361 bigendian = bfd_big_endian (stdoutput);
4362
4363 aux_out = (union aux_ext *) (*buf + offset);
4364
4365 iaux = 0;
4366
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)
4371 {
4372 int fil_cnt;
4373 efdr_t *fil_ptr;
4374 efdr_t *fil_end;
4375
4376 if (file_link->next == (vlinks_t *) NULL)
4377 fil_cnt = file_desc.objects_last_page;
4378 else
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++)
4383 {
4384 vlinks_t *aux_link;
4385
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)
4391 {
4392 int aux_cnt;
4393 aux_t *aux_ptr;
4394 aux_t *aux_end;
4395
4396 if (aux_link->next == (vlinks_t *) NULL)
4397 aux_cnt = fil_ptr->aux_syms.objects_last_page;
4398 else
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++)
4403 {
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,
4408 (char *) aux_out,
4409 sizeof (union aux_ext)));
4410 switch (aux_ptr->type)
4411 {
4412 case aux_tir:
4413 (*backend->swap_tir_out) (bigendian,
4414 &aux_ptr->data.ti,
4415 &aux_out->a_ti);
4416 break;
4417 case aux_rndx:
4418 (*backend->swap_rndx_out) (bigendian,
4419 &aux_ptr->data.rndx,
4420 &aux_out->a_rndx);
4421 break;
4422 case aux_dnLow:
4423 AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow,
4424 aux_out);
4425 break;
4426 case aux_dnHigh:
4427 AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh,
4428 aux_out);
4429 break;
4430 case aux_isym:
4431 AUX_PUT_ISYM (bigendian, aux_ptr->data.isym,
4432 aux_out);
4433 break;
4434 case aux_iss:
4435 AUX_PUT_ISS (bigendian, aux_ptr->data.iss,
4436 aux_out);
4437 break;
4438 case aux_width:
4439 AUX_PUT_WIDTH (bigendian, aux_ptr->data.width,
4440 aux_out);
4441 break;
4442 case aux_count:
4443 AUX_PUT_COUNT (bigendian, aux_ptr->data.count,
4444 aux_out);
4445 break;
4446 }
4447
4448 ++aux_out;
4449 ++iaux;
4450 }
4451 }
4452 fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase;
4453 }
4454 }
4455
4456 return ecoff_padding_adjust (backend, buf, bufend,
4457 offset + iaux * sizeof (union aux_ext),
4458 (char **) NULL);
4459 }
4460
4461 /* Copy out the strings from a varray_t. This returns the number of
4462 bytes copied, rather than the new offset. */
4463
4464 static unsigned long
4465 ecoff_build_strings (char **buf,
4466 char **bufend,
4467 unsigned long offset,
4468 varray_t *vp)
4469 {
4470 unsigned long istr;
4471 char *str_out;
4472 vlinks_t *str_link;
4473
4474 str_out = *buf + offset;
4475
4476 istr = 0;
4477
4478 for (str_link = vp->first;
4479 str_link != (vlinks_t *) NULL;
4480 str_link = str_link->next)
4481 {
4482 unsigned long str_cnt;
4483
4484 if (str_link->next == (vlinks_t *) NULL)
4485 str_cnt = vp->objects_last_page;
4486 else
4487 str_cnt = vp->objects_per_page;
4488
4489 if ((unsigned long)(*bufend - str_out) < str_cnt)
4490 str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt);
4491
4492 memcpy (str_out, str_link->datum->byte, str_cnt);
4493 str_out += str_cnt;
4494 istr += str_cnt;
4495 }
4496
4497 return istr;
4498 }
4499
4500 /* Dump out the local strings. */
4501
4502 static unsigned long
4503 ecoff_build_ss (const struct ecoff_debug_swap *backend,
4504 char **buf,
4505 char **bufend,
4506 unsigned long offset)
4507 {
4508 long iss;
4509 vlinks_t *file_link;
4510
4511 iss = 0;
4512
4513 for (file_link = file_desc.first;
4514 file_link != (vlinks_t *) NULL;
4515 file_link = file_link->next)
4516 {
4517 int fil_cnt;
4518 efdr_t *fil_ptr;
4519 efdr_t *fil_end;
4520
4521 if (file_link->next == (vlinks_t *) NULL)
4522 fil_cnt = file_desc.objects_last_page;
4523 else
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++)
4528 {
4529 long ss_cnt;
4530
4531 fil_ptr->fdr.issBase = iss;
4532 ss_cnt = ecoff_build_strings (buf, bufend, offset + iss,
4533 &fil_ptr->strings);
4534 fil_ptr->fdr.cbSs = ss_cnt;
4535 iss += ss_cnt;
4536 }
4537 }
4538
4539 return ecoff_padding_adjust (backend, buf, bufend, offset + iss,
4540 (char **) NULL);
4541 }
4542
4543 /* Swap out the file descriptors. */
4544
4545 static unsigned long
4546 ecoff_build_fdr (const struct ecoff_debug_swap *backend,
4547 char **buf,
4548 char **bufend,
4549 unsigned long offset)
4550 {
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;
4554 long ifile;
4555 char *fdr_out;
4556 vlinks_t *file_link;
4557
4558 ifile = 0;
4559
4560 fdr_out = *buf + offset;
4561
4562 for (file_link = file_desc.first;
4563 file_link != (vlinks_t *) NULL;
4564 file_link = file_link->next)
4565 {
4566 int fil_cnt;
4567 efdr_t *fil_ptr;
4568 efdr_t *fil_end;
4569
4570 if (file_link->next == (vlinks_t *) NULL)
4571 fil_cnt = file_desc.objects_last_page;
4572 else
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++)
4577 {
4578 if ((bfd_size_type)(*bufend - fdr_out) < external_fdr_size)
4579 fdr_out = ecoff_add_bytes (buf, bufend, fdr_out,
4580 external_fdr_size);
4581 (*swap_fdr_out) (stdoutput, &fil_ptr->fdr, fdr_out);
4582 fdr_out += external_fdr_size;
4583 ++ifile;
4584 }
4585 }
4586
4587 return offset + ifile * external_fdr_size;
4588 }
4589
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. */
4593
4594 static void
4595 ecoff_setup_ext (void)
4596 {
4597 register symbolS *sym;
4598
4599 for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym))
4600 {
4601 if (symbol_get_obj (sym)->ecoff_symbol == NULL)
4602 continue;
4603
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))
4608 {
4609 struct localsym *lsym;
4610
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;
4616 }
4617
4618 obj_ecoff_set_ext (sym, &symbol_get_obj (sym)->ecoff_symbol->ecoff_sym);
4619 }
4620 }
4621
4622 /* Build the ECOFF debugging information. */
4623
4624 unsigned long
4625 ecoff_build_debug (HDRR *hdr,
4626 char **bufp,
4627 const struct ecoff_debug_swap *backend)
4628 {
4629 const bfd_size_type external_pdr_size = backend->external_pdr_size;
4630 tag_t *ptag;
4631 tag_t *ptag_next;
4632 efdr_t *fil_ptr;
4633 int end_warning;
4634 efdr_t *hold_file_ptr;
4635 proc_t *hold_proc_ptr;
4636 symbolS *sym;
4637 char *buf;
4638 char *bufend;
4639 unsigned long offset;
4640
4641 /* Make sure we have a file. */
4642 if (first_file == (efdr_t *) NULL)
4643 add_file ((const char *) NULL, 0, 1);
4644
4645 /* Handle any top level tags. */
4646 for (ptag = top_tag_head->first_tag;
4647 ptag != (tag_t *) NULL;
4648 ptag = ptag_next)
4649 {
4650 if (ptag->forward_ref != (forward_t *) NULL)
4651 add_unknown_tag (ptag);
4652
4653 ptag_next = ptag->same_block;
4654 ptag->hash_ptr->tag_ptr = ptag->same_name;
4655 free_tag (ptag);
4656 }
4657
4658 free_thead (top_tag_head);
4659
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))
4666 {
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)
4670 continue;
4671
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);
4675 }
4676 cur_proc_ptr = hold_proc_ptr;
4677 cur_file_ptr = hold_file_ptr;
4678
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
4681 files. */
4682 end_warning = 0;
4683 for (fil_ptr = first_file;
4684 fil_ptr != (efdr_t *) NULL;
4685 fil_ptr = fil_ptr->next_file)
4686 {
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)
4690 {
4691 cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev;
4692 if (! end_warning && ! cur_file_ptr->fake)
4693 {
4694 as_warn (_("missing .end or .bend at end of file"));
4695 end_warning = 1;
4696 }
4697 }
4698 if (cur_file_ptr->cur_scope != (scope_t *) NULL)
4699 (void) add_ecoff_symbol ((const char *) NULL,
4700 st_End, sc_Text,
4701 (symbolS *) NULL,
4702 (bfd_vma) 0,
4703 (symint_t) 0,
4704 (symint_t) 0);
4705 }
4706
4707 /* Build the symbolic information. */
4708 offset = 0;
4709 buf = (char *) xmalloc (PAGE_SIZE);
4710 bufend = buf + PAGE_SIZE;
4711
4712 /* Build the line number information. */
4713 hdr->cbLineOffset = offset;
4714 offset = ecoff_build_lineno (backend, &buf, &bufend, offset,
4715 &hdr->ilineMax);
4716 hdr->cbLine = offset - hdr->cbLineOffset;
4717
4718 /* We don't use dense numbers at all. */
4719 hdr->idnMax = 0;
4720 hdr->cbDnOffset = 0;
4721
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;
4731
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;
4736
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);
4740
4741 /* We don't use optimization symbols. */
4742 hdr->ioptMax = 0;
4743 hdr->cbOptOffset = 0;
4744
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);
4749
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;
4754
4755 /* We don't use relative file descriptors. */
4756 hdr->crfd = 0;
4757 hdr->cbRfdOffset = 0;
4758
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;
4763
4764 /* Set up the external symbols, which are handled by the BFD back
4765 end. */
4766 hdr->issExtMax = 0;
4767 hdr->cbSsExtOffset = 0;
4768 hdr->iextMax = 0;
4769 hdr->cbExtOffset = 0;
4770 ecoff_setup_ext ();
4771
4772 know ((offset & (backend->debug_align - 1)) == 0);
4773
4774 /* FIXME: This value should be determined from the .verstamp directive,
4775 with reasonable defaults in config files. */
4776 #ifdef TC_ALPHA
4777 hdr->vstamp = 0x030b;
4778 #else
4779 hdr->vstamp = 0x020b;
4780 #endif
4781
4782 *bufp = buf;
4783 return offset;
4784 }
4785 \f
4786 /* Allocate a cluster of pages. */
4787
4788 #ifndef MALLOC_CHECK
4789
4790 static page_type *
4791 allocate_cluster (unsigned long npages)
4792 {
4793 register page_type *value = (page_type *) xmalloc (npages * PAGE_USIZE);
4794
4795 #ifdef ECOFF_DEBUG
4796 if (debug > 3)
4797 fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value);
4798 #endif
4799
4800 memset (value, 0, npages * PAGE_USIZE);
4801
4802 return value;
4803 }
4804
4805 static page_type *cluster_ptr = NULL;
4806 static unsigned long pages_left = 0;
4807
4808 #endif /* MALLOC_CHECK */
4809
4810 /* Allocate one page (which is initialized to 0). */
4811
4812 static page_type *
4813 allocate_page (void)
4814 {
4815 #ifndef MALLOC_CHECK
4816
4817 if (pages_left == 0)
4818 {
4819 pages_left = MAX_CLUSTER_PAGES;
4820 cluster_ptr = allocate_cluster (pages_left);
4821 }
4822
4823 pages_left--;
4824 return cluster_ptr++;
4825
4826 #else /* MALLOC_CHECK */
4827
4828 page_type *ptr;
4829
4830 ptr = xmalloc (PAGE_USIZE);
4831 memset (ptr, 0, PAGE_USIZE);
4832 return ptr;
4833
4834 #endif /* MALLOC_CHECK */
4835 }
4836 \f
4837 /* Allocate scoping information. */
4838
4839 static scope_t *
4840 allocate_scope (void)
4841 {
4842 register scope_t *ptr;
4843 static scope_t initial_scope;
4844
4845 #ifndef MALLOC_CHECK
4846
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;
4850 else
4851 {
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;
4854
4855 if (unallocated == 0)
4856 {
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++;
4860 }
4861
4862 ptr = &cur_page->scope[--unallocated];
4863 alloc_counts[(int) alloc_type_scope].unallocated = unallocated;
4864 }
4865
4866 #else
4867
4868 ptr = (scope_t *) xmalloc (sizeof (scope_t));
4869
4870 #endif
4871
4872 alloc_counts[(int) alloc_type_scope].total_alloc++;
4873 *ptr = initial_scope;
4874 return ptr;
4875 }
4876
4877 /* Free scoping information. */
4878
4879 static void
4880 free_scope (scope_t *ptr)
4881 {
4882 alloc_counts[(int) alloc_type_scope].total_free++;
4883
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;
4887 #else
4888 free ((void *) ptr);
4889 #endif
4890 }
4891 \f
4892 /* Allocate links for pages in a virtual array. */
4893
4894 static vlinks_t *
4895 allocate_vlinks (void)
4896 {
4897 register vlinks_t *ptr;
4898 static vlinks_t initial_vlinks;
4899
4900 #ifndef MALLOC_CHECK
4901
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;
4904
4905 if (unallocated == 0)
4906 {
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++;
4910 }
4911
4912 ptr = &cur_page->vlinks[--unallocated];
4913 alloc_counts[(int) alloc_type_vlinks].unallocated = unallocated;
4914
4915 #else
4916
4917 ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t));
4918
4919 #endif
4920
4921 alloc_counts[(int) alloc_type_vlinks].total_alloc++;
4922 *ptr = initial_vlinks;
4923 return ptr;
4924 }
4925 \f
4926 /* Allocate string hash buckets. */
4927
4928 static shash_t *
4929 allocate_shash (void)
4930 {
4931 register shash_t *ptr;
4932 static shash_t initial_shash;
4933
4934 #ifndef MALLOC_CHECK
4935
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;
4938
4939 if (unallocated == 0)
4940 {
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++;
4944 }
4945
4946 ptr = &cur_page->shash[--unallocated];
4947 alloc_counts[(int) alloc_type_shash].unallocated = unallocated;
4948
4949 #else
4950
4951 ptr = (shash_t *) xmalloc (sizeof (shash_t));
4952
4953 #endif
4954
4955 alloc_counts[(int) alloc_type_shash].total_alloc++;
4956 *ptr = initial_shash;
4957 return ptr;
4958 }
4959 \f
4960 /* Allocate type hash buckets. */
4961
4962 static thash_t *
4963 allocate_thash (void)
4964 {
4965 register thash_t *ptr;
4966 static thash_t initial_thash;
4967
4968 #ifndef MALLOC_CHECK
4969
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;
4972
4973 if (unallocated == 0)
4974 {
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++;
4978 }
4979
4980 ptr = &cur_page->thash[--unallocated];
4981 alloc_counts[(int) alloc_type_thash].unallocated = unallocated;
4982
4983 #else
4984
4985 ptr = (thash_t *) xmalloc (sizeof (thash_t));
4986
4987 #endif
4988
4989 alloc_counts[(int) alloc_type_thash].total_alloc++;
4990 *ptr = initial_thash;
4991 return ptr;
4992 }
4993 \f
4994 /* Allocate structure, union, or enum tag information. */
4995
4996 static tag_t *
4997 allocate_tag (void)
4998 {
4999 register tag_t *ptr;
5000 static tag_t initial_tag;
5001
5002 #ifndef MALLOC_CHECK
5003
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;
5007 else
5008 {
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;
5011
5012 if (unallocated == 0)
5013 {
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++;
5017 }
5018
5019 ptr = &cur_page->tag[--unallocated];
5020 alloc_counts[(int) alloc_type_tag].unallocated = unallocated;
5021 }
5022
5023 #else
5024
5025 ptr = (tag_t *) xmalloc (sizeof (tag_t));
5026
5027 #endif
5028
5029 alloc_counts[(int) alloc_type_tag].total_alloc++;
5030 *ptr = initial_tag;
5031 return ptr;
5032 }
5033
5034 /* Free scoping information. */
5035
5036 static void
5037 free_tag (tag_t *ptr)
5038 {
5039 alloc_counts[(int) alloc_type_tag].total_free++;
5040
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;
5044 #else
5045 free ((PTR_T) ptr);
5046 #endif
5047 }
5048 \f
5049 /* Allocate forward reference to a yet unknown tag. */
5050
5051 static forward_t *
5052 allocate_forward (void)
5053 {
5054 register forward_t *ptr;
5055 static forward_t initial_forward;
5056
5057 #ifndef MALLOC_CHECK
5058
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;
5061
5062 if (unallocated == 0)
5063 {
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++;
5067 }
5068
5069 ptr = &cur_page->forward[--unallocated];
5070 alloc_counts[(int) alloc_type_forward].unallocated = unallocated;
5071
5072 #else
5073
5074 ptr = (forward_t *) xmalloc (sizeof (forward_t));
5075
5076 #endif
5077
5078 alloc_counts[(int) alloc_type_forward].total_alloc++;
5079 *ptr = initial_forward;
5080 return ptr;
5081 }
5082 \f
5083 /* Allocate head of type hash list. */
5084
5085 static thead_t *
5086 allocate_thead (void)
5087 {
5088 register thead_t *ptr;
5089 static thead_t initial_thead;
5090
5091 #ifndef MALLOC_CHECK
5092
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;
5096 else
5097 {
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;
5100
5101 if (unallocated == 0)
5102 {
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++;
5106 }
5107
5108 ptr = &cur_page->thead[--unallocated];
5109 alloc_counts[(int) alloc_type_thead].unallocated = unallocated;
5110 }
5111
5112 #else
5113
5114 ptr = (thead_t *) xmalloc (sizeof (thead_t));
5115
5116 #endif
5117
5118 alloc_counts[(int) alloc_type_thead].total_alloc++;
5119 *ptr = initial_thead;
5120 return ptr;
5121 }
5122
5123 /* Free scoping information. */
5124
5125 static void
5126 free_thead (thead_t *ptr)
5127 {
5128 alloc_counts[(int) alloc_type_thead].total_free++;
5129
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;
5133 #else
5134 free ((PTR_T) ptr);
5135 #endif
5136 }
5137 \f
5138 static lineno_list_t *
5139 allocate_lineno_list (void)
5140 {
5141 register lineno_list_t *ptr;
5142 static lineno_list_t initial_lineno_list;
5143
5144 #ifndef MALLOC_CHECK
5145
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;
5148
5149 if (unallocated == 0)
5150 {
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++;
5154 }
5155
5156 ptr = &cur_page->lineno[--unallocated];
5157 alloc_counts[(int) alloc_type_lineno].unallocated = unallocated;
5158
5159 #else
5160
5161 ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t));
5162
5163 #endif
5164
5165 alloc_counts[(int) alloc_type_lineno].total_alloc++;
5166 *ptr = initial_lineno_list;
5167 return ptr;
5168 }
5169
5170 void
5171 ecoff_set_gp_prolog_size (int sz)
5172 {
5173 if (cur_proc_ptr == 0)
5174 return;
5175
5176 cur_proc_ptr->pdr.gp_prologue = sz;
5177 if (cur_proc_ptr->pdr.gp_prologue != sz)
5178 {
5179 as_warn (_("GP prologue size exceeds field size, using 0 instead"));
5180 cur_proc_ptr->pdr.gp_prologue = 0;
5181 }
5182
5183 cur_proc_ptr->pdr.gp_used = 1;
5184 }
5185
5186 int
5187 ecoff_no_current_file (void)
5188 {
5189 return cur_file_ptr == (efdr_t *) NULL;
5190 }
5191
5192 void
5193 ecoff_generate_asm_lineno (void)
5194 {
5195 unsigned int lineno;
5196 char *filename;
5197 lineno_list_t *list;
5198
5199 as_where (&filename, &lineno);
5200
5201 if (current_stabs_filename == (char *) NULL
5202 || filename_cmp (current_stabs_filename, filename))
5203 add_file (filename, 0, 1);
5204
5205 list = allocate_lineno_list ();
5206
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;
5213
5214 /* We don't want to merge files which have line numbers. */
5215 cur_file_ptr->fdr.fMerge = 0;
5216
5217 /* A .loc directive will sometimes appear before a .ent directive,
5218 which means that cur_proc_ptr will be NULL here. Arrange to
5219 patch this up. */
5220 if (cur_proc_ptr == (proc_t *) NULL)
5221 {
5222 lineno_list_t **pl;
5223
5224 pl = &noproc_lineno;
5225 while (*pl != (lineno_list_t *) NULL)
5226 pl = &(*pl)->next;
5227 *pl = list;
5228 }
5229 else
5230 {
5231 last_lineno = list;
5232 *last_lineno_ptr = list;
5233 last_lineno_ptr = &list->next;
5234 }
5235 }
5236
5237 #else
5238
5239 void
5240 ecoff_generate_asm_lineno (void)
5241 {
5242 }
5243
5244 #endif /* ECOFF_DEBUGGING */
This page took 0.192133 seconds and 4 git commands to generate.