]>
Commit | Line | Data |
---|---|---|
db40ba14 | 1 | /* coff object file format with bfd |
c593cf41 SC |
2 | Copyright (C) 1989, 1990, 1991 Free Software Foundation, Inc. |
3 | ||
4 | This file is part of GAS. | |
5 | ||
6 | GAS is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GAS is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
db40ba14 SC |
19 | |
20 | /* | |
c593cf41 SC |
21 | |
22 | How does this releate to the rest of GAS ? | |
23 | ||
24 | Well, all the other files in gas are more or less a black box. It | |
25 | takes care of opening files, parsing command lines, stripping blanks | |
26 | etc etc. This module gets a chance to register what it wants to do by | |
27 | saying that it is interested in various pseduo ops. The other big | |
28 | change is write_object_file. This runs through all the data | |
29 | structures that gas builds, and outputs the file in the format of our | |
30 | choice. | |
355afbcd | 31 | |
c593cf41 SC |
32 | Hacked for BFDness by steve chamberlain |
33 | ||
033400ec | 34 | This object module now supports the Hitachi H8/{3|5}00 and the AMD 29k |
c593cf41 SC |
35 | |
36 | [email protected] | |
37 | */ | |
db40ba14 SC |
38 | |
39 | #include "as.h" | |
40 | #include "obstack.h" | |
41 | #include "subsegs.h" | |
42 | #include "frags.h" | |
43 | #include "../bfd/libbfd.h" | |
30d9fb57 | 44 | #include "../bfd/libcoff.h" |
db40ba14 | 45 | |
016e0d42 ILT |
46 | /* The NOP_OPCODE is for the alignment fill value. Fill with nop so |
47 | that we can stick sections together without causing trouble. */ | |
48 | #ifndef NOP_OPCODE | |
49 | #define NOP_OPCODE 0x00 | |
50 | #endif | |
db40ba14 | 51 | |
d752f749 | 52 | #define MIN(a,b) ((a) < (b)? (a) : (b)) |
db40ba14 | 53 | /* This vector is used to turn an internal segment into a section # |
355afbcd | 54 | suitable for insertion into a coff symbol table |
c593cf41 | 55 | */ |
db40ba14 | 56 | |
355afbcd KR |
57 | const short seg_N_TYPE[] = |
58 | { /* in: segT out: N_TYPE bits */ | |
59 | C_ABS_SECTION, | |
60 | 1, | |
61 | 2, | |
62 | 3, | |
63 | 4, | |
64 | 5, | |
65 | 6, | |
66 | 7, | |
67 | 8, | |
68 | 9, | |
69 | 10, | |
70 | C_UNDEF_SECTION, /* SEG_UNKNOWN */ | |
71 | C_UNDEF_SECTION, /* SEG_ABSENT */ | |
72 | C_UNDEF_SECTION, /* SEG_PASS1 */ | |
73 | C_UNDEF_SECTION, /* SEG_GOOF */ | |
74 | C_UNDEF_SECTION, /* SEG_BIG */ | |
75 | C_UNDEF_SECTION, /* SEG_DIFFERENCE */ | |
76 | C_DEBUG_SECTION, /* SEG_DEBUG */ | |
77 | C_NTV_SECTION, /* SEG_NTV */ | |
78 | C_PTV_SECTION, /* SEG_PTV */ | |
79 | C_REGISTER_SECTION, /* SEG_REGISTER */ | |
db40ba14 SC |
80 | }; |
81 | ||
82 | ||
83 | int function_lineoff = -1; /* Offset in line#s where the last function | |
84 | started (the odd entry for line #0) */ | |
85 | ||
db40ba14 | 86 | |
355afbcd | 87 | static symbolS *last_line_symbol; |
9a75dc1f | 88 | |
db40ba14 SC |
89 | /* Add 4 to the real value to get the index and compensate the |
90 | negatives. This vector is used by S_GET_SEGMENT to turn a coff | |
355afbcd | 91 | section number into a segment number |
c593cf41 | 92 | */ |
db40ba14 | 93 | static symbolS *previous_file_symbol = NULL; |
355afbcd | 94 | void c_symbol_merge (); |
9ce31b66 | 95 | static int line_base; |
db40ba14 | 96 | |
355afbcd | 97 | symbolS *c_section_symbol (); |
db40ba14 | 98 | bfd *abfd; |
355afbcd KR |
99 | void EXFUN (bfd_as_write_hook, (struct internal_filehdr *, |
100 | bfd * abfd)); | |
db40ba14 | 101 | |
016e0d42 | 102 | static void EXFUN (fixup_segment, (segment_info_type *segP, |
355afbcd | 103 | segT this_segment_type)); |
db40ba14 | 104 | |
3ad9ec6a | 105 | |
9a75dc1f ILT |
106 | static void EXFUN (fixup_mdeps, (fragS *, |
107 | object_headers *, | |
108 | segT)); | |
3ad9ec6a ILT |
109 | |
110 | ||
355afbcd | 111 | static void EXFUN (fill_section, (bfd * abfd, |
9a75dc1f ILT |
112 | object_headers *, |
113 | unsigned long *)); | |
db40ba14 SC |
114 | |
115 | ||
355afbcd KR |
116 | char *EXFUN (s_get_name, (symbolS * s)); |
117 | static symbolS *EXFUN (tag_find_or_make, (char *name)); | |
118 | static symbolS *EXFUN (tag_find, (char *name)); | |
db40ba14 SC |
119 | |
120 | ||
121 | static int | |
355afbcd KR |
122 | EXFUN (c_line_new, ( |
123 | symbolS * symbol, | |
124 | long paddr, | |
125 | unsigned short line_number, | |
126 | fragS * frag)); | |
127 | ||
128 | ||
129 | static void EXFUN (w_symbols, | |
130 | (bfd * abfd, | |
131 | char *where, | |
132 | symbolS * symbol_rootP)); | |
133 | ||
134 | ||
135 | ||
136 | static void EXFUN (obj_coff_def, (int what)); | |
137 | static void EXFUN (obj_coff_lcomm, (void)); | |
138 | static void EXFUN (obj_coff_dim, (void)); | |
139 | static void EXFUN (obj_coff_text, (void)); | |
140 | static void EXFUN (obj_coff_data, (void)); | |
9a75dc1f ILT |
141 | static void EXFUN( obj_coff_bss,(void)); |
142 | static void EXFUN( obj_coff_ident,(void)); | |
355afbcd KR |
143 | static void EXFUN (obj_coff_endef, (void)); |
144 | static void EXFUN (obj_coff_line, (void)); | |
9a7d824a | 145 | static void EXFUN (obj_coff_ln, (int)); |
355afbcd KR |
146 | static void EXFUN (obj_coff_scl, (void)); |
147 | static void EXFUN (obj_coff_size, (void)); | |
148 | static void EXFUN (obj_coff_tag, (void)); | |
149 | static void EXFUN (obj_coff_type, (void)); | |
150 | static void EXFUN (obj_coff_val, (void)); | |
151 | void EXFUN (obj_coff_section, (void)); | |
152 | static void EXFUN (tag_init, (void)); | |
153 | static void EXFUN (tag_insert, (char *name, symbolS * symbolP)); | |
db40ba14 SC |
154 | |
155 | ||
156 | static struct hash_control *tag_hash; | |
157 | static symbolS *def_symbol_in_progress = NULL; | |
158 | ||
355afbcd KR |
159 | const pseudo_typeS obj_pseudo_table[] = |
160 | { | |
161 | {"def", obj_coff_def, 0}, | |
162 | {"dim", obj_coff_dim, 0}, | |
163 | {"endef", obj_coff_endef, 0}, | |
164 | {"line", obj_coff_line, 0}, | |
165 | {"ln", obj_coff_ln, 0}, | |
9a7d824a | 166 | {"appline", obj_coff_ln, 1}, |
355afbcd KR |
167 | {"scl", obj_coff_scl, 0}, |
168 | {"size", obj_coff_size, 0}, | |
169 | {"tag", obj_coff_tag, 0}, | |
170 | {"type", obj_coff_type, 0}, | |
171 | {"val", obj_coff_val, 0}, | |
172 | {"section", obj_coff_section, 0}, | |
173 | {"use", obj_coff_section, 0}, | |
174 | {"sect", obj_coff_section, 0}, | |
175 | {"text", obj_coff_text, 0}, | |
176 | {"data", obj_coff_data, 0}, | |
9a75dc1f ILT |
177 | {"bss", obj_coff_bss, 0}, |
178 | {"ident", obj_coff_ident, 0}, | |
355afbcd KR |
179 | {"ABORT", s_abort, 0}, |
180 | {"lcomm", obj_coff_lcomm, 0}, | |
181 | {NULL} /* end sentinel */ | |
182 | }; /* obj_pseudo_table */ | |
183 | ||
184 | ||
185 | ||
186 | /* Section stuff | |
c593cf41 | 187 | |
db40ba14 SC |
188 | We allow more than just the standard 3 sections, infact, we allow |
189 | 10 sections, (though the usual three have to be there). | |
c593cf41 | 190 | |
db40ba14 | 191 | This structure performs the mappings for us: |
c593cf41 SC |
192 | |
193 | */ | |
db40ba14 | 194 | |
355afbcd | 195 | /* OBS stuff |
c593cf41 SC |
196 | static struct internal_scnhdr bss_section_header; |
197 | struct internal_scnhdr data_section_header; | |
198 | struct internal_scnhdr text_section_header; | |
199 | ||
200 | const segT N_TYPE_seg [32] = | |
201 | { | |
202 | ||
203 | }; | |
204 | ||
205 | */ | |
db40ba14 SC |
206 | |
207 | #define N_SEG 32 | |
355afbcd | 208 | typedef struct |
db40ba14 | 209 | { |
2cb0bdc7 SC |
210 | segT seg_t; |
211 | int i; | |
212 | } seg_info_type; | |
355afbcd | 213 | |
2cb0bdc7 | 214 | seg_info_type seg_info_off_by_4[N_SEG] = |
db40ba14 | 215 | { |
2cb0bdc7 SC |
216 | {SEG_PTV, }, |
217 | {SEG_NTV, }, | |
218 | {SEG_DEBUG, }, | |
219 | {SEG_ABSOLUTE, }, | |
220 | {SEG_UNKNOWN, }, | |
221 | {SEG_E0}, | |
222 | {SEG_E1}, | |
223 | {SEG_E2}, | |
224 | {SEG_E3}, | |
225 | {SEG_E4}, | |
226 | {SEG_E5}, | |
227 | {SEG_E6}, | |
228 | {SEG_E7}, | |
229 | {SEG_E8}, | |
230 | {SEG_E9}, | |
231 | {(segT)15}, | |
232 | {(segT)16}, | |
233 | {(segT)17}, | |
234 | {(segT)18}, | |
235 | {(segT)19}, | |
236 | {(segT)20}, | |
237 | {(segT)0}, | |
238 | {(segT)0}, | |
239 | {(segT)0}, | |
240 | {SEG_REGISTER} | |
241 | }; | |
242 | ||
243 | ||
db40ba14 SC |
244 | |
245 | #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4]) | |
246 | #define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)]) | |
247 | ||
248 | ||
355afbcd KR |
249 | relax_addressT |
250 | DEFUN (relax_align, (address, alignment), | |
251 | register relax_addressT address AND | |
252 | register long alignment) | |
db40ba14 | 253 | { |
355afbcd KR |
254 | relax_addressT mask; |
255 | relax_addressT new_address; | |
c593cf41 | 256 | |
355afbcd KR |
257 | mask = ~((~0) << alignment); |
258 | new_address = (address + mask) & (~mask); | |
c593cf41 | 259 | return (new_address - address); |
355afbcd | 260 | } /* relax_align() */ |
db40ba14 SC |
261 | |
262 | ||
355afbcd KR |
263 | segT |
264 | DEFUN (s_get_segment, (x), | |
265 | symbolS * x) | |
db40ba14 | 266 | { |
355afbcd | 267 | return SEG_INFO_FROM_SECTION_NUMBER (x->sy_symbol.ost_entry.n_scnum).seg_t; |
db40ba14 SC |
268 | } |
269 | ||
270 | ||
271 | ||
272 | /* calculate the size of the frag chain and fill in the section header | |
273 | to contain all of it, also fill in the addr of the sections */ | |
355afbcd KR |
274 | static unsigned int |
275 | DEFUN (size_section, (abfd, idx), | |
276 | bfd * abfd AND | |
277 | unsigned int idx) | |
db40ba14 | 278 | { |
c593cf41 SC |
279 | |
280 | unsigned int size = 0; | |
281 | fragS *frag = segment_info[idx].frchainP->frch_root; | |
355afbcd KR |
282 | while (frag) |
283 | { | |
284 | size = frag->fr_address; | |
355afbcd KR |
285 | if (frag->fr_address != size) |
286 | { | |
287 | printf ("Out of step\n"); | |
c593cf41 | 288 | size = frag->fr_address; |
db40ba14 | 289 | } |
3ad9ec6a | 290 | |
355afbcd KR |
291 | switch (frag->fr_type) |
292 | { | |
3ad9ec6a | 293 | #ifdef TC_COFF_SIZEMACHDEP |
355afbcd KR |
294 | case rs_machine_dependent: |
295 | size += TC_COFF_SIZEMACHDEP (frag); | |
296 | break; | |
3ad9ec6a | 297 | #endif |
c593cf41 SC |
298 | case rs_fill: |
299 | case rs_org: | |
355afbcd KR |
300 | size += frag->fr_fix; |
301 | size += frag->fr_offset * frag->fr_var; | |
c593cf41 SC |
302 | break; |
303 | case rs_align: | |
355afbcd KR |
304 | size += frag->fr_fix; |
305 | size += relax_align (size, frag->fr_offset); | |
c593cf41 SC |
306 | } |
307 | frag = frag->fr_next; | |
308 | } | |
309 | segment_info[idx].scnhdr.s_size = size; | |
310 | return size; | |
db40ba14 SC |
311 | } |
312 | ||
313 | ||
355afbcd KR |
314 | static unsigned int |
315 | DEFUN (count_entries_in_chain, (idx), | |
316 | unsigned int idx) | |
db40ba14 | 317 | { |
355afbcd KR |
318 | unsigned int nrelocs; |
319 | fixS *fixup_ptr; | |
c593cf41 | 320 | |
355afbcd KR |
321 | /* Count the relocations */ |
322 | fixup_ptr = segment_info[idx].fix_root; | |
323 | nrelocs = 0; | |
324 | while (fixup_ptr != (fixS *) NULL) | |
c593cf41 | 325 | { |
355afbcd | 326 | if (TC_COUNT_RELOC (fixup_ptr)) |
c593cf41 | 327 | { |
355afbcd | 328 | |
db40ba14 | 329 | #ifdef TC_A29K |
c593cf41 | 330 | |
355afbcd KR |
331 | if (fixup_ptr->fx_r_type == RELOC_CONSTH) |
332 | nrelocs += 2; | |
333 | else | |
c593cf41 | 334 | nrelocs++; |
355afbcd KR |
335 | #else |
336 | nrelocs++; | |
db40ba14 | 337 | #endif |
c593cf41 | 338 | } |
355afbcd KR |
339 | |
340 | fixup_ptr = fixup_ptr->fx_next; | |
c593cf41 | 341 | } |
355afbcd | 342 | return nrelocs; |
db40ba14 SC |
343 | } |
344 | ||
345 | /* output all the relocations for a section */ | |
355afbcd | 346 | void |
9a75dc1f | 347 | DEFUN (do_relocs_for, (abfd, h, file_cursor), |
355afbcd | 348 | bfd * abfd AND |
9a75dc1f | 349 | object_headers * h AND |
355afbcd | 350 | unsigned long *file_cursor) |
db40ba14 | 351 | { |
c593cf41 SC |
352 | unsigned int nrelocs; |
353 | unsigned int idx; | |
9a75dc1f ILT |
354 | unsigned long reloc_start = *file_cursor; |
355 | ||
355afbcd KR |
356 | for (idx = SEG_E0; idx < SEG_E9; idx++) |
357 | { | |
358 | if (segment_info[idx].scnhdr.s_name[0]) | |
359 | { | |
355afbcd KR |
360 | struct external_reloc *ext_ptr; |
361 | struct external_reloc *external_reloc_vec; | |
362 | unsigned int external_reloc_size; | |
9a75dc1f | 363 | unsigned int base = segment_info[idx].scnhdr.s_paddr; |
355afbcd KR |
364 | fixS *fix_ptr = segment_info[idx].fix_root; |
365 | nrelocs = count_entries_in_chain (idx); | |
366 | ||
155e7bc4 KR |
367 | if (nrelocs) |
368 | /* Bypass this stuff if no relocs. This also incidentally | |
369 | avoids a SCO bug, where free(malloc(0)) tends to crash. */ | |
355afbcd | 370 | { |
155e7bc4 KR |
371 | external_reloc_size = nrelocs * RELSZ; |
372 | external_reloc_vec = | |
373 | (struct external_reloc *) malloc (external_reloc_size); | |
c593cf41 | 374 | |
155e7bc4 KR |
375 | ext_ptr = external_reloc_vec; |
376 | ||
377 | /* Fill in the internal coff style reloc struct from the | |
378 | internal fix list. */ | |
379 | while (fix_ptr) | |
355afbcd | 380 | { |
155e7bc4 KR |
381 | symbolS *symbol_ptr; |
382 | struct internal_reloc intr; | |
383 | ||
384 | /* Only output some of the relocations */ | |
385 | if (TC_COUNT_RELOC (fix_ptr)) | |
386 | { | |
32e44774 | 387 | #ifdef TC_RELOC_MANGLE |
155e7bc4 | 388 | TC_RELOC_MANGLE (fix_ptr, &intr, base); |
355afbcd | 389 | |
410e67eb | 390 | #else |
155e7bc4 KR |
391 | symbolS *dot; |
392 | symbol_ptr = fix_ptr->fx_addsy; | |
c593cf41 | 393 | |
155e7bc4 KR |
394 | intr.r_type = TC_COFF_FIX2RTYPE (fix_ptr); |
395 | intr.r_vaddr = | |
396 | base + fix_ptr->fx_frag->fr_address + fix_ptr->fx_where; | |
c593cf41 | 397 | |
155e7bc4 | 398 | intr.r_offset = fix_ptr->fx_offset; |
c593cf41 | 399 | |
155e7bc4 | 400 | intr.r_offset = 0; |
c593cf41 | 401 | |
155e7bc4 KR |
402 | /* Turn the segment of the symbol into an offset. */ |
403 | if (symbol_ptr) | |
355afbcd | 404 | { |
155e7bc4 KR |
405 | dot = segment_info[S_GET_SEGMENT (symbol_ptr)].dot; |
406 | if (dot) | |
407 | { | |
408 | intr.r_symndx = dot->sy_number; | |
409 | } | |
410 | else | |
411 | { | |
412 | intr.r_symndx = symbol_ptr->sy_number; | |
413 | } | |
414 | ||
355afbcd KR |
415 | } |
416 | else | |
417 | { | |
155e7bc4 | 418 | intr.r_symndx = -1; |
355afbcd | 419 | } |
410e67eb | 420 | #endif |
c593cf41 | 421 | |
155e7bc4 KR |
422 | (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr); |
423 | ext_ptr++; | |
c593cf41 | 424 | |
db40ba14 | 425 | #if defined(TC_A29K) |
9a75dc1f | 426 | |
155e7bc4 KR |
427 | /* The 29k has a special kludge for the high 16 bit |
428 | reloc. Two relocations are emited, R_IHIHALF, | |
429 | and R_IHCONST. The second one doesn't contain a | |
430 | symbol, but uses the value for offset. */ | |
355afbcd | 431 | |
155e7bc4 KR |
432 | if (intr.r_type == R_IHIHALF) |
433 | { | |
434 | /* now emit the second bit */ | |
435 | intr.r_type = R_IHCONST; | |
436 | intr.r_symndx = fix_ptr->fx_addnumber; | |
155e7bc4 KR |
437 | (void) bfd_coff_swap_reloc_out (abfd, &intr, ext_ptr); |
438 | ext_ptr++; | |
439 | } | |
db40ba14 | 440 | #endif |
155e7bc4 KR |
441 | } |
442 | ||
443 | fix_ptr = fix_ptr->fx_next; | |
355afbcd KR |
444 | } |
445 | ||
155e7bc4 KR |
446 | /* Write out the reloc table */ |
447 | bfd_write ((PTR) external_reloc_vec, 1, external_reloc_size, | |
448 | abfd); | |
449 | free (external_reloc_vec); | |
355afbcd | 450 | |
155e7bc4 KR |
451 | /* Fill in section header info. */ |
452 | segment_info[idx].scnhdr.s_relptr = *file_cursor; | |
453 | *file_cursor += external_reloc_size; | |
e02eaa59 | 454 | segment_info[idx].scnhdr.s_nreloc = nrelocs; |
155e7bc4 KR |
455 | } |
456 | else | |
457 | { | |
458 | /* No relocs */ | |
459 | segment_info[idx].scnhdr.s_relptr = 0; | |
460 | } | |
c593cf41 | 461 | } |
355afbcd | 462 | } |
9a75dc1f ILT |
463 | /* Set relocation_size field in file headers */ |
464 | H_SET_RELOCATION_SIZE (h, *file_cursor - reloc_start, 0); | |
db40ba14 SC |
465 | } |
466 | ||
467 | ||
468 | /* run through a frag chain and write out the data to go with it, fill | |
355afbcd | 469 | in the scnhdrs with the info on the file postions |
c593cf41 | 470 | */ |
355afbcd | 471 | static void |
9a75dc1f | 472 | DEFUN (fill_section, (abfd, h, file_cursor), |
355afbcd | 473 | bfd * abfd AND |
9a75dc1f | 474 | object_headers *h AND |
355afbcd | 475 | unsigned long *file_cursor) |
db40ba14 | 476 | { |
c593cf41 | 477 | |
c58dbabf | 478 | unsigned int i; |
016e0d42 | 479 | unsigned int paddr = 0; |
c58dbabf | 480 | |
355afbcd KR |
481 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) |
482 | { | |
483 | unsigned int offset = 0; | |
484 | ||
485 | struct internal_scnhdr *s = &(segment_info[i].scnhdr); | |
486 | ||
487 | if (s->s_name[0]) | |
488 | { | |
489 | fragS *frag = segment_info[i].frchainP->frch_root; | |
016e0d42 ILT |
490 | char *buffer; |
491 | ||
9a75dc1f ILT |
492 | if (s->s_size == 0) |
493 | s->s_scnptr = 0; | |
355afbcd | 494 | else |
016e0d42 | 495 | { |
9a75dc1f ILT |
496 | buffer = xmalloc (s->s_size); |
497 | s->s_scnptr = *file_cursor; | |
016e0d42 | 498 | } |
9a75dc1f | 499 | know (s->s_paddr == paddr); |
355afbcd | 500 | |
355afbcd KR |
501 | if (strcmp (s->s_name, ".text") == 0) |
502 | s->s_flags |= STYP_TEXT; | |
503 | else if (strcmp (s->s_name, ".data") == 0) | |
504 | s->s_flags |= STYP_DATA; | |
505 | else if (strcmp (s->s_name, ".bss") == 0) | |
9a75dc1f ILT |
506 | { |
507 | s->s_scnptr = 0; | |
508 | s->s_flags |= STYP_BSS; | |
509 | #ifndef TC_I386 | |
543d88e4 | 510 | #ifndef TC_A29K |
9a75dc1f | 511 | /* Apparently the SVR3 linker is confused by noload |
543d88e4 | 512 | sections. So is the UDI mondfe program. */ |
9a75dc1f | 513 | s->s_flags |= STYP_NOLOAD; |
543d88e4 | 514 | #endif |
9a75dc1f ILT |
515 | #endif |
516 | } | |
355afbcd KR |
517 | else if (strcmp (s->s_name, ".lit") == 0) |
518 | s->s_flags = STYP_LIT | STYP_TEXT; | |
016e0d42 ILT |
519 | else if (strcmp (s->s_name, ".init") == 0) |
520 | s->s_flags |= STYP_TEXT; | |
521 | else if (strcmp (s->s_name, ".fini") == 0) | |
522 | s->s_flags |= STYP_TEXT; | |
9a75dc1f ILT |
523 | else if (strncmp (s->s_name, ".comment", 8) == 0) |
524 | s->s_flags |= STYP_INFO; | |
355afbcd KR |
525 | |
526 | while (frag) | |
c58dbabf | 527 | { |
355afbcd KR |
528 | unsigned int fill_size; |
529 | switch (frag->fr_type) | |
530 | { | |
531 | case rs_machine_dependent: | |
532 | if (frag->fr_fix) | |
533 | { | |
534 | memcpy (buffer + frag->fr_address, | |
535 | frag->fr_literal, | |
536 | frag->fr_fix); | |
537 | offset += frag->fr_fix; | |
538 | } | |
539 | ||
540 | break; | |
541 | case rs_fill: | |
542 | case rs_align: | |
543 | case rs_org: | |
544 | if (frag->fr_fix) | |
545 | { | |
546 | memcpy (buffer + frag->fr_address, | |
547 | frag->fr_literal, | |
548 | frag->fr_fix); | |
549 | offset += frag->fr_fix; | |
550 | } | |
551 | ||
552 | fill_size = frag->fr_var; | |
115147fb | 553 | if (fill_size && frag->fr_offset > 0) |
355afbcd KR |
554 | { |
555 | unsigned int count; | |
556 | unsigned int off = frag->fr_fix; | |
557 | for (count = frag->fr_offset; count; count--) | |
558 | { | |
9a75dc1f ILT |
559 | if (fill_size < s->s_size) |
560 | { | |
561 | memcpy (buffer + frag->fr_address + off, | |
562 | frag->fr_literal + frag->fr_fix, | |
563 | fill_size); | |
564 | off += fill_size; | |
565 | offset += fill_size; | |
566 | } | |
2cb0bdc7 | 567 | } |
355afbcd KR |
568 | } |
569 | break; | |
570 | case rs_broken_word: | |
571 | break; | |
572 | default: | |
573 | abort (); | |
574 | } | |
575 | frag = frag->fr_next; | |
a39116f1 | 576 | } |
c58dbabf | 577 | |
9a75dc1f | 578 | if (s->s_size != 0) |
016e0d42 | 579 | { |
9a75dc1f ILT |
580 | if (s->s_scnptr != 0) |
581 | { | |
582 | bfd_write (buffer, s->s_size, 1, abfd); | |
583 | *file_cursor += s->s_size; | |
584 | } | |
016e0d42 | 585 | free (buffer); |
016e0d42 | 586 | } |
016e0d42 | 587 | paddr += s->s_size; |
355afbcd KR |
588 | } |
589 | } | |
db40ba14 SC |
590 | } |
591 | ||
db40ba14 SC |
592 | /* Coff file generation & utilities */ |
593 | ||
355afbcd | 594 | static void |
9a75dc1f | 595 | DEFUN (coff_header_append, (abfd, h), |
355afbcd | 596 | bfd * abfd AND |
9a75dc1f | 597 | object_headers * h) |
db40ba14 | 598 | { |
c593cf41 SC |
599 | unsigned int i; |
600 | char buffer[1000]; | |
601 | char buffero[1000]; | |
602 | ||
355afbcd | 603 | bfd_seek (abfd, 0, 0); |
9a75dc1f ILT |
604 | |
605 | #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER | |
606 | H_SET_MAGIC_NUMBER (h, COFF_MAGIC); | |
607 | H_SET_VERSION_STAMP (h, 0); | |
608 | H_SET_ENTRY_POINT (h, 0); | |
609 | H_SET_TEXT_START (h, segment_info[SEG_E0].frchainP->frch_root->fr_address); | |
610 | H_SET_DATA_START (h, segment_info[SEG_E1].frchainP->frch_root->fr_address); | |
611 | H_SET_SIZEOF_OPTIONAL_HEADER (h, bfd_coff_swap_aouthdr_out(abfd, &h->aouthdr, | |
612 | buffero)); | |
613 | #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */ | |
614 | H_SET_SIZEOF_OPTIONAL_HEADER (h, 0); | |
615 | #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */ | |
616 | ||
617 | i = bfd_coff_swap_filehdr_out (abfd, &h->filehdr, buffer); | |
c593cf41 | 618 | |
355afbcd | 619 | bfd_write (buffer, i, 1, abfd); |
9a75dc1f | 620 | bfd_write (buffero, H_GET_SIZEOF_OPTIONAL_HEADER (h), 1, abfd); |
c593cf41 | 621 | |
355afbcd KR |
622 | for (i = SEG_E0; i < SEG_E9; i++) |
623 | { | |
624 | if (segment_info[i].scnhdr.s_name[0]) | |
625 | { | |
626 | unsigned int size = | |
627 | bfd_coff_swap_scnhdr_out (abfd, | |
628 | &(segment_info[i].scnhdr), | |
629 | buffer); | |
630 | bfd_write (buffer, size, 1, abfd); | |
631 | } | |
c593cf41 | 632 | } |
db40ba14 SC |
633 | } |
634 | ||
635 | ||
636 | char * | |
355afbcd KR |
637 | DEFUN (symbol_to_chars, (abfd, where, symbolP), |
638 | bfd * abfd AND | |
639 | char *where AND | |
640 | symbolS * symbolP) | |
db40ba14 | 641 | { |
355afbcd KR |
642 | unsigned int numaux = symbolP->sy_symbol.ost_entry.n_numaux; |
643 | unsigned int i; | |
85051959 | 644 | valueT val; |
c593cf41 | 645 | |
355afbcd KR |
646 | /* Turn any symbols with register attributes into abs symbols */ |
647 | if (S_GET_SEGMENT (symbolP) == SEG_REGISTER) | |
c593cf41 | 648 | { |
355afbcd | 649 | S_SET_SEGMENT (symbolP, SEG_ABSOLUTE); |
c593cf41 | 650 | } |
355afbcd KR |
651 | /* At the same time, relocate all symbols to their output value */ |
652 | ||
85051959 ILT |
653 | val = (segment_info[S_GET_SEGMENT (symbolP)].scnhdr.s_paddr |
654 | + S_GET_VALUE (symbolP)); | |
655 | ||
656 | S_SET_VALUE (symbolP, val); | |
657 | ||
658 | symbolP->sy_symbol.ost_entry.n_value = val; | |
355afbcd KR |
659 | |
660 | where += bfd_coff_swap_sym_out (abfd, &symbolP->sy_symbol.ost_entry, | |
661 | where); | |
662 | ||
663 | for (i = 0; i < numaux; i++) | |
664 | { | |
665 | where += bfd_coff_swap_aux_out (abfd, | |
666 | &symbolP->sy_symbol.ost_auxent[i], | |
667 | S_GET_DATA_TYPE (symbolP), | |
668 | S_GET_STORAGE_CLASS (symbolP), | |
669 | where); | |
c593cf41 | 670 | } |
355afbcd KR |
671 | return where; |
672 | ||
673 | } | |
db40ba14 SC |
674 | |
675 | ||
355afbcd KR |
676 | void |
677 | obj_symbol_new_hook (symbolP) | |
678 | symbolS *symbolP; | |
db40ba14 | 679 | { |
355afbcd KR |
680 | char underscore = 0; /* Symbol has leading _ */ |
681 | ||
682 | /* Effective symbol */ | |
683 | /* Store the pointer in the offset. */ | |
684 | S_SET_ZEROES (symbolP, 0L); | |
685 | S_SET_DATA_TYPE (symbolP, T_NULL); | |
686 | S_SET_STORAGE_CLASS (symbolP, 0); | |
687 | S_SET_NUMBER_AUXILIARY (symbolP, 0); | |
688 | /* Additional information */ | |
689 | symbolP->sy_symbol.ost_flags = 0; | |
690 | /* Auxiliary entries */ | |
691 | bzero ((char *) &symbolP->sy_symbol.ost_auxent[0], AUXESZ); | |
c593cf41 | 692 | |
db40ba14 | 693 | #ifdef STRIP_UNDERSCORE |
355afbcd | 694 | /* Remove leading underscore at the beginning of the symbol. |
db40ba14 SC |
695 | * This is to be compatible with the standard librairies. |
696 | */ | |
355afbcd KR |
697 | if (*S_GET_NAME (symbolP) == '_') |
698 | { | |
699 | underscore = 1; | |
700 | S_SET_NAME (symbolP, S_GET_NAME (symbolP) + 1); | |
701 | } /* strip underscore */ | |
db40ba14 | 702 | #endif /* STRIP_UNDERSCORE */ |
c593cf41 | 703 | |
355afbcd KR |
704 | if (S_IS_STRING (symbolP)) |
705 | SF_SET_STRING (symbolP); | |
706 | if (!underscore && S_IS_LOCAL (symbolP)) | |
707 | SF_SET_LOCAL (symbolP); | |
c593cf41 | 708 | |
355afbcd KR |
709 | return; |
710 | } /* obj_symbol_new_hook() */ | |
db40ba14 | 711 | |
355afbcd KR |
712 | /* stack stuff */ |
713 | stack * | |
714 | stack_init (chunk_size, element_size) | |
715 | unsigned long chunk_size; | |
716 | unsigned long element_size; | |
db40ba14 | 717 | { |
355afbcd | 718 | stack *st; |
c593cf41 | 719 | |
355afbcd KR |
720 | if ((st = (stack *) malloc (sizeof (stack))) == (stack *) 0) |
721 | return (stack *) 0; | |
722 | if ((st->data = malloc (chunk_size)) == (char *) 0) | |
723 | { | |
724 | free (st); | |
725 | return (stack *) 0; | |
726 | } | |
727 | st->pointer = 0; | |
728 | st->size = chunk_size; | |
729 | st->chunk_size = chunk_size; | |
730 | st->element_size = element_size; | |
731 | return st; | |
732 | } /* stack_init() */ | |
733 | ||
734 | void | |
735 | stack_delete (st) | |
736 | stack *st; | |
db40ba14 | 737 | { |
355afbcd KR |
738 | free (st->data); |
739 | free (st); | |
db40ba14 SC |
740 | } |
741 | ||
355afbcd KR |
742 | char * |
743 | stack_push (st, element) | |
744 | stack *st; | |
745 | char *element; | |
db40ba14 | 746 | { |
355afbcd KR |
747 | if (st->pointer + st->element_size >= st->size) |
748 | { | |
749 | st->size += st->chunk_size; | |
750 | if ((st->data = xrealloc (st->data, st->size)) == (char *) 0) | |
751 | return (char *) 0; | |
752 | } | |
753 | memcpy (st->data + st->pointer, element, st->element_size); | |
754 | st->pointer += st->element_size; | |
755 | return st->data + st->pointer; | |
756 | } /* stack_push() */ | |
db40ba14 | 757 | |
355afbcd KR |
758 | char * |
759 | stack_pop (st) | |
760 | stack *st; | |
db40ba14 | 761 | { |
355afbcd KR |
762 | if ((st->pointer -= st->element_size) < 0) |
763 | { | |
764 | st->pointer = 0; | |
765 | return (char *) 0; | |
c593cf41 SC |
766 | } |
767 | ||
355afbcd | 768 | return st->data + st->pointer; |
db40ba14 SC |
769 | } |
770 | ||
355afbcd KR |
771 | char * |
772 | stack_top (st) | |
773 | stack *st; | |
db40ba14 | 774 | { |
355afbcd | 775 | return st->data + st->pointer - st->element_size; |
db40ba14 SC |
776 | } |
777 | ||
778 | ||
779 | /* | |
780 | * Handle .ln directives. | |
781 | */ | |
782 | ||
355afbcd | 783 | static void |
9a7d824a ILT |
784 | obj_coff_ln (appline) |
785 | int appline; | |
9ce31b66 | 786 | { |
c593cf41 | 787 | int l; |
355afbcd | 788 | |
9a7d824a | 789 | if (! appline && def_symbol_in_progress != NULL) |
355afbcd KR |
790 | { |
791 | as_warn (".ln pseudo-op inside .def/.endef: ignored."); | |
792 | demand_empty_rest_of_line (); | |
c593cf41 SC |
793 | return; |
794 | } /* wrong context */ | |
795 | ||
355afbcd KR |
796 | c_line_new (0, |
797 | obstack_next_free (&frags) - frag_now->fr_literal, | |
798 | l = get_absolute_expression (), | |
799 | frag_now); | |
9ce31b66 | 800 | #ifndef NO_LISTING |
c593cf41 | 801 | { |
355afbcd KR |
802 | extern int listing; |
803 | ||
804 | if (listing) | |
805 | { | |
9a7d824a ILT |
806 | if (! appline) |
807 | l += line_base - 1; | |
808 | listing_source_line (l); | |
355afbcd KR |
809 | } |
810 | ||
c593cf41 | 811 | } |
9ce31b66 | 812 | #endif |
355afbcd | 813 | demand_empty_rest_of_line (); |
c593cf41 | 814 | return; |
9ce31b66 | 815 | } /* obj_coff_line() */ |
db40ba14 SC |
816 | |
817 | /* | |
818 | * def() | |
819 | * | |
820 | * Handle .def directives. | |
821 | * | |
822 | * One might ask : why can't we symbol_new if the symbol does not | |
823 | * already exist and fill it with debug information. Because of | |
824 | * the C_EFCN special symbol. It would clobber the value of the | |
825 | * function symbol before we have a chance to notice that it is | |
826 | * a C_EFCN. And a second reason is that the code is more clear this | |
827 | * way. (at least I think it is :-). | |
828 | * | |
829 | */ | |
830 | ||
831 | #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';') | |
832 | #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \ | |
c593cf41 SC |
833 | *input_line_pointer == '\t') \ |
834 | input_line_pointer++; | |
db40ba14 | 835 | |
355afbcd KR |
836 | static void |
837 | DEFUN (obj_coff_def, (what), | |
838 | int what) | |
db40ba14 | 839 | { |
355afbcd KR |
840 | char name_end; /* Char after the end of name */ |
841 | char *symbol_name; /* Name of the debug symbol */ | |
842 | char *symbol_name_copy; /* Temporary copy of the name */ | |
843 | unsigned int symbol_name_length; | |
844 | /*$char* directiveP;$ *//* Name of the pseudo opcode */ | |
845 | /*$char directive[MAX_DIRECTIVE];$ *//* Backup of the directive */ | |
846 | /*$char end = 0;$ *//* If 1, stop parsing */ | |
847 | ||
848 | if (def_symbol_in_progress != NULL) | |
849 | { | |
850 | as_warn (".def pseudo-op used inside of .def/.endef: ignored."); | |
851 | demand_empty_rest_of_line (); | |
852 | return; | |
853 | } /* if not inside .def/.endef */ | |
854 | ||
855 | SKIP_WHITESPACES (); | |
856 | ||
857 | def_symbol_in_progress = (symbolS *) obstack_alloc (¬es, sizeof (*def_symbol_in_progress)); | |
858 | bzero (def_symbol_in_progress, sizeof (*def_symbol_in_progress)); | |
859 | ||
860 | symbol_name = input_line_pointer; | |
861 | name_end = get_symbol_end (); | |
862 | symbol_name_length = strlen (symbol_name); | |
863 | symbol_name_copy = xmalloc (symbol_name_length + 1); | |
864 | strcpy (symbol_name_copy, symbol_name); | |
865 | ||
866 | /* Initialize the new symbol */ | |
db40ba14 | 867 | #ifdef STRIP_UNDERSCORE |
355afbcd KR |
868 | S_SET_NAME (def_symbol_in_progress, (*symbol_name_copy == '_' |
869 | ? symbol_name_copy + 1 | |
870 | : symbol_name_copy)); | |
871 | #else /* STRIP_UNDERSCORE */ | |
872 | S_SET_NAME (def_symbol_in_progress, symbol_name_copy); | |
873 | #endif /* STRIP_UNDERSCORE */ | |
874 | /* free(symbol_name_copy); */ | |
875 | def_symbol_in_progress->sy_name_offset = ~0; | |
876 | def_symbol_in_progress->sy_number = ~0; | |
877 | def_symbol_in_progress->sy_frag = &zero_address_frag; | |
878 | ||
879 | if (S_IS_STRING (def_symbol_in_progress)) | |
880 | { | |
881 | SF_SET_STRING (def_symbol_in_progress); | |
882 | } /* "long" name */ | |
883 | ||
884 | *input_line_pointer = name_end; | |
885 | ||
886 | demand_empty_rest_of_line (); | |
887 | return; | |
db40ba14 SC |
888 | } /* obj_coff_def() */ |
889 | ||
890 | unsigned int dim_index; | |
355afbcd KR |
891 | static void |
892 | DEFUN_VOID (obj_coff_endef) | |
db40ba14 | 893 | { |
355afbcd KR |
894 | symbolS *symbolP = 0; |
895 | /* DIM BUG FIX [email protected] */ | |
896 | dim_index = 0; | |
897 | if (def_symbol_in_progress == NULL) | |
898 | { | |
899 | as_warn (".endef pseudo-op used outside of .def/.endef: ignored."); | |
900 | demand_empty_rest_of_line (); | |
901 | return; | |
902 | } /* if not inside .def/.endef */ | |
903 | ||
904 | /* Set the section number according to storage class. */ | |
905 | switch (S_GET_STORAGE_CLASS (def_symbol_in_progress)) | |
906 | { | |
907 | case C_STRTAG: | |
908 | case C_ENTAG: | |
909 | case C_UNTAG: | |
910 | SF_SET_TAG (def_symbol_in_progress); | |
911 | /* intentional fallthrough */ | |
912 | case C_FILE: | |
913 | case C_TPDEF: | |
914 | SF_SET_DEBUG (def_symbol_in_progress); | |
915 | S_SET_SEGMENT (def_symbol_in_progress, SEG_DEBUG); | |
916 | break; | |
917 | ||
918 | case C_EFCN: | |
919 | SF_SET_LOCAL (def_symbol_in_progress); /* Do not emit this symbol. */ | |
920 | /* intentional fallthrough */ | |
921 | case C_BLOCK: | |
922 | SF_SET_PROCESS (def_symbol_in_progress); /* Will need processing before writing */ | |
923 | /* intentional fallthrough */ | |
924 | case C_FCN: | |
925 | S_SET_SEGMENT (def_symbol_in_progress, SEG_E0); | |
926 | ||
a36f6645 | 927 | if (strcmp (S_GET_NAME (def_symbol_in_progress), ".bf") == 0) |
355afbcd KR |
928 | { /* .bf */ |
929 | if (function_lineoff < 0) | |
930 | { | |
931 | fprintf (stderr, "`.bf' symbol without preceding function\n"); | |
932 | } /* missing function symbol */ | |
933 | SA_GET_SYM_LNNOPTR (last_line_symbol) = function_lineoff; | |
934 | ||
935 | SF_SET_PROCESS (last_line_symbol); | |
936 | function_lineoff = -1; | |
937 | } | |
938 | break; | |
c593cf41 | 939 | |
db40ba14 | 940 | #ifdef C_AUTOARG |
355afbcd KR |
941 | case C_AUTOARG: |
942 | #endif /* C_AUTOARG */ | |
943 | case C_AUTO: | |
944 | case C_REG: | |
945 | case C_MOS: | |
946 | case C_MOE: | |
947 | case C_MOU: | |
948 | case C_ARG: | |
949 | case C_REGPARM: | |
950 | case C_FIELD: | |
951 | case C_EOS: | |
952 | SF_SET_DEBUG (def_symbol_in_progress); | |
953 | S_SET_SEGMENT (def_symbol_in_progress, SEG_ABSOLUTE); | |
954 | break; | |
955 | ||
956 | case C_EXT: | |
957 | case C_STAT: | |
958 | case C_LABEL: | |
959 | /* Valid but set somewhere else (s_comm, s_lcomm, colon) */ | |
960 | break; | |
961 | ||
962 | case C_USTATIC: | |
963 | case C_EXTDEF: | |
964 | case C_ULABEL: | |
965 | as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress)); | |
966 | break; | |
967 | } /* switch on storage class */ | |
968 | ||
b27caf27 KR |
969 | /* Now that we have built a debug symbol, try to find if we should |
970 | merge with an existing symbol or not. If a symbol is C_EFCN or | |
971 | SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. We also | |
972 | don't merge labels, which are in a different namespace, nor | |
973 | symbols which have not yet been defined since they are typically | |
974 | unique, nor do we merge tags with non-tags. */ | |
975 | ||
976 | /* Two cases for functions. Either debug followed by definition or | |
977 | definition followed by debug. For definition first, we will | |
978 | merge the debug symbol into the definition. For debug first, the | |
979 | lineno entry MUST point to the definition function or else it | |
980 | will point off into space when crawl_symbols() merges the debug | |
981 | symbol into the real symbol. Therefor, let's presume the debug | |
982 | symbol is a real function reference. */ | |
983 | ||
984 | /* FIXME-SOON If for some reason the definition label/symbol is | |
985 | never seen, this will probably leave an undefined symbol at link | |
986 | time. */ | |
c593cf41 | 987 | |
355afbcd | 988 | if (S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_EFCN |
016e0d42 | 989 | || S_GET_STORAGE_CLASS (def_symbol_in_progress) == C_LABEL |
355afbcd KR |
990 | || (S_GET_SEGMENT (def_symbol_in_progress) == SEG_DEBUG |
991 | && !SF_GET_TAG (def_symbol_in_progress)) | |
992 | || S_GET_SEGMENT (def_symbol_in_progress) == SEG_ABSOLUTE | |
016e0d42 ILT |
993 | || def_symbol_in_progress->sy_forward != NULL |
994 | || (symbolP = symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP)) == NULL | |
995 | || (SF_GET_TAG (def_symbol_in_progress) != SF_GET_TAG (symbolP))) | |
355afbcd | 996 | { |
b27caf27 KR |
997 | symbol_append (def_symbol_in_progress, symbol_lastP, &symbol_rootP, |
998 | &symbol_lastP); | |
355afbcd KR |
999 | } |
1000 | else | |
1001 | { | |
b27caf27 KR |
1002 | /* This symbol already exists, merge the newly created symbol |
1003 | into the This is not mandatory. The linker can handle | |
1004 | duplicate symbols correctly. But I guess that it save a *lot* | |
1005 | of space if the assembly file defines a lot of | |
1006 | symbols. [loic] */ | |
c593cf41 | 1007 | |
b27caf27 KR |
1008 | /* The debug entry (def_symbol_in_progress) is merged into the |
1009 | previous definition. */ | |
c593cf41 | 1010 | |
355afbcd KR |
1011 | c_symbol_merge (def_symbol_in_progress, symbolP); |
1012 | /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */ | |
1013 | def_symbol_in_progress = symbolP; | |
c593cf41 | 1014 | |
355afbcd KR |
1015 | if (SF_GET_FUNCTION (def_symbol_in_progress) |
1016 | || SF_GET_TAG (def_symbol_in_progress)) | |
1017 | { | |
b27caf27 KR |
1018 | /* For functions, and tags, the symbol *must* be where the |
1019 | debug symbol appears. Move the existing symbol to the | |
1020 | current place. */ | |
355afbcd KR |
1021 | /* If it already is at the end of the symbol list, do nothing */ |
1022 | if (def_symbol_in_progress != symbol_lastP) | |
1023 | { | |
b27caf27 KR |
1024 | symbol_remove (def_symbol_in_progress, &symbol_rootP, |
1025 | &symbol_lastP); | |
1026 | symbol_append (def_symbol_in_progress, symbol_lastP, | |
1027 | &symbol_rootP, &symbol_lastP); | |
355afbcd KR |
1028 | } /* if not already in place */ |
1029 | } /* if function */ | |
1030 | } /* normal or mergable */ | |
1031 | ||
1032 | if (SF_GET_TAG (def_symbol_in_progress) | |
1033 | && symbol_find_base (S_GET_NAME (def_symbol_in_progress), DO_NOT_STRIP) == NULL) | |
1034 | { | |
1035 | tag_insert (S_GET_NAME (def_symbol_in_progress), def_symbol_in_progress); | |
b27caf27 | 1036 | } |
c593cf41 | 1037 | |
355afbcd KR |
1038 | if (SF_GET_FUNCTION (def_symbol_in_progress)) |
1039 | { | |
1040 | know (sizeof (def_symbol_in_progress) <= sizeof (long)); | |
1041 | function_lineoff | |
1042 | = c_line_new (def_symbol_in_progress, 0, 0, &zero_address_frag); | |
c593cf41 | 1043 | |
355afbcd | 1044 | SF_SET_PROCESS (def_symbol_in_progress); |
c593cf41 | 1045 | |
355afbcd KR |
1046 | if (symbolP == NULL) |
1047 | { | |
b27caf27 KR |
1048 | /* That is, if this is the first time we've seen the |
1049 | function... */ | |
355afbcd KR |
1050 | symbol_table_insert (def_symbol_in_progress); |
1051 | } /* definition follows debug */ | |
1052 | } /* Create the line number entry pointing to the function being defined */ | |
c593cf41 | 1053 | |
355afbcd KR |
1054 | def_symbol_in_progress = NULL; |
1055 | demand_empty_rest_of_line (); | |
1056 | return; | |
b27caf27 | 1057 | } |
db40ba14 | 1058 | |
355afbcd KR |
1059 | static void |
1060 | DEFUN_VOID (obj_coff_dim) | |
db40ba14 | 1061 | { |
355afbcd | 1062 | register int dim_index; |
c593cf41 | 1063 | |
355afbcd | 1064 | if (def_symbol_in_progress == NULL) |
c593cf41 | 1065 | { |
355afbcd KR |
1066 | as_warn (".dim pseudo-op used outside of .def/.endef: ignored."); |
1067 | demand_empty_rest_of_line (); | |
1068 | return; | |
c593cf41 SC |
1069 | } /* if not inside .def/.endef */ |
1070 | ||
355afbcd | 1071 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); |
c593cf41 | 1072 | |
355afbcd | 1073 | for (dim_index = 0; dim_index < DIMNUM; dim_index++) |
c593cf41 | 1074 | { |
355afbcd KR |
1075 | SKIP_WHITESPACES (); |
1076 | SA_SET_SYM_DIMEN (def_symbol_in_progress, dim_index, get_absolute_expression ()); | |
c593cf41 | 1077 | |
355afbcd | 1078 | switch (*input_line_pointer) |
c593cf41 SC |
1079 | { |
1080 | ||
355afbcd KR |
1081 | case ',': |
1082 | input_line_pointer++; | |
1083 | break; | |
1084 | ||
1085 | default: | |
1086 | as_warn ("badly formed .dim directive ignored"); | |
1087 | /* intentional fallthrough */ | |
1088 | case '\n': | |
1089 | case ';': | |
1090 | dim_index = DIMNUM; | |
1091 | break; | |
c593cf41 SC |
1092 | } /* switch on following character */ |
1093 | } /* for each dimension */ | |
1094 | ||
355afbcd KR |
1095 | demand_empty_rest_of_line (); |
1096 | return; | |
db40ba14 SC |
1097 | } /* obj_coff_dim() */ |
1098 | ||
355afbcd KR |
1099 | static void |
1100 | obj_coff_line () | |
9ce31b66 | 1101 | { |
c593cf41 | 1102 | int this_base; |
355afbcd KR |
1103 | |
1104 | if (def_symbol_in_progress == NULL) | |
1105 | { | |
9a7d824a | 1106 | obj_coff_ln (0); |
c593cf41 SC |
1107 | return; |
1108 | } /* if it looks like a stabs style line */ | |
1109 | ||
355afbcd KR |
1110 | this_base = get_absolute_expression (); |
1111 | if (this_base > line_base) | |
1112 | { | |
1113 | line_base = this_base; | |
1114 | } | |
1115 | ||
1116 | ||
1117 | #ifndef NO_LISTING | |
c593cf41 | 1118 | { |
355afbcd KR |
1119 | extern int listing; |
1120 | if (listing && 0) | |
1121 | { | |
1122 | listing_source_line (line_base); | |
1123 | } | |
c593cf41 | 1124 | } |
9ce31b66 | 1125 | #endif |
355afbcd KR |
1126 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); |
1127 | SA_SET_SYM_LNNO (def_symbol_in_progress, line_base); | |
c593cf41 | 1128 | |
355afbcd | 1129 | demand_empty_rest_of_line (); |
c593cf41 | 1130 | return; |
9ce31b66 | 1131 | } /* obj_coff_line() */ |
db40ba14 | 1132 | |
355afbcd KR |
1133 | static void |
1134 | obj_coff_size () | |
1135 | { | |
1136 | if (def_symbol_in_progress == NULL) | |
1137 | { | |
1138 | as_warn (".size pseudo-op used outside of .def/.endef ignored."); | |
1139 | demand_empty_rest_of_line (); | |
1140 | return; | |
1141 | } /* if not inside .def/.endef */ | |
1142 | ||
1143 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
1144 | SA_SET_SYM_SIZE (def_symbol_in_progress, get_absolute_expression ()); | |
1145 | demand_empty_rest_of_line (); | |
1146 | return; | |
1147 | } /* obj_coff_size() */ | |
1148 | ||
1149 | static void | |
1150 | obj_coff_scl () | |
1151 | { | |
1152 | if (def_symbol_in_progress == NULL) | |
1153 | { | |
1154 | as_warn (".scl pseudo-op used outside of .def/.endef ignored."); | |
1155 | demand_empty_rest_of_line (); | |
1156 | return; | |
1157 | } /* if not inside .def/.endef */ | |
1158 | ||
1159 | S_SET_STORAGE_CLASS (def_symbol_in_progress, get_absolute_expression ()); | |
1160 | demand_empty_rest_of_line (); | |
1161 | return; | |
1162 | } /* obj_coff_scl() */ | |
1163 | ||
1164 | static void | |
1165 | obj_coff_tag () | |
1166 | { | |
1167 | char *symbol_name; | |
1168 | char name_end; | |
1169 | ||
1170 | if (def_symbol_in_progress == NULL) | |
1171 | { | |
1172 | as_warn (".tag pseudo-op used outside of .def/.endef ignored."); | |
1173 | demand_empty_rest_of_line (); | |
1174 | return; | |
1175 | } /* if not inside .def/.endef */ | |
1176 | ||
1177 | S_SET_NUMBER_AUXILIARY (def_symbol_in_progress, 1); | |
1178 | symbol_name = input_line_pointer; | |
1179 | name_end = get_symbol_end (); | |
1180 | ||
1181 | /* Assume that the symbol referred to by .tag is always defined. */ | |
1182 | /* This was a bad assumption. I've added find_or_make. xoxorich. */ | |
1183 | SA_SET_SYM_TAGNDX (def_symbol_in_progress, (long) tag_find_or_make (symbol_name)); | |
1184 | if (SA_GET_SYM_TAGNDX (def_symbol_in_progress) == 0L) | |
1185 | { | |
1186 | as_warn ("tag not found for .tag %s", symbol_name); | |
1187 | } /* not defined */ | |
1188 | ||
1189 | SF_SET_TAGGED (def_symbol_in_progress); | |
1190 | *input_line_pointer = name_end; | |
1191 | ||
1192 | demand_empty_rest_of_line (); | |
1193 | return; | |
1194 | } /* obj_coff_tag() */ | |
1195 | ||
1196 | static void | |
1197 | obj_coff_type () | |
1198 | { | |
1199 | if (def_symbol_in_progress == NULL) | |
1200 | { | |
1201 | as_warn (".type pseudo-op used outside of .def/.endef ignored."); | |
1202 | demand_empty_rest_of_line (); | |
1203 | return; | |
1204 | } /* if not inside .def/.endef */ | |
1205 | ||
1206 | S_SET_DATA_TYPE (def_symbol_in_progress, get_absolute_expression ()); | |
1207 | ||
1208 | if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress)) && | |
1209 | S_GET_STORAGE_CLASS (def_symbol_in_progress) != C_TPDEF) | |
1210 | { | |
1211 | SF_SET_FUNCTION (def_symbol_in_progress); | |
1212 | } /* is a function */ | |
1213 | ||
1214 | demand_empty_rest_of_line (); | |
1215 | return; | |
1216 | } /* obj_coff_type() */ | |
1217 | ||
1218 | static void | |
1219 | obj_coff_val () | |
1220 | { | |
1221 | if (def_symbol_in_progress == NULL) | |
1222 | { | |
1223 | as_warn (".val pseudo-op used outside of .def/.endef ignored."); | |
1224 | demand_empty_rest_of_line (); | |
1225 | return; | |
1226 | } /* if not inside .def/.endef */ | |
1227 | ||
1228 | if (is_name_beginner (*input_line_pointer)) | |
1229 | { | |
1230 | char *symbol_name = input_line_pointer; | |
1231 | char name_end = get_symbol_end (); | |
1232 | ||
1233 | if (!strcmp (symbol_name, ".")) | |
1234 | { | |
1235 | def_symbol_in_progress->sy_frag = frag_now; | |
1236 | S_SET_VALUE (def_symbol_in_progress, obstack_next_free (&frags) - frag_now->fr_literal); | |
1237 | /* If the .val is != from the .def (e.g. statics) */ | |
1238 | } | |
1239 | else if (strcmp (S_GET_NAME (def_symbol_in_progress), symbol_name)) | |
1240 | { | |
1241 | def_symbol_in_progress->sy_forward = symbol_find_or_make (symbol_name); | |
1242 | ||
1243 | /* If the segment is undefined when the forward | |
db40ba14 SC |
1244 | reference is solved, then copy the segment id |
1245 | from the forward symbol. */ | |
355afbcd | 1246 | SF_SET_GET_SEGMENT (def_symbol_in_progress); |
016e0d42 ILT |
1247 | |
1248 | /* FIXME: gcc can generate address expressions | |
1249 | here in unusual cases (search for "obscure" | |
1250 | in sdbout.c). We just ignore the offset | |
1251 | here, thus generating incorrect debugging | |
1252 | information. We ignore the rest of the | |
1253 | line just below. */ | |
355afbcd | 1254 | } |
016e0d42 ILT |
1255 | /* Otherwise, it is the name of a non debug symbol and |
1256 | its value will be calculated later. */ | |
355afbcd | 1257 | *input_line_pointer = name_end; |
016e0d42 ILT |
1258 | |
1259 | /* FIXME: this is to avoid an error message in the | |
1260 | FIXME case mentioned just above. */ | |
1261 | while (! is_end_of_line[*input_line_pointer]) | |
1262 | ++input_line_pointer; | |
355afbcd KR |
1263 | } |
1264 | else | |
1265 | { | |
1266 | S_SET_VALUE (def_symbol_in_progress, get_absolute_expression ()); | |
1267 | } /* if symbol based */ | |
c593cf41 | 1268 | |
355afbcd KR |
1269 | demand_empty_rest_of_line (); |
1270 | return; | |
1271 | } /* obj_coff_val() */ | |
db40ba14 SC |
1272 | |
1273 | /* | |
1274 | * Maintain a list of the tagnames of the structres. | |
1275 | */ | |
1276 | ||
355afbcd KR |
1277 | static void |
1278 | tag_init () | |
1279 | { | |
1280 | tag_hash = hash_new (); | |
1281 | return; | |
1282 | } /* tag_init() */ | |
db40ba14 | 1283 | |
355afbcd KR |
1284 | static void |
1285 | tag_insert (name, symbolP) | |
1286 | char *name; | |
1287 | symbolS *symbolP; | |
db40ba14 | 1288 | { |
355afbcd | 1289 | register char *error_string; |
c593cf41 | 1290 | |
355afbcd KR |
1291 | if (*(error_string = hash_jam (tag_hash, name, (char *) symbolP))) |
1292 | { | |
1293 | as_fatal ("Inserting \"%s\" into structure table failed: %s", | |
1294 | name, error_string); | |
1295 | } | |
1296 | return; | |
1297 | } /* tag_insert() */ | |
db40ba14 | 1298 | |
355afbcd KR |
1299 | static symbolS * |
1300 | tag_find_or_make (name) | |
1301 | char *name; | |
db40ba14 | 1302 | { |
355afbcd | 1303 | symbolS *symbolP; |
c593cf41 | 1304 | |
355afbcd KR |
1305 | if ((symbolP = tag_find (name)) == NULL) |
1306 | { | |
1307 | symbolP = symbol_new (name, | |
1308 | SEG_UNKNOWN, | |
1309 | 0, | |
1310 | &zero_address_frag); | |
c593cf41 | 1311 | |
355afbcd | 1312 | tag_insert (S_GET_NAME (symbolP), symbolP); |
355afbcd | 1313 | } /* not found */ |
c593cf41 | 1314 | |
355afbcd KR |
1315 | return (symbolP); |
1316 | } /* tag_find_or_make() */ | |
db40ba14 | 1317 | |
355afbcd KR |
1318 | static symbolS * |
1319 | tag_find (name) | |
1320 | char *name; | |
db40ba14 SC |
1321 | { |
1322 | #ifdef STRIP_UNDERSCORE | |
355afbcd KR |
1323 | if (*name == '_') |
1324 | name++; | |
db40ba14 | 1325 | #endif /* STRIP_UNDERSCORE */ |
355afbcd KR |
1326 | return ((symbolS *) hash_find (tag_hash, name)); |
1327 | } /* tag_find() */ | |
db40ba14 | 1328 | |
355afbcd KR |
1329 | void |
1330 | obj_read_begin_hook () | |
1331 | { | |
1332 | /* These had better be the same. Usually 18 bytes. */ | |
db40ba14 | 1333 | #ifndef BFD_HEADERS |
355afbcd KR |
1334 | know (sizeof (SYMENT) == sizeof (AUXENT)); |
1335 | know (SYMESZ == AUXESZ); | |
db40ba14 | 1336 | #endif |
355afbcd | 1337 | tag_init (); |
c593cf41 | 1338 | |
355afbcd KR |
1339 | return; |
1340 | } /* obj_read_begin_hook() */ | |
db40ba14 SC |
1341 | |
1342 | /* This function runs through the symbol table and puts all the | |
1343 | externals onto another chain */ | |
1344 | ||
1345 | /* The chain of externals */ | |
1346 | symbolS *symbol_externP = NULL; | |
1347 | symbolS *symbol_extern_lastP = NULL; | |
1348 | ||
355afbcd KR |
1349 | stack *block_stack; |
1350 | symbolS *last_functionP = NULL; | |
1351 | symbolS *last_tagP; | |
db40ba14 | 1352 | |
355afbcd KR |
1353 | static unsigned int |
1354 | DEFUN_VOID (yank_symbols) | |
db40ba14 | 1355 | { |
c593cf41 | 1356 | symbolS *symbolP; |
355afbcd | 1357 | unsigned int symbol_number = 0; |
c0f1bbb6 | 1358 | unsigned int last_file_symno = 0; |
355afbcd | 1359 | |
c593cf41 SC |
1360 | for (symbolP = symbol_rootP; |
1361 | symbolP; | |
355afbcd KR |
1362 | symbolP = symbolP ? symbol_next (symbolP) : symbol_rootP) |
1363 | { | |
1364 | if (!SF_GET_DEBUG (symbolP)) | |
1365 | { | |
c593cf41 | 1366 | /* Debug symbols do not need all this rubbish */ |
355afbcd | 1367 | symbolS *real_symbolP; |
c593cf41 SC |
1368 | |
1369 | /* L* and C_EFCN symbols never merge. */ | |
355afbcd | 1370 | if (!SF_GET_LOCAL (symbolP) |
016e0d42 | 1371 | && S_GET_STORAGE_CLASS (symbolP) != C_LABEL |
b27caf27 | 1372 | && symbolP->sy_forward == NULL |
355afbcd KR |
1373 | && (real_symbolP = symbol_find_base (S_GET_NAME (symbolP), DO_NOT_STRIP)) |
1374 | && real_symbolP != symbolP) | |
1375 | { | |
c593cf41 SC |
1376 | /* FIXME-SOON: where do dups come from? |
1377 | Maybe tag references before definitions? xoxorich. */ | |
1378 | /* Move the debug data from the debug symbol to the | |
1379 | real symbol. Do NOT do the oposite (i.e. move from | |
1380 | real symbol to debug symbol and remove real symbol from the | |
1381 | list.) Because some pointers refer to the real symbol | |
1382 | whereas no pointers refer to the debug symbol. */ | |
355afbcd | 1383 | c_symbol_merge (symbolP, real_symbolP); |
c593cf41 SC |
1384 | /* Replace the current symbol by the real one */ |
1385 | /* The symbols will never be the last or the first | |
1386 | because : 1st symbol is .file and 3 last symbols are | |
1387 | .text, .data, .bss */ | |
355afbcd KR |
1388 | symbol_remove (real_symbolP, &symbol_rootP, &symbol_lastP); |
1389 | symbol_insert (real_symbolP, symbolP, &symbol_rootP, &symbol_lastP); | |
1390 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
c593cf41 SC |
1391 | symbolP = real_symbolP; |
1392 | } /* if not local but dup'd */ | |
1393 | ||
355afbcd KR |
1394 | if (flagseen['R'] && (S_GET_SEGMENT (symbolP) == SEG_E1)) |
1395 | { | |
1396 | S_SET_SEGMENT (symbolP, SEG_E0); | |
c593cf41 SC |
1397 | } /* push data into text */ |
1398 | ||
355afbcd KR |
1399 | S_SET_VALUE (symbolP, |
1400 | S_GET_VALUE (symbolP) + symbolP->sy_frag->fr_address); | |
c593cf41 | 1401 | |
355afbcd | 1402 | if (!S_IS_DEFINED (symbolP) && !SF_GET_LOCAL (symbolP)) |
c593cf41 | 1403 | { |
355afbcd KR |
1404 | S_SET_EXTERNAL (symbolP); |
1405 | } | |
1406 | else if (S_GET_STORAGE_CLASS (symbolP) == C_NULL) | |
c593cf41 | 1407 | { |
355afbcd KR |
1408 | if (S_GET_SEGMENT (symbolP) == SEG_E0) |
1409 | { | |
1410 | S_SET_STORAGE_CLASS (symbolP, C_LABEL); | |
1411 | } | |
1412 | else | |
1413 | { | |
1414 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
1415 | } | |
c593cf41 | 1416 | } |
c593cf41 SC |
1417 | |
1418 | /* Mainly to speed up if not -g */ | |
355afbcd KR |
1419 | if (SF_GET_PROCESS (symbolP)) |
1420 | { | |
1421 | /* Handle the nested blocks auxiliary info. */ | |
1422 | if (S_GET_STORAGE_CLASS (symbolP) == C_BLOCK) | |
1423 | { | |
1424 | if (!strcmp (S_GET_NAME (symbolP), ".bb")) | |
1425 | stack_push (block_stack, (char *) &symbolP); | |
1426 | else | |
1427 | { /* .eb */ | |
1428 | register symbolS *begin_symbolP; | |
1429 | begin_symbolP = *(symbolS **) stack_pop (block_stack); | |
1430 | if (begin_symbolP == (symbolS *) 0) | |
1431 | as_warn ("mismatched .eb"); | |
1432 | else | |
1433 | SA_SET_SYM_ENDNDX (begin_symbolP, symbol_number + 2); | |
1434 | } | |
1435 | } | |
1436 | /* If we are able to identify the type of a function, and we | |
c593cf41 SC |
1437 | are out of a function (last_functionP == 0) then, the |
1438 | function symbol will be associated with an auxiliary | |
1439 | entry. */ | |
355afbcd KR |
1440 | if (last_functionP == (symbolS *) 0 && |
1441 | SF_GET_FUNCTION (symbolP)) | |
1442 | { | |
1443 | last_functionP = symbolP; | |
c593cf41 | 1444 | |
355afbcd KR |
1445 | if (S_GET_NUMBER_AUXILIARY (symbolP) < 1) |
1446 | { | |
1447 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
1448 | } /* make it at least 1 */ | |
c593cf41 | 1449 | |
355afbcd | 1450 | /* Clobber possible stale .dim information. */ |
c593cf41 | 1451 | #if 0 |
355afbcd KR |
1452 | /* Iffed out by steve - this fries the lnnoptr info too */ |
1453 | bzero (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen, | |
1454 | sizeof (symbolP->sy_symbol.ost_auxent[0].x_sym.x_fcnary.x_ary.x_dimen)); | |
c593cf41 | 1455 | #endif |
355afbcd | 1456 | } |
c0f1bbb6 KR |
1457 | /* The C_FCN doesn't need any additional information. I |
1458 | don't even know if this is needed for sdb. But the | |
1459 | standard assembler generates it, so... */ | |
355afbcd KR |
1460 | if (S_GET_STORAGE_CLASS (symbolP) == C_EFCN) |
1461 | { | |
1462 | if (last_functionP == (symbolS *) 0) | |
1463 | as_fatal ("C_EFCN symbol out of scope"); | |
1464 | SA_SET_SYM_FSIZE (last_functionP, | |
1465 | (long) (S_GET_VALUE (symbolP) - | |
1466 | S_GET_VALUE (last_functionP))); | |
1467 | SA_SET_SYM_ENDNDX (last_functionP, symbol_number); | |
1468 | last_functionP = (symbolS *) 0; | |
1469 | } | |
1470 | } | |
1471 | } | |
1472 | else if (SF_GET_TAG (symbolP)) | |
1473 | { | |
1474 | /* First descriptor of a structure must point to | |
c593cf41 | 1475 | the first slot after the structure description. */ |
355afbcd KR |
1476 | last_tagP = symbolP; |
1477 | ||
1478 | } | |
1479 | else if (S_GET_STORAGE_CLASS (symbolP) == C_EOS) | |
1480 | { | |
1481 | /* +2 take in account the current symbol */ | |
1482 | SA_SET_SYM_ENDNDX (last_tagP, symbol_number + 2); | |
1483 | } | |
1484 | else if (S_GET_STORAGE_CLASS (symbolP) == C_FILE) | |
1485 | { | |
1486 | if (S_GET_VALUE (symbolP)) | |
1487 | { | |
c0f1bbb6 KR |
1488 | S_SET_VALUE (symbolP, last_file_symno); |
1489 | last_file_symno = symbol_number; | |
355afbcd KR |
1490 | } /* no one points at the first .file symbol */ |
1491 | } /* if debug or tag or eos or file */ | |
c593cf41 SC |
1492 | |
1493 | /* We must put the external symbols apart. The loader | |
1494 | does not bomb if we do not. But the references in | |
1495 | the endndx field for a .bb symbol are not corrected | |
1496 | if an external symbol is removed between .bb and .be. | |
1497 | I.e in the following case : | |
1498 | [20] .bb endndx = 22 | |
1499 | [21] foo external | |
1500 | [22] .be | |
1501 | ld will move the symbol 21 to the end of the list but | |
1502 | endndx will still be 22 instead of 21. */ | |
1503 | ||
1504 | ||
355afbcd KR |
1505 | if (SF_GET_LOCAL (symbolP)) |
1506 | { | |
c593cf41 SC |
1507 | /* remove C_EFCN and LOCAL (L...) symbols */ |
1508 | /* next pointer remains valid */ | |
355afbcd | 1509 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); |
c593cf41 SC |
1510 | |
1511 | } | |
355afbcd KR |
1512 | else if (!S_IS_DEFINED (symbolP) |
1513 | && !S_IS_DEBUG (symbolP) | |
1514 | && !SF_GET_STATICS (symbolP) && | |
1515 | S_GET_STORAGE_CLASS (symbolP) == C_EXT) | |
1516 | { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */ | |
1517 | /* if external, Remove from the list */ | |
1518 | symbolS *hold = symbol_previous (symbolP); | |
1519 | ||
1520 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); | |
1521 | symbol_clear_list_pointers (symbolP); | |
1522 | symbol_append (symbolP, symbol_extern_lastP, &symbol_externP, &symbol_extern_lastP); | |
1523 | symbolP = hold; | |
1524 | } | |
1525 | else | |
1526 | { | |
1527 | if (SF_GET_STRING (symbolP)) | |
1528 | { | |
1529 | symbolP->sy_name_offset = string_byte_count; | |
1530 | string_byte_count += strlen (S_GET_NAME (symbolP)) + 1; | |
1531 | } | |
1532 | else | |
1533 | { | |
1534 | symbolP->sy_name_offset = 0; | |
1535 | } /* fix "long" names */ | |
1536 | ||
1537 | symbolP->sy_number = symbol_number; | |
1538 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP); | |
1539 | } /* if local symbol */ | |
c593cf41 SC |
1540 | } /* traverse the symbol list */ |
1541 | return symbol_number; | |
355afbcd | 1542 | |
db40ba14 SC |
1543 | } |
1544 | ||
1545 | ||
355afbcd KR |
1546 | static unsigned int |
1547 | DEFUN_VOID (glue_symbols) | |
db40ba14 | 1548 | { |
c593cf41 | 1549 | unsigned int symbol_number = 0; |
355afbcd KR |
1550 | symbolS *symbolP; |
1551 | for (symbolP = symbol_externP; symbol_externP;) | |
1552 | { | |
c593cf41 SC |
1553 | symbolS *tmp = symbol_externP; |
1554 | ||
1555 | /* append */ | |
355afbcd KR |
1556 | symbol_remove (tmp, &symbol_externP, &symbol_extern_lastP); |
1557 | symbol_append (tmp, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
c593cf41 SC |
1558 | |
1559 | /* and process */ | |
355afbcd KR |
1560 | if (SF_GET_STRING (tmp)) |
1561 | { | |
c593cf41 | 1562 | tmp->sy_name_offset = string_byte_count; |
355afbcd KR |
1563 | string_byte_count += strlen (S_GET_NAME (tmp)) + 1; |
1564 | } | |
1565 | else | |
1566 | { | |
1567 | tmp->sy_name_offset = 0; | |
1568 | } /* fix "long" names */ | |
c593cf41 SC |
1569 | |
1570 | tmp->sy_number = symbol_number; | |
355afbcd | 1571 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (tmp); |
c593cf41 SC |
1572 | } /* append the entire extern chain */ |
1573 | return symbol_number; | |
355afbcd | 1574 | |
db40ba14 SC |
1575 | } |
1576 | ||
355afbcd KR |
1577 | static unsigned int |
1578 | DEFUN_VOID (tie_tags) | |
db40ba14 | 1579 | { |
c593cf41 | 1580 | unsigned int symbol_number = 0; |
355afbcd KR |
1581 | |
1582 | symbolS *symbolP; | |
c593cf41 | 1583 | for (symbolP = symbol_rootP; symbolP; symbolP = |
355afbcd KR |
1584 | symbol_next (symbolP)) |
1585 | { | |
1586 | symbolP->sy_number = symbol_number; | |
c593cf41 SC |
1587 | |
1588 | ||
1589 | ||
355afbcd KR |
1590 | if (SF_GET_TAGGED (symbolP)) |
1591 | { | |
1592 | SA_SET_SYM_TAGNDX | |
1593 | (symbolP, | |
1594 | ((symbolS *) SA_GET_SYM_TAGNDX (symbolP))->sy_number); | |
1595 | } | |
c593cf41 | 1596 | |
355afbcd KR |
1597 | symbol_number += 1 + S_GET_NUMBER_AUXILIARY (symbolP); |
1598 | } | |
c593cf41 | 1599 | return symbol_number; |
355afbcd | 1600 | |
db40ba14 SC |
1601 | } |
1602 | ||
355afbcd | 1603 | static void |
9a75dc1f ILT |
1604 | DEFUN (crawl_symbols, (h, abfd), |
1605 | object_headers *h AND | |
355afbcd | 1606 | bfd * abfd) |
db40ba14 | 1607 | { |
c593cf41 | 1608 | |
355afbcd | 1609 | unsigned int i; |
c593cf41 SC |
1610 | symbolS *symbolP; |
1611 | ||
1612 | /* Initialize the stack used to keep track of the matching .bb .be */ | |
1613 | ||
355afbcd | 1614 | block_stack = stack_init (512, sizeof (symbolS *)); |
c593cf41 | 1615 | /* JF deal with forward references first... */ |
b27caf27 KR |
1616 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) |
1617 | if (symbolP->sy_forward) | |
1618 | { | |
1619 | S_SET_VALUE (symbolP, (S_GET_VALUE (symbolP) | |
1620 | + S_GET_VALUE (symbolP->sy_forward) | |
355afbcd | 1621 | + symbolP->sy_forward->sy_frag->fr_address)); |
b27caf27 KR |
1622 | if (SF_GET_GET_SEGMENT (symbolP)) |
1623 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (symbolP->sy_forward)); | |
1624 | } | |
c593cf41 SC |
1625 | |
1626 | /* The symbol list should be ordered according to the following sequence | |
1627 | * order : | |
1628 | * . .file symbol | |
1629 | * . debug entries for functions | |
1630 | * . fake symbols for the sections, including.text .data and .bss | |
1631 | * . defined symbols | |
1632 | * . undefined symbols | |
1633 | * But this is not mandatory. The only important point is to put the | |
1634 | * undefined symbols at the end of the list. | |
1635 | */ | |
1636 | ||
1637 | if (symbol_rootP == NULL | |
355afbcd KR |
1638 | || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE) |
1639 | { | |
1640 | c_dot_file_symbol ("fake"); | |
c593cf41 SC |
1641 | } |
1642 | /* Is there a .file symbol ? If not insert one at the beginning. */ | |
1643 | ||
1644 | /* | |
1645 | * Build up static symbols for the sections, they are filled in later | |
1646 | */ | |
1647 | ||
1648 | ||
355afbcd | 1649 | for (i = SEG_E0; i < SEG_E9; i++) |
c593cf41 | 1650 | { |
355afbcd KR |
1651 | if (segment_info[i].scnhdr.s_name[0]) |
1652 | { | |
9a75dc1f | 1653 | char name[9]; |
355afbcd | 1654 | |
9a75dc1f ILT |
1655 | strncpy (name, segment_info[i].scnhdr.s_name, 8); |
1656 | name[8] = '\0'; | |
1657 | segment_info[i].dot = c_section_symbol (name, i - SEG_E0 + 1); | |
355afbcd | 1658 | } |
c593cf41 | 1659 | } |
c593cf41 SC |
1660 | |
1661 | ||
1662 | /* Take all the externals out and put them into another chain */ | |
9a75dc1f | 1663 | H_SET_SYMBOL_TABLE_SIZE (h, yank_symbols ()); |
c593cf41 | 1664 | /* Take the externals and glue them onto the end.*/ |
9a75dc1f | 1665 | H_SET_SYMBOL_TABLE_SIZE (h, H_GET_SYMBOL_COUNT (h) + glue_symbols ()); |
c593cf41 | 1666 | |
9a75dc1f | 1667 | H_SET_SYMBOL_TABLE_SIZE (h, tie_tags ()); |
355afbcd KR |
1668 | know (symbol_externP == NULL); |
1669 | know (symbol_extern_lastP == NULL); | |
c593cf41 SC |
1670 | |
1671 | return; | |
db40ba14 SC |
1672 | } |
1673 | ||
1674 | /* | |
1675 | * Find strings by crawling along symbol table chain. | |
1676 | */ | |
1677 | ||
355afbcd KR |
1678 | void |
1679 | DEFUN (w_strings, (where), | |
1680 | char *where) | |
db40ba14 | 1681 | { |
c593cf41 SC |
1682 | symbolS *symbolP; |
1683 | ||
1684 | /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */ | |
ad86fa70 SC |
1685 | md_number_to_chars (where, string_byte_count, 4); |
1686 | where += 4; | |
c593cf41 SC |
1687 | for (symbolP = symbol_rootP; |
1688 | symbolP; | |
355afbcd KR |
1689 | symbolP = symbol_next (symbolP)) |
1690 | { | |
1691 | unsigned int size; | |
1692 | ||
1693 | if (SF_GET_STRING (symbolP)) | |
1694 | { | |
1695 | size = strlen (S_GET_NAME (symbolP)) + 1; | |
1696 | ||
1697 | memcpy (where, S_GET_NAME (symbolP), size); | |
1698 | where += size; | |
1699 | ||
1700 | } | |
1701 | } | |
c593cf41 | 1702 | |
db40ba14 SC |
1703 | } |
1704 | ||
355afbcd | 1705 | static void |
9a75dc1f | 1706 | DEFUN (do_linenos_for, (abfd, h, file_cursor), |
355afbcd | 1707 | bfd * abfd AND |
9a75dc1f | 1708 | object_headers * h AND |
355afbcd | 1709 | unsigned long *file_cursor) |
db40ba14 | 1710 | { |
c593cf41 | 1711 | unsigned int idx; |
9a75dc1f | 1712 | unsigned long start = *file_cursor; |
c593cf41 | 1713 | |
355afbcd | 1714 | for (idx = SEG_E0; idx < SEG_E9; idx++) |
c593cf41 | 1715 | { |
355afbcd | 1716 | segment_info_type *s = segment_info + idx; |
c593cf41 | 1717 | |
c593cf41 | 1718 | |
355afbcd KR |
1719 | if (s->scnhdr.s_nlnno != 0) |
1720 | { | |
1721 | struct lineno_list *line_ptr; | |
1722 | ||
1723 | struct external_lineno *buffer = | |
1724 | (struct external_lineno *) xmalloc (s->scnhdr.s_nlnno * LINESZ); | |
c593cf41 | 1725 | |
355afbcd KR |
1726 | struct external_lineno *dst = buffer; |
1727 | ||
1728 | /* Run through the table we've built and turn it into its external | |
c593cf41 SC |
1729 | form, take this chance to remove duplicates */ |
1730 | ||
355afbcd KR |
1731 | for (line_ptr = s->lineno_list_head; |
1732 | line_ptr != (struct lineno_list *) NULL; | |
1733 | line_ptr = line_ptr->next) | |
1734 | { | |
c593cf41 | 1735 | |
355afbcd KR |
1736 | if (line_ptr->line.l_lnno == 0) |
1737 | { | |
1738 | /* Turn a pointer to a symbol into the symbols' index */ | |
1739 | line_ptr->line.l_addr.l_symndx = | |
1740 | ((symbolS *) line_ptr->line.l_addr.l_symndx)->sy_number; | |
1741 | } | |
1742 | else | |
1743 | { | |
1744 | line_ptr->line.l_addr.l_paddr += ((struct frag *) (line_ptr->frag))->fr_address; | |
1745 | } | |
c593cf41 | 1746 | |
c593cf41 | 1747 | |
355afbcd KR |
1748 | (void) bfd_coff_swap_lineno_out (abfd, &(line_ptr->line), dst); |
1749 | dst++; | |
1750 | ||
1751 | } | |
1752 | ||
1753 | s->scnhdr.s_lnnoptr = *file_cursor; | |
1754 | ||
1755 | bfd_write (buffer, 1, s->scnhdr.s_nlnno * LINESZ, abfd); | |
1756 | free (buffer); | |
1757 | ||
1758 | *file_cursor += s->scnhdr.s_nlnno * LINESZ; | |
1759 | } | |
c593cf41 | 1760 | } |
9a75dc1f | 1761 | H_SET_LINENO_SIZE (h, *file_cursor - start); |
db40ba14 SC |
1762 | } |
1763 | ||
1764 | ||
1765 | /* Now we run through the list of frag chains in a segment and | |
1766 | make all the subsegment frags appear at the end of the | |
1767 | list, as if the seg 0 was extra long */ | |
1768 | ||
355afbcd KR |
1769 | static void |
1770 | DEFUN_VOID (remove_subsegs) | |
db40ba14 | 1771 | { |
355afbcd KR |
1772 | unsigned int i; |
1773 | ||
1774 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
1775 | { | |
1776 | frchainS *head = segment_info[i].frchainP; | |
1777 | fragS dummy; | |
1778 | fragS *prev_frag = &dummy; | |
1779 | ||
1780 | while (head && head->frch_seg == i) | |
c593cf41 | 1781 | { |
355afbcd KR |
1782 | prev_frag->fr_next = head->frch_root; |
1783 | prev_frag = head->frch_last; | |
1784 | head = head->frch_next; | |
c593cf41 | 1785 | } |
355afbcd | 1786 | prev_frag->fr_next = 0; |
c593cf41 | 1787 | } |
db40ba14 SC |
1788 | } |
1789 | ||
163107a1 SC |
1790 | int machine; |
1791 | int coff_flags; | |
355afbcd KR |
1792 | extern void |
1793 | DEFUN_VOID (write_object_file) | |
db40ba14 | 1794 | { |
355afbcd KR |
1795 | int i; |
1796 | struct frchain *frchain_ptr; | |
c593cf41 | 1797 | |
9a75dc1f | 1798 | object_headers headers; |
355afbcd KR |
1799 | unsigned long file_cursor; |
1800 | bfd *abfd; | |
1801 | unsigned int addr; | |
1802 | abfd = bfd_openw (out_file_name, TARGET_FORMAT); | |
c593cf41 SC |
1803 | |
1804 | ||
355afbcd KR |
1805 | if (abfd == 0) |
1806 | { | |
1807 | as_perror ("FATAL: Can't create %s", out_file_name); | |
1808 | exit (42); | |
1809 | } | |
1810 | bfd_set_format (abfd, bfd_object); | |
1811 | bfd_set_arch_mach (abfd, BFD_ARCH, machine); | |
c593cf41 | 1812 | |
355afbcd KR |
1813 | string_byte_count = 4; |
1814 | ||
1815 | for (frchain_ptr = frchain_root; | |
1816 | frchain_ptr != (struct frchain *) NULL; | |
1817 | frchain_ptr = frchain_ptr->frch_next) | |
1818 | { | |
1819 | /* Run through all the sub-segments and align them up. Also close any | |
c593cf41 SC |
1820 | open frags. We tack a .fill onto the end of the frag chain so |
1821 | that any .align's size can be worked by looking at the next | |
1822 | frag */ | |
1823 | ||
355afbcd | 1824 | subseg_new (frchain_ptr->frch_seg, frchain_ptr->frch_subseg); |
016e0d42 | 1825 | #ifndef SUB_SEGMENT_ALIGN |
2492e118 | 1826 | #define SUB_SEGMENT_ALIGN(SEG) 1 |
016e0d42 | 1827 | #endif |
2492e118 | 1828 | frag_align (SUB_SEGMENT_ALIGN (now_seg), NOP_OPCODE); |
355afbcd KR |
1829 | frag_wane (frag_now); |
1830 | frag_now->fr_fix = 0; | |
1831 | know (frag_now->fr_next == NULL); | |
1832 | } | |
c593cf41 SC |
1833 | |
1834 | ||
355afbcd | 1835 | remove_subsegs (); |
c593cf41 | 1836 | |
355afbcd KR |
1837 | |
1838 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
c593cf41 | 1839 | { |
355afbcd | 1840 | relax_segment (segment_info[i].frchainP->frch_root, i); |
c593cf41 | 1841 | } |
c593cf41 | 1842 | |
9a75dc1f | 1843 | H_SET_NUMBER_OF_SECTIONS (&headers, 0); |
355afbcd KR |
1844 | |
1845 | /* Find out how big the sections are, and set the addresses. */ | |
1846 | addr = 0; | |
1847 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) | |
1848 | { | |
9a75dc1f ILT |
1849 | long size; |
1850 | ||
355afbcd | 1851 | segment_info[i].scnhdr.s_paddr = addr; |
e63164f9 | 1852 | segment_info[i].scnhdr.s_vaddr = addr; |
c593cf41 | 1853 | |
355afbcd | 1854 | if (segment_info[i].scnhdr.s_name[0]) |
a39116f1 | 1855 | { |
9a75dc1f ILT |
1856 | H_SET_NUMBER_OF_SECTIONS (&headers, |
1857 | H_GET_NUMBER_OF_SECTIONS (&headers) + 1); | |
a39116f1 | 1858 | } |
355afbcd | 1859 | |
9a75dc1f ILT |
1860 | size = size_section (abfd, i); |
1861 | addr += size; | |
016e0d42 | 1862 | |
9a75dc1f ILT |
1863 | if (i == SEG_E0) |
1864 | H_SET_TEXT_SIZE (&headers, size); | |
1865 | else if (i == SEG_E1) | |
1866 | H_SET_DATA_SIZE (&headers, size); | |
1867 | else if (i == SEG_E2) | |
1868 | H_SET_BSS_SIZE (&headers, size); | |
355afbcd | 1869 | } |
c593cf41 | 1870 | |
9a75dc1f ILT |
1871 | /* Turn the gas native symbol table shape into a coff symbol table */ |
1872 | crawl_symbols (&headers, abfd); | |
1873 | ||
1874 | if (string_byte_count == 4) | |
1875 | string_byte_count = 0; | |
c593cf41 | 1876 | |
9a75dc1f | 1877 | H_SET_STRING_SIZE (&headers, string_byte_count); |
c593cf41 | 1878 | |
033400ec | 1879 | #if !defined(TC_H8300) && !defined(TC_Z8K) |
355afbcd | 1880 | for (i = SEG_E0; i < SEG_UNKNOWN; i++) |
c593cf41 | 1881 | { |
9a75dc1f | 1882 | fixup_mdeps (segment_info[i].frchainP->frch_root, &headers, i); |
016e0d42 | 1883 | fixup_segment (&segment_info[i], i); |
c593cf41 SC |
1884 | } |
1885 | #endif | |
1886 | ||
9a75dc1f | 1887 | file_cursor = H_GET_TEXT_FILE_OFFSET (&headers); |
355afbcd KR |
1888 | |
1889 | bfd_seek (abfd, file_cursor, 0); | |
c593cf41 | 1890 | |
355afbcd | 1891 | /* Plant the data */ |
c593cf41 | 1892 | |
9a75dc1f | 1893 | fill_section (abfd, &headers, &file_cursor); |
c593cf41 | 1894 | |
9a75dc1f | 1895 | do_relocs_for (abfd, &headers, &file_cursor); |
c593cf41 | 1896 | |
9a75dc1f | 1897 | do_linenos_for (abfd, &headers, &file_cursor); |
c593cf41 | 1898 | |
9a75dc1f ILT |
1899 | H_SET_FILE_MAGIC_NUMBER (&headers, COFF_MAGIC); |
1900 | #ifndef OBJ_COFF_OMIT_TIMESTAMP | |
1901 | H_SET_TIME_STAMP (&headers, (long)time((long*)0)); | |
1902 | #else | |
1903 | H_SET_TIME_STAMP (&headers, 0); | |
1904 | #endif | |
c593cf41 | 1905 | |
9a75dc1f ILT |
1906 | #ifdef KEEP_RELOC_INFO |
1907 | H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) | | |
1908 | COFF_FLAGS | coff_flags)); | |
1909 | #else | |
1910 | H_SET_FLAGS (&headers, ((H_GET_LINENO_SIZE(&headers) ? 0 : F_LNNO) | | |
1911 | (H_GET_RELOCATION_SIZE(&headers) ? 0 : F_RELFLG) | | |
1912 | COFF_FLAGS | coff_flags)); | |
1913 | #endif | |
c593cf41 SC |
1914 | |
1915 | { | |
9a75dc1f ILT |
1916 | unsigned int symtable_size = H_GET_SYMBOL_TABLE_SIZE (&headers); |
1917 | char *buffer1 = xmalloc (symtable_size + string_byte_count + 1); | |
355afbcd | 1918 | char *ptr = buffer1; |
9a75dc1f | 1919 | H_SET_SYMBOL_TABLE_POINTER (&headers, bfd_tell (abfd)); |
355afbcd | 1920 | w_symbols (abfd, buffer1, symbol_rootP); |
9a75dc1f ILT |
1921 | if (string_byte_count > 0) |
1922 | w_strings (buffer1 + symtable_size); | |
1923 | bfd_write (buffer1, 1, symtable_size + string_byte_count, abfd); | |
355afbcd | 1924 | free (buffer1); |
c593cf41 | 1925 | } |
9a75dc1f ILT |
1926 | |
1927 | coff_header_append (abfd, &headers); | |
c593cf41 | 1928 | |
355afbcd KR |
1929 | if (bfd_close_all_done (abfd) == false) |
1930 | as_fatal ("Can't close %s: %s", out_file_name, | |
1931 | bfd_errmsg (bfd_error)); | |
db40ba14 SC |
1932 | } |
1933 | ||
1934 | ||
355afbcd KR |
1935 | static void |
1936 | DEFUN (change_to_section, (name, len, exp), | |
1937 | char *name AND | |
1938 | unsigned int len AND | |
1939 | unsigned int exp) | |
db40ba14 | 1940 | { |
355afbcd | 1941 | unsigned int i; |
c593cf41 | 1942 | /* Find out if we've already got a section of this name etc */ |
355afbcd | 1943 | for (i = SEG_E0; i < SEG_E9 && segment_info[i].scnhdr.s_name[0]; i++) |
c593cf41 | 1944 | { |
355afbcd KR |
1945 | if (strncmp (segment_info[i].scnhdr.s_name, name, len) == 0) |
1946 | { | |
1947 | subseg_new (i, exp); | |
1948 | return; | |
355afbcd | 1949 | } |
c593cf41 | 1950 | } |
c593cf41 | 1951 | /* No section, add one */ |
355afbcd | 1952 | strncpy (segment_info[i].scnhdr.s_name, name, 8); |
b27caf27 | 1953 | segment_info[i].scnhdr.s_flags = STYP_REG; |
355afbcd | 1954 | subseg_new (i, exp); |
db40ba14 SC |
1955 | } |
1956 | ||
9a75dc1f ILT |
1957 | /* |
1958 | * implement the .section pseudo op: | |
1959 | * .section name {, "flags"} | |
1960 | * ^ ^ | |
1961 | * | +--- optional flags: 'b' for bss | |
1962 | * | 'i' for info | |
1963 | * +-- section name 'l' for lib | |
1964 | * 'n' for noload | |
1965 | * 'o' for over | |
1966 | * 'w' for data | |
1967 | * 'x' for text | |
1968 | * But if the argument is not a quoted string, treat it as a | |
1969 | * subsegment number. | |
1970 | */ | |
1971 | ||
355afbcd KR |
1972 | void |
1973 | DEFUN_VOID (obj_coff_section) | |
db40ba14 | 1974 | { |
355afbcd KR |
1975 | /* Strip out the section name */ |
1976 | char *section_name; | |
1977 | char *section_name_end; | |
1978 | char c; | |
9a75dc1f | 1979 | int argp; |
355afbcd KR |
1980 | unsigned int len; |
1981 | unsigned int exp; | |
9a75dc1f | 1982 | long flags; |
355afbcd KR |
1983 | |
1984 | section_name = input_line_pointer; | |
1985 | c = get_symbol_end (); | |
1986 | section_name_end = input_line_pointer; | |
1987 | ||
1988 | len = section_name_end - section_name; | |
1989 | input_line_pointer++; | |
1990 | SKIP_WHITESPACE (); | |
016e0d42 | 1991 | |
9a75dc1f ILT |
1992 | argp = 0; |
1993 | if (c == ',') | |
1994 | argp = 1; | |
1995 | else if (*input_line_pointer == ',') | |
355afbcd | 1996 | { |
9a75dc1f ILT |
1997 | argp = 1; |
1998 | ++input_line_pointer; | |
1999 | SKIP_WHITESPACE (); | |
c593cf41 | 2000 | } |
9a75dc1f ILT |
2001 | |
2002 | exp = 0; | |
2003 | flags = 0; | |
2004 | if (argp) | |
c593cf41 | 2005 | { |
9a75dc1f ILT |
2006 | if (*input_line_pointer != '"') |
2007 | exp = get_absolute_expression (); | |
2008 | else | |
2009 | { | |
2010 | ++input_line_pointer; | |
2011 | while (*input_line_pointer != '"' | |
2012 | && ! is_end_of_line[*input_line_pointer]) | |
2013 | { | |
2014 | switch (*input_line_pointer) | |
2015 | { | |
2016 | case 'b': flags |= STYP_BSS; break; | |
2017 | case 'i': flags |= STYP_INFO; break; | |
2018 | case 'l': flags |= STYP_LIB; break; | |
2019 | case 'n': flags |= STYP_NOLOAD; break; | |
2020 | case 'o': flags |= STYP_OVER; break; | |
2021 | case 'w': flags |= STYP_DATA; break; | |
2022 | case 'x': flags |= STYP_TEXT; break; | |
2023 | default: | |
2024 | as_warn("unknown section attribute '%c'", | |
2025 | *input_line_pointer); | |
2026 | break; | |
2027 | } | |
2028 | ++input_line_pointer; | |
2029 | } | |
2030 | if (*input_line_pointer == '"') | |
2031 | ++input_line_pointer; | |
2032 | } | |
c593cf41 | 2033 | } |
355afbcd KR |
2034 | |
2035 | change_to_section (section_name, len, exp); | |
9a75dc1f ILT |
2036 | |
2037 | segment_info[now_seg].scnhdr.s_flags |= flags; | |
2038 | ||
355afbcd | 2039 | *section_name_end = c; |
db40ba14 SC |
2040 | } |
2041 | ||
2042 | ||
355afbcd KR |
2043 | static void |
2044 | obj_coff_text () | |
db40ba14 | 2045 | { |
355afbcd | 2046 | change_to_section (".text", 5, get_absolute_expression ()); |
db40ba14 SC |
2047 | } |
2048 | ||
2049 | ||
355afbcd KR |
2050 | static void |
2051 | obj_coff_data () | |
db40ba14 | 2052 | { |
355afbcd | 2053 | change_to_section (".data", 5, get_absolute_expression ()); |
db40ba14 SC |
2054 | } |
2055 | ||
9a75dc1f ILT |
2056 | static void |
2057 | obj_coff_bss() | |
2058 | { | |
2059 | if (*input_line_pointer == '\n') /* .bss */ | |
2060 | change_to_section(".bss",4, get_absolute_expression()); | |
2061 | else /* .bss id,expr */ | |
2062 | obj_coff_lcomm(); | |
2063 | } | |
2064 | ||
2065 | static void | |
2066 | obj_coff_ident() | |
2067 | { | |
2068 | segT current_seg = now_seg; /* save current seg */ | |
2069 | subsegT current_subseg = now_subseg; | |
2070 | change_to_section (".comment", 8, 0); /* .comment seg */ | |
2071 | stringer (1); /* read string */ | |
2072 | subseg_new (current_seg, current_subseg); /* restore current seg */ | |
2073 | } | |
2074 | ||
355afbcd KR |
2075 | void |
2076 | c_symbol_merge (debug, normal) | |
2077 | symbolS *debug; | |
2078 | symbolS *normal; | |
db40ba14 | 2079 | { |
355afbcd KR |
2080 | S_SET_DATA_TYPE (normal, S_GET_DATA_TYPE (debug)); |
2081 | S_SET_STORAGE_CLASS (normal, S_GET_STORAGE_CLASS (debug)); | |
c593cf41 | 2082 | |
355afbcd KR |
2083 | if (S_GET_NUMBER_AUXILIARY (debug) > S_GET_NUMBER_AUXILIARY (normal)) |
2084 | { | |
2085 | S_SET_NUMBER_AUXILIARY (normal, S_GET_NUMBER_AUXILIARY (debug)); | |
2086 | } /* take the most we have */ | |
c593cf41 | 2087 | |
355afbcd KR |
2088 | if (S_GET_NUMBER_AUXILIARY (debug) > 0) |
2089 | { | |
2090 | memcpy ((char *) &normal->sy_symbol.ost_auxent[0], (char *) &debug->sy_symbol.ost_auxent[0], S_GET_NUMBER_AUXILIARY (debug) * AUXESZ); | |
2091 | } /* Move all the auxiliary information */ | |
c593cf41 | 2092 | |
355afbcd KR |
2093 | /* Move the debug flags. */ |
2094 | SF_SET_DEBUG_FIELD (normal, SF_GET_DEBUG_FIELD (debug)); | |
2095 | } /* c_symbol_merge() */ | |
db40ba14 SC |
2096 | |
2097 | static int | |
355afbcd KR |
2098 | DEFUN (c_line_new, (symbol, paddr, line_number, frag), |
2099 | symbolS * symbol AND | |
2100 | long paddr AND | |
2101 | unsigned short line_number AND | |
2102 | fragS * frag) | |
db40ba14 | 2103 | { |
355afbcd KR |
2104 | struct lineno_list *new_line = |
2105 | (struct lineno_list *) xmalloc (sizeof (struct lineno_list)); | |
2106 | ||
2107 | segment_info_type *s = segment_info + now_seg; | |
c593cf41 SC |
2108 | new_line->line.l_lnno = line_number; |
2109 | ||
355afbcd KR |
2110 | if (line_number == 0) |
2111 | { | |
2112 | last_line_symbol = symbol; | |
2113 | new_line->line.l_addr.l_symndx = (long) symbol; | |
2114 | } | |
2115 | else | |
2116 | { | |
2117 | new_line->line.l_addr.l_paddr = paddr; | |
2118 | } | |
c593cf41 | 2119 | |
355afbcd KR |
2120 | new_line->frag = (char *) frag; |
2121 | new_line->next = (struct lineno_list *) NULL; | |
2122 | ||
2123 | ||
2124 | if (s->lineno_list_head == (struct lineno_list *) NULL) | |
2125 | { | |
2126 | s->lineno_list_head = new_line; | |
2127 | } | |
2128 | else | |
2129 | { | |
2130 | s->lineno_list_tail->next = new_line; | |
2131 | } | |
c58dbabf | 2132 | s->lineno_list_tail = new_line; |
355afbcd | 2133 | return LINESZ * s->scnhdr.s_nlnno++; |
db40ba14 SC |
2134 | } |
2135 | ||
355afbcd KR |
2136 | void |
2137 | c_dot_file_symbol (filename) | |
2138 | char *filename; | |
db40ba14 | 2139 | { |
355afbcd | 2140 | symbolS *symbolP; |
c593cf41 | 2141 | |
355afbcd KR |
2142 | symbolP = symbol_new (".file", |
2143 | SEG_DEBUG, | |
2144 | 0, | |
2145 | &zero_address_frag); | |
c593cf41 | 2146 | |
355afbcd KR |
2147 | S_SET_STORAGE_CLASS (symbolP, C_FILE); |
2148 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
2149 | SA_SET_FILE_FNAME (symbolP, filename); | |
9ce31b66 | 2150 | #ifndef NO_LISTING |
c593cf41 SC |
2151 | { |
2152 | extern int listing; | |
355afbcd KR |
2153 | if (listing) |
2154 | { | |
2155 | listing_source_file (filename); | |
2156 | } | |
2157 | ||
c593cf41 | 2158 | } |
c593cf41 | 2159 | |
355afbcd KR |
2160 | #endif |
2161 | SF_SET_DEBUG (symbolP); | |
2162 | S_SET_VALUE (symbolP, (long) previous_file_symbol); | |
2163 | ||
2164 | previous_file_symbol = symbolP; | |
c593cf41 | 2165 | |
355afbcd KR |
2166 | /* Make sure that the symbol is first on the symbol chain */ |
2167 | if (symbol_rootP != symbolP) | |
2168 | { | |
2169 | if (symbolP == symbol_lastP) | |
2170 | { | |
2171 | symbol_lastP = symbol_lastP->sy_previous; | |
2172 | } /* if it was the last thing on the list */ | |
c593cf41 | 2173 | |
355afbcd KR |
2174 | symbol_remove (symbolP, &symbol_rootP, &symbol_lastP); |
2175 | symbol_insert (symbolP, symbol_rootP, &symbol_rootP, &symbol_lastP); | |
2176 | symbol_rootP = symbolP; | |
2177 | } /* if not first on the list */ | |
c593cf41 | 2178 | |
355afbcd | 2179 | } /* c_dot_file_symbol() */ |
db40ba14 SC |
2180 | |
2181 | /* | |
2182 | * Build a 'section static' symbol. | |
2183 | */ | |
2184 | ||
355afbcd KR |
2185 | symbolS * |
2186 | c_section_symbol (name, idx) | |
2187 | char *name; | |
2188 | int idx; | |
db40ba14 | 2189 | { |
355afbcd | 2190 | symbolS *symbolP; |
c593cf41 | 2191 | |
355afbcd KR |
2192 | symbolP = symbol_new (name, idx, |
2193 | 0, | |
2194 | &zero_address_frag); | |
c593cf41 | 2195 | |
355afbcd KR |
2196 | S_SET_STORAGE_CLASS (symbolP, C_STAT); |
2197 | S_SET_NUMBER_AUXILIARY (symbolP, 1); | |
c593cf41 | 2198 | |
355afbcd | 2199 | SF_SET_STATICS (symbolP); |
c593cf41 | 2200 | |
355afbcd KR |
2201 | return symbolP; |
2202 | } /* c_section_symbol() */ | |
db40ba14 | 2203 | |
355afbcd KR |
2204 | static void |
2205 | DEFUN (w_symbols, (abfd, where, symbol_rootP), | |
2206 | bfd * abfd AND | |
2207 | char *where AND | |
2208 | symbolS * symbol_rootP) | |
db40ba14 | 2209 | { |
355afbcd KR |
2210 | symbolS *symbolP; |
2211 | unsigned int i; | |
2212 | ||
2213 | /* First fill in those values we have only just worked out */ | |
2214 | for (i = SEG_E0; i < SEG_E9; i++) | |
2215 | { | |
2216 | symbolP = segment_info[i].dot; | |
2217 | if (symbolP) | |
c593cf41 | 2218 | { |
355afbcd KR |
2219 | |
2220 | SA_SET_SCN_SCNLEN (symbolP, segment_info[i].scnhdr.s_size); | |
2221 | SA_SET_SCN_NRELOC (symbolP, segment_info[i].scnhdr.s_nreloc); | |
2222 | SA_SET_SCN_NLINNO (symbolP, segment_info[i].scnhdr.s_nlnno); | |
2223 | ||
c593cf41 SC |
2224 | } |
2225 | } | |
355afbcd KR |
2226 | |
2227 | /* | |
c593cf41 SC |
2228 | * Emit all symbols left in the symbol chain. |
2229 | */ | |
355afbcd KR |
2230 | for (symbolP = symbol_rootP; symbolP; symbolP = symbol_next (symbolP)) |
2231 | { | |
2232 | /* Used to save the offset of the name. It is used to point | |
c593cf41 | 2233 | to the string in memory but must be a file offset. */ |
355afbcd | 2234 | register char *temp; |
c593cf41 | 2235 | |
355afbcd | 2236 | tc_coff_symbol_emit_hook (symbolP); |
c593cf41 | 2237 | |
355afbcd KR |
2238 | temp = S_GET_NAME (symbolP); |
2239 | if (SF_GET_STRING (symbolP)) | |
2240 | { | |
2241 | S_SET_OFFSET (symbolP, symbolP->sy_name_offset); | |
2242 | S_SET_ZEROES (symbolP, 0); | |
db40ba14 | 2243 | } |
355afbcd KR |
2244 | else |
2245 | { | |
2246 | bzero (symbolP->sy_symbol.ost_entry.n_name, SYMNMLEN); | |
2247 | strncpy (symbolP->sy_symbol.ost_entry.n_name, temp, SYMNMLEN); | |
2248 | } | |
2249 | where = symbol_to_chars (abfd, where, symbolP); | |
2250 | S_SET_NAME (symbolP, temp); | |
2251 | } | |
2252 | ||
db40ba14 SC |
2253 | } /* w_symbols() */ |
2254 | ||
355afbcd KR |
2255 | static void |
2256 | DEFUN_VOID (obj_coff_lcomm) | |
db40ba14 | 2257 | { |
b066f445 SEF |
2258 | char *name; |
2259 | char c; | |
2260 | int temp; | |
2261 | char *p; | |
d752f749 | 2262 | |
b066f445 SEF |
2263 | symbolS *symbolP; |
2264 | name = input_line_pointer; | |
c593cf41 | 2265 | |
355afbcd | 2266 | c = get_symbol_end (); |
b066f445 SEF |
2267 | p = input_line_pointer; |
2268 | *p = c; | |
355afbcd KR |
2269 | SKIP_WHITESPACE (); |
2270 | if (*input_line_pointer != ',') | |
2271 | { | |
2272 | as_bad ("Expected comma after name"); | |
2273 | ignore_rest_of_line (); | |
2274 | return; | |
2275 | } | |
2276 | if (*input_line_pointer == '\n') | |
2277 | { | |
2278 | as_bad ("Missing size expression"); | |
2279 | return; | |
2280 | } | |
b066f445 | 2281 | input_line_pointer++; |
355afbcd KR |
2282 | if ((temp = get_absolute_expression ()) < 0) |
2283 | { | |
2284 | as_warn ("lcomm length (%d.) <0! Ignored.", temp); | |
2285 | ignore_rest_of_line (); | |
2286 | return; | |
2287 | } | |
b066f445 | 2288 | *p = 0; |
c593cf41 | 2289 | |
9a75dc1f ILT |
2290 | symbolP = symbol_find_or_make(name); |
2291 | ||
2292 | if (S_GET_SEGMENT(symbolP) == SEG_UNKNOWN && | |
2293 | S_GET_VALUE(symbolP) == 0) | |
2294 | { | |
2295 | if (! need_pass_2) | |
2296 | { | |
2297 | char *p; | |
2298 | segT current_seg = now_seg; /* save current seg */ | |
2299 | subsegT current_subseg = now_subseg; | |
2300 | ||
2301 | subseg_new (SEG_E2, 1); | |
2302 | symbolP->sy_frag = frag_now; | |
2303 | p = frag_var(rs_org, 1, 1, (relax_substateT)0, symbolP, | |
2304 | temp, (char *)0); | |
2305 | *p = 0; | |
2306 | subseg_new (current_seg, current_subseg); /* restore current seg */ | |
2307 | S_SET_SEGMENT(symbolP, SEG_E2); | |
2308 | S_SET_STORAGE_CLASS(symbolP, C_STAT); | |
2309 | } | |
2310 | } | |
2311 | else | |
2312 | as_bad("Symbol %s already defined", name); | |
2313 | ||
2314 | demand_empty_rest_of_line(); | |
db40ba14 SC |
2315 | } |
2316 | ||
355afbcd | 2317 | static void |
9a75dc1f ILT |
2318 | DEFUN (fixup_mdeps, (frags, h, this_segment), |
2319 | fragS * frags AND | |
2320 | object_headers * h AND | |
2321 | segT this_segment) | |
3ad9ec6a | 2322 | { |
9a75dc1f | 2323 | subseg_change (this_segment, 0); |
355afbcd | 2324 | while (frags) |
3ad9ec6a | 2325 | { |
355afbcd KR |
2326 | switch (frags->fr_type) |
2327 | { | |
2328 | case rs_align: | |
2329 | case rs_org: | |
2330 | frags->fr_type = rs_fill; | |
2331 | frags->fr_offset = | |
2332 | (frags->fr_next->fr_address - frags->fr_address - frags->fr_fix); | |
2333 | break; | |
2334 | case rs_machine_dependent: | |
9a75dc1f ILT |
2335 | md_convert_frag (h, frags); |
2336 | frag_wane (frags); | |
355afbcd KR |
2337 | break; |
2338 | default: | |
2339 | ; | |
2340 | } | |
2341 | frags = frags->fr_next; | |
3ad9ec6a | 2342 | } |
3ad9ec6a | 2343 | } |
355afbcd | 2344 | |
db40ba14 | 2345 | #if 1 |
355afbcd | 2346 | static void |
2cb0bdc7 | 2347 | DEFUN (fixup_segment, (segP, this_segment_type), |
016e0d42 | 2348 | segment_info_type * segP AND |
355afbcd | 2349 | segT this_segment_type) |
db40ba14 | 2350 | { |
016e0d42 | 2351 | register fixS * fixP; |
355afbcd KR |
2352 | register symbolS *add_symbolP; |
2353 | register symbolS *sub_symbolP; | |
2354 | register long add_number; | |
2355 | register int size; | |
2356 | register char *place; | |
2357 | register long where; | |
2358 | register char pcrel; | |
2359 | register fragS *fragP; | |
2360 | register segT add_symbol_segment = SEG_ABSOLUTE; | |
2361 | ||
2362 | ||
016e0d42 | 2363 | for (fixP = segP->fix_root; fixP; fixP = fixP->fx_next) |
355afbcd KR |
2364 | { |
2365 | fragP = fixP->fx_frag; | |
2366 | know (fragP); | |
2367 | where = fixP->fx_where; | |
2368 | place = fragP->fr_literal + where; | |
2369 | size = fixP->fx_size; | |
2370 | add_symbolP = fixP->fx_addsy; | |
db40ba14 | 2371 | #ifdef TC_I960 |
355afbcd KR |
2372 | if (fixP->fx_callj && TC_S_IS_CALLNAME (add_symbolP)) |
2373 | { | |
2374 | /* Relocation should be done via the | |
c593cf41 SC |
2375 | associated 'bal' entry point |
2376 | symbol. */ | |
2377 | ||
355afbcd KR |
2378 | if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP))) |
2379 | { | |
2380 | as_bad ("No 'bal' entry point for leafproc %s", | |
2381 | S_GET_NAME (add_symbolP)); | |
2382 | continue; | |
2383 | } | |
2384 | fixP->fx_addsy = add_symbolP = tc_get_bal_of_call (add_symbolP); | |
2385 | } /* callj relocation */ | |
db40ba14 | 2386 | #endif |
355afbcd KR |
2387 | sub_symbolP = fixP->fx_subsy; |
2388 | add_number = fixP->fx_offset; | |
2389 | pcrel = fixP->fx_pcrel; | |
2390 | ||
2391 | if (add_symbolP) | |
2392 | { | |
2393 | add_symbol_segment = S_GET_SEGMENT (add_symbolP); | |
2394 | } /* if there is an addend */ | |
2395 | ||
2396 | if (sub_symbolP) | |
2397 | { | |
2398 | if (!add_symbolP) | |
2399 | { | |
2400 | /* Its just -sym */ | |
2401 | if (S_GET_SEGMENT (sub_symbolP) != SEG_ABSOLUTE) | |
2402 | { | |
2403 | as_bad ("Negative of non-absolute symbol %s", S_GET_NAME (sub_symbolP)); | |
2404 | } /* not absolute */ | |
2405 | ||
2406 | add_number -= S_GET_VALUE (sub_symbolP); | |
2407 | fixP->fx_subsy = 0; | |
2408 | ||
2409 | /* if sub_symbol is in the same segment that add_symbol | |
c593cf41 | 2410 | and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */ |
355afbcd KR |
2411 | } |
2412 | else if ((S_GET_SEGMENT (sub_symbolP) == add_symbol_segment) | |
2413 | && (SEG_NORMAL (add_symbol_segment) | |
2414 | || (add_symbol_segment == SEG_ABSOLUTE))) | |
2415 | { | |
2416 | /* Difference of 2 symbols from same segment. */ | |
2417 | /* Can't make difference of 2 undefineds: 'value' means */ | |
2418 | /* something different for N_UNDF. */ | |
db40ba14 | 2419 | #ifdef TC_I960 |
355afbcd | 2420 | /* Makes no sense to use the difference of 2 arbitrary symbols |
eeeaa778 | 2421 | as the target of a call instruction. */ |
355afbcd KR |
2422 | if (fixP->fx_callj) |
2423 | { | |
2424 | as_bad ("callj to difference of 2 symbols"); | |
2425 | } | |
2426 | #endif /* TC_I960 */ | |
2427 | add_number += S_GET_VALUE (add_symbolP) - | |
2428 | S_GET_VALUE (sub_symbolP); | |
2429 | ||
2430 | add_symbolP = NULL; | |
2431 | fixP->fx_addsy = NULL; | |
2432 | } | |
2433 | else | |
2434 | { | |
2435 | /* Different segments in subtraction. */ | |
2436 | know (!(S_IS_EXTERNAL (sub_symbolP) && (S_GET_SEGMENT (sub_symbolP) == SEG_ABSOLUTE))); | |
2437 | ||
2438 | if ((S_GET_SEGMENT (sub_symbolP) == SEG_ABSOLUTE)) | |
2439 | { | |
2440 | add_number -= S_GET_VALUE (sub_symbolP); | |
2441 | } | |
2442 | else | |
2443 | { | |
2444 | as_bad ("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %d.", | |
2445 | segment_name (S_GET_SEGMENT (sub_symbolP)), | |
2446 | S_GET_NAME (sub_symbolP), fragP->fr_address + where); | |
2447 | } /* if absolute */ | |
2448 | } | |
2449 | } /* if sub_symbolP */ | |
2450 | ||
2451 | if (add_symbolP) | |
2452 | { | |
2453 | if (add_symbol_segment == this_segment_type && pcrel) | |
2454 | { | |
2455 | /* | |
eeeaa778 KR |
2456 | * This fixup was made when the symbol's segment was |
2457 | * SEG_UNKNOWN, but it is now in the local segment. | |
2458 | * So we know how to do the address without relocation. | |
2459 | */ | |
db40ba14 | 2460 | #ifdef TC_I960 |
355afbcd | 2461 | /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal', |
eeeaa778 KR |
2462 | * in which cases it modifies *fixP as appropriate. In the case |
2463 | * of a 'calls', no further work is required, and *fixP has been | |
2464 | * set up to make the rest of the code below a no-op. | |
2465 | */ | |
355afbcd KR |
2466 | reloc_callj (fixP); |
2467 | #endif /* TC_I960 */ | |
2468 | ||
2469 | add_number += S_GET_VALUE (add_symbolP); | |
2470 | add_number -= md_pcrel_from (fixP); | |
016e0d42 ILT |
2471 | #ifdef TC_I386 |
2472 | /* On the 386 we must adjust by the segment | |
2473 | vaddr as well. Ian Taylor. */ | |
2474 | add_number -= segP->scnhdr.s_vaddr; | |
2475 | #endif | |
355afbcd KR |
2476 | pcrel = 0; /* Lie. Don't want further pcrel processing. */ |
2477 | fixP->fx_addsy = NULL; /* No relocations please. */ | |
2478 | } | |
2479 | else | |
2480 | { | |
2481 | switch (add_symbol_segment) | |
2482 | { | |
2483 | case SEG_ABSOLUTE: | |
db40ba14 | 2484 | #ifdef TC_I960 |
355afbcd KR |
2485 | reloc_callj (fixP); /* See comment about reloc_callj() above*/ |
2486 | #endif /* TC_I960 */ | |
2487 | add_number += S_GET_VALUE (add_symbolP); | |
2488 | fixP->fx_addsy = NULL; | |
2489 | add_symbolP = NULL; | |
2490 | break; | |
2491 | default: | |
2492 | ||
61001d96 ILT |
2493 | #ifdef TC_A29K |
2494 | /* This really should be handled in the linker, but | |
2495 | backward compatibility forbids. */ | |
2496 | add_number += S_GET_VALUE (add_symbolP); | |
2497 | #else | |
355afbcd KR |
2498 | add_number += S_GET_VALUE (add_symbolP) + |
2499 | segment_info[S_GET_SEGMENT (add_symbolP)].scnhdr.s_paddr; | |
61001d96 | 2500 | #endif |
355afbcd KR |
2501 | break; |
2502 | ||
2503 | case SEG_UNKNOWN: | |
db40ba14 | 2504 | #ifdef TC_I960 |
355afbcd KR |
2505 | if ((int) fixP->fx_bit_fixP == 13) |
2506 | { | |
2507 | /* This is a COBR instruction. They have only a | |
eeeaa778 KR |
2508 | * 13-bit displacement and are only to be used |
2509 | * for local branches: flag as error, don't generate | |
2510 | * relocation. | |
2511 | */ | |
355afbcd KR |
2512 | as_bad ("can't use COBR format with external label"); |
2513 | fixP->fx_addsy = NULL; /* No relocations please. */ | |
2514 | continue; | |
2515 | } /* COBR */ | |
2516 | #endif /* TC_I960 */ | |
6142210d | 2517 | #ifdef TC_I386 |
355afbcd | 2518 | /* 386 COFF uses a peculiar format in |
016e0d42 ILT |
2519 | which the value of a common symbol is |
2520 | stored in the .text segment (I've | |
2521 | checked this on SVR3.2 and SCO 3.2.2) | |
2522 | Ian Taylor <[email protected]>. */ | |
9a75dc1f ILT |
2523 | if (S_IS_COMMON (add_symbolP)) |
2524 | add_number += S_GET_VALUE (add_symbolP); | |
6142210d | 2525 | #endif |
355afbcd KR |
2526 | break; |
2527 | ||
2528 | ||
2529 | } /* switch on symbol seg */ | |
2530 | } /* if not in local seg */ | |
2531 | } /* if there was a + symbol */ | |
2532 | ||
2533 | if (pcrel) | |
2534 | { | |
2535 | add_number -= md_pcrel_from (fixP); | |
2536 | if (add_symbolP == 0) | |
2537 | { | |
2538 | fixP->fx_addsy = &abs_symbol; | |
2539 | } /* if there's an add_symbol */ | |
016e0d42 ILT |
2540 | #ifdef TC_I386 |
2541 | /* On the 386 we must adjust by the segment vaddr | |
2542 | as well. Ian Taylor. */ | |
2543 | add_number -= segP->scnhdr.s_vaddr; | |
2544 | #endif | |
355afbcd KR |
2545 | } /* if pcrel */ |
2546 | ||
2547 | if (!fixP->fx_bit_fixP) | |
2548 | { | |
2549 | if ((size == 1 && | |
2550 | (add_number & ~0xFF) && ((add_number & ~0xFF) != (-1 & ~0xFF))) || | |
2551 | (size == 2 && | |
2552 | (add_number & ~0xFFFF) && ((add_number & ~0xFFFF) != (-1 & ~0xFFFF)))) | |
2553 | { | |
2554 | as_bad ("Value of %d too large for field of %d bytes at 0x%x", | |
2555 | add_number, size, fragP->fr_address + where); | |
2556 | } /* generic error checking */ | |
e41474b7 | 2557 | #ifdef WARN_SIGNED_OVERFLOW_WORD |
355afbcd | 2558 | /* Warn if a .word value is too large when treated as |
eeeaa778 KR |
2559 | a signed number. We already know it is not too |
2560 | negative. This is to catch over-large switches | |
2561 | generated by gcc on the 68k. */ | |
355afbcd KR |
2562 | if (!flagseen['J'] |
2563 | && size == 2 | |
2564 | && add_number > 0x7fff) | |
2565 | as_bad ("Signed .word overflow; switch may be too large; %d at 0x%x", | |
2566 | add_number, fragP->fr_address + where); | |
e41474b7 | 2567 | #endif |
355afbcd KR |
2568 | } /* not a bit fix */ |
2569 | /* once this fix has been applied, we don't have to output anything | |
c593cf41 | 2570 | nothing more need be done -*/ |
355afbcd | 2571 | md_apply_fix (fixP, add_number); |
355afbcd | 2572 | } /* For each fixS in this segment. */ |
355afbcd | 2573 | } /* fixup_segment() */ |
c593cf41 | 2574 | |
355afbcd | 2575 | #endif |