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