1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "opcode/ppc.h"
32 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
34 /* FIXME: This should be handled in a different way. */
35 extern int target_big_endian
;
37 static void ppc_set_cpu
PARAMS ((void));
38 static unsigned long ppc_insert_operand
39 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
40 offsetT val
, char *file
, unsigned int line
));
41 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
42 static void ppc_byte
PARAMS ((int));
43 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
44 static void ppc_tc
PARAMS ((int));
46 static void ppc_comm
PARAMS ((int));
47 static void ppc_bb
PARAMS ((int));
48 static void ppc_bf
PARAMS ((int));
49 static void ppc_biei
PARAMS ((int));
50 static void ppc_bs
PARAMS ((int));
51 static void ppc_eb
PARAMS ((int));
52 static void ppc_ef
PARAMS ((int));
53 static void ppc_es
PARAMS ((int));
54 static void ppc_csect
PARAMS ((int));
55 static void ppc_function
PARAMS ((int));
56 static void ppc_extern
PARAMS ((int));
57 static void ppc_lglobl
PARAMS ((int));
58 static void ppc_stabx
PARAMS ((int));
59 static void ppc_rename
PARAMS ((int));
60 static void ppc_toc
PARAMS ((int));
63 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
64 static void ppc_elf_cons
PARAMS ((int));
65 static void ppc_elf_validate_fix (fixS
*, segT
);
68 /* Generic assembler global variables which must be defined by all
71 /* Characters which always start a comment. */
72 const char comment_chars
[] = "#";
74 /* Characters which start a comment at the beginning of a line. */
75 const char line_comment_chars
[] = "#";
77 /* Characters which may be used to separate multiple commands on a
79 const char line_separator_chars
[] = ";";
81 /* Characters which are used to indicate an exponent in a floating
83 const char EXP_CHARS
[] = "eE";
85 /* Characters which mean that a number is a floating point constant,
87 const char FLT_CHARS
[] = "dD";
89 /* The target specific pseudo-ops which we support. */
91 const pseudo_typeS md_pseudo_table
[] =
93 /* Pseudo-ops which must be overridden. */
94 { "byte", ppc_byte
, 0 },
97 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
98 legitimately belong in the obj-*.c file. However, XCOFF is based
99 on COFF, and is only implemented for the RS/6000. We just use
100 obj-coff.c, and add what we need here. */
101 { "comm", ppc_comm
, 0 },
102 { "lcomm", ppc_comm
, 1 },
105 { "bi", ppc_biei
, 0 },
107 { "csect", ppc_csect
, 0 },
110 { "ei", ppc_biei
, 1 },
112 { "extern", ppc_extern
, 0 },
113 { "function", ppc_function
, 0 },
114 { "lglobl", ppc_lglobl
, 0 },
115 { "rename", ppc_rename
, 0 },
116 { "stabx", ppc_stabx
, 0 },
117 { "toc", ppc_toc
, 0 },
120 { "long", ppc_elf_cons
, 4 },
121 { "word", ppc_elf_cons
, 2 },
122 { "short", ppc_elf_cons
, 2 },
125 /* This pseudo-op is used even when not generating XCOFF output. */
131 /* Local variables. */
133 /* The type of processor we are assembling for. This is one or more
134 of the PPC_OPCODE flags defined in opcode/ppc.h. */
135 static int ppc_cpu
= 0;
137 /* The size of the processor we are assembling for. This is either
138 PPC_OPCODE_32 or PPC_OPCODE_64. */
139 static int ppc_size
= PPC_OPCODE_32
;
141 /* The endianness we are using. */
142 static int ppc_big_endian
= PPC_BIG_ENDIAN
;
144 /* Opcode hash table. */
145 static struct hash_control
*ppc_hash
;
147 /* Macro hash table. */
148 static struct hash_control
*ppc_macro_hash
;
151 /* Whether to warn about non PC relative relocations that aren't
152 in the .got2 section. */
153 static boolean mrelocatable
= false;
158 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
159 using a bunch of different sections. These assembler sections,
160 however, are all encompassed within the .text or .data sections of
161 the final output file. We handle this by using different
162 subsegments within these main segments. */
164 /* Next subsegment to allocate within the .text segment. */
165 static subsegT ppc_text_subsegment
= 2;
167 /* Linked list of csects in the text section. */
168 static symbolS
*ppc_text_csects
;
170 /* Next subsegment to allocate within the .data segment. */
171 static subsegT ppc_data_subsegment
= 2;
173 /* Linked list of csects in the data section. */
174 static symbolS
*ppc_data_csects
;
176 /* The current csect. */
177 static symbolS
*ppc_current_csect
;
179 /* The RS/6000 assembler uses a TOC which holds addresses of functions
180 and variables. Symbols are put in the TOC with the .tc pseudo-op.
181 A special relocation is used when accessing TOC entries. We handle
182 the TOC as a subsegment within the .data segment. We set it up if
183 we see a .toc pseudo-op, and save the csect symbol here. */
184 static symbolS
*ppc_toc_csect
;
186 /* The first frag in the TOC subsegment. */
187 static fragS
*ppc_toc_frag
;
189 /* The first frag in the first subsegment after the TOC in the .data
190 segment. NULL if there are no subsegments after the TOC. */
191 static fragS
*ppc_after_toc_frag
;
193 /* The current static block. */
194 static symbolS
*ppc_current_block
;
196 /* The COFF debugging section; set by md_begin. This is not the
197 .debug section, but is instead the secret BFD section which will
198 cause BFD to set the section number of a symbol to N_DEBUG. */
199 static asection
*ppc_coff_debug_section
;
201 /* The size of the .debug section. */
202 static bfd_size_type ppc_debug_name_section_size
;
204 #endif /* OBJ_COFF */
207 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
210 #ifndef WORKING_DOT_WORD
211 const int md_short_jump_size
= 4;
212 const int md_long_jump_size
= 4;
216 CONST
char *md_shortopts
= "um:VQ:";
218 CONST
char *md_shortopts
= "um:";
220 struct option md_longopts
[] = {
221 {NULL
, no_argument
, NULL
, 0}
223 size_t md_longopts_size
= sizeof(md_longopts
);
226 md_parse_option (c
, arg
)
233 /* -u means that any undefined symbols should be treated as
234 external, which is the default for gas anyhow. */
238 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
240 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
241 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
242 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
243 else if (strcmp (arg
, "pwr") == 0)
244 ppc_cpu
= PPC_OPCODE_POWER
;
245 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
246 ignore the option for now, but we should really use it to permit
247 instructions defined on the 601 that are not part of the standard
248 PowerPC architecture (mostly holdovers from the POWER). */
249 else if (strcmp (arg
, "601") == 0)
250 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
251 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
252 Motorola PowerPC 603/604. */
253 else if (strcmp (arg
, "ppc") == 0
254 || strcmp (arg
, "ppc32") == 0
255 || strcmp (arg
, "603") == 0
256 || strcmp (arg
, "604") == 0)
257 ppc_cpu
= PPC_OPCODE_PPC
;
258 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
260 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
262 ppc_cpu
= PPC_OPCODE_PPC
;
263 ppc_size
= PPC_OPCODE_64
;
265 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
266 else if (strcmp (arg
, "any") == 0)
267 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
269 /* -mrelocatable -- warn about initializations that require relocation */
270 else if (strcmp (arg
, "relocatable") == 0)
275 as_bad ("invalid architecture -m%s", arg
);
281 /* -V: SVR4 argument to print version ID. */
286 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
287 should be emitted or not. FIXME: Not implemented. */
300 md_show_usage (stream
)
306 -mpwrx generate code for IBM POWER/2 (RIOS2)\n\
307 -mpwr generate code for IBM POWER (RIOS1)\n\
308 -m601 generate code for Motorola PowerPC 601\n\
309 -mppc, -mppc32, -m603, -m604\n\
310 generate code for Motorola PowerPC 603/604\n\
311 -many generate code for any architecture (PWR/PWRX/PPC)\n");
314 -mrelocatable warn incompatible with GCC's -mrelocatble option\n\
315 -V print assembler version number\n\
316 -Qy, -Qn ignored\n");
320 /* Set ppc_cpu if it is not already set. */
325 const char *default_cpu
= TARGET_CPU
;
329 if (strcmp (default_cpu
, "rs6000") == 0)
330 ppc_cpu
= PPC_OPCODE_POWER
;
331 else if (strcmp (default_cpu
, "powerpc") == 0)
332 ppc_cpu
= PPC_OPCODE_PPC
;
338 /* Figure out the BFD architecture to use. */
340 enum bfd_architecture
345 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
346 return bfd_arch_powerpc
;
347 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
348 return bfd_arch_rs6000
;
353 /* This function is called when the assembler starts up. It is called
354 after the options have been parsed and the output file has been
360 register const struct powerpc_opcode
*op
;
361 const struct powerpc_opcode
*op_end
;
362 const struct powerpc_macro
*macro
;
363 const struct powerpc_macro
*macro_end
;
368 /* Set the -mrelocatable flag bit */
370 bfd_set_private_flags (stdoutput
, EF_PPC_RELOCATABLE
);
373 /* Insert the opcodes into a hash table. */
374 ppc_hash
= hash_new ();
376 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
377 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
379 know ((op
->opcode
& op
->mask
) == op
->opcode
);
381 if ((op
->flags
& ppc_cpu
) != 0
382 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
383 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
387 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
388 if (retval
!= (const char *) NULL
)
390 /* We permit a duplication of the mfdec instruction on
391 the 601, because it seems to have one value on the
392 601 and a different value on other PowerPC
393 processors. It's easier to permit a duplication than
394 to define a new instruction type flag. When using
395 -many, the comparison instructions are a harmless
397 if (strcmp (retval
, "exists") != 0
398 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
399 || strcmp (op
->name
, "mfdec") != 0)
400 && (ppc_cpu
!= (PPC_OPCODE_POWER
403 || (strcmp (op
->name
, "cmpli") != 0
404 && strcmp (op
->name
, "cmpi") != 0
405 && strcmp (op
->name
, "cmp") != 0
406 && strcmp (op
->name
, "cmpl") != 0))))
412 /* Insert the macros into a hash table. */
413 ppc_macro_hash
= hash_new ();
415 macro_end
= powerpc_macros
+ powerpc_num_macros
;
416 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
418 if ((macro
->flags
& ppc_cpu
) != 0)
422 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
423 if (retval
!= (const char *) NULL
)
428 /* Tell the main code what the endianness is. */
429 target_big_endian
= ppc_big_endian
;
432 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
434 /* Create dummy symbols to serve as initial csects. This forces the
435 text csects to precede the data csects. These symbols will not
437 ppc_text_csects
= symbol_make ("dummy\001");
438 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
439 ppc_data_csects
= symbol_make ("dummy\001");
440 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
444 /* Insert an operand value into an instruction. */
447 ppc_insert_operand (insn
, operand
, val
, file
, line
)
449 const struct powerpc_operand
*operand
;
454 if (operand
->bits
!= 32)
459 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
461 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
462 && ppc_size
== PPC_OPCODE_32
)
463 max
= (1 << operand
->bits
) - 1;
465 max
= (1 << (operand
->bits
- 1)) - 1;
466 min
= - (1 << (operand
->bits
- 1));
470 max
= (1 << operand
->bits
) - 1;
474 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
479 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
482 "operand out of range (%s not between %ld and %ld)";
485 sprint_value (buf
, test
);
486 if (file
== (char *) NULL
)
487 as_warn (err
, buf
, min
, max
);
489 as_warn_where (file
, line
, err
, buf
, min
, max
);
498 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
499 if (errmsg
!= (const char *) NULL
)
503 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
510 /* Parse @got, etc. and return the desired relocation. */
511 static bfd_reloc_code_real_type
512 ppc_elf_suffix (str_p
)
518 return BFD_RELOC_UNUSED
;
520 if (strncmp (str
, "@GOT", 4) == 0 || strncmp (str
, "@got", 4) == 0)
523 return BFD_RELOC_PPC_TOC16
;
525 else if (strncmp (str
, "@L", 2) == 0 || strncmp (str
, "@l", 2) == 0)
528 return BFD_RELOC_LO16
;
530 else if (strncmp (str
, "@HA", 3) == 0 || strncmp (str
, "@ha", 3) == 0)
533 return BFD_RELOC_HI16_S
;
535 else if (strncmp (str
, "@H", 2) == 0 || strncmp (str
, "@h", 2) == 0)
538 return BFD_RELOC_HI16
;
541 return BFD_RELOC_UNUSED
;
544 /* Like normal .long/.short/.word, except support @got, etc. */
545 /* clobbers input_line_pointer, checks */
548 ppc_elf_cons (nbytes
)
549 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
552 bfd_reloc_code_real_type reloc
;
554 if (is_it_end_of_statement ())
556 demand_empty_rest_of_line ();
564 && exp
.X_op
== O_symbol
565 && *input_line_pointer
== '@'
566 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
568 register char *p
= frag_more ((int) nbytes
);
569 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
570 int offset
= (!reloc_howto
) ? 0 : (nbytes
- bfd_get_reloc_size (reloc_howto
));
575 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, (int) nbytes
- offset
, &exp
, 0, reloc
);
578 emit_expr (&exp
, (unsigned int) nbytes
);
580 while (*input_line_pointer
++ == ',');
582 input_line_pointer
--; /* Put terminator back into stream. */
583 demand_empty_rest_of_line ();
586 /* Validate any relocations emitted for -mrelocatable */
588 ppc_elf_validate_fix (fixS
*fixp
, segT seg
)
593 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
594 && strcmp (segment_name (seg
), ".got2") != 0
595 && strcmp (segment_name (seg
), ".stab") != 0)
597 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
598 "Relocation cannot be done when using -mrelocatable");
604 /* We need to keep a list of fixups. We can't simply generate them as
605 we go, because that would require us to first create the frag, and
606 that would screw up references to ``.''. */
612 bfd_reloc_code_real_type reloc
;
615 #define MAX_INSN_FIXUPS (5)
617 /* This routine is called for each instruction to be assembled. */
624 const struct powerpc_opcode
*opcode
;
626 const unsigned char *opindex_ptr
;
630 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
634 bfd_reloc_code_real_type reloc
;
636 /* Get the opcode. */
637 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
642 /* Look up the opcode in the hash table. */
643 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
644 if (opcode
== (const struct powerpc_opcode
*) NULL
)
646 const struct powerpc_macro
*macro
;
648 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
649 if (macro
== (const struct powerpc_macro
*) NULL
)
650 as_bad ("Unrecognized opcode: `%s'", str
);
652 ppc_macro (s
, macro
);
657 insn
= opcode
->opcode
;
660 while (isspace (*str
))
663 /* PowerPC operands are just expressions. The only real issue is
664 that a few operand types are optional. All cases which might use
665 an optional operand separate the operands only with commas (in
666 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
667 cases never have optional operands). There is never more than
668 one optional operand for an instruction. So, before we start
669 seriously parsing the operands, we check to see if we have an
670 optional operand, and, if we do, we count the number of commas to
671 see whether the operand should be omitted. */
673 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
675 const struct powerpc_operand
*operand
;
677 operand
= &powerpc_operands
[*opindex_ptr
];
678 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
680 unsigned int opcount
;
682 /* There is an optional operand. Count the number of
683 commas in the input line. */
690 while ((s
= strchr (s
, ',')) != (char *) NULL
)
697 /* If there are fewer operands in the line then are called
698 for by the instruction, we want to skip the optional
700 if (opcount
< strlen (opcode
->operands
))
707 /* Gather the operands. */
711 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
713 const struct powerpc_operand
*operand
;
719 if (next_opindex
== 0)
720 operand
= &powerpc_operands
[*opindex_ptr
];
723 operand
= &powerpc_operands
[next_opindex
];
729 /* If this is a fake operand, then we do not expect anything
731 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
733 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
734 if (errmsg
!= (const char *) NULL
)
739 /* If this is an optional operand, and we are skipping it, just
741 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
746 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
747 if (errmsg
!= (const char *) NULL
)
750 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
751 next_opindex
= *opindex_ptr
+ 1;
755 /* Gather the operand. */
756 hold
= input_line_pointer
;
757 input_line_pointer
= str
;
759 str
= input_line_pointer
;
760 input_line_pointer
= hold
;
762 if (ex
.X_op
== O_illegal
)
763 as_bad ("illegal operand");
764 else if (ex
.X_op
== O_absent
)
765 as_bad ("missing operand");
766 else if (ex
.X_op
== O_constant
)
767 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
771 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
773 /* We need to generate a fixup for this expression. */
774 if (fc
>= MAX_INSN_FIXUPS
)
775 as_fatal ("too many fixups");
777 fixups
[fc
].opindex
= 0;
778 fixups
[fc
].reloc
= reloc
;
785 /* We need to generate a fixup for this expression. */
786 if (fc
>= MAX_INSN_FIXUPS
)
787 as_fatal ("too many fixups");
789 fixups
[fc
].opindex
= *opindex_ptr
;
790 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
799 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
807 /* The call to expression should have advanced str past any
810 && (endc
!= ',' || *str
!= '\0'))
812 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
820 while (isspace (*str
))
824 as_bad ("junk at end of line: `%s'", str
);
826 /* Write out the instruction. */
828 md_number_to_chars (f
, insn
, 4);
830 /* Create any fixups. At this point we do not use a
831 bfd_reloc_code_real_type, but instead just use the operand index.
832 This lets us easily handle fixups for any operand type, although
833 that is admittedly not a very exciting feature. We pick a BFD
834 reloc type in md_apply_fix. */
835 for (i
= 0; i
< fc
; i
++)
837 const struct powerpc_operand
*operand
;
839 operand
= &powerpc_operands
[fixups
[i
].opindex
];
840 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
842 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
843 int offset
= (!reloc_howto
) ? 0 : (4 - bfd_get_reloc_size (reloc_howto
));
848 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, 4 - offset
,
849 &fixups
[i
].exp
, (reloc_howto
&& reloc_howto
->pc_relative
),
853 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
855 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
856 ((bfd_reloc_code_real_type
)
857 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
861 #ifndef WORKING_DOT_WORD
862 /* Handle long and short jumps */
864 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
866 addressT from_addr
, to_addr
;
874 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
876 addressT from_addr
, to_addr
;
884 /* Handle a macro. Gather all the operands, transform them as
885 described by the macro, and call md_assemble recursively. All the
886 operands are separated by commas; we don't accept parentheses
887 around operands here. */
890 ppc_macro (str
, macro
)
892 const struct powerpc_macro
*macro
;
903 /* Gather the users operands into the operands array. */
908 if (count
>= sizeof operands
/ sizeof operands
[0])
910 operands
[count
++] = s
;
912 if (s
== (char *) NULL
)
917 if (count
!= macro
->operands
)
919 as_bad ("wrong number of operands");
923 /* Work out how large the string must be (the size is unbounded
924 because it includes user input). */
926 format
= macro
->format
;
927 while (*format
!= '\0')
936 arg
= strtol (format
+ 1, &send
, 10);
937 know (send
!= format
&& arg
>= 0 && arg
< count
);
938 len
+= strlen (operands
[arg
]);
943 /* Put the string together. */
944 complete
= s
= (char *) alloca (len
+ 1);
945 format
= macro
->format
;
946 while (*format
!= '\0')
952 arg
= strtol (format
+ 1, &send
, 10);
953 strcpy (s
, operands
[arg
]);
960 /* Assemble the constructed instruction. */
961 md_assemble (complete
);
964 /* Pseudo-op handling. */
966 /* The .byte pseudo-op. This is similar to the normal .byte
967 pseudo-op, but it can also take a single ASCII string. */
973 if (*input_line_pointer
!= '\"')
979 /* Gather characters. A real double quote is doubled. Unusual
980 characters are not permitted. */
981 ++input_line_pointer
;
986 c
= *input_line_pointer
++;
990 if (*input_line_pointer
!= '\"')
992 ++input_line_pointer
;
995 FRAG_APPEND_1_CHAR (c
);
998 demand_empty_rest_of_line ();
1003 /* XCOFF specific pseudo-op handling. */
1005 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1006 symbols in the .bss segment as though they were local common
1007 symbols, and uses a different smclas. */
1013 asection
*current_seg
= now_seg
;
1014 subsegT current_subseg
= now_subseg
;
1020 symbolS
*lcomm_sym
= NULL
;
1024 name
= input_line_pointer
;
1025 endc
= get_symbol_end ();
1026 end_name
= input_line_pointer
;
1029 if (*input_line_pointer
!= ',')
1031 as_bad ("missing size");
1032 ignore_rest_of_line ();
1035 ++input_line_pointer
;
1037 size
= get_absolute_expression ();
1040 as_bad ("negative size");
1041 ignore_rest_of_line ();
1047 /* The third argument to .comm is the alignment. */
1048 if (*input_line_pointer
!= ',')
1052 ++input_line_pointer
;
1053 align
= get_absolute_expression ();
1056 as_warn ("ignoring bad alignment");
1075 /* The third argument to .lcomm appears to be the real local
1076 common symbol to create. References to the symbol named in
1077 the first argument are turned into references to the third
1079 if (*input_line_pointer
!= ',')
1081 as_bad ("missing real symbol name");
1082 ignore_rest_of_line ();
1085 ++input_line_pointer
;
1087 lcomm_name
= input_line_pointer
;
1088 lcomm_endc
= get_symbol_end ();
1090 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1092 *input_line_pointer
= lcomm_endc
;
1096 sym
= symbol_find_or_make (name
);
1099 if (S_IS_DEFINED (sym
)
1100 || S_GET_VALUE (sym
) != 0)
1102 as_bad ("attempt to redefine symbol");
1103 ignore_rest_of_line ();
1107 record_alignment (bss_section
, align
);
1110 || ! S_IS_DEFINED (lcomm_sym
))
1119 S_SET_EXTERNAL (sym
);
1123 lcomm_sym
->sy_tc
.output
= 1;
1124 def_sym
= lcomm_sym
;
1128 subseg_set (bss_section
, 1);
1129 frag_align (align
, 0);
1131 def_sym
->sy_frag
= frag_now
;
1132 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1133 def_size
, (char *) NULL
);
1135 S_SET_SEGMENT (def_sym
, bss_section
);
1136 def_sym
->sy_tc
.align
= align
;
1140 /* Align the size of lcomm_sym. */
1141 lcomm_sym
->sy_frag
->fr_offset
=
1142 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1143 &~ ((1 << align
) - 1));
1144 if (align
> lcomm_sym
->sy_tc
.align
)
1145 lcomm_sym
->sy_tc
.align
= align
;
1150 /* Make sym an offset from lcomm_sym. */
1151 S_SET_SEGMENT (sym
, bss_section
);
1152 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1153 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1154 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1157 subseg_set (current_seg
, current_subseg
);
1159 demand_empty_rest_of_line ();
1162 /* The .csect pseudo-op. This switches us into a different
1163 subsegment. The first argument is a symbol whose value is the
1164 start of the .csect. In COFF, csect symbols get special aux
1165 entries defined by the x_csect field of union internal_auxent. The
1166 optional second argument is the alignment (the default is 2). */
1176 name
= input_line_pointer
;
1177 endc
= get_symbol_end ();
1179 sym
= symbol_find_or_make (name
);
1181 *input_line_pointer
= endc
;
1183 if (S_IS_DEFINED (sym
))
1184 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1191 /* This is a new csect. We need to look at the symbol class to
1192 figure out whether it should go in the text section or the
1195 switch (sym
->sy_tc
.class)
1205 S_SET_SEGMENT (sym
, text_section
);
1206 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1207 ++ppc_text_subsegment
;
1208 list_ptr
= &ppc_text_csects
;
1217 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1219 S_SET_SEGMENT (sym
, data_section
);
1220 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1221 ++ppc_data_subsegment
;
1222 list_ptr
= &ppc_data_csects
;
1228 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1230 ppc_after_toc_frag
= frag_now
;
1232 sym
->sy_frag
= frag_now
;
1233 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1235 sym
->sy_tc
.align
= 2;
1236 sym
->sy_tc
.output
= 1;
1237 sym
->sy_tc
.within
= sym
;
1239 for (list
= *list_ptr
;
1240 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1241 list
= list
->sy_tc
.next
)
1243 list
->sy_tc
.next
= sym
;
1245 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1246 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1249 if (*input_line_pointer
== ',')
1251 ++input_line_pointer
;
1252 sym
->sy_tc
.align
= get_absolute_expression ();
1255 ppc_current_csect
= sym
;
1257 demand_empty_rest_of_line ();
1260 /* The .extern pseudo-op. We create an undefined symbol. */
1269 name
= input_line_pointer
;
1270 endc
= get_symbol_end ();
1272 (void) symbol_find_or_make (name
);
1274 *input_line_pointer
= endc
;
1276 demand_empty_rest_of_line ();
1279 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1280 this because it can't handle undefined symbols. I think we can
1290 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1291 although I don't know why it bothers. */
1302 name
= input_line_pointer
;
1303 endc
= get_symbol_end ();
1305 sym
= symbol_find_or_make (name
);
1307 *input_line_pointer
= endc
;
1309 if (*input_line_pointer
!= ',')
1311 as_bad ("missing rename string");
1312 ignore_rest_of_line ();
1315 ++input_line_pointer
;
1317 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1319 demand_empty_rest_of_line ();
1322 /* The .stabx pseudo-op. This is similar to a normal .stabs
1323 pseudo-op, but slightly different. A sample is
1324 .stabx "main:F-1",.main,142,0
1325 The first argument is the symbol name to create. The second is the
1326 value, and the third is the storage class. The fourth seems to be
1327 always zero, and I am assuming it is the type. */
1338 name
= demand_copy_C_string (&len
);
1340 if (*input_line_pointer
!= ',')
1342 as_bad ("missing value");
1345 ++input_line_pointer
;
1347 sym
= symbol_make (name
);
1349 (void) expression (&exp
);
1356 as_bad ("illegal .stabx expression; zero assumed");
1357 exp
.X_add_number
= 0;
1360 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1361 sym
->sy_frag
= &zero_address_frag
;
1365 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1366 sym
->sy_value
= exp
;
1370 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1371 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1376 /* The value is some complex expression. This will probably
1377 fail at some later point, but this is probably the right
1378 thing to do here. */
1379 sym
->sy_value
= exp
;
1383 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1384 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1386 if (*input_line_pointer
!= ',')
1388 as_bad ("missing class");
1391 ++input_line_pointer
;
1393 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1395 if (*input_line_pointer
!= ',')
1397 as_bad ("missing type");
1400 ++input_line_pointer
;
1402 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1404 sym
->sy_tc
.output
= 1;
1406 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1407 sym
->sy_tc
.within
= ppc_current_block
;
1409 if (exp
.X_op
!= O_symbol
1410 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1411 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1412 ppc_frob_label (sym
);
1415 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1416 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1417 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1418 ppc_current_csect
->sy_tc
.within
= sym
;
1421 if (strlen (name
) > SYMNMLEN
)
1423 /* For some reason, each name is preceded by a two byte length
1424 and followed by a null byte. */
1425 ppc_debug_name_section_size
+= strlen (name
) + 3;
1428 demand_empty_rest_of_line ();
1431 /* The .function pseudo-op. This takes several arguments. The first
1432 argument seems to be the external name of the symbol. The second
1433 argment seems to be the label for the start of the function. gcc
1434 uses the same name for both. I have no idea what the third and
1435 fourth arguments are meant to be. The optional fifth argument is
1436 an expression for the size of the function. In COFF this symbol
1437 gets an aux entry like that used for a csect. */
1440 ppc_function (ignore
)
1449 name
= input_line_pointer
;
1450 endc
= get_symbol_end ();
1452 /* Ignore any [PR] suffix. */
1453 name
= ppc_canonicalize_symbol_name (name
);
1454 s
= strchr (name
, '[');
1455 if (s
!= (char *) NULL
1456 && strcmp (s
+ 1, "PR]") == 0)
1459 ext_sym
= symbol_find_or_make (name
);
1461 *input_line_pointer
= endc
;
1463 if (*input_line_pointer
!= ',')
1465 as_bad ("missing symbol name");
1466 ignore_rest_of_line ();
1469 ++input_line_pointer
;
1471 name
= input_line_pointer
;
1472 endc
= get_symbol_end ();
1474 lab_sym
= symbol_find_or_make (name
);
1476 *input_line_pointer
= endc
;
1478 if (ext_sym
!= lab_sym
)
1480 ext_sym
->sy_value
.X_op
= O_symbol
;
1481 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1482 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1483 ext_sym
->sy_value
.X_add_number
= 0;
1486 if (ext_sym
->sy_tc
.class == -1)
1487 ext_sym
->sy_tc
.class = XMC_PR
;
1488 ext_sym
->sy_tc
.output
= 1;
1490 if (*input_line_pointer
== ',')
1494 /* Ignore the third argument. */
1495 ++input_line_pointer
;
1496 expression (&ignore
);
1497 if (*input_line_pointer
== ',')
1499 /* Ignore the fourth argument. */
1500 ++input_line_pointer
;
1501 expression (&ignore
);
1502 if (*input_line_pointer
== ',')
1504 /* The fifth argument is the function size. */
1505 ++input_line_pointer
;
1506 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
1509 &zero_address_frag
);
1510 pseudo_set (ext_sym
->sy_tc
.size
);
1515 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
1516 SF_SET_FUNCTION (ext_sym
);
1517 SF_SET_PROCESS (ext_sym
);
1518 coff_add_linesym (ext_sym
);
1520 demand_empty_rest_of_line ();
1523 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
1532 sym
= symbol_make (".bf");
1533 S_SET_SEGMENT (sym
, text_section
);
1534 sym
->sy_frag
= frag_now
;
1535 S_SET_VALUE (sym
, frag_now_fix ());
1536 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1538 coff_line_base
= get_absolute_expression ();
1540 S_SET_NUMBER_AUXILIARY (sym
, 1);
1541 SA_SET_SYM_LNNO (sym
, coff_line_base
);
1543 sym
->sy_tc
.output
= 1;
1545 ppc_frob_label (sym
);
1547 demand_empty_rest_of_line ();
1550 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
1551 ".ef", except that the line number is absolute, not relative to the
1552 most recent ".bf" symbol. */
1560 sym
= symbol_make (".ef");
1561 S_SET_SEGMENT (sym
, text_section
);
1562 sym
->sy_frag
= frag_now
;
1563 S_SET_VALUE (sym
, frag_now_fix ());
1564 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1565 S_SET_NUMBER_AUXILIARY (sym
, 1);
1566 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1567 sym
->sy_tc
.output
= 1;
1569 ppc_frob_label (sym
);
1571 demand_empty_rest_of_line ();
1574 /* The .bi and .ei pseudo-ops. These take a string argument and
1575 generates a C_BINCL or C_EINCL symbol, which goes at the start of
1587 name
= demand_copy_C_string (&len
);
1589 sym
= symbol_make (name
);
1590 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1591 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1593 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
1594 offset in the file to the line number entry to use. That is
1595 quite difficult to implement using BFD, so I'm just not doing it.
1596 Sorry. Please add it if you can figure out how. Note that this
1597 approach is the only way to support multiple files in COFF, since
1598 line numbers are associated with function symbols. Note further
1599 that it still doesn't work, since the line numbers are stored as
1600 offsets from a base line number. */
1602 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
1603 sym
->sy_tc
.output
= 1;
1605 for (look
= symbol_rootP
;
1606 (look
!= (symbolS
*) NULL
1607 && (S_GET_STORAGE_CLASS (look
) == C_FILE
1608 || S_GET_STORAGE_CLASS (look
) == C_BINCL
1609 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
1610 look
= symbol_next (look
))
1612 if (look
!= (symbolS
*) NULL
)
1614 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1615 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
1618 demand_empty_rest_of_line ();
1621 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
1622 There is one argument, which is a csect symbol. The value of the
1623 .bs symbol is the index of this csect symbol. */
1634 if (ppc_current_block
!= NULL
)
1635 as_bad ("nested .bs blocks");
1637 name
= input_line_pointer
;
1638 endc
= get_symbol_end ();
1640 csect
= symbol_find_or_make (name
);
1642 *input_line_pointer
= endc
;
1644 sym
= symbol_make (".bs");
1645 S_SET_SEGMENT (sym
, now_seg
);
1646 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
1647 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1648 sym
->sy_tc
.output
= 1;
1650 sym
->sy_tc
.within
= csect
;
1652 ppc_frob_label (sym
);
1654 ppc_current_block
= sym
;
1656 demand_empty_rest_of_line ();
1659 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
1667 if (ppc_current_block
== NULL
)
1668 as_bad (".es without preceding .bs");
1670 sym
= symbol_make (".es");
1671 S_SET_SEGMENT (sym
, now_seg
);
1672 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
1673 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1674 sym
->sy_tc
.output
= 1;
1676 ppc_frob_label (sym
);
1678 ppc_current_block
= NULL
;
1680 demand_empty_rest_of_line ();
1683 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
1692 sym
= symbol_make (".bb");
1693 S_SET_SEGMENT (sym
, text_section
);
1694 sym
->sy_frag
= frag_now
;
1695 S_SET_VALUE (sym
, frag_now_fix ());
1696 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
1698 S_SET_NUMBER_AUXILIARY (sym
, 1);
1699 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1701 sym
->sy_tc
.output
= 1;
1703 ppc_frob_label (sym
);
1705 demand_empty_rest_of_line ();
1708 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
1717 sym
= symbol_make (".eb");
1718 S_SET_SEGMENT (sym
, text_section
);
1719 sym
->sy_frag
= frag_now
;
1720 S_SET_VALUE (sym
, frag_now_fix ());
1721 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1722 S_SET_NUMBER_AUXILIARY (sym
, 1);
1723 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1724 sym
->sy_tc
.output
= 1;
1726 ppc_frob_label (sym
);
1728 demand_empty_rest_of_line ();
1731 /* The .toc pseudo-op. Switch to the .toc subsegment. */
1737 if (ppc_toc_csect
!= (symbolS
*) NULL
)
1738 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
1745 subseg
= ppc_data_subsegment
;
1746 ++ppc_data_subsegment
;
1748 subseg_new (segment_name (data_section
), subseg
);
1749 ppc_toc_frag
= frag_now
;
1751 sym
= symbol_find_or_make ("TOC[TC0]");
1752 sym
->sy_frag
= frag_now
;
1753 S_SET_SEGMENT (sym
, data_section
);
1754 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1755 sym
->sy_tc
.subseg
= subseg
;
1756 sym
->sy_tc
.output
= 1;
1757 sym
->sy_tc
.within
= sym
;
1759 ppc_toc_csect
= sym
;
1761 for (list
= ppc_data_csects
;
1762 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1763 list
= list
->sy_tc
.next
)
1765 list
->sy_tc
.next
= sym
;
1767 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1768 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1771 ppc_current_csect
= ppc_toc_csect
;
1773 demand_empty_rest_of_line ();
1776 #endif /* OBJ_COFF */
1778 /* The .tc pseudo-op. This is used when generating either XCOFF or
1779 ELF. This takes two or more arguments.
1781 When generating XCOFF output, the first argument is the name to
1782 give to this location in the toc; this will be a symbol with class
1783 TC. The rest of the arguments are 4 byte values to actually put at
1784 this location in the TOC; often there is just one more argument, a
1785 relocateable symbol reference.
1787 When not generating XCOFF output, the arguments are the same, but
1788 the first argument is simply ignored. */
1796 /* Define the TOC symbol name. */
1802 if (ppc_toc_csect
== (symbolS
*) NULL
1803 || ppc_toc_csect
!= ppc_current_csect
)
1805 as_bad (".tc not in .toc section");
1806 ignore_rest_of_line ();
1810 name
= input_line_pointer
;
1811 endc
= get_symbol_end ();
1813 sym
= symbol_find_or_make (name
);
1815 *input_line_pointer
= endc
;
1817 if (S_IS_DEFINED (sym
))
1821 label
= ppc_current_csect
->sy_tc
.within
;
1822 if (label
->sy_tc
.class != XMC_TC0
)
1824 as_warn (".tc with no label");
1825 ignore_rest_of_line ();
1829 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
1830 label
->sy_frag
= sym
->sy_frag
;
1831 S_SET_VALUE (label
, S_GET_VALUE (sym
));
1833 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1834 ++input_line_pointer
;
1839 S_SET_SEGMENT (sym
, now_seg
);
1840 sym
->sy_frag
= frag_now
;
1841 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1842 sym
->sy_tc
.class = XMC_TC
;
1843 sym
->sy_tc
.output
= 1;
1845 ppc_frob_label (sym
);
1848 #else /* ! defined (OBJ_COFF) */
1850 /* Skip the TOC symbol name. */
1851 while (is_part_of_name (*input_line_pointer
)
1852 || *input_line_pointer
== '['
1853 || *input_line_pointer
== ']'
1854 || *input_line_pointer
== '{'
1855 || *input_line_pointer
== '}')
1856 ++input_line_pointer
;
1858 /* Align to a four byte boundary. */
1860 record_alignment (now_seg
, 2);
1862 #endif /* ! defined (OBJ_COFF) */
1864 if (*input_line_pointer
!= ',')
1865 demand_empty_rest_of_line ();
1868 ++input_line_pointer
;
1875 /* XCOFF specific symbol and file handling. */
1877 /* Canonicalize the symbol name. We use the to force the suffix, if
1878 any, to use square brackets, and to be in upper case. */
1881 ppc_canonicalize_symbol_name (name
)
1886 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
1900 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
1904 if (*s
== '\0' || s
[1] != '\0')
1905 as_bad ("bad symbol suffix");
1913 /* Set the class of a symbol based on the suffix, if any. This is
1914 called whenever a new symbol is created. */
1917 ppc_symbol_new_hook (sym
)
1922 sym
->sy_tc
.next
= NULL
;
1923 sym
->sy_tc
.output
= 0;
1924 sym
->sy_tc
.class = -1;
1925 sym
->sy_tc
.real_name
= NULL
;
1926 sym
->sy_tc
.subseg
= 0;
1927 sym
->sy_tc
.align
= 0;
1928 sym
->sy_tc
.size
= NULL
;
1929 sym
->sy_tc
.within
= NULL
;
1931 s
= strchr (S_GET_NAME (sym
), '[');
1932 if (s
== (const char *) NULL
)
1934 /* There is no suffix. */
1943 if (strcmp (s
, "BS]") == 0)
1944 sym
->sy_tc
.class = XMC_BS
;
1947 if (strcmp (s
, "DB]") == 0)
1948 sym
->sy_tc
.class = XMC_DB
;
1949 else if (strcmp (s
, "DS]") == 0)
1950 sym
->sy_tc
.class = XMC_DS
;
1953 if (strcmp (s
, "GL]") == 0)
1954 sym
->sy_tc
.class = XMC_GL
;
1957 if (strcmp (s
, "PR]") == 0)
1958 sym
->sy_tc
.class = XMC_PR
;
1961 if (strcmp (s
, "RO]") == 0)
1962 sym
->sy_tc
.class = XMC_RO
;
1963 else if (strcmp (s
, "RW]") == 0)
1964 sym
->sy_tc
.class = XMC_RW
;
1967 if (strcmp (s
, "SV]") == 0)
1968 sym
->sy_tc
.class = XMC_SV
;
1971 if (strcmp (s
, "TC]") == 0)
1972 sym
->sy_tc
.class = XMC_TC
;
1973 else if (strcmp (s
, "TI]") == 0)
1974 sym
->sy_tc
.class = XMC_TI
;
1975 else if (strcmp (s
, "TB]") == 0)
1976 sym
->sy_tc
.class = XMC_TB
;
1977 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
1978 sym
->sy_tc
.class = XMC_TC0
;
1981 if (strcmp (s
, "UA]") == 0)
1982 sym
->sy_tc
.class = XMC_UA
;
1983 else if (strcmp (s
, "UC]") == 0)
1984 sym
->sy_tc
.class = XMC_UC
;
1987 if (strcmp (s
, "XO]") == 0)
1988 sym
->sy_tc
.class = XMC_XO
;
1992 if (sym
->sy_tc
.class == -1)
1993 as_bad ("Unrecognized symbol suffix");
1996 /* Set the class of a label based on where it is defined. This
1997 handles symbols without suffixes. Also, move the symbol so that it
1998 follows the csect symbol. */
2001 ppc_frob_label (sym
)
2004 if (ppc_current_csect
!= (symbolS
*) NULL
)
2006 if (sym
->sy_tc
.class == -1)
2007 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
2009 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2010 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
2012 ppc_current_csect
->sy_tc
.within
= sym
;
2016 /* Change the name of a symbol just before writing it out. Set the
2017 real name if the .rename pseudo-op was used. Otherwise, remove any
2018 class suffix. Return 1 if the symbol should not be included in the
2022 ppc_frob_symbol (sym
)
2025 static symbolS
*ppc_last_function
;
2026 static symbolS
*set_end
;
2028 /* Discard symbols that should not be included in the output symbol
2030 if (! sym
->sy_used_in_reloc
2031 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
2032 || (! S_IS_EXTERNAL (sym
)
2033 && ! sym
->sy_tc
.output
2034 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
2037 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
2038 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
2044 name
= S_GET_NAME (sym
);
2045 s
= strchr (name
, '[');
2046 if (s
!= (char *) NULL
)
2052 snew
= xmalloc (len
+ 1);
2053 memcpy (snew
, name
, len
);
2056 S_SET_NAME (sym
, snew
);
2060 if (set_end
!= (symbolS
*) NULL
)
2062 SA_SET_SYM_ENDNDX (set_end
, sym
);
2066 if (SF_GET_FUNCTION (sym
))
2068 if (ppc_last_function
!= (symbolS
*) NULL
)
2069 as_warn ("two .function pseudo-ops with no intervening .ef");
2070 ppc_last_function
= sym
;
2071 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
2073 resolve_symbol_value (sym
->sy_tc
.size
);
2074 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
2077 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
2078 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
2080 if (ppc_last_function
== (symbolS
*) NULL
)
2081 as_warn (".ef with no preceding .function");
2084 set_end
= ppc_last_function
;
2085 ppc_last_function
= NULL
;
2087 /* We don't have a C_EFCN symbol, but we need to force the
2088 COFF backend to believe that it has seen one. */
2089 coff_last_function
= NULL
;
2093 if (! S_IS_EXTERNAL (sym
)
2094 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
2095 && S_GET_STORAGE_CLASS (sym
) != C_FILE
2096 && S_GET_STORAGE_CLASS (sym
) != C_FCN
2097 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
2098 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
2099 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
2100 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
2102 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
2103 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
2106 union internal_auxent
*a
;
2108 /* Create a csect aux. */
2109 i
= S_GET_NUMBER_AUXILIARY (sym
);
2110 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
2111 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
2112 if (sym
->sy_tc
.class == XMC_TC0
)
2114 /* This is the TOC table. */
2115 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
2116 a
->x_csect
.x_scnlen
.l
= 0;
2117 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2119 else if (sym
->sy_tc
.subseg
!= 0)
2121 /* This is a csect symbol. x_scnlen is the size of the
2123 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
2124 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2125 S_GET_SEGMENT (sym
))
2126 - S_GET_VALUE (sym
));
2129 resolve_symbol_value (sym
->sy_tc
.next
);
2130 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
2131 - S_GET_VALUE (sym
));
2133 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
2135 else if (S_GET_SEGMENT (sym
) == bss_section
)
2137 /* This is a common symbol. */
2138 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
2139 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
2140 if (S_IS_EXTERNAL (sym
))
2141 sym
->sy_tc
.class = XMC_RW
;
2143 sym
->sy_tc
.class = XMC_BS
;
2145 else if (! S_IS_DEFINED (sym
))
2147 /* This is an external symbol. */
2148 a
->x_csect
.x_scnlen
.l
= 0;
2149 a
->x_csect
.x_smtyp
= XTY_ER
;
2151 else if (sym
->sy_tc
.class == XMC_TC
)
2155 /* This is a TOC definition. x_scnlen is the size of the
2157 next
= symbol_next (sym
);
2158 while (next
->sy_tc
.class == XMC_TC0
)
2159 next
= symbol_next (next
);
2160 if (next
== (symbolS
*) NULL
2161 || next
->sy_tc
.class != XMC_TC
)
2163 if (ppc_after_toc_frag
== (fragS
*) NULL
)
2164 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2166 - S_GET_VALUE (sym
));
2168 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
2169 - S_GET_VALUE (sym
));
2173 resolve_symbol_value (next
);
2174 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
2175 - S_GET_VALUE (sym
));
2177 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2183 /* This is a normal symbol definition. x_scnlen is the
2184 symbol index of the containing csect. */
2185 if (S_GET_SEGMENT (sym
) == text_section
)
2186 csect
= ppc_text_csects
;
2187 else if (S_GET_SEGMENT (sym
) == data_section
)
2188 csect
= ppc_data_csects
;
2192 /* Skip the initial dummy symbol. */
2193 csect
= csect
->sy_tc
.next
;
2195 if (csect
== (symbolS
*) NULL
)
2196 a
->x_csect
.x_scnlen
.l
= 0;
2199 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
2201 resolve_symbol_value (csect
->sy_tc
.next
);
2202 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
2204 csect
= csect
->sy_tc
.next
;
2207 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
2208 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
2210 a
->x_csect
.x_smtyp
= XTY_LD
;
2213 a
->x_csect
.x_parmhash
= 0;
2214 a
->x_csect
.x_snhash
= 0;
2215 if (sym
->sy_tc
.class == -1)
2216 a
->x_csect
.x_smclas
= XMC_PR
;
2218 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
2219 a
->x_csect
.x_stab
= 0;
2220 a
->x_csect
.x_snstab
= 0;
2222 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
2224 /* We want the value to be the symbol index of the referenced
2225 csect symbol. BFD will do that for us if we set the right
2228 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
2229 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
2231 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2236 /* The value is the offset from the enclosing csect. */
2237 block
= sym
->sy_tc
.within
;
2238 csect
= block
->sy_tc
.within
;
2239 resolve_symbol_value (csect
);
2240 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
2246 /* Set the VMA for a section. This is called on all the sections in
2250 ppc_frob_section (sec
)
2253 static bfd_size_type vma
= 0;
2255 bfd_set_section_vma (stdoutput
, sec
, vma
);
2256 vma
+= bfd_section_size (stdoutput
, sec
);
2259 /* Adjust the file by adding a .debug section if needed. */
2264 if (ppc_debug_name_section_size
> 0)
2268 sec
= bfd_make_section (stdoutput
, ".debug");
2269 if (sec
== (asection
*) NULL
2270 || ! bfd_set_section_size (stdoutput
, sec
,
2271 ppc_debug_name_section_size
)
2272 || ! bfd_set_section_flags (stdoutput
, sec
,
2273 SEC_HAS_CONTENTS
| SEC_LOAD
))
2274 as_fatal ("can't make .debug section");
2278 #endif /* OBJ_COFF */
2280 /* Turn a string in input_line_pointer into a floating point constant
2281 of type type, and store the appropriate bytes in *litp. The number
2282 of LITTLENUMS emitted is stored in *sizep . An error message is
2283 returned, or NULL on OK. */
2286 md_atof (type
, litp
, sizep
)
2292 LITTLENUM_TYPE words
[4];
2308 return "bad call to md_atof";
2311 t
= atof_ieee (input_line_pointer
, type
, words
);
2313 input_line_pointer
= t
;
2319 for (i
= 0; i
< prec
; i
++)
2321 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2327 for (i
= prec
- 1; i
>= 0; i
--)
2329 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2337 /* Write a value out to the object file, using the appropriate
2341 md_number_to_chars (buf
, val
, n
)
2347 number_to_chars_bigendian (buf
, val
, n
);
2349 number_to_chars_littleendian (buf
, val
, n
);
2352 /* Align a section (I don't know why this is machine dependent). */
2355 md_section_align (seg
, addr
)
2359 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2361 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
2364 /* We don't have any form of relaxing. */
2367 md_estimate_size_before_relax (fragp
, seg
)
2374 const relax_typeS md_relax_table
[] =
2379 /* Convert a machine dependent frag. We never generate these. */
2382 md_convert_frag (abfd
, sec
, fragp
)
2390 /* We have no need to default values of symbols. */
2394 md_undefined_symbol (name
)
2400 /* Functions concerning relocs. */
2402 /* The location from which a PC relative jump should be calculated,
2403 given a PC relative reloc. */
2406 md_pcrel_from (fixp
)
2410 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2411 && ! S_IS_DEFINED (fixp
->fx_addsy
))
2415 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2420 /* This is called to see whether a fixup should be adjusted to use a
2421 section symbol. We take the opportunity to change a fixup against
2422 a symbol in the TOC subsegment into a reloc against the
2423 corresponding .tc symbol. */
2426 ppc_fix_adjustable (fix
)
2431 resolve_symbol_value (fix
->fx_addsy
);
2432 val
= S_GET_VALUE (fix
->fx_addsy
);
2433 if (ppc_toc_csect
!= (symbolS
*) NULL
2434 && fix
->fx_addsy
!= (symbolS
*) NULL
2435 && fix
->fx_addsy
!= ppc_toc_csect
2436 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
2437 && val
>= ppc_toc_frag
->fr_address
2438 && (ppc_after_toc_frag
== (fragS
*) NULL
2439 || val
< ppc_after_toc_frag
->fr_address
))
2443 for (sy
= symbol_next (ppc_toc_csect
);
2444 sy
!= (symbolS
*) NULL
;
2445 sy
= symbol_next (sy
))
2447 if (sy
->sy_tc
.class == XMC_TC0
)
2449 if (sy
->sy_tc
.class != XMC_TC
)
2451 resolve_symbol_value (sy
);
2452 if (val
== S_GET_VALUE (sy
))
2455 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
2460 as_bad_where (fix
->fx_file
, fix
->fx_line
,
2461 "symbol in .toc does not match any .tc");
2464 /* Possibly adjust the reloc to be against the csect. */
2465 if (fix
->fx_addsy
!= (symbolS
*) NULL
2466 && fix
->fx_addsy
->sy_tc
.subseg
== 0
2467 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
2468 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
2469 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
2473 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
2474 csect
= ppc_text_csects
;
2475 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
2476 csect
= ppc_data_csects
;
2480 /* Skip the initial dummy symbol. */
2481 csect
= csect
->sy_tc
.next
;
2483 if (csect
!= (symbolS
*) NULL
)
2485 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
2486 && (csect
->sy_tc
.next
->sy_frag
->fr_address
2487 <= fix
->fx_addsy
->sy_frag
->fr_address
))
2488 csect
= csect
->sy_tc
.next
;
2490 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2491 - csect
->sy_frag
->fr_address
);
2492 fix
->fx_addsy
= csect
;
2496 /* Adjust a reloc against a .lcomm symbol to be against the base
2498 if (fix
->fx_addsy
!= (symbolS
*) NULL
2499 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
2500 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
2502 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
2503 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2504 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
2505 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
2513 /* See whether a symbol is in the TOC section. */
2516 ppc_is_toc_sym (sym
)
2520 return sym
->sy_tc
.class == XMC_TC
;
2522 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
2526 /* Apply a fixup to the object code. This is called for all the
2527 fixups we generated by the call to fix_new_exp, above. In the call
2528 above we used a reloc code which was the largest legal reloc code
2529 plus the operand index. Here we undo that to recover the operand
2530 index. At this point all symbol values should be fully resolved,
2531 and we attempt to completely resolve the reloc. If we can not do
2532 that, we determine the correct reloc code and put it back in the
2536 md_apply_fix3 (fixp
, valuep
, seg
)
2543 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
2544 the symbol values. Since we are using BFD_ASSEMBLER, if we are
2545 doing this relocation the code in write.c is going to call
2546 bfd_perform_relocation, which is also going to use the symbol
2547 value. That means that if the reloc is fully resolved we want to
2548 use *valuep since bfd_perform_relocation is not being used.
2549 However, if the reloc is not fully resolved we do not want to use
2550 *valuep, and must use fx_offset instead. However, if the reloc
2551 is PC relative, we do want to use *valuep since it includes the
2552 result of md_pcrel_from. This is confusing. */
2554 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2559 else if (fixp
->fx_pcrel
)
2563 value
= fixp
->fx_offset
;
2564 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2566 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2567 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2570 /* We can't actually support subtracting a symbol. */
2571 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2572 "expression too complex");
2577 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2580 const struct powerpc_operand
*operand
;
2584 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2586 operand
= &powerpc_operands
[opindex
];
2589 /* It appears that an instruction like
2591 when LC..1 is not a TOC symbol does not generate a reloc. It
2592 uses the offset of LC..1 within its csect. However, .long
2593 LC..1 will generate a reloc. I can't find any documentation
2594 on how these cases are to be distinguished, so this is a wild
2595 guess. These cases are generated by gcc -mminimal-toc. */
2596 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2597 && operand
->bits
== 16
2598 && operand
->shift
== 0
2599 && operand
->insert
== NULL
2600 && fixp
->fx_addsy
!= NULL
2601 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
2602 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
2603 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
2604 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
2606 value
= fixp
->fx_offset
;
2611 /* Fetch the instruction, insert the fully resolved operand
2612 value, and stuff the instruction back again. */
2613 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2615 insn
= bfd_getb32 ((unsigned char *) where
);
2617 insn
= bfd_getl32 ((unsigned char *) where
);
2618 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
2619 fixp
->fx_file
, fixp
->fx_line
);
2621 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2623 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2627 /* Nothing else to do here. */
2631 /* Determine a BFD reloc value based on the operand information.
2632 We are only prepared to turn a few of the operands into
2634 FIXME: We need to handle the DS field at the very least.
2635 FIXME: Handling 16 bit branches would also be reasonable.
2636 FIXME: Selecting the reloc type is a bit haphazard; perhaps
2637 there should be a new field in the operand table. */
2638 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
2639 && operand
->bits
== 26
2640 && operand
->shift
== 0)
2641 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
2642 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
2643 && operand
->bits
== 26
2644 && operand
->shift
== 0)
2645 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
2646 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2647 && operand
->bits
== 16
2648 && operand
->shift
== 0
2649 && operand
->insert
== NULL
2650 && fixp
->fx_addsy
!= NULL
2651 && ppc_is_toc_sym (fixp
->fx_addsy
))
2655 fixp
->fx_where
+= 2;
2656 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
2660 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2661 "unresolved expression that must be resolved");
2669 ppc_elf_validate_fix (fixp
, seg
);
2671 switch (fixp
->fx_r_type
)
2676 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
2677 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2678 } /* fall through */
2680 case BFD_RELOC_32_PCREL
:
2681 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2684 case BFD_RELOC_LO16
:
2685 case BFD_RELOC_HI16
:
2686 case BFD_RELOC_HI16_S
:
2687 case BFD_RELOC_PPC_TOC16
:
2692 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2700 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2709 fixp
->fx_addnumber
= value
;
2711 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
2712 fixp
->fx_addnumber
= 0;
2715 /* We want to use the offset within the data segment of the
2716 symbol, not the actual VMA of the symbol. */
2717 fixp
->fx_addnumber
=
2718 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
2725 /* Generate a reloc for a fixup. */
2728 tc_gen_reloc (seg
, fixp
)
2734 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2736 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2737 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2738 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2739 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2741 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2742 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
2745 reloc
->addend
= fixp
->fx_addnumber
;