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"));
2328 /* .TOC. used in an opd entry as .TOC.@tocbase doesn't need to be
2329 emitted. Other uses of .TOC. will cause the symbol to be marked
2330 with BSF_KEEP in md_apply_fix. */
2333 ppc_elf_adjust_symtab (void)
2338 symp = symbol_find (".TOC.");
2341 asymbol *bsym = symbol_get_bfdsym (symp);
2342 if ((bsym->flags & BSF_KEEP) == 0)
2343 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2349 #endif /* OBJ_ELF */
2354 * Summary of parse_toc_entry.
2356 * in: Input_line_pointer points to the '[' in one of:
2358 * [toc] [tocv] [toc32] [toc64]
2360 * Anything else is an error of one kind or another.
2363 * return value: success or failure
2364 * toc_kind: kind of toc reference
2365 * input_line_pointer:
2366 * success: first char after the ']'
2367 * failure: unchanged
2371 * [toc] - rv == success, toc_kind = default_toc
2372 * [tocv] - rv == success, toc_kind = data_in_toc
2373 * [toc32] - rv == success, toc_kind = must_be_32
2374 * [toc64] - rv == success, toc_kind = must_be_64
2378 enum toc_size_qualifier
2380 default_toc, /* The toc cell constructed should be the system default size */
2381 data_in_toc, /* This is a direct reference to a toc cell */
2382 must_be_32, /* The toc cell constructed must be 32 bits wide */
2383 must_be_64 /* The toc cell constructed must be 64 bits wide */
2387 parse_toc_entry (enum toc_size_qualifier *toc_kind)
2392 enum toc_size_qualifier t;
2394 /* Save the input_line_pointer. */
2395 start = input_line_pointer;
2397 /* Skip over the '[' , and whitespace. */
2398 ++input_line_pointer;
2401 /* Find the spelling of the operand. */
2402 toc_spec = input_line_pointer;
2403 c = get_symbol_end ();
2405 if (strcmp (toc_spec, "toc") == 0)
2409 else if (strcmp (toc_spec, "tocv") == 0)
2413 else if (strcmp (toc_spec, "toc32") == 0)
2417 else if (strcmp (toc_spec, "toc64") == 0)
2423 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
2424 *input_line_pointer = c;
2425 input_line_pointer = start;
2429 /* Now find the ']'. */
2430 *input_line_pointer = c;
2432 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2433 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
2437 as_bad (_("syntax error: expected `]', found `%c'"), c);
2438 input_line_pointer = start;
2447 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
2448 /* See whether a symbol is in the TOC section. */
2451 ppc_is_toc_sym (symbolS *sym)
2454 return symbol_get_tc (sym)->symbol_class == XMC_TC;
2457 const char *sname = segment_name (S_GET_SEGMENT (sym));
2459 return strcmp (sname, ".toc") == 0;
2461 return strcmp (sname, ".got") == 0;
2464 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
2468 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2470 ppc_apuinfo_section_add (unsigned int apu, unsigned int version)
2474 /* Check we don't already exist. */
2475 for (i = 0; i < ppc_apuinfo_num; i++)
2476 if (ppc_apuinfo_list[i] == APUID (apu, version))
2479 if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2481 if (ppc_apuinfo_num_alloc == 0)
2483 ppc_apuinfo_num_alloc = 4;
2484 ppc_apuinfo_list = (unsigned long *)
2485 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2489 ppc_apuinfo_num_alloc += 4;
2490 ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list,
2491 sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2494 ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2500 /* We need to keep a list of fixups. We can't simply generate them as
2501 we go, because that would require us to first create the frag, and
2502 that would screw up references to ``.''. */
2508 bfd_reloc_code_real_type reloc;
2511 #define MAX_INSN_FIXUPS (5)
2514 #define E_OR2I_INSN 0x7000C000
2515 #define E_AND2I_DOT_INSN 0x7000C800
2516 #define E_OR2IS_INSN 0x7000D000
2517 #define E_LIS_INSN 0x7000E000
2518 #define E_AND2IS_DOT_INSN 0x7000E800
2521 #define E_ADD2I_DOT_INSN 0x70008800
2522 #define E_ADD2IS_INSN 0x70009000
2523 #define E_CMP16I_INSN 0x70009800
2524 #define E_MULL2I_INSN 0x7000A000
2525 #define E_CMPL16I_INSN 0x7000A800
2526 #define E_CMPH16I_INSN 0x7000B000
2527 #define E_CMPHL16I_INSN 0x7000B800
2529 /* This routine is called for each instruction to be assembled. */
2532 md_assemble (char *str)
2535 const struct powerpc_opcode *opcode;
2537 const unsigned char *opindex_ptr;
2541 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
2546 unsigned int insn_length;
2548 /* Get the opcode. */
2549 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
2554 /* Look up the opcode in the hash table. */
2555 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
2556 if (opcode == (const struct powerpc_opcode *) NULL)
2558 const struct powerpc_macro *macro;
2560 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
2561 if (macro == (const struct powerpc_macro *) NULL)
2562 as_bad (_("unrecognized opcode: `%s'"), str);
2564 ppc_macro (s, macro);
2569 insn = opcode->opcode;
2572 while (ISSPACE (*str))
2575 /* PowerPC operands are just expressions. The only real issue is
2576 that a few operand types are optional. All cases which might use
2577 an optional operand separate the operands only with commas (in some
2578 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2579 have optional operands). Most instructions with optional operands
2580 have only one. Those that have more than one optional operand can
2581 take either all their operands or none. So, before we start seriously
2582 parsing the operands, we check to see if we have optional operands,
2583 and if we do, we count the number of commas to see which operands
2584 have been omitted. */
2586 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2588 const struct powerpc_operand *operand;
2590 operand = &powerpc_operands[*opindex_ptr];
2591 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
2593 unsigned int opcount;
2594 unsigned int num_operands_expected;
2596 /* There is an optional operand. Count the number of
2597 commas in the input line. */
2604 while ((s = strchr (s, ',')) != (char *) NULL)
2611 /* Compute the number of expected operands.
2612 Do not count fake operands. */
2613 for (num_operands_expected = 0, i = 0; opcode->operands[i]; i ++)
2614 if ((powerpc_operands [opcode->operands[i]].flags & PPC_OPERAND_FAKE) == 0)
2615 ++ num_operands_expected;
2617 /* If there are fewer operands in the line then are called
2618 for by the instruction, we want to skip the optional
2620 if (opcount < num_operands_expected)
2627 /* Gather the operands. */
2631 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2633 const struct powerpc_operand *operand;
2639 if (next_opindex == 0)
2640 operand = &powerpc_operands[*opindex_ptr];
2643 operand = &powerpc_operands[next_opindex];
2648 /* If this is a fake operand, then we do not expect anything
2650 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
2652 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2653 if (errmsg != (const char *) NULL)
2654 as_bad ("%s", errmsg);
2658 /* If this is an optional operand, and we are skipping it, just
2660 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
2663 if (operand->insert)
2665 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2666 if (errmsg != (const char *) NULL)
2667 as_bad ("%s", errmsg);
2669 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
2670 next_opindex = *opindex_ptr + 1;
2674 /* Gather the operand. */
2675 hold = input_line_pointer;
2676 input_line_pointer = str;
2679 if (*input_line_pointer == '[')
2681 /* We are expecting something like the second argument here:
2683 * lwz r4,[toc].GS.0.static_int(rtoc)
2684 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2685 * The argument following the `]' must be a symbol name, and the
2686 * register must be the toc register: 'rtoc' or '2'
2688 * The effect is to 0 as the displacement field
2689 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2690 * the appropriate variation) reloc against it based on the symbol.
2691 * The linker will build the toc, and insert the resolved toc offset.
2694 * o The size of the toc entry is currently assumed to be
2695 * 32 bits. This should not be assumed to be a hard coded
2697 * o In an effort to cope with a change from 32 to 64 bits,
2698 * there are also toc entries that are specified to be
2699 * either 32 or 64 bits:
2700 * lwz r4,[toc32].GS.0.static_int(rtoc)
2701 * lwz r4,[toc64].GS.0.static_int(rtoc)
2702 * These demand toc entries of the specified size, and the
2703 * instruction probably requires it.
2707 enum toc_size_qualifier toc_kind;
2708 bfd_reloc_code_real_type toc_reloc;
2710 /* Go parse off the [tocXX] part. */
2711 valid_toc = parse_toc_entry (&toc_kind);
2715 /* Note: message has already been issued.
2716 FIXME: what sort of recovery should we do?
2717 demand_rest_of_line (); return; ? */
2720 /* Now get the symbol following the ']'. */
2726 /* In this case, we may not have seen the symbol yet,
2727 since it is allowed to appear on a .extern or .globl
2728 or just be a label in the .data section. */
2729 toc_reloc = BFD_RELOC_PPC_TOC16;
2732 /* 1. The symbol must be defined and either in the toc
2733 section, or a global.
2734 2. The reloc generated must have the TOCDEFN flag set
2735 in upper bit mess of the reloc type.
2736 FIXME: It's a little confusing what the tocv
2737 qualifier can be used for. At the very least, I've
2738 seen three uses, only one of which I'm sure I can
2740 if (ex.X_op == O_symbol)
2742 gas_assert (ex.X_add_symbol != NULL);
2743 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2746 as_bad (_("[tocv] symbol is not a toc symbol"));
2750 toc_reloc = BFD_RELOC_PPC_TOC16;
2753 /* FIXME: these next two specifically specify 32/64 bit
2754 toc entries. We don't support them today. Is this
2755 the right way to say that? */
2756 toc_reloc = BFD_RELOC_UNUSED;
2757 as_bad (_("unimplemented toc32 expression modifier"));
2760 /* FIXME: see above. */
2761 toc_reloc = BFD_RELOC_UNUSED;
2762 as_bad (_("unimplemented toc64 expression modifier"));
2766 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2772 /* We need to generate a fixup for this expression. */
2773 if (fc >= MAX_INSN_FIXUPS)
2774 as_fatal (_("too many fixups"));
2776 fixups[fc].reloc = toc_reloc;
2777 fixups[fc].exp = ex;
2778 fixups[fc].opindex = *opindex_ptr;
2781 /* Ok. We've set up the fixup for the instruction. Now make it
2782 look like the constant 0 was found here. */
2784 ex.X_op = O_constant;
2785 ex.X_add_number = 0;
2786 ex.X_add_symbol = NULL;
2787 ex.X_op_symbol = NULL;
2794 && (((operand->flags & PPC_OPERAND_CR_BIT) != 0)
2795 || ((operand->flags & PPC_OPERAND_CR_REG) != 0)))
2796 || !register_name (&ex))
2798 char save_lex = lex_type['%'];
2800 if (((operand->flags & PPC_OPERAND_CR_REG) != 0)
2801 || (operand->flags & PPC_OPERAND_CR_BIT) != 0)
2804 lex_type['%'] |= LEX_BEGIN_NAME;
2808 lex_type['%'] = save_lex;
2812 str = input_line_pointer;
2813 input_line_pointer = hold;
2815 if (ex.X_op == O_illegal)
2816 as_bad (_("illegal operand"));
2817 else if (ex.X_op == O_absent)
2818 as_bad (_("missing operand"));
2819 else if (ex.X_op == O_register)
2821 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2822 ppc_cpu, (char *) NULL, 0);
2824 else if (ex.X_op == O_constant)
2827 /* Allow @HA, @L, @H on constants. */
2828 bfd_reloc_code_real_type reloc;
2829 char *orig_str = str;
2831 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2838 case BFD_RELOC_LO16:
2839 /* X_unsigned is the default, so if the user has done
2840 something which cleared it, we always produce a
2842 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2843 ex.X_add_number &= 0xffff;
2845 ex.X_add_number = SEX16 (ex.X_add_number);
2848 case BFD_RELOC_HI16:
2849 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2850 ex.X_add_number = PPC_HI (ex.X_add_number);
2852 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2855 case BFD_RELOC_HI16_S:
2856 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2857 ex.X_add_number = PPC_HA (ex.X_add_number);
2859 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2862 case BFD_RELOC_PPC64_HIGHER:
2863 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2864 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2866 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2869 case BFD_RELOC_PPC64_HIGHER_S:
2870 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2871 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2873 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2876 case BFD_RELOC_PPC64_HIGHEST:
2877 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2878 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2880 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2883 case BFD_RELOC_PPC64_HIGHEST_S:
2884 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2885 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2887 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2890 #endif /* OBJ_ELF */
2891 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2892 ppc_cpu, (char *) NULL, 0);
2896 bfd_reloc_code_real_type reloc = BFD_RELOC_UNUSED;
2898 if (ex.X_op == O_symbol && str[0] == '(')
2900 const char *sym_name = S_GET_NAME (ex.X_add_symbol);
2901 if (sym_name[0] == '.')
2904 if (strcasecmp (sym_name, "__tls_get_addr") == 0)
2906 expressionS tls_exp;
2908 hold = input_line_pointer;
2909 input_line_pointer = str + 1;
2910 expression (&tls_exp);
2911 if (tls_exp.X_op == O_symbol)
2913 reloc = BFD_RELOC_UNUSED;
2914 if (strncasecmp (input_line_pointer, "@tlsgd)", 7) == 0)
2916 reloc = BFD_RELOC_PPC_TLSGD;
2917 input_line_pointer += 7;
2919 else if (strncasecmp (input_line_pointer, "@tlsld)", 7) == 0)
2921 reloc = BFD_RELOC_PPC_TLSLD;
2922 input_line_pointer += 7;
2924 if (reloc != BFD_RELOC_UNUSED)
2927 str = input_line_pointer;
2929 if (fc >= MAX_INSN_FIXUPS)
2930 as_fatal (_("too many fixups"));
2931 fixups[fc].exp = tls_exp;
2932 fixups[fc].opindex = *opindex_ptr;
2933 fixups[fc].reloc = reloc;
2937 input_line_pointer = hold;
2941 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2943 /* Some TLS tweaks. */
2949 case BFD_RELOC_PPC_TLS:
2950 if (!_bfd_elf_ppc_at_tls_transform (opcode->opcode, 0))
2951 as_bad (_("@tls may not be used with \"%s\" operands"),
2953 else if (operand->shift != 11)
2954 as_bad (_("@tls may only be used in last operand"));
2956 insn = ppc_insert_operand (insn, operand,
2958 ppc_cpu, (char *) NULL, 0);
2961 /* We'll only use the 32 (or 64) bit form of these relocations
2962 in constants. Instructions get the 16 bit form. */
2963 case BFD_RELOC_PPC_DTPREL:
2964 reloc = BFD_RELOC_PPC_DTPREL16;
2966 case BFD_RELOC_PPC_TPREL:
2967 reloc = BFD_RELOC_PPC_TPREL16;
2971 /* If VLE-mode convert LO/HI/HA relocations. */
2972 if (opcode->flags & PPC_OPCODE_VLE)
2974 int tmp_insn = insn & opcode->mask;
2976 int use_d_reloc = (tmp_insn == E_OR2I_INSN
2977 || tmp_insn == E_AND2I_DOT_INSN
2978 || tmp_insn == E_OR2IS_INSN
2979 || tmp_insn == E_LIS_INSN
2980 || tmp_insn == E_AND2IS_DOT_INSN);
2983 int use_a_reloc = (tmp_insn == E_ADD2I_DOT_INSN
2984 || tmp_insn == E_ADD2IS_INSN
2985 || tmp_insn == E_CMP16I_INSN
2986 || tmp_insn == E_MULL2I_INSN
2987 || tmp_insn == E_CMPL16I_INSN
2988 || tmp_insn == E_CMPH16I_INSN
2989 || tmp_insn == E_CMPHL16I_INSN);
2996 case BFD_RELOC_PPC_EMB_SDA21:
2997 reloc = BFD_RELOC_PPC_VLE_SDA21;
3000 case BFD_RELOC_LO16:
3002 reloc = BFD_RELOC_PPC_VLE_LO16D;
3003 else if (use_a_reloc)
3004 reloc = BFD_RELOC_PPC_VLE_LO16A;
3007 case BFD_RELOC_HI16:
3009 reloc = BFD_RELOC_PPC_VLE_HI16D;
3010 else if (use_a_reloc)
3011 reloc = BFD_RELOC_PPC_VLE_HI16A;
3014 case BFD_RELOC_HI16_S:
3016 reloc = BFD_RELOC_PPC_VLE_HA16D;
3017 else if (use_a_reloc)
3018 reloc = BFD_RELOC_PPC_VLE_HA16A;
3021 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
3023 reloc = BFD_RELOC_PPC_VLE_SDAREL_LO16D;
3026 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
3028 reloc = BFD_RELOC_PPC_VLE_SDAREL_HI16D;
3031 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
3033 reloc = BFD_RELOC_PPC_VLE_SDAREL_HA16D;
3038 /* For the absolute forms of branches, convert the PC
3039 relative form back into the absolute. */
3040 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
3044 case BFD_RELOC_PPC_B26:
3045 reloc = BFD_RELOC_PPC_BA26;
3047 case BFD_RELOC_PPC_B16:
3048 reloc = BFD_RELOC_PPC_BA16;
3050 case BFD_RELOC_PPC_B16_BRTAKEN:
3051 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
3053 case BFD_RELOC_PPC_B16_BRNTAKEN:
3054 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
3063 case BFD_RELOC_PPC_TOC16:
3064 toc_reloc_types |= has_small_toc_reloc;
3066 case BFD_RELOC_PPC64_TOC16_LO:
3067 case BFD_RELOC_PPC64_TOC16_HI:
3068 case BFD_RELOC_PPC64_TOC16_HA:
3069 toc_reloc_types |= has_large_toc_reloc;
3075 if ((operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
3080 reloc = BFD_RELOC_PPC64_ADDR16_DS;
3082 case BFD_RELOC_LO16:
3083 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
3085 case BFD_RELOC_16_GOTOFF:
3086 reloc = BFD_RELOC_PPC64_GOT16_DS;
3088 case BFD_RELOC_LO16_GOTOFF:
3089 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
3091 case BFD_RELOC_LO16_PLTOFF:
3092 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
3094 case BFD_RELOC_16_BASEREL:
3095 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
3097 case BFD_RELOC_LO16_BASEREL:
3098 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
3100 case BFD_RELOC_PPC_TOC16:
3101 reloc = BFD_RELOC_PPC64_TOC16_DS;
3103 case BFD_RELOC_PPC64_TOC16_LO:
3104 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
3106 case BFD_RELOC_PPC64_PLTGOT16:
3107 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
3109 case BFD_RELOC_PPC64_PLTGOT16_LO:
3110 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
3112 case BFD_RELOC_PPC_DTPREL16:
3113 reloc = BFD_RELOC_PPC64_DTPREL16_DS;
3115 case BFD_RELOC_PPC_DTPREL16_LO:
3116 reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
3118 case BFD_RELOC_PPC_TPREL16:
3119 reloc = BFD_RELOC_PPC64_TPREL16_DS;
3121 case BFD_RELOC_PPC_TPREL16_LO:
3122 reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
3124 case BFD_RELOC_PPC_GOT_DTPREL16:
3125 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
3126 case BFD_RELOC_PPC_GOT_TPREL16:
3127 case BFD_RELOC_PPC_GOT_TPREL16_LO:
3130 as_bad (_("unsupported relocation for DS offset field"));
3135 #endif /* OBJ_ELF */
3137 if (reloc != BFD_RELOC_UNUSED)
3139 /* Determine a BFD reloc value based on the operand information.
3140 We are only prepared to turn a few of the operands into
3142 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3143 && operand->bitm == 0x3fffffc
3144 && operand->shift == 0)
3145 reloc = BFD_RELOC_PPC_B26;
3146 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3147 && operand->bitm == 0xfffc
3148 && operand->shift == 0)
3149 reloc = BFD_RELOC_PPC_B16;
3150 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3151 && operand->bitm == 0x1fe
3152 && operand->shift == -1)
3153 reloc = BFD_RELOC_PPC_VLE_REL8;
3154 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3155 && operand->bitm == 0xfffe
3156 && operand->shift == 0)
3157 reloc = BFD_RELOC_PPC_VLE_REL15;
3158 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3159 && operand->bitm == 0x1fffffe
3160 && operand->shift == 0)
3161 reloc = BFD_RELOC_PPC_VLE_REL24;
3162 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
3163 && operand->bitm == 0x3fffffc
3164 && operand->shift == 0)
3165 reloc = BFD_RELOC_PPC_BA26;
3166 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
3167 && operand->bitm == 0xfffc
3168 && operand->shift == 0)
3169 reloc = BFD_RELOC_PPC_BA16;
3170 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3171 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
3172 && (operand->bitm & 0xfff0) == 0xfff0
3173 && operand->shift == 0)
3175 if (ppc_is_toc_sym (ex.X_add_symbol))
3177 reloc = BFD_RELOC_PPC_TOC16;
3180 && (operand->flags & PPC_OPERAND_DS) != 0)
3181 reloc = BFD_RELOC_PPC64_TOC16_DS;
3186 reloc = BFD_RELOC_16;
3189 && (operand->flags & PPC_OPERAND_DS) != 0)
3190 reloc = BFD_RELOC_PPC64_ADDR16_DS;
3194 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3196 /* We need to generate a fixup for this expression. */
3197 if (fc >= MAX_INSN_FIXUPS)
3198 as_fatal (_("too many fixups"));
3199 fixups[fc].exp = ex;
3200 fixups[fc].opindex = *opindex_ptr;
3201 fixups[fc].reloc = reloc;
3209 /* If expecting more operands, then we want to see "),". */
3210 if (*str == endc && opindex_ptr[1] != 0)
3214 while (ISSPACE (*str));
3218 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
3226 /* The call to expression should have advanced str past any
3229 && (endc != ',' || *str != '\0'))
3232 as_bad (_("syntax error; end of line, expected `%c'"), endc);
3234 as_bad (_("syntax error; found `%c', expected `%c'"), *str, endc);
3242 while (ISSPACE (*str))
3246 as_bad (_("junk at end of line: `%s'"), str);
3249 /* Do we need/want an APUinfo section? */
3250 if ((ppc_cpu & (PPC_OPCODE_E500 | PPC_OPCODE_E500MC | PPC_OPCODE_VLE)) != 0)
3252 /* These are all version "1". */
3253 if (opcode->flags & PPC_OPCODE_SPE)
3254 ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
3255 if (opcode->flags & PPC_OPCODE_ISEL)
3256 ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
3257 if (opcode->flags & PPC_OPCODE_EFS)
3258 ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
3259 if (opcode->flags & PPC_OPCODE_BRLOCK)
3260 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
3261 if (opcode->flags & PPC_OPCODE_PMR)
3262 ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
3263 if (opcode->flags & PPC_OPCODE_CACHELCK)
3264 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
3265 if (opcode->flags & PPC_OPCODE_RFMCI)
3266 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
3267 if (opcode->flags & PPC_OPCODE_VLE)
3268 ppc_apuinfo_section_add (PPC_APUINFO_VLE, 1);
3272 /* Write out the instruction. */
3273 /* Differentiate between two and four byte insns. */
3274 if (ppc_mach () == bfd_mach_ppc_vle)
3276 if (PPC_OP_SE_VLE (insn))
3280 addr_mod = frag_now_fix () & 1;
3285 addr_mod = frag_now_fix () & 3;
3287 /* All instructions can start on a 2 byte boundary for VLE. */
3288 f = frag_more (insn_length);
3289 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
3291 if (ppc_mach() == bfd_mach_ppc_vle)
3292 as_bad (_("instruction address is not a multiple of 2"));
3294 as_bad (_("instruction address is not a multiple of 4"));
3296 frag_now->insn_addr = addr_mod;
3297 frag_now->has_code = 1;
3298 md_number_to_chars (f, insn, insn_length);
3301 dwarf2_emit_insn (insn_length);
3304 /* Create any fixups. */
3305 for (i = 0; i < fc; i++)
3308 if (fixups[i].reloc != BFD_RELOC_UNUSED)
3310 reloc_howto_type *reloc_howto;
3314 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
3318 size = bfd_get_reloc_size (reloc_howto);
3319 offset = target_big_endian ? (insn_length - size) : 0;
3321 if (size < 1 || size > 4)
3324 fixP = fix_new_exp (frag_now,
3325 f - frag_now->fr_literal + offset,
3328 reloc_howto->pc_relative,
3333 const struct powerpc_operand *operand;
3335 operand = &powerpc_operands[fixups[i].opindex];
3336 fixP = fix_new_exp (frag_now,
3337 f - frag_now->fr_literal,
3340 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
3343 fixP->fx_pcrel_adjust = fixups[i].opindex;
3347 /* Handle a macro. Gather all the operands, transform them as
3348 described by the macro, and call md_assemble recursively. All the
3349 operands are separated by commas; we don't accept parentheses
3350 around operands here. */
3353 ppc_macro (char *str, const struct powerpc_macro *macro)
3364 /* Gather the users operands into the operands array. */
3369 if (count >= sizeof operands / sizeof operands[0])
3371 operands[count++] = s;
3372 s = strchr (s, ',');
3373 if (s == (char *) NULL)
3378 if (count != macro->operands)
3380 as_bad (_("wrong number of operands"));
3384 /* Work out how large the string must be (the size is unbounded
3385 because it includes user input). */
3387 format = macro->format;
3388 while (*format != '\0')
3397 arg = strtol (format + 1, &send, 10);
3398 know (send != format && arg < count);
3399 len += strlen (operands[arg]);
3404 /* Put the string together. */
3405 complete = s = (char *) alloca (len + 1);
3406 format = macro->format;
3407 while (*format != '\0')
3413 arg = strtol (format + 1, &send, 10);
3414 strcpy (s, operands[arg]);
3421 /* Assemble the constructed instruction. */
3422 md_assemble (complete);
3426 /* For ELF, add support for SHT_ORDERED. */
3429 ppc_section_type (char *str, size_t len)
3431 if (len == 7 && strncmp (str, "ordered", 7) == 0)
3438 ppc_section_flags (flagword flags, bfd_vma attr ATTRIBUTE_UNUSED, int type)
3440 if (type == SHT_ORDERED)
3441 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
3445 #endif /* OBJ_ELF */
3448 /* Pseudo-op handling. */
3450 /* The .byte pseudo-op. This is similar to the normal .byte
3451 pseudo-op, but it can also take a single ASCII string. */
3454 ppc_byte (int ignore ATTRIBUTE_UNUSED)
3456 if (*input_line_pointer != '\"')
3462 /* Gather characters. A real double quote is doubled. Unusual
3463 characters are not permitted. */
3464 ++input_line_pointer;
3469 c = *input_line_pointer++;
3473 if (*input_line_pointer != '\"')
3475 ++input_line_pointer;
3478 FRAG_APPEND_1_CHAR (c);
3481 demand_empty_rest_of_line ();
3486 /* XCOFF specific pseudo-op handling. */
3488 /* This is set if we are creating a .stabx symbol, since we don't want
3489 to handle symbol suffixes for such symbols. */
3490 static bfd_boolean ppc_stab_symbol;
3492 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
3493 symbols in the .bss segment as though they were local common
3494 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
3495 aligns .comm and .lcomm to 4 bytes. */
3498 ppc_comm (int lcomm)
3500 asection *current_seg = now_seg;
3501 subsegT current_subseg = now_subseg;
3507 symbolS *lcomm_sym = NULL;
3511 name = input_line_pointer;
3512 endc = get_symbol_end ();
3513 end_name = input_line_pointer;
3516 if (*input_line_pointer != ',')
3518 as_bad (_("missing size"));
3519 ignore_rest_of_line ();
3522 ++input_line_pointer;
3524 size = get_absolute_expression ();
3527 as_bad (_("negative size"));
3528 ignore_rest_of_line ();
3534 /* The third argument to .comm is the alignment. */
3535 if (*input_line_pointer != ',')
3539 ++input_line_pointer;
3540 align = get_absolute_expression ();
3543 as_warn (_("ignoring bad alignment"));
3558 /* The third argument to .lcomm appears to be the real local
3559 common symbol to create. References to the symbol named in
3560 the first argument are turned into references to the third
3562 if (*input_line_pointer != ',')
3564 as_bad (_("missing real symbol name"));
3565 ignore_rest_of_line ();
3568 ++input_line_pointer;
3570 lcomm_name = input_line_pointer;
3571 lcomm_endc = get_symbol_end ();
3573 lcomm_sym = symbol_find_or_make (lcomm_name);
3575 *input_line_pointer = lcomm_endc;
3579 sym = symbol_find_or_make (name);
3582 if (S_IS_DEFINED (sym)
3583 || S_GET_VALUE (sym) != 0)
3585 as_bad (_("attempt to redefine symbol"));
3586 ignore_rest_of_line ();
3590 record_alignment (bss_section, align);
3593 || ! S_IS_DEFINED (lcomm_sym))
3602 S_SET_EXTERNAL (sym);
3606 symbol_get_tc (lcomm_sym)->output = 1;
3607 def_sym = lcomm_sym;
3611 subseg_set (bss_section, 1);
3612 frag_align (align, 0, 0);
3614 symbol_set_frag (def_sym, frag_now);
3615 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
3616 def_size, (char *) NULL);
3618 S_SET_SEGMENT (def_sym, bss_section);
3619 symbol_get_tc (def_sym)->align = align;
3623 /* Align the size of lcomm_sym. */
3624 symbol_get_frag (lcomm_sym)->fr_offset =
3625 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
3626 &~ ((1 << align) - 1));
3627 if (align > symbol_get_tc (lcomm_sym)->align)
3628 symbol_get_tc (lcomm_sym)->align = align;
3633 /* Make sym an offset from lcomm_sym. */
3634 S_SET_SEGMENT (sym, bss_section);
3635 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
3636 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
3637 symbol_get_frag (lcomm_sym)->fr_offset += size;
3640 subseg_set (current_seg, current_subseg);
3642 demand_empty_rest_of_line ();
3645 /* The .csect pseudo-op. This switches us into a different
3646 subsegment. The first argument is a symbol whose value is the
3647 start of the .csect. In COFF, csect symbols get special aux
3648 entries defined by the x_csect field of union internal_auxent. The
3649 optional second argument is the alignment (the default is 2). */
3652 ppc_csect (int ignore ATTRIBUTE_UNUSED)
3659 name = input_line_pointer;
3660 endc = get_symbol_end ();
3662 sym = symbol_find_or_make (name);
3664 *input_line_pointer = endc;
3666 if (S_GET_NAME (sym)[0] == '\0')
3668 /* An unnamed csect is assumed to be [PR]. */
3669 symbol_get_tc (sym)->symbol_class = XMC_PR;
3673 if (*input_line_pointer == ',')
3675 ++input_line_pointer;
3676 align = get_absolute_expression ();
3679 ppc_change_csect (sym, align);
3681 demand_empty_rest_of_line ();
3684 /* Change to a different csect. */
3687 ppc_change_csect (symbolS *sym, offsetT align)
3689 if (S_IS_DEFINED (sym))
3690 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
3700 /* This is a new csect. We need to look at the symbol class to
3701 figure out whether it should go in the text section or the
3705 switch (symbol_get_tc (sym)->symbol_class)
3715 S_SET_SEGMENT (sym, text_section);
3716 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
3717 ++ppc_text_subsegment;
3718 list_ptr = &ppc_text_csects;
3728 if (ppc_toc_csect != NULL
3729 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
3730 == ppc_data_subsegment))
3732 S_SET_SEGMENT (sym, data_section);
3733 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
3734 ++ppc_data_subsegment;
3735 list_ptr = &ppc_data_csects;
3741 /* We set the obstack chunk size to a small value before
3742 changing subsegments, so that we don't use a lot of memory
3743 space for what may be a small section. */
3744 hold_chunksize = chunksize;
3747 sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
3748 symbol_get_tc (sym)->subseg);
3750 chunksize = hold_chunksize;
3753 ppc_after_toc_frag = frag_now;
3755 record_alignment (sec, align);
3757 frag_align_code (align, 0);
3759 frag_align (align, 0, 0);
3761 symbol_set_frag (sym, frag_now);
3762 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3764 symbol_get_tc (sym)->align = align;
3765 symbol_get_tc (sym)->output = 1;
3766 symbol_get_tc (sym)->within = sym;
3768 for (list = *list_ptr;
3769 symbol_get_tc (list)->next != (symbolS *) NULL;
3770 list = symbol_get_tc (list)->next)
3772 symbol_get_tc (list)->next = sym;
3774 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3775 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3779 ppc_current_csect = sym;
3783 ppc_change_debug_section (unsigned int idx, subsegT subseg)
3787 const struct xcoff_dwsect_name *dw = &xcoff_dwsect_names[idx];
3789 sec = subseg_new (dw->name, subseg);
3790 oldflags = bfd_get_section_flags (stdoutput, sec);
3791 if (oldflags == SEC_NO_FLAGS)
3793 /* Just created section. */
3794 gas_assert (dw_sections[idx].sect == NULL);
3796 bfd_set_section_flags (stdoutput, sec, SEC_DEBUGGING);
3797 bfd_set_section_alignment (stdoutput, sec, 0);
3798 dw_sections[idx].sect = sec;
3801 /* Not anymore in a csect. */
3802 ppc_current_csect = NULL;
3805 /* The .dwsect pseudo-op. Defines a DWARF section. Syntax is:
3806 .dwsect flag [, opt-label ]
3810 ppc_dwsect (int ignore ATTRIBUTE_UNUSED)
3814 const struct xcoff_dwsect_name *dw;
3815 struct dw_subsection *subseg;
3816 struct dw_section *dws;
3820 flag = get_absolute_expression ();
3822 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
3823 if (xcoff_dwsect_names[i].flag == flag)
3825 dw = &xcoff_dwsect_names[i];
3829 /* Parse opt-label. */
3830 if (*input_line_pointer == ',')
3835 ++input_line_pointer;
3837 label = input_line_pointer;
3838 c = get_symbol_end ();
3839 opt_label = symbol_find_or_make (label);
3840 *input_line_pointer = c;
3845 demand_empty_rest_of_line ();
3847 /* Return now in case of unknown subsection. */
3850 as_bad (_("no known dwarf XCOFF section for flag 0x%08x\n"),
3855 /* Find the subsection. */
3856 dws = &dw_sections[i];
3858 if (opt_label != NULL && S_IS_DEFINED (opt_label))
3860 /* Sanity check (note that in theory S_GET_SEGMENT mustn't be null). */
3861 if (dws->sect == NULL || S_GET_SEGMENT (opt_label) != dws->sect)
3863 as_bad (_("label %s was not defined in this dwarf section"),
3864 S_GET_NAME (opt_label));
3865 subseg = dws->anon_subseg;
3869 subseg = symbol_get_tc (opt_label)->u.dw;
3874 /* Switch to the subsection. */
3875 ppc_change_debug_section (i, subseg->subseg);
3879 /* Create a new dw subsection. */
3880 subseg = (struct dw_subsection *)
3881 xmalloc (sizeof (struct dw_subsection));
3883 if (opt_label == NULL)
3885 /* The anonymous one. */
3887 subseg->link = NULL;
3888 dws->anon_subseg = subseg;
3893 if (dws->list_subseg != NULL)
3894 subseg->subseg = dws->list_subseg->subseg + 1;
3898 subseg->link = dws->list_subseg;
3899 dws->list_subseg = subseg;
3900 symbol_get_tc (opt_label)->u.dw = subseg;
3903 ppc_change_debug_section (i, subseg->subseg);
3907 /* Add the length field. */
3908 expressionS *exp = &subseg->end_exp;
3911 if (opt_label != NULL)
3912 symbol_set_value_now (opt_label);
3914 /* Add the length field. Note that according to the AIX assembler
3915 manual, the size of the length field is 4 for powerpc32 but
3916 12 for powerpc64. */
3919 /* Write the 64bit marker. */
3920 md_number_to_chars (frag_more (4), -1, 4);
3923 exp->X_op = O_subtract;
3924 exp->X_op_symbol = symbol_temp_new_now ();
3925 exp->X_add_symbol = symbol_temp_make ();
3927 sz = ppc_obj64 ? 8 : 4;
3928 exp->X_add_number = -sz;
3929 emit_expr (exp, sz);
3934 /* This function handles the .text and .data pseudo-ops. These
3935 pseudo-ops aren't really used by XCOFF; we implement them for the
3936 convenience of people who aren't used to XCOFF. */
3939 ppc_section (int type)
3946 else if (type == 'd')
3951 sym = symbol_find_or_make (name);
3953 ppc_change_csect (sym, 2);
3955 demand_empty_rest_of_line ();
3958 /* This function handles the .section pseudo-op. This is mostly to
3959 give an error, since XCOFF only supports .text, .data and .bss, but
3960 we do permit the user to name the text or data section. */
3963 ppc_named_section (int ignore ATTRIBUTE_UNUSED)
3966 const char *real_name;
3970 user_name = input_line_pointer;
3971 c = get_symbol_end ();
3973 if (strcmp (user_name, ".text") == 0)
3974 real_name = ".text[PR]";
3975 else if (strcmp (user_name, ".data") == 0)
3976 real_name = ".data[RW]";
3979 as_bad (_("the XCOFF file format does not support arbitrary sections"));
3980 *input_line_pointer = c;
3981 ignore_rest_of_line ();
3985 *input_line_pointer = c;
3987 sym = symbol_find_or_make (real_name);
3989 ppc_change_csect (sym, 2);
3991 demand_empty_rest_of_line ();
3994 /* The .extern pseudo-op. We create an undefined symbol. */
3997 ppc_extern (int ignore ATTRIBUTE_UNUSED)
4002 name = input_line_pointer;
4003 endc = get_symbol_end ();
4005 (void) symbol_find_or_make (name);
4007 *input_line_pointer = endc;
4009 demand_empty_rest_of_line ();
4012 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
4015 ppc_lglobl (int ignore ATTRIBUTE_UNUSED)
4021 name = input_line_pointer;
4022 endc = get_symbol_end ();
4024 sym = symbol_find_or_make (name);
4026 *input_line_pointer = endc;
4028 symbol_get_tc (sym)->output = 1;
4030 demand_empty_rest_of_line ();
4033 /* The .ref pseudo-op. It takes a list of symbol names and inserts R_REF
4034 relocations at the beginning of the current csect.
4036 (In principle, there's no reason why the relocations _have_ to be at
4037 the beginning. Anywhere in the csect would do. However, inserting
4038 at the beginning is what the native assmebler does, and it helps to
4039 deal with cases where the .ref statements follow the section contents.)
4041 ??? .refs don't work for empty .csects. However, the native assembler
4042 doesn't report an error in this case, and neither yet do we. */
4045 ppc_ref (int ignore ATTRIBUTE_UNUSED)
4050 if (ppc_current_csect == NULL)
4052 as_bad (_(".ref outside .csect"));
4053 ignore_rest_of_line ();
4059 name = input_line_pointer;
4060 c = get_symbol_end ();
4062 fix_at_start (symbol_get_frag (ppc_current_csect), 0,
4063 symbol_find_or_make (name), 0, FALSE, BFD_RELOC_NONE);
4065 *input_line_pointer = c;
4067 c = *input_line_pointer;
4070 input_line_pointer++;
4072 if (is_end_of_line[(unsigned char) *input_line_pointer])
4074 as_bad (_("missing symbol name"));
4075 ignore_rest_of_line ();
4082 demand_empty_rest_of_line ();
4085 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
4086 although I don't know why it bothers. */
4089 ppc_rename (int ignore ATTRIBUTE_UNUSED)
4096 name = input_line_pointer;
4097 endc = get_symbol_end ();
4099 sym = symbol_find_or_make (name);
4101 *input_line_pointer = endc;
4103 if (*input_line_pointer != ',')
4105 as_bad (_("missing rename string"));
4106 ignore_rest_of_line ();
4109 ++input_line_pointer;
4111 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
4113 demand_empty_rest_of_line ();
4116 /* The .stabx pseudo-op. This is similar to a normal .stabs
4117 pseudo-op, but slightly different. A sample is
4118 .stabx "main:F-1",.main,142,0
4119 The first argument is the symbol name to create. The second is the
4120 value, and the third is the storage class. The fourth seems to be
4121 always zero, and I am assuming it is the type. */
4124 ppc_stabx (int ignore ATTRIBUTE_UNUSED)
4131 name = demand_copy_C_string (&len);
4133 if (*input_line_pointer != ',')
4135 as_bad (_("missing value"));
4138 ++input_line_pointer;
4140 ppc_stab_symbol = TRUE;
4141 sym = symbol_make (name);
4142 ppc_stab_symbol = FALSE;
4144 symbol_get_tc (sym)->real_name = name;
4146 (void) expression (&exp);
4153 as_bad (_("illegal .stabx expression; zero assumed"));
4154 exp.X_add_number = 0;
4157 S_SET_VALUE (sym, (valueT) exp.X_add_number);
4158 symbol_set_frag (sym, &zero_address_frag);
4162 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
4163 symbol_set_value_expression (sym, &exp);
4167 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
4168 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
4173 /* The value is some complex expression. This will probably
4174 fail at some later point, but this is probably the right
4175 thing to do here. */
4176 symbol_set_value_expression (sym, &exp);
4180 S_SET_SEGMENT (sym, ppc_coff_debug_section);
4181 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4183 if (*input_line_pointer != ',')
4185 as_bad (_("missing class"));
4188 ++input_line_pointer;
4190 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
4192 if (*input_line_pointer != ',')
4194 as_bad (_("missing type"));
4197 ++input_line_pointer;
4199 S_SET_DATA_TYPE (sym, get_absolute_expression ());
4201 symbol_get_tc (sym)->output = 1;
4203 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4208 .stabx "z",arrays_,133,0
4211 .comm arrays_,13768,3
4213 resolve_symbol_value will copy the exp's "within" into sym's when the
4214 offset is 0. Since this seems to be corner case problem,
4215 only do the correction for storage class C_STSYM. A better solution
4216 would be to have the tc field updated in ppc_symbol_new_hook. */
4218 if (exp.X_op == O_symbol)
4220 if (ppc_current_block == NULL)
4221 as_bad (_(".stabx of storage class stsym must be within .bs/.es"));
4223 symbol_get_tc (sym)->within = ppc_current_block;
4224 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
4228 if (exp.X_op != O_symbol
4229 || ! S_IS_EXTERNAL (exp.X_add_symbol)
4230 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
4231 ppc_frob_label (sym);
4234 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4235 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
4236 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
4237 symbol_get_tc (ppc_current_csect)->within = sym;
4240 demand_empty_rest_of_line ();
4243 /* The .function pseudo-op. This takes several arguments. The first
4244 argument seems to be the external name of the symbol. The second
4245 argument seems to be the label for the start of the function. gcc
4246 uses the same name for both. I have no idea what the third and
4247 fourth arguments are meant to be. The optional fifth argument is
4248 an expression for the size of the function. In COFF this symbol
4249 gets an aux entry like that used for a csect. */
4252 ppc_function (int ignore ATTRIBUTE_UNUSED)
4260 name = input_line_pointer;
4261 endc = get_symbol_end ();
4263 /* Ignore any [PR] suffix. */
4264 name = ppc_canonicalize_symbol_name (name);
4265 s = strchr (name, '[');
4266 if (s != (char *) NULL
4267 && strcmp (s + 1, "PR]") == 0)
4270 ext_sym = symbol_find_or_make (name);
4272 *input_line_pointer = endc;
4274 if (*input_line_pointer != ',')
4276 as_bad (_("missing symbol name"));
4277 ignore_rest_of_line ();
4280 ++input_line_pointer;
4282 name = input_line_pointer;
4283 endc = get_symbol_end ();
4285 lab_sym = symbol_find_or_make (name);
4287 *input_line_pointer = endc;
4289 if (ext_sym != lab_sym)
4293 exp.X_op = O_symbol;
4294 exp.X_add_symbol = lab_sym;
4295 exp.X_op_symbol = NULL;
4296 exp.X_add_number = 0;
4298 symbol_set_value_expression (ext_sym, &exp);
4301 if (symbol_get_tc (ext_sym)->symbol_class == -1)
4302 symbol_get_tc (ext_sym)->symbol_class = XMC_PR;
4303 symbol_get_tc (ext_sym)->output = 1;
4305 if (*input_line_pointer == ',')
4309 /* Ignore the third argument. */
4310 ++input_line_pointer;
4312 if (*input_line_pointer == ',')
4314 /* Ignore the fourth argument. */
4315 ++input_line_pointer;
4317 if (*input_line_pointer == ',')
4319 /* The fifth argument is the function size. */
4320 ++input_line_pointer;
4321 symbol_get_tc (ext_sym)->u.size = symbol_new
4322 ("L0\001", absolute_section,(valueT) 0, &zero_address_frag);
4323 pseudo_set (symbol_get_tc (ext_sym)->u.size);
4328 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4329 SF_SET_FUNCTION (ext_sym);
4330 SF_SET_PROCESS (ext_sym);
4331 coff_add_linesym (ext_sym);
4333 demand_empty_rest_of_line ();
4336 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
4337 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
4338 with the correct line number */
4340 static symbolS *saved_bi_sym = 0;
4343 ppc_bf (int ignore ATTRIBUTE_UNUSED)
4347 sym = symbol_make (".bf");
4348 S_SET_SEGMENT (sym, text_section);
4349 symbol_set_frag (sym, frag_now);
4350 S_SET_VALUE (sym, frag_now_fix ());
4351 S_SET_STORAGE_CLASS (sym, C_FCN);
4353 coff_line_base = get_absolute_expression ();
4355 S_SET_NUMBER_AUXILIARY (sym, 1);
4356 SA_SET_SYM_LNNO (sym, coff_line_base);
4358 /* Line number for bi. */
4361 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
4366 symbol_get_tc (sym)->output = 1;
4368 ppc_frob_label (sym);
4370 demand_empty_rest_of_line ();
4373 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
4374 ".ef", except that the line number is absolute, not relative to the
4375 most recent ".bf" symbol. */
4378 ppc_ef (int ignore ATTRIBUTE_UNUSED)
4382 sym = symbol_make (".ef");
4383 S_SET_SEGMENT (sym, text_section);
4384 symbol_set_frag (sym, frag_now);
4385 S_SET_VALUE (sym, frag_now_fix ());
4386 S_SET_STORAGE_CLASS (sym, C_FCN);
4387 S_SET_NUMBER_AUXILIARY (sym, 1);
4388 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4389 symbol_get_tc (sym)->output = 1;
4391 ppc_frob_label (sym);
4393 demand_empty_rest_of_line ();
4396 /* The .bi and .ei pseudo-ops. These take a string argument and
4397 generates a C_BINCL or C_EINCL symbol, which goes at the start of
4398 the symbol list. The value of .bi will be know when the next .bf
4404 static symbolS *last_biei;
4411 name = demand_copy_C_string (&len);
4413 /* The value of these symbols is actually file offset. Here we set
4414 the value to the index into the line number entries. In
4415 ppc_frob_symbols we set the fix_line field, which will cause BFD
4416 to do the right thing. */
4418 sym = symbol_make (name);
4419 /* obj-coff.c currently only handles line numbers correctly in the
4421 S_SET_SEGMENT (sym, text_section);
4422 S_SET_VALUE (sym, coff_n_line_nos);
4423 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4425 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
4426 symbol_get_tc (sym)->output = 1;
4434 for (look = last_biei ? last_biei : symbol_rootP;
4435 (look != (symbolS *) NULL
4436 && (S_GET_STORAGE_CLASS (look) == C_FILE
4437 || S_GET_STORAGE_CLASS (look) == C_BINCL
4438 || S_GET_STORAGE_CLASS (look) == C_EINCL));
4439 look = symbol_next (look))
4441 if (look != (symbolS *) NULL)
4443 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4444 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
4448 demand_empty_rest_of_line ();
4451 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
4452 There is one argument, which is a csect symbol. The value of the
4453 .bs symbol is the index of this csect symbol. */
4456 ppc_bs (int ignore ATTRIBUTE_UNUSED)
4463 if (ppc_current_block != NULL)
4464 as_bad (_("nested .bs blocks"));
4466 name = input_line_pointer;
4467 endc = get_symbol_end ();
4469 csect = symbol_find_or_make (name);
4471 *input_line_pointer = endc;
4473 sym = symbol_make (".bs");
4474 S_SET_SEGMENT (sym, now_seg);
4475 S_SET_STORAGE_CLASS (sym, C_BSTAT);
4476 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4477 symbol_get_tc (sym)->output = 1;
4479 symbol_get_tc (sym)->within = csect;
4481 ppc_frob_label (sym);
4483 ppc_current_block = sym;
4485 demand_empty_rest_of_line ();
4488 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
4491 ppc_es (int ignore ATTRIBUTE_UNUSED)
4495 if (ppc_current_block == NULL)
4496 as_bad (_(".es without preceding .bs"));
4498 sym = symbol_make (".es");
4499 S_SET_SEGMENT (sym, now_seg);
4500 S_SET_STORAGE_CLASS (sym, C_ESTAT);
4501 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4502 symbol_get_tc (sym)->output = 1;
4504 ppc_frob_label (sym);
4506 ppc_current_block = NULL;
4508 demand_empty_rest_of_line ();
4511 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
4515 ppc_bb (int ignore ATTRIBUTE_UNUSED)
4519 sym = symbol_make (".bb");
4520 S_SET_SEGMENT (sym, text_section);
4521 symbol_set_frag (sym, frag_now);
4522 S_SET_VALUE (sym, frag_now_fix ());
4523 S_SET_STORAGE_CLASS (sym, C_BLOCK);
4525 S_SET_NUMBER_AUXILIARY (sym, 1);
4526 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4528 symbol_get_tc (sym)->output = 1;
4530 SF_SET_PROCESS (sym);
4532 ppc_frob_label (sym);
4534 demand_empty_rest_of_line ();
4537 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
4541 ppc_eb (int ignore ATTRIBUTE_UNUSED)
4545 sym = symbol_make (".eb");
4546 S_SET_SEGMENT (sym, text_section);
4547 symbol_set_frag (sym, frag_now);
4548 S_SET_VALUE (sym, frag_now_fix ());
4549 S_SET_STORAGE_CLASS (sym, C_BLOCK);
4550 S_SET_NUMBER_AUXILIARY (sym, 1);
4551 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4552 symbol_get_tc (sym)->output = 1;
4554 SF_SET_PROCESS (sym);
4556 ppc_frob_label (sym);
4558 demand_empty_rest_of_line ();
4561 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
4565 ppc_bc (int ignore ATTRIBUTE_UNUSED)
4571 name = demand_copy_C_string (&len);
4572 sym = symbol_make (name);
4573 S_SET_SEGMENT (sym, ppc_coff_debug_section);
4574 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4575 S_SET_STORAGE_CLASS (sym, C_BCOMM);
4576 S_SET_VALUE (sym, 0);
4577 symbol_get_tc (sym)->output = 1;
4579 ppc_frob_label (sym);
4581 demand_empty_rest_of_line ();
4584 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
4587 ppc_ec (int ignore ATTRIBUTE_UNUSED)
4591 sym = symbol_make (".ec");
4592 S_SET_SEGMENT (sym, ppc_coff_debug_section);
4593 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4594 S_SET_STORAGE_CLASS (sym, C_ECOMM);
4595 S_SET_VALUE (sym, 0);
4596 symbol_get_tc (sym)->output = 1;
4598 ppc_frob_label (sym);
4600 demand_empty_rest_of_line ();
4603 /* The .toc pseudo-op. Switch to the .toc subsegment. */
4606 ppc_toc (int ignore ATTRIBUTE_UNUSED)
4608 if (ppc_toc_csect != (symbolS *) NULL)
4609 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
4616 subseg = ppc_data_subsegment;
4617 ++ppc_data_subsegment;
4619 subseg_new (segment_name (data_section), subseg);
4620 ppc_toc_frag = frag_now;
4622 sym = symbol_find_or_make ("TOC[TC0]");
4623 symbol_set_frag (sym, frag_now);
4624 S_SET_SEGMENT (sym, data_section);
4625 S_SET_VALUE (sym, (valueT) frag_now_fix ());
4626 symbol_get_tc (sym)->subseg = subseg;
4627 symbol_get_tc (sym)->output = 1;
4628 symbol_get_tc (sym)->within = sym;
4630 ppc_toc_csect = sym;
4632 for (list = ppc_data_csects;
4633 symbol_get_tc (list)->next != (symbolS *) NULL;
4634 list = symbol_get_tc (list)->next)
4636 symbol_get_tc (list)->next = sym;
4638 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4639 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
4643 ppc_current_csect = ppc_toc_csect;
4645 demand_empty_rest_of_line ();
4648 /* The AIX assembler automatically aligns the operands of a .long or
4649 .short pseudo-op, and we want to be compatible. */
4652 ppc_xcoff_cons (int log_size)
4654 frag_align (log_size, 0, 0);
4655 record_alignment (now_seg, log_size);
4656 cons (1 << log_size);
4660 ppc_vbyte (int dummy ATTRIBUTE_UNUSED)
4665 (void) expression (&exp);
4667 if (exp.X_op != O_constant)
4669 as_bad (_("non-constant byte count"));
4673 byte_count = exp.X_add_number;
4675 if (*input_line_pointer != ',')
4677 as_bad (_("missing value"));
4681 ++input_line_pointer;
4686 ppc_xcoff_end (void)
4690 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
4692 struct dw_section *dws = &dw_sections[i];
4693 struct dw_subsection *dwss;
4695 if (dws->anon_subseg)
4697 dwss = dws->anon_subseg;
4698 dwss->link = dws->list_subseg;
4701 dwss = dws->list_subseg;
4703 for (; dwss != NULL; dwss = dwss->link)
4704 if (dwss->end_exp.X_add_symbol != NULL)
4706 subseg_set (dws->sect, dwss->subseg);
4707 symbol_set_value_now (dwss->end_exp.X_add_symbol);
4712 #endif /* OBJ_XCOFF */
4713 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
4715 /* The .tc pseudo-op. This is used when generating either XCOFF or
4716 ELF. This takes two or more arguments.
4718 When generating XCOFF output, the first argument is the name to
4719 give to this location in the toc; this will be a symbol with class
4720 TC. The rest of the arguments are N-byte values to actually put at
4721 this location in the TOC; often there is just one more argument, a
4722 relocatable symbol reference. The size of the value to store
4723 depends on target word size. A 32-bit target uses 4-byte values, a
4724 64-bit target uses 8-byte values.
4726 When not generating XCOFF output, the arguments are the same, but
4727 the first argument is simply ignored. */
4730 ppc_tc (int ignore ATTRIBUTE_UNUSED)
4734 /* Define the TOC symbol name. */
4740 if (ppc_toc_csect == (symbolS *) NULL
4741 || ppc_toc_csect != ppc_current_csect)
4743 as_bad (_(".tc not in .toc section"));
4744 ignore_rest_of_line ();
4748 name = input_line_pointer;
4749 endc = get_symbol_end ();
4751 sym = symbol_find_or_make (name);
4753 *input_line_pointer = endc;
4755 if (S_IS_DEFINED (sym))
4759 label = symbol_get_tc (ppc_current_csect)->within;
4760 if (symbol_get_tc (label)->symbol_class != XMC_TC0)
4762 as_bad (_(".tc with no label"));
4763 ignore_rest_of_line ();
4767 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
4768 symbol_set_frag (label, symbol_get_frag (sym));
4769 S_SET_VALUE (label, S_GET_VALUE (sym));
4771 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4772 ++input_line_pointer;
4777 S_SET_SEGMENT (sym, now_seg);
4778 symbol_set_frag (sym, frag_now);
4779 S_SET_VALUE (sym, (valueT) frag_now_fix ());
4780 symbol_get_tc (sym)->symbol_class = XMC_TC;
4781 symbol_get_tc (sym)->output = 1;
4783 ppc_frob_label (sym);
4786 #endif /* OBJ_XCOFF */
4790 /* Skip the TOC symbol name. */
4791 while (is_part_of_name (*input_line_pointer)
4792 || *input_line_pointer == ' '
4793 || *input_line_pointer == '['
4794 || *input_line_pointer == ']'
4795 || *input_line_pointer == '{'
4796 || *input_line_pointer == '}')
4797 ++input_line_pointer;
4799 /* Align to a four/eight byte boundary. */
4800 align = ppc_obj64 ? 3 : 2;
4801 frag_align (align, 0, 0);
4802 record_alignment (now_seg, align);
4803 #endif /* OBJ_ELF */
4805 if (*input_line_pointer != ',')
4806 demand_empty_rest_of_line ();
4809 ++input_line_pointer;
4810 cons (ppc_obj64 ? 8 : 4);
4814 /* Pseudo-op .machine. */
4817 ppc_machine (int ignore ATTRIBUTE_UNUSED)
4820 #define MAX_HISTORY 100
4821 static ppc_cpu_t *cpu_history;
4822 static int curr_hist;
4826 if (*input_line_pointer == '"')
4829 cpu_string = demand_copy_C_string (&len);
4834 cpu_string = input_line_pointer;
4835 c = get_symbol_end ();
4836 cpu_string = xstrdup (cpu_string);
4837 *input_line_pointer = c;
4840 if (cpu_string != NULL)
4842 ppc_cpu_t old_cpu = ppc_cpu;
4846 for (p = cpu_string; *p != 0; p++)
4849 if (strcmp (cpu_string, "push") == 0)
4851 if (cpu_history == NULL)
4852 cpu_history = xmalloc (MAX_HISTORY * sizeof (*cpu_history));
4854 if (curr_hist >= MAX_HISTORY)
4855 as_bad (_(".machine stack overflow"));
4857 cpu_history[curr_hist++] = ppc_cpu;
4859 else if (strcmp (cpu_string, "pop") == 0)
4862 as_bad (_(".machine stack underflow"));
4864 ppc_cpu = cpu_history[--curr_hist];
4866 else if ((new_cpu = ppc_parse_cpu (ppc_cpu, cpu_string)) != 0)
4869 as_bad (_("invalid machine `%s'"), cpu_string);
4871 if (ppc_cpu != old_cpu)
4872 ppc_setup_opcodes ();
4875 demand_empty_rest_of_line ();
4877 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4881 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4883 /* Set the current section. */
4885 ppc_set_current_section (segT new)
4887 ppc_previous_section = ppc_current_section;
4888 ppc_current_section = new;
4891 /* pseudo-op: .previous
4892 behaviour: toggles the current section with the previous section.
4894 warnings: "No previous section" */
4897 ppc_previous (int ignore ATTRIBUTE_UNUSED)
4899 if (ppc_previous_section == NULL)
4901 as_warn (_("no previous section to return to, ignored."));
4905 subseg_set (ppc_previous_section, 0);
4907 ppc_set_current_section (ppc_previous_section);
4910 /* pseudo-op: .pdata
4911 behaviour: predefined read only data section
4915 initial: .section .pdata "adr3"
4916 a - don't know -- maybe a misprint
4917 d - initialized data
4919 3 - double word aligned (that would be 4 byte boundary)
4922 Tag index tables (also known as the function table) for exception
4923 handling, debugging, etc. */
4926 ppc_pdata (int ignore ATTRIBUTE_UNUSED)
4928 if (pdata_section == 0)
4930 pdata_section = subseg_new (".pdata", 0);
4932 bfd_set_section_flags (stdoutput, pdata_section,
4933 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4934 | SEC_READONLY | SEC_DATA ));
4936 bfd_set_section_alignment (stdoutput, pdata_section, 2);
4940 pdata_section = subseg_new (".pdata", 0);
4942 ppc_set_current_section (pdata_section);
4945 /* pseudo-op: .ydata
4946 behaviour: predefined read only data section
4950 initial: .section .ydata "drw3"
4951 a - don't know -- maybe a misprint
4952 d - initialized data
4954 3 - double word aligned (that would be 4 byte boundary)
4956 Tag tables (also known as the scope table) for exception handling,
4960 ppc_ydata (int ignore ATTRIBUTE_UNUSED)
4962 if (ydata_section == 0)
4964 ydata_section = subseg_new (".ydata", 0);
4965 bfd_set_section_flags (stdoutput, ydata_section,
4966 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4967 | SEC_READONLY | SEC_DATA ));
4969 bfd_set_section_alignment (stdoutput, ydata_section, 3);
4973 ydata_section = subseg_new (".ydata", 0);
4975 ppc_set_current_section (ydata_section);
4978 /* pseudo-op: .reldata
4979 behaviour: predefined read write data section
4980 double word aligned (4-byte)
4981 FIXME: relocation is applied to it
4982 FIXME: what's the difference between this and .data?
4985 initial: .section .reldata "drw3"
4986 d - initialized data
4989 3 - double word aligned (that would be 8 byte boundary)
4992 Like .data, but intended to hold data subject to relocation, such as
4993 function descriptors, etc. */
4996 ppc_reldata (int ignore ATTRIBUTE_UNUSED)
4998 if (reldata_section == 0)
5000 reldata_section = subseg_new (".reldata", 0);
5002 bfd_set_section_flags (stdoutput, reldata_section,
5003 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
5006 bfd_set_section_alignment (stdoutput, reldata_section, 2);
5010 reldata_section = subseg_new (".reldata", 0);
5012 ppc_set_current_section (reldata_section);
5015 /* pseudo-op: .rdata
5016 behaviour: predefined read only data section
5020 initial: .section .rdata "dr3"
5021 d - initialized data
5023 3 - double word aligned (that would be 4 byte boundary) */
5026 ppc_rdata (int ignore ATTRIBUTE_UNUSED)
5028 if (rdata_section == 0)
5030 rdata_section = subseg_new (".rdata", 0);
5031 bfd_set_section_flags (stdoutput, rdata_section,
5032 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
5033 | SEC_READONLY | SEC_DATA ));
5035 bfd_set_section_alignment (stdoutput, rdata_section, 2);
5039 rdata_section = subseg_new (".rdata", 0);
5041 ppc_set_current_section (rdata_section);
5044 /* pseudo-op: .ualong
5045 behaviour: much like .int, with the exception that no alignment is
5047 FIXME: test the alignment statement
5052 ppc_ualong (int ignore ATTRIBUTE_UNUSED)
5058 /* pseudo-op: .znop <symbol name>
5059 behaviour: Issue a nop instruction
5060 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
5061 the supplied symbol name.
5063 warnings: Missing symbol name */
5066 ppc_znop (int ignore ATTRIBUTE_UNUSED)
5069 const struct powerpc_opcode *opcode;
5076 /* Strip out the symbol name. */
5077 symbol_name = input_line_pointer;
5078 c = get_symbol_end ();
5080 name = xmalloc (input_line_pointer - symbol_name + 1);
5081 strcpy (name, symbol_name);
5083 sym = symbol_find_or_make (name);
5085 *input_line_pointer = c;
5089 /* Look up the opcode in the hash table. */
5090 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
5092 /* Stick in the nop. */
5093 insn = opcode->opcode;
5095 /* Write out the instruction. */
5097 md_number_to_chars (f, insn, 4);
5099 f - frag_now->fr_literal,
5104 BFD_RELOC_16_GOT_PCREL);
5114 ppc_pe_comm (int lcomm)
5123 name = input_line_pointer;
5124 c = get_symbol_end ();
5126 /* just after name is now '\0'. */
5127 p = input_line_pointer;
5130 if (*input_line_pointer != ',')
5132 as_bad (_("expected comma after symbol-name: rest of line ignored."));
5133 ignore_rest_of_line ();
5137 input_line_pointer++; /* skip ',' */
5138 if ((temp = get_absolute_expression ()) < 0)
5140 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
5141 ignore_rest_of_line ();
5147 /* The third argument to .comm is the alignment. */
5148 if (*input_line_pointer != ',')
5152 ++input_line_pointer;
5153 align = get_absolute_expression ();
5156 as_warn (_("ignoring bad alignment"));
5163 symbolP = symbol_find_or_make (name);
5166 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
5168 as_bad (_("ignoring attempt to re-define symbol `%s'."),
5169 S_GET_NAME (symbolP));
5170 ignore_rest_of_line ();
5174 if (S_GET_VALUE (symbolP))
5176 if (S_GET_VALUE (symbolP) != (valueT) temp)
5177 as_bad (_("length of .comm \"%s\" is already %ld. Not changed to %ld."),
5178 S_GET_NAME (symbolP),
5179 (long) S_GET_VALUE (symbolP),
5184 S_SET_VALUE (symbolP, (valueT) temp);
5185 S_SET_EXTERNAL (symbolP);
5186 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
5189 demand_empty_rest_of_line ();
5193 * implement the .section pseudo op:
5194 * .section name {, "flags"}
5196 * | +--- optional flags: 'b' for bss
5198 * +-- section name 'l' for lib
5202 * 'd' (apparently m88k for data)
5204 * But if the argument is not a quoted string, treat it as a
5205 * subsegment number.
5207 * FIXME: this is a copy of the section processing from obj-coff.c, with
5208 * additions/changes for the moto-pas assembler support. There are three
5211 * FIXME: I just noticed this. This doesn't work at all really. It it
5212 * setting bits that bfd probably neither understands or uses. The
5213 * correct approach (?) will have to incorporate extra fields attached
5214 * to the section to hold the system specific stuff. (krk)
5217 * 'a' - unknown - referred to in documentation, but no definition supplied
5218 * 'c' - section has code
5219 * 'd' - section has initialized data
5220 * 'u' - section has uninitialized data
5221 * 'i' - section contains directives (info)
5222 * 'n' - section can be discarded
5223 * 'R' - remove section at link time
5225 * Section Protection:
5226 * 'r' - section is readable
5227 * 'w' - section is writeable
5228 * 'x' - section is executable
5229 * 's' - section is sharable
5231 * Section Alignment:
5232 * '0' - align to byte boundary
5233 * '1' - align to halfword undary
5234 * '2' - align to word boundary
5235 * '3' - align to doubleword boundary
5236 * '4' - align to quadword boundary
5237 * '5' - align to 32 byte boundary
5238 * '6' - align to 64 byte boundary
5243 ppc_pe_section (int ignore ATTRIBUTE_UNUSED)
5245 /* Strip out the section name. */
5254 section_name = input_line_pointer;
5255 c = get_symbol_end ();
5257 name = xmalloc (input_line_pointer - section_name + 1);
5258 strcpy (name, section_name);
5260 *input_line_pointer = c;
5265 flags = SEC_NO_FLAGS;
5267 if (strcmp (name, ".idata$2") == 0)
5271 else if (strcmp (name, ".idata$3") == 0)
5275 else if (strcmp (name, ".idata$4") == 0)
5279 else if (strcmp (name, ".idata$5") == 0)
5283 else if (strcmp (name, ".idata$6") == 0)
5288 /* Default alignment to 16 byte boundary. */
5291 if (*input_line_pointer == ',')
5293 ++input_line_pointer;
5295 if (*input_line_pointer != '"')
5296 exp = get_absolute_expression ();
5299 ++input_line_pointer;
5300 while (*input_line_pointer != '"'
5301 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5303 switch (*input_line_pointer)
5305 /* Section Contents */
5306 case 'a': /* unknown */
5307 as_bad (_("unsupported section attribute -- 'a'"));
5309 case 'c': /* code section */
5312 case 'd': /* section has initialized data */
5315 case 'u': /* section has uninitialized data */
5316 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
5320 case 'i': /* section contains directives (info) */
5321 /* FIXME: This is IMAGE_SCN_LNK_INFO
5323 flags |= SEC_HAS_CONTENTS;
5325 case 'n': /* section can be discarded */
5328 case 'R': /* Remove section at link time */
5329 flags |= SEC_NEVER_LOAD;
5331 #if IFLICT_BRAIN_DAMAGE
5332 /* Section Protection */
5333 case 'r': /* section is readable */
5334 flags |= IMAGE_SCN_MEM_READ;
5336 case 'w': /* section is writeable */
5337 flags |= IMAGE_SCN_MEM_WRITE;
5339 case 'x': /* section is executable */
5340 flags |= IMAGE_SCN_MEM_EXECUTE;
5342 case 's': /* section is sharable */
5343 flags |= IMAGE_SCN_MEM_SHARED;
5346 /* Section Alignment */
5347 case '0': /* align to byte boundary */
5348 flags |= IMAGE_SCN_ALIGN_1BYTES;
5351 case '1': /* align to halfword boundary */
5352 flags |= IMAGE_SCN_ALIGN_2BYTES;
5355 case '2': /* align to word boundary */
5356 flags |= IMAGE_SCN_ALIGN_4BYTES;
5359 case '3': /* align to doubleword boundary */
5360 flags |= IMAGE_SCN_ALIGN_8BYTES;
5363 case '4': /* align to quadword boundary */
5364 flags |= IMAGE_SCN_ALIGN_16BYTES;
5367 case '5': /* align to 32 byte boundary */
5368 flags |= IMAGE_SCN_ALIGN_32BYTES;
5371 case '6': /* align to 64 byte boundary */
5372 flags |= IMAGE_SCN_ALIGN_64BYTES;
5377 as_bad (_("unknown section attribute '%c'"),
5378 *input_line_pointer);
5381 ++input_line_pointer;
5383 if (*input_line_pointer == '"')
5384 ++input_line_pointer;
5388 sec = subseg_new (name, (subsegT) exp);
5390 ppc_set_current_section (sec);
5392 if (flags != SEC_NO_FLAGS)
5394 if (! bfd_set_section_flags (stdoutput, sec, flags))
5395 as_bad (_("error setting flags for \"%s\": %s"),
5396 bfd_section_name (stdoutput, sec),
5397 bfd_errmsg (bfd_get_error ()));
5400 bfd_set_section_alignment (stdoutput, sec, align);
5404 ppc_pe_function (int ignore ATTRIBUTE_UNUSED)
5410 name = input_line_pointer;
5411 endc = get_symbol_end ();
5413 ext_sym = symbol_find_or_make (name);
5415 *input_line_pointer = endc;
5417 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
5418 SF_SET_FUNCTION (ext_sym);
5419 SF_SET_PROCESS (ext_sym);
5420 coff_add_linesym (ext_sym);
5422 demand_empty_rest_of_line ();
5426 ppc_pe_tocd (int ignore ATTRIBUTE_UNUSED)
5428 if (tocdata_section == 0)
5430 tocdata_section = subseg_new (".tocd", 0);
5431 /* FIXME: section flags won't work. */
5432 bfd_set_section_flags (stdoutput, tocdata_section,
5433 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
5434 | SEC_READONLY | SEC_DATA));
5436 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
5440 rdata_section = subseg_new (".tocd", 0);
5443 ppc_set_current_section (tocdata_section);
5445 demand_empty_rest_of_line ();
5448 /* Don't adjust TOC relocs to use the section symbol. */
5451 ppc_pe_fix_adjustable (fixS *fix)
5453 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
5460 /* XCOFF specific symbol and file handling. */
5462 /* Canonicalize the symbol name. We use the to force the suffix, if
5463 any, to use square brackets, and to be in upper case. */
5466 ppc_canonicalize_symbol_name (char *name)
5470 if (ppc_stab_symbol)
5473 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
5487 for (s++; *s != '\0' && *s != brac; s++)
5490 if (*s == '\0' || s[1] != '\0')
5491 as_bad (_("bad symbol suffix"));
5499 /* Set the class of a symbol based on the suffix, if any. This is
5500 called whenever a new symbol is created. */
5503 ppc_symbol_new_hook (symbolS *sym)
5505 struct ppc_tc_sy *tc;
5508 tc = symbol_get_tc (sym);
5511 tc->symbol_class = -1;
5512 tc->real_name = NULL;
5519 if (ppc_stab_symbol)
5522 s = strchr (S_GET_NAME (sym), '[');
5523 if (s == (const char *) NULL)
5525 /* There is no suffix. */
5534 if (strcmp (s, "BS]") == 0)
5535 tc->symbol_class = XMC_BS;
5538 if (strcmp (s, "DB]") == 0)
5539 tc->symbol_class = XMC_DB;
5540 else if (strcmp (s, "DS]") == 0)
5541 tc->symbol_class = XMC_DS;
5544 if (strcmp (s, "GL]") == 0)
5545 tc->symbol_class = XMC_GL;
5548 if (strcmp (s, "PR]") == 0)
5549 tc->symbol_class = XMC_PR;
5552 if (strcmp (s, "RO]") == 0)
5553 tc->symbol_class = XMC_RO;
5554 else if (strcmp (s, "RW]") == 0)
5555 tc->symbol_class = XMC_RW;
5558 if (strcmp (s, "SV]") == 0)
5559 tc->symbol_class = XMC_SV;
5562 if (strcmp (s, "TC]") == 0)
5563 tc->symbol_class = XMC_TC;
5564 else if (strcmp (s, "TI]") == 0)
5565 tc->symbol_class = XMC_TI;
5566 else if (strcmp (s, "TB]") == 0)
5567 tc->symbol_class = XMC_TB;
5568 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
5569 tc->symbol_class = XMC_TC0;
5572 if (strcmp (s, "UA]") == 0)
5573 tc->symbol_class = XMC_UA;
5574 else if (strcmp (s, "UC]") == 0)
5575 tc->symbol_class = XMC_UC;
5578 if (strcmp (s, "XO]") == 0)
5579 tc->symbol_class = XMC_XO;
5583 if (tc->symbol_class == -1)
5584 as_bad (_("unrecognized symbol suffix"));
5587 /* Set the class of a label based on where it is defined. This
5588 handles symbols without suffixes. Also, move the symbol so that it
5589 follows the csect symbol. */
5592 ppc_frob_label (symbolS *sym)
5594 if (ppc_current_csect != (symbolS *) NULL)
5596 if (symbol_get_tc (sym)->symbol_class == -1)
5597 symbol_get_tc (sym)->symbol_class = symbol_get_tc (ppc_current_csect)->symbol_class;
5599 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5600 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
5601 &symbol_rootP, &symbol_lastP);
5602 symbol_get_tc (ppc_current_csect)->within = sym;
5603 symbol_get_tc (sym)->within = ppc_current_csect;
5607 dwarf2_emit_label (sym);
5611 /* This variable is set by ppc_frob_symbol if any absolute symbols are
5612 seen. It tells ppc_adjust_symtab whether it needs to look through
5615 static bfd_boolean ppc_saw_abs;
5617 /* Change the name of a symbol just before writing it out. Set the
5618 real name if the .rename pseudo-op was used. Otherwise, remove any
5619 class suffix. Return 1 if the symbol should not be included in the
5623 ppc_frob_symbol (symbolS *sym)
5625 static symbolS *ppc_last_function;
5626 static symbolS *set_end;
5628 /* Discard symbols that should not be included in the output symbol
5630 if (! symbol_used_in_reloc_p (sym)
5631 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
5632 || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5633 && ! symbol_get_tc (sym)->output
5634 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
5637 /* This one will disappear anyway. Don't make a csect sym for it. */
5638 if (sym == abs_section_sym)
5641 if (symbol_get_tc (sym)->real_name != (char *) NULL)
5642 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
5648 name = S_GET_NAME (sym);
5649 s = strchr (name, '[');
5650 if (s != (char *) NULL)
5656 snew = xmalloc (len + 1);
5657 memcpy (snew, name, len);
5660 S_SET_NAME (sym, snew);
5664 if (set_end != (symbolS *) NULL)
5666 SA_SET_SYM_ENDNDX (set_end, sym);
5670 if (SF_GET_FUNCTION (sym))
5672 if (ppc_last_function != (symbolS *) NULL)
5673 as_bad (_("two .function pseudo-ops with no intervening .ef"));
5674 ppc_last_function = sym;
5675 if (symbol_get_tc (sym)->u.size != (symbolS *) NULL)
5677 resolve_symbol_value (symbol_get_tc (sym)->u.size);
5678 SA_SET_SYM_FSIZE (sym,
5679 (long) S_GET_VALUE (symbol_get_tc (sym)->u.size));
5682 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
5683 && strcmp (S_GET_NAME (sym), ".ef") == 0)
5685 if (ppc_last_function == (symbolS *) NULL)
5686 as_bad (_(".ef with no preceding .function"));
5689 set_end = ppc_last_function;
5690 ppc_last_function = NULL;
5692 /* We don't have a C_EFCN symbol, but we need to force the
5693 COFF backend to believe that it has seen one. */
5694 coff_last_function = NULL;
5698 if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5699 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
5700 && S_GET_STORAGE_CLASS (sym) != C_FILE
5701 && S_GET_STORAGE_CLASS (sym) != C_FCN
5702 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
5703 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
5704 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
5705 && S_GET_STORAGE_CLASS (sym) != C_BINCL
5706 && S_GET_STORAGE_CLASS (sym) != C_EINCL
5707 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
5708 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
5710 if (S_GET_STORAGE_CLASS (sym) == C_EXT
5711 || S_GET_STORAGE_CLASS (sym) == C_AIX_WEAKEXT
5712 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
5715 union internal_auxent *a;
5717 /* Create a csect aux. */
5718 i = S_GET_NUMBER_AUXILIARY (sym);
5719 S_SET_NUMBER_AUXILIARY (sym, i + 1);
5720 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
5721 if (symbol_get_tc (sym)->symbol_class == XMC_TC0)
5723 /* This is the TOC table. */
5724 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
5725 a->x_csect.x_scnlen.l = 0;
5726 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5728 else if (symbol_get_tc (sym)->subseg != 0)
5730 /* This is a csect symbol. x_scnlen is the size of the
5732 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
5733 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5734 S_GET_SEGMENT (sym))
5735 - S_GET_VALUE (sym));
5738 resolve_symbol_value (symbol_get_tc (sym)->next);
5739 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
5740 - S_GET_VALUE (sym));
5742 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
5744 else if (S_GET_SEGMENT (sym) == bss_section)
5746 /* This is a common symbol. */
5747 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
5748 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
5749 if (S_IS_EXTERNAL (sym))
5750 symbol_get_tc (sym)->symbol_class = XMC_RW;
5752 symbol_get_tc (sym)->symbol_class = XMC_BS;
5754 else if (S_GET_SEGMENT (sym) == absolute_section)
5756 /* This is an absolute symbol. The csect will be created by
5757 ppc_adjust_symtab. */
5759 a->x_csect.x_smtyp = XTY_LD;
5760 if (symbol_get_tc (sym)->symbol_class == -1)
5761 symbol_get_tc (sym)->symbol_class = XMC_XO;
5763 else if (! S_IS_DEFINED (sym))
5765 /* This is an external symbol. */
5766 a->x_csect.x_scnlen.l = 0;
5767 a->x_csect.x_smtyp = XTY_ER;
5769 else if (symbol_get_tc (sym)->symbol_class == XMC_TC)
5773 /* This is a TOC definition. x_scnlen is the size of the
5775 next = symbol_next (sym);
5776 while (symbol_get_tc (next)->symbol_class == XMC_TC0)
5777 next = symbol_next (next);
5778 if (next == (symbolS *) NULL
5779 || symbol_get_tc (next)->symbol_class != XMC_TC)
5781 if (ppc_after_toc_frag == (fragS *) NULL)
5782 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5784 - S_GET_VALUE (sym));
5786 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
5787 - S_GET_VALUE (sym));
5791 resolve_symbol_value (next);
5792 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
5793 - S_GET_VALUE (sym));
5795 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5801 /* This is a normal symbol definition. x_scnlen is the
5802 symbol index of the containing csect. */
5803 if (S_GET_SEGMENT (sym) == text_section)
5804 csect = ppc_text_csects;
5805 else if (S_GET_SEGMENT (sym) == data_section)
5806 csect = ppc_data_csects;
5810 /* Skip the initial dummy symbol. */
5811 csect = symbol_get_tc (csect)->next;
5813 if (csect == (symbolS *) NULL)
5815 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
5816 a->x_csect.x_scnlen.l = 0;
5820 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
5822 resolve_symbol_value (symbol_get_tc (csect)->next);
5823 if (S_GET_VALUE (symbol_get_tc (csect)->next)
5824 > S_GET_VALUE (sym))
5826 csect = symbol_get_tc (csect)->next;
5829 a->x_csect.x_scnlen.p =
5830 coffsymbol (symbol_get_bfdsym (csect))->native;
5831 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
5834 a->x_csect.x_smtyp = XTY_LD;
5837 a->x_csect.x_parmhash = 0;
5838 a->x_csect.x_snhash = 0;
5839 if (symbol_get_tc (sym)->symbol_class == -1)
5840 a->x_csect.x_smclas = XMC_PR;
5842 a->x_csect.x_smclas = symbol_get_tc (sym)->symbol_class;
5843 a->x_csect.x_stab = 0;
5844 a->x_csect.x_snstab = 0;
5846 /* Don't let the COFF backend resort these symbols. */
5847 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
5849 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
5851 /* We want the value to be the symbol index of the referenced
5852 csect symbol. BFD will do that for us if we set the right
5854 asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
5855 combined_entry_type *c = coffsymbol (bsym)->native;
5857 S_SET_VALUE (sym, (valueT) (size_t) c);
5858 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
5860 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5865 block = symbol_get_tc (sym)->within;
5868 /* The value is the offset from the enclosing csect. */
5871 csect = symbol_get_tc (block)->within;
5872 resolve_symbol_value (csect);
5873 base = S_GET_VALUE (csect);
5878 S_SET_VALUE (sym, S_GET_VALUE (sym) - base);
5880 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
5881 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
5883 /* We want the value to be a file offset into the line numbers.
5884 BFD will do that for us if we set the right flags. We have
5885 already set the value correctly. */
5886 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
5892 /* Adjust the symbol table. This creates csect symbols for all
5893 absolute symbols. */
5896 ppc_adjust_symtab (void)
5903 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
5907 union internal_auxent *a;
5909 if (S_GET_SEGMENT (sym) != absolute_section)
5912 csect = symbol_create (".abs[XO]", absolute_section,
5913 S_GET_VALUE (sym), &zero_address_frag);
5914 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
5915 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
5916 i = S_GET_NUMBER_AUXILIARY (csect);
5917 S_SET_NUMBER_AUXILIARY (csect, i + 1);
5918 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
5919 a->x_csect.x_scnlen.l = 0;
5920 a->x_csect.x_smtyp = XTY_SD;
5921 a->x_csect.x_parmhash = 0;
5922 a->x_csect.x_snhash = 0;
5923 a->x_csect.x_smclas = XMC_XO;
5924 a->x_csect.x_stab = 0;
5925 a->x_csect.x_snstab = 0;
5927 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
5929 i = S_GET_NUMBER_AUXILIARY (sym);
5930 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
5931 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
5932 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
5935 ppc_saw_abs = FALSE;
5938 /* Set the VMA for a section. This is called on all the sections in
5942 ppc_frob_section (asection *sec)
5944 static bfd_vma vma = 0;
5946 /* Dwarf sections start at 0. */
5947 if (bfd_get_section_flags (NULL, sec) & SEC_DEBUGGING)
5950 vma = md_section_align (sec, vma);
5951 bfd_set_section_vma (stdoutput, sec, vma);
5952 vma += bfd_section_size (stdoutput, sec);
5955 #endif /* OBJ_XCOFF */
5958 md_atof (int type, char *litp, int *sizep)
5960 return ieee_md_atof (type, litp, sizep, target_big_endian);
5963 /* Write a value out to the object file, using the appropriate
5967 md_number_to_chars (char *buf, valueT val, int n)
5969 if (target_big_endian)
5970 number_to_chars_bigendian (buf, val, n);
5972 number_to_chars_littleendian (buf, val, n);
5975 /* Align a section (I don't know why this is machine dependent). */
5978 md_section_align (asection *seg ATTRIBUTE_UNUSED, valueT addr)
5983 int align = bfd_get_section_alignment (stdoutput, seg);
5985 return ((addr + (1 << align) - 1) & (-1 << align));
5989 /* We don't have any form of relaxing. */
5992 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
5993 asection *seg ATTRIBUTE_UNUSED)
5999 /* Convert a machine dependent frag. We never generate these. */
6002 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
6003 asection *sec ATTRIBUTE_UNUSED,
6004 fragS *fragp ATTRIBUTE_UNUSED)
6009 /* We have no need to default values of symbols. */
6012 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
6017 /* Functions concerning relocs. */
6019 /* The location from which a PC relative jump should be calculated,
6020 given a PC relative reloc. */
6023 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
6025 return fixp->fx_frag->fr_address + fixp->fx_where;
6030 /* This is called to see whether a fixup should be adjusted to use a
6031 section symbol. We take the opportunity to change a fixup against
6032 a symbol in the TOC subsegment into a reloc against the
6033 corresponding .tc symbol. */
6036 ppc_fix_adjustable (fixS *fix)
6038 valueT val = resolve_symbol_value (fix->fx_addsy);
6039 segT symseg = S_GET_SEGMENT (fix->fx_addsy);
6040 TC_SYMFIELD_TYPE *tc;
6042 if (symseg == absolute_section)
6045 /* Always adjust symbols in debugging sections. */
6046 if (bfd_get_section_flags (stdoutput, symseg) & SEC_DEBUGGING)
6049 if (ppc_toc_csect != (symbolS *) NULL
6050 && fix->fx_addsy != ppc_toc_csect
6051 && symseg == data_section
6052 && val >= ppc_toc_frag->fr_address
6053 && (ppc_after_toc_frag == (fragS *) NULL
6054 || val < ppc_after_toc_frag->fr_address))
6058 for (sy = symbol_next (ppc_toc_csect);
6059 sy != (symbolS *) NULL;
6060 sy = symbol_next (sy))
6062 TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
6064 if (sy_tc->symbol_class == XMC_TC0)
6066 if (sy_tc->symbol_class != XMC_TC)
6068 if (val == resolve_symbol_value (sy))
6071 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
6076 as_bad_where (fix->fx_file, fix->fx_line,
6077 _("symbol in .toc does not match any .tc"));
6080 /* Possibly adjust the reloc to be against the csect. */
6081 tc = symbol_get_tc (fix->fx_addsy);
6083 && tc->symbol_class != XMC_TC0
6084 && tc->symbol_class != XMC_TC
6085 && symseg != bss_section
6086 /* Don't adjust if this is a reloc in the toc section. */
6087 && (symseg != data_section
6088 || ppc_toc_csect == NULL
6089 || val < ppc_toc_frag->fr_address
6090 || (ppc_after_toc_frag != NULL
6091 && val >= ppc_after_toc_frag->fr_address)))
6093 symbolS *csect = tc->within;
6095 /* If the symbol was not declared by a label (eg: a section symbol),
6096 use the section instead of the csect. This doesn't happen in
6097 normal AIX assembly code. */
6099 csect = seg_info (symseg)->sym;
6101 fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
6102 fix->fx_addsy = csect;
6107 /* Adjust a reloc against a .lcomm symbol to be against the base
6109 if (symseg == bss_section
6110 && ! S_IS_EXTERNAL (fix->fx_addsy))
6112 symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
6114 fix->fx_offset += val - resolve_symbol_value (sy);
6121 /* A reloc from one csect to another must be kept. The assembler
6122 will, of course, keep relocs between sections, and it will keep
6123 absolute relocs, but we need to force it to keep PC relative relocs
6124 between two csects in the same section. */
6127 ppc_force_relocation (fixS *fix)
6129 /* At this point fix->fx_addsy should already have been converted to
6130 a csect symbol. If the csect does not include the fragment, then
6131 we need to force the relocation. */
6133 && fix->fx_addsy != NULL
6134 && symbol_get_tc (fix->fx_addsy)->subseg != 0
6135 && ((symbol_get_frag (fix->fx_addsy)->fr_address
6136 > fix->fx_frag->fr_address)
6137 || (symbol_get_tc (fix->fx_addsy)->next != NULL
6138 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
6139 <= fix->fx_frag->fr_address))))
6142 return generic_force_reloc (fix);
6146 ppc_new_dot_label (symbolS *sym)
6148 /* Anchor this label to the current csect for relocations. */
6149 symbol_get_tc (sym)->within = ppc_current_csect;
6152 #endif /* OBJ_XCOFF */
6155 /* If this function returns non-zero, it guarantees that a relocation
6156 will be emitted for a fixup. */
6159 ppc_force_relocation (fixS *fix)
6161 /* Branch prediction relocations must force a relocation, as must
6162 the vtable description relocs. */
6163 switch (fix->fx_r_type)
6165 case BFD_RELOC_PPC_B16_BRTAKEN:
6166 case BFD_RELOC_PPC_B16_BRNTAKEN:
6167 case BFD_RELOC_PPC_BA16_BRTAKEN:
6168 case BFD_RELOC_PPC_BA16_BRNTAKEN:
6169 case BFD_RELOC_24_PLT_PCREL:
6170 case BFD_RELOC_PPC64_TOC:
6176 if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
6177 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
6180 return generic_force_reloc (fix);
6184 ppc_fix_adjustable (fixS *fix)
6186 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
6187 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
6188 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
6189 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
6190 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_DS
6191 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_LO_DS
6192 && fix->fx_r_type != BFD_RELOC_GPREL16
6193 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
6194 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
6195 && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
6196 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA));
6201 ppc_frag_check (struct frag *fragP)
6203 if (!fragP->has_code)
6206 if (ppc_mach() == bfd_mach_ppc_vle)
6208 if (((fragP->fr_address + fragP->insn_addr) & 1) != 0)
6209 as_bad (_("instruction address is not a multiple of 2"));
6213 if (((fragP->fr_address + fragP->insn_addr) & 3) != 0)
6214 as_bad (_("instruction address is not a multiple of 4"));
6218 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
6219 rs_align_code frag. */
6222 ppc_handle_align (struct frag *fragP)
6224 valueT count = (fragP->fr_next->fr_address
6225 - (fragP->fr_address + fragP->fr_fix));
6227 if (ppc_mach() == bfd_mach_ppc_vle && count != 0 && (count & 1) == 0)
6229 char *dest = fragP->fr_literal + fragP->fr_fix;
6232 md_number_to_chars (dest, 0x4400, 2);
6234 else if (count != 0 && (count & 3) == 0)
6236 char *dest = fragP->fr_literal + fragP->fr_fix;
6240 if (count > 4 * nop_limit && count < 0x2000000)
6244 /* Make a branch, then follow with nops. Insert another
6245 frag to handle the nops. */
6246 md_number_to_chars (dest, 0x48000000 + count, 4);
6251 rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6252 memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
6253 fragP->fr_next = rest;
6255 rest->fr_address += rest->fr_fix + 4;
6257 /* If we leave the next frag as rs_align_code we'll come here
6258 again, resulting in a bunch of branches rather than a
6259 branch followed by nops. */
6260 rest->fr_type = rs_align;
6261 dest = rest->fr_literal;
6264 md_number_to_chars (dest, 0x60000000, 4);
6266 if ((ppc_cpu & PPC_OPCODE_POWER6) != 0
6267 || (ppc_cpu & PPC_OPCODE_POWER7) != 0)
6269 /* For power6 and power7, we want the last nop to be a group
6270 terminating one. Do this by inserting an rs_fill frag immediately
6271 after this one, with its address set to the last nop location.
6272 This will automatically reduce the number of nops in the current
6276 struct frag *group_nop = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6278 memcpy (group_nop, fragP, SIZEOF_STRUCT_FRAG);
6279 group_nop->fr_address = group_nop->fr_next->fr_address - 4;
6280 group_nop->fr_fix = 0;
6281 group_nop->fr_offset = 1;
6282 group_nop->fr_type = rs_fill;
6283 fragP->fr_next = group_nop;
6284 dest = group_nop->fr_literal;
6287 if ((ppc_cpu & PPC_OPCODE_POWER7) != 0)
6289 if (ppc_cpu & PPC_OPCODE_E500MC)
6290 /* e500mc group terminating nop: "ori 0,0,0". */
6291 md_number_to_chars (dest, 0x60000000, 4);
6293 /* power7 group terminating nop: "ori 2,2,0". */
6294 md_number_to_chars (dest, 0x60420000, 4);
6297 /* power6 group terminating nop: "ori 1,1,0". */
6298 md_number_to_chars (dest, 0x60210000, 4);
6303 /* Apply a fixup to the object code. This is called for all the
6304 fixups we generated by the calls to fix_new_exp, above. */
6307 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
6309 valueT value = * valP;
6312 if (fixP->fx_addsy != NULL)
6314 /* Hack around bfd_install_relocation brain damage. */
6316 value += fixP->fx_frag->fr_address + fixP->fx_where;
6321 /* FIXME FIXME FIXME: The value we are passed in *valP includes
6322 the symbol values. If we are doing this relocation the code in
6323 write.c is going to call bfd_install_relocation, which is also
6324 going to use the symbol value. That means that if the reloc is
6325 fully resolved we want to use *valP since bfd_install_relocation is
6327 However, if the reloc is not fully resolved we do not want to
6328 use *valP, and must use fx_offset instead. If the relocation
6329 is PC-relative, we then need to re-apply md_pcrel_from_section
6330 to this new relocation value. */
6331 if (fixP->fx_addsy == (symbolS *) NULL)
6336 value = fixP->fx_offset;
6338 value -= md_pcrel_from_section (fixP, seg);
6342 if (fixP->fx_subsy != (symbolS *) NULL)
6344 /* We can't actually support subtracting a symbol. */
6345 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
6348 if (fixP->fx_pcrel_adjust != 0)
6350 /* Handle relocs in an insn. */
6352 int opindex = fixP->fx_pcrel_adjust & 0xff;
6353 const struct powerpc_operand *operand = &powerpc_operands[opindex];
6359 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
6360 does not generate a reloc. It uses the offset of `sym' within its
6361 csect. Other usages, such as `.long sym', generate relocs. This
6362 is the documented behaviour of non-TOC symbols. */
6363 if ((operand->flags & PPC_OPERAND_PARENS) != 0
6364 && (operand->bitm & 0xfff0) == 0xfff0
6365 && operand->shift == 0
6366 && (operand->insert == NULL || ppc_obj64)
6367 && fixP->fx_addsy != NULL
6368 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
6369 && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC
6370 && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC0
6371 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
6373 value = fixP->fx_offset;
6378 switch (fixP->fx_r_type)
6381 case BFD_RELOC_PPC64_ADDR16_LO_DS:
6386 case BFD_RELOC_LO16:
6388 fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
6390 case BFD_RELOC_LO16_PCREL:
6391 fieldval = SEX16 (value);
6394 case BFD_RELOC_HI16:
6396 fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
6398 case BFD_RELOC_HI16_PCREL:
6399 fieldval = SEX16 (PPC_HI (value));
6402 case BFD_RELOC_HI16_S:
6404 fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
6406 case BFD_RELOC_HI16_S_PCREL:
6407 fieldval = SEX16 (PPC_HA (value));
6411 case BFD_RELOC_PPC64_HIGHER:
6414 fieldval = SEX16 (PPC_HIGHER (value));
6417 case BFD_RELOC_PPC64_HIGHER_S:
6420 fieldval = SEX16 (PPC_HIGHERA (value));
6423 case BFD_RELOC_PPC64_HIGHEST:
6426 fieldval = SEX16 (PPC_HIGHEST (value));
6429 case BFD_RELOC_PPC64_HIGHEST_S:
6432 fieldval = SEX16 (PPC_HIGHESTA (value));
6435 /* The following relocs can't be calculated by the assembler.
6436 Leave the field zero. */
6437 case BFD_RELOC_PPC_TPREL16:
6438 case BFD_RELOC_PPC_TPREL16_LO:
6439 case BFD_RELOC_PPC_TPREL16_HI:
6440 case BFD_RELOC_PPC_TPREL16_HA:
6441 case BFD_RELOC_PPC_DTPREL16:
6442 case BFD_RELOC_PPC_DTPREL16_LO:
6443 case BFD_RELOC_PPC_DTPREL16_HI:
6444 case BFD_RELOC_PPC_DTPREL16_HA:
6445 case BFD_RELOC_PPC_GOT_TLSGD16:
6446 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
6447 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
6448 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
6449 case BFD_RELOC_PPC_GOT_TLSLD16:
6450 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
6451 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
6452 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
6453 case BFD_RELOC_PPC_GOT_TPREL16:
6454 case BFD_RELOC_PPC_GOT_TPREL16_LO:
6455 case BFD_RELOC_PPC_GOT_TPREL16_HI:
6456 case BFD_RELOC_PPC_GOT_TPREL16_HA:
6457 case BFD_RELOC_PPC_GOT_DTPREL16:
6458 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
6459 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
6460 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
6461 case BFD_RELOC_PPC64_TPREL16_DS:
6462 case BFD_RELOC_PPC64_TPREL16_LO_DS:
6463 case BFD_RELOC_PPC64_TPREL16_HIGHER:
6464 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
6465 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
6466 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
6467 case BFD_RELOC_PPC64_DTPREL16_DS:
6468 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
6469 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
6470 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
6471 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
6472 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
6473 gas_assert (fixP->fx_addsy != NULL);
6474 S_SET_THREAD_LOCAL (fixP->fx_addsy);
6480 /* These also should leave the field zero for the same
6481 reason. Note that older versions of gas wrote values
6482 here. If we want to go back to the old behaviour, then
6483 all _LO and _LO_DS cases will need to be treated like
6484 BFD_RELOC_LO16_PCREL above. Similarly for _HI etc. */
6485 case BFD_RELOC_16_GOTOFF:
6486 case BFD_RELOC_LO16_GOTOFF:
6487 case BFD_RELOC_HI16_GOTOFF:
6488 case BFD_RELOC_HI16_S_GOTOFF:
6489 case BFD_RELOC_LO16_PLTOFF:
6490 case BFD_RELOC_HI16_PLTOFF:
6491 case BFD_RELOC_HI16_S_PLTOFF:
6492 case BFD_RELOC_GPREL16:
6493 case BFD_RELOC_16_BASEREL:
6494 case BFD_RELOC_LO16_BASEREL:
6495 case BFD_RELOC_HI16_BASEREL:
6496 case BFD_RELOC_HI16_S_BASEREL:
6497 case BFD_RELOC_PPC_TOC16:
6498 case BFD_RELOC_PPC64_TOC16_LO:
6499 case BFD_RELOC_PPC64_TOC16_HI:
6500 case BFD_RELOC_PPC64_TOC16_HA:
6501 case BFD_RELOC_PPC64_PLTGOT16:
6502 case BFD_RELOC_PPC64_PLTGOT16_LO:
6503 case BFD_RELOC_PPC64_PLTGOT16_HI:
6504 case BFD_RELOC_PPC64_PLTGOT16_HA:
6505 case BFD_RELOC_PPC64_GOT16_DS:
6506 case BFD_RELOC_PPC64_GOT16_LO_DS:
6507 case BFD_RELOC_PPC64_PLT16_LO_DS:
6508 case BFD_RELOC_PPC64_SECTOFF_DS:
6509 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
6510 case BFD_RELOC_PPC64_TOC16_DS:
6511 case BFD_RELOC_PPC64_TOC16_LO_DS:
6512 case BFD_RELOC_PPC64_PLTGOT16_DS:
6513 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
6514 case BFD_RELOC_PPC_EMB_NADDR16:
6515 case BFD_RELOC_PPC_EMB_NADDR16_LO:
6516 case BFD_RELOC_PPC_EMB_NADDR16_HI:
6517 case BFD_RELOC_PPC_EMB_NADDR16_HA:
6518 case BFD_RELOC_PPC_EMB_SDAI16:
6519 case BFD_RELOC_PPC_EMB_SDA2I16:
6520 case BFD_RELOC_PPC_EMB_SDA2REL:
6521 case BFD_RELOC_PPC_EMB_SDA21:
6522 case BFD_RELOC_PPC_EMB_MRKREF:
6523 case BFD_RELOC_PPC_EMB_RELSEC16:
6524 case BFD_RELOC_PPC_EMB_RELST_LO:
6525 case BFD_RELOC_PPC_EMB_RELST_HI:
6526 case BFD_RELOC_PPC_EMB_RELST_HA:
6527 case BFD_RELOC_PPC_EMB_BIT_FLD:
6528 case BFD_RELOC_PPC_EMB_RELSDA:
6529 case BFD_RELOC_PPC_VLE_SDA21:
6530 case BFD_RELOC_PPC_VLE_SDA21_LO:
6531 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
6532 case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
6533 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
6534 case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
6535 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
6536 case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
6537 gas_assert (fixP->fx_addsy != NULL);
6540 case BFD_RELOC_PPC_TLS:
6541 case BFD_RELOC_PPC_TLSGD:
6542 case BFD_RELOC_PPC_TLSLD:
6554 /* powerpc uses RELA style relocs, so if emitting a reloc the field
6555 contents can stay at zero. */
6556 #define APPLY_RELOC fixP->fx_done
6558 #define APPLY_RELOC 1
6560 if ((fieldval != 0 && APPLY_RELOC) || operand->insert != NULL)
6562 /* Fetch the instruction, insert the fully resolved operand
6563 value, and stuff the instruction back again. */
6564 where = fixP->fx_frag->fr_literal + fixP->fx_where;
6565 if (target_big_endian)
6567 if (fixP->fx_size == 4)
6568 insn = bfd_getb32 ((unsigned char *) where);
6570 insn = bfd_getb16 ((unsigned char *) where);
6574 if (fixP->fx_size == 4)
6575 insn = bfd_getl32 ((unsigned char *) where);
6577 insn = bfd_getl16 ((unsigned char *) where);
6579 insn = ppc_insert_operand (insn, operand, fieldval,
6580 fixP->tc_fix_data.ppc_cpu,
6581 fixP->fx_file, fixP->fx_line);
6582 if (target_big_endian)
6584 if (fixP->fx_size == 4)
6585 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
6587 bfd_putb16 ((bfd_vma) insn, (unsigned char *) where);
6591 if (fixP->fx_size == 4)
6592 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
6594 bfd_putl16 ((bfd_vma) insn, (unsigned char *) where);
6599 /* Nothing else to do here. */
6602 gas_assert (fixP->fx_addsy != NULL);
6603 if (fixP->fx_r_type == BFD_RELOC_UNUSED)
6608 /* Use expr_symbol_where to see if this is an expression
6610 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
6611 as_bad_where (fixP->fx_file, fixP->fx_line,
6612 _("unresolved expression that must be resolved"));
6614 as_bad_where (fixP->fx_file, fixP->fx_line,
6615 _("unsupported relocation against %s"),
6616 S_GET_NAME (fixP->fx_addsy));
6624 offsetT fieldval = value;
6626 /* Handle relocs in data. */
6627 switch (fixP->fx_r_type)
6629 case BFD_RELOC_CTOR:
6636 fixP->fx_r_type = BFD_RELOC_32_PCREL;
6639 case BFD_RELOC_32_PCREL:
6647 fixP->fx_r_type = BFD_RELOC_64_PCREL;
6650 case BFD_RELOC_64_PCREL:
6656 fixP->fx_r_type = BFD_RELOC_16_PCREL;
6659 case BFD_RELOC_16_PCREL:
6674 /* Use expr_symbol_where to see if this is an
6675 expression symbol. */
6676 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
6677 as_bad_where (fixP->fx_file, fixP->fx_line,
6678 _("unresolved expression that must"
6681 as_bad_where (fixP->fx_file, fixP->fx_line,
6682 _("cannot emit PC relative %s relocation"
6684 bfd_get_reloc_code_name (fixP->fx_r_type),
6685 S_GET_NAME (fixP->fx_addsy));
6688 as_bad_where (fixP->fx_file, fixP->fx_line,
6689 _("unable to resolve expression"));
6696 case BFD_RELOC_VTABLE_INHERIT:
6698 && !S_IS_DEFINED (fixP->fx_addsy)
6699 && !S_IS_WEAK (fixP->fx_addsy))
6700 S_SET_WEAK (fixP->fx_addsy);
6703 case BFD_RELOC_VTABLE_ENTRY:
6708 /* These can appear with @l etc. in data. */
6709 case BFD_RELOC_LO16:
6711 fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
6712 case BFD_RELOC_LO16_PCREL:
6716 case BFD_RELOC_HI16:
6718 fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
6719 case BFD_RELOC_HI16_PCREL:
6721 fieldval = PPC_HI (value);
6724 case BFD_RELOC_HI16_S:
6726 fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
6727 case BFD_RELOC_HI16_S_PCREL:
6729 fieldval = PPC_HA (value);
6732 case BFD_RELOC_PPC64_HIGHER:
6736 fieldval = PPC_HIGHER (value);
6739 case BFD_RELOC_PPC64_HIGHER_S:
6743 fieldval = PPC_HIGHERA (value);
6746 case BFD_RELOC_PPC64_HIGHEST:
6750 fieldval = PPC_HIGHEST (value);
6753 case BFD_RELOC_PPC64_HIGHEST_S:
6757 fieldval = PPC_HIGHESTA (value);
6760 case BFD_RELOC_PPC_DTPMOD:
6761 case BFD_RELOC_PPC_TPREL:
6762 case BFD_RELOC_PPC_DTPREL:
6763 S_SET_THREAD_LOCAL (fixP->fx_addsy);
6766 /* Just punt all of these to the linker. */
6767 case BFD_RELOC_PPC_B16_BRTAKEN:
6768 case BFD_RELOC_PPC_B16_BRNTAKEN:
6769 case BFD_RELOC_16_GOTOFF:
6770 case BFD_RELOC_LO16_GOTOFF:
6771 case BFD_RELOC_HI16_GOTOFF:
6772 case BFD_RELOC_HI16_S_GOTOFF:
6773 case BFD_RELOC_LO16_PLTOFF:
6774 case BFD_RELOC_HI16_PLTOFF:
6775 case BFD_RELOC_HI16_S_PLTOFF:
6776 case BFD_RELOC_PPC_COPY:
6777 case BFD_RELOC_PPC_GLOB_DAT:
6778 case BFD_RELOC_16_BASEREL:
6779 case BFD_RELOC_LO16_BASEREL:
6780 case BFD_RELOC_HI16_BASEREL:
6781 case BFD_RELOC_HI16_S_BASEREL:
6782 case BFD_RELOC_PPC_TLS:
6783 case BFD_RELOC_PPC_DTPREL16_LO:
6784 case BFD_RELOC_PPC_DTPREL16_HI:
6785 case BFD_RELOC_PPC_DTPREL16_HA:
6786 case BFD_RELOC_PPC_TPREL16_LO:
6787 case BFD_RELOC_PPC_TPREL16_HI:
6788 case BFD_RELOC_PPC_TPREL16_HA:
6789 case BFD_RELOC_PPC_GOT_TLSGD16:
6790 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
6791 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
6792 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
6793 case BFD_RELOC_PPC_GOT_TLSLD16:
6794 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
6795 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
6796 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
6797 case BFD_RELOC_PPC_GOT_DTPREL16:
6798 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
6799 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
6800 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
6801 case BFD_RELOC_PPC_GOT_TPREL16:
6802 case BFD_RELOC_PPC_GOT_TPREL16_LO:
6803 case BFD_RELOC_PPC_GOT_TPREL16_HI:
6804 case BFD_RELOC_PPC_GOT_TPREL16_HA:
6805 case BFD_RELOC_24_PLT_PCREL:
6806 case BFD_RELOC_PPC_LOCAL24PC:
6807 case BFD_RELOC_32_PLT_PCREL:
6808 case BFD_RELOC_GPREL16:
6809 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
6810 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
6811 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
6812 case BFD_RELOC_PPC_EMB_NADDR32:
6813 case BFD_RELOC_PPC_EMB_NADDR16:
6814 case BFD_RELOC_PPC_EMB_NADDR16_LO:
6815 case BFD_RELOC_PPC_EMB_NADDR16_HI:
6816 case BFD_RELOC_PPC_EMB_NADDR16_HA:
6817 case BFD_RELOC_PPC_EMB_SDAI16:
6818 case BFD_RELOC_PPC_EMB_SDA2REL:
6819 case BFD_RELOC_PPC_EMB_SDA2I16:
6820 case BFD_RELOC_PPC_EMB_SDA21:
6821 case BFD_RELOC_PPC_VLE_SDA21_LO:
6822 case BFD_RELOC_PPC_EMB_MRKREF:
6823 case BFD_RELOC_PPC_EMB_RELSEC16:
6824 case BFD_RELOC_PPC_EMB_RELST_LO:
6825 case BFD_RELOC_PPC_EMB_RELST_HI:
6826 case BFD_RELOC_PPC_EMB_RELST_HA:
6827 case BFD_RELOC_PPC_EMB_BIT_FLD:
6828 case BFD_RELOC_PPC_EMB_RELSDA:
6829 case BFD_RELOC_PPC64_TOC:
6830 case BFD_RELOC_PPC_TOC16:
6831 case BFD_RELOC_PPC64_TOC16_LO:
6832 case BFD_RELOC_PPC64_TOC16_HI:
6833 case BFD_RELOC_PPC64_TOC16_HA:
6834 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
6835 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
6836 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
6837 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
6838 case BFD_RELOC_PPC64_TPREL16_HIGHER:
6839 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
6840 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
6841 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
6847 case BFD_RELOC_NONE:
6853 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
6858 if (size && APPLY_RELOC)
6859 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6864 ppc_elf_validate_fix (fixP, seg);
6865 fixP->fx_addnumber = value;
6867 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6868 from the section contents. If we are going to be emitting a reloc
6869 then the section contents are immaterial, so don't warn if they
6870 happen to overflow. Leave such warnings to ld. */
6873 fixP->fx_no_overflow = 1;
6875 /* Arrange to emit .TOC. as a normal symbol if used in anything
6876 but .TOC.@tocbase. */
6878 && fixP->fx_r_type != BFD_RELOC_PPC64_TOC
6879 && fixP->fx_addsy != NULL
6880 && strcmp (S_GET_NAME (fixP->fx_addsy), ".TOC.") == 0)
6881 symbol_get_bfdsym (fixP->fx_addsy)->flags |= BSF_KEEP;
6884 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
6885 fixP->fx_addnumber = 0;
6889 fixP->fx_addnumber = 0;
6891 /* We want to use the offset within the toc, not the actual VMA
6893 fixP->fx_addnumber =
6894 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy))
6895 - S_GET_VALUE (ppc_toc_csect);
6901 /* Generate a reloc for a fixup. */
6904 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
6908 reloc = (arelent *) xmalloc (sizeof (arelent));
6910 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
6911 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
6912 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6913 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6914 if (reloc->howto == (reloc_howto_type *) NULL)
6916 as_bad_where (fixp->fx_file, fixp->fx_line,
6917 _("reloc %d not supported by object file format"),
6918 (int) fixp->fx_r_type);
6921 reloc->addend = fixp->fx_addnumber;
6927 ppc_cfi_frame_initial_instructions (void)
6929 cfi_add_CFA_def_cfa (1, 0);
6933 tc_ppc_regname_to_dw2regnum (char *regname)
6935 unsigned int regnum = -1;
6939 static struct { char *name; int dw2regnum; } regnames[] =
6941 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6942 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6943 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6944 { "spe_acc", 111 }, { "spefscr", 112 }
6947 for (i = 0; i < ARRAY_SIZE (regnames); ++i)
6948 if (strcmp (regnames[i].name, regname) == 0)
6949 return regnames[i].dw2regnum;
6951 if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
6953 p = regname + 1 + (regname[1] == '.');
6954 regnum = strtoul (p, &q, 10);
6955 if (p == q || *q || regnum >= 32)
6957 if (regname[0] == 'f')
6959 else if (regname[0] == 'v')
6962 else if (regname[0] == 'c' && regname[1] == 'r')
6964 p = regname + 2 + (regname[2] == '.');
6965 if (p[0] < '0' || p[0] > '7' || p[1])
6967 regnum = p[0] - '0' + 68;