Commit | Line | Data |
---|---|---|
3d3c5039 ILT |
1 | /* ECOFF object file format. |
2 | Copyright (C) 1993 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support. | |
4 | This file was put together by Ian Lance Taylor <ian@cygnus.com>. A | |
5 | good deal of it comes directly from mips-tfile.c, by Michael | |
6 | Meissner <meissner@osf.org>. | |
7 | ||
8 | This file is part of GAS. | |
9 | ||
10 | GAS is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GAS is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GAS; see the file COPYING. If not, write to | |
22 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
23 | ||
24 | #include "as.h" | |
25 | #include "coff/internal.h" | |
26 | #include "coff/mips.h" | |
27 | #include "coff/sym.h" | |
28 | #include "coff/symconst.h" | |
29 | #include "coff/ecoff-ext.h" | |
30 | #include "aout/stab_gnu.h" | |
31 | #include "../bfd/libecoff.h" | |
32 | ||
670a50eb ILT |
33 | #include <ctype.h> |
34 | ||
3d3c5039 ILT |
35 | /* Why isn't this in coff/sym.h? */ |
36 | #define ST_RFDESCAPE 0xfff | |
37 | ||
918692a5 ILT |
38 | /* Why isn't this in listing.h? */ |
39 | extern int listing; | |
40 | ||
3d3c5039 ILT |
41 | /* The ECOFF file format uses COFF style sections, but with a unique |
42 | debugging format. We just build generic BFD sections since BFD | |
43 | knows how to write them out. The debugging format, however, we | |
44 | must construct here; all BFD knows at the moment is to write it out | |
45 | as a large block of data. | |
46 | ||
47 | We support both COFF style debugging and stabs debugging (the stabs | |
48 | symbols are encapsulated in COFF symbols). This should let us | |
49 | handle anything the compiler might throw at us. Parsing the COFF | |
50 | and stabs debugging information is similar to work done by COFF and | |
51 | a.out targets, but since the result is completely different the | |
52 | code is not shared. */ | |
53 | ||
54 | /* Here is a brief description of the MIPS ECOFF symbol table, by | |
55 | Michael Meissner. The MIPS symbol table has the following pieces: | |
56 | ||
57 | Symbolic Header | |
58 | | | |
59 | +-- Auxiliary Symbols | |
60 | | | |
61 | +-- Dense number table | |
62 | | | |
63 | +-- Optimizer Symbols | |
64 | | | |
65 | +-- External Strings | |
66 | | | |
67 | +-- External Symbols | |
68 | | | |
69 | +-- Relative file descriptors | |
70 | | | |
71 | +-- File table | |
72 | | | |
73 | +-- Procedure table | |
74 | | | |
75 | +-- Line number table | |
76 | | | |
77 | +-- Local Strings | |
78 | | | |
79 | +-- Local Symbols | |
80 | ||
81 | The symbolic header points to each of the other tables, and also | |
82 | contains the number of entries. It also contains a magic number | |
83 | and MIPS compiler version number, such as 2.0. | |
84 | ||
85 | The auxiliary table is a series of 32 bit integers, that are | |
86 | referenced as needed from the local symbol table. Unlike standard | |
87 | COFF, the aux. information does not follow the symbol that uses | |
88 | it, but rather is a separate table. In theory, this would allow | |
89 | the MIPS compilers to collapse duplicate aux. entries, but I've not | |
90 | noticed this happening with the 1.31 compiler suite. The different | |
91 | types of aux. entries are: | |
92 | ||
93 | 1) dnLow: Low bound on array dimension. | |
94 | ||
95 | 2) dnHigh: High bound on array dimension. | |
96 | ||
97 | 3) isym: Index to the local symbol which is the start of the | |
98 | function for the end of function first aux. entry. | |
99 | ||
100 | 4) width: Width of structures and bitfields. | |
101 | ||
102 | 5) count: Count of ranges for variant part. | |
103 | ||
104 | 6) rndx: A relative index into the symbol table. The relative | |
105 | index field has two parts: rfd which is a pointer into the | |
106 | relative file index table or ST_RFDESCAPE which says the next | |
107 | aux. entry is the file number, and index: which is the pointer | |
108 | into the local symbol within a given file table. This is for | |
109 | things like references to types defined in another file. | |
110 | ||
111 | 7) Type information: This is like the COFF type bits, except it | |
112 | is 32 bits instead of 16; they still have room to add new | |
113 | basic types; and they can handle more than 6 levels of array, | |
114 | pointer, function, etc. Each type information field contains | |
115 | the following structure members: | |
116 | ||
117 | a) fBitfield: a bit that says this is a bitfield, and the | |
118 | size in bits follows as the next aux. entry. | |
119 | ||
120 | b) continued: a bit that says the next aux. entry is a | |
121 | continuation of the current type information (in case | |
122 | there are more than 6 levels of array/ptr/function). | |
123 | ||
124 | c) bt: an integer containing the base type before adding | |
125 | array, pointer, function, etc. qualifiers. The | |
126 | current base types that I have documentation for are: | |
127 | ||
128 | btNil -- undefined | |
129 | btAdr -- address - integer same size as ptr | |
130 | btChar -- character | |
131 | btUChar -- unsigned character | |
132 | btShort -- short | |
133 | btUShort -- unsigned short | |
134 | btInt -- int | |
135 | btUInt -- unsigned int | |
136 | btLong -- long | |
137 | btULong -- unsigned long | |
138 | btFloat -- float (real) | |
139 | btDouble -- Double (real) | |
140 | btStruct -- Structure (Record) | |
141 | btUnion -- Union (variant) | |
142 | btEnum -- Enumerated | |
143 | btTypedef -- defined via a typedef isymRef | |
144 | btRange -- subrange of int | |
145 | btSet -- pascal sets | |
146 | btComplex -- fortran complex | |
147 | btDComplex -- fortran double complex | |
148 | btIndirect -- forward or unnamed typedef | |
149 | btFixedDec -- Fixed Decimal | |
150 | btFloatDec -- Float Decimal | |
151 | btString -- Varying Length Character String | |
152 | btBit -- Aligned Bit String | |
153 | btPicture -- Picture | |
154 | btVoid -- Void (MIPS cc revision >= 2.00) | |
155 | ||
156 | d) tq0 - tq5: type qualifier fields as needed. The | |
157 | current type qualifier fields I have documentation for | |
158 | are: | |
159 | ||
160 | tqNil -- no more qualifiers | |
161 | tqPtr -- pointer | |
162 | tqProc -- procedure | |
163 | tqArray -- array | |
164 | tqFar -- 8086 far pointers | |
165 | tqVol -- volatile | |
166 | ||
167 | ||
168 | The dense number table is used in the front ends, and disappears by | |
169 | the time the .o is created. | |
170 | ||
171 | With the 1.31 compiler suite, the optimization symbols don't seem | |
172 | to be used as far as I can tell. | |
173 | ||
174 | The linker is the first entity that creates the relative file | |
175 | descriptor table, and I believe it is used so that the individual | |
176 | file table pointers don't have to be rewritten when the objects are | |
177 | merged together into the program file. | |
178 | ||
179 | Unlike COFF, the basic symbol & string tables are split into | |
180 | external and local symbols/strings. The relocation information | |
181 | only goes off of the external symbol table, and the debug | |
182 | information only goes off of the internal symbol table. The | |
183 | external symbols can have links to an appropriate file index and | |
184 | symbol within the file to give it the appropriate type information. | |
185 | Because of this, the external symbols are actually larger than the | |
186 | internal symbols (to contain the link information), and contain the | |
187 | local symbol structure as a member, though this member is not the | |
188 | first member of the external symbol structure (!). I suspect this | |
189 | split is to make strip easier to deal with. | |
190 | ||
191 | Each file table has offsets for where the line numbers, local | |
192 | strings, local symbols, and procedure table starts from within the | |
193 | global tables, and the indexs are reset to 0 for each of those | |
194 | tables for the file. | |
195 | ||
196 | The procedure table contains the binary equivalents of the .ent | |
197 | (start of the function address), .frame (what register is the | |
198 | virtual frame pointer, constant offset from the register to obtain | |
199 | the VFP, and what register holds the return address), .mask/.fmask | |
200 | (bitmask of saved registers, and where the first register is stored | |
201 | relative to the VFP) assembler directives. It also contains the | |
202 | low and high bounds of the line numbers if debugging is turned on. | |
203 | ||
204 | The line number table is a compressed form of the normal COFF line | |
205 | table. Each line number entry is either 1 or 3 bytes long, and | |
206 | contains a signed delta from the previous line, and an unsigned | |
207 | count of the number of instructions this statement takes. | |
208 | ||
209 | The local symbol table contains the following fields: | |
210 | ||
211 | 1) iss: index to the local string table giving the name of the | |
212 | symbol. | |
213 | ||
214 | 2) value: value of the symbol (address, register number, etc.). | |
215 | ||
216 | 3) st: symbol type. The current symbol types are: | |
217 | ||
218 | stNil -- Nuthin' special | |
219 | stGlobal -- external symbol | |
220 | stStatic -- static | |
221 | stParam -- procedure argument | |
222 | stLocal -- local variable | |
223 | stLabel -- label | |
224 | stProc -- External Procedure | |
225 | stBlock -- beginning of block | |
226 | stEnd -- end (of anything) | |
227 | stMember -- member (of anything) | |
228 | stTypedef -- type definition | |
229 | stFile -- file name | |
230 | stRegReloc -- register relocation | |
231 | stForward -- forwarding address | |
232 | stStaticProc -- Static procedure | |
233 | stConstant -- const | |
234 | ||
235 | 4) sc: storage class. The current storage classes are: | |
236 | ||
237 | scText -- text symbol | |
238 | scData -- initialized data symbol | |
239 | scBss -- un-initialized data symbol | |
240 | scRegister -- value of symbol is register number | |
241 | scAbs -- value of symbol is absolute | |
242 | scUndefined -- who knows? | |
243 | scCdbLocal -- variable's value is IN se->va.?? | |
244 | scBits -- this is a bit field | |
245 | scCdbSystem -- value is IN debugger's address space | |
246 | scRegImage -- register value saved on stack | |
247 | scInfo -- symbol contains debugger information | |
248 | scUserStruct -- addr in struct user for current process | |
249 | scSData -- load time only small data | |
250 | scSBss -- load time only small common | |
251 | scRData -- load time only read only data | |
252 | scVar -- Var parameter (fortranpascal) | |
253 | scCommon -- common variable | |
254 | scSCommon -- small common | |
255 | scVarRegister -- Var parameter in a register | |
256 | scVariant -- Variant record | |
257 | scSUndefined -- small undefined(external) data | |
258 | scInit -- .init section symbol | |
259 | ||
260 | 5) index: pointer to a local symbol or aux. entry. | |
261 | ||
262 | ||
263 | ||
264 | For the following program: | |
265 | ||
266 | #include <stdio.h> | |
267 | ||
268 | main(){ | |
269 | printf("Hello World!\n"); | |
270 | return 0; | |
271 | } | |
272 | ||
273 | Mips-tdump produces the following information: | |
274 | ||
275 | Global file header: | |
276 | magic number 0x162 | |
277 | # sections 2 | |
278 | timestamp 645311799, Wed Jun 13 17:16:39 1990 | |
279 | symbolic header offset 284 | |
280 | symbolic header size 96 | |
281 | optional header 56 | |
282 | flags 0x0 | |
283 | ||
284 | Symbolic header, magic number = 0x7009, vstamp = 1.31: | |
285 | ||
286 | Info Offset Number Bytes | |
287 | ==== ====== ====== ===== | |
288 | ||
289 | Line numbers 380 4 4 [13] | |
290 | Dense numbers 0 0 0 | |
291 | Procedures Tables 384 1 52 | |
292 | Local Symbols 436 16 192 | |
293 | Optimization Symbols 0 0 0 | |
294 | Auxiliary Symbols 628 39 156 | |
295 | Local Strings 784 80 80 | |
296 | External Strings 864 144 144 | |
297 | File Tables 1008 2 144 | |
298 | Relative Files 0 0 0 | |
299 | External Symbols 1152 20 320 | |
300 | ||
301 | File #0, "hello2.c" | |
302 | ||
303 | Name index = 1 Readin = No | |
304 | Merge = No Endian = LITTLE | |
305 | Debug level = G2 Language = C | |
306 | Adr = 0x00000000 | |
307 | ||
308 | Info Start Number Size Offset | |
309 | ==== ===== ====== ==== ====== | |
310 | Local strings 0 15 15 784 | |
311 | Local symbols 0 6 72 436 | |
312 | Line numbers 0 13 13 380 | |
313 | Optimization symbols 0 0 0 0 | |
314 | Procedures 0 1 52 384 | |
315 | Auxiliary symbols 0 14 56 628 | |
316 | Relative Files 0 0 0 0 | |
317 | ||
318 | There are 6 local symbols, starting at 436 | |
319 | ||
320 | Symbol# 0: "hello2.c" | |
321 | End+1 symbol = 6 | |
322 | String index = 1 | |
323 | Storage class = Text Index = 6 | |
324 | Symbol type = File Value = 0 | |
325 | ||
326 | Symbol# 1: "main" | |
327 | End+1 symbol = 5 | |
328 | Type = int | |
329 | String index = 10 | |
330 | Storage class = Text Index = 12 | |
331 | Symbol type = Proc Value = 0 | |
332 | ||
333 | Symbol# 2: "" | |
334 | End+1 symbol = 4 | |
335 | String index = 0 | |
336 | Storage class = Text Index = 4 | |
337 | Symbol type = Block Value = 8 | |
338 | ||
339 | Symbol# 3: "" | |
340 | First symbol = 2 | |
341 | String index = 0 | |
342 | Storage class = Text Index = 2 | |
343 | Symbol type = End Value = 28 | |
344 | ||
345 | Symbol# 4: "main" | |
346 | First symbol = 1 | |
347 | String index = 10 | |
348 | Storage class = Text Index = 1 | |
349 | Symbol type = End Value = 52 | |
350 | ||
351 | Symbol# 5: "hello2.c" | |
352 | First symbol = 0 | |
353 | String index = 1 | |
354 | Storage class = Text Index = 0 | |
355 | Symbol type = End Value = 0 | |
356 | ||
357 | There are 14 auxiliary table entries, starting at 628. | |
358 | ||
359 | * #0 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
360 | * #1 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0] | |
361 | * #2 8, [ 8/ 0], [ 2 0:0 0:0:0:0:0:0] | |
362 | * #3 16, [ 16/ 0], [ 4 0:0 0:0:0:0:0:0] | |
363 | * #4 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0] | |
364 | * #5 32, [ 32/ 0], [ 8 0:0 0:0:0:0:0:0] | |
365 | * #6 40, [ 40/ 0], [10 0:0 0:0:0:0:0:0] | |
366 | * #7 44, [ 44/ 0], [11 0:0 0:0:0:0:0:0] | |
367 | * #8 12, [ 12/ 0], [ 3 0:0 0:0:0:0:0:0] | |
368 | * #9 20, [ 20/ 0], [ 5 0:0 0:0:0:0:0:0] | |
369 | * #10 28, [ 28/ 0], [ 7 0:0 0:0:0:0:0:0] | |
370 | * #11 36, [ 36/ 0], [ 9 0:0 0:0:0:0:0:0] | |
371 | #12 5, [ 5/ 0], [ 1 1:0 0:0:0:0:0:0] | |
372 | #13 24, [ 24/ 0], [ 6 0:0 0:0:0:0:0:0] | |
373 | ||
374 | There are 1 procedure descriptor entries, starting at 0. | |
375 | ||
376 | Procedure descriptor 0: | |
377 | Name index = 10 Name = "main" | |
378 | .mask 0x80000000,-4 .fmask 0x00000000,0 | |
379 | .frame $29,24,$31 | |
380 | Opt. start = -1 Symbols start = 1 | |
381 | First line # = 3 Last line # = 6 | |
382 | Line Offset = 0 Address = 0x00000000 | |
383 | ||
384 | There are 4 bytes holding line numbers, starting at 380. | |
385 | Line 3, delta 0, count 2 | |
386 | Line 4, delta 1, count 3 | |
387 | Line 5, delta 1, count 2 | |
388 | Line 6, delta 1, count 6 | |
389 | ||
390 | File #1, "/usr/include/stdio.h" | |
391 | ||
392 | Name index = 1 Readin = No | |
393 | Merge = Yes Endian = LITTLE | |
394 | Debug level = G2 Language = C | |
395 | Adr = 0x00000000 | |
396 | ||
397 | Info Start Number Size Offset | |
398 | ==== ===== ====== ==== ====== | |
399 | Local strings 15 65 65 799 | |
400 | Local symbols 6 10 120 508 | |
401 | Line numbers 0 0 0 380 | |
402 | Optimization symbols 0 0 0 0 | |
403 | Procedures 1 0 0 436 | |
404 | Auxiliary symbols 14 25 100 684 | |
405 | Relative Files 0 0 0 0 | |
406 | ||
407 | There are 10 local symbols, starting at 442 | |
408 | ||
409 | Symbol# 0: "/usr/include/stdio.h" | |
410 | End+1 symbol = 10 | |
411 | String index = 1 | |
412 | Storage class = Text Index = 10 | |
413 | Symbol type = File Value = 0 | |
414 | ||
415 | Symbol# 1: "_iobuf" | |
416 | End+1 symbol = 9 | |
417 | String index = 22 | |
418 | Storage class = Info Index = 9 | |
419 | Symbol type = Block Value = 20 | |
420 | ||
421 | Symbol# 2: "_cnt" | |
422 | Type = int | |
423 | String index = 29 | |
424 | Storage class = Info Index = 4 | |
425 | Symbol type = Member Value = 0 | |
426 | ||
427 | Symbol# 3: "_ptr" | |
428 | Type = ptr to char | |
429 | String index = 34 | |
430 | Storage class = Info Index = 15 | |
431 | Symbol type = Member Value = 32 | |
432 | ||
433 | Symbol# 4: "_base" | |
434 | Type = ptr to char | |
435 | String index = 39 | |
436 | Storage class = Info Index = 16 | |
437 | Symbol type = Member Value = 64 | |
438 | ||
439 | Symbol# 5: "_bufsiz" | |
440 | Type = int | |
441 | String index = 45 | |
442 | Storage class = Info Index = 4 | |
443 | Symbol type = Member Value = 96 | |
444 | ||
445 | Symbol# 6: "_flag" | |
446 | Type = short | |
447 | String index = 53 | |
448 | Storage class = Info Index = 3 | |
449 | Symbol type = Member Value = 128 | |
450 | ||
451 | Symbol# 7: "_file" | |
452 | Type = char | |
453 | String index = 59 | |
454 | Storage class = Info Index = 2 | |
455 | Symbol type = Member Value = 144 | |
456 | ||
457 | Symbol# 8: "" | |
458 | First symbol = 1 | |
459 | String index = 0 | |
460 | Storage class = Info Index = 1 | |
461 | Symbol type = End Value = 0 | |
462 | ||
463 | Symbol# 9: "/usr/include/stdio.h" | |
464 | First symbol = 0 | |
465 | String index = 1 | |
466 | Storage class = Text Index = 0 | |
467 | Symbol type = End Value = 0 | |
468 | ||
469 | There are 25 auxiliary table entries, starting at 642. | |
470 | ||
471 | * #14 -1, [4095/1048575], [63 1:1 f:f:f:f:f:f] | |
472 | #15 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0] | |
473 | #16 65544, [ 8/ 16], [ 2 0:0 1:0:0:0:0:0] | |
474 | * #17 196656, [ 48/ 48], [12 0:0 3:0:0:0:0:0] | |
475 | * #18 8191, [4095/ 1], [63 1:1 0:0:0:0:f:1] | |
476 | * #19 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0] | |
477 | * #20 20479, [4095/ 4], [63 1:1 0:0:0:0:f:4] | |
478 | * #21 1, [ 1/ 0], [ 0 1:0 0:0:0:0:0:0] | |
479 | * #22 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
480 | * #23 2, [ 2/ 0], [ 0 0:1 0:0:0:0:0:0] | |
481 | * #24 160, [ 160/ 0], [40 0:0 0:0:0:0:0:0] | |
482 | * #25 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
483 | * #26 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
484 | * #27 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
485 | * #28 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
486 | * #29 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
487 | * #30 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
488 | * #31 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
489 | * #32 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
490 | * #33 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
491 | * #34 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
492 | * #35 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
493 | * #36 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
494 | * #37 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
495 | * #38 0, [ 0/ 0], [ 0 0:0 0:0:0:0:0:0] | |
496 | ||
497 | There are 0 procedure descriptor entries, starting at 1. | |
498 | ||
499 | There are 20 external symbols, starting at 1152 | |
500 | ||
501 | Symbol# 0: "_iob" | |
502 | Type = array [3 {160}] of struct _iobuf { ifd = 1, index = 1 } | |
503 | String index = 0 Ifd = 1 | |
504 | Storage class = Nil Index = 17 | |
505 | Symbol type = Global Value = 60 | |
506 | ||
507 | Symbol# 1: "fopen" | |
508 | String index = 5 Ifd = 1 | |
509 | Storage class = Nil Index = 1048575 | |
510 | Symbol type = Proc Value = 0 | |
511 | ||
512 | Symbol# 2: "fdopen" | |
513 | String index = 11 Ifd = 1 | |
514 | Storage class = Nil Index = 1048575 | |
515 | Symbol type = Proc Value = 0 | |
516 | ||
517 | Symbol# 3: "freopen" | |
518 | String index = 18 Ifd = 1 | |
519 | Storage class = Nil Index = 1048575 | |
520 | Symbol type = Proc Value = 0 | |
521 | ||
522 | Symbol# 4: "popen" | |
523 | String index = 26 Ifd = 1 | |
524 | Storage class = Nil Index = 1048575 | |
525 | Symbol type = Proc Value = 0 | |
526 | ||
527 | Symbol# 5: "tmpfile" | |
528 | String index = 32 Ifd = 1 | |
529 | Storage class = Nil Index = 1048575 | |
530 | Symbol type = Proc Value = 0 | |
531 | ||
532 | Symbol# 6: "ftell" | |
533 | String index = 40 Ifd = 1 | |
534 | Storage class = Nil Index = 1048575 | |
535 | Symbol type = Proc Value = 0 | |
536 | ||
537 | Symbol# 7: "rewind" | |
538 | String index = 46 Ifd = 1 | |
539 | Storage class = Nil Index = 1048575 | |
540 | Symbol type = Proc Value = 0 | |
541 | ||
542 | Symbol# 8: "setbuf" | |
543 | String index = 53 Ifd = 1 | |
544 | Storage class = Nil Index = 1048575 | |
545 | Symbol type = Proc Value = 0 | |
546 | ||
547 | Symbol# 9: "setbuffer" | |
548 | String index = 60 Ifd = 1 | |
549 | Storage class = Nil Index = 1048575 | |
550 | Symbol type = Proc Value = 0 | |
551 | ||
552 | Symbol# 10: "setlinebuf" | |
553 | String index = 70 Ifd = 1 | |
554 | Storage class = Nil Index = 1048575 | |
555 | Symbol type = Proc Value = 0 | |
556 | ||
557 | Symbol# 11: "fgets" | |
558 | String index = 81 Ifd = 1 | |
559 | Storage class = Nil Index = 1048575 | |
560 | Symbol type = Proc Value = 0 | |
561 | ||
562 | Symbol# 12: "gets" | |
563 | String index = 87 Ifd = 1 | |
564 | Storage class = Nil Index = 1048575 | |
565 | Symbol type = Proc Value = 0 | |
566 | ||
567 | Symbol# 13: "ctermid" | |
568 | String index = 92 Ifd = 1 | |
569 | Storage class = Nil Index = 1048575 | |
570 | Symbol type = Proc Value = 0 | |
571 | ||
572 | Symbol# 14: "cuserid" | |
573 | String index = 100 Ifd = 1 | |
574 | Storage class = Nil Index = 1048575 | |
575 | Symbol type = Proc Value = 0 | |
576 | ||
577 | Symbol# 15: "tempnam" | |
578 | String index = 108 Ifd = 1 | |
579 | Storage class = Nil Index = 1048575 | |
580 | Symbol type = Proc Value = 0 | |
581 | ||
582 | Symbol# 16: "tmpnam" | |
583 | String index = 116 Ifd = 1 | |
584 | Storage class = Nil Index = 1048575 | |
585 | Symbol type = Proc Value = 0 | |
586 | ||
587 | Symbol# 17: "sprintf" | |
588 | String index = 123 Ifd = 1 | |
589 | Storage class = Nil Index = 1048575 | |
590 | Symbol type = Proc Value = 0 | |
591 | ||
592 | Symbol# 18: "main" | |
593 | Type = int | |
594 | String index = 131 Ifd = 0 | |
595 | Storage class = Text Index = 1 | |
596 | Symbol type = Proc Value = 0 | |
597 | ||
598 | Symbol# 19: "printf" | |
599 | String index = 136 Ifd = 0 | |
600 | Storage class = Undefined Index = 1048575 | |
601 | Symbol type = Proc Value = 0 | |
602 | ||
603 | The following auxiliary table entries were unused: | |
604 | ||
605 | #0 0 0x00000000 void | |
606 | #2 8 0x00000008 char | |
607 | #3 16 0x00000010 short | |
608 | #4 24 0x00000018 int | |
609 | #5 32 0x00000020 long | |
610 | #6 40 0x00000028 float | |
611 | #7 44 0x0000002c double | |
612 | #8 12 0x0000000c unsigned char | |
613 | #9 20 0x00000014 unsigned short | |
614 | #10 28 0x0000001c unsigned int | |
615 | #11 36 0x00000024 unsigned long | |
616 | #14 0 0x00000000 void | |
617 | #15 24 0x00000018 int | |
618 | #19 32 0x00000020 long | |
619 | #20 40 0x00000028 float | |
620 | #21 44 0x0000002c double | |
621 | #22 12 0x0000000c unsigned char | |
622 | #23 20 0x00000014 unsigned short | |
623 | #24 28 0x0000001c unsigned int | |
624 | #25 36 0x00000024 unsigned long | |
625 | #26 48 0x00000030 struct no name { ifd = -1, index = 1048575 } | |
626 | \f | |
627 | */ | |
628 | /* Redefinition of of storage classes as an enumeration for better | |
629 | debugging. */ | |
630 | ||
631 | typedef enum sc { | |
632 | sc_Nil = scNil, /* no storage class */ | |
633 | sc_Text = scText, /* text symbol */ | |
634 | sc_Data = scData, /* initialized data symbol */ | |
635 | sc_Bss = scBss, /* un-initialized data symbol */ | |
636 | sc_Register = scRegister, /* value of symbol is register number */ | |
637 | sc_Abs = scAbs, /* value of symbol is absolute */ | |
638 | sc_Undefined = scUndefined, /* who knows? */ | |
639 | sc_CdbLocal = scCdbLocal, /* variable's value is IN se->va.?? */ | |
640 | sc_Bits = scBits, /* this is a bit field */ | |
641 | sc_CdbSystem = scCdbSystem, /* value is IN CDB's address space */ | |
642 | sc_RegImage = scRegImage, /* register value saved on stack */ | |
643 | sc_Info = scInfo, /* symbol contains debugger information */ | |
644 | sc_UserStruct = scUserStruct, /* addr in struct user for current process */ | |
645 | sc_SData = scSData, /* load time only small data */ | |
646 | sc_SBss = scSBss, /* load time only small common */ | |
647 | sc_RData = scRData, /* load time only read only data */ | |
648 | sc_Var = scVar, /* Var parameter (fortran,pascal) */ | |
649 | sc_Common = scCommon, /* common variable */ | |
650 | sc_SCommon = scSCommon, /* small common */ | |
651 | sc_VarRegister = scVarRegister, /* Var parameter in a register */ | |
652 | sc_Variant = scVariant, /* Variant record */ | |
653 | sc_SUndefined = scSUndefined, /* small undefined(external) data */ | |
654 | sc_Init = scInit, /* .init section symbol */ | |
655 | sc_Max = scMax /* Max storage class+1 */ | |
656 | } sc_t; | |
657 | ||
658 | /* Redefinition of symbol type. */ | |
659 | ||
660 | typedef enum st { | |
661 | st_Nil = stNil, /* Nuthin' special */ | |
662 | st_Global = stGlobal, /* external symbol */ | |
663 | st_Static = stStatic, /* static */ | |
664 | st_Param = stParam, /* procedure argument */ | |
665 | st_Local = stLocal, /* local variable */ | |
666 | st_Label = stLabel, /* label */ | |
667 | st_Proc = stProc, /* " " Procedure */ | |
668 | st_Block = stBlock, /* beginning of block */ | |
669 | st_End = stEnd, /* end (of anything) */ | |
670 | st_Member = stMember, /* member (of anything - struct/union/enum */ | |
671 | st_Typedef = stTypedef, /* type definition */ | |
672 | st_File = stFile, /* file name */ | |
673 | st_RegReloc = stRegReloc, /* register relocation */ | |
674 | st_Forward = stForward, /* forwarding address */ | |
675 | st_StaticProc = stStaticProc, /* load time only static procs */ | |
676 | st_Constant = stConstant, /* const */ | |
677 | st_Str = stStr, /* string */ | |
678 | st_Number = stNumber, /* pure number (ie. 4 NOR 2+2) */ | |
679 | st_Expr = stExpr, /* 2+2 vs. 4 */ | |
680 | st_Type = stType, /* post-coercion SER */ | |
681 | st_Max = stMax /* max type+1 */ | |
682 | } st_t; | |
683 | ||
684 | /* Redefinition of type qualifiers. */ | |
685 | ||
686 | typedef enum tq { | |
687 | tq_Nil = tqNil, /* bt is what you see */ | |
688 | tq_Ptr = tqPtr, /* pointer */ | |
689 | tq_Proc = tqProc, /* procedure */ | |
690 | tq_Array = tqArray, /* duh */ | |
691 | tq_Far = tqFar, /* longer addressing - 8086/8 land */ | |
692 | tq_Vol = tqVol, /* volatile */ | |
693 | tq_Max = tqMax /* Max type qualifier+1 */ | |
694 | } tq_t; | |
695 | ||
696 | /* Redefinition of basic types. */ | |
697 | ||
698 | typedef enum bt { | |
699 | bt_Nil = btNil, /* undefined */ | |
700 | bt_Adr = btAdr, /* address - integer same size as pointer */ | |
701 | bt_Char = btChar, /* character */ | |
702 | bt_UChar = btUChar, /* unsigned character */ | |
703 | bt_Short = btShort, /* short */ | |
704 | bt_UShort = btUShort, /* unsigned short */ | |
705 | bt_Int = btInt, /* int */ | |
706 | bt_UInt = btUInt, /* unsigned int */ | |
707 | bt_Long = btLong, /* long */ | |
708 | bt_ULong = btULong, /* unsigned long */ | |
709 | bt_Float = btFloat, /* float (real) */ | |
710 | bt_Double = btDouble, /* Double (real) */ | |
711 | bt_Struct = btStruct, /* Structure (Record) */ | |
712 | bt_Union = btUnion, /* Union (variant) */ | |
713 | bt_Enum = btEnum, /* Enumerated */ | |
714 | bt_Typedef = btTypedef, /* defined via a typedef, isymRef points */ | |
715 | bt_Range = btRange, /* subrange of int */ | |
716 | bt_Set = btSet, /* pascal sets */ | |
717 | bt_Complex = btComplex, /* fortran complex */ | |
718 | bt_DComplex = btDComplex, /* fortran double complex */ | |
719 | bt_Indirect = btIndirect, /* forward or unnamed typedef */ | |
720 | bt_FixedDec = btFixedDec, /* Fixed Decimal */ | |
721 | bt_FloatDec = btFloatDec, /* Float Decimal */ | |
722 | bt_String = btString, /* Varying Length Character String */ | |
723 | bt_Bit = btBit, /* Aligned Bit String */ | |
724 | bt_Picture = btPicture, /* Picture */ | |
725 | bt_Void = btVoid, /* Void */ | |
726 | bt_Max = btMax /* Max basic type+1 */ | |
727 | } bt_t; | |
728 | ||
729 | #define N_TQ itqMax | |
730 | ||
731 | /* States for whether to hash type or not. */ | |
732 | typedef enum hash_state { | |
733 | hash_no = 0, /* don't hash type */ | |
734 | hash_yes = 1, /* ok to hash type, or use previous hash */ | |
735 | hash_record = 2 /* ok to record hash, but don't use prev. */ | |
736 | } hash_state_t; | |
737 | ||
738 | /* Types of different sized allocation requests. */ | |
739 | enum alloc_type { | |
740 | alloc_type_none, /* dummy value */ | |
741 | alloc_type_scope, /* nested scopes linked list */ | |
742 | alloc_type_vlinks, /* glue linking pages in varray */ | |
743 | alloc_type_shash, /* string hash element */ | |
744 | alloc_type_thash, /* type hash element */ | |
745 | alloc_type_tag, /* struct/union/tag element */ | |
746 | alloc_type_forward, /* element to hold unknown tag */ | |
747 | alloc_type_thead, /* head of type hash list */ | |
748 | alloc_type_varray, /* general varray allocation */ | |
749 | alloc_type_lineno, /* line number list */ | |
750 | alloc_type_last /* last+1 element for array bounds */ | |
751 | }; | |
752 | ||
753 | /* Types of auxiliary type information. */ | |
754 | enum aux_type { | |
755 | aux_tir, /* TIR type information */ | |
756 | aux_rndx, /* relative index into symbol table */ | |
757 | aux_dnLow, /* low dimension */ | |
758 | aux_dnHigh, /* high dimension */ | |
759 | aux_isym, /* symbol table index (end of proc) */ | |
760 | aux_iss, /* index into string space (not used) */ | |
761 | aux_width, /* width for non-default sized struc fields */ | |
762 | aux_count /* count of ranges for variant arm */ | |
763 | }; | |
764 | \f | |
765 | /* Structures to provide n-number of virtual arrays, each of which can | |
766 | grow linearly, and which are written in the object file as | |
767 | sequential pages. On systems with a BSD malloc, the | |
768 | MAX_CLUSTER_PAGES should be 1 less than a power of two, since | |
769 | malloc adds it's overhead, and rounds up to the next power of 2. | |
770 | Pages are linked together via a linked list. | |
771 | ||
772 | If PAGE_SIZE is > 4096, the string length in the shash_t structure | |
773 | can't be represented (assuming there are strings > 4096 bytes). */ | |
774 | ||
775 | #ifndef PAGE_SIZE | |
776 | #define PAGE_SIZE 4096 /* size of varray pages */ | |
777 | #endif | |
778 | ||
779 | #define PAGE_USIZE ((unsigned long) PAGE_SIZE) | |
780 | ||
781 | ||
782 | #ifndef MAX_CLUSTER_PAGES /* # pages to get from system */ | |
783 | #define MAX_CLUSTER_PAGES 63 | |
784 | #endif | |
785 | ||
786 | ||
787 | /* Linked list connecting separate page allocations. */ | |
788 | typedef struct vlinks { | |
789 | struct vlinks *prev; /* previous set of pages */ | |
790 | struct vlinks *next; /* next set of pages */ | |
791 | union page *datum; /* start of page */ | |
792 | unsigned long start_index; /* starting index # of page */ | |
793 | } vlinks_t; | |
794 | ||
795 | ||
796 | /* Virtual array header. */ | |
797 | typedef struct varray { | |
798 | vlinks_t *first; /* first page link */ | |
799 | vlinks_t *last; /* last page link */ | |
800 | unsigned long num_allocated; /* # objects allocated */ | |
801 | unsigned short object_size; /* size in bytes of each object */ | |
802 | unsigned short objects_per_page; /* # objects that can fit on a page */ | |
803 | unsigned short objects_last_page; /* # objects allocated on last page */ | |
804 | } varray_t; | |
805 | ||
806 | #ifndef MALLOC_CHECK | |
807 | #define OBJECTS_PER_PAGE(type) (PAGE_SIZE / sizeof (type)) | |
808 | #else | |
809 | #define OBJECTS_PER_PAGE(type) ((sizeof (type) > 1) ? 1 : PAGE_SIZE) | |
810 | #endif | |
811 | ||
812 | #define INIT_VARRAY(type) { /* macro to initialize a varray */ \ | |
813 | (vlinks_t *)0, /* first */ \ | |
814 | (vlinks_t *)0, /* last */ \ | |
815 | 0, /* num_allocated */ \ | |
816 | sizeof (type), /* object_size */ \ | |
817 | OBJECTS_PER_PAGE (type), /* objects_per_page */ \ | |
818 | OBJECTS_PER_PAGE (type), /* objects_last_page */ \ | |
819 | } | |
820 | ||
821 | ||
822 | /* Master type for indexes within the symbol table. */ | |
823 | typedef unsigned long symint_t; | |
824 | ||
825 | ||
826 | /* Linked list support for nested scopes (file, block, structure, etc.). */ | |
827 | typedef struct scope { | |
828 | struct scope *prev; /* previous scope level */ | |
829 | struct scope *free; /* free list pointer */ | |
830 | struct localsym *lsym; /* pointer to local symbol node */ | |
831 | st_t type; /* type of the node */ | |
832 | } scope_t; | |
833 | ||
834 | ||
835 | /* For a local symbol we store a gas symbol as well as the debugging | |
836 | information we generate. The gas symbol will be NULL if this is | |
837 | only a debugging symbol. */ | |
838 | typedef struct localsym { | |
f6a91cc0 | 839 | const char *name; /* symbol name */ |
3d3c5039 ILT |
840 | symbolS *as_sym; /* symbol as seen by gas */ |
841 | struct efdr *file_ptr; /* file pointer */ | |
842 | struct ecoff_proc *proc_ptr; /* proc pointer */ | |
843 | struct localsym *begin_ptr; /* symbol at start of block */ | |
844 | struct ecoff_aux *index_ptr; /* index value to be filled in */ | |
845 | struct forward *forward_ref; /* forward references to this symbol */ | |
846 | long sym_index; /* final symbol index */ | |
847 | SYMR ecoff_sym; /* ECOFF debugging symbol */ | |
848 | } localsym_t; | |
849 | ||
850 | ||
851 | /* For aux information we keep the type and the data. */ | |
852 | typedef struct ecoff_aux { | |
853 | enum aux_type type; /* aux type */ | |
854 | AUXU data; /* aux data */ | |
855 | } aux_t; | |
856 | ||
857 | /* For a procedure we store the gas symbol as well as the PDR | |
858 | debugging information. */ | |
859 | typedef struct ecoff_proc { | |
860 | localsym_t *sym; /* associated symbol */ | |
861 | PDR pdr; /* ECOFF debugging info */ | |
862 | } proc_t; | |
863 | ||
864 | /* Number of proc_t structures allocated. */ | |
865 | static unsigned long proc_cnt; | |
866 | ||
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 | ||
877 | /* Linked list support for tags. The first tag in the list is always | |
878 | the current tag for that block. */ | |
879 | typedef struct tag { | |
880 | struct tag *free; /* free list pointer */ | |
881 | struct shash *hash_ptr; /* pointer to the hash table head */ | |
882 | struct tag *same_name; /* tag with same name in outer scope */ | |
883 | struct tag *same_block; /* next tag defined in the same block. */ | |
884 | struct forward *forward_ref; /* list of forward references */ | |
885 | bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */ | |
886 | symint_t ifd; /* file # tag defined in */ | |
887 | localsym_t *sym; /* file's local symbols */ | |
888 | } tag_t; | |
889 | ||
890 | ||
891 | /* Head of a block's linked list of tags. */ | |
892 | typedef struct thead { | |
893 | struct thead *prev; /* previous block */ | |
894 | struct thead *free; /* free list pointer */ | |
895 | struct tag *first_tag; /* first tag in block defined */ | |
896 | } thead_t; | |
897 | ||
898 | ||
899 | /* Union containing pointers to each the small structures which are freed up. */ | |
900 | typedef union small_free { | |
901 | scope_t *f_scope; /* scope structure */ | |
902 | thead_t *f_thead; /* tag head structure */ | |
903 | tag_t *f_tag; /* tag element structure */ | |
904 | forward_t *f_forward; /* forward tag reference */ | |
905 | } small_free_t; | |
906 | ||
907 | ||
908 | /* String hash table entry. */ | |
909 | ||
910 | typedef struct shash { | |
911 | char *string; /* string we are hashing */ | |
912 | symint_t indx; /* index within string table */ | |
913 | EXTR *esym_ptr; /* global symbol pointer */ | |
914 | localsym_t *sym_ptr; /* local symbol pointer */ | |
915 | localsym_t *end_ptr; /* symbol pointer to end block */ | |
916 | tag_t *tag_ptr; /* tag pointer */ | |
917 | proc_t *proc_ptr; /* procedure descriptor pointer */ | |
918 | } shash_t; | |
919 | ||
920 | ||
921 | /* Type hash table support. The size of the hash table must fit | |
922 | within a page with the other extended file descriptor information. | |
923 | Because unique types which are hashed are fewer in number than | |
924 | strings, we use a smaller hash value. */ | |
925 | ||
926 | #define HASHBITS 30 | |
927 | ||
928 | #ifndef THASH_SIZE | |
929 | #define THASH_SIZE 113 | |
930 | #endif | |
931 | ||
932 | typedef struct thash { | |
933 | struct thash *next; /* next hash value */ | |
934 | AUXU type; /* type we are hashing */ | |
935 | symint_t indx; /* index within string table */ | |
936 | } thash_t; | |
937 | ||
938 | ||
939 | /* Extended file descriptor that contains all of the support necessary | |
940 | to add things to each file separately. */ | |
941 | typedef struct efdr { | |
942 | FDR fdr; /* File header to be written out */ | |
943 | FDR *orig_fdr; /* original file header */ | |
944 | char *name; /* filename */ | |
945 | symint_t void_type; /* aux. pointer to 'void' type */ | |
946 | symint_t int_type; /* aux. pointer to 'int' type */ | |
947 | scope_t *cur_scope; /* current nested scopes */ | |
948 | symint_t file_index; /* current file number */ | |
949 | int nested_scopes; /* # nested scopes */ | |
950 | varray_t strings; /* local strings */ | |
951 | varray_t symbols; /* local symbols */ | |
952 | varray_t procs; /* procedures */ | |
953 | varray_t aux_syms; /* auxiliary symbols */ | |
954 | struct efdr *next_file; /* next file descriptor */ | |
955 | /* string/type hash tables */ | |
956 | struct hash_control *str_hash; /* string hash table */ | |
957 | thash_t *thash_head[THASH_SIZE]; | |
958 | } efdr_t; | |
959 | ||
960 | /* Pre-initialized extended file structure. */ | |
961 | static const efdr_t init_file = | |
962 | { | |
963 | { /* FDR structure */ | |
964 | 0, /* adr: memory address of beginning of file */ | |
965 | 0, /* rss: file name (of source, if known) */ | |
966 | 0, /* issBase: file's string space */ | |
967 | 0, /* cbSs: number of bytes in the ss */ | |
968 | 0, /* isymBase: beginning of symbols */ | |
969 | 0, /* csym: count file's of symbols */ | |
970 | 0, /* ilineBase: file's line symbols */ | |
971 | 0, /* cline: count of file's line symbols */ | |
972 | 0, /* ioptBase: file's optimization entries */ | |
973 | 0, /* copt: count of file's optimization entries */ | |
974 | 0, /* ipdFirst: start of procedures for this file */ | |
975 | 0, /* cpd: count of procedures for this file */ | |
976 | 0, /* iauxBase: file's auxiliary entries */ | |
977 | 0, /* caux: count of file's auxiliary entries */ | |
978 | 0, /* rfdBase: index into the file indirect table */ | |
979 | 0, /* crfd: count file indirect entries */ | |
980 | langC, /* lang: language for this file */ | |
918692a5 | 981 | 0, /* fMerge: whether this file can be merged */ |
3d3c5039 ILT |
982 | 0, /* fReadin: true if read in (not just created) */ |
983 | #ifdef TARGET_BYTES_BIG_ENDIAN | |
984 | 1, /* fBigendian: if 1, compiled on big endian machine */ | |
985 | #else | |
986 | 0, /* fBigendian: if 1, compiled on big endian machine */ | |
987 | #endif | |
988 | GLEVEL_2, /* glevel: level this file was compiled with */ | |
989 | 0, /* reserved: reserved for future use */ | |
990 | 0, /* cbLineOffset: byte offset from header for this file ln's */ | |
991 | 0, /* cbLine: size of lines for this file */ | |
992 | }, | |
993 | ||
994 | (FDR *)0, /* orig_fdr: original file header pointer */ | |
995 | (char *)0, /* name: pointer to filename */ | |
996 | 0, /* void_type: ptr to aux node for void type */ | |
997 | 0, /* int_type: ptr to aux node for int type */ | |
998 | (scope_t *)0, /* cur_scope: current scope being processed */ | |
999 | 0, /* file_index: current file # */ | |
1000 | 0, /* nested_scopes: # nested scopes */ | |
1001 | INIT_VARRAY (char), /* strings: local string varray */ | |
1002 | INIT_VARRAY (localsym_t), /* symbols: local symbols varray */ | |
1003 | INIT_VARRAY (proc_t), /* procs: procedure varray */ | |
1004 | INIT_VARRAY (aux_t), /* aux_syms: auxiliary symbols varray */ | |
1005 | ||
1006 | (struct efdr *)0, /* next_file: next file structure */ | |
1007 | ||
1008 | (struct hash_control *)0, /* str_hash: string hash table */ | |
1009 | { 0 }, /* thash_head: type hash table */ | |
1010 | }; | |
1011 | ||
1012 | ||
1013 | static efdr_t *first_file; /* first file descriptor */ | |
1014 | static efdr_t **last_file_ptr = &first_file; /* file descriptor tail */ | |
1015 | ||
1016 | ||
1017 | /* Line number information is kept in a list until the assembly is | |
1018 | finished. */ | |
1019 | typedef struct lineno_list { | |
1020 | struct lineno_list *next; /* next element in list */ | |
1021 | efdr_t *file; /* file this line is in */ | |
1022 | proc_t *proc; /* procedure this line is in */ | |
1023 | fragS *frag; /* fragment this line number is in */ | |
1024 | unsigned long paddr; /* offset within fragment */ | |
1025 | long lineno; /* actual line number */ | |
1026 | } lineno_list_t; | |
1027 | ||
1028 | static lineno_list_t *first_lineno; | |
1029 | static lineno_list_t **last_lineno_ptr = &first_lineno; | |
1030 | ||
1031 | /* Sometimes there will be some .loc statements before a .ent. We | |
1032 | keep them in this list so that we can fill in the procedure pointer | |
1033 | after we see the .ent. */ | |
1034 | static lineno_list_t *noproc_lineno; | |
1035 | ||
1036 | /* Union of various things that are held in pages. */ | |
1037 | typedef union page { | |
1038 | char byte [ PAGE_SIZE ]; | |
1039 | unsigned char ubyte [ PAGE_SIZE ]; | |
1040 | efdr_t file [ PAGE_SIZE / sizeof (efdr_t) ]; | |
1041 | FDR ofile [ PAGE_SIZE / sizeof (FDR) ]; | |
1042 | proc_t proc [ PAGE_SIZE / sizeof (proc_t) ]; | |
1043 | localsym_t sym [ PAGE_SIZE / sizeof (localsym_t) ]; | |
1044 | aux_t aux [ PAGE_SIZE / sizeof (aux_t) ]; | |
1045 | DNR dense [ PAGE_SIZE / sizeof (DNR) ]; | |
1046 | scope_t scope [ PAGE_SIZE / sizeof (scope_t) ]; | |
1047 | vlinks_t vlinks [ PAGE_SIZE / sizeof (vlinks_t) ]; | |
1048 | shash_t shash [ PAGE_SIZE / sizeof (shash_t) ]; | |
1049 | thash_t thash [ PAGE_SIZE / sizeof (thash_t) ]; | |
1050 | tag_t tag [ PAGE_SIZE / sizeof (tag_t) ]; | |
1051 | forward_t forward [ PAGE_SIZE / sizeof (forward_t) ]; | |
1052 | thead_t thead [ PAGE_SIZE / sizeof (thead_t) ]; | |
1053 | lineno_list_t lineno [ PAGE_SIZE / sizeof (lineno_list_t) ]; | |
1054 | } page_t; | |
1055 | ||
1056 | ||
1057 | /* Structure holding allocation information for small sized structures. */ | |
1058 | typedef struct alloc_info { | |
1059 | char *alloc_name; /* name of this allocation type (must be first) */ | |
1060 | page_t *cur_page; /* current page being allocated from */ | |
1061 | small_free_t free_list; /* current free list if any */ | |
1062 | int unallocated; /* number of elements unallocated on page */ | |
1063 | int total_alloc; /* total number of allocations */ | |
1064 | int total_free; /* total number of frees */ | |
1065 | int total_pages; /* total number of pages allocated */ | |
1066 | } alloc_info_t; | |
1067 | ||
1068 | ||
1069 | /* Type information collected together. */ | |
1070 | typedef struct type_info { | |
1071 | bt_t basic_type; /* basic type */ | |
1072 | int orig_type; /* original COFF-based type */ | |
1073 | int num_tq; /* # type qualifiers */ | |
1074 | int num_dims; /* # dimensions */ | |
1075 | int num_sizes; /* # sizes */ | |
1076 | int extra_sizes; /* # extra sizes not tied with dims */ | |
1077 | tag_t * tag_ptr; /* tag pointer */ | |
1078 | int bitfield; /* symbol is a bitfield */ | |
1079 | tq_t type_qualifiers[N_TQ]; /* type qualifiers (ptr, func, array)*/ | |
1080 | symint_t dimensions [N_TQ]; /* dimensions for each array */ | |
1081 | symint_t sizes [N_TQ+2]; /* sizes of each array slice + size of | |
1082 | struct/union/enum + bitfield size */ | |
1083 | } type_info_t; | |
1084 | ||
1085 | /* Pre-initialized type_info struct. */ | |
1086 | static const type_info_t type_info_init = { | |
1087 | bt_Nil, /* basic type */ | |
1088 | T_NULL, /* original COFF-based type */ | |
1089 | 0, /* # type qualifiers */ | |
1090 | 0, /* # dimensions */ | |
1091 | 0, /* # sizes */ | |
1092 | 0, /* sizes not tied with dims */ | |
1093 | NULL, /* ptr to tag */ | |
1094 | 0, /* bitfield */ | |
1095 | { /* type qualifiers */ | |
1096 | tq_Nil, | |
1097 | tq_Nil, | |
1098 | tq_Nil, | |
1099 | tq_Nil, | |
1100 | tq_Nil, | |
1101 | tq_Nil, | |
1102 | }, | |
1103 | { /* dimensions */ | |
1104 | 0, | |
1105 | 0, | |
1106 | 0, | |
1107 | 0, | |
1108 | 0, | |
1109 | 0 | |
1110 | }, | |
1111 | { /* sizes */ | |
1112 | 0, | |
1113 | 0, | |
1114 | 0, | |
1115 | 0, | |
1116 | 0, | |
1117 | 0, | |
1118 | 0, | |
1119 | 0, | |
1120 | }, | |
1121 | }; | |
1122 | ||
1123 | /* Global hash table for the tags table and global table for file | |
1124 | descriptors. */ | |
1125 | ||
1126 | static varray_t file_desc = INIT_VARRAY (efdr_t); | |
1127 | ||
1128 | static struct hash_control *tag_hash; | |
1129 | ||
1130 | /* Static types for int and void. Also, remember the last function's | |
1131 | type (which is set up when we encounter the declaration for the | |
1132 | function, and used when the end block for the function is emitted. */ | |
1133 | ||
1134 | static type_info_t int_type_info; | |
1135 | static type_info_t void_type_info; | |
1136 | static type_info_t last_func_type_info; | |
1137 | static symbolS *last_func_sym_value; | |
1138 | ||
1139 | ||
1140 | /* Convert COFF basic type to ECOFF basic type. The T_NULL type | |
1141 | really should use bt_Void, but this causes the current ecoff GDB to | |
1142 | issue unsupported type messages, and the Ultrix 4.00 dbx (aka MIPS | |
1143 | 2.0) doesn't understand it, even though the compiler generates it. | |
1144 | Maybe this will be fixed in 2.10 or 2.20 of the MIPS compiler | |
1145 | suite, but for now go with what works. | |
1146 | ||
1147 | It would make sense for the .type and .scl directives to use the | |
1148 | ECOFF numbers directly, rather than using the COFF numbers and | |
1149 | mapping them. Unfortunately, this is historically what mips-tfile | |
1150 | expects, and changing gcc now would be a considerable pain (the | |
1151 | native compiler generates debugging information internally, rather | |
1152 | than via the assembler, so it will never use .type or .scl). */ | |
1153 | ||
1154 | static const bt_t map_coff_types[] = { | |
1155 | bt_Nil, /* T_NULL */ | |
1156 | bt_Nil, /* T_ARG */ | |
1157 | bt_Char, /* T_CHAR */ | |
1158 | bt_Short, /* T_SHORT */ | |
1159 | bt_Int, /* T_INT */ | |
1160 | bt_Long, /* T_LONG */ | |
1161 | bt_Float, /* T_FLOAT */ | |
1162 | bt_Double, /* T_DOUBLE */ | |
1163 | bt_Struct, /* T_STRUCT */ | |
1164 | bt_Union, /* T_UNION */ | |
1165 | bt_Enum, /* T_ENUM */ | |
1166 | bt_Enum, /* T_MOE */ | |
1167 | bt_UChar, /* T_UCHAR */ | |
1168 | bt_UShort, /* T_USHORT */ | |
1169 | bt_UInt, /* T_UINT */ | |
1170 | bt_ULong /* T_ULONG */ | |
1171 | }; | |
1172 | ||
1173 | /* Convert COFF storage class to ECOFF storage class. */ | |
1174 | static const sc_t map_coff_storage[] = { | |
1175 | sc_Nil, /* 0: C_NULL */ | |
1176 | sc_Abs, /* 1: C_AUTO auto var */ | |
1177 | sc_Undefined, /* 2: C_EXT external */ | |
1178 | sc_Data, /* 3: C_STAT static */ | |
1179 | sc_Register, /* 4: C_REG register */ | |
1180 | sc_Undefined, /* 5: C_EXTDEF ??? */ | |
1181 | sc_Text, /* 6: C_LABEL label */ | |
1182 | sc_Text, /* 7: C_ULABEL user label */ | |
1183 | sc_Info, /* 8: C_MOS member of struct */ | |
1184 | sc_Abs, /* 9: C_ARG argument */ | |
1185 | sc_Info, /* 10: C_STRTAG struct tag */ | |
1186 | sc_Info, /* 11: C_MOU member of union */ | |
1187 | sc_Info, /* 12: C_UNTAG union tag */ | |
1188 | sc_Info, /* 13: C_TPDEF typedef */ | |
1189 | sc_Data, /* 14: C_USTATIC ??? */ | |
1190 | sc_Info, /* 15: C_ENTAG enum tag */ | |
1191 | sc_Info, /* 16: C_MOE member of enum */ | |
1192 | sc_Register, /* 17: C_REGPARM register parameter */ | |
1193 | sc_Bits, /* 18; C_FIELD bitfield */ | |
1194 | sc_Nil, /* 19 */ | |
1195 | sc_Nil, /* 20 */ | |
1196 | sc_Nil, /* 21 */ | |
1197 | sc_Nil, /* 22 */ | |
1198 | sc_Nil, /* 23 */ | |
1199 | sc_Nil, /* 24 */ | |
1200 | sc_Nil, /* 25 */ | |
1201 | sc_Nil, /* 26 */ | |
1202 | sc_Nil, /* 27 */ | |
1203 | sc_Nil, /* 28 */ | |
1204 | sc_Nil, /* 29 */ | |
1205 | sc_Nil, /* 30 */ | |
1206 | sc_Nil, /* 31 */ | |
1207 | sc_Nil, /* 32 */ | |
1208 | sc_Nil, /* 33 */ | |
1209 | sc_Nil, /* 34 */ | |
1210 | sc_Nil, /* 35 */ | |
1211 | sc_Nil, /* 36 */ | |
1212 | sc_Nil, /* 37 */ | |
1213 | sc_Nil, /* 38 */ | |
1214 | sc_Nil, /* 39 */ | |
1215 | sc_Nil, /* 40 */ | |
1216 | sc_Nil, /* 41 */ | |
1217 | sc_Nil, /* 42 */ | |
1218 | sc_Nil, /* 43 */ | |
1219 | sc_Nil, /* 44 */ | |
1220 | sc_Nil, /* 45 */ | |
1221 | sc_Nil, /* 46 */ | |
1222 | sc_Nil, /* 47 */ | |
1223 | sc_Nil, /* 48 */ | |
1224 | sc_Nil, /* 49 */ | |
1225 | sc_Nil, /* 50 */ | |
1226 | sc_Nil, /* 51 */ | |
1227 | sc_Nil, /* 52 */ | |
1228 | sc_Nil, /* 53 */ | |
1229 | sc_Nil, /* 54 */ | |
1230 | sc_Nil, /* 55 */ | |
1231 | sc_Nil, /* 56 */ | |
1232 | sc_Nil, /* 57 */ | |
1233 | sc_Nil, /* 58 */ | |
1234 | sc_Nil, /* 59 */ | |
1235 | sc_Nil, /* 60 */ | |
1236 | sc_Nil, /* 61 */ | |
1237 | sc_Nil, /* 62 */ | |
1238 | sc_Nil, /* 63 */ | |
1239 | sc_Nil, /* 64 */ | |
1240 | sc_Nil, /* 65 */ | |
1241 | sc_Nil, /* 66 */ | |
1242 | sc_Nil, /* 67 */ | |
1243 | sc_Nil, /* 68 */ | |
1244 | sc_Nil, /* 69 */ | |
1245 | sc_Nil, /* 70 */ | |
1246 | sc_Nil, /* 71 */ | |
1247 | sc_Nil, /* 72 */ | |
1248 | sc_Nil, /* 73 */ | |
1249 | sc_Nil, /* 74 */ | |
1250 | sc_Nil, /* 75 */ | |
1251 | sc_Nil, /* 76 */ | |
1252 | sc_Nil, /* 77 */ | |
1253 | sc_Nil, /* 78 */ | |
1254 | sc_Nil, /* 79 */ | |
1255 | sc_Nil, /* 80 */ | |
1256 | sc_Nil, /* 81 */ | |
1257 | sc_Nil, /* 82 */ | |
1258 | sc_Nil, /* 83 */ | |
1259 | sc_Nil, /* 84 */ | |
1260 | sc_Nil, /* 85 */ | |
1261 | sc_Nil, /* 86 */ | |
1262 | sc_Nil, /* 87 */ | |
1263 | sc_Nil, /* 88 */ | |
1264 | sc_Nil, /* 89 */ | |
1265 | sc_Nil, /* 90 */ | |
1266 | sc_Nil, /* 91 */ | |
1267 | sc_Nil, /* 92 */ | |
1268 | sc_Nil, /* 93 */ | |
1269 | sc_Nil, /* 94 */ | |
1270 | sc_Nil, /* 95 */ | |
1271 | sc_Nil, /* 96 */ | |
1272 | sc_Nil, /* 97 */ | |
1273 | sc_Nil, /* 98 */ | |
1274 | sc_Nil, /* 99 */ | |
1275 | sc_Text, /* 100: C_BLOCK block start/end */ | |
1276 | sc_Text, /* 101: C_FCN function start/end */ | |
1277 | sc_Info, /* 102: C_EOS end of struct/union/enum */ | |
1278 | sc_Nil, /* 103: C_FILE file start */ | |
1279 | sc_Nil, /* 104: C_LINE line number */ | |
1280 | sc_Nil, /* 105: C_ALIAS combined type info */ | |
1281 | sc_Nil, /* 106: C_HIDDEN ??? */ | |
1282 | }; | |
1283 | ||
1284 | /* Convert COFF storage class to ECOFF symbol type. */ | |
1285 | static const st_t map_coff_sym_type[] = { | |
1286 | st_Nil, /* 0: C_NULL */ | |
1287 | st_Local, /* 1: C_AUTO auto var */ | |
1288 | st_Global, /* 2: C_EXT external */ | |
1289 | st_Static, /* 3: C_STAT static */ | |
1290 | st_Local, /* 4: C_REG register */ | |
1291 | st_Global, /* 5: C_EXTDEF ??? */ | |
1292 | st_Label, /* 6: C_LABEL label */ | |
1293 | st_Label, /* 7: C_ULABEL user label */ | |
1294 | st_Member, /* 8: C_MOS member of struct */ | |
1295 | st_Param, /* 9: C_ARG argument */ | |
1296 | st_Block, /* 10: C_STRTAG struct tag */ | |
1297 | st_Member, /* 11: C_MOU member of union */ | |
1298 | st_Block, /* 12: C_UNTAG union tag */ | |
1299 | st_Typedef, /* 13: C_TPDEF typedef */ | |
1300 | st_Static, /* 14: C_USTATIC ??? */ | |
1301 | st_Block, /* 15: C_ENTAG enum tag */ | |
1302 | st_Member, /* 16: C_MOE member of enum */ | |
1303 | st_Param, /* 17: C_REGPARM register parameter */ | |
1304 | st_Member, /* 18; C_FIELD bitfield */ | |
1305 | st_Nil, /* 19 */ | |
1306 | st_Nil, /* 20 */ | |
1307 | st_Nil, /* 21 */ | |
1308 | st_Nil, /* 22 */ | |
1309 | st_Nil, /* 23 */ | |
1310 | st_Nil, /* 24 */ | |
1311 | st_Nil, /* 25 */ | |
1312 | st_Nil, /* 26 */ | |
1313 | st_Nil, /* 27 */ | |
1314 | st_Nil, /* 28 */ | |
1315 | st_Nil, /* 29 */ | |
1316 | st_Nil, /* 30 */ | |
1317 | st_Nil, /* 31 */ | |
1318 | st_Nil, /* 32 */ | |
1319 | st_Nil, /* 33 */ | |
1320 | st_Nil, /* 34 */ | |
1321 | st_Nil, /* 35 */ | |
1322 | st_Nil, /* 36 */ | |
1323 | st_Nil, /* 37 */ | |
1324 | st_Nil, /* 38 */ | |
1325 | st_Nil, /* 39 */ | |
1326 | st_Nil, /* 40 */ | |
1327 | st_Nil, /* 41 */ | |
1328 | st_Nil, /* 42 */ | |
1329 | st_Nil, /* 43 */ | |
1330 | st_Nil, /* 44 */ | |
1331 | st_Nil, /* 45 */ | |
1332 | st_Nil, /* 46 */ | |
1333 | st_Nil, /* 47 */ | |
1334 | st_Nil, /* 48 */ | |
1335 | st_Nil, /* 49 */ | |
1336 | st_Nil, /* 50 */ | |
1337 | st_Nil, /* 51 */ | |
1338 | st_Nil, /* 52 */ | |
1339 | st_Nil, /* 53 */ | |
1340 | st_Nil, /* 54 */ | |
1341 | st_Nil, /* 55 */ | |
1342 | st_Nil, /* 56 */ | |
1343 | st_Nil, /* 57 */ | |
1344 | st_Nil, /* 58 */ | |
1345 | st_Nil, /* 59 */ | |
1346 | st_Nil, /* 60 */ | |
1347 | st_Nil, /* 61 */ | |
1348 | st_Nil, /* 62 */ | |
1349 | st_Nil, /* 63 */ | |
1350 | st_Nil, /* 64 */ | |
1351 | st_Nil, /* 65 */ | |
1352 | st_Nil, /* 66 */ | |
1353 | st_Nil, /* 67 */ | |
1354 | st_Nil, /* 68 */ | |
1355 | st_Nil, /* 69 */ | |
1356 | st_Nil, /* 70 */ | |
1357 | st_Nil, /* 71 */ | |
1358 | st_Nil, /* 72 */ | |
1359 | st_Nil, /* 73 */ | |
1360 | st_Nil, /* 74 */ | |
1361 | st_Nil, /* 75 */ | |
1362 | st_Nil, /* 76 */ | |
1363 | st_Nil, /* 77 */ | |
1364 | st_Nil, /* 78 */ | |
1365 | st_Nil, /* 79 */ | |
1366 | st_Nil, /* 80 */ | |
1367 | st_Nil, /* 81 */ | |
1368 | st_Nil, /* 82 */ | |
1369 | st_Nil, /* 83 */ | |
1370 | st_Nil, /* 84 */ | |
1371 | st_Nil, /* 85 */ | |
1372 | st_Nil, /* 86 */ | |
1373 | st_Nil, /* 87 */ | |
1374 | st_Nil, /* 88 */ | |
1375 | st_Nil, /* 89 */ | |
1376 | st_Nil, /* 90 */ | |
1377 | st_Nil, /* 91 */ | |
1378 | st_Nil, /* 92 */ | |
1379 | st_Nil, /* 93 */ | |
1380 | st_Nil, /* 94 */ | |
1381 | st_Nil, /* 95 */ | |
1382 | st_Nil, /* 96 */ | |
1383 | st_Nil, /* 97 */ | |
1384 | st_Nil, /* 98 */ | |
1385 | st_Nil, /* 99 */ | |
1386 | st_Block, /* 100: C_BLOCK block start/end */ | |
1387 | st_Proc, /* 101: C_FCN function start/end */ | |
1388 | st_End, /* 102: C_EOS end of struct/union/enum */ | |
1389 | st_File, /* 103: C_FILE file start */ | |
1390 | st_Nil, /* 104: C_LINE line number */ | |
1391 | st_Nil, /* 105: C_ALIAS combined type info */ | |
1392 | st_Nil, /* 106: C_HIDDEN ??? */ | |
1393 | }; | |
1394 | ||
1395 | ||
1396 | /* Keep track of different sized allocation requests. */ | |
1397 | static alloc_info_t alloc_counts[ (int)alloc_type_last ]; | |
1398 | \f | |
1399 | /* Various statics. */ | |
1400 | static efdr_t *cur_file_ptr = (efdr_t *) 0; /* current file desc. header */ | |
1401 | static proc_t *cur_proc_ptr = (proc_t *) 0; /* current procedure header */ | |
f6a91cc0 ILT |
1402 | static thead_t *top_tag_head = (thead_t *) 0; /* top level tag head */ |
1403 | static thead_t *cur_tag_head = (thead_t *) 0; /* current tag head */ | |
3d3c5039 ILT |
1404 | #ifdef ECOFF_DEBUG |
1405 | static int debug = 0; /* trace functions */ | |
1406 | #endif | |
1407 | static int stabs_seen = 0; /* != 0 if stabs have been seen */ | |
1408 | ||
1409 | ||
1410 | /* Pseudo symbol to use when putting stabs into the symbol table. */ | |
1411 | #ifndef STABS_SYMBOL | |
1412 | #define STABS_SYMBOL "@stabs" | |
1413 | #endif | |
1414 | ||
1415 | static char stabs_symbol[] = STABS_SYMBOL; | |
1416 | \f | |
1417 | /* Prototypes for functions defined in this file. */ | |
1418 | ||
1419 | static void add_varray_page PARAMS ((varray_t *vp)); | |
1420 | static symint_t add_string PARAMS ((varray_t *vp, | |
1421 | struct hash_control *hash_tbl, | |
1422 | const char *str, | |
1423 | shash_t **ret_hash)); | |
1424 | static localsym_t *add_ecoff_symbol PARAMS ((const char *str, st_t type, | |
1425 | sc_t storage, symbolS *sym, | |
1426 | symint_t value, | |
1427 | symint_t indx)); | |
1428 | static symint_t add_aux_sym_symint PARAMS ((symint_t aux_word)); | |
1429 | static symint_t add_aux_sym_rndx PARAMS ((int file_index, | |
1430 | symint_t sym_index)); | |
1431 | static symint_t add_aux_sym_tir PARAMS ((type_info_t *t, | |
1432 | hash_state_t state, | |
1433 | thash_t **hash_tbl)); | |
1434 | static tag_t *get_tag PARAMS ((const char *tag, localsym_t *sym, | |
1435 | bt_t basic_type)); | |
1436 | static void add_unknown_tag PARAMS ((tag_t *ptag)); | |
1437 | static void add_procedure PARAMS ((char *func)); | |
1438 | static void add_file PARAMS ((const char *file_name, int indx)); | |
1439 | #ifdef ECOFF_DEBUG | |
1440 | static char *sc_to_string PARAMS ((sc_t storage_class)); | |
1441 | static char *st_to_string PARAMS ((st_t symbol_type)); | |
1442 | #endif | |
1443 | static void obj_ecoff_def PARAMS ((int)); | |
1444 | static void obj_ecoff_dim PARAMS ((int)); | |
1445 | static void obj_ecoff_endef PARAMS ((int)); | |
1446 | static void obj_ecoff_file PARAMS ((int)); | |
1447 | static void obj_ecoff_scl PARAMS ((int)); | |
1448 | static void obj_ecoff_size PARAMS ((int)); | |
1449 | static void obj_ecoff_tag PARAMS ((int)); | |
1450 | static void obj_ecoff_type PARAMS ((int)); | |
1451 | static void obj_ecoff_val PARAMS ((int)); | |
1452 | static void obj_ecoff_stab PARAMS ((int)); | |
1453 | static void obj_ecoff_ent PARAMS ((int)); | |
1454 | static void obj_ecoff_begin PARAMS ((int)); | |
1455 | static void obj_ecoff_bend PARAMS ((int)); | |
1456 | static void obj_ecoff_end PARAMS ((int)); | |
1457 | static void obj_ecoff_fmask PARAMS ((int)); | |
1458 | static void obj_ecoff_frame PARAMS ((int)); | |
1459 | static void obj_ecoff_loc PARAMS ((int)); | |
1460 | static void obj_ecoff_mask PARAMS ((int)); | |
1461 | static void mark_stabs PARAMS ((int)); | |
1462 | static char *ecoff_add_bytes PARAMS ((char **buf, char **bufend, | |
1463 | char *bufptr, long need)); | |
1464 | static long ecoff_longword_adjust PARAMS ((char **buf, char **bufend, | |
1465 | long offset, char **bufptrptr)); | |
1466 | static long ecoff_build_lineno PARAMS ((char **buf, char **bufend, | |
1467 | long offset, long *linecntptr)); | |
1468 | static long ecoff_build_symbols PARAMS ((char **buf, char **bufend, | |
1469 | long offset, | |
1470 | char **extbuf, char **extbufend, | |
1471 | long *extoffset, | |
1472 | varray_t *ext_strings, | |
1473 | struct hash_control *ext_str_hash)); | |
1474 | static long ecoff_build_procs PARAMS ((char **buf, char **bufend, | |
1475 | long offset)); | |
1476 | static long ecoff_build_aux PARAMS ((char **buf, char **bufend, | |
1477 | long offset)); | |
1478 | static long ecoff_build_strings PARAMS ((char **buf, char **bufend, | |
1479 | long offset, | |
1480 | varray_t *vp)); | |
1481 | static long ecoff_build_ss PARAMS ((char **buf, char **bufend, | |
1482 | long offset)); | |
1483 | static long ecoff_build_fdr PARAMS ((char **buf, char **bufend, | |
1484 | long offset)); | |
3d3c5039 ILT |
1485 | static page_t *allocate_cluster PARAMS ((unsigned long npages)); |
1486 | static page_t *allocate_page PARAMS ((void)); | |
1487 | static scope_t *allocate_scope PARAMS ((void)); | |
1488 | static void free_scope PARAMS ((scope_t *ptr)); | |
1489 | static vlinks_t *allocate_vlinks PARAMS ((void)); | |
1490 | static shash_t *allocate_shash PARAMS ((void)); | |
1491 | static thash_t *allocate_thash PARAMS ((void)); | |
1492 | static tag_t *allocate_tag PARAMS ((void)); | |
1493 | static void free_tag PARAMS ((tag_t *ptr)); | |
1494 | static forward_t *allocate_forward PARAMS ((void)); | |
1495 | static thead_t *allocate_thead PARAMS ((void)); | |
1496 | static void free_thead PARAMS ((thead_t *ptr)); | |
1497 | static lineno_list_t *allocate_lineno_list PARAMS ((void)); | |
1498 | ||
1499 | /* Why isn't this in some header file somewhere? In fact, is it even | |
1500 | necessary? */ | |
1501 | #define SKIP_WHITESPACES() \ | |
1502 | do \ | |
1503 | { \ | |
1504 | while (*input_line_pointer == ' ' \ | |
1505 | || *input_line_pointer == '\t') \ | |
1506 | ++input_line_pointer; \ | |
1507 | } \ | |
1508 | while (0) | |
1509 | \f | |
1510 | /* These are the pseudo-ops we support in this file. Only those | |
1511 | relating to debugging information are supported here. | |
1512 | ||
1513 | The following pseudo-ops from the Kane and Heinrich MIPS book | |
1514 | should be defined here, but are currently unsupported: .aent, | |
1515 | .bgnb, .endb, .verstamp, .vreg. | |
1516 | ||
1517 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
1518 | MIPS CPU specific, and should be defined by tc-mips.c: .alias, | |
1519 | .extern, .galive, .gjaldef, .gjrlive, .livereg, .noalias, .option, | |
1520 | .rdata, .sdata, .set. | |
1521 | ||
1522 | The following pseudo-ops from the Kane and Heinrich MIPS book are | |
1523 | not MIPS CPU specific, but are also not ECOFF specific. I have | |
1524 | only listed the ones which are not already in read.c. It's not | |
1525 | completely clear where these should be defined, but tc-mips.c is | |
1526 | probably the most reasonable place: .asciiz, .asm0, .endr, .err, | |
1527 | .half, .lab, .repeat, .struct, .weakext. */ | |
1528 | ||
1529 | const pseudo_typeS obj_pseudo_table[] = | |
1530 | { | |
1531 | /* COFF style debugging information. .ln is not used; .loc is used | |
1532 | instead. */ | |
1533 | { "def", obj_ecoff_def, 0 }, | |
1534 | { "dim", obj_ecoff_dim, 0 }, | |
1535 | { "endef", obj_ecoff_endef, 0 }, | |
1536 | { "file", obj_ecoff_file, 0 }, | |
1537 | { "scl", obj_ecoff_scl, 0 }, | |
1538 | { "size", obj_ecoff_size, 0 }, | |
1539 | { "tag", obj_ecoff_tag, 0 }, | |
1540 | { "type", obj_ecoff_type, 0 }, | |
1541 | { "val", obj_ecoff_val, 0 }, | |
1542 | ||
1543 | /* stabs debugging information. */ | |
1544 | { "stabd", obj_ecoff_stab, 'd' }, | |
1545 | { "stabn", obj_ecoff_stab, 'n' }, | |
1546 | { "stabs", obj_ecoff_stab, 's' }, | |
1547 | ||
1548 | /* ECOFF specific debugging information. */ | |
1549 | { "begin", obj_ecoff_begin, 0 }, | |
1550 | { "bend", obj_ecoff_bend, 0 }, | |
1551 | { "end", obj_ecoff_end, 0 }, | |
1552 | { "ent", obj_ecoff_ent, 0 }, | |
1553 | { "fmask", obj_ecoff_fmask, 0 }, | |
1554 | { "frame", obj_ecoff_frame, 0 }, | |
1555 | { "loc", obj_ecoff_loc, 0 }, | |
1556 | { "mask", obj_ecoff_mask, 0 }, | |
1557 | ||
1558 | /* Sentinel. */ | |
1559 | { NULL } | |
1560 | }; | |
1561 | \f | |
1562 | /* This function is called when the assembler starts up. */ | |
1563 | ||
1564 | void | |
1565 | obj_read_begin_hook () | |
1566 | { | |
1567 | tag_hash = hash_new (); | |
f6a91cc0 ILT |
1568 | top_tag_head = allocate_thead (); |
1569 | top_tag_head->first_tag = (tag_t *) NULL; | |
1570 | top_tag_head->free = (thead_t *) NULL; | |
1571 | top_tag_head->prev = cur_tag_head; | |
1572 | cur_tag_head = top_tag_head; | |
3d3c5039 ILT |
1573 | } |
1574 | ||
1575 | /* This function is called when a symbol is created. */ | |
1576 | ||
1577 | void | |
1578 | obj_symbol_new_hook (symbolP) | |
1579 | symbolS *symbolP; | |
1580 | { | |
918692a5 ILT |
1581 | if (cur_file_ptr == (efdr_t *) NULL) |
1582 | add_file ((const char *) NULL, 0); | |
3d3c5039 ILT |
1583 | symbolP->ecoff_file = cur_file_ptr; |
1584 | symbolP->ecoff_symbol = 0; | |
670a50eb | 1585 | symbolP->ecoff_undefined = 0; |
3d3c5039 ILT |
1586 | } |
1587 | \f | |
1588 | /* Add a page to a varray object. */ | |
1589 | ||
1590 | static void | |
1591 | add_varray_page (vp) | |
1592 | varray_t *vp; /* varray to add page to */ | |
1593 | { | |
1594 | vlinks_t *new_links = allocate_vlinks (); | |
1595 | ||
1596 | #ifdef MALLOC_CHECK | |
1597 | if (vp->object_size > 1) | |
1598 | new_links->datum = (page_t *) xcalloc (1, vp->object_size); | |
1599 | else | |
1600 | #endif | |
1601 | new_links->datum = allocate_page (); | |
1602 | ||
1603 | alloc_counts[(int)alloc_type_varray].total_alloc++; | |
1604 | alloc_counts[(int)alloc_type_varray].total_pages++; | |
1605 | ||
1606 | new_links->start_index = vp->num_allocated; | |
1607 | vp->objects_last_page = 0; | |
1608 | ||
1609 | if (vp->first == (vlinks_t *) NULL) /* first allocation? */ | |
1610 | vp->first = vp->last = new_links; | |
1611 | else | |
1612 | { /* 2nd or greater allocation */ | |
1613 | new_links->prev = vp->last; | |
1614 | vp->last->next = new_links; | |
1615 | vp->last = new_links; | |
1616 | } | |
1617 | } | |
1618 | \f | |
1619 | /* Add a string (and null pad) to one of the string tables. */ | |
1620 | ||
1621 | static symint_t | |
1622 | add_string (vp, hash_tbl, str, ret_hash) | |
1623 | varray_t *vp; /* string obstack */ | |
1624 | struct hash_control *hash_tbl; /* ptr to hash table */ | |
1625 | const char *str; /* string */ | |
1626 | shash_t **ret_hash; /* return hash pointer */ | |
1627 | { | |
1628 | register unsigned int len = strlen (str); | |
1629 | register shash_t *hash_ptr; | |
1630 | ||
1631 | if (len >= PAGE_USIZE) | |
1632 | as_fatal ("String too big (%lu bytes)", len); | |
1633 | ||
1634 | hash_ptr = (shash_t *) hash_find (hash_tbl, str); | |
1635 | if (hash_ptr == (shash_t *) NULL) | |
1636 | { | |
1637 | register char *err; | |
1638 | ||
1639 | if (vp->objects_last_page + len >= PAGE_USIZE) | |
1640 | { | |
1641 | vp->num_allocated = | |
1642 | ((vp->num_allocated + PAGE_USIZE - 1) / PAGE_USIZE) * PAGE_USIZE; | |
1643 | add_varray_page (vp); | |
1644 | } | |
1645 | ||
1646 | hash_ptr = allocate_shash (); | |
1647 | hash_ptr->indx = vp->num_allocated; | |
1648 | ||
1649 | hash_ptr->string = &vp->last->datum->byte[vp->objects_last_page]; | |
1650 | ||
1651 | vp->objects_last_page += len + 1; | |
1652 | vp->num_allocated += len + 1; | |
1653 | ||
1654 | strcpy (hash_ptr->string, str); | |
1655 | ||
1656 | err = hash_insert (hash_tbl, str, (char *) hash_ptr); | |
1657 | if (*err != '\0') | |
1658 | as_fatal ("Inserting \"%s\" into string hash table: %s", | |
1659 | str, err); | |
1660 | } | |
1661 | ||
1662 | if (ret_hash != (shash_t **) NULL) | |
1663 | *ret_hash = hash_ptr; | |
1664 | ||
1665 | return hash_ptr->indx; | |
1666 | } | |
1667 | \f | |
1668 | /* Add debugging information for a symbol. */ | |
1669 | ||
1670 | static localsym_t * | |
1671 | add_ecoff_symbol (str, type, storage, sym_value, value, indx) | |
1672 | const char *str; /* symbol name */ | |
1673 | st_t type; /* symbol type */ | |
1674 | sc_t storage; /* storage class */ | |
1675 | symbolS *sym_value; /* associated symbol. */ | |
1676 | symint_t value; /* value of symbol */ | |
1677 | symint_t indx; /* index to local/aux. syms */ | |
1678 | { | |
1679 | localsym_t *psym; | |
1680 | register scope_t *pscope; | |
1681 | register thead_t *ptag_head; | |
1682 | register tag_t *ptag; | |
1683 | register tag_t *ptag_next; | |
918692a5 | 1684 | register varray_t *vp; |
3d3c5039 ILT |
1685 | register int scope_delta = 0; |
1686 | shash_t *hash_ptr = (shash_t *) NULL; | |
1687 | ||
1688 | if (cur_file_ptr == (efdr_t *) NULL) | |
1689 | as_fatal ("no current file pointer"); | |
1690 | ||
1691 | vp = &cur_file_ptr->symbols; | |
1692 | ||
1693 | if (vp->objects_last_page == vp->objects_per_page) | |
1694 | add_varray_page (vp); | |
1695 | ||
1696 | psym = &vp->last->datum->sym[ vp->objects_last_page++ ]; | |
1697 | ||
f6a91cc0 ILT |
1698 | if (str == (const char *) NULL && sym_value != (symbolS *) NULL) |
1699 | psym->name = S_GET_NAME (sym_value); | |
1700 | else | |
1701 | psym->name = str; | |
3d3c5039 ILT |
1702 | psym->as_sym = sym_value; |
1703 | if (sym_value != (symbolS *) NULL) | |
1704 | sym_value->ecoff_symbol = 1; | |
1705 | psym->file_ptr = cur_file_ptr; | |
1706 | psym->proc_ptr = cur_proc_ptr; | |
1707 | psym->begin_ptr = (localsym_t *) NULL; | |
1708 | psym->index_ptr = (aux_t *) NULL; | |
1709 | psym->forward_ref = (forward_t *) NULL; | |
1710 | psym->sym_index = -1; | |
1711 | psym->ecoff_sym.value = value; | |
1712 | psym->ecoff_sym.st = (unsigned) type; | |
1713 | psym->ecoff_sym.sc = (unsigned) storage; | |
1714 | psym->ecoff_sym.index = indx; | |
1715 | ||
1716 | /* If there is an associated symbol, we wait until the end of the | |
1717 | assembly before deciding where to put the name (it may be just an | |
1718 | external symbol). Otherwise, this is just a debugging symbol and | |
1719 | the name should go with the current file. */ | |
1720 | if (sym_value == (symbolS *) NULL) | |
1721 | psym->ecoff_sym.iss = ((str == (const char *) NULL) | |
1722 | ? 0 | |
1723 | : add_string (&cur_file_ptr->strings, | |
1724 | cur_file_ptr->str_hash, | |
1725 | str, | |
1726 | &hash_ptr)); | |
1727 | ||
1728 | ++vp->num_allocated; | |
1729 | ||
1730 | if (MIPS_IS_STAB (&psym->ecoff_sym)) | |
1731 | return psym; | |
1732 | ||
1733 | /* Save the symbol within the hash table if this is a static | |
1734 | item, and it has a name. */ | |
1735 | if (hash_ptr != (shash_t *) NULL | |
1736 | && (type == st_Global || type == st_Static || type == st_Label | |
1737 | || type == st_Proc || type == st_StaticProc)) | |
1738 | hash_ptr->sym_ptr = psym; | |
1739 | ||
1740 | /* push or pop a scope if appropriate. */ | |
1741 | switch (type) | |
1742 | { | |
1743 | default: | |
1744 | break; | |
1745 | ||
1746 | case st_File: /* beginning of file */ | |
1747 | case st_Proc: /* procedure */ | |
1748 | case st_StaticProc: /* static procedure */ | |
1749 | case st_Block: /* begin scope */ | |
1750 | pscope = allocate_scope (); | |
1751 | pscope->prev = cur_file_ptr->cur_scope; | |
1752 | pscope->lsym = psym; | |
1753 | pscope->type = type; | |
1754 | cur_file_ptr->cur_scope = pscope; | |
1755 | ||
1756 | if (type != st_File) | |
1757 | scope_delta = 1; | |
1758 | ||
1759 | /* For every block type except file, struct, union, or | |
1760 | enumeration blocks, push a level on the tag stack. We omit | |
1761 | file types, so that tags can span file boundaries. */ | |
1762 | if (type != st_File && storage != sc_Info) | |
1763 | { | |
1764 | ptag_head = allocate_thead (); | |
1765 | ptag_head->first_tag = 0; | |
1766 | ptag_head->prev = cur_tag_head; | |
1767 | cur_tag_head = ptag_head; | |
1768 | } | |
1769 | break; | |
1770 | ||
1771 | case st_End: | |
1772 | pscope = cur_file_ptr->cur_scope; | |
1773 | if (pscope == (scope_t *) NULL) | |
1774 | as_fatal ("too many st_End's"); | |
1775 | else | |
1776 | { | |
1777 | st_t begin_type = (st_t) pscope->lsym->ecoff_sym.st; | |
1778 | ||
1779 | psym->begin_ptr = pscope->lsym; | |
1780 | ||
1781 | if (begin_type != st_File) | |
1782 | scope_delta = -1; | |
1783 | ||
1784 | /* Except for file, structure, union, or enumeration end | |
1785 | blocks remove all tags created within this scope. */ | |
1786 | if (begin_type != st_File && storage != sc_Info) | |
1787 | { | |
1788 | ptag_head = cur_tag_head; | |
1789 | cur_tag_head = ptag_head->prev; | |
1790 | ||
1791 | for (ptag = ptag_head->first_tag; | |
1792 | ptag != (tag_t *) NULL; | |
1793 | ptag = ptag_next) | |
1794 | { | |
1795 | if (ptag->forward_ref != (forward_t *) NULL) | |
1796 | add_unknown_tag (ptag); | |
1797 | ||
1798 | ptag_next = ptag->same_block; | |
1799 | ptag->hash_ptr->tag_ptr = ptag->same_name; | |
1800 | free_tag (ptag); | |
1801 | } | |
1802 | ||
1803 | free_thead (ptag_head); | |
1804 | } | |
1805 | ||
1806 | cur_file_ptr->cur_scope = pscope->prev; | |
1807 | ||
1808 | /* block begin gets next sym #. This is set when we know | |
1809 | the symbol index value. */ | |
1810 | ||
1811 | /* Functions push two or more aux words as follows: | |
1812 | 1st word: index+1 of the end symbol (filled in later). | |
1813 | 2nd word: type of the function (plus any aux words needed). | |
1814 | Also, tie the external pointer back to the function begin symbol. */ | |
1815 | if (begin_type != st_File && begin_type != st_Block) | |
1816 | { | |
1817 | symint_t type; | |
1818 | varray_t *vp = &cur_file_ptr->aux_syms; | |
1819 | ||
1820 | pscope->lsym->ecoff_sym.index = add_aux_sym_symint (0); | |
1821 | pscope->lsym->index_ptr = | |
1822 | &vp->last->datum->aux[vp->objects_last_page - 1]; | |
1823 | type = add_aux_sym_tir (&last_func_type_info, | |
1824 | hash_no, | |
1825 | &cur_file_ptr->thash_head[0]); | |
1826 | /* | |
1827 | if (last_func_sym_value != (symbolS *) NULL) | |
1828 | { | |
1829 | last_func_sym_value->ifd = cur_file_ptr->file_index; | |
1830 | last_func_sym_value->index = type; | |
1831 | } | |
1832 | */ | |
1833 | } | |
1834 | ||
1835 | free_scope (pscope); | |
1836 | } | |
1837 | } | |
1838 | ||
1839 | cur_file_ptr->nested_scopes += scope_delta; | |
1840 | ||
1841 | #ifdef ECOFF_DEBUG | |
1842 | if (debug && type != st_File | |
1843 | && (debug > 2 || type == st_Block || type == st_End | |
1844 | || type == st_Proc || type == st_StaticProc)) | |
1845 | { | |
1846 | char *sc_str = sc_to_string (storage); | |
1847 | char *st_str = st_to_string (type); | |
1848 | int depth = cur_file_ptr->nested_scopes + (scope_delta < 0); | |
1849 | ||
1850 | fprintf (stderr, | |
1851 | "\tlsym\tv= %10ld, depth= %2d, sc= %-12s", | |
1852 | value, depth, sc_str); | |
1853 | ||
1854 | if (str_start && str_end_p1 - str_start > 0) | |
1855 | fprintf (stderr, " st= %-11s name= %.*s\n", st_str, str_end_p1 - str_start, str_start); | |
1856 | else | |
1857 | { | |
1858 | unsigned long len = strlen (st_str); | |
1859 | fprintf (stderr, " st= %.*s\n", len-1, st_str); | |
1860 | } | |
1861 | } | |
1862 | #endif | |
1863 | ||
1864 | return psym; | |
1865 | } | |
1866 | \f | |
1867 | /* Add an auxiliary symbol (passing a symint). This is actually used | |
1868 | for integral aux types, not just symints. */ | |
1869 | ||
1870 | static symint_t | |
1871 | add_aux_sym_symint (aux_word) | |
1872 | symint_t aux_word; /* auxiliary information word */ | |
1873 | { | |
1874 | register varray_t *vp; | |
1875 | register aux_t *aux_ptr; | |
1876 | ||
1877 | if (cur_file_ptr == (efdr_t *) NULL) | |
1878 | as_fatal ("no current file pointer"); | |
1879 | ||
1880 | vp = &cur_file_ptr->aux_syms; | |
1881 | ||
1882 | if (vp->objects_last_page == vp->objects_per_page) | |
1883 | add_varray_page (vp); | |
1884 | ||
1885 | aux_ptr = &vp->last->datum->aux[vp->objects_last_page++]; | |
1886 | aux_ptr->type = aux_isym; | |
1887 | aux_ptr->data.isym = aux_word; | |
1888 | ||
1889 | return vp->num_allocated++; | |
1890 | } | |
1891 | ||
1892 | ||
1893 | /* Add an auxiliary symbol (passing a file/symbol index combo). */ | |
1894 | ||
1895 | static symint_t | |
1896 | add_aux_sym_rndx (file_index, sym_index) | |
1897 | int file_index; | |
1898 | symint_t sym_index; | |
1899 | { | |
1900 | register varray_t *vp; | |
1901 | register aux_t *aux_ptr; | |
1902 | ||
1903 | if (cur_file_ptr == (efdr_t *) NULL) | |
1904 | as_fatal ("no current file pointer"); | |
1905 | ||
1906 | vp = &cur_file_ptr->aux_syms; | |
1907 | ||
1908 | if (vp->objects_last_page == vp->objects_per_page) | |
1909 | add_varray_page (vp); | |
1910 | ||
1911 | aux_ptr = &vp->last->datum->aux[vp->objects_last_page++]; | |
1912 | aux_ptr->type = aux_rndx; | |
1913 | aux_ptr->data.rndx.rfd = file_index; | |
1914 | aux_ptr->data.rndx.index = sym_index; | |
1915 | ||
1916 | return vp->num_allocated++; | |
1917 | } | |
1918 | \f | |
1919 | /* Add an auxiliary symbol (passing the basic type and possibly | |
1920 | type qualifiers). */ | |
1921 | ||
1922 | static symint_t | |
1923 | add_aux_sym_tir (t, state, hash_tbl) | |
1924 | type_info_t *t; /* current type information */ | |
1925 | hash_state_t state; /* whether to hash type or not */ | |
1926 | thash_t **hash_tbl; /* pointer to hash table to use */ | |
1927 | { | |
1928 | register varray_t *vp; | |
1929 | register aux_t *aux_ptr; | |
1930 | static AUXU init_aux; | |
1931 | symint_t ret; | |
1932 | int i; | |
1933 | AUXU aux; | |
1934 | ||
1935 | if (cur_file_ptr == (efdr_t *) NULL) | |
1936 | as_fatal ("no current file pointer"); | |
1937 | ||
1938 | vp = &cur_file_ptr->aux_syms; | |
1939 | ||
1940 | aux = init_aux; | |
1941 | aux.ti.bt = (int) t->basic_type; | |
1942 | aux.ti.continued = 0; | |
1943 | aux.ti.fBitfield = t->bitfield; | |
1944 | ||
1945 | aux.ti.tq0 = (int) t->type_qualifiers[0]; | |
1946 | aux.ti.tq1 = (int) t->type_qualifiers[1]; | |
1947 | aux.ti.tq2 = (int) t->type_qualifiers[2]; | |
1948 | aux.ti.tq3 = (int) t->type_qualifiers[3]; | |
1949 | aux.ti.tq4 = (int) t->type_qualifiers[4]; | |
1950 | aux.ti.tq5 = (int) t->type_qualifiers[5]; | |
1951 | ||
1952 | ||
1953 | /* For anything that adds additional information, we must not hash, | |
1954 | so check here, and reset our state. */ | |
1955 | ||
1956 | if (state != hash_no | |
1957 | && (t->type_qualifiers[0] == tq_Array | |
1958 | || t->type_qualifiers[1] == tq_Array | |
1959 | || t->type_qualifiers[2] == tq_Array | |
1960 | || t->type_qualifiers[3] == tq_Array | |
1961 | || t->type_qualifiers[4] == tq_Array | |
1962 | || t->type_qualifiers[5] == tq_Array | |
1963 | || t->basic_type == bt_Struct | |
1964 | || t->basic_type == bt_Union | |
1965 | || t->basic_type == bt_Enum | |
1966 | || t->bitfield | |
1967 | || t->num_dims > 0)) | |
1968 | state = hash_no; | |
1969 | ||
1970 | /* See if we can hash this type, and save some space, but some types | |
1971 | can't be hashed (because they contain arrays or continuations), | |
1972 | and others can be put into the hash list, but cannot use existing | |
1973 | types because other aux entries precede this one. */ | |
1974 | ||
1975 | if (state != hash_no) | |
1976 | { | |
1977 | register thash_t *hash_ptr; | |
1978 | register symint_t hi; | |
1979 | ||
1980 | hi = aux.isym & ((1 << HASHBITS) - 1); | |
1981 | hi %= THASH_SIZE; | |
1982 | ||
1983 | for (hash_ptr = hash_tbl[hi]; | |
1984 | hash_ptr != (thash_t *)0; | |
1985 | hash_ptr = hash_ptr->next) | |
1986 | { | |
1987 | if (aux.isym == hash_ptr->type.isym) | |
1988 | break; | |
1989 | } | |
1990 | ||
1991 | if (hash_ptr != (thash_t *) NULL && state == hash_yes) | |
1992 | return hash_ptr->indx; | |
1993 | ||
1994 | if (hash_ptr == (thash_t *) NULL) | |
1995 | { | |
1996 | hash_ptr = allocate_thash (); | |
1997 | hash_ptr->next = hash_tbl[hi]; | |
1998 | hash_ptr->type = aux; | |
1999 | hash_ptr->indx = vp->num_allocated; | |
2000 | hash_tbl[hi] = hash_ptr; | |
2001 | } | |
2002 | } | |
2003 | ||
2004 | /* Everything is set up, add the aux symbol. */ | |
2005 | if (vp->objects_last_page == vp->objects_per_page) | |
2006 | add_varray_page (vp); | |
2007 | ||
2008 | aux_ptr = &vp->last->datum->aux[ vp->objects_last_page++ ]; | |
2009 | aux_ptr->type = aux_tir; | |
2010 | aux_ptr->data = aux; | |
2011 | ||
2012 | ret = vp->num_allocated++; | |
2013 | ||
2014 | /* Add bitfield length if it exists. | |
2015 | ||
2016 | NOTE: Mips documentation claims bitfield goes at the end of the | |
2017 | AUX record, but the DECstation compiler emits it here. | |
2018 | (This would only make a difference for enum bitfields.) | |
2019 | ||
2020 | Also note: We use the last size given since gcc may emit 2 | |
2021 | for an enum bitfield. */ | |
2022 | ||
2023 | if (t->bitfield) | |
2024 | (void) add_aux_sym_symint ((symint_t)t->sizes[t->num_sizes-1]); | |
2025 | ||
2026 | ||
2027 | /* Add tag information if needed. Structure, union, and enum | |
2028 | references add 2 aux symbols: a [file index, symbol index] | |
2029 | pointer to the structure type, and the current file index. */ | |
2030 | ||
2031 | if (t->basic_type == bt_Struct | |
2032 | || t->basic_type == bt_Union | |
2033 | || t->basic_type == bt_Enum) | |
2034 | { | |
2035 | register symint_t file_index = t->tag_ptr->ifd; | |
2036 | register localsym_t *sym = t->tag_ptr->sym; | |
2037 | register forward_t *forward_ref = allocate_forward (); | |
2038 | ||
2039 | if (sym != (localsym_t *) NULL) | |
2040 | { | |
2041 | forward_ref->next = sym->forward_ref; | |
2042 | sym->forward_ref = forward_ref; | |
2043 | } | |
2044 | else | |
2045 | { | |
2046 | forward_ref->next = t->tag_ptr->forward_ref; | |
2047 | t->tag_ptr->forward_ref = forward_ref; | |
2048 | } | |
2049 | ||
2050 | (void) add_aux_sym_rndx (ST_RFDESCAPE, indexNil); | |
2051 | forward_ref->index_ptr | |
2052 | = &vp->last->datum->aux[ vp->objects_last_page - 1]; | |
2053 | ||
2054 | (void) add_aux_sym_symint (file_index); | |
2055 | forward_ref->ifd_ptr | |
2056 | = &vp->last->datum->aux[ vp->objects_last_page - 1]; | |
2057 | } | |
2058 | ||
2059 | /* Add information about array bounds if they exist. */ | |
2060 | for (i = 0; i < t->num_dims; i++) | |
2061 | { | |
2062 | (void) add_aux_sym_rndx (ST_RFDESCAPE, | |
2063 | cur_file_ptr->int_type); | |
2064 | ||
2065 | (void) add_aux_sym_symint (cur_file_ptr->file_index); /* file index*/ | |
2066 | (void) add_aux_sym_symint ((symint_t) 0); /* low bound */ | |
2067 | (void) add_aux_sym_symint (t->dimensions[i] - 1); /* high bound*/ | |
2068 | (void) add_aux_sym_symint ((t->dimensions[i] == 0) /* stride */ | |
2069 | ? 0 | |
2070 | : (t->sizes[i] * 8) / t->dimensions[i]); | |
2071 | }; | |
2072 | ||
2073 | /* NOTE: Mips documentation claims that the bitfield width goes here. | |
2074 | But it needs to be emitted earlier. */ | |
2075 | ||
2076 | return ret; | |
2077 | } | |
2078 | \f | |
2079 | /* Add a tag to the tag table (unless it already exists). */ | |
2080 | ||
2081 | static tag_t * | |
2082 | get_tag (tag, sym, basic_type) | |
2083 | const char *tag; /* tag name */ | |
2084 | localsym_t *sym; /* tag start block */ | |
2085 | bt_t basic_type; /* bt_Struct, bt_Union, or bt_Enum */ | |
2086 | { | |
2087 | shash_t *hash_ptr; | |
2088 | char *err; | |
2089 | tag_t *tag_ptr; | |
2090 | ||
2091 | if (cur_file_ptr == (efdr_t *) NULL) | |
2092 | as_fatal ("no current file pointer"); | |
2093 | ||
2094 | hash_ptr = (shash_t *) hash_find (tag_hash, tag); | |
2095 | ||
2096 | if (hash_ptr != (shash_t *) NULL | |
2097 | && hash_ptr->tag_ptr != (tag_t *) NULL) | |
2098 | { | |
2099 | tag_ptr = hash_ptr->tag_ptr; | |
2100 | if (sym != (localsym_t *) NULL) | |
2101 | { | |
2102 | tag_ptr->basic_type = basic_type; | |
2103 | tag_ptr->ifd = cur_file_ptr->file_index; | |
2104 | tag_ptr->sym = sym; | |
2105 | } | |
2106 | return tag_ptr; | |
2107 | } | |
2108 | ||
2109 | if (hash_ptr == (shash_t *) NULL) | |
2110 | { | |
2111 | hash_ptr = allocate_shash (); | |
2112 | err = hash_insert (tag_hash, tag, (char *) hash_ptr); | |
2113 | if (*err != '\0') | |
2114 | as_fatal ("Inserting \"%s\" into tag hash table: %s", | |
2115 | tag, err); | |
2116 | } | |
2117 | ||
2118 | tag_ptr = allocate_tag (); | |
2119 | tag_ptr->forward_ref = (forward_t *) NULL; | |
2120 | tag_ptr->hash_ptr = hash_ptr; | |
2121 | tag_ptr->same_name = hash_ptr->tag_ptr; | |
2122 | tag_ptr->basic_type = basic_type; | |
2123 | tag_ptr->sym = sym; | |
2124 | tag_ptr->ifd = ((sym == (localsym_t *) NULL) | |
2125 | ? -1 | |
2126 | : cur_file_ptr->file_index); | |
2127 | tag_ptr->same_block = cur_tag_head->first_tag; | |
2128 | ||
2129 | cur_tag_head->first_tag = tag_ptr; | |
2130 | hash_ptr->tag_ptr = tag_ptr; | |
2131 | ||
2132 | return tag_ptr; | |
2133 | } | |
2134 | \f | |
2135 | /* Add an unknown {struct, union, enum} tag. */ | |
2136 | ||
2137 | static void | |
2138 | add_unknown_tag (ptag) | |
2139 | tag_t *ptag; /* pointer to tag information */ | |
2140 | { | |
2141 | shash_t *hash_ptr = ptag->hash_ptr; | |
2142 | char *name = hash_ptr->string; | |
2143 | localsym_t *sym; | |
2144 | forward_t **pf; | |
2145 | ||
2146 | #ifdef ECOFF_DEBUG | |
2147 | if (debug > 1) | |
2148 | { | |
2149 | char *agg_type = "{unknown aggregate type}"; | |
2150 | switch (ptag->basic_type) | |
2151 | { | |
2152 | case bt_Struct: agg_type = "struct"; break; | |
2153 | case bt_Union: agg_type = "union"; break; | |
2154 | case bt_Enum: agg_type = "enum"; break; | |
2155 | default: break; | |
2156 | } | |
2157 | ||
2158 | fprintf (stderr, "unknown %s %.*s found\n", agg_type, | |
2159 | hash_ptr->len, name_start); | |
2160 | } | |
2161 | #endif | |
2162 | ||
2163 | sym = add_ecoff_symbol (name, | |
2164 | st_Block, | |
2165 | sc_Info, | |
2166 | (symbolS *) NULL, | |
2167 | (symint_t) 0, | |
2168 | (symint_t) 0); | |
2169 | ||
2170 | (void) add_ecoff_symbol (name, | |
2171 | st_End, | |
2172 | sc_Info, | |
2173 | (symbolS *) NULL, | |
2174 | (symint_t) 0, | |
2175 | (symint_t) 0); | |
2176 | ||
2177 | for (pf = &sym->forward_ref; *pf != (forward_t *) NULL; pf = &(*pf)->next) | |
2178 | ; | |
2179 | *pf = ptag->forward_ref; | |
2180 | } | |
2181 | \f | |
2182 | /* Add a procedure to the current file's list of procedures, and record | |
2183 | this is the current procedure. */ | |
2184 | ||
2185 | static void | |
2186 | add_procedure (func) | |
2187 | char *func; /* func name */ | |
2188 | { | |
2189 | register varray_t *vp; | |
2190 | register proc_t *new_proc_ptr; | |
2191 | ||
2192 | #ifdef ECOFF_DEBUG | |
2193 | if (debug) | |
2194 | fputc ('\n', stderr); | |
2195 | #endif | |
2196 | ||
2197 | if (cur_file_ptr == (efdr_t *) NULL) | |
2198 | as_fatal ("no current file pointer"); | |
2199 | ||
2200 | vp = &cur_file_ptr->procs; | |
2201 | ||
2202 | if (vp->objects_last_page == vp->objects_per_page) | |
2203 | add_varray_page (vp); | |
2204 | ||
2205 | cur_proc_ptr = new_proc_ptr = &vp->last->datum->proc[vp->objects_last_page++]; | |
2206 | ||
2207 | vp->num_allocated++; | |
2208 | ||
2209 | new_proc_ptr->pdr.isym = -1; | |
2210 | new_proc_ptr->pdr.iline = -1; | |
670a50eb ILT |
2211 | new_proc_ptr->pdr.lnLow = -1; |
2212 | new_proc_ptr->pdr.lnHigh = -1; | |
3d3c5039 ILT |
2213 | |
2214 | /* Push the start of the function. */ | |
f6a91cc0 | 2215 | new_proc_ptr->sym = add_ecoff_symbol ((const char *) NULL, st_Proc, sc_Text, |
3d3c5039 ILT |
2216 | symbol_find_or_make (func), |
2217 | (symint_t) 0, (symint_t) 0); | |
2218 | ||
2219 | ++proc_cnt; | |
2220 | ||
2221 | /* Fill in the linenos preceding the .ent, if any. */ | |
2222 | if (noproc_lineno != (lineno_list_t *) NULL) | |
2223 | { | |
2224 | lineno_list_t *l; | |
2225 | ||
2226 | for (l = noproc_lineno; l != (lineno_list_t *) NULL; l = l->next) | |
2227 | l->proc = new_proc_ptr; | |
2228 | *last_lineno_ptr = noproc_lineno; | |
2229 | while (*last_lineno_ptr != NULL) | |
2230 | last_lineno_ptr = &(*last_lineno_ptr)->next; | |
2231 | noproc_lineno = (lineno_list_t *) NULL; | |
2232 | } | |
2233 | } | |
2234 | \f | |
2235 | /* Add a new filename, and set up all of the file relative | |
2236 | virtual arrays (strings, symbols, aux syms, etc.). Record | |
2237 | where the current file structure lives. */ | |
2238 | ||
2239 | static void | |
2240 | add_file (file_name, indx) | |
2241 | const char *file_name; /* file name */ | |
2242 | int indx; | |
2243 | { | |
2244 | register int first_ch; | |
2245 | register efdr_t *fil_ptr; | |
2246 | ||
2247 | #ifdef ECOFF_DEBUG | |
2248 | if (debug) | |
2249 | fprintf (stderr, "\tfile\t%.*s\n", len, file_start); | |
2250 | #endif | |
2251 | ||
2252 | /* If the file name is NULL, then no .file symbol appeared, and we | |
2253 | want to use the actual file name. Unfortunately, we don't have a | |
2254 | clean way to access it. */ | |
2255 | if (file_name == (const char *) NULL) | |
2256 | { | |
2257 | extern char *logical_input_file; | |
2258 | extern char *physical_input_file; | |
2259 | ||
2260 | if (first_file != (efdr_t *) NULL) | |
2261 | as_fatal ("fake .file after real one"); | |
2262 | file_name = logical_input_file; | |
2263 | if (file_name == (const char *) NULL) | |
2264 | { | |
2265 | file_name = physical_input_file; | |
2266 | if (file_name == (const char *) NULL) | |
2267 | file_name = "UNKNOWN"; | |
2268 | } | |
2269 | } | |
2270 | ||
918692a5 ILT |
2271 | #ifndef NO_LISTING |
2272 | if (listing) | |
2273 | listing_source_file (file_name); | |
2274 | #endif | |
2275 | ||
670a50eb ILT |
2276 | /* If we're creating stabs, then we don't actually make a new FDR. |
2277 | Instead, we just create a stabs symbol. */ | |
2278 | if (stabs_seen) | |
2279 | { | |
2280 | (void) add_ecoff_symbol (file_name, st_Nil, sc_Nil, | |
2281 | symbol_new ("L0\001", now_seg, | |
2282 | frag_now_fix (), frag_now), | |
2283 | 0, MIPS_MARK_STAB (N_SOL)); | |
2284 | return; | |
2285 | } | |
2286 | ||
3d3c5039 ILT |
2287 | first_ch = *file_name; |
2288 | ||
2289 | /* See if the file has already been created. */ | |
2290 | for (fil_ptr = first_file; | |
2291 | fil_ptr != (efdr_t *) NULL; | |
2292 | fil_ptr = fil_ptr->next_file) | |
2293 | { | |
2294 | if (first_ch == fil_ptr->name[0] | |
2295 | && strcmp (file_name, fil_ptr->name) == 0) | |
2296 | { | |
2297 | cur_file_ptr = fil_ptr; | |
2298 | break; | |
2299 | } | |
2300 | } | |
2301 | ||
2302 | /* If this is a new file, create it. */ | |
2303 | if (fil_ptr == (efdr_t *) NULL) | |
2304 | { | |
2305 | if (file_desc.objects_last_page == file_desc.objects_per_page) | |
2306 | add_varray_page (&file_desc); | |
2307 | ||
2308 | fil_ptr = cur_file_ptr = | |
2309 | &file_desc.last->datum->file[file_desc.objects_last_page++]; | |
2310 | *fil_ptr = init_file; | |
2311 | ||
2312 | fil_ptr->file_index = indx; | |
2313 | ++file_desc.num_allocated; | |
2314 | ||
2315 | /* Allocate the string hash table. */ | |
2316 | fil_ptr->str_hash = hash_new (); | |
3d3c5039 ILT |
2317 | |
2318 | /* Make sure 0 byte in string table is null */ | |
2319 | add_string (&fil_ptr->strings, | |
2320 | fil_ptr->str_hash, | |
2321 | "", | |
2322 | (shash_t **)0); | |
2323 | ||
2324 | if (strlen (file_name) > PAGE_USIZE - 2) | |
2325 | as_fatal ("Filename goes over one page boundary."); | |
2326 | ||
2327 | /* Push the start of the filename. We assume that the filename | |
2328 | will be stored at string offset 1. */ | |
2329 | (void) add_ecoff_symbol (file_name, st_File, sc_Text, | |
2330 | (symbolS *) NULL, | |
2331 | (symint_t) 0, (symint_t) 0); | |
2332 | fil_ptr->fdr.rss = 1; | |
2333 | fil_ptr->name = &fil_ptr->strings.last->datum->byte[1]; | |
2334 | ||
2335 | /* Update the linked list of file descriptors. */ | |
2336 | *last_file_ptr = fil_ptr; | |
2337 | last_file_ptr = &fil_ptr->next_file; | |
2338 | ||
2339 | /* Add void & int types to the file (void should be first to catch | |
2340 | errant 0's within the index fields). */ | |
2341 | fil_ptr->void_type = add_aux_sym_tir (&void_type_info, | |
2342 | hash_yes, | |
2343 | &cur_file_ptr->thash_head[0]); | |
2344 | ||
2345 | fil_ptr->int_type = add_aux_sym_tir (&int_type_info, | |
2346 | hash_yes, | |
2347 | &cur_file_ptr->thash_head[0]); | |
2348 | } | |
2349 | } | |
2350 | \f | |
2351 | #ifdef ECOFF_DEBUG | |
2352 | ||
2353 | /* Convert storage class to string. */ | |
2354 | ||
2355 | static char * | |
2356 | sc_to_string(storage_class) | |
2357 | sc_t storage_class; | |
2358 | { | |
2359 | switch(storage_class) | |
2360 | { | |
2361 | case sc_Nil: return "Nil,"; | |
2362 | case sc_Text: return "Text,"; | |
2363 | case sc_Data: return "Data,"; | |
2364 | case sc_Bss: return "Bss,"; | |
2365 | case sc_Register: return "Register,"; | |
2366 | case sc_Abs: return "Abs,"; | |
2367 | case sc_Undefined: return "Undefined,"; | |
2368 | case sc_CdbLocal: return "CdbLocal,"; | |
2369 | case sc_Bits: return "Bits,"; | |
2370 | case sc_CdbSystem: return "CdbSystem,"; | |
2371 | case sc_RegImage: return "RegImage,"; | |
2372 | case sc_Info: return "Info,"; | |
2373 | case sc_UserStruct: return "UserStruct,"; | |
2374 | case sc_SData: return "SData,"; | |
2375 | case sc_SBss: return "SBss,"; | |
2376 | case sc_RData: return "RData,"; | |
2377 | case sc_Var: return "Var,"; | |
2378 | case sc_Common: return "Common,"; | |
2379 | case sc_SCommon: return "SCommon,"; | |
2380 | case sc_VarRegister: return "VarRegister,"; | |
2381 | case sc_Variant: return "Variant,"; | |
2382 | case sc_SUndefined: return "SUndefined,"; | |
2383 | case sc_Init: return "Init,"; | |
2384 | case sc_Max: return "Max,"; | |
2385 | } | |
2386 | ||
2387 | return "???,"; | |
2388 | } | |
2389 | ||
2390 | #endif /* DEBUG */ | |
2391 | \f | |
2392 | #ifdef ECOFF_DEBUG | |
2393 | ||
2394 | /* Convert symbol type to string. */ | |
2395 | ||
2396 | static char * | |
2397 | st_to_string(symbol_type) | |
2398 | st_t symbol_type; | |
2399 | { | |
2400 | switch(symbol_type) | |
2401 | { | |
2402 | case st_Nil: return "Nil,"; | |
2403 | case st_Global: return "Global,"; | |
2404 | case st_Static: return "Static,"; | |
2405 | case st_Param: return "Param,"; | |
2406 | case st_Local: return "Local,"; | |
2407 | case st_Label: return "Label,"; | |
2408 | case st_Proc: return "Proc,"; | |
2409 | case st_Block: return "Block,"; | |
2410 | case st_End: return "End,"; | |
2411 | case st_Member: return "Member,"; | |
2412 | case st_Typedef: return "Typedef,"; | |
2413 | case st_File: return "File,"; | |
2414 | case st_RegReloc: return "RegReloc,"; | |
2415 | case st_Forward: return "Forward,"; | |
2416 | case st_StaticProc: return "StaticProc,"; | |
2417 | case st_Constant: return "Constant,"; | |
2418 | case st_Str: return "String,"; | |
2419 | case st_Number: return "Number,"; | |
2420 | case st_Expr: return "Expr,"; | |
2421 | case st_Type: return "Type,"; | |
2422 | case st_Max: return "Max,"; | |
2423 | } | |
2424 | ||
2425 | return "???,"; | |
2426 | } | |
2427 | ||
2428 | #endif /* DEBUG */ | |
2429 | \f | |
2430 | /* Parse .begin directives which have a label as the first argument | |
2431 | which gives the location of the start of the block. */ | |
2432 | ||
2433 | static void | |
2434 | obj_ecoff_begin (ignore) | |
2435 | int ignore; | |
2436 | { | |
2437 | char *name; | |
2438 | char name_end; | |
2439 | ||
2440 | if (cur_file_ptr == (efdr_t *) NULL) | |
2441 | { | |
2442 | as_warn (".begin directive without a preceding .file directive"); | |
2443 | demand_empty_rest_of_line (); | |
2444 | return; | |
2445 | } | |
2446 | ||
2447 | if (cur_proc_ptr == (proc_t *) NULL) | |
2448 | { | |
2449 | as_warn (".begin directive without a preceding .ent directive"); | |
2450 | demand_empty_rest_of_line (); | |
2451 | return; | |
2452 | } | |
2453 | ||
2454 | name = input_line_pointer; | |
2455 | name_end = get_symbol_end (); | |
2456 | ||
2457 | (void) add_ecoff_symbol ((const char *) NULL, st_Block, sc_Text, | |
2458 | symbol_find_or_make (name), | |
2459 | (symint_t) 0, (symint_t) 0); | |
2460 | ||
2461 | *input_line_pointer = name_end; | |
2462 | ||
f6a91cc0 | 2463 | /* The line number follows, but we don't use it. */ |
670a50eb ILT |
2464 | (void) get_absolute_expression (); |
2465 | demand_empty_rest_of_line (); | |
3d3c5039 ILT |
2466 | } |
2467 | \f | |
2468 | /* Parse .bend directives which have a label as the first argument | |
2469 | which gives the location of the end of the block. */ | |
2470 | ||
2471 | static void | |
2472 | obj_ecoff_bend (ignore) | |
2473 | int ignore; | |
2474 | { | |
2475 | char *name; | |
2476 | char name_end; | |
f6a91cc0 | 2477 | symbolS *endsym; |
3d3c5039 ILT |
2478 | |
2479 | if (cur_file_ptr == (efdr_t *) NULL) | |
2480 | { | |
2481 | as_warn (".bend directive without a preceding .file directive"); | |
2482 | demand_empty_rest_of_line (); | |
2483 | return; | |
2484 | } | |
2485 | ||
2486 | if (cur_proc_ptr == (proc_t *) NULL) | |
2487 | { | |
2488 | as_warn (".bend directive without a preceding .ent directive"); | |
2489 | demand_empty_rest_of_line (); | |
2490 | return; | |
2491 | } | |
2492 | ||
2493 | name = input_line_pointer; | |
2494 | name_end = get_symbol_end (); | |
2495 | ||
2496 | /* The value is the distance between the .bend directive and the | |
f6a91cc0 ILT |
2497 | corresponding symbol. We fill in the offset when we write out |
2498 | the symbol. */ | |
2499 | endsym = symbol_find (name); | |
2500 | if (endsym == (symbolS *) NULL) | |
3d3c5039 ILT |
2501 | as_warn (".bend directive names unknown symbol"); |
2502 | else | |
f6a91cc0 | 2503 | (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, endsym, |
3d3c5039 ILT |
2504 | (symint_t) 0, (symint_t) 0); |
2505 | ||
2506 | *input_line_pointer = name_end; | |
2507 | ||
f6a91cc0 | 2508 | /* The line number follows, but we don't use it. */ |
670a50eb ILT |
2509 | (void) get_absolute_expression (); |
2510 | demand_empty_rest_of_line (); | |
3d3c5039 ILT |
2511 | } |
2512 | \f | |
2513 | /* COFF debugging information is provided as a series of directives | |
2514 | (.def, .scl, etc.). We build up information as we read the | |
2515 | directives in the following static variables, and file it away when | |
2516 | we reach the .endef directive. */ | |
2517 | static char *coff_sym_name; | |
2518 | static type_info_t coff_type; | |
2519 | static sc_t coff_storage_class; | |
2520 | static st_t coff_symbol_type; | |
2521 | static int coff_is_function; | |
2522 | static char *coff_tag; | |
2523 | static long coff_value; /* FIXME: Might be 64 bits. */ | |
2524 | symbolS *coff_sym_value; | |
2525 | static int coff_inside_enumeration; | |
2526 | ||
2527 | /* Handle a .def directive: start defining a symbol. */ | |
2528 | ||
2529 | static void | |
2530 | obj_ecoff_def (ignore) | |
2531 | int ignore; | |
2532 | { | |
2533 | char *name; | |
2534 | char name_end; | |
2535 | ||
2536 | SKIP_WHITESPACES (); | |
2537 | ||
2538 | name = input_line_pointer; | |
2539 | name_end = get_symbol_end (); | |
2540 | ||
2541 | if (coff_sym_name != (char *) NULL) | |
2542 | as_warn (".def pseudo-op used inside of .def/.endef; ignored"); | |
2543 | else if (*name == '\0') | |
2544 | as_warn ("Empty symbol name in .def; ignored"); | |
2545 | else | |
2546 | { | |
2547 | if (coff_sym_name != (char *) NULL) | |
2548 | free (coff_sym_name); | |
2549 | if (coff_tag != (char *) NULL) | |
2550 | free (coff_tag); | |
2551 | coff_sym_name = (char *) xmalloc (strlen (name) + 1); | |
2552 | strcpy (coff_sym_name, name); | |
2553 | coff_type = type_info_init; | |
2554 | coff_storage_class = sc_Nil; | |
2555 | coff_symbol_type = st_Nil; | |
2556 | coff_is_function = 0; | |
2557 | coff_tag = (char *) NULL; | |
2558 | coff_value = 0; | |
2559 | coff_sym_value = (symbolS *) NULL; | |
2560 | } | |
2561 | ||
2562 | *input_line_pointer = name_end; | |
2563 | ||
2564 | demand_empty_rest_of_line (); | |
2565 | } | |
2566 | ||
2567 | /* Handle a .dim directive, used to give dimensions for an array. The | |
2568 | arguments are comma separated numbers. mips-tfile assumes that | |
2569 | there will not be more than 6 dimensions, and gdb won't read any | |
2570 | more than that anyhow, so I will also make that assumption. */ | |
2571 | ||
2572 | static void | |
2573 | obj_ecoff_dim (ignore) | |
2574 | int ignore; | |
2575 | { | |
2576 | int dimens[N_TQ]; | |
2577 | int i; | |
2578 | ||
2579 | if (coff_sym_name == (char *) NULL) | |
2580 | { | |
2581 | as_warn (".dim pseudo-op used outside of .def/.endef; ignored"); | |
2582 | demand_empty_rest_of_line (); | |
2583 | return; | |
2584 | } | |
2585 | ||
2586 | for (i = 0; i < N_TQ; i++) | |
2587 | { | |
2588 | SKIP_WHITESPACES (); | |
2589 | dimens[i] = get_absolute_expression (); | |
2590 | if (*input_line_pointer == ',') | |
2591 | ++input_line_pointer; | |
2592 | else | |
2593 | { | |
2594 | if (*input_line_pointer != '\n' | |
2595 | && *input_line_pointer != ';') | |
2596 | as_warn ("Badly formed .dim directive"); | |
2597 | break; | |
2598 | } | |
2599 | } | |
2600 | ||
2601 | if (i == N_TQ) | |
2602 | --i; | |
2603 | ||
2604 | /* The dimensions are stored away in reverse order. */ | |
2605 | for (; i >= 0; i--) | |
2606 | { | |
2607 | if (coff_type.num_dims >= N_TQ) | |
2608 | { | |
2609 | as_warn ("Too many .dim entries"); | |
2610 | break; | |
2611 | } | |
2612 | coff_type.dimensions[coff_type.num_dims] = dimens[i]; | |
2613 | ++coff_type.num_dims; | |
2614 | } | |
2615 | ||
2616 | demand_empty_rest_of_line (); | |
2617 | } | |
2618 | ||
2619 | /* Handle a .scl directive, which sets the COFF storage class of the | |
2620 | symbol. */ | |
2621 | ||
2622 | static void | |
2623 | obj_ecoff_scl (ignore) | |
2624 | int ignore; | |
2625 | { | |
2626 | long val; | |
2627 | ||
2628 | if (coff_sym_name == (char *) NULL) | |
2629 | { | |
2630 | as_warn (".scl pseudo-op used outside of .def/.endef; ignored"); | |
2631 | demand_empty_rest_of_line (); | |
2632 | return; | |
2633 | } | |
2634 | ||
2635 | val = get_absolute_expression (); | |
2636 | ||
f6a91cc0 ILT |
2637 | coff_symbol_type = map_coff_sym_type[val]; |
2638 | coff_storage_class = map_coff_storage[val]; | |
3d3c5039 ILT |
2639 | |
2640 | demand_empty_rest_of_line (); | |
2641 | } | |
2642 | ||
2643 | /* Handle a .size directive. For some reason mips-tfile.c thinks that | |
2644 | .size can have multiple arguments. We humor it, although gcc will | |
2645 | never generate more than one argument. */ | |
2646 | ||
2647 | static void | |
2648 | obj_ecoff_size (ignore) | |
2649 | int ignore; | |
2650 | { | |
2651 | int sizes[N_TQ]; | |
2652 | int i; | |
2653 | ||
2654 | if (coff_sym_name == (char *) NULL) | |
2655 | { | |
2656 | as_warn (".size pseudo-op used outside of .def/.endef; ignored"); | |
2657 | demand_empty_rest_of_line (); | |
2658 | return; | |
2659 | } | |
2660 | ||
2661 | for (i = 0; i < N_TQ; i++) | |
2662 | { | |
2663 | SKIP_WHITESPACES (); | |
2664 | sizes[i] = get_absolute_expression (); | |
2665 | if (*input_line_pointer == ',') | |
2666 | ++input_line_pointer; | |
2667 | else | |
2668 | { | |
2669 | if (*input_line_pointer != '\n' | |
2670 | && *input_line_pointer != ';') | |
2671 | as_warn ("Badly formed .size directive"); | |
2672 | break; | |
2673 | } | |
2674 | } | |
2675 | ||
2676 | if (i == N_TQ) | |
2677 | --i; | |
2678 | ||
2679 | /* The sizes are stored away in reverse order. */ | |
2680 | for (; i >= 0; i--) | |
2681 | { | |
2682 | if (coff_type.num_sizes >= N_TQ) | |
2683 | { | |
2684 | as_warn ("Too many .size entries"); | |
2685 | break; | |
2686 | } | |
2687 | coff_type.sizes[coff_type.num_sizes] = sizes[i]; | |
2688 | ++coff_type.num_sizes; | |
2689 | } | |
2690 | ||
2691 | demand_empty_rest_of_line (); | |
2692 | } | |
2693 | ||
2694 | /* Handle the .type directive, which gives the COFF type of the | |
2695 | symbol. */ | |
2696 | ||
2697 | static void | |
2698 | obj_ecoff_type (ignore) | |
2699 | int ignore; | |
2700 | { | |
2701 | long val; | |
2702 | tq_t *tq_ptr; | |
f6a91cc0 | 2703 | tq_t *tq_shft; |
3d3c5039 ILT |
2704 | |
2705 | if (coff_sym_name == (char *) NULL) | |
2706 | { | |
2707 | as_warn (".type pseudo-op used outside of .def/.endef; ignored"); | |
2708 | demand_empty_rest_of_line (); | |
2709 | return; | |
2710 | } | |
2711 | ||
2712 | val = get_absolute_expression (); | |
2713 | ||
2714 | coff_type.orig_type = BTYPE (val); | |
2715 | coff_type.basic_type = map_coff_types[coff_type.orig_type]; | |
2716 | ||
f6a91cc0 | 2717 | tq_ptr = &coff_type.type_qualifiers[N_TQ]; |
3d3c5039 ILT |
2718 | while (val &~ N_BTMASK) |
2719 | { | |
f6a91cc0 | 2720 | if (tq_ptr == &coff_type.type_qualifiers[0]) |
3d3c5039 ILT |
2721 | { |
2722 | as_warn ("Too derived values in .type argument"); | |
2723 | break; | |
2724 | } | |
2725 | if (ISPTR (val)) | |
f6a91cc0 | 2726 | *--tq_ptr = tq_Ptr; |
3d3c5039 | 2727 | else if (ISFCN (val)) |
f6a91cc0 | 2728 | *--tq_ptr = tq_Proc; |
3d3c5039 | 2729 | else if (ISARY (val)) |
f6a91cc0 | 2730 | *--tq_ptr = tq_Array; |
3d3c5039 ILT |
2731 | else |
2732 | as_fatal ("Unrecognized .type argument"); | |
2733 | ||
2734 | val = DECREF (val); | |
2735 | } | |
2736 | ||
f6a91cc0 ILT |
2737 | tq_shft = &coff_type.type_qualifiers[0]; |
2738 | while (tq_ptr != &coff_type.type_qualifiers[N_TQ]) | |
2739 | *tq_shft++ = *tq_ptr++; | |
2740 | ||
2741 | if (tq_shft != &coff_type.type_qualifiers[0] && tq_shft[-1] == tq_Proc) | |
3d3c5039 ILT |
2742 | { |
2743 | /* If this is a function, ignore it, so that we don't get two | |
2744 | entries (one from the .ent, and one for the .def that | |
2745 | precedes it). Save the type information so that the end | |
2746 | block can properly add it after the begin block index. For | |
2747 | MIPS knows what reason, we must strip off the function type | |
2748 | at this point. */ | |
2749 | coff_is_function = 1; | |
f6a91cc0 | 2750 | tq_shft[-1] = tq_Nil; |
3d3c5039 ILT |
2751 | } |
2752 | ||
f6a91cc0 ILT |
2753 | while (tq_shft != &coff_type.type_qualifiers[N_TQ]) |
2754 | *tq_shft++ = tq_Nil; | |
2755 | ||
3d3c5039 ILT |
2756 | demand_empty_rest_of_line (); |
2757 | } | |
2758 | ||
2759 | /* Handle the .tag directive, which gives the name of a structure, | |
2760 | union or enum. */ | |
2761 | ||
2762 | static void | |
2763 | obj_ecoff_tag (ignore) | |
2764 | int ignore; | |
2765 | { | |
2766 | char *name; | |
2767 | char name_end; | |
2768 | ||
2769 | if (coff_sym_name == (char *) NULL) | |
2770 | { | |
2771 | as_warn (".tag pseudo-op used outside of .def/.endef; ignored"); | |
2772 | demand_empty_rest_of_line (); | |
2773 | return; | |
2774 | } | |
2775 | ||
2776 | name = input_line_pointer; | |
2777 | name_end = get_symbol_end (); | |
2778 | ||
2779 | coff_tag = (char *) xmalloc (strlen (name) + 1); | |
2780 | strcpy (coff_tag, name); | |
2781 | ||
2782 | *input_line_pointer = name_end; | |
2783 | ||
2784 | demand_empty_rest_of_line (); | |
2785 | } | |
2786 | ||
2787 | /* Handle the .val directive, which gives the value of the symbol. It | |
2788 | may be the name of a static or global symbol. */ | |
2789 | ||
2790 | static void | |
2791 | obj_ecoff_val (ignore) | |
2792 | int ignore; | |
2793 | { | |
2794 | if (coff_sym_name == (char *) NULL) | |
2795 | { | |
2796 | as_warn (".val pseudo-op used outside of .def/.endef; ignored"); | |
2797 | demand_empty_rest_of_line (); | |
2798 | return; | |
2799 | } | |
2800 | ||
2801 | if (! is_name_beginner ((unsigned char) *input_line_pointer)) | |
2802 | coff_value = get_absolute_expression (); | |
2803 | else | |
2804 | { | |
2805 | char *name; | |
2806 | char name_end; | |
2807 | ||
2808 | name = input_line_pointer; | |
2809 | name_end = get_symbol_end (); | |
2810 | ||
2811 | if (strcmp (name, ".") == 0) | |
2812 | as_warn ("`.val .' not supported"); | |
2813 | else | |
2814 | coff_sym_value = symbol_find_or_make (name); | |
2815 | ||
2816 | *input_line_pointer = name_end; | |
2817 | ||
2818 | /* FIXME: gcc can generate address expressions here in unusual | |
2819 | cases (search for "obscure" in sdbout.c), although this is | |
2820 | very unlikely for a MIPS chip. */ | |
2821 | } | |
2822 | ||
2823 | demand_empty_rest_of_line (); | |
2824 | } | |
2825 | ||
2826 | /* Handle the .endef directive, which terminates processing of COFF | |
2827 | debugging information for a symbol. */ | |
2828 | ||
2829 | static void | |
2830 | obj_ecoff_endef (ignore) | |
2831 | int ignore; | |
2832 | { | |
f6a91cc0 | 2833 | char *name; |
3d3c5039 ILT |
2834 | symint_t indx; |
2835 | localsym_t *sym; | |
2836 | ||
2837 | demand_empty_rest_of_line (); | |
2838 | ||
2839 | if (coff_sym_name == (char *) NULL) | |
2840 | { | |
2841 | as_warn (".endef pseudo-op used before .def; ignored"); | |
2842 | return; | |
2843 | } | |
2844 | ||
f6a91cc0 ILT |
2845 | name = coff_sym_name; |
2846 | coff_sym_name = (char *) NULL; | |
2847 | ||
2848 | /* If the symbol is a static or external, we have already gotten the | |
2849 | appropriate type and class, so make sure we don't override those | |
2850 | values. This is needed because there are some type and classes | |
2851 | that are not in COFF, such as short data, etc. */ | |
2852 | if (coff_sym_value != (symbolS *) NULL) | |
2853 | { | |
2854 | coff_symbol_type = st_Nil; | |
2855 | coff_storage_class = sc_Nil; | |
2856 | } | |
2857 | ||
3d3c5039 ILT |
2858 | coff_type.extra_sizes = coff_tag != (char *) NULL; |
2859 | if (coff_type.num_dims > 0) | |
2860 | { | |
2861 | int diff = coff_type.num_dims - coff_type.num_sizes; | |
2862 | int i = coff_type.num_dims - 1; | |
2863 | int j; | |
2864 | ||
2865 | if (coff_type.num_sizes != 1 || diff < 0) | |
2866 | { | |
2867 | as_warn ("Bad COFF debugging info"); | |
2868 | return; | |
2869 | } | |
2870 | ||
2871 | /* If this is an array, make sure the same number of dimensions | |
2872 | and sizes were passed, creating extra sizes for multiply | |
2873 | dimensioned arrays if not passed. */ | |
2874 | coff_type.extra_sizes = 0; | |
2875 | if (diff) | |
2876 | { | |
2877 | j = (sizeof (coff_type.sizes) / sizeof (coff_type.sizes[0])) - 1; | |
2878 | while (j >= 0) | |
2879 | { | |
2880 | coff_type.sizes[j] = (((j - diff) >= 0) | |
2881 | ? coff_type.sizes[j - diff] | |
2882 | : 0); | |
2883 | j--; | |
2884 | } | |
2885 | ||
2886 | coff_type.num_sizes = i + 1; | |
2887 | for (i--; i >= 0; i--) | |
2888 | coff_type.sizes[i] = (coff_type.sizes[i + 1] | |
2889 | / coff_type.dimensions[i + 1]); | |
2890 | } | |
2891 | } | |
2892 | else if (coff_symbol_type == st_Member | |
2893 | && coff_type.num_sizes - coff_type.extra_sizes == 1) | |
2894 | { | |
2895 | /* Is this a bitfield? This is indicated by a structure memeber | |
2896 | having a size field that isn't an array. */ | |
2897 | coff_type.bitfield = 1; | |
2898 | } | |
2899 | ||
2900 | /* Except for enumeration members & begin/ending of scopes, put the | |
2901 | type word in the aux. symbol table. */ | |
2902 | if (coff_symbol_type == st_Block || coff_symbol_type == st_End) | |
2903 | indx = 0; | |
2904 | else if (coff_inside_enumeration) | |
2905 | indx = cur_file_ptr->void_type; | |
2906 | else | |
2907 | { | |
2908 | if (coff_type.basic_type == bt_Struct | |
2909 | || coff_type.basic_type == bt_Union | |
2910 | || coff_type.basic_type == bt_Enum) | |
2911 | { | |
2912 | if (coff_tag == (char *) NULL) | |
2913 | { | |
f6a91cc0 | 2914 | as_warn ("No tag specified for %s", name); |
3d3c5039 ILT |
2915 | return; |
2916 | } | |
2917 | ||
2918 | coff_type.tag_ptr = get_tag (coff_tag, (localsym_t *) NULL, | |
2919 | coff_type.basic_type); | |
2920 | } | |
2921 | ||
2922 | if (coff_is_function) | |
2923 | { | |
2924 | last_func_type_info = coff_type; | |
2925 | last_func_sym_value = coff_sym_value; | |
2926 | return; | |
2927 | } | |
2928 | ||
2929 | indx = add_aux_sym_tir (&coff_type, | |
2930 | hash_yes, | |
2931 | &cur_file_ptr->thash_head[0]); | |
2932 | } | |
2933 | ||
2934 | /* Do any last minute adjustments that are necessary. */ | |
2935 | switch (coff_symbol_type) | |
2936 | { | |
2937 | default: | |
2938 | break; | |
2939 | ||
2940 | /* For the beginning of structs, unions, and enumerations, the | |
2941 | size info needs to be passed in the value field. */ | |
2942 | case st_Block: | |
2943 | if (coff_type.num_sizes - coff_type.num_dims - coff_type.extra_sizes | |
2944 | != 1) | |
2945 | { | |
2946 | as_warn ("Bad COFF debugging information"); | |
2947 | return; | |
2948 | } | |
2949 | else | |
2950 | coff_value = coff_type.sizes[0]; | |
2951 | ||
2952 | coff_inside_enumeration = (coff_type.orig_type == T_ENUM); | |
2953 | break; | |
2954 | ||
2955 | /* For the end of structs, unions, and enumerations, omit the | |
2956 | name which is always ".eos". This needs to be done last, so | |
2957 | that any error reporting above gives the correct name. */ | |
2958 | case st_End: | |
f6a91cc0 ILT |
2959 | free (name); |
2960 | name = (char *) NULL; | |
3d3c5039 ILT |
2961 | coff_value = 0; |
2962 | coff_inside_enumeration = 0; | |
2963 | break; | |
2964 | ||
2965 | /* Members of structures and unions that aren't bitfields, need | |
2966 | to adjust the value from a byte offset to a bit offset. | |
2967 | Members of enumerations do not have the value adjusted, and | |
2968 | can be distinguished by indx == indexNil. For enumerations, | |
2969 | update the maximum enumeration value. */ | |
2970 | case st_Member: | |
2971 | if (! coff_type.bitfield && ! coff_inside_enumeration) | |
2972 | coff_value *= 8; | |
2973 | ||
2974 | break; | |
2975 | } | |
2976 | ||
2977 | /* Add the symbol. */ | |
f6a91cc0 | 2978 | sym = add_ecoff_symbol (name, |
3d3c5039 ILT |
2979 | coff_symbol_type, |
2980 | coff_storage_class, | |
2981 | coff_sym_value, | |
2982 | coff_value, | |
2983 | indx); | |
2984 | ||
2985 | /* deal with struct, union, and enum tags. */ | |
2986 | if (coff_symbol_type == st_Block) | |
2987 | { | |
2988 | /* Create or update the tag information. */ | |
f6a91cc0 | 2989 | tag_t *tag_ptr = get_tag (name, |
3d3c5039 ILT |
2990 | sym, |
2991 | coff_type.basic_type); | |
2992 | forward_t **pf; | |
2993 | ||
2994 | /* Remember any forward references. */ | |
2995 | for (pf = &sym->forward_ref; | |
2996 | *pf != (forward_t *) NULL; | |
2997 | pf = &(*pf)->next) | |
2998 | ; | |
2999 | *pf = tag_ptr->forward_ref; | |
3000 | tag_ptr->forward_ref = (forward_t *) NULL; | |
3001 | } | |
3002 | } | |
3003 | \f | |
3004 | /* Parse .end directives. */ | |
3005 | ||
3006 | static void | |
3007 | obj_ecoff_end (ignore) | |
3008 | int ignore; | |
3009 | { | |
3010 | char *name; | |
3011 | char name_end; | |
3012 | register int ch; | |
3013 | symbolS *ent; | |
3014 | ||
3015 | if (cur_file_ptr == (efdr_t *) NULL) | |
3016 | { | |
3017 | as_warn (".end directive without a preceding .file directive"); | |
3018 | demand_empty_rest_of_line (); | |
3019 | return; | |
3020 | } | |
3021 | ||
3022 | if (cur_proc_ptr == (proc_t *) NULL) | |
3023 | { | |
3024 | as_warn (".end directive without a preceding .ent directive"); | |
3025 | demand_empty_rest_of_line (); | |
3026 | return; | |
3027 | } | |
3028 | ||
3029 | name = input_line_pointer; | |
3030 | name_end = get_symbol_end (); | |
3031 | ||
3032 | ch = *name; | |
3033 | if (! is_name_beginner (ch)) | |
3034 | { | |
3035 | as_warn (".end directive has no name"); | |
3036 | *input_line_pointer = name_end; | |
3037 | demand_empty_rest_of_line (); | |
3038 | return; | |
3039 | } | |
3040 | ||
3041 | /* The value is the distance between the .end directive and the | |
3042 | corresponding symbol. We create a fake symbol to hold the | |
3043 | current location, and put in the offset when we write out the | |
3044 | symbol. */ | |
3045 | ent = symbol_find (name); | |
3046 | if (ent == (symbolS *) NULL) | |
3047 | as_warn (".end directive names unknown symbol"); | |
3048 | else | |
f6a91cc0 | 3049 | (void) add_ecoff_symbol ((const char *) NULL, st_End, sc_Text, |
3d3c5039 ILT |
3050 | symbol_new ("L0\001", now_seg, |
3051 | frag_now_fix (), frag_now), | |
3052 | (symint_t) 0, (symint_t) 0); | |
3053 | ||
3054 | cur_proc_ptr = (proc_t *) NULL; | |
3055 | ||
3056 | *input_line_pointer = name_end; | |
3057 | demand_empty_rest_of_line (); | |
3058 | } | |
3059 | \f | |
3060 | /* Parse .ent directives. */ | |
3061 | ||
3062 | static void | |
3063 | obj_ecoff_ent (ignore) | |
3064 | int ignore; | |
3065 | { | |
3066 | char *name; | |
3067 | char name_end; | |
3068 | register int ch; | |
3069 | ||
3070 | if (cur_file_ptr == (efdr_t *) NULL) | |
3071 | add_file ((const char *) NULL, 0); | |
3072 | ||
3073 | if (cur_proc_ptr != (proc_t *) NULL) | |
3074 | { | |
3075 | as_warn ("second .ent directive found before .end directive"); | |
3076 | demand_empty_rest_of_line (); | |
3077 | return; | |
3078 | } | |
3079 | ||
3080 | name = input_line_pointer; | |
3081 | name_end = get_symbol_end (); | |
3082 | ||
3083 | ch = *name; | |
3084 | if (! is_name_beginner (ch)) | |
3085 | { | |
3086 | as_warn (".ent directive has no name"); | |
3087 | *input_line_pointer = name_end; | |
3088 | demand_empty_rest_of_line (); | |
3089 | return; | |
3090 | } | |
3091 | ||
3092 | add_procedure (name); | |
3093 | ||
3094 | *input_line_pointer = name_end; | |
3095 | demand_empty_rest_of_line (); | |
3096 | } | |
3097 | \f | |
3098 | /* Parse .file directives. */ | |
3099 | ||
3100 | static void | |
3101 | obj_ecoff_file (ignore) | |
3102 | int ignore; | |
3103 | { | |
3104 | int indx; | |
3105 | char *name; | |
3106 | int len; | |
3107 | ||
3108 | if (cur_proc_ptr != (proc_t *) NULL) | |
3109 | { | |
3110 | as_warn ("No way to handle .file within .ent/.end section"); | |
3111 | demand_empty_rest_of_line (); | |
3112 | return; | |
3113 | } | |
3114 | ||
3115 | indx = (int) get_absolute_expression (); | |
3116 | ||
3117 | /* FIXME: we don't have to save the name here. */ | |
3118 | name = demand_copy_C_string (&len); | |
3119 | ||
3120 | add_file (name, indx - 1); | |
3121 | ||
3122 | demand_empty_rest_of_line (); | |
3123 | } | |
3124 | \f | |
3125 | /* Parse .fmask directives. */ | |
3126 | ||
3127 | static void | |
3128 | obj_ecoff_fmask (ignore) | |
3129 | int ignore; | |
3130 | { | |
3131 | long val; | |
3132 | ||
3133 | if (cur_proc_ptr == (proc_t *) NULL) | |
3134 | { | |
3135 | as_warn (".fmask outside of .ent"); | |
3136 | demand_empty_rest_of_line (); | |
3137 | return; | |
3138 | } | |
3139 | ||
3140 | if (get_absolute_expression_and_terminator (&val) != ',') | |
3141 | { | |
3142 | as_warn ("Bad .fmask directive"); | |
3143 | --input_line_pointer; | |
3144 | demand_empty_rest_of_line (); | |
3145 | return; | |
3146 | } | |
3147 | ||
3148 | cur_proc_ptr->pdr.fregmask = val; | |
3149 | cur_proc_ptr->pdr.fregoffset = get_absolute_expression (); | |
3150 | ||
3151 | demand_empty_rest_of_line (); | |
3152 | } | |
3153 | \f | |
3154 | /* Parse .frame directives. */ | |
3155 | ||
3156 | static void | |
3157 | obj_ecoff_frame (ignore) | |
3158 | int ignore; | |
3159 | { | |
3160 | long val; | |
3161 | ||
3162 | if (cur_proc_ptr == (proc_t *) NULL) | |
3163 | { | |
3164 | as_warn (".frame outside of .ent"); | |
3165 | demand_empty_rest_of_line (); | |
3166 | return; | |
3167 | } | |
3168 | ||
3169 | cur_proc_ptr->pdr.framereg = tc_get_register (); | |
3170 | ||
3171 | SKIP_WHITESPACE (); | |
3172 | if (*input_line_pointer++ != ',' | |
3173 | || get_absolute_expression_and_terminator (&val) != ',') | |
3174 | { | |
3175 | as_warn ("Bad .frame directive"); | |
3176 | --input_line_pointer; | |
3177 | demand_empty_rest_of_line (); | |
3178 | return; | |
3179 | } | |
3180 | ||
3181 | cur_proc_ptr->pdr.frameoffset = val; | |
3182 | ||
3183 | cur_proc_ptr->pdr.pcreg = tc_get_register (); | |
3184 | ||
3185 | demand_empty_rest_of_line (); | |
3186 | } | |
3187 | \f | |
3188 | /* Parse .mask directives. */ | |
3189 | ||
3190 | static void | |
3191 | obj_ecoff_mask (ignore) | |
3192 | int ignore; | |
3193 | { | |
3194 | long val; | |
3195 | ||
3196 | if (cur_proc_ptr == (proc_t *) NULL) | |
3197 | { | |
3198 | as_warn (".mask outside of .ent"); | |
3199 | demand_empty_rest_of_line (); | |
3200 | return; | |
3201 | } | |
3202 | ||
3203 | if (get_absolute_expression_and_terminator (&val) != ',') | |
3204 | { | |
3205 | as_warn ("Bad .mask directive"); | |
3206 | --input_line_pointer; | |
3207 | demand_empty_rest_of_line (); | |
3208 | return; | |
3209 | } | |
3210 | ||
3211 | cur_proc_ptr->pdr.regmask = val; | |
3212 | cur_proc_ptr->pdr.regoffset = get_absolute_expression (); | |
3213 | ||
3214 | demand_empty_rest_of_line (); | |
3215 | } | |
3216 | \f | |
3217 | /* Parse .loc directives. */ | |
3218 | ||
3219 | static void | |
3220 | obj_ecoff_loc (ignore) | |
3221 | int ignore; | |
3222 | { | |
3d3c5039 | 3223 | lineno_list_t *list; |
918692a5 | 3224 | int lineno; |
3d3c5039 ILT |
3225 | |
3226 | if (cur_file_ptr == (efdr_t *) NULL) | |
3227 | { | |
3228 | as_warn (".loc before .file"); | |
3229 | demand_empty_rest_of_line (); | |
3230 | return; | |
3231 | } | |
3232 | ||
3233 | if (now_seg != text_section) | |
3234 | { | |
3235 | as_warn (".loc outside of .text"); | |
3236 | demand_empty_rest_of_line (); | |
3237 | return; | |
3238 | } | |
3239 | ||
f6a91cc0 ILT |
3240 | /* Skip the file number. */ |
3241 | SKIP_WHITESPACE (); | |
3242 | get_absolute_expression (); | |
3d3c5039 | 3243 | SKIP_WHITESPACE (); |
3d3c5039 | 3244 | |
918692a5 ILT |
3245 | lineno = get_absolute_expression (); |
3246 | ||
3247 | #ifndef NO_LISTING | |
3248 | if (listing) | |
3249 | listing_source_line (lineno); | |
3250 | #endif | |
3251 | ||
670a50eb ILT |
3252 | /* If we're building stabs, then output a special label rather than |
3253 | ECOFF line number info. */ | |
3254 | if (stabs_seen) | |
3255 | { | |
3256 | (void) add_ecoff_symbol ((char *) NULL, st_Label, sc_Text, | |
3257 | symbol_new ("L0\001", now_seg, | |
3258 | frag_now_fix (), frag_now), | |
918692a5 | 3259 | 0, lineno); |
670a50eb ILT |
3260 | return; |
3261 | } | |
3262 | ||
3d3c5039 ILT |
3263 | list = allocate_lineno_list (); |
3264 | ||
3265 | list->next = (lineno_list_t *) NULL; | |
3266 | list->file = cur_file_ptr; | |
3267 | list->proc = cur_proc_ptr; | |
3268 | list->frag = frag_now; | |
3269 | list->paddr = frag_now_fix (); | |
918692a5 | 3270 | list->lineno = lineno; |
3d3c5039 ILT |
3271 | |
3272 | /* A .loc directive will sometimes appear before a .ent directive, | |
3273 | which means that cur_proc_ptr will be NULL here. Arrange to | |
3274 | patch this up. */ | |
3275 | if (cur_proc_ptr == (proc_t *) NULL) | |
3276 | { | |
3277 | lineno_list_t **pl; | |
3278 | ||
3279 | pl = &noproc_lineno; | |
3280 | while (*pl != (lineno_list_t *) NULL) | |
3281 | pl = &(*pl)->next; | |
3282 | *pl = list; | |
3283 | } | |
3284 | else | |
3285 | { | |
3286 | *last_lineno_ptr = list; | |
3287 | last_lineno_ptr = &list->next; | |
3288 | } | |
3289 | } | |
3290 | \f | |
3291 | /* Make sure the @stabs symbol is emitted. */ | |
3292 | ||
3293 | static void | |
3294 | mark_stabs (ignore) | |
3295 | int ignore; | |
3296 | { | |
3297 | if (! stabs_seen) | |
3298 | { | |
3299 | /* Add a dummy @stabs dymbol. */ | |
3300 | stabs_seen = 1; | |
3301 | (void) add_ecoff_symbol (stabs_symbol, stNil, scInfo, | |
3302 | (symbolS *) NULL, | |
3303 | (symint_t) -1, MIPS_MARK_STAB (0)); | |
3304 | } | |
3305 | } | |
3306 | \f | |
3307 | /* Parse .stabs directives. | |
3308 | ||
3309 | .stabs directives have five fields: | |
3310 | "string" a string, encoding the type information. | |
3311 | code a numeric code, defined in <stab.h> | |
3312 | 0 a zero | |
3313 | 0 a zero or line number | |
3314 | value a numeric value or an address. | |
3315 | ||
3316 | If the value is relocatable, we transform this into: | |
3317 | iss points as an index into string space | |
3318 | value value from lookup of the name | |
3319 | st st from lookup of the name | |
3320 | sc sc from lookup of the name | |
3321 | index code|CODE_MASK | |
3322 | ||
3323 | If the value is not relocatable, we transform this into: | |
3324 | iss points as an index into string space | |
3325 | value value | |
3326 | st st_Nil | |
3327 | sc sc_Nil | |
3328 | index code|CODE_MASK | |
3329 | ||
3330 | .stabn directives have four fields (string is null): | |
3331 | code a numeric code, defined in <stab.h> | |
3332 | 0 a zero | |
3333 | 0 a zero or a line number | |
3334 | value a numeric value or an address. */ | |
3335 | ||
3336 | static void | |
3337 | obj_ecoff_stab (type) | |
3338 | int type; | |
3339 | { | |
3340 | char *string; | |
3341 | efdr_t *save_file_ptr = cur_file_ptr; | |
3342 | symint_t code; | |
3343 | symint_t value; | |
3344 | symbolS *sym; | |
3345 | st_t st; | |
3346 | sc_t sc; | |
3347 | ||
918692a5 ILT |
3348 | if (cur_file_ptr == (efdr_t *) NULL) |
3349 | { | |
3350 | add_file ((const char *) NULL, 0); | |
3351 | save_file_ptr = cur_file_ptr; | |
3352 | } | |
3353 | ||
3d3c5039 ILT |
3354 | if (stabs_seen == 0) |
3355 | mark_stabs (0); | |
3356 | ||
3357 | if (type != 's') | |
3358 | string = (char *) NULL; | |
3359 | else | |
3360 | { | |
3361 | int len; | |
3362 | ||
3363 | string = demand_copy_C_string (&len); | |
3364 | SKIP_WHITESPACE (); | |
3365 | if (*input_line_pointer == ',') | |
3366 | input_line_pointer++; | |
3367 | else | |
3368 | { | |
3369 | as_warn ("Bad .stab%c directive", type); | |
3370 | demand_empty_rest_of_line (); | |
3371 | return; | |
3372 | } | |
3373 | } | |
3374 | ||
3375 | code = (symint_t) get_absolute_expression (); | |
3376 | ||
3377 | SKIP_WHITESPACE (); | |
3378 | if (*input_line_pointer++ != ',') | |
3379 | { | |
3380 | as_warn ("Bad .stab%c directive", type); | |
3381 | --input_line_pointer; | |
3382 | demand_empty_rest_of_line (); | |
3383 | return; | |
3384 | } | |
3385 | ||
3386 | if (get_absolute_expression () != 0) | |
3387 | { | |
3388 | as_warn ("Bad .stab%c directive (expected 0)", type); | |
3389 | demand_empty_rest_of_line (); | |
3390 | return; | |
3391 | } | |
3392 | ||
3393 | SKIP_WHITESPACE (); | |
3394 | if (*input_line_pointer++ != ',') | |
3395 | { | |
3396 | as_warn ("Bad .stab%c directive", type); | |
3397 | --input_line_pointer; | |
3398 | demand_empty_rest_of_line (); | |
3399 | return; | |
3400 | } | |
3401 | ||
3402 | /* Line number stabs are handled differently, since they have two values, | |
3403 | the line number and the address of the label. We use the index field | |
3404 | (aka code) to hold the line number, and the value field to hold the | |
3405 | address. The symbol type is st_Label, which should be different from | |
3406 | the other stabs, so that gdb can recognize it. */ | |
3407 | if (code == N_SLINE) | |
3408 | { | |
3409 | SYMR dummy_symr; | |
3410 | char *name; | |
3411 | char name_end; | |
3412 | ||
3413 | code = (symint_t) get_absolute_expression (); | |
3414 | ||
918692a5 ILT |
3415 | #ifndef NO_LISTING |
3416 | if (listing) | |
3417 | listing_source_line (code); | |
3418 | #endif | |
3419 | ||
3d3c5039 ILT |
3420 | if (*input_line_pointer++ != ',') |
3421 | { | |
3422 | as_warn ("Bad .stab%c directive", type); | |
3423 | --input_line_pointer; | |
3424 | demand_empty_rest_of_line (); | |
3425 | return; | |
3426 | } | |
3427 | ||
3428 | dummy_symr.index = code; | |
3429 | if (dummy_symr.index != code) | |
3430 | { | |
3431 | as_warn ("Line number (%d) for .stab%c directive cannot fit in index field (20 bits)", | |
3432 | code, type); | |
3433 | demand_empty_rest_of_line (); | |
3434 | return; | |
3435 | } | |
3436 | ||
3437 | SKIP_WHITESPACE (); | |
3438 | name = input_line_pointer; | |
3439 | name_end = get_symbol_end (); | |
3440 | ||
3441 | sym = symbol_find_or_make (name); | |
3442 | *input_line_pointer = name_end; | |
3443 | ||
3444 | value = 0; | |
3445 | st = st_Label; | |
670a50eb | 3446 | sc = sc_Text; |
3d3c5039 ILT |
3447 | } |
3448 | else | |
3449 | { | |
918692a5 ILT |
3450 | #ifndef NO_LISTING |
3451 | if (listing && (code == N_SO || code == N_SOL)) | |
3452 | listing_source_file (string); | |
3453 | #endif | |
3454 | ||
670a50eb ILT |
3455 | /* The next number is sometimes the line number of the |
3456 | declaration. We have nowhere to put it, so we just ignore | |
3457 | it. */ | |
3458 | (void) get_absolute_expression (); | |
3d3c5039 ILT |
3459 | |
3460 | SKIP_WHITESPACE (); | |
3461 | if (*input_line_pointer++ != ',') | |
3462 | { | |
3463 | as_warn ("Bad .stab%c directive", type); | |
3464 | --input_line_pointer; | |
3465 | demand_empty_rest_of_line (); | |
3466 | return; | |
3467 | } | |
3468 | ||
3469 | SKIP_WHITESPACE (); | |
3470 | if (isdigit (*input_line_pointer) | |
3471 | || *input_line_pointer == '-' | |
3472 | || *input_line_pointer == '+') | |
3473 | { | |
3474 | st = st_Nil; | |
3475 | sc = sc_Nil; | |
3476 | sym = (symbolS *) NULL; | |
3477 | value = get_absolute_expression (); | |
3478 | } | |
3479 | else if (! is_name_beginner ((unsigned char) *input_line_pointer)) | |
3480 | { | |
3481 | as_warn ("Illegal .stab%c directive, bad character", type); | |
3482 | demand_empty_rest_of_line (); | |
3483 | return; | |
3484 | } | |
3485 | else | |
3486 | { | |
3487 | char *name; | |
3488 | char name_end; | |
3489 | ||
3490 | name = input_line_pointer; | |
3491 | name_end = get_symbol_end (); | |
3492 | ||
3493 | sym = symbol_find_or_make (name); | |
3494 | ||
670a50eb ILT |
3495 | sc = sc_Nil; |
3496 | st = st_Nil; | |
3d3c5039 ILT |
3497 | value = 0; |
3498 | ||
3499 | *input_line_pointer = name_end; | |
3500 | if (name_end == '+' || name_end == '-') | |
3501 | { | |
3502 | ++input_line_pointer; | |
3503 | value = get_absolute_expression (); | |
3504 | if (name_end == '-') | |
3505 | value = - value; | |
3506 | } | |
3507 | } | |
3508 | ||
3509 | code = MIPS_MARK_STAB (code); | |
3510 | } | |
3511 | ||
3512 | (void) add_ecoff_symbol (string, st, sc, sym, value, code); | |
3513 | ||
3514 | /* Restore normal file type. */ | |
3515 | cur_file_ptr = save_file_ptr; | |
3516 | } | |
3517 | \f | |
3518 | /* Add bytes to the symbolic information buffer. */ | |
3519 | ||
3520 | static char * | |
3521 | ecoff_add_bytes (buf, bufend, bufptr, need) | |
3522 | char **buf; | |
3523 | char **bufend; | |
3524 | char *bufptr; | |
3525 | long need; | |
3526 | { | |
3527 | unsigned long at; | |
3528 | unsigned long want; | |
3529 | ||
3530 | at = bufptr - *buf; | |
3531 | need -= *bufend - bufptr; | |
3532 | if (need < PAGE_SIZE) | |
3533 | need = PAGE_SIZE; | |
3534 | want = (*bufend - *buf) + need; | |
3535 | *buf = xrealloc (*buf, want); | |
3536 | *bufend = *buf + want; | |
3537 | return *buf + at; | |
3538 | } | |
3539 | ||
3540 | /* Adjust the symbolic information buffer to a longword boundary. */ | |
3541 | ||
3542 | static long | |
3543 | ecoff_longword_adjust (buf, bufend, offset, bufptrptr) | |
3544 | char **buf; | |
3545 | char **bufend; | |
3546 | long offset; | |
3547 | char **bufptrptr; | |
3548 | { | |
3549 | if ((offset & 3) != 0) | |
3550 | { | |
3551 | long add; | |
3552 | ||
3553 | add = 4 - (offset & 3); | |
3554 | if (*bufend - (*buf + offset) < add) | |
3555 | (void) ecoff_add_bytes (buf, bufend, *buf + offset, add); | |
670a50eb | 3556 | memset (*buf + offset, 0, add); |
3d3c5039 ILT |
3557 | offset += add; |
3558 | if (bufptrptr != (char **) NULL) | |
3559 | *bufptrptr = *buf + offset; | |
3560 | } | |
3561 | ||
3562 | return offset; | |
3563 | } | |
3564 | ||
3565 | /* Build the line number information. */ | |
3566 | ||
3567 | static long | |
3568 | ecoff_build_lineno (buf, bufend, offset, linecntptr) | |
3569 | char **buf; | |
3570 | char **bufend; | |
3571 | long offset; | |
3572 | long *linecntptr; | |
3573 | { | |
3574 | char *bufptr; | |
3575 | register lineno_list_t *l; | |
3576 | lineno_list_t *last; | |
3577 | efdr_t *file; | |
3578 | proc_t *proc; | |
3579 | long c; | |
3580 | long iline; | |
670a50eb | 3581 | long totcount; |
3d3c5039 | 3582 | |
918692a5 ILT |
3583 | if (linecntptr != (long *) NULL) |
3584 | *linecntptr = 0; | |
3585 | ||
3d3c5039 ILT |
3586 | bufptr = *buf + offset; |
3587 | ||
3588 | file = (efdr_t *) NULL; | |
3589 | proc = (proc_t *) NULL; | |
3590 | last = (lineno_list_t *) NULL; | |
3591 | c = offset; | |
3592 | iline = 0; | |
670a50eb | 3593 | totcount = 0; |
3d3c5039 ILT |
3594 | for (l = first_lineno; l != (lineno_list_t *) NULL; l = l->next) |
3595 | { | |
3596 | long count; | |
3597 | long delta; | |
670a50eb ILT |
3598 | |
3599 | /* Get the offset to the memory address of the next line number | |
3600 | (in words). Do this first, so that we can skip ahead to the | |
3601 | next useful line number entry. */ | |
3602 | if (l->next == (lineno_list_t *) NULL) | |
3603 | count = 0; | |
3604 | else | |
3605 | { | |
3606 | count = ((l->next->frag->fr_address + l->next->paddr | |
3607 | - (l->frag->fr_address + l->paddr)) | |
3608 | >> 2); | |
3609 | if (count <= 0) | |
3610 | { | |
3611 | /* Don't change last, so we still get the right delta. */ | |
3612 | continue; | |
3613 | } | |
3614 | } | |
3d3c5039 ILT |
3615 | |
3616 | if (l->file != file || l->proc != proc) | |
3617 | { | |
3618 | if (l->proc != proc && proc != (proc_t *) NULL) | |
3619 | proc->pdr.lnHigh = last->lineno; | |
3620 | if (l->file != file && file != (efdr_t *) NULL) | |
3621 | { | |
3622 | file->fdr.cbLine = c - file->fdr.cbLineOffset; | |
670a50eb ILT |
3623 | /* The cline field is ill-documented. This is a guess |
3624 | at the right value. */ | |
3625 | file->fdr.cline = totcount + count; | |
918692a5 ILT |
3626 | if (linecntptr != (long *) NULL) |
3627 | *linecntptr += totcount + count; | |
3628 | totcount = 0; | |
3d3c5039 ILT |
3629 | } |
3630 | ||
3d3c5039 ILT |
3631 | if (l->file != file) |
3632 | { | |
3633 | file = l->file; | |
3634 | file->fdr.ilineBase = iline; | |
3635 | file->fdr.cbLineOffset = c; | |
3636 | } | |
3637 | if (l->proc != proc) | |
3638 | { | |
3639 | proc = l->proc; | |
3640 | if (proc != (proc_t *) NULL) | |
3641 | { | |
3d3c5039 ILT |
3642 | proc->pdr.lnLow = l->lineno; |
3643 | proc->pdr.cbLineOffset = c - file->fdr.cbLineOffset; | |
670a50eb ILT |
3644 | /* The iline field is ill-documented. This is a |
3645 | guess at the right value. */ | |
3646 | proc->pdr.iline = totcount; | |
3d3c5039 ILT |
3647 | } |
3648 | } | |
3649 | ||
3650 | last = (lineno_list_t *) NULL; | |
3651 | } | |
3652 | ||
670a50eb | 3653 | totcount += count; |
3d3c5039 ILT |
3654 | |
3655 | /* Get the offset to this line number. */ | |
3656 | if (last == (lineno_list_t *) NULL) | |
3657 | delta = 0; | |
3658 | else | |
3659 | delta = l->lineno - last->lineno; | |
3660 | ||
670a50eb ILT |
3661 | /* Put in the offset to this line number. */ |
3662 | while (delta != 0) | |
3d3c5039 | 3663 | { |
670a50eb ILT |
3664 | int setcount; |
3665 | ||
3666 | /* 1 is added to each count read. */ | |
3667 | --count; | |
3668 | /* We can only adjust the word count by up to 15 words at a | |
3669 | time. */ | |
3670 | if (count <= 0x0f) | |
3d3c5039 | 3671 | { |
670a50eb ILT |
3672 | setcount = count; |
3673 | count = 0; | |
3d3c5039 ILT |
3674 | } |
3675 | else | |
3676 | { | |
670a50eb ILT |
3677 | setcount = 0x0f; |
3678 | count -= 0x0f; | |
3d3c5039 | 3679 | } |
3d3c5039 ILT |
3680 | if (delta >= -7 && delta <= 7) |
3681 | { | |
3682 | if (bufptr >= *bufend) | |
3683 | bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1); | |
670a50eb | 3684 | *bufptr++ = setcount + (delta << 4); |
3d3c5039 ILT |
3685 | delta = 0; |
3686 | ++c; | |
3687 | } | |
3688 | else | |
3689 | { | |
3690 | int set; | |
3691 | ||
3692 | if (*bufend - bufptr < 3) | |
3693 | bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 3); | |
670a50eb | 3694 | *bufptr++ = setcount + (8 << 4); |
3d3c5039 ILT |
3695 | if (delta < -0x8000) |
3696 | { | |
3697 | set = -0x8000; | |
3698 | delta += 0x8000; | |
3699 | } | |
3700 | else if (delta > 0x7fff) | |
3701 | { | |
3702 | set = 0x7fff; | |
3703 | delta -= 0x7fff; | |
3704 | } | |
3705 | else | |
3706 | { | |
3707 | set = delta; | |
3708 | delta = 0; | |
3709 | } | |
3710 | *bufptr++ = set >> 8; | |
3711 | *bufptr++ = set & 0xffff; | |
3712 | c += 3; | |
3713 | } | |
670a50eb ILT |
3714 | } |
3715 | ||
3716 | /* Finish adjusting the count. */ | |
3717 | while (count > 0) | |
3718 | { | |
3719 | if (bufptr >= *bufend) | |
3720 | bufptr = ecoff_add_bytes (buf, bufend, bufptr, (long) 1); | |
3721 | /* 1 is added to each count read. */ | |
3722 | --count; | |
3723 | if (count > 0x0f) | |
3724 | { | |
3725 | *bufptr++ = 0x0f; | |
3726 | count -= 0x0f; | |
3727 | } | |
3728 | else | |
3729 | { | |
3730 | *bufptr++ = count; | |
3731 | count = 0; | |
3732 | } | |
3733 | ++c; | |
3d3c5039 ILT |
3734 | } |
3735 | ||
3736 | ++iline; | |
3737 | last = l; | |
3738 | } | |
3739 | ||
3740 | if (proc != (proc_t *) NULL) | |
3741 | proc->pdr.lnHigh = last->lineno; | |
3742 | if (file != (efdr_t *) NULL) | |
3743 | { | |
3744 | file->fdr.cbLine = c - file->fdr.cbLineOffset; | |
670a50eb | 3745 | file->fdr.cline = totcount; |
3d3c5039 ILT |
3746 | } |
3747 | ||
3d3c5039 | 3748 | if (linecntptr != (long *) NULL) |
918692a5 ILT |
3749 | *linecntptr += totcount; |
3750 | ||
3751 | c = ecoff_longword_adjust (buf, bufend, c, &bufptr); | |
3d3c5039 ILT |
3752 | |
3753 | return c; | |
3754 | } | |
3755 | ||
3756 | /* Build and swap out the symbols. */ | |
3757 | ||
3758 | static long | |
3759 | ecoff_build_symbols (buf, | |
3760 | bufend, | |
3761 | offset, | |
3762 | extbuf, | |
3763 | extbufend, | |
3764 | extoffset, | |
3765 | ext_strings, | |
3766 | ext_str_hash) | |
3767 | char **buf; | |
3768 | char **bufend; | |
3769 | long offset; | |
3770 | char **extbuf; | |
3771 | char **extbufend; | |
3772 | long *extoffset; | |
3773 | varray_t *ext_strings; | |
3774 | struct hash_control *ext_str_hash; | |
3775 | { | |
3776 | struct sym_ext *sym_out; | |
3777 | struct ext_ext *ext_out; | |
3778 | long isym; | |
3779 | long iext; | |
3780 | vlinks_t *file_link; | |
3781 | ||
3782 | sym_out = (struct sym_ext *) (*buf + offset); | |
3783 | ext_out = (struct ext_ext *) (*extbuf + *extoffset); | |
3784 | ||
3785 | isym = 0; | |
3786 | iext = 0; | |
3787 | ||
3788 | /* The symbols are stored by file. */ | |
3789 | for (file_link = file_desc.first; | |
3790 | file_link != (vlinks_t *) NULL; | |
3791 | file_link = file_link->next) | |
3792 | { | |
3793 | int ifilesym; | |
3794 | int fil_cnt; | |
3795 | efdr_t *fil_ptr; | |
3796 | efdr_t *fil_end; | |
3797 | ||
3d3c5039 ILT |
3798 | if (file_link->next == (vlinks_t *) NULL) |
3799 | fil_cnt = file_desc.objects_last_page; | |
3800 | else | |
3801 | fil_cnt = file_desc.objects_per_page; | |
3802 | fil_ptr = file_link->datum->file; | |
3803 | fil_end = fil_ptr + fil_cnt; | |
3804 | for (; fil_ptr < fil_end; fil_ptr++) | |
3805 | { | |
3806 | vlinks_t *sym_link; | |
3807 | ||
3808 | fil_ptr->fdr.isymBase = isym; | |
670a50eb | 3809 | ifilesym = isym; |
3d3c5039 ILT |
3810 | for (sym_link = fil_ptr->symbols.first; |
3811 | sym_link != (vlinks_t *) NULL; | |
3812 | sym_link = sym_link->next) | |
3813 | { | |
3814 | int sym_cnt; | |
3815 | localsym_t *sym_ptr; | |
3816 | localsym_t *sym_end; | |
3817 | ||
3818 | if (sym_link->next == (vlinks_t *) NULL) | |
3819 | sym_cnt = fil_ptr->symbols.objects_last_page; | |
3820 | else | |
3821 | sym_cnt = fil_ptr->symbols.objects_per_page; | |
3822 | sym_ptr = sym_link->datum->sym; | |
3823 | sym_end = sym_ptr + sym_cnt; | |
3824 | for (; sym_ptr < sym_end; sym_ptr++) | |
3825 | { | |
3826 | int local; | |
f6a91cc0 | 3827 | symbolS *as_sym; |
3d3c5039 ILT |
3828 | forward_t *f; |
3829 | ||
3830 | know (sym_ptr->file_ptr == fil_ptr); | |
3831 | ||
3832 | /* If there is no associated gas symbol, then this | |
3833 | is a pure debugging symbol. We have already | |
3834 | added the name (if any) to fil_ptr->strings. | |
3835 | Otherwise we must decide whether this is an | |
3836 | external or a local symbol (actually, it may be | |
3837 | both if the local provides additional debugging | |
3838 | information for the external). */ | |
3839 | local = 1; | |
f6a91cc0 ILT |
3840 | as_sym = sym_ptr->as_sym; |
3841 | if (as_sym != (symbolS *) NULL) | |
3d3c5039 | 3842 | { |
670a50eb ILT |
3843 | symint_t indx; |
3844 | ||
3845 | /* The value of a block start symbol is the | |
3846 | offset from the start of the procedure. For | |
3847 | other symbols we just use the gas value. */ | |
3848 | if (sym_ptr->ecoff_sym.st == (int) st_Block | |
3849 | && sym_ptr->ecoff_sym.sc == (int) sc_Text) | |
3850 | { | |
3851 | know (sym_ptr->proc_ptr != (proc_t *) NULL); | |
3852 | sym_ptr->ecoff_sym.value = | |
918692a5 ILT |
3853 | (bfd_asymbol_value (as_sym->bsym) |
3854 | - bfd_asymbol_value (sym_ptr->proc_ptr->sym | |
3855 | ->as_sym->bsym)); | |
670a50eb ILT |
3856 | } |
3857 | else | |
918692a5 ILT |
3858 | sym_ptr->ecoff_sym.value = |
3859 | bfd_asymbol_value (as_sym->bsym); | |
3860 | ||
3861 | /* Set st_Proc to st_StaticProc for local | |
3862 | functions. */ | |
3863 | if (sym_ptr->ecoff_sym.st == st_Proc | |
3864 | && S_IS_DEFINED (as_sym) | |
3865 | && ! S_IS_EXTERNAL (as_sym)) | |
3866 | sym_ptr->ecoff_sym.st = st_StaticProc; | |
f6a91cc0 ILT |
3867 | |
3868 | /* Get the type and storage class based on where | |
670a50eb ILT |
3869 | the symbol actually wound up. Traditionally, |
3870 | N_LBRAC and N_RBRAC are *not* relocated. */ | |
3871 | indx = sym_ptr->ecoff_sym.index; | |
f6a91cc0 ILT |
3872 | if (sym_ptr->ecoff_sym.st == st_Nil |
3873 | && sym_ptr->ecoff_sym.sc == sc_Nil | |
670a50eb ILT |
3874 | && (! MIPS_IS_STAB (&sym_ptr->ecoff_sym) |
3875 | || ((MIPS_UNMARK_STAB (indx) != N_LBRAC) | |
3876 | && (MIPS_UNMARK_STAB (indx) != N_RBRAC)))) | |
f6a91cc0 | 3877 | { |
670a50eb ILT |
3878 | segT seg; |
3879 | const char *segname; | |
f6a91cc0 ILT |
3880 | st_t st; |
3881 | sc_t sc; | |
3882 | ||
670a50eb ILT |
3883 | seg = S_GET_SEGMENT (as_sym); |
3884 | segname = segment_name (seg); | |
3885 | ||
f6a91cc0 ILT |
3886 | if (S_IS_EXTERNAL (as_sym) |
3887 | || ! S_IS_DEFINED (as_sym)) | |
3888 | st = st_Global; | |
670a50eb | 3889 | else if (seg == text_section) |
f6a91cc0 ILT |
3890 | st = st_Label; |
3891 | else | |
3892 | st = st_Static; | |
3893 | ||
670a50eb ILT |
3894 | if (! S_IS_DEFINED (as_sym) |
3895 | || as_sym->ecoff_undefined) | |
3896 | { | |
3897 | if (S_GET_VALUE (as_sym) > 0 | |
3898 | && (S_GET_VALUE (as_sym) | |
3899 | <= bfd_get_gp_size (stdoutput))) | |
3900 | sc = sc_SUndefined; | |
3901 | else | |
3902 | sc = sc_Undefined; | |
3903 | } | |
f6a91cc0 | 3904 | else if (S_IS_COMMON (as_sym)) |
670a50eb ILT |
3905 | { |
3906 | if (S_GET_VALUE (as_sym) > 0 | |
3907 | && (S_GET_VALUE (as_sym) | |
3908 | <= bfd_get_gp_size (stdoutput))) | |
3909 | sc = sc_SCommon; | |
3910 | else | |
3911 | sc = sc_Common; | |
3912 | } | |
3913 | else if (seg == text_section) | |
f6a91cc0 | 3914 | sc = sc_Text; |
670a50eb | 3915 | else if (seg == data_section) |
f6a91cc0 | 3916 | sc = sc_Data; |
670a50eb ILT |
3917 | else if (strcmp (segname, ".rdata") == 0) |
3918 | sc = sc_RData; | |
3919 | else if (strcmp (segname, ".sdata") == 0) | |
3920 | sc = sc_SData; | |
3921 | else if (seg == bss_section) | |
f6a91cc0 | 3922 | sc = sc_Bss; |
670a50eb ILT |
3923 | else if (strcmp (segname, ".sbss") == 0) |
3924 | sc = sc_SBss; | |
918692a5 ILT |
3925 | else if (seg == &bfd_abs_section) |
3926 | sc = sc_Abs; | |
f6a91cc0 ILT |
3927 | else |
3928 | abort (); | |
3929 | ||
3930 | sym_ptr->ecoff_sym.st = (int) st; | |
3931 | sym_ptr->ecoff_sym.sc = (int) sc; | |
3932 | } | |
3d3c5039 ILT |
3933 | |
3934 | /* This is just an external symbol if it is | |
f6a91cc0 ILT |
3935 | outside a procedure and it has a type. |
3936 | FIXME: g++ will generate symbols which have | |
3937 | different names in the debugging information | |
3938 | than the actual symbol. Should we handle | |
3939 | them here? */ | |
3940 | if ((S_IS_EXTERNAL (as_sym) | |
3941 | || ! S_IS_DEFINED (as_sym)) | |
3d3c5039 | 3942 | && sym_ptr->proc_ptr == (proc_t *) NULL |
670a50eb ILT |
3943 | && sym_ptr->ecoff_sym.st != (int) st_Nil |
3944 | && ! MIPS_IS_STAB (&sym_ptr->ecoff_sym)) | |
3d3c5039 ILT |
3945 | local = 0; |
3946 | ||
3947 | /* If an st_end symbol has an associated gas | |
f6a91cc0 | 3948 | symbol, then it is a local label created for |
670a50eb ILT |
3949 | a .bend or .end directive. Stabs line |
3950 | numbers will have \001 in the names. */ | |
3951 | if (local | |
3952 | && sym_ptr->ecoff_sym.st != st_End | |
3953 | && strchr (sym_ptr->name, '\001') == 0) | |
3d3c5039 ILT |
3954 | sym_ptr->ecoff_sym.iss = |
3955 | add_string (&fil_ptr->strings, | |
3956 | fil_ptr->str_hash, | |
f6a91cc0 | 3957 | sym_ptr->name, |
3d3c5039 ILT |
3958 | (shash_t **) NULL); |
3959 | } | |
3960 | ||
3961 | /* We now know the index of this symbol; fill in | |
3962 | locations that have been waiting for that | |
3963 | information. */ | |
3964 | if (sym_ptr->begin_ptr != (localsym_t *) NULL) | |
3965 | { | |
3966 | localsym_t *begin_ptr; | |
3967 | st_t begin_type; | |
3968 | ||
3969 | know (local); | |
3970 | begin_ptr = sym_ptr->begin_ptr; | |
3971 | know (begin_ptr->sym_index != -1); | |
3972 | sym_ptr->ecoff_sym.index = begin_ptr->sym_index; | |
3973 | if (sym_ptr->ecoff_sym.sc != (int) sc_Info) | |
3974 | sym_ptr->ecoff_sym.iss = begin_ptr->ecoff_sym.iss; | |
3975 | ||
3976 | begin_type = begin_ptr->ecoff_sym.st; | |
3977 | if (begin_type == st_File | |
3978 | || begin_type == st_Block) | |
3979 | { | |
3980 | begin_ptr->ecoff_sym.index = isym - ifilesym + 1; | |
3981 | ecoff_swap_sym_out (stdoutput, | |
3982 | &begin_ptr->ecoff_sym, | |
3983 | (((struct sym_ext *) | |
3984 | (*buf + offset)) | |
3985 | + begin_ptr->sym_index)); | |
3986 | } | |
3987 | else | |
3988 | { | |
349f20de ILT |
3989 | know (begin_ptr->index_ptr != (aux_t *) NULL); |
3990 | begin_ptr->index_ptr->data.isym = | |
3d3c5039 ILT |
3991 | isym - ifilesym + 1; |
3992 | } | |
3993 | ||
3994 | /* The value of the symbol marking the end of a | |
670a50eb ILT |
3995 | procedure is the size of the procedure. The |
3996 | value of the symbol marking the end of a | |
3997 | block is the offset from the start of the | |
3998 | procedure to the block. */ | |
3999 | if (begin_type == st_Proc) | |
3d3c5039 | 4000 | { |
f6a91cc0 | 4001 | know (as_sym != (symbolS *) NULL); |
3d3c5039 ILT |
4002 | know (begin_ptr->as_sym != (symbolS *) NULL); |
4003 | sym_ptr->ecoff_sym.value = | |
918692a5 ILT |
4004 | (bfd_asymbol_value (as_sym->bsym) |
4005 | - bfd_asymbol_value (begin_ptr->as_sym->bsym)); | |
3d3c5039 | 4006 | } |
670a50eb ILT |
4007 | else if (begin_type == st_Block |
4008 | && sym_ptr->ecoff_sym.sc != (int) sc_Info) | |
4009 | { | |
4010 | know (as_sym != (symbolS *) NULL); | |
4011 | know (sym_ptr->proc_ptr != (proc_t *) NULL); | |
4012 | sym_ptr->ecoff_sym.value = | |
918692a5 ILT |
4013 | (bfd_asymbol_value (as_sym->bsym) |
4014 | - bfd_asymbol_value (sym_ptr->proc_ptr->sym | |
4015 | ->as_sym->bsym)); | |
670a50eb | 4016 | } |
3d3c5039 ILT |
4017 | } |
4018 | ||
4019 | for (f = sym_ptr->forward_ref; | |
4020 | f != (forward_t *) NULL; | |
4021 | f = f->next) | |
4022 | { | |
4023 | know (local); | |
4024 | f->ifd_ptr->data.isym = fil_ptr->file_index; | |
4025 | f->index_ptr->data.rndx.index = isym - ifilesym; | |
4026 | } | |
4027 | ||
4028 | if (local) | |
4029 | { | |
4030 | if (*bufend - (char *) sym_out < sizeof (struct sym_ext)) | |
4031 | sym_out = ((struct sym_ext *) | |
4032 | ecoff_add_bytes (buf, bufend, | |
4033 | (char *) sym_out, | |
4034 | sizeof (struct sym_ext))); | |
4035 | ecoff_swap_sym_out (stdoutput, &sym_ptr->ecoff_sym, | |
4036 | sym_out); | |
4037 | ++sym_out; | |
670a50eb | 4038 | |
3d3c5039 | 4039 | sym_ptr->sym_index = isym; |
3d3c5039 ILT |
4040 | |
4041 | if (sym_ptr->proc_ptr != (proc_t *) NULL | |
4042 | && sym_ptr->proc_ptr->sym == sym_ptr) | |
4043 | sym_ptr->proc_ptr->pdr.isym = isym - ifilesym; | |
670a50eb ILT |
4044 | |
4045 | ++isym; | |
3d3c5039 ILT |
4046 | } |
4047 | ||
4048 | /* If this is an external symbol, swap it out. */ | |
f6a91cc0 ILT |
4049 | if (as_sym != (symbolS *) NULL |
4050 | && (S_IS_EXTERNAL (as_sym) | |
670a50eb ILT |
4051 | || ! S_IS_DEFINED (as_sym)) |
4052 | && ! MIPS_IS_STAB (&sym_ptr->ecoff_sym)) | |
3d3c5039 ILT |
4053 | { |
4054 | EXTR ext; | |
4055 | ||
4056 | memset (&ext, 0, sizeof ext); | |
4057 | ext.asym = sym_ptr->ecoff_sym; | |
918692a5 ILT |
4058 | if (sym_ptr->ecoff_sym.st == st_Proc |
4059 | || sym_ptr->ecoff_sym.st == st_StaticProc) | |
4060 | { | |
4061 | know (local); | |
4062 | ext.asym.index = isym - ifilesym - 1; | |
4063 | } | |
3d3c5039 ILT |
4064 | ext.ifd = fil_ptr->file_index; |
4065 | ext.asym.iss = add_string (ext_strings, | |
4066 | ext_str_hash, | |
f6a91cc0 | 4067 | S_GET_NAME (as_sym), |
3d3c5039 ILT |
4068 | (shash_t **) NULL); |
4069 | if (*extbufend - (char *) ext_out | |
4070 | < sizeof (struct ext_ext)) | |
4071 | ext_out = ((struct ext_ext *) | |
4072 | ecoff_add_bytes (extbuf, extbufend, | |
4073 | (char *) ext_out, | |
4074 | sizeof (struct ext_ext))); | |
4075 | ecoff_swap_ext_out (stdoutput, &ext, ext_out); | |
f6a91cc0 | 4076 | ecoff_set_sym_index (as_sym->bsym, iext); |
3d3c5039 ILT |
4077 | ++ext_out; |
4078 | ++iext; | |
4079 | } | |
4080 | } | |
4081 | } | |
4082 | fil_ptr->fdr.csym = isym - fil_ptr->fdr.isymBase; | |
4083 | } | |
4084 | } | |
4085 | ||
4086 | *extoffset += iext * sizeof (struct ext_ext); | |
4087 | return offset + isym * sizeof (struct sym_ext); | |
4088 | } | |
4089 | ||
4090 | /* Swap out the procedure information. */ | |
4091 | ||
4092 | static long | |
4093 | ecoff_build_procs (buf, bufend, offset) | |
4094 | char **buf; | |
4095 | char **bufend; | |
4096 | long offset; | |
4097 | { | |
4098 | struct pdr_ext *pdr_out; | |
918692a5 | 4099 | int first_fil; |
3d3c5039 ILT |
4100 | long iproc; |
4101 | vlinks_t *file_link; | |
4102 | ||
4103 | pdr_out = (struct pdr_ext *) (*buf + offset); | |
4104 | ||
918692a5 | 4105 | first_fil = 1; |
3d3c5039 ILT |
4106 | iproc = 0; |
4107 | ||
4108 | /* The procedures are stored by file. */ | |
4109 | for (file_link = file_desc.first; | |
4110 | file_link != (vlinks_t *) NULL; | |
4111 | file_link = file_link->next) | |
4112 | { | |
4113 | int fil_cnt; | |
4114 | efdr_t *fil_ptr; | |
4115 | efdr_t *fil_end; | |
4116 | ||
4117 | if (file_link->next == (vlinks_t *) NULL) | |
4118 | fil_cnt = file_desc.objects_last_page; | |
4119 | else | |
4120 | fil_cnt = file_desc.objects_per_page; | |
4121 | fil_ptr = file_link->datum->file; | |
4122 | fil_end = fil_ptr + fil_cnt; | |
4123 | for (; fil_ptr < fil_end; fil_ptr++) | |
4124 | { | |
4125 | vlinks_t *proc_link; | |
4126 | int first; | |
4127 | ||
4128 | fil_ptr->fdr.ipdFirst = iproc; | |
4129 | first = 1; | |
4130 | for (proc_link = fil_ptr->procs.first; | |
4131 | proc_link != (vlinks_t *) NULL; | |
4132 | proc_link = proc_link->next) | |
4133 | { | |
4134 | int proc_cnt; | |
4135 | proc_t *proc_ptr; | |
4136 | proc_t *proc_end; | |
4137 | ||
4138 | if (proc_link->next == (vlinks_t *) NULL) | |
4139 | proc_cnt = fil_ptr->procs.objects_last_page; | |
4140 | else | |
4141 | proc_cnt = fil_ptr->procs.objects_per_page; | |
4142 | proc_ptr = proc_link->datum->proc; | |
4143 | proc_end = proc_ptr + proc_cnt; | |
4144 | for (; proc_ptr < proc_end; proc_ptr++) | |
4145 | { | |
4146 | unsigned long adr; | |
4147 | ||
918692a5 | 4148 | adr = bfd_asymbol_value (proc_ptr->sym->as_sym->bsym); |
3d3c5039 ILT |
4149 | if (first) |
4150 | { | |
918692a5 ILT |
4151 | if (first_fil) |
4152 | first_fil = 0; | |
4153 | else | |
4154 | fil_ptr->fdr.adr = adr; | |
3d3c5039 ILT |
4155 | first = 0; |
4156 | } | |
4157 | proc_ptr->pdr.adr = adr - fil_ptr->fdr.adr; | |
4158 | if (*bufend - (char *) pdr_out < sizeof (struct pdr_ext)) | |
4159 | pdr_out = ((struct pdr_ext *) | |
4160 | ecoff_add_bytes (buf, bufend, | |
4161 | (char *) pdr_out, | |
4162 | sizeof (struct pdr_ext))); | |
4163 | ecoff_swap_pdr_out (stdoutput, &proc_ptr->pdr, pdr_out); | |
4164 | ++pdr_out; | |
4165 | ++iproc; | |
4166 | } | |
4167 | } | |
4168 | fil_ptr->fdr.cpd = iproc - fil_ptr->fdr.ipdFirst; | |
4169 | } | |
4170 | } | |
4171 | ||
4172 | return offset + iproc * sizeof (struct pdr_ext); | |
4173 | } | |
4174 | ||
4175 | /* Swap out the aux information. */ | |
4176 | ||
4177 | static long | |
4178 | ecoff_build_aux (buf, bufend, offset) | |
4179 | char **buf; | |
4180 | char **bufend; | |
4181 | long offset; | |
4182 | { | |
4183 | int bigendian; | |
4184 | union aux_ext *aux_out; | |
4185 | long iaux; | |
4186 | vlinks_t *file_link; | |
4187 | ||
4188 | bigendian = stdoutput->xvec->header_byteorder_big_p; | |
4189 | ||
4190 | aux_out = (union aux_ext *) (*buf + offset); | |
4191 | ||
4192 | iaux = 0; | |
4193 | ||
4194 | /* The aux entries are stored by file. */ | |
4195 | for (file_link = file_desc.first; | |
4196 | file_link != (vlinks_t *) NULL; | |
4197 | file_link = file_link->next) | |
4198 | { | |
4199 | int fil_cnt; | |
4200 | efdr_t *fil_ptr; | |
4201 | efdr_t *fil_end; | |
4202 | ||
4203 | if (file_link->next == (vlinks_t *) NULL) | |
4204 | fil_cnt = file_desc.objects_last_page; | |
4205 | else | |
4206 | fil_cnt = file_desc.objects_per_page; | |
4207 | fil_ptr = file_link->datum->file; | |
4208 | fil_end = fil_ptr + fil_cnt; | |
4209 | for (; fil_ptr < fil_end; fil_ptr++) | |
4210 | { | |
4211 | vlinks_t *aux_link; | |
4212 | ||
4213 | fil_ptr->fdr.fBigendian = bigendian; | |
4214 | fil_ptr->fdr.iauxBase = iaux; | |
4215 | for (aux_link = fil_ptr->aux_syms.first; | |
4216 | aux_link != (vlinks_t *) NULL; | |
4217 | aux_link = aux_link->next) | |
4218 | { | |
4219 | int aux_cnt; | |
4220 | aux_t *aux_ptr; | |
4221 | aux_t *aux_end; | |
4222 | ||
4223 | if (aux_link->next == (vlinks_t *) NULL) | |
4224 | aux_cnt = fil_ptr->aux_syms.objects_last_page; | |
4225 | else | |
4226 | aux_cnt = fil_ptr->aux_syms.objects_per_page; | |
4227 | aux_ptr = aux_link->datum->aux; | |
4228 | aux_end = aux_ptr + aux_cnt; | |
4229 | for (; aux_ptr < aux_end; aux_ptr++) | |
4230 | { | |
4231 | if (*bufend - (char *) aux_out < sizeof (union aux_ext)) | |
4232 | aux_out = ((union aux_ext *) | |
4233 | ecoff_add_bytes (buf, bufend, | |
4234 | (char *) aux_out, | |
4235 | sizeof (union aux_ext))); | |
4236 | switch (aux_ptr->type) | |
4237 | { | |
4238 | case aux_tir: | |
4239 | ecoff_swap_tir_out (bigendian, &aux_ptr->data.ti, | |
4240 | &aux_out->a_ti); | |
4241 | break; | |
4242 | case aux_rndx: | |
4243 | ecoff_swap_rndx_out (bigendian, &aux_ptr->data.rndx, | |
4244 | &aux_out->a_rndx); | |
4245 | break; | |
4246 | case aux_dnLow: | |
4247 | AUX_PUT_DNLOW (bigendian, aux_ptr->data.dnLow, | |
4248 | aux_out); | |
4249 | break; | |
4250 | case aux_dnHigh: | |
4251 | AUX_PUT_DNHIGH (bigendian, aux_ptr->data.dnHigh, | |
4252 | aux_out); | |
4253 | break; | |
4254 | case aux_isym: | |
4255 | AUX_PUT_ISYM (bigendian, aux_ptr->data.isym, | |
4256 | aux_out); | |
4257 | break; | |
4258 | case aux_iss: | |
4259 | AUX_PUT_ISS (bigendian, aux_ptr->data.iss, | |
4260 | aux_out); | |
4261 | break; | |
4262 | case aux_width: | |
4263 | AUX_PUT_WIDTH (bigendian, aux_ptr->data.width, | |
4264 | aux_out); | |
4265 | break; | |
4266 | case aux_count: | |
4267 | AUX_PUT_COUNT (bigendian, aux_ptr->data.count, | |
4268 | aux_out); | |
4269 | break; | |
4270 | } | |
4271 | ||
4272 | ++aux_out; | |
4273 | ++iaux; | |
4274 | } | |
4275 | } | |
4276 | fil_ptr->fdr.caux = iaux - fil_ptr->fdr.iauxBase; | |
4277 | } | |
4278 | } | |
4279 | ||
4280 | return offset + iaux * sizeof (union aux_ext); | |
4281 | } | |
4282 | ||
4283 | /* Copy out the strings from a varray_t. This returns the number of | |
4284 | bytes copied, rather than the new offset. */ | |
4285 | ||
4286 | static long | |
4287 | ecoff_build_strings (buf, bufend, offset, vp) | |
4288 | char **buf; | |
4289 | char **bufend; | |
4290 | long offset; | |
4291 | varray_t *vp; | |
4292 | { | |
4293 | long istr; | |
4294 | char *str_out; | |
4295 | vlinks_t *str_link; | |
4296 | ||
4297 | str_out = *buf + offset; | |
4298 | ||
4299 | istr = 0; | |
4300 | ||
4301 | for (str_link = vp->first; | |
4302 | str_link != (vlinks_t *) NULL; | |
4303 | str_link = str_link->next) | |
4304 | { | |
4305 | long str_cnt; | |
4306 | ||
4307 | if (str_link->next == (vlinks_t *) NULL) | |
4308 | str_cnt = vp->objects_last_page; | |
4309 | else | |
4310 | str_cnt = vp->objects_per_page; | |
4311 | ||
4312 | if (*bufend - str_out < str_cnt) | |
4313 | str_out = ecoff_add_bytes (buf, bufend, str_out, str_cnt); | |
4314 | ||
4315 | memcpy (str_out, str_link->datum->byte, str_cnt); | |
4316 | str_out += str_cnt; | |
4317 | istr += str_cnt; | |
4318 | } | |
4319 | ||
4320 | return istr; | |
4321 | } | |
4322 | ||
4323 | /* Dump out the local strings. */ | |
4324 | ||
4325 | static long | |
4326 | ecoff_build_ss (buf, bufend, offset) | |
4327 | char **buf; | |
4328 | char **bufend; | |
4329 | long offset; | |
4330 | { | |
4331 | long iss; | |
4332 | vlinks_t *file_link; | |
4333 | ||
4334 | iss = 0; | |
4335 | ||
4336 | for (file_link = file_desc.first; | |
4337 | file_link != (vlinks_t *) NULL; | |
4338 | file_link = file_link->next) | |
4339 | { | |
4340 | int fil_cnt; | |
4341 | efdr_t *fil_ptr; | |
4342 | efdr_t *fil_end; | |
4343 | ||
4344 | if (file_link->next == (vlinks_t *) NULL) | |
4345 | fil_cnt = file_desc.objects_last_page; | |
4346 | else | |
4347 | fil_cnt = file_desc.objects_per_page; | |
4348 | fil_ptr = file_link->datum->file; | |
4349 | fil_end = fil_ptr + fil_cnt; | |
4350 | for (; fil_ptr < fil_end; fil_ptr++) | |
4351 | { | |
4352 | long ss_cnt; | |
4353 | ||
4354 | fil_ptr->fdr.issBase = iss; | |
4355 | ss_cnt = ecoff_build_strings (buf, bufend, offset + iss, | |
4356 | &fil_ptr->strings); | |
4357 | fil_ptr->fdr.cbSs = ss_cnt; | |
4358 | iss += ss_cnt; | |
4359 | } | |
4360 | } | |
4361 | ||
4362 | return ecoff_longword_adjust (buf, bufend, offset + iss, (char **) NULL); | |
4363 | } | |
4364 | ||
4365 | /* Swap out the file descriptors. */ | |
4366 | ||
4367 | static long | |
4368 | ecoff_build_fdr (buf, bufend, offset) | |
4369 | char **buf; | |
4370 | char **bufend; | |
4371 | long offset; | |
4372 | { | |
4373 | long ifile; | |
4374 | struct fdr_ext *fdr_out; | |
4375 | vlinks_t *file_link; | |
4376 | ||
4377 | ifile = 0; | |
4378 | ||
4379 | fdr_out = (struct fdr_ext *) (*buf + offset); | |
4380 | ||
4381 | for (file_link = file_desc.first; | |
4382 | file_link != (vlinks_t *) NULL; | |
4383 | file_link = file_link->next) | |
4384 | { | |
4385 | int fil_cnt; | |
4386 | efdr_t *fil_ptr; | |
4387 | efdr_t *fil_end; | |
4388 | ||
4389 | if (file_link->next == (vlinks_t *) NULL) | |
4390 | fil_cnt = file_desc.objects_last_page; | |
4391 | else | |
4392 | fil_cnt = file_desc.objects_per_page; | |
4393 | fil_ptr = file_link->datum->file; | |
4394 | fil_end = fil_ptr + fil_cnt; | |
4395 | for (; fil_ptr < fil_end; fil_ptr++) | |
4396 | { | |
4397 | if (*bufend - (char *) fdr_out < sizeof (struct fdr_ext)) | |
4398 | fdr_out = ((struct fdr_ext *) | |
4399 | ecoff_add_bytes (buf, bufend, (char *) fdr_out, | |
4400 | sizeof (struct fdr_ext))); | |
4401 | ecoff_swap_fdr_out (stdoutput, &fil_ptr->fdr, fdr_out); | |
4402 | ++fdr_out; | |
4403 | ++ifile; | |
4404 | } | |
4405 | } | |
4406 | ||
4407 | return offset + ifile * sizeof (struct fdr_ext); | |
4408 | } | |
4409 | ||
3d3c5039 ILT |
4410 | /* Swap out the symbols and debugging information for BFD. */ |
4411 | ||
4412 | void | |
4413 | ecoff_frob_file () | |
4414 | { | |
f6a91cc0 ILT |
4415 | tag_t *ptag; |
4416 | tag_t *ptag_next; | |
3d3c5039 | 4417 | efdr_t *fil_ptr; |
5276e361 | 4418 | int end_warning; |
3d3c5039 ILT |
4419 | efdr_t *hold_file_ptr; |
4420 | proc_t * hold_proc_ptr; | |
918692a5 ILT |
4421 | bfd_vma addr; |
4422 | asection *sec; | |
3d3c5039 ILT |
4423 | symbolS *sym; |
4424 | HDRR *hdr; | |
4425 | char *buf; | |
4426 | char *bufend; | |
4427 | long offset; | |
4428 | char *extbuf; | |
4429 | char *extbufend; | |
4430 | long extoffset; | |
4431 | varray_t ext_strings; | |
4432 | static varray_t init_ext_strings = INIT_VARRAY (char); | |
4433 | struct hash_control *ext_str_hash; | |
4434 | char *set; | |
4435 | ||
670a50eb ILT |
4436 | /* Make sure we have a file. */ |
4437 | if (first_file == (efdr_t *) NULL) | |
4438 | add_file ((const char *) NULL, 0); | |
4439 | ||
f6a91cc0 ILT |
4440 | /* Handle any top level tags. */ |
4441 | for (ptag = top_tag_head->first_tag; | |
4442 | ptag != (tag_t *) NULL; | |
4443 | ptag = ptag_next) | |
4444 | { | |
4445 | if (ptag->forward_ref != (forward_t *) NULL) | |
4446 | add_unknown_tag (ptag); | |
4447 | ||
4448 | ptag_next = ptag->same_block; | |
4449 | ptag->hash_ptr->tag_ptr = ptag->same_name; | |
4450 | free_tag (ptag); | |
4451 | } | |
4452 | ||
4453 | free_thead (top_tag_head); | |
4454 | ||
3d3c5039 ILT |
4455 | /* Output an ending symbol for all the files. We have to do this |
4456 | here for the last file, so we may as well do it for all of the | |
4457 | files. */ | |
5276e361 | 4458 | end_warning = 0; |
3d3c5039 ILT |
4459 | for (fil_ptr = first_file; |
4460 | fil_ptr != (efdr_t *) NULL; | |
4461 | fil_ptr = fil_ptr->next_file) | |
4462 | { | |
4463 | cur_file_ptr = fil_ptr; | |
5276e361 ILT |
4464 | while (cur_file_ptr->cur_scope->prev != (scope_t *) NULL) |
4465 | { | |
4466 | cur_file_ptr->cur_scope = cur_file_ptr->cur_scope->prev; | |
4467 | if (! end_warning) | |
4468 | { | |
4469 | as_warn ("Missing .end or .bend at end of file"); | |
4470 | end_warning = 1; | |
4471 | } | |
4472 | } | |
3d3c5039 ILT |
4473 | (void) add_ecoff_symbol ((const char *) NULL, |
4474 | st_End, sc_Text, | |
4475 | (symbolS *) NULL, | |
4476 | (symint_t) 0, | |
4477 | (symint_t) 0); | |
4478 | } | |
4479 | ||
918692a5 ILT |
4480 | /* Set the section VMA values. */ |
4481 | addr = 0; | |
4482 | for (sec = stdoutput->sections; sec != (asection *) NULL; sec = sec->next) | |
4483 | { | |
4484 | bfd_set_section_vma (stdoutput, sec, addr); | |
4485 | addr += bfd_section_size (stdoutput, sec); | |
4486 | } | |
4487 | ||
3d3c5039 ILT |
4488 | /* Look through the symbols. Add debugging information for each |
4489 | symbol that has not already received it. */ | |
4490 | hold_file_ptr = cur_file_ptr; | |
4491 | hold_proc_ptr = cur_proc_ptr; | |
4492 | cur_proc_ptr = (proc_t *) NULL; | |
4493 | for (sym = symbol_rootP; sym != (symbolS *) NULL; sym = symbol_next (sym)) | |
4494 | { | |
3d3c5039 | 4495 | if (sym->ecoff_symbol |
918692a5 ILT |
4496 | || sym->ecoff_file == (efdr_t *) NULL |
4497 | || (sym->bsym->flags & BSF_SECTION_SYM) != 0) | |
3d3c5039 ILT |
4498 | continue; |
4499 | ||
3d3c5039 | 4500 | cur_file_ptr = sym->ecoff_file; |
f6a91cc0 | 4501 | add_ecoff_symbol ((const char *) NULL, st_Nil, sc_Nil, sym, |
918692a5 | 4502 | bfd_asymbol_value (sym->bsym), indexNil); |
3d3c5039 ILT |
4503 | } |
4504 | cur_proc_ptr = hold_proc_ptr; | |
4505 | cur_file_ptr = hold_file_ptr; | |
4506 | ||
4507 | /* Build the symbolic information. */ | |
4508 | hdr = &ecoff_data (stdoutput)->symbolic_header; | |
4509 | offset = 0; | |
4510 | buf = xmalloc (PAGE_SIZE); | |
4511 | bufend = buf + PAGE_SIZE; | |
4512 | ||
4513 | /* Build the line number information. */ | |
4514 | hdr->cbLineOffset = offset; | |
4515 | offset = ecoff_build_lineno (&buf, &bufend, offset, &hdr->ilineMax); | |
4516 | hdr->cbLine = offset - hdr->cbLineOffset; | |
4517 | ||
4518 | /* We don't use dense numbers at all. */ | |
4519 | hdr->idnMax = 0; | |
4520 | hdr->cbDnOffset = 0; | |
4521 | ||
4522 | /* We can't build the PDR table until we have built the symbols, | |
4523 | because a PDR contains a symbol index. However, we set aside | |
4524 | space at this point. */ | |
4525 | hdr->ipdMax = proc_cnt; | |
4526 | hdr->cbPdOffset = offset; | |
4527 | if (bufend - (buf + offset) < proc_cnt * sizeof (struct pdr_ext)) | |
4528 | (void) ecoff_add_bytes (&buf, &bufend, buf + offset, | |
4529 | proc_cnt * sizeof (struct pdr_ext)); | |
4530 | offset += proc_cnt * sizeof (struct pdr_ext); | |
4531 | ||
4532 | /* Build the symbols. It's convenient to build both the local and | |
4533 | external symbols at the same time. We can put the local symbols | |
4534 | directly into the buffer, but we have to hold the external | |
4535 | symbols apart until we know where they are going to go. */ | |
4536 | extbuf = xmalloc (PAGE_SIZE); | |
4537 | extbufend = extbuf + PAGE_SIZE; | |
4538 | extoffset = 0; | |
4539 | ext_strings = init_ext_strings; | |
4540 | ext_str_hash = hash_new (); | |
4541 | hdr->cbSymOffset = offset; | |
4542 | offset = ecoff_build_symbols (&buf, &bufend, offset, | |
4543 | &extbuf, &extbufend, &extoffset, | |
4544 | &ext_strings, ext_str_hash); | |
4545 | hdr->isymMax = (offset - hdr->cbSymOffset) / sizeof (struct sym_ext); | |
4546 | ||
4547 | /* Building the symbols initializes the symbol index in the PDR's. | |
4548 | Now we can swap out the PDR's. */ | |
4549 | (void) ecoff_build_procs (&buf, &bufend, hdr->cbPdOffset); | |
4550 | ||
4551 | /* We don't use optimization symbols. */ | |
4552 | hdr->ioptMax = 0; | |
4553 | hdr->cbOptOffset = 0; | |
4554 | ||
4555 | /* Swap out the auxiliary type information. */ | |
4556 | hdr->cbAuxOffset = offset; | |
4557 | offset = ecoff_build_aux (&buf, &bufend, offset); | |
4558 | hdr->iauxMax = (offset - hdr->cbAuxOffset) / sizeof (union aux_ext); | |
4559 | ||
4560 | /* Copy out the local strings. */ | |
4561 | hdr->cbSsOffset = offset; | |
4562 | offset = ecoff_build_ss (&buf, &bufend, offset); | |
4563 | hdr->issMax = offset - hdr->cbSsOffset; | |
4564 | ||
4565 | /* Copy out the external strings. */ | |
4566 | hdr->cbSsExtOffset = offset; | |
4567 | offset += ecoff_build_strings (&buf, &bufend, offset, &ext_strings); | |
4568 | offset = ecoff_longword_adjust (&buf, &bufend, offset, (char **) NULL); | |
4569 | hdr->issExtMax = offset - hdr->cbSsExtOffset; | |
4570 | ||
4571 | /* We don't use relative file descriptors. */ | |
4572 | hdr->crfd = 0; | |
4573 | hdr->cbRfdOffset = 0; | |
4574 | ||
4575 | /* Swap out the file descriptors. */ | |
4576 | hdr->cbFdOffset = offset; | |
4577 | offset = ecoff_build_fdr (&buf, &bufend, offset); | |
4578 | hdr->ifdMax = (offset - hdr->cbFdOffset) / sizeof (struct fdr_ext); | |
4579 | ||
4580 | /* Copy out the external symbols. */ | |
4581 | hdr->cbExtOffset = offset; | |
4582 | if (bufend - (buf + offset) < extoffset) | |
4583 | (void) ecoff_add_bytes (&buf, &bufend, buf + offset, extoffset); | |
4584 | memcpy (buf + offset, extbuf, extoffset); | |
4585 | offset += extoffset; | |
4586 | hdr->iextMax = (offset - hdr->cbExtOffset) / sizeof (struct ext_ext); | |
4587 | ||
4588 | know ((offset & 3) == 0); | |
4589 | ||
4590 | /* That completes the symbolic debugging information. We must now | |
4591 | finish up the symbolic header and the ecoff_tdata structure. */ | |
4592 | set = buf; | |
4593 | #define SET(ptr, count, type) \ | |
4594 | ecoff_data (stdoutput)->ptr = (type *) set; \ | |
4595 | set += hdr->count * sizeof (type) | |
4596 | ||
4597 | SET (line, cbLine, unsigned char); | |
4598 | SET (external_dnr, idnMax, struct dnr_ext); | |
4599 | SET (external_pdr, ipdMax, struct pdr_ext); | |
4600 | SET (external_sym, isymMax, struct sym_ext); | |
4601 | SET (external_opt, ioptMax, struct opt_ext); | |
4602 | SET (external_aux, iauxMax, union aux_ext); | |
4603 | SET (ss, issMax, char); | |
4604 | SET (ssext, issExtMax, char); | |
4605 | SET (external_rfd, crfd, struct rfd_ext); | |
4606 | SET (external_fdr, ifdMax, struct fdr_ext); | |
4607 | SET (external_ext, iextMax, struct ext_ext); | |
4608 | ||
4609 | #undef SET | |
4610 | ||
3d3c5039 ILT |
4611 | /* FIXME: set the register masks. */ |
4612 | ||
4613 | ecoff_data (stdoutput)->raw_size = offset; | |
4614 | ecoff_data (stdoutput)->raw_syments = buf; | |
4615 | ||
4616 | hdr->magic = magicSym; | |
4617 | /* FIXME: what should hdr->vstamp be? */ | |
918692a5 ILT |
4618 | |
4619 | bfd_set_symtab (stdoutput, bfd_get_outsymbols (stdoutput), | |
4620 | hdr->isymMax + hdr->iextMax); | |
3d3c5039 ILT |
4621 | } |
4622 | \f | |
4623 | /* Allocate a cluster of pages. */ | |
4624 | ||
4625 | #ifndef MALLOC_CHECK | |
4626 | ||
4627 | static page_t * | |
4628 | allocate_cluster (npages) | |
4629 | unsigned long npages; | |
4630 | { | |
4631 | register page_t *value = (page_t *) xmalloc (npages * PAGE_USIZE); | |
4632 | ||
4633 | #ifdef ECOFF_DEBUG | |
4634 | if (debug > 3) | |
4635 | fprintf (stderr, "\talloc\tnpages = %d, value = 0x%.8x\n", npages, value); | |
4636 | #endif | |
4637 | ||
4638 | memset (value, 0, npages * PAGE_USIZE); | |
4639 | ||
4640 | return value; | |
4641 | } | |
4642 | ||
4643 | ||
4644 | static page_t *cluster_ptr = NULL; | |
4645 | static unsigned long pages_left = 0; | |
4646 | ||
4647 | #endif /* MALLOC_CHECK */ | |
4648 | ||
4649 | /* Allocate one page (which is initialized to 0). */ | |
4650 | ||
4651 | static page_t * | |
4652 | allocate_page () | |
4653 | { | |
4654 | #ifndef MALLOC_CHECK | |
4655 | ||
4656 | if (pages_left == 0) | |
4657 | { | |
4658 | pages_left = MAX_CLUSTER_PAGES; | |
4659 | cluster_ptr = allocate_cluster (pages_left); | |
4660 | } | |
4661 | ||
4662 | pages_left--; | |
4663 | return cluster_ptr++; | |
4664 | ||
4665 | #else /* MALLOC_CHECK */ | |
4666 | ||
4667 | page_t *ptr; | |
4668 | ||
4669 | ptr = xmalloc (PAGE_USIZE); | |
4670 | memset (ptr, 0, PAGE_USIZE); | |
4671 | return ptr; | |
4672 | ||
4673 | #endif /* MALLOC_CHECK */ | |
4674 | } | |
4675 | \f | |
4676 | /* Allocate scoping information. */ | |
4677 | ||
4678 | static scope_t * | |
4679 | allocate_scope () | |
4680 | { | |
4681 | register scope_t *ptr; | |
4682 | static scope_t initial_scope; | |
4683 | ||
4684 | #ifndef MALLOC_CHECK | |
4685 | ||
4686 | ptr = alloc_counts[(int)alloc_type_scope].free_list.f_scope; | |
4687 | if (ptr != (scope_t *) NULL) | |
4688 | alloc_counts[ (int)alloc_type_scope ].free_list.f_scope = ptr->free; | |
4689 | else | |
4690 | { | |
4691 | register int unallocated = alloc_counts[(int)alloc_type_scope].unallocated; | |
4692 | register page_t *cur_page = alloc_counts[(int)alloc_type_scope].cur_page; | |
4693 | ||
4694 | if (unallocated == 0) | |
4695 | { | |
4696 | unallocated = PAGE_SIZE / sizeof (scope_t); | |
4697 | alloc_counts[(int)alloc_type_scope].cur_page = cur_page = allocate_page (); | |
4698 | alloc_counts[(int)alloc_type_scope].total_pages++; | |
4699 | } | |
4700 | ||
4701 | ptr = &cur_page->scope[--unallocated]; | |
4702 | alloc_counts[(int)alloc_type_scope].unallocated = unallocated; | |
4703 | } | |
4704 | ||
4705 | #else | |
4706 | ||
4707 | ptr = (scope_t *) xmalloc (sizeof (scope_t)); | |
4708 | ||
4709 | #endif | |
4710 | ||
4711 | alloc_counts[(int)alloc_type_scope].total_alloc++; | |
4712 | *ptr = initial_scope; | |
4713 | return ptr; | |
4714 | } | |
4715 | ||
4716 | /* Free scoping information. */ | |
4717 | ||
4718 | static void | |
4719 | free_scope (ptr) | |
4720 | scope_t *ptr; | |
4721 | { | |
4722 | alloc_counts[(int)alloc_type_scope].total_free++; | |
4723 | ||
4724 | #ifndef MALLOC_CHECK | |
4725 | ptr->free = alloc_counts[(int)alloc_type_scope].free_list.f_scope; | |
4726 | alloc_counts[(int)alloc_type_scope].free_list.f_scope = ptr; | |
4727 | #else | |
4728 | free ((PTR) ptr); | |
4729 | #endif | |
4730 | } | |
4731 | \f | |
4732 | /* Allocate links for pages in a virtual array. */ | |
4733 | ||
4734 | static vlinks_t * | |
4735 | allocate_vlinks () | |
4736 | { | |
4737 | register vlinks_t *ptr; | |
4738 | static vlinks_t initial_vlinks; | |
4739 | ||
4740 | #ifndef MALLOC_CHECK | |
4741 | ||
4742 | register int unallocated = alloc_counts[(int)alloc_type_vlinks].unallocated; | |
4743 | register page_t *cur_page = alloc_counts[(int)alloc_type_vlinks].cur_page; | |
4744 | ||
4745 | if (unallocated == 0) | |
4746 | { | |
4747 | unallocated = PAGE_SIZE / sizeof (vlinks_t); | |
4748 | alloc_counts[(int)alloc_type_vlinks].cur_page = cur_page = allocate_page (); | |
4749 | alloc_counts[(int)alloc_type_vlinks].total_pages++; | |
4750 | } | |
4751 | ||
4752 | ptr = &cur_page->vlinks[--unallocated]; | |
4753 | alloc_counts[(int)alloc_type_vlinks].unallocated = unallocated; | |
4754 | ||
4755 | #else | |
4756 | ||
4757 | ptr = (vlinks_t *) xmalloc (sizeof (vlinks_t)); | |
4758 | ||
4759 | #endif | |
4760 | ||
4761 | alloc_counts[(int)alloc_type_vlinks].total_alloc++; | |
4762 | *ptr = initial_vlinks; | |
4763 | return ptr; | |
4764 | } | |
4765 | \f | |
4766 | /* Allocate string hash buckets. */ | |
4767 | ||
4768 | static shash_t * | |
4769 | allocate_shash () | |
4770 | { | |
4771 | register shash_t *ptr; | |
4772 | static shash_t initial_shash; | |
4773 | ||
4774 | #ifndef MALLOC_CHECK | |
4775 | ||
4776 | register int unallocated = alloc_counts[(int)alloc_type_shash].unallocated; | |
4777 | register page_t *cur_page = alloc_counts[(int)alloc_type_shash].cur_page; | |
4778 | ||
4779 | if (unallocated == 0) | |
4780 | { | |
4781 | unallocated = PAGE_SIZE / sizeof (shash_t); | |
4782 | alloc_counts[(int)alloc_type_shash].cur_page = cur_page = allocate_page (); | |
4783 | alloc_counts[(int)alloc_type_shash].total_pages++; | |
4784 | } | |
4785 | ||
4786 | ptr = &cur_page->shash[--unallocated]; | |
4787 | alloc_counts[(int)alloc_type_shash].unallocated = unallocated; | |
4788 | ||
4789 | #else | |
4790 | ||
4791 | ptr = (shash_t *) xmalloc (sizeof (shash_t)); | |
4792 | ||
4793 | #endif | |
4794 | ||
4795 | alloc_counts[(int)alloc_type_shash].total_alloc++; | |
4796 | *ptr = initial_shash; | |
4797 | return ptr; | |
4798 | } | |
4799 | \f | |
4800 | /* Allocate type hash buckets. */ | |
4801 | ||
4802 | static thash_t * | |
4803 | allocate_thash () | |
4804 | { | |
4805 | register thash_t *ptr; | |
4806 | static thash_t initial_thash; | |
4807 | ||
4808 | #ifndef MALLOC_CHECK | |
4809 | ||
4810 | register int unallocated = alloc_counts[(int)alloc_type_thash].unallocated; | |
4811 | register page_t *cur_page = alloc_counts[(int)alloc_type_thash].cur_page; | |
4812 | ||
4813 | if (unallocated == 0) | |
4814 | { | |
4815 | unallocated = PAGE_SIZE / sizeof (thash_t); | |
4816 | alloc_counts[(int)alloc_type_thash].cur_page = cur_page = allocate_page (); | |
4817 | alloc_counts[(int)alloc_type_thash].total_pages++; | |
4818 | } | |
4819 | ||
4820 | ptr = &cur_page->thash[--unallocated]; | |
4821 | alloc_counts[(int)alloc_type_thash].unallocated = unallocated; | |
4822 | ||
4823 | #else | |
4824 | ||
4825 | ptr = (thash_t *) xmalloc (sizeof (thash_t)); | |
4826 | ||
4827 | #endif | |
4828 | ||
4829 | alloc_counts[(int)alloc_type_thash].total_alloc++; | |
4830 | *ptr = initial_thash; | |
4831 | return ptr; | |
4832 | } | |
4833 | \f | |
4834 | /* Allocate structure, union, or enum tag information. */ | |
4835 | ||
4836 | static tag_t * | |
4837 | allocate_tag () | |
4838 | { | |
4839 | register tag_t *ptr; | |
4840 | static tag_t initial_tag; | |
4841 | ||
4842 | #ifndef MALLOC_CHECK | |
4843 | ||
4844 | ptr = alloc_counts[(int)alloc_type_tag].free_list.f_tag; | |
4845 | if (ptr != (tag_t *) NULL) | |
4846 | alloc_counts[(int)alloc_type_tag].free_list.f_tag = ptr->free; | |
4847 | else | |
4848 | { | |
4849 | register int unallocated = alloc_counts[(int)alloc_type_tag].unallocated; | |
4850 | register page_t *cur_page = alloc_counts[(int)alloc_type_tag].cur_page; | |
4851 | ||
4852 | if (unallocated == 0) | |
4853 | { | |
4854 | unallocated = PAGE_SIZE / sizeof (tag_t); | |
4855 | alloc_counts[(int)alloc_type_tag].cur_page = cur_page = allocate_page (); | |
4856 | alloc_counts[(int)alloc_type_tag].total_pages++; | |
4857 | } | |
4858 | ||
4859 | ptr = &cur_page->tag[--unallocated]; | |
4860 | alloc_counts[(int)alloc_type_tag].unallocated = unallocated; | |
4861 | } | |
4862 | ||
4863 | #else | |
4864 | ||
4865 | ptr = (tag_t *) xmalloc (sizeof (tag_t)); | |
4866 | ||
4867 | #endif | |
4868 | ||
4869 | alloc_counts[(int)alloc_type_tag].total_alloc++; | |
4870 | *ptr = initial_tag; | |
4871 | return ptr; | |
4872 | } | |
4873 | ||
4874 | /* Free scoping information. */ | |
4875 | ||
4876 | static void | |
4877 | free_tag (ptr) | |
4878 | tag_t *ptr; | |
4879 | { | |
4880 | alloc_counts[(int)alloc_type_tag].total_free++; | |
4881 | ||
4882 | #ifndef MALLOC_CHECK | |
4883 | ptr->free = alloc_counts[(int)alloc_type_tag].free_list.f_tag; | |
4884 | alloc_counts[(int)alloc_type_tag].free_list.f_tag = ptr; | |
4885 | #else | |
4886 | free ((PTR_T) ptr); | |
4887 | #endif | |
4888 | } | |
4889 | \f | |
4890 | /* Allocate forward reference to a yet unknown tag. */ | |
4891 | ||
4892 | static forward_t * | |
4893 | allocate_forward () | |
4894 | { | |
4895 | register forward_t *ptr; | |
4896 | static forward_t initial_forward; | |
4897 | ||
4898 | #ifndef MALLOC_CHECK | |
4899 | ||
4900 | register int unallocated = alloc_counts[(int)alloc_type_forward].unallocated; | |
4901 | register page_t *cur_page = alloc_counts[(int)alloc_type_forward].cur_page; | |
4902 | ||
4903 | if (unallocated == 0) | |
4904 | { | |
4905 | unallocated = PAGE_SIZE / sizeof (forward_t); | |
4906 | alloc_counts[(int)alloc_type_forward].cur_page = cur_page = allocate_page (); | |
4907 | alloc_counts[(int)alloc_type_forward].total_pages++; | |
4908 | } | |
4909 | ||
4910 | ptr = &cur_page->forward[--unallocated]; | |
4911 | alloc_counts[(int)alloc_type_forward].unallocated = unallocated; | |
4912 | ||
4913 | #else | |
4914 | ||
4915 | ptr = (forward_t *) xmalloc (sizeof (forward_t)); | |
4916 | ||
4917 | #endif | |
4918 | ||
4919 | alloc_counts[(int)alloc_type_forward].total_alloc++; | |
4920 | *ptr = initial_forward; | |
4921 | return ptr; | |
4922 | } | |
4923 | \f | |
4924 | /* Allocate head of type hash list. */ | |
4925 | ||
4926 | static thead_t * | |
4927 | allocate_thead () | |
4928 | { | |
4929 | register thead_t *ptr; | |
4930 | static thead_t initial_thead; | |
4931 | ||
4932 | #ifndef MALLOC_CHECK | |
4933 | ||
4934 | ptr = alloc_counts[(int)alloc_type_thead].free_list.f_thead; | |
4935 | if (ptr != (thead_t *) NULL) | |
4936 | alloc_counts[ (int)alloc_type_thead ].free_list.f_thead = ptr->free; | |
4937 | else | |
4938 | { | |
4939 | register int unallocated = alloc_counts[(int)alloc_type_thead].unallocated; | |
4940 | register page_t *cur_page = alloc_counts[(int)alloc_type_thead].cur_page; | |
4941 | ||
4942 | if (unallocated == 0) | |
4943 | { | |
4944 | unallocated = PAGE_SIZE / sizeof (thead_t); | |
4945 | alloc_counts[(int)alloc_type_thead].cur_page = cur_page = allocate_page (); | |
4946 | alloc_counts[(int)alloc_type_thead].total_pages++; | |
4947 | } | |
4948 | ||
4949 | ptr = &cur_page->thead[--unallocated]; | |
4950 | alloc_counts[(int)alloc_type_thead].unallocated = unallocated; | |
4951 | } | |
4952 | ||
4953 | #else | |
4954 | ||
4955 | ptr = (thead_t *) xmalloc (sizeof (thead_t)); | |
4956 | ||
4957 | #endif | |
4958 | ||
4959 | alloc_counts[(int)alloc_type_thead].total_alloc++; | |
4960 | *ptr = initial_thead; | |
4961 | return ptr; | |
4962 | } | |
4963 | ||
4964 | /* Free scoping information. */ | |
4965 | ||
4966 | static void | |
4967 | free_thead (ptr) | |
4968 | thead_t *ptr; | |
4969 | { | |
4970 | alloc_counts[(int)alloc_type_thead].total_free++; | |
4971 | ||
4972 | #ifndef MALLOC_CHECK | |
4973 | ptr->free = (thead_t *) alloc_counts[(int)alloc_type_thead].free_list.f_thead; | |
4974 | alloc_counts[(int)alloc_type_thead].free_list.f_thead = ptr; | |
4975 | #else | |
4976 | free ((PTR_T) ptr); | |
4977 | #endif | |
4978 | } | |
4979 | \f | |
4980 | static lineno_list_t * | |
4981 | allocate_lineno_list () | |
4982 | { | |
4983 | register lineno_list_t *ptr; | |
4984 | static lineno_list_t initial_lineno_list; | |
4985 | ||
4986 | #ifndef MALLOC_CHECK | |
4987 | ||
4988 | register int unallocated = alloc_counts[(int)alloc_type_lineno].unallocated; | |
4989 | register page_t *cur_page = alloc_counts[(int)alloc_type_lineno].cur_page; | |
4990 | ||
4991 | if (unallocated == 0) | |
4992 | { | |
4993 | unallocated = PAGE_SIZE / sizeof (lineno_list_t); | |
4994 | alloc_counts[(int)alloc_type_lineno].cur_page = cur_page = allocate_page (); | |
4995 | alloc_counts[(int)alloc_type_lineno].total_pages++; | |
4996 | } | |
4997 | ||
4998 | ptr = &cur_page->lineno[--unallocated]; | |
4999 | alloc_counts[(int)alloc_type_lineno].unallocated = unallocated; | |
5000 | ||
5001 | #else | |
5002 | ||
5003 | ptr = (lineno_list_t *) xmalloc (sizeof (lineno_list_t)); | |
5004 | ||
5005 | #endif | |
5006 | ||
5007 | alloc_counts[(int)alloc_type_lineno].total_alloc++; | |
5008 | *ptr = initial_lineno_list; | |
5009 | return ptr; | |
5010 | } |