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 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Written by Ian Lance Taylor, Cygnus Support.
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to the Free
21 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
25 #include "safe-ctype.h"
27 #include "dw2gencfi.h"
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
40 #include "coff/xcoff.h"
44 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
46 /* Tell the main code what the endianness is. */
47 extern int target_big_endian
;
49 /* Whether or not, we've set target_big_endian. */
50 static int set_target_endian
= 0;
52 /* Whether to use user friendly register names. */
53 #ifndef TARGET_REG_NAMES_P
55 #define TARGET_REG_NAMES_P TRUE
57 #define TARGET_REG_NAMES_P FALSE
61 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
64 /* #lo(value) denotes the least significant 16 bits of the indicated. */
65 #define PPC_LO(v) ((v) & 0xffff)
67 /* Split the indicated value with the msbs in bits 11-15
68 and the lsbs in bits 21-31. */
69 #define PPC_VLE_SPLIT16A(v) ((v & 0xf800) << 11) | (v & 0x7ff)
71 /* Split the indicated value with the msbs in bits 6-10
72 and the lsbs in bits 21-31. */
73 #define PPC_VLE_SPLIT16D(v) ((v & 0xf800) << 5) | (v & 0x7ff)
75 /* #lo(value) denotes the lsb 16 bits in split16a format. */
76 #define PPC_VLE_LO16A(v) PPC_VLE_SPLIT16A(PPC_LO(v))
78 /* #lo(value) denotes the lsb 16 bits in split16d format. */
79 #define PPC_VLE_LO16D(v) PPC_VLE_SPLIT16D(PPC_LO(v))
81 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
82 #define PPC_HI(v) (((v) >> 16) & 0xffff)
84 /* #lo(value) denotes the msb 16 bits in split16a format. */
85 #define PPC_VLE_HI16A(v) PPC_VLE_SPLIT16A(PPC_HI(v))
87 /* #lo(value) denotes the msb 16 bits in split16d format. */
88 #define PPC_VLE_HI16D(v) PPC_VLE_SPLIT16D(PPC_HI(v))
90 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
91 the indicated value, compensating for #lo() being treated as a
93 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
95 /* #ha(value) denotes the high adjusted value in split16a format. */
96 #define PPC_VLE_HA16A(v) PPC_VLE_SPLIT16A(PPC_HA(v))
98 /* #ha(value) denotes the high adjusted value in split16d format. */
99 #define PPC_VLE_HA16D(v) PPC_VLE_SPLIT16D(PPC_HA(v))
101 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
102 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
104 /* #highera(value) denotes bits 32 through 47 of the indicated value,
105 compensating for #lo() being treated as a signed number. */
106 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
108 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
109 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
111 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
112 compensating for #lo being treated as a signed number. */
113 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
115 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
117 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
119 static void ppc_macro (char *, const struct powerpc_macro
*);
120 static void ppc_byte (int);
122 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
123 static void ppc_tc (int);
124 static void ppc_machine (int);
128 static void ppc_comm (int);
129 static void ppc_bb (int);
130 static void ppc_bc (int);
131 static void ppc_bf (int);
132 static void ppc_biei (int);
133 static void ppc_bs (int);
134 static void ppc_eb (int);
135 static void ppc_ec (int);
136 static void ppc_ef (int);
137 static void ppc_es (int);
138 static void ppc_csect (int);
139 static void ppc_dwsect (int);
140 static void ppc_change_csect (symbolS
*, offsetT
);
141 static void ppc_function (int);
142 static void ppc_extern (int);
143 static void ppc_lglobl (int);
144 static void ppc_ref (int);
145 static void ppc_section (int);
146 static void ppc_named_section (int);
147 static void ppc_stabx (int);
148 static void ppc_rename (int);
149 static void ppc_toc (int);
150 static void ppc_xcoff_cons (int);
151 static void ppc_vbyte (int);
155 static void ppc_elf_cons (int);
156 static void ppc_elf_rdata (int);
157 static void ppc_elf_lcomm (int);
161 static void ppc_previous (int);
162 static void ppc_pdata (int);
163 static void ppc_ydata (int);
164 static void ppc_reldata (int);
165 static void ppc_rdata (int);
166 static void ppc_ualong (int);
167 static void ppc_znop (int);
168 static void ppc_pe_comm (int);
169 static void ppc_pe_section (int);
170 static void ppc_pe_function (int);
171 static void ppc_pe_tocd (int);
174 /* Generic assembler global variables which must be defined by all
178 /* This string holds the chars that always start a comment. If the
179 pre-processor is disabled, these aren't very useful. The macro
180 tc_comment_chars points to this. We use this, rather than the
181 usual comment_chars, so that we can switch for Solaris conventions. */
182 static const char ppc_solaris_comment_chars
[] = "#!";
183 static const char ppc_eabi_comment_chars
[] = "#";
185 #ifdef TARGET_SOLARIS_COMMENT
186 const char *ppc_comment_chars
= ppc_solaris_comment_chars
;
188 const char *ppc_comment_chars
= ppc_eabi_comment_chars
;
191 const char comment_chars
[] = "#";
194 /* Characters which start a comment at the beginning of a line. */
195 const char line_comment_chars
[] = "#";
197 /* Characters which may be used to separate multiple commands on a
199 const char line_separator_chars
[] = ";";
201 /* Characters which are used to indicate an exponent in a floating
203 const char EXP_CHARS
[] = "eE";
205 /* Characters which mean that a number is a floating point constant,
207 const char FLT_CHARS
[] = "dD";
209 /* Anything that can start an operand needs to be mentioned here,
210 to stop the input scrubber eating whitespace. */
211 const char ppc_symbol_chars
[] = "%[";
213 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
214 int ppc_cie_data_alignment
;
216 /* The dwarf2 minimum instruction length. */
217 int ppc_dwarf2_line_min_insn_length
;
219 /* More than this number of nops in an alignment op gets a branch
221 unsigned long nop_limit
= 4;
223 /* The type of processor we are assembling for. This is one or more
224 of the PPC_OPCODE flags defined in opcode/ppc.h. */
225 ppc_cpu_t ppc_cpu
= 0;
227 /* Flags set on encountering toc relocs. */
229 has_large_toc_reloc
= 1,
230 has_small_toc_reloc
= 2
233 /* The target specific pseudo-ops which we support. */
235 const pseudo_typeS md_pseudo_table
[] =
237 /* Pseudo-ops which must be overridden. */
238 { "byte", ppc_byte
, 0 },
241 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
242 legitimately belong in the obj-*.c file. However, XCOFF is based
243 on COFF, and is only implemented for the RS/6000. We just use
244 obj-coff.c, and add what we need here. */
245 { "comm", ppc_comm
, 0 },
246 { "lcomm", ppc_comm
, 1 },
250 { "bi", ppc_biei
, 0 },
252 { "csect", ppc_csect
, 0 },
253 { "dwsect", ppc_dwsect
, 0 },
254 { "data", ppc_section
, 'd' },
258 { "ei", ppc_biei
, 1 },
260 { "extern", ppc_extern
, 0 },
261 { "function", ppc_function
, 0 },
262 { "lglobl", ppc_lglobl
, 0 },
263 { "ref", ppc_ref
, 0 },
264 { "rename", ppc_rename
, 0 },
265 { "section", ppc_named_section
, 0 },
266 { "stabx", ppc_stabx
, 0 },
267 { "text", ppc_section
, 't' },
268 { "toc", ppc_toc
, 0 },
269 { "long", ppc_xcoff_cons
, 2 },
270 { "llong", ppc_xcoff_cons
, 3 },
271 { "word", ppc_xcoff_cons
, 1 },
272 { "short", ppc_xcoff_cons
, 1 },
273 { "vbyte", ppc_vbyte
, 0 },
277 { "llong", ppc_elf_cons
, 8 },
278 { "quad", ppc_elf_cons
, 8 },
279 { "long", ppc_elf_cons
, 4 },
280 { "word", ppc_elf_cons
, 2 },
281 { "short", ppc_elf_cons
, 2 },
282 { "rdata", ppc_elf_rdata
, 0 },
283 { "rodata", ppc_elf_rdata
, 0 },
284 { "lcomm", ppc_elf_lcomm
, 0 },
288 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
289 { "previous", ppc_previous
, 0 },
290 { "pdata", ppc_pdata
, 0 },
291 { "ydata", ppc_ydata
, 0 },
292 { "reldata", ppc_reldata
, 0 },
293 { "rdata", ppc_rdata
, 0 },
294 { "ualong", ppc_ualong
, 0 },
295 { "znop", ppc_znop
, 0 },
296 { "comm", ppc_pe_comm
, 0 },
297 { "lcomm", ppc_pe_comm
, 1 },
298 { "section", ppc_pe_section
, 0 },
299 { "function", ppc_pe_function
,0 },
300 { "tocd", ppc_pe_tocd
, 0 },
303 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
305 { "machine", ppc_machine
, 0 },
312 /* Predefined register names if -mregnames (or default for Windows NT).
313 In general, there are lots of them, in an attempt to be compatible
314 with a number of other Windows NT assemblers. */
316 /* Structure to hold information about predefined registers. */
323 /* List of registers that are pre-defined:
325 Each general register has predefined names of the form:
326 1. r<reg_num> which has the value <reg_num>.
327 2. r.<reg_num> which has the value <reg_num>.
329 Each floating point register has predefined names of the form:
330 1. f<reg_num> which has the value <reg_num>.
331 2. f.<reg_num> which has the value <reg_num>.
333 Each vector unit register has predefined names of the form:
334 1. v<reg_num> which has the value <reg_num>.
335 2. v.<reg_num> which has the value <reg_num>.
337 Each condition register has predefined names of the form:
338 1. cr<reg_num> which has the value <reg_num>.
339 2. cr.<reg_num> which has the value <reg_num>.
341 There are individual registers as well:
342 sp or r.sp has the value 1
343 rtoc or r.toc has the value 2
344 fpscr has the value 0
350 dsisr has the value 18
352 sdr1 has the value 25
353 srr0 has the value 26
354 srr1 has the value 27
356 The table is sorted. Suitable for searching by a binary search. */
358 static const struct pd_reg pre_defined_registers
[] =
360 { "cr.0", 0 }, /* Condition Registers */
380 { "dar", 19 }, /* Data Access Register */
381 { "dec", 22 }, /* Decrementer */
382 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
384 { "f.0", 0 }, /* Floating point registers */
411 { "f.32", 32 }, /* Extended floating point scalar registers (ISA 2.06). */
477 { "f32", 32 }, /* Extended floating point scalar registers (ISA 2.06). */
518 /* Quantization registers used with pair single instructions. */
536 { "lr", 8 }, /* Link Register */
540 { "r.0", 0 }, /* General Purpose Registers */
573 { "r.sp", 1 }, /* Stack Pointer */
575 { "r.toc", 2 }, /* Pointer to the table of contents */
577 { "r0", 0 }, /* More general purpose registers */
610 { "rtoc", 2 }, /* Table of contents */
612 { "sdr1", 25 }, /* Storage Description Register 1 */
616 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
617 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
619 { "v.0", 0 }, /* Vector (Altivec/VMX) registers */
685 { "vs.0", 0 }, /* Vector Scalar (VSX) registers (ISA 2.06). */
819 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
821 /* Given NAME, find the register number associated with that name, return
822 the integer value associated with the given name or -1 on failure. */
825 reg_name_search (const struct pd_reg
*regs
, int regcount
, const char *name
)
827 int middle
, low
, high
;
835 middle
= (low
+ high
) / 2;
836 cmp
= strcasecmp (name
, regs
[middle
].name
);
842 return regs
[middle
].value
;
850 * Summary of register_name.
852 * in: Input_line_pointer points to 1st char of operand.
854 * out: A expressionS.
855 * The operand may have been a register: in this case, X_op == O_register,
856 * X_add_number is set to the register number, and truth is returned.
857 * Input_line_pointer->(next non-blank) char after operand, or is in its
862 register_name (expressionS
*expressionP
)
869 /* Find the spelling of the operand. */
870 start
= name
= input_line_pointer
;
871 if (name
[0] == '%' && ISALPHA (name
[1]))
872 name
= ++input_line_pointer
;
874 else if (!reg_names_p
|| !ISALPHA (name
[0]))
877 c
= get_symbol_end ();
878 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
880 /* Put back the delimiting char. */
881 *input_line_pointer
= c
;
883 /* Look to see if it's in the register table. */
886 expressionP
->X_op
= O_register
;
887 expressionP
->X_add_number
= reg_number
;
889 /* Make the rest nice. */
890 expressionP
->X_add_symbol
= NULL
;
891 expressionP
->X_op_symbol
= NULL
;
895 /* Reset the line as if we had not done anything. */
896 input_line_pointer
= start
;
900 /* This function is called for each symbol seen in an expression. It
901 handles the special parsing which PowerPC assemblers are supposed
902 to use for condition codes. */
904 /* Whether to do the special parsing. */
905 static bfd_boolean cr_operand
;
907 /* Names to recognize in a condition code. This table is sorted. */
908 static const struct pd_reg cr_names
[] =
925 /* Parsing function. This returns non-zero if it recognized an
929 ppc_parse_name (const char *name
, expressionS
*exp
)
938 val
= reg_name_search (cr_names
, sizeof cr_names
/ sizeof cr_names
[0],
943 exp
->X_op
= O_constant
;
944 exp
->X_add_number
= val
;
949 /* Local variables. */
951 /* Whether to target xcoff64/elf64. */
952 static unsigned int ppc_obj64
= BFD_DEFAULT_TARGET_SIZE
== 64;
954 /* Opcode hash table. */
955 static struct hash_control
*ppc_hash
;
957 /* Macro hash table. */
958 static struct hash_control
*ppc_macro_hash
;
961 /* What type of shared library support to use. */
962 static enum { SHLIB_NONE
, SHLIB_PIC
, SHLIB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
964 /* Flags to set in the elf header. */
965 static flagword ppc_flags
= 0;
967 /* Whether this is Solaris or not. */
968 #ifdef TARGET_SOLARIS_COMMENT
969 #define SOLARIS_P TRUE
971 #define SOLARIS_P FALSE
974 static bfd_boolean msolaris
= SOLARIS_P
;
979 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
980 using a bunch of different sections. These assembler sections,
981 however, are all encompassed within the .text or .data sections of
982 the final output file. We handle this by using different
983 subsegments within these main segments. */
985 /* Next subsegment to allocate within the .text segment. */
986 static subsegT ppc_text_subsegment
= 2;
988 /* Linked list of csects in the text section. */
989 static symbolS
*ppc_text_csects
;
991 /* Next subsegment to allocate within the .data segment. */
992 static subsegT ppc_data_subsegment
= 2;
994 /* Linked list of csects in the data section. */
995 static symbolS
*ppc_data_csects
;
997 /* The current csect. */
998 static symbolS
*ppc_current_csect
;
1000 /* The RS/6000 assembler uses a TOC which holds addresses of functions
1001 and variables. Symbols are put in the TOC with the .tc pseudo-op.
1002 A special relocation is used when accessing TOC entries. We handle
1003 the TOC as a subsegment within the .data segment. We set it up if
1004 we see a .toc pseudo-op, and save the csect symbol here. */
1005 static symbolS
*ppc_toc_csect
;
1007 /* The first frag in the TOC subsegment. */
1008 static fragS
*ppc_toc_frag
;
1010 /* The first frag in the first subsegment after the TOC in the .data
1011 segment. NULL if there are no subsegments after the TOC. */
1012 static fragS
*ppc_after_toc_frag
;
1014 /* The current static block. */
1015 static symbolS
*ppc_current_block
;
1017 /* The COFF debugging section; set by md_begin. This is not the
1018 .debug section, but is instead the secret BFD section which will
1019 cause BFD to set the section number of a symbol to N_DEBUG. */
1020 static asection
*ppc_coff_debug_section
;
1022 /* Structure to set the length field of the dwarf sections. */
1023 struct dw_subsection
{
1024 /* Subsections are simply linked. */
1025 struct dw_subsection
*link
;
1027 /* The subsection number. */
1030 /* Expression to compute the length of the section. */
1031 expressionS end_exp
;
1034 static struct dw_section
{
1035 /* Corresponding section. */
1038 /* Simply linked list of subsections with a label. */
1039 struct dw_subsection
*list_subseg
;
1041 /* The anonymous subsection. */
1042 struct dw_subsection
*anon_subseg
;
1043 } dw_sections
[XCOFF_DWSECT_NBR_NAMES
];
1044 #endif /* OBJ_XCOFF */
1048 /* Various sections that we need for PE coff support. */
1049 static segT ydata_section
;
1050 static segT pdata_section
;
1051 static segT reldata_section
;
1052 static segT rdata_section
;
1053 static segT tocdata_section
;
1055 /* The current section and the previous section. See ppc_previous. */
1056 static segT ppc_previous_section
;
1057 static segT ppc_current_section
;
1062 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
1063 #define PPC_APUINFO_ISEL 0x40
1064 #define PPC_APUINFO_PMR 0x41
1065 #define PPC_APUINFO_RFMCI 0x42
1066 #define PPC_APUINFO_CACHELCK 0x43
1067 #define PPC_APUINFO_SPE 0x100
1068 #define PPC_APUINFO_EFS 0x101
1069 #define PPC_APUINFO_BRLOCK 0x102
1070 #define PPC_APUINFO_VLE 0x104
1073 * We keep a list of APUinfo
1075 unsigned long *ppc_apuinfo_list
;
1076 unsigned int ppc_apuinfo_num
;
1077 unsigned int ppc_apuinfo_num_alloc
;
1078 #endif /* OBJ_ELF */
1081 const char *const md_shortopts
= "b:l:usm:K:VQ:";
1083 const char *const md_shortopts
= "um:";
1085 #define OPTION_NOPS (OPTION_MD_BASE + 0)
1086 const struct option md_longopts
[] = {
1087 {"nops", required_argument
, NULL
, OPTION_NOPS
},
1088 {NULL
, no_argument
, NULL
, 0}
1090 const size_t md_longopts_size
= sizeof (md_longopts
);
1093 md_parse_option (int c
, char *arg
)
1100 /* -u means that any undefined symbols should be treated as
1101 external, which is the default for gas anyhow. */
1106 /* Solaris as takes -le (presumably for little endian). For completeness
1107 sake, recognize -be also. */
1108 if (strcmp (arg
, "e") == 0)
1110 target_big_endian
= 0;
1111 set_target_endian
= 1;
1112 if (ppc_cpu
& PPC_OPCODE_VLE
)
1113 as_bad (_("the use of -mvle requires big endian."));
1121 if (strcmp (arg
, "e") == 0)
1123 target_big_endian
= 1;
1124 set_target_endian
= 1;
1132 /* Recognize -K PIC. */
1133 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
1136 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1144 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
1146 if (strcmp (arg
, "64") == 0)
1150 if (ppc_cpu
& PPC_OPCODE_VLE
)
1151 as_bad (_("the use of -mvle requires -a32."));
1153 as_fatal (_("%s unsupported"), "-a64");
1156 else if (strcmp (arg
, "32") == 0)
1163 new_cpu
= ppc_parse_cpu (ppc_cpu
, arg
);
1167 if (strcmp (arg
, "vle") == 0)
1169 if (set_target_endian
&& target_big_endian
== 0)
1170 as_bad (_("the use of -mvle requires big endian."));
1172 as_bad (_("the use of -mvle requires -a32."));
1176 else if (strcmp (arg
, "regnames") == 0)
1179 else if (strcmp (arg
, "no-regnames") == 0)
1180 reg_names_p
= FALSE
;
1183 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1184 that require relocation. */
1185 else if (strcmp (arg
, "relocatable") == 0)
1187 shlib
= SHLIB_MRELOCATABLE
;
1188 ppc_flags
|= EF_PPC_RELOCATABLE
;
1191 else if (strcmp (arg
, "relocatable-lib") == 0)
1193 shlib
= SHLIB_MRELOCATABLE
;
1194 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
1197 /* -memb, set embedded bit. */
1198 else if (strcmp (arg
, "emb") == 0)
1199 ppc_flags
|= EF_PPC_EMB
;
1201 /* -mlittle/-mbig set the endianness. */
1202 else if (strcmp (arg
, "little") == 0
1203 || strcmp (arg
, "little-endian") == 0)
1205 target_big_endian
= 0;
1206 set_target_endian
= 1;
1207 if (ppc_cpu
& PPC_OPCODE_VLE
)
1208 as_bad (_("the use of -mvle requires big endian."));
1211 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
1213 target_big_endian
= 1;
1214 set_target_endian
= 1;
1217 else if (strcmp (arg
, "solaris") == 0)
1220 ppc_comment_chars
= ppc_solaris_comment_chars
;
1223 else if (strcmp (arg
, "no-solaris") == 0)
1226 ppc_comment_chars
= ppc_eabi_comment_chars
;
1231 as_bad (_("invalid switch -m%s"), arg
);
1237 /* -V: SVR4 argument to print version ID. */
1239 print_version_id ();
1242 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1243 should be emitted or not. FIXME: Not implemented. */
1247 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1248 rather than .stabs.excl, which is ignored by the linker.
1249 FIXME: Not implemented. */
1260 nop_limit
= strtoul (optarg
, &end
, 0);
1262 as_bad (_("--nops needs a numeric argument"));
1274 md_show_usage (FILE *stream
)
1276 fprintf (stream
, _("\
1278 -a32 generate ELF32/XCOFF32\n\
1279 -a64 generate ELF64/XCOFF64\n\
1281 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1282 -mpwr generate code for POWER (RIOS1)\n\
1283 -m601 generate code for PowerPC 601\n\
1284 -mppc, -mppc32, -m603, -m604\n\
1285 generate code for PowerPC 603/604\n\
1286 -m403 generate code for PowerPC 403\n\
1287 -m405 generate code for PowerPC 405\n\
1288 -m440 generate code for PowerPC 440\n\
1289 -m464 generate code for PowerPC 464\n\
1290 -m476 generate code for PowerPC 476\n\
1291 -m7400, -m7410, -m7450, -m7455\n\
1292 generate code for PowerPC 7400/7410/7450/7455\n\
1293 -m750cl generate code for PowerPC 750cl\n"));
1294 fprintf (stream
, _("\
1295 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1296 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1297 -mbooke generate code for 32-bit PowerPC BookE\n\
1298 -ma2 generate code for A2 architecture\n\
1299 -mpower4, -mpwr4 generate code for Power4 architecture\n\
1300 -mpower5, -mpwr5, -mpwr5x\n\
1301 generate code for Power5 architecture\n\
1302 -mpower6, -mpwr6 generate code for Power6 architecture\n\
1303 -mpower7, -mpwr7 generate code for Power7 architecture\n\
1304 -mcell generate code for Cell Broadband Engine architecture\n\
1305 -mcom generate code Power/PowerPC common instructions\n\
1306 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1307 fprintf (stream
, _("\
1308 -maltivec generate code for AltiVec\n\
1309 -mvsx generate code for Vector-Scalar (VSX) instructions\n\
1310 -me300 generate code for PowerPC e300 family\n\
1311 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1312 -me500mc, generate code for Freescale e500mc core complex\n\
1313 -me500mc64, generate code for Freescale e500mc64 core complex\n\
1314 -me5500, generate code for Freescale e5500 core complex\n\
1315 -me6500, generate code for Freescale e6500 core complex\n\
1316 -mspe generate code for Motorola SPE instructions\n\
1317 -mvle generate code for Freescale VLE instructions\n\
1318 -mtitan generate code for AppliedMicro Titan core complex\n\
1319 -mregnames Allow symbolic names for registers\n\
1320 -mno-regnames Do not allow symbolic names for registers\n"));
1322 fprintf (stream
, _("\
1323 -mrelocatable support for GCC's -mrelocatble option\n\
1324 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1325 -memb set PPC_EMB bit in ELF flags\n\
1326 -mlittle, -mlittle-endian, -le\n\
1327 generate code for a little endian machine\n\
1328 -mbig, -mbig-endian, -be\n\
1329 generate code for a big endian machine\n\
1330 -msolaris generate code for Solaris\n\
1331 -mno-solaris do not generate code for Solaris\n\
1332 -K PIC set EF_PPC_RELOCATABLE_LIB in ELF flags\n\
1333 -V print assembler version number\n\
1334 -Qy, -Qn ignored\n"));
1336 fprintf (stream
, _("\
1337 -nops=count when aligning, more than COUNT nops uses a branch\n"));
1340 /* Set ppc_cpu if it is not already set. */
1345 const char *default_os
= TARGET_OS
;
1346 const char *default_cpu
= TARGET_CPU
;
1348 if ((ppc_cpu
& ~(ppc_cpu_t
) PPC_OPCODE_ANY
) == 0)
1351 ppc_cpu
|= PPC_OPCODE_PPC
| PPC_OPCODE_64
;
1352 else if (strncmp (default_os
, "aix", 3) == 0
1353 && default_os
[3] >= '4' && default_os
[3] <= '9')
1354 ppc_cpu
|= PPC_OPCODE_COMMON
;
1355 else if (strncmp (default_os
, "aix3", 4) == 0)
1356 ppc_cpu
|= PPC_OPCODE_POWER
;
1357 else if (strcmp (default_cpu
, "rs6000") == 0)
1358 ppc_cpu
|= PPC_OPCODE_POWER
;
1359 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1360 ppc_cpu
|= PPC_OPCODE_PPC
;
1362 as_fatal (_("unknown default cpu = %s, os = %s"),
1363 default_cpu
, default_os
);
1367 /* Figure out the BFD architecture to use. This function and ppc_mach
1368 are called well before md_begin, when the output file is opened. */
1370 enum bfd_architecture
1373 const char *default_cpu
= TARGET_CPU
;
1376 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
1377 return bfd_arch_powerpc
;
1378 if ((ppc_cpu
& PPC_OPCODE_VLE
) != 0)
1379 return bfd_arch_powerpc
;
1380 if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
1381 return bfd_arch_rs6000
;
1382 if ((ppc_cpu
& (PPC_OPCODE_COMMON
| PPC_OPCODE_ANY
)) != 0)
1384 if (strcmp (default_cpu
, "rs6000") == 0)
1385 return bfd_arch_rs6000
;
1386 else if (strncmp (default_cpu
, "powerpc", 7) == 0)
1387 return bfd_arch_powerpc
;
1390 as_fatal (_("neither Power nor PowerPC opcodes were selected."));
1391 return bfd_arch_unknown
;
1398 return bfd_mach_ppc64
;
1399 else if (ppc_arch () == bfd_arch_rs6000
)
1400 return bfd_mach_rs6k
;
1401 else if (ppc_cpu
& PPC_OPCODE_TITAN
)
1402 return bfd_mach_ppc_titan
;
1403 else if (ppc_cpu
& PPC_OPCODE_VLE
)
1404 return bfd_mach_ppc_vle
;
1406 return bfd_mach_ppc
;
1410 ppc_target_format (void)
1414 return target_big_endian
? "pe-powerpc" : "pe-powerpcle";
1416 return "xcoff-powermac";
1419 return (ppc_obj64
? "aix5coff64-rs6000" : "aixcoff-rs6000");
1421 return (ppc_obj64
? "aixcoff64-rs6000" : "aixcoff-rs6000");
1427 return (ppc_obj64
? "elf64-powerpc-freebsd" : "elf32-powerpc-freebsd");
1428 # elif defined (TE_VXWORKS)
1429 return "elf32-powerpc-vxworks";
1431 return (target_big_endian
1432 ? (ppc_obj64
? "elf64-powerpc" : "elf32-powerpc")
1433 : (ppc_obj64
? "elf64-powerpcle" : "elf32-powerpcle"));
1438 /* Validate one entry in powerpc_opcodes[] or vle_opcodes[].
1439 Return TRUE if there's a problem, otherwise FALSE. */
1442 insn_validate (const struct powerpc_opcode
*op
)
1444 const unsigned char *o
;
1445 unsigned long omask
= op
->mask
;
1447 /* The mask had better not trim off opcode bits. */
1448 if ((op
->opcode
& omask
) != op
->opcode
)
1450 as_bad (_("mask trims opcode bits for %s"), op
->name
);
1454 /* The operands must not overlap the opcode or each other. */
1455 for (o
= op
->operands
; *o
; ++o
)
1457 if (*o
>= num_powerpc_operands
)
1459 as_bad (_("operand index error for %s"), op
->name
);
1464 const struct powerpc_operand
*operand
= &powerpc_operands
[*o
];
1465 if (operand
->shift
!= PPC_OPSHIFT_INV
)
1469 if (operand
->shift
>= 0)
1470 mask
= operand
->bitm
<< operand
->shift
;
1472 mask
= operand
->bitm
>> -operand
->shift
;
1475 as_bad (_("operand %d overlap in %s"),
1476 (int) (o
- op
->operands
), op
->name
);
1486 /* Insert opcodes and macros into hash tables. Called at startup and
1487 for .machine pseudo. */
1490 ppc_setup_opcodes (void)
1492 const struct powerpc_opcode
*op
;
1493 const struct powerpc_opcode
*op_end
;
1494 const struct powerpc_macro
*macro
;
1495 const struct powerpc_macro
*macro_end
;
1496 bfd_boolean bad_insn
= FALSE
;
1498 if (ppc_hash
!= NULL
)
1499 hash_die (ppc_hash
);
1500 if (ppc_macro_hash
!= NULL
)
1501 hash_die (ppc_macro_hash
);
1503 /* Insert the opcodes into a hash table. */
1504 ppc_hash
= hash_new ();
1506 if (ENABLE_CHECKING
)
1510 /* An index into powerpc_operands is stored in struct fix
1511 fx_pcrel_adjust which is 8 bits wide. */
1512 gas_assert (num_powerpc_operands
< 256);
1514 /* Check operand masks. Code here and in the disassembler assumes
1515 all the 1's in the mask are contiguous. */
1516 for (i
= 0; i
< num_powerpc_operands
; ++i
)
1518 unsigned long mask
= powerpc_operands
[i
].bitm
;
1519 unsigned long right_bit
;
1522 right_bit
= mask
& -mask
;
1524 right_bit
= mask
& -mask
;
1525 if (mask
!= right_bit
)
1527 as_bad (_("powerpc_operands[%d].bitm invalid"), i
);
1530 for (j
= i
+ 1; j
< num_powerpc_operands
; ++j
)
1531 if (memcmp (&powerpc_operands
[i
], &powerpc_operands
[j
],
1532 sizeof (powerpc_operands
[0])) == 0)
1534 as_bad (_("powerpc_operands[%d] duplicates powerpc_operands[%d]"),
1541 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
1542 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1544 if (ENABLE_CHECKING
)
1546 if (op
!= powerpc_opcodes
)
1548 int old_opcode
= PPC_OP (op
[-1].opcode
);
1549 int new_opcode
= PPC_OP (op
[0].opcode
);
1551 #ifdef PRINT_OPCODE_TABLE
1552 printf ("%-14s\t#%04d\tmajor op: 0x%x\top: 0x%x\tmask: 0x%x\tflags: 0x%llx\n",
1553 op
->name
, op
- powerpc_opcodes
, (unsigned int) new_opcode
,
1554 (unsigned int) op
->opcode
, (unsigned int) op
->mask
,
1555 (unsigned long long) op
->flags
);
1558 /* The major opcodes had better be sorted. Code in the
1559 disassembler assumes the insns are sorted according to
1561 if (new_opcode
< old_opcode
)
1563 as_bad (_("major opcode is not sorted for %s"),
1568 bad_insn
|= insn_validate (op
);
1571 if ((ppc_cpu
& op
->flags
) != 0
1572 && !(ppc_cpu
& op
->deprecated
))
1576 retval
= hash_insert (ppc_hash
, op
->name
, (void *) op
);
1579 as_bad (_("duplicate instruction %s"),
1586 if ((ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1587 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
1588 hash_insert (ppc_hash
, op
->name
, (void *) op
);
1590 op_end
= vle_opcodes
+ vle_num_opcodes
;
1591 for (op
= vle_opcodes
; op
< op_end
; op
++)
1593 if (ENABLE_CHECKING
)
1595 if (op
!= vle_opcodes
)
1597 unsigned old_seg
, new_seg
;
1599 old_seg
= VLE_OP (op
[-1].opcode
, op
[-1].mask
);
1600 old_seg
= VLE_OP_TO_SEG (old_seg
);
1601 new_seg
= VLE_OP (op
[0].opcode
, op
[0].mask
);
1602 new_seg
= VLE_OP_TO_SEG (new_seg
);
1604 #ifdef PRINT_OPCODE_TABLE
1605 printf ("%-14s\t#%04d\tmajor op: 0x%x\top: 0x%x\tmask: 0x%x\tflags: 0x%llx\n",
1606 op
->name
, op
- powerpc_opcodes
, (unsigned int) new_opcode
,
1607 (unsigned int) op
->opcode
, (unsigned int) op
->mask
,
1608 (unsigned long long) op
->flags
);
1610 /* The major opcodes had better be sorted. Code in the
1611 disassembler assumes the insns are sorted according to
1613 if (new_seg
< old_seg
)
1615 as_bad (_("major opcode is not sorted for %s"),
1621 bad_insn
|= insn_validate (op
);
1624 if ((ppc_cpu
& op
->flags
) != 0
1625 && !(ppc_cpu
& op
->deprecated
))
1629 retval
= hash_insert (ppc_hash
, op
->name
, (void *) op
);
1632 as_bad (_("duplicate instruction %s"),
1639 if ((ppc_cpu
& PPC_OPCODE_VLE
) != 0)
1640 for (op
= vle_opcodes
; op
< op_end
; op
++)
1641 hash_insert (ppc_hash
, op
->name
, (void *) op
);
1643 /* Insert the macros into a hash table. */
1644 ppc_macro_hash
= hash_new ();
1646 macro_end
= powerpc_macros
+ powerpc_num_macros
;
1647 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
1649 if ((macro
->flags
& ppc_cpu
) != 0 || (ppc_cpu
& PPC_OPCODE_ANY
) != 0)
1653 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (void *) macro
);
1654 if (retval
!= (const char *) NULL
)
1656 as_bad (_("duplicate macro %s"), macro
->name
);
1666 /* This function is called when the assembler starts up. It is called
1667 after the options have been parsed and the output file has been
1675 ppc_cie_data_alignment
= ppc_obj64
? -8 : -4;
1676 ppc_dwarf2_line_min_insn_length
= (ppc_cpu
& PPC_OPCODE_VLE
) ? 2 : 4;
1679 /* Set the ELF flags if desired. */
1680 if (ppc_flags
&& !msolaris
)
1681 bfd_set_private_flags (stdoutput
, ppc_flags
);
1684 ppc_setup_opcodes ();
1686 /* Tell the main code what the endianness is if it is not overridden
1688 if (!set_target_endian
)
1690 set_target_endian
= 1;
1691 target_big_endian
= PPC_BIG_ENDIAN
;
1695 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
1697 /* Create dummy symbols to serve as initial csects. This forces the
1698 text csects to precede the data csects. These symbols will not
1700 ppc_text_csects
= symbol_make ("dummy\001");
1701 symbol_get_tc (ppc_text_csects
)->within
= ppc_text_csects
;
1702 ppc_data_csects
= symbol_make ("dummy\001");
1703 symbol_get_tc (ppc_data_csects
)->within
= ppc_data_csects
;
1708 ppc_current_section
= text_section
;
1709 ppc_previous_section
= 0;
1718 if (ppc_apuinfo_list
== NULL
)
1721 /* Ok, so write the section info out. We have this layout:
1725 0 8 length of "APUinfo\0"
1726 4 (n*4) number of APU's (4 bytes each)
1729 20 APU#1 first APU's info
1730 24 APU#2 second APU's info
1735 asection
*seg
= now_seg
;
1736 subsegT subseg
= now_subseg
;
1737 asection
*apuinfo_secp
= (asection
*) NULL
;
1740 /* Create the .PPC.EMB.apuinfo section. */
1741 apuinfo_secp
= subseg_new (".PPC.EMB.apuinfo", 0);
1742 bfd_set_section_flags (stdoutput
,
1744 SEC_HAS_CONTENTS
| SEC_READONLY
);
1747 md_number_to_chars (p
, (valueT
) 8, 4);
1750 md_number_to_chars (p
, (valueT
) ppc_apuinfo_num
* 4, 4);
1753 md_number_to_chars (p
, (valueT
) 2, 4);
1756 strcpy (p
, "APUinfo");
1758 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
1761 md_number_to_chars (p
, (valueT
) ppc_apuinfo_list
[i
], 4);
1764 frag_align (2, 0, 0);
1766 /* We probably can't restore the current segment, for there likely
1769 subseg_set (seg
, subseg
);
1774 /* Insert an operand value into an instruction. */
1776 static unsigned long
1777 ppc_insert_operand (unsigned long insn
,
1778 const struct powerpc_operand
*operand
,
1784 long min
, max
, right
;
1786 max
= operand
->bitm
;
1790 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
1792 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) == 0)
1793 max
= (max
>> 1) & -right
;
1794 min
= ~max
& -right
;
1797 if ((operand
->flags
& PPC_OPERAND_PLUS1
) != 0)
1800 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
1809 /* Some people write constants with the sign extension done by
1810 hand but only up to 32 bits. This shouldn't really be valid,
1811 but, to permit this code to assemble on a 64-bit host, we
1812 sign extend the 32-bit value to 64 bits if so doing makes the
1815 && (offsetT
) (val
- 0x80000000 - 0x80000000) >= min
1816 && (offsetT
) (val
- 0x80000000 - 0x80000000) <= max
1817 && ((val
- 0x80000000 - 0x80000000) & (right
- 1)) == 0)
1818 val
= val
- 0x80000000 - 0x80000000;
1820 /* Similarly, people write expressions like ~(1<<15), and expect
1821 this to be OK for a 32-bit unsigned value. */
1823 && (offsetT
) (val
+ 0x80000000 + 0x80000000) >= min
1824 && (offsetT
) (val
+ 0x80000000 + 0x80000000) <= max
1825 && ((val
+ 0x80000000 + 0x80000000) & (right
- 1)) == 0)
1826 val
= val
+ 0x80000000 + 0x80000000;
1830 || (val
& (right
- 1)) != 0)
1831 as_bad_value_out_of_range (_("operand"), val
, min
, max
, file
, line
);
1834 if (operand
->insert
)
1839 insn
= (*operand
->insert
) (insn
, (long) val
, cpu
, &errmsg
);
1840 if (errmsg
!= (const char *) NULL
)
1841 as_bad_where (file
, line
, "%s", errmsg
);
1843 else if (operand
->shift
>= 0)
1844 insn
|= ((long) val
& operand
->bitm
) << operand
->shift
;
1846 insn
|= ((long) val
& operand
->bitm
) >> -operand
->shift
;
1853 /* Parse @got, etc. and return the desired relocation. */
1854 static bfd_reloc_code_real_type
1855 ppc_elf_suffix (char **str_p
, expressionS
*exp_p
)
1859 unsigned int length
: 8;
1860 unsigned int valid32
: 1;
1861 unsigned int valid64
: 1;
1870 const struct map_bfd
*ptr
;
1872 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1873 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1874 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1876 static const struct map_bfd mapping
[] = {
1877 MAP ("l", BFD_RELOC_LO16
),
1878 MAP ("h", BFD_RELOC_HI16
),
1879 MAP ("ha", BFD_RELOC_HI16_S
),
1880 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN
),
1881 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN
),
1882 MAP ("got", BFD_RELOC_16_GOTOFF
),
1883 MAP ("got@l", BFD_RELOC_LO16_GOTOFF
),
1884 MAP ("got@h", BFD_RELOC_HI16_GOTOFF
),
1885 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF
),
1886 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF
),
1887 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF
),
1888 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF
),
1889 MAP ("copy", BFD_RELOC_PPC_COPY
),
1890 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT
),
1891 MAP ("sectoff", BFD_RELOC_16_BASEREL
),
1892 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL
),
1893 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL
),
1894 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL
),
1895 MAP ("tls", BFD_RELOC_PPC_TLS
),
1896 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD
),
1897 MAP ("dtprel", BFD_RELOC_PPC_DTPREL
),
1898 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO
),
1899 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI
),
1900 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA
),
1901 MAP ("tprel", BFD_RELOC_PPC_TPREL
),
1902 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO
),
1903 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI
),
1904 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA
),
1905 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16
),
1906 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO
),
1907 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI
),
1908 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA
),
1909 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16
),
1910 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO
),
1911 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI
),
1912 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA
),
1913 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16
),
1914 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO
),
1915 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI
),
1916 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA
),
1917 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16
),
1918 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO
),
1919 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI
),
1920 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA
),
1921 MAP32 ("fixup", BFD_RELOC_CTOR
),
1922 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL
),
1923 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL
),
1924 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC
),
1925 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC
),
1926 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL
),
1927 MAP32 ("sdarel", BFD_RELOC_GPREL16
),
1928 MAP32 ("sdarel@l", BFD_RELOC_PPC_VLE_SDAREL_LO16A
),
1929 MAP32 ("sdarel@h", BFD_RELOC_PPC_VLE_SDAREL_HI16A
),
1930 MAP32 ("sdarel@ha", BFD_RELOC_PPC_VLE_SDAREL_HA16A
),
1931 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32
),
1932 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16
),
1933 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO
),
1934 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI
),
1935 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA
),
1936 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16
),
1937 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL
),
1938 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16
),
1939 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21
),
1940 MAP32 ("sda21@l", BFD_RELOC_PPC_VLE_SDA21_LO
),
1941 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF
),
1942 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16
),
1943 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO
),
1944 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI
),
1945 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA
),
1946 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD
),
1947 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA
),
1948 MAP32 ("xgot", BFD_RELOC_PPC_TOC16
),
1949 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER
),
1950 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S
),
1951 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST
),
1952 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S
),
1953 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC
),
1954 MAP64 ("toc", BFD_RELOC_PPC_TOC16
),
1955 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO
),
1956 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI
),
1957 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA
),
1958 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER
),
1959 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA
),
1960 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST
),
1961 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA
),
1962 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER
),
1963 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA
),
1964 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST
),
1965 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA
),
1966 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED
}
1970 return BFD_RELOC_UNUSED
;
1972 for (ch
= *str
, str2
= ident
;
1973 (str2
< ident
+ sizeof (ident
) - 1
1974 && (ISALNUM (ch
) || ch
== '@'));
1977 *str2
++ = TOLOWER (ch
);
1984 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
1985 if (ch
== ptr
->string
[0]
1986 && len
== ptr
->length
1987 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0
1988 && (ppc_obj64
? ptr
->valid64
: ptr
->valid32
))
1990 int reloc
= ptr
->reloc
;
1992 if (!ppc_obj64
&& exp_p
->X_add_number
!= 0)
1996 case BFD_RELOC_16_GOTOFF
:
1997 case BFD_RELOC_LO16_GOTOFF
:
1998 case BFD_RELOC_HI16_GOTOFF
:
1999 case BFD_RELOC_HI16_S_GOTOFF
:
2000 as_warn (_("identifier+constant@got means "
2001 "identifier@got+constant"));
2004 case BFD_RELOC_PPC_GOT_TLSGD16
:
2005 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
2006 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
2007 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
2008 case BFD_RELOC_PPC_GOT_TLSLD16
:
2009 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
2010 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
2011 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
2012 case BFD_RELOC_PPC_GOT_DTPREL16
:
2013 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
2014 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
2015 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
2016 case BFD_RELOC_PPC_GOT_TPREL16
:
2017 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
2018 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
2019 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
2020 as_bad (_("symbol+offset not supported for got tls"));
2025 /* Now check for identifier@suffix+constant. */
2026 if (*str
== '-' || *str
== '+')
2028 char *orig_line
= input_line_pointer
;
2029 expressionS new_exp
;
2031 input_line_pointer
= str
;
2032 expression (&new_exp
);
2033 if (new_exp
.X_op
== O_constant
)
2035 exp_p
->X_add_number
+= new_exp
.X_add_number
;
2036 str
= input_line_pointer
;
2039 if (&input_line_pointer
!= str_p
)
2040 input_line_pointer
= orig_line
;
2044 if (reloc
== (int) BFD_RELOC_PPC64_TOC
2045 && exp_p
->X_op
== O_symbol
2046 && strcmp (S_GET_NAME (exp_p
->X_add_symbol
), ".TOC.") == 0)
2048 /* Change the symbol so that the dummy .TOC. symbol can be
2049 omitted from the object file. */
2050 exp_p
->X_add_symbol
= &abs_symbol
;
2053 return (bfd_reloc_code_real_type
) reloc
;
2056 return BFD_RELOC_UNUSED
;
2059 /* Like normal .long/.short/.word, except support @got, etc.
2060 Clobbers input_line_pointer, checks end-of-line. */
2062 ppc_elf_cons (int nbytes
/* 1=.byte, 2=.word, 4=.long, 8=.llong */)
2065 bfd_reloc_code_real_type reloc
;
2067 if (is_it_end_of_statement ())
2069 demand_empty_rest_of_line ();
2076 if (exp
.X_op
== O_symbol
2077 && *input_line_pointer
== '@'
2078 && (reloc
= ppc_elf_suffix (&input_line_pointer
,
2079 &exp
)) != BFD_RELOC_UNUSED
)
2081 reloc_howto_type
*reloc_howto
;
2084 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
2085 size
= bfd_get_reloc_size (reloc_howto
);
2089 as_bad (_("%s relocations do not fit in %d bytes\n"),
2090 reloc_howto
->name
, nbytes
);
2097 p
= frag_more (nbytes
);
2098 memset (p
, 0, nbytes
);
2100 if (target_big_endian
)
2101 offset
= nbytes
- size
;
2102 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
,
2107 emit_expr (&exp
, (unsigned int) nbytes
);
2109 while (*input_line_pointer
++ == ',');
2111 /* Put terminator back into stream. */
2112 input_line_pointer
--;
2113 demand_empty_rest_of_line ();
2116 /* Solaris pseduo op to change to the .rodata section. */
2118 ppc_elf_rdata (int xxx
)
2120 char *save_line
= input_line_pointer
;
2121 static char section
[] = ".rodata\n";
2123 /* Just pretend this is .section .rodata */
2124 input_line_pointer
= section
;
2125 obj_elf_section (xxx
);
2127 input_line_pointer
= save_line
;
2130 /* Pseudo op to make file scope bss items. */
2132 ppc_elf_lcomm (int xxx ATTRIBUTE_UNUSED
)
2145 name
= input_line_pointer
;
2146 c
= get_symbol_end ();
2148 /* just after name is now '\0'. */
2149 p
= input_line_pointer
;
2152 if (*input_line_pointer
!= ',')
2154 as_bad (_("expected comma after symbol-name: rest of line ignored."));
2155 ignore_rest_of_line ();
2159 input_line_pointer
++; /* skip ',' */
2160 if ((size
= get_absolute_expression ()) < 0)
2162 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
2163 ignore_rest_of_line ();
2167 /* The third argument to .lcomm is the alignment. */
2168 if (*input_line_pointer
!= ',')
2172 ++input_line_pointer
;
2173 align
= get_absolute_expression ();
2176 as_warn (_("ignoring bad alignment"));
2182 symbolP
= symbol_find_or_make (name
);
2185 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
2187 as_bad (_("ignoring attempt to re-define symbol `%s'."),
2188 S_GET_NAME (symbolP
));
2189 ignore_rest_of_line ();
2193 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
2195 as_bad (_("length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
2196 S_GET_NAME (symbolP
),
2197 (long) S_GET_VALUE (symbolP
),
2200 ignore_rest_of_line ();
2206 old_subsec
= now_subseg
;
2209 /* Convert to a power of 2 alignment. */
2210 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
);
2213 as_bad (_("common alignment not a power of 2"));
2214 ignore_rest_of_line ();
2221 record_alignment (bss_section
, align2
);
2222 subseg_set (bss_section
, 0);
2224 frag_align (align2
, 0, 0);
2225 if (S_GET_SEGMENT (symbolP
) == bss_section
)
2226 symbol_get_frag (symbolP
)->fr_symbol
= 0;
2227 symbol_set_frag (symbolP
, frag_now
);
2228 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
2231 S_SET_SIZE (symbolP
, size
);
2232 S_SET_SEGMENT (symbolP
, bss_section
);
2233 subseg_set (old_sec
, old_subsec
);
2234 demand_empty_rest_of_line ();
2237 /* Validate any relocations emitted for -mrelocatable, possibly adding
2238 fixups for word relocations in writable segments, so we can adjust
2241 ppc_elf_validate_fix (fixS
*fixp
, segT seg
)
2243 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
2252 case SHLIB_MRELOCATABLE
:
2253 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
2254 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
2255 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
2256 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
2257 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
2258 && fixp
->fx_r_type
!= BFD_RELOC_16_BASEREL
2259 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
2260 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
2261 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
2262 && (seg
->flags
& SEC_LOAD
) != 0
2263 && strcmp (segment_name (seg
), ".got2") != 0
2264 && strcmp (segment_name (seg
), ".dtors") != 0
2265 && strcmp (segment_name (seg
), ".ctors") != 0
2266 && strcmp (segment_name (seg
), ".fixup") != 0
2267 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
2268 && strcmp (segment_name (seg
), ".eh_frame") != 0
2269 && strcmp (segment_name (seg
), ".ex_shared") != 0)
2271 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
2272 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
2274 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2275 _("relocation cannot be done when using -mrelocatable"));
2282 /* Prevent elf_frob_file_before_adjust removing a weak undefined
2283 function descriptor sym if the corresponding code sym is used. */
2286 ppc_frob_file_before_adjust (void)
2294 for (symp
= symbol_rootP
; symp
; symp
= symbol_next (symp
))
2301 name
= S_GET_NAME (symp
);
2305 if (! S_IS_WEAK (symp
)
2306 || S_IS_DEFINED (symp
))
2309 len
= strlen (name
) + 1;
2310 dotname
= xmalloc (len
+ 1);
2312 memcpy (dotname
+ 1, name
, len
);
2313 dotsym
= symbol_find_noref (dotname
, 1);
2315 if (dotsym
!= NULL
&& (symbol_used_p (dotsym
)
2316 || symbol_used_in_reloc_p (dotsym
)))
2317 symbol_mark_used (symp
);
2321 toc
= bfd_get_section_by_name (stdoutput
, ".toc");
2323 && toc_reloc_types
!= has_large_toc_reloc
2324 && bfd_section_size (stdoutput
, toc
) > 0x10000)
2325 as_warn (_("TOC section size exceeds 64k"));
2327 /* Don't emit .TOC. symbol. */
2328 symp
= symbol_find (".TOC.");
2330 symbol_remove (symp
, &symbol_rootP
, &symbol_lastP
);
2332 #endif /* OBJ_ELF */
2337 * Summary of parse_toc_entry.
2339 * in: Input_line_pointer points to the '[' in one of:
2341 * [toc] [tocv] [toc32] [toc64]
2343 * Anything else is an error of one kind or another.
2346 * return value: success or failure
2347 * toc_kind: kind of toc reference
2348 * input_line_pointer:
2349 * success: first char after the ']'
2350 * failure: unchanged
2354 * [toc] - rv == success, toc_kind = default_toc
2355 * [tocv] - rv == success, toc_kind = data_in_toc
2356 * [toc32] - rv == success, toc_kind = must_be_32
2357 * [toc64] - rv == success, toc_kind = must_be_64
2361 enum toc_size_qualifier
2363 default_toc
, /* The toc cell constructed should be the system default size */
2364 data_in_toc
, /* This is a direct reference to a toc cell */
2365 must_be_32
, /* The toc cell constructed must be 32 bits wide */
2366 must_be_64
/* The toc cell constructed must be 64 bits wide */
2370 parse_toc_entry (enum toc_size_qualifier
*toc_kind
)
2375 enum toc_size_qualifier t
;
2377 /* Save the input_line_pointer. */
2378 start
= input_line_pointer
;
2380 /* Skip over the '[' , and whitespace. */
2381 ++input_line_pointer
;
2384 /* Find the spelling of the operand. */
2385 toc_spec
= input_line_pointer
;
2386 c
= get_symbol_end ();
2388 if (strcmp (toc_spec
, "toc") == 0)
2392 else if (strcmp (toc_spec
, "tocv") == 0)
2396 else if (strcmp (toc_spec
, "toc32") == 0)
2400 else if (strcmp (toc_spec
, "toc64") == 0)
2406 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec
);
2407 *input_line_pointer
= c
;
2408 input_line_pointer
= start
;
2412 /* Now find the ']'. */
2413 *input_line_pointer
= c
;
2415 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2416 c
= *input_line_pointer
++; /* input_line_pointer->past char in c. */
2420 as_bad (_("syntax error: expected `]', found `%c'"), c
);
2421 input_line_pointer
= start
;
2430 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
2431 /* See whether a symbol is in the TOC section. */
2434 ppc_is_toc_sym (symbolS
*sym
)
2437 return symbol_get_tc (sym
)->symbol_class
== XMC_TC
;
2440 const char *sname
= segment_name (S_GET_SEGMENT (sym
));
2442 return strcmp (sname
, ".toc") == 0;
2444 return strcmp (sname
, ".got") == 0;
2447 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
2451 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2453 ppc_apuinfo_section_add (unsigned int apu
, unsigned int version
)
2457 /* Check we don't already exist. */
2458 for (i
= 0; i
< ppc_apuinfo_num
; i
++)
2459 if (ppc_apuinfo_list
[i
] == APUID (apu
, version
))
2462 if (ppc_apuinfo_num
== ppc_apuinfo_num_alloc
)
2464 if (ppc_apuinfo_num_alloc
== 0)
2466 ppc_apuinfo_num_alloc
= 4;
2467 ppc_apuinfo_list
= (unsigned long *)
2468 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2472 ppc_apuinfo_num_alloc
+= 4;
2473 ppc_apuinfo_list
= (unsigned long *) xrealloc (ppc_apuinfo_list
,
2474 sizeof (unsigned long) * ppc_apuinfo_num_alloc
);
2477 ppc_apuinfo_list
[ppc_apuinfo_num
++] = APUID (apu
, version
);
2483 /* We need to keep a list of fixups. We can't simply generate them as
2484 we go, because that would require us to first create the frag, and
2485 that would screw up references to ``.''. */
2491 bfd_reloc_code_real_type reloc
;
2494 #define MAX_INSN_FIXUPS (5)
2497 #define E_OR2I_INSN 0x7000C000
2498 #define E_AND2I_DOT_INSN 0x7000C800
2499 #define E_OR2IS_INSN 0x7000D000
2500 #define E_LIS_INSN 0x7000E000
2501 #define E_AND2IS_DOT_INSN 0x7000E800
2504 #define E_ADD2I_DOT_INSN 0x70008800
2505 #define E_ADD2IS_INSN 0x70009000
2506 #define E_CMP16I_INSN 0x70009800
2507 #define E_MULL2I_INSN 0x7000A000
2508 #define E_CMPL16I_INSN 0x7000A800
2509 #define E_CMPH16I_INSN 0x7000B000
2510 #define E_CMPHL16I_INSN 0x7000B800
2512 /* This routine is called for each instruction to be assembled. */
2515 md_assemble (char *str
)
2518 const struct powerpc_opcode
*opcode
;
2520 const unsigned char *opindex_ptr
;
2524 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
2529 unsigned int insn_length
;
2531 /* Get the opcode. */
2532 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
2537 /* Look up the opcode in the hash table. */
2538 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
2539 if (opcode
== (const struct powerpc_opcode
*) NULL
)
2541 const struct powerpc_macro
*macro
;
2543 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
2544 if (macro
== (const struct powerpc_macro
*) NULL
)
2545 as_bad (_("unrecognized opcode: `%s'"), str
);
2547 ppc_macro (s
, macro
);
2552 insn
= opcode
->opcode
;
2555 while (ISSPACE (*str
))
2558 /* PowerPC operands are just expressions. The only real issue is
2559 that a few operand types are optional. All cases which might use
2560 an optional operand separate the operands only with commas (in some
2561 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2562 have optional operands). Most instructions with optional operands
2563 have only one. Those that have more than one optional operand can
2564 take either all their operands or none. So, before we start seriously
2565 parsing the operands, we check to see if we have optional operands,
2566 and if we do, we count the number of commas to see which operands
2567 have been omitted. */
2569 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2571 const struct powerpc_operand
*operand
;
2573 operand
= &powerpc_operands
[*opindex_ptr
];
2574 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
2576 unsigned int opcount
;
2577 unsigned int num_operands_expected
;
2579 /* There is an optional operand. Count the number of
2580 commas in the input line. */
2587 while ((s
= strchr (s
, ',')) != (char *) NULL
)
2594 /* Compute the number of expected operands.
2595 Do not count fake operands. */
2596 for (num_operands_expected
= 0, i
= 0; opcode
->operands
[i
]; i
++)
2597 if ((powerpc_operands
[opcode
->operands
[i
]].flags
& PPC_OPERAND_FAKE
) == 0)
2598 ++ num_operands_expected
;
2600 /* If there are fewer operands in the line then are called
2601 for by the instruction, we want to skip the optional
2603 if (opcount
< num_operands_expected
)
2610 /* Gather the operands. */
2614 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2616 const struct powerpc_operand
*operand
;
2622 if (next_opindex
== 0)
2623 operand
= &powerpc_operands
[*opindex_ptr
];
2626 operand
= &powerpc_operands
[next_opindex
];
2631 /* If this is a fake operand, then we do not expect anything
2633 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
2635 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2636 if (errmsg
!= (const char *) NULL
)
2637 as_bad ("%s", errmsg
);
2641 /* If this is an optional operand, and we are skipping it, just
2643 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
2646 if (operand
->insert
)
2648 insn
= (*operand
->insert
) (insn
, 0L, ppc_cpu
, &errmsg
);
2649 if (errmsg
!= (const char *) NULL
)
2650 as_bad ("%s", errmsg
);
2652 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
2653 next_opindex
= *opindex_ptr
+ 1;
2657 /* Gather the operand. */
2658 hold
= input_line_pointer
;
2659 input_line_pointer
= str
;
2662 if (*input_line_pointer
== '[')
2664 /* We are expecting something like the second argument here:
2666 * lwz r4,[toc].GS.0.static_int(rtoc)
2667 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2668 * The argument following the `]' must be a symbol name, and the
2669 * register must be the toc register: 'rtoc' or '2'
2671 * The effect is to 0 as the displacement field
2672 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2673 * the appropriate variation) reloc against it based on the symbol.
2674 * The linker will build the toc, and insert the resolved toc offset.
2677 * o The size of the toc entry is currently assumed to be
2678 * 32 bits. This should not be assumed to be a hard coded
2680 * o In an effort to cope with a change from 32 to 64 bits,
2681 * there are also toc entries that are specified to be
2682 * either 32 or 64 bits:
2683 * lwz r4,[toc32].GS.0.static_int(rtoc)
2684 * lwz r4,[toc64].GS.0.static_int(rtoc)
2685 * These demand toc entries of the specified size, and the
2686 * instruction probably requires it.
2690 enum toc_size_qualifier toc_kind
;
2691 bfd_reloc_code_real_type toc_reloc
;
2693 /* Go parse off the [tocXX] part. */
2694 valid_toc
= parse_toc_entry (&toc_kind
);
2698 /* Note: message has already been issued.
2699 FIXME: what sort of recovery should we do?
2700 demand_rest_of_line (); return; ? */
2703 /* Now get the symbol following the ']'. */
2709 /* In this case, we may not have seen the symbol yet,
2710 since it is allowed to appear on a .extern or .globl
2711 or just be a label in the .data section. */
2712 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2715 /* 1. The symbol must be defined and either in the toc
2716 section, or a global.
2717 2. The reloc generated must have the TOCDEFN flag set
2718 in upper bit mess of the reloc type.
2719 FIXME: It's a little confusing what the tocv
2720 qualifier can be used for. At the very least, I've
2721 seen three uses, only one of which I'm sure I can
2723 if (ex
.X_op
== O_symbol
)
2725 gas_assert (ex
.X_add_symbol
!= NULL
);
2726 if (symbol_get_bfdsym (ex
.X_add_symbol
)->section
2729 as_bad (_("[tocv] symbol is not a toc symbol"));
2733 toc_reloc
= BFD_RELOC_PPC_TOC16
;
2736 /* FIXME: these next two specifically specify 32/64 bit
2737 toc entries. We don't support them today. Is this
2738 the right way to say that? */
2739 toc_reloc
= BFD_RELOC_UNUSED
;
2740 as_bad (_("unimplemented toc32 expression modifier"));
2743 /* FIXME: see above. */
2744 toc_reloc
= BFD_RELOC_UNUSED
;
2745 as_bad (_("unimplemented toc64 expression modifier"));
2749 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2755 /* We need to generate a fixup for this expression. */
2756 if (fc
>= MAX_INSN_FIXUPS
)
2757 as_fatal (_("too many fixups"));
2759 fixups
[fc
].reloc
= toc_reloc
;
2760 fixups
[fc
].exp
= ex
;
2761 fixups
[fc
].opindex
= *opindex_ptr
;
2764 /* Ok. We've set up the fixup for the instruction. Now make it
2765 look like the constant 0 was found here. */
2767 ex
.X_op
= O_constant
;
2768 ex
.X_add_number
= 0;
2769 ex
.X_add_symbol
= NULL
;
2770 ex
.X_op_symbol
= NULL
;
2777 && (((operand
->flags
& PPC_OPERAND_CR_BIT
) != 0)
2778 || ((operand
->flags
& PPC_OPERAND_CR_REG
) != 0)))
2779 || !register_name (&ex
))
2781 char save_lex
= lex_type
['%'];
2783 if (((operand
->flags
& PPC_OPERAND_CR_REG
) != 0)
2784 || (operand
->flags
& PPC_OPERAND_CR_BIT
) != 0)
2787 lex_type
['%'] |= LEX_BEGIN_NAME
;
2791 lex_type
['%'] = save_lex
;
2795 str
= input_line_pointer
;
2796 input_line_pointer
= hold
;
2798 if (ex
.X_op
== O_illegal
)
2799 as_bad (_("illegal operand"));
2800 else if (ex
.X_op
== O_absent
)
2801 as_bad (_("missing operand"));
2802 else if (ex
.X_op
== O_register
)
2804 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2805 ppc_cpu
, (char *) NULL
, 0);
2807 else if (ex
.X_op
== O_constant
)
2810 /* Allow @HA, @L, @H on constants. */
2811 bfd_reloc_code_real_type reloc
;
2812 char *orig_str
= str
;
2814 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2821 case BFD_RELOC_LO16
:
2822 /* X_unsigned is the default, so if the user has done
2823 something which cleared it, we always produce a
2825 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2826 ex
.X_add_number
&= 0xffff;
2828 ex
.X_add_number
= SEX16 (ex
.X_add_number
);
2831 case BFD_RELOC_HI16
:
2832 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2833 ex
.X_add_number
= PPC_HI (ex
.X_add_number
);
2835 ex
.X_add_number
= SEX16 (PPC_HI (ex
.X_add_number
));
2838 case BFD_RELOC_HI16_S
:
2839 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2840 ex
.X_add_number
= PPC_HA (ex
.X_add_number
);
2842 ex
.X_add_number
= SEX16 (PPC_HA (ex
.X_add_number
));
2845 case BFD_RELOC_PPC64_HIGHER
:
2846 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2847 ex
.X_add_number
= PPC_HIGHER (ex
.X_add_number
);
2849 ex
.X_add_number
= SEX16 (PPC_HIGHER (ex
.X_add_number
));
2852 case BFD_RELOC_PPC64_HIGHER_S
:
2853 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2854 ex
.X_add_number
= PPC_HIGHERA (ex
.X_add_number
);
2856 ex
.X_add_number
= SEX16 (PPC_HIGHERA (ex
.X_add_number
));
2859 case BFD_RELOC_PPC64_HIGHEST
:
2860 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2861 ex
.X_add_number
= PPC_HIGHEST (ex
.X_add_number
);
2863 ex
.X_add_number
= SEX16 (PPC_HIGHEST (ex
.X_add_number
));
2866 case BFD_RELOC_PPC64_HIGHEST_S
:
2867 if (ex
.X_unsigned
&& ! (operand
->flags
& PPC_OPERAND_SIGNED
))
2868 ex
.X_add_number
= PPC_HIGHESTA (ex
.X_add_number
);
2870 ex
.X_add_number
= SEX16 (PPC_HIGHESTA (ex
.X_add_number
));
2873 #endif /* OBJ_ELF */
2874 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
2875 ppc_cpu
, (char *) NULL
, 0);
2879 bfd_reloc_code_real_type reloc
= BFD_RELOC_UNUSED
;
2881 if (ex
.X_op
== O_symbol
&& str
[0] == '(')
2883 const char *sym_name
= S_GET_NAME (ex
.X_add_symbol
);
2884 if (sym_name
[0] == '.')
2887 if (strcasecmp (sym_name
, "__tls_get_addr") == 0)
2889 expressionS tls_exp
;
2891 hold
= input_line_pointer
;
2892 input_line_pointer
= str
+ 1;
2893 expression (&tls_exp
);
2894 if (tls_exp
.X_op
== O_symbol
)
2896 reloc
= BFD_RELOC_UNUSED
;
2897 if (strncasecmp (input_line_pointer
, "@tlsgd)", 7) == 0)
2899 reloc
= BFD_RELOC_PPC_TLSGD
;
2900 input_line_pointer
+= 7;
2902 else if (strncasecmp (input_line_pointer
, "@tlsld)", 7) == 0)
2904 reloc
= BFD_RELOC_PPC_TLSLD
;
2905 input_line_pointer
+= 7;
2907 if (reloc
!= BFD_RELOC_UNUSED
)
2910 str
= input_line_pointer
;
2912 if (fc
>= MAX_INSN_FIXUPS
)
2913 as_fatal (_("too many fixups"));
2914 fixups
[fc
].exp
= tls_exp
;
2915 fixups
[fc
].opindex
= *opindex_ptr
;
2916 fixups
[fc
].reloc
= reloc
;
2920 input_line_pointer
= hold
;
2924 if ((reloc
= ppc_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2926 /* Some TLS tweaks. */
2932 case BFD_RELOC_PPC_TLS
:
2933 if (!_bfd_elf_ppc_at_tls_transform (opcode
->opcode
, 0))
2934 as_bad (_("@tls may not be used with \"%s\" operands"),
2936 else if (operand
->shift
!= 11)
2937 as_bad (_("@tls may only be used in last operand"));
2939 insn
= ppc_insert_operand (insn
, operand
,
2941 ppc_cpu
, (char *) NULL
, 0);
2944 /* We'll only use the 32 (or 64) bit form of these relocations
2945 in constants. Instructions get the 16 bit form. */
2946 case BFD_RELOC_PPC_DTPREL
:
2947 reloc
= BFD_RELOC_PPC_DTPREL16
;
2949 case BFD_RELOC_PPC_TPREL
:
2950 reloc
= BFD_RELOC_PPC_TPREL16
;
2954 /* If VLE-mode convert LO/HI/HA relocations. */
2955 if (opcode
->flags
& PPC_OPCODE_VLE
)
2957 int tmp_insn
= insn
& opcode
->mask
;
2959 int use_d_reloc
= (tmp_insn
== E_OR2I_INSN
2960 || tmp_insn
== E_AND2I_DOT_INSN
2961 || tmp_insn
== E_OR2IS_INSN
2962 || tmp_insn
== E_LIS_INSN
2963 || tmp_insn
== E_AND2IS_DOT_INSN
);
2966 int use_a_reloc
= (tmp_insn
== E_ADD2I_DOT_INSN
2967 || tmp_insn
== E_ADD2IS_INSN
2968 || tmp_insn
== E_CMP16I_INSN
2969 || tmp_insn
== E_MULL2I_INSN
2970 || tmp_insn
== E_CMPL16I_INSN
2971 || tmp_insn
== E_CMPH16I_INSN
2972 || tmp_insn
== E_CMPHL16I_INSN
);
2979 case BFD_RELOC_PPC_EMB_SDA21
:
2980 reloc
= BFD_RELOC_PPC_VLE_SDA21
;
2983 case BFD_RELOC_LO16
:
2985 reloc
= BFD_RELOC_PPC_VLE_LO16D
;
2986 else if (use_a_reloc
)
2987 reloc
= BFD_RELOC_PPC_VLE_LO16A
;
2990 case BFD_RELOC_HI16
:
2992 reloc
= BFD_RELOC_PPC_VLE_HI16D
;
2993 else if (use_a_reloc
)
2994 reloc
= BFD_RELOC_PPC_VLE_HI16A
;
2997 case BFD_RELOC_HI16_S
:
2999 reloc
= BFD_RELOC_PPC_VLE_HA16D
;
3000 else if (use_a_reloc
)
3001 reloc
= BFD_RELOC_PPC_VLE_HA16A
;
3004 case BFD_RELOC_PPC_VLE_SDAREL_LO16A
:
3006 reloc
= BFD_RELOC_PPC_VLE_SDAREL_LO16D
;
3009 case BFD_RELOC_PPC_VLE_SDAREL_HI16A
:
3011 reloc
= BFD_RELOC_PPC_VLE_SDAREL_HI16D
;
3014 case BFD_RELOC_PPC_VLE_SDAREL_HA16A
:
3016 reloc
= BFD_RELOC_PPC_VLE_SDAREL_HA16D
;
3021 /* For the absolute forms of branches, convert the PC
3022 relative form back into the absolute. */
3023 if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
3027 case BFD_RELOC_PPC_B26
:
3028 reloc
= BFD_RELOC_PPC_BA26
;
3030 case BFD_RELOC_PPC_B16
:
3031 reloc
= BFD_RELOC_PPC_BA16
;
3033 case BFD_RELOC_PPC_B16_BRTAKEN
:
3034 reloc
= BFD_RELOC_PPC_BA16_BRTAKEN
;
3036 case BFD_RELOC_PPC_B16_BRNTAKEN
:
3037 reloc
= BFD_RELOC_PPC_BA16_BRNTAKEN
;
3046 case BFD_RELOC_PPC_TOC16
:
3047 toc_reloc_types
|= has_small_toc_reloc
;
3049 case BFD_RELOC_PPC64_TOC16_LO
:
3050 case BFD_RELOC_PPC64_TOC16_HI
:
3051 case BFD_RELOC_PPC64_TOC16_HA
:
3052 toc_reloc_types
|= has_large_toc_reloc
;
3058 if ((operand
->flags
& (PPC_OPERAND_DS
| PPC_OPERAND_DQ
)) != 0)
3063 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
3065 case BFD_RELOC_LO16
:
3066 reloc
= BFD_RELOC_PPC64_ADDR16_LO_DS
;
3068 case BFD_RELOC_16_GOTOFF
:
3069 reloc
= BFD_RELOC_PPC64_GOT16_DS
;
3071 case BFD_RELOC_LO16_GOTOFF
:
3072 reloc
= BFD_RELOC_PPC64_GOT16_LO_DS
;
3074 case BFD_RELOC_LO16_PLTOFF
:
3075 reloc
= BFD_RELOC_PPC64_PLT16_LO_DS
;
3077 case BFD_RELOC_16_BASEREL
:
3078 reloc
= BFD_RELOC_PPC64_SECTOFF_DS
;
3080 case BFD_RELOC_LO16_BASEREL
:
3081 reloc
= BFD_RELOC_PPC64_SECTOFF_LO_DS
;
3083 case BFD_RELOC_PPC_TOC16
:
3084 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
3086 case BFD_RELOC_PPC64_TOC16_LO
:
3087 reloc
= BFD_RELOC_PPC64_TOC16_LO_DS
;
3089 case BFD_RELOC_PPC64_PLTGOT16
:
3090 reloc
= BFD_RELOC_PPC64_PLTGOT16_DS
;
3092 case BFD_RELOC_PPC64_PLTGOT16_LO
:
3093 reloc
= BFD_RELOC_PPC64_PLTGOT16_LO_DS
;
3095 case BFD_RELOC_PPC_DTPREL16
:
3096 reloc
= BFD_RELOC_PPC64_DTPREL16_DS
;
3098 case BFD_RELOC_PPC_DTPREL16_LO
:
3099 reloc
= BFD_RELOC_PPC64_DTPREL16_LO_DS
;
3101 case BFD_RELOC_PPC_TPREL16
:
3102 reloc
= BFD_RELOC_PPC64_TPREL16_DS
;
3104 case BFD_RELOC_PPC_TPREL16_LO
:
3105 reloc
= BFD_RELOC_PPC64_TPREL16_LO_DS
;
3107 case BFD_RELOC_PPC_GOT_DTPREL16
:
3108 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
3109 case BFD_RELOC_PPC_GOT_TPREL16
:
3110 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
3113 as_bad (_("unsupported relocation for DS offset field"));
3118 #endif /* OBJ_ELF */
3120 if (reloc
!= BFD_RELOC_UNUSED
)
3122 /* Determine a BFD reloc value based on the operand information.
3123 We are only prepared to turn a few of the operands into
3125 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3126 && operand
->bitm
== 0x3fffffc
3127 && operand
->shift
== 0)
3128 reloc
= BFD_RELOC_PPC_B26
;
3129 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3130 && operand
->bitm
== 0xfffc
3131 && operand
->shift
== 0)
3132 reloc
= BFD_RELOC_PPC_B16
;
3133 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3134 && operand
->bitm
== 0x1fe
3135 && operand
->shift
== -1)
3136 reloc
= BFD_RELOC_PPC_VLE_REL8
;
3137 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3138 && operand
->bitm
== 0xfffe
3139 && operand
->shift
== 0)
3140 reloc
= BFD_RELOC_PPC_VLE_REL15
;
3141 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
3142 && operand
->bitm
== 0x1fffffe
3143 && operand
->shift
== 0)
3144 reloc
= BFD_RELOC_PPC_VLE_REL24
;
3145 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3146 && operand
->bitm
== 0x3fffffc
3147 && operand
->shift
== 0)
3148 reloc
= BFD_RELOC_PPC_BA26
;
3149 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
3150 && operand
->bitm
== 0xfffc
3151 && operand
->shift
== 0)
3152 reloc
= BFD_RELOC_PPC_BA16
;
3153 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3154 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
3155 && (operand
->bitm
& 0xfff0) == 0xfff0
3156 && operand
->shift
== 0)
3158 if (ppc_is_toc_sym (ex
.X_add_symbol
))
3160 reloc
= BFD_RELOC_PPC_TOC16
;
3163 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
3164 reloc
= BFD_RELOC_PPC64_TOC16_DS
;
3169 reloc
= BFD_RELOC_16
;
3172 && (operand
->flags
& PPC_OPERAND_DS
) != 0)
3173 reloc
= BFD_RELOC_PPC64_ADDR16_DS
;
3177 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3179 /* We need to generate a fixup for this expression. */
3180 if (fc
>= MAX_INSN_FIXUPS
)
3181 as_fatal (_("too many fixups"));
3182 fixups
[fc
].exp
= ex
;
3183 fixups
[fc
].opindex
= *opindex_ptr
;
3184 fixups
[fc
].reloc
= reloc
;
3192 /* If expecting more operands, then we want to see "),". */
3193 if (*str
== endc
&& opindex_ptr
[1] != 0)
3197 while (ISSPACE (*str
));
3201 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
3209 /* The call to expression should have advanced str past any
3212 && (endc
!= ',' || *str
!= '\0'))
3215 as_bad (_("syntax error; end of line, expected `%c'"), endc
);
3217 as_bad (_("syntax error; found `%c', expected `%c'"), *str
, endc
);
3225 while (ISSPACE (*str
))
3229 as_bad (_("junk at end of line: `%s'"), str
);
3232 /* Do we need/want an APUinfo section? */
3233 if ((ppc_cpu
& (PPC_OPCODE_E500
| PPC_OPCODE_E500MC
| PPC_OPCODE_VLE
)) != 0)
3235 /* These are all version "1". */
3236 if (opcode
->flags
& PPC_OPCODE_SPE
)
3237 ppc_apuinfo_section_add (PPC_APUINFO_SPE
, 1);
3238 if (opcode
->flags
& PPC_OPCODE_ISEL
)
3239 ppc_apuinfo_section_add (PPC_APUINFO_ISEL
, 1);
3240 if (opcode
->flags
& PPC_OPCODE_EFS
)
3241 ppc_apuinfo_section_add (PPC_APUINFO_EFS
, 1);
3242 if (opcode
->flags
& PPC_OPCODE_BRLOCK
)
3243 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK
, 1);
3244 if (opcode
->flags
& PPC_OPCODE_PMR
)
3245 ppc_apuinfo_section_add (PPC_APUINFO_PMR
, 1);
3246 if (opcode
->flags
& PPC_OPCODE_CACHELCK
)
3247 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK
, 1);
3248 if (opcode
->flags
& PPC_OPCODE_RFMCI
)
3249 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI
, 1);
3250 if (opcode
->flags
& PPC_OPCODE_VLE
)
3251 ppc_apuinfo_section_add (PPC_APUINFO_VLE
, 1);
3255 /* Write out the instruction. */
3256 /* Differentiate between two and four byte insns. */
3257 if (ppc_mach () == bfd_mach_ppc_vle
)
3259 if (PPC_OP_SE_VLE (insn
))
3263 addr_mod
= frag_now_fix () & 1;
3268 addr_mod
= frag_now_fix () & 3;
3270 /* All instructions can start on a 2 byte boundary for VLE. */
3271 f
= frag_more (insn_length
);
3272 if (frag_now
->has_code
&& frag_now
->insn_addr
!= addr_mod
)
3274 if (ppc_mach() == bfd_mach_ppc_vle
)
3275 as_bad (_("instruction address is not a multiple of 2"));
3277 as_bad (_("instruction address is not a multiple of 4"));
3279 frag_now
->insn_addr
= addr_mod
;
3280 frag_now
->has_code
= 1;
3281 md_number_to_chars (f
, insn
, insn_length
);
3284 dwarf2_emit_insn (insn_length
);
3287 /* Create any fixups. */
3288 for (i
= 0; i
< fc
; i
++)
3291 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
3293 reloc_howto_type
*reloc_howto
;
3297 reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
3301 size
= bfd_get_reloc_size (reloc_howto
);
3302 offset
= target_big_endian
? (insn_length
- size
) : 0;
3304 if (size
< 1 || size
> 4)
3307 fixP
= fix_new_exp (frag_now
,
3308 f
- frag_now
->fr_literal
+ offset
,
3311 reloc_howto
->pc_relative
,
3316 const struct powerpc_operand
*operand
;
3318 operand
= &powerpc_operands
[fixups
[i
].opindex
];
3319 fixP
= fix_new_exp (frag_now
,
3320 f
- frag_now
->fr_literal
,
3323 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
3326 fixP
->fx_pcrel_adjust
= fixups
[i
].opindex
;
3330 /* Handle a macro. Gather all the operands, transform them as
3331 described by the macro, and call md_assemble recursively. All the
3332 operands are separated by commas; we don't accept parentheses
3333 around operands here. */
3336 ppc_macro (char *str
, const struct powerpc_macro
*macro
)
3347 /* Gather the users operands into the operands array. */
3352 if (count
>= sizeof operands
/ sizeof operands
[0])
3354 operands
[count
++] = s
;
3355 s
= strchr (s
, ',');
3356 if (s
== (char *) NULL
)
3361 if (count
!= macro
->operands
)
3363 as_bad (_("wrong number of operands"));
3367 /* Work out how large the string must be (the size is unbounded
3368 because it includes user input). */
3370 format
= macro
->format
;
3371 while (*format
!= '\0')
3380 arg
= strtol (format
+ 1, &send
, 10);
3381 know (send
!= format
&& arg
< count
);
3382 len
+= strlen (operands
[arg
]);
3387 /* Put the string together. */
3388 complete
= s
= (char *) alloca (len
+ 1);
3389 format
= macro
->format
;
3390 while (*format
!= '\0')
3396 arg
= strtol (format
+ 1, &send
, 10);
3397 strcpy (s
, operands
[arg
]);
3404 /* Assemble the constructed instruction. */
3405 md_assemble (complete
);
3409 /* For ELF, add support for SHT_ORDERED. */
3412 ppc_section_type (char *str
, size_t len
)
3414 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
3421 ppc_section_flags (flagword flags
, bfd_vma attr ATTRIBUTE_UNUSED
, int type
)
3423 if (type
== SHT_ORDERED
)
3424 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
3428 #endif /* OBJ_ELF */
3431 /* Pseudo-op handling. */
3433 /* The .byte pseudo-op. This is similar to the normal .byte
3434 pseudo-op, but it can also take a single ASCII string. */
3437 ppc_byte (int ignore ATTRIBUTE_UNUSED
)
3439 if (*input_line_pointer
!= '\"')
3445 /* Gather characters. A real double quote is doubled. Unusual
3446 characters are not permitted. */
3447 ++input_line_pointer
;
3452 c
= *input_line_pointer
++;
3456 if (*input_line_pointer
!= '\"')
3458 ++input_line_pointer
;
3461 FRAG_APPEND_1_CHAR (c
);
3464 demand_empty_rest_of_line ();
3469 /* XCOFF specific pseudo-op handling. */
3471 /* This is set if we are creating a .stabx symbol, since we don't want
3472 to handle symbol suffixes for such symbols. */
3473 static bfd_boolean ppc_stab_symbol
;
3475 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
3476 symbols in the .bss segment as though they were local common
3477 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
3478 aligns .comm and .lcomm to 4 bytes. */
3481 ppc_comm (int lcomm
)
3483 asection
*current_seg
= now_seg
;
3484 subsegT current_subseg
= now_subseg
;
3490 symbolS
*lcomm_sym
= NULL
;
3494 name
= input_line_pointer
;
3495 endc
= get_symbol_end ();
3496 end_name
= input_line_pointer
;
3499 if (*input_line_pointer
!= ',')
3501 as_bad (_("missing size"));
3502 ignore_rest_of_line ();
3505 ++input_line_pointer
;
3507 size
= get_absolute_expression ();
3510 as_bad (_("negative size"));
3511 ignore_rest_of_line ();
3517 /* The third argument to .comm is the alignment. */
3518 if (*input_line_pointer
!= ',')
3522 ++input_line_pointer
;
3523 align
= get_absolute_expression ();
3526 as_warn (_("ignoring bad alignment"));
3541 /* The third argument to .lcomm appears to be the real local
3542 common symbol to create. References to the symbol named in
3543 the first argument are turned into references to the third
3545 if (*input_line_pointer
!= ',')
3547 as_bad (_("missing real symbol name"));
3548 ignore_rest_of_line ();
3551 ++input_line_pointer
;
3553 lcomm_name
= input_line_pointer
;
3554 lcomm_endc
= get_symbol_end ();
3556 lcomm_sym
= symbol_find_or_make (lcomm_name
);
3558 *input_line_pointer
= lcomm_endc
;
3562 sym
= symbol_find_or_make (name
);
3565 if (S_IS_DEFINED (sym
)
3566 || S_GET_VALUE (sym
) != 0)
3568 as_bad (_("attempt to redefine symbol"));
3569 ignore_rest_of_line ();
3573 record_alignment (bss_section
, align
);
3576 || ! S_IS_DEFINED (lcomm_sym
))
3585 S_SET_EXTERNAL (sym
);
3589 symbol_get_tc (lcomm_sym
)->output
= 1;
3590 def_sym
= lcomm_sym
;
3594 subseg_set (bss_section
, 1);
3595 frag_align (align
, 0, 0);
3597 symbol_set_frag (def_sym
, frag_now
);
3598 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
3599 def_size
, (char *) NULL
);
3601 S_SET_SEGMENT (def_sym
, bss_section
);
3602 symbol_get_tc (def_sym
)->align
= align
;
3606 /* Align the size of lcomm_sym. */
3607 symbol_get_frag (lcomm_sym
)->fr_offset
=
3608 ((symbol_get_frag (lcomm_sym
)->fr_offset
+ (1 << align
) - 1)
3609 &~ ((1 << align
) - 1));
3610 if (align
> symbol_get_tc (lcomm_sym
)->align
)
3611 symbol_get_tc (lcomm_sym
)->align
= align
;
3616 /* Make sym an offset from lcomm_sym. */
3617 S_SET_SEGMENT (sym
, bss_section
);
3618 symbol_set_frag (sym
, symbol_get_frag (lcomm_sym
));
3619 S_SET_VALUE (sym
, symbol_get_frag (lcomm_sym
)->fr_offset
);
3620 symbol_get_frag (lcomm_sym
)->fr_offset
+= size
;
3623 subseg_set (current_seg
, current_subseg
);
3625 demand_empty_rest_of_line ();
3628 /* The .csect pseudo-op. This switches us into a different
3629 subsegment. The first argument is a symbol whose value is the
3630 start of the .csect. In COFF, csect symbols get special aux
3631 entries defined by the x_csect field of union internal_auxent. The
3632 optional second argument is the alignment (the default is 2). */
3635 ppc_csect (int ignore ATTRIBUTE_UNUSED
)
3642 name
= input_line_pointer
;
3643 endc
= get_symbol_end ();
3645 sym
= symbol_find_or_make (name
);
3647 *input_line_pointer
= endc
;
3649 if (S_GET_NAME (sym
)[0] == '\0')
3651 /* An unnamed csect is assumed to be [PR]. */
3652 symbol_get_tc (sym
)->symbol_class
= XMC_PR
;
3656 if (*input_line_pointer
== ',')
3658 ++input_line_pointer
;
3659 align
= get_absolute_expression ();
3662 ppc_change_csect (sym
, align
);
3664 demand_empty_rest_of_line ();
3667 /* Change to a different csect. */
3670 ppc_change_csect (symbolS
*sym
, offsetT align
)
3672 if (S_IS_DEFINED (sym
))
3673 subseg_set (S_GET_SEGMENT (sym
), symbol_get_tc (sym
)->subseg
);
3683 /* This is a new csect. We need to look at the symbol class to
3684 figure out whether it should go in the text section or the
3688 switch (symbol_get_tc (sym
)->symbol_class
)
3698 S_SET_SEGMENT (sym
, text_section
);
3699 symbol_get_tc (sym
)->subseg
= ppc_text_subsegment
;
3700 ++ppc_text_subsegment
;
3701 list_ptr
= &ppc_text_csects
;
3711 if (ppc_toc_csect
!= NULL
3712 && (symbol_get_tc (ppc_toc_csect
)->subseg
+ 1
3713 == ppc_data_subsegment
))
3715 S_SET_SEGMENT (sym
, data_section
);
3716 symbol_get_tc (sym
)->subseg
= ppc_data_subsegment
;
3717 ++ppc_data_subsegment
;
3718 list_ptr
= &ppc_data_csects
;
3724 /* We set the obstack chunk size to a small value before
3725 changing subsegments, so that we don't use a lot of memory
3726 space for what may be a small section. */
3727 hold_chunksize
= chunksize
;
3730 sec
= subseg_new (segment_name (S_GET_SEGMENT (sym
)),
3731 symbol_get_tc (sym
)->subseg
);
3733 chunksize
= hold_chunksize
;
3736 ppc_after_toc_frag
= frag_now
;
3738 record_alignment (sec
, align
);
3740 frag_align_code (align
, 0);
3742 frag_align (align
, 0, 0);
3744 symbol_set_frag (sym
, frag_now
);
3745 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
3747 symbol_get_tc (sym
)->align
= align
;
3748 symbol_get_tc (sym
)->output
= 1;
3749 symbol_get_tc (sym
)->within
= sym
;
3751 for (list
= *list_ptr
;
3752 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
3753 list
= symbol_get_tc (list
)->next
)
3755 symbol_get_tc (list
)->next
= sym
;
3757 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3758 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
3762 ppc_current_csect
= sym
;
3766 ppc_change_debug_section (unsigned int idx
, subsegT subseg
)
3770 const struct xcoff_dwsect_name
*dw
= &xcoff_dwsect_names
[idx
];
3772 sec
= subseg_new (dw
->name
, subseg
);
3773 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
3774 if (oldflags
== SEC_NO_FLAGS
)
3776 /* Just created section. */
3777 gas_assert (dw_sections
[idx
].sect
== NULL
);
3779 bfd_set_section_flags (stdoutput
, sec
, SEC_DEBUGGING
);
3780 bfd_set_section_alignment (stdoutput
, sec
, 0);
3781 dw_sections
[idx
].sect
= sec
;
3784 /* Not anymore in a csect. */
3785 ppc_current_csect
= NULL
;
3788 /* The .dwsect pseudo-op. Defines a DWARF section. Syntax is:
3789 .dwsect flag [, opt-label ]
3793 ppc_dwsect (int ignore ATTRIBUTE_UNUSED
)
3797 const struct xcoff_dwsect_name
*dw
;
3798 struct dw_subsection
*subseg
;
3799 struct dw_section
*dws
;
3803 flag
= get_absolute_expression ();
3805 for (i
= 0; i
< XCOFF_DWSECT_NBR_NAMES
; i
++)
3806 if (xcoff_dwsect_names
[i
].flag
== flag
)
3808 dw
= &xcoff_dwsect_names
[i
];
3812 /* Parse opt-label. */
3813 if (*input_line_pointer
== ',')
3818 ++input_line_pointer
;
3820 label
= input_line_pointer
;
3821 c
= get_symbol_end ();
3822 opt_label
= symbol_find_or_make (label
);
3823 *input_line_pointer
= c
;
3828 demand_empty_rest_of_line ();
3830 /* Return now in case of unknown subsection. */
3833 as_bad (_("no known dwarf XCOFF section for flag 0x%08x\n"),
3838 /* Find the subsection. */
3839 dws
= &dw_sections
[i
];
3841 if (opt_label
!= NULL
&& S_IS_DEFINED (opt_label
))
3843 /* Sanity check (note that in theory S_GET_SEGMENT mustn't be null). */
3844 if (dws
->sect
== NULL
|| S_GET_SEGMENT (opt_label
) != dws
->sect
)
3846 as_bad (_("label %s was not defined in this dwarf section"),
3847 S_GET_NAME (opt_label
));
3848 subseg
= dws
->anon_subseg
;
3852 subseg
= symbol_get_tc (opt_label
)->u
.dw
;
3857 /* Switch to the subsection. */
3858 ppc_change_debug_section (i
, subseg
->subseg
);
3862 /* Create a new dw subsection. */
3863 subseg
= (struct dw_subsection
*)
3864 xmalloc (sizeof (struct dw_subsection
));
3866 if (opt_label
== NULL
)
3868 /* The anonymous one. */
3870 subseg
->link
= NULL
;
3871 dws
->anon_subseg
= subseg
;
3876 if (dws
->list_subseg
!= NULL
)
3877 subseg
->subseg
= dws
->list_subseg
->subseg
+ 1;
3881 subseg
->link
= dws
->list_subseg
;
3882 dws
->list_subseg
= subseg
;
3883 symbol_get_tc (opt_label
)->u
.dw
= subseg
;
3886 ppc_change_debug_section (i
, subseg
->subseg
);
3890 /* Add the length field. */
3891 expressionS
*exp
= &subseg
->end_exp
;
3894 if (opt_label
!= NULL
)
3895 symbol_set_value_now (opt_label
);
3897 /* Add the length field. Note that according to the AIX assembler
3898 manual, the size of the length field is 4 for powerpc32 but
3899 12 for powerpc64. */
3902 /* Write the 64bit marker. */
3903 md_number_to_chars (frag_more (4), -1, 4);
3906 exp
->X_op
= O_subtract
;
3907 exp
->X_op_symbol
= symbol_temp_new_now ();
3908 exp
->X_add_symbol
= symbol_temp_make ();
3910 sz
= ppc_obj64
? 8 : 4;
3911 exp
->X_add_number
= -sz
;
3912 emit_expr (exp
, sz
);
3917 /* This function handles the .text and .data pseudo-ops. These
3918 pseudo-ops aren't really used by XCOFF; we implement them for the
3919 convenience of people who aren't used to XCOFF. */
3922 ppc_section (int type
)
3929 else if (type
== 'd')
3934 sym
= symbol_find_or_make (name
);
3936 ppc_change_csect (sym
, 2);
3938 demand_empty_rest_of_line ();
3941 /* This function handles the .section pseudo-op. This is mostly to
3942 give an error, since XCOFF only supports .text, .data and .bss, but
3943 we do permit the user to name the text or data section. */
3946 ppc_named_section (int ignore ATTRIBUTE_UNUSED
)
3949 const char *real_name
;
3953 user_name
= input_line_pointer
;
3954 c
= get_symbol_end ();
3956 if (strcmp (user_name
, ".text") == 0)
3957 real_name
= ".text[PR]";
3958 else if (strcmp (user_name
, ".data") == 0)
3959 real_name
= ".data[RW]";
3962 as_bad (_("the XCOFF file format does not support arbitrary sections"));
3963 *input_line_pointer
= c
;
3964 ignore_rest_of_line ();
3968 *input_line_pointer
= c
;
3970 sym
= symbol_find_or_make (real_name
);
3972 ppc_change_csect (sym
, 2);
3974 demand_empty_rest_of_line ();
3977 /* The .extern pseudo-op. We create an undefined symbol. */
3980 ppc_extern (int ignore ATTRIBUTE_UNUSED
)
3985 name
= input_line_pointer
;
3986 endc
= get_symbol_end ();
3988 (void) symbol_find_or_make (name
);
3990 *input_line_pointer
= endc
;
3992 demand_empty_rest_of_line ();
3995 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3998 ppc_lglobl (int ignore ATTRIBUTE_UNUSED
)
4004 name
= input_line_pointer
;
4005 endc
= get_symbol_end ();
4007 sym
= symbol_find_or_make (name
);
4009 *input_line_pointer
= endc
;
4011 symbol_get_tc (sym
)->output
= 1;
4013 demand_empty_rest_of_line ();
4016 /* The .ref pseudo-op. It takes a list of symbol names and inserts R_REF
4017 relocations at the beginning of the current csect.
4019 (In principle, there's no reason why the relocations _have_ to be at
4020 the beginning. Anywhere in the csect would do. However, inserting
4021 at the beginning is what the native assmebler does, and it helps to
4022 deal with cases where the .ref statements follow the section contents.)
4024 ??? .refs don't work for empty .csects. However, the native assembler
4025 doesn't report an error in this case, and neither yet do we. */
4028 ppc_ref (int ignore ATTRIBUTE_UNUSED
)
4033 if (ppc_current_csect
== NULL
)
4035 as_bad (_(".ref outside .csect"));
4036 ignore_rest_of_line ();
4042 name
= input_line_pointer
;
4043 c
= get_symbol_end ();
4045 fix_at_start (symbol_get_frag (ppc_current_csect
), 0,
4046 symbol_find_or_make (name
), 0, FALSE
, BFD_RELOC_NONE
);
4048 *input_line_pointer
= c
;
4050 c
= *input_line_pointer
;
4053 input_line_pointer
++;
4055 if (is_end_of_line
[(unsigned char) *input_line_pointer
])
4057 as_bad (_("missing symbol name"));
4058 ignore_rest_of_line ();
4065 demand_empty_rest_of_line ();
4068 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
4069 although I don't know why it bothers. */
4072 ppc_rename (int ignore ATTRIBUTE_UNUSED
)
4079 name
= input_line_pointer
;
4080 endc
= get_symbol_end ();
4082 sym
= symbol_find_or_make (name
);
4084 *input_line_pointer
= endc
;
4086 if (*input_line_pointer
!= ',')
4088 as_bad (_("missing rename string"));
4089 ignore_rest_of_line ();
4092 ++input_line_pointer
;
4094 symbol_get_tc (sym
)->real_name
= demand_copy_C_string (&len
);
4096 demand_empty_rest_of_line ();
4099 /* The .stabx pseudo-op. This is similar to a normal .stabs
4100 pseudo-op, but slightly different. A sample is
4101 .stabx "main:F-1",.main,142,0
4102 The first argument is the symbol name to create. The second is the
4103 value, and the third is the storage class. The fourth seems to be
4104 always zero, and I am assuming it is the type. */
4107 ppc_stabx (int ignore ATTRIBUTE_UNUSED
)
4114 name
= demand_copy_C_string (&len
);
4116 if (*input_line_pointer
!= ',')
4118 as_bad (_("missing value"));
4121 ++input_line_pointer
;
4123 ppc_stab_symbol
= TRUE
;
4124 sym
= symbol_make (name
);
4125 ppc_stab_symbol
= FALSE
;
4127 symbol_get_tc (sym
)->real_name
= name
;
4129 (void) expression (&exp
);
4136 as_bad (_("illegal .stabx expression; zero assumed"));
4137 exp
.X_add_number
= 0;
4140 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
4141 symbol_set_frag (sym
, &zero_address_frag
);
4145 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
4146 symbol_set_value_expression (sym
, &exp
);
4150 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
4151 symbol_set_frag (sym
, symbol_get_frag (exp
.X_add_symbol
));
4156 /* The value is some complex expression. This will probably
4157 fail at some later point, but this is probably the right
4158 thing to do here. */
4159 symbol_set_value_expression (sym
, &exp
);
4163 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
4164 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4166 if (*input_line_pointer
!= ',')
4168 as_bad (_("missing class"));
4171 ++input_line_pointer
;
4173 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
4175 if (*input_line_pointer
!= ',')
4177 as_bad (_("missing type"));
4180 ++input_line_pointer
;
4182 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
4184 symbol_get_tc (sym
)->output
= 1;
4186 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
4191 .stabx "z",arrays_,133,0
4194 .comm arrays_,13768,3
4196 resolve_symbol_value will copy the exp's "within" into sym's when the
4197 offset is 0. Since this seems to be corner case problem,
4198 only do the correction for storage class C_STSYM. A better solution
4199 would be to have the tc field updated in ppc_symbol_new_hook. */
4201 if (exp
.X_op
== O_symbol
)
4203 if (ppc_current_block
== NULL
)
4204 as_bad (_(".stabx of storage class stsym must be within .bs/.es"));
4206 symbol_get_tc (sym
)->within
= ppc_current_block
;
4207 symbol_get_tc (exp
.X_add_symbol
)->within
= ppc_current_block
;
4211 if (exp
.X_op
!= O_symbol
4212 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
4213 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
4214 ppc_frob_label (sym
);
4217 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4218 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
4219 if (symbol_get_tc (ppc_current_csect
)->within
== exp
.X_add_symbol
)
4220 symbol_get_tc (ppc_current_csect
)->within
= sym
;
4223 demand_empty_rest_of_line ();
4226 /* The .function pseudo-op. This takes several arguments. The first
4227 argument seems to be the external name of the symbol. The second
4228 argument seems to be the label for the start of the function. gcc
4229 uses the same name for both. I have no idea what the third and
4230 fourth arguments are meant to be. The optional fifth argument is
4231 an expression for the size of the function. In COFF this symbol
4232 gets an aux entry like that used for a csect. */
4235 ppc_function (int ignore ATTRIBUTE_UNUSED
)
4243 name
= input_line_pointer
;
4244 endc
= get_symbol_end ();
4246 /* Ignore any [PR] suffix. */
4247 name
= ppc_canonicalize_symbol_name (name
);
4248 s
= strchr (name
, '[');
4249 if (s
!= (char *) NULL
4250 && strcmp (s
+ 1, "PR]") == 0)
4253 ext_sym
= symbol_find_or_make (name
);
4255 *input_line_pointer
= endc
;
4257 if (*input_line_pointer
!= ',')
4259 as_bad (_("missing symbol name"));
4260 ignore_rest_of_line ();
4263 ++input_line_pointer
;
4265 name
= input_line_pointer
;
4266 endc
= get_symbol_end ();
4268 lab_sym
= symbol_find_or_make (name
);
4270 *input_line_pointer
= endc
;
4272 if (ext_sym
!= lab_sym
)
4276 exp
.X_op
= O_symbol
;
4277 exp
.X_add_symbol
= lab_sym
;
4278 exp
.X_op_symbol
= NULL
;
4279 exp
.X_add_number
= 0;
4281 symbol_set_value_expression (ext_sym
, &exp
);
4284 if (symbol_get_tc (ext_sym
)->symbol_class
== -1)
4285 symbol_get_tc (ext_sym
)->symbol_class
= XMC_PR
;
4286 symbol_get_tc (ext_sym
)->output
= 1;
4288 if (*input_line_pointer
== ',')
4292 /* Ignore the third argument. */
4293 ++input_line_pointer
;
4295 if (*input_line_pointer
== ',')
4297 /* Ignore the fourth argument. */
4298 ++input_line_pointer
;
4300 if (*input_line_pointer
== ',')
4302 /* The fifth argument is the function size. */
4303 ++input_line_pointer
;
4304 symbol_get_tc (ext_sym
)->u
.size
= symbol_new
4305 ("L0\001", absolute_section
,(valueT
) 0, &zero_address_frag
);
4306 pseudo_set (symbol_get_tc (ext_sym
)->u
.size
);
4311 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
4312 SF_SET_FUNCTION (ext_sym
);
4313 SF_SET_PROCESS (ext_sym
);
4314 coff_add_linesym (ext_sym
);
4316 demand_empty_rest_of_line ();
4319 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
4320 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
4321 with the correct line number */
4323 static symbolS
*saved_bi_sym
= 0;
4326 ppc_bf (int ignore ATTRIBUTE_UNUSED
)
4330 sym
= symbol_make (".bf");
4331 S_SET_SEGMENT (sym
, text_section
);
4332 symbol_set_frag (sym
, frag_now
);
4333 S_SET_VALUE (sym
, frag_now_fix ());
4334 S_SET_STORAGE_CLASS (sym
, C_FCN
);
4336 coff_line_base
= get_absolute_expression ();
4338 S_SET_NUMBER_AUXILIARY (sym
, 1);
4339 SA_SET_SYM_LNNO (sym
, coff_line_base
);
4341 /* Line number for bi. */
4344 S_SET_VALUE (saved_bi_sym
, coff_n_line_nos
);
4349 symbol_get_tc (sym
)->output
= 1;
4351 ppc_frob_label (sym
);
4353 demand_empty_rest_of_line ();
4356 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
4357 ".ef", except that the line number is absolute, not relative to the
4358 most recent ".bf" symbol. */
4361 ppc_ef (int ignore ATTRIBUTE_UNUSED
)
4365 sym
= symbol_make (".ef");
4366 S_SET_SEGMENT (sym
, text_section
);
4367 symbol_set_frag (sym
, frag_now
);
4368 S_SET_VALUE (sym
, frag_now_fix ());
4369 S_SET_STORAGE_CLASS (sym
, C_FCN
);
4370 S_SET_NUMBER_AUXILIARY (sym
, 1);
4371 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
4372 symbol_get_tc (sym
)->output
= 1;
4374 ppc_frob_label (sym
);
4376 demand_empty_rest_of_line ();
4379 /* The .bi and .ei pseudo-ops. These take a string argument and
4380 generates a C_BINCL or C_EINCL symbol, which goes at the start of
4381 the symbol list. The value of .bi will be know when the next .bf
4387 static symbolS
*last_biei
;
4394 name
= demand_copy_C_string (&len
);
4396 /* The value of these symbols is actually file offset. Here we set
4397 the value to the index into the line number entries. In
4398 ppc_frob_symbols we set the fix_line field, which will cause BFD
4399 to do the right thing. */
4401 sym
= symbol_make (name
);
4402 /* obj-coff.c currently only handles line numbers correctly in the
4404 S_SET_SEGMENT (sym
, text_section
);
4405 S_SET_VALUE (sym
, coff_n_line_nos
);
4406 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4408 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
4409 symbol_get_tc (sym
)->output
= 1;
4417 for (look
= last_biei
? last_biei
: symbol_rootP
;
4418 (look
!= (symbolS
*) NULL
4419 && (S_GET_STORAGE_CLASS (look
) == C_FILE
4420 || S_GET_STORAGE_CLASS (look
) == C_BINCL
4421 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
4422 look
= symbol_next (look
))
4424 if (look
!= (symbolS
*) NULL
)
4426 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4427 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
4431 demand_empty_rest_of_line ();
4434 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
4435 There is one argument, which is a csect symbol. The value of the
4436 .bs symbol is the index of this csect symbol. */
4439 ppc_bs (int ignore ATTRIBUTE_UNUSED
)
4446 if (ppc_current_block
!= NULL
)
4447 as_bad (_("nested .bs blocks"));
4449 name
= input_line_pointer
;
4450 endc
= get_symbol_end ();
4452 csect
= symbol_find_or_make (name
);
4454 *input_line_pointer
= endc
;
4456 sym
= symbol_make (".bs");
4457 S_SET_SEGMENT (sym
, now_seg
);
4458 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
4459 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4460 symbol_get_tc (sym
)->output
= 1;
4462 symbol_get_tc (sym
)->within
= csect
;
4464 ppc_frob_label (sym
);
4466 ppc_current_block
= sym
;
4468 demand_empty_rest_of_line ();
4471 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
4474 ppc_es (int ignore ATTRIBUTE_UNUSED
)
4478 if (ppc_current_block
== NULL
)
4479 as_bad (_(".es without preceding .bs"));
4481 sym
= symbol_make (".es");
4482 S_SET_SEGMENT (sym
, now_seg
);
4483 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
4484 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4485 symbol_get_tc (sym
)->output
= 1;
4487 ppc_frob_label (sym
);
4489 ppc_current_block
= NULL
;
4491 demand_empty_rest_of_line ();
4494 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
4498 ppc_bb (int ignore ATTRIBUTE_UNUSED
)
4502 sym
= symbol_make (".bb");
4503 S_SET_SEGMENT (sym
, text_section
);
4504 symbol_set_frag (sym
, frag_now
);
4505 S_SET_VALUE (sym
, frag_now_fix ());
4506 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
4508 S_SET_NUMBER_AUXILIARY (sym
, 1);
4509 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
4511 symbol_get_tc (sym
)->output
= 1;
4513 SF_SET_PROCESS (sym
);
4515 ppc_frob_label (sym
);
4517 demand_empty_rest_of_line ();
4520 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
4524 ppc_eb (int ignore ATTRIBUTE_UNUSED
)
4528 sym
= symbol_make (".eb");
4529 S_SET_SEGMENT (sym
, text_section
);
4530 symbol_set_frag (sym
, frag_now
);
4531 S_SET_VALUE (sym
, frag_now_fix ());
4532 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
4533 S_SET_NUMBER_AUXILIARY (sym
, 1);
4534 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
4535 symbol_get_tc (sym
)->output
= 1;
4537 SF_SET_PROCESS (sym
);
4539 ppc_frob_label (sym
);
4541 demand_empty_rest_of_line ();
4544 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
4548 ppc_bc (int ignore ATTRIBUTE_UNUSED
)
4554 name
= demand_copy_C_string (&len
);
4555 sym
= symbol_make (name
);
4556 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
4557 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4558 S_SET_STORAGE_CLASS (sym
, C_BCOMM
);
4559 S_SET_VALUE (sym
, 0);
4560 symbol_get_tc (sym
)->output
= 1;
4562 ppc_frob_label (sym
);
4564 demand_empty_rest_of_line ();
4567 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
4570 ppc_ec (int ignore ATTRIBUTE_UNUSED
)
4574 sym
= symbol_make (".ec");
4575 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
4576 symbol_get_bfdsym (sym
)->flags
|= BSF_DEBUGGING
;
4577 S_SET_STORAGE_CLASS (sym
, C_ECOMM
);
4578 S_SET_VALUE (sym
, 0);
4579 symbol_get_tc (sym
)->output
= 1;
4581 ppc_frob_label (sym
);
4583 demand_empty_rest_of_line ();
4586 /* The .toc pseudo-op. Switch to the .toc subsegment. */
4589 ppc_toc (int ignore ATTRIBUTE_UNUSED
)
4591 if (ppc_toc_csect
!= (symbolS
*) NULL
)
4592 subseg_set (data_section
, symbol_get_tc (ppc_toc_csect
)->subseg
);
4599 subseg
= ppc_data_subsegment
;
4600 ++ppc_data_subsegment
;
4602 subseg_new (segment_name (data_section
), subseg
);
4603 ppc_toc_frag
= frag_now
;
4605 sym
= symbol_find_or_make ("TOC[TC0]");
4606 symbol_set_frag (sym
, frag_now
);
4607 S_SET_SEGMENT (sym
, data_section
);
4608 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
4609 symbol_get_tc (sym
)->subseg
= subseg
;
4610 symbol_get_tc (sym
)->output
= 1;
4611 symbol_get_tc (sym
)->within
= sym
;
4613 ppc_toc_csect
= sym
;
4615 for (list
= ppc_data_csects
;
4616 symbol_get_tc (list
)->next
!= (symbolS
*) NULL
;
4617 list
= symbol_get_tc (list
)->next
)
4619 symbol_get_tc (list
)->next
= sym
;
4621 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
4622 symbol_append (sym
, symbol_get_tc (list
)->within
, &symbol_rootP
,
4626 ppc_current_csect
= ppc_toc_csect
;
4628 demand_empty_rest_of_line ();
4631 /* The AIX assembler automatically aligns the operands of a .long or
4632 .short pseudo-op, and we want to be compatible. */
4635 ppc_xcoff_cons (int log_size
)
4637 frag_align (log_size
, 0, 0);
4638 record_alignment (now_seg
, log_size
);
4639 cons (1 << log_size
);
4643 ppc_vbyte (int dummy ATTRIBUTE_UNUSED
)
4648 (void) expression (&exp
);
4650 if (exp
.X_op
!= O_constant
)
4652 as_bad (_("non-constant byte count"));
4656 byte_count
= exp
.X_add_number
;
4658 if (*input_line_pointer
!= ',')
4660 as_bad (_("missing value"));
4664 ++input_line_pointer
;
4669 ppc_xcoff_end (void)
4673 for (i
= 0; i
< XCOFF_DWSECT_NBR_NAMES
; i
++)
4675 struct dw_section
*dws
= &dw_sections
[i
];
4676 struct dw_subsection
*dwss
;
4678 if (dws
->anon_subseg
)
4680 dwss
= dws
->anon_subseg
;
4681 dwss
->link
= dws
->list_subseg
;
4684 dwss
= dws
->list_subseg
;
4686 for (; dwss
!= NULL
; dwss
= dwss
->link
)
4687 if (dwss
->end_exp
.X_add_symbol
!= NULL
)
4689 subseg_set (dws
->sect
, dwss
->subseg
);
4690 symbol_set_value_now (dwss
->end_exp
.X_add_symbol
);
4695 #endif /* OBJ_XCOFF */
4696 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
4698 /* The .tc pseudo-op. This is used when generating either XCOFF or
4699 ELF. This takes two or more arguments.
4701 When generating XCOFF output, the first argument is the name to
4702 give to this location in the toc; this will be a symbol with class
4703 TC. The rest of the arguments are N-byte values to actually put at
4704 this location in the TOC; often there is just one more argument, a
4705 relocatable symbol reference. The size of the value to store
4706 depends on target word size. A 32-bit target uses 4-byte values, a
4707 64-bit target uses 8-byte values.
4709 When not generating XCOFF output, the arguments are the same, but
4710 the first argument is simply ignored. */
4713 ppc_tc (int ignore ATTRIBUTE_UNUSED
)
4717 /* Define the TOC symbol name. */
4723 if (ppc_toc_csect
== (symbolS
*) NULL
4724 || ppc_toc_csect
!= ppc_current_csect
)
4726 as_bad (_(".tc not in .toc section"));
4727 ignore_rest_of_line ();
4731 name
= input_line_pointer
;
4732 endc
= get_symbol_end ();
4734 sym
= symbol_find_or_make (name
);
4736 *input_line_pointer
= endc
;
4738 if (S_IS_DEFINED (sym
))
4742 label
= symbol_get_tc (ppc_current_csect
)->within
;
4743 if (symbol_get_tc (label
)->symbol_class
!= XMC_TC0
)
4745 as_bad (_(".tc with no label"));
4746 ignore_rest_of_line ();
4750 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
4751 symbol_set_frag (label
, symbol_get_frag (sym
));
4752 S_SET_VALUE (label
, S_GET_VALUE (sym
));
4754 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
4755 ++input_line_pointer
;
4760 S_SET_SEGMENT (sym
, now_seg
);
4761 symbol_set_frag (sym
, frag_now
);
4762 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
4763 symbol_get_tc (sym
)->symbol_class
= XMC_TC
;
4764 symbol_get_tc (sym
)->output
= 1;
4766 ppc_frob_label (sym
);
4769 #endif /* OBJ_XCOFF */
4773 /* Skip the TOC symbol name. */
4774 while (is_part_of_name (*input_line_pointer
)
4775 || *input_line_pointer
== ' '
4776 || *input_line_pointer
== '['
4777 || *input_line_pointer
== ']'
4778 || *input_line_pointer
== '{'
4779 || *input_line_pointer
== '}')
4780 ++input_line_pointer
;
4782 /* Align to a four/eight byte boundary. */
4783 align
= ppc_obj64
? 3 : 2;
4784 frag_align (align
, 0, 0);
4785 record_alignment (now_seg
, align
);
4786 #endif /* OBJ_ELF */
4788 if (*input_line_pointer
!= ',')
4789 demand_empty_rest_of_line ();
4792 ++input_line_pointer
;
4793 cons (ppc_obj64
? 8 : 4);
4797 /* Pseudo-op .machine. */
4800 ppc_machine (int ignore ATTRIBUTE_UNUSED
)
4803 #define MAX_HISTORY 100
4804 static ppc_cpu_t
*cpu_history
;
4805 static int curr_hist
;
4809 if (*input_line_pointer
== '"')
4812 cpu_string
= demand_copy_C_string (&len
);
4817 cpu_string
= input_line_pointer
;
4818 c
= get_symbol_end ();
4819 cpu_string
= xstrdup (cpu_string
);
4820 *input_line_pointer
= c
;
4823 if (cpu_string
!= NULL
)
4825 ppc_cpu_t old_cpu
= ppc_cpu
;
4829 for (p
= cpu_string
; *p
!= 0; p
++)
4832 if (strcmp (cpu_string
, "push") == 0)
4834 if (cpu_history
== NULL
)
4835 cpu_history
= xmalloc (MAX_HISTORY
* sizeof (*cpu_history
));
4837 if (curr_hist
>= MAX_HISTORY
)
4838 as_bad (_(".machine stack overflow"));
4840 cpu_history
[curr_hist
++] = ppc_cpu
;
4842 else if (strcmp (cpu_string
, "pop") == 0)
4845 as_bad (_(".machine stack underflow"));
4847 ppc_cpu
= cpu_history
[--curr_hist
];
4849 else if ((new_cpu
= ppc_parse_cpu (ppc_cpu
, cpu_string
)) != 0)
4852 as_bad (_("invalid machine `%s'"), cpu_string
);
4854 if (ppc_cpu
!= old_cpu
)
4855 ppc_setup_opcodes ();
4858 demand_empty_rest_of_line ();
4860 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4864 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4866 /* Set the current section. */
4868 ppc_set_current_section (segT
new)
4870 ppc_previous_section
= ppc_current_section
;
4871 ppc_current_section
= new;
4874 /* pseudo-op: .previous
4875 behaviour: toggles the current section with the previous section.
4877 warnings: "No previous section" */
4880 ppc_previous (int ignore ATTRIBUTE_UNUSED
)
4882 if (ppc_previous_section
== NULL
)
4884 as_warn (_("no previous section to return to, ignored."));
4888 subseg_set (ppc_previous_section
, 0);
4890 ppc_set_current_section (ppc_previous_section
);
4893 /* pseudo-op: .pdata
4894 behaviour: predefined read only data section
4898 initial: .section .pdata "adr3"
4899 a - don't know -- maybe a misprint
4900 d - initialized data
4902 3 - double word aligned (that would be 4 byte boundary)
4905 Tag index tables (also known as the function table) for exception
4906 handling, debugging, etc. */
4909 ppc_pdata (int ignore ATTRIBUTE_UNUSED
)
4911 if (pdata_section
== 0)
4913 pdata_section
= subseg_new (".pdata", 0);
4915 bfd_set_section_flags (stdoutput
, pdata_section
,
4916 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4917 | SEC_READONLY
| SEC_DATA
));
4919 bfd_set_section_alignment (stdoutput
, pdata_section
, 2);
4923 pdata_section
= subseg_new (".pdata", 0);
4925 ppc_set_current_section (pdata_section
);
4928 /* pseudo-op: .ydata
4929 behaviour: predefined read only data section
4933 initial: .section .ydata "drw3"
4934 a - don't know -- maybe a misprint
4935 d - initialized data
4937 3 - double word aligned (that would be 4 byte boundary)
4939 Tag tables (also known as the scope table) for exception handling,
4943 ppc_ydata (int ignore ATTRIBUTE_UNUSED
)
4945 if (ydata_section
== 0)
4947 ydata_section
= subseg_new (".ydata", 0);
4948 bfd_set_section_flags (stdoutput
, ydata_section
,
4949 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4950 | SEC_READONLY
| SEC_DATA
));
4952 bfd_set_section_alignment (stdoutput
, ydata_section
, 3);
4956 ydata_section
= subseg_new (".ydata", 0);
4958 ppc_set_current_section (ydata_section
);
4961 /* pseudo-op: .reldata
4962 behaviour: predefined read write data section
4963 double word aligned (4-byte)
4964 FIXME: relocation is applied to it
4965 FIXME: what's the difference between this and .data?
4968 initial: .section .reldata "drw3"
4969 d - initialized data
4972 3 - double word aligned (that would be 8 byte boundary)
4975 Like .data, but intended to hold data subject to relocation, such as
4976 function descriptors, etc. */
4979 ppc_reldata (int ignore ATTRIBUTE_UNUSED
)
4981 if (reldata_section
== 0)
4983 reldata_section
= subseg_new (".reldata", 0);
4985 bfd_set_section_flags (stdoutput
, reldata_section
,
4986 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
4989 bfd_set_section_alignment (stdoutput
, reldata_section
, 2);
4993 reldata_section
= subseg_new (".reldata", 0);
4995 ppc_set_current_section (reldata_section
);
4998 /* pseudo-op: .rdata
4999 behaviour: predefined read only data section
5003 initial: .section .rdata "dr3"
5004 d - initialized data
5006 3 - double word aligned (that would be 4 byte boundary) */
5009 ppc_rdata (int ignore ATTRIBUTE_UNUSED
)
5011 if (rdata_section
== 0)
5013 rdata_section
= subseg_new (".rdata", 0);
5014 bfd_set_section_flags (stdoutput
, rdata_section
,
5015 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
5016 | SEC_READONLY
| SEC_DATA
));
5018 bfd_set_section_alignment (stdoutput
, rdata_section
, 2);
5022 rdata_section
= subseg_new (".rdata", 0);
5024 ppc_set_current_section (rdata_section
);
5027 /* pseudo-op: .ualong
5028 behaviour: much like .int, with the exception that no alignment is
5030 FIXME: test the alignment statement
5035 ppc_ualong (int ignore ATTRIBUTE_UNUSED
)
5041 /* pseudo-op: .znop <symbol name>
5042 behaviour: Issue a nop instruction
5043 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
5044 the supplied symbol name.
5046 warnings: Missing symbol name */
5049 ppc_znop (int ignore ATTRIBUTE_UNUSED
)
5052 const struct powerpc_opcode
*opcode
;
5059 /* Strip out the symbol name. */
5060 symbol_name
= input_line_pointer
;
5061 c
= get_symbol_end ();
5063 name
= xmalloc (input_line_pointer
- symbol_name
+ 1);
5064 strcpy (name
, symbol_name
);
5066 sym
= symbol_find_or_make (name
);
5068 *input_line_pointer
= c
;
5072 /* Look up the opcode in the hash table. */
5073 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, "nop");
5075 /* Stick in the nop. */
5076 insn
= opcode
->opcode
;
5078 /* Write out the instruction. */
5080 md_number_to_chars (f
, insn
, 4);
5082 f
- frag_now
->fr_literal
,
5087 BFD_RELOC_16_GOT_PCREL
);
5097 ppc_pe_comm (int lcomm
)
5106 name
= input_line_pointer
;
5107 c
= get_symbol_end ();
5109 /* just after name is now '\0'. */
5110 p
= input_line_pointer
;
5113 if (*input_line_pointer
!= ',')
5115 as_bad (_("expected comma after symbol-name: rest of line ignored."));
5116 ignore_rest_of_line ();
5120 input_line_pointer
++; /* skip ',' */
5121 if ((temp
= get_absolute_expression ()) < 0)
5123 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp
);
5124 ignore_rest_of_line ();
5130 /* The third argument to .comm is the alignment. */
5131 if (*input_line_pointer
!= ',')
5135 ++input_line_pointer
;
5136 align
= get_absolute_expression ();
5139 as_warn (_("ignoring bad alignment"));
5146 symbolP
= symbol_find_or_make (name
);
5149 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
5151 as_bad (_("ignoring attempt to re-define symbol `%s'."),
5152 S_GET_NAME (symbolP
));
5153 ignore_rest_of_line ();
5157 if (S_GET_VALUE (symbolP
))
5159 if (S_GET_VALUE (symbolP
) != (valueT
) temp
)
5160 as_bad (_("length of .comm \"%s\" is already %ld. Not changed to %ld."),
5161 S_GET_NAME (symbolP
),
5162 (long) S_GET_VALUE (symbolP
),
5167 S_SET_VALUE (symbolP
, (valueT
) temp
);
5168 S_SET_EXTERNAL (symbolP
);
5169 S_SET_SEGMENT (symbolP
, bfd_com_section_ptr
);
5172 demand_empty_rest_of_line ();
5176 * implement the .section pseudo op:
5177 * .section name {, "flags"}
5179 * | +--- optional flags: 'b' for bss
5181 * +-- section name 'l' for lib
5185 * 'd' (apparently m88k for data)
5187 * But if the argument is not a quoted string, treat it as a
5188 * subsegment number.
5190 * FIXME: this is a copy of the section processing from obj-coff.c, with
5191 * additions/changes for the moto-pas assembler support. There are three
5194 * FIXME: I just noticed this. This doesn't work at all really. It it
5195 * setting bits that bfd probably neither understands or uses. The
5196 * correct approach (?) will have to incorporate extra fields attached
5197 * to the section to hold the system specific stuff. (krk)
5200 * 'a' - unknown - referred to in documentation, but no definition supplied
5201 * 'c' - section has code
5202 * 'd' - section has initialized data
5203 * 'u' - section has uninitialized data
5204 * 'i' - section contains directives (info)
5205 * 'n' - section can be discarded
5206 * 'R' - remove section at link time
5208 * Section Protection:
5209 * 'r' - section is readable
5210 * 'w' - section is writeable
5211 * 'x' - section is executable
5212 * 's' - section is sharable
5214 * Section Alignment:
5215 * '0' - align to byte boundary
5216 * '1' - align to halfword undary
5217 * '2' - align to word boundary
5218 * '3' - align to doubleword boundary
5219 * '4' - align to quadword boundary
5220 * '5' - align to 32 byte boundary
5221 * '6' - align to 64 byte boundary
5226 ppc_pe_section (int ignore ATTRIBUTE_UNUSED
)
5228 /* Strip out the section name. */
5237 section_name
= input_line_pointer
;
5238 c
= get_symbol_end ();
5240 name
= xmalloc (input_line_pointer
- section_name
+ 1);
5241 strcpy (name
, section_name
);
5243 *input_line_pointer
= c
;
5248 flags
= SEC_NO_FLAGS
;
5250 if (strcmp (name
, ".idata$2") == 0)
5254 else if (strcmp (name
, ".idata$3") == 0)
5258 else if (strcmp (name
, ".idata$4") == 0)
5262 else if (strcmp (name
, ".idata$5") == 0)
5266 else if (strcmp (name
, ".idata$6") == 0)
5271 /* Default alignment to 16 byte boundary. */
5274 if (*input_line_pointer
== ',')
5276 ++input_line_pointer
;
5278 if (*input_line_pointer
!= '"')
5279 exp
= get_absolute_expression ();
5282 ++input_line_pointer
;
5283 while (*input_line_pointer
!= '"'
5284 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
5286 switch (*input_line_pointer
)
5288 /* Section Contents */
5289 case 'a': /* unknown */
5290 as_bad (_("unsupported section attribute -- 'a'"));
5292 case 'c': /* code section */
5295 case 'd': /* section has initialized data */
5298 case 'u': /* section has uninitialized data */
5299 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
5303 case 'i': /* section contains directives (info) */
5304 /* FIXME: This is IMAGE_SCN_LNK_INFO
5306 flags
|= SEC_HAS_CONTENTS
;
5308 case 'n': /* section can be discarded */
5311 case 'R': /* Remove section at link time */
5312 flags
|= SEC_NEVER_LOAD
;
5314 #if IFLICT_BRAIN_DAMAGE
5315 /* Section Protection */
5316 case 'r': /* section is readable */
5317 flags
|= IMAGE_SCN_MEM_READ
;
5319 case 'w': /* section is writeable */
5320 flags
|= IMAGE_SCN_MEM_WRITE
;
5322 case 'x': /* section is executable */
5323 flags
|= IMAGE_SCN_MEM_EXECUTE
;
5325 case 's': /* section is sharable */
5326 flags
|= IMAGE_SCN_MEM_SHARED
;
5329 /* Section Alignment */
5330 case '0': /* align to byte boundary */
5331 flags
|= IMAGE_SCN_ALIGN_1BYTES
;
5334 case '1': /* align to halfword boundary */
5335 flags
|= IMAGE_SCN_ALIGN_2BYTES
;
5338 case '2': /* align to word boundary */
5339 flags
|= IMAGE_SCN_ALIGN_4BYTES
;
5342 case '3': /* align to doubleword boundary */
5343 flags
|= IMAGE_SCN_ALIGN_8BYTES
;
5346 case '4': /* align to quadword boundary */
5347 flags
|= IMAGE_SCN_ALIGN_16BYTES
;
5350 case '5': /* align to 32 byte boundary */
5351 flags
|= IMAGE_SCN_ALIGN_32BYTES
;
5354 case '6': /* align to 64 byte boundary */
5355 flags
|= IMAGE_SCN_ALIGN_64BYTES
;
5360 as_bad (_("unknown section attribute '%c'"),
5361 *input_line_pointer
);
5364 ++input_line_pointer
;
5366 if (*input_line_pointer
== '"')
5367 ++input_line_pointer
;
5371 sec
= subseg_new (name
, (subsegT
) exp
);
5373 ppc_set_current_section (sec
);
5375 if (flags
!= SEC_NO_FLAGS
)
5377 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
5378 as_bad (_("error setting flags for \"%s\": %s"),
5379 bfd_section_name (stdoutput
, sec
),
5380 bfd_errmsg (bfd_get_error ()));
5383 bfd_set_section_alignment (stdoutput
, sec
, align
);
5387 ppc_pe_function (int ignore ATTRIBUTE_UNUSED
)
5393 name
= input_line_pointer
;
5394 endc
= get_symbol_end ();
5396 ext_sym
= symbol_find_or_make (name
);
5398 *input_line_pointer
= endc
;
5400 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
5401 SF_SET_FUNCTION (ext_sym
);
5402 SF_SET_PROCESS (ext_sym
);
5403 coff_add_linesym (ext_sym
);
5405 demand_empty_rest_of_line ();
5409 ppc_pe_tocd (int ignore ATTRIBUTE_UNUSED
)
5411 if (tocdata_section
== 0)
5413 tocdata_section
= subseg_new (".tocd", 0);
5414 /* FIXME: section flags won't work. */
5415 bfd_set_section_flags (stdoutput
, tocdata_section
,
5416 (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
5417 | SEC_READONLY
| SEC_DATA
));
5419 bfd_set_section_alignment (stdoutput
, tocdata_section
, 2);
5423 rdata_section
= subseg_new (".tocd", 0);
5426 ppc_set_current_section (tocdata_section
);
5428 demand_empty_rest_of_line ();
5431 /* Don't adjust TOC relocs to use the section symbol. */
5434 ppc_pe_fix_adjustable (fixS
*fix
)
5436 return fix
->fx_r_type
!= BFD_RELOC_PPC_TOC16
;
5443 /* XCOFF specific symbol and file handling. */
5445 /* Canonicalize the symbol name. We use the to force the suffix, if
5446 any, to use square brackets, and to be in upper case. */
5449 ppc_canonicalize_symbol_name (char *name
)
5453 if (ppc_stab_symbol
)
5456 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
5470 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
5473 if (*s
== '\0' || s
[1] != '\0')
5474 as_bad (_("bad symbol suffix"));
5482 /* Set the class of a symbol based on the suffix, if any. This is
5483 called whenever a new symbol is created. */
5486 ppc_symbol_new_hook (symbolS
*sym
)
5488 struct ppc_tc_sy
*tc
;
5491 tc
= symbol_get_tc (sym
);
5494 tc
->symbol_class
= -1;
5495 tc
->real_name
= NULL
;
5502 if (ppc_stab_symbol
)
5505 s
= strchr (S_GET_NAME (sym
), '[');
5506 if (s
== (const char *) NULL
)
5508 /* There is no suffix. */
5517 if (strcmp (s
, "BS]") == 0)
5518 tc
->symbol_class
= XMC_BS
;
5521 if (strcmp (s
, "DB]") == 0)
5522 tc
->symbol_class
= XMC_DB
;
5523 else if (strcmp (s
, "DS]") == 0)
5524 tc
->symbol_class
= XMC_DS
;
5527 if (strcmp (s
, "GL]") == 0)
5528 tc
->symbol_class
= XMC_GL
;
5531 if (strcmp (s
, "PR]") == 0)
5532 tc
->symbol_class
= XMC_PR
;
5535 if (strcmp (s
, "RO]") == 0)
5536 tc
->symbol_class
= XMC_RO
;
5537 else if (strcmp (s
, "RW]") == 0)
5538 tc
->symbol_class
= XMC_RW
;
5541 if (strcmp (s
, "SV]") == 0)
5542 tc
->symbol_class
= XMC_SV
;
5545 if (strcmp (s
, "TC]") == 0)
5546 tc
->symbol_class
= XMC_TC
;
5547 else if (strcmp (s
, "TI]") == 0)
5548 tc
->symbol_class
= XMC_TI
;
5549 else if (strcmp (s
, "TB]") == 0)
5550 tc
->symbol_class
= XMC_TB
;
5551 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
5552 tc
->symbol_class
= XMC_TC0
;
5555 if (strcmp (s
, "UA]") == 0)
5556 tc
->symbol_class
= XMC_UA
;
5557 else if (strcmp (s
, "UC]") == 0)
5558 tc
->symbol_class
= XMC_UC
;
5561 if (strcmp (s
, "XO]") == 0)
5562 tc
->symbol_class
= XMC_XO
;
5566 if (tc
->symbol_class
== -1)
5567 as_bad (_("unrecognized symbol suffix"));
5570 /* Set the class of a label based on where it is defined. This
5571 handles symbols without suffixes. Also, move the symbol so that it
5572 follows the csect symbol. */
5575 ppc_frob_label (symbolS
*sym
)
5577 if (ppc_current_csect
!= (symbolS
*) NULL
)
5579 if (symbol_get_tc (sym
)->symbol_class
== -1)
5580 symbol_get_tc (sym
)->symbol_class
= symbol_get_tc (ppc_current_csect
)->symbol_class
;
5582 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
5583 symbol_append (sym
, symbol_get_tc (ppc_current_csect
)->within
,
5584 &symbol_rootP
, &symbol_lastP
);
5585 symbol_get_tc (ppc_current_csect
)->within
= sym
;
5586 symbol_get_tc (sym
)->within
= ppc_current_csect
;
5590 dwarf2_emit_label (sym
);
5594 /* This variable is set by ppc_frob_symbol if any absolute symbols are
5595 seen. It tells ppc_adjust_symtab whether it needs to look through
5598 static bfd_boolean ppc_saw_abs
;
5600 /* Change the name of a symbol just before writing it out. Set the
5601 real name if the .rename pseudo-op was used. Otherwise, remove any
5602 class suffix. Return 1 if the symbol should not be included in the
5606 ppc_frob_symbol (symbolS
*sym
)
5608 static symbolS
*ppc_last_function
;
5609 static symbolS
*set_end
;
5611 /* Discard symbols that should not be included in the output symbol
5613 if (! symbol_used_in_reloc_p (sym
)
5614 && ((symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) != 0
5615 || (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
5616 && ! symbol_get_tc (sym
)->output
5617 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
5620 /* This one will disappear anyway. Don't make a csect sym for it. */
5621 if (sym
== abs_section_sym
)
5624 if (symbol_get_tc (sym
)->real_name
!= (char *) NULL
)
5625 S_SET_NAME (sym
, symbol_get_tc (sym
)->real_name
);
5631 name
= S_GET_NAME (sym
);
5632 s
= strchr (name
, '[');
5633 if (s
!= (char *) NULL
)
5639 snew
= xmalloc (len
+ 1);
5640 memcpy (snew
, name
, len
);
5643 S_SET_NAME (sym
, snew
);
5647 if (set_end
!= (symbolS
*) NULL
)
5649 SA_SET_SYM_ENDNDX (set_end
, sym
);
5653 if (SF_GET_FUNCTION (sym
))
5655 if (ppc_last_function
!= (symbolS
*) NULL
)
5656 as_bad (_("two .function pseudo-ops with no intervening .ef"));
5657 ppc_last_function
= sym
;
5658 if (symbol_get_tc (sym
)->u
.size
!= (symbolS
*) NULL
)
5660 resolve_symbol_value (symbol_get_tc (sym
)->u
.size
);
5661 SA_SET_SYM_FSIZE (sym
,
5662 (long) S_GET_VALUE (symbol_get_tc (sym
)->u
.size
));
5665 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
5666 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
5668 if (ppc_last_function
== (symbolS
*) NULL
)
5669 as_bad (_(".ef with no preceding .function"));
5672 set_end
= ppc_last_function
;
5673 ppc_last_function
= NULL
;
5675 /* We don't have a C_EFCN symbol, but we need to force the
5676 COFF backend to believe that it has seen one. */
5677 coff_last_function
= NULL
;
5681 if (! (S_IS_EXTERNAL (sym
) || S_IS_WEAK (sym
))
5682 && (symbol_get_bfdsym (sym
)->flags
& BSF_SECTION_SYM
) == 0
5683 && S_GET_STORAGE_CLASS (sym
) != C_FILE
5684 && S_GET_STORAGE_CLASS (sym
) != C_FCN
5685 && S_GET_STORAGE_CLASS (sym
) != C_BLOCK
5686 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
5687 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
5688 && S_GET_STORAGE_CLASS (sym
) != C_BINCL
5689 && S_GET_STORAGE_CLASS (sym
) != C_EINCL
5690 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
5691 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
5693 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
5694 || S_GET_STORAGE_CLASS (sym
) == C_AIX_WEAKEXT
5695 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
5698 union internal_auxent
*a
;
5700 /* Create a csect aux. */
5701 i
= S_GET_NUMBER_AUXILIARY (sym
);
5702 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
5703 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].u
.auxent
;
5704 if (symbol_get_tc (sym
)->symbol_class
== XMC_TC0
)
5706 /* This is the TOC table. */
5707 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
5708 a
->x_csect
.x_scnlen
.l
= 0;
5709 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5711 else if (symbol_get_tc (sym
)->subseg
!= 0)
5713 /* This is a csect symbol. x_scnlen is the size of the
5715 if (symbol_get_tc (sym
)->next
== (symbolS
*) NULL
)
5716 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5717 S_GET_SEGMENT (sym
))
5718 - S_GET_VALUE (sym
));
5721 resolve_symbol_value (symbol_get_tc (sym
)->next
);
5722 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (symbol_get_tc (sym
)->next
)
5723 - S_GET_VALUE (sym
));
5725 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_SD
;
5727 else if (S_GET_SEGMENT (sym
) == bss_section
)
5729 /* This is a common symbol. */
5730 a
->x_csect
.x_scnlen
.l
= symbol_get_frag (sym
)->fr_offset
;
5731 a
->x_csect
.x_smtyp
= (symbol_get_tc (sym
)->align
<< 3) | XTY_CM
;
5732 if (S_IS_EXTERNAL (sym
))
5733 symbol_get_tc (sym
)->symbol_class
= XMC_RW
;
5735 symbol_get_tc (sym
)->symbol_class
= XMC_BS
;
5737 else if (S_GET_SEGMENT (sym
) == absolute_section
)
5739 /* This is an absolute symbol. The csect will be created by
5740 ppc_adjust_symtab. */
5742 a
->x_csect
.x_smtyp
= XTY_LD
;
5743 if (symbol_get_tc (sym
)->symbol_class
== -1)
5744 symbol_get_tc (sym
)->symbol_class
= XMC_XO
;
5746 else if (! S_IS_DEFINED (sym
))
5748 /* This is an external symbol. */
5749 a
->x_csect
.x_scnlen
.l
= 0;
5750 a
->x_csect
.x_smtyp
= XTY_ER
;
5752 else if (symbol_get_tc (sym
)->symbol_class
== XMC_TC
)
5756 /* This is a TOC definition. x_scnlen is the size of the
5758 next
= symbol_next (sym
);
5759 while (symbol_get_tc (next
)->symbol_class
== XMC_TC0
)
5760 next
= symbol_next (next
);
5761 if (next
== (symbolS
*) NULL
5762 || symbol_get_tc (next
)->symbol_class
!= XMC_TC
)
5764 if (ppc_after_toc_frag
== (fragS
*) NULL
)
5765 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
5767 - S_GET_VALUE (sym
));
5769 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
5770 - S_GET_VALUE (sym
));
5774 resolve_symbol_value (next
);
5775 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
5776 - S_GET_VALUE (sym
));
5778 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
5784 /* This is a normal symbol definition. x_scnlen is the
5785 symbol index of the containing csect. */
5786 if (S_GET_SEGMENT (sym
) == text_section
)
5787 csect
= ppc_text_csects
;
5788 else if (S_GET_SEGMENT (sym
) == data_section
)
5789 csect
= ppc_data_csects
;
5793 /* Skip the initial dummy symbol. */
5794 csect
= symbol_get_tc (csect
)->next
;
5796 if (csect
== (symbolS
*) NULL
)
5798 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym
));
5799 a
->x_csect
.x_scnlen
.l
= 0;
5803 while (symbol_get_tc (csect
)->next
!= (symbolS
*) NULL
)
5805 resolve_symbol_value (symbol_get_tc (csect
)->next
);
5806 if (S_GET_VALUE (symbol_get_tc (csect
)->next
)
5807 > S_GET_VALUE (sym
))
5809 csect
= symbol_get_tc (csect
)->next
;
5812 a
->x_csect
.x_scnlen
.p
=
5813 coffsymbol (symbol_get_bfdsym (csect
))->native
;
5814 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
+ 1].fix_scnlen
=
5817 a
->x_csect
.x_smtyp
= XTY_LD
;
5820 a
->x_csect
.x_parmhash
= 0;
5821 a
->x_csect
.x_snhash
= 0;
5822 if (symbol_get_tc (sym
)->symbol_class
== -1)
5823 a
->x_csect
.x_smclas
= XMC_PR
;
5825 a
->x_csect
.x_smclas
= symbol_get_tc (sym
)->symbol_class
;
5826 a
->x_csect
.x_stab
= 0;
5827 a
->x_csect
.x_snstab
= 0;
5829 /* Don't let the COFF backend resort these symbols. */
5830 symbol_get_bfdsym (sym
)->flags
|= BSF_NOT_AT_END
;
5832 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
5834 /* We want the value to be the symbol index of the referenced
5835 csect symbol. BFD will do that for us if we set the right
5837 asymbol
*bsym
= symbol_get_bfdsym (symbol_get_tc (sym
)->within
);
5838 combined_entry_type
*c
= coffsymbol (bsym
)->native
;
5840 S_SET_VALUE (sym
, (valueT
) (size_t) c
);
5841 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_value
= 1;
5843 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
5848 block
= symbol_get_tc (sym
)->within
;
5851 /* The value is the offset from the enclosing csect. */
5854 csect
= symbol_get_tc (block
)->within
;
5855 resolve_symbol_value (csect
);
5856 base
= S_GET_VALUE (csect
);
5861 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - base
);
5863 else if (S_GET_STORAGE_CLASS (sym
) == C_BINCL
5864 || S_GET_STORAGE_CLASS (sym
) == C_EINCL
)
5866 /* We want the value to be a file offset into the line numbers.
5867 BFD will do that for us if we set the right flags. We have
5868 already set the value correctly. */
5869 coffsymbol (symbol_get_bfdsym (sym
))->native
->fix_line
= 1;
5875 /* Adjust the symbol table. This creates csect symbols for all
5876 absolute symbols. */
5879 ppc_adjust_symtab (void)
5886 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
5890 union internal_auxent
*a
;
5892 if (S_GET_SEGMENT (sym
) != absolute_section
)
5895 csect
= symbol_create (".abs[XO]", absolute_section
,
5896 S_GET_VALUE (sym
), &zero_address_frag
);
5897 symbol_get_bfdsym (csect
)->value
= S_GET_VALUE (sym
);
5898 S_SET_STORAGE_CLASS (csect
, C_HIDEXT
);
5899 i
= S_GET_NUMBER_AUXILIARY (csect
);
5900 S_SET_NUMBER_AUXILIARY (csect
, i
+ 1);
5901 a
= &coffsymbol (symbol_get_bfdsym (csect
))->native
[i
+ 1].u
.auxent
;
5902 a
->x_csect
.x_scnlen
.l
= 0;
5903 a
->x_csect
.x_smtyp
= XTY_SD
;
5904 a
->x_csect
.x_parmhash
= 0;
5905 a
->x_csect
.x_snhash
= 0;
5906 a
->x_csect
.x_smclas
= XMC_XO
;
5907 a
->x_csect
.x_stab
= 0;
5908 a
->x_csect
.x_snstab
= 0;
5910 symbol_insert (csect
, sym
, &symbol_rootP
, &symbol_lastP
);
5912 i
= S_GET_NUMBER_AUXILIARY (sym
);
5913 a
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].u
.auxent
;
5914 a
->x_csect
.x_scnlen
.p
= coffsymbol (symbol_get_bfdsym (csect
))->native
;
5915 coffsymbol (symbol_get_bfdsym (sym
))->native
[i
].fix_scnlen
= 1;
5918 ppc_saw_abs
= FALSE
;
5921 /* Set the VMA for a section. This is called on all the sections in
5925 ppc_frob_section (asection
*sec
)
5927 static bfd_vma vma
= 0;
5929 /* Dwarf sections start at 0. */
5930 if (bfd_get_section_flags (NULL
, sec
) & SEC_DEBUGGING
)
5933 vma
= md_section_align (sec
, vma
);
5934 bfd_set_section_vma (stdoutput
, sec
, vma
);
5935 vma
+= bfd_section_size (stdoutput
, sec
);
5938 #endif /* OBJ_XCOFF */
5941 md_atof (int type
, char *litp
, int *sizep
)
5943 return ieee_md_atof (type
, litp
, sizep
, target_big_endian
);
5946 /* Write a value out to the object file, using the appropriate
5950 md_number_to_chars (char *buf
, valueT val
, int n
)
5952 if (target_big_endian
)
5953 number_to_chars_bigendian (buf
, val
, n
);
5955 number_to_chars_littleendian (buf
, val
, n
);
5958 /* Align a section (I don't know why this is machine dependent). */
5961 md_section_align (asection
*seg ATTRIBUTE_UNUSED
, valueT addr
)
5966 int align
= bfd_get_section_alignment (stdoutput
, seg
);
5968 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
5972 /* We don't have any form of relaxing. */
5975 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
5976 asection
*seg ATTRIBUTE_UNUSED
)
5982 /* Convert a machine dependent frag. We never generate these. */
5985 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
5986 asection
*sec ATTRIBUTE_UNUSED
,
5987 fragS
*fragp ATTRIBUTE_UNUSED
)
5992 /* We have no need to default values of symbols. */
5995 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
6000 /* Functions concerning relocs. */
6002 /* The location from which a PC relative jump should be calculated,
6003 given a PC relative reloc. */
6006 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
6008 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6013 /* This is called to see whether a fixup should be adjusted to use a
6014 section symbol. We take the opportunity to change a fixup against
6015 a symbol in the TOC subsegment into a reloc against the
6016 corresponding .tc symbol. */
6019 ppc_fix_adjustable (fixS
*fix
)
6021 valueT val
= resolve_symbol_value (fix
->fx_addsy
);
6022 segT symseg
= S_GET_SEGMENT (fix
->fx_addsy
);
6023 TC_SYMFIELD_TYPE
*tc
;
6025 if (symseg
== absolute_section
)
6028 /* Always adjust symbols in debugging sections. */
6029 if (bfd_get_section_flags (stdoutput
, symseg
) & SEC_DEBUGGING
)
6032 if (ppc_toc_csect
!= (symbolS
*) NULL
6033 && fix
->fx_addsy
!= ppc_toc_csect
6034 && symseg
== data_section
6035 && val
>= ppc_toc_frag
->fr_address
6036 && (ppc_after_toc_frag
== (fragS
*) NULL
6037 || val
< ppc_after_toc_frag
->fr_address
))
6041 for (sy
= symbol_next (ppc_toc_csect
);
6042 sy
!= (symbolS
*) NULL
;
6043 sy
= symbol_next (sy
))
6045 TC_SYMFIELD_TYPE
*sy_tc
= symbol_get_tc (sy
);
6047 if (sy_tc
->symbol_class
== XMC_TC0
)
6049 if (sy_tc
->symbol_class
!= XMC_TC
)
6051 if (val
== resolve_symbol_value (sy
))
6054 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
6059 as_bad_where (fix
->fx_file
, fix
->fx_line
,
6060 _("symbol in .toc does not match any .tc"));
6063 /* Possibly adjust the reloc to be against the csect. */
6064 tc
= symbol_get_tc (fix
->fx_addsy
);
6066 && tc
->symbol_class
!= XMC_TC0
6067 && tc
->symbol_class
!= XMC_TC
6068 && symseg
!= bss_section
6069 /* Don't adjust if this is a reloc in the toc section. */
6070 && (symseg
!= data_section
6071 || ppc_toc_csect
== NULL
6072 || val
< ppc_toc_frag
->fr_address
6073 || (ppc_after_toc_frag
!= NULL
6074 && val
>= ppc_after_toc_frag
->fr_address
)))
6076 symbolS
*csect
= tc
->within
;
6078 /* If the symbol was not declared by a label (eg: a section symbol),
6079 use the section instead of the csect. This doesn't happen in
6080 normal AIX assembly code. */
6082 csect
= seg_info (symseg
)->sym
;
6084 fix
->fx_offset
+= val
- symbol_get_frag (csect
)->fr_address
;
6085 fix
->fx_addsy
= csect
;
6090 /* Adjust a reloc against a .lcomm symbol to be against the base
6092 if (symseg
== bss_section
6093 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
6095 symbolS
*sy
= symbol_get_frag (fix
->fx_addsy
)->fr_symbol
;
6097 fix
->fx_offset
+= val
- resolve_symbol_value (sy
);
6104 /* A reloc from one csect to another must be kept. The assembler
6105 will, of course, keep relocs between sections, and it will keep
6106 absolute relocs, but we need to force it to keep PC relative relocs
6107 between two csects in the same section. */
6110 ppc_force_relocation (fixS
*fix
)
6112 /* At this point fix->fx_addsy should already have been converted to
6113 a csect symbol. If the csect does not include the fragment, then
6114 we need to force the relocation. */
6116 && fix
->fx_addsy
!= NULL
6117 && symbol_get_tc (fix
->fx_addsy
)->subseg
!= 0
6118 && ((symbol_get_frag (fix
->fx_addsy
)->fr_address
6119 > fix
->fx_frag
->fr_address
)
6120 || (symbol_get_tc (fix
->fx_addsy
)->next
!= NULL
6121 && (symbol_get_frag (symbol_get_tc (fix
->fx_addsy
)->next
)->fr_address
6122 <= fix
->fx_frag
->fr_address
))))
6125 return generic_force_reloc (fix
);
6129 ppc_new_dot_label (symbolS
*sym
)
6131 /* Anchor this label to the current csect for relocations. */
6132 symbol_get_tc (sym
)->within
= ppc_current_csect
;
6135 #endif /* OBJ_XCOFF */
6138 /* If this function returns non-zero, it guarantees that a relocation
6139 will be emitted for a fixup. */
6142 ppc_force_relocation (fixS
*fix
)
6144 /* Branch prediction relocations must force a relocation, as must
6145 the vtable description relocs. */
6146 switch (fix
->fx_r_type
)
6148 case BFD_RELOC_PPC_B16_BRTAKEN
:
6149 case BFD_RELOC_PPC_B16_BRNTAKEN
:
6150 case BFD_RELOC_PPC_BA16_BRTAKEN
:
6151 case BFD_RELOC_PPC_BA16_BRNTAKEN
:
6152 case BFD_RELOC_24_PLT_PCREL
:
6153 case BFD_RELOC_PPC64_TOC
:
6159 if (fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
6160 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
)
6163 return generic_force_reloc (fix
);
6167 ppc_fix_adjustable (fixS
*fix
)
6169 return (fix
->fx_r_type
!= BFD_RELOC_16_GOTOFF
6170 && fix
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
6171 && fix
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
6172 && fix
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
6173 && fix
->fx_r_type
!= BFD_RELOC_PPC64_GOT16_DS
6174 && fix
->fx_r_type
!= BFD_RELOC_PPC64_GOT16_LO_DS
6175 && fix
->fx_r_type
!= BFD_RELOC_GPREL16
6176 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_INHERIT
6177 && fix
->fx_r_type
!= BFD_RELOC_VTABLE_ENTRY
6178 && !(fix
->fx_r_type
>= BFD_RELOC_PPC_TLS
6179 && fix
->fx_r_type
<= BFD_RELOC_PPC64_DTPREL16_HIGHESTA
));
6184 ppc_frag_check (struct frag
*fragP
)
6186 if (!fragP
->has_code
)
6189 if (ppc_mach() == bfd_mach_ppc_vle
)
6191 if (((fragP
->fr_address
+ fragP
->insn_addr
) & 1) != 0)
6192 as_bad (_("instruction address is not a multiple of 2"));
6196 if (((fragP
->fr_address
+ fragP
->insn_addr
) & 3) != 0)
6197 as_bad (_("instruction address is not a multiple of 4"));
6201 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
6202 rs_align_code frag. */
6205 ppc_handle_align (struct frag
*fragP
)
6207 valueT count
= (fragP
->fr_next
->fr_address
6208 - (fragP
->fr_address
+ fragP
->fr_fix
));
6210 if (ppc_mach() == bfd_mach_ppc_vle
&& count
!= 0 && (count
& 1) == 0)
6212 char *dest
= fragP
->fr_literal
+ fragP
->fr_fix
;
6215 md_number_to_chars (dest
, 0x4400, 2);
6217 else if (count
!= 0 && (count
& 3) == 0)
6219 char *dest
= fragP
->fr_literal
+ fragP
->fr_fix
;
6223 if (count
> 4 * nop_limit
&& count
< 0x2000000)
6227 /* Make a branch, then follow with nops. Insert another
6228 frag to handle the nops. */
6229 md_number_to_chars (dest
, 0x48000000 + count
, 4);
6234 rest
= xmalloc (SIZEOF_STRUCT_FRAG
+ 4);
6235 memcpy (rest
, fragP
, SIZEOF_STRUCT_FRAG
);
6236 fragP
->fr_next
= rest
;
6238 rest
->fr_address
+= rest
->fr_fix
+ 4;
6240 /* If we leave the next frag as rs_align_code we'll come here
6241 again, resulting in a bunch of branches rather than a
6242 branch followed by nops. */
6243 rest
->fr_type
= rs_align
;
6244 dest
= rest
->fr_literal
;
6247 md_number_to_chars (dest
, 0x60000000, 4);
6249 if ((ppc_cpu
& PPC_OPCODE_POWER6
) != 0
6250 || (ppc_cpu
& PPC_OPCODE_POWER7
) != 0)
6252 /* For power6 and power7, we want the last nop to be a group
6253 terminating one. Do this by inserting an rs_fill frag immediately
6254 after this one, with its address set to the last nop location.
6255 This will automatically reduce the number of nops in the current
6259 struct frag
*group_nop
= xmalloc (SIZEOF_STRUCT_FRAG
+ 4);
6261 memcpy (group_nop
, fragP
, SIZEOF_STRUCT_FRAG
);
6262 group_nop
->fr_address
= group_nop
->fr_next
->fr_address
- 4;
6263 group_nop
->fr_fix
= 0;
6264 group_nop
->fr_offset
= 1;
6265 group_nop
->fr_type
= rs_fill
;
6266 fragP
->fr_next
= group_nop
;
6267 dest
= group_nop
->fr_literal
;
6270 if ((ppc_cpu
& PPC_OPCODE_POWER7
) != 0)
6272 if (ppc_cpu
& PPC_OPCODE_E500MC
)
6273 /* e500mc group terminating nop: "ori 0,0,0". */
6274 md_number_to_chars (dest
, 0x60000000, 4);
6276 /* power7 group terminating nop: "ori 2,2,0". */
6277 md_number_to_chars (dest
, 0x60420000, 4);
6280 /* power6 group terminating nop: "ori 1,1,0". */
6281 md_number_to_chars (dest
, 0x60210000, 4);
6286 /* Apply a fixup to the object code. This is called for all the
6287 fixups we generated by the calls to fix_new_exp, above. */
6290 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
6292 valueT value
= * valP
;
6295 if (fixP
->fx_addsy
!= NULL
)
6297 /* Hack around bfd_install_relocation brain damage. */
6299 value
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
6304 /* FIXME FIXME FIXME: The value we are passed in *valP includes
6305 the symbol values. If we are doing this relocation the code in
6306 write.c is going to call bfd_install_relocation, which is also
6307 going to use the symbol value. That means that if the reloc is
6308 fully resolved we want to use *valP since bfd_install_relocation is
6310 However, if the reloc is not fully resolved we do not want to
6311 use *valP, and must use fx_offset instead. If the relocation
6312 is PC-relative, we then need to re-apply md_pcrel_from_section
6313 to this new relocation value. */
6314 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
6319 value
= fixP
->fx_offset
;
6321 value
-= md_pcrel_from_section (fixP
, seg
);
6325 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
6327 /* We can't actually support subtracting a symbol. */
6328 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
6331 if (fixP
->fx_pcrel_adjust
!= 0)
6333 /* Handle relocs in an insn. */
6335 int opindex
= fixP
->fx_pcrel_adjust
& 0xff;
6336 const struct powerpc_operand
*operand
= &powerpc_operands
[opindex
];
6342 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
6343 does not generate a reloc. It uses the offset of `sym' within its
6344 csect. Other usages, such as `.long sym', generate relocs. This
6345 is the documented behaviour of non-TOC symbols. */
6346 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
6347 && (operand
->bitm
& 0xfff0) == 0xfff0
6348 && operand
->shift
== 0
6349 && (operand
->insert
== NULL
|| ppc_obj64
)
6350 && fixP
->fx_addsy
!= NULL
6351 && symbol_get_tc (fixP
->fx_addsy
)->subseg
!= 0
6352 && symbol_get_tc (fixP
->fx_addsy
)->symbol_class
!= XMC_TC
6353 && symbol_get_tc (fixP
->fx_addsy
)->symbol_class
!= XMC_TC0
6354 && S_GET_SEGMENT (fixP
->fx_addsy
) != bss_section
)
6356 value
= fixP
->fx_offset
;
6361 switch (fixP
->fx_r_type
)
6364 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
6369 case BFD_RELOC_LO16
:
6371 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
6373 case BFD_RELOC_LO16_PCREL
:
6374 fieldval
= SEX16 (value
);
6377 case BFD_RELOC_HI16
:
6379 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
6381 case BFD_RELOC_HI16_PCREL
:
6382 fieldval
= SEX16 (PPC_HI (value
));
6385 case BFD_RELOC_HI16_S
:
6387 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
6389 case BFD_RELOC_HI16_S_PCREL
:
6390 fieldval
= SEX16 (PPC_HA (value
));
6394 case BFD_RELOC_PPC64_HIGHER
:
6397 fieldval
= SEX16 (PPC_HIGHER (value
));
6400 case BFD_RELOC_PPC64_HIGHER_S
:
6403 fieldval
= SEX16 (PPC_HIGHERA (value
));
6406 case BFD_RELOC_PPC64_HIGHEST
:
6409 fieldval
= SEX16 (PPC_HIGHEST (value
));
6412 case BFD_RELOC_PPC64_HIGHEST_S
:
6415 fieldval
= SEX16 (PPC_HIGHESTA (value
));
6418 /* The following relocs can't be calculated by the assembler.
6419 Leave the field zero. */
6420 case BFD_RELOC_PPC_TPREL16
:
6421 case BFD_RELOC_PPC_TPREL16_LO
:
6422 case BFD_RELOC_PPC_TPREL16_HI
:
6423 case BFD_RELOC_PPC_TPREL16_HA
:
6424 case BFD_RELOC_PPC_DTPREL16
:
6425 case BFD_RELOC_PPC_DTPREL16_LO
:
6426 case BFD_RELOC_PPC_DTPREL16_HI
:
6427 case BFD_RELOC_PPC_DTPREL16_HA
:
6428 case BFD_RELOC_PPC_GOT_TLSGD16
:
6429 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
6430 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
6431 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
6432 case BFD_RELOC_PPC_GOT_TLSLD16
:
6433 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
6434 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
6435 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
6436 case BFD_RELOC_PPC_GOT_TPREL16
:
6437 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
6438 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
6439 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
6440 case BFD_RELOC_PPC_GOT_DTPREL16
:
6441 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
6442 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
6443 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
6444 case BFD_RELOC_PPC64_TPREL16_DS
:
6445 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
6446 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
6447 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
6448 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
6449 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
6450 case BFD_RELOC_PPC64_DTPREL16_DS
:
6451 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
6452 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
6453 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
6454 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
6455 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
6456 gas_assert (fixP
->fx_addsy
!= NULL
);
6457 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
6463 /* These also should leave the field zero for the same
6464 reason. Note that older versions of gas wrote values
6465 here. If we want to go back to the old behaviour, then
6466 all _LO and _LO_DS cases will need to be treated like
6467 BFD_RELOC_LO16_PCREL above. Similarly for _HI etc. */
6468 case BFD_RELOC_16_GOTOFF
:
6469 case BFD_RELOC_LO16_GOTOFF
:
6470 case BFD_RELOC_HI16_GOTOFF
:
6471 case BFD_RELOC_HI16_S_GOTOFF
:
6472 case BFD_RELOC_LO16_PLTOFF
:
6473 case BFD_RELOC_HI16_PLTOFF
:
6474 case BFD_RELOC_HI16_S_PLTOFF
:
6475 case BFD_RELOC_GPREL16
:
6476 case BFD_RELOC_16_BASEREL
:
6477 case BFD_RELOC_LO16_BASEREL
:
6478 case BFD_RELOC_HI16_BASEREL
:
6479 case BFD_RELOC_HI16_S_BASEREL
:
6480 case BFD_RELOC_PPC_TOC16
:
6481 case BFD_RELOC_PPC64_TOC16_LO
:
6482 case BFD_RELOC_PPC64_TOC16_HI
:
6483 case BFD_RELOC_PPC64_TOC16_HA
:
6484 case BFD_RELOC_PPC64_PLTGOT16
:
6485 case BFD_RELOC_PPC64_PLTGOT16_LO
:
6486 case BFD_RELOC_PPC64_PLTGOT16_HI
:
6487 case BFD_RELOC_PPC64_PLTGOT16_HA
:
6488 case BFD_RELOC_PPC64_GOT16_DS
:
6489 case BFD_RELOC_PPC64_GOT16_LO_DS
:
6490 case BFD_RELOC_PPC64_PLT16_LO_DS
:
6491 case BFD_RELOC_PPC64_SECTOFF_DS
:
6492 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
6493 case BFD_RELOC_PPC64_TOC16_DS
:
6494 case BFD_RELOC_PPC64_TOC16_LO_DS
:
6495 case BFD_RELOC_PPC64_PLTGOT16_DS
:
6496 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
:
6497 case BFD_RELOC_PPC_EMB_NADDR16
:
6498 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
6499 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
6500 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
6501 case BFD_RELOC_PPC_EMB_SDAI16
:
6502 case BFD_RELOC_PPC_EMB_SDA2I16
:
6503 case BFD_RELOC_PPC_EMB_SDA2REL
:
6504 case BFD_RELOC_PPC_EMB_SDA21
:
6505 case BFD_RELOC_PPC_EMB_MRKREF
:
6506 case BFD_RELOC_PPC_EMB_RELSEC16
:
6507 case BFD_RELOC_PPC_EMB_RELST_LO
:
6508 case BFD_RELOC_PPC_EMB_RELST_HI
:
6509 case BFD_RELOC_PPC_EMB_RELST_HA
:
6510 case BFD_RELOC_PPC_EMB_BIT_FLD
:
6511 case BFD_RELOC_PPC_EMB_RELSDA
:
6512 case BFD_RELOC_PPC_VLE_SDA21
:
6513 case BFD_RELOC_PPC_VLE_SDA21_LO
:
6514 case BFD_RELOC_PPC_VLE_SDAREL_LO16A
:
6515 case BFD_RELOC_PPC_VLE_SDAREL_LO16D
:
6516 case BFD_RELOC_PPC_VLE_SDAREL_HI16A
:
6517 case BFD_RELOC_PPC_VLE_SDAREL_HI16D
:
6518 case BFD_RELOC_PPC_VLE_SDAREL_HA16A
:
6519 case BFD_RELOC_PPC_VLE_SDAREL_HA16D
:
6520 gas_assert (fixP
->fx_addsy
!= NULL
);
6523 case BFD_RELOC_PPC_TLS
:
6524 case BFD_RELOC_PPC_TLSGD
:
6525 case BFD_RELOC_PPC_TLSLD
:
6537 /* powerpc uses RELA style relocs, so if emitting a reloc the field
6538 contents can stay at zero. */
6539 #define APPLY_RELOC fixP->fx_done
6541 #define APPLY_RELOC 1
6543 if ((fieldval
!= 0 && APPLY_RELOC
) || operand
->insert
!= NULL
)
6545 /* Fetch the instruction, insert the fully resolved operand
6546 value, and stuff the instruction back again. */
6547 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
6548 if (target_big_endian
)
6550 if (fixP
->fx_size
== 4)
6551 insn
= bfd_getb32 ((unsigned char *) where
);
6553 insn
= bfd_getb16 ((unsigned char *) where
);
6557 if (fixP
->fx_size
== 4)
6558 insn
= bfd_getl32 ((unsigned char *) where
);
6560 insn
= bfd_getl16 ((unsigned char *) where
);
6562 insn
= ppc_insert_operand (insn
, operand
, fieldval
,
6563 fixP
->tc_fix_data
.ppc_cpu
,
6564 fixP
->fx_file
, fixP
->fx_line
);
6565 if (target_big_endian
)
6567 if (fixP
->fx_size
== 4)
6568 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
6570 bfd_putb16 ((bfd_vma
) insn
, (unsigned char *) where
);
6574 if (fixP
->fx_size
== 4)
6575 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
6577 bfd_putl16 ((bfd_vma
) insn
, (unsigned char *) where
);
6582 /* Nothing else to do here. */
6585 gas_assert (fixP
->fx_addsy
!= NULL
);
6586 if (fixP
->fx_r_type
== BFD_RELOC_UNUSED
)
6591 /* Use expr_symbol_where to see if this is an expression
6593 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
6594 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6595 _("unresolved expression that must be resolved"));
6597 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6598 _("unsupported relocation against %s"),
6599 S_GET_NAME (fixP
->fx_addsy
));
6606 /* Handle relocs in data. */
6607 switch (fixP
->fx_r_type
)
6609 case BFD_RELOC_CTOR
:
6616 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
6619 case BFD_RELOC_32_PCREL
:
6621 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6628 fixP
->fx_r_type
= BFD_RELOC_64_PCREL
;
6631 case BFD_RELOC_64_PCREL
:
6632 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6638 fixP
->fx_r_type
= BFD_RELOC_16_PCREL
;
6641 case BFD_RELOC_16_PCREL
:
6642 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6657 /* Use expr_symbol_where to see if this is an
6658 expression symbol. */
6659 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
6660 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6661 _("unresolved expression that must"
6664 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6665 _("cannot emit PC relative %s relocation"
6667 bfd_get_reloc_code_name (fixP
->fx_r_type
),
6668 S_GET_NAME (fixP
->fx_addsy
));
6671 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
6672 _("unable to resolve expression"));
6676 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6680 case BFD_RELOC_VTABLE_INHERIT
:
6682 && !S_IS_DEFINED (fixP
->fx_addsy
)
6683 && !S_IS_WEAK (fixP
->fx_addsy
))
6684 S_SET_WEAK (fixP
->fx_addsy
);
6687 case BFD_RELOC_VTABLE_ENTRY
:
6692 /* These can appear with @l etc. in data. */
6693 case BFD_RELOC_LO16
:
6695 fixP
->fx_r_type
= BFD_RELOC_LO16_PCREL
;
6696 case BFD_RELOC_LO16_PCREL
:
6697 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6701 case BFD_RELOC_HI16
:
6703 fixP
->fx_r_type
= BFD_RELOC_HI16_PCREL
;
6704 case BFD_RELOC_HI16_PCREL
:
6705 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6709 case BFD_RELOC_HI16_S
:
6711 fixP
->fx_r_type
= BFD_RELOC_HI16_S_PCREL
;
6712 case BFD_RELOC_HI16_S_PCREL
:
6713 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6717 case BFD_RELOC_PPC64_HIGHER
:
6720 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6721 PPC_HIGHER (value
), 2);
6724 case BFD_RELOC_PPC64_HIGHER_S
:
6727 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6728 PPC_HIGHERA (value
), 2);
6731 case BFD_RELOC_PPC64_HIGHEST
:
6734 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6735 PPC_HIGHEST (value
), 2);
6738 case BFD_RELOC_PPC64_HIGHEST_S
:
6741 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
6742 PPC_HIGHESTA (value
), 2);
6745 case BFD_RELOC_PPC_DTPMOD
:
6746 case BFD_RELOC_PPC_TPREL
:
6747 case BFD_RELOC_PPC_DTPREL
:
6748 S_SET_THREAD_LOCAL (fixP
->fx_addsy
);
6751 /* Just punt all of these to the linker. */
6752 case BFD_RELOC_PPC_B16_BRTAKEN
:
6753 case BFD_RELOC_PPC_B16_BRNTAKEN
:
6754 case BFD_RELOC_16_GOTOFF
:
6755 case BFD_RELOC_LO16_GOTOFF
:
6756 case BFD_RELOC_HI16_GOTOFF
:
6757 case BFD_RELOC_HI16_S_GOTOFF
:
6758 case BFD_RELOC_LO16_PLTOFF
:
6759 case BFD_RELOC_HI16_PLTOFF
:
6760 case BFD_RELOC_HI16_S_PLTOFF
:
6761 case BFD_RELOC_PPC_COPY
:
6762 case BFD_RELOC_PPC_GLOB_DAT
:
6763 case BFD_RELOC_16_BASEREL
:
6764 case BFD_RELOC_LO16_BASEREL
:
6765 case BFD_RELOC_HI16_BASEREL
:
6766 case BFD_RELOC_HI16_S_BASEREL
:
6767 case BFD_RELOC_PPC_TLS
:
6768 case BFD_RELOC_PPC_DTPREL16_LO
:
6769 case BFD_RELOC_PPC_DTPREL16_HI
:
6770 case BFD_RELOC_PPC_DTPREL16_HA
:
6771 case BFD_RELOC_PPC_TPREL16_LO
:
6772 case BFD_RELOC_PPC_TPREL16_HI
:
6773 case BFD_RELOC_PPC_TPREL16_HA
:
6774 case BFD_RELOC_PPC_GOT_TLSGD16
:
6775 case BFD_RELOC_PPC_GOT_TLSGD16_LO
:
6776 case BFD_RELOC_PPC_GOT_TLSGD16_HI
:
6777 case BFD_RELOC_PPC_GOT_TLSGD16_HA
:
6778 case BFD_RELOC_PPC_GOT_TLSLD16
:
6779 case BFD_RELOC_PPC_GOT_TLSLD16_LO
:
6780 case BFD_RELOC_PPC_GOT_TLSLD16_HI
:
6781 case BFD_RELOC_PPC_GOT_TLSLD16_HA
:
6782 case BFD_RELOC_PPC_GOT_DTPREL16
:
6783 case BFD_RELOC_PPC_GOT_DTPREL16_LO
:
6784 case BFD_RELOC_PPC_GOT_DTPREL16_HI
:
6785 case BFD_RELOC_PPC_GOT_DTPREL16_HA
:
6786 case BFD_RELOC_PPC_GOT_TPREL16
:
6787 case BFD_RELOC_PPC_GOT_TPREL16_LO
:
6788 case BFD_RELOC_PPC_GOT_TPREL16_HI
:
6789 case BFD_RELOC_PPC_GOT_TPREL16_HA
:
6790 case BFD_RELOC_24_PLT_PCREL
:
6791 case BFD_RELOC_PPC_LOCAL24PC
:
6792 case BFD_RELOC_32_PLT_PCREL
:
6793 case BFD_RELOC_GPREL16
:
6794 case BFD_RELOC_PPC_VLE_SDAREL_LO16A
:
6795 case BFD_RELOC_PPC_VLE_SDAREL_HI16A
:
6796 case BFD_RELOC_PPC_VLE_SDAREL_HA16A
:
6797 case BFD_RELOC_PPC_EMB_NADDR32
:
6798 case BFD_RELOC_PPC_EMB_NADDR16
:
6799 case BFD_RELOC_PPC_EMB_NADDR16_LO
:
6800 case BFD_RELOC_PPC_EMB_NADDR16_HI
:
6801 case BFD_RELOC_PPC_EMB_NADDR16_HA
:
6802 case BFD_RELOC_PPC_EMB_SDAI16
:
6803 case BFD_RELOC_PPC_EMB_SDA2REL
:
6804 case BFD_RELOC_PPC_EMB_SDA2I16
:
6805 case BFD_RELOC_PPC_EMB_SDA21
:
6806 case BFD_RELOC_PPC_VLE_SDA21_LO
:
6807 case BFD_RELOC_PPC_EMB_MRKREF
:
6808 case BFD_RELOC_PPC_EMB_RELSEC16
:
6809 case BFD_RELOC_PPC_EMB_RELST_LO
:
6810 case BFD_RELOC_PPC_EMB_RELST_HI
:
6811 case BFD_RELOC_PPC_EMB_RELST_HA
:
6812 case BFD_RELOC_PPC_EMB_BIT_FLD
:
6813 case BFD_RELOC_PPC_EMB_RELSDA
:
6814 case BFD_RELOC_PPC64_TOC
:
6815 case BFD_RELOC_PPC_TOC16
:
6816 case BFD_RELOC_PPC64_TOC16_LO
:
6817 case BFD_RELOC_PPC64_TOC16_HI
:
6818 case BFD_RELOC_PPC64_TOC16_HA
:
6819 case BFD_RELOC_PPC64_DTPREL16_HIGHER
:
6820 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
:
6821 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
:
6822 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
:
6823 case BFD_RELOC_PPC64_TPREL16_HIGHER
:
6824 case BFD_RELOC_PPC64_TPREL16_HIGHERA
:
6825 case BFD_RELOC_PPC64_TPREL16_HIGHEST
:
6826 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
:
6832 case BFD_RELOC_NONE
:
6838 _("Gas failure, reloc value %d\n"), fixP
->fx_r_type
);
6845 ppc_elf_validate_fix (fixP
, seg
);
6846 fixP
->fx_addnumber
= value
;
6848 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6849 from the section contents. If we are going to be emitting a reloc
6850 then the section contents are immaterial, so don't warn if they
6851 happen to overflow. Leave such warnings to ld. */
6853 fixP
->fx_no_overflow
= 1;
6855 if (fixP
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
6856 fixP
->fx_addnumber
= 0;
6860 fixP
->fx_addnumber
= 0;
6862 /* We want to use the offset within the toc, not the actual VMA
6864 fixP
->fx_addnumber
=
6865 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixP
->fx_addsy
))
6866 - S_GET_VALUE (ppc_toc_csect
);
6872 /* Generate a reloc for a fixup. */
6875 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
6879 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
6881 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
6882 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
6883 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
6884 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
6885 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
6887 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
6888 _("reloc %d not supported by object file format"),
6889 (int) fixp
->fx_r_type
);
6892 reloc
->addend
= fixp
->fx_addnumber
;
6898 ppc_cfi_frame_initial_instructions (void)
6900 cfi_add_CFA_def_cfa (1, 0);
6904 tc_ppc_regname_to_dw2regnum (char *regname
)
6906 unsigned int regnum
= -1;
6910 static struct { char *name
; int dw2regnum
; } regnames
[] =
6912 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6913 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6914 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6915 { "spe_acc", 111 }, { "spefscr", 112 }
6918 for (i
= 0; i
< ARRAY_SIZE (regnames
); ++i
)
6919 if (strcmp (regnames
[i
].name
, regname
) == 0)
6920 return regnames
[i
].dw2regnum
;
6922 if (regname
[0] == 'r' || regname
[0] == 'f' || regname
[0] == 'v')
6924 p
= regname
+ 1 + (regname
[1] == '.');
6925 regnum
= strtoul (p
, &q
, 10);
6926 if (p
== q
|| *q
|| regnum
>= 32)
6928 if (regname
[0] == 'f')
6930 else if (regname
[0] == 'v')
6933 else if (regname
[0] == 'c' && regname
[1] == 'r')
6935 p
= regname
+ 2 + (regname
[2] == '.');
6936 if (p
[0] < '0' || p
[0] > '7' || p
[1])
6938 regnum
= p
[0] - '0' + 68;