1 /* write.c - emit .o file
2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 1995
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This thing should be set up to do byteordering correctly. But... */
26 #include "output-file.h"
28 /* This looks like a good idea. Let's try turning it on always, for now. */
29 #undef BFD_FAST_SECTION_FILL
30 #define BFD_FAST_SECTION_FILL
32 /* The NOP_OPCODE is for the alignment fill value. Fill it with a nop
33 instruction so that the disassembler does not choke on it. */
35 #define NOP_OPCODE 0x00
38 #ifndef TC_ADJUST_RELOC_COUNT
39 #define TC_ADJUST_RELOC_COUNT(FIXP,COUNT)
42 #ifndef TC_FORCE_RELOCATION
43 #define TC_FORCE_RELOCATION(FIXP) 0
46 #ifndef TC_FORCE_RELOCATION_SECTION
47 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP)
50 #ifndef MD_PCREL_FROM_SECTION
51 #define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from(FIXP)
54 #ifndef WORKING_DOT_WORD
55 extern CONST
int md_short_jump_size
;
56 extern CONST
int md_long_jump_size
;
59 int symbol_table_frozen
;
60 void print_fixup
PARAMS ((fixS
*));
63 static void renumber_sections
PARAMS ((bfd
*, asection
*, PTR
));
65 /* We generally attach relocs to frag chains. However, after we have
66 chained these all together into a segment, any relocs we add after
67 that must be attached to a segment. This will include relocs added
68 in md_estimate_size_for_relax, for example. */
69 static int frags_chained
= 0;
75 struct frag
*text_frag_root
;
76 struct frag
*data_frag_root
;
77 struct frag
*bss_frag_root
;
79 struct frag
*text_last_frag
; /* Last frag in segment. */
80 struct frag
*data_last_frag
; /* Last frag in segment. */
81 static struct frag
*bss_last_frag
; /* Last frag in segment. */
85 static object_headers headers
;
88 long string_byte_count
;
89 char *next_object_file_charP
; /* Tracks object file bytes. */
92 int magic_number_for_object_file
= DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE
;
95 #endif /* BFD_ASSEMBLER */
98 static fixS
*fix_new_internal
PARAMS ((fragS
*, int where
, int size
,
99 symbolS
*add
, symbolS
*sub
,
100 offsetT offset
, int pcrel
,
101 bfd_reloc_code_real_type r_type
));
103 static fixS
*fix_new_internal
PARAMS ((fragS
*, int where
, int size
,
104 symbolS
*add
, symbolS
*sub
,
105 offsetT offset
, int pcrel
,
108 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
109 static long fixup_segment
PARAMS ((fixS
* fixP
, segT this_segment_type
));
111 static relax_addressT relax_align
PARAMS ((relax_addressT addr
, int align
));
116 * Create a fixS in obstack 'notes'.
119 fix_new_internal (frag
, where
, size
, add_symbol
, sub_symbol
, offset
, pcrel
,
121 fragS
*frag
; /* Which frag? */
122 int where
; /* Where in that frag? */
123 int size
; /* 1, 2, or 4 usually. */
124 symbolS
*add_symbol
; /* X_add_symbol. */
125 symbolS
*sub_symbol
; /* X_op_symbol. */
126 offsetT offset
; /* X_add_number. */
127 int pcrel
; /* TRUE if PC-relative relocation. */
129 bfd_reloc_code_real_type r_type
; /* Relocation type */
131 int r_type
; /* Relocation type */
136 fixP
= (fixS
*) obstack_alloc (¬es
, sizeof (fixS
));
138 fixP
->fx_frag
= frag
;
139 fixP
->fx_where
= where
;
140 fixP
->fx_size
= size
;
141 /* We've made fx_size a narrow field; check that it's wide enough. */
142 if (fixP
->fx_size
!= size
)
144 as_bad ("field fx_size too small to hold %d", size
);
147 fixP
->fx_addsy
= add_symbol
;
148 fixP
->fx_subsy
= sub_symbol
;
149 fixP
->fx_offset
= offset
;
150 fixP
->fx_pcrel
= pcrel
;
152 #if defined(NEED_FX_R_TYPE) || defined (BFD_ASSEMBLER)
153 fixP
->fx_r_type
= r_type
;
155 fixP
->fx_im_disp
= 0;
156 fixP
->fx_pcrel_adjust
= 0;
157 fixP
->fx_bit_fixP
= 0;
158 fixP
->fx_addnumber
= 0;
163 TC_INIT_FIX_DATA(fixP
);
166 as_where (&fixP
->fx_file
, &fixP
->fx_line
);
168 /* Usually, we want relocs sorted numerically, but while
169 comparing to older versions of gas that have relocs
170 reverse sorted, it is convenient to have this compile
171 time option. xoxorich. */
176 fixS
**seg_fix_rootP
= (frags_chained
177 ? &seg_info (now_seg
)->fix_root
178 : &frchain_now
->fix_root
);
179 fixS
**seg_fix_tailP
= (frags_chained
180 ? &seg_info (now_seg
)->fix_tail
181 : &frchain_now
->fix_tail
);
184 #ifdef REVERSE_SORT_RELOCS
186 fixP
->fx_next
= *seg_fix_rootP
;
187 *seg_fix_rootP
= fixP
;
189 #else /* REVERSE_SORT_RELOCS */
191 fixP
->fx_next
= NULL
;
194 (*seg_fix_tailP
)->fx_next
= fixP
;
196 *seg_fix_rootP
= fixP
;
197 *seg_fix_tailP
= fixP
;
199 #endif /* REVERSE_SORT_RELOCS */
206 /* Create a fixup relative to a symbol (plus a constant). */
209 fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
)
210 fragS
*frag
; /* Which frag? */
211 int where
; /* Where in that frag? */
212 int size
; /* 1, 2, or 4 usually. */
213 symbolS
*add_symbol
; /* X_add_symbol. */
214 offsetT offset
; /* X_add_number. */
215 int pcrel
; /* TRUE if PC-relative relocation. */
217 bfd_reloc_code_real_type r_type
; /* Relocation type */
219 int r_type
; /* Relocation type */
222 return fix_new_internal (frag
, where
, size
, add_symbol
,
223 (symbolS
*) NULL
, offset
, pcrel
, r_type
);
226 /* Create a fixup for an expression. Currently we only support fixups
227 for difference expressions. That is itself more than most object
228 file formats support anyhow. */
231 fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
)
232 fragS
*frag
; /* Which frag? */
233 int where
; /* Where in that frag? */
234 int size
; /* 1, 2, or 4 usually. */
235 expressionS
*exp
; /* Expression. */
236 int pcrel
; /* TRUE if PC-relative relocation. */
238 bfd_reloc_code_real_type r_type
; /* Relocation type */
240 int r_type
; /* Relocation type */
253 /* This comes up when _GLOBAL_OFFSET_TABLE_+(.-L0) is read, if
254 the difference expression cannot immediately be reduced. */
256 extern symbolS
*make_expr_symbol ();
257 symbolS
*stmp
= make_expr_symbol (exp
);
258 exp
->X_op
= O_symbol
;
259 exp
->X_op_symbol
= 0;
260 exp
->X_add_symbol
= stmp
;
261 exp
->X_add_number
= 0;
262 return fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
266 add
= exp
->X_add_symbol
;
267 off
= exp
->X_add_number
;
269 #if defined(BFD_ASSEMBLER)
270 r_type
= BFD_RELOC_RVA
;
271 #elif defined(TC_RVA_RELOC)
272 r_type
= TC_RVA_RELOC
;
274 as_fatal("rva not supported");
279 sub
= exp
->X_add_symbol
;
280 off
= exp
->X_add_number
;
284 sub
= exp
->X_op_symbol
;
287 add
= exp
->X_add_symbol
;
290 off
= exp
->X_add_number
;
294 as_bad ("expression too complex for fixup");
297 return fix_new_internal (frag
, where
, size
, add
, sub
, off
,
301 /* Append a string onto another string, bumping the pointer along. */
303 append (charPP
, fromP
, length
)
306 unsigned long length
;
308 /* Don't trust memcpy() of 0 chars. */
312 memcpy (*charPP
, fromP
, length
);
316 #ifndef BFD_ASSEMBLER
317 int section_alignment
[SEG_MAXIMUM_ORDINAL
];
321 * This routine records the largest alignment seen for each segment.
322 * If the beginning of the segment is aligned on the worst-case
323 * boundary, all of the other alignments within it will work. At
324 * least one object format really uses this info.
327 record_alignment (seg
, align
)
328 /* Segment to which alignment pertains */
330 /* Alignment, as a power of 2 (e.g., 1 => 2-byte boundary, 2 => 4-byte
334 if (seg
== absolute_section
)
337 if (align
> bfd_get_section_alignment (stdoutput
, seg
))
338 bfd_set_section_alignment (stdoutput
, seg
, align
);
340 if (align
> section_alignment
[(int) seg
])
341 section_alignment
[(int) seg
] = align
;
347 /* Reset the section indices after removing the gas created sections. */
350 renumber_sections (abfd
, sec
, countparg
)
355 int *countp
= (int *) countparg
;
357 sec
->index
= *countp
;
361 #endif /* defined (BFD_ASSEMBLER) */
363 #if defined (BFD_ASSEMBLER) || ! defined (BFD)
366 chain_frchains_together_1 (section
, frchp
)
368 struct frchain
*frchp
;
370 fragS dummy
, *prev_frag
= &dummy
;
372 fixS fix_dummy
, *prev_fix
= &fix_dummy
;
375 for (; frchp
&& frchp
->frch_seg
== section
; frchp
= frchp
->frch_next
)
377 prev_frag
->fr_next
= frchp
->frch_root
;
378 prev_frag
= frchp
->frch_last
;
379 assert (prev_frag
->fr_type
!= 0);
381 if (frchp
->fix_root
!= (fixS
*) NULL
)
383 if (seg_info (section
)->fix_root
== (fixS
*) NULL
)
384 seg_info (section
)->fix_root
= frchp
->fix_root
;
385 prev_fix
->fx_next
= frchp
->fix_root
;
386 seg_info (section
)->fix_tail
= frchp
->fix_tail
;
387 prev_fix
= frchp
->fix_tail
;
391 assert (prev_frag
->fr_type
!= 0);
392 prev_frag
->fr_next
= 0;
401 chain_frchains_together (abfd
, section
, xxx
)
402 bfd
*abfd
; /* unused */
404 PTR xxx
; /* unused */
406 segment_info_type
*info
;
408 /* BFD may have introduced its own sections without using
409 subseg_new, so it is possible that seg_info is NULL. */
410 info
= seg_info (section
);
411 if (info
!= (segment_info_type
*) NULL
)
412 info
->frchainP
->frch_last
413 = chain_frchains_together_1 (section
, info
->frchainP
);
415 /* Now that we've chained the frags together, we must add new fixups
416 to the segment, not to the frag chain. */
422 #if !defined (BFD) && !defined (BFD_ASSEMBLER)
425 remove_subsegs (head
, seg
, root
, last
)
431 *root
= head
->frch_root
;
432 *last
= chain_frchains_together_1 (seg
, head
);
437 #if defined (BFD_ASSEMBLER) || !defined (BFD)
441 cvt_frag_to_fill (sec
, fragP
)
446 cvt_frag_to_fill (headersP
, sec
, fragP
)
447 object_headers
*headersP
;
452 switch (fragP
->fr_type
)
459 HANDLE_ALIGN (fragP
);
461 know (fragP
->fr_next
!= NULL
);
462 fragP
->fr_offset
= (fragP
->fr_next
->fr_address
464 - fragP
->fr_fix
) / fragP
->fr_var
;
465 if (fragP
->fr_offset
< 0)
467 as_bad ("attempt to .org/.space backwards? (%ld)",
468 (long) fragP
->fr_offset
);
470 fragP
->fr_type
= rs_fill
;
476 case rs_machine_dependent
:
478 md_convert_frag (stdoutput
, sec
, fragP
);
480 md_convert_frag (headersP
, sec
, fragP
);
483 assert (fragP
->fr_next
== NULL
|| (fragP
->fr_next
->fr_address
- fragP
->fr_address
== fragP
->fr_fix
));
486 * After md_convert_frag, we make the frag into a ".space 0".
487 * Md_convert_frag() should set up any fixSs and constants
493 #ifndef WORKING_DOT_WORD
496 struct broken_word
*lie
;
498 if (fragP
->fr_subtype
)
500 fragP
->fr_fix
+= md_short_jump_size
;
501 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
502 lie
&& lie
->dispfrag
== fragP
;
503 lie
= lie
->next_broken_word
)
505 fragP
->fr_fix
+= md_long_jump_size
;
513 BAD_CASE (fragP
->fr_type
);
518 #endif /* defined (BFD_ASSEMBLER) || !defined (BFD) */
522 relax_and_size_seg (abfd
, sec
, xxx
)
529 segment_info_type
*seginfo
;
531 valueT size
, newsize
;
533 subseg_change (sec
, 0);
535 flags
= bfd_get_section_flags (abfd
, sec
);
537 seginfo
= seg_info (sec
);
538 if (seginfo
&& seginfo
->frchainP
)
540 relax_segment (seginfo
->frchainP
->frch_root
, sec
);
541 for (fragp
= seginfo
->frchainP
->frch_root
; fragp
; fragp
= fragp
->fr_next
)
542 cvt_frag_to_fill (sec
, fragp
);
543 for (fragp
= seginfo
->frchainP
->frch_root
;
545 fragp
= fragp
->fr_next
)
546 /* walk to last elt */;
547 size
= fragp
->fr_address
+ fragp
->fr_fix
;
552 if (size
> 0 && ! seginfo
->bss
)
553 flags
|= SEC_HAS_CONTENTS
;
555 /* @@ This is just an approximation. */
556 if (seginfo
&& seginfo
->fix_root
)
560 x
= bfd_set_section_flags (abfd
, sec
, flags
);
563 newsize
= md_section_align (sec
, size
);
564 x
= bfd_set_section_size (abfd
, sec
, newsize
);
567 /* If the size had to be rounded up, add some padding in the last
569 assert (newsize
>= size
);
572 fragS
*last
= seginfo
->frchainP
->frch_last
;
573 fragp
= seginfo
->frchainP
->frch_root
;
574 while (fragp
->fr_next
!= last
)
575 fragp
= fragp
->fr_next
;
576 last
->fr_address
= size
;
577 fragp
->fr_offset
+= newsize
- size
;
580 #ifdef tc_frob_section
581 tc_frob_section (sec
);
583 #ifdef obj_frob_section
584 obj_frob_section (sec
);
590 dump_section_relocs (abfd
, sec
, stream_
)
595 FILE *stream
= (FILE *) stream_
;
596 segment_info_type
*seginfo
= seg_info (sec
);
597 fixS
*fixp
= seginfo
->fix_root
;
602 fprintf (stream
, "sec %s relocs:\n", sec
->name
);
605 symbolS
*s
= fixp
->fx_addsy
;
608 fprintf (stream
, " %08x: %s(%s", fixp
, S_GET_NAME (s
),
609 s
->bsym
->section
->name
);
610 if (s
->bsym
->flags
& BSF_SECTION_SYM
)
612 fprintf (stream
, " section sym");
614 fprintf (stream
, "+%x", S_GET_VALUE (s
));
617 fprintf (stream
, "+%x", S_GET_VALUE (s
));
618 fprintf (stream
, ")+%x\n", fixp
->fx_offset
);
621 fprintf (stream
, " %08x: type %d no sym\n", fixp
, fixp
->fx_r_type
);
622 fixp
= fixp
->fx_next
;
626 #define dump_section_relocs(ABFD,SEC,STREAM) (void)(ABFD,SEC,STREAM)
629 #ifndef EMIT_SECTION_SYMBOLS
630 #define EMIT_SECTION_SYMBOLS 1
634 adjust_reloc_syms (abfd
, sec
, xxx
)
639 segment_info_type
*seginfo
= seg_info (sec
);
645 dump_section_relocs (abfd
, sec
, stderr
);
647 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
650 else if (fixp
->fx_addsy
)
658 fprintf (stderr
, "\n\nadjusting fixup:\n");
662 sym
= fixp
->fx_addsy
;
663 symsec
= sym
->bsym
->section
;
665 if (sym
!= NULL
&& sym
->sy_mri_common
)
667 /* These symbols are handled specially in fixup_segment. */
671 /* If it's one of these sections, assume the symbol is
672 definitely going to be output. The code in
673 md_estimate_size_before_relax in tc-mips.c uses this test
674 as well, so if you change this code you should look at that
676 if (bfd_is_und_section (symsec
)
677 || bfd_is_abs_section (symsec
)
678 || bfd_is_com_section (symsec
))
680 fixp
->fx_addsy
->sy_used_in_reloc
= 1;
681 #ifdef UNDEFINED_DIFFERENCE_OK
682 /* We have the difference of an undefined symbol and some
683 other symbol. Make sure to mark the other symbol as used
684 in a relocation so that it will always be output. */
686 fixp
->fx_subsy
->sy_used_in_reloc
= 1;
691 /* Since we're reducing to section symbols, don't attempt to reduce
692 anything that's already using one. */
693 if (sym
->bsym
->flags
& BSF_SECTION_SYM
)
695 fixp
->fx_addsy
->sy_used_in_reloc
= 1;
699 /* Is there some other reason we can't adjust this one? (E.g.,
700 call/bal links in i960-bout symbols.) */
701 #ifdef obj_fix_adjustable
702 if (! obj_fix_adjustable (fixp
))
704 fixp
->fx_addsy
->sy_used_in_reloc
= 1;
709 /* Is there some other (target cpu dependent) reason we can't adjust
710 this one? (E.g. relocations involving function addresses on
712 #ifdef tc_fix_adjustable
713 if (! tc_fix_adjustable (fixp
))
715 fixp
->fx_addsy
->sy_used_in_reloc
= 1;
720 /* For PIC support: We may get expressions like
721 "_GLOBAL_OFFSET_TABLE_+(.-L5)" where "." and "L5" may not
722 necessarily have had a fixed difference initially. But now
723 it should be a known constant, so we can reduce it. Since
724 we can't easily handle a symbol value that looks like
725 someUndefinedSymbol+const, though, we convert the fixup to
726 access the undefined symbol directly, and discard the
727 intermediate symbol. */
728 if (S_GET_SEGMENT (sym
) == expr_section
729 && sym
->sy_value
.X_op
== O_add
730 && (resolve_symbol_value (sym
->sy_value
.X_add_symbol
),
731 S_GET_SEGMENT (sym
->sy_value
.X_add_symbol
) == undefined_section
)
732 && (resolve_symbol_value (sym
->sy_value
.X_op_symbol
),
733 S_GET_SEGMENT (sym
->sy_value
.X_op_symbol
) == absolute_section
))
735 fixp
->fx_offset
+= S_GET_VALUE (sym
->sy_value
.X_op_symbol
);
736 fixp
->fx_offset
+= sym
->sy_value
.X_add_number
;
737 fixp
->fx_addsy
= sym
->sy_value
.X_add_symbol
;
741 /* If the section symbol isn't going to be output, the relocs
742 at least should still work. If not, figure out what to do
743 when we run into that case. */
744 fixp
->fx_offset
+= S_GET_VALUE (sym
);
745 fixp
->fx_addsy
= section_symbol (symsec
);
746 fixp
->fx_addsy
->sy_used_in_reloc
= 1;
751 #if 1/*def RELOC_REQUIRES_SYMBOL*/
754 /* There was no symbol required by this relocation. However,
755 BFD doesn't really handle relocations without symbols well.
756 (At least, the COFF support doesn't.) So for now we fake up
757 a local symbol in the absolute section. */
759 fixp
->fx_addsy
= section_symbol (absolute_section
);
760 /* fixp->fx_addsy->sy_used_in_reloc = 1; */
764 dump_section_relocs (abfd
, sec
, stderr
);
768 write_relocs (abfd
, sec
, xxx
)
773 segment_info_type
*seginfo
= seg_info (sec
);
780 /* If seginfo is NULL, we did not create this section; don't do
785 fixup_segment (seginfo
->fix_root
, sec
);
788 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
791 #ifndef RELOC_EXPANSION_POSSIBLE
792 /* Set up reloc information as well. */
793 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
794 n
* sizeof (arelent
*));
795 memset ((char*)relocs
, 0, n
* sizeof (arelent
*));
798 for (fixp
= seginfo
->fix_root
; fixp
!= (fixS
*) NULL
; fixp
= fixp
->fx_next
)
801 bfd_reloc_status_type s
;
808 reloc
= tc_gen_reloc (sec
, fixp
);
814 if (fixp
->fx_where
+ fixp
->fx_size
815 > fixp
->fx_frag
->fr_fix
+ fixp
->fx_frag
->fr_offset
)
818 s
= bfd_install_relocation (stdoutput
, reloc
,
819 fixp
->fx_frag
->fr_literal
,
820 fixp
->fx_frag
->fr_address
,
826 case bfd_reloc_overflow
:
827 as_bad_where (fixp
->fx_file
, fixp
->fx_line
, "relocation overflow");
830 as_fatal ("%s:%u: bad return from bfd_perform_relocation",
831 fixp
->fx_file
, fixp
->fx_line
);
836 n
= n
* MAX_RELOC_EXPANSION
;
837 /* Set up reloc information as well. */
838 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
839 n
* sizeof (arelent
*));
842 for (fixp
= seginfo
->fix_root
; fixp
!= (fixS
*) NULL
; fixp
= fixp
->fx_next
)
846 bfd_reloc_status_type s
;
854 reloc
= tc_gen_reloc (sec
, fixp
);
856 for (j
= 0; reloc
[j
]; j
++)
858 relocs
[i
++] = reloc
[j
];
861 data
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
862 if (fixp
->fx_where
+ fixp
->fx_size
863 > fixp
->fx_frag
->fr_fix
+ fixp
->fx_frag
->fr_offset
)
865 for (j
= 0; reloc
[j
]; j
++)
867 s
= bfd_install_relocation (stdoutput
, reloc
[j
],
868 fixp
->fx_frag
->fr_literal
,
869 fixp
->fx_frag
->fr_address
,
875 case bfd_reloc_overflow
:
876 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
877 "relocation overflow");
880 as_fatal ("%s:%u: bad return from bfd_perform_relocation",
881 fixp
->fx_file
, fixp
->fx_line
);
892 sympp
= bfd_get_outsymbols (stdoutput
);
893 nsyms
= bfd_get_symcount (stdoutput
);
894 for (i
= 0; i
< n
; i
++)
895 if (((*relocs
[i
]->sym_ptr_ptr
)->flags
& BSF_SECTION_SYM
) == 0)
897 for (j
= 0; j
< nsyms
; j
++)
898 if (sympp
[j
] == *relocs
[i
]->sym_ptr_ptr
)
907 bfd_set_reloc (stdoutput
, sec
, relocs
, n
);
909 bfd_set_section_flags (abfd
, sec
,
910 (bfd_get_section_flags (abfd
, sec
)
911 & (flagword
) ~SEC_RELOC
));
918 fprintf (stderr
, "relocs for sec %s\n", sec
->name
);
919 for (i
= 0; i
< n
; i
++)
923 fprintf (stderr
, " reloc %2d @%08x off %4x : sym %-10s addend %x\n",
924 i
, r
, r
->address
, s
->name
, r
->addend
);
931 write_contents (abfd
, sec
, xxx
)
936 segment_info_type
*seginfo
= seg_info (sec
);
937 unsigned long offset
= 0;
940 /* Write out the frags. */
942 || ! (bfd_get_section_flags (abfd
, sec
) & SEC_HAS_CONTENTS
))
945 for (f
= seginfo
->frchainP
->frch_root
;
950 unsigned long fill_size
;
954 assert (f
->fr_type
== rs_fill
);
957 x
= bfd_set_section_contents (stdoutput
, sec
,
958 f
->fr_literal
, (file_ptr
) offset
,
959 (bfd_size_type
) f
->fr_fix
);
962 bfd_perror (stdoutput
->filename
);
963 as_perror ("FATAL: Can't write %s", stdoutput
->filename
);
968 fill_literal
= f
->fr_literal
+ f
->fr_fix
;
969 fill_size
= f
->fr_var
;
970 count
= f
->fr_offset
;
972 if (fill_size
&& count
)
975 if (fill_size
> sizeof(buf
))
977 /* Do it the old way. Can this ever happen? */
980 x
= bfd_set_section_contents (stdoutput
, sec
,
983 (bfd_size_type
) fill_size
);
986 bfd_perror (stdoutput
->filename
);
987 as_perror ("FATAL: Can't write %s", stdoutput
->filename
);
995 /* Build a buffer full of fill objects and output it as
996 often as necessary. This saves on the overhead of
997 potentially lots of bfd_set_section_contents calls. */
1001 n_per_buf
= sizeof (buf
);
1002 memset (buf
, *fill_literal
, n_per_buf
);
1007 n_per_buf
= sizeof(buf
)/fill_size
;
1008 for (i
= n_per_buf
, bufp
= buf
; i
; i
--, bufp
+= fill_size
)
1009 memcpy(bufp
, fill_literal
, fill_size
);
1011 for (; count
> 0; count
-= n_per_buf
)
1013 n_per_buf
= n_per_buf
> count
? count
: n_per_buf
;
1014 x
= bfd_set_section_contents (stdoutput
, sec
,
1015 buf
, (file_ptr
) offset
,
1016 (bfd_size_type
) n_per_buf
* fill_size
);
1018 as_fatal ("Cannot write to output file.");
1019 offset
+= n_per_buf
* fill_size
;
1027 #if defined(BFD_ASSEMBLER) || (!defined (BFD) && !defined(OBJ_AOUT))
1029 merge_data_into_text ()
1031 #if defined(BFD_ASSEMBLER) || defined(MANY_SEGMENTS)
1032 seg_info (text_section
)->frchainP
->frch_last
->fr_next
=
1033 seg_info (data_section
)->frchainP
->frch_root
;
1034 seg_info (text_section
)->frchainP
->frch_last
=
1035 seg_info (data_section
)->frchainP
->frch_last
;
1036 seg_info (data_section
)->frchainP
= 0;
1040 text_last_frag
->fr_next
= data_frag_root
;
1041 text_last_frag
= data_last_frag
;
1042 data_last_frag
= NULL
;
1043 data_frag_root
= NULL
;
1046 for (tmp
= text_fix_root
; tmp
->fx_next
; tmp
= tmp
->fx_next
);;
1047 tmp
->fx_next
= data_fix_root
;
1048 text_fix_tail
= data_fix_tail
;
1051 text_fix_root
= data_fix_root
;
1052 data_fix_root
= NULL
;
1055 #endif /* BFD_ASSEMBLER || (! BFD && ! OBJ_AOUT) */
1057 #if !defined (BFD_ASSEMBLER) && !defined (BFD)
1059 relax_and_size_all_segments ()
1063 relax_segment (text_frag_root
, SEG_TEXT
);
1064 relax_segment (data_frag_root
, SEG_DATA
);
1065 relax_segment (bss_frag_root
, SEG_BSS
);
1067 * Now the addresses of frags are correct within the segment.
1070 know (text_last_frag
->fr_type
== rs_fill
&& text_last_frag
->fr_offset
== 0);
1071 H_SET_TEXT_SIZE (&headers
, text_last_frag
->fr_address
);
1072 text_last_frag
->fr_address
= H_GET_TEXT_SIZE (&headers
);
1075 * Join the 2 segments into 1 huge segment.
1076 * To do this, re-compute every rn_address in the SEG_DATA frags.
1077 * Then join the data frags after the text frags.
1079 * Determine a_data [length of data segment].
1083 register relax_addressT slide
;
1085 know ((text_last_frag
->fr_type
== rs_fill
) && (text_last_frag
->fr_offset
== 0));
1087 H_SET_DATA_SIZE (&headers
, data_last_frag
->fr_address
);
1088 data_last_frag
->fr_address
= H_GET_DATA_SIZE (&headers
);
1089 slide
= H_GET_TEXT_SIZE (&headers
); /* & in file of the data segment. */
1091 #define RoundUp(N,S) (((N)+(S)-1)&-(S))
1092 /* For b.out: If the data section has a strict alignment
1093 requirement, its load address in the .o file will be
1094 rounded up from the size of the text section. These
1095 two values are *not* the same! Similarly for the bss
1097 slide
= RoundUp (slide
, 1 << section_alignment
[SEG_DATA
]);
1100 for (fragP
= data_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1102 fragP
->fr_address
+= slide
;
1103 } /* for each data frag */
1105 know (text_last_frag
!= 0);
1106 text_last_frag
->fr_next
= data_frag_root
;
1110 H_SET_DATA_SIZE (&headers
, 0);
1114 /* See above comments on b.out data section address. */
1117 if (data_last_frag
== 0)
1118 bss_vma
= H_GET_TEXT_SIZE (&headers
);
1120 bss_vma
= data_last_frag
->fr_address
;
1121 bss_vma
= RoundUp (bss_vma
, 1 << section_alignment
[SEG_BSS
]);
1122 bss_address_frag
.fr_address
= bss_vma
;
1124 #else /* ! OBJ_BOUT */
1125 bss_address_frag
.fr_address
= (H_GET_TEXT_SIZE (&headers
) +
1126 H_GET_DATA_SIZE (&headers
));
1128 #endif /* ! OBJ_BOUT */
1130 /* Slide all the frags */
1133 relax_addressT slide
= bss_address_frag
.fr_address
;
1135 for (fragP
= bss_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1137 fragP
->fr_address
+= slide
;
1138 } /* for each bss frag */
1142 H_SET_BSS_SIZE (&headers
,
1143 bss_last_frag
->fr_address
- bss_frag_root
->fr_address
);
1145 H_SET_BSS_SIZE (&headers
, 0);
1147 #endif /* ! BFD_ASSEMBLER && ! BFD */
1149 #if defined (BFD_ASSEMBLER) || !defined (BFD)
1151 #ifdef BFD_ASSEMBLER
1159 extern PTR bfd_alloc
PARAMS ((bfd
*, size_t));
1161 /* Count symbols. We can't rely on a count made by the loop in
1162 write_object_file, because *_frob_file may add a new symbol or
1165 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1172 asympp
= (asymbol
**) bfd_alloc (stdoutput
,
1173 nsyms
* sizeof (asymbol
*));
1174 symp
= symbol_rootP
;
1175 for (i
= 0; i
< nsyms
; i
++, symp
= symbol_next (symp
))
1177 asympp
[i
] = symp
->bsym
;
1183 result
= bfd_set_symtab (stdoutput
, asympp
, nsyms
);
1184 assert (result
== true);
1185 symbol_table_frozen
= 1;
1190 write_object_file ()
1192 struct frchain
*frchainP
; /* Track along all frchains. */
1193 #if ! defined (BFD_ASSEMBLER) || ! defined (WORKING_DOT_WORD)
1194 fragS
*fragP
; /* Track along all frags. */
1197 /* Do we really want to write it? */
1199 int n_warns
, n_errs
;
1200 n_warns
= had_warnings ();
1201 n_errs
= had_errors ();
1202 /* The -Z flag indicates that an object file should be generated,
1203 regardless of warnings and errors. */
1204 if (flag_always_generate_output
)
1206 if (n_warns
|| n_errs
)
1207 as_warn ("%d error%s, %d warning%s, generating bad object file.\n",
1208 n_errs
, n_errs
== 1 ? "" : "s",
1209 n_warns
, n_warns
== 1 ? "" : "s");
1214 as_fatal ("%d error%s, %d warning%s, no object file generated.\n",
1215 n_errs
, n_errs
== 1 ? "" : "s",
1216 n_warns
, n_warns
== 1 ? "" : "s");
1221 /* Under VMS we try to be compatible with VAX-11 "C". Thus, we call
1222 a routine to check for the definition of the procedure "_main",
1223 and if so -- fix it up so that it can be program entry point. */
1224 vms_check_for_main ();
1225 #endif /* OBJ_VMS */
1227 /* After every sub-segment, we fake an ".align ...". This conforms to
1228 BSD4.2 brane-damage. We then fake ".fill 0" because that is the kind of
1229 frag that requires least thought. ".align" frags like to have a
1230 following frag since that makes calculating their intended length
1233 @@ Is this really necessary?? */
1234 #ifndef SUB_SEGMENT_ALIGN
1235 #ifdef BFD_ASSEMBLER
1236 #define SUB_SEGMENT_ALIGN(SEG) (0)
1238 #define SUB_SEGMENT_ALIGN(SEG) (2)
1241 for (frchainP
= frchain_root
; frchainP
; frchainP
= frchainP
->frch_next
)
1243 subseg_set (frchainP
->frch_seg
, frchainP
->frch_subseg
);
1244 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
1245 /* frag_align will have left a new frag.
1246 Use this last frag for an empty ".fill".
1248 For this segment ...
1249 Create a last frag. Do not leave a "being filled in frag". */
1250 frag_wane (frag_now
);
1251 frag_now
->fr_fix
= 0;
1252 know (frag_now
->fr_next
== NULL
);
1255 /* From now on, we don't care about sub-segments. Build one frag chain
1256 for each segment. Linked thru fr_next. */
1258 #ifdef BFD_ASSEMBLER
1259 /* Remove the sections created by gas for its own purposes. */
1261 asection
**seclist
, *sec
;
1264 seclist
= &stdoutput
->sections
;
1265 while (seclist
&& *seclist
)
1268 while (sec
== reg_section
|| sec
== expr_section
)
1272 stdoutput
->section_count
--;
1277 seclist
= &(*seclist
)->next
;
1280 bfd_map_over_sections (stdoutput
, renumber_sections
, &i
);
1283 bfd_map_over_sections (stdoutput
, chain_frchains_together
, (char *) 0);
1285 remove_subsegs (frchain_root
, SEG_TEXT
, &text_frag_root
, &text_last_frag
);
1286 remove_subsegs (data0_frchainP
, SEG_DATA
, &data_frag_root
, &data_last_frag
);
1287 remove_subsegs (bss0_frchainP
, SEG_BSS
, &bss_frag_root
, &bss_last_frag
);
1290 /* We have two segments. If user gave -R flag, then we must put the
1291 data frags into the text segment. Do this before relaxing so
1292 we know to take advantage of -R and make shorter addresses. */
1293 #if !defined (OBJ_AOUT) || defined (BFD_ASSEMBLER)
1294 if (flag_readonly_data_in_text
)
1296 merge_data_into_text ();
1300 #ifdef BFD_ASSEMBLER
1301 bfd_map_over_sections (stdoutput
, relax_and_size_seg
, (char *) 0);
1303 relax_and_size_all_segments ();
1304 #endif /* BFD_ASSEMBLER */
1306 #ifndef BFD_ASSEMBLER
1309 * Crawl the symbol chain.
1311 * For each symbol whose value depends on a frag, take the address of
1312 * that frag and subsume it into the value of the symbol.
1313 * After this, there is just one way to lookup a symbol value.
1314 * Values are left in their final state for object file emission.
1315 * We adjust the values of 'L' local symbols, even if we do
1316 * not intend to emit them to the object file, because their values
1317 * are needed for fix-ups.
1319 * Unless we saw a -L flag, remove all symbols that begin with 'L'
1320 * from the symbol chain. (They are still pointed to by the fixes.)
1322 * Count the remaining symbols.
1323 * Assign a symbol number to each symbol.
1324 * Count the number of string-table chars we will emit.
1325 * Put this info into the headers as appropriate.
1328 know (zero_address_frag
.fr_address
== 0);
1329 string_byte_count
= sizeof (string_byte_count
);
1331 obj_crawl_symbol_chain (&headers
);
1333 if (string_byte_count
== sizeof (string_byte_count
))
1334 string_byte_count
= 0;
1336 H_SET_STRING_SIZE (&headers
, string_byte_count
);
1339 * Addresses of frags now reflect addresses we use in the object file.
1340 * Symbol values are correct.
1341 * Scan the frags, converting any ".org"s and ".align"s to ".fill"s.
1342 * Also converting any machine-dependent frags using md_convert_frag();
1344 subseg_change (SEG_TEXT
, 0);
1346 for (fragP
= text_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1348 cvt_frag_to_fill (&headers
, SEG_TEXT
, fragP
);
1350 /* Some assert macros don't work with # directives mixed in. */
1352 if (!(fragP
->fr_next
== NULL
1354 || fragP
->fr_next
== data_frag_root
1356 || ((fragP
->fr_next
->fr_address
- fragP
->fr_address
)
1357 == (fragP
->fr_fix
+ fragP
->fr_offset
* fragP
->fr_var
))))
1361 #endif /* ! BFD_ASSEMBLER */
1363 #ifndef WORKING_DOT_WORD
1365 struct broken_word
*lie
;
1366 struct broken_word
**prevP
;
1368 prevP
= &broken_words
;
1369 for (lie
= broken_words
; lie
; lie
= lie
->next_broken_word
)
1374 exp
.X_op
= O_subtract
;
1375 exp
.X_add_symbol
= lie
->add
;
1376 exp
.X_op_symbol
= lie
->sub
;
1377 exp
.X_add_number
= lie
->addnum
;
1378 #ifdef BFD_ASSEMBLER
1379 #ifdef TC_CONS_FIX_NEW
1380 TC_CONS_FIX_NEW (lie
->frag
,
1381 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1384 fix_new_exp (lie
->frag
,
1385 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1386 2, &exp
, 0, BFD_RELOC_NONE
);
1389 #if defined(TC_SPARC) || defined(TC_A29K) || defined(NEED_FX_R_TYPE)
1390 fix_new_exp (lie
->frag
,
1391 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1392 2, &exp
, 0, NO_RELOC
);
1395 fix_new_ns32k_exp (lie
->frag
,
1396 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1397 2, &exp
, 0, 0, 2, 0, 0);
1399 fix_new_exp (lie
->frag
,
1400 lie
->word_goes_here
- lie
->frag
->fr_literal
,
1402 #endif /* TC_NS32K */
1403 #endif /* TC_SPARC|TC_A29K|NEED_FX_R_TYPE */
1404 #endif /* BFD_ASSEMBLER */
1405 *prevP
= lie
->next_broken_word
;
1408 prevP
= &(lie
->next_broken_word
);
1410 for (lie
= broken_words
; lie
;)
1412 struct broken_word
*untruth
;
1414 addressT table_addr
;
1415 addressT from_addr
, to_addr
;
1418 fragP
= lie
->dispfrag
;
1420 /* Find out how many broken_words go here. */
1422 for (untruth
= lie
; untruth
&& untruth
->dispfrag
== fragP
; untruth
= untruth
->next_broken_word
)
1423 if (untruth
->added
== 1)
1426 table_ptr
= lie
->dispfrag
->fr_opcode
;
1427 table_addr
= lie
->dispfrag
->fr_address
+ (table_ptr
- lie
->dispfrag
->fr_literal
);
1428 /* Create the jump around the long jumps. This is a short
1429 jump from table_ptr+0 to table_ptr+n*long_jump_size. */
1430 from_addr
= table_addr
;
1431 to_addr
= table_addr
+ md_short_jump_size
+ n
* md_long_jump_size
;
1432 md_create_short_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
, lie
->add
);
1433 table_ptr
+= md_short_jump_size
;
1434 table_addr
+= md_short_jump_size
;
1436 for (m
= 0; lie
&& lie
->dispfrag
== fragP
; m
++, lie
= lie
->next_broken_word
)
1438 if (lie
->added
== 2)
1440 /* Patch the jump table */
1441 /* This is the offset from ??? to table_ptr+0 */
1442 to_addr
= table_addr
- S_GET_VALUE (lie
->sub
);
1443 #ifdef BFD_ASSEMBLER
1444 to_addr
-= lie
->sub
->sy_frag
->fr_address
;
1446 md_number_to_chars (lie
->word_goes_here
, to_addr
, 2);
1447 for (untruth
= lie
->next_broken_word
; untruth
&& untruth
->dispfrag
== fragP
; untruth
= untruth
->next_broken_word
)
1449 if (untruth
->use_jump
== lie
)
1450 md_number_to_chars (untruth
->word_goes_here
, to_addr
, 2);
1453 /* Install the long jump */
1454 /* this is a long jump from table_ptr+0 to the final target */
1455 from_addr
= table_addr
;
1456 to_addr
= S_GET_VALUE (lie
->add
) + lie
->addnum
;
1457 #ifdef BFD_ASSEMBLER
1458 to_addr
+= lie
->add
->sy_frag
->fr_address
;
1460 md_create_long_jump (table_ptr
, from_addr
, to_addr
, lie
->dispfrag
, lie
->add
);
1461 table_ptr
+= md_long_jump_size
;
1462 table_addr
+= md_long_jump_size
;
1466 #endif /* not WORKING_DOT_WORD */
1468 #ifndef BFD_ASSEMBLER
1471 char *the_object_file
;
1472 long object_file_size
;
1474 * Scan every FixS performing fixups. We had to wait until now to do
1475 * this because md_convert_frag() may have made some fixSs.
1479 subseg_change (SEG_TEXT
, 0);
1480 trsize
= md_reloc_size
* fixup_segment (text_fix_root
, SEG_TEXT
);
1481 subseg_change (SEG_DATA
, 0);
1482 drsize
= md_reloc_size
* fixup_segment (data_fix_root
, SEG_DATA
);
1483 H_SET_RELOCATION_SIZE (&headers
, trsize
, drsize
);
1485 /* FIXME move this stuff into the pre-write-hook */
1486 H_SET_MAGIC_NUMBER (&headers
, magic_number_for_object_file
);
1487 H_SET_ENTRY_POINT (&headers
, 0);
1489 obj_pre_write_hook (&headers
); /* extra coff stuff */
1491 object_file_size
= H_GET_FILE_SIZE (&headers
);
1492 next_object_file_charP
= the_object_file
= xmalloc (object_file_size
);
1494 output_file_create (out_file_name
);
1496 obj_header_append (&next_object_file_charP
, &headers
);
1498 know ((next_object_file_charP
- the_object_file
) == H_GET_HEADER_SIZE (&headers
));
1503 for (fragP
= text_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1505 register long count
;
1506 register char *fill_literal
;
1507 register long fill_size
;
1510 know (fragP
->fr_type
== rs_fill
);
1511 append (&next_object_file_charP
, fragP
->fr_literal
, (unsigned long) fragP
->fr_fix
);
1512 fill_literal
= fragP
->fr_literal
+ fragP
->fr_fix
;
1513 fill_size
= fragP
->fr_var
;
1514 know (fragP
->fr_offset
>= 0);
1516 for (count
= fragP
->fr_offset
; count
; count
--)
1518 append (&next_object_file_charP
, fill_literal
, (unsigned long) fill_size
);
1521 } /* for each code frag. */
1523 know ((next_object_file_charP
- the_object_file
) == (H_GET_HEADER_SIZE (&headers
) + H_GET_TEXT_SIZE (&headers
) + H_GET_DATA_SIZE (&headers
)));
1528 obj_emit_relocations (&next_object_file_charP
, text_fix_root
, (relax_addressT
) 0);
1529 know ((next_object_file_charP
- the_object_file
) == (H_GET_HEADER_SIZE (&headers
) + H_GET_TEXT_SIZE (&headers
) + H_GET_DATA_SIZE (&headers
) + H_GET_TEXT_RELOCATION_SIZE (&headers
)));
1531 /* Make addresses in data relocation directives relative to beginning of
1532 * first data fragment, not end of last text fragment: alignment of the
1533 * start of the data segment may place a gap between the segments.
1535 obj_emit_relocations (&next_object_file_charP
, data_fix_root
, data0_frchainP
->frch_root
->fr_address
);
1537 obj_emit_relocations (&next_object_file_charP
, data_fix_root
, text_last_frag
->fr_address
);
1538 #endif /* TC_I960 */
1540 know ((next_object_file_charP
- the_object_file
) == (H_GET_HEADER_SIZE (&headers
) + H_GET_TEXT_SIZE (&headers
) + H_GET_DATA_SIZE (&headers
) + H_GET_TEXT_RELOCATION_SIZE (&headers
) + H_GET_DATA_RELOCATION_SIZE (&headers
)));
1543 * Emit line number entries.
1545 OBJ_EMIT_LINENO (&next_object_file_charP
, lineno_rootP
, the_object_file
);
1546 know ((next_object_file_charP
- the_object_file
) == (H_GET_HEADER_SIZE (&headers
) + H_GET_TEXT_SIZE (&headers
) + H_GET_DATA_SIZE (&headers
) + H_GET_TEXT_RELOCATION_SIZE (&headers
) + H_GET_DATA_RELOCATION_SIZE (&headers
) + H_GET_LINENO_SIZE (&headers
)));
1551 obj_emit_symbols (&next_object_file_charP
, symbol_rootP
);
1552 know ((next_object_file_charP
- the_object_file
) == (H_GET_HEADER_SIZE (&headers
) + H_GET_TEXT_SIZE (&headers
) + H_GET_DATA_SIZE (&headers
) + H_GET_TEXT_RELOCATION_SIZE (&headers
) + H_GET_DATA_RELOCATION_SIZE (&headers
) + H_GET_LINENO_SIZE (&headers
) + H_GET_SYMBOL_TABLE_SIZE (&headers
)));
1558 if (string_byte_count
> 0)
1560 obj_emit_strings (&next_object_file_charP
);
1561 } /* only if we have a string table */
1564 bfd_seek (stdoutput
, 0, 0);
1565 bfd_write (the_object_file
, 1, object_file_size
, stdoutput
);
1568 /* Write the data to the file */
1569 output_file_append (the_object_file
, object_file_size
, out_file_name
);
1570 free (the_object_file
);
1572 } /* non vms output */
1575 * Now do the VMS-dependent part of writing the object file
1577 vms_write_object_file (H_GET_TEXT_SIZE (&headers
),
1578 H_GET_DATA_SIZE (&headers
),
1579 H_GET_BSS_SIZE (&headers
),
1580 text_frag_root
, data_frag_root
);
1581 #endif /* OBJ_VMS */
1582 #else /* BFD_ASSEMBLER */
1584 /* Resolve symbol values. This needs to be done before processing
1590 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1591 if (!symp
->sy_resolved
)
1592 resolve_symbol_value (symp
);
1597 bfd_map_over_sections (stdoutput
, adjust_reloc_syms
, (char *)0);
1599 /* Set up symbol table, and write it out. */
1604 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1609 if (symp
->sy_mri_common
)
1611 if (S_IS_EXTERNAL (symp
))
1612 as_bad ("%s: global symbols not supported in common sections",
1614 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1618 name
= S_GET_NAME (symp
);
1621 const char *name2
= decode_local_label_name ((char *)S_GET_NAME (symp
));
1622 /* They only differ if `name' is a fb or dollar local
1624 if (name2
!= name
&& ! S_IS_DEFINED (symp
))
1625 as_bad ("local label %s is not defined", name2
);
1628 /* Do it again, because adjust_reloc_syms might introduce
1629 more symbols. They'll probably only be section symbols,
1630 but they'll still need to have the values computed. */
1631 if (! symp
->sy_resolved
)
1633 if (symp
->sy_value
.X_op
== O_constant
)
1635 /* This is the normal case; skip the call. */
1638 + symp
->sy_frag
->fr_address
));
1639 symp
->sy_resolved
= 1;
1642 resolve_symbol_value (symp
);
1645 /* So far, common symbols have been treated like undefined symbols.
1646 Put them in the common section now. */
1647 if (S_IS_DEFINED (symp
) == 0
1648 && S_GET_VALUE (symp
) != 0)
1649 S_SET_SEGMENT (symp
, bfd_com_section_ptr
);
1651 printf ("symbol `%s'\n\t@%x: value=%d flags=%x seg=%s\n",
1652 S_GET_NAME (symp
), symp
,
1655 segment_name (symp
->bsym
->section
));
1658 #ifdef obj_frob_symbol
1659 obj_frob_symbol (symp
, punt
);
1661 #ifdef tc_frob_symbol
1662 if (! punt
|| symp
->sy_used_in_reloc
)
1663 tc_frob_symbol (symp
, punt
);
1666 /* If we don't want to keep this symbol, splice it out of
1667 the chain now. If EMIT_SECTION_SYMBOLS is 0, we never
1668 want section symbols. Otherwise, we skip local symbols
1669 and symbols that the frob_symbol macros told us to punt,
1670 but we keep such symbols if they are used in relocs. */
1671 if ((! EMIT_SECTION_SYMBOLS
1672 && (symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0)
1673 /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
1674 opposites. Sometimes the former checks flags and the
1675 latter examines the name... */
1676 || (!S_IS_EXTERN (symp
)
1677 && (S_IS_LOCAL (symp
) || punt
)
1678 && ! symp
->sy_used_in_reloc
))
1680 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1681 /* After symbol_remove, symbol_next(symp) still returns
1682 the one that came after it in the chain. So we don't
1683 need to do any extra cleanup work here. */
1688 /* Make sure we really got a value for the symbol. */
1689 if (! symp
->sy_resolved
)
1691 as_bad ("can't resolve value for symbol \"%s\"",
1693 symp
->sy_resolved
= 1;
1696 /* Set the value into the BFD symbol. Up til now the value
1697 has only been kept in the gas symbolS struct. */
1698 symp
->bsym
->value
= S_GET_VALUE (symp
);
1704 /* Now do any format-specific adjustments to the symbol table, such
1705 as adding file symbols. */
1706 #ifdef obj_adjust_symtab
1707 obj_adjust_symtab ();
1710 /* Now that all the sizes are known, and contents correct, we can
1711 start writing to the file. */
1714 /* If *_frob_file changes the symbol value at this point, it is
1715 responsible for moving the changed value into symp->bsym->value
1716 as well. Hopefully all symbol value changing can be done in
1721 #ifdef obj_frob_file
1725 bfd_map_over_sections (stdoutput
, write_relocs
, (char *) 0);
1727 bfd_map_over_sections (stdoutput
, write_contents
, (char *) 0);
1728 #endif /* BFD_ASSEMBLER */
1735 * Now we have a segment, not a crowd of sub-segments, we can make fr_address
1740 * After this, all frags in this segment have addresses that are correct
1741 * within the segment. Since segments live in different file addresses,
1742 * these frag addresses may not be the same as final object-file addresses.
1745 #ifndef md_relax_frag
1747 /* Subroutines of relax_segment. */
1753 for (; f1
; f1
= f1
->fr_next
)
1754 if (f1
->fr_next
== f2
)
1759 #endif /* ! defined (md_relax_frag) */
1761 /* Relax_align. Advance location counter to next address that has 'alignment'
1762 lowest order bits all 0s, return size of adjustment made. */
1763 static relax_addressT
1764 relax_align (address
, alignment
)
1765 register relax_addressT address
; /* Address now. */
1766 register int alignment
; /* Alignment (binary). */
1768 relax_addressT mask
;
1769 relax_addressT new_address
;
1771 mask
= ~((~0) << alignment
);
1772 new_address
= (address
+ mask
) & (~mask
);
1773 #ifdef LINKER_RELAXING_SHRINKS_ONLY
1775 /* We must provide lots of padding, so the linker can discard it
1776 when needed. The linker will not add extra space, ever. */
1777 new_address
+= (1 << alignment
);
1779 return (new_address
- address
);
1783 relax_segment (segment_frag_root
, segment
)
1784 struct frag
*segment_frag_root
;
1787 register struct frag
*fragP
;
1788 register relax_addressT address
;
1789 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
1790 know (segment
== SEG_DATA
|| segment
== SEG_TEXT
|| segment
== SEG_BSS
);
1792 /* In case md_estimate_size_before_relax() wants to make fixSs. */
1793 subseg_change (segment
, 0);
1795 /* For each frag in segment: count and store (a 1st guess of)
1798 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1800 fragP
->fr_address
= address
;
1801 address
+= fragP
->fr_fix
;
1803 switch (fragP
->fr_type
)
1806 address
+= fragP
->fr_offset
* fragP
->fr_var
;
1812 int offset
= relax_align (address
, (int) fragP
->fr_offset
);
1813 if (offset
% fragP
->fr_var
!= 0)
1815 as_bad ("alignment padding (%d bytes) not a multiple of %ld",
1816 offset
, (long) fragP
->fr_var
);
1817 offset
-= (offset
% fragP
->fr_var
);
1825 /* Assume .org is nugatory. It will grow with 1st relax. */
1828 case rs_machine_dependent
:
1829 address
+= md_estimate_size_before_relax (fragP
, segment
);
1832 #ifndef WORKING_DOT_WORD
1833 /* Broken words don't concern us yet */
1834 case rs_broken_word
:
1839 BAD_CASE (fragP
->fr_type
);
1841 } /* switch(fr_type) */
1842 } /* for each frag in the segment */
1846 long stretch
; /* May be any size, 0 or negative. */
1847 /* Cumulative number of addresses we have */
1848 /* relaxed this pass. */
1849 /* We may have relaxed more than one address. */
1850 long stretched
; /* Have we stretched on this pass? */
1851 /* This is 'cuz stretch may be zero, when, in fact some piece of code
1852 grew, and another shrank. If a branch instruction doesn't fit anymore,
1853 we could be scrod. */
1857 stretch
= stretched
= 0;
1858 for (fragP
= segment_frag_root
; fragP
; fragP
= fragP
->fr_next
)
1861 unsigned long was_address
;
1867 was_address
= fragP
->fr_address
;
1868 address
= fragP
->fr_address
+= stretch
;
1869 symbolP
= fragP
->fr_symbol
;
1870 offset
= fragP
->fr_offset
;
1872 switch (fragP
->fr_type
)
1874 case rs_fill
: /* .fill never relaxes. */
1878 #ifndef WORKING_DOT_WORD
1879 /* JF: This is RMS's idea. I do *NOT* want to be blamed
1880 for it I do not want to write it. I do not want to have
1881 anything to do with it. This is not the proper way to
1882 implement this misfeature. */
1883 case rs_broken_word
:
1885 struct broken_word
*lie
;
1886 struct broken_word
*untruth
;
1888 /* Yes this is ugly (storing the broken_word pointer
1889 in the symbol slot). Still, this whole chunk of
1890 code is ugly, and I don't feel like doing anything
1891 about it. Think of it as stubbornness in action. */
1893 for (lie
= (struct broken_word
*) (fragP
->fr_symbol
);
1894 lie
&& lie
->dispfrag
== fragP
;
1895 lie
= lie
->next_broken_word
)
1901 offset
= (lie
->add
->sy_frag
->fr_address
1902 + S_GET_VALUE (lie
->add
)
1904 - (lie
->sub
->sy_frag
->fr_address
1905 + S_GET_VALUE (lie
->sub
)));
1906 if (offset
<= -32768 || offset
>= 32767)
1908 if (flag_warn_displacement
)
1911 sprint_value (buf
, (addressT
) lie
->addnum
);
1912 as_warn (".word %s-%s+%s didn't fit",
1913 S_GET_NAME (lie
->add
),
1914 S_GET_NAME (lie
->sub
),
1918 if (fragP
->fr_subtype
== 0)
1920 fragP
->fr_subtype
++;
1921 growth
+= md_short_jump_size
;
1923 for (untruth
= lie
->next_broken_word
;
1924 untruth
&& untruth
->dispfrag
== lie
->dispfrag
;
1925 untruth
= untruth
->next_broken_word
)
1926 if ((untruth
->add
->sy_frag
== lie
->add
->sy_frag
)
1927 && S_GET_VALUE (untruth
->add
) == S_GET_VALUE (lie
->add
))
1930 untruth
->use_jump
= lie
;
1932 growth
+= md_long_jump_size
;
1937 } /* case rs_broken_word */
1941 growth
= (relax_align ((relax_addressT
) (address
1944 - relax_align ((relax_addressT
) (was_address
1954 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
1955 know ((S_GET_SEGMENT (symbolP
) == SEG_ABSOLUTE
)
1956 || (S_GET_SEGMENT (symbolP
) == SEG_DATA
)
1957 || (S_GET_SEGMENT (symbolP
) == SEG_TEXT
)
1958 || S_GET_SEGMENT (symbolP
) == SEG_BSS
);
1959 know (symbolP
->sy_frag
);
1960 know (!(S_GET_SEGMENT (symbolP
) == SEG_ABSOLUTE
)
1961 || (symbolP
->sy_frag
== &zero_address_frag
));
1963 target
+= S_GET_VALUE (symbolP
)
1964 + symbolP
->sy_frag
->fr_address
;
1965 } /* if we have a symbol */
1967 know (fragP
->fr_next
);
1968 after
= fragP
->fr_next
->fr_address
;
1969 growth
= target
- after
;
1972 /* Growth may be negative, but variable part of frag
1973 cannot have fewer than 0 chars. That is, we can't
1975 as_bad ("attempt to .org backwards ignored");
1979 growth
-= stretch
; /* This is an absolute growth factor */
1985 growth
= S_GET_VALUE (symbolP
);
1986 if (symbolP
->sy_frag
!= &zero_address_frag
)
1987 as_bad (".space specifies non-absolute value");
1988 fragP
->fr_symbol
= 0;
1991 as_warn (".space or .fill with negative value, ignored");
1999 case rs_machine_dependent
:
2000 #ifdef md_relax_frag
2001 growth
= md_relax_frag (fragP
, stretch
);
2003 #ifdef TC_GENERIC_RELAX_TABLE
2004 /* The default way to relax a frag is to look through
2007 const relax_typeS
*this_type
;
2008 const relax_typeS
*start_type
;
2009 relax_substateT next_state
;
2010 relax_substateT this_state
;
2012 const relax_typeS
*table
= TC_GENERIC_RELAX_TABLE
;
2014 this_state
= fragP
->fr_subtype
;
2015 start_type
= this_type
= table
+ this_state
;
2020 #ifndef DIFF_EXPR_OK
2021 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
2022 know ((S_GET_SEGMENT (symbolP
) == SEG_ABSOLUTE
)
2023 || (S_GET_SEGMENT (symbolP
) == SEG_DATA
)
2024 || (S_GET_SEGMENT (symbolP
) == SEG_BSS
)
2025 || (S_GET_SEGMENT (symbolP
) == SEG_TEXT
));
2027 know (symbolP
->sy_frag
);
2029 know (!(S_GET_SEGMENT (symbolP
) == absolute_section
)
2030 || symbolP
->sy_frag
== &zero_address_frag
);
2032 S_GET_VALUE (symbolP
)
2033 + symbolP
->sy_frag
->fr_address
;
2035 /* If frag has yet to be reached on this pass,
2036 assume it will move by STRETCH just as we did.
2037 If this is not so, it will be because some frag
2038 between grows, and that will force another pass.
2040 Beware zero-length frags.
2042 There should be a faster way to do this. */
2044 if (symbolP
->sy_frag
->fr_address
>= was_address
2045 && is_dnrange (fragP
, symbolP
->sy_frag
))
2051 aim
= target
- address
- fragP
->fr_fix
;
2052 #ifdef TC_PCREL_ADJUST
2053 /* Currently only the ns32k family needs this */
2054 aim
+= TC_PCREL_ADJUST(fragP
);
2056 /* This machine doesn't want to use pcrel_adjust.
2057 In that case, pcrel_adjust should be zero. */
2058 assert (fragP
->fr_pcrel_adjust
== 0);
2063 /* Look backwards. */
2064 for (next_state
= this_type
->rlx_more
; next_state
;)
2065 if (aim
>= this_type
->rlx_backward
)
2069 /* Grow to next state. */
2070 this_state
= next_state
;
2071 this_type
= table
+ this_state
;
2072 next_state
= this_type
->rlx_more
;
2077 #ifdef M68K_AIM_KLUDGE
2078 M68K_AIM_KLUDGE (aim
, this_state
, this_type
);
2080 /* Look forwards. */
2081 for (next_state
= this_type
->rlx_more
; next_state
;)
2082 if (aim
<= this_type
->rlx_forward
)
2086 /* Grow to next state. */
2087 this_state
= next_state
;
2088 this_type
= table
+ this_state
;
2089 next_state
= this_type
->rlx_more
;
2093 growth
= this_type
->rlx_length
- start_type
->rlx_length
;
2095 fragP
->fr_subtype
= this_state
;
2097 #endif /* TC_GENERIC_RELAX_TABLE */
2102 BAD_CASE (fragP
->fr_type
);
2110 } /* For each frag in the segment. */
2112 while (stretched
); /* Until nothing further to relax. */
2116 * We now have valid fr_address'es for each frag.
2120 * All fr_address's are correct, relative to their own segment.
2121 * We have made all the fixS we will ever make.
2123 } /* relax_segment() */
2125 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
2127 #ifndef TC_RELOC_RTSYM_LOC_FIXUP
2128 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)
2133 Go through all the fixS's in a segment and see which ones can be
2134 handled now. (These consist of fixS where we have since discovered
2135 the value of a symbol, or the address of the frag involved.)
2136 For each one, call md_apply_fix to put the fix into the frag data.
2138 Result is a count of how many relocation structs will be needed to
2139 handle the remaining fixS's that we couldn't completely handle here.
2140 These will be output later by emit_relocations(). */
2143 fixup_segment (fixP
, this_segment_type
)
2144 register fixS
*fixP
;
2145 segT this_segment_type
; /* N_TYPE bits for segment. */
2147 long seg_reloc_count
= 0;
2148 symbolS
*add_symbolP
;
2149 symbolS
*sub_symbolP
;
2156 segT add_symbol_segment
= absolute_section
;
2158 /* If the linker is doing the relaxing, we must not do any fixups.
2160 Well, strictly speaking that's not true -- we could do any that are
2161 PC-relative and don't cross regions that could change size. And for the
2162 i960 (the only machine for which we've got a relaxing linker right now),
2163 we might be able to turn callx/callj into bal anyways in cases where we
2164 know the maximum displacement. */
2167 for (; fixP
; fixP
= fixP
->fx_next
)
2169 TC_ADJUST_RELOC_COUNT (fixP
, seg_reloc_count
);
2170 return seg_reloc_count
;
2173 for (; fixP
; fixP
= fixP
->fx_next
)
2176 fprintf (stderr
, "\nprocessing fixup:\n");
2180 fragP
= fixP
->fx_frag
;
2182 where
= fixP
->fx_where
;
2183 place
= fragP
->fr_literal
+ where
;
2184 size
= fixP
->fx_size
;
2185 add_symbolP
= fixP
->fx_addsy
;
2186 #ifdef TC_VALIDATE_FIX
2187 TC_VALIDATE_FIX (fixP
, this_segment_type
, skip
);
2189 sub_symbolP
= fixP
->fx_subsy
;
2190 add_number
= fixP
->fx_offset
;
2191 pcrel
= fixP
->fx_pcrel
;
2194 if (add_symbolP
!= NULL
2195 && add_symbolP
->sy_mri_common
)
2197 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
2198 add_number
+= S_GET_VALUE (add_symbolP
);
2199 fixP
->fx_offset
= add_number
;
2200 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
2204 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
2208 resolve_symbol_value (sub_symbolP
);
2209 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
2211 if (add_symbolP
!= NULL
)
2213 add_number
+= S_GET_VALUE (add_symbolP
);
2215 fixP
->fx_addsy
= NULL
;
2218 /* It's just -sym */
2219 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
2221 add_number
-= S_GET_VALUE (sub_symbolP
);
2222 fixP
->fx_subsy
= NULL
;
2225 && S_GET_SEGMENT (sub_symbolP
) == this_segment_type
)
2227 /* Should try converting to a constant. */
2232 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2233 "Negative of non-absolute symbol %s",
2234 S_GET_NAME (sub_symbolP
));
2236 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
2237 && SEG_NORMAL (add_symbol_segment
))
2239 /* Difference of 2 symbols from same segment.
2240 Can't make difference of 2 undefineds: 'value' means
2241 something different for N_UNDF. */
2243 /* Makes no sense to use the difference of 2 arbitrary symbols
2244 as the target of a call instruction. */
2246 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2247 "callj to difference of 2 symbols");
2248 #endif /* TC_I960 */
2249 add_number
+= S_GET_VALUE (add_symbolP
) -
2250 S_GET_VALUE (sub_symbolP
);
2253 pcrel
= 0; /* No further pcrel processing. */
2255 /* Let the target machine make the final determination
2256 as to whether or not a relocation will be needed to
2257 handle this fixup. */
2258 if (!TC_FORCE_RELOCATION_SECTION (fixP
, this_segment_type
))
2261 fixP
->fx_addsy
= NULL
;
2262 fixP
->fx_subsy
= NULL
;
2267 /* Different segments in subtraction. */
2268 know (!(S_IS_EXTERNAL (sub_symbolP
)
2269 && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
2271 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
2272 add_number
-= S_GET_VALUE (sub_symbolP
);
2275 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
2276 #if 0 /* Do this even if it's already described as pc-relative. For example,
2277 on the m68k, an operand of "pc@(foo-.-2)" should address "foo" in a
2278 pc-relative mode. */
2283 /* Make it pc-relative. */
2284 add_number
+= (MD_PCREL_FROM_SECTION (fixP
, this_segment_type
)
2285 - S_GET_VALUE (sub_symbolP
));
2292 #ifdef UNDEFINED_DIFFERENCE_OK
2293 /* The PA needs this for PIC code generation. We basically
2294 don't want to do anything if we have the difference of two
2295 symbols at this point. */
2298 /* Leave it alone. */
2301 #ifdef BFD_ASSEMBLER
2302 else if (fixP
->fx_r_type
== BFD_RELOC_GPREL32
2303 || fixP
->fx_r_type
== BFD_RELOC_GPREL16
)
2305 /* Leave it alone. */
2311 sprint_value (buf
, fragP
->fr_address
+ where
);
2312 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2313 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %s.",
2314 segment_name (S_GET_SEGMENT (sub_symbolP
)),
2315 S_GET_NAME (sub_symbolP
), buf
);
2322 if (add_symbol_segment
== this_segment_type
&& pcrel
&& !plt
2323 && TC_RELOC_RTSYM_LOC_FIXUP (fixP
))
2326 * This fixup was made when the symbol's segment was
2327 * SEG_UNKNOWN, but it is now in the local segment.
2328 * So we know how to do the address without relocation.
2331 /* reloc_callj() may replace a 'call' with a 'calls' or a
2332 'bal', in which cases it modifies *fixP as appropriate.
2333 In the case of a 'calls', no further work is required,
2334 and *fixP has been set up to make the rest of the code
2337 #endif /* TC_I960 */
2339 add_number
+= S_GET_VALUE (add_symbolP
);
2340 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment_type
);
2341 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
2343 /* Let the target machine make the final determination
2344 as to whether or not a relocation will be needed to
2345 handle this fixup. */
2346 if (!TC_FORCE_RELOCATION (fixP
))
2349 fixP
->fx_addsy
= NULL
;
2354 if (add_symbol_segment
== absolute_section
)
2357 /* See comment about reloc_callj() above. */
2359 #endif /* TC_I960 */
2360 add_number
+= S_GET_VALUE (add_symbolP
);
2362 /* Let the target machine make the final determination
2363 as to whether or not a relocation will be needed to
2364 handle this fixup. */
2366 if (!TC_FORCE_RELOCATION (fixP
))
2368 fixP
->fx_addsy
= NULL
;
2372 else if (add_symbol_segment
== undefined_section
2373 #ifdef BFD_ASSEMBLER
2374 || bfd_is_com_section (add_symbol_segment
)
2379 if ((int) fixP
->fx_bit_fixP
== 13)
2381 /* This is a COBR instruction. They have only a
2382 * 13-bit displacement and are only to be used
2383 * for local branches: flag as error, don't generate
2386 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2387 "can't use COBR format with external label");
2388 fixP
->fx_addsy
= NULL
;
2392 #endif /* TC_I960 */
2396 if (S_IS_COMMON (add_symbolP
))
2397 add_number
+= S_GET_VALUE (add_symbolP
);
2398 #endif /* TE_I386AIX */
2399 #endif /* OBJ_COFF */
2405 #if !defined (TC_I386) || !(defined (OBJ_ELF) || defined (OBJ_COFF))
2406 add_number
+= S_GET_VALUE (add_symbolP
);
2414 add_number
-= MD_PCREL_FROM_SECTION (fixP
, this_segment_type
);
2415 if (add_symbolP
== 0)
2417 #ifndef BFD_ASSEMBLER
2418 fixP
->fx_addsy
= &abs_symbol
;
2420 fixP
->fx_addsy
= section_symbol (absolute_section
);
2422 fixP
->fx_addsy
->sy_used_in_reloc
= 1;
2427 if (!fixP
->fx_bit_fixP
&& !fixP
->fx_no_overflow
&& size
> 0)
2430 if (size
< sizeof (mask
))
2432 /* set all bits to one */
2434 /* Technically, combining these produces an undefined result
2435 if size is sizeof (valueT), though I think these two
2436 half-way operations should both be defined. And the
2437 compiler should be able to combine them if it's valid on
2438 the host architecture. */
2441 if ((add_number
& mask
) != 0
2442 && (add_number
& mask
) != mask
)
2444 char buf
[50], buf2
[50];
2445 sprint_value (buf
, fragP
->fr_address
+ where
);
2446 if (add_number
> 1000)
2447 sprint_value (buf2
, add_number
);
2449 sprintf (buf2
, "%ld", (long) add_number
);
2450 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2451 "Value of %s too large for field of %d bytes at %s",
2453 } /* generic error checking */
2455 #ifdef WARN_SIGNED_OVERFLOW_WORD
2456 /* Warn if a .word value is too large when treated as a signed
2457 number. We already know it is not too negative. This is to
2458 catch over-large switches generated by gcc on the 68k. */
2459 if (!flag_signed_overflow_ok
2461 && add_number
> 0x7fff)
2462 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2463 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
2465 (unsigned long) (fragP
->fr_address
+ where
));
2467 } /* not a bit fix */
2471 #ifdef MD_APPLY_FIX3
2472 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
2474 #ifdef BFD_ASSEMBLER
2475 md_apply_fix (fixP
, &add_number
);
2477 md_apply_fix (fixP
, add_number
);
2481 #ifndef TC_HANDLES_FX_DONE
2482 /* If the tc-* files haven't been converted, assume it's handling
2483 it the old way, where a null fx_addsy means that the fix has
2484 been applied completely, and no further work is needed. */
2485 if (fixP
->fx_addsy
== 0 && fixP
->fx_pcrel
== 0)
2489 #ifdef TC_VALIDATE_FIX
2493 fprintf (stderr
, "result:\n");
2496 } /* For each fixS in this segment. */
2498 TC_ADJUST_RELOC_COUNT (fixP
, seg_reloc_count
);
2499 return seg_reloc_count
;
2502 #endif /* defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) */
2505 number_to_chars_bigendian (buf
, val
, n
)
2510 if (n
> sizeof (val
)|| n
<= 0)
2514 buf
[n
] = val
& 0xff;
2520 number_to_chars_littleendian (buf
, val
, n
)
2525 if (n
> sizeof (val
) || n
<= 0)
2529 *buf
++ = val
& 0xff;
2535 extern int indent_level
;
2536 extern void print_symbol_value_1 ();
2543 fprintf (stderr
, "fix %lx %s:%d", (long) fixp
, fixp
->fx_file
, fixp
->fx_line
);
2545 fprintf (stderr
, " pcrel");
2546 if (fixp
->fx_pcrel_adjust
)
2547 fprintf (stderr
, " pcrel_adjust=%d", fixp
->fx_pcrel_adjust
);
2548 if (fixp
->fx_im_disp
)
2551 fprintf (stderr
, " im_disp=%d", fixp
->fx_im_disp
);
2553 fprintf (stderr
, " im_disp");
2557 fprintf (stderr
, " tcbit");
2559 fprintf (stderr
, " done");
2560 fprintf (stderr
, "\n size=%d frag=%lx where=%ld offset=%lx addnumber=%lx",
2561 fixp
->fx_size
, (long) fixp
->fx_frag
, (long) fixp
->fx_where
,
2562 (long) fixp
->fx_offset
, (long) fixp
->fx_addnumber
);
2563 #ifdef BFD_ASSEMBLER
2564 fprintf (stderr
, "\n %s (%d)", bfd_get_reloc_code_name (fixp
->fx_r_type
),
2567 #ifdef NEED_FX_R_TYPE
2568 fprintf (stderr
, " r_type=%d", fixp
->fx_r_type
);
2573 fprintf (stderr
, "\n +<");
2574 print_symbol_value_1 (stderr
, fixp
->fx_addsy
);
2575 fprintf (stderr
, ">");
2579 fprintf (stderr
, "\n -<");
2580 print_symbol_value_1 (stderr
, fixp
->fx_subsy
);
2581 fprintf (stderr
, ">");
2583 fprintf (stderr
, "\n");
2586 /* end of write.c */