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
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
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)
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.
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
23 /* This thing should be set up to do byteordering correctly. But... */
28 #include "output-file.h"
29 #include "dwarf2dbg.h"
32 #ifndef TC_ADJUST_RELOC_COUNT
33 #define TC_ADJUST_RELOC_COUNT(FIX, COUNT)
36 #ifndef TC_FORCE_RELOCATION
37 #define TC_FORCE_RELOCATION(FIX) \
38 (generic_force_reloc (FIX))
41 #ifndef TC_FORCE_RELOCATION_ABS
42 #define TC_FORCE_RELOCATION_ABS(FIX) \
43 (TC_FORCE_RELOCATION (FIX))
46 #ifndef TC_FORCE_RELOCATION_LOCAL
47 #define TC_FORCE_RELOCATION_LOCAL(FIX) \
49 || TC_FORCE_RELOCATION (FIX))
52 #ifndef TC_FORCE_RELOCATION_SUB_SAME
53 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) \
57 #ifndef TC_FORCE_RELOCATION_SUB_ABS
58 #define TC_FORCE_RELOCATION_SUB_ABS(FIX) 0
61 #ifndef TC_FORCE_RELOCATION_SUB_LOCAL
63 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 0
65 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 1
69 #ifndef TC_VALIDATE_FIX_SUB
70 #ifdef UNDEFINED_DIFFERENCE_OK
71 /* The PA needs this for PIC code generation. */
72 #define TC_VALIDATE_FIX_SUB(FIX) 1
74 #define TC_VALIDATE_FIX_SUB(FIX) \
75 ((FIX)->fx_r_type == BFD_RELOC_GPREL32 \
76 || (FIX)->fx_r_type == BFD_RELOC_GPREL16)
80 #ifndef TC_LINKRELAX_FIXUP
81 #define TC_LINKRELAX_FIXUP(SEG) 1
84 #ifndef MD_APPLY_SYM_VALUE
85 #define MD_APPLY_SYM_VALUE(FIX) 1
88 #ifndef TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
89 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 1
92 #ifndef MD_PCREL_FROM_SECTION
93 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX)
97 #define TC_FAKE_LABEL(NAME) (strcmp ((NAME), FAKE_LABEL_NAME) == 0)
100 /* Positive values of TC_FX_SIZE_SLACK allow a target to define
101 fixups that far past the end of a frag. Having such fixups
102 is of course most most likely a bug in setting fx_size correctly.
103 A negative value disables the fixup check entirely, which is
104 appropriate for something like the Renesas / SuperH SH_COUNT
106 #ifndef TC_FX_SIZE_SLACK
107 #define TC_FX_SIZE_SLACK(FIX) 0
110 /* Used to control final evaluation of expressions. */
111 int finalize_syms
= 0;
113 int symbol_table_frozen
;
115 symbolS
*abs_section_sym
;
117 /* Remember the value of dot when parsing expressions. */
120 /* Relocs generated by ".reloc" pseudo. */
121 struct reloc_list
* reloc_list
;
123 void print_fixup (fixS
*);
125 /* We generally attach relocs to frag chains. However, after we have
126 chained these all together into a segment, any relocs we add after
127 that must be attached to a segment. This will include relocs added
128 in md_estimate_size_for_relax, for example. */
129 static int frags_chained
= 0;
133 #define RELOC_ENUM enum bfd_reloc_code_real
135 /* Create a fixS in obstack 'notes'. */
138 fix_new_internal (fragS
*frag
, /* Which frag? */
139 int where
, /* Where in that frag? */
140 int size
, /* 1, 2, or 4 usually. */
141 symbolS
*add_symbol
, /* X_add_symbol. */
142 symbolS
*sub_symbol
, /* X_op_symbol. */
143 offsetT offset
, /* X_add_number. */
144 int pcrel
, /* TRUE if PC-relative relocation. */
145 RELOC_ENUM r_type ATTRIBUTE_UNUSED
/* Relocation type. */)
151 fixP
= obstack_alloc (¬es
, sizeof (fixS
));
153 frag
->nacl_fixup
= fixP
;
155 fixP
->fx_frag
= frag
;
156 fixP
->fx_where
= where
;
157 fixP
->fx_size
= size
;
158 /* We've made fx_size a narrow field; check that it's wide enough. */
159 if (fixP
->fx_size
!= size
)
161 as_bad (_("field fx_size too small to hold %d"), size
);
164 fixP
->fx_addsy
= add_symbol
;
165 fixP
->fx_subsy
= sub_symbol
;
166 fixP
->fx_offset
= offset
;
167 fixP
->fx_dot_value
= dot_value
;
168 fixP
->fx_pcrel
= pcrel
;
169 fixP
->fx_r_type
= r_type
;
170 fixP
->fx_im_disp
= 0;
171 fixP
->fx_pcrel_adjust
= 0;
172 fixP
->fx_bit_fixP
= 0;
173 fixP
->fx_addnumber
= 0;
177 fixP
->fx_no_overflow
= 0;
181 fixP
->fx_cgen
.insn
= NULL
;
182 fixP
->fx_cgen
.opinfo
= 0;
186 TC_INIT_FIX_DATA (fixP
);
189 as_where (&fixP
->fx_file
, &fixP
->fx_line
);
191 /* Usually, we want relocs sorted numerically, but while
192 comparing to older versions of gas that have relocs
193 reverse sorted, it is convenient to have this compile
194 time option. xoxorich. */
197 fixS
**seg_fix_rootP
= (frags_chained
198 ? &seg_info (now_seg
)->fix_root
199 : &frchain_now
->fix_root
);
200 fixS
**seg_fix_tailP
= (frags_chained
201 ? &seg_info (now_seg
)->fix_tail
202 : &frchain_now
->fix_tail
);
204 #ifdef REVERSE_SORT_RELOCS
206 fixP
->fx_next
= *seg_fix_rootP
;
207 *seg_fix_rootP
= fixP
;
209 #else /* REVERSE_SORT_RELOCS */
211 fixP
->fx_next
= NULL
;
214 (*seg_fix_tailP
)->fx_next
= fixP
;
216 *seg_fix_rootP
= fixP
;
217 *seg_fix_tailP
= fixP
;
219 #endif /* REVERSE_SORT_RELOCS */
225 /* Create a fixup relative to a symbol (plus a constant). */
228 fix_new (fragS
*frag
, /* Which frag? */
229 int where
, /* Where in that frag? */
230 int size
, /* 1, 2, or 4 usually. */
231 symbolS
*add_symbol
, /* X_add_symbol. */
232 offsetT offset
, /* X_add_number. */
233 int pcrel
, /* TRUE if PC-relative relocation. */
234 RELOC_ENUM r_type
/* Relocation type. */)
236 return fix_new_internal (frag
, where
, size
, add_symbol
,
237 (symbolS
*) NULL
, offset
, pcrel
, r_type
);
240 /* Create a fixup for an expression. Currently we only support fixups
241 for difference expressions. That is itself more than most object
242 file formats support anyhow. */
245 fix_new_exp (fragS
*frag
, /* Which frag? */
246 int where
, /* Where in that frag? */
247 int size
, /* 1, 2, or 4 usually. */
248 expressionS
*exp
, /* Expression. */
249 int pcrel
, /* TRUE if PC-relative relocation. */
250 RELOC_ENUM r_type
/* Relocation type. */)
262 as_bad (_("register value used as expression"));
266 /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
267 the difference expression cannot immediately be reduced. */
269 symbolS
*stmp
= make_expr_symbol (exp
);
271 exp
->X_op
= O_symbol
;
272 exp
->X_op_symbol
= 0;
273 exp
->X_add_symbol
= stmp
;
274 exp
->X_add_number
= 0;
276 return fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
280 add
= exp
->X_add_symbol
;
281 off
= exp
->X_add_number
;
282 r_type
= BFD_RELOC_RVA
;
286 sub
= exp
->X_add_symbol
;
287 off
= exp
->X_add_number
;
291 sub
= exp
->X_op_symbol
;
294 add
= exp
->X_add_symbol
;
297 off
= exp
->X_add_number
;
301 add
= make_expr_symbol (exp
);
305 return fix_new_internal (frag
, where
, size
, add
, sub
, off
, pcrel
, r_type
);
308 /* Generic function to determine whether a fixup requires a relocation. */
310 generic_force_reloc (fixS
*fix
)
312 if (fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
313 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
316 if (fix
->fx_addsy
== NULL
)
319 return S_FORCE_RELOC (fix
->fx_addsy
, fix
->fx_subsy
== NULL
);
322 /* Append a string onto another string, bumping the pointer along. */
324 append (char **charPP
, char *fromP
, unsigned long length
)
326 /* Don't trust memcpy() of 0 chars. */
330 memcpy (*charPP
, fromP
, length
);
334 /* This routine records the largest alignment seen for each segment.
335 If the beginning of the segment is aligned on the worst-case
336 boundary, all of the other alignments within it will work. At
337 least one object format really uses this info. */
340 record_alignment (/* Segment to which alignment pertains. */
342 /* Alignment, as a power of 2 (e.g., 1 => 2-byte
343 boundary, 2 => 4-byte boundary, etc.) */
346 if (seg
== absolute_section
)
349 if ((unsigned int) align
> bfd_get_section_alignment (stdoutput
, seg
))
350 bfd_set_section_alignment (stdoutput
, seg
, align
);
354 get_recorded_alignment (segT seg
)
356 if (seg
== absolute_section
)
359 return bfd_get_section_alignment (stdoutput
, seg
);
362 /* Reset the section indices after removing the gas created sections. */
365 renumber_sections (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *countparg
)
367 int *countp
= (int *) countparg
;
369 sec
->index
= *countp
;
374 chain_frchains_together_1 (segT section
, struct frchain
*frchp
)
376 fragS dummy
, *prev_frag
= &dummy
;
377 fixS fix_dummy
, *prev_fix
= &fix_dummy
;
379 for (; frchp
; frchp
= frchp
->frch_next
)
381 prev_frag
->fr_next
= frchp
->frch_root
;
382 prev_frag
= frchp
->frch_last
;
383 assert (prev_frag
->fr_type
!= 0);
384 if (frchp
->fix_root
!= (fixS
*) NULL
)
386 if (seg_info (section
)->fix_root
== (fixS
*) NULL
)
387 seg_info (section
)->fix_root
= frchp
->fix_root
;
388 prev_fix
->fx_next
= frchp
->fix_root
;
389 seg_info (section
)->fix_tail
= frchp
->fix_tail
;
390 prev_fix
= frchp
->fix_tail
;
393 assert (prev_frag
->fr_type
!= 0);
394 assert (prev_frag
!= &dummy
);
395 prev_frag
->fr_next
= 0;
400 chain_frchains_together (bfd
*abfd ATTRIBUTE_UNUSED
,
402 void *xxx ATTRIBUTE_UNUSED
)
404 segment_info_type
*info
;
406 /* BFD may have introduced its own sections without using
407 subseg_new, so it is possible that seg_info is NULL. */
408 info
= seg_info (section
);
409 if (info
!= (segment_info_type
*) NULL
)
410 info
->frchainP
->frch_last
411 = chain_frchains_together_1 (section
, info
->frchainP
);
413 /* Now that we've chained the frags together, we must add new fixups
414 to the segment, not to the frag chain. */
419 move_call_insn_to_end(fragS
*fragP
, fragS
*next ATTRIBUTE_UNUSED
)
421 if (fragP
->fr_offset
!= 0) {
422 // fragP->fr_fix is the start of the fixup code (i.e. nops).
424 unsigned char *tmp
= alloca(fragP
->fr_fix
);
425 memcpy(tmp
, fragP
->fr_literal
, fragP
->fr_fix
);
426 for (i
= 0; i
< fragP
->fr_var
; i
++) {
427 fragP
->fr_literal
[i
] = fragP
->fr_literal
[fragP
->fr_fix
+i
];
429 for (i
= 0; i
< fragP
->fr_fix
; i
++) {
430 fragP
->fr_literal
[fragP
->fr_var
+i
] = tmp
[i
];
432 // TODO: this code should be obsolete. Remove it.
433 // If it was a direct call, there's a fixup for the target address.
434 // This needs to corrected to point to the new location of the
435 // constant after we moved the nops.
436 // If there is no fixup, but this is a call, then it is an indirect
437 // call, and we need to put in the fixups for the sandbox code.
438 if (fragP
->nacl_fixup
) {
439 fragP
->nacl_fixup
->fx_where
+= fragP
->fr_var
;
441 else if (getenv("NACL_CONTROL_ENFORCE_RANGE")) {
442 symbolS
* and_mask
= symbol_find_or_make("__nacl_and_mask");
443 symbolS
* exec_start
= symbol_find_or_make("__executable_start");
444 fix_new (fragP
, 2+fragP
->fr_var
, 4, and_mask
, 0, 0, BFD_RELOC_32
);
445 fix_new (fragP
, 8+fragP
->fr_var
, 4, exec_start
, 0, 0, BFD_RELOC_32
);
451 cvt_frag_to_fill (segT sec ATTRIBUTE_UNUSED
, fragS
*fragP
)
453 switch (fragP
->fr_type
)
461 HANDLE_ALIGN (fragP
);
463 know (fragP
->fr_next
!= NULL
);
464 fragP
->fr_offset
= (fragP
->fr_next
->fr_address
466 - fragP
->fr_fix
) / fragP
->fr_var
;
467 if (fragP
->fr_offset
< 0)
469 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
470 _("attempt to .org/.space backwards? (%ld)"),
471 (long) fragP
->fr_offset
);
472 fragP
->fr_offset
= 0;
475 if (fragP
->is_call
&& (nacl_alignment
> 0)) {
476 move_call_insn_to_end(fragP
, NULL
);
478 fragP
->fr_type
= rs_fill
;
486 valueT value
= S_GET_VALUE (fragP
->fr_symbol
);
489 size
= output_leb128 (fragP
->fr_literal
+ fragP
->fr_fix
, value
,
492 fragP
->fr_fix
+= size
;
493 fragP
->fr_type
= rs_fill
;
495 fragP
->fr_offset
= 0;
496 fragP
->fr_symbol
= NULL
;
501 eh_frame_convert_frag (fragP
);
505 dwarf2dbg_convert_frag (fragP
);
508 case rs_machine_dependent
:
509 md_convert_frag (stdoutput
, sec
, fragP
);
511 assert (fragP
->fr_next
== NULL
512 || ((offsetT
) (fragP
->fr_next
->fr_address
- fragP
->fr_address
)
515 /* After md_convert_frag, we make the frag into a ".space 0".
516 md_convert_frag() should set up any fixSs and constants
521 #ifndef WORKING_DOT_WORD
524 struct broken_word
*lie
;
526 if (fragP
->fr_subtype
)
528 fragP
->fr_fix
+= md_short_jump_size
;
529 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
530 lie
&& lie
->dispfrag
== fragP
;
531 lie
= lie
->next_broken_word
)
533 fragP
->fr_fix
+= md_long_jump_size
;
541 BAD_CASE (fragP
->fr_type
);
545 md_frag_check (fragP
);
549 struct relax_seg_info
556 relax_seg (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *xxx
)
558 segment_info_type
*seginfo
= seg_info (sec
);
559 struct relax_seg_info
*info
= (struct relax_seg_info
*) xxx
;
561 if (seginfo
&& seginfo
->frchainP
562 && relax_segment (seginfo
->frchainP
->frch_root
, sec
, info
->pass
))
567 size_seg (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
571 segment_info_type
*seginfo
;
573 valueT size
, newsize
;
575 subseg_change (sec
, 0);
577 seginfo
= seg_info (sec
);
578 if (seginfo
&& seginfo
->frchainP
)
580 for (fragp
= seginfo
->frchainP
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
581 cvt_frag_to_fill (sec
, fragp
);
582 for (fragp
= seginfo
->frchainP
->frch_root
;
584 fragp
= fragp
->fr_next
)
585 /* Walk to last elt. */
587 size
= fragp
->fr_address
+ fragp
->fr_fix
;
592 flags
= bfd_get_section_flags (abfd
, sec
);
594 if (size
> 0 && ! seginfo
->bss
)
595 flags
|= SEC_HAS_CONTENTS
;
598 x
= bfd_set_section_flags (abfd
, sec
, flags
);
601 newsize
= md_section_align (sec
, size
);
602 x
= bfd_set_section_size (abfd
, sec
, newsize
);
605 /* If the size had to be rounded up, add some padding in the last
607 assert (newsize
>= size
);
610 fragS
*last
= seginfo
->frchainP
->frch_last
;
611 fragp
= seginfo
->frchainP
->frch_root
;
612 while (fragp
->fr_next
!= last
)
613 fragp
= fragp
->fr_next
;
614 last
->fr_address
= size
;
615 if ((newsize
- size
) % fragp
->fr_var
== 0)
616 fragp
->fr_offset
+= (newsize
- size
) / fragp
->fr_var
;
618 /* If we hit this abort, it's likely due to subsegs_finish not
619 providing sufficient alignment on the last frag, and the
620 machine dependent code using alignment frags with fr_var
625 #ifdef tc_frob_section
626 tc_frob_section (sec
);
628 #ifdef obj_frob_section
629 obj_frob_section (sec
);
635 dump_section_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, FILE *stream
)
637 segment_info_type
*seginfo
= seg_info (sec
);
638 fixS
*fixp
= seginfo
->fix_root
;
643 fprintf (stream
, "sec %s relocs:\n", sec
->name
);
646 symbolS
*s
= fixp
->fx_addsy
;
648 fprintf (stream
, " %08lx: type %d ", (unsigned long) fixp
,
649 (int) fixp
->fx_r_type
);
651 fprintf (stream
, "no sym\n");
654 print_symbol_value_1 (stream
, s
);
655 fprintf (stream
, "\n");
657 fixp
= fixp
->fx_next
;
661 #define dump_section_relocs(ABFD,SEC,STREAM) ((void) 0)
664 #ifndef EMIT_SECTION_SYMBOLS
665 #define EMIT_SECTION_SYMBOLS 1
668 /* Resolve U.A.OFFSET_SYM and U.A.SYM fields of RELOC_LIST entries,
669 and check for validity. Convert RELOC_LIST from using U.A fields
672 resolve_reloc_expr_symbols (void)
674 struct reloc_list
*r
;
676 for (r
= reloc_list
; r
; r
= r
->next
)
680 bfd_vma offset
, addend
;
682 reloc_howto_type
*howto
;
684 resolve_symbol_value (r
->u
.a
.offset_sym
);
685 symval
= symbol_get_value_expression (r
->u
.a
.offset_sym
);
689 if (symval
->X_op
== O_constant
)
690 sym
= r
->u
.a
.offset_sym
;
691 else if (symval
->X_op
== O_symbol
)
693 sym
= symval
->X_add_symbol
;
694 offset
= symval
->X_add_number
;
695 symval
= symbol_get_value_expression (symval
->X_add_symbol
);
698 || symval
->X_op
!= O_constant
699 || (sec
= S_GET_SEGMENT (sym
)) == NULL
700 || !SEG_NORMAL (sec
))
702 as_bad_where (r
->file
, r
->line
, _("invalid offset expression"));
706 offset
+= S_GET_VALUE (sym
);
709 addend
= r
->u
.a
.addend
;
710 if (r
->u
.a
.sym
!= NULL
)
712 resolve_symbol_value (r
->u
.a
.sym
);
713 symval
= symbol_get_value_expression (r
->u
.a
.sym
);
714 if (symval
->X_op
== O_constant
)
716 else if (symval
->X_op
== O_symbol
)
718 sym
= symval
->X_add_symbol
;
719 addend
+= symval
->X_add_number
;
720 symval
= symbol_get_value_expression (symval
->X_add_symbol
);
722 if (symval
->X_op
!= O_constant
)
724 as_bad_where (r
->file
, r
->line
, _("invalid reloc expression"));
727 else if (sym
!= NULL
)
728 symbol_mark_used_in_reloc (sym
);
732 if (abs_section_sym
== NULL
)
733 abs_section_sym
= section_symbol (absolute_section
);
734 sym
= abs_section_sym
;
737 howto
= r
->u
.a
.howto
;
740 r
->u
.b
.s
= symbol_get_bfdsym (sym
);
741 r
->u
.b
.r
.sym_ptr_ptr
= &r
->u
.b
.s
;
742 r
->u
.b
.r
.address
= offset
;
743 r
->u
.b
.r
.addend
= addend
;
744 r
->u
.b
.r
.howto
= howto
;
748 /* This pass over fixups decides whether symbols can be replaced with
752 adjust_reloc_syms (bfd
*abfd ATTRIBUTE_UNUSED
,
754 void *xxx ATTRIBUTE_UNUSED
)
756 segment_info_type
*seginfo
= seg_info (sec
);
762 dump_section_relocs (abfd
, sec
, stderr
);
764 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
768 else if (fixp
->fx_addsy
)
774 fprintf (stderr
, "\n\nadjusting fixup:\n");
778 sym
= fixp
->fx_addsy
;
780 /* All symbols should have already been resolved at this
781 point. It is possible to see unresolved expression
782 symbols, though, since they are not in the regular symbol
784 resolve_symbol_value (sym
);
786 if (fixp
->fx_subsy
!= NULL
)
787 resolve_symbol_value (fixp
->fx_subsy
);
789 /* If this symbol is equated to an undefined or common symbol,
790 convert the fixup to being against that symbol. */
791 while (symbol_equated_reloc_p (sym
)
792 || S_IS_WEAKREFR (sym
))
794 symbolS
*newsym
= symbol_get_value_expression (sym
)->X_add_symbol
;
797 fixp
->fx_offset
+= symbol_get_value_expression (sym
)->X_add_number
;
798 fixp
->fx_addsy
= newsym
;
802 if (symbol_mri_common_p (sym
))
804 fixp
->fx_offset
+= S_GET_VALUE (sym
);
805 fixp
->fx_addsy
= symbol_get_value_expression (sym
)->X_add_symbol
;
809 /* If the symbol is undefined, common, weak, or global (ELF
810 shared libs), we can't replace it with the section symbol. */
811 if (S_FORCE_RELOC (fixp
->fx_addsy
, 1))
814 /* Is there some other (target cpu dependent) reason we can't adjust
815 this one? (E.g. relocations involving function addresses on
817 #ifdef tc_fix_adjustable
818 if (! tc_fix_adjustable (fixp
))
822 /* Since we're reducing to section symbols, don't attempt to reduce
823 anything that's already using one. */
824 if (symbol_section_p (sym
))
827 symsec
= S_GET_SEGMENT (sym
);
831 if (bfd_is_abs_section (symsec
))
833 /* The fixup_segment routine normally will not use this
834 symbol in a relocation. */
838 /* Don't try to reduce relocs which refer to non-local symbols
839 in .linkonce sections. It can lead to confusion when a
840 debugging section refers to a .linkonce section. I hope
841 this will always be correct. */
842 if (symsec
!= sec
&& ! S_IS_LOCAL (sym
))
844 if ((symsec
->flags
& SEC_LINK_ONCE
) != 0
846 /* The GNU toolchain uses an extension for ELF: a
847 section beginning with the magic string
848 .gnu.linkonce is a linkonce section. */
849 && strncmp (segment_name (symsec
), ".gnu.linkonce",
850 sizeof ".gnu.linkonce" - 1) == 0))
854 /* Never adjust a reloc against local symbol in a merge section
855 with non-zero addend. */
856 if ((symsec
->flags
& SEC_MERGE
) != 0
857 && (fixp
->fx_offset
!= 0 || fixp
->fx_subsy
!= NULL
))
860 /* Never adjust a reloc against TLS local symbol. */
861 if ((symsec
->flags
& SEC_THREAD_LOCAL
) != 0)
864 /* We refetch the segment when calling section_symbol, rather
865 than using symsec, because S_GET_VALUE may wind up changing
866 the section when it calls resolve_symbol_value. */
867 fixp
->fx_offset
+= S_GET_VALUE (sym
);
868 fixp
->fx_addsy
= section_symbol (S_GET_SEGMENT (sym
));
870 fprintf (stderr
, "\nadjusted fixup:\n");
875 dump_section_relocs (abfd
, sec
, stderr
);
880 Go through all the fixS's in a segment and see which ones can be
881 handled now. (These consist of fixS where we have since discovered
882 the value of a symbol, or the address of the frag involved.)
883 For each one, call md_apply_fix to put the fix into the frag data.
885 Result is a count of how many relocation structs will be needed to
886 handle the remaining fixS's that we couldn't completely handle here.
887 These will be output later by emit_relocations(). */
890 fixup_segment (fixS
*fixP
, segT this_segment
)
892 long seg_reloc_count
= 0;
895 segT add_symbol_segment
= absolute_section
;
897 if (fixP
!= NULL
&& abs_section_sym
== NULL
)
898 abs_section_sym
= section_symbol (absolute_section
);
900 /* If the linker is doing the relaxing, we must not do any fixups.
902 Well, strictly speaking that's not true -- we could do any that
903 are PC-relative and don't cross regions that could change size.
904 And for the i960 we might be able to turn callx/callj into bal
905 anyways in cases where we know the maximum displacement. */
906 if (linkrelax
&& TC_LINKRELAX_FIXUP (this_segment
))
908 for (; fixP
; fixP
= fixP
->fx_next
)
911 if (fixP
->fx_addsy
== NULL
)
913 /* There was no symbol required by this relocation.
914 However, BFD doesn't really handle relocations
915 without symbols well. So fake up a local symbol in
916 the absolute section. */
917 fixP
->fx_addsy
= abs_section_sym
;
919 symbol_mark_used_in_reloc (fixP
->fx_addsy
);
920 if (fixP
->fx_subsy
!= NULL
)
921 symbol_mark_used_in_reloc (fixP
->fx_subsy
);
924 TC_ADJUST_RELOC_COUNT (fixP
, seg_reloc_count
);
925 return seg_reloc_count
;
928 for (; fixP
; fixP
= fixP
->fx_next
)
931 fprintf (stderr
, "\nprocessing fixup:\n");
935 fragP
= fixP
->fx_frag
;
937 #ifdef TC_VALIDATE_FIX
938 TC_VALIDATE_FIX (fixP
, this_segment
, skip
);
940 add_number
= fixP
->fx_offset
;
942 if (fixP
->fx_addsy
!= NULL
)
943 add_symbol_segment
= S_GET_SEGMENT (fixP
->fx_addsy
);
945 if (fixP
->fx_subsy
!= NULL
)
947 segT sub_symbol_segment
;
948 resolve_symbol_value (fixP
->fx_subsy
);
949 sub_symbol_segment
= S_GET_SEGMENT (fixP
->fx_subsy
);
950 if (fixP
->fx_addsy
!= NULL
951 && sub_symbol_segment
== add_symbol_segment
952 && !TC_FORCE_RELOCATION_SUB_SAME (fixP
, add_symbol_segment
))
954 add_number
+= S_GET_VALUE (fixP
->fx_addsy
);
955 add_number
-= S_GET_VALUE (fixP
->fx_subsy
);
956 fixP
->fx_offset
= add_number
;
957 fixP
->fx_addsy
= NULL
;
958 fixP
->fx_subsy
= NULL
;
960 /* See the comment below about 68k weirdness. */
964 else if (sub_symbol_segment
== absolute_section
965 && !TC_FORCE_RELOCATION_SUB_ABS (fixP
))
967 add_number
-= S_GET_VALUE (fixP
->fx_subsy
);
968 fixP
->fx_offset
= add_number
;
969 fixP
->fx_subsy
= NULL
;
971 else if (sub_symbol_segment
== this_segment
972 && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP
))
974 add_number
-= S_GET_VALUE (fixP
->fx_subsy
);
975 fixP
->fx_offset
= (add_number
+ fixP
->fx_dot_value
976 + fixP
->fx_frag
->fr_address
);
978 /* Make it pc-relative. If the back-end code has not
979 selected a pc-relative reloc, cancel the adjustment
980 we do later on all pc-relative relocs. */
983 /* Do this for m68k even if it's already described
984 as pc-relative. On the m68k, an operand of
985 "pc@(foo-.-2)" should address "foo" in a
990 add_number
+= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
991 fixP
->fx_subsy
= NULL
;
994 else if (!TC_VALIDATE_FIX_SUB (fixP
))
996 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
997 _("can't resolve `%s' {%s section} - `%s' {%s section}"),
998 fixP
->fx_addsy
? S_GET_NAME (fixP
->fx_addsy
) : "0",
999 segment_name (add_symbol_segment
),
1000 S_GET_NAME (fixP
->fx_subsy
),
1001 segment_name (sub_symbol_segment
));
1007 if (add_symbol_segment
== this_segment
1008 && !TC_FORCE_RELOCATION_LOCAL (fixP
))
1010 /* This fixup was made when the symbol's segment was
1011 SEG_UNKNOWN, but it is now in the local segment.
1012 So we know how to do the address without relocation. */
1013 add_number
+= S_GET_VALUE (fixP
->fx_addsy
);
1014 fixP
->fx_offset
= add_number
;
1016 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
1017 fixP
->fx_addsy
= NULL
;
1020 else if (add_symbol_segment
== absolute_section
1021 && !TC_FORCE_RELOCATION_ABS (fixP
))
1023 add_number
+= S_GET_VALUE (fixP
->fx_addsy
);
1024 fixP
->fx_offset
= add_number
;
1025 fixP
->fx_addsy
= NULL
;
1027 else if (add_symbol_segment
!= undefined_section
1028 && ! bfd_is_com_section (add_symbol_segment
)
1029 && MD_APPLY_SYM_VALUE (fixP
))
1030 add_number
+= S_GET_VALUE (fixP
->fx_addsy
);
1035 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
1036 if (!fixP
->fx_done
&& fixP
->fx_addsy
== NULL
)
1038 /* There was no symbol required by this relocation.
1039 However, BFD doesn't really handle relocations
1040 without symbols well. So fake up a local symbol in
1041 the absolute section. */
1042 fixP
->fx_addsy
= abs_section_sym
;
1047 md_apply_fix (fixP
, &add_number
, this_segment
);
1052 if (fixP
->fx_addsy
== NULL
)
1053 fixP
->fx_addsy
= abs_section_sym
;
1054 symbol_mark_used_in_reloc (fixP
->fx_addsy
);
1055 if (fixP
->fx_subsy
!= NULL
)
1056 symbol_mark_used_in_reloc (fixP
->fx_subsy
);
1059 if (!fixP
->fx_bit_fixP
&& !fixP
->fx_no_overflow
&& fixP
->fx_size
!= 0)
1061 if (fixP
->fx_size
< sizeof (valueT
))
1066 mask
--; /* Set all bits to one. */
1067 mask
<<= fixP
->fx_size
* 8 - (fixP
->fx_signed
? 1 : 0);
1068 if ((add_number
& mask
) != 0 && (add_number
& mask
) != mask
)
1070 char buf
[50], buf2
[50];
1071 sprint_value (buf
, fragP
->fr_address
+ fixP
->fx_where
);
1072 if (add_number
> 1000)
1073 sprint_value (buf2
, add_number
);
1075 sprintf (buf2
, "%ld", (long) add_number
);
1076 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1077 _("value of %s too large for field of %d bytes at %s"),
1078 buf2
, fixP
->fx_size
, buf
);
1079 } /* Generic error checking. */
1081 #ifdef WARN_SIGNED_OVERFLOW_WORD
1082 /* Warn if a .word value is too large when treated as a signed
1083 number. We already know it is not too negative. This is to
1084 catch over-large switches generated by gcc on the 68k. */
1085 if (!flag_signed_overflow_ok
1086 && fixP
->fx_size
== 2
1087 && add_number
> 0x7fff)
1088 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1089 _("signed .word overflow; switch may be too large; %ld at 0x%lx"),
1091 (long) (fragP
->fr_address
+ fixP
->fx_where
));
1093 } /* Not a bit fix. */
1095 #ifdef TC_VALIDATE_FIX
1096 skip
: ATTRIBUTE_UNUSED_LABEL
1100 fprintf (stderr
, "result:\n");
1103 } /* For each fixS in this segment. */
1105 TC_ADJUST_RELOC_COUNT (fixP
, seg_reloc_count
);
1106 return seg_reloc_count
;
1110 fix_segment (bfd
*abfd ATTRIBUTE_UNUSED
,
1112 void *xxx ATTRIBUTE_UNUSED
)
1114 segment_info_type
*seginfo
= seg_info (sec
);
1116 fixup_segment (seginfo
->fix_root
, sec
);
1120 install_reloc (asection
*sec
, arelent
*reloc
, fragS
*fragp
,
1121 char *file
, unsigned int line
)
1124 bfd_reloc_status_type s
;
1126 s
= bfd_install_relocation (stdoutput
, reloc
,
1127 fragp
->fr_literal
, fragp
->fr_address
,
1133 case bfd_reloc_overflow
:
1134 as_bad_where (file
, line
, _("relocation overflow"));
1136 case bfd_reloc_outofrange
:
1137 as_bad_where (file
, line
, _("relocation out of range"));
1140 as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"),
1146 write_relocs (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
1148 segment_info_type
*seginfo
= seg_info (sec
);
1151 struct reloc_list
*my_reloc_list
, **rp
, *r
;
1155 /* If seginfo is NULL, we did not create this section; don't do
1156 anything with it. */
1157 if (seginfo
== NULL
)
1161 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
1165 #ifdef RELOC_EXPANSION_POSSIBLE
1166 n
*= MAX_RELOC_EXPANSION
;
1169 /* Extract relocs for this section from reloc_list. */
1171 my_reloc_list
= NULL
;
1172 while ((r
= *rp
) != NULL
)
1174 if (r
->u
.b
.sec
== sec
)
1177 r
->next
= my_reloc_list
;
1185 relocs
= xcalloc (n
, sizeof (arelent
*));
1188 for (fixp
= seginfo
->fix_root
; fixp
!= (fixS
*) NULL
; fixp
= fixp
->fx_next
)
1192 /* NativeClient change here to handle moving calls. */
1199 fx_size
= fixp
->fx_size
;
1200 slack
= TC_FX_SIZE_SLACK (fixp
);
1202 fx_size
= fx_size
> slack
? fx_size
- slack
: 0;
1203 loc
= fixp
->fx_where
+ fx_size
;
1204 limitsize
= (fixp
->fx_frag
->is_call
?
1205 (fixp
->fx_frag
->fr_fix
+ fixp
->fx_frag
->fr_var
) :
1206 fixp
->fx_frag
->fr_fix
);
1207 if (slack
>= 0 && loc
> limitsize
)
1208 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1209 _("internal error: fixup not contained within frag"));
1211 #ifndef RELOC_EXPANSION_POSSIBLE
1213 arelent
*reloc
= tc_gen_reloc (sec
, fixp
);
1217 relocs
[i
++] = reloc
;
1222 arelent
**reloc
= tc_gen_reloc (sec
, fixp
);
1224 for (j
= 0; reloc
[j
]; j
++)
1225 relocs
[i
++] = reloc
[j
];
1229 for ( ; j
!= 0; --j
)
1230 install_reloc (sec
, relocs
[i
- j
], fixp
->fx_frag
,
1231 fixp
->fx_file
, fixp
->fx_line
);
1237 unsigned int i
, j
, nsyms
;
1239 sympp
= bfd_get_outsymbols (stdoutput
);
1240 nsyms
= bfd_get_symcount (stdoutput
);
1241 for (i
= 0; i
< n
; i
++)
1242 if (((*relocs
[i
]->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
1244 for (j
= 0; j
< nsyms
; j
++)
1245 if (sympp
[j
] == *relocs
[i
]->sym_ptr_ptr
)
1253 for (r
= my_reloc_list
; r
!= NULL
; r
= r
->next
)
1256 for (f
= seginfo
->frchainP
->frch_root
; f
; f
= f
->fr_next
)
1257 if (f
->fr_address
<= r
->u
.b
.r
.address
1258 && r
->u
.b
.r
.address
< f
->fr_address
+ f
->fr_fix
)
1261 as_bad_where (r
->file
, r
->line
,
1262 _("reloc not within (fixed part of) section"));
1265 relocs
[n
++] = &r
->u
.b
.r
;
1266 install_reloc (sec
, &r
->u
.b
.r
, f
, r
->file
, r
->line
);
1272 flagword flags
= bfd_get_section_flags (abfd
, sec
);
1274 bfd_set_section_flags (abfd
, sec
, flags
);
1275 bfd_set_reloc (stdoutput
, sec
, relocs
, n
);
1278 #ifdef SET_SECTION_RELOCS
1279 SET_SECTION_RELOCS (sec
, relocs
, n
);
1287 fprintf (stderr
, "relocs for sec %s\n", sec
->name
);
1288 for (i
= 0; i
< n
; i
++)
1291 s
= *r
->sym_ptr_ptr
;
1292 fprintf (stderr
, " reloc %2d @%p off %4lx : sym %-10s addend %lx\n",
1293 i
, r
, (unsigned long)r
->address
, s
->name
, (unsigned long)r
->addend
);
1300 write_contents (bfd
*abfd ATTRIBUTE_UNUSED
,
1302 void *xxx ATTRIBUTE_UNUSED
)
1304 segment_info_type
*seginfo
= seg_info (sec
);
1305 addressT offset
= 0;
1308 /* Write out the frags. */
1310 || !(bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
))
1313 for (f
= seginfo
->frchainP
->frch_root
;
1322 assert (f
->fr_type
== rs_fill
);
1325 x
= bfd_set_section_contents (stdoutput
, sec
,
1326 f
->fr_literal
, (file_ptr
) offset
,
1327 (bfd_size_type
) f
->fr_fix
);
1329 as_fatal (_("can't write %s: %s"), stdoutput
->filename
,
1330 bfd_errmsg (bfd_get_error ()));
1331 offset
+= f
->fr_fix
;
1333 fill_literal
= f
->fr_literal
+ f
->fr_fix
;
1334 fill_size
= f
->fr_var
;
1335 count
= f
->fr_offset
;
1336 assert (count
>= 0);
1337 if (fill_size
&& count
)
1340 if (fill_size
> sizeof (buf
))
1342 /* Do it the old way. Can this ever happen? */
1345 x
= bfd_set_section_contents (stdoutput
, sec
,
1348 (bfd_size_type
) fill_size
);
1350 as_fatal (_("can't write %s: %s"), stdoutput
->filename
,
1351 bfd_errmsg (bfd_get_error ()));
1352 offset
+= fill_size
;
1357 /* Build a buffer full of fill objects and output it as
1358 often as necessary. This saves on the overhead of
1359 potentially lots of bfd_set_section_contents calls. */
1363 n_per_buf
= sizeof (buf
);
1364 memset (buf
, *fill_literal
, n_per_buf
);
1369 n_per_buf
= sizeof (buf
) / fill_size
;
1370 for (i
= n_per_buf
, bufp
= buf
; i
; i
--, bufp
+= fill_size
)
1371 memcpy (bufp
, fill_literal
, fill_size
);
1373 for (; count
> 0; count
-= n_per_buf
)
1375 n_per_buf
= n_per_buf
> count
? count
: n_per_buf
;
1376 x
= bfd_set_section_contents
1377 (stdoutput
, sec
, buf
, (file_ptr
) offset
,
1378 (bfd_size_type
) n_per_buf
* fill_size
);
1380 as_fatal (_("cannot write to output file"));
1381 offset
+= n_per_buf
* fill_size
;
1389 merge_data_into_text (void)
1391 seg_info (text_section
)->frchainP
->frch_last
->fr_next
=
1392 seg_info (data_section
)->frchainP
->frch_root
;
1393 seg_info (text_section
)->frchainP
->frch_last
=
1394 seg_info (data_section
)->frchainP
->frch_last
;
1395 seg_info (data_section
)->frchainP
= 0;
1406 /* Count symbols. We can't rely on a count made by the loop in
1407 write_object_file, because *_frob_file may add a new symbol or
1410 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1416 bfd_size_type amt
= (bfd_size_type
) nsyms
* sizeof (asymbol
*);
1418 asympp
= bfd_alloc (stdoutput
, amt
);
1419 symp
= symbol_rootP
;
1420 for (i
= 0; i
< nsyms
; i
++, symp
= symbol_next (symp
))
1422 asympp
[i
] = symbol_get_bfdsym (symp
);
1423 symbol_mark_written (symp
);
1428 result
= bfd_set_symtab (stdoutput
, asympp
, nsyms
);
1430 symbol_table_frozen
= 1;
1433 /* Finish the subsegments. After every sub-segment, we fake an
1434 ".align ...". This conforms to BSD4.2 brane-damage. We then fake
1435 ".fill 0" because that is the kind of frag that requires least
1436 thought. ".align" frags like to have a following frag since that
1437 makes calculating their intended length trivial. */
1439 #ifndef SUB_SEGMENT_ALIGN
1441 /* The last subsegment gets an alignment corresponding to the alignment
1442 of the section. This allows proper nop-filling at the end of
1443 code-bearing sections. */
1444 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
1445 (!(FRCHAIN)->frch_next ? get_recorded_alignment (SEG) : 0)
1447 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
1452 subsegs_finish (void)
1454 struct frchain
*frchainP
;
1457 for (s
= stdoutput
->sections
; s
; s
= s
->next
)
1459 segment_info_type
*seginfo
= seg_info (s
);
1463 for (frchainP
= seginfo
->frchainP
;
1465 frchainP
= frchainP
->frch_next
)
1469 subseg_set (s
, frchainP
->frch_subseg
);
1471 /* This now gets called even if we had errors. In that case,
1472 any alignment is meaningless, and, moreover, will look weird
1473 if we are generating a listing. */
1476 alignment
= SUB_SEGMENT_ALIGN (now_seg
, frchainP
);
1477 if ((bfd_get_section_flags (now_seg
->owner
, now_seg
) & SEC_MERGE
)
1478 && now_seg
->entsize
)
1480 unsigned int entsize
= now_seg
->entsize
;
1483 while ((entsize
& 1) == 0)
1488 if (entalign
> alignment
)
1489 alignment
= entalign
;
1493 if (subseg_text_p (now_seg
))
1494 frag_align_code (alignment
, 0);
1496 frag_align (alignment
, 0, 0);
1498 /* frag_align will have left a new frag.
1499 Use this last frag for an empty ".fill".
1501 For this segment ...
1502 Create a last frag. Do not leave a "being filled in frag". */
1503 frag_wane (frag_now
);
1504 frag_now
->fr_fix
= 0;
1505 know (frag_now
->fr_next
== NULL
);
1510 /* Write the object file. */
1513 write_object_file (void)
1515 struct relax_seg_info rsi
;
1516 #ifndef WORKING_DOT_WORD
1517 fragS
*fragP
; /* Track along all frags. */
1520 /* Do we really want to write it? */
1522 int n_warns
, n_errs
;
1523 n_warns
= had_warnings ();
1524 n_errs
= had_errors ();
1525 /* The -Z flag indicates that an object file should be generated,
1526 regardless of warnings and errors. */
1527 if (flag_always_generate_output
)
1529 if (n_warns
|| n_errs
)
1530 as_warn (_("%d error%s, %d warning%s, generating bad object file"),
1531 n_errs
, n_errs
== 1 ? "" : "s",
1532 n_warns
, n_warns
== 1 ? "" : "s");
1537 as_fatal (_("%d error%s, %d warning%s, no object file generated"),
1538 n_errs
, n_errs
== 1 ? "" : "s",
1539 n_warns
, n_warns
== 1 ? "" : "s");
1544 /* Under VMS we try to be compatible with VAX-11 "C". Thus, we call
1545 a routine to check for the definition of the procedure "_main",
1546 and if so -- fix it up so that it can be program entry point. */
1547 vms_check_for_main ();
1548 #endif /* OBJ_VMS */
1550 /* From now on, we don't care about sub-segments. Build one frag chain
1551 for each segment. Linked thru fr_next. */
1553 /* Remove the sections created by gas for its own purposes. */
1557 bfd_section_list_remove (stdoutput
, reg_section
);
1558 bfd_section_list_remove (stdoutput
, expr_section
);
1559 stdoutput
->section_count
-= 2;
1561 bfd_map_over_sections (stdoutput
, renumber_sections
, &i
);
1564 bfd_map_over_sections (stdoutput
, chain_frchains_together
, (char *) 0);
1566 /* We have two segments. If user gave -R flag, then we must put the
1567 data frags into the text segment. Do this before relaxing so
1568 we know to take advantage of -R and make shorter addresses. */
1569 if (flag_readonly_data_in_text
)
1571 merge_data_into_text ();
1577 #ifndef WORKING_DOT_WORD
1578 /* We need to reset the markers in the broken word list and
1579 associated frags between calls to relax_segment (via
1580 relax_seg). Since the broken word list is global, we do it
1581 once per round, rather than locally in relax_segment for each
1583 struct broken_word
*brokp
;
1585 for (brokp
= broken_words
;
1586 brokp
!= (struct broken_word
*) NULL
;
1587 brokp
= brokp
->next_broken_word
)
1591 if (brokp
->dispfrag
!= (fragS
*) NULL
1592 && brokp
->dispfrag
->fr_type
== rs_broken_word
)
1593 brokp
->dispfrag
->fr_subtype
= 0;
1598 bfd_map_over_sections (stdoutput
, relax_seg
, &rsi
);
1604 /* Note - Most ports will use the default value of
1605 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG, which 1. This will force
1606 local symbols to be resolved, removing their frag information.
1607 Some ports however, will not have finished relaxing all of
1608 their frags and will still need the local symbol frag
1609 information. These ports can set
1610 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to 0. */
1611 finalize_syms
= TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
;
1613 bfd_map_over_sections (stdoutput
, size_seg
, (char *) 0);
1615 /* Relaxation has completed. Freeze all syms. */
1618 #ifdef md_post_relax_hook
1622 #ifndef WORKING_DOT_WORD
1624 struct broken_word
*lie
;
1625 struct broken_word
**prevP
;
1627 prevP
= &broken_words
;
1628 for (lie
= broken_words
; lie
; lie
= lie
->next_broken_word
)
1633 subseg_change (lie
->seg
, lie
->subseg
);
1634 exp
.X_op
= O_subtract
;
1635 exp
.X_add_symbol
= lie
->add
;
1636 exp
.X_op_symbol
= lie
->sub
;
1637 exp
.X_add_number
= lie
->addnum
;
1638 #ifdef TC_CONS_FIX_NEW
1639 TC_CONS_FIX_NEW (lie
->frag
,
1640 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1643 fix_new_exp (lie
->frag
,
1644 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1645 2, &exp
, 0, BFD_RELOC_16
);
1647 *prevP
= lie
->next_broken_word
;
1650 prevP
= &(lie
->next_broken_word
);
1652 for (lie
= broken_words
; lie
;)
1654 struct broken_word
*untruth
;
1656 addressT table_addr
;
1657 addressT from_addr
, to_addr
;
1660 subseg_change (lie
->seg
, lie
->subseg
);
1661 fragP
= lie
->dispfrag
;
1663 /* Find out how many broken_words go here. */
1666 untruth
&& untruth
->dispfrag
== fragP
;
1667 untruth
= untruth
->next_broken_word
)
1668 if (untruth
->added
== 1)
1671 table_ptr
= lie
->dispfrag
->fr_opcode
;
1672 table_addr
= (lie
->dispfrag
->fr_address
1673 + (table_ptr
- lie
->dispfrag
->fr_literal
));
1674 /* Create the jump around the long jumps. This is a short
1675 jump from table_ptr+0 to table_ptr+n*long_jump_size. */
1676 from_addr
= table_addr
;
1677 to_addr
= table_addr
+ md_short_jump_size
+ n
* md_long_jump_size
;
1678 md_create_short_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
,
1680 table_ptr
+= md_short_jump_size
;
1681 table_addr
+= md_short_jump_size
;
1684 lie
&& lie
->dispfrag
== fragP
;
1685 m
++, lie
= lie
->next_broken_word
)
1687 if (lie
->added
== 2)
1689 /* Patch the jump table. */
1690 /* This is the offset from ??? to table_ptr+0. */
1691 to_addr
= table_addr
- S_GET_VALUE (lie
->sub
);
1692 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
1693 TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr
, lie
);
1695 md_number_to_chars (lie
->word_goes_here
, to_addr
, 2);
1696 for (untruth
= lie
->next_broken_word
;
1697 untruth
&& untruth
->dispfrag
== fragP
;
1698 untruth
= untruth
->next_broken_word
)
1700 if (untruth
->use_jump
== lie
)
1701 md_number_to_chars (untruth
->word_goes_here
, to_addr
, 2);
1704 /* Install the long jump. */
1705 /* This is a long jump from table_ptr+0 to the final target. */
1706 from_addr
= table_addr
;
1707 to_addr
= S_GET_VALUE (lie
->add
) + lie
->addnum
;
1708 md_create_long_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
,
1710 table_ptr
+= md_long_jump_size
;
1711 table_addr
+= md_long_jump_size
;
1715 #endif /* not WORKING_DOT_WORD */
1717 /* Resolve symbol values. This needs to be done before processing
1723 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1724 resolve_symbol_value (symp
);
1726 resolve_local_symbol_values ();
1727 resolve_reloc_expr_symbols ();
1731 #ifdef tc_frob_file_before_adjust
1732 tc_frob_file_before_adjust ();
1734 #ifdef obj_frob_file_before_adjust
1735 obj_frob_file_before_adjust ();
1738 bfd_map_over_sections (stdoutput
, adjust_reloc_syms
, (char *) 0);
1740 #ifdef tc_frob_file_before_fix
1741 tc_frob_file_before_fix ();
1743 #ifdef obj_frob_file_before_fix
1744 obj_frob_file_before_fix ();
1747 bfd_map_over_sections (stdoutput
, fix_segment
, (char *) 0);
1749 /* Set up symbol table, and write it out. */
1753 bfd_boolean skip_next_symbol
= FALSE
;
1755 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1760 if (skip_next_symbol
)
1762 /* Don't do anything besides moving the value of the
1763 symbol from the GAS value-field to the BFD value-field. */
1764 symbol_get_bfdsym (symp
)->value
= S_GET_VALUE (symp
);
1765 skip_next_symbol
= FALSE
;
1769 if (symbol_mri_common_p (symp
))
1771 if (S_IS_EXTERNAL (symp
))
1772 as_bad (_("%s: global symbols not supported in common sections"),
1774 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1778 name
= S_GET_NAME (symp
);
1782 decode_local_label_name ((char *) S_GET_NAME (symp
));
1783 /* They only differ if `name' is a fb or dollar local
1785 if (name2
!= name
&& ! S_IS_DEFINED (symp
))
1786 as_bad (_("local label `%s' is not defined"), name2
);
1789 /* Do it again, because adjust_reloc_syms might introduce
1790 more symbols. They'll probably only be section symbols,
1791 but they'll still need to have the values computed. */
1792 resolve_symbol_value (symp
);
1794 /* Skip symbols which were equated to undefined or common
1796 if (symbol_equated_reloc_p (symp
)
1797 || S_IS_WEAKREFR (symp
))
1799 const char *name
= S_GET_NAME (symp
);
1800 if (S_IS_COMMON (symp
)
1801 && !TC_FAKE_LABEL (name
)
1802 && !S_IS_WEAKREFR (symp
)
1803 && (!S_IS_EXTERNAL (symp
) || S_IS_LOCAL (symp
)))
1805 expressionS
*e
= symbol_get_value_expression (symp
);
1806 as_bad (_("Local symbol `%s' can't be equated to common symbol `%s'"),
1807 name
, S_GET_NAME (e
->X_add_symbol
));
1809 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1813 #ifdef obj_frob_symbol
1814 obj_frob_symbol (symp
, punt
);
1816 #ifdef tc_frob_symbol
1817 if (! punt
|| symbol_used_in_reloc_p (symp
))
1818 tc_frob_symbol (symp
, punt
);
1821 /* If we don't want to keep this symbol, splice it out of
1822 the chain now. If EMIT_SECTION_SYMBOLS is 0, we never
1823 want section symbols. Otherwise, we skip local symbols
1824 and symbols that the frob_symbol macros told us to punt,
1825 but we keep such symbols if they are used in relocs. */
1826 if (symp
== abs_section_sym
1827 || (! EMIT_SECTION_SYMBOLS
1828 && symbol_section_p (symp
))
1829 /* Note that S_IS_EXTERNAL and S_IS_LOCAL are not always
1830 opposites. Sometimes the former checks flags and the
1831 latter examines the name... */
1832 || (!S_IS_EXTERNAL (symp
)
1833 && (punt
|| S_IS_LOCAL (symp
) ||
1834 (S_IS_WEAKREFD (symp
) && ! symbol_used_p (symp
)))
1835 && ! symbol_used_in_reloc_p (symp
)))
1837 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1839 /* After symbol_remove, symbol_next(symp) still returns
1840 the one that came after it in the chain. So we don't
1841 need to do any extra cleanup work here. */
1845 /* Make sure we really got a value for the symbol. */
1846 if (! symbol_resolved_p (symp
))
1848 as_bad (_("can't resolve value for symbol `%s'"),
1850 symbol_mark_resolved (symp
);
1853 /* Set the value into the BFD symbol. Up til now the value
1854 has only been kept in the gas symbolS struct. */
1855 symbol_get_bfdsym (symp
)->value
= S_GET_VALUE (symp
);
1857 /* A warning construct is a warning symbol followed by the
1858 symbol warned about. Don't let anything object-format or
1859 target-specific muck with it; it's ready for output. */
1860 if (symbol_get_bfdsym (symp
)->flags
& BSF_WARNING
)
1861 skip_next_symbol
= TRUE
;
1867 /* Now do any format-specific adjustments to the symbol table, such
1868 as adding file symbols. */
1869 #ifdef tc_adjust_symtab
1870 tc_adjust_symtab ();
1872 #ifdef obj_adjust_symtab
1873 obj_adjust_symtab ();
1876 /* Now that all the sizes are known, and contents correct, we can
1877 start writing to the file. */
1880 /* If *_frob_file changes the symbol value at this point, it is
1881 responsible for moving the changed value into symp->bsym->value
1882 as well. Hopefully all symbol value changing can be done in
1887 #ifdef obj_frob_file
1891 bfd_map_over_sections (stdoutput
, write_relocs
, (char *) 0);
1893 #ifdef tc_frob_file_after_relocs
1894 tc_frob_file_after_relocs ();
1896 #ifdef obj_frob_file_after_relocs
1897 obj_frob_file_after_relocs ();
1900 bfd_map_over_sections (stdoutput
, write_contents
, (char *) 0);
1903 #ifdef TC_GENERIC_RELAX_TABLE
1904 /* Relax a fragment by scanning TC_GENERIC_RELAX_TABLE. */
1907 relax_frag (segT segment
, fragS
*fragP
, long stretch
)
1909 const relax_typeS
*this_type
;
1910 const relax_typeS
*start_type
;
1911 relax_substateT next_state
;
1912 relax_substateT this_state
;
1918 const relax_typeS
*table
;
1920 target
= fragP
->fr_offset
;
1921 address
= fragP
->fr_address
;
1922 table
= TC_GENERIC_RELAX_TABLE
;
1923 this_state
= fragP
->fr_subtype
;
1924 start_type
= this_type
= table
+ this_state
;
1925 symbolP
= fragP
->fr_symbol
;
1931 sym_frag
= symbol_get_frag (symbolP
);
1933 #ifndef DIFF_EXPR_OK
1934 know (sym_frag
!= NULL
);
1936 know (S_GET_SEGMENT (symbolP
) != absolute_section
1937 || sym_frag
== &zero_address_frag
);
1938 target
+= S_GET_VALUE (symbolP
);
1940 /* If frag has yet to be reached on this pass,
1941 assume it will move by STRETCH just as we did.
1942 If this is not so, it will be because some frag
1943 between grows, and that will force another pass. */
1946 && sym_frag
->relax_marker
!= fragP
->relax_marker
1947 && S_GET_SEGMENT (symbolP
) == segment
)
1953 aim
= target
- address
- fragP
->fr_fix
;
1954 #ifdef TC_PCREL_ADJUST
1955 /* Currently only the ns32k family needs this. */
1956 aim
+= TC_PCREL_ADJUST (fragP
);
1959 #ifdef md_prepare_relax_scan
1960 /* Formerly called M68K_AIM_KLUDGE. */
1961 md_prepare_relax_scan (fragP
, address
, aim
, this_state
, this_type
);
1966 /* Look backwards. */
1967 for (next_state
= this_type
->rlx_more
; next_state
;)
1968 if (aim
>= this_type
->rlx_backward
)
1972 /* Grow to next state. */
1973 this_state
= next_state
;
1974 this_type
= table
+ this_state
;
1975 next_state
= this_type
->rlx_more
;
1980 /* Look forwards. */
1981 for (next_state
= this_type
->rlx_more
; next_state
;)
1982 if (aim
<= this_type
->rlx_forward
)
1986 /* Grow to next state. */
1987 this_state
= next_state
;
1988 this_type
= table
+ this_state
;
1989 next_state
= this_type
->rlx_more
;
1993 growth
= this_type
->rlx_length
- start_type
->rlx_length
;
1995 fragP
->fr_subtype
= this_state
;
1999 #endif /* defined (TC_GENERIC_RELAX_TABLE) */
2001 /* Relax_align. Advance location counter to next address that has 'alignment'
2002 lowest order bits all 0s, return size of adjustment made. */
2003 static relax_addressT
2004 relax_align (register relax_addressT address
, /* Address now. */
2005 register int alignment
/* Alignment (binary). */)
2007 relax_addressT mask
;
2008 relax_addressT new_address
;
2010 mask
= ~((~0) << alignment
);
2011 new_address
= (address
+ mask
) & (~mask
);
2012 #ifdef LINKER_RELAXING_SHRINKS_ONLY
2014 /* We must provide lots of padding, so the linker can discard it
2015 when needed. The linker will not add extra space, ever. */
2016 new_address
+= (1 << alignment
);
2018 return (new_address
- address
);
2021 /* Now we have a segment, not a crowd of sub-segments, we can make
2026 After this, all frags in this segment have addresses that are correct
2027 within the segment. Since segments live in different file addresses,
2028 these frag addresses may not be the same as final object-file
2032 relax_segment (struct frag
*segment_frag_root
, segT segment
, int pass
)
2034 unsigned long frag_count
;
2036 relax_addressT address
;
2039 /* In case md_estimate_size_before_relax() wants to make fixSs. */
2040 subseg_change (segment
, 0);
2042 /* For each frag in segment: count and store (a 1st guess of)
2045 for (frag_count
= 0, fragP
= segment_frag_root
;
2047 fragP
= fragP
->fr_next
, frag_count
++)
2049 fragP
->relax_marker
= 0;
2050 fragP
->fr_address
= address
;
2051 address
+= fragP
->fr_fix
;
2053 switch (fragP
->fr_type
)
2056 address
+= fragP
->fr_offset
* fragP
->fr_var
;
2063 addressT offset
= relax_align (address
, (int) fragP
->fr_offset
);
2065 if (fragP
->fr_subtype
!= 0 && offset
> fragP
->fr_subtype
)
2068 if (offset
% fragP
->fr_var
!= 0)
2070 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2071 _("alignment padding (%lu bytes) not a multiple of %ld"),
2072 (unsigned long) offset
, (long) fragP
->fr_var
);
2073 offset
-= (offset
% fragP
->fr_var
);
2082 /* Assume .org is nugatory. It will grow with 1st relax. */
2085 case rs_machine_dependent
:
2086 /* If fr_symbol is an expression, this call to
2087 resolve_symbol_value sets up the correct segment, which will
2088 likely be needed in md_estimate_size_before_relax. */
2089 if (fragP
->fr_symbol
)
2090 resolve_symbol_value (fragP
->fr_symbol
);
2092 address
+= md_estimate_size_before_relax (fragP
, segment
);
2095 #ifndef WORKING_DOT_WORD
2096 /* Broken words don't concern us yet. */
2097 case rs_broken_word
:
2102 /* Initial guess is always 1; doing otherwise can result in
2103 stable solutions that are larger than the minimum. */
2104 address
+= fragP
->fr_offset
= 1;
2108 address
+= eh_frame_estimate_size_before_relax (fragP
);
2112 address
+= dwarf2dbg_estimate_size_before_relax (fragP
);
2116 BAD_CASE (fragP
->fr_type
);
2123 unsigned long max_iterations
;
2125 /* Cumulative address adjustment. */
2128 /* Have we made any adjustment this pass? We can't just test
2129 stretch because one piece of code may have grown and another
2133 /* Most horrible, but gcc may give us some exception data that
2134 is impossible to assemble, of the form
2138 .uleb128 end - start
2144 If the leb128 is two bytes in size, then end-start is 128*128,
2145 which requires a three byte leb128. If the leb128 is three
2146 bytes in size, then end-start is 128*128-1, which requires a
2147 two byte leb128. We work around this dilemma by inserting
2148 an extra 4 bytes of alignment just after the .align. This
2149 works because the data after the align is accessed relative to
2152 This counter is used in a tiny state machine to detect
2153 whether a leb128 followed by an align is impossible to
2155 int rs_leb128_fudge
= 0;
2157 /* We want to prevent going into an infinite loop where one frag grows
2158 depending upon the location of a symbol which is in turn moved by
2159 the growing frag. eg:
2165 So we dictate that this algorithm can be at most O2. */
2166 max_iterations
= frag_count
* frag_count
;
2167 /* Check for overflow. */
2168 if (max_iterations
< frag_count
)
2169 max_iterations
= frag_count
;
2177 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
2180 addressT was_address
;
2184 fragP
->relax_marker
^= 1;
2185 was_address
= fragP
->fr_address
;
2186 address
= fragP
->fr_address
+= stretch
;
2187 symbolP
= fragP
->fr_symbol
;
2188 offset
= fragP
->fr_offset
;
2190 switch (fragP
->fr_type
)
2192 case rs_fill
: /* .fill never relaxes. */
2196 #ifndef WORKING_DOT_WORD
2197 /* JF: This is RMS's idea. I do *NOT* want to be blamed
2198 for it I do not want to write it. I do not want to have
2199 anything to do with it. This is not the proper way to
2200 implement this misfeature. */
2201 case rs_broken_word
:
2203 struct broken_word
*lie
;
2204 struct broken_word
*untruth
;
2206 /* Yes this is ugly (storing the broken_word pointer
2207 in the symbol slot). Still, this whole chunk of
2208 code is ugly, and I don't feel like doing anything
2209 about it. Think of it as stubbornness in action. */
2211 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
2212 lie
&& lie
->dispfrag
== fragP
;
2213 lie
= lie
->next_broken_word
)
2219 offset
= (S_GET_VALUE (lie
->add
)
2221 - S_GET_VALUE (lie
->sub
));
2222 if (offset
<= -32768 || offset
>= 32767)
2224 if (flag_warn_displacement
)
2227 sprint_value (buf
, (addressT
) lie
->addnum
);
2228 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
2229 _(".word %s-%s+%s didn't fit"),
2230 S_GET_NAME (lie
->add
),
2231 S_GET_NAME (lie
->sub
),
2235 if (fragP
->fr_subtype
== 0)
2237 fragP
->fr_subtype
++;
2238 growth
+= md_short_jump_size
;
2240 for (untruth
= lie
->next_broken_word
;
2241 untruth
&& untruth
->dispfrag
== lie
->dispfrag
;
2242 untruth
= untruth
->next_broken_word
)
2243 if ((symbol_get_frag (untruth
->add
)
2244 == symbol_get_frag (lie
->add
))
2245 && (S_GET_VALUE (untruth
->add
)
2246 == S_GET_VALUE (lie
->add
)))
2249 untruth
->use_jump
= lie
;
2251 growth
+= md_long_jump_size
;
2256 } /* case rs_broken_word */
2262 addressT oldoff
, newoff
;
2264 oldoff
= relax_align (was_address
+ fragP
->fr_fix
,
2266 newoff
= relax_align (address
+ fragP
->fr_fix
,
2269 if (fragP
->fr_subtype
!= 0)
2271 if (oldoff
> fragP
->fr_subtype
)
2273 if (newoff
> fragP
->fr_subtype
)
2277 growth
= newoff
- oldoff
;
2279 /* If this align happens to follow a leb128 and
2280 we have determined that the leb128 is bouncing
2281 in size, then break the cycle by inserting an
2284 && (rs_leb128_fudge
& 16) != 0
2285 && (rs_leb128_fudge
& 15) >= 2)
2287 segment_info_type
*seginfo
= seg_info (segment
);
2288 struct obstack
*ob
= &seginfo
->frchainP
->frch_obstack
;
2291 newf
= frag_alloc (ob
);
2292 obstack_blank_fast (ob
, fragP
->fr_var
);
2293 obstack_finish (ob
);
2294 memcpy (newf
, fragP
, SIZEOF_STRUCT_FRAG
);
2295 memcpy (newf
->fr_literal
,
2296 fragP
->fr_literal
+ fragP
->fr_fix
,
2298 newf
->fr_type
= rs_fill
;
2300 newf
->fr_offset
= (((offsetT
) 1 << fragP
->fr_offset
)
2302 if (newf
->fr_offset
* newf
->fr_var
2303 != (offsetT
) 1 << fragP
->fr_offset
)
2305 newf
->fr_offset
= (offsetT
) 1 << fragP
->fr_offset
;
2308 /* Include growth of new frag, because rs_fill
2309 frags don't normally grow. */
2310 growth
+= newf
->fr_offset
* newf
->fr_var
;
2311 /* The new frag address is newoff. Adjust this
2312 for the amount we'll add when we process the
2314 newf
->fr_address
= newoff
- stretch
- growth
;
2315 newf
->relax_marker
^= 1;
2316 fragP
->fr_next
= newf
;
2318 as_warn (_("padding added"));
2326 addressT target
= offset
;
2331 /* Convert from an actual address to an octet offset
2332 into the section. Here it is assumed that the
2333 section's VMA is zero, and can omit subtracting it
2334 from the symbol's value to get the address offset. */
2335 know (S_GET_SEGMENT (symbolP
)->vma
== 0);
2336 target
+= S_GET_VALUE (symbolP
) * OCTETS_PER_BYTE
;
2339 know (fragP
->fr_next
);
2340 after
= fragP
->fr_next
->fr_address
;
2341 growth
= target
- after
;
2346 /* Don't error on first few frag relax passes.
2347 The symbol might be an expression involving
2348 symbol values from other sections. If those
2349 sections have not yet been processed their
2350 frags will all have zero addresses, so we
2351 will calculate incorrect values for them. The
2352 number of passes we allow before giving an
2353 error is somewhat arbitrary. It should be at
2354 least one, with larger values requiring
2355 increasingly contrived dependencies between
2356 frags to trigger a false error. */
2359 /* Force another pass. */
2364 /* Growth may be negative, but variable part of frag
2365 cannot have fewer than 0 chars. That is, we can't
2367 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2368 _("attempt to move .org backwards"));
2370 /* We've issued an error message. Change the
2371 frag to avoid cascading errors. */
2372 fragP
->fr_type
= rs_align
;
2373 fragP
->fr_subtype
= 0;
2374 fragP
->fr_offset
= 0;
2375 fragP
->fr_fix
= after
- was_address
;
2379 /* This is an absolute growth factor */
2390 amount
= S_GET_VALUE (symbolP
);
2391 if (S_GET_SEGMENT (symbolP
) != absolute_section
2392 || S_IS_COMMON (symbolP
)
2393 || ! S_IS_DEFINED (symbolP
))
2395 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2396 _(".space specifies non-absolute value"));
2397 /* Prevent repeat of this error message. */
2398 fragP
->fr_symbol
= 0;
2400 else if (amount
< 0)
2402 /* Don't error on first few frag relax passes.
2403 See rs_org comment for a longer explanation. */
2410 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
2411 _(".space or .fill with negative value, ignored"));
2412 fragP
->fr_symbol
= 0;
2415 growth
= (was_address
+ fragP
->fr_fix
+ amount
2416 - fragP
->fr_next
->fr_address
);
2420 case rs_machine_dependent
:
2421 #ifdef md_relax_frag
2422 growth
= md_relax_frag (segment
, fragP
, stretch
);
2424 #ifdef TC_GENERIC_RELAX_TABLE
2425 /* The default way to relax a frag is to look through
2426 TC_GENERIC_RELAX_TABLE. */
2427 growth
= relax_frag (segment
, fragP
, stretch
);
2428 #endif /* TC_GENERIC_RELAX_TABLE */
2437 value
= resolve_symbol_value (fragP
->fr_symbol
);
2438 size
= sizeof_leb128 (value
, fragP
->fr_subtype
);
2439 growth
= size
- fragP
->fr_offset
;
2440 fragP
->fr_offset
= size
;
2445 growth
= eh_frame_relax_frag (fragP
);
2449 growth
= dwarf2dbg_relax_frag (fragP
);
2453 BAD_CASE (fragP
->fr_type
);
2460 if (fragP
->fr_type
== rs_leb128
)
2461 rs_leb128_fudge
+= 16;
2462 else if (fragP
->fr_type
== rs_align
2463 && (rs_leb128_fudge
& 16) != 0
2465 rs_leb128_fudge
+= 16;
2467 rs_leb128_fudge
= 0;
2472 && (rs_leb128_fudge
& 16) == 0
2473 && (rs_leb128_fudge
& -16) != 0)
2474 rs_leb128_fudge
+= 1;
2476 rs_leb128_fudge
= 0;
2478 /* Until nothing further to relax. */
2479 while (stretched
&& -- max_iterations
);
2482 as_fatal (_("Infinite loop encountered whilst attempting to compute the addresses of symbols in section %s"),
2483 segment_name (segment
));
2486 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
2487 if (fragP
->last_fr_address
!= fragP
->fr_address
)
2489 fragP
->last_fr_address
= fragP
->fr_address
;
2496 number_to_chars_bigendian (char *buf
, valueT val
, int n
)
2502 buf
[n
] = val
& 0xff;
2508 number_to_chars_littleendian (char *buf
, valueT val
, int n
)
2514 *buf
++ = val
& 0xff;
2520 write_print_statistics (FILE *file
)
2522 fprintf (file
, "fixups: %d\n", n_fixups
);
2525 /* For debugging. */
2526 extern int indent_level
;
2529 print_fixup (fixS
*fixp
)
2532 fprintf (stderr
, "fix ");
2533 fprintf_vma (stderr
, (bfd_vma
)((bfd_hostptr_t
) fixp
));
2534 fprintf (stderr
, " %s:%d",fixp
->fx_file
, fixp
->fx_line
);
2536 fprintf (stderr
, " pcrel");
2537 if (fixp
->fx_pcrel_adjust
)
2538 fprintf (stderr
, " pcrel_adjust=%d", fixp
->fx_pcrel_adjust
);
2539 if (fixp
->fx_im_disp
)
2542 fprintf (stderr
, " im_disp=%d", fixp
->fx_im_disp
);
2544 fprintf (stderr
, " im_disp");
2548 fprintf (stderr
, " tcbit");
2550 fprintf (stderr
, " done");
2551 fprintf (stderr
, "\n size=%d frag=", fixp
->fx_size
);
2552 fprintf_vma (stderr
, (bfd_vma
) ((bfd_hostptr_t
) fixp
->fx_frag
));
2553 fprintf (stderr
, " where=%ld offset=%lx addnumber=%lx",
2554 (long) fixp
->fx_where
,
2555 (long) fixp
->fx_offset
, (long) fixp
->fx_addnumber
);
2556 fprintf (stderr
, "\n %s (%d)", bfd_get_reloc_code_name (fixp
->fx_r_type
),
2560 fprintf (stderr
, "\n +<");
2561 print_symbol_value_1 (stderr
, fixp
->fx_addsy
);
2562 fprintf (stderr
, ">");
2566 fprintf (stderr
, "\n -<");
2567 print_symbol_value_1 (stderr
, fixp
->fx_subsy
);
2568 fprintf (stderr
, ">");
2570 fprintf (stderr
, "\n");
2571 #ifdef TC_FIX_DATA_PRINT
2572 TC_FIX_DATA_PRINT (stderr
, fixp
);