* symbols.c (resolve_symbol_value): Don't change X_add_number for
[binutils-gdb.git] / gas / write.c
1 /* write.c - emit .o file
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 /* This thing should be set up to do byteordering correctly. But... */
23
24 #include "as.h"
25 #include "subsegs.h"
26 #include "obstack.h"
27 #include "output-file.h"
28
29 /* This looks like a good idea. Let's try turning it on always, for now. */
30 #undef BFD_FAST_SECTION_FILL
31 #define BFD_FAST_SECTION_FILL
32
33 /* The NOP_OPCODE is for the alignment fill value. Fill it with a nop
34 instruction so that the disassembler does not choke on it. */
35 #ifndef NOP_OPCODE
36 #define NOP_OPCODE 0x00
37 #endif
38
39 #ifndef TC_ADJUST_RELOC_COUNT
40 #define TC_ADJUST_RELOC_COUNT(FIXP,COUNT)
41 #endif
42
43 #ifndef TC_FORCE_RELOCATION
44 #define TC_FORCE_RELOCATION(FIXP) 0
45 #endif
46
47 #ifndef TC_FORCE_RELOCATION_SECTION
48 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP)
49 #endif
50
51 #ifndef MD_PCREL_FROM_SECTION
52 #define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from(FIXP)
53 #endif
54
55 #ifndef WORKING_DOT_WORD
56 extern CONST int md_short_jump_size;
57 extern CONST int md_long_jump_size;
58 #endif
59
60 int symbol_table_frozen;
61 void print_fixup PARAMS ((fixS *));
62
63 #ifdef BFD_ASSEMBLER
64 static void renumber_sections PARAMS ((bfd *, asection *, PTR));
65
66 /* We generally attach relocs to frag chains. However, after we have
67 chained these all together into a segment, any relocs we add after
68 that must be attached to a segment. This will include relocs added
69 in md_estimate_size_for_relax, for example. */
70 static int frags_chained = 0;
71 #endif
72
73 #ifndef BFD_ASSEMBLER
74
75 #ifndef MANY_SEGMENTS
76 struct frag *text_frag_root;
77 struct frag *data_frag_root;
78 struct frag *bss_frag_root;
79
80 struct frag *text_last_frag; /* Last frag in segment. */
81 struct frag *data_last_frag; /* Last frag in segment. */
82 static struct frag *bss_last_frag; /* Last frag in segment. */
83 #endif
84
85 #ifndef BFD
86 static object_headers headers;
87 #endif
88
89 long string_byte_count;
90 char *next_object_file_charP; /* Tracks object file bytes. */
91
92 #ifndef OBJ_VMS
93 int magic_number_for_object_file = DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE;
94 #endif
95
96 #endif /* BFD_ASSEMBLER */
97
98 static int n_fixups;
99
100 #ifdef BFD_ASSEMBLER
101 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size,
102 symbolS *add, symbolS *sub,
103 offsetT offset, int pcrel,
104 bfd_reloc_code_real_type r_type));
105 #else
106 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size,
107 symbolS *add, symbolS *sub,
108 offsetT offset, int pcrel,
109 int r_type));
110 #endif
111 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
112 static long fixup_segment PARAMS ((fixS * fixP, segT this_segment_type));
113 #endif
114 static relax_addressT relax_align PARAMS ((relax_addressT addr, int align));
115
116 /*
117 * fix_new()
118 *
119 * Create a fixS in obstack 'notes'.
120 */
121 static fixS *
122 fix_new_internal (frag, where, size, add_symbol, sub_symbol, offset, pcrel,
123 r_type)
124 fragS *frag; /* Which frag? */
125 int where; /* Where in that frag? */
126 int size; /* 1, 2, or 4 usually. */
127 symbolS *add_symbol; /* X_add_symbol. */
128 symbolS *sub_symbol; /* X_op_symbol. */
129 offsetT offset; /* X_add_number. */
130 int pcrel; /* TRUE if PC-relative relocation. */
131 #ifdef BFD_ASSEMBLER
132 bfd_reloc_code_real_type r_type; /* Relocation type */
133 #else
134 int r_type; /* Relocation type */
135 #endif
136 {
137 fixS *fixP;
138
139 n_fixups++;
140
141 fixP = (fixS *) obstack_alloc (&notes, sizeof (fixS));
142
143 fixP->fx_frag = frag;
144 fixP->fx_where = where;
145 fixP->fx_size = size;
146 /* We've made fx_size a narrow field; check that it's wide enough. */
147 if (fixP->fx_size != size)
148 {
149 as_bad ("field fx_size too small to hold %d", size);
150 abort ();
151 }
152 fixP->fx_addsy = add_symbol;
153 fixP->fx_subsy = sub_symbol;
154 fixP->fx_offset = offset;
155 fixP->fx_pcrel = pcrel;
156 fixP->fx_plt = 0;
157 #if defined(NEED_FX_R_TYPE) || defined (BFD_ASSEMBLER)
158 fixP->fx_r_type = r_type;
159 #endif
160 fixP->fx_im_disp = 0;
161 fixP->fx_pcrel_adjust = 0;
162 fixP->fx_bit_fixP = 0;
163 fixP->fx_addnumber = 0;
164 fixP->fx_tcbit = 0;
165 fixP->fx_done = 0;
166 fixP->fx_no_overflow = 0;
167 fixP->fx_signed = 0;
168
169 #ifdef TC_FIX_TYPE
170 TC_INIT_FIX_DATA(fixP);
171 #endif
172
173 as_where (&fixP->fx_file, &fixP->fx_line);
174
175 /* Usually, we want relocs sorted numerically, but while
176 comparing to older versions of gas that have relocs
177 reverse sorted, it is convenient to have this compile
178 time option. xoxorich. */
179
180 {
181
182 #ifdef BFD_ASSEMBLER
183 fixS **seg_fix_rootP = (frags_chained
184 ? &seg_info (now_seg)->fix_root
185 : &frchain_now->fix_root);
186 fixS **seg_fix_tailP = (frags_chained
187 ? &seg_info (now_seg)->fix_tail
188 : &frchain_now->fix_tail);
189 #endif
190
191 #ifdef REVERSE_SORT_RELOCS
192
193 fixP->fx_next = *seg_fix_rootP;
194 *seg_fix_rootP = fixP;
195
196 #else /* REVERSE_SORT_RELOCS */
197
198 fixP->fx_next = NULL;
199
200 if (*seg_fix_tailP)
201 (*seg_fix_tailP)->fx_next = fixP;
202 else
203 *seg_fix_rootP = fixP;
204 *seg_fix_tailP = fixP;
205
206 #endif /* REVERSE_SORT_RELOCS */
207
208 }
209
210 return fixP;
211 }
212
213 /* Create a fixup relative to a symbol (plus a constant). */
214
215 fixS *
216 fix_new (frag, where, size, add_symbol, offset, pcrel, r_type)
217 fragS *frag; /* Which frag? */
218 int where; /* Where in that frag? */
219 int size; /* 1, 2, or 4 usually. */
220 symbolS *add_symbol; /* X_add_symbol. */
221 offsetT offset; /* X_add_number. */
222 int pcrel; /* TRUE if PC-relative relocation. */
223 #ifdef BFD_ASSEMBLER
224 bfd_reloc_code_real_type r_type; /* Relocation type */
225 #else
226 int r_type; /* Relocation type */
227 #endif
228 {
229 return fix_new_internal (frag, where, size, add_symbol,
230 (symbolS *) NULL, offset, pcrel, r_type);
231 }
232
233 /* Create a fixup for an expression. Currently we only support fixups
234 for difference expressions. That is itself more than most object
235 file formats support anyhow. */
236
237 fixS *
238 fix_new_exp (frag, where, size, exp, pcrel, r_type)
239 fragS *frag; /* Which frag? */
240 int where; /* Where in that frag? */
241 int size; /* 1, 2, or 4 usually. */
242 expressionS *exp; /* Expression. */
243 int pcrel; /* TRUE if PC-relative relocation. */
244 #ifdef BFD_ASSEMBLER
245 bfd_reloc_code_real_type r_type; /* Relocation type */
246 #else
247 int r_type; /* Relocation type */
248 #endif
249 {
250 symbolS *add = NULL;
251 symbolS *sub = NULL;
252 offsetT off = 0;
253
254 switch (exp->X_op)
255 {
256 case O_absent:
257 break;
258
259 case O_add:
260 /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
261 the difference expression cannot immediately be reduced. */
262 {
263 extern symbolS *make_expr_symbol ();
264 symbolS *stmp = make_expr_symbol (exp);
265 exp->X_op = O_symbol;
266 exp->X_op_symbol = 0;
267 exp->X_add_symbol = stmp;
268 exp->X_add_number = 0;
269 return fix_new_exp (frag, where, size, exp, pcrel, r_type);
270 }
271
272 case O_symbol_rva:
273 add = exp->X_add_symbol;
274 off = exp->X_add_number;
275
276 #if defined(BFD_ASSEMBLER)
277 r_type = BFD_RELOC_RVA;
278 #else
279 #if defined(TC_RVA_RELOC)
280 r_type = TC_RVA_RELOC;
281 #else
282 as_fatal("rva not supported");
283 #endif
284 #endif
285 break;
286
287 case O_uminus:
288 sub = exp->X_add_symbol;
289 off = exp->X_add_number;
290 break;
291
292 case O_subtract:
293 sub = exp->X_op_symbol;
294 /* Fall through. */
295 case O_symbol:
296 add = exp->X_add_symbol;
297 /* Fall through. */
298 case O_constant:
299 off = exp->X_add_number;
300 break;
301
302 default:
303 add = make_expr_symbol (exp);
304 break;
305 }
306
307 return fix_new_internal (frag, where, size, add, sub, off,
308 pcrel, r_type);
309 }
310
311 /* Append a string onto another string, bumping the pointer along. */
312 void
313 append (charPP, fromP, length)
314 char **charPP;
315 char *fromP;
316 unsigned long length;
317 {
318 /* Don't trust memcpy() of 0 chars. */
319 if (length == 0)
320 return;
321
322 memcpy (*charPP, fromP, length);
323 *charPP += length;
324 }
325
326 #ifndef BFD_ASSEMBLER
327 int section_alignment[SEG_MAXIMUM_ORDINAL];
328 #endif
329
330 /*
331 * This routine records the largest alignment seen for each segment.
332 * If the beginning of the segment is aligned on the worst-case
333 * boundary, all of the other alignments within it will work. At
334 * least one object format really uses this info.
335 */
336 void
337 record_alignment (seg, align)
338 /* Segment to which alignment pertains */
339 segT seg;
340 /* Alignment, as a power of 2 (e.g., 1 => 2-byte boundary, 2 => 4-byte
341 boundary, etc.) */
342 int align;
343 {
344 if (seg == absolute_section)
345 return;
346 #ifdef BFD_ASSEMBLER
347 if (align > bfd_get_section_alignment (stdoutput, seg))
348 bfd_set_section_alignment (stdoutput, seg, align);
349 #else
350 if (align > section_alignment[(int) seg])
351 section_alignment[(int) seg] = align;
352 #endif
353 }
354
355 #ifdef BFD_ASSEMBLER
356
357 /* Reset the section indices after removing the gas created sections. */
358
359 static void
360 renumber_sections (abfd, sec, countparg)
361 bfd *abfd;
362 asection *sec;
363 PTR countparg;
364 {
365 int *countp = (int *) countparg;
366
367 sec->index = *countp;
368 ++*countp;
369 }
370
371 #endif /* defined (BFD_ASSEMBLER) */
372
373 #if defined (BFD_ASSEMBLER) || ! defined (BFD)
374
375 static fragS *
376 chain_frchains_together_1 (section, frchp)
377 segT section;
378 struct frchain *frchp;
379 {
380 fragS dummy, *prev_frag = &dummy;
381 #ifdef BFD_ASSEMBLER
382 fixS fix_dummy, *prev_fix = &fix_dummy;
383 #endif
384
385 for (; frchp && frchp->frch_seg == section; frchp = frchp->frch_next)
386 {
387 prev_frag->fr_next = frchp->frch_root;
388 prev_frag = frchp->frch_last;
389 assert (prev_frag->fr_type != 0);
390 #ifdef BFD_ASSEMBLER
391 if (frchp->fix_root != (fixS *) NULL)
392 {
393 if (seg_info (section)->fix_root == (fixS *) NULL)
394 seg_info (section)->fix_root = frchp->fix_root;
395 prev_fix->fx_next = frchp->fix_root;
396 seg_info (section)->fix_tail = frchp->fix_tail;
397 prev_fix = frchp->fix_tail;
398 }
399 #endif
400 }
401 assert (prev_frag->fr_type != 0);
402 prev_frag->fr_next = 0;
403 return prev_frag;
404 }
405
406 #endif
407
408 #ifdef BFD_ASSEMBLER
409
410 static void
411 chain_frchains_together (abfd, section, xxx)
412 bfd *abfd; /* unused */
413 segT section;
414 PTR xxx; /* unused */
415 {
416 segment_info_type *info;
417
418 /* BFD may have introduced its own sections without using
419 subseg_new, so it is possible that seg_info is NULL. */
420 info = seg_info (section);
421 if (info != (segment_info_type *) NULL)
422 info->frchainP->frch_last
423 = chain_frchains_together_1 (section, info->frchainP);
424
425 /* Now that we've chained the frags together, we must add new fixups
426 to the segment, not to the frag chain. */
427 frags_chained = 1;
428 }
429
430 #endif
431
432 #if !defined (BFD) && !defined (BFD_ASSEMBLER)
433
434 void
435 remove_subsegs (head, seg, root, last)
436 frchainS *head;
437 int seg;
438 fragS **root;
439 fragS **last;
440 {
441 *root = head->frch_root;
442 *last = chain_frchains_together_1 (seg, head);
443 }
444
445 #endif /* BFD */
446
447 #if defined (BFD_ASSEMBLER) || !defined (BFD)
448
449 #ifdef BFD_ASSEMBLER
450 static void
451 cvt_frag_to_fill (sec, fragP)
452 segT sec;
453 fragS *fragP;
454 #else
455 static void
456 cvt_frag_to_fill (headersP, sec, fragP)
457 object_headers *headersP;
458 segT sec;
459 fragS *fragP;
460 #endif
461 {
462 switch (fragP->fr_type)
463 {
464 case rs_align:
465 case rs_align_code:
466 case rs_org:
467 case rs_space:
468 #ifdef HANDLE_ALIGN
469 HANDLE_ALIGN (fragP);
470 #endif
471 know (fragP->fr_next != NULL);
472 fragP->fr_offset = (fragP->fr_next->fr_address
473 - fragP->fr_address
474 - fragP->fr_fix) / fragP->fr_var;
475 if (fragP->fr_offset < 0)
476 {
477 as_bad ("attempt to .org/.space backwards? (%ld)",
478 (long) fragP->fr_offset);
479 }
480 fragP->fr_type = rs_fill;
481 break;
482
483 case rs_fill:
484 break;
485
486 case rs_machine_dependent:
487 #ifdef BFD_ASSEMBLER
488 md_convert_frag (stdoutput, sec, fragP);
489 #else
490 md_convert_frag (headersP, sec, fragP);
491 #endif
492
493 assert (fragP->fr_next == NULL || (fragP->fr_next->fr_address - fragP->fr_address == fragP->fr_fix));
494
495 /*
496 * After md_convert_frag, we make the frag into a ".space 0".
497 * Md_convert_frag() should set up any fixSs and constants
498 * required.
499 */
500 frag_wane (fragP);
501 break;
502
503 #ifndef WORKING_DOT_WORD
504 case rs_broken_word:
505 {
506 struct broken_word *lie;
507
508 if (fragP->fr_subtype)
509 {
510 fragP->fr_fix += md_short_jump_size;
511 for (lie = (struct broken_word *) (fragP->fr_symbol);
512 lie && lie->dispfrag == fragP;
513 lie = lie->next_broken_word)
514 if (lie->added == 1)
515 fragP->fr_fix += md_long_jump_size;
516 }
517 frag_wane (fragP);
518 }
519 break;
520 #endif
521
522 default:
523 BAD_CASE (fragP->fr_type);
524 break;
525 }
526 }
527
528 #endif /* defined (BFD_ASSEMBLER) || !defined (BFD) */
529
530 #ifdef BFD_ASSEMBLER
531 static void
532 relax_and_size_seg (abfd, sec, xxx)
533 bfd *abfd;
534 asection *sec;
535 PTR xxx;
536 {
537 flagword flags;
538 fragS *fragp;
539 segment_info_type *seginfo;
540 int x;
541 valueT size, newsize;
542
543 subseg_change (sec, 0);
544
545 flags = bfd_get_section_flags (abfd, sec);
546
547 seginfo = seg_info (sec);
548 if (seginfo && seginfo->frchainP)
549 {
550 relax_segment (seginfo->frchainP->frch_root, sec);
551 for (fragp = seginfo->frchainP->frch_root; fragp; fragp = fragp->fr_next)
552 cvt_frag_to_fill (sec, fragp);
553 for (fragp = seginfo->frchainP->frch_root;
554 fragp->fr_next;
555 fragp = fragp->fr_next)
556 /* walk to last elt */;
557 size = fragp->fr_address + fragp->fr_fix;
558 }
559 else
560 size = 0;
561
562 if (size > 0 && ! seginfo->bss)
563 flags |= SEC_HAS_CONTENTS;
564
565 /* @@ This is just an approximation. */
566 if (seginfo && seginfo->fix_root)
567 flags |= SEC_RELOC;
568 else
569 flags &= ~SEC_RELOC;
570 x = bfd_set_section_flags (abfd, sec, flags);
571 assert (x == true);
572
573 newsize = md_section_align (sec, size);
574 x = bfd_set_section_size (abfd, sec, newsize);
575 assert (x == true);
576
577 /* If the size had to be rounded up, add some padding in the last
578 non-empty frag. */
579 assert (newsize >= size);
580 if (size != newsize)
581 {
582 fragS *last = seginfo->frchainP->frch_last;
583 fragp = seginfo->frchainP->frch_root;
584 while (fragp->fr_next != last)
585 fragp = fragp->fr_next;
586 last->fr_address = size;
587 fragp->fr_offset += newsize - size;
588 }
589
590 #ifdef tc_frob_section
591 tc_frob_section (sec);
592 #endif
593 #ifdef obj_frob_section
594 obj_frob_section (sec);
595 #endif
596 }
597
598 #ifdef DEBUG2
599 static void
600 dump_section_relocs (abfd, sec, stream_)
601 bfd *abfd;
602 asection *sec;
603 char *stream_;
604 {
605 FILE *stream = (FILE *) stream_;
606 segment_info_type *seginfo = seg_info (sec);
607 fixS *fixp = seginfo->fix_root;
608
609 if (!fixp)
610 return;
611
612 fprintf (stream, "sec %s relocs:\n", sec->name);
613 while (fixp)
614 {
615 symbolS *s = fixp->fx_addsy;
616 if (s)
617 {
618 fprintf (stream, " %08x: %s(%s", fixp, S_GET_NAME (s),
619 s->bsym->section->name);
620 if (s->bsym->flags & BSF_SECTION_SYM)
621 {
622 fprintf (stream, " section sym");
623 if (S_GET_VALUE (s))
624 fprintf (stream, "+%x", S_GET_VALUE (s));
625 }
626 else
627 fprintf (stream, "+%x", S_GET_VALUE (s));
628 fprintf (stream, ")+%x\n", fixp->fx_offset);
629 }
630 else
631 fprintf (stream, " %08x: type %d no sym\n", fixp, fixp->fx_r_type);
632 fixp = fixp->fx_next;
633 }
634 }
635 #else
636 #define dump_section_relocs(ABFD,SEC,STREAM) ((void) 0)
637 #endif
638
639 #ifndef EMIT_SECTION_SYMBOLS
640 #define EMIT_SECTION_SYMBOLS 1
641 #endif
642
643 static void
644 adjust_reloc_syms (abfd, sec, xxx)
645 bfd *abfd;
646 asection *sec;
647 PTR xxx;
648 {
649 segment_info_type *seginfo = seg_info (sec);
650 fixS *fixp;
651
652 if (seginfo == NULL)
653 return;
654
655 dump_section_relocs (abfd, sec, stderr);
656
657 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
658 if (fixp->fx_done)
659 /* ignore it */;
660 else if (fixp->fx_addsy)
661 {
662 symbolS *sym;
663 asection *symsec;
664
665 reduce_fixup:
666
667 #ifdef DEBUG5
668 fprintf (stderr, "\n\nadjusting fixup:\n");
669 print_fixup (fixp);
670 #endif
671
672 sym = fixp->fx_addsy;
673
674 /* All symbols should have already been resolved at this
675 point. It is possible to see unresolved expression
676 symbols, though, since they are not in the regular symbol
677 table. */
678 if (sym != NULL && ! sym->sy_resolved)
679 resolve_symbol_value (sym);
680 if (fixp->fx_subsy != NULL && ! fixp->fx_subsy->sy_resolved)
681 resolve_symbol_value (fixp->fx_subsy);
682
683 /* If this symbol is equated to an undefined symbol, convert
684 the fixup to being against that symbol. */
685 if (sym->sy_value.X_op == O_symbol
686 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
687 {
688 fixp->fx_offset += sym->sy_value.X_add_number;
689 sym = sym->sy_value.X_add_symbol;
690 fixp->fx_addsy = sym;
691 }
692
693 symsec = S_GET_SEGMENT (sym);
694
695 if (sym != NULL && sym->sy_mri_common)
696 {
697 /* These symbols are handled specially in fixup_segment. */
698 goto done;
699 }
700
701 if (bfd_is_abs_section (symsec))
702 {
703 /* The fixup_segment routine will not use this symbol in a
704 relocation unless TC_FORCE_RELOCATION returns 1. */
705 if (TC_FORCE_RELOCATION (fixp))
706 {
707 fixp->fx_addsy->sy_used_in_reloc = 1;
708 #ifdef UNDEFINED_DIFFERENCE_OK
709 if (fixp->fx_subsy != NULL)
710 fixp->fx_subsy->sy_used_in_reloc = 1;
711 #endif
712 }
713 goto done;
714 }
715
716 /* If it's one of these sections, assume the symbol is
717 definitely going to be output. The code in
718 md_estimate_size_before_relax in tc-mips.c uses this test
719 as well, so if you change this code you should look at that
720 code. */
721 if (bfd_is_und_section (symsec)
722 || bfd_is_com_section (symsec))
723 {
724 fixp->fx_addsy->sy_used_in_reloc = 1;
725 #ifdef UNDEFINED_DIFFERENCE_OK
726 /* We have the difference of an undefined symbol and some
727 other symbol. Make sure to mark the other symbol as used
728 in a relocation so that it will always be output. */
729 if (fixp->fx_subsy)
730 fixp->fx_subsy->sy_used_in_reloc = 1;
731 #endif
732 goto done;
733 }
734
735 /* Don't try to reduce relocs which refer to .linkonce
736 sections. It can lead to confusion when a debugging
737 section refers to a .linkonce section. I hope this will
738 always be correct. */
739 if (symsec != sec)
740 {
741 boolean linkonce;
742
743 linkonce = false;
744 #ifdef BFD_ASSEMBLER
745 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE)
746 != 0)
747 linkonce = true;
748 #endif
749 #ifdef OBJ_ELF
750 /* The GNU toolchain uses an extension for ELF: a section
751 beginning with the magic string .gnu.linkonce is a
752 linkonce section. */
753 if (strncmp (segment_name (symsec), ".gnu.linkonce",
754 sizeof ".gnu.linkonce" - 1) == 0)
755 linkonce = true;
756 #endif
757
758 if (linkonce)
759 {
760 fixp->fx_addsy->sy_used_in_reloc = 1;
761 #ifdef UNDEFINED_DIFFERENCE_OK
762 if (fixp->fx_subsy != NULL)
763 fixp->fx_subsy->sy_used_in_reloc = 1;
764 #endif
765 goto done;
766 }
767 }
768
769 /* Since we're reducing to section symbols, don't attempt to reduce
770 anything that's already using one. */
771 if (sym->bsym->flags & BSF_SECTION_SYM)
772 {
773 fixp->fx_addsy->sy_used_in_reloc = 1;
774 goto done;
775 }
776
777 /* Is there some other reason we can't adjust this one? (E.g.,
778 call/bal links in i960-bout symbols.) */
779 #ifdef obj_fix_adjustable
780 if (! obj_fix_adjustable (fixp))
781 {
782 fixp->fx_addsy->sy_used_in_reloc = 1;
783 goto done;
784 }
785 #endif
786
787 /* Is there some other (target cpu dependent) reason we can't adjust
788 this one? (E.g. relocations involving function addresses on
789 the PA. */
790 #ifdef tc_fix_adjustable
791 if (! tc_fix_adjustable (fixp))
792 {
793 fixp->fx_addsy->sy_used_in_reloc = 1;
794 goto done;
795 }
796 #endif
797
798 /* If the section symbol isn't going to be output, the relocs
799 at least should still work. If not, figure out what to do
800 when we run into that case.
801
802 We refetch the segment when calling section_symbol, rather
803 than using symsec, because S_GET_VALUE may wind up changing
804 the section when it calls resolve_symbol_value. */
805 fixp->fx_offset += S_GET_VALUE (sym);
806 fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym));
807 fixp->fx_addsy->sy_used_in_reloc = 1;
808
809 done:
810 ;
811 }
812 #if 1/*def RELOC_REQUIRES_SYMBOL*/
813 else
814 {
815 /* There was no symbol required by this relocation. However,
816 BFD doesn't really handle relocations without symbols well.
817 (At least, the COFF support doesn't.) So for now we fake up
818 a local symbol in the absolute section. */
819
820 fixp->fx_addsy = section_symbol (absolute_section);
821 /* fixp->fx_addsy->sy_used_in_reloc = 1; */
822 }
823 #endif
824
825 dump_section_relocs (abfd, sec, stderr);
826 }
827
828 static void
829 write_relocs (abfd, sec, xxx)
830 bfd *abfd;
831 asection *sec;
832 PTR xxx;
833 {
834 segment_info_type *seginfo = seg_info (sec);
835 int i;
836 unsigned int n;
837 arelent **relocs;
838 fixS *fixp;
839 char *err;
840
841 /* If seginfo is NULL, we did not create this section; don't do
842 anything with it. */
843 if (seginfo == NULL)
844 return;
845
846 fixup_segment (seginfo->fix_root, sec);
847
848 n = 0;
849 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
850 n++;
851
852 #ifndef RELOC_EXPANSION_POSSIBLE
853 /* Set up reloc information as well. */
854 relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
855 n * sizeof (arelent *));
856 memset ((char*)relocs, 0, n * sizeof (arelent*));
857
858 i = 0;
859 for (fixp = seginfo->fix_root; fixp != (fixS *) NULL; fixp = fixp->fx_next)
860 {
861 arelent *reloc;
862 bfd_reloc_status_type s;
863 symbolS *sym;
864
865 if (fixp->fx_done)
866 {
867 n--;
868 continue;
869 }
870
871 /* If this is an undefined symbol which was equated to another
872 symbol, then use generate the reloc against the latter symbol
873 rather than the former. */
874 sym = fixp->fx_addsy;
875 while (sym->sy_value.X_op == O_symbol
876 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
877 {
878 symbolS *n;
879
880 /* We must avoid looping, as that can occur with a badly
881 written program. */
882 n = sym->sy_value.X_add_symbol;
883 if (n == sym)
884 break;
885 fixp->fx_offset += sym->sy_value.X_add_number;
886 sym = n;
887 }
888 fixp->fx_addsy = sym;
889
890 reloc = tc_gen_reloc (sec, fixp);
891 if (!reloc)
892 {
893 n--;
894 continue;
895 }
896
897 #if 0
898 /* This test is triggered inappropriately for the SH. */
899 if (fixp->fx_where + fixp->fx_size
900 > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
901 abort ();
902 #endif
903
904 s = bfd_install_relocation (stdoutput, reloc,
905 fixp->fx_frag->fr_literal,
906 fixp->fx_frag->fr_address,
907 sec, &err);
908 switch (s)
909 {
910 case bfd_reloc_ok:
911 break;
912 case bfd_reloc_overflow:
913 as_bad_where (fixp->fx_file, fixp->fx_line, "relocation overflow");
914 break;
915 default:
916 as_fatal ("%s:%u: bad return from bfd_perform_relocation",
917 fixp->fx_file, fixp->fx_line);
918 }
919 relocs[i++] = reloc;
920 }
921 #else
922 n = n * MAX_RELOC_EXPANSION;
923 /* Set up reloc information as well. */
924 relocs = (arelent **) bfd_alloc_by_size_t (stdoutput,
925 n * sizeof (arelent *));
926
927 i = 0;
928 for (fixp = seginfo->fix_root; fixp != (fixS *) NULL; fixp = fixp->fx_next)
929 {
930 arelent **reloc;
931 char *data;
932 bfd_reloc_status_type s;
933 symbolS *sym;
934 int j;
935
936 if (fixp->fx_done)
937 {
938 n--;
939 continue;
940 }
941
942 /* If this is an undefined symbol which was equated to another
943 symbol, then use generate the reloc against the latter symbol
944 rather than the former. */
945 sym = fixp->fx_addsy;
946 while (sym->sy_value.X_op == O_symbol
947 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
948 sym = sym->sy_value.X_add_symbol;
949 fixp->fx_addsy = sym;
950
951 reloc = tc_gen_reloc (sec, fixp);
952
953 for (j = 0; reloc[j]; j++)
954 {
955 relocs[i++] = reloc[j];
956 assert(i <= n);
957 }
958 data = fixp->fx_frag->fr_literal + fixp->fx_where;
959 if (fixp->fx_where + fixp->fx_size
960 > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
961 as_bad_where (fixp->fx_file, fixp->fx_line,
962 "internal error: fixup not contained within frag");
963 for (j = 0; reloc[j]; j++)
964 {
965 s = bfd_install_relocation (stdoutput, reloc[j],
966 fixp->fx_frag->fr_literal,
967 fixp->fx_frag->fr_address,
968 sec, &err);
969 switch (s)
970 {
971 case bfd_reloc_ok:
972 break;
973 case bfd_reloc_overflow:
974 as_bad_where (fixp->fx_file, fixp->fx_line,
975 "relocation overflow");
976 break;
977 default:
978 as_fatal ("%s:%u: bad return from bfd_perform_relocation",
979 fixp->fx_file, fixp->fx_line);
980 }
981 }
982 }
983 n = i;
984 #endif
985
986 #ifdef DEBUG4
987 {
988 int i, j, nsyms;
989 asymbol **sympp;
990 sympp = bfd_get_outsymbols (stdoutput);
991 nsyms = bfd_get_symcount (stdoutput);
992 for (i = 0; i < n; i++)
993 if (((*relocs[i]->sym_ptr_ptr)->flags & BSF_SECTION_SYM) == 0)
994 {
995 for (j = 0; j < nsyms; j++)
996 if (sympp[j] == *relocs[i]->sym_ptr_ptr)
997 break;
998 if (j == nsyms)
999 abort ();
1000 }
1001 }
1002 #endif
1003
1004 if (n)
1005 bfd_set_reloc (stdoutput, sec, relocs, n);
1006 else
1007 bfd_set_section_flags (abfd, sec,
1008 (bfd_get_section_flags (abfd, sec)
1009 & (flagword) ~SEC_RELOC));
1010
1011 #ifdef DEBUG3
1012 {
1013 int i;
1014 arelent *r;
1015 asymbol *s;
1016 fprintf (stderr, "relocs for sec %s\n", sec->name);
1017 for (i = 0; i < n; i++)
1018 {
1019 r = relocs[i];
1020 s = *r->sym_ptr_ptr;
1021 fprintf (stderr, " reloc %2d @%08x off %4x : sym %-10s addend %x\n",
1022 i, r, r->address, s->name, r->addend);
1023 }
1024 }
1025 #endif
1026 }
1027
1028 static void
1029 write_contents (abfd, sec, xxx)
1030 bfd *abfd;
1031 asection *sec;
1032 PTR xxx;
1033 {
1034 segment_info_type *seginfo = seg_info (sec);
1035 unsigned long offset = 0;
1036 fragS *f;
1037
1038 /* Write out the frags. */
1039 if (seginfo == NULL
1040 || ! (bfd_get_section_flags (abfd, sec) & SEC_HAS_CONTENTS))
1041 return;
1042
1043 for (f = seginfo->frchainP->frch_root;
1044 f;
1045 f = f->fr_next)
1046 {
1047 int x;
1048 unsigned long fill_size;
1049 char *fill_literal;
1050 long count;
1051
1052 assert (f->fr_type == rs_fill);
1053 if (f->fr_fix)
1054 {
1055 x = bfd_set_section_contents (stdoutput, sec,
1056 f->fr_literal, (file_ptr) offset,
1057 (bfd_size_type) f->fr_fix);
1058 if (x == false)
1059 {
1060 bfd_perror (stdoutput->filename);
1061 as_perror ("FATAL: Can't write %s", stdoutput->filename);
1062 exit (EXIT_FAILURE);
1063 }
1064 offset += f->fr_fix;
1065 }
1066 fill_literal = f->fr_literal + f->fr_fix;
1067 fill_size = f->fr_var;
1068 count = f->fr_offset;
1069 assert (count >= 0);
1070 if (fill_size && count)
1071 {
1072 char buf[256];
1073 if (fill_size > sizeof(buf))
1074 {
1075 /* Do it the old way. Can this ever happen? */
1076 while (count--)
1077 {
1078 x = bfd_set_section_contents (stdoutput, sec,
1079 fill_literal,
1080 (file_ptr) offset,
1081 (bfd_size_type) fill_size);
1082 if (x == false)
1083 {
1084 bfd_perror (stdoutput->filename);
1085 as_perror ("FATAL: Can't write %s", stdoutput->filename);
1086 exit (EXIT_FAILURE);
1087 }
1088 offset += fill_size;
1089 }
1090 }
1091 else
1092 {
1093 /* Build a buffer full of fill objects and output it as
1094 often as necessary. This saves on the overhead of
1095 potentially lots of bfd_set_section_contents calls. */
1096 int n_per_buf, i;
1097 if (fill_size == 1)
1098 {
1099 n_per_buf = sizeof (buf);
1100 memset (buf, *fill_literal, n_per_buf);
1101 }
1102 else
1103 {
1104 char *bufp;
1105 n_per_buf = sizeof(buf)/fill_size;
1106 for (i = n_per_buf, bufp = buf; i; i--, bufp += fill_size)
1107 memcpy(bufp, fill_literal, fill_size);
1108 }
1109 for (; count > 0; count -= n_per_buf)
1110 {
1111 n_per_buf = n_per_buf > count ? count : n_per_buf;
1112 x = bfd_set_section_contents (stdoutput, sec,
1113 buf, (file_ptr) offset,
1114 (bfd_size_type) n_per_buf * fill_size);
1115 if (x != true)
1116 as_fatal ("Cannot write to output file.");
1117 offset += n_per_buf * fill_size;
1118 }
1119 }
1120 }
1121 }
1122 }
1123 #endif
1124
1125 #if defined(BFD_ASSEMBLER) || (!defined (BFD) && !defined(OBJ_AOUT))
1126 static void
1127 merge_data_into_text ()
1128 {
1129 #if defined(BFD_ASSEMBLER) || defined(MANY_SEGMENTS)
1130 seg_info (text_section)->frchainP->frch_last->fr_next =
1131 seg_info (data_section)->frchainP->frch_root;
1132 seg_info (text_section)->frchainP->frch_last =
1133 seg_info (data_section)->frchainP->frch_last;
1134 seg_info (data_section)->frchainP = 0;
1135 #else
1136 fixS *tmp;
1137
1138 text_last_frag->fr_next = data_frag_root;
1139 text_last_frag = data_last_frag;
1140 data_last_frag = NULL;
1141 data_frag_root = NULL;
1142 if (text_fix_root)
1143 {
1144 for (tmp = text_fix_root; tmp->fx_next; tmp = tmp->fx_next);;
1145 tmp->fx_next = data_fix_root;
1146 text_fix_tail = data_fix_tail;
1147 }
1148 else
1149 text_fix_root = data_fix_root;
1150 data_fix_root = NULL;
1151 #endif
1152 }
1153 #endif /* BFD_ASSEMBLER || (! BFD && ! OBJ_AOUT) */
1154
1155 #if !defined (BFD_ASSEMBLER) && !defined (BFD)
1156 static void
1157 relax_and_size_all_segments ()
1158 {
1159 fragS *fragP;
1160
1161 relax_segment (text_frag_root, SEG_TEXT);
1162 relax_segment (data_frag_root, SEG_DATA);
1163 relax_segment (bss_frag_root, SEG_BSS);
1164 /*
1165 * Now the addresses of frags are correct within the segment.
1166 */
1167
1168 know (text_last_frag->fr_type == rs_fill && text_last_frag->fr_offset == 0);
1169 H_SET_TEXT_SIZE (&headers, text_last_frag->fr_address);
1170 text_last_frag->fr_address = H_GET_TEXT_SIZE (&headers);
1171
1172 /*
1173 * Join the 2 segments into 1 huge segment.
1174 * To do this, re-compute every rn_address in the SEG_DATA frags.
1175 * Then join the data frags after the text frags.
1176 *
1177 * Determine a_data [length of data segment].
1178 */
1179 if (data_frag_root)
1180 {
1181 register relax_addressT slide;
1182
1183 know ((text_last_frag->fr_type == rs_fill) && (text_last_frag->fr_offset == 0));
1184
1185 H_SET_DATA_SIZE (&headers, data_last_frag->fr_address);
1186 data_last_frag->fr_address = H_GET_DATA_SIZE (&headers);
1187 slide = H_GET_TEXT_SIZE (&headers); /* & in file of the data segment. */
1188 #ifdef OBJ_BOUT
1189 #define RoundUp(N,S) (((N)+(S)-1)&-(S))
1190 /* For b.out: If the data section has a strict alignment
1191 requirement, its load address in the .o file will be
1192 rounded up from the size of the text section. These
1193 two values are *not* the same! Similarly for the bss
1194 section.... */
1195 slide = RoundUp (slide, 1 << section_alignment[SEG_DATA]);
1196 #endif
1197
1198 for (fragP = data_frag_root; fragP; fragP = fragP->fr_next)
1199 {
1200 fragP->fr_address += slide;
1201 } /* for each data frag */
1202
1203 know (text_last_frag != 0);
1204 text_last_frag->fr_next = data_frag_root;
1205 }
1206 else
1207 {
1208 H_SET_DATA_SIZE (&headers, 0);
1209 }
1210
1211 #ifdef OBJ_BOUT
1212 /* See above comments on b.out data section address. */
1213 {
1214 long bss_vma;
1215 if (data_last_frag == 0)
1216 bss_vma = H_GET_TEXT_SIZE (&headers);
1217 else
1218 bss_vma = data_last_frag->fr_address;
1219 bss_vma = RoundUp (bss_vma, 1 << section_alignment[SEG_BSS]);
1220 bss_address_frag.fr_address = bss_vma;
1221 }
1222 #else /* ! OBJ_BOUT */
1223 bss_address_frag.fr_address = (H_GET_TEXT_SIZE (&headers) +
1224 H_GET_DATA_SIZE (&headers));
1225
1226 #endif /* ! OBJ_BOUT */
1227
1228 /* Slide all the frags */
1229 if (bss_frag_root)
1230 {
1231 relax_addressT slide = bss_address_frag.fr_address;
1232
1233 for (fragP = bss_frag_root; fragP; fragP = fragP->fr_next)
1234 {
1235 fragP->fr_address += slide;
1236 } /* for each bss frag */
1237 }
1238
1239 if (bss_last_frag)
1240 H_SET_BSS_SIZE (&headers,
1241 bss_last_frag->fr_address - bss_frag_root->fr_address);
1242 else
1243 H_SET_BSS_SIZE (&headers, 0);
1244 }
1245 #endif /* ! BFD_ASSEMBLER && ! BFD */
1246
1247 #if defined (BFD_ASSEMBLER) || !defined (BFD)
1248
1249 #ifdef BFD_ASSEMBLER
1250 static void
1251 set_symtab ()
1252 {
1253 int nsyms;
1254 asymbol **asympp;
1255 symbolS *symp;
1256 boolean result;
1257 extern PTR bfd_alloc PARAMS ((bfd *, size_t));
1258
1259 /* Count symbols. We can't rely on a count made by the loop in
1260 write_object_file, because *_frob_file may add a new symbol or
1261 two. */
1262 nsyms = 0;
1263 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
1264 nsyms++;
1265
1266 if (nsyms)
1267 {
1268 int i;
1269
1270 asympp = (asymbol **) bfd_alloc (stdoutput,
1271 nsyms * sizeof (asymbol *));
1272 symp = symbol_rootP;
1273 for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
1274 {
1275 asympp[i] = symp->bsym;
1276 symp->written = 1;
1277 }
1278 }
1279 else
1280 asympp = 0;
1281 result = bfd_set_symtab (stdoutput, asympp, nsyms);
1282 assert (result == true);
1283 symbol_table_frozen = 1;
1284 }
1285 #endif
1286
1287 void
1288 write_object_file ()
1289 {
1290 struct frchain *frchainP; /* Track along all frchains. */
1291 #if ! defined (BFD_ASSEMBLER) || ! defined (WORKING_DOT_WORD)
1292 fragS *fragP; /* Track along all frags. */
1293 #endif
1294
1295 /* Do we really want to write it? */
1296 {
1297 int n_warns, n_errs;
1298 n_warns = had_warnings ();
1299 n_errs = had_errors ();
1300 /* The -Z flag indicates that an object file should be generated,
1301 regardless of warnings and errors. */
1302 if (flag_always_generate_output)
1303 {
1304 if (n_warns || n_errs)
1305 as_warn ("%d error%s, %d warning%s, generating bad object file.\n",
1306 n_errs, n_errs == 1 ? "" : "s",
1307 n_warns, n_warns == 1 ? "" : "s");
1308 }
1309 else
1310 {
1311 if (n_errs)
1312 as_fatal ("%d error%s, %d warning%s, no object file generated.\n",
1313 n_errs, n_errs == 1 ? "" : "s",
1314 n_warns, n_warns == 1 ? "" : "s");
1315 }
1316 }
1317
1318 #ifdef OBJ_VMS
1319 /* Under VMS we try to be compatible with VAX-11 "C". Thus, we call
1320 a routine to check for the definition of the procedure "_main",
1321 and if so -- fix it up so that it can be program entry point. */
1322 vms_check_for_main ();
1323 #endif /* OBJ_VMS */
1324
1325 /* After every sub-segment, we fake an ".align ...". This conforms to
1326 BSD4.2 brane-damage. We then fake ".fill 0" because that is the kind of
1327 frag that requires least thought. ".align" frags like to have a
1328 following frag since that makes calculating their intended length
1329 trivial.
1330
1331 @@ Is this really necessary?? */
1332 #ifndef SUB_SEGMENT_ALIGN
1333 #ifdef BFD_ASSEMBLER
1334 #define SUB_SEGMENT_ALIGN(SEG) (0)
1335 #else
1336 #define SUB_SEGMENT_ALIGN(SEG) (2)
1337 #endif
1338 #endif
1339 for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next)
1340 {
1341 subseg_set (frchainP->frch_seg, frchainP->frch_subseg);
1342 frag_align (SUB_SEGMENT_ALIGN (now_seg), NOP_OPCODE);
1343 /* frag_align will have left a new frag.
1344 Use this last frag for an empty ".fill".
1345
1346 For this segment ...
1347 Create a last frag. Do not leave a "being filled in frag". */
1348 frag_wane (frag_now);
1349 frag_now->fr_fix = 0;
1350 know (frag_now->fr_next == NULL);
1351 }
1352
1353 /* From now on, we don't care about sub-segments. Build one frag chain
1354 for each segment. Linked thru fr_next. */
1355
1356 #ifdef BFD_ASSEMBLER
1357 /* Remove the sections created by gas for its own purposes. */
1358 {
1359 asection **seclist, *sec;
1360 int i;
1361
1362 seclist = &stdoutput->sections;
1363 while (seclist && *seclist)
1364 {
1365 sec = *seclist;
1366 while (sec == reg_section || sec == expr_section)
1367 {
1368 sec = sec->next;
1369 *seclist = sec;
1370 stdoutput->section_count--;
1371 if (!sec)
1372 break;
1373 }
1374 if (*seclist)
1375 seclist = &(*seclist)->next;
1376 }
1377 i = 0;
1378 bfd_map_over_sections (stdoutput, renumber_sections, &i);
1379 }
1380
1381 bfd_map_over_sections (stdoutput, chain_frchains_together, (char *) 0);
1382 #else
1383 remove_subsegs (frchain_root, SEG_TEXT, &text_frag_root, &text_last_frag);
1384 remove_subsegs (data0_frchainP, SEG_DATA, &data_frag_root, &data_last_frag);
1385 remove_subsegs (bss0_frchainP, SEG_BSS, &bss_frag_root, &bss_last_frag);
1386 #endif
1387
1388 /* We have two segments. If user gave -R flag, then we must put the
1389 data frags into the text segment. Do this before relaxing so
1390 we know to take advantage of -R and make shorter addresses. */
1391 #if !defined (OBJ_AOUT) || defined (BFD_ASSEMBLER)
1392 if (flag_readonly_data_in_text)
1393 {
1394 merge_data_into_text ();
1395 }
1396 #endif
1397
1398 #ifdef BFD_ASSEMBLER
1399 bfd_map_over_sections (stdoutput, relax_and_size_seg, (char *) 0);
1400 #else
1401 relax_and_size_all_segments ();
1402 #endif /* BFD_ASSEMBLER */
1403
1404 #ifndef BFD_ASSEMBLER
1405 /*
1406 *
1407 * Crawl the symbol chain.
1408 *
1409 * For each symbol whose value depends on a frag, take the address of
1410 * that frag and subsume it into the value of the symbol.
1411 * After this, there is just one way to lookup a symbol value.
1412 * Values are left in their final state for object file emission.
1413 * We adjust the values of 'L' local symbols, even if we do
1414 * not intend to emit them to the object file, because their values
1415 * are needed for fix-ups.
1416 *
1417 * Unless we saw a -L flag, remove all symbols that begin with 'L'
1418 * from the symbol chain. (They are still pointed to by the fixes.)
1419 *
1420 * Count the remaining symbols.
1421 * Assign a symbol number to each symbol.
1422 * Count the number of string-table chars we will emit.
1423 * Put this info into the headers as appropriate.
1424 *
1425 */
1426 know (zero_address_frag.fr_address == 0);
1427 string_byte_count = sizeof (string_byte_count);
1428
1429 obj_crawl_symbol_chain (&headers);
1430
1431 if (string_byte_count == sizeof (string_byte_count))
1432 string_byte_count = 0;
1433
1434 H_SET_STRING_SIZE (&headers, string_byte_count);
1435
1436 /*
1437 * Addresses of frags now reflect addresses we use in the object file.
1438 * Symbol values are correct.
1439 * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
1440 * Also converting any machine-dependent frags using md_convert_frag();
1441 */
1442 subseg_change (SEG_TEXT, 0);
1443
1444 for (fragP = text_frag_root; fragP; fragP = fragP->fr_next)
1445 {
1446 cvt_frag_to_fill (&headers, SEG_TEXT, fragP);
1447
1448 /* Some assert macros don't work with # directives mixed in. */
1449 #ifndef NDEBUG
1450 if (!(fragP->fr_next == NULL
1451 #ifdef OBJ_BOUT
1452 || fragP->fr_next == data_frag_root
1453 #endif
1454 || ((fragP->fr_next->fr_address - fragP->fr_address)
1455 == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var))))
1456 abort ();
1457 #endif
1458 }
1459 #endif /* ! BFD_ASSEMBLER */
1460
1461 #ifndef WORKING_DOT_WORD
1462 {
1463 struct broken_word *lie;
1464 struct broken_word **prevP;
1465
1466 prevP = &broken_words;
1467 for (lie = broken_words; lie; lie = lie->next_broken_word)
1468 if (!lie->added)
1469 {
1470 expressionS exp;
1471
1472 exp.X_op = O_subtract;
1473 exp.X_add_symbol = lie->add;
1474 exp.X_op_symbol = lie->sub;
1475 exp.X_add_number = lie->addnum;
1476 #ifdef BFD_ASSEMBLER
1477 #ifdef TC_CONS_FIX_NEW
1478 TC_CONS_FIX_NEW (lie->frag,
1479 lie->word_goes_here - lie->frag->fr_literal,
1480 2, &exp);
1481 #else
1482 fix_new_exp (lie->frag,
1483 lie->word_goes_here - lie->frag->fr_literal,
1484 2, &exp, 0, BFD_RELOC_16);
1485 #endif
1486 #else
1487 #if defined(TC_SPARC) || defined(TC_A29K) || defined(NEED_FX_R_TYPE)
1488 fix_new_exp (lie->frag,
1489 lie->word_goes_here - lie->frag->fr_literal,
1490 2, &exp, 0, NO_RELOC);
1491 #else
1492 #ifdef TC_NS32K
1493 fix_new_ns32k_exp (lie->frag,
1494 lie->word_goes_here - lie->frag->fr_literal,
1495 2, &exp, 0, 0, 2, 0, 0);
1496 #else
1497 fix_new_exp (lie->frag,
1498 lie->word_goes_here - lie->frag->fr_literal,
1499 2, &exp, 0, 0);
1500 #endif /* TC_NS32K */
1501 #endif /* TC_SPARC|TC_A29K|NEED_FX_R_TYPE */
1502 #endif /* BFD_ASSEMBLER */
1503 *prevP = lie->next_broken_word;
1504 }
1505 else
1506 prevP = &(lie->next_broken_word);
1507
1508 for (lie = broken_words; lie;)
1509 {
1510 struct broken_word *untruth;
1511 char *table_ptr;
1512 addressT table_addr;
1513 addressT from_addr, to_addr;
1514 int n, m;
1515
1516 fragP = lie->dispfrag;
1517
1518 /* Find out how many broken_words go here. */
1519 n = 0;
1520 for (untruth = lie; untruth && untruth->dispfrag == fragP; untruth = untruth->next_broken_word)
1521 if (untruth->added == 1)
1522 n++;
1523
1524 table_ptr = lie->dispfrag->fr_opcode;
1525 table_addr = lie->dispfrag->fr_address + (table_ptr - lie->dispfrag->fr_literal);
1526 /* Create the jump around the long jumps. This is a short
1527 jump from table_ptr+0 to table_ptr+n*long_jump_size. */
1528 from_addr = table_addr;
1529 to_addr = table_addr + md_short_jump_size + n * md_long_jump_size;
1530 md_create_short_jump (table_ptr, from_addr, to_addr, lie->dispfrag, lie->add);
1531 table_ptr += md_short_jump_size;
1532 table_addr += md_short_jump_size;
1533
1534 for (m = 0; lie && lie->dispfrag == fragP; m++, lie = lie->next_broken_word)
1535 {
1536 if (lie->added == 2)
1537 continue;
1538 /* Patch the jump table */
1539 /* This is the offset from ??? to table_ptr+0 */
1540 to_addr = table_addr - S_GET_VALUE (lie->sub);
1541 #ifdef BFD_ASSEMBLER
1542 to_addr -= lie->sub->sy_frag->fr_address;
1543 #endif
1544 md_number_to_chars (lie->word_goes_here, to_addr, 2);
1545 for (untruth = lie->next_broken_word; untruth && untruth->dispfrag == fragP; untruth = untruth->next_broken_word)
1546 {
1547 if (untruth->use_jump == lie)
1548 md_number_to_chars (untruth->word_goes_here, to_addr, 2);
1549 }
1550
1551 /* Install the long jump */
1552 /* this is a long jump from table_ptr+0 to the final target */
1553 from_addr = table_addr;
1554 to_addr = S_GET_VALUE (lie->add) + lie->addnum;
1555 #ifdef BFD_ASSEMBLER
1556 to_addr += lie->add->sy_frag->fr_address;
1557 #endif
1558 md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag, lie->add);
1559 table_ptr += md_long_jump_size;
1560 table_addr += md_long_jump_size;
1561 }
1562 }
1563 }
1564 #endif /* not WORKING_DOT_WORD */
1565
1566 #ifndef BFD_ASSEMBLER
1567 #ifndef OBJ_VMS
1568 { /* not vms */
1569 char *the_object_file;
1570 long object_file_size;
1571 /*
1572 * Scan every FixS performing fixups. We had to wait until now to do
1573 * this because md_convert_frag() may have made some fixSs.
1574 */
1575 int trsize, drsize;
1576
1577 subseg_change (SEG_TEXT, 0);
1578 trsize = md_reloc_size * fixup_segment (text_fix_root, SEG_TEXT);
1579 subseg_change (SEG_DATA, 0);
1580 drsize = md_reloc_size * fixup_segment (data_fix_root, SEG_DATA);
1581 H_SET_RELOCATION_SIZE (&headers, trsize, drsize);
1582
1583 /* FIXME move this stuff into the pre-write-hook */
1584 H_SET_MAGIC_NUMBER (&headers, magic_number_for_object_file);
1585 H_SET_ENTRY_POINT (&headers, 0);
1586
1587 obj_pre_write_hook (&headers); /* extra coff stuff */
1588
1589 object_file_size = H_GET_FILE_SIZE (&headers);
1590 next_object_file_charP = the_object_file = xmalloc (object_file_size);
1591
1592 output_file_create (out_file_name);
1593
1594 obj_header_append (&next_object_file_charP, &headers);
1595
1596 know ((next_object_file_charP - the_object_file) == H_GET_HEADER_SIZE (&headers));
1597
1598 /*
1599 * Emit code.
1600 */
1601 for (fragP = text_frag_root; fragP; fragP = fragP->fr_next)
1602 {
1603 register long count;
1604 register char *fill_literal;
1605 register long fill_size;
1606
1607 PROGRESS (1);
1608 know (fragP->fr_type == rs_fill);
1609 append (&next_object_file_charP, fragP->fr_literal, (unsigned long) fragP->fr_fix);
1610 fill_literal = fragP->fr_literal + fragP->fr_fix;
1611 fill_size = fragP->fr_var;
1612 know (fragP->fr_offset >= 0);
1613
1614 for (count = fragP->fr_offset; count; count--)
1615 {
1616 append (&next_object_file_charP, fill_literal, (unsigned long) fill_size);
1617 } /* for each */
1618
1619 } /* for each code frag. */
1620
1621 know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers)));
1622
1623 /*
1624 * Emit relocations.
1625 */
1626 obj_emit_relocations (&next_object_file_charP, text_fix_root, (relax_addressT) 0);
1627 know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers)));
1628 #ifdef TC_I960
1629 /* Make addresses in data relocation directives relative to beginning of
1630 * first data fragment, not end of last text fragment: alignment of the
1631 * start of the data segment may place a gap between the segments.
1632 */
1633 obj_emit_relocations (&next_object_file_charP, data_fix_root, data0_frchainP->frch_root->fr_address);
1634 #else /* TC_I960 */
1635 obj_emit_relocations (&next_object_file_charP, data_fix_root, text_last_frag->fr_address);
1636 #endif /* TC_I960 */
1637
1638 know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers)));
1639
1640 /*
1641 * Emit line number entries.
1642 */
1643 OBJ_EMIT_LINENO (&next_object_file_charP, lineno_rootP, the_object_file);
1644 know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers) + H_GET_LINENO_SIZE (&headers)));
1645
1646 /*
1647 * Emit symbols.
1648 */
1649 obj_emit_symbols (&next_object_file_charP, symbol_rootP);
1650 know ((next_object_file_charP - the_object_file) == (H_GET_HEADER_SIZE (&headers) + H_GET_TEXT_SIZE (&headers) + H_GET_DATA_SIZE (&headers) + H_GET_TEXT_RELOCATION_SIZE (&headers) + H_GET_DATA_RELOCATION_SIZE (&headers) + H_GET_LINENO_SIZE (&headers) + H_GET_SYMBOL_TABLE_SIZE (&headers)));
1651
1652 /*
1653 * Emit strings.
1654 */
1655
1656 if (string_byte_count > 0)
1657 {
1658 obj_emit_strings (&next_object_file_charP);
1659 } /* only if we have a string table */
1660
1661 #ifdef BFD_HEADERS
1662 bfd_seek (stdoutput, 0, 0);
1663 bfd_write (the_object_file, 1, object_file_size, stdoutput);
1664 #else
1665
1666 /* Write the data to the file */
1667 output_file_append (the_object_file, object_file_size, out_file_name);
1668 free (the_object_file);
1669 #endif
1670 } /* non vms output */
1671 #else /* OBJ_VMS */
1672 /*
1673 * Now do the VMS-dependent part of writing the object file
1674 */
1675 vms_write_object_file (H_GET_TEXT_SIZE (&headers),
1676 H_GET_DATA_SIZE (&headers),
1677 H_GET_BSS_SIZE (&headers),
1678 text_frag_root, data_frag_root);
1679 #endif /* OBJ_VMS */
1680 #else /* BFD_ASSEMBLER */
1681
1682 /* Resolve symbol values. This needs to be done before processing
1683 the relocations. */
1684 if (symbol_rootP)
1685 {
1686 symbolS *symp;
1687
1688 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
1689 if (!symp->sy_resolved)
1690 resolve_symbol_value (symp);
1691 }
1692
1693 PROGRESS (1);
1694
1695 #ifdef tc_frob_file_before_adjust
1696 tc_frob_file_before_adjust ();
1697 #endif
1698 #ifdef obj_frob_file_before_adjust
1699 obj_frob_file_before_adjust ();
1700 #endif
1701
1702 bfd_map_over_sections (stdoutput, adjust_reloc_syms, (char *)0);
1703
1704 /* Set up symbol table, and write it out. */
1705 if (symbol_rootP)
1706 {
1707 symbolS *symp;
1708
1709 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
1710 {
1711 int punt = 0;
1712 const char *name;
1713
1714 if (symp->sy_mri_common)
1715 {
1716 if (S_IS_EXTERNAL (symp))
1717 as_bad ("%s: global symbols not supported in common sections",
1718 S_GET_NAME (symp));
1719 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
1720 continue;
1721 }
1722
1723 name = S_GET_NAME (symp);
1724 if (name)
1725 {
1726 const char *name2 = decode_local_label_name ((char *)S_GET_NAME (symp));
1727 /* They only differ if `name' is a fb or dollar local
1728 label name. */
1729 if (name2 != name && ! S_IS_DEFINED (symp))
1730 as_bad ("local label %s is not defined", name2);
1731 }
1732
1733 /* Do it again, because adjust_reloc_syms might introduce
1734 more symbols. They'll probably only be section symbols,
1735 but they'll still need to have the values computed. */
1736 if (! symp->sy_resolved)
1737 {
1738 if (symp->sy_value.X_op == O_constant)
1739 {
1740 /* This is the normal case; skip the call. */
1741 S_SET_VALUE (symp,
1742 (S_GET_VALUE (symp)
1743 + symp->sy_frag->fr_address));
1744 symp->sy_resolved = 1;
1745 }
1746 else
1747 resolve_symbol_value (symp);
1748 }
1749
1750 /* Skip symbols which were equated to undefined or common
1751 symbols. */
1752 if (symp->sy_value.X_op == O_symbol
1753 && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp)))
1754 {
1755 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
1756 continue;
1757 }
1758
1759 /* So far, common symbols have been treated like undefined symbols.
1760 Put them in the common section now. */
1761 if (S_IS_DEFINED (symp) == 0
1762 && S_GET_VALUE (symp) != 0)
1763 S_SET_SEGMENT (symp, bfd_com_section_ptr);
1764 #if 0
1765 printf ("symbol `%s'\n\t@%x: value=%d flags=%x seg=%s\n",
1766 S_GET_NAME (symp), symp,
1767 S_GET_VALUE (symp),
1768 symp->bsym->flags,
1769 segment_name (symp->bsym->section));
1770 #endif
1771
1772 #ifdef obj_frob_symbol
1773 obj_frob_symbol (symp, punt);
1774 #endif
1775 #ifdef tc_frob_symbol
1776 if (! punt || symp->sy_used_in_reloc)
1777 tc_frob_symbol (symp, punt);
1778 #endif
1779
1780 /* If we don't want to keep this symbol, splice it out of
1781 the chain now. If EMIT_SECTION_SYMBOLS is 0, we never
1782 want section symbols. Otherwise, we skip local symbols
1783 and symbols that the frob_symbol macros told us to punt,
1784 but we keep such symbols if they are used in relocs. */
1785 if ((! EMIT_SECTION_SYMBOLS
1786 && (symp->bsym->flags & BSF_SECTION_SYM) != 0)
1787 /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
1788 opposites. Sometimes the former checks flags and the
1789 latter examines the name... */
1790 || (!S_IS_EXTERN (symp)
1791 && (S_IS_LOCAL (symp) || punt)
1792 && ! symp->sy_used_in_reloc))
1793 {
1794 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
1795 /* After symbol_remove, symbol_next(symp) still returns
1796 the one that came after it in the chain. So we don't
1797 need to do any extra cleanup work here. */
1798
1799 continue;
1800 }
1801
1802 /* Make sure we really got a value for the symbol. */
1803 if (! symp->sy_resolved)
1804 {
1805 as_bad ("can't resolve value for symbol \"%s\"",
1806 S_GET_NAME (symp));
1807 symp->sy_resolved = 1;
1808 }
1809
1810 /* Set the value into the BFD symbol. Up til now the value
1811 has only been kept in the gas symbolS struct. */
1812 symp->bsym->value = S_GET_VALUE (symp);
1813 }
1814 }
1815
1816 PROGRESS (1);
1817
1818 /* Now do any format-specific adjustments to the symbol table, such
1819 as adding file symbols. */
1820 #ifdef tc_adjust_symtab
1821 tc_adjust_symtab ();
1822 #endif
1823 #ifdef obj_adjust_symtab
1824 obj_adjust_symtab ();
1825 #endif
1826
1827 /* Now that all the sizes are known, and contents correct, we can
1828 start writing to the file. */
1829 set_symtab ();
1830
1831 /* If *_frob_file changes the symbol value at this point, it is
1832 responsible for moving the changed value into symp->bsym->value
1833 as well. Hopefully all symbol value changing can be done in
1834 *_frob_symbol. */
1835 #ifdef tc_frob_file
1836 tc_frob_file ();
1837 #endif
1838 #ifdef obj_frob_file
1839 obj_frob_file ();
1840 #endif
1841
1842 bfd_map_over_sections (stdoutput, write_relocs, (char *) 0);
1843
1844 #ifdef tc_frob_file_after_relocs
1845 tc_frob_file_after_relocs ();
1846 #endif
1847 #ifdef obj_frob_file_after_relocs
1848 obj_frob_file_after_relocs ();
1849 #endif
1850
1851 bfd_map_over_sections (stdoutput, write_contents, (char *) 0);
1852 #endif /* BFD_ASSEMBLER */
1853 }
1854 #endif /* ! BFD */
1855
1856 /*
1857 * relax_segment()
1858 *
1859 * Now we have a segment, not a crowd of sub-segments, we can make fr_address
1860 * values.
1861 *
1862 * Relax the frags.
1863 *
1864 * After this, all frags in this segment have addresses that are correct
1865 * within the segment. Since segments live in different file addresses,
1866 * these frag addresses may not be the same as final object-file addresses.
1867 */
1868
1869 #ifdef TC_GENERIC_RELAX_TABLE
1870
1871 /* Subroutines of relax_segment. */
1872 static int
1873 is_dnrange (f1, f2)
1874 struct frag *f1;
1875 struct frag *f2;
1876 {
1877 for (; f1; f1 = f1->fr_next)
1878 if (f1->fr_next == f2)
1879 return 1;
1880 return 0;
1881 }
1882
1883 /* Relax a fragment by scanning TC_GENERIC_RELAX_TABLE. */
1884
1885 long
1886 relax_frag (fragP, stretch)
1887 fragS *fragP;
1888 long stretch;
1889 {
1890 const relax_typeS *this_type;
1891 const relax_typeS *start_type;
1892 relax_substateT next_state;
1893 relax_substateT this_state;
1894 long aim, target, growth;
1895 symbolS *symbolP = fragP->fr_symbol;
1896 long offset = fragP->fr_offset;
1897 /* Recompute was_address by undoing "+= stretch" done by relax_segment. */
1898 unsigned long was_address = fragP->fr_address - stretch;
1899 unsigned long address = fragP->fr_address;
1900 const relax_typeS *table = TC_GENERIC_RELAX_TABLE;
1901
1902 this_state = fragP->fr_subtype;
1903 start_type = this_type = table + this_state;
1904 target = offset;
1905
1906 if (symbolP)
1907 {
1908 #ifndef DIFF_EXPR_OK
1909 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
1910 know ((S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
1911 || (S_GET_SEGMENT (symbolP) == SEG_DATA)
1912 || (S_GET_SEGMENT (symbolP) == SEG_BSS)
1913 || (S_GET_SEGMENT (symbolP) == SEG_TEXT));
1914 #endif
1915 know (symbolP->sy_frag);
1916 #endif
1917 know (!(S_GET_SEGMENT (symbolP) == absolute_section)
1918 || symbolP->sy_frag == &zero_address_frag);
1919 target +=
1920 S_GET_VALUE (symbolP)
1921 + symbolP->sy_frag->fr_address;
1922
1923 /* If frag has yet to be reached on this pass,
1924 assume it will move by STRETCH just as we did.
1925 If this is not so, it will be because some frag
1926 between grows, and that will force another pass.
1927
1928 Beware zero-length frags.
1929
1930 There should be a faster way to do this. */
1931
1932 if (symbolP->sy_frag->fr_address >= was_address
1933 && is_dnrange (fragP, symbolP->sy_frag))
1934 {
1935 target += stretch;
1936 }
1937 }
1938
1939 aim = target - address - fragP->fr_fix;
1940 #ifdef TC_PCREL_ADJUST
1941 /* Currently only the ns32k family needs this */
1942 aim += TC_PCREL_ADJUST(fragP);
1943 /*#else*/
1944 /* This machine doesn't want to use pcrel_adjust.
1945 In that case, pcrel_adjust should be zero. */
1946 /* assert (fragP->fr_pcrel_adjust == 0);*/
1947 #endif
1948 #ifdef md_prepare_relax_scan /* formerly called M68K_AIM_KLUDGE */
1949 md_prepare_relax_scan (fragP, address, aim, this_state, this_type);
1950 #endif
1951
1952 if (aim < 0)
1953 {
1954 /* Look backwards. */
1955 for (next_state = this_type->rlx_more; next_state;)
1956 if (aim >= this_type->rlx_backward)
1957 next_state = 0;
1958 else
1959 {
1960 /* Grow to next state. */
1961 this_state = next_state;
1962 this_type = table + this_state;
1963 next_state = this_type->rlx_more;
1964 }
1965 }
1966 else
1967 {
1968 /* Look forwards. */
1969 for (next_state = this_type->rlx_more; next_state;)
1970 if (aim <= this_type->rlx_forward)
1971 next_state = 0;
1972 else
1973 {
1974 /* Grow to next state. */
1975 this_state = next_state;
1976 this_type = table + this_state;
1977 next_state = this_type->rlx_more;
1978 }
1979 }
1980
1981 growth = this_type->rlx_length - start_type->rlx_length;
1982 if (growth != 0)
1983 fragP->fr_subtype = this_state;
1984 return growth;
1985 }
1986
1987 #endif /* defined (TC_GENERIC_RELAX_TABLE) */
1988
1989 /* Relax_align. Advance location counter to next address that has 'alignment'
1990 lowest order bits all 0s, return size of adjustment made. */
1991 static relax_addressT
1992 relax_align (address, alignment)
1993 register relax_addressT address; /* Address now. */
1994 register int alignment; /* Alignment (binary). */
1995 {
1996 relax_addressT mask;
1997 relax_addressT new_address;
1998
1999 mask = ~((~0) << alignment);
2000 new_address = (address + mask) & (~mask);
2001 #ifdef LINKER_RELAXING_SHRINKS_ONLY
2002 if (linkrelax)
2003 /* We must provide lots of padding, so the linker can discard it
2004 when needed. The linker will not add extra space, ever. */
2005 new_address += (1 << alignment);
2006 #endif
2007 return (new_address - address);
2008 }
2009
2010 void
2011 relax_segment (segment_frag_root, segment)
2012 struct frag *segment_frag_root;
2013 segT segment;
2014 {
2015 register struct frag *fragP;
2016 register relax_addressT address;
2017 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
2018 know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS);
2019 #endif
2020 /* In case md_estimate_size_before_relax() wants to make fixSs. */
2021 subseg_change (segment, 0);
2022
2023 /* For each frag in segment: count and store (a 1st guess of)
2024 fr_address. */
2025 address = 0;
2026 for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
2027 {
2028 fragP->fr_address = address;
2029 address += fragP->fr_fix;
2030
2031 switch (fragP->fr_type)
2032 {
2033 case rs_fill:
2034 address += fragP->fr_offset * fragP->fr_var;
2035 break;
2036
2037 case rs_align:
2038 case rs_align_code:
2039 {
2040 int offset = relax_align (address, (int) fragP->fr_offset);
2041 if (offset % fragP->fr_var != 0)
2042 {
2043 as_bad ("alignment padding (%d bytes) not a multiple of %ld",
2044 offset, (long) fragP->fr_var);
2045 offset -= (offset % fragP->fr_var);
2046 }
2047 address += offset;
2048 }
2049 break;
2050
2051 case rs_org:
2052 case rs_space:
2053 /* Assume .org is nugatory. It will grow with 1st relax. */
2054 break;
2055
2056 case rs_machine_dependent:
2057 address += md_estimate_size_before_relax (fragP, segment);
2058 break;
2059
2060 #ifndef WORKING_DOT_WORD
2061 /* Broken words don't concern us yet */
2062 case rs_broken_word:
2063 break;
2064 #endif
2065
2066 default:
2067 BAD_CASE (fragP->fr_type);
2068 break;
2069 } /* switch(fr_type) */
2070 } /* for each frag in the segment */
2071
2072 /* Do relax(). */
2073 {
2074 long stretch; /* May be any size, 0 or negative. */
2075 /* Cumulative number of addresses we have */
2076 /* relaxed this pass. */
2077 /* We may have relaxed more than one address. */
2078 long stretched; /* Have we stretched on this pass? */
2079 /* This is 'cuz stretch may be zero, when, in fact some piece of code
2080 grew, and another shrank. If a branch instruction doesn't fit anymore,
2081 we could be scrod. */
2082
2083 do
2084 {
2085 stretch = stretched = 0;
2086 for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
2087 {
2088 long growth = 0;
2089 unsigned long was_address;
2090 long offset;
2091 symbolS *symbolP;
2092
2093 was_address = fragP->fr_address;
2094 address = fragP->fr_address += stretch;
2095 symbolP = fragP->fr_symbol;
2096 offset = fragP->fr_offset;
2097
2098 switch (fragP->fr_type)
2099 {
2100 case rs_fill: /* .fill never relaxes. */
2101 growth = 0;
2102 break;
2103
2104 #ifndef WORKING_DOT_WORD
2105 /* JF: This is RMS's idea. I do *NOT* want to be blamed
2106 for it I do not want to write it. I do not want to have
2107 anything to do with it. This is not the proper way to
2108 implement this misfeature. */
2109 case rs_broken_word:
2110 {
2111 struct broken_word *lie;
2112 struct broken_word *untruth;
2113
2114 /* Yes this is ugly (storing the broken_word pointer
2115 in the symbol slot). Still, this whole chunk of
2116 code is ugly, and I don't feel like doing anything
2117 about it. Think of it as stubbornness in action. */
2118 growth = 0;
2119 for (lie = (struct broken_word *) (fragP->fr_symbol);
2120 lie && lie->dispfrag == fragP;
2121 lie = lie->next_broken_word)
2122 {
2123
2124 if (lie->added)
2125 continue;
2126
2127 offset = (lie->add->sy_frag->fr_address
2128 + S_GET_VALUE (lie->add)
2129 + lie->addnum
2130 - (lie->sub->sy_frag->fr_address
2131 + S_GET_VALUE (lie->sub)));
2132 if (offset <= -32768 || offset >= 32767)
2133 {
2134 if (flag_warn_displacement)
2135 {
2136 char buf[50];
2137 sprint_value (buf, (addressT) lie->addnum);
2138 as_warn (".word %s-%s+%s didn't fit",
2139 S_GET_NAME (lie->add),
2140 S_GET_NAME (lie->sub),
2141 buf);
2142 }
2143 lie->added = 1;
2144 if (fragP->fr_subtype == 0)
2145 {
2146 fragP->fr_subtype++;
2147 growth += md_short_jump_size;
2148 }
2149 for (untruth = lie->next_broken_word;
2150 untruth && untruth->dispfrag == lie->dispfrag;
2151 untruth = untruth->next_broken_word)
2152 if ((untruth->add->sy_frag == lie->add->sy_frag)
2153 && S_GET_VALUE (untruth->add) == S_GET_VALUE (lie->add))
2154 {
2155 untruth->added = 2;
2156 untruth->use_jump = lie;
2157 }
2158 growth += md_long_jump_size;
2159 }
2160 }
2161
2162 break;
2163 } /* case rs_broken_word */
2164 #endif
2165 case rs_align:
2166 case rs_align_code:
2167 growth = (relax_align ((relax_addressT) (address
2168 + fragP->fr_fix),
2169 (int) offset)
2170 - relax_align ((relax_addressT) (was_address
2171 + fragP->fr_fix),
2172 (int) offset));
2173 break;
2174
2175 case rs_org:
2176 {
2177 long target = offset;
2178 long after;
2179
2180 if (symbolP)
2181 {
2182 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
2183 know ((S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
2184 || (S_GET_SEGMENT (symbolP) == SEG_DATA)
2185 || (S_GET_SEGMENT (symbolP) == SEG_TEXT)
2186 || S_GET_SEGMENT (symbolP) == SEG_BSS);
2187 know (symbolP->sy_frag);
2188 know (!(S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
2189 || (symbolP->sy_frag == &zero_address_frag));
2190 #endif
2191 target += S_GET_VALUE (symbolP)
2192 + symbolP->sy_frag->fr_address;
2193 } /* if we have a symbol */
2194
2195 know (fragP->fr_next);
2196 after = fragP->fr_next->fr_address;
2197 growth = target - after;
2198 if (growth < 0)
2199 {
2200 /* Growth may be negative, but variable part of frag
2201 cannot have fewer than 0 chars. That is, we can't
2202 .org backwards. */
2203 as_bad ("attempt to .org backwards ignored");
2204 growth = 0;
2205 }
2206
2207 growth -= stretch; /* This is an absolute growth factor */
2208 break;
2209 }
2210
2211 case rs_space:
2212 if (symbolP)
2213 {
2214 growth = S_GET_VALUE (symbolP);
2215 if (symbolP->sy_frag != &zero_address_frag
2216 || S_IS_COMMON (symbolP)
2217 || ! S_IS_DEFINED (symbolP))
2218 as_bad_where (fragP->fr_file, fragP->fr_line,
2219 ".space specifies non-absolute value");
2220 fragP->fr_symbol = 0;
2221 if (growth < 0)
2222 {
2223 as_warn (".space or .fill with negative value, ignored");
2224 growth = 0;
2225 }
2226 }
2227 else
2228 growth = 0;
2229 break;
2230
2231 case rs_machine_dependent:
2232 #ifdef md_relax_frag
2233 growth = md_relax_frag (fragP, stretch);
2234 #else
2235 #ifdef TC_GENERIC_RELAX_TABLE
2236 /* The default way to relax a frag is to look through
2237 TC_GENERIC_RELAX_TABLE. */
2238 growth = relax_frag (fragP, stretch);
2239 #endif /* TC_GENERIC_RELAX_TABLE */
2240 #endif
2241 break;
2242
2243 default:
2244 BAD_CASE (fragP->fr_type);
2245 break;
2246 }
2247 if (growth)
2248 {
2249 stretch += growth;
2250 stretched++;
2251 }
2252 } /* For each frag in the segment. */
2253 }
2254 while (stretched); /* Until nothing further to relax. */
2255 } /* do_relax */
2256
2257 /*
2258 * We now have valid fr_address'es for each frag.
2259 */
2260
2261 /*
2262 * All fr_address's are correct, relative to their own segment.
2263 * We have made all the fixS we will ever make.
2264 */
2265 } /* relax_segment() */
2266
2267 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
2268
2269 #ifndef TC_RELOC_RTSYM_LOC_FIXUP
2270 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)
2271 #endif
2272
2273 /* fixup_segment()
2274
2275 Go through all the fixS's in a segment and see which ones can be
2276 handled now. (These consist of fixS where we have since discovered
2277 the value of a symbol, or the address of the frag involved.)
2278 For each one, call md_apply_fix to put the fix into the frag data.
2279
2280 Result is a count of how many relocation structs will be needed to
2281 handle the remaining fixS's that we couldn't completely handle here.
2282 These will be output later by emit_relocations(). */
2283
2284 static long
2285 fixup_segment (fixP, this_segment_type)
2286 register fixS *fixP;
2287 segT this_segment_type; /* N_TYPE bits for segment. */
2288 {
2289 long seg_reloc_count = 0;
2290 symbolS *add_symbolP;
2291 symbolS *sub_symbolP;
2292 valueT add_number;
2293 int size;
2294 char *place;
2295 long where;
2296 int pcrel, plt;
2297 fragS *fragP;
2298 segT add_symbol_segment = absolute_section;
2299
2300 /* If the linker is doing the relaxing, we must not do any fixups.
2301
2302 Well, strictly speaking that's not true -- we could do any that are
2303 PC-relative and don't cross regions that could change size. And for the
2304 i960 (the only machine for which we've got a relaxing linker right now),
2305 we might be able to turn callx/callj into bal anyways in cases where we
2306 know the maximum displacement. */
2307 if (linkrelax)
2308 {
2309 for (; fixP; fixP = fixP->fx_next)
2310 seg_reloc_count++;
2311 TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
2312 return seg_reloc_count;
2313 }
2314
2315 for (; fixP; fixP = fixP->fx_next)
2316 {
2317 #ifdef DEBUG5
2318 fprintf (stderr, "\nprocessing fixup:\n");
2319 print_fixup (fixP);
2320 #endif
2321
2322 fragP = fixP->fx_frag;
2323 know (fragP);
2324 where = fixP->fx_where;
2325 place = fragP->fr_literal + where;
2326 size = fixP->fx_size;
2327 add_symbolP = fixP->fx_addsy;
2328 #ifdef TC_VALIDATE_FIX
2329 TC_VALIDATE_FIX (fixP, this_segment_type, skip);
2330 #endif
2331 sub_symbolP = fixP->fx_subsy;
2332 add_number = fixP->fx_offset;
2333 pcrel = fixP->fx_pcrel;
2334 plt = fixP->fx_plt;
2335
2336 if (add_symbolP != NULL
2337 && add_symbolP->sy_mri_common)
2338 {
2339 know (add_symbolP->sy_value.X_op == O_symbol);
2340 add_number += S_GET_VALUE (add_symbolP);
2341 fixP->fx_offset = add_number;
2342 add_symbolP = fixP->fx_addsy = add_symbolP->sy_value.X_add_symbol;
2343 }
2344
2345 if (add_symbolP)
2346 add_symbol_segment = S_GET_SEGMENT (add_symbolP);
2347
2348 if (sub_symbolP)
2349 {
2350 resolve_symbol_value (sub_symbolP);
2351 if (add_symbolP == NULL || add_symbol_segment == absolute_section)
2352 {
2353 if (add_symbolP != NULL)
2354 {
2355 add_number += S_GET_VALUE (add_symbolP);
2356 add_symbolP = NULL;
2357 fixP->fx_addsy = NULL;
2358 }
2359
2360 /* It's just -sym */
2361 if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
2362 {
2363 add_number -= S_GET_VALUE (sub_symbolP);
2364 fixP->fx_subsy = NULL;
2365 }
2366 else if (pcrel
2367 && S_GET_SEGMENT (sub_symbolP) == this_segment_type)
2368 {
2369 /* Should try converting to a constant. */
2370 goto bad_sub_reloc;
2371 }
2372 else
2373 bad_sub_reloc:
2374 as_bad_where (fixP->fx_file, fixP->fx_line,
2375 "Negative of non-absolute symbol %s",
2376 S_GET_NAME (sub_symbolP));
2377 }
2378 else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
2379 && SEG_NORMAL (add_symbol_segment))
2380 {
2381 /* Difference of 2 symbols from same segment.
2382 Can't make difference of 2 undefineds: 'value' means
2383 something different for N_UNDF. */
2384 #ifdef TC_I960
2385 /* Makes no sense to use the difference of 2 arbitrary symbols
2386 as the target of a call instruction. */
2387 if (fixP->fx_tcbit)
2388 as_bad_where (fixP->fx_file, fixP->fx_line,
2389 "callj to difference of 2 symbols");
2390 #endif /* TC_I960 */
2391 add_number += S_GET_VALUE (add_symbolP) -
2392 S_GET_VALUE (sub_symbolP);
2393
2394 add_symbolP = NULL;
2395 pcrel = 0; /* No further pcrel processing. */
2396
2397 /* Let the target machine make the final determination
2398 as to whether or not a relocation will be needed to
2399 handle this fixup. */
2400 if (!TC_FORCE_RELOCATION_SECTION (fixP, this_segment_type))
2401 {
2402 fixP->fx_pcrel = 0;
2403 fixP->fx_addsy = NULL;
2404 fixP->fx_subsy = NULL;
2405 }
2406 }
2407 else
2408 {
2409 /* Different segments in subtraction. */
2410 know (!(S_IS_EXTERNAL (sub_symbolP)
2411 && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
2412
2413 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
2414 add_number -= S_GET_VALUE (sub_symbolP);
2415
2416 #ifdef DIFF_EXPR_OK
2417 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
2418 #if 0 /* Do this even if it's already described as pc-relative. For example,
2419 on the m68k, an operand of "pc@(foo-.-2)" should address "foo" in a
2420 pc-relative mode. */
2421 && pcrel
2422 #endif
2423 )
2424 {
2425 /* Make it pc-relative. */
2426 add_number += (MD_PCREL_FROM_SECTION (fixP, this_segment_type)
2427 - S_GET_VALUE (sub_symbolP));
2428 pcrel = 1;
2429 fixP->fx_pcrel = 1;
2430 sub_symbolP = 0;
2431 fixP->fx_subsy = 0;
2432 }
2433 #endif
2434 #ifdef UNDEFINED_DIFFERENCE_OK
2435 /* The PA needs this for PIC code generation. We basically
2436 don't want to do anything if we have the difference of two
2437 symbols at this point. */
2438 else if (1)
2439 {
2440 /* Leave it alone. */
2441 }
2442 #endif
2443 #ifdef BFD_ASSEMBLER
2444 else if (fixP->fx_r_type == BFD_RELOC_GPREL32
2445 || fixP->fx_r_type == BFD_RELOC_GPREL16)
2446 {
2447 /* Leave it alone. */
2448 }
2449 #endif
2450 else
2451 {
2452 char buf[50];
2453 sprint_value (buf, fragP->fr_address + where);
2454 as_bad_where (fixP->fx_file, fixP->fx_line,
2455 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %s.",
2456 segment_name (S_GET_SEGMENT (sub_symbolP)),
2457 S_GET_NAME (sub_symbolP), buf);
2458 }
2459 }
2460 }
2461
2462 if (add_symbolP)
2463 {
2464 if (add_symbol_segment == this_segment_type && pcrel && !plt
2465 && TC_RELOC_RTSYM_LOC_FIXUP (fixP))
2466 {
2467 /*
2468 * This fixup was made when the symbol's segment was
2469 * SEG_UNKNOWN, but it is now in the local segment.
2470 * So we know how to do the address without relocation.
2471 */
2472 #ifdef TC_I960
2473 /* reloc_callj() may replace a 'call' with a 'calls' or a
2474 'bal', in which cases it modifies *fixP as appropriate.
2475 In the case of a 'calls', no further work is required,
2476 and *fixP has been set up to make the rest of the code
2477 below a no-op. */
2478 reloc_callj (fixP);
2479 #endif /* TC_I960 */
2480
2481 add_number += S_GET_VALUE (add_symbolP);
2482 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type);
2483 pcrel = 0; /* Lie. Don't want further pcrel processing. */
2484
2485 /* Let the target machine make the final determination
2486 as to whether or not a relocation will be needed to
2487 handle this fixup. */
2488 if (!TC_FORCE_RELOCATION (fixP))
2489 {
2490 fixP->fx_pcrel = 0;
2491 fixP->fx_addsy = NULL;
2492 }
2493 }
2494 else
2495 {
2496 if (add_symbol_segment == absolute_section
2497 && ! pcrel)
2498 {
2499 #ifdef TC_I960
2500 /* See comment about reloc_callj() above. */
2501 reloc_callj (fixP);
2502 #endif /* TC_I960 */
2503 add_number += S_GET_VALUE (add_symbolP);
2504
2505 /* Let the target machine make the final determination
2506 as to whether or not a relocation will be needed to
2507 handle this fixup. */
2508
2509 if (!TC_FORCE_RELOCATION (fixP))
2510 {
2511 fixP->fx_addsy = NULL;
2512 add_symbolP = NULL;
2513 }
2514 }
2515 else if (add_symbol_segment == undefined_section
2516 #ifdef BFD_ASSEMBLER
2517 || bfd_is_com_section (add_symbol_segment)
2518 #endif
2519 )
2520 {
2521 #ifdef TC_I960
2522 if ((int) fixP->fx_bit_fixP == 13)
2523 {
2524 /* This is a COBR instruction. They have only a
2525 * 13-bit displacement and are only to be used
2526 * for local branches: flag as error, don't generate
2527 * relocation.
2528 */
2529 as_bad_where (fixP->fx_file, fixP->fx_line,
2530 "can't use COBR format with external label");
2531 fixP->fx_addsy = NULL;
2532 fixP->fx_done = 1;
2533 continue;
2534 } /* COBR */
2535 #endif /* TC_I960 */
2536
2537 #ifdef OBJ_COFF
2538 #ifdef TE_I386AIX
2539 if (S_IS_COMMON (add_symbolP))
2540 add_number += S_GET_VALUE (add_symbolP);
2541 #endif /* TE_I386AIX */
2542 #endif /* OBJ_COFF */
2543 ++seg_reloc_count;
2544 }
2545 else
2546 {
2547 seg_reloc_count++;
2548 /* start-sanitize-v850 */
2549 #if !(defined (TC_V850) && defined (OBJ_ELF))
2550 /* end-sanitize-v850 */
2551 #if !(defined (TC_M68K) && defined (OBJ_ELF))
2552 #if !defined (TC_I386) || !(defined (OBJ_ELF) || defined (OBJ_COFF))
2553 add_number += S_GET_VALUE (add_symbolP);
2554 /* start-sanitize-v850 */
2555 #endif
2556 /* end-sanitize-v850 */
2557 #endif
2558 #endif
2559 }
2560 }
2561 }
2562
2563 if (pcrel)
2564 {
2565 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type);
2566 if (add_symbolP == 0)
2567 {
2568 #ifndef BFD_ASSEMBLER
2569 fixP->fx_addsy = &abs_symbol;
2570 #else
2571 fixP->fx_addsy = section_symbol (absolute_section);
2572 #endif
2573 fixP->fx_addsy->sy_used_in_reloc = 1;
2574 ++seg_reloc_count;
2575 }
2576 }
2577
2578 if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && size > 0)
2579 {
2580 if (size < sizeof (valueT))
2581 {
2582 valueT mask, hibit;
2583
2584 /* set all bits to one */
2585 mask = 0;
2586 mask--;
2587 /* Technically, combining these produces an undefined result
2588 if size is sizeof (valueT), though I think these two
2589 half-way operations should both be defined. And the
2590 compiler should be able to combine them if it's valid on
2591 the host architecture. */
2592 mask <<= size * 4;
2593 mask <<= size * 4;
2594 hibit = (valueT) 1 << (size * 8 - 1);
2595 if (((add_number & mask) != 0
2596 || (fixP->fx_signed
2597 && (add_number & hibit) != 0))
2598 && ((add_number & mask) != mask
2599 || (add_number & hibit) == 0))
2600 {
2601 char buf[50], buf2[50];
2602 sprint_value (buf, fragP->fr_address + where);
2603 if (add_number > 1000)
2604 sprint_value (buf2, add_number);
2605 else
2606 sprintf (buf2, "%ld", (long) add_number);
2607 as_bad_where (fixP->fx_file, fixP->fx_line,
2608 "Value of %s too large for field of %d bytes at %s",
2609 buf2, size, buf);
2610 } /* generic error checking */
2611 }
2612 #ifdef WARN_SIGNED_OVERFLOW_WORD
2613 /* Warn if a .word value is too large when treated as a signed
2614 number. We already know it is not too negative. This is to
2615 catch over-large switches generated by gcc on the 68k. */
2616 if (!flag_signed_overflow_ok
2617 && size == 2
2618 && add_number > 0x7fff)
2619 as_bad_where (fixP->fx_file, fixP->fx_line,
2620 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
2621 (long) add_number,
2622 (unsigned long) (fragP->fr_address + where));
2623 #endif
2624 } /* not a bit fix */
2625
2626 if (!fixP->fx_done)
2627 {
2628 #ifdef MD_APPLY_FIX3
2629 md_apply_fix3 (fixP, &add_number, this_segment_type);
2630 #else
2631 #ifdef BFD_ASSEMBLER
2632 md_apply_fix (fixP, &add_number);
2633 #else
2634 md_apply_fix (fixP, add_number);
2635 #endif
2636 #endif
2637
2638 #ifndef TC_HANDLES_FX_DONE
2639 /* If the tc-* files haven't been converted, assume it's handling
2640 it the old way, where a null fx_addsy means that the fix has
2641 been applied completely, and no further work is needed. */
2642 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)
2643 fixP->fx_done = 1;
2644 #endif
2645 }
2646 #ifdef TC_VALIDATE_FIX
2647 skip: ;
2648 #endif
2649 #ifdef DEBUG5
2650 fprintf (stderr, "result:\n");
2651 print_fixup (fixP);
2652 #endif
2653 } /* For each fixS in this segment. */
2654
2655 TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
2656 return seg_reloc_count;
2657 }
2658
2659 #endif /* defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) */
2660
2661 void
2662 number_to_chars_bigendian (buf, val, n)
2663 char *buf;
2664 valueT val;
2665 int n;
2666 {
2667 if (n > sizeof (val)|| n <= 0)
2668 abort ();
2669 while (n--)
2670 {
2671 buf[n] = val & 0xff;
2672 val >>= 8;
2673 }
2674 }
2675
2676 void
2677 number_to_chars_littleendian (buf, val, n)
2678 char *buf;
2679 valueT val;
2680 int n;
2681 {
2682 if (n > sizeof (val) || n <= 0)
2683 abort ();
2684 while (n--)
2685 {
2686 *buf++ = val & 0xff;
2687 val >>= 8;
2688 }
2689 }
2690
2691 void
2692 write_print_statistics (file)
2693 FILE *file;
2694 {
2695 fprintf (stderr, "fixups: %d\n", n_fixups);
2696 }
2697
2698 /* for debugging */
2699 extern int indent_level;
2700 extern void print_symbol_value_1 ();
2701
2702 void
2703 print_fixup (fixp)
2704 fixS *fixp;
2705 {
2706 indent_level = 1;
2707 fprintf (stderr, "fix %lx %s:%d", (long) fixp, fixp->fx_file, fixp->fx_line);
2708 if (fixp->fx_pcrel)
2709 fprintf (stderr, " pcrel");
2710 if (fixp->fx_pcrel_adjust)
2711 fprintf (stderr, " pcrel_adjust=%d", fixp->fx_pcrel_adjust);
2712 if (fixp->fx_im_disp)
2713 {
2714 #ifdef TC_NS32K
2715 fprintf (stderr, " im_disp=%d", fixp->fx_im_disp);
2716 #else
2717 fprintf (stderr, " im_disp");
2718 #endif
2719 }
2720 if (fixp->fx_tcbit)
2721 fprintf (stderr, " tcbit");
2722 if (fixp->fx_done)
2723 fprintf (stderr, " done");
2724 fprintf (stderr, "\n size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
2725 fixp->fx_size, (long) fixp->fx_frag, (long) fixp->fx_where,
2726 (long) fixp->fx_offset, (long) fixp->fx_addnumber);
2727 #ifdef BFD_ASSEMBLER
2728 fprintf (stderr, "\n %s (%d)", bfd_get_reloc_code_name (fixp->fx_r_type),
2729 fixp->fx_r_type);
2730 #else
2731 #ifdef NEED_FX_R_TYPE
2732 fprintf (stderr, " r_type=%d", fixp->fx_r_type);
2733 #endif
2734 #endif
2735 if (fixp->fx_addsy)
2736 {
2737 fprintf (stderr, "\n +<");
2738 print_symbol_value_1 (stderr, fixp->fx_addsy);
2739 fprintf (stderr, ">");
2740 }
2741 if (fixp->fx_subsy)
2742 {
2743 fprintf (stderr, "\n -<");
2744 print_symbol_value_1 (stderr, fixp->fx_subsy);
2745 fprintf (stderr, ">");
2746 }
2747 fprintf (stderr, "\n");
2748 }
2749
2750 /* end of write.c */