1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "safe-ctype.h"
27 #include "dw2gencfi.h"
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian
;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian
= 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P TRUE
52 #define TARGET_REG_NAMES_P FALSE
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
86 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
88 static bfd_boolean register_name
PARAMS ((expressionS
*));
89 static void ppc_set_cpu
PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
92 offsetT val
, char *file
, unsigned int line
));
93 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
94 static void ppc_byte
PARAMS ((int));
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
98 static void ppc_tc
PARAMS ((int));
99 static void ppc_machine
PARAMS ((int));
103 static void ppc_comm
PARAMS ((int));
104 static void ppc_bb
PARAMS ((int));
105 static void ppc_bc
PARAMS ((int));
106 static void ppc_bf
PARAMS ((int));
107 static void ppc_biei
PARAMS ((int));
108 static void ppc_bs
PARAMS ((int));
109 static void ppc_eb
PARAMS ((int));
110 static void ppc_ec
PARAMS ((int));
111 static void ppc_ef
PARAMS ((int));
112 static void ppc_es
PARAMS ((int));
113 static void ppc_csect
PARAMS ((int));
114 static void ppc_change_csect
PARAMS ((symbolS
*, offsetT
));
115 static void ppc_function
PARAMS ((int));
116 static void ppc_extern
PARAMS ((int));
117 static void ppc_lglobl
PARAMS ((int));
118 static void ppc_section
PARAMS ((int));
119 static void ppc_named_section
PARAMS ((int));
120 static void ppc_stabx
PARAMS ((int));
121 static void ppc_rename
PARAMS ((int));
122 static void ppc_toc
PARAMS ((int));
123 static void ppc_xcoff_cons
PARAMS ((int));
124 static void ppc_vbyte
PARAMS ((int));
128 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **, expressionS
*));
129 static void ppc_elf_cons
PARAMS ((int));
130 static void ppc_elf_rdata
PARAMS ((int));
131 static void ppc_elf_lcomm
PARAMS ((int));
132 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
133 static void ppc_apuinfo_section_add
PARAMS ((unsigned int apu
, unsigned int version
));
137 static void ppc_set_current_section
PARAMS ((segT
));
138 static void ppc_previous
PARAMS ((int));
139 static void ppc_pdata
PARAMS ((int));
140 static void ppc_ydata
PARAMS ((int));
141 static void ppc_reldata
PARAMS ((int));
142 static void ppc_rdata
PARAMS ((int));
143 static void ppc_ualong
PARAMS ((int));
144 static void ppc_znop
PARAMS ((int));
145 static void ppc_pe_comm
PARAMS ((int));
146 static void ppc_pe_section
PARAMS ((int));
147 static void ppc_pe_function
PARAMS ((int));
148 static void ppc_pe_tocd
PARAMS ((int));
151 /* Generic assembler global variables which must be defined by all
155 /* This string holds the chars that always start a comment. If the
156 pre-processor is disabled, these aren't very useful. The macro
157 tc_comment_chars points to this. We use this, rather than the
158 usual comment_chars, so that we can switch for Solaris conventions. */
159 static const char ppc_solaris_comment_chars
[] = "#!";
160 static const char ppc_eabi_comment_chars
[] = "#";
162 #ifdef TARGET_SOLARIS_COMMENT
163 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
165 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
168 const char comment_chars
[] = "#";
171 /* Characters which start a comment at the beginning of a line. */
172 const char line_comment_chars
[] = "#";
174 /* Characters which may be used to separate multiple commands on a
176 const char line_separator_chars
[] = ";";
178 /* Characters which are used to indicate an exponent in a floating
180 const char EXP_CHARS
[] = "eE";
182 /* Characters which mean that a number is a floating point constant,
184 const char FLT_CHARS
[] = "dD";
186 /* '+' and '-' can be used as postfix predicate predictors for conditional
187 branches. So they need to be accepted as symbol characters. */
188 const char ppc_symbol_chars
[] = "+-";
190 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
191 int ppc_cie_data_alignment
;
193 /* The target specific pseudo-ops which we support. */
195 const pseudo_typeS md_pseudo_table
[] =
197 /* Pseudo-ops which must be overridden. */
198 { "byte", ppc_byte
, 0 },
201 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
202 legitimately belong in the obj-*.c file. However, XCOFF is based
203 on COFF, and is only implemented for the RS/6000. We just use
204 obj-coff.c, and add what we need here. */
205 { "comm", ppc_comm
, 0 },
206 { "lcomm", ppc_comm
, 1 },
210 { "bi", ppc_biei
, 0 },
212 { "csect", ppc_csect
, 0 },
213 { "data", ppc_section
, 'd' },
217 { "ei", ppc_biei
, 1 },
219 { "extern", ppc_extern
, 0 },
220 { "function", ppc_function
, 0 },
221 { "lglobl", ppc_lglobl
, 0 },
222 { "rename", ppc_rename
, 0 },
223 { "section", ppc_named_section
, 0 },
224 { "stabx", ppc_stabx
, 0 },
225 { "text", ppc_section
, 't' },
226 { "toc", ppc_toc
, 0 },
227 { "long", ppc_xcoff_cons
, 2 },
228 { "llong", ppc_xcoff_cons
, 3 },
229 { "word", ppc_xcoff_cons
, 1 },
230 { "short", ppc_xcoff_cons
, 1 },
231 { "vbyte", ppc_vbyte
, 0 },
235 { "llong", ppc_elf_cons
, 8 },
236 { "quad", ppc_elf_cons
, 8 },
237 { "long", ppc_elf_cons
, 4 },
238 { "word", ppc_elf_cons
, 2 },
239 { "short", ppc_elf_cons
, 2 },
240 { "rdata", ppc_elf_rdata
, 0 },
241 { "rodata", ppc_elf_rdata
, 0 },
242 { "lcomm", ppc_elf_lcomm
, 0 },
246 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
247 { "previous", ppc_previous
, 0 },
248 { "pdata", ppc_pdata
, 0 },
249 { "ydata", ppc_ydata
, 0 },
250 { "reldata", ppc_reldata
, 0 },
251 { "rdata", ppc_rdata
, 0 },
252 { "ualong", ppc_ualong
, 0 },
253 { "znop", ppc_znop
, 0 },
254 { "comm", ppc_pe_comm
, 0 },
255 { "lcomm", ppc_pe_comm
, 1 },
256 { "section", ppc_pe_section
, 0 },
257 { "function", ppc_pe_function
,0 },
258 { "tocd", ppc_pe_tocd
, 0 },
261 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
263 { "machine", ppc_machine
, 0 },
270 /* Predefined register names if -mregnames (or default for Windows NT).
271 In general, there are lots of them, in an attempt to be compatible
272 with a number of other Windows NT assemblers. */
274 /* Structure to hold information about predefined registers. */
281 /* List of registers that are pre-defined:
283 Each general register has predefined names of the form:
284 1. r<reg_num> which has the value <reg_num>.
285 2. r.<reg_num> which has the value <reg_num>.
287 Each floating point register has predefined names of the form:
288 1. f<reg_num> which has the value <reg_num>.
289 2. f.<reg_num> which has the value <reg_num>.
291 Each vector unit register has predefined names of the form:
292 1. v<reg_num> which has the value <reg_num>.
293 2. v.<reg_num> which has the value <reg_num>.
295 Each condition register has predefined names of the form:
296 1. cr<reg_num> which has the value <reg_num>.
297 2. cr.<reg_num> which has the value <reg_num>.
299 There are individual registers as well:
300 sp or r.sp has the value 1
301 rtoc or r.toc has the value 2
302 fpscr has the value 0
308 dsisr has the value 18
310 sdr1 has the value 25
311 srr0 has the value 26
312 srr1 has the value 27
314 The table is sorted. Suitable for searching by a binary search. */
316 static const struct pd_reg pre_defined_registers
[] =
318 { "cr.0", 0 }, /* Condition Registers */
338 { "dar", 19 }, /* Data Access Register */
339 { "dec", 22 }, /* Decrementer */
340 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
342 { "f.0", 0 }, /* Floating point registers */
410 { "lr", 8 }, /* Link Register */
414 { "r.0", 0 }, /* General Purpose Registers */
447 { "r.sp", 1 }, /* Stack Pointer */
449 { "r.toc", 2 }, /* Pointer to the table of contents */
451 { "r0", 0 }, /* More general purpose registers */
484 { "rtoc", 2 }, /* Table of contents */
486 { "sdr1", 25 }, /* Storage Description Register 1 */
490 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
491 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
493 { "v.0", 0 }, /* Vector registers */
563 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
565 /* Given NAME, find the register number associated with that name, return
566 the integer value associated with the given name or -1 on failure. */
568 static int reg_name_search
569 PARAMS ((const struct pd_reg
*, int, const char * name
));
572 reg_name_search (regs
, regcount
, name
)
573 const struct pd_reg
*regs
;
577 int middle
, low
, high
;
585 middle
= (low
+ high
) / 2;
586 cmp
= strcasecmp (name
, regs
[middle
].name
);
592 return regs
[middle
].value
;
600 * Summary of register_name.
602 * in: Input_line_pointer points to 1st char of operand.
604 * out: A expressionS.
605 * The operand may have been a register: in this case, X_op == O_register,
606 * X_add_number is set to the register number, and truth is returned.
607 * Input_line_pointer->(next non-blank) char after operand, or is in its
612 register_name (expressionP
)
613 expressionS
*expressionP
;
620 /* Find the spelling of the operand. */
621 start
= name
= input_line_pointer
;
622 if (name
[0] == '%' && ISALPHA (name
[1]))
623 name
= ++input_line_pointer
;
625 else if (!reg_names_p
|| !ISALPHA (name
[0]))
628 c
= get_symbol_end ();
629 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
631 /* Put back the delimiting char. */
632 *input_line_pointer
= c
;
634 /* Look to see if it's in the register table. */
637 expressionP
->X_op
= O_register
;
638 expressionP
->X_add_number
= reg_number
;
640 /* Make the rest nice. */
641 expressionP
->X_add_symbol
= NULL
;
642 expressionP
->X_op_symbol
= NULL
;
646 /* Reset the line as if we had not done anything. */
647 input_line_pointer
= start
;
651 /* This function is called for each symbol seen in an expression. It
652 handles the special parsing which PowerPC assemblers are supposed
653 to use for condition codes. */
655 /* Whether to do the special parsing. */
656 static bfd_boolean cr_operand
;
658 /* Names to recognize in a condition code. This table is sorted. */
659 static const struct pd_reg cr_names
[] =
676 /* Parsing function. This returns non-zero if it recognized an
680 ppc_parse_name (name
, expr
)
689 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
694 expr
->X_op
= O_constant
;
695 expr
->X_add_number
= val
;
700 /* Local variables. */
702 /* The type of processor we are assembling for. This is one or more
703 of the PPC_OPCODE flags defined in opcode/ppc.h. */
704 static unsigned long ppc_cpu
= 0;
706 /* Whether to target xcoff64/elf64. */
707 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
709 /* Opcode hash table. */
710 static struct hash_control
*ppc_hash
;
712 /* Macro hash table. */
713 static struct hash_control
*ppc_macro_hash
;
716 /* What type of shared library support to use. */
717 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
719 /* Flags to set in the elf header. */
720 static flagword ppc_flags
= 0;
722 /* Whether this is Solaris or not. */
723 #ifdef TARGET_SOLARIS_COMMENT
724 #define SOLARIS_P TRUE
726 #define SOLARIS_P FALSE
729 static bfd_boolean msolaris
= SOLARIS_P
;
734 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
735 using a bunch of different sections. These assembler sections,
736 however, are all encompassed within the .text or .data sections of
737 the final output file. We handle this by using different
738 subsegments within these main segments. */
740 /* Next subsegment to allocate within the .text segment. */
741 static subsegT ppc_text_subsegment
= 2;
743 /* Linked list of csects in the text section. */
744 static symbolS
*ppc_text_csects
;
746 /* Next subsegment to allocate within the .data segment. */
747 static subsegT ppc_data_subsegment
= 2;
749 /* Linked list of csects in the data section. */
750 static symbolS
*ppc_data_csects
;
752 /* The current csect. */
753 static symbolS
*ppc_current_csect
;
755 /* The RS/6000 assembler uses a TOC which holds addresses of functions
756 and variables. Symbols are put in the TOC with the .tc pseudo-op.
757 A special relocation is used when accessing TOC entries. We handle
758 the TOC as a subsegment within the .data segment. We set it up if
759 we see a .toc pseudo-op, and save the csect symbol here. */
760 static symbolS
*ppc_toc_csect
;
762 /* The first frag in the TOC subsegment. */
763 static fragS
*ppc_toc_frag
;
765 /* The first frag in the first subsegment after the TOC in the .data
766 segment. NULL if there are no subsegments after the TOC. */
767 static fragS
*ppc_after_toc_frag
;
769 /* The current static block. */
770 static symbolS
*ppc_current_block
;
772 /* The COFF debugging section; set by md_begin. This is not the
773 .debug section, but is instead the secret BFD section which will
774 cause BFD to set the section number of a symbol to N_DEBUG. */
775 static asection
*ppc_coff_debug_section
;
777 #endif /* OBJ_XCOFF */
781 /* Various sections that we need for PE coff support. */
782 static segT ydata_section
;
783 static segT pdata_section
;
784 static segT reldata_section
;
785 static segT rdata_section
;
786 static segT tocdata_section
;
788 /* The current section and the previous section. See ppc_previous. */
789 static segT ppc_previous_section
;
790 static segT ppc_current_section
;
795 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
796 #define PPC_APUINFO_ISEL 0x40
797 #define PPC_APUINFO_PMR 0x41
798 #define PPC_APUINFO_RFMCI 0x42
799 #define PPC_APUINFO_CACHELCK 0x43
800 #define PPC_APUINFO_SPE 0x100
801 #define PPC_APUINFO_EFS 0x101
802 #define PPC_APUINFO_BRLOCK 0x102
805 * We keep a list of APUinfo
807 unsigned long *ppc_apuinfo_list
;
808 unsigned int ppc_apuinfo_num
;
809 unsigned int ppc_apuinfo_num_alloc
;
813 const char *const md_shortopts
= "b:l:usm:K:VQ:";
815 const char *const md_shortopts
= "um:";
817 const struct option md_longopts
[] = {
818 {NULL
, no_argument
, NULL
, 0}
820 const size_t md_longopts_size
= sizeof (md_longopts
);
823 md_parse_option (c
, arg
)
830 /* -u means that any undefined symbols should be treated as
831 external, which is the default for gas anyhow. */
836 /* Solaris as takes -le (presumably for little endian). For completeness
837 sake, recognize -be also. */
838 if (strcmp (arg
, "e") == 0)
840 target_big_endian
= 0;
841 set_target_endian
= 1;
849 if (strcmp (arg
, "e") == 0)
851 target_big_endian
= 1;
852 set_target_endian
= 1;
860 /* Recognize -K PIC. */
861 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
864 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
872 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
874 if (strcmp (arg
, "64") == 0)
879 as_fatal (_("%s unsupported"), "-a64");
882 else if (strcmp (arg
, "32") == 0)
889 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
891 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
892 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_32
;
893 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
894 else if (strcmp (arg
, "pwr") == 0)
895 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
896 /* -m601 means to assemble for the PowerPC 601, which includes
897 instructions that are holdovers from the Power. */
898 else if (strcmp (arg
, "601") == 0)
899 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
900 | PPC_OPCODE_601
| PPC_OPCODE_32
);
901 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
903 else if (strcmp (arg
, "ppc") == 0
904 || strcmp (arg
, "ppc32") == 0
905 || strcmp (arg
, "603") == 0
906 || strcmp (arg
, "604") == 0)
907 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
908 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
909 else if (strcmp (arg
, "403") == 0
910 || strcmp (arg
, "405") == 0)
911 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
912 | PPC_OPCODE_403
| PPC_OPCODE_32
);
913 else if (strcmp (arg
, "440") == 0)
914 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
915 | PPC_OPCODE_440
| PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
);
916 else if (strcmp (arg
, "7400") == 0
917 || strcmp (arg
, "7410") == 0
918 || strcmp (arg
, "7450") == 0
919 || strcmp (arg
, "7455") == 0)
920 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
921 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_32
);
922 else if (strcmp (arg
, "altivec") == 0)
925 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_ALTIVEC
;
927 ppc_cpu
|= PPC_OPCODE_ALTIVEC
;
929 else if (strcmp (arg
, "e500") == 0 || strcmp (arg
, "e500x2") == 0)
931 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
932 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
933 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
936 else if (strcmp (arg
, "spe") == 0)
939 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_SPE
| PPC_OPCODE_EFS
;
941 ppc_cpu
|= PPC_OPCODE_SPE
;
943 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
945 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
947 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
949 else if (strcmp (arg
, "ppc64bridge") == 0)
951 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
952 | PPC_OPCODE_64_BRIDGE
| PPC_OPCODE_64
);
954 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
955 else if (strcmp (arg
, "booke") == 0 || strcmp (arg
, "booke32") == 0)
957 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_32
;
959 /* -mbooke64 means enable 64-bit BookE support. */
960 else if (strcmp (arg
, "booke64") == 0)
962 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
963 | PPC_OPCODE_BOOKE64
| PPC_OPCODE_64
);
965 else if (strcmp (arg
, "power4") == 0)
967 ppc_cpu
= (PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
968 | PPC_OPCODE_64
| PPC_OPCODE_POWER4
);
970 /* -mcom means assemble for the common intersection between Power
971 and PowerPC. At present, we just allow the union, rather
972 than the intersection. */
973 else if (strcmp (arg
, "com") == 0)
974 ppc_cpu
= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
975 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
976 else if (strcmp (arg
, "any") == 0)
977 ppc_cpu
|= PPC_OPCODE_ANY
;
979 else if (strcmp (arg
, "regnames") == 0)
982 else if (strcmp (arg
, "no-regnames") == 0)
986 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
987 that require relocation. */
988 else if (strcmp (arg
, "relocatable") == 0)
990 shlib
= SHLIB_MRELOCATABLE
;
991 ppc_flags
|= EF_PPC_RELOCATABLE
;
994 else if (strcmp (arg
, "relocatable-lib") == 0)
996 shlib
= SHLIB_MRELOCATABLE
;
997 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1000 /* -memb, set embedded bit. */
1001 else if (strcmp (arg
, "emb") == 0)
1002 ppc_flags
|= EF_PPC_EMB
;
1004 /* -mlittle/-mbig set the endianess. */
1005 else if (strcmp (arg
, "little") == 0
1006 || strcmp (arg
, "little-endian") == 0)
1008 target_big_endian
= 0;
1009 set_target_endian
= 1;
1012 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1014 target_big_endian
= 1;
1015 set_target_endian
= 1;
1018 else if (strcmp (arg
, "solaris") == 0)
1021 ppc_comment_chars
= ppc_solaris_comment_chars
;
1024 else if (strcmp (arg
, "no-solaris") == 0)
1027 ppc_comment_chars
= ppc_eabi_comment_chars
;
1032 as_bad (_("invalid switch -m%s"), arg
);
1038 /* -V: SVR4 argument to print version ID. */
1040 print_version_id ();
1043 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1044 should be emitted or not. FIXME: Not implemented. */
1048 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1049 rather than .stabs.excl, which is ignored by the linker.
1050 FIXME: Not implemented. */
1066 md_show_usage (stream
)
1069 fprintf (stream
, _("\
1071 -a32 generate ELF32/XCOFF32\n\
1072 -a64 generate ELF64/XCOFF64\n\
1074 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1075 -mpwr generate code for POWER (RIOS1)\n\
1076 -m601 generate code for PowerPC 601\n\
1077 -mppc, -mppc32, -m603, -m604\n\
1078 generate code for PowerPC 603/604\n\
1079 -m403, -m405 generate code for PowerPC 403/405\n\
1080 -m440 generate code for PowerPC 440\n\
1081 -m7400, -m7410, -m7450, -m7455\n\
1082 generate code For PowerPC 7400/7410/7450/7455\n"));
1083 fprintf (stream
, _("\
1084 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1085 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1086 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1087 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1088 -mpower4 generate code for Power4 architecture\n\
1089 -mcom generate code Power/PowerPC common instructions\n\
1090 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1091 fprintf (stream
, _("\
1092 -maltivec generate code for AltiVec\n\
1093 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1094 -mspe generate code for Motorola SPE instructions\n\
1095 -mregnames Allow symbolic names for registers\n\
1096 -mno-regnames Do not allow symbolic names for registers\n"));
1098 fprintf (stream
, _("\
1099 -mrelocatable support for GCC's -mrelocatble option\n\
1100 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1101 -memb set PPC_EMB bit in ELF flags\n\
1102 -mlittle, -mlittle-endian, -l, -le\n\
1103 generate code for a little endian machine\n\
1104 -mbig, -mbig-endian, -b, -be\n\
1105 generate code for a big endian machine\n\
1106 -msolaris generate code for Solaris\n\
1107 -mno-solaris do not generate code for Solaris\n\
1108 -V print assembler version number\n\
1109 -Qy, -Qn ignored\n"));
1113 /* Set ppc_cpu if it is not already set. */
1118 const char *default_os
= TARGET_OS
;
1119 const char *default_cpu
= TARGET_CPU
;
1121 if ((ppc_cpu
& ~PPC_OPCODE_ANY
) == 0)
1124 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1125 else if (strncmp (default_os
, "aix", 3) == 0
1126 && default_os
[3] >= '4' && default_os
[3] <= '9')
1127 ppc_cpu
|= PPC_OPCODE_COMMON
| PPC_OPCODE_32
;
1128 else if (strncmp (default_os
, "aix3", 4) == 0)
1129 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1130 else if (strcmp (default_cpu
, "rs6000") == 0)
1131 ppc_cpu
|= PPC_OPCODE_POWER
| PPC_OPCODE_32
;
1132 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1134 if (default_cpu
[7] == '6' && default_cpu
[8] == '4')
1135 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_64
;
1137 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_CLASSIC
| PPC_OPCODE_32
;
1140 as_fatal (_("Unknown default cpu = %s, os = %s"),
1141 default_cpu
, default_os
);
1145 /* Figure out the BFD architecture to use. */
1147 enum bfd_architecture
1150 const char *default_cpu
= TARGET_CPU
;
1153 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1154 return bfd_arch_powerpc
;
1155 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1156 return bfd_arch_rs6000
;
1157 else if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1159 if (strcmp (default_cpu
, "rs6000") == 0)
1160 return bfd_arch_rs6000
;
1161 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1162 return bfd_arch_powerpc
;
1165 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1166 return bfd_arch_unknown
;
1173 return bfd_mach_ppc64
;
1174 else if (ppc_arch () == bfd_arch_rs6000
)
1175 return bfd_mach_rs6k
;
1177 return bfd_mach_ppc
;
1181 ppc_target_format ()
1185 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1187 return "xcoff-powermac";
1190 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1192 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1197 return (target_big_endian
1198 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1199 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1203 /* This function is called when the assembler starts up. It is called
1204 after the options have been parsed and the output file has been
1210 register const struct powerpc_opcode
*op
;
1211 const struct powerpc_opcode
*op_end
;
1212 const struct powerpc_macro
*macro
;
1213 const struct powerpc_macro
*macro_end
;
1214 bfd_boolean dup_insn
= FALSE
;
1218 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1221 /* Set the ELF flags if desired. */
1222 if (ppc_flags
&& !msolaris
)
1223 bfd_set_private_flags (stdoutput
, ppc_flags
);
1226 /* Insert the opcodes into a hash table. */
1227 ppc_hash
= hash_new ();
1229 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1230 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1232 know ((op
->opcode
& op
->mask
) == op
->opcode
);
1234 if ((op
->flags
& ppc_cpu
& ~(PPC_OPCODE_32
| PPC_OPCODE_64
)) != 0
1235 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
1236 || ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
))
1237 == (ppc_cpu
& (PPC_OPCODE_32
| PPC_OPCODE_64
)))
1238 || (ppc_cpu
& PPC_OPCODE_64_BRIDGE
) != 0)
1239 /* Certain instructions (eg: extsw) do not exist in the
1240 32-bit BookE instruction set, but they do exist in the
1241 64-bit BookE instruction set, and other PPC instruction
1242 sets. Check to see if the opcode has the BOOKE64 flag set.
1243 If it does make sure that the target CPU is not the BookE32. */
1244 && ((op
->flags
& PPC_OPCODE_BOOKE64
) == 0
1245 || (ppc_cpu
& PPC_OPCODE_BOOKE64
) == PPC_OPCODE_BOOKE64
1246 || (ppc_cpu
& PPC_OPCODE_BOOKE
) == 0)
1247 && ((op
->flags
& (PPC_OPCODE_POWER4
| PPC_OPCODE_NOPOWER4
)) == 0
1248 || ((op
->flags
& PPC_OPCODE_POWER4
)
1249 == (ppc_cpu
& PPC_OPCODE_POWER4
))))
1253 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1254 if (retval
!= (const char *) NULL
)
1256 /* Ignore Power duplicates for -m601. */
1257 if ((ppc_cpu
& PPC_OPCODE_601
) != 0
1258 && (op
->flags
& PPC_OPCODE_POWER
) != 0)
1261 as_bad (_("Internal assembler error for instruction %s"),
1268 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1269 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1270 hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
1272 /* Insert the macros into a hash table. */
1273 ppc_macro_hash
= hash_new ();
1275 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1276 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1278 if ((macro
->flags
& ppc_cpu
) != 0)
1282 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
1283 if (retval
!= (const char *) NULL
)
1285 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
1294 /* Tell the main code what the endianness is if it is not overidden
1296 if (!set_target_endian
)
1298 set_target_endian
= 1;
1299 target_big_endian
= PPC_BIG_ENDIAN
;
1303 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1305 /* Create dummy symbols to serve as initial csects. This forces the
1306 text csects to precede the data csects. These symbols will not
1308 ppc_text_csects
= symbol_make ("dummy\001");
1309 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1310 ppc_data_csects
= symbol_make ("dummy\001");
1311 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1316 ppc_current_section
= text_section
;
1317 ppc_previous_section
= 0;
1326 if (ppc_apuinfo_list
== NULL
)
1329 /* Ok, so write the section info out. We have this layout:
1333 0 8 length of "APUinfo\0"
1334 4 (n*4) number of APU's (4 bytes each)
1337 20 APU#1 first APU's info
1338 24 APU#2 second APU's info
1343 asection
*seg
= now_seg
;
1344 subsegT subseg
= now_subseg
;
1345 asection
*apuinfo_secp
= (asection
*) NULL
;
1348 /* Create the .PPC.EMB.apuinfo section. */
1349 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1350 bfd_set_section_flags (stdoutput
,
1352 SEC_HAS_CONTENTS
| SEC_READONLY
);
1355 md_number_to_chars (p
, (valueT
) 8, 4);
1358 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1361 md_number_to_chars (p
, (valueT
) 2, 4);
1364 strcpy (p
, "APUinfo");
1366 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1369 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1372 frag_align (2, 0, 0);
1374 /* We probably can't restore the current segment, for there likely
1377 subseg_set (seg
, subseg
);
1382 /* Insert an operand value into an instruction. */
1384 static unsigned long
1385 ppc_insert_operand (insn
, operand
, val
, file
, line
)
1387 const struct powerpc_operand
*operand
;
1392 if (operand
->bits
!= 32)
1397 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1399 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0)
1400 max
= (1 << operand
->bits
) - 1;
1402 max
= (1 << (operand
->bits
- 1)) - 1;
1403 min
= - (1 << (operand
->bits
- 1));
1407 /* Some people write 32 bit hex constants with the sign
1408 extension done by hand. This shouldn't really be
1409 valid, but, to permit this code to assemble on a 64
1410 bit host, we sign extend the 32 bit value. */
1412 && (val
& (offsetT
) 0x80000000) != 0
1413 && (val
& (offsetT
) 0xffffffff) == val
)
1422 max
= (1 << operand
->bits
) - 1;
1426 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1431 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
1434 _("operand out of range (%s not between %ld and %ld)");
1437 sprint_value (buf
, test
);
1438 as_bad_where (file
, line
, err
, buf
, min
, max
);
1442 if (operand
->insert
)
1447 insn
= (*operand
->insert
) (insn
, (long) val
, ppc_cpu
, &errmsg
);
1448 if (errmsg
!= (const char *) NULL
)
1449 as_bad_where (file
, line
, errmsg
);
1452 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
1460 /* Parse @got, etc. and return the desired relocation. */
1461 static bfd_reloc_code_real_type
1462 ppc_elf_suffix (str_p
, exp_p
)
1477 const struct map_bfd
*ptr
;
1479 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1481 static const struct map_bfd mapping
[] = {
1482 MAP ("l", (int) BFD_RELOC_LO16
),
1483 MAP ("h", (int) BFD_RELOC_HI16
),
1484 MAP ("ha", (int) BFD_RELOC_HI16_S
),
1485 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN
),
1486 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN
),
1487 MAP ("got", (int) BFD_RELOC_16_GOTOFF
),
1488 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF
),
1489 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF
),
1490 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF
),
1491 MAP ("fixup", (int) BFD_RELOC_CTOR
),
1492 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL
),
1493 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL
),
1494 MAP ("copy", (int) BFD_RELOC_PPC_COPY
),
1495 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT
),
1496 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC
),
1497 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC
),
1498 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL
),
1499 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF
),
1500 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF
),
1501 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF
),
1502 MAP ("sdarel", (int) BFD_RELOC_GPREL16
),
1503 MAP ("sectoff", (int) BFD_RELOC_16_BASEREL
),
1504 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL
),
1505 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL
),
1506 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL
),
1507 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32
),
1508 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16
),
1509 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO
),
1510 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI
),
1511 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA
),
1512 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16
),
1513 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL
),
1514 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16
),
1515 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21
),
1516 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF
),
1517 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16
),
1518 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO
),
1519 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI
),
1520 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA
),
1521 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD
),
1522 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA
),
1523 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16
),
1524 MAP ("tls", (int) BFD_RELOC_PPC_TLS
),
1525 MAP ("dtpmod", (int) BFD_RELOC_PPC_DTPMOD
),
1526 MAP ("dtprel", (int) BFD_RELOC_PPC_DTPREL
),
1527 MAP ("dtprel@l", (int) BFD_RELOC_PPC_DTPREL16_LO
),
1528 MAP ("dtprel@h", (int) BFD_RELOC_PPC_DTPREL16_HI
),
1529 MAP ("dtprel@ha", (int) BFD_RELOC_PPC_DTPREL16_HA
),
1530 MAP ("tprel", (int) BFD_RELOC_PPC_TPREL
),
1531 MAP ("tprel@l", (int) BFD_RELOC_PPC_TPREL16_LO
),
1532 MAP ("tprel@h", (int) BFD_RELOC_PPC_TPREL16_HI
),
1533 MAP ("tprel@ha", (int) BFD_RELOC_PPC_TPREL16_HA
),
1534 MAP ("got@tlsgd", (int) BFD_RELOC_PPC_GOT_TLSGD16
),
1535 MAP ("got@tlsgd@l", (int) BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1536 MAP ("got@tlsgd@h", (int) BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1537 MAP ("got@tlsgd@ha", (int) BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1538 MAP ("got@tlsld", (int) BFD_RELOC_PPC_GOT_TLSLD16
),
1539 MAP ("got@tlsld@l", (int) BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1540 MAP ("got@tlsld@h", (int) BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1541 MAP ("got@tlsld@ha", (int) BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1542 MAP ("got@dtprel", (int) BFD_RELOC_PPC_GOT_DTPREL16
),
1543 MAP ("got@dtprel@l", (int) BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1544 MAP ("got@dtprel@h", (int) BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1545 MAP ("got@dtprel@ha", (int) BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1546 MAP ("got@tprel", (int) BFD_RELOC_PPC_GOT_TPREL16
),
1547 MAP ("got@tprel@l", (int) BFD_RELOC_PPC_GOT_TPREL16_LO
),
1548 MAP ("got@tprel@h", (int) BFD_RELOC_PPC_GOT_TPREL16_HI
),
1549 MAP ("got@tprel@ha", (int) BFD_RELOC_PPC_GOT_TPREL16_HA
),
1550 /* The following are only valid for ppc64. Negative values are
1551 used instead of a flag. */
1552 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER
),
1553 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S
),
1554 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST
),
1555 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S
),
1556 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC
),
1557 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16
),
1558 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO
),
1559 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI
),
1560 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA
),
1561 MAP ("dtprel@higher", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1562 MAP ("dtprel@highera", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1563 MAP ("dtprel@highest", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1564 MAP ("dtprel@highesta", - (int) BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1565 MAP ("tprel@higher", - (int) BFD_RELOC_PPC64_TPREL16_HIGHER
),
1566 MAP ("tprel@highera", - (int) BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1567 MAP ("tprel@highest", - (int) BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1568 MAP ("tprel@highesta", - (int) BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1569 { (char *) 0, 0, (int) BFD_RELOC_UNUSED
}
1573 return BFD_RELOC_UNUSED
;
1575 for (ch
= *str
, str2
= ident
;
1576 (str2
< ident
+ sizeof (ident
) - 1
1577 && (ISALNUM (ch
) || ch
== '@'));
1580 *str2
++ = TOLOWER (ch
);
1587 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1588 if (ch
== ptr
->string
[0]
1589 && len
== ptr
->length
1590 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
1592 int reloc
= ptr
->reloc
;
1597 return BFD_RELOC_UNUSED
;
1602 if (exp_p
->X_add_number
!= 0
1603 && (reloc
== (int) BFD_RELOC_16_GOTOFF
1604 || reloc
== (int) BFD_RELOC_LO16_GOTOFF
1605 || reloc
== (int) BFD_RELOC_HI16_GOTOFF
1606 || reloc
== (int) BFD_RELOC_HI16_S_GOTOFF
))
1607 as_warn (_("identifier+constant@got means identifier@got+constant"));
1609 /* Now check for identifier@suffix+constant. */
1610 if (*str
== '-' || *str
== '+')
1612 char *orig_line
= input_line_pointer
;
1613 expressionS new_exp
;
1615 input_line_pointer
= str
;
1616 expression (&new_exp
);
1617 if (new_exp
.X_op
== O_constant
)
1619 exp_p
->X_add_number
+= new_exp
.X_add_number
;
1620 str
= input_line_pointer
;
1623 if (&input_line_pointer
!= str_p
)
1624 input_line_pointer
= orig_line
;
1628 if (reloc
== (int) BFD_RELOC_PPC64_TOC
1629 && exp_p
->X_op
== O_symbol
1630 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
1632 /* Change the symbol so that the dummy .TOC. symbol can be
1633 omitted from the object file. */
1634 exp_p
->X_add_symbol
= &abs_symbol
;
1637 return (bfd_reloc_code_real_type
) reloc
;
1640 return BFD_RELOC_UNUSED
;
1643 /* Like normal .long/.short/.word, except support @got, etc.
1644 Clobbers input_line_pointer, checks end-of-line. */
1646 ppc_elf_cons (nbytes
)
1647 register int nbytes
; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1650 bfd_reloc_code_real_type reloc
;
1652 if (is_it_end_of_statement ())
1654 demand_empty_rest_of_line ();
1661 if (exp
.X_op
== O_symbol
1662 && *input_line_pointer
== '@'
1663 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
1664 &exp
)) != BFD_RELOC_UNUSED
)
1666 reloc_howto_type
*reloc_howto
;
1669 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
1670 size
= bfd_get_reloc_size (reloc_howto
);
1674 as_bad (_("%s relocations do not fit in %d bytes\n"),
1675 reloc_howto
->name
, nbytes
);
1682 p
= frag_more (nbytes
);
1684 if (target_big_endian
)
1685 offset
= nbytes
- size
;
1686 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
1691 emit_expr (&exp
, (unsigned int) nbytes
);
1693 while (*input_line_pointer
++ == ',');
1695 /* Put terminator back into stream. */
1696 input_line_pointer
--;
1697 demand_empty_rest_of_line ();
1700 /* Solaris pseduo op to change to the .rodata section. */
1705 char *save_line
= input_line_pointer
;
1706 static char section
[] = ".rodata\n";
1708 /* Just pretend this is .section .rodata */
1709 input_line_pointer
= section
;
1710 obj_elf_section (xxx
);
1712 input_line_pointer
= save_line
;
1715 /* Pseudo op to make file scope bss items. */
1718 int xxx ATTRIBUTE_UNUSED
;
1720 register char *name
;
1724 register symbolS
*symbolP
;
1731 name
= input_line_pointer
;
1732 c
= get_symbol_end ();
1734 /* just after name is now '\0'. */
1735 p
= input_line_pointer
;
1738 if (*input_line_pointer
!= ',')
1740 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1741 ignore_rest_of_line ();
1745 input_line_pointer
++; /* skip ',' */
1746 if ((size
= get_absolute_expression ()) < 0)
1748 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1749 ignore_rest_of_line ();
1753 /* The third argument to .lcomm is the alignment. */
1754 if (*input_line_pointer
!= ',')
1758 ++input_line_pointer
;
1759 align
= get_absolute_expression ();
1762 as_warn (_("ignoring bad alignment"));
1768 symbolP
= symbol_find_or_make (name
);
1771 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1773 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1774 S_GET_NAME (symbolP
));
1775 ignore_rest_of_line ();
1779 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1781 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1782 S_GET_NAME (symbolP
),
1783 (long) S_GET_VALUE (symbolP
),
1786 ignore_rest_of_line ();
1792 old_subsec
= now_subseg
;
1795 /* Convert to a power of 2 alignment. */
1796 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
1799 as_bad (_("Common alignment not a power of 2"));
1800 ignore_rest_of_line ();
1807 record_alignment (bss_section
, align2
);
1808 subseg_set (bss_section
, 0);
1810 frag_align (align2
, 0, 0);
1811 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1812 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1813 symbol_set_frag (symbolP
, frag_now
);
1814 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1817 S_SET_SIZE (symbolP
, size
);
1818 S_SET_SEGMENT (symbolP
, bss_section
);
1819 subseg_set (old_sec
, old_subsec
);
1820 demand_empty_rest_of_line ();
1823 /* Validate any relocations emitted for -mrelocatable, possibly adding
1824 fixups for word relocations in writable segments, so we can adjust
1827 ppc_elf_validate_fix (fixp
, seg
)
1831 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1840 case SHLIB_MRELOCATABLE
:
1841 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1842 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1843 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1844 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1845 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1846 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
1847 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1848 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1849 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1850 && (seg
->flags
& SEC_LOAD
) != 0
1851 && strcmp (segment_name (seg
), ".got2") != 0
1852 && strcmp (segment_name (seg
), ".dtors") != 0
1853 && strcmp (segment_name (seg
), ".ctors") != 0
1854 && strcmp (segment_name (seg
), ".fixup") != 0
1855 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1856 && strcmp (segment_name (seg
), ".eh_frame") != 0
1857 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1859 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1860 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1862 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1863 _("Relocation cannot be done when using -mrelocatable"));
1870 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1871 function descriptor sym if the corresponding code sym is used. */
1874 ppc_frob_file_before_adjust ()
1881 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
1888 name
= S_GET_NAME (symp
);
1892 if (! S_IS_WEAK (symp
)
1893 || S_IS_DEFINED (symp
))
1896 len
= strlen (name
) + 1;
1897 dotname
= xmalloc (len
+ 1);
1899 memcpy (dotname
+ 1, name
, len
);
1900 dotsym
= symbol_find (dotname
);
1902 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
1903 || symbol_used_in_reloc_p (dotsym
)))
1905 symbol_mark_used (symp
);
1909 /* Don't emit .TOC. symbol. */
1910 symp
= symbol_find (".TOC.");
1912 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
1914 #endif /* OBJ_ELF */
1919 * Summary of parse_toc_entry.
1921 * in: Input_line_pointer points to the '[' in one of:
1923 * [toc] [tocv] [toc32] [toc64]
1925 * Anything else is an error of one kind or another.
1928 * return value: success or failure
1929 * toc_kind: kind of toc reference
1930 * input_line_pointer:
1931 * success: first char after the ']'
1932 * failure: unchanged
1936 * [toc] - rv == success, toc_kind = default_toc
1937 * [tocv] - rv == success, toc_kind = data_in_toc
1938 * [toc32] - rv == success, toc_kind = must_be_32
1939 * [toc64] - rv == success, toc_kind = must_be_64
1943 enum toc_size_qualifier
1945 default_toc
, /* The toc cell constructed should be the system default size */
1946 data_in_toc
, /* This is a direct reference to a toc cell */
1947 must_be_32
, /* The toc cell constructed must be 32 bits wide */
1948 must_be_64
/* The toc cell constructed must be 64 bits wide */
1952 parse_toc_entry (toc_kind
)
1953 enum toc_size_qualifier
*toc_kind
;
1958 enum toc_size_qualifier t
;
1960 /* Save the input_line_pointer. */
1961 start
= input_line_pointer
;
1963 /* Skip over the '[' , and whitespace. */
1964 ++input_line_pointer
;
1967 /* Find the spelling of the operand. */
1968 toc_spec
= input_line_pointer
;
1969 c
= get_symbol_end ();
1971 if (strcmp (toc_spec
, "toc") == 0)
1975 else if (strcmp (toc_spec
, "tocv") == 0)
1979 else if (strcmp (toc_spec
, "toc32") == 0)
1983 else if (strcmp (toc_spec
, "toc64") == 0)
1989 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
1990 *input_line_pointer
= c
;
1991 input_line_pointer
= start
;
1995 /* Now find the ']'. */
1996 *input_line_pointer
= c
;
1998 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1999 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2003 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2004 input_line_pointer
= start
;
2015 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2017 ppc_apuinfo_section_add (apu
, version
)
2018 unsigned int apu
, version
;
2022 /* Check we don't already exist. */
2023 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2024 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2027 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2029 if (ppc_apuinfo_num_alloc
== 0)
2031 ppc_apuinfo_num_alloc
= 4;
2032 ppc_apuinfo_list
= (unsigned long *)
2033 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2037 ppc_apuinfo_num_alloc
+= 4;
2038 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2039 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2042 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2048 /* We need to keep a list of fixups. We can't simply generate them as
2049 we go, because that would require us to first create the frag, and
2050 that would screw up references to ``.''. */
2056 bfd_reloc_code_real_type reloc
;
2059 #define MAX_INSN_FIXUPS (5)
2061 /* This routine is called for each instruction to be assembled. */
2068 const struct powerpc_opcode
*opcode
;
2070 const unsigned char *opindex_ptr
;
2074 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2079 bfd_reloc_code_real_type reloc
;
2082 /* Get the opcode. */
2083 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2088 /* Look up the opcode in the hash table. */
2089 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2090 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2092 const struct powerpc_macro
*macro
;
2094 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2095 if (macro
== (const struct powerpc_macro
*) NULL
)
2096 as_bad (_("Unrecognized opcode: `%s'"), str
);
2098 ppc_macro (s
, macro
);
2103 insn
= opcode
->opcode
;
2106 while (ISSPACE (*str
))
2109 /* PowerPC operands are just expressions. The only real issue is
2110 that a few operand types are optional. All cases which might use
2111 an optional operand separate the operands only with commas (in
2112 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
2113 cases never have optional operands). There is never more than
2114 one optional operand for an instruction. So, before we start
2115 seriously parsing the operands, we check to see if we have an
2116 optional operand, and, if we do, we count the number of commas to
2117 see whether the operand should be omitted. */
2119 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2121 const struct powerpc_operand
*operand
;
2123 operand
= &powerpc_operands
[*opindex_ptr
];
2124 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2126 unsigned int opcount
;
2127 unsigned int num_operands_expected
;
2130 /* There is an optional operand. Count the number of
2131 commas in the input line. */
2138 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2145 /* Compute the number of expected operands.
2146 Do not count fake operands. */
2147 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2148 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2149 ++ num_operands_expected
;
2151 /* If there are fewer operands in the line then are called
2152 for by the instruction, we want to skip the optional
2154 if (opcount
< num_operands_expected
)
2161 /* Gather the operands. */
2165 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2167 const struct powerpc_operand
*operand
;
2173 if (next_opindex
== 0)
2174 operand
= &powerpc_operands
[*opindex_ptr
];
2177 operand
= &powerpc_operands
[next_opindex
];
2182 /* If this is a fake operand, then we do not expect anything
2184 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2186 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2187 if (errmsg
!= (const char *) NULL
)
2192 /* If this is an optional operand, and we are skipping it, just
2194 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2197 if (operand
->insert
)
2199 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2200 if (errmsg
!= (const char *) NULL
)
2203 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2204 next_opindex
= *opindex_ptr
+ 1;
2208 /* Gather the operand. */
2209 hold
= input_line_pointer
;
2210 input_line_pointer
= str
;
2213 if (*input_line_pointer
== '[')
2215 /* We are expecting something like the second argument here:
2217 * lwz r4,[toc].GS.0.static_int(rtoc)
2218 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2219 * The argument following the `]' must be a symbol name, and the
2220 * register must be the toc register: 'rtoc' or '2'
2222 * The effect is to 0 as the displacement field
2223 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2224 * the appropriate variation) reloc against it based on the symbol.
2225 * The linker will build the toc, and insert the resolved toc offset.
2228 * o The size of the toc entry is currently assumed to be
2229 * 32 bits. This should not be assumed to be a hard coded
2231 * o In an effort to cope with a change from 32 to 64 bits,
2232 * there are also toc entries that are specified to be
2233 * either 32 or 64 bits:
2234 * lwz r4,[toc32].GS.0.static_int(rtoc)
2235 * lwz r4,[toc64].GS.0.static_int(rtoc)
2236 * These demand toc entries of the specified size, and the
2237 * instruction probably requires it.
2241 enum toc_size_qualifier toc_kind
;
2242 bfd_reloc_code_real_type toc_reloc
;
2244 /* Go parse off the [tocXX] part. */
2245 valid_toc
= parse_toc_entry (&toc_kind
);
2249 /* Note: message has already been issued.
2250 FIXME: what sort of recovery should we do?
2251 demand_rest_of_line (); return; ? */
2254 /* Now get the symbol following the ']'. */
2260 /* In this case, we may not have seen the symbol yet,
2261 since it is allowed to appear on a .extern or .globl
2262 or just be a label in the .data section. */
2263 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2266 /* 1. The symbol must be defined and either in the toc
2267 section, or a global.
2268 2. The reloc generated must have the TOCDEFN flag set
2269 in upper bit mess of the reloc type.
2270 FIXME: It's a little confusing what the tocv
2271 qualifier can be used for. At the very least, I've
2272 seen three uses, only one of which I'm sure I can
2274 if (ex
.X_op
== O_symbol
)
2276 assert (ex
.X_add_symbol
!= NULL
);
2277 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2280 as_bad (_("[tocv] symbol is not a toc symbol"));
2284 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2287 /* FIXME: these next two specifically specify 32/64 bit
2288 toc entries. We don't support them today. Is this
2289 the right way to say that? */
2290 toc_reloc
= BFD_RELOC_UNUSED
;
2291 as_bad (_("Unimplemented toc32 expression modifier"));
2294 /* FIXME: see above. */
2295 toc_reloc
= BFD_RELOC_UNUSED
;
2296 as_bad (_("Unimplemented toc64 expression modifier"));
2300 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2306 /* We need to generate a fixup for this expression. */
2307 if (fc
>= MAX_INSN_FIXUPS
)
2308 as_fatal (_("too many fixups"));
2310 fixups
[fc
].reloc
= toc_reloc
;
2311 fixups
[fc
].exp
= ex
;
2312 fixups
[fc
].opindex
= *opindex_ptr
;
2315 /* Ok. We've set up the fixup for the instruction. Now make it
2316 look like the constant 0 was found here. */
2318 ex
.X_op
= O_constant
;
2319 ex
.X_add_number
= 0;
2320 ex
.X_add_symbol
= NULL
;
2321 ex
.X_op_symbol
= NULL
;
2327 if (! register_name (&ex
))
2329 if ((operand
->flags
& PPC_OPERAND_CR
) != 0)
2336 str
= input_line_pointer
;
2337 input_line_pointer
= hold
;
2339 if (ex
.X_op
== O_illegal
)
2340 as_bad (_("illegal operand"));
2341 else if (ex
.X_op
== O_absent
)
2342 as_bad (_("missing operand"));
2343 else if (ex
.X_op
== O_register
)
2345 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2348 else if (ex
.X_op
== O_constant
)
2351 /* Allow @HA, @L, @H on constants. */
2352 char *orig_str
= str
;
2354 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2361 case BFD_RELOC_LO16
:
2362 /* X_unsigned is the default, so if the user has done
2363 something which cleared it, we always produce a
2365 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2366 ex
.X_add_number
&= 0xffff;
2368 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2371 case BFD_RELOC_HI16
:
2372 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2373 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2375 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2378 case BFD_RELOC_HI16_S
:
2379 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2380 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2382 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2385 case BFD_RELOC_PPC64_HIGHER
:
2386 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2387 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2389 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2392 case BFD_RELOC_PPC64_HIGHER_S
:
2393 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2394 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2396 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2399 case BFD_RELOC_PPC64_HIGHEST
:
2400 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2401 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2403 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2406 case BFD_RELOC_PPC64_HIGHEST_S
:
2407 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2408 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2410 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2413 #endif /* OBJ_ELF */
2414 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2418 else if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2420 /* Some TLS tweaks. */
2425 case BFD_RELOC_PPC_TLS
:
2426 insn
= ppc_insert_operand (insn
, operand
, ppc_obj64
? 13 : 2,
2429 /* We'll only use the 32 (or 64) bit form of these relocations
2430 in constants. Instructions get the 16 bit form. */
2431 case BFD_RELOC_PPC_DTPREL
:
2432 reloc
= BFD_RELOC_PPC_DTPREL16
;
2434 case BFD_RELOC_PPC_TPREL
:
2435 reloc
= BFD_RELOC_PPC_TPREL16
;
2439 /* For the absolute forms of branches, convert the PC
2440 relative form back into the absolute. */
2441 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
2445 case BFD_RELOC_PPC_B26
:
2446 reloc
= BFD_RELOC_PPC_BA26
;
2448 case BFD_RELOC_PPC_B16
:
2449 reloc
= BFD_RELOC_PPC_BA16
;
2451 case BFD_RELOC_PPC_B16_BRTAKEN
:
2452 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
2454 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2455 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
2463 && (operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
2468 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
2470 case BFD_RELOC_LO16
:
2471 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
2473 case BFD_RELOC_16_GOTOFF
:
2474 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
2476 case BFD_RELOC_LO16_GOTOFF
:
2477 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
2479 case BFD_RELOC_LO16_PLTOFF
:
2480 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
2482 case BFD_RELOC_16_BASEREL
:
2483 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
2485 case BFD_RELOC_LO16_BASEREL
:
2486 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
2488 case BFD_RELOC_PPC_TOC16
:
2489 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
2491 case BFD_RELOC_PPC64_TOC16_LO
:
2492 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
2494 case BFD_RELOC_PPC64_PLTGOT16
:
2495 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
2497 case BFD_RELOC_PPC64_PLTGOT16_LO
:
2498 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
2500 case BFD_RELOC_PPC_DTPREL16
:
2501 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
2503 case BFD_RELOC_PPC_DTPREL16_LO
:
2504 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
2506 case BFD_RELOC_PPC_TPREL16
:
2507 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
2509 case BFD_RELOC_PPC_TPREL16_LO
:
2510 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
2512 case BFD_RELOC_PPC_GOT_DTPREL16
:
2513 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2514 case BFD_RELOC_PPC_GOT_TPREL16
:
2515 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2518 as_bad (_("unsupported relocation for DS offset field"));
2523 /* We need to generate a fixup for this expression. */
2524 if (fc
>= MAX_INSN_FIXUPS
)
2525 as_fatal (_("too many fixups"));
2526 fixups
[fc
].exp
= ex
;
2527 fixups
[fc
].opindex
= 0;
2528 fixups
[fc
].reloc
= reloc
;
2531 #endif /* OBJ_ELF */
2535 /* We need to generate a fixup for this expression. */
2536 if (fc
>= MAX_INSN_FIXUPS
)
2537 as_fatal (_("too many fixups"));
2538 fixups
[fc
].exp
= ex
;
2539 fixups
[fc
].opindex
= *opindex_ptr
;
2540 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2549 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
2557 /* The call to expression should have advanced str past any
2560 && (endc
!= ',' || *str
!= '\0'))
2562 as_bad (_("syntax error; found `%c' but expected `%c'"), *str
, endc
);
2570 while (ISSPACE (*str
))
2574 as_bad (_("junk at end of line: `%s'"), str
);
2577 /* Do we need/want a APUinfo section? */
2578 if (ppc_cpu
& (PPC_OPCODE_SPE
2579 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
2580 | PPC_OPCODE_BRLOCK
| PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
2581 | PPC_OPCODE_RFMCI
))
2583 /* These are all version "1". */
2584 if (opcode
->flags
& PPC_OPCODE_SPE
)
2585 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
2586 if (opcode
->flags
& PPC_OPCODE_ISEL
)
2587 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
2588 if (opcode
->flags
& PPC_OPCODE_EFS
)
2589 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
2590 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
2591 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
2592 if (opcode
->flags
& PPC_OPCODE_PMR
)
2593 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
2594 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
2595 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
2596 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
2597 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
2601 /* Write out the instruction. */
2603 md_number_to_chars (f
, insn
, 4);
2606 dwarf2_emit_insn (4);
2609 /* Create any fixups. At this point we do not use a
2610 bfd_reloc_code_real_type, but instead just use the
2611 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2612 handle fixups for any operand type, although that is admittedly
2613 not a very exciting feature. We pick a BFD reloc type in
2615 for (i
= 0; i
< fc
; i
++)
2617 const struct powerpc_operand
*operand
;
2619 operand
= &powerpc_operands
[fixups
[i
].opindex
];
2620 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2622 reloc_howto_type
*reloc_howto
;
2627 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2631 size
= bfd_get_reloc_size (reloc_howto
);
2632 offset
= target_big_endian
? (4 - size
) : 0;
2634 if (size
< 1 || size
> 4)
2637 fixP
= fix_new_exp (frag_now
,
2638 f
- frag_now
->fr_literal
+ offset
,
2641 reloc_howto
->pc_relative
,
2644 /* Turn off complaints that the addend is too large for things like
2646 switch (fixups
[i
].reloc
)
2648 case BFD_RELOC_16_GOTOFF
:
2649 case BFD_RELOC_PPC_TOC16
:
2650 case BFD_RELOC_LO16
:
2651 case BFD_RELOC_HI16
:
2652 case BFD_RELOC_HI16_S
:
2654 case BFD_RELOC_PPC64_HIGHER
:
2655 case BFD_RELOC_PPC64_HIGHER_S
:
2656 case BFD_RELOC_PPC64_HIGHEST
:
2657 case BFD_RELOC_PPC64_HIGHEST_S
:
2659 fixP
->fx_no_overflow
= 1;
2666 fix_new_exp (frag_now
,
2667 f
- frag_now
->fr_literal
,
2670 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
2671 ((bfd_reloc_code_real_type
)
2672 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2676 /* Handle a macro. Gather all the operands, transform them as
2677 described by the macro, and call md_assemble recursively. All the
2678 operands are separated by commas; we don't accept parentheses
2679 around operands here. */
2682 ppc_macro (str
, macro
)
2684 const struct powerpc_macro
*macro
;
2695 /* Gather the users operands into the operands array. */
2700 if (count
>= sizeof operands
/ sizeof operands
[0])
2702 operands
[count
++] = s
;
2703 s
= strchr (s
, ',');
2704 if (s
== (char *) NULL
)
2709 if (count
!= macro
->operands
)
2711 as_bad (_("wrong number of operands"));
2715 /* Work out how large the string must be (the size is unbounded
2716 because it includes user input). */
2718 format
= macro
->format
;
2719 while (*format
!= '\0')
2728 arg
= strtol (format
+ 1, &send
, 10);
2729 know (send
!= format
&& arg
>= 0 && arg
< count
);
2730 len
+= strlen (operands
[arg
]);
2735 /* Put the string together. */
2736 complete
= s
= (char *) alloca (len
+ 1);
2737 format
= macro
->format
;
2738 while (*format
!= '\0')
2744 arg
= strtol (format
+ 1, &send
, 10);
2745 strcpy (s
, operands
[arg
]);
2752 /* Assemble the constructed instruction. */
2753 md_assemble (complete
);
2757 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2760 ppc_section_letter (letter
, ptr_msg
)
2767 *ptr_msg
= _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2772 ppc_section_word (str
, len
)
2776 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2783 ppc_section_type (str
, len
)
2787 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2794 ppc_section_flags (flags
, attr
, type
)
2799 if (type
== SHT_ORDERED
)
2800 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2802 if (attr
& SHF_EXCLUDE
)
2803 flags
|= SEC_EXCLUDE
;
2807 #endif /* OBJ_ELF */
2810 /* Pseudo-op handling. */
2812 /* The .byte pseudo-op. This is similar to the normal .byte
2813 pseudo-op, but it can also take a single ASCII string. */
2817 int ignore ATTRIBUTE_UNUSED
;
2819 if (*input_line_pointer
!= '\"')
2825 /* Gather characters. A real double quote is doubled. Unusual
2826 characters are not permitted. */
2827 ++input_line_pointer
;
2832 c
= *input_line_pointer
++;
2836 if (*input_line_pointer
!= '\"')
2838 ++input_line_pointer
;
2841 FRAG_APPEND_1_CHAR (c
);
2844 demand_empty_rest_of_line ();
2849 /* XCOFF specific pseudo-op handling. */
2851 /* This is set if we are creating a .stabx symbol, since we don't want
2852 to handle symbol suffixes for such symbols. */
2853 static bfd_boolean ppc_stab_symbol
;
2855 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2856 symbols in the .bss segment as though they were local common
2857 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2858 aligns .comm and .lcomm to 4 bytes. */
2864 asection
*current_seg
= now_seg
;
2865 subsegT current_subseg
= now_subseg
;
2871 symbolS
*lcomm_sym
= NULL
;
2875 name
= input_line_pointer
;
2876 endc
= get_symbol_end ();
2877 end_name
= input_line_pointer
;
2880 if (*input_line_pointer
!= ',')
2882 as_bad (_("missing size"));
2883 ignore_rest_of_line ();
2886 ++input_line_pointer
;
2888 size
= get_absolute_expression ();
2891 as_bad (_("negative size"));
2892 ignore_rest_of_line ();
2898 /* The third argument to .comm is the alignment. */
2899 if (*input_line_pointer
!= ',')
2903 ++input_line_pointer
;
2904 align
= get_absolute_expression ();
2907 as_warn (_("ignoring bad alignment"));
2922 /* The third argument to .lcomm appears to be the real local
2923 common symbol to create. References to the symbol named in
2924 the first argument are turned into references to the third
2926 if (*input_line_pointer
!= ',')
2928 as_bad (_("missing real symbol name"));
2929 ignore_rest_of_line ();
2932 ++input_line_pointer
;
2934 lcomm_name
= input_line_pointer
;
2935 lcomm_endc
= get_symbol_end ();
2937 lcomm_sym
= symbol_find_or_make (lcomm_name
);
2939 *input_line_pointer
= lcomm_endc
;
2943 sym
= symbol_find_or_make (name
);
2946 if (S_IS_DEFINED (sym
)
2947 || S_GET_VALUE (sym
) != 0)
2949 as_bad (_("attempt to redefine symbol"));
2950 ignore_rest_of_line ();
2954 record_alignment (bss_section
, align
);
2957 || ! S_IS_DEFINED (lcomm_sym
))
2966 S_SET_EXTERNAL (sym
);
2970 symbol_get_tc (lcomm_sym
)->output
= 1;
2971 def_sym
= lcomm_sym
;
2975 subseg_set (bss_section
, 1);
2976 frag_align (align
, 0, 0);
2978 symbol_set_frag (def_sym
, frag_now
);
2979 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
2980 def_size
, (char *) NULL
);
2982 S_SET_SEGMENT (def_sym
, bss_section
);
2983 symbol_get_tc (def_sym
)->align
= align
;
2987 /* Align the size of lcomm_sym. */
2988 symbol_get_frag (lcomm_sym
)->fr_offset
=
2989 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
2990 &~ ((1 << align
) - 1));
2991 if (align
> symbol_get_tc (lcomm_sym
)->align
)
2992 symbol_get_tc (lcomm_sym
)->align
= align
;
2997 /* Make sym an offset from lcomm_sym. */
2998 S_SET_SEGMENT (sym
, bss_section
);
2999 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3000 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3001 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3004 subseg_set (current_seg
, current_subseg
);
3006 demand_empty_rest_of_line ();
3009 /* The .csect pseudo-op. This switches us into a different
3010 subsegment. The first argument is a symbol whose value is the
3011 start of the .csect. In COFF, csect symbols get special aux
3012 entries defined by the x_csect field of union internal_auxent. The
3013 optional second argument is the alignment (the default is 2). */
3017 int ignore ATTRIBUTE_UNUSED
;
3024 name
= input_line_pointer
;
3025 endc
= get_symbol_end ();
3027 sym
= symbol_find_or_make (name
);
3029 *input_line_pointer
= endc
;
3031 if (S_GET_NAME (sym
)[0] == '\0')
3033 /* An unnamed csect is assumed to be [PR]. */
3034 symbol_get_tc (sym
)->class = XMC_PR
;
3038 if (*input_line_pointer
== ',')
3040 ++input_line_pointer
;
3041 align
= get_absolute_expression ();
3044 ppc_change_csect (sym
, align
);
3046 demand_empty_rest_of_line ();
3049 /* Change to a different csect. */
3052 ppc_change_csect (sym
, align
)
3056 if (S_IS_DEFINED (sym
))
3057 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3067 /* This is a new csect. We need to look at the symbol class to
3068 figure out whether it should go in the text section or the
3072 switch (symbol_get_tc (sym
)->class)
3082 S_SET_SEGMENT (sym
, text_section
);
3083 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3084 ++ppc_text_subsegment
;
3085 list_ptr
= &ppc_text_csects
;
3095 if (ppc_toc_csect
!= NULL
3096 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3097 == ppc_data_subsegment
))
3099 S_SET_SEGMENT (sym
, data_section
);
3100 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3101 ++ppc_data_subsegment
;
3102 list_ptr
= &ppc_data_csects
;
3108 /* We set the obstack chunk size to a small value before
3109 changing subsegments, so that we don't use a lot of memory
3110 space for what may be a small section. */
3111 hold_chunksize
= chunksize
;
3114 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3115 symbol_get_tc (sym
)->subseg
);
3117 chunksize
= hold_chunksize
;
3120 ppc_after_toc_frag
= frag_now
;
3122 record_alignment (sec
, align
);
3124 frag_align_code (align
, 0);
3126 frag_align (align
, 0, 0);
3128 symbol_set_frag (sym
, frag_now
);
3129 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3131 symbol_get_tc (sym
)->align
= align
;
3132 symbol_get_tc (sym
)->output
= 1;
3133 symbol_get_tc (sym
)->within
= sym
;
3135 for (list
= *list_ptr
;
3136 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3137 list
= symbol_get_tc (list
)->next
)
3139 symbol_get_tc (list
)->next
= sym
;
3141 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3142 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3146 ppc_current_csect
= sym
;
3149 /* This function handles the .text and .data pseudo-ops. These
3150 pseudo-ops aren't really used by XCOFF; we implement them for the
3151 convenience of people who aren't used to XCOFF. */
3162 else if (type
== 'd')
3167 sym
= symbol_find_or_make (name
);
3169 ppc_change_csect (sym
, 2);
3171 demand_empty_rest_of_line ();
3174 /* This function handles the .section pseudo-op. This is mostly to
3175 give an error, since XCOFF only supports .text, .data and .bss, but
3176 we do permit the user to name the text or data section. */
3179 ppc_named_section (ignore
)
3180 int ignore ATTRIBUTE_UNUSED
;
3183 const char *real_name
;
3187 user_name
= input_line_pointer
;
3188 c
= get_symbol_end ();
3190 if (strcmp (user_name
, ".text") == 0)
3191 real_name
= ".text[PR]";
3192 else if (strcmp (user_name
, ".data") == 0)
3193 real_name
= ".data[RW]";
3196 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3197 *input_line_pointer
= c
;
3198 ignore_rest_of_line ();
3202 *input_line_pointer
= c
;
3204 sym
= symbol_find_or_make (real_name
);
3206 ppc_change_csect (sym
, 2);
3208 demand_empty_rest_of_line ();
3211 /* The .extern pseudo-op. We create an undefined symbol. */
3215 int ignore ATTRIBUTE_UNUSED
;
3220 name
= input_line_pointer
;
3221 endc
= get_symbol_end ();
3223 (void) symbol_find_or_make (name
);
3225 *input_line_pointer
= endc
;
3227 demand_empty_rest_of_line ();
3230 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3234 int ignore ATTRIBUTE_UNUSED
;
3240 name
= input_line_pointer
;
3241 endc
= get_symbol_end ();
3243 sym
= symbol_find_or_make (name
);
3245 *input_line_pointer
= endc
;
3247 symbol_get_tc (sym
)->output
= 1;
3249 demand_empty_rest_of_line ();
3252 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3253 although I don't know why it bothers. */
3257 int ignore ATTRIBUTE_UNUSED
;
3264 name
= input_line_pointer
;
3265 endc
= get_symbol_end ();
3267 sym
= symbol_find_or_make (name
);
3269 *input_line_pointer
= endc
;
3271 if (*input_line_pointer
!= ',')
3273 as_bad (_("missing rename string"));
3274 ignore_rest_of_line ();
3277 ++input_line_pointer
;
3279 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
3281 demand_empty_rest_of_line ();
3284 /* The .stabx pseudo-op. This is similar to a normal .stabs
3285 pseudo-op, but slightly different. A sample is
3286 .stabx "main:F-1",.main,142,0
3287 The first argument is the symbol name to create. The second is the
3288 value, and the third is the storage class. The fourth seems to be
3289 always zero, and I am assuming it is the type. */
3293 int ignore ATTRIBUTE_UNUSED
;
3300 name
= demand_copy_C_string (&len
);
3302 if (*input_line_pointer
!= ',')
3304 as_bad (_("missing value"));
3307 ++input_line_pointer
;
3309 ppc_stab_symbol
= TRUE
;
3310 sym
= symbol_make (name
);
3311 ppc_stab_symbol
= FALSE
;
3313 symbol_get_tc (sym
)->real_name
= name
;
3315 (void) expression (&exp
);
3322 as_bad (_("illegal .stabx expression; zero assumed"));
3323 exp
.X_add_number
= 0;
3326 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
3327 symbol_set_frag (sym
, &zero_address_frag
);
3331 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
3332 symbol_set_value_expression (sym
, &exp
);
3336 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
3337 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
3342 /* The value is some complex expression. This will probably
3343 fail at some later point, but this is probably the right
3344 thing to do here. */
3345 symbol_set_value_expression (sym
, &exp
);
3349 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3350 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3352 if (*input_line_pointer
!= ',')
3354 as_bad (_("missing class"));
3357 ++input_line_pointer
;
3359 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
3361 if (*input_line_pointer
!= ',')
3363 as_bad (_("missing type"));
3366 ++input_line_pointer
;
3368 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
3370 symbol_get_tc (sym
)->output
= 1;
3372 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
) {
3374 symbol_get_tc (sym
)->within
= ppc_current_block
;
3379 .stabx "z",arrays_,133,0
3382 .comm arrays_,13768,3
3384 resolve_symbol_value will copy the exp's "within" into sym's when the
3385 offset is 0. Since this seems to be corner case problem,
3386 only do the correction for storage class C_STSYM. A better solution
3387 would be to have the tc field updated in ppc_symbol_new_hook. */
3389 if (exp
.X_op
== O_symbol
)
3391 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
3395 if (exp
.X_op
!= O_symbol
3396 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
3397 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
3398 ppc_frob_label (sym
);
3401 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3402 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
3403 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
3404 symbol_get_tc (ppc_current_csect
)->within
= sym
;
3407 demand_empty_rest_of_line ();
3410 /* The .function pseudo-op. This takes several arguments. The first
3411 argument seems to be the external name of the symbol. The second
3412 argment seems to be the label for the start of the function. gcc
3413 uses the same name for both. I have no idea what the third and
3414 fourth arguments are meant to be. The optional fifth argument is
3415 an expression for the size of the function. In COFF this symbol
3416 gets an aux entry like that used for a csect. */
3419 ppc_function (ignore
)
3420 int ignore ATTRIBUTE_UNUSED
;
3428 name
= input_line_pointer
;
3429 endc
= get_symbol_end ();
3431 /* Ignore any [PR] suffix. */
3432 name
= ppc_canonicalize_symbol_name (name
);
3433 s
= strchr (name
, '[');
3434 if (s
!= (char *) NULL
3435 && strcmp (s
+ 1, "PR]") == 0)
3438 ext_sym
= symbol_find_or_make (name
);
3440 *input_line_pointer
= endc
;
3442 if (*input_line_pointer
!= ',')
3444 as_bad (_("missing symbol name"));
3445 ignore_rest_of_line ();
3448 ++input_line_pointer
;
3450 name
= input_line_pointer
;
3451 endc
= get_symbol_end ();
3453 lab_sym
= symbol_find_or_make (name
);
3455 *input_line_pointer
= endc
;
3457 if (ext_sym
!= lab_sym
)
3461 exp
.X_op
= O_symbol
;
3462 exp
.X_add_symbol
= lab_sym
;
3463 exp
.X_op_symbol
= NULL
;
3464 exp
.X_add_number
= 0;
3466 symbol_set_value_expression (ext_sym
, &exp
);
3469 if (symbol_get_tc (ext_sym
)->class == -1)
3470 symbol_get_tc (ext_sym
)->class = XMC_PR
;
3471 symbol_get_tc (ext_sym
)->output
= 1;
3473 if (*input_line_pointer
== ',')
3477 /* Ignore the third argument. */
3478 ++input_line_pointer
;
3479 expression (&ignore
);
3480 if (*input_line_pointer
== ',')
3482 /* Ignore the fourth argument. */
3483 ++input_line_pointer
;
3484 expression (&ignore
);
3485 if (*input_line_pointer
== ',')
3487 /* The fifth argument is the function size. */
3488 ++input_line_pointer
;
3489 symbol_get_tc (ext_sym
)->size
= symbol_new ("L0\001",
3492 &zero_address_frag
);
3493 pseudo_set (symbol_get_tc (ext_sym
)->size
);
3498 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
3499 SF_SET_FUNCTION (ext_sym
);
3500 SF_SET_PROCESS (ext_sym
);
3501 coff_add_linesym (ext_sym
);
3503 demand_empty_rest_of_line ();
3506 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3507 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3508 with the correct line number */
3510 static symbolS
*saved_bi_sym
= 0;
3514 int ignore ATTRIBUTE_UNUSED
;
3518 sym
= symbol_make (".bf");
3519 S_SET_SEGMENT (sym
, text_section
);
3520 symbol_set_frag (sym
, frag_now
);
3521 S_SET_VALUE (sym
, frag_now_fix ());
3522 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3524 coff_line_base
= get_absolute_expression ();
3526 S_SET_NUMBER_AUXILIARY (sym
, 1);
3527 SA_SET_SYM_LNNO (sym
, coff_line_base
);
3529 /* Line number for bi. */
3532 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
3537 symbol_get_tc (sym
)->output
= 1;
3539 ppc_frob_label (sym
);
3541 demand_empty_rest_of_line ();
3544 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3545 ".ef", except that the line number is absolute, not relative to the
3546 most recent ".bf" symbol. */
3550 int ignore ATTRIBUTE_UNUSED
;
3554 sym
= symbol_make (".ef");
3555 S_SET_SEGMENT (sym
, text_section
);
3556 symbol_set_frag (sym
, frag_now
);
3557 S_SET_VALUE (sym
, frag_now_fix ());
3558 S_SET_STORAGE_CLASS (sym
, C_FCN
);
3559 S_SET_NUMBER_AUXILIARY (sym
, 1);
3560 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3561 symbol_get_tc (sym
)->output
= 1;
3563 ppc_frob_label (sym
);
3565 demand_empty_rest_of_line ();
3568 /* The .bi and .ei pseudo-ops. These take a string argument and
3569 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3570 the symbol list. The value of .bi will be know when the next .bf
3577 static symbolS
*last_biei
;
3584 name
= demand_copy_C_string (&len
);
3586 /* The value of these symbols is actually file offset. Here we set
3587 the value to the index into the line number entries. In
3588 ppc_frob_symbols we set the fix_line field, which will cause BFD
3589 to do the right thing. */
3591 sym
= symbol_make (name
);
3592 /* obj-coff.c currently only handles line numbers correctly in the
3594 S_SET_SEGMENT (sym
, text_section
);
3595 S_SET_VALUE (sym
, coff_n_line_nos
);
3596 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3598 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
3599 symbol_get_tc (sym
)->output
= 1;
3607 for (look
= last_biei
? last_biei
: symbol_rootP
;
3608 (look
!= (symbolS
*) NULL
3609 && (S_GET_STORAGE_CLASS (look
) == C_FILE
3610 || S_GET_STORAGE_CLASS (look
) == C_BINCL
3611 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
3612 look
= symbol_next (look
))
3614 if (look
!= (symbolS
*) NULL
)
3616 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3617 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
3621 demand_empty_rest_of_line ();
3624 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3625 There is one argument, which is a csect symbol. The value of the
3626 .bs symbol is the index of this csect symbol. */
3630 int ignore ATTRIBUTE_UNUSED
;
3637 if (ppc_current_block
!= NULL
)
3638 as_bad (_("nested .bs blocks"));
3640 name
= input_line_pointer
;
3641 endc
= get_symbol_end ();
3643 csect
= symbol_find_or_make (name
);
3645 *input_line_pointer
= endc
;
3647 sym
= symbol_make (".bs");
3648 S_SET_SEGMENT (sym
, now_seg
);
3649 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
3650 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3651 symbol_get_tc (sym
)->output
= 1;
3653 symbol_get_tc (sym
)->within
= csect
;
3655 ppc_frob_label (sym
);
3657 ppc_current_block
= sym
;
3659 demand_empty_rest_of_line ();
3662 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3666 int ignore ATTRIBUTE_UNUSED
;
3670 if (ppc_current_block
== NULL
)
3671 as_bad (_(".es without preceding .bs"));
3673 sym
= symbol_make (".es");
3674 S_SET_SEGMENT (sym
, now_seg
);
3675 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
3676 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3677 symbol_get_tc (sym
)->output
= 1;
3679 ppc_frob_label (sym
);
3681 ppc_current_block
= NULL
;
3683 demand_empty_rest_of_line ();
3686 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3691 int ignore ATTRIBUTE_UNUSED
;
3695 sym
= symbol_make (".bb");
3696 S_SET_SEGMENT (sym
, text_section
);
3697 symbol_set_frag (sym
, frag_now
);
3698 S_SET_VALUE (sym
, frag_now_fix ());
3699 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3701 S_SET_NUMBER_AUXILIARY (sym
, 1);
3702 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3704 symbol_get_tc (sym
)->output
= 1;
3706 SF_SET_PROCESS (sym
);
3708 ppc_frob_label (sym
);
3710 demand_empty_rest_of_line ();
3713 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3718 int ignore ATTRIBUTE_UNUSED
;
3722 sym
= symbol_make (".eb");
3723 S_SET_SEGMENT (sym
, text_section
);
3724 symbol_set_frag (sym
, frag_now
);
3725 S_SET_VALUE (sym
, frag_now_fix ());
3726 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
3727 S_SET_NUMBER_AUXILIARY (sym
, 1);
3728 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
3729 symbol_get_tc (sym
)->output
= 1;
3731 SF_SET_PROCESS (sym
);
3733 ppc_frob_label (sym
);
3735 demand_empty_rest_of_line ();
3738 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3743 int ignore ATTRIBUTE_UNUSED
;
3749 name
= demand_copy_C_string (&len
);
3750 sym
= symbol_make (name
);
3751 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3752 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3753 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
3754 S_SET_VALUE (sym
, 0);
3755 symbol_get_tc (sym
)->output
= 1;
3757 ppc_frob_label (sym
);
3759 demand_empty_rest_of_line ();
3762 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3766 int ignore ATTRIBUTE_UNUSED
;
3770 sym
= symbol_make (".ec");
3771 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
3772 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
3773 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
3774 S_SET_VALUE (sym
, 0);
3775 symbol_get_tc (sym
)->output
= 1;
3777 ppc_frob_label (sym
);
3779 demand_empty_rest_of_line ();
3782 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3786 int ignore ATTRIBUTE_UNUSED
;
3788 if (ppc_toc_csect
!= (symbolS
*) NULL
)
3789 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
3796 subseg
= ppc_data_subsegment
;
3797 ++ppc_data_subsegment
;
3799 subseg_new (segment_name (data_section
), subseg
);
3800 ppc_toc_frag
= frag_now
;
3802 sym
= symbol_find_or_make ("TOC[TC0]");
3803 symbol_set_frag (sym
, frag_now
);
3804 S_SET_SEGMENT (sym
, data_section
);
3805 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3806 symbol_get_tc (sym
)->subseg
= subseg
;
3807 symbol_get_tc (sym
)->output
= 1;
3808 symbol_get_tc (sym
)->within
= sym
;
3810 ppc_toc_csect
= sym
;
3812 for (list
= ppc_data_csects
;
3813 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3814 list
= symbol_get_tc (list
)->next
)
3816 symbol_get_tc (list
)->next
= sym
;
3818 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3819 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3823 ppc_current_csect
= ppc_toc_csect
;
3825 demand_empty_rest_of_line ();
3828 /* The AIX assembler automatically aligns the operands of a .long or
3829 .short pseudo-op, and we want to be compatible. */
3832 ppc_xcoff_cons (log_size
)
3835 frag_align (log_size
, 0, 0);
3836 record_alignment (now_seg
, log_size
);
3837 cons (1 << log_size
);
3842 int dummy ATTRIBUTE_UNUSED
;
3847 (void) expression (&exp
);
3849 if (exp
.X_op
!= O_constant
)
3851 as_bad (_("non-constant byte count"));
3855 byte_count
= exp
.X_add_number
;
3857 if (*input_line_pointer
!= ',')
3859 as_bad (_("missing value"));
3863 ++input_line_pointer
;
3867 #endif /* OBJ_XCOFF */
3868 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3870 /* The .tc pseudo-op. This is used when generating either XCOFF or
3871 ELF. This takes two or more arguments.
3873 When generating XCOFF output, the first argument is the name to
3874 give to this location in the toc; this will be a symbol with class
3875 TC. The rest of the arguments are N-byte values to actually put at
3876 this location in the TOC; often there is just one more argument, a
3877 relocatable symbol reference. The size of the value to store
3878 depends on target word size. A 32-bit target uses 4-byte values, a
3879 64-bit target uses 8-byte values.
3881 When not generating XCOFF output, the arguments are the same, but
3882 the first argument is simply ignored. */
3886 int ignore ATTRIBUTE_UNUSED
;
3890 /* Define the TOC symbol name. */
3896 if (ppc_toc_csect
== (symbolS
*) NULL
3897 || ppc_toc_csect
!= ppc_current_csect
)
3899 as_bad (_(".tc not in .toc section"));
3900 ignore_rest_of_line ();
3904 name
= input_line_pointer
;
3905 endc
= get_symbol_end ();
3907 sym
= symbol_find_or_make (name
);
3909 *input_line_pointer
= endc
;
3911 if (S_IS_DEFINED (sym
))
3915 label
= symbol_get_tc (ppc_current_csect
)->within
;
3916 if (symbol_get_tc (label
)->class != XMC_TC0
)
3918 as_bad (_(".tc with no label"));
3919 ignore_rest_of_line ();
3923 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
3924 symbol_set_frag (label
, symbol_get_frag (sym
));
3925 S_SET_VALUE (label
, S_GET_VALUE (sym
));
3927 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3928 ++input_line_pointer
;
3933 S_SET_SEGMENT (sym
, now_seg
);
3934 symbol_set_frag (sym
, frag_now
);
3935 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3936 symbol_get_tc (sym
)->class = XMC_TC
;
3937 symbol_get_tc (sym
)->output
= 1;
3939 ppc_frob_label (sym
);
3942 #endif /* OBJ_XCOFF */
3946 /* Skip the TOC symbol name. */
3947 while (is_part_of_name (*input_line_pointer
)
3948 || *input_line_pointer
== '['
3949 || *input_line_pointer
== ']'
3950 || *input_line_pointer
== '{'
3951 || *input_line_pointer
== '}')
3952 ++input_line_pointer
;
3954 /* Align to a four/eight byte boundary. */
3955 align
= ppc_obj64
? 3 : 2;
3956 frag_align (align
, 0, 0);
3957 record_alignment (now_seg
, align
);
3958 #endif /* OBJ_ELF */
3960 if (*input_line_pointer
!= ',')
3961 demand_empty_rest_of_line ();
3964 ++input_line_pointer
;
3965 cons (ppc_obj64
? 8 : 4);
3969 /* Pseudo-op .machine. */
3970 /* FIXME: `.machine' is a nop for the moment. It would be nice to
3971 accept this directive on the first line of input and set ppc_obj64
3972 and the target format accordingly. Unfortunately, the target
3973 format is selected in output-file.c:output_file_create before we
3974 even get to md_begin, so it's not possible without changing
3978 ppc_machine (ignore
)
3979 int ignore ATTRIBUTE_UNUSED
;
3981 discard_rest_of_line ();
3984 /* See whether a symbol is in the TOC section. */
3987 ppc_is_toc_sym (sym
)
3991 return symbol_get_tc (sym
)->class == XMC_TC
;
3994 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
3996 return strcmp (sname
, ".toc") == 0;
3998 return strcmp (sname
, ".got") == 0;
4001 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4005 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4007 /* Set the current section. */
4009 ppc_set_current_section (new)
4012 ppc_previous_section
= ppc_current_section
;
4013 ppc_current_section
= new;
4016 /* pseudo-op: .previous
4017 behaviour: toggles the current section with the previous section.
4019 warnings: "No previous section" */
4022 ppc_previous (ignore
)
4023 int ignore ATTRIBUTE_UNUSED
;
4027 if (ppc_previous_section
== NULL
)
4029 as_warn (_("No previous section to return to. Directive ignored."));
4033 subseg_set (ppc_previous_section
, 0);
4035 ppc_set_current_section (ppc_previous_section
);
4038 /* pseudo-op: .pdata
4039 behaviour: predefined read only data section
4043 initial: .section .pdata "adr3"
4044 a - don't know -- maybe a misprint
4045 d - initialized data
4047 3 - double word aligned (that would be 4 byte boundary)
4050 Tag index tables (also known as the function table) for exception
4051 handling, debugging, etc. */
4055 int ignore ATTRIBUTE_UNUSED
;
4057 if (pdata_section
== 0)
4059 pdata_section
= subseg_new (".pdata", 0);
4061 bfd_set_section_flags (stdoutput
, pdata_section
,
4062 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4063 | SEC_READONLY
| SEC_DATA
));
4065 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4069 pdata_section
= subseg_new (".pdata", 0);
4071 ppc_set_current_section (pdata_section
);
4074 /* pseudo-op: .ydata
4075 behaviour: predefined read only data section
4079 initial: .section .ydata "drw3"
4080 a - don't know -- maybe a misprint
4081 d - initialized data
4083 3 - double word aligned (that would be 4 byte boundary)
4085 Tag tables (also known as the scope table) for exception handling,
4090 int ignore ATTRIBUTE_UNUSED
;
4092 if (ydata_section
== 0)
4094 ydata_section
= subseg_new (".ydata", 0);
4095 bfd_set_section_flags (stdoutput
, ydata_section
,
4096 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4097 | SEC_READONLY
| SEC_DATA
));
4099 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4103 ydata_section
= subseg_new (".ydata", 0);
4105 ppc_set_current_section (ydata_section
);
4108 /* pseudo-op: .reldata
4109 behaviour: predefined read write data section
4110 double word aligned (4-byte)
4111 FIXME: relocation is applied to it
4112 FIXME: what's the difference between this and .data?
4115 initial: .section .reldata "drw3"
4116 d - initialized data
4119 3 - double word aligned (that would be 8 byte boundary)
4122 Like .data, but intended to hold data subject to relocation, such as
4123 function descriptors, etc. */
4126 ppc_reldata (ignore
)
4127 int ignore ATTRIBUTE_UNUSED
;
4129 if (reldata_section
== 0)
4131 reldata_section
= subseg_new (".reldata", 0);
4133 bfd_set_section_flags (stdoutput
, reldata_section
,
4134 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4137 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4141 reldata_section
= subseg_new (".reldata", 0);
4143 ppc_set_current_section (reldata_section
);
4146 /* pseudo-op: .rdata
4147 behaviour: predefined read only data section
4151 initial: .section .rdata "dr3"
4152 d - initialized data
4154 3 - double word aligned (that would be 4 byte boundary) */
4158 int ignore ATTRIBUTE_UNUSED
;
4160 if (rdata_section
== 0)
4162 rdata_section
= subseg_new (".rdata", 0);
4163 bfd_set_section_flags (stdoutput
, rdata_section
,
4164 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4165 | SEC_READONLY
| SEC_DATA
));
4167 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
4171 rdata_section
= subseg_new (".rdata", 0);
4173 ppc_set_current_section (rdata_section
);
4176 /* pseudo-op: .ualong
4177 behaviour: much like .int, with the exception that no alignment is
4179 FIXME: test the alignment statement
4185 int ignore ATTRIBUTE_UNUSED
;
4191 /* pseudo-op: .znop <symbol name>
4192 behaviour: Issue a nop instruction
4193 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4194 the supplied symbol name.
4196 warnings: Missing symbol name */
4200 int ignore ATTRIBUTE_UNUSED
;
4203 const struct powerpc_opcode
*opcode
;
4214 /* Strip out the symbol name. */
4215 symbol_name
= input_line_pointer
;
4216 c
= get_symbol_end ();
4218 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
4219 strcpy (name
, symbol_name
);
4221 sym
= symbol_find_or_make (name
);
4223 *input_line_pointer
= c
;
4227 /* Look up the opcode in the hash table. */
4228 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
4230 /* Stick in the nop. */
4231 insn
= opcode
->opcode
;
4233 /* Write out the instruction. */
4235 md_number_to_chars (f
, insn
, 4);
4237 f
- frag_now
->fr_literal
,
4242 BFD_RELOC_16_GOT_PCREL
);
4255 register char *name
;
4259 register symbolS
*symbolP
;
4262 name
= input_line_pointer
;
4263 c
= get_symbol_end ();
4265 /* just after name is now '\0'. */
4266 p
= input_line_pointer
;
4269 if (*input_line_pointer
!= ',')
4271 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4272 ignore_rest_of_line ();
4276 input_line_pointer
++; /* skip ',' */
4277 if ((temp
= get_absolute_expression ()) < 0)
4279 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
4280 ignore_rest_of_line ();
4286 /* The third argument to .comm is the alignment. */
4287 if (*input_line_pointer
!= ',')
4291 ++input_line_pointer
;
4292 align
= get_absolute_expression ();
4295 as_warn (_("ignoring bad alignment"));
4302 symbolP
= symbol_find_or_make (name
);
4305 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
4307 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4308 S_GET_NAME (symbolP
));
4309 ignore_rest_of_line ();
4313 if (S_GET_VALUE (symbolP
))
4315 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
4316 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4317 S_GET_NAME (symbolP
),
4318 (long) S_GET_VALUE (symbolP
),
4323 S_SET_VALUE (symbolP
, (valueT
) temp
);
4324 S_SET_EXTERNAL (symbolP
);
4327 demand_empty_rest_of_line ();
4331 * implement the .section pseudo op:
4332 * .section name {, "flags"}
4334 * | +--- optional flags: 'b' for bss
4336 * +-- section name 'l' for lib
4340 * 'd' (apparently m88k for data)
4342 * But if the argument is not a quoted string, treat it as a
4343 * subsegment number.
4345 * FIXME: this is a copy of the section processing from obj-coff.c, with
4346 * additions/changes for the moto-pas assembler support. There are three
4349 * FIXME: I just noticed this. This doesn't work at all really. It it
4350 * setting bits that bfd probably neither understands or uses. The
4351 * correct approach (?) will have to incorporate extra fields attached
4352 * to the section to hold the system specific stuff. (krk)
4355 * 'a' - unknown - referred to in documentation, but no definition supplied
4356 * 'c' - section has code
4357 * 'd' - section has initialized data
4358 * 'u' - section has uninitialized data
4359 * 'i' - section contains directives (info)
4360 * 'n' - section can be discarded
4361 * 'R' - remove section at link time
4363 * Section Protection:
4364 * 'r' - section is readable
4365 * 'w' - section is writeable
4366 * 'x' - section is executable
4367 * 's' - section is sharable
4369 * Section Alignment:
4370 * '0' - align to byte boundary
4371 * '1' - align to halfword undary
4372 * '2' - align to word boundary
4373 * '3' - align to doubleword boundary
4374 * '4' - align to quadword boundary
4375 * '5' - align to 32 byte boundary
4376 * '6' - align to 64 byte boundary
4381 ppc_pe_section (ignore
)
4382 int ignore ATTRIBUTE_UNUSED
;
4384 /* Strip out the section name. */
4393 section_name
= input_line_pointer
;
4394 c
= get_symbol_end ();
4396 name
= xmalloc (input_line_pointer
- section_name
+ 1);
4397 strcpy (name
, section_name
);
4399 *input_line_pointer
= c
;
4404 flags
= SEC_NO_FLAGS
;
4406 if (strcmp (name
, ".idata$2") == 0)
4410 else if (strcmp (name
, ".idata$3") == 0)
4414 else if (strcmp (name
, ".idata$4") == 0)
4418 else if (strcmp (name
, ".idata$5") == 0)
4422 else if (strcmp (name
, ".idata$6") == 0)
4427 /* Default alignment to 16 byte boundary. */
4430 if (*input_line_pointer
== ',')
4432 ++input_line_pointer
;
4434 if (*input_line_pointer
!= '"')
4435 exp
= get_absolute_expression ();
4438 ++input_line_pointer
;
4439 while (*input_line_pointer
!= '"'
4440 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
4442 switch (*input_line_pointer
)
4444 /* Section Contents */
4445 case 'a': /* unknown */
4446 as_bad (_("Unsupported section attribute -- 'a'"));
4448 case 'c': /* code section */
4451 case 'd': /* section has initialized data */
4454 case 'u': /* section has uninitialized data */
4455 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4459 case 'i': /* section contains directives (info) */
4460 /* FIXME: This is IMAGE_SCN_LNK_INFO
4462 flags
|= SEC_HAS_CONTENTS
;
4464 case 'n': /* section can be discarded */
4467 case 'R': /* Remove section at link time */
4468 flags
|= SEC_NEVER_LOAD
;
4471 /* Section Protection */
4472 case 'r': /* section is readable */
4473 flags
|= IMAGE_SCN_MEM_READ
;
4475 case 'w': /* section is writeable */
4476 flags
|= IMAGE_SCN_MEM_WRITE
;
4478 case 'x': /* section is executable */
4479 flags
|= IMAGE_SCN_MEM_EXECUTE
;
4481 case 's': /* section is sharable */
4482 flags
|= IMAGE_SCN_MEM_SHARED
;
4485 /* Section Alignment */
4486 case '0': /* align to byte boundary */
4487 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
4490 case '1': /* align to halfword boundary */
4491 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
4494 case '2': /* align to word boundary */
4495 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
4498 case '3': /* align to doubleword boundary */
4499 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
4502 case '4': /* align to quadword boundary */
4503 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
4506 case '5': /* align to 32 byte boundary */
4507 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
4510 case '6': /* align to 64 byte boundary */
4511 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
4516 as_bad (_("unknown section attribute '%c'"),
4517 *input_line_pointer
);
4520 ++input_line_pointer
;
4522 if (*input_line_pointer
== '"')
4523 ++input_line_pointer
;
4527 sec
= subseg_new (name
, (subsegT
) exp
);
4529 ppc_set_current_section (sec
);
4531 if (flags
!= SEC_NO_FLAGS
)
4533 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
4534 as_bad (_("error setting flags for \"%s\": %s"),
4535 bfd_section_name (stdoutput
, sec
),
4536 bfd_errmsg (bfd_get_error ()));
4539 bfd_set_section_alignment (stdoutput
, sec
, align
);
4544 ppc_pe_function (ignore
)
4545 int ignore ATTRIBUTE_UNUSED
;
4551 name
= input_line_pointer
;
4552 endc
= get_symbol_end ();
4554 ext_sym
= symbol_find_or_make (name
);
4556 *input_line_pointer
= endc
;
4558 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4559 SF_SET_FUNCTION (ext_sym
);
4560 SF_SET_PROCESS (ext_sym
);
4561 coff_add_linesym (ext_sym
);
4563 demand_empty_rest_of_line ();
4567 ppc_pe_tocd (ignore
)
4568 int ignore ATTRIBUTE_UNUSED
;
4570 if (tocdata_section
== 0)
4572 tocdata_section
= subseg_new (".tocd", 0);
4573 /* FIXME: section flags won't work. */
4574 bfd_set_section_flags (stdoutput
, tocdata_section
,
4575 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4576 | SEC_READONLY
| SEC_DATA
));
4578 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
4582 rdata_section
= subseg_new (".tocd", 0);
4585 ppc_set_current_section (tocdata_section
);
4587 demand_empty_rest_of_line ();
4590 /* Don't adjust TOC relocs to use the section symbol. */
4593 ppc_pe_fix_adjustable (fix
)
4596 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
4603 /* XCOFF specific symbol and file handling. */
4605 /* Canonicalize the symbol name. We use the to force the suffix, if
4606 any, to use square brackets, and to be in upper case. */
4609 ppc_canonicalize_symbol_name (name
)
4614 if (ppc_stab_symbol
)
4617 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
4631 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
4634 if (*s
== '\0' || s
[1] != '\0')
4635 as_bad (_("bad symbol suffix"));
4643 /* Set the class of a symbol based on the suffix, if any. This is
4644 called whenever a new symbol is created. */
4647 ppc_symbol_new_hook (sym
)
4650 struct ppc_tc_sy
*tc
;
4653 tc
= symbol_get_tc (sym
);
4657 tc
->real_name
= NULL
;
4663 if (ppc_stab_symbol
)
4666 s
= strchr (S_GET_NAME (sym
), '[');
4667 if (s
== (const char *) NULL
)
4669 /* There is no suffix. */
4678 if (strcmp (s
, "BS]") == 0)
4682 if (strcmp (s
, "DB]") == 0)
4684 else if (strcmp (s
, "DS]") == 0)
4688 if (strcmp (s
, "GL]") == 0)
4692 if (strcmp (s
, "PR]") == 0)
4696 if (strcmp (s
, "RO]") == 0)
4698 else if (strcmp (s
, "RW]") == 0)
4702 if (strcmp (s
, "SV]") == 0)
4706 if (strcmp (s
, "TC]") == 0)
4708 else if (strcmp (s
, "TI]") == 0)
4710 else if (strcmp (s
, "TB]") == 0)
4712 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
4713 tc
->class = XMC_TC0
;
4716 if (strcmp (s
, "UA]") == 0)
4718 else if (strcmp (s
, "UC]") == 0)
4722 if (strcmp (s
, "XO]") == 0)
4727 if (tc
->class == -1)
4728 as_bad (_("Unrecognized symbol suffix"));
4731 /* Set the class of a label based on where it is defined. This
4732 handles symbols without suffixes. Also, move the symbol so that it
4733 follows the csect symbol. */
4736 ppc_frob_label (sym
)
4739 if (ppc_current_csect
!= (symbolS
*) NULL
)
4741 if (symbol_get_tc (sym
)->class == -1)
4742 symbol_get_tc (sym
)->class = symbol_get_tc (ppc_current_csect
)->class;
4744 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4745 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
4746 &symbol_rootP
, &symbol_lastP
);
4747 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4751 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4752 seen. It tells ppc_adjust_symtab whether it needs to look through
4755 static bfd_boolean ppc_saw_abs
;
4757 /* Change the name of a symbol just before writing it out. Set the
4758 real name if the .rename pseudo-op was used. Otherwise, remove any
4759 class suffix. Return 1 if the symbol should not be included in the
4763 ppc_frob_symbol (sym
)
4766 static symbolS
*ppc_last_function
;
4767 static symbolS
*set_end
;
4769 /* Discard symbols that should not be included in the output symbol
4771 if (! symbol_used_in_reloc_p (sym
)
4772 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
4773 || (! S_IS_EXTERNAL (sym
)
4774 && ! symbol_get_tc (sym
)->output
4775 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
4778 /* This one will disappear anyway. Don't make a csect sym for it. */
4779 if (sym
== abs_section_sym
)
4782 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
4783 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
4789 name
= S_GET_NAME (sym
);
4790 s
= strchr (name
, '[');
4791 if (s
!= (char *) NULL
)
4797 snew
= xmalloc (len
+ 1);
4798 memcpy (snew
, name
, len
);
4801 S_SET_NAME (sym
, snew
);
4805 if (set_end
!= (symbolS
*) NULL
)
4807 SA_SET_SYM_ENDNDX (set_end
, sym
);
4811 if (SF_GET_FUNCTION (sym
))
4813 if (ppc_last_function
!= (symbolS
*) NULL
)
4814 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4815 ppc_last_function
= sym
;
4816 if (symbol_get_tc (sym
)->size
!= (symbolS
*) NULL
)
4818 resolve_symbol_value (symbol_get_tc (sym
)->size
);
4819 SA_SET_SYM_FSIZE (sym
,
4820 (long) S_GET_VALUE (symbol_get_tc (sym
)->size
));
4823 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
4824 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
4826 if (ppc_last_function
== (symbolS
*) NULL
)
4827 as_bad (_(".ef with no preceding .function"));
4830 set_end
= ppc_last_function
;
4831 ppc_last_function
= NULL
;
4833 /* We don't have a C_EFCN symbol, but we need to force the
4834 COFF backend to believe that it has seen one. */
4835 coff_last_function
= NULL
;
4839 if (! S_IS_EXTERNAL (sym
)
4840 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
4841 && S_GET_STORAGE_CLASS (sym
) != C_FILE
4842 && S_GET_STORAGE_CLASS (sym
) != C_FCN
4843 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
4844 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
4845 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
4846 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
4847 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
4848 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
4849 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
4851 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
4852 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
4855 union internal_auxent
*a
;
4857 /* Create a csect aux. */
4858 i
= S_GET_NUMBER_AUXILIARY (sym
);
4859 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
4860 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
4861 if (symbol_get_tc (sym
)->class == XMC_TC0
)
4863 /* This is the TOC table. */
4864 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
4865 a
->x_csect
.x_scnlen
.l
= 0;
4866 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4868 else if (symbol_get_tc (sym
)->subseg
!= 0)
4870 /* This is a csect symbol. x_scnlen is the size of the
4872 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
4873 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4874 S_GET_SEGMENT (sym
))
4875 - S_GET_VALUE (sym
));
4878 resolve_symbol_value (symbol_get_tc (sym
)->next
);
4879 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
4880 - S_GET_VALUE (sym
));
4882 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
4884 else if (S_GET_SEGMENT (sym
) == bss_section
)
4886 /* This is a common symbol. */
4887 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
4888 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
4889 if (S_IS_EXTERNAL (sym
))
4890 symbol_get_tc (sym
)->class = XMC_RW
;
4892 symbol_get_tc (sym
)->class = XMC_BS
;
4894 else if (S_GET_SEGMENT (sym
) == absolute_section
)
4896 /* This is an absolute symbol. The csect will be created by
4897 ppc_adjust_symtab. */
4899 a
->x_csect
.x_smtyp
= XTY_LD
;
4900 if (symbol_get_tc (sym
)->class == -1)
4901 symbol_get_tc (sym
)->class = XMC_XO
;
4903 else if (! S_IS_DEFINED (sym
))
4905 /* This is an external symbol. */
4906 a
->x_csect
.x_scnlen
.l
= 0;
4907 a
->x_csect
.x_smtyp
= XTY_ER
;
4909 else if (symbol_get_tc (sym
)->class == XMC_TC
)
4913 /* This is a TOC definition. x_scnlen is the size of the
4915 next
= symbol_next (sym
);
4916 while (symbol_get_tc (next
)->class == XMC_TC0
)
4917 next
= symbol_next (next
);
4918 if (next
== (symbolS
*) NULL
4919 || symbol_get_tc (next
)->class != XMC_TC
)
4921 if (ppc_after_toc_frag
== (fragS
*) NULL
)
4922 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
4924 - S_GET_VALUE (sym
));
4926 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
4927 - S_GET_VALUE (sym
));
4931 resolve_symbol_value (next
);
4932 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
4933 - S_GET_VALUE (sym
));
4935 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
4941 /* This is a normal symbol definition. x_scnlen is the
4942 symbol index of the containing csect. */
4943 if (S_GET_SEGMENT (sym
) == text_section
)
4944 csect
= ppc_text_csects
;
4945 else if (S_GET_SEGMENT (sym
) == data_section
)
4946 csect
= ppc_data_csects
;
4950 /* Skip the initial dummy symbol. */
4951 csect
= symbol_get_tc (csect
)->next
;
4953 if (csect
== (symbolS
*) NULL
)
4955 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
4956 a
->x_csect
.x_scnlen
.l
= 0;
4960 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
4962 resolve_symbol_value (symbol_get_tc (csect
)->next
);
4963 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
4964 > S_GET_VALUE (sym
))
4966 csect
= symbol_get_tc (csect
)->next
;
4969 a
->x_csect
.x_scnlen
.p
=
4970 coffsymbol (symbol_get_bfdsym (csect
))->native
;
4971 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
4974 a
->x_csect
.x_smtyp
= XTY_LD
;
4977 a
->x_csect
.x_parmhash
= 0;
4978 a
->x_csect
.x_snhash
= 0;
4979 if (symbol_get_tc (sym
)->class == -1)
4980 a
->x_csect
.x_smclas
= XMC_PR
;
4982 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->class;
4983 a
->x_csect
.x_stab
= 0;
4984 a
->x_csect
.x_snstab
= 0;
4986 /* Don't let the COFF backend resort these symbols. */
4987 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
4989 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
4991 /* We want the value to be the symbol index of the referenced
4992 csect symbol. BFD will do that for us if we set the right
4994 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
4995 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
4997 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
4998 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5000 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5005 /* The value is the offset from the enclosing csect. */
5006 block
= symbol_get_tc (sym
)->within
;
5007 csect
= symbol_get_tc (block
)->within
;
5008 resolve_symbol_value (csect
);
5009 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
5011 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5012 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5014 /* We want the value to be a file offset into the line numbers.
5015 BFD will do that for us if we set the right flags. We have
5016 already set the value correctly. */
5017 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5023 /* Adjust the symbol table. This creates csect symbols for all
5024 absolute symbols. */
5027 ppc_adjust_symtab ()
5034 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5038 union internal_auxent
*a
;
5040 if (S_GET_SEGMENT (sym
) != absolute_section
)
5043 csect
= symbol_create (".abs[XO]", absolute_section
,
5044 S_GET_VALUE (sym
), &zero_address_frag
);
5045 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5046 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5047 i
= S_GET_NUMBER_AUXILIARY (csect
);
5048 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5049 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5050 a
->x_csect
.x_scnlen
.l
= 0;
5051 a
->x_csect
.x_smtyp
= XTY_SD
;
5052 a
->x_csect
.x_parmhash
= 0;
5053 a
->x_csect
.x_snhash
= 0;
5054 a
->x_csect
.x_smclas
= XMC_XO
;
5055 a
->x_csect
.x_stab
= 0;
5056 a
->x_csect
.x_snstab
= 0;
5058 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5060 i
= S_GET_NUMBER_AUXILIARY (sym
);
5061 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5062 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5063 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5066 ppc_saw_abs
= FALSE
;
5069 /* Set the VMA for a section. This is called on all the sections in
5073 ppc_frob_section (sec
)
5076 static bfd_vma vma
= 0;
5078 vma
= md_section_align (sec
, vma
);
5079 bfd_set_section_vma (stdoutput
, sec
, vma
);
5080 vma
+= bfd_section_size (stdoutput
, sec
);
5083 #endif /* OBJ_XCOFF */
5085 /* Turn a string in input_line_pointer into a floating point constant
5086 of type TYPE, and store the appropriate bytes in *LITP. The number
5087 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5088 returned, or NULL on OK. */
5091 md_atof (type
, litp
, sizep
)
5097 LITTLENUM_TYPE words
[4];
5113 return _("bad call to md_atof");
5116 t
= atof_ieee (input_line_pointer
, type
, words
);
5118 input_line_pointer
= t
;
5122 if (target_big_endian
)
5124 for (i
= 0; i
< prec
; i
++)
5126 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5132 for (i
= prec
- 1; i
>= 0; i
--)
5134 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
5142 /* Write a value out to the object file, using the appropriate
5146 md_number_to_chars (buf
, val
, n
)
5151 if (target_big_endian
)
5152 number_to_chars_bigendian (buf
, val
, n
);
5154 number_to_chars_littleendian (buf
, val
, n
);
5157 /* Align a section (I don't know why this is machine dependent). */
5160 md_section_align (seg
, addr
)
5164 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5166 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5169 /* We don't have any form of relaxing. */
5172 md_estimate_size_before_relax (fragp
, seg
)
5173 fragS
*fragp ATTRIBUTE_UNUSED
;
5174 asection
*seg ATTRIBUTE_UNUSED
;
5180 /* Convert a machine dependent frag. We never generate these. */
5183 md_convert_frag (abfd
, sec
, fragp
)
5184 bfd
*abfd ATTRIBUTE_UNUSED
;
5185 asection
*sec ATTRIBUTE_UNUSED
;
5186 fragS
*fragp ATTRIBUTE_UNUSED
;
5191 /* We have no need to default values of symbols. */
5194 md_undefined_symbol (name
)
5195 char *name ATTRIBUTE_UNUSED
;
5200 /* Functions concerning relocs. */
5202 /* The location from which a PC relative jump should be calculated,
5203 given a PC relative reloc. */
5206 md_pcrel_from_section (fixp
, sec
)
5208 segT sec ATTRIBUTE_UNUSED
;
5210 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5215 /* This is called to see whether a fixup should be adjusted to use a
5216 section symbol. We take the opportunity to change a fixup against
5217 a symbol in the TOC subsegment into a reloc against the
5218 corresponding .tc symbol. */
5221 ppc_fix_adjustable (fix
)
5224 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
5225 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
5226 TC_SYMFIELD_TYPE
*tc
;
5228 if (symseg
== absolute_section
)
5231 if (ppc_toc_csect
!= (symbolS
*) NULL
5232 && fix
->fx_addsy
!= ppc_toc_csect
5233 && symseg
== data_section
5234 && val
>= ppc_toc_frag
->fr_address
5235 && (ppc_after_toc_frag
== (fragS
*) NULL
5236 || val
< ppc_after_toc_frag
->fr_address
))
5240 for (sy
= symbol_next (ppc_toc_csect
);
5241 sy
!= (symbolS
*) NULL
;
5242 sy
= symbol_next (sy
))
5244 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
5246 if (sy_tc
->class == XMC_TC0
)
5248 if (sy_tc
->class != XMC_TC
)
5250 if (val
== resolve_symbol_value (sy
))
5253 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
5258 as_bad_where (fix
->fx_file
, fix
->fx_line
,
5259 _("symbol in .toc does not match any .tc"));
5262 /* Possibly adjust the reloc to be against the csect. */
5263 tc
= symbol_get_tc (fix
->fx_addsy
);
5265 && tc
->class != XMC_TC0
5266 && tc
->class != XMC_TC
5267 && symseg
!= bss_section
5268 /* Don't adjust if this is a reloc in the toc section. */
5269 && (symseg
!= data_section
5270 || ppc_toc_csect
== NULL
5271 || val
< ppc_toc_frag
->fr_address
5272 || (ppc_after_toc_frag
!= NULL
5273 && val
>= ppc_after_toc_frag
->fr_address
)))
5276 symbolS
*next_csect
;
5278 if (symseg
== text_section
)
5279 csect
= ppc_text_csects
;
5280 else if (symseg
== data_section
)
5281 csect
= ppc_data_csects
;
5285 /* Skip the initial dummy symbol. */
5286 csect
= symbol_get_tc (csect
)->next
;
5288 if (csect
!= (symbolS
*) NULL
)
5290 while ((next_csect
= symbol_get_tc (csect
)->next
) != (symbolS
*) NULL
5291 && (symbol_get_frag (next_csect
)->fr_address
<= val
))
5293 /* If the csect address equals the symbol value, then we
5294 have to look through the full symbol table to see
5295 whether this is the csect we want. Note that we will
5296 only get here if the csect has zero length. */
5297 if (symbol_get_frag (csect
)->fr_address
== val
5298 && S_GET_VALUE (csect
) == val
)
5302 for (scan
= symbol_next (csect
);
5304 scan
= symbol_next (scan
))
5306 if (symbol_get_tc (scan
)->subseg
!= 0)
5308 if (scan
== fix
->fx_addsy
)
5312 /* If we found the symbol before the next csect
5313 symbol, then this is the csect we want. */
5314 if (scan
== fix
->fx_addsy
)
5321 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
5322 fix
->fx_addsy
= csect
;
5327 /* Adjust a reloc against a .lcomm symbol to be against the base
5329 if (symseg
== bss_section
5330 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
5332 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
5334 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
5341 /* A reloc from one csect to another must be kept. The assembler
5342 will, of course, keep relocs between sections, and it will keep
5343 absolute relocs, but we need to force it to keep PC relative relocs
5344 between two csects in the same section. */
5347 ppc_force_relocation (fix
)
5350 /* At this point fix->fx_addsy should already have been converted to
5351 a csect symbol. If the csect does not include the fragment, then
5352 we need to force the relocation. */
5354 && fix
->fx_addsy
!= NULL
5355 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
5356 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
5357 > fix
->fx_frag
->fr_address
)
5358 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
5359 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
5360 <= fix
->fx_frag
->fr_address
))))
5363 return generic_force_reloc (fix
);
5366 #endif /* OBJ_XCOFF */
5369 /* If this function returns non-zero, it guarantees that a relocation
5370 will be emitted for a fixup. */
5373 ppc_force_relocation (fix
)
5376 /* Branch prediction relocations must force a relocation, as must
5377 the vtable description relocs. */
5378 switch (fix
->fx_r_type
)
5380 case BFD_RELOC_PPC_B16_BRTAKEN
:
5381 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5382 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5383 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5384 case BFD_RELOC_PPC64_TOC
:
5390 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5391 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5394 return generic_force_reloc (fix
);
5398 ppc_fix_adjustable (fix
)
5401 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
5402 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
5403 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
5404 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
5405 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
5406 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
5407 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
5408 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
5409 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
5411 || (fix
->fx_subsy
!= NULL
5412 && (S_GET_SEGMENT (fix
->fx_subsy
)
5413 == S_GET_SEGMENT (fix
->fx_addsy
)))
5414 || S_IS_LOCAL (fix
->fx_addsy
)));
5418 /* Apply a fixup to the object code. This is called for all the
5419 fixups we generated by the call to fix_new_exp, above. In the call
5420 above we used a reloc code which was the largest legal reloc code
5421 plus the operand index. Here we undo that to recover the operand
5422 index. At this point all symbol values should be fully resolved,
5423 and we attempt to completely resolve the reloc. If we can not do
5424 that, we determine the correct reloc code and put it back in the
5428 md_apply_fix3 (fixP
, valP
, seg
)
5431 segT seg ATTRIBUTE_UNUSED
;
5433 valueT value
= * valP
;
5436 if (fixP
->fx_addsy
!= NULL
)
5438 /* Hack around bfd_install_relocation brain damage. */
5440 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
5445 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5446 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5447 doing this relocation the code in write.c is going to call
5448 bfd_install_relocation, which is also going to use the symbol
5449 value. That means that if the reloc is fully resolved we want to
5450 use *valP since bfd_install_relocation is not being used.
5451 However, if the reloc is not fully resolved we do not want to use
5452 *valP, and must use fx_offset instead. However, if the reloc
5453 is PC relative, we do want to use *valP since it includes the
5454 result of md_pcrel_from. This is confusing. */
5455 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
5458 else if (fixP
->fx_pcrel
)
5462 value
= fixP
->fx_offset
;
5465 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
5467 /* We can't actually support subtracting a symbol. */
5468 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
5471 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
5474 const struct powerpc_operand
*operand
;
5478 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
5480 operand
= &powerpc_operands
[opindex
];
5483 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5484 does not generate a reloc. It uses the offset of `sym' within its
5485 csect. Other usages, such as `.long sym', generate relocs. This
5486 is the documented behaviour of non-TOC symbols. */
5487 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5488 && operand
->bits
== 16
5489 && operand
->shift
== 0
5490 && (operand
->insert
== NULL
|| ppc_obj64
)
5491 && fixP
->fx_addsy
!= NULL
5492 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
5493 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC
5494 && symbol_get_tc (fixP
->fx_addsy
)->class != XMC_TC0
5495 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
5497 value
= fixP
->fx_offset
;
5502 /* Fetch the instruction, insert the fully resolved operand
5503 value, and stuff the instruction back again. */
5504 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5505 if (target_big_endian
)
5506 insn
= bfd_getb32 ((unsigned char *) where
);
5508 insn
= bfd_getl32 ((unsigned char *) where
);
5509 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
5510 fixP
->fx_file
, fixP
->fx_line
);
5511 if (target_big_endian
)
5512 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5514 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5517 /* Nothing else to do here. */
5520 assert (fixP
->fx_addsy
!= NULL
);
5522 /* Determine a BFD reloc value based on the operand information.
5523 We are only prepared to turn a few of the operands into
5525 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5526 && operand
->bits
== 26
5527 && operand
->shift
== 0)
5528 fixP
->fx_r_type
= BFD_RELOC_PPC_B26
;
5529 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
5530 && operand
->bits
== 16
5531 && operand
->shift
== 0)
5533 fixP
->fx_r_type
= BFD_RELOC_PPC_B16
;
5536 if (target_big_endian
)
5537 fixP
->fx_where
+= 2;
5540 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5541 && operand
->bits
== 26
5542 && operand
->shift
== 0)
5543 fixP
->fx_r_type
= BFD_RELOC_PPC_BA26
;
5544 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
5545 && operand
->bits
== 16
5546 && operand
->shift
== 0)
5548 fixP
->fx_r_type
= BFD_RELOC_PPC_BA16
;
5551 if (target_big_endian
)
5552 fixP
->fx_where
+= 2;
5555 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5556 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
5557 && operand
->bits
== 16
5558 && operand
->shift
== 0)
5560 if (ppc_is_toc_sym (fixP
->fx_addsy
))
5562 fixP
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
5565 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5566 fixP
->fx_r_type
= BFD_RELOC_PPC64_TOC16_DS
;
5571 fixP
->fx_r_type
= BFD_RELOC_16
;
5574 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
5575 fixP
->fx_r_type
= BFD_RELOC_PPC64_ADDR16_DS
;
5579 if (target_big_endian
)
5580 fixP
->fx_where
+= 2;
5582 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5588 /* Use expr_symbol_where to see if this is an expression
5590 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
5591 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5592 _("unresolved expression that must be resolved"));
5594 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5595 _("unsupported relocation against %s"),
5596 S_GET_NAME (fixP
->fx_addsy
));
5604 ppc_elf_validate_fix (fixP
, seg
);
5606 switch (fixP
->fx_r_type
)
5608 case BFD_RELOC_CTOR
:
5615 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
5619 case BFD_RELOC_32_PCREL
:
5620 case BFD_RELOC_PPC_EMB_NADDR32
:
5621 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5628 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
5631 case BFD_RELOC_64_PCREL
:
5632 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5636 case BFD_RELOC_LO16
:
5638 case BFD_RELOC_GPREL16
:
5639 case BFD_RELOC_16_GOT_PCREL
:
5640 case BFD_RELOC_16_GOTOFF
:
5641 case BFD_RELOC_LO16_GOTOFF
:
5642 case BFD_RELOC_HI16_GOTOFF
:
5643 case BFD_RELOC_HI16_S_GOTOFF
:
5644 case BFD_RELOC_16_BASEREL
:
5645 case BFD_RELOC_LO16_BASEREL
:
5646 case BFD_RELOC_HI16_BASEREL
:
5647 case BFD_RELOC_HI16_S_BASEREL
:
5648 case BFD_RELOC_PPC_EMB_NADDR16
:
5649 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
5650 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
5651 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
5652 case BFD_RELOC_PPC_EMB_SDAI16
:
5653 case BFD_RELOC_PPC_EMB_SDA2REL
:
5654 case BFD_RELOC_PPC_EMB_SDA2I16
:
5655 case BFD_RELOC_PPC_EMB_RELSEC16
:
5656 case BFD_RELOC_PPC_EMB_RELST_LO
:
5657 case BFD_RELOC_PPC_EMB_RELST_HI
:
5658 case BFD_RELOC_PPC_EMB_RELST_HA
:
5659 case BFD_RELOC_PPC_EMB_RELSDA
:
5660 case BFD_RELOC_PPC_TOC16
:
5662 case BFD_RELOC_PPC64_TOC16_LO
:
5663 case BFD_RELOC_PPC64_TOC16_HI
:
5664 case BFD_RELOC_PPC64_TOC16_HA
:
5668 if (fixP
->fx_addsy
!= NULL
)
5669 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5670 _("cannot emit PC relative %s relocation against %s"),
5671 bfd_get_reloc_code_name (fixP
->fx_r_type
),
5672 S_GET_NAME (fixP
->fx_addsy
));
5674 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5675 _("cannot emit PC relative %s relocation"),
5676 bfd_get_reloc_code_name (fixP
->fx_r_type
));
5679 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5683 /* This case happens when you write, for example,
5685 where L1 and L2 are defined later. */
5686 case BFD_RELOC_HI16
:
5689 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5693 case BFD_RELOC_HI16_S
:
5696 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5701 case BFD_RELOC_PPC64_HIGHER
:
5704 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5705 PPC_HIGHER (value
), 2);
5708 case BFD_RELOC_PPC64_HIGHER_S
:
5711 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5712 PPC_HIGHERA (value
), 2);
5715 case BFD_RELOC_PPC64_HIGHEST
:
5718 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5719 PPC_HIGHEST (value
), 2);
5722 case BFD_RELOC_PPC64_HIGHEST_S
:
5725 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5726 PPC_HIGHESTA (value
), 2);
5729 case BFD_RELOC_PPC64_ADDR16_DS
:
5730 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
5731 case BFD_RELOC_PPC64_GOT16_DS
:
5732 case BFD_RELOC_PPC64_GOT16_LO_DS
:
5733 case BFD_RELOC_PPC64_PLT16_LO_DS
:
5734 case BFD_RELOC_PPC64_SECTOFF_DS
:
5735 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
5736 case BFD_RELOC_PPC64_TOC16_DS
:
5737 case BFD_RELOC_PPC64_TOC16_LO_DS
:
5738 case BFD_RELOC_PPC64_PLTGOT16_DS
:
5739 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
5743 unsigned char *where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5744 unsigned long val
, mask
;
5746 if (target_big_endian
)
5747 val
= bfd_getb32 (where
- 2);
5749 val
= bfd_getl32 (where
);
5751 /* lq insns reserve the four lsbs. */
5752 if ((ppc_cpu
& PPC_OPCODE_POWER4
) != 0
5753 && (val
& (0x3f << 26)) == (56u << 26))
5755 val
|= value
& mask
;
5756 if (target_big_endian
)
5757 bfd_putb16 ((bfd_vma
) val
, where
);
5759 bfd_putl16 ((bfd_vma
) val
, where
);
5763 case BFD_RELOC_PPC_B16_BRTAKEN
:
5764 case BFD_RELOC_PPC_B16_BRNTAKEN
:
5765 case BFD_RELOC_PPC_BA16_BRTAKEN
:
5766 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
5769 case BFD_RELOC_PPC_TLS
:
5770 case BFD_RELOC_PPC_DTPMOD
:
5771 case BFD_RELOC_PPC_TPREL16
:
5772 case BFD_RELOC_PPC_TPREL16_LO
:
5773 case BFD_RELOC_PPC_TPREL16_HI
:
5774 case BFD_RELOC_PPC_TPREL16_HA
:
5775 case BFD_RELOC_PPC_TPREL
:
5776 case BFD_RELOC_PPC_DTPREL16
:
5777 case BFD_RELOC_PPC_DTPREL16_LO
:
5778 case BFD_RELOC_PPC_DTPREL16_HI
:
5779 case BFD_RELOC_PPC_DTPREL16_HA
:
5780 case BFD_RELOC_PPC_DTPREL
:
5781 case BFD_RELOC_PPC_GOT_TLSGD16
:
5782 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
5783 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
5784 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
5785 case BFD_RELOC_PPC_GOT_TLSLD16
:
5786 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
5787 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
5788 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
5789 case BFD_RELOC_PPC_GOT_TPREL16
:
5790 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
5791 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
5792 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
5793 case BFD_RELOC_PPC_GOT_DTPREL16
:
5794 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
5795 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
5796 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
5797 case BFD_RELOC_PPC64_TPREL16_DS
:
5798 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
5799 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
5800 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
5801 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
5802 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
5803 case BFD_RELOC_PPC64_DTPREL16_DS
:
5804 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
5805 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
5806 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
5807 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
5808 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
5811 /* Because SDA21 modifies the register field, the size is set to 4
5812 bytes, rather than 2, so offset it here appropriately. */
5813 case BFD_RELOC_PPC_EMB_SDA21
:
5817 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
5818 + ((target_big_endian
) ? 2 : 0),
5826 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
5830 case BFD_RELOC_24_PLT_PCREL
:
5831 case BFD_RELOC_PPC_LOCAL24PC
:
5832 if (!fixP
->fx_pcrel
&& !fixP
->fx_done
)
5840 /* Fetch the instruction, insert the fully resolved operand
5841 value, and stuff the instruction back again. */
5842 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
5843 if (target_big_endian
)
5844 insn
= bfd_getb32 ((unsigned char *) where
);
5846 insn
= bfd_getl32 ((unsigned char *) where
);
5847 if ((value
& 3) != 0)
5848 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5849 _("must branch to an address a multiple of 4"));
5850 if ((offsetT
) value
< -0x40000000
5851 || (offsetT
) value
>= 0x40000000)
5852 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
5853 _("@local or @plt branch destination is too far away, %ld bytes"),
5855 insn
= insn
| (value
& 0x03fffffc);
5856 if (target_big_endian
)
5857 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
5859 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
5863 case BFD_RELOC_VTABLE_INHERIT
:
5866 && !S_IS_DEFINED (fixP
->fx_addsy
)
5867 && !S_IS_WEAK (fixP
->fx_addsy
))
5868 S_SET_WEAK (fixP
->fx_addsy
);
5871 case BFD_RELOC_VTABLE_ENTRY
:
5876 /* Generated by reference to `sym@tocbase'. The sym is
5877 ignored by the linker. */
5878 case BFD_RELOC_PPC64_TOC
:
5884 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
5891 fixP
->fx_addnumber
= value
;
5893 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
5894 fixP
->fx_addnumber
= 0;
5898 fixP
->fx_addnumber
= 0;
5900 /* We want to use the offset within the data segment of the
5901 symbol, not the actual VMA of the symbol. */
5902 fixP
->fx_addnumber
=
5903 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
));
5909 /* Generate a reloc for a fixup. */
5912 tc_gen_reloc (seg
, fixp
)
5913 asection
*seg ATTRIBUTE_UNUSED
;
5918 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
5920 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
5921 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
5922 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
5923 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
5924 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
5926 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
5927 _("reloc %d not supported by object file format"),
5928 (int) fixp
->fx_r_type
);
5931 reloc
->addend
= fixp
->fx_addnumber
;
5937 ppc_cfi_frame_initial_instructions ()
5939 cfi_add_CFA_def_cfa (1, 0);
5943 tc_ppc_regname_to_dw2regnum (const char *regname
)
5945 unsigned int regnum
= -1;
5949 static struct { char *name
; int dw2regnum
; } regnames
[] =
5951 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
5952 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
5953 { "cc", 68 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
5954 { "spe_acc", 111 }, { "spefscr", 112 }
5957 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
5958 if (strcmp (regnames
[i
].name
, regname
) == 0)
5959 return regnames
[i
].dw2regnum
;
5961 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
5963 p
= regname
+ 1 + (regname
[1] == '.');
5964 regnum
= strtoul (p
, &q
, 10);
5965 if (p
== q
|| *q
|| regnum
>= 32)
5967 if (regname
[0] == 'f')
5969 else if (regname
[0] == 'v')
5972 else if (regname
[0] == 'c' && regname
[1] == 'r')
5974 p
= regname
+ 2 + (regname
[2] == '.');
5975 if (p
[0] < '0' || p
[0] > '7' || p
[1])
5977 regnum
= p
[0] - '0' + 68;