1 /* write.c - emit .o file
2 Copyright (C) 1986-2024 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* This thing should be set up to do byte ordering correctly. But... */
26 #include "output-file.h"
27 #include "dwarf2dbg.h"
28 #include "compress-debug.h"
31 #ifndef TC_FORCE_RELOCATION
32 #define TC_FORCE_RELOCATION(FIX) \
33 (generic_force_reloc (FIX))
36 #ifndef TC_FORCE_RELOCATION_ABS
37 #define TC_FORCE_RELOCATION_ABS(FIX) \
38 (TC_FORCE_RELOCATION (FIX))
41 #define GENERIC_FORCE_RELOCATION_LOCAL(FIX) \
43 || TC_FORCE_RELOCATION (FIX))
44 #ifndef TC_FORCE_RELOCATION_LOCAL
45 #define TC_FORCE_RELOCATION_LOCAL GENERIC_FORCE_RELOCATION_LOCAL
48 #define GENERIC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) \
50 #ifndef TC_FORCE_RELOCATION_SUB_SAME
51 #define TC_FORCE_RELOCATION_SUB_SAME GENERIC_FORCE_RELOCATION_SUB_SAME
54 #ifndef md_register_arithmetic
55 # define md_register_arithmetic 1
58 #ifndef TC_FORCE_RELOCATION_SUB_ABS
59 #define TC_FORCE_RELOCATION_SUB_ABS(FIX, SEG) \
60 (!md_register_arithmetic && (SEG) == reg_section)
63 #ifndef TC_FORCE_RELOCATION_SUB_LOCAL
65 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) \
66 (!md_register_arithmetic && (SEG) == reg_section)
68 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX, SEG) 1
72 #ifndef TC_VALIDATE_FIX_SUB
73 #define TC_VALIDATE_FIX_SUB(FIX, SEG) 0
76 #ifndef TC_LINKRELAX_FIXUP
77 #define TC_LINKRELAX_FIXUP(SEG) 1
80 #ifndef MD_APPLY_SYM_VALUE
81 #define MD_APPLY_SYM_VALUE(FIX) 1
84 #ifndef TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
85 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 1
88 #ifndef MD_PCREL_FROM_SECTION
89 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX)
93 #define TC_FAKE_LABEL(NAME) (strcmp ((NAME), FAKE_LABEL_NAME) == 0)
96 /* Positive values of TC_FX_SIZE_SLACK allow a target to define
97 fixups that far past the end of a frag. Having such fixups
98 is of course most most likely a bug in setting fx_size correctly.
99 A negative value disables the fixup check entirely, which is
100 appropriate for something like the Renesas / SuperH SH_COUNT
102 #ifndef TC_FX_SIZE_SLACK
103 #define TC_FX_SIZE_SLACK(FIX) 0
106 /* Used to control final evaluation of expressions. */
107 int finalize_syms
= 0;
109 int symbol_table_frozen
;
111 symbolS
*abs_section_sym
;
113 /* Remember the value of dot when parsing expressions. */
116 /* The frag that dot_value is based from. */
119 /* Relocs generated by ".reloc" pseudo. */
120 struct reloc_list
* reloc_list
;
122 void print_fixup (fixS
*);
124 /* We generally attach relocs to frag chains. However, after we have
125 chained these all together into a segment, any relocs we add after
126 that must be attached to a segment. This will include relocs added
127 in md_estimate_size_before_relax, for example. */
128 static bool frags_chained
= false;
130 static unsigned int n_fixups
;
132 #define RELOC_ENUM enum bfd_reloc_code_real
134 /* Create a fixS in obstack 'notes'. */
137 fix_new_internal (fragS
*frag
, /* Which frag? */
138 unsigned long where
, /* Where in that frag? */
139 unsigned long size
, /* 1, 2, or 4 usually. */
140 symbolS
*add_symbol
, /* X_add_symbol. */
141 symbolS
*sub_symbol
, /* X_op_symbol. */
142 offsetT offset
, /* X_add_number. */
143 int pcrel
, /* TRUE if PC-relative relocation. */
144 RELOC_ENUM r_type
/* Relocation type. */,
145 int at_beginning
) /* Add to the start of the list? */
151 fixP
= (fixS
*) obstack_alloc (¬es
, sizeof (fixS
));
153 fixP
->fx_frag
= frag
;
154 fixP
->fx_where
= where
;
155 fixP
->fx_size
= size
;
156 /* We've made fx_size a narrow field; check that it's wide enough. */
157 if (fixP
->fx_size
!= size
)
159 as_bad (_("field fx_size too small to hold %lu"), size
);
162 fixP
->fx_addsy
= add_symbol
;
163 fixP
->fx_subsy
= sub_symbol
;
164 fixP
->fx_offset
= offset
;
165 fixP
->fx_dot_value
= dot_value
;
166 fixP
->fx_dot_frag
= dot_frag
;
167 fixP
->fx_pcrel
= pcrel
;
168 fixP
->fx_r_type
= r_type
;
169 fixP
->fx_pcrel_adjust
= 0;
170 fixP
->fx_addnumber
= 0;
175 fixP
->fx_no_overflow
= 0;
179 fixP
->fx_cgen
.insn
= NULL
;
180 fixP
->fx_cgen
.opinfo
= 0;
184 TC_INIT_FIX_DATA (fixP
);
187 fixP
->fx_file
= as_where (&fixP
->fx_line
);
191 fixS
**seg_fix_rootP
= (frags_chained
192 ? &seg_info (now_seg
)->fix_root
193 : &frchain_now
->fix_root
);
194 fixS
**seg_fix_tailP
= (frags_chained
195 ? &seg_info (now_seg
)->fix_tail
196 : &frchain_now
->fix_tail
);
200 fixP
->fx_next
= *seg_fix_rootP
;
201 *seg_fix_rootP
= fixP
;
202 if (fixP
->fx_next
== NULL
)
203 *seg_fix_tailP
= fixP
;
207 fixP
->fx_next
= NULL
;
209 (*seg_fix_tailP
)->fx_next
= fixP
;
211 *seg_fix_rootP
= fixP
;
212 *seg_fix_tailP
= fixP
;
219 /* Create a fixup relative to a symbol (plus a constant). */
222 fix_new (fragS
*frag
, /* Which frag? */
223 unsigned long where
, /* Where in that frag? */
224 unsigned long size
, /* 1, 2, or 4 usually. */
225 symbolS
*add_symbol
, /* X_add_symbol. */
226 offsetT offset
, /* X_add_number. */
227 int pcrel
, /* TRUE if PC-relative relocation. */
228 RELOC_ENUM r_type
/* Relocation type. */)
230 return fix_new_internal (frag
, where
, size
, add_symbol
,
231 (symbolS
*) NULL
, offset
, pcrel
, r_type
, false);
234 /* Create a fixup for an expression. Currently we only support fixups
235 for difference expressions. That is itself more than most object
236 file formats support anyhow. */
239 fix_new_exp (fragS
*frag
, /* Which frag? */
240 unsigned long where
, /* Where in that frag? */
241 unsigned long size
, /* 1, 2, or 4 usually. */
242 const expressionS
*exp
, /* Expression. */
243 int pcrel
, /* TRUE if PC-relative relocation. */
244 RELOC_ENUM r_type
/* Relocation type. */)
256 as_bad (_("register value used as expression"));
260 add
= exp
->X_add_symbol
;
261 off
= exp
->X_add_number
;
262 r_type
= BFD_RELOC_RVA
;
266 sub
= exp
->X_add_symbol
;
267 off
= exp
->X_add_number
;
271 sub
= exp
->X_op_symbol
;
274 add
= exp
->X_add_symbol
;
277 off
= exp
->X_add_number
;
280 case O_add
: /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
281 the difference expression cannot immediately be reduced. */
283 add
= make_expr_symbol (exp
);
287 return fix_new_internal (frag
, where
, size
, add
, sub
, off
, pcrel
,
291 /* Create a fixup at the beginning of FRAG. The arguments are the same
292 as for fix_new, except that WHERE is implicitly 0. */
295 fix_at_start (fragS
*frag
, unsigned long size
, symbolS
*add_symbol
,
296 offsetT offset
, int pcrel
, RELOC_ENUM r_type
)
298 return fix_new_internal (frag
, 0, size
, add_symbol
,
299 (symbolS
*) NULL
, offset
, pcrel
, r_type
, true);
302 /* Generic function to determine whether a fixup requires a relocation. */
304 generic_force_reloc (fixS
*fix
)
306 if (fix
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
307 || fix
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
310 if (fix
->fx_addsy
== NULL
)
313 return S_FORCE_RELOC (fix
->fx_addsy
, fix
->fx_subsy
== NULL
);
316 /* Append a string onto another string, bumping the pointer along. */
318 append (char **charPP
, char *fromP
, unsigned long length
)
320 /* Don't trust memcpy() of 0 chars. */
324 memcpy (*charPP
, fromP
, length
);
328 /* This routine records the largest alignment seen for each segment.
329 If the beginning of the segment is aligned on the worst-case
330 boundary, all of the other alignments within it will work. At
331 least one object format really uses this info. */
334 record_alignment (/* Segment to which alignment pertains. */
336 /* Alignment, as a power of 2 (e.g., 1 => 2-byte
337 boundary, 2 => 4-byte boundary, etc.) */
340 if (seg
== absolute_section
)
343 if (align
> bfd_section_alignment (seg
))
344 bfd_set_section_alignment (seg
, align
);
348 get_recorded_alignment (segT seg
)
350 if (seg
== absolute_section
)
353 return bfd_section_alignment (seg
);
356 /* Reset the section indices after removing the gas created sections. */
359 renumber_sections (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *countparg
)
361 int *countp
= (int *) countparg
;
363 sec
->index
= *countp
;
368 chain_frchains_together_1 (segT section
, struct frchain
*frchp
)
370 fragS dummy
, *prev_frag
= &dummy
;
371 fixS fix_dummy
, *prev_fix
= &fix_dummy
;
375 prev_frag
->fr_next
= frchp
->frch_root
;
376 prev_frag
= frchp
->frch_last
;
377 gas_assert (prev_frag
->fr_type
!= 0);
378 if (frchp
->fix_root
!= (fixS
*) NULL
)
380 if (seg_info (section
)->fix_root
== (fixS
*) NULL
)
381 seg_info (section
)->fix_root
= frchp
->fix_root
;
382 prev_fix
->fx_next
= frchp
->fix_root
;
383 seg_info (section
)->fix_tail
= frchp
->fix_tail
;
384 prev_fix
= frchp
->fix_tail
;
386 frchp
= frchp
->frch_next
;
388 gas_assert (prev_frag
!= &dummy
389 && prev_frag
->fr_type
!= 0);
390 prev_frag
->fr_next
= 0;
395 chain_frchains_together (bfd
*abfd ATTRIBUTE_UNUSED
,
397 void *xxx ATTRIBUTE_UNUSED
)
399 segment_info_type
*info
;
401 /* BFD may have introduced its own sections without using
402 subseg_new, so it is possible that seg_info is NULL. */
403 info
= seg_info (section
);
404 if (info
!= (segment_info_type
*) NULL
)
405 info
->frchainP
->frch_last
406 = chain_frchains_together_1 (section
, info
->frchainP
);
408 /* Now that we've chained the frags together, we must add new fixups
409 to the segment, not to the frag chain. */
410 frags_chained
= true;
414 cvt_frag_to_fill (segT sec ATTRIBUTE_UNUSED
, fragS
*fragP
)
416 switch (fragP
->fr_type
)
426 HANDLE_ALIGN (fragP
);
429 know (fragP
->fr_next
!= NULL
);
430 fragP
->fr_offset
= (fragP
->fr_next
->fr_address
432 - fragP
->fr_fix
) / fragP
->fr_var
;
433 if (fragP
->fr_offset
< 0)
435 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
436 _("attempt to .org/.space/.nops backwards? (%ld)"),
437 (long) fragP
->fr_offset
);
438 fragP
->fr_offset
= 0;
440 if (fragP
->fr_type
== rs_space_nop
)
441 fragP
->fr_type
= rs_fill_nop
;
443 fragP
->fr_type
= rs_fill
;
452 valueT value
= S_GET_VALUE (fragP
->fr_symbol
);
455 if (!S_IS_DEFINED (fragP
->fr_symbol
))
457 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
458 _("leb128 operand is an undefined symbol: %s"),
459 S_GET_NAME (fragP
->fr_symbol
));
462 size
= output_leb128 (fragP
->fr_literal
+ fragP
->fr_fix
, value
,
465 fragP
->fr_fix
+= size
;
466 fragP
->fr_type
= rs_fill
;
468 fragP
->fr_offset
= 0;
469 fragP
->fr_symbol
= NULL
;
474 eh_frame_convert_frag (fragP
);
478 dwarf2dbg_convert_frag (fragP
);
482 sframe_convert_frag (fragP
);
485 case rs_machine_dependent
:
486 md_convert_frag (stdoutput
, sec
, fragP
);
488 gas_assert (fragP
->fr_next
== NULL
489 || (fragP
->fr_next
->fr_address
- fragP
->fr_address
492 /* After md_convert_frag, we make the frag into a ".space 0".
493 md_convert_frag() should set up any fixSs and constants
498 #ifndef WORKING_DOT_WORD
501 struct broken_word
*lie
;
503 if (fragP
->fr_subtype
)
505 fragP
->fr_fix
+= md_short_jump_size
;
506 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
507 lie
&& lie
->dispfrag
== fragP
;
508 lie
= lie
->next_broken_word
)
510 fragP
->fr_fix
+= md_long_jump_size
;
517 #if defined (TE_PE) && defined (O_secrel)
520 offsetT value
= S_GET_VALUE (fragP
->fr_symbol
);
523 if (!S_IS_DEFINED (fragP
->fr_symbol
))
525 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
526 _(".cv_%ccomp operand is an undefined symbol: %s"),
527 fragP
->fr_subtype
? 's' : 'u',
528 S_GET_NAME (fragP
->fr_symbol
));
531 size
= output_cv_comp (fragP
->fr_literal
+ fragP
->fr_fix
, value
,
534 fragP
->fr_fix
+= size
;
535 fragP
->fr_type
= rs_fill
;
537 fragP
->fr_offset
= 0;
538 fragP
->fr_symbol
= NULL
;
544 BAD_CASE (fragP
->fr_type
);
548 md_frag_check (fragP
);
552 struct relax_seg_info
559 relax_seg (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *xxx
)
561 segment_info_type
*seginfo
= seg_info (sec
);
562 struct relax_seg_info
*info
= (struct relax_seg_info
*) xxx
;
564 if (seginfo
&& seginfo
->frchainP
565 && relax_segment (seginfo
->frchainP
->frch_root
, sec
, info
->pass
))
570 size_seg (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
574 segment_info_type
*seginfo
;
576 valueT size
, newsize
;
578 subseg_change (sec
, 0);
580 seginfo
= seg_info (sec
);
581 if (seginfo
&& seginfo
->frchainP
)
583 for (fragp
= seginfo
->frchainP
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
584 cvt_frag_to_fill (sec
, fragp
);
585 for (fragp
= seginfo
->frchainP
->frch_root
;
587 fragp
= fragp
->fr_next
)
588 /* Walk to last elt. */
590 size
= fragp
->fr_address
+ fragp
->fr_fix
;
595 flags
= bfd_section_flags (sec
);
596 if (size
== 0 && bfd_section_size (sec
) != 0 &&
597 (flags
& SEC_HAS_CONTENTS
) != 0)
600 if (size
> 0 && ! seginfo
->bss
)
601 flags
|= SEC_HAS_CONTENTS
;
603 x
= bfd_set_section_flags (sec
, flags
);
606 /* If permitted, allow the backend to pad out the section
607 to some alignment boundary. */
608 if (do_not_pad_sections_to_alignment
)
611 newsize
= md_section_align (sec
, size
);
612 x
= bfd_set_section_size (sec
, newsize
);
615 /* If the size had to be rounded up, add some padding in the last
617 gas_assert (newsize
>= size
);
620 fragS
*last
= seginfo
->frchainP
->frch_last
;
621 fragp
= seginfo
->frchainP
->frch_root
;
622 while (fragp
->fr_next
!= last
)
623 fragp
= fragp
->fr_next
;
624 last
->fr_address
= size
;
625 if ((newsize
- size
) % fragp
->fr_var
== 0)
626 fragp
->fr_offset
+= (newsize
- size
) / fragp
->fr_var
;
628 /* If we hit this abort, it's likely due to subsegs_finish not
629 providing sufficient alignment on the last frag, and the
630 machine dependent code using alignment frags with fr_var
635 #ifdef tc_frob_section
636 tc_frob_section (sec
);
638 #ifdef obj_frob_section
639 obj_frob_section (sec
);
645 dump_section_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, FILE *stream
)
647 segment_info_type
*seginfo
= seg_info (sec
);
648 fixS
*fixp
= seginfo
->fix_root
;
653 fprintf (stream
, "sec %s relocs:\n", sec
->name
);
656 symbolS
*s
= fixp
->fx_addsy
;
658 fprintf (stream
, " %08lx: type %d ", (unsigned long) fixp
,
659 (int) fixp
->fx_r_type
);
661 fprintf (stream
, "no sym\n");
664 print_symbol_value_1 (stream
, s
);
665 fprintf (stream
, "\n");
667 fixp
= fixp
->fx_next
;
671 #define dump_section_relocs(ABFD,SEC,STREAM) ((void) 0)
674 #ifndef EMIT_SECTION_SYMBOLS
675 #define EMIT_SECTION_SYMBOLS 1
678 /* Resolve U.A.OFFSET_SYM and U.A.SYM fields of RELOC_LIST entries,
679 and check for validity. Convert RELOC_LIST from using U.A fields
682 resolve_reloc_expr_symbols (void)
684 bfd_vma addr_mask
= 1;
685 struct reloc_list
*r
;
687 /* Avoid a shift by the width of type. */
688 addr_mask
<<= bfd_arch_bits_per_address (stdoutput
) - 1;
692 for (r
= reloc_list
; r
; r
= r
->next
)
694 reloc_howto_type
*howto
= r
->u
.a
.howto
;
697 bfd_vma offset
, addend
;
700 resolve_symbol_value (r
->u
.a
.offset_sym
);
701 symval
= symbol_get_value_expression (r
->u
.a
.offset_sym
);
705 if (symval
->X_op
== O_constant
)
706 sym
= r
->u
.a
.offset_sym
;
707 else if (symval
->X_op
== O_symbol
)
709 sym
= symval
->X_add_symbol
;
710 offset
= symval
->X_add_number
;
711 symval
= symbol_get_value_expression (symval
->X_add_symbol
);
714 || symval
->X_op
!= O_constant
715 || (sec
= S_GET_SEGMENT (sym
)) == NULL
716 || !SEG_NORMAL (sec
))
718 as_bad_where (r
->file
, r
->line
, _("invalid offset expression"));
722 offset
+= S_GET_VALUE (sym
);
725 addend
= r
->u
.a
.addend
;
726 if (r
->u
.a
.sym
!= NULL
)
728 resolve_symbol_value (r
->u
.a
.sym
);
729 symval
= symbol_get_value_expression (r
->u
.a
.sym
);
730 if (symval
->X_op
== O_constant
)
732 else if (symval
->X_op
== O_symbol
)
734 sym
= symval
->X_add_symbol
;
735 addend
+= symval
->X_add_number
;
736 symval
= symbol_get_value_expression (symval
->X_add_symbol
);
738 if (symval
->X_op
!= O_constant
)
740 as_bad_where (r
->file
, r
->line
, _("invalid reloc expression"));
743 else if (sym
!= NULL
&& sec
!= NULL
)
745 /* Convert relocs against local symbols to refer to the
746 corresponding section symbol plus offset instead. Keep
747 PC-relative relocs of the REL variety intact though to
748 prevent the offset from overflowing the relocated field,
749 unless it has enough bits to cover the whole address
752 && S_IS_DEFINED (sym
)
753 && !symbol_section_p (sym
)
755 || (howto
->partial_inplace
756 && (!howto
->pc_relative
757 || howto
->src_mask
== addr_mask
))))
759 asection
*symsec
= S_GET_SEGMENT (sym
);
760 if (!(((symsec
->flags
& SEC_MERGE
) != 0
762 || (symsec
->flags
& SEC_THREAD_LOCAL
) != 0))
764 addend
+= S_GET_VALUE (sym
);
765 sym
= section_symbol (symsec
);
768 symbol_mark_used_in_reloc (sym
);
773 if (abs_section_sym
== NULL
)
774 abs_section_sym
= section_symbol (absolute_section
);
775 sym
= abs_section_sym
;
779 r
->u
.b
.s
= symbol_get_bfdsym (sym
);
780 r
->u
.b
.r
.sym_ptr_ptr
= &r
->u
.b
.s
;
781 r
->u
.b
.r
.address
= offset
;
782 r
->u
.b
.r
.addend
= addend
;
783 r
->u
.b
.r
.howto
= howto
;
787 /* This pass over fixups decides whether symbols can be replaced with
791 adjust_reloc_syms (bfd
*abfd ATTRIBUTE_UNUSED
,
793 void *xxx ATTRIBUTE_UNUSED
)
795 segment_info_type
*seginfo
= seg_info (sec
);
802 dump_section_relocs (abfd
, sec
, stderr
);
804 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
808 else if (fixp
->fx_addsy
)
814 fprintf (stderr
, "\n\nadjusting fixup:\n");
818 sym
= fixp
->fx_addsy
;
820 /* All symbols should have already been resolved at this
821 point. It is possible to see unresolved expression
822 symbols, though, since they are not in the regular symbol
824 resolve_symbol_value (sym
);
826 if (fixp
->fx_subsy
!= NULL
)
827 resolve_symbol_value (fixp
->fx_subsy
);
829 /* If this symbol is equated to an undefined or common symbol,
830 convert the fixup to being against that symbol. */
831 while (symbol_equated_reloc_p (sym
)
832 || S_IS_WEAKREFR (sym
))
834 symbolS
*newsym
= symbol_get_value_expression (sym
)->X_add_symbol
;
837 fixp
->fx_offset
+= symbol_get_value_expression (sym
)->X_add_number
;
838 fixp
->fx_addsy
= newsym
;
842 if (symbol_mri_common_p (sym
))
844 fixp
->fx_offset
+= S_GET_VALUE (sym
);
845 fixp
->fx_addsy
= symbol_get_value_expression (sym
)->X_add_symbol
;
849 /* If the symbol is undefined, common, weak, or global (ELF
850 shared libs), we can't replace it with the section symbol. */
851 if (S_FORCE_RELOC (fixp
->fx_addsy
, 1))
854 /* Is there some other (target cpu dependent) reason we can't adjust
855 this one? (E.g. relocations involving function addresses on
857 #ifdef tc_fix_adjustable
858 if (! tc_fix_adjustable (fixp
))
862 /* Since we're reducing to section symbols, don't attempt to reduce
863 anything that's already using one. */
864 if (symbol_section_p (sym
))
866 /* Mark the section symbol used in relocation so that it will
867 be included in the symbol table. */
868 symbol_mark_used_in_reloc (sym
);
872 symsec
= S_GET_SEGMENT (sym
);
876 if (bfd_is_abs_section (symsec
)
877 || symsec
== reg_section
)
879 /* The fixup_segment routine normally will not use this
880 symbol in a relocation. */
884 /* Don't try to reduce relocs which refer to non-local symbols
885 in .linkonce sections. It can lead to confusion when a
886 debugging section refers to a .linkonce section. I hope
887 this will always be correct. */
888 if (symsec
!= sec
&& ! S_IS_LOCAL (sym
))
890 if ((symsec
->flags
& SEC_LINK_ONCE
) != 0
892 /* The GNU toolchain uses an extension for ELF: a
893 section beginning with the magic string
894 .gnu.linkonce is a linkonce section. */
895 && startswith (segment_name (symsec
), ".gnu.linkonce")))
899 /* Never adjust a reloc against local symbol in a merge section
900 with non-zero addend. */
901 if ((symsec
->flags
& SEC_MERGE
) != 0
902 && (fixp
->fx_offset
!= 0 || fixp
->fx_subsy
!= NULL
))
905 /* Never adjust a reloc against TLS local symbol. */
906 if ((symsec
->flags
& SEC_THREAD_LOCAL
) != 0)
909 val
= S_GET_VALUE (sym
);
911 #if defined(TC_AARCH64) && defined(OBJ_COFF)
912 /* coff aarch64 relocation offsets need to be limited to 21bits.
913 This is because addend may need to be stored in an ADRP instruction.
914 In this case the addend cannot be stored down shifted otherwise rounding errors occur. */
915 if ((val
+ 0x100000) > 0x1fffff)
919 /* We refetch the segment when calling section_symbol, rather
920 than using symsec, because S_GET_VALUE may wind up changing
921 the section when it calls resolve_symbol_value. */
922 fixp
->fx_offset
+= val
;
923 fixp
->fx_addsy
= section_symbol (S_GET_SEGMENT (sym
));
925 fprintf (stderr
, "\nadjusted fixup:\n");
930 dump_section_relocs (abfd
, sec
, stderr
);
934 as_bad_subtract (fixS
*fixp
)
936 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
937 _("can't resolve %s - %s"),
938 fixp
->fx_addsy
? S_GET_NAME (fixp
->fx_addsy
) : "0",
939 S_GET_NAME (fixp
->fx_subsy
));
944 Go through all the fixS's in a segment and see which ones can be
945 handled now. (These consist of fixS where we have since discovered
946 the value of a symbol, or the address of the frag involved.)
947 For each one, call md_apply_fix to put the fix into the frag data.
948 Ones that we couldn't completely handle here will be output later
949 by emit_relocations. */
952 fixup_segment (fixS
*fixP
, segT this_segment
)
957 if (fixP
!= NULL
&& abs_section_sym
== NULL
)
958 abs_section_sym
= section_symbol (absolute_section
);
960 /* If the linker is doing the relaxing, we must not do any fixups.
962 Well, strictly speaking that's not true -- we could do any that
963 are PC-relative and don't cross regions that could change size. */
964 if (linkrelax
&& TC_LINKRELAX_FIXUP (this_segment
))
966 for (; fixP
; fixP
= fixP
->fx_next
)
969 if (fixP
->fx_addsy
== NULL
)
971 /* There was no symbol required by this relocation.
972 However, BFD doesn't really handle relocations
973 without symbols well. So fake up a local symbol in
974 the absolute section. */
975 fixP
->fx_addsy
= abs_section_sym
;
977 symbol_mark_used_in_reloc (fixP
->fx_addsy
);
978 if (fixP
->fx_subsy
!= NULL
)
979 symbol_mark_used_in_reloc (fixP
->fx_subsy
);
984 for (; fixP
; fixP
= fixP
->fx_next
)
986 segT add_symbol_segment
= absolute_section
;
989 fprintf (stderr
, "\nprocessing fixup:\n");
993 fragP
= fixP
->fx_frag
;
995 #ifdef TC_VALIDATE_FIX
996 TC_VALIDATE_FIX (fixP
, this_segment
, skip
);
998 add_number
= fixP
->fx_offset
;
1000 if (fixP
->fx_addsy
!= NULL
)
1001 add_symbol_segment
= S_GET_SEGMENT (fixP
->fx_addsy
);
1003 if (fixP
->fx_subsy
!= NULL
)
1005 segT sub_symbol_segment
;
1007 resolve_symbol_value (fixP
->fx_subsy
);
1008 sub_symbol_segment
= S_GET_SEGMENT (fixP
->fx_subsy
);
1010 if (fixP
->fx_addsy
!= NULL
1011 && sub_symbol_segment
== add_symbol_segment
1012 && !S_FORCE_RELOC (fixP
->fx_addsy
, 0)
1013 && !S_FORCE_RELOC (fixP
->fx_subsy
, 0)
1014 && !TC_FORCE_RELOCATION_SUB_SAME (fixP
, add_symbol_segment
))
1016 add_number
+= S_GET_VALUE_WHERE (fixP
->fx_addsy
, fixP
->fx_file
, fixP
->fx_line
);
1017 add_number
-= S_GET_VALUE_WHERE (fixP
->fx_subsy
, fixP
->fx_file
, fixP
->fx_line
);
1018 fixP
->fx_offset
= add_number
;
1019 fixP
->fx_addsy
= NULL
;
1020 fixP
->fx_subsy
= NULL
;
1022 /* See the comment below about 68k weirdness. */
1026 else if (sub_symbol_segment
== absolute_section
1027 && !S_FORCE_RELOC (fixP
->fx_subsy
, 0)
1028 && !TC_FORCE_RELOCATION_SUB_ABS (fixP
, add_symbol_segment
))
1030 add_number
-= S_GET_VALUE_WHERE (fixP
->fx_subsy
, fixP
->fx_file
, fixP
->fx_line
);
1031 fixP
->fx_offset
= add_number
;
1032 fixP
->fx_subsy
= NULL
;
1034 else if (sub_symbol_segment
== this_segment
1035 && !S_FORCE_RELOC (fixP
->fx_subsy
, 0)
1036 && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP
, add_symbol_segment
))
1038 add_number
-= S_GET_VALUE_WHERE (fixP
->fx_subsy
, fixP
->fx_file
, fixP
->fx_line
);
1039 fixP
->fx_offset
= (add_number
+ fixP
->fx_dot_value
1040 + fixP
->fx_dot_frag
->fr_address
);
1042 /* Make it pc-relative. If the back-end code has not
1043 selected a pc-relative reloc, cancel the adjustment
1044 we do later on all pc-relative relocs. */
1047 /* Do this for m68k even if it's already described
1048 as pc-relative. On the m68k, an operand of
1049 "pc@(foo-.-2)" should address "foo" in a
1050 pc-relative mode. */
1054 add_number
+= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
1055 fixP
->fx_subsy
= NULL
;
1058 else if (!TC_VALIDATE_FIX_SUB (fixP
, add_symbol_segment
))
1060 if (!md_register_arithmetic
1061 && (add_symbol_segment
== reg_section
1062 || sub_symbol_segment
== reg_section
))
1063 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1064 _("register value used as expression"));
1066 as_bad_subtract (fixP
);
1068 else if (sub_symbol_segment
!= undefined_section
1069 && ! bfd_is_com_section (sub_symbol_segment
)
1070 && MD_APPLY_SYM_VALUE (fixP
))
1071 add_number
-= S_GET_VALUE_WHERE (fixP
->fx_subsy
, fixP
->fx_file
, fixP
->fx_line
);
1076 if (add_symbol_segment
== this_segment
1077 && !S_FORCE_RELOC (fixP
->fx_addsy
, 0)
1078 && !TC_FORCE_RELOCATION_LOCAL (fixP
))
1080 /* This fixup was made when the symbol's segment was
1081 SEG_UNKNOWN, but it is now in the local segment.
1082 So we know how to do the address without relocation. */
1083 add_number
+= S_GET_VALUE_WHERE (fixP
->fx_addsy
, fixP
->fx_file
, fixP
->fx_line
);
1084 fixP
->fx_offset
= add_number
;
1086 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
1087 fixP
->fx_addsy
= NULL
;
1090 else if (add_symbol_segment
== absolute_section
1091 && !S_FORCE_RELOC (fixP
->fx_addsy
, 0)
1092 && !TC_FORCE_RELOCATION_ABS (fixP
))
1094 add_number
+= S_GET_VALUE_WHERE (fixP
->fx_addsy
, fixP
->fx_file
, fixP
->fx_line
);
1095 fixP
->fx_offset
= add_number
;
1096 fixP
->fx_addsy
= NULL
;
1098 else if (add_symbol_segment
!= undefined_section
1099 && ! bfd_is_com_section (add_symbol_segment
)
1100 && MD_APPLY_SYM_VALUE (fixP
))
1101 add_number
+= S_GET_VALUE_WHERE (fixP
->fx_addsy
, fixP
->fx_file
, fixP
->fx_line
);
1106 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment
);
1107 if (!fixP
->fx_done
&& fixP
->fx_addsy
== NULL
)
1109 /* There was no symbol required by this relocation.
1110 However, BFD doesn't really handle relocations
1111 without symbols well. So fake up a local symbol in
1112 the absolute section. */
1113 fixP
->fx_addsy
= abs_section_sym
;
1118 md_apply_fix (fixP
, &add_number
, this_segment
);
1122 if (fixP
->fx_addsy
== NULL
)
1123 fixP
->fx_addsy
= abs_section_sym
;
1124 symbol_mark_used_in_reloc (fixP
->fx_addsy
);
1125 if (fixP
->fx_subsy
!= NULL
)
1126 symbol_mark_used_in_reloc (fixP
->fx_subsy
);
1129 if (!fixP
->fx_no_overflow
&& fixP
->fx_size
!= 0)
1131 if (fixP
->fx_size
< sizeof (valueT
))
1136 mask
--; /* Set all bits to one. */
1137 mask
<<= fixP
->fx_size
* 8 - (fixP
->fx_signed
? 1 : 0);
1138 if ((add_number
& mask
) != 0
1140 ? (add_number
& mask
) != mask
1141 : (-add_number
& mask
) != 0))
1143 char buf
[50], buf2
[50];
1144 bfd_sprintf_vma (stdoutput
, buf
, fragP
->fr_address
+ fixP
->fx_where
);
1145 if (add_number
> 1000)
1146 bfd_sprintf_vma (stdoutput
, buf2
, add_number
);
1148 sprintf (buf2
, "%ld", (long) add_number
);
1149 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1150 ngettext ("value of %s too large for field "
1152 "value of %s too large for field "
1153 "of %d bytes at %s",
1155 buf2
, fixP
->fx_size
, buf
);
1156 } /* Generic error checking. */
1158 #ifdef WARN_SIGNED_OVERFLOW_WORD
1159 /* Warn if a .word value is too large when treated as a signed
1160 number. We already know it is not too negative. This is to
1161 catch over-large switches generated by gcc on the 68k. */
1162 if (!flag_signed_overflow_ok
1163 && fixP
->fx_size
== 2
1164 && add_number
> 0x7fff)
1165 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1166 _("signed .word overflow; switch may be too large; %ld at 0x%lx"),
1168 (long) (fragP
->fr_address
+ fixP
->fx_where
));
1172 #ifdef TC_VALIDATE_FIX
1173 skip
: ATTRIBUTE_UNUSED_LABEL
1177 fprintf (stderr
, "result:\n");
1180 } /* For each fixS in this segment. */
1184 fix_segment (bfd
*abfd ATTRIBUTE_UNUSED
,
1186 void *xxx ATTRIBUTE_UNUSED
)
1188 segment_info_type
*seginfo
= seg_info (sec
);
1190 fixup_segment (seginfo
->fix_root
, sec
);
1194 install_reloc (asection
*sec
, arelent
*reloc
, fragS
*fragp
,
1195 const char *file
, unsigned int line
)
1198 bfd_reloc_status_type s
;
1201 if (reloc
->sym_ptr_ptr
!= NULL
1202 && (sym
= *reloc
->sym_ptr_ptr
) != NULL
1203 && (sym
->flags
& BSF_KEEP
) == 0
1204 && ((sym
->flags
& BSF_SECTION_SYM
) == 0
1205 || (EMIT_SECTION_SYMBOLS
1206 && !bfd_is_abs_section (sym
->section
))))
1207 as_bad_where (file
, line
, _("redefined symbol cannot be used on reloc"));
1209 s
= bfd_install_relocation (stdoutput
, reloc
,
1210 fragp
->fr_literal
, fragp
->fr_address
,
1216 case bfd_reloc_overflow
:
1217 as_bad_where (file
, line
, _("relocation overflow"));
1219 case bfd_reloc_outofrange
:
1220 as_bad_where (file
, line
, _("relocation out of range"));
1223 as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"),
1229 get_frag_for_reloc (fragS
*last_frag
,
1230 const segment_info_type
*seginfo
,
1231 const struct reloc_list
*r
)
1235 for (f
= last_frag
; f
!= NULL
; f
= f
->fr_next
)
1236 if (f
->fr_address
<= r
->u
.b
.r
.address
1237 && r
->u
.b
.r
.address
< f
->fr_address
+ f
->fr_fix
)
1240 for (f
= seginfo
->frchainP
->frch_root
; f
!= NULL
; f
= f
->fr_next
)
1241 if (f
->fr_address
<= r
->u
.b
.r
.address
1242 && r
->u
.b
.r
.address
< f
->fr_address
+ f
->fr_fix
)
1245 for (f
= seginfo
->frchainP
->frch_root
; f
!= NULL
; f
= f
->fr_next
)
1246 if (f
->fr_address
<= r
->u
.b
.r
.address
1247 && r
->u
.b
.r
.address
<= f
->fr_address
+ f
->fr_fix
)
1250 as_bad_where (r
->file
, r
->line
,
1251 _("reloc not within (fixed part of) section"));
1256 write_relocs (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
,
1257 void *xxx ATTRIBUTE_UNUSED
)
1259 segment_info_type
*seginfo
= seg_info (sec
);
1261 struct reloc_list
*my_reloc_list
, **rp
, *r
;
1266 /* If seginfo is NULL, we did not create this section; don't do
1267 anything with it. */
1268 if (seginfo
== NULL
)
1272 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
1276 #ifdef RELOC_EXPANSION_POSSIBLE
1277 n
*= MAX_RELOC_EXPANSION
;
1280 /* Extract relocs for this section from reloc_list. */
1283 my_reloc_list
= NULL
;
1284 while ((r
= *rp
) != NULL
)
1286 if (r
->u
.b
.sec
== sec
)
1289 r
->next
= my_reloc_list
;
1297 relocs
= XCNEWVEC (arelent
*, n
);
1302 for (fixp
= seginfo
->fix_root
; fixp
!= (fixS
*) NULL
; fixp
= fixp
->fx_next
)
1307 #ifndef RELOC_EXPANSION_POSSIBLE
1316 fx_size
= fixp
->fx_size
;
1317 slack
= TC_FX_SIZE_SLACK (fixp
);
1319 fx_size
= fx_size
> slack
? fx_size
- slack
: 0;
1320 loc
= fixp
->fx_where
+ fx_size
;
1321 if (slack
>= 0 && loc
> fixp
->fx_frag
->fr_fix
)
1322 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1323 _("internal error: fixup not contained within frag"));
1325 #ifdef obj_fixup_removed_symbol
1326 if (fixp
->fx_addsy
&& symbol_removed_p (fixp
->fx_addsy
))
1327 obj_fixup_removed_symbol (&fixp
->fx_addsy
);
1328 if (fixp
->fx_subsy
&& symbol_removed_p (fixp
->fx_subsy
))
1329 obj_fixup_removed_symbol (&fixp
->fx_subsy
);
1332 #ifndef RELOC_EXPANSION_POSSIBLE
1333 *reloc
= tc_gen_reloc (sec
, fixp
);
1335 reloc
= tc_gen_reloc (sec
, fixp
);
1340 while (r
!= NULL
&& r
->u
.b
.r
.address
< (*reloc
)->address
)
1342 fragS
*f
= get_frag_for_reloc (last_frag
, seginfo
, r
);
1346 relocs
[n
++] = &r
->u
.b
.r
;
1347 install_reloc (sec
, &r
->u
.b
.r
, f
, r
->file
, r
->line
);
1351 #ifdef GAS_SORT_RELOCS
1352 if (n
!= 0 && (*reloc
)->address
< relocs
[n
- 1]->address
)
1356 bfd_vma look
= (*reloc
)->address
;
1359 size_t mid
= (lo
+ hi
) / 2;
1360 if (relocs
[mid
]->address
> look
)
1365 if (relocs
[mid
]->address
== look
)
1369 while (lo
< hi
&& relocs
[lo
]->address
== look
)
1371 memmove (relocs
+ lo
+ 1, relocs
+ lo
,
1372 (n
- lo
) * sizeof (*relocs
));
1374 relocs
[lo
] = *reloc
;
1378 relocs
[n
++] = *reloc
;
1379 install_reloc (sec
, *reloc
, fixp
->fx_frag
,
1380 fixp
->fx_file
, fixp
->fx_line
);
1381 #ifndef RELOC_EXPANSION_POSSIBLE
1391 fragS
*f
= get_frag_for_reloc (last_frag
, seginfo
, r
);
1395 relocs
[n
++] = &r
->u
.b
.r
;
1396 install_reloc (sec
, &r
->u
.b
.r
, f
, r
->file
, r
->line
);
1403 unsigned int k
, j
, nsyms
;
1405 sympp
= bfd_get_outsymbols (stdoutput
);
1406 nsyms
= bfd_get_symcount (stdoutput
);
1407 for (k
= 0; k
< n
; k
++)
1408 if (((*relocs
[k
]->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
1410 for (j
= 0; j
< nsyms
; j
++)
1411 if (sympp
[j
] == *relocs
[k
]->sym_ptr_ptr
)
1419 bfd_set_reloc (stdoutput
, sec
, n
? relocs
: NULL
, n
);
1421 #ifdef SET_SECTION_RELOCS
1422 SET_SECTION_RELOCS (sec
, relocs
, n
);
1429 fprintf (stderr
, "relocs for sec %s\n", sec
->name
);
1430 for (k
= 0; k
< n
; k
++)
1432 arelent
*rel
= relocs
[k
];
1433 asymbol
*s
= *rel
->sym_ptr_ptr
;
1434 fprintf (stderr
, " reloc %2d @%p off %4lx : sym %-10s addend %lx\n",
1435 k
, rel
, (unsigned long)rel
->address
, s
->name
,
1436 (unsigned long)rel
->addend
);
1443 compress_frag (bool use_zstd
, void *ctx
, const char *contents
, int in_size
,
1444 fragS
**last_newf
, struct obstack
*ob
)
1447 int total_out_size
= 0;
1448 fragS
*f
= *last_newf
;
1452 /* Call the compression routine repeatedly until it has finished
1453 processing the frag. */
1456 /* Reserve all the space available in the current chunk.
1457 If none is available, start a new frag. */
1458 avail_out
= obstack_room (ob
);
1461 obstack_finish (ob
);
1462 f
= frag_alloc (ob
);
1463 f
->fr_type
= rs_fill
;
1464 (*last_newf
)->fr_next
= f
;
1466 avail_out
= obstack_room (ob
);
1469 as_fatal (_("can't extend frag"));
1470 next_out
= obstack_next_free (ob
);
1471 obstack_blank_fast (ob
, avail_out
);
1472 out_size
= compress_data (use_zstd
, ctx
, &contents
, &in_size
, &next_out
,
1477 f
->fr_fix
+= out_size
;
1478 total_out_size
+= out_size
;
1480 /* Return unused space. */
1482 obstack_blank_fast (ob
, -avail_out
);
1485 return total_out_size
;
1489 compress_debug (bfd
*abfd
, asection
*sec
, void *xxx ATTRIBUTE_UNUSED
)
1491 segment_info_type
*seginfo
= seg_info (sec
);
1492 bfd_size_type uncompressed_size
= sec
->size
;
1493 flagword flags
= bfd_section_flags (sec
);
1496 || uncompressed_size
< 32
1497 || (flags
& SEC_HAS_CONTENTS
) == 0)
1500 const char *section_name
= bfd_section_name (sec
);
1501 if (!startswith (section_name
, ".debug_")
1502 && !startswith (section_name
, ".gnu.debuglto_.debug_")
1503 && !startswith (section_name
, ".gnu.linkonce.wi."))
1506 bool use_zstd
= abfd
->flags
& BFD_COMPRESS_ZSTD
;
1507 void *ctx
= compress_init (use_zstd
);
1511 unsigned int header_size
;
1512 if ((abfd
->flags
& BFD_COMPRESS_GABI
) == 0)
1515 header_size
= bfd_get_compression_header_size (stdoutput
, NULL
);
1517 /* Create a new frag to contain the compression header. */
1518 struct obstack
*ob
= &seginfo
->frchainP
->frch_obstack
;
1519 fragS
*first_newf
= frag_alloc (ob
);
1520 if (obstack_room (ob
) < header_size
)
1521 first_newf
= frag_alloc (ob
);
1522 if (obstack_room (ob
) < header_size
)
1523 as_fatal (ngettext ("can't extend frag %lu char",
1524 "can't extend frag %lu chars",
1525 (unsigned long) header_size
),
1526 (unsigned long) header_size
);
1527 fragS
*last_newf
= first_newf
;
1528 obstack_blank_fast (ob
, header_size
);
1529 last_newf
->fr_type
= rs_fill
;
1530 last_newf
->fr_fix
= header_size
;
1531 char *header
= last_newf
->fr_literal
;
1532 bfd_size_type compressed_size
= header_size
;
1534 /* Stream the frags through the compression engine, adding new frags
1535 as necessary to accommodate the compressed output. */
1536 for (fragS
*f
= seginfo
->frchainP
->frch_root
;
1545 gas_assert (f
->fr_type
== rs_fill
);
1548 out_size
= compress_frag (use_zstd
, ctx
, f
->fr_literal
, f
->fr_fix
,
1552 compressed_size
+= out_size
;
1554 fill_literal
= f
->fr_literal
+ f
->fr_fix
;
1555 fill_size
= f
->fr_var
;
1556 count
= f
->fr_offset
;
1557 gas_assert (count
>= 0);
1558 if (fill_size
&& count
)
1562 out_size
= compress_frag (use_zstd
, ctx
, fill_literal
,
1563 (int)fill_size
, &last_newf
, ob
);
1566 compressed_size
+= out_size
;
1571 /* Flush the compression state. */
1578 /* Reserve all the space available in the current chunk.
1579 If none is available, start a new frag. */
1580 avail_out
= obstack_room (ob
);
1585 obstack_finish (ob
);
1586 newf
= frag_alloc (ob
);
1587 newf
->fr_type
= rs_fill
;
1588 last_newf
->fr_next
= newf
;
1590 avail_out
= obstack_room (ob
);
1593 as_fatal (_("can't extend frag"));
1594 next_out
= obstack_next_free (ob
);
1595 obstack_blank_fast (ob
, avail_out
);
1596 int x
= compress_finish (use_zstd
, ctx
, &next_out
, &avail_out
, &out_size
);
1600 last_newf
->fr_fix
+= out_size
;
1601 compressed_size
+= out_size
;
1603 /* Return unused space. */
1605 obstack_blank_fast (ob
, -avail_out
);
1611 /* PR binutils/18087: If compression didn't make the section smaller,
1612 just keep it uncompressed. */
1613 if (compressed_size
>= uncompressed_size
)
1616 /* Replace the uncompressed frag list with the compressed frag list. */
1617 seginfo
->frchainP
->frch_root
= first_newf
;
1618 seginfo
->frchainP
->frch_last
= last_newf
;
1620 /* Update the section size and its name. */
1621 bfd_update_compression_header (abfd
, (bfd_byte
*) header
, sec
);
1622 bool x
= bfd_set_section_size (sec
, compressed_size
);
1624 if ((abfd
->flags
& BFD_COMPRESS_GABI
) == 0
1625 && section_name
[1] == 'd')
1627 char *compressed_name
= bfd_debug_name_to_zdebug (abfd
, section_name
);
1628 bfd_rename_section (sec
, compressed_name
);
1632 #ifndef md_generate_nops
1633 /* Genenerate COUNT bytes of no-op instructions to WHERE. A target
1634 backend must override this with proper no-op instructions. */
1637 md_generate_nops (fragS
*f ATTRIBUTE_UNUSED
,
1638 char *where ATTRIBUTE_UNUSED
,
1639 offsetT count ATTRIBUTE_UNUSED
,
1640 int control ATTRIBUTE_UNUSED
)
1642 as_bad (_("unimplemented .nops directive"));
1647 write_contents (bfd
*abfd ATTRIBUTE_UNUSED
,
1649 void *xxx ATTRIBUTE_UNUSED
)
1651 segment_info_type
*seginfo
= seg_info (sec
);
1652 addressT offset
= 0;
1655 /* Write out the frags. */
1657 || !(bfd_section_flags (sec
) & SEC_HAS_CONTENTS
))
1660 for (f
= seginfo
->frchainP
->frch_root
;
1669 gas_assert (f
->fr_type
== rs_fill
|| f
->fr_type
== rs_fill_nop
);
1672 x
= bfd_set_section_contents (stdoutput
, sec
,
1673 f
->fr_literal
, (file_ptr
) offset
,
1674 (bfd_size_type
) f
->fr_fix
);
1676 as_fatal (ngettext ("can't write %ld byte "
1677 "to section %s of %s: '%s'",
1678 "can't write %ld bytes "
1679 "to section %s of %s: '%s'",
1682 bfd_section_name (sec
), bfd_get_filename (stdoutput
),
1683 bfd_errmsg (bfd_get_error ()));
1684 offset
+= f
->fr_fix
;
1687 fill_size
= f
->fr_var
;
1688 count
= f
->fr_offset
;
1689 fill_literal
= f
->fr_literal
+ f
->fr_fix
;
1691 if (f
->fr_type
== rs_fill_nop
)
1693 gas_assert (count
>= 0 && fill_size
== 1);
1696 char *buf
= xmalloc (count
);
1697 md_generate_nops (f
, buf
, count
, *fill_literal
);
1698 x
= bfd_set_section_contents
1699 (stdoutput
, sec
, buf
, (file_ptr
) offset
,
1700 (bfd_size_type
) count
);
1702 as_fatal (ngettext ("can't fill %ld byte "
1703 "in section %s of %s: '%s'",
1704 "can't fill %ld bytes "
1705 "in section %s of %s: '%s'",
1708 bfd_section_name (sec
),
1709 bfd_get_filename (stdoutput
),
1710 bfd_errmsg (bfd_get_error ()));
1713 if (listing
& LISTING_LISTING
)
1722 gas_assert (count
>= 0);
1723 if (fill_size
&& count
)
1726 if (fill_size
> sizeof (buf
))
1728 /* Do it the old way. Can this ever happen? */
1731 x
= bfd_set_section_contents (stdoutput
, sec
,
1734 (bfd_size_type
) fill_size
);
1736 as_fatal (ngettext ("can't fill %ld byte "
1737 "in section %s of %s: '%s'",
1738 "can't fill %ld bytes "
1739 "in section %s of %s: '%s'",
1742 bfd_section_name (sec
),
1743 bfd_get_filename (stdoutput
),
1744 bfd_errmsg (bfd_get_error ()));
1745 offset
+= fill_size
;
1750 /* Build a buffer full of fill objects and output it as
1751 often as necessary. This saves on the overhead of
1752 potentially lots of bfd_set_section_contents calls. */
1756 n_per_buf
= sizeof (buf
);
1757 memset (buf
, *fill_literal
, n_per_buf
);
1762 n_per_buf
= sizeof (buf
) / fill_size
;
1763 for (i
= n_per_buf
, bufp
= buf
; i
; i
--, bufp
+= fill_size
)
1764 memcpy (bufp
, fill_literal
, fill_size
);
1766 for (; count
> 0; count
-= n_per_buf
)
1768 n_per_buf
= n_per_buf
> count
? count
: n_per_buf
;
1769 x
= bfd_set_section_contents
1770 (stdoutput
, sec
, buf
, (file_ptr
) offset
,
1771 (bfd_size_type
) n_per_buf
* fill_size
);
1773 as_fatal (ngettext ("can't fill %ld byte "
1774 "in section %s of %s: '%s'",
1775 "can't fill %ld bytes "
1776 "in section %s of %s: '%s'",
1777 (long) (n_per_buf
* fill_size
)),
1778 (long) (n_per_buf
* fill_size
),
1779 bfd_section_name (sec
),
1780 bfd_get_filename (stdoutput
),
1781 bfd_errmsg (bfd_get_error ()));
1782 offset
+= n_per_buf
* fill_size
;
1790 merge_data_into_text (void)
1792 seg_info (text_section
)->frchainP
->frch_last
->fr_next
=
1793 seg_info (data_section
)->frchainP
->frch_root
;
1794 seg_info (text_section
)->frchainP
->frch_last
=
1795 seg_info (data_section
)->frchainP
->frch_last
;
1796 seg_info (data_section
)->frchainP
= 0;
1807 /* Count symbols. We can't rely on a count made by the loop in
1808 write_object_file, because *_frob_file may add a new symbol or
1809 two. Generate unused section symbols only if needed. */
1811 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1812 if (!symbol_removed_p (symp
)
1813 && (bfd_keep_unused_section_symbols (stdoutput
)
1814 || !symbol_section_p (symp
)
1815 || symbol_used_in_reloc_p (symp
)))
1821 bfd_size_type amt
= (bfd_size_type
) nsyms
* sizeof (asymbol
*);
1823 asympp
= (asymbol
**) bfd_alloc (stdoutput
, amt
);
1824 symp
= symbol_rootP
;
1825 for (i
= 0; i
< nsyms
; symp
= symbol_next (symp
))
1826 if (!symbol_removed_p (symp
)
1827 && (bfd_keep_unused_section_symbols (stdoutput
)
1828 || !symbol_section_p (symp
)
1829 || symbol_used_in_reloc_p (symp
)))
1831 asympp
[i
] = symbol_get_bfdsym (symp
);
1832 if (asympp
[i
]->flags
!= BSF_SECTION_SYM
1833 || !(bfd_is_const_section (asympp
[i
]->section
)
1834 && asympp
[i
]->section
->symbol
== asympp
[i
]))
1835 asympp
[i
]->flags
|= BSF_KEEP
;
1836 symbol_mark_written (symp
);
1837 /* Include this section symbol in the symbol table. */
1838 if (symbol_section_p (symp
))
1839 asympp
[i
]->flags
|= BSF_SECTION_SYM_USED
;
1845 result
= bfd_set_symtab (stdoutput
, asympp
, nsyms
);
1846 gas_assert (result
);
1847 symbol_table_frozen
= 1;
1850 /* Finish the subsegments. After every sub-segment, we fake an
1851 ".align ...". This conforms to BSD4.2 brain-damage. We then fake
1852 ".fill 0" because that is the kind of frag that requires least
1853 thought. ".align" frags like to have a following frag since that
1854 makes calculating their intended length trivial. */
1856 #ifndef SUB_SEGMENT_ALIGN
1858 /* The last subsegment gets an alignment corresponding to the alignment
1859 of the section. This allows proper nop-filling at the end of
1860 code-bearing sections. */
1861 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
1862 (!(FRCHAIN)->frch_next && subseg_text_p (SEG) \
1863 && !do_not_pad_sections_to_alignment \
1864 ? get_recorded_alignment (SEG) \
1867 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
1872 subsegs_finish_section (asection
*s
)
1874 struct frchain
*frchainP
;
1875 segment_info_type
*seginfo
= seg_info (s
);
1879 /* This now gets called even if we had errors. In that case, any alignment
1880 is meaningless, and, moreover, will look weird if we are generating a
1883 do_not_pad_sections_to_alignment
= 1;
1885 for (frchainP
= seginfo
->frchainP
;
1887 frchainP
= frchainP
->frch_next
)
1891 subseg_set (s
, frchainP
->frch_subseg
);
1893 alignment
= SUB_SEGMENT_ALIGN (now_seg
, frchainP
);
1894 if ((bfd_section_flags (now_seg
) & (SEC_MERGE
| SEC_STRINGS
))
1895 && now_seg
->entsize
)
1897 unsigned int entsize
= now_seg
->entsize
;
1900 while ((entsize
& 1) == 0)
1906 if (entalign
> alignment
)
1907 alignment
= entalign
;
1910 if (subseg_text_p (now_seg
))
1911 frag_align_code (alignment
, 0);
1913 frag_align (alignment
, 0, 0);
1915 /* frag_align will have left a new frag.
1916 Use this last frag for an empty ".fill".
1918 For this segment ...
1919 Create a last frag. Do not leave a "being filled in frag". */
1920 frag_wane (frag_now
);
1921 frag_now
->fr_fix
= 0;
1922 know (frag_now
->fr_next
== NULL
);
1927 subsegs_finish (void)
1931 for (s
= stdoutput
->sections
; s
; s
= s
->next
)
1932 subsegs_finish_section (s
);
1937 create_obj_attrs_section (void)
1944 size
= bfd_elf_obj_attr_size (stdoutput
);
1948 name
= get_elf_backend_data (stdoutput
)->obj_attrs_section
;
1950 name
= ".gnu.attributes";
1951 s
= subseg_new (name
, 0);
1952 elf_section_type (s
)
1953 = get_elf_backend_data (stdoutput
)->obj_attrs_section_type
;
1954 bfd_set_section_flags (s
, SEC_READONLY
| SEC_DATA
);
1956 p
= frag_more (size
);
1957 bfd_elf_set_obj_attr_contents (stdoutput
, (bfd_byte
*)p
, size
);
1959 subsegs_finish_section (s
);
1960 relax_segment (seg_info (s
)->frchainP
->frch_root
, s
, 0);
1961 size_seg (stdoutput
, s
, NULL
);
1964 /* Create a relocation against an entry in a GNU Build attribute section. */
1967 create_note_reloc (segT sec
,
1969 bfd_size_type note_offset
,
1970 bfd_size_type desc2_offset
,
1976 struct reloc_list
* reloc
;
1978 reloc
= XNEW (struct reloc_list
);
1980 /* We create a .b type reloc as resolve_reloc_expr_symbols() has already been called. */
1981 reloc
->u
.b
.sec
= sec
;
1982 reloc
->u
.b
.s
= symbol_get_bfdsym (sym
);
1983 reloc
->u
.b
.r
.sym_ptr_ptr
= & reloc
->u
.b
.s
;
1984 reloc
->u
.b
.r
.address
= note_offset
+ desc2_offset
;
1985 reloc
->u
.b
.r
.addend
= addend
;
1986 reloc
->u
.b
.r
.howto
= bfd_reloc_type_lookup (stdoutput
, reloc_type
);
1988 if (reloc
->u
.b
.r
.howto
== NULL
)
1990 as_bad (_("unable to create reloc for build note"));
1994 reloc
->file
= N_("<gnu build note>");
1997 reloc
->next
= reloc_list
;
2000 /* For REL relocs, store the addend in the section. */
2001 if (! sec
->use_rela_p
2002 /* The SH target is a special case that uses RELA relocs
2003 but still stores the addend in the word being relocated. */
2004 || strstr (bfd_get_target (stdoutput
), "-sh") != NULL
)
2008 /* Zero out the addend, since it is now stored in the note. */
2009 reloc
->u
.b
.r
.addend
= 0;
2011 if (target_big_endian
)
2013 for (i
= desc2_size
; addend
!= 0 && i
> 0; addend
>>= 8, i
--)
2014 note
[desc2_offset
+ i
- 1] = (addend
& 0xff);
2018 for (i
= 0; addend
!= 0 && i
< desc2_size
; addend
>>= 8, i
++)
2019 note
[desc2_offset
+ i
] = (addend
& 0xff);
2025 maybe_generate_build_notes (void)
2032 offsetT desc2_offset
;
2037 if (! flag_generate_build_notes
2038 || bfd_get_section_by_name (stdoutput
,
2039 GNU_BUILD_ATTRS_SECTION_NAME
) != NULL
)
2042 /* Create a GNU Build Attribute section. */
2043 sec
= subseg_new (GNU_BUILD_ATTRS_SECTION_NAME
, false);
2044 elf_section_type (sec
) = SHT_NOTE
;
2045 bfd_set_section_flags (sec
, (SEC_READONLY
| SEC_HAS_CONTENTS
| SEC_DATA
2047 bfd_set_section_alignment (sec
, 2);
2049 /* Work out the size of the notes that we will create,
2050 and the relocation we should use. */
2051 if (bfd_arch_bits_per_address (stdoutput
) <= 32)
2054 desc_size
= 8; /* Two 4-byte offsets. */
2057 /* FIXME: The BFD backend for the CRX target does not support the
2058 BFD_RELOC_32, even though it really should. Likewise for the
2059 CR16 target. So we have special case code here... */
2060 if (strstr (bfd_get_target (stdoutput
), "-crx") != NULL
)
2061 desc_reloc
= BFD_RELOC_CRX_NUM32
;
2062 else if (strstr (bfd_get_target (stdoutput
), "-cr16") != NULL
)
2063 desc_reloc
= BFD_RELOC_CR16_NUM32
;
2065 desc_reloc
= BFD_RELOC_32
;
2070 desc_size
= 16; /* Two 8-byte offsets. */
2072 /* FIXME: The BFD backend for the IA64 target does not support the
2073 BFD_RELOC_64, even though it really should. The HPPA backend
2074 has a similar issue, although it does not support BFD_RELOCs at
2075 all! So we have special case code to handle these targets. */
2076 if (strstr (bfd_get_target (stdoutput
), "-ia64") != NULL
)
2077 desc_reloc
= target_big_endian
? BFD_RELOC_IA64_DIR32MSB
: BFD_RELOC_IA64_DIR32LSB
;
2078 else if (strstr (bfd_get_target (stdoutput
), "-hppa") != NULL
)
2079 desc_reloc
= 80; /* R_PARISC_DIR64. */
2081 desc_reloc
= BFD_RELOC_64
;
2084 /* We have to create a note for *each* code section.
2085 Linker garbage collection might discard some. */
2089 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
2090 if ((bsym
= symbol_get_bfdsym (sym
)) != NULL
2091 && bsym
->flags
& BSF_SECTION_SYM
2092 && bsym
->section
!= NULL
2093 /* Skip linkonce sections - we cannot use these section symbols as they may disappear. */
2094 && (bsym
->section
->flags
& (SEC_CODE
| SEC_LINK_ONCE
)) == SEC_CODE
2095 /* Not all linkonce sections are flagged... */
2096 && !startswith (S_GET_NAME (sym
), ".gnu.linkonce"))
2098 /* Create a version note. */
2100 note
= frag_more (note_size
);
2101 memset (note
, 0, note_size
);
2103 if (target_big_endian
)
2105 note
[3] = 8; /* strlen (name) + 1. */
2106 note
[7] = desc_size
; /* Two N-byte offsets. */
2107 note
[10] = NT_GNU_BUILD_ATTRIBUTE_OPEN
>> 8;
2108 note
[11] = NT_GNU_BUILD_ATTRIBUTE_OPEN
& 0xff;
2112 note
[0] = 8; /* strlen (name) + 1. */
2113 note
[4] = desc_size
; /* Two N-byte offsets. */
2114 note
[8] = NT_GNU_BUILD_ATTRIBUTE_OPEN
& 0xff;
2115 note
[9] = NT_GNU_BUILD_ATTRIBUTE_OPEN
>> 8;
2118 /* The a1 version number indicates that this note was
2119 generated by the assembler and not the gcc annobin plugin. */
2120 memcpy (note
+ 12, "GA$\x013a1", 8);
2122 /* Create a relocation to install the start address of the note... */
2123 create_note_reloc (sec
, sym
, total_size
, 20, desc_size
/ 2, desc_reloc
, 0, note
);
2125 /* ...and another one to install the end address. */
2126 create_note_reloc (sec
, sym
, total_size
, desc2_offset
,
2129 bfd_section_size (bsym
->section
),
2132 /* Mark the section symbol used in relocation so that it will be
2133 included in the symbol table. */
2134 symbol_mark_used_in_reloc (sym
);
2136 total_size
+= note_size
;
2137 /* FIXME: Maybe add a note recording the assembler command line and version ? */
2140 /* Install the note(s) into the section. */
2142 bfd_set_section_contents (stdoutput
, sec
, (bfd_byte
*) note
, 0, total_size
);
2143 subsegs_finish_section (sec
);
2144 relax_segment (seg_info (sec
)->frchainP
->frch_root
, sec
, 0);
2145 size_seg (stdoutput
, sec
, NULL
);
2147 #endif /* OBJ_ELF */
2149 /* Write the object file. */
2152 write_object_file (void)
2154 struct relax_seg_info rsi
;
2155 #ifndef WORKING_DOT_WORD
2156 fragS
*fragP
; /* Track along all frags. */
2161 #ifdef md_pre_output_hook
2165 #ifdef md_pre_relax_hook
2169 /* From now on, we don't care about sub-segments. Build one frag chain
2170 for each segment. Linked through fr_next. */
2172 /* Remove the sections created by gas for its own purposes. */
2176 bfd_section_list_remove (stdoutput
, reg_section
);
2177 bfd_section_list_remove (stdoutput
, expr_section
);
2178 stdoutput
->section_count
-= 2;
2180 bfd_map_over_sections (stdoutput
, renumber_sections
, &i
);
2183 bfd_map_over_sections (stdoutput
, chain_frchains_together
, (char *) 0);
2185 /* We have two segments. If user gave -R flag, then we must put the
2186 data frags into the text segment. Do this before relaxing so
2187 we know to take advantage of -R and make shorter addresses. */
2188 if (flag_readonly_data_in_text
)
2190 merge_data_into_text ();
2196 #ifndef WORKING_DOT_WORD
2197 /* We need to reset the markers in the broken word list and
2198 associated frags between calls to relax_segment (via
2199 relax_seg). Since the broken word list is global, we do it
2200 once per round, rather than locally in relax_segment for each
2202 struct broken_word
*brokp
;
2204 for (brokp
= broken_words
;
2205 brokp
!= (struct broken_word
*) NULL
;
2206 brokp
= brokp
->next_broken_word
)
2210 if (brokp
->dispfrag
!= (fragS
*) NULL
2211 && brokp
->dispfrag
->fr_type
== rs_broken_word
)
2212 brokp
->dispfrag
->fr_subtype
= 0;
2217 bfd_map_over_sections (stdoutput
, relax_seg
, &rsi
);
2223 /* Note - Most ports will use the default value of
2224 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG, which 1. This will force
2225 local symbols to be resolved, removing their frag information.
2226 Some ports however, will not have finished relaxing all of
2227 their frags and will still need the local symbol frag
2228 information. These ports can set
2229 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to 0. */
2230 finalize_syms
= TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
;
2232 bfd_map_over_sections (stdoutput
, size_seg
, (char *) 0);
2234 /* Relaxation has completed. Freeze all syms. */
2237 dwarf2dbg_final_check ();
2239 #ifdef md_post_relax_hook
2245 create_obj_attrs_section ();
2248 #ifndef WORKING_DOT_WORD
2250 struct broken_word
*lie
;
2251 struct broken_word
**prevP
;
2253 prevP
= &broken_words
;
2254 for (lie
= broken_words
; lie
; lie
= lie
->next_broken_word
)
2259 subseg_change (lie
->seg
, lie
->subseg
);
2260 exp
.X_op
= O_subtract
;
2261 exp
.X_add_symbol
= lie
->add
;
2262 exp
.X_op_symbol
= lie
->sub
;
2263 exp
.X_add_number
= lie
->addnum
;
2264 #ifdef TC_CONS_FIX_NEW
2265 TC_CONS_FIX_NEW (lie
->frag
,
2266 lie
->word_goes_here
- lie
->frag
->fr_literal
,
2267 2, &exp
, TC_PARSE_CONS_RETURN_NONE
);
2269 fix_new_exp (lie
->frag
,
2270 lie
->word_goes_here
- lie
->frag
->fr_literal
,
2271 2, &exp
, 0, BFD_RELOC_16
);
2273 *prevP
= lie
->next_broken_word
;
2276 prevP
= &(lie
->next_broken_word
);
2278 for (lie
= broken_words
; lie
;)
2280 struct broken_word
*untruth
;
2282 addressT table_addr
;
2283 addressT from_addr
, to_addr
;
2286 subseg_change (lie
->seg
, lie
->subseg
);
2287 fragP
= lie
->dispfrag
;
2289 /* Find out how many broken_words go here. */
2292 untruth
&& untruth
->dispfrag
== fragP
;
2293 untruth
= untruth
->next_broken_word
)
2294 if (untruth
->added
== 1)
2297 table_ptr
= lie
->dispfrag
->fr_opcode
;
2298 table_addr
= (lie
->dispfrag
->fr_address
2299 + (table_ptr
- lie
->dispfrag
->fr_literal
));
2300 /* Create the jump around the long jumps. This is a short
2301 jump from table_ptr+0 to table_ptr+n*long_jump_size. */
2302 from_addr
= table_addr
;
2303 to_addr
= table_addr
+ md_short_jump_size
+ n
* md_long_jump_size
;
2304 md_create_short_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
,
2306 table_ptr
+= md_short_jump_size
;
2307 table_addr
+= md_short_jump_size
;
2310 lie
&& lie
->dispfrag
== fragP
;
2311 m
++, lie
= lie
->next_broken_word
)
2313 if (lie
->added
== 2)
2315 /* Patch the jump table. */
2316 for (untruth
= (struct broken_word
*) (fragP
->fr_symbol
);
2317 untruth
&& untruth
->dispfrag
== fragP
;
2318 untruth
= untruth
->next_broken_word
)
2320 if (untruth
->use_jump
== lie
)
2322 /* This is the offset from ??? to table_ptr+0.
2323 The target is the same for all users of this
2324 md_long_jump, but the "sub" bases (and hence the
2325 offsets) may be different. */
2326 addressT to_word
= table_addr
- S_GET_VALUE (untruth
->sub
);
2327 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
2328 TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_word
, untruth
);
2330 md_number_to_chars (untruth
->word_goes_here
, to_word
, 2);
2334 /* Install the long jump. */
2335 /* This is a long jump from table_ptr+0 to the final target. */
2336 from_addr
= table_addr
;
2337 to_addr
= S_GET_VALUE (lie
->add
) + lie
->addnum
;
2338 md_create_long_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
,
2340 table_ptr
+= md_long_jump_size
;
2341 table_addr
+= md_long_jump_size
;
2345 #endif /* not WORKING_DOT_WORD */
2347 /* Resolve symbol values. This needs to be done before processing
2353 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2354 resolve_symbol_value (symp
);
2356 resolve_local_symbol_values ();
2357 resolve_reloc_expr_symbols ();
2361 maybe_generate_build_notes ();
2364 #ifdef tc_frob_file_before_adjust
2365 tc_frob_file_before_adjust ();
2367 #ifdef obj_frob_file_before_adjust
2368 obj_frob_file_before_adjust ();
2371 bfd_map_over_sections (stdoutput
, adjust_reloc_syms
, (char *) 0);
2373 #ifdef tc_frob_file_before_fix
2374 tc_frob_file_before_fix ();
2376 #ifdef obj_frob_file_before_fix
2377 obj_frob_file_before_fix ();
2380 bfd_map_over_sections (stdoutput
, fix_segment
, (char *) 0);
2382 /* Set up symbol table, and write it out. */
2386 bool skip_next_symbol
= false;
2388 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2393 if (skip_next_symbol
)
2395 /* Don't do anything besides moving the value of the
2396 symbol from the GAS value-field to the BFD value-field. */
2397 symbol_get_bfdsym (symp
)->value
= S_GET_VALUE (symp
);
2398 skip_next_symbol
= false;
2402 if (symbol_mri_common_p (symp
))
2404 if (S_IS_EXTERNAL (symp
))
2405 as_bad (_("%s: global symbols not supported in common sections"),
2407 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2411 name
= S_GET_NAME (symp
);
2415 decode_local_label_name ((char *) S_GET_NAME (symp
));
2416 /* They only differ if `name' is a fb or dollar local
2418 if (name2
!= name
&& ! S_IS_DEFINED (symp
))
2419 as_bad (_("local label `%s' is not defined"), name2
);
2422 /* Do it again, because adjust_reloc_syms might introduce
2423 more symbols. They'll probably only be section symbols,
2424 but they'll still need to have the values computed. */
2425 resolve_symbol_value (symp
);
2427 /* Skip symbols which were equated to undefined or common
2429 if (symbol_equated_reloc_p (symp
)
2430 || S_IS_WEAKREFR (symp
))
2432 const char *sname
= S_GET_NAME (symp
);
2434 if (S_IS_COMMON (symp
)
2435 && !TC_FAKE_LABEL (sname
)
2436 && !S_IS_WEAKREFR (symp
))
2438 expressionS
*e
= symbol_get_value_expression (symp
);
2440 as_bad (_("`%s' can't be equated to common symbol `%s'"),
2441 sname
, S_GET_NAME (e
->X_add_symbol
));
2443 if (S_GET_SEGMENT (symp
) == reg_section
)
2445 /* Report error only if we know the symbol name. */
2446 if (S_GET_NAME (symp
) != reg_section
->name
)
2447 as_bad (_("can't make global register symbol `%s'"),
2450 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2454 #ifdef obj_frob_symbol
2455 obj_frob_symbol (symp
, punt
);
2457 #ifdef tc_frob_symbol
2458 if (! punt
|| symbol_used_in_reloc_p (symp
))
2459 tc_frob_symbol (symp
, punt
);
2462 /* If we don't want to keep this symbol, splice it out of
2463 the chain now. If EMIT_SECTION_SYMBOLS is 0, we never
2464 want section symbols. Otherwise, we skip local symbols
2465 and symbols that the frob_symbol macros told us to punt,
2466 but we keep such symbols if they are used in relocs. */
2467 if (symp
== abs_section_sym
2468 || (! EMIT_SECTION_SYMBOLS
2469 && symbol_section_p (symp
))
2470 /* Note that S_IS_EXTERNAL and S_IS_LOCAL are not always
2471 opposites. Sometimes the former checks flags and the
2472 latter examines the name... */
2473 || (!S_IS_EXTERNAL (symp
)
2474 && (punt
|| S_IS_LOCAL (symp
) ||
2475 (S_IS_WEAKREFD (symp
) && ! symbol_used_p (symp
)))
2476 && ! symbol_used_in_reloc_p (symp
)))
2478 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2480 /* After symbol_remove, symbol_next(symp) still returns
2481 the one that came after it in the chain. So we don't
2482 need to do any extra cleanup work here. */
2486 /* Make sure we really got a value for the symbol. */
2487 if (! symbol_resolved_p (symp
))
2489 as_bad (_("can't resolve value for symbol `%s'"),
2491 symbol_mark_resolved (symp
);
2494 /* Set the value into the BFD symbol. Up til now the value
2495 has only been kept in the gas symbolS struct. */
2496 symbol_get_bfdsym (symp
)->value
= S_GET_VALUE (symp
);
2498 /* A warning construct is a warning symbol followed by the
2499 symbol warned about. Don't let anything object-format or
2500 target-specific muck with it; it's ready for output. */
2501 if (symbol_get_bfdsym (symp
)->flags
& BSF_WARNING
)
2502 skip_next_symbol
= true;
2506 /* Now do any format-specific adjustments to the symbol table, such
2507 as adding file symbols. */
2508 #ifdef tc_adjust_symtab
2509 tc_adjust_symtab ();
2511 #ifdef obj_adjust_symtab
2512 obj_adjust_symtab ();
2515 /* Stop if there is an error. */
2516 if (!flag_always_generate_output
&& had_errors ())
2519 /* Now that all the sizes are known, and contents correct, we can
2520 start writing to the file. */
2523 /* If *_frob_file changes the symbol value at this point, it is
2524 responsible for moving the changed value into symp->bsym->value
2525 as well. Hopefully all symbol value changing can be done in
2530 #ifdef obj_frob_file
2533 #ifdef obj_coff_generate_pdata
2534 obj_coff_generate_pdata ();
2537 bfd_map_over_sections (stdoutput
, write_relocs
, (char *) 0);
2539 #ifdef tc_frob_file_after_relocs
2540 tc_frob_file_after_relocs ();
2542 #ifdef obj_frob_file_after_relocs
2543 obj_frob_file_after_relocs ();
2546 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
2547 if (IS_ELF
&& flag_use_elf_stt_common
)
2548 stdoutput
->flags
|= BFD_CONVERT_ELF_COMMON
| BFD_USE_ELF_STT_COMMON
;
2551 /* Once all relocations have been written, we can compress the
2552 contents of the debug sections. This needs to be done before
2553 we start writing any sections, because it will affect the file
2554 layout, which is fixed once we start writing contents. */
2555 if (flag_compress_debug
!= COMPRESS_DEBUG_NONE
)
2557 flagword flags
= BFD_COMPRESS
;
2558 if (flag_compress_debug
== COMPRESS_DEBUG_GABI_ZLIB
)
2559 flags
= BFD_COMPRESS
| BFD_COMPRESS_GABI
;
2560 else if (flag_compress_debug
== COMPRESS_DEBUG_ZSTD
)
2561 flags
= BFD_COMPRESS
| BFD_COMPRESS_GABI
| BFD_COMPRESS_ZSTD
;
2562 stdoutput
->flags
|= flags
& bfd_applicable_file_flags (stdoutput
);
2563 if ((stdoutput
->flags
& BFD_COMPRESS
) != 0)
2564 bfd_map_over_sections (stdoutput
, compress_debug
, (char *) 0);
2567 bfd_map_over_sections (stdoutput
, write_contents
, (char *) 0);
2570 #ifdef TC_GENERIC_RELAX_TABLE
2571 #ifndef md_generic_table_relax_frag
2572 #define md_generic_table_relax_frag relax_frag
2575 /* Relax a fragment by scanning TC_GENERIC_RELAX_TABLE. */
2578 relax_frag (segT segment
, fragS
*fragP
, long stretch
)
2580 const relax_typeS
*this_type
;
2581 const relax_typeS
*start_type
;
2582 relax_substateT next_state
;
2583 relax_substateT this_state
;
2589 const relax_typeS
*table
;
2591 target
= fragP
->fr_offset
;
2592 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2593 table
= TC_GENERIC_RELAX_TABLE
;
2594 this_state
= fragP
->fr_subtype
;
2595 start_type
= this_type
= table
+ this_state
;
2596 symbolP
= fragP
->fr_symbol
;
2602 sym_frag
= symbol_get_frag (symbolP
);
2604 #ifndef DIFF_EXPR_OK
2605 know (sym_frag
!= NULL
);
2607 know (S_GET_SEGMENT (symbolP
) != absolute_section
2608 || sym_frag
== &zero_address_frag
);
2609 target
+= S_GET_VALUE (symbolP
);
2611 /* If SYM_FRAG has yet to be reached on this pass, assume it
2612 will move by STRETCH just as we did, unless there is an
2613 alignment frag between here and SYM_FRAG. An alignment may
2614 well absorb any STRETCH, and we don't want to choose a larger
2615 branch insn by overestimating the needed reach of this
2616 branch. It isn't critical to calculate TARGET exactly; We
2617 know we'll be doing another pass if STRETCH is non-zero. */
2620 && sym_frag
->relax_marker
!= fragP
->relax_marker
2621 && S_GET_SEGMENT (symbolP
) == segment
)
2624 || sym_frag
->region
== fragP
->region
)
2626 /* If we get here we know we have a forward branch. This
2627 relax pass may have stretched previous instructions so
2628 far that omitting STRETCH would make the branch
2629 negative. Don't allow this in case the negative reach is
2630 large enough to require a larger branch instruction. */
2631 else if (target
< address
)
2636 aim
= target
- address
;
2637 #ifdef TC_PCREL_ADJUST
2638 /* Currently only the ns32k and arc needs this. */
2639 aim
+= TC_PCREL_ADJUST (fragP
);
2642 #ifdef md_prepare_relax_scan
2643 /* Formerly called M68K_AIM_KLUDGE. */
2644 md_prepare_relax_scan (fragP
, address
, aim
, this_state
, this_type
);
2649 /* Look backwards. */
2650 for (next_state
= this_type
->rlx_more
; next_state
;)
2651 if (aim
>= this_type
->rlx_backward
)
2655 /* Grow to next state. */
2656 this_state
= next_state
;
2657 this_type
= table
+ this_state
;
2658 next_state
= this_type
->rlx_more
;
2663 /* Look forwards. */
2664 for (next_state
= this_type
->rlx_more
; next_state
;)
2665 if (aim
<= this_type
->rlx_forward
)
2669 /* Grow to next state. */
2670 this_state
= next_state
;
2671 this_type
= table
+ this_state
;
2672 next_state
= this_type
->rlx_more
;
2676 growth
= this_type
->rlx_length
- start_type
->rlx_length
;
2678 fragP
->fr_subtype
= this_state
;
2682 #endif /* defined (TC_GENERIC_RELAX_TABLE) */
2684 /* Relax_align. Advance location counter to next address that has 'alignment'
2685 lowest order bits all 0s, return size of adjustment made. */
2686 static relax_addressT
2687 relax_align (relax_addressT address
, /* Address now. */
2688 int alignment
/* Alignment (binary). */)
2690 relax_addressT mask
;
2691 relax_addressT new_address
;
2693 mask
= ~((relax_addressT
) ~0 << alignment
);
2694 new_address
= (address
+ mask
) & (~mask
);
2695 #ifdef LINKER_RELAXING_SHRINKS_ONLY
2697 /* We must provide lots of padding, so the linker can discard it
2698 when needed. The linker will not add extra space, ever. */
2699 new_address
+= (1 << alignment
);
2701 return (new_address
- address
);
2704 /* Now we have a segment, not a crowd of sub-segments, we can make
2709 After this, all frags in this segment have addresses that are correct
2710 within the segment. Since segments live in different file addresses,
2711 these frag addresses may not be the same as final object-file
2715 relax_segment (struct frag
*segment_frag_root
, segT segment
, int pass
)
2717 unsigned long frag_count
;
2719 relax_addressT address
;
2723 /* In case md_estimate_size_before_relax() wants to make fixSs. */
2724 subseg_change (segment
, 0);
2726 /* For each frag in segment: count and store (a 1st guess of)
2730 for (frag_count
= 0, fragP
= segment_frag_root
;
2732 fragP
= fragP
->fr_next
, frag_count
++)
2734 fragP
->region
= region
;
2735 fragP
->relax_marker
= 0;
2736 fragP
->fr_address
= address
;
2737 address
+= fragP
->fr_fix
;
2739 switch (fragP
->fr_type
)
2742 address
+= fragP
->fr_offset
* fragP
->fr_var
;
2749 addressT offset
= relax_align (address
, (int) fragP
->fr_offset
);
2751 if (fragP
->fr_subtype
!= 0 && offset
> fragP
->fr_subtype
)
2754 if (offset
% fragP
->fr_var
!= 0)
2756 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
2757 ngettext ("alignment padding (%lu byte) "
2758 "not a multiple of %ld",
2759 "alignment padding (%lu bytes) "
2760 "not a multiple of %ld",
2761 (unsigned long) offset
),
2762 (unsigned long) offset
, (long) fragP
->fr_var
);
2763 offset
-= (offset
% fragP
->fr_var
);
2772 /* Assume .org is nugatory. It will grow with 1st relax. */
2780 case rs_machine_dependent
:
2781 /* If fr_symbol is an expression, this call to
2782 resolve_symbol_value sets up the correct segment, which will
2783 likely be needed in md_estimate_size_before_relax. */
2784 if (fragP
->fr_symbol
)
2785 resolve_symbol_value (fragP
->fr_symbol
);
2787 address
+= md_estimate_size_before_relax (fragP
, segment
);
2790 #ifndef WORKING_DOT_WORD
2791 /* Broken words don't concern us yet. */
2792 case rs_broken_word
:
2797 #if defined (TE_PE) && defined (O_secrel)
2800 /* Initial guess is always 1; doing otherwise can result in
2801 stable solutions that are larger than the minimum. */
2802 address
+= fragP
->fr_offset
= 1;
2806 address
+= eh_frame_estimate_size_before_relax (fragP
);
2810 address
+= dwarf2dbg_estimate_size_before_relax (fragP
);
2814 /* Initial estimate can be set to atleast 1 byte. */
2815 address
+= sframe_estimate_size_before_relax (fragP
);
2819 BAD_CASE (fragP
->fr_type
);
2826 unsigned long max_iterations
;
2828 /* Cumulative address adjustment. */
2831 /* Have we made any adjustment this pass? We can't just test
2832 stretch because one piece of code may have grown and another
2836 /* Most horrible, but gcc may give us some exception data that
2837 is impossible to assemble, of the form
2841 .uleb128 end - start
2847 If the leb128 is two bytes in size, then end-start is 128*128,
2848 which requires a three byte leb128. If the leb128 is three
2849 bytes in size, then end-start is 128*128-1, which requires a
2850 two byte leb128. We work around this dilemma by inserting
2851 an extra 4 bytes of alignment just after the .align. This
2852 works because the data after the align is accessed relative to
2855 This counter is used in a tiny state machine to detect
2856 whether a leb128 followed by an align is impossible to
2858 int rs_leb128_fudge
= 0;
2860 /* We want to prevent going into an infinite loop where one frag grows
2861 depending upon the location of a symbol which is in turn moved by
2862 the growing frag. eg:
2868 So we dictate that this algorithm can be at most O2. */
2869 max_iterations
= frag_count
* frag_count
;
2870 /* Check for overflow. */
2871 if (max_iterations
< frag_count
)
2872 max_iterations
= frag_count
;
2880 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
2883 addressT was_address
;
2887 fragP
->relax_marker
^= 1;
2888 was_address
= fragP
->fr_address
;
2889 address
= fragP
->fr_address
+= stretch
;
2890 symbolP
= fragP
->fr_symbol
;
2891 offset
= fragP
->fr_offset
;
2893 switch (fragP
->fr_type
)
2895 case rs_fill
: /* .fill never relaxes. */
2899 #ifndef WORKING_DOT_WORD
2900 /* JF: This is RMS's idea. I do *NOT* want to be blamed
2901 for it I do not want to write it. I do not want to have
2902 anything to do with it. This is not the proper way to
2903 implement this misfeature. */
2904 case rs_broken_word
:
2906 struct broken_word
*lie
;
2907 struct broken_word
*untruth
;
2909 /* Yes this is ugly (storing the broken_word pointer
2910 in the symbol slot). Still, this whole chunk of
2911 code is ugly, and I don't feel like doing anything
2912 about it. Think of it as stubbornness in action. */
2914 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
2915 lie
&& lie
->dispfrag
== fragP
;
2916 lie
= lie
->next_broken_word
)
2922 offset
= (S_GET_VALUE (lie
->add
)
2924 - S_GET_VALUE (lie
->sub
));
2925 if (offset
<= -32768 || offset
>= 32767)
2927 if (flag_warn_displacement
)
2931 bfd_sprintf_vma (stdoutput
, buf
,
2932 (addressT
) lie
->addnum
);
2933 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
2934 _(".word %s-%s+%s didn't fit"),
2935 S_GET_NAME (lie
->add
),
2936 S_GET_NAME (lie
->sub
),
2939 if (fragP
->fr_subtype
== 0)
2941 fragP
->fr_subtype
++;
2942 growth
+= md_short_jump_size
;
2945 /* Redirect *all* words of this table with the same
2946 target, lest we have to handle the case where the
2947 same target but with a offset that fits on this
2948 round overflows at the next relaxation round. */
2949 for (untruth
= (struct broken_word
*) (fragP
->fr_symbol
);
2950 untruth
&& untruth
->dispfrag
== lie
->dispfrag
;
2951 untruth
= untruth
->next_broken_word
)
2952 if ((symbol_get_frag (untruth
->add
)
2953 == symbol_get_frag (lie
->add
))
2954 && (S_GET_VALUE (untruth
->add
)
2955 == S_GET_VALUE (lie
->add
)))
2958 untruth
->use_jump
= lie
;
2962 growth
+= md_long_jump_size
;
2967 } /* case rs_broken_word */
2973 addressT oldoff
, newoff
;
2975 oldoff
= relax_align (was_address
+ fragP
->fr_fix
,
2977 newoff
= relax_align (address
+ fragP
->fr_fix
,
2980 if (fragP
->fr_subtype
!= 0)
2982 if (oldoff
> fragP
->fr_subtype
)
2984 if (newoff
> fragP
->fr_subtype
)
2988 growth
= newoff
- oldoff
;
2990 /* If this align happens to follow a leb128 and
2991 we have determined that the leb128 is bouncing
2992 in size, then break the cycle by inserting an
2995 && (rs_leb128_fudge
& 16) != 0
2996 && (rs_leb128_fudge
& 15) >= 2)
2998 segment_info_type
*seginfo
= seg_info (segment
);
2999 struct obstack
*ob
= &seginfo
->frchainP
->frch_obstack
;
3002 newf
= frag_alloc (ob
);
3003 obstack_blank_fast (ob
, fragP
->fr_var
);
3004 obstack_finish (ob
);
3005 memcpy (newf
, fragP
, SIZEOF_STRUCT_FRAG
);
3006 memcpy (newf
->fr_literal
,
3007 fragP
->fr_literal
+ fragP
->fr_fix
,
3009 newf
->fr_type
= rs_fill
;
3010 newf
->fr_address
= address
+ fragP
->fr_fix
+ newoff
;
3012 newf
->fr_offset
= (((offsetT
) 1 << fragP
->fr_offset
)
3014 if (newf
->fr_offset
* newf
->fr_var
3015 != (offsetT
) 1 << fragP
->fr_offset
)
3017 newf
->fr_offset
= (offsetT
) 1 << fragP
->fr_offset
;
3020 /* Include size of new frag in GROWTH. */
3021 growth
+= newf
->fr_offset
* newf
->fr_var
;
3022 /* Adjust the new frag address for the amount
3023 we'll add when we process the new frag. */
3024 newf
->fr_address
-= stretch
+ growth
;
3025 newf
->relax_marker
^= 1;
3026 fragP
->fr_next
= newf
;
3028 as_warn (_("padding added"));
3036 offsetT target
= offset
;
3041 /* Convert from an actual address to an octet offset
3042 into the section. Here it is assumed that the
3043 section's VMA is zero, and can omit subtracting it
3044 from the symbol's value to get the address offset. */
3045 know (S_GET_SEGMENT (symbolP
)->vma
== 0);
3046 target
+= S_GET_VALUE (symbolP
) * OCTETS_PER_BYTE
;
3049 know (fragP
->fr_next
);
3050 after
= fragP
->fr_next
->fr_address
+ stretch
;
3051 growth
= target
- after
;
3053 /* Growth may be negative, but variable part of frag
3054 cannot have fewer than 0 chars. That is, we can't
3056 if ((offsetT
) (address
+ fragP
->fr_fix
) > target
)
3060 /* Don't error on first few frag relax passes.
3061 The symbol might be an expression involving
3062 symbol values from other sections. If those
3063 sections have not yet been processed their
3064 frags will all have zero addresses, so we
3065 will calculate incorrect values for them. The
3066 number of passes we allow before giving an
3067 error is somewhat arbitrary. It should be at
3068 least one, with larger values requiring
3069 increasingly contrived dependencies between
3070 frags to trigger a false error. */
3073 /* Force another pass. */
3078 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3079 _("attempt to move .org backwards"));
3081 /* We've issued an error message. Change the
3082 frag to avoid cascading errors. */
3083 fragP
->fr_type
= rs_align
;
3084 fragP
->fr_subtype
= 0;
3085 fragP
->fr_offset
= 0;
3086 fragP
->fr_fix
= after
- address
;
3098 amount
= S_GET_VALUE (symbolP
);
3099 if (S_GET_SEGMENT (symbolP
) != absolute_section
3100 || S_IS_COMMON (symbolP
)
3101 || ! S_IS_DEFINED (symbolP
))
3103 as_bad_where (fragP
->fr_file
, fragP
->fr_line
,
3104 _(".space, .nops or .fill specifies non-absolute value"));
3105 /* Prevent repeat of this error message. */
3106 fragP
->fr_symbol
= 0;
3108 else if (amount
< 0)
3110 /* Don't error on first few frag relax passes.
3111 See rs_org comment for a longer explanation. */
3118 as_warn_where (fragP
->fr_file
, fragP
->fr_line
,
3119 _(".space, .nops or .fill with negative value, ignored"));
3120 fragP
->fr_symbol
= 0;
3123 growth
= (was_address
+ fragP
->fr_fix
+ amount
3124 - fragP
->fr_next
->fr_address
);
3128 case rs_machine_dependent
:
3129 #ifdef md_relax_frag
3130 growth
= md_relax_frag (segment
, fragP
, stretch
);
3132 #ifdef TC_GENERIC_RELAX_TABLE
3133 /* The default way to relax a frag is to look through
3134 TC_GENERIC_RELAX_TABLE. */
3135 growth
= md_generic_table_relax_frag (segment
, fragP
,
3137 #endif /* TC_GENERIC_RELAX_TABLE */
3146 value
= resolve_symbol_value (fragP
->fr_symbol
);
3147 size
= sizeof_leb128 (value
, fragP
->fr_subtype
);
3148 growth
= size
- fragP
->fr_offset
;
3149 fragP
->fr_offset
= size
;
3153 #if defined (TE_PE) && defined (O_secrel)
3159 value
= resolve_symbol_value (fragP
->fr_symbol
);
3160 size
= sizeof_cv_comp (value
, fragP
->fr_subtype
);
3161 growth
= size
- fragP
->fr_offset
;
3162 fragP
->fr_offset
= size
;
3168 growth
= eh_frame_relax_frag (fragP
);
3172 growth
= dwarf2dbg_relax_frag (fragP
);
3176 growth
= sframe_relax_frag (fragP
);
3180 BAD_CASE (fragP
->fr_type
);
3187 if (fragP
->fr_type
== rs_leb128
)
3188 rs_leb128_fudge
+= 16;
3189 else if (fragP
->fr_type
== rs_align
3190 && (rs_leb128_fudge
& 16) != 0
3192 rs_leb128_fudge
+= 16;
3194 rs_leb128_fudge
= 0;
3199 && (rs_leb128_fudge
& 16) == 0
3200 && (rs_leb128_fudge
& -16) != 0)
3201 rs_leb128_fudge
+= 1;
3203 rs_leb128_fudge
= 0;
3205 /* Until nothing further to relax. */
3206 while (stretched
&& -- max_iterations
);
3209 as_fatal (_("Infinite loop encountered whilst attempting to compute the addresses of symbols in section %s"),
3210 segment_name (segment
));
3213 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
3214 if (fragP
->last_fr_address
!= fragP
->fr_address
)
3216 fragP
->last_fr_address
= fragP
->fr_address
;
3223 number_to_chars_bigendian (char *buf
, valueT val
, int n
)
3229 buf
[n
] = val
& 0xff;
3235 number_to_chars_littleendian (char *buf
, valueT val
, int n
)
3241 *buf
++ = val
& 0xff;
3247 write_print_statistics (FILE *file
)
3249 fprintf (file
, "fixups: %d\n", n_fixups
);
3252 /* For debugging. */
3253 extern int indent_level
;
3256 print_fixup (fixS
*fixp
)
3259 fprintf (stderr
, "fix %p %s:%d", fixp
, fixp
->fx_file
, fixp
->fx_line
);
3261 fprintf (stderr
, " pcrel");
3262 if (fixp
->fx_pcrel_adjust
)
3263 fprintf (stderr
, " pcrel_adjust=%d", fixp
->fx_pcrel_adjust
);
3265 fprintf (stderr
, " tcbit");
3267 fprintf (stderr
, " done");
3268 fprintf (stderr
, "\n size=%d frag=%p", fixp
->fx_size
, fixp
->fx_frag
);
3269 fprintf (stderr
, " where=%ld offset=%" PRIx64
" addnumber=%" PRIx64
,
3270 fixp
->fx_where
, (uint64_t) fixp
->fx_offset
,
3271 (uint64_t) fixp
->fx_addnumber
);
3272 fprintf (stderr
, "\n %s (%d)", bfd_get_reloc_code_name (fixp
->fx_r_type
),
3276 fprintf (stderr
, "\n +<");
3277 print_symbol_value_1 (stderr
, fixp
->fx_addsy
);
3278 fprintf (stderr
, ">");
3282 fprintf (stderr
, "\n -<");
3283 print_symbol_value_1 (stderr
, fixp
->fx_subsy
);
3284 fprintf (stderr
, ">");
3286 fprintf (stderr
, "\n");
3287 #ifdef TC_FIX_DATA_PRINT
3288 TC_FIX_DATA_PRINT (stderr
, fixp
);