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 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
24 #include "safe-ctype.h"
26 #include "dw2gencfi.h"
27 #include "opcode/ppc.h"
31 #include "dwarf2dbg.h"
39 #include "coff/xcoff.h"
43 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
45 /* Tell the main code what the endianness is. */
46 extern int target_big_endian;
48 /* Whether or not, we've set target_big_endian. */
49 static int set_target_endian = 0;
51 /* Whether to use user friendly register names. */
52 #ifndef TARGET_REG_NAMES_P
54 #define TARGET_REG_NAMES_P TRUE
56 #define TARGET_REG_NAMES_P FALSE
60 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
63 /* #lo(value) denotes the least significant 16 bits of the indicated. */
64 #define PPC_LO(v) ((v) & 0xffff)
66 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
67 #define PPC_HI(v) (((v) >> 16) & 0xffff)
69 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
70 the indicated value, compensating for #lo() being treated as a
72 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
74 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
75 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
77 /* #highera(value) denotes bits 32 through 47 of the indicated value,
78 compensating for #lo() being treated as a signed number. */
79 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
81 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
82 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
84 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
85 compensating for #lo being treated as a signed number. */
86 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
88 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
90 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
92 static void ppc_macro (char *, const struct powerpc_macro *);
93 static void ppc_byte (int);
95 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
96 static void ppc_tc (int);
97 static void ppc_machine (int);
101 static void ppc_comm (int);
102 static void ppc_bb (int);
103 static void ppc_bc (int);
104 static void ppc_bf (int);
105 static void ppc_biei (int);
106 static void ppc_bs (int);
107 static void ppc_eb (int);
108 static void ppc_ec (int);
109 static void ppc_ef (int);
110 static void ppc_es (int);
111 static void ppc_csect (int);
112 static void ppc_dwsect (int);
113 static void ppc_change_csect (symbolS *, offsetT);
114 static void ppc_function (int);
115 static void ppc_extern (int);
116 static void ppc_lglobl (int);
117 static void ppc_ref (int);
118 static void ppc_section (int);
119 static void ppc_named_section (int);
120 static void ppc_stabx (int);
121 static void ppc_rename (int);
122 static void ppc_toc (int);
123 static void ppc_xcoff_cons (int);
124 static void ppc_vbyte (int);
128 static void ppc_elf_cons (int);
129 static void ppc_elf_rdata (int);
130 static void ppc_elf_lcomm (int);
134 static void ppc_previous (int);
135 static void ppc_pdata (int);
136 static void ppc_ydata (int);
137 static void ppc_reldata (int);
138 static void ppc_rdata (int);
139 static void ppc_ualong (int);
140 static void ppc_znop (int);
141 static void ppc_pe_comm (int);
142 static void ppc_pe_section (int);
143 static void ppc_pe_function (int);
144 static void ppc_pe_tocd (int);
147 /* Generic assembler global variables which must be defined by all
151 /* This string holds the chars that always start a comment. If the
152 pre-processor is disabled, these aren't very useful. The macro
153 tc_comment_chars points to this. We use this, rather than the
154 usual comment_chars, so that we can switch for Solaris conventions. */
155 static const char ppc_solaris_comment_chars[] = "#!";
156 static const char ppc_eabi_comment_chars[] = "#";
158 #ifdef TARGET_SOLARIS_COMMENT
159 const char *ppc_comment_chars = ppc_solaris_comment_chars;
161 const char *ppc_comment_chars = ppc_eabi_comment_chars;
164 const char comment_chars[] = "#";
167 /* Characters which start a comment at the beginning of a line. */
168 const char line_comment_chars[] = "#";
170 /* Characters which may be used to separate multiple commands on a
172 const char line_separator_chars[] = ";";
174 /* Characters which are used to indicate an exponent in a floating
176 const char EXP_CHARS[] = "eE";
178 /* Characters which mean that a number is a floating point constant,
180 const char FLT_CHARS[] = "dD";
182 /* Anything that can start an operand needs to be mentioned here,
183 to stop the input scrubber eating whitespace. */
184 const char ppc_symbol_chars[] = "%[";
186 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
187 int ppc_cie_data_alignment;
189 /* More than this number of nops in an alignment op gets a branch
191 unsigned long nop_limit = 4;
193 /* The type of processor we are assembling for. This is one or more
194 of the PPC_OPCODE flags defined in opcode/ppc.h. */
195 ppc_cpu_t ppc_cpu = 0;
197 /* Flags set on encountering toc relocs. */
199 has_large_toc_reloc = 1,
200 has_small_toc_reloc = 2
203 /* The target specific pseudo-ops which we support. */
205 const pseudo_typeS md_pseudo_table[] =
207 /* Pseudo-ops which must be overridden. */
208 { "byte", ppc_byte, 0 },
211 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
212 legitimately belong in the obj-*.c file. However, XCOFF is based
213 on COFF, and is only implemented for the RS/6000. We just use
214 obj-coff.c, and add what we need here. */
215 { "comm", ppc_comm, 0 },
216 { "lcomm", ppc_comm, 1 },
220 { "bi", ppc_biei, 0 },
222 { "csect", ppc_csect, 0 },
223 { "dwsect", ppc_dwsect, 0 },
224 { "data", ppc_section, 'd' },
228 { "ei", ppc_biei, 1 },
230 { "extern", ppc_extern, 0 },
231 { "function", ppc_function, 0 },
232 { "lglobl", ppc_lglobl, 0 },
233 { "ref", ppc_ref, 0 },
234 { "rename", ppc_rename, 0 },
235 { "section", ppc_named_section, 0 },
236 { "stabx", ppc_stabx, 0 },
237 { "text", ppc_section, 't' },
238 { "toc", ppc_toc, 0 },
239 { "long", ppc_xcoff_cons, 2 },
240 { "llong", ppc_xcoff_cons, 3 },
241 { "word", ppc_xcoff_cons, 1 },
242 { "short", ppc_xcoff_cons, 1 },
243 { "vbyte", ppc_vbyte, 0 },
247 { "llong", ppc_elf_cons, 8 },
248 { "quad", ppc_elf_cons, 8 },
249 { "long", ppc_elf_cons, 4 },
250 { "word", ppc_elf_cons, 2 },
251 { "short", ppc_elf_cons, 2 },
252 { "rdata", ppc_elf_rdata, 0 },
253 { "rodata", ppc_elf_rdata, 0 },
254 { "lcomm", ppc_elf_lcomm, 0 },
258 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
259 { "previous", ppc_previous, 0 },
260 { "pdata", ppc_pdata, 0 },
261 { "ydata", ppc_ydata, 0 },
262 { "reldata", ppc_reldata, 0 },
263 { "rdata", ppc_rdata, 0 },
264 { "ualong", ppc_ualong, 0 },
265 { "znop", ppc_znop, 0 },
266 { "comm", ppc_pe_comm, 0 },
267 { "lcomm", ppc_pe_comm, 1 },
268 { "section", ppc_pe_section, 0 },
269 { "function", ppc_pe_function,0 },
270 { "tocd", ppc_pe_tocd, 0 },
273 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
275 { "machine", ppc_machine, 0 },
282 /* Predefined register names if -mregnames (or default for Windows NT).
283 In general, there are lots of them, in an attempt to be compatible
284 with a number of other Windows NT assemblers. */
286 /* Structure to hold information about predefined registers. */
293 /* List of registers that are pre-defined:
295 Each general register has predefined names of the form:
296 1. r<reg_num> which has the value <reg_num>.
297 2. r.<reg_num> which has the value <reg_num>.
299 Each floating point register has predefined names of the form:
300 1. f<reg_num> which has the value <reg_num>.
301 2. f.<reg_num> which has the value <reg_num>.
303 Each vector unit register has predefined names of the form:
304 1. v<reg_num> which has the value <reg_num>.
305 2. v.<reg_num> which has the value <reg_num>.
307 Each condition register has predefined names of the form:
308 1. cr<reg_num> which has the value <reg_num>.
309 2. cr.<reg_num> which has the value <reg_num>.
311 There are individual registers as well:
312 sp or r.sp has the value 1
313 rtoc or r.toc has the value 2
314 fpscr has the value 0
320 dsisr has the value 18
322 sdr1 has the value 25
323 srr0 has the value 26
324 srr1 has the value 27
326 The table is sorted. Suitable for searching by a binary search. */
328 static const struct pd_reg pre_defined_registers[] =
330 { "cr.0", 0 }, /* Condition Registers */
350 { "dar", 19 }, /* Data Access Register */
351 { "dec", 22 }, /* Decrementer */
352 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
354 { "f.0", 0 }, /* Floating point registers */
381 { "f.32", 32 }, /* Extended floating point scalar registers (ISA 2.06). */
447 { "f32", 32 }, /* Extended floating point scalar registers (ISA 2.06). */
488 /* Quantization registers used with pair single instructions. */
506 { "lr", 8 }, /* Link Register */
510 { "r.0", 0 }, /* General Purpose Registers */
543 { "r.sp", 1 }, /* Stack Pointer */
545 { "r.toc", 2 }, /* Pointer to the table of contents */
547 { "r0", 0 }, /* More general purpose registers */
580 { "rtoc", 2 }, /* Table of contents */
582 { "sdr1", 25 }, /* Storage Description Register 1 */
586 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
587 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
589 { "v.0", 0 }, /* Vector (Altivec/VMX) registers */
655 { "vs.0", 0 }, /* Vector Scalar (VSX) registers (ISA 2.06). */
789 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
791 /* Given NAME, find the register number associated with that name, return
792 the integer value associated with the given name or -1 on failure. */
795 reg_name_search (const struct pd_reg *regs, int regcount, const char *name)
797 int middle, low, high;
805 middle = (low + high) / 2;
806 cmp = strcasecmp (name, regs[middle].name);
812 return regs[middle].value;
820 * Summary of register_name.
822 * in: Input_line_pointer points to 1st char of operand.
824 * out: A expressionS.
825 * The operand may have been a register: in this case, X_op == O_register,
826 * X_add_number is set to the register number, and truth is returned.
827 * Input_line_pointer->(next non-blank) char after operand, or is in its
832 register_name (expressionS *expressionP)
839 /* Find the spelling of the operand. */
840 start = name = input_line_pointer;
841 if (name[0] == '%' && ISALPHA (name[1]))
842 name = ++input_line_pointer;
844 else if (!reg_names_p || !ISALPHA (name[0]))
847 c = get_symbol_end ();
848 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
850 /* Put back the delimiting char. */
851 *input_line_pointer = c;
853 /* Look to see if it's in the register table. */
856 expressionP->X_op = O_register;
857 expressionP->X_add_number = reg_number;
859 /* Make the rest nice. */
860 expressionP->X_add_symbol = NULL;
861 expressionP->X_op_symbol = NULL;
865 /* Reset the line as if we had not done anything. */
866 input_line_pointer = start;
870 /* This function is called for each symbol seen in an expression. It
871 handles the special parsing which PowerPC assemblers are supposed
872 to use for condition codes. */
874 /* Whether to do the special parsing. */
875 static bfd_boolean cr_operand;
877 /* Names to recognize in a condition code. This table is sorted. */
878 static const struct pd_reg cr_names[] =
895 /* Parsing function. This returns non-zero if it recognized an
899 ppc_parse_name (const char *name, expressionS *exp)
908 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
913 exp->X_op = O_constant;
914 exp->X_add_number = val;
919 /* Local variables. */
921 /* Whether to target xcoff64/elf64. */
922 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
924 /* Opcode hash table. */
925 static struct hash_control *ppc_hash;
927 /* Macro hash table. */
928 static struct hash_control *ppc_macro_hash;
931 /* What type of shared library support to use. */
932 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
934 /* Flags to set in the elf header. */
935 static flagword ppc_flags = 0;
937 /* Whether this is Solaris or not. */
938 #ifdef TARGET_SOLARIS_COMMENT
939 #define SOLARIS_P TRUE
941 #define SOLARIS_P FALSE
944 static bfd_boolean msolaris = SOLARIS_P;
949 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
950 using a bunch of different sections. These assembler sections,
951 however, are all encompassed within the .text or .data sections of
952 the final output file. We handle this by using different
953 subsegments within these main segments. */
955 /* Next subsegment to allocate within the .text segment. */
956 static subsegT ppc_text_subsegment = 2;
958 /* Linked list of csects in the text section. */
959 static symbolS *ppc_text_csects;
961 /* Next subsegment to allocate within the .data segment. */
962 static subsegT ppc_data_subsegment = 2;
964 /* Linked list of csects in the data section. */
965 static symbolS *ppc_data_csects;
967 /* The current csect. */
968 static symbolS *ppc_current_csect;
970 /* The RS/6000 assembler uses a TOC which holds addresses of functions
971 and variables. Symbols are put in the TOC with the .tc pseudo-op.
972 A special relocation is used when accessing TOC entries. We handle
973 the TOC as a subsegment within the .data segment. We set it up if
974 we see a .toc pseudo-op, and save the csect symbol here. */
975 static symbolS *ppc_toc_csect;
977 /* The first frag in the TOC subsegment. */
978 static fragS *ppc_toc_frag;
980 /* The first frag in the first subsegment after the TOC in the .data
981 segment. NULL if there are no subsegments after the TOC. */
982 static fragS *ppc_after_toc_frag;
984 /* The current static block. */
985 static symbolS *ppc_current_block;
987 /* The COFF debugging section; set by md_begin. This is not the
988 .debug section, but is instead the secret BFD section which will
989 cause BFD to set the section number of a symbol to N_DEBUG. */
990 static asection *ppc_coff_debug_section;
992 /* Structure to set the length field of the dwarf sections. */
993 struct dw_subsection {
994 /* Subsections are simply linked. */
995 struct dw_subsection *link;
997 /* The subsection number. */
1000 /* Expression to compute the length of the section. */
1001 expressionS end_exp;
1004 static struct dw_section {
1005 /* Corresponding section. */
1008 /* Simply linked list of subsections with a label. */
1009 struct dw_subsection *list_subseg;
1011 /* The anonymous subsection. */
1012 struct dw_subsection *anon_subseg;
1013 } dw_sections[XCOFF_DWSECT_NBR_NAMES];
1014 #endif /* OBJ_XCOFF */
1018 /* Various sections that we need for PE coff support. */
1019 static segT ydata_section;
1020 static segT pdata_section;
1021 static segT reldata_section;
1022 static segT rdata_section;
1023 static segT tocdata_section;
1025 /* The current section and the previous section. See ppc_previous. */
1026 static segT ppc_previous_section;
1027 static segT ppc_current_section;
1032 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
1033 #define PPC_APUINFO_ISEL 0x40
1034 #define PPC_APUINFO_PMR 0x41
1035 #define PPC_APUINFO_RFMCI 0x42
1036 #define PPC_APUINFO_CACHELCK 0x43
1037 #define PPC_APUINFO_SPE 0x100
1038 #define PPC_APUINFO_EFS 0x101
1039 #define PPC_APUINFO_BRLOCK 0x102
1042 * We keep a list of APUinfo
1044 unsigned long *ppc_apuinfo_list;
1045 unsigned int ppc_apuinfo_num;
1046 unsigned int ppc_apuinfo_num_alloc;
1047 #endif /* OBJ_ELF */
1050 const char *const md_shortopts = "b:l:usm:K:VQ:";
1052 const char *const md_shortopts = "um:";
1054 #define OPTION_NOPS (OPTION_MD_BASE + 0)
1055 const struct option md_longopts[] = {
1056 {"nops", required_argument, NULL, OPTION_NOPS},
1057 {NULL, no_argument, NULL, 0}
1059 const size_t md_longopts_size = sizeof (md_longopts);
1062 md_parse_option (int c, char *arg)
1069 /* -u means that any undefined symbols should be treated as
1070 external, which is the default for gas anyhow. */
1075 /* Solaris as takes -le (presumably for little endian). For completeness
1076 sake, recognize -be also. */
1077 if (strcmp (arg, "e") == 0)
1079 target_big_endian = 0;
1080 set_target_endian = 1;
1088 if (strcmp (arg, "e") == 0)
1090 target_big_endian = 1;
1091 set_target_endian = 1;
1099 /* Recognize -K PIC. */
1100 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
1103 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1111 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
1113 if (strcmp (arg, "64") == 0)
1118 as_fatal (_("%s unsupported"), "-a64");
1121 else if (strcmp (arg, "32") == 0)
1128 if ((new_cpu = ppc_parse_cpu (ppc_cpu, arg)) != 0)
1131 else if (strcmp (arg, "regnames") == 0)
1134 else if (strcmp (arg, "no-regnames") == 0)
1135 reg_names_p = FALSE;
1138 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1139 that require relocation. */
1140 else if (strcmp (arg, "relocatable") == 0)
1142 shlib = SHLIB_MRELOCATABLE;
1143 ppc_flags |= EF_PPC_RELOCATABLE;
1146 else if (strcmp (arg, "relocatable-lib") == 0)
1148 shlib = SHLIB_MRELOCATABLE;
1149 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1152 /* -memb, set embedded bit. */
1153 else if (strcmp (arg, "emb") == 0)
1154 ppc_flags |= EF_PPC_EMB;
1156 /* -mlittle/-mbig set the endianess. */
1157 else if (strcmp (arg, "little") == 0
1158 || strcmp (arg, "little-endian") == 0)
1160 target_big_endian = 0;
1161 set_target_endian = 1;
1164 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
1166 target_big_endian = 1;
1167 set_target_endian = 1;
1170 else if (strcmp (arg, "solaris") == 0)
1173 ppc_comment_chars = ppc_solaris_comment_chars;
1176 else if (strcmp (arg, "no-solaris") == 0)
1179 ppc_comment_chars = ppc_eabi_comment_chars;
1184 as_bad (_("invalid switch -m%s"), arg);
1190 /* -V: SVR4 argument to print version ID. */
1192 print_version_id ();
1195 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1196 should be emitted or not. FIXME: Not implemented. */
1200 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1201 rather than .stabs.excl, which is ignored by the linker.
1202 FIXME: Not implemented. */
1213 nop_limit = strtoul (optarg, &end, 0);
1215 as_bad (_("--nops needs a numeric argument"));
1227 md_show_usage (FILE *stream)
1229 fprintf (stream, _("\
1231 -a32 generate ELF32/XCOFF32\n\
1232 -a64 generate ELF64/XCOFF64\n\
1234 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1235 -mpwr generate code for POWER (RIOS1)\n\
1236 -m601 generate code for PowerPC 601\n\
1237 -mppc, -mppc32, -m603, -m604\n\
1238 generate code for PowerPC 603/604\n\
1239 -m403 generate code for PowerPC 403\n\
1240 -m405 generate code for PowerPC 405\n\
1241 -m440 generate code for PowerPC 440\n\
1242 -m464 generate code for PowerPC 464\n\
1243 -m476 generate code for PowerPC 476\n\
1244 -m7400, -m7410, -m7450, -m7455\n\
1245 generate code for PowerPC 7400/7410/7450/7455\n\
1246 -m750cl generate code for PowerPC 750cl\n"));
1247 fprintf (stream, _("\
1248 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1249 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1250 -mbooke generate code for 32-bit PowerPC BookE\n\
1251 -ma2 generate code for A2 architecture\n\
1252 -mpower4, -mpwr4 generate code for Power4 architecture\n\
1253 -mpower5, -mpwr5, -mpwr5x\n\
1254 generate code for Power5 architecture\n\
1255 -mpower6, -mpwr6 generate code for Power6 architecture\n\
1256 -mpower7, -mpwr7 generate code for Power7 architecture\n\
1257 -mcell generate code for Cell Broadband Engine architecture\n\
1258 -mcom generate code Power/PowerPC common instructions\n\
1259 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1260 fprintf (stream, _("\
1261 -maltivec generate code for AltiVec\n\
1262 -mvsx generate code for Vector-Scalar (VSX) instructions\n\
1263 -me300 generate code for PowerPC e300 family\n\
1264 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1265 -me500mc, generate code for Freescale e500mc core complex\n\
1266 -me500mc64, generate code for Freescale e500mc64 core complex\n\
1267 -mspe generate code for Motorola SPE instructions\n\
1268 -mtitan generate code for AppliedMicro Titan core complex\n\
1269 -mregnames Allow symbolic names for registers\n\
1270 -mno-regnames Do not allow symbolic names for registers\n"));
1272 fprintf (stream, _("\
1273 -mrelocatable support for GCC's -mrelocatble option\n\
1274 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1275 -memb set PPC_EMB bit in ELF flags\n\
1276 -mlittle, -mlittle-endian, -le\n\
1277 generate code for a little endian machine\n\
1278 -mbig, -mbig-endian, -be\n\
1279 generate code for a big endian machine\n\
1280 -msolaris generate code for Solaris\n\
1281 -mno-solaris do not generate code for Solaris\n\
1282 -K PIC set EF_PPC_RELOCATABLE_LIB in ELF flags\n\
1283 -V print assembler version number\n\
1284 -Qy, -Qn ignored\n"));
1286 fprintf (stream, _("\
1287 -nops=count when aligning, more than COUNT nops uses a branch\n"));
1290 /* Set ppc_cpu if it is not already set. */
1295 const char *default_os = TARGET_OS;
1296 const char *default_cpu = TARGET_CPU;
1298 if ((ppc_cpu & ~(ppc_cpu_t) PPC_OPCODE_ANY) == 0)
1301 ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_64;
1302 else if (strncmp (default_os, "aix", 3) == 0
1303 && default_os[3] >= '4' && default_os[3] <= '9')
1304 ppc_cpu |= PPC_OPCODE_COMMON;
1305 else if (strncmp (default_os, "aix3", 4) == 0)
1306 ppc_cpu |= PPC_OPCODE_POWER;
1307 else if (strcmp (default_cpu, "rs6000") == 0)
1308 ppc_cpu |= PPC_OPCODE_POWER;
1309 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1310 ppc_cpu |= PPC_OPCODE_PPC;
1312 as_fatal (_("Unknown default cpu = %s, os = %s"),
1313 default_cpu, default_os);
1317 /* Figure out the BFD architecture to use. This function and ppc_mach
1318 are called well before md_begin, when the output file is opened. */
1320 enum bfd_architecture
1323 const char *default_cpu = TARGET_CPU;
1326 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1327 return bfd_arch_powerpc;
1328 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1329 return bfd_arch_rs6000;
1330 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1332 if (strcmp (default_cpu, "rs6000") == 0)
1333 return bfd_arch_rs6000;
1334 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1335 return bfd_arch_powerpc;
1338 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1339 return bfd_arch_unknown;
1346 return bfd_mach_ppc64;
1347 else if (ppc_arch () == bfd_arch_rs6000)
1348 return bfd_mach_rs6k;
1349 else if (ppc_cpu & PPC_OPCODE_TITAN)
1350 return bfd_mach_ppc_titan;
1352 return bfd_mach_ppc;
1356 ppc_target_format (void)
1360 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1362 return "xcoff-powermac";
1365 return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1367 return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1373 return "elf32-powerpc-vxworks";
1375 return (target_big_endian
1376 ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc")
1377 : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1382 /* Insert opcodes and macros into hash tables. Called at startup and
1386 ppc_setup_opcodes (void)
1388 const struct powerpc_opcode *op;
1389 const struct powerpc_opcode *op_end;
1390 const struct powerpc_macro *macro;
1391 const struct powerpc_macro *macro_end;
1392 bfd_boolean bad_insn = FALSE;
1394 if (ppc_hash != NULL)
1395 hash_die (ppc_hash);
1396 if (ppc_macro_hash != NULL)
1397 hash_die (ppc_macro_hash);
1399 /* Insert the opcodes into a hash table. */
1400 ppc_hash = hash_new ();
1402 if (ENABLE_CHECKING)
1406 /* Check operand masks. Code here and in the disassembler assumes
1407 all the 1's in the mask are contiguous. */
1408 for (i = 0; i < num_powerpc_operands; ++i)
1410 unsigned long mask = powerpc_operands[i].bitm;
1411 unsigned long right_bit;
1414 right_bit = mask & -mask;
1416 right_bit = mask & -mask;
1417 if (mask != right_bit)
1419 as_bad (_("powerpc_operands[%d].bitm invalid"), i);
1422 for (j = i + 1; j < num_powerpc_operands; ++j)
1423 if (memcmp (&powerpc_operands[i], &powerpc_operands[j],
1424 sizeof (powerpc_operands[0])) == 0)
1426 as_bad (_("powerpc_operands[%d] duplicates powerpc_operands[%d]"),
1433 op_end = powerpc_opcodes + powerpc_num_opcodes;
1434 for (op = powerpc_opcodes; op < op_end; op++)
1436 if (ENABLE_CHECKING)
1438 const unsigned char *o;
1439 unsigned long omask = op->mask;
1441 if (op != powerpc_opcodes)
1443 /* The major opcodes had better be sorted. Code in the
1444 disassembler assumes the insns are sorted according to
1446 if (PPC_OP (op[0].opcode) < PPC_OP (op[-1].opcode))
1448 as_bad (_("major opcode is not sorted for %s"),
1453 /* Warn if the table isn't more strictly ordered.
1454 Unfortunately it doesn't seem possible to order the
1455 table on much more than the major opcode, which makes
1456 it difficult to implement a binary search in the
1457 disassembler. The problem is that we have multiple
1458 ways to disassemble instructions, and we usually want
1459 to choose a more specific form (with more bits set in
1460 the opcode) than a more general form. eg. all of the
1461 following are equivalent:
1462 bne label # opcode = 0x40820000, mask = 0xff830003
1463 bf 2,label # opcode = 0x40800000, mask = 0xff800003
1464 bc 4,2,label # opcode = 0x40000000, mask = 0xfc000003
1466 There are also cases where the table needs to be out
1467 of order to disassemble the correct instruction for
1468 processor variants. */
1471 unsigned long t1 = op[0].opcode;
1472 unsigned long t2 = op[-1].opcode;
1474 if (((t1 ^ t2) & 0xfc0007ff) == 0
1475 && (t1 & 0xfc0006df) == 0x7c000286)
1477 /* spr field is split. */
1478 t1 = ((t1 & ~0x1ff800)
1479 | ((t1 & 0xf800) << 5) | ((t1 & 0x1f0000) >> 5));
1480 t2 = ((t2 & ~0x1ff800)
1481 | ((t2 & 0xf800) << 5) | ((t2 & 0x1f0000) >> 5));
1484 as_warn (_("%s (%08lx %08lx) after %s (%08lx %08lx)"),
1485 op[0].name, op[0].opcode, op[0].mask,
1486 op[-1].name, op[-1].opcode, op[-1].mask);
1490 /* The mask had better not trim off opcode bits. */
1491 if ((op->opcode & omask) != op->opcode)
1493 as_bad (_("mask trims opcode bits for %s"),
1498 /* The operands must not overlap the opcode or each other. */
1499 for (o = op->operands; *o; ++o)
1500 if (*o >= num_powerpc_operands)
1502 as_bad (_("operand index error for %s"),
1508 const struct powerpc_operand *operand = &powerpc_operands[*o];
1509 if (operand->shift >= 0)
1511 unsigned long mask = operand->bitm << operand->shift;
1514 as_bad (_("operand %d overlap in %s"),
1515 (int) (o - op->operands), op->name);
1523 if ((ppc_cpu & op->flags) != 0
1524 && !(ppc_cpu & op->deprecated))
1528 retval = hash_insert (ppc_hash, op->name, (void *) op);
1531 as_bad (_("duplicate instruction %s"),
1538 if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
1539 for (op = powerpc_opcodes; op < op_end; op++)
1540 hash_insert (ppc_hash, op->name, (void *) op);
1542 /* Insert the macros into a hash table. */
1543 ppc_macro_hash = hash_new ();
1545 macro_end = powerpc_macros + powerpc_num_macros;
1546 for (macro = powerpc_macros; macro < macro_end; macro++)
1548 if ((macro->flags & ppc_cpu) != 0 || (ppc_cpu & PPC_OPCODE_ANY) != 0)
1552 retval = hash_insert (ppc_macro_hash, macro->name, (void *) macro);
1553 if (retval != (const char *) NULL)
1555 as_bad (_("duplicate macro %s"), macro->name);
1565 /* This function is called when the assembler starts up. It is called
1566 after the options have been parsed and the output file has been
1574 ppc_cie_data_alignment = ppc_obj64 ? -8 : -4;
1577 /* Set the ELF flags if desired. */
1578 if (ppc_flags && !msolaris)
1579 bfd_set_private_flags (stdoutput, ppc_flags);
1582 ppc_setup_opcodes ();
1584 /* Tell the main code what the endianness is if it is not overridden
1586 if (!set_target_endian)
1588 set_target_endian = 1;
1589 target_big_endian = PPC_BIG_ENDIAN;
1593 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1595 /* Create dummy symbols to serve as initial csects. This forces the
1596 text csects to precede the data csects. These symbols will not
1598 ppc_text_csects = symbol_make ("dummy\001");
1599 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1600 ppc_data_csects = symbol_make ("dummy\001");
1601 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1606 ppc_current_section = text_section;
1607 ppc_previous_section = 0;
1616 if (ppc_apuinfo_list == NULL)
1619 /* Ok, so write the section info out. We have this layout:
1623 0 8 length of "APUinfo\0"
1624 4 (n*4) number of APU's (4 bytes each)
1627 20 APU#1 first APU's info
1628 24 APU#2 second APU's info
1633 asection *seg = now_seg;
1634 subsegT subseg = now_subseg;
1635 asection *apuinfo_secp = (asection *) NULL;
1638 /* Create the .PPC.EMB.apuinfo section. */
1639 apuinfo_secp = subseg_new (".PPC.EMB.apuinfo", 0);
1640 bfd_set_section_flags (stdoutput,
1642 SEC_HAS_CONTENTS | SEC_READONLY);
1645 md_number_to_chars (p, (valueT) 8, 4);
1648 md_number_to_chars (p, (valueT) ppc_apuinfo_num * 4, 4);
1651 md_number_to_chars (p, (valueT) 2, 4);
1654 strcpy (p, "APUinfo");
1656 for (i = 0; i < ppc_apuinfo_num; i++)
1659 md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4);
1662 frag_align (2, 0, 0);
1664 /* We probably can't restore the current segment, for there likely
1667 subseg_set (seg, subseg);
1672 /* Insert an operand value into an instruction. */
1674 static unsigned long
1675 ppc_insert_operand (unsigned long insn,
1676 const struct powerpc_operand *operand,
1682 long min, max, right;
1684 max = operand->bitm;
1688 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1690 if ((operand->flags & PPC_OPERAND_SIGNOPT) == 0)
1691 max = (max >> 1) & -right;
1692 min = ~max & -right;
1695 if ((operand->flags & PPC_OPERAND_PLUS1) != 0)
1698 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1707 /* Some people write constants with the sign extension done by
1708 hand but only up to 32 bits. This shouldn't really be valid,
1709 but, to permit this code to assemble on a 64-bit host, we
1710 sign extend the 32-bit value to 64 bits if so doing makes the
1713 && (offsetT) (val - 0x80000000 - 0x80000000) >= min
1714 && (offsetT) (val - 0x80000000 - 0x80000000) <= max
1715 && ((val - 0x80000000 - 0x80000000) & (right - 1)) == 0)
1716 val = val - 0x80000000 - 0x80000000;
1718 /* Similarly, people write expressions like ~(1<<15), and expect
1719 this to be OK for a 32-bit unsigned value. */
1721 && (offsetT) (val + 0x80000000 + 0x80000000) >= min
1722 && (offsetT) (val + 0x80000000 + 0x80000000) <= max
1723 && ((val + 0x80000000 + 0x80000000) & (right - 1)) == 0)
1724 val = val + 0x80000000 + 0x80000000;
1728 || (val & (right - 1)) != 0)
1729 as_bad_value_out_of_range (_("operand"), val, min, max, file, line);
1732 if (operand->insert)
1737 insn = (*operand->insert) (insn, (long) val, cpu, &errmsg);
1738 if (errmsg != (const char *) NULL)
1739 as_bad_where (file, line, "%s", errmsg);
1742 insn |= ((long) val & operand->bitm) << operand->shift;
1749 /* Parse @got, etc. and return the desired relocation. */
1750 static bfd_reloc_code_real_type
1751 ppc_elf_suffix (char **str_p, expressionS *exp_p)
1755 unsigned int length : 8;
1756 unsigned int valid32 : 1;
1757 unsigned int valid64 : 1;
1766 const struct map_bfd *ptr;
1768 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1769 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1770 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1772 static const struct map_bfd mapping[] = {
1773 MAP ("l", BFD_RELOC_LO16),
1774 MAP ("h", BFD_RELOC_HI16),
1775 MAP ("ha", BFD_RELOC_HI16_S),
1776 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1777 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1778 MAP ("got", BFD_RELOC_16_GOTOFF),
1779 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1780 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1781 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1782 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1783 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1784 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1785 MAP ("copy", BFD_RELOC_PPC_COPY),
1786 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1787 MAP ("sectoff", BFD_RELOC_16_BASEREL),
1788 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1789 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1790 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1791 MAP ("tls", BFD_RELOC_PPC_TLS),
1792 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD),
1793 MAP ("dtprel", BFD_RELOC_PPC_DTPREL),
1794 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO),
1795 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI),
1796 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA),
1797 MAP ("tprel", BFD_RELOC_PPC_TPREL),
1798 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO),
1799 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI),
1800 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA),
1801 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16),
1802 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO),
1803 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI),
1804 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA),
1805 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16),
1806 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO),
1807 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI),
1808 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA),
1809 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16),
1810 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO),
1811 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI),
1812 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA),
1813 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16),
1814 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO),
1815 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI),
1816 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA),
1817 MAP32 ("fixup", BFD_RELOC_CTOR),
1818 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL),
1819 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1820 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1821 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC),
1822 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL),
1823 MAP32 ("sdarel", BFD_RELOC_GPREL16),
1824 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1825 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1826 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1827 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1828 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1829 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1830 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1831 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1832 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1833 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1834 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1835 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1836 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1837 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1838 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1839 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1840 MAP32 ("xgot", BFD_RELOC_PPC_TOC16),
1841 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER),
1842 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S),
1843 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST),
1844 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S),
1845 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC),
1846 MAP64 ("toc", BFD_RELOC_PPC_TOC16),
1847 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO),
1848 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI),
1849 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA),
1850 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER),
1851 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA),
1852 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST),
1853 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA),
1854 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER),
1855 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA),
1856 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST),
1857 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA),
1858 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED }
1862 return BFD_RELOC_UNUSED;
1864 for (ch = *str, str2 = ident;
1865 (str2 < ident + sizeof (ident) - 1
1866 && (ISALNUM (ch) || ch == '@'));
1869 *str2++ = TOLOWER (ch);
1876 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1877 if (ch == ptr->string[0]
1878 && len == ptr->length
1879 && memcmp (ident, ptr->string, ptr->length) == 0
1880 && (ppc_obj64 ? ptr->valid64 : ptr->valid32))
1882 int reloc = ptr->reloc;
1884 if (!ppc_obj64 && exp_p->X_add_number != 0)
1888 case BFD_RELOC_16_GOTOFF:
1889 case BFD_RELOC_LO16_GOTOFF:
1890 case BFD_RELOC_HI16_GOTOFF:
1891 case BFD_RELOC_HI16_S_GOTOFF:
1892 as_warn (_("identifier+constant@got means "
1893 "identifier@got+constant"));
1896 case BFD_RELOC_PPC_GOT_TLSGD16:
1897 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
1898 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
1899 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
1900 case BFD_RELOC_PPC_GOT_TLSLD16:
1901 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
1902 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
1903 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
1904 case BFD_RELOC_PPC_GOT_DTPREL16:
1905 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
1906 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
1907 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
1908 case BFD_RELOC_PPC_GOT_TPREL16:
1909 case BFD_RELOC_PPC_GOT_TPREL16_LO:
1910 case BFD_RELOC_PPC_GOT_TPREL16_HI:
1911 case BFD_RELOC_PPC_GOT_TPREL16_HA:
1912 as_bad (_("symbol+offset not supported for got tls"));
1917 /* Now check for identifier@suffix+constant. */
1918 if (*str == '-' || *str == '+')
1920 char *orig_line = input_line_pointer;
1921 expressionS new_exp;
1923 input_line_pointer = str;
1924 expression (&new_exp);
1925 if (new_exp.X_op == O_constant)
1927 exp_p->X_add_number += new_exp.X_add_number;
1928 str = input_line_pointer;
1931 if (&input_line_pointer != str_p)
1932 input_line_pointer = orig_line;
1936 if (reloc == (int) BFD_RELOC_PPC64_TOC
1937 && exp_p->X_op == O_symbol
1938 && strcmp (S_GET_NAME (exp_p->X_add_symbol), ".TOC.") == 0)
1940 /* Change the symbol so that the dummy .TOC. symbol can be
1941 omitted from the object file. */
1942 exp_p->X_add_symbol = &abs_symbol;
1945 return (bfd_reloc_code_real_type) reloc;
1948 return BFD_RELOC_UNUSED;
1951 /* Like normal .long/.short/.word, except support @got, etc.
1952 Clobbers input_line_pointer, checks end-of-line. */
1954 ppc_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long, 8=.llong */)
1957 bfd_reloc_code_real_type reloc;
1959 if (is_it_end_of_statement ())
1961 demand_empty_rest_of_line ();
1968 if (exp.X_op == O_symbol
1969 && *input_line_pointer == '@'
1970 && (reloc = ppc_elf_suffix (&input_line_pointer,
1971 &exp)) != BFD_RELOC_UNUSED)
1973 reloc_howto_type *reloc_howto;
1976 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1977 size = bfd_get_reloc_size (reloc_howto);
1981 as_bad (_("%s relocations do not fit in %d bytes\n"),
1982 reloc_howto->name, nbytes);
1989 p = frag_more (nbytes);
1990 memset (p, 0, nbytes);
1992 if (target_big_endian)
1993 offset = nbytes - size;
1994 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1999 emit_expr (&exp, (unsigned int) nbytes);
2001 while (*input_line_pointer++ == ',');
2003 /* Put terminator back into stream. */
2004 input_line_pointer--;
2005 demand_empty_rest_of_line ();
2008 /* Solaris pseduo op to change to the .rodata section. */
2010 ppc_elf_rdata (int xxx)
2012 char *save_line = input_line_pointer;
2013 static char section[] = ".rodata\n";
2015 /* Just pretend this is .section .rodata */
2016 input_line_pointer = section;
2017 obj_elf_section (xxx);
2019 input_line_pointer = save_line;
2022 /* Pseudo op to make file scope bss items. */
2024 ppc_elf_lcomm (int xxx ATTRIBUTE_UNUSED)
2037 name = input_line_pointer;
2038 c = get_symbol_end ();
2040 /* just after name is now '\0'. */
2041 p = input_line_pointer;
2044 if (*input_line_pointer != ',')
2046 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
2047 ignore_rest_of_line ();
2051 input_line_pointer++; /* skip ',' */
2052 if ((size = get_absolute_expression ()) < 0)
2054 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
2055 ignore_rest_of_line ();
2059 /* The third argument to .lcomm is the alignment. */
2060 if (*input_line_pointer != ',')
2064 ++input_line_pointer;
2065 align = get_absolute_expression ();
2068 as_warn (_("ignoring bad alignment"));
2074 symbolP = symbol_find_or_make (name);
2077 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
2079 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2080 S_GET_NAME (symbolP));
2081 ignore_rest_of_line ();
2085 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
2087 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
2088 S_GET_NAME (symbolP),
2089 (long) S_GET_VALUE (symbolP),
2092 ignore_rest_of_line ();
2098 old_subsec = now_subseg;
2101 /* Convert to a power of 2 alignment. */
2102 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
2105 as_bad (_("Common alignment not a power of 2"));
2106 ignore_rest_of_line ();
2113 record_alignment (bss_section, align2);
2114 subseg_set (bss_section, 0);
2116 frag_align (align2, 0, 0);
2117 if (S_GET_SEGMENT (symbolP) == bss_section)
2118 symbol_get_frag (symbolP)->fr_symbol = 0;
2119 symbol_set_frag (symbolP, frag_now);
2120 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
2123 S_SET_SIZE (symbolP, size);
2124 S_SET_SEGMENT (symbolP, bss_section);
2125 subseg_set (old_sec, old_subsec);
2126 demand_empty_rest_of_line ();
2129 /* Validate any relocations emitted for -mrelocatable, possibly adding
2130 fixups for word relocations in writable segments, so we can adjust
2133 ppc_elf_validate_fix (fixS *fixp, segT seg)
2135 if (fixp->fx_done || fixp->fx_pcrel)
2144 case SHLIB_MRELOCATABLE:
2145 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
2146 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
2147 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
2148 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
2149 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
2150 && fixp->fx_r_type != BFD_RELOC_16_BASEREL
2151 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
2152 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
2153 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
2154 && (seg->flags & SEC_LOAD) != 0
2155 && strcmp (segment_name (seg), ".got2") != 0
2156 && strcmp (segment_name (seg), ".dtors") != 0
2157 && strcmp (segment_name (seg), ".ctors") != 0
2158 && strcmp (segment_name (seg), ".fixup") != 0
2159 && strcmp (segment_name (seg), ".gcc_except_table") != 0
2160 && strcmp (segment_name (seg), ".eh_frame") != 0
2161 && strcmp (segment_name (seg), ".ex_shared") != 0)
2163 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
2164 || fixp->fx_r_type != BFD_RELOC_CTOR)
2166 as_bad_where (fixp->fx_file, fixp->fx_line,
2167 _("Relocation cannot be done when using -mrelocatable"));
2174 /* Prevent elf_frob_file_before_adjust removing a weak undefined
2175 function descriptor sym if the corresponding code sym is used. */
2178 ppc_frob_file_before_adjust (void)
2186 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
2193 name = S_GET_NAME (symp);
2197 if (! S_IS_WEAK (symp)
2198 || S_IS_DEFINED (symp))
2201 len = strlen (name) + 1;
2202 dotname = xmalloc (len + 1);
2204 memcpy (dotname + 1, name, len);
2205 dotsym = symbol_find_noref (dotname, 1);
2207 if (dotsym != NULL && (symbol_used_p (dotsym)
2208 || symbol_used_in_reloc_p (dotsym)))
2209 symbol_mark_used (symp);
2213 toc = bfd_get_section_by_name (stdoutput, ".toc");
2215 && toc_reloc_types != has_large_toc_reloc
2216 && bfd_section_size (stdoutput, toc) > 0x10000)
2217 as_warn (_("TOC section size exceeds 64k"));
2219 /* Don't emit .TOC. symbol. */
2220 symp = symbol_find (".TOC.");
2222 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2224 #endif /* OBJ_ELF */
2229 * Summary of parse_toc_entry.
2231 * in: Input_line_pointer points to the '[' in one of:
2233 * [toc] [tocv] [toc32] [toc64]
2235 * Anything else is an error of one kind or another.
2238 * return value: success or failure
2239 * toc_kind: kind of toc reference
2240 * input_line_pointer:
2241 * success: first char after the ']'
2242 * failure: unchanged
2246 * [toc] - rv == success, toc_kind = default_toc
2247 * [tocv] - rv == success, toc_kind = data_in_toc
2248 * [toc32] - rv == success, toc_kind = must_be_32
2249 * [toc64] - rv == success, toc_kind = must_be_64
2253 enum toc_size_qualifier
2255 default_toc, /* The toc cell constructed should be the system default size */
2256 data_in_toc, /* This is a direct reference to a toc cell */
2257 must_be_32, /* The toc cell constructed must be 32 bits wide */
2258 must_be_64 /* The toc cell constructed must be 64 bits wide */
2262 parse_toc_entry (enum toc_size_qualifier *toc_kind)
2267 enum toc_size_qualifier t;
2269 /* Save the input_line_pointer. */
2270 start = input_line_pointer;
2272 /* Skip over the '[' , and whitespace. */
2273 ++input_line_pointer;
2276 /* Find the spelling of the operand. */
2277 toc_spec = input_line_pointer;
2278 c = get_symbol_end ();
2280 if (strcmp (toc_spec, "toc") == 0)
2284 else if (strcmp (toc_spec, "tocv") == 0)
2288 else if (strcmp (toc_spec, "toc32") == 0)
2292 else if (strcmp (toc_spec, "toc64") == 0)
2298 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
2299 *input_line_pointer = c;
2300 input_line_pointer = start;
2304 /* Now find the ']'. */
2305 *input_line_pointer = c;
2307 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2308 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
2312 as_bad (_("syntax error: expected `]', found `%c'"), c);
2313 input_line_pointer = start;
2324 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2326 ppc_apuinfo_section_add (unsigned int apu, unsigned int version)
2330 /* Check we don't already exist. */
2331 for (i = 0; i < ppc_apuinfo_num; i++)
2332 if (ppc_apuinfo_list[i] == APUID (apu, version))
2335 if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2337 if (ppc_apuinfo_num_alloc == 0)
2339 ppc_apuinfo_num_alloc = 4;
2340 ppc_apuinfo_list = (unsigned long *)
2341 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2345 ppc_apuinfo_num_alloc += 4;
2346 ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list,
2347 sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2350 ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2356 /* We need to keep a list of fixups. We can't simply generate them as
2357 we go, because that would require us to first create the frag, and
2358 that would screw up references to ``.''. */
2364 bfd_reloc_code_real_type reloc;
2367 #define MAX_INSN_FIXUPS (5)
2369 /* This routine is called for each instruction to be assembled. */
2372 md_assemble (char *str)
2375 const struct powerpc_opcode *opcode;
2377 const unsigned char *opindex_ptr;
2381 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
2387 bfd_reloc_code_real_type reloc;
2390 /* Get the opcode. */
2391 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
2396 /* Look up the opcode in the hash table. */
2397 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
2398 if (opcode == (const struct powerpc_opcode *) NULL)
2400 const struct powerpc_macro *macro;
2402 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
2403 if (macro == (const struct powerpc_macro *) NULL)
2404 as_bad (_("Unrecognized opcode: `%s'"), str);
2406 ppc_macro (s, macro);
2411 insn = opcode->opcode;
2414 while (ISSPACE (*str))
2417 /* PowerPC operands are just expressions. The only real issue is
2418 that a few operand types are optional. All cases which might use
2419 an optional operand separate the operands only with commas (in some
2420 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2421 have optional operands). Most instructions with optional operands
2422 have only one. Those that have more than one optional operand can
2423 take either all their operands or none. So, before we start seriously
2424 parsing the operands, we check to see if we have optional operands,
2425 and if we do, we count the number of commas to see which operands
2426 have been omitted. */
2428 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2430 const struct powerpc_operand *operand;
2432 operand = &powerpc_operands[*opindex_ptr];
2433 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
2435 unsigned int opcount;
2436 unsigned int num_operands_expected;
2438 /* There is an optional operand. Count the number of
2439 commas in the input line. */
2446 while ((s = strchr (s, ',')) != (char *) NULL)
2453 /* Compute the number of expected operands.
2454 Do not count fake operands. */
2455 for (num_operands_expected = 0, i = 0; opcode->operands[i]; i ++)
2456 if ((powerpc_operands [opcode->operands[i]].flags & PPC_OPERAND_FAKE) == 0)
2457 ++ num_operands_expected;
2459 /* If there are fewer operands in the line then are called
2460 for by the instruction, we want to skip the optional
2462 if (opcount < num_operands_expected)
2469 /* Gather the operands. */
2473 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2475 const struct powerpc_operand *operand;
2481 if (next_opindex == 0)
2482 operand = &powerpc_operands[*opindex_ptr];
2485 operand = &powerpc_operands[next_opindex];
2490 /* If this is a fake operand, then we do not expect anything
2492 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
2494 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2495 if (errmsg != (const char *) NULL)
2496 as_bad ("%s", errmsg);
2500 /* If this is an optional operand, and we are skipping it, just
2502 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
2505 if (operand->insert)
2507 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2508 if (errmsg != (const char *) NULL)
2509 as_bad ("%s", errmsg);
2511 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
2512 next_opindex = *opindex_ptr + 1;
2516 /* Gather the operand. */
2517 hold = input_line_pointer;
2518 input_line_pointer = str;
2521 if (*input_line_pointer == '[')
2523 /* We are expecting something like the second argument here:
2525 * lwz r4,[toc].GS.0.static_int(rtoc)
2526 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2527 * The argument following the `]' must be a symbol name, and the
2528 * register must be the toc register: 'rtoc' or '2'
2530 * The effect is to 0 as the displacement field
2531 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2532 * the appropriate variation) reloc against it based on the symbol.
2533 * The linker will build the toc, and insert the resolved toc offset.
2536 * o The size of the toc entry is currently assumed to be
2537 * 32 bits. This should not be assumed to be a hard coded
2539 * o In an effort to cope with a change from 32 to 64 bits,
2540 * there are also toc entries that are specified to be
2541 * either 32 or 64 bits:
2542 * lwz r4,[toc32].GS.0.static_int(rtoc)
2543 * lwz r4,[toc64].GS.0.static_int(rtoc)
2544 * These demand toc entries of the specified size, and the
2545 * instruction probably requires it.
2549 enum toc_size_qualifier toc_kind;
2550 bfd_reloc_code_real_type toc_reloc;
2552 /* Go parse off the [tocXX] part. */
2553 valid_toc = parse_toc_entry (&toc_kind);
2557 /* Note: message has already been issued.
2558 FIXME: what sort of recovery should we do?
2559 demand_rest_of_line (); return; ? */
2562 /* Now get the symbol following the ']'. */
2568 /* In this case, we may not have seen the symbol yet,
2569 since it is allowed to appear on a .extern or .globl
2570 or just be a label in the .data section. */
2571 toc_reloc = BFD_RELOC_PPC_TOC16;
2574 /* 1. The symbol must be defined and either in the toc
2575 section, or a global.
2576 2. The reloc generated must have the TOCDEFN flag set
2577 in upper bit mess of the reloc type.
2578 FIXME: It's a little confusing what the tocv
2579 qualifier can be used for. At the very least, I've
2580 seen three uses, only one of which I'm sure I can
2582 if (ex.X_op == O_symbol)
2584 gas_assert (ex.X_add_symbol != NULL);
2585 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2588 as_bad (_("[tocv] symbol is not a toc symbol"));
2592 toc_reloc = BFD_RELOC_PPC_TOC16;
2595 /* FIXME: these next two specifically specify 32/64 bit
2596 toc entries. We don't support them today. Is this
2597 the right way to say that? */
2598 toc_reloc = BFD_RELOC_UNUSED;
2599 as_bad (_("Unimplemented toc32 expression modifier"));
2602 /* FIXME: see above. */
2603 toc_reloc = BFD_RELOC_UNUSED;
2604 as_bad (_("Unimplemented toc64 expression modifier"));
2608 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2614 /* We need to generate a fixup for this expression. */
2615 if (fc >= MAX_INSN_FIXUPS)
2616 as_fatal (_("too many fixups"));
2618 fixups[fc].reloc = toc_reloc;
2619 fixups[fc].exp = ex;
2620 fixups[fc].opindex = *opindex_ptr;
2623 /* Ok. We've set up the fixup for the instruction. Now make it
2624 look like the constant 0 was found here. */
2626 ex.X_op = O_constant;
2627 ex.X_add_number = 0;
2628 ex.X_add_symbol = NULL;
2629 ex.X_op_symbol = NULL;
2635 if ((reg_names_p && (operand->flags & PPC_OPERAND_CR) != 0)
2636 || !register_name (&ex))
2638 char save_lex = lex_type['%'];
2640 if ((operand->flags & PPC_OPERAND_CR) != 0)
2643 lex_type['%'] |= LEX_BEGIN_NAME;
2647 lex_type['%'] = save_lex;
2651 str = input_line_pointer;
2652 input_line_pointer = hold;
2654 if (ex.X_op == O_illegal)
2655 as_bad (_("illegal operand"));
2656 else if (ex.X_op == O_absent)
2657 as_bad (_("missing operand"));
2658 else if (ex.X_op == O_register)
2660 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2661 ppc_cpu, (char *) NULL, 0);
2663 else if (ex.X_op == O_constant)
2666 /* Allow @HA, @L, @H on constants. */
2667 char *orig_str = str;
2669 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2676 case BFD_RELOC_LO16:
2677 /* X_unsigned is the default, so if the user has done
2678 something which cleared it, we always produce a
2680 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2681 ex.X_add_number &= 0xffff;
2683 ex.X_add_number = SEX16 (ex.X_add_number);
2686 case BFD_RELOC_HI16:
2687 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2688 ex.X_add_number = PPC_HI (ex.X_add_number);
2690 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2693 case BFD_RELOC_HI16_S:
2694 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2695 ex.X_add_number = PPC_HA (ex.X_add_number);
2697 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2700 case BFD_RELOC_PPC64_HIGHER:
2701 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2702 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2704 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2707 case BFD_RELOC_PPC64_HIGHER_S:
2708 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2709 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2711 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2714 case BFD_RELOC_PPC64_HIGHEST:
2715 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2716 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2718 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2721 case BFD_RELOC_PPC64_HIGHEST_S:
2722 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2723 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2725 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2728 #endif /* OBJ_ELF */
2729 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2730 ppc_cpu, (char *) NULL, 0);
2735 if (ex.X_op == O_symbol && str[0] == '(')
2737 const char *sym_name = S_GET_NAME (ex.X_add_symbol);
2738 if (sym_name[0] == '.')
2741 if (strcasecmp (sym_name, "__tls_get_addr") == 0)
2743 expressionS tls_exp;
2745 hold = input_line_pointer;
2746 input_line_pointer = str + 1;
2747 expression (&tls_exp);
2748 if (tls_exp.X_op == O_symbol)
2750 reloc = BFD_RELOC_UNUSED;
2751 if (strncasecmp (input_line_pointer, "@tlsgd)", 7) == 0)
2753 reloc = BFD_RELOC_PPC_TLSGD;
2754 input_line_pointer += 7;
2756 else if (strncasecmp (input_line_pointer, "@tlsld)", 7) == 0)
2758 reloc = BFD_RELOC_PPC_TLSLD;
2759 input_line_pointer += 7;
2761 if (reloc != BFD_RELOC_UNUSED)
2764 str = input_line_pointer;
2766 if (fc >= MAX_INSN_FIXUPS)
2767 as_fatal (_("too many fixups"));
2768 fixups[fc].exp = tls_exp;
2769 fixups[fc].opindex = *opindex_ptr;
2770 fixups[fc].reloc = reloc;
2774 input_line_pointer = hold;
2778 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2780 /* Some TLS tweaks. */
2786 case BFD_RELOC_PPC_TLS:
2787 if (!_bfd_elf_ppc_at_tls_transform (opcode->opcode, 0))
2788 as_bad (_("@tls may not be used with \"%s\" operands"),
2790 else if (operand->shift != 11)
2791 as_bad (_("@tls may only be used in last operand"));
2793 insn = ppc_insert_operand (insn, operand,
2795 ppc_cpu, (char *) NULL, 0);
2798 /* We'll only use the 32 (or 64) bit form of these relocations
2799 in constants. Instructions get the 16 bit form. */
2800 case BFD_RELOC_PPC_DTPREL:
2801 reloc = BFD_RELOC_PPC_DTPREL16;
2803 case BFD_RELOC_PPC_TPREL:
2804 reloc = BFD_RELOC_PPC_TPREL16;
2808 /* For the absolute forms of branches, convert the PC
2809 relative form back into the absolute. */
2810 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2814 case BFD_RELOC_PPC_B26:
2815 reloc = BFD_RELOC_PPC_BA26;
2817 case BFD_RELOC_PPC_B16:
2818 reloc = BFD_RELOC_PPC_BA16;
2820 case BFD_RELOC_PPC_B16_BRTAKEN:
2821 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2823 case BFD_RELOC_PPC_B16_BRNTAKEN:
2824 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2833 case BFD_RELOC_PPC_TOC16:
2834 toc_reloc_types |= has_small_toc_reloc;
2836 case BFD_RELOC_PPC64_TOC16_LO:
2837 case BFD_RELOC_PPC64_TOC16_HI:
2838 case BFD_RELOC_PPC64_TOC16_HA:
2839 toc_reloc_types |= has_large_toc_reloc;
2846 && (operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
2851 reloc = BFD_RELOC_PPC64_ADDR16_DS;
2853 case BFD_RELOC_LO16:
2854 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2856 case BFD_RELOC_16_GOTOFF:
2857 reloc = BFD_RELOC_PPC64_GOT16_DS;
2859 case BFD_RELOC_LO16_GOTOFF:
2860 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2862 case BFD_RELOC_LO16_PLTOFF:
2863 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2865 case BFD_RELOC_16_BASEREL:
2866 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2868 case BFD_RELOC_LO16_BASEREL:
2869 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2871 case BFD_RELOC_PPC_TOC16:
2872 reloc = BFD_RELOC_PPC64_TOC16_DS;
2874 case BFD_RELOC_PPC64_TOC16_LO:
2875 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2877 case BFD_RELOC_PPC64_PLTGOT16:
2878 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2880 case BFD_RELOC_PPC64_PLTGOT16_LO:
2881 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2883 case BFD_RELOC_PPC_DTPREL16:
2884 reloc = BFD_RELOC_PPC64_DTPREL16_DS;
2886 case BFD_RELOC_PPC_DTPREL16_LO:
2887 reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
2889 case BFD_RELOC_PPC_TPREL16:
2890 reloc = BFD_RELOC_PPC64_TPREL16_DS;
2892 case BFD_RELOC_PPC_TPREL16_LO:
2893 reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
2895 case BFD_RELOC_PPC_GOT_DTPREL16:
2896 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
2897 case BFD_RELOC_PPC_GOT_TPREL16:
2898 case BFD_RELOC_PPC_GOT_TPREL16_LO:
2901 as_bad (_("unsupported relocation for DS offset field"));
2907 /* We need to generate a fixup for this expression. */
2908 if (fc >= MAX_INSN_FIXUPS)
2909 as_fatal (_("too many fixups"));
2910 fixups[fc].exp = ex;
2911 fixups[fc].opindex = *opindex_ptr;
2912 fixups[fc].reloc = reloc;
2918 /* We need to generate a fixup for this expression. */
2919 if (fc >= MAX_INSN_FIXUPS)
2920 as_fatal (_("too many fixups"));
2921 fixups[fc].exp = ex;
2922 fixups[fc].opindex = *opindex_ptr;
2923 fixups[fc].reloc = BFD_RELOC_UNUSED;
2926 #endif /* OBJ_ELF */
2932 /* If expecting more operands, then we want to see "),". */
2933 if (*str == endc && opindex_ptr[1] != 0)
2937 while (ISSPACE (*str));
2941 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2949 /* The call to expression should have advanced str past any
2952 && (endc != ',' || *str != '\0'))
2955 as_bad (_("syntax error; end of line, expected `%c'"), endc);
2957 as_bad (_("syntax error; found `%c', expected `%c'"), *str, endc);
2965 while (ISSPACE (*str))
2969 as_bad (_("junk at end of line: `%s'"), str);
2972 /* Do we need/want a APUinfo section? */
2973 if ((ppc_cpu & (PPC_OPCODE_E500 | PPC_OPCODE_E500MC)) != 0)
2975 /* These are all version "1". */
2976 if (opcode->flags & PPC_OPCODE_SPE)
2977 ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
2978 if (opcode->flags & PPC_OPCODE_ISEL)
2979 ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
2980 if (opcode->flags & PPC_OPCODE_EFS)
2981 ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
2982 if (opcode->flags & PPC_OPCODE_BRLOCK)
2983 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
2984 if (opcode->flags & PPC_OPCODE_PMR)
2985 ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
2986 if (opcode->flags & PPC_OPCODE_CACHELCK)
2987 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
2988 if (opcode->flags & PPC_OPCODE_RFMCI)
2989 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
2993 /* Write out the instruction. */
2995 addr_mod = frag_now_fix () & 3;
2996 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
2997 as_bad (_("instruction address is not a multiple of 4"));
2998 frag_now->insn_addr = addr_mod;
2999 frag_now->has_code = 1;
3000 md_number_to_chars (f, insn, 4);
3003 dwarf2_emit_insn (4);
3006 /* Create any fixups. At this point we do not use a
3007 bfd_reloc_code_real_type, but instead just use the
3008 BFD_RELOC_UNUSED plus the operand index. This lets us easily
3009 handle fixups for any operand type, although that is admittedly
3010 not a very exciting feature. We pick a BFD reloc type in
3012 for (i = 0; i < fc; i++)
3014 if (fixups[i].reloc != BFD_RELOC_UNUSED)
3016 reloc_howto_type *reloc_howto;
3021 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
3025 size = bfd_get_reloc_size (reloc_howto);
3026 offset = target_big_endian ? (4 - size) : 0;
3028 if (size < 1 || size > 4)
3031 fixP = fix_new_exp (frag_now,
3032 f - frag_now->fr_literal + offset,
3035 reloc_howto->pc_relative,
3038 /* Turn off complaints that the addend is too large for things like
3040 switch (fixups[i].reloc)
3042 case BFD_RELOC_16_GOTOFF:
3043 case BFD_RELOC_PPC_TOC16:
3044 case BFD_RELOC_LO16:
3045 case BFD_RELOC_HI16:
3046 case BFD_RELOC_HI16_S:
3048 case BFD_RELOC_PPC64_HIGHER:
3049 case BFD_RELOC_PPC64_HIGHER_S:
3050 case BFD_RELOC_PPC64_HIGHEST:
3051 case BFD_RELOC_PPC64_HIGHEST_S:
3053 fixP->fx_no_overflow = 1;
3061 const struct powerpc_operand *operand;
3063 operand = &powerpc_operands[fixups[i].opindex];
3064 fix_new_exp (frag_now,
3065 f - frag_now->fr_literal,
3068 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
3069 ((bfd_reloc_code_real_type)
3070 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
3075 /* Handle a macro. Gather all the operands, transform them as
3076 described by the macro, and call md_assemble recursively. All the
3077 operands are separated by commas; we don't accept parentheses
3078 around operands here. */
3081 ppc_macro (char *str, const struct powerpc_macro *macro)
3092 /* Gather the users operands into the operands array. */
3097 if (count >= sizeof operands / sizeof operands[0])
3099 operands[count++] = s;
3100 s = strchr (s, ',');
3101 if (s == (char *) NULL)
3106 if (count != macro->operands)
3108 as_bad (_("wrong number of operands"));
3112 /* Work out how large the string must be (the size is unbounded
3113 because it includes user input). */
3115 format = macro->format;
3116 while (*format != '\0')
3125 arg = strtol (format + 1, &send, 10);
3126 know (send != format && arg < count);
3127 len += strlen (operands[arg]);
3132 /* Put the string together. */
3133 complete = s = (char *) alloca (len + 1);
3134 format = macro->format;
3135 while (*format != '\0')
3141 arg = strtol (format + 1, &send, 10);
3142 strcpy (s, operands[arg]);
3149 /* Assemble the constructed instruction. */
3150 md_assemble (complete);
3154 /* For ELF, add support for SHT_ORDERED. */
3157 ppc_section_type (char *str, size_t len)
3159 if (len == 7 && strncmp (str, "ordered", 7) == 0)
3166 ppc_section_flags (flagword flags, bfd_vma attr ATTRIBUTE_UNUSED, int type)
3168 if (type == SHT_ORDERED)
3169 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
3173 #endif /* OBJ_ELF */
3176 /* Pseudo-op handling. */
3178 /* The .byte pseudo-op. This is similar to the normal .byte
3179 pseudo-op, but it can also take a single ASCII string. */
3182 ppc_byte (int ignore ATTRIBUTE_UNUSED)
3184 if (*input_line_pointer != '\"')
3190 /* Gather characters. A real double quote is doubled. Unusual
3191 characters are not permitted. */
3192 ++input_line_pointer;
3197 c = *input_line_pointer++;
3201 if (*input_line_pointer != '\"')
3203 ++input_line_pointer;
3206 FRAG_APPEND_1_CHAR (c);
3209 demand_empty_rest_of_line ();
3214 /* XCOFF specific pseudo-op handling. */
3216 /* This is set if we are creating a .stabx symbol, since we don't want
3217 to handle symbol suffixes for such symbols. */
3218 static bfd_boolean ppc_stab_symbol;
3220 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
3221 symbols in the .bss segment as though they were local common
3222 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
3223 aligns .comm and .lcomm to 4 bytes. */
3226 ppc_comm (int lcomm)
3228 asection *current_seg = now_seg;
3229 subsegT current_subseg = now_subseg;
3235 symbolS *lcomm_sym = NULL;
3239 name = input_line_pointer;
3240 endc = get_symbol_end ();
3241 end_name = input_line_pointer;
3244 if (*input_line_pointer != ',')
3246 as_bad (_("missing size"));
3247 ignore_rest_of_line ();
3250 ++input_line_pointer;
3252 size = get_absolute_expression ();
3255 as_bad (_("negative size"));
3256 ignore_rest_of_line ();
3262 /* The third argument to .comm is the alignment. */
3263 if (*input_line_pointer != ',')
3267 ++input_line_pointer;
3268 align = get_absolute_expression ();
3271 as_warn (_("ignoring bad alignment"));
3286 /* The third argument to .lcomm appears to be the real local
3287 common symbol to create. References to the symbol named in
3288 the first argument are turned into references to the third
3290 if (*input_line_pointer != ',')
3292 as_bad (_("missing real symbol name"));
3293 ignore_rest_of_line ();
3296 ++input_line_pointer;
3298 lcomm_name = input_line_pointer;
3299 lcomm_endc = get_symbol_end ();
3301 lcomm_sym = symbol_find_or_make (lcomm_name);
3303 *input_line_pointer = lcomm_endc;
3307 sym = symbol_find_or_make (name);
3310 if (S_IS_DEFINED (sym)
3311 || S_GET_VALUE (sym) != 0)
3313 as_bad (_("attempt to redefine symbol"));
3314 ignore_rest_of_line ();
3318 record_alignment (bss_section, align);
3321 || ! S_IS_DEFINED (lcomm_sym))
3330 S_SET_EXTERNAL (sym);
3334 symbol_get_tc (lcomm_sym)->output = 1;
3335 def_sym = lcomm_sym;
3339 subseg_set (bss_section, 1);
3340 frag_align (align, 0, 0);
3342 symbol_set_frag (def_sym, frag_now);
3343 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
3344 def_size, (char *) NULL);
3346 S_SET_SEGMENT (def_sym, bss_section);
3347 symbol_get_tc (def_sym)->align = align;
3351 /* Align the size of lcomm_sym. */
3352 symbol_get_frag (lcomm_sym)->fr_offset =
3353 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
3354 &~ ((1 << align) - 1));
3355 if (align > symbol_get_tc (lcomm_sym)->align)
3356 symbol_get_tc (lcomm_sym)->align = align;
3361 /* Make sym an offset from lcomm_sym. */
3362 S_SET_SEGMENT (sym, bss_section);
3363 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
3364 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
3365 symbol_get_frag (lcomm_sym)->fr_offset += size;
3368 subseg_set (current_seg, current_subseg);
3370 demand_empty_rest_of_line ();
3373 /* The .csect pseudo-op. This switches us into a different
3374 subsegment. The first argument is a symbol whose value is the
3375 start of the .csect. In COFF, csect symbols get special aux
3376 entries defined by the x_csect field of union internal_auxent. The
3377 optional second argument is the alignment (the default is 2). */
3380 ppc_csect (int ignore ATTRIBUTE_UNUSED)
3387 name = input_line_pointer;
3388 endc = get_symbol_end ();
3390 sym = symbol_find_or_make (name);
3392 *input_line_pointer = endc;
3394 if (S_GET_NAME (sym)[0] == '\0')
3396 /* An unnamed csect is assumed to be [PR]. */
3397 symbol_get_tc (sym)->symbol_class = XMC_PR;
3401 if (*input_line_pointer == ',')
3403 ++input_line_pointer;
3404 align = get_absolute_expression ();
3407 ppc_change_csect (sym, align);
3409 demand_empty_rest_of_line ();
3412 /* Change to a different csect. */
3415 ppc_change_csect (symbolS *sym, offsetT align)
3417 if (S_IS_DEFINED (sym))
3418 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
3428 /* This is a new csect. We need to look at the symbol class to
3429 figure out whether it should go in the text section or the
3433 switch (symbol_get_tc (sym)->symbol_class)
3443 S_SET_SEGMENT (sym, text_section);
3444 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
3445 ++ppc_text_subsegment;
3446 list_ptr = &ppc_text_csects;
3456 if (ppc_toc_csect != NULL
3457 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
3458 == ppc_data_subsegment))
3460 S_SET_SEGMENT (sym, data_section);
3461 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
3462 ++ppc_data_subsegment;
3463 list_ptr = &ppc_data_csects;
3469 /* We set the obstack chunk size to a small value before
3470 changing subsegments, so that we don't use a lot of memory
3471 space for what may be a small section. */
3472 hold_chunksize = chunksize;
3475 sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
3476 symbol_get_tc (sym)->subseg);
3478 chunksize = hold_chunksize;
3481 ppc_after_toc_frag = frag_now;
3483 record_alignment (sec, align);
3485 frag_align_code (align, 0);
3487 frag_align (align, 0, 0);
3489 symbol_set_frag (sym, frag_now);
3490 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3492 symbol_get_tc (sym)->align = align;
3493 symbol_get_tc (sym)->output = 1;
3494 symbol_get_tc (sym)->within = sym;
3496 for (list = *list_ptr;
3497 symbol_get_tc (list)->next != (symbolS *) NULL;
3498 list = symbol_get_tc (list)->next)
3500 symbol_get_tc (list)->next = sym;
3502 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3503 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3507 ppc_current_csect = sym;
3511 ppc_change_debug_section (unsigned int idx, subsegT subseg)
3515 const struct xcoff_dwsect_name *dw = &xcoff_dwsect_names[idx];
3517 sec = subseg_new (dw->name, subseg);
3518 oldflags = bfd_get_section_flags (stdoutput, sec);
3519 if (oldflags == SEC_NO_FLAGS)
3521 /* Just created section. */
3522 gas_assert (dw_sections[idx].sect == NULL);
3524 bfd_set_section_flags (stdoutput, sec, SEC_DEBUGGING);
3525 bfd_set_section_alignment (stdoutput, sec, 0);
3526 dw_sections[idx].sect = sec;
3529 /* Not anymore in a csect. */
3530 ppc_current_csect = NULL;
3533 /* The .dwsect pseudo-op. Defines a DWARF section. Syntax is:
3534 .dwsect flag [, opt-label ]
3538 ppc_dwsect (int ignore ATTRIBUTE_UNUSED)
3542 const struct xcoff_dwsect_name *dw;
3543 struct dw_subsection *subseg;
3544 struct dw_section *dws;
3548 flag = get_absolute_expression ();
3550 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
3551 if (xcoff_dwsect_names[i].flag == flag)
3553 dw = &xcoff_dwsect_names[i];
3557 /* Parse opt-label. */
3558 if (*input_line_pointer == ',')
3563 ++input_line_pointer;
3565 label = input_line_pointer;
3566 c = get_symbol_end ();
3567 opt_label = symbol_find_or_make (label);
3568 *input_line_pointer = c;
3573 demand_empty_rest_of_line ();
3575 /* Return now in case of unknown subsection. */
3578 as_bad (_("No known dwarf XCOFF section for flag 0x%08x\n"),
3583 /* Find the subsection. */
3584 dws = &dw_sections[i];
3586 if (opt_label != NULL && S_IS_DEFINED (opt_label))
3588 /* Sanity check (note that in theory S_GET_SEGMENT mustn't be null). */
3589 if (dws->sect == NULL || S_GET_SEGMENT (opt_label) != dws->sect)
3591 as_bad (_("label %s was not defined in this dwarf section"),
3592 S_GET_NAME (opt_label));
3593 subseg = dws->anon_subseg;
3597 subseg = symbol_get_tc (opt_label)->u.dw;
3602 /* Switch to the subsection. */
3603 ppc_change_debug_section (i, subseg->subseg);
3607 /* Create a new dw subsection. */
3608 subseg = (struct dw_subsection *)
3609 xmalloc (sizeof (struct dw_subsection));
3611 if (opt_label == NULL)
3613 /* The anonymous one. */
3615 subseg->link = NULL;
3616 dws->anon_subseg = subseg;
3621 if (dws->list_subseg != NULL)
3622 subseg->subseg = dws->list_subseg->subseg + 1;
3626 subseg->link = dws->list_subseg;
3627 dws->list_subseg = subseg;
3628 symbol_get_tc (opt_label)->u.dw = subseg;
3631 ppc_change_debug_section (i, subseg->subseg);
3635 /* Add the length field. */
3636 expressionS *exp = &subseg->end_exp;
3639 if (opt_label != NULL)
3640 symbol_set_value_now (opt_label);
3642 /* Add the length field. Note that according to the AIX assembler
3643 manual, the size of the length field is 4 for powerpc32 but
3644 12 for powerpc64. */
3647 /* Write the 64bit marker. */
3648 md_number_to_chars (frag_more (4), -1, 4);
3651 exp->X_op = O_subtract;
3652 exp->X_op_symbol = symbol_temp_new_now ();
3653 exp->X_add_symbol = symbol_temp_make ();
3655 sz = ppc_obj64 ? 8 : 4;
3656 exp->X_add_number = -sz;
3657 emit_expr (exp, sz);
3662 /* This function handles the .text and .data pseudo-ops. These
3663 pseudo-ops aren't really used by XCOFF; we implement them for the
3664 convenience of people who aren't used to XCOFF. */
3667 ppc_section (int type)
3674 else if (type == 'd')
3679 sym = symbol_find_or_make (name);
3681 ppc_change_csect (sym, 2);
3683 demand_empty_rest_of_line ();
3686 /* This function handles the .section pseudo-op. This is mostly to
3687 give an error, since XCOFF only supports .text, .data and .bss, but
3688 we do permit the user to name the text or data section. */
3691 ppc_named_section (int ignore ATTRIBUTE_UNUSED)
3694 const char *real_name;
3698 user_name = input_line_pointer;
3699 c = get_symbol_end ();
3701 if (strcmp (user_name, ".text") == 0)
3702 real_name = ".text[PR]";
3703 else if (strcmp (user_name, ".data") == 0)
3704 real_name = ".data[RW]";
3707 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3708 *input_line_pointer = c;
3709 ignore_rest_of_line ();
3713 *input_line_pointer = c;
3715 sym = symbol_find_or_make (real_name);
3717 ppc_change_csect (sym, 2);
3719 demand_empty_rest_of_line ();
3722 /* The .extern pseudo-op. We create an undefined symbol. */
3725 ppc_extern (int ignore ATTRIBUTE_UNUSED)
3730 name = input_line_pointer;
3731 endc = get_symbol_end ();
3733 (void) symbol_find_or_make (name);
3735 *input_line_pointer = endc;
3737 demand_empty_rest_of_line ();
3740 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3743 ppc_lglobl (int ignore ATTRIBUTE_UNUSED)
3749 name = input_line_pointer;
3750 endc = get_symbol_end ();
3752 sym = symbol_find_or_make (name);
3754 *input_line_pointer = endc;
3756 symbol_get_tc (sym)->output = 1;
3758 demand_empty_rest_of_line ();
3761 /* The .ref pseudo-op. It takes a list of symbol names and inserts R_REF
3762 relocations at the beginning of the current csect.
3764 (In principle, there's no reason why the relocations _have_ to be at
3765 the beginning. Anywhere in the csect would do. However, inserting
3766 at the beginning is what the native assmebler does, and it helps to
3767 deal with cases where the .ref statements follow the section contents.)
3769 ??? .refs don't work for empty .csects. However, the native assembler
3770 doesn't report an error in this case, and neither yet do we. */
3773 ppc_ref (int ignore ATTRIBUTE_UNUSED)
3778 if (ppc_current_csect == NULL)
3780 as_bad (_(".ref outside .csect"));
3781 ignore_rest_of_line ();
3787 name = input_line_pointer;
3788 c = get_symbol_end ();
3790 fix_at_start (symbol_get_frag (ppc_current_csect), 0,
3791 symbol_find_or_make (name), 0, FALSE, BFD_RELOC_NONE);
3793 *input_line_pointer = c;
3795 c = *input_line_pointer;
3798 input_line_pointer++;
3800 if (is_end_of_line[(unsigned char) *input_line_pointer])
3802 as_bad (_("missing symbol name"));
3803 ignore_rest_of_line ();
3810 demand_empty_rest_of_line ();
3813 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3814 although I don't know why it bothers. */
3817 ppc_rename (int ignore ATTRIBUTE_UNUSED)
3824 name = input_line_pointer;
3825 endc = get_symbol_end ();
3827 sym = symbol_find_or_make (name);
3829 *input_line_pointer = endc;
3831 if (*input_line_pointer != ',')
3833 as_bad (_("missing rename string"));
3834 ignore_rest_of_line ();
3837 ++input_line_pointer;
3839 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
3841 demand_empty_rest_of_line ();
3844 /* The .stabx pseudo-op. This is similar to a normal .stabs
3845 pseudo-op, but slightly different. A sample is
3846 .stabx "main:F-1",.main,142,0
3847 The first argument is the symbol name to create. The second is the
3848 value, and the third is the storage class. The fourth seems to be
3849 always zero, and I am assuming it is the type. */
3852 ppc_stabx (int ignore ATTRIBUTE_UNUSED)
3859 name = demand_copy_C_string (&len);
3861 if (*input_line_pointer != ',')
3863 as_bad (_("missing value"));
3866 ++input_line_pointer;
3868 ppc_stab_symbol = TRUE;
3869 sym = symbol_make (name);
3870 ppc_stab_symbol = FALSE;
3872 symbol_get_tc (sym)->real_name = name;
3874 (void) expression (&exp);
3881 as_bad (_("illegal .stabx expression; zero assumed"));
3882 exp.X_add_number = 0;
3885 S_SET_VALUE (sym, (valueT) exp.X_add_number);
3886 symbol_set_frag (sym, &zero_address_frag);
3890 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3891 symbol_set_value_expression (sym, &exp);
3895 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3896 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3901 /* The value is some complex expression. This will probably
3902 fail at some later point, but this is probably the right
3903 thing to do here. */
3904 symbol_set_value_expression (sym, &exp);
3908 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3909 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3911 if (*input_line_pointer != ',')
3913 as_bad (_("missing class"));
3916 ++input_line_pointer;
3918 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3920 if (*input_line_pointer != ',')
3922 as_bad (_("missing type"));
3925 ++input_line_pointer;
3927 S_SET_DATA_TYPE (sym, get_absolute_expression ());
3929 symbol_get_tc (sym)->output = 1;
3931 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
3936 .stabx "z",arrays_,133,0
3939 .comm arrays_,13768,3
3941 resolve_symbol_value will copy the exp's "within" into sym's when the
3942 offset is 0. Since this seems to be corner case problem,
3943 only do the correction for storage class C_STSYM. A better solution
3944 would be to have the tc field updated in ppc_symbol_new_hook. */
3946 if (exp.X_op == O_symbol)
3948 if (ppc_current_block == NULL)
3949 as_bad (_(".stabx of storage class stsym must be within .bs/.es"));
3951 symbol_get_tc (sym)->within = ppc_current_block;
3952 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3956 if (exp.X_op != O_symbol
3957 || ! S_IS_EXTERNAL (exp.X_add_symbol)
3958 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3959 ppc_frob_label (sym);
3962 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3963 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3964 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3965 symbol_get_tc (ppc_current_csect)->within = sym;
3968 demand_empty_rest_of_line ();
3971 /* The .function pseudo-op. This takes several arguments. The first
3972 argument seems to be the external name of the symbol. The second
3973 argument seems to be the label for the start of the function. gcc
3974 uses the same name for both. I have no idea what the third and
3975 fourth arguments are meant to be. The optional fifth argument is
3976 an expression for the size of the function. In COFF this symbol
3977 gets an aux entry like that used for a csect. */
3980 ppc_function (int ignore ATTRIBUTE_UNUSED)
3988 name = input_line_pointer;
3989 endc = get_symbol_end ();
3991 /* Ignore any [PR] suffix. */
3992 name = ppc_canonicalize_symbol_name (name);
3993 s = strchr (name, '[');
3994 if (s != (char *) NULL
3995 && strcmp (s + 1, "PR]") == 0)
3998 ext_sym = symbol_find_or_make (name);
4000 *input_line_pointer = endc;
4002 if (*input_line_pointer != ',')
4004 as_bad (_("missing symbol name"));
4005 ignore_rest_of_line ();
4008 ++input_line_pointer;
4010 name = input_line_pointer;
4011 endc = get_symbol_end ();
4013 lab_sym = symbol_find_or_make (name);
4015 *input_line_pointer = endc;
4017 if (ext_sym != lab_sym)
4021 exp.X_op = O_symbol;
4022 exp.X_add_symbol = lab_sym;
4023 exp.X_op_symbol = NULL;
4024 exp.X_add_number = 0;
4026 symbol_set_value_expression (ext_sym, &exp);
4029 if (symbol_get_tc (ext_sym)->symbol_class == -1)
4030 symbol_get_tc (ext_sym)->symbol_class = XMC_PR;
4031 symbol_get_tc (ext_sym)->output = 1;
4033 if (*input_line_pointer == ',')
4037 /* Ignore the third argument. */
4038 ++input_line_pointer;
4040 if (*input_line_pointer == ',')
4042 /* Ignore the fourth argument. */
4043 ++input_line_pointer;
4045 if (*input_line_pointer == ',')
4047 /* The fifth argument is the function size. */
4048 ++input_line_pointer;
4049 symbol_get_tc (ext_sym)->u.size = symbol_new
4050 ("L0\001", absolute_section,(valueT) 0, &zero_address_frag);
4051 pseudo_set (symbol_get_tc (ext_sym)->u.size);
4056 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4057 SF_SET_FUNCTION (ext_sym);
4058 SF_SET_PROCESS (ext_sym);
4059 coff_add_linesym (ext_sym);
4061 demand_empty_rest_of_line ();
4064 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
4065 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
4066 with the correct line number */
4068 static symbolS *saved_bi_sym = 0;
4071 ppc_bf (int ignore ATTRIBUTE_UNUSED)
4075 sym = symbol_make (".bf");
4076 S_SET_SEGMENT (sym, text_section);
4077 symbol_set_frag (sym, frag_now);
4078 S_SET_VALUE (sym, frag_now_fix ());
4079 S_SET_STORAGE_CLASS (sym, C_FCN);
4081 coff_line_base = get_absolute_expression ();
4083 S_SET_NUMBER_AUXILIARY (sym, 1);
4084 SA_SET_SYM_LNNO (sym, coff_line_base);
4086 /* Line number for bi. */
4089 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
4094 symbol_get_tc (sym)->output = 1;
4096 ppc_frob_label (sym);
4098 demand_empty_rest_of_line ();
4101 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
4102 ".ef", except that the line number is absolute, not relative to the
4103 most recent ".bf" symbol. */
4106 ppc_ef (int ignore ATTRIBUTE_UNUSED)
4110 sym = symbol_make (".ef");
4111 S_SET_SEGMENT (sym, text_section);
4112 symbol_set_frag (sym, frag_now);
4113 S_SET_VALUE (sym, frag_now_fix ());
4114 S_SET_STORAGE_CLASS (sym, C_FCN);
4115 S_SET_NUMBER_AUXILIARY (sym, 1);
4116 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4117 symbol_get_tc (sym)->output = 1;
4119 ppc_frob_label (sym);
4121 demand_empty_rest_of_line ();
4124 /* The .bi and .ei pseudo-ops. These take a string argument and
4125 generates a C_BINCL or C_EINCL symbol, which goes at the start of
4126 the symbol list. The value of .bi will be know when the next .bf
4132 static symbolS *last_biei;
4139 name = demand_copy_C_string (&len);
4141 /* The value of these symbols is actually file offset. Here we set
4142 the value to the index into the line number entries. In
4143 ppc_frob_symbols we set the fix_line field, which will cause BFD
4144 to do the right thing. */
4146 sym = symbol_make (name);
4147 /* obj-coff.c currently only handles line numbers correctly in the
4149 S_SET_SEGMENT (sym, text_section);
4150 S_SET_VALUE (sym, coff_n_line_nos);
4151 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4153 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
4154 symbol_get_tc (sym)->output = 1;
4162 for (look = last_biei ? last_biei : symbol_rootP;
4163 (look != (symbolS *) NULL
4164 && (S_GET_STORAGE_CLASS (look) == C_FILE
4165 || S_GET_STORAGE_CLASS (look) == C_BINCL
4166 || S_GET_STORAGE_CLASS (look) == C_EINCL));
4167 look = symbol_next (look))
4169 if (look != (symbolS *) NULL)
4171 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4172 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
4176 demand_empty_rest_of_line ();
4179 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
4180 There is one argument, which is a csect symbol. The value of the
4181 .bs symbol is the index of this csect symbol. */
4184 ppc_bs (int ignore ATTRIBUTE_UNUSED)
4191 if (ppc_current_block != NULL)
4192 as_bad (_("nested .bs blocks"));
4194 name = input_line_pointer;
4195 endc = get_symbol_end ();
4197 csect = symbol_find_or_make (name);
4199 *input_line_pointer = endc;
4201 sym = symbol_make (".bs");
4202 S_SET_SEGMENT (sym, now_seg);
4203 S_SET_STORAGE_CLASS (sym, C_BSTAT);
4204 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4205 symbol_get_tc (sym)->output = 1;
4207 symbol_get_tc (sym)->within = csect;
4209 ppc_frob_label (sym);
4211 ppc_current_block = sym;
4213 demand_empty_rest_of_line ();
4216 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
4219 ppc_es (int ignore ATTRIBUTE_UNUSED)
4223 if (ppc_current_block == NULL)
4224 as_bad (_(".es without preceding .bs"));
4226 sym = symbol_make (".es");
4227 S_SET_SEGMENT (sym, now_seg);
4228 S_SET_STORAGE_CLASS (sym, C_ESTAT);
4229 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4230 symbol_get_tc (sym)->output = 1;
4232 ppc_frob_label (sym);
4234 ppc_current_block = NULL;
4236 demand_empty_rest_of_line ();
4239 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
4243 ppc_bb (int ignore ATTRIBUTE_UNUSED)
4247 sym = symbol_make (".bb");
4248 S_SET_SEGMENT (sym, text_section);
4249 symbol_set_frag (sym, frag_now);
4250 S_SET_VALUE (sym, frag_now_fix ());
4251 S_SET_STORAGE_CLASS (sym, C_BLOCK);
4253 S_SET_NUMBER_AUXILIARY (sym, 1);
4254 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4256 symbol_get_tc (sym)->output = 1;
4258 SF_SET_PROCESS (sym);
4260 ppc_frob_label (sym);
4262 demand_empty_rest_of_line ();
4265 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
4269 ppc_eb (int ignore ATTRIBUTE_UNUSED)
4273 sym = symbol_make (".eb");
4274 S_SET_SEGMENT (sym, text_section);
4275 symbol_set_frag (sym, frag_now);
4276 S_SET_VALUE (sym, frag_now_fix ());
4277 S_SET_STORAGE_CLASS (sym, C_BLOCK);
4278 S_SET_NUMBER_AUXILIARY (sym, 1);
4279 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4280 symbol_get_tc (sym)->output = 1;
4282 SF_SET_PROCESS (sym);
4284 ppc_frob_label (sym);
4286 demand_empty_rest_of_line ();
4289 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
4293 ppc_bc (int ignore ATTRIBUTE_UNUSED)
4299 name = demand_copy_C_string (&len);
4300 sym = symbol_make (name);
4301 S_SET_SEGMENT (sym, ppc_coff_debug_section);
4302 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4303 S_SET_STORAGE_CLASS (sym, C_BCOMM);
4304 S_SET_VALUE (sym, 0);
4305 symbol_get_tc (sym)->output = 1;
4307 ppc_frob_label (sym);
4309 demand_empty_rest_of_line ();
4312 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
4315 ppc_ec (int ignore ATTRIBUTE_UNUSED)
4319 sym = symbol_make (".ec");
4320 S_SET_SEGMENT (sym, ppc_coff_debug_section);
4321 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4322 S_SET_STORAGE_CLASS (sym, C_ECOMM);
4323 S_SET_VALUE (sym, 0);
4324 symbol_get_tc (sym)->output = 1;
4326 ppc_frob_label (sym);
4328 demand_empty_rest_of_line ();
4331 /* The .toc pseudo-op. Switch to the .toc subsegment. */
4334 ppc_toc (int ignore ATTRIBUTE_UNUSED)
4336 if (ppc_toc_csect != (symbolS *) NULL)
4337 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
4344 subseg = ppc_data_subsegment;
4345 ++ppc_data_subsegment;
4347 subseg_new (segment_name (data_section), subseg);
4348 ppc_toc_frag = frag_now;
4350 sym = symbol_find_or_make ("TOC[TC0]");
4351 symbol_set_frag (sym, frag_now);
4352 S_SET_SEGMENT (sym, data_section);
4353 S_SET_VALUE (sym, (valueT) frag_now_fix ());
4354 symbol_get_tc (sym)->subseg = subseg;
4355 symbol_get_tc (sym)->output = 1;
4356 symbol_get_tc (sym)->within = sym;
4358 ppc_toc_csect = sym;
4360 for (list = ppc_data_csects;
4361 symbol_get_tc (list)->next != (symbolS *) NULL;
4362 list = symbol_get_tc (list)->next)
4364 symbol_get_tc (list)->next = sym;
4366 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4367 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
4371 ppc_current_csect = ppc_toc_csect;
4373 demand_empty_rest_of_line ();
4376 /* The AIX assembler automatically aligns the operands of a .long or
4377 .short pseudo-op, and we want to be compatible. */
4380 ppc_xcoff_cons (int log_size)
4382 frag_align (log_size, 0, 0);
4383 record_alignment (now_seg, log_size);
4384 cons (1 << log_size);
4388 ppc_vbyte (int dummy ATTRIBUTE_UNUSED)
4393 (void) expression (&exp);
4395 if (exp.X_op != O_constant)
4397 as_bad (_("non-constant byte count"));
4401 byte_count = exp.X_add_number;
4403 if (*input_line_pointer != ',')
4405 as_bad (_("missing value"));
4409 ++input_line_pointer;
4414 ppc_xcoff_end (void)
4418 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
4420 struct dw_section *dws = &dw_sections[i];
4421 struct dw_subsection *dwss;
4423 if (dws->anon_subseg)
4425 dwss = dws->anon_subseg;
4426 dwss->link = dws->list_subseg;
4429 dwss = dws->list_subseg;
4431 for (; dwss != NULL; dwss = dwss->link)
4432 if (dwss->end_exp.X_add_symbol != NULL)
4434 subseg_set (dws->sect, dwss->subseg);
4435 symbol_set_value_now (dwss->end_exp.X_add_symbol);
4440 #endif /* OBJ_XCOFF */
4441 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
4443 /* The .tc pseudo-op. This is used when generating either XCOFF or
4444 ELF. This takes two or more arguments.
4446 When generating XCOFF output, the first argument is the name to
4447 give to this location in the toc; this will be a symbol with class
4448 TC. The rest of the arguments are N-byte values to actually put at
4449 this location in the TOC; often there is just one more argument, a
4450 relocatable symbol reference. The size of the value to store
4451 depends on target word size. A 32-bit target uses 4-byte values, a
4452 64-bit target uses 8-byte values.
4454 When not generating XCOFF output, the arguments are the same, but
4455 the first argument is simply ignored. */
4458 ppc_tc (int ignore ATTRIBUTE_UNUSED)
4462 /* Define the TOC symbol name. */
4468 if (ppc_toc_csect == (symbolS *) NULL
4469 || ppc_toc_csect != ppc_current_csect)
4471 as_bad (_(".tc not in .toc section"));
4472 ignore_rest_of_line ();
4476 name = input_line_pointer;
4477 endc = get_symbol_end ();
4479 sym = symbol_find_or_make (name);
4481 *input_line_pointer = endc;
4483 if (S_IS_DEFINED (sym))
4487 label = symbol_get_tc (ppc_current_csect)->within;
4488 if (symbol_get_tc (label)->symbol_class != XMC_TC0)
4490 as_bad (_(".tc with no label"));
4491 ignore_rest_of_line ();
4495 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
4496 symbol_set_frag (label, symbol_get_frag (sym));
4497 S_SET_VALUE (label, S_GET_VALUE (sym));
4499 while (! is_end_of_line[(unsigned char) *input_line_pointer])
4500 ++input_line_pointer;
4505 S_SET_SEGMENT (sym, now_seg);
4506 symbol_set_frag (sym, frag_now);
4507 S_SET_VALUE (sym, (valueT) frag_now_fix ());
4508 symbol_get_tc (sym)->symbol_class = XMC_TC;
4509 symbol_get_tc (sym)->output = 1;
4511 ppc_frob_label (sym);
4514 #endif /* OBJ_XCOFF */
4518 /* Skip the TOC symbol name. */
4519 while (is_part_of_name (*input_line_pointer)
4520 || *input_line_pointer == ' '
4521 || *input_line_pointer == '['
4522 || *input_line_pointer == ']'
4523 || *input_line_pointer == '{'
4524 || *input_line_pointer == '}')
4525 ++input_line_pointer;
4527 /* Align to a four/eight byte boundary. */
4528 align = ppc_obj64 ? 3 : 2;
4529 frag_align (align, 0, 0);
4530 record_alignment (now_seg, align);
4531 #endif /* OBJ_ELF */
4533 if (*input_line_pointer != ',')
4534 demand_empty_rest_of_line ();
4537 ++input_line_pointer;
4538 cons (ppc_obj64 ? 8 : 4);
4542 /* Pseudo-op .machine. */
4545 ppc_machine (int ignore ATTRIBUTE_UNUSED)
4548 #define MAX_HISTORY 100
4549 static ppc_cpu_t *cpu_history;
4550 static int curr_hist;
4554 if (*input_line_pointer == '"')
4557 cpu_string = demand_copy_C_string (&len);
4562 cpu_string = input_line_pointer;
4563 c = get_symbol_end ();
4564 cpu_string = xstrdup (cpu_string);
4565 *input_line_pointer = c;
4568 if (cpu_string != NULL)
4570 ppc_cpu_t old_cpu = ppc_cpu;
4574 for (p = cpu_string; *p != 0; p++)
4577 if (strcmp (cpu_string, "push") == 0)
4579 if (cpu_history == NULL)
4580 cpu_history = xmalloc (MAX_HISTORY * sizeof (*cpu_history));
4582 if (curr_hist >= MAX_HISTORY)
4583 as_bad (_(".machine stack overflow"));
4585 cpu_history[curr_hist++] = ppc_cpu;
4587 else if (strcmp (cpu_string, "pop") == 0)
4590 as_bad (_(".machine stack underflow"));
4592 ppc_cpu = cpu_history[--curr_hist];
4594 else if ((new_cpu = ppc_parse_cpu (ppc_cpu, cpu_string)) != 0)
4597 as_bad (_("invalid machine `%s'"), cpu_string);
4599 if (ppc_cpu != old_cpu)
4600 ppc_setup_opcodes ();
4603 demand_empty_rest_of_line ();
4606 /* See whether a symbol is in the TOC section. */
4609 ppc_is_toc_sym (symbolS *sym)
4612 return symbol_get_tc (sym)->symbol_class == XMC_TC;
4615 const char *sname = segment_name (S_GET_SEGMENT (sym));
4617 return strcmp (sname, ".toc") == 0;
4619 return strcmp (sname, ".got") == 0;
4622 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4626 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4628 /* Set the current section. */
4630 ppc_set_current_section (segT new)
4632 ppc_previous_section = ppc_current_section;
4633 ppc_current_section = new;
4636 /* pseudo-op: .previous
4637 behaviour: toggles the current section with the previous section.
4639 warnings: "No previous section" */
4642 ppc_previous (int ignore ATTRIBUTE_UNUSED)
4646 if (ppc_previous_section == NULL)
4648 as_warn (_("No previous section to return to. Directive ignored."));
4652 subseg_set (ppc_previous_section, 0);
4654 ppc_set_current_section (ppc_previous_section);
4657 /* pseudo-op: .pdata
4658 behaviour: predefined read only data section
4662 initial: .section .pdata "adr3"
4663 a - don't know -- maybe a misprint
4664 d - initialized data
4666 3 - double word aligned (that would be 4 byte boundary)
4669 Tag index tables (also known as the function table) for exception
4670 handling, debugging, etc. */
4673 ppc_pdata (int ignore ATTRIBUTE_UNUSED)
4675 if (pdata_section == 0)
4677 pdata_section = subseg_new (".pdata", 0);
4679 bfd_set_section_flags (stdoutput, pdata_section,
4680 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4681 | SEC_READONLY | SEC_DATA ));
4683 bfd_set_section_alignment (stdoutput, pdata_section, 2);
4687 pdata_section = subseg_new (".pdata", 0);
4689 ppc_set_current_section (pdata_section);
4692 /* pseudo-op: .ydata
4693 behaviour: predefined read only data section
4697 initial: .section .ydata "drw3"
4698 a - don't know -- maybe a misprint
4699 d - initialized data
4701 3 - double word aligned (that would be 4 byte boundary)
4703 Tag tables (also known as the scope table) for exception handling,
4707 ppc_ydata (int ignore ATTRIBUTE_UNUSED)
4709 if (ydata_section == 0)
4711 ydata_section = subseg_new (".ydata", 0);
4712 bfd_set_section_flags (stdoutput, ydata_section,
4713 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4714 | SEC_READONLY | SEC_DATA ));
4716 bfd_set_section_alignment (stdoutput, ydata_section, 3);
4720 ydata_section = subseg_new (".ydata", 0);
4722 ppc_set_current_section (ydata_section);
4725 /* pseudo-op: .reldata
4726 behaviour: predefined read write data section
4727 double word aligned (4-byte)
4728 FIXME: relocation is applied to it
4729 FIXME: what's the difference between this and .data?
4732 initial: .section .reldata "drw3"
4733 d - initialized data
4736 3 - double word aligned (that would be 8 byte boundary)
4739 Like .data, but intended to hold data subject to relocation, such as
4740 function descriptors, etc. */
4743 ppc_reldata (int ignore ATTRIBUTE_UNUSED)
4745 if (reldata_section == 0)
4747 reldata_section = subseg_new (".reldata", 0);
4749 bfd_set_section_flags (stdoutput, reldata_section,
4750 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4753 bfd_set_section_alignment (stdoutput, reldata_section, 2);
4757 reldata_section = subseg_new (".reldata", 0);
4759 ppc_set_current_section (reldata_section);
4762 /* pseudo-op: .rdata
4763 behaviour: predefined read only data section
4767 initial: .section .rdata "dr3"
4768 d - initialized data
4770 3 - double word aligned (that would be 4 byte boundary) */
4773 ppc_rdata (int ignore ATTRIBUTE_UNUSED)
4775 if (rdata_section == 0)
4777 rdata_section = subseg_new (".rdata", 0);
4778 bfd_set_section_flags (stdoutput, rdata_section,
4779 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4780 | SEC_READONLY | SEC_DATA ));
4782 bfd_set_section_alignment (stdoutput, rdata_section, 2);
4786 rdata_section = subseg_new (".rdata", 0);
4788 ppc_set_current_section (rdata_section);
4791 /* pseudo-op: .ualong
4792 behaviour: much like .int, with the exception that no alignment is
4794 FIXME: test the alignment statement
4799 ppc_ualong (int ignore ATTRIBUTE_UNUSED)
4805 /* pseudo-op: .znop <symbol name>
4806 behaviour: Issue a nop instruction
4807 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4808 the supplied symbol name.
4810 warnings: Missing symbol name */
4813 ppc_znop (int ignore ATTRIBUTE_UNUSED)
4816 const struct powerpc_opcode *opcode;
4827 /* Strip out the symbol name. */
4828 symbol_name = input_line_pointer;
4829 c = get_symbol_end ();
4831 name = xmalloc (input_line_pointer - symbol_name + 1);
4832 strcpy (name, symbol_name);
4834 sym = symbol_find_or_make (name);
4836 *input_line_pointer = c;
4840 /* Look up the opcode in the hash table. */
4841 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
4843 /* Stick in the nop. */
4844 insn = opcode->opcode;
4846 /* Write out the instruction. */
4848 md_number_to_chars (f, insn, 4);
4850 f - frag_now->fr_literal,
4855 BFD_RELOC_16_GOT_PCREL);
4865 ppc_pe_comm (int lcomm)
4874 name = input_line_pointer;
4875 c = get_symbol_end ();
4877 /* just after name is now '\0'. */
4878 p = input_line_pointer;
4881 if (*input_line_pointer != ',')
4883 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4884 ignore_rest_of_line ();
4888 input_line_pointer++; /* skip ',' */
4889 if ((temp = get_absolute_expression ()) < 0)
4891 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
4892 ignore_rest_of_line ();
4898 /* The third argument to .comm is the alignment. */
4899 if (*input_line_pointer != ',')
4903 ++input_line_pointer;
4904 align = get_absolute_expression ();
4907 as_warn (_("ignoring bad alignment"));
4914 symbolP = symbol_find_or_make (name);
4917 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4919 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4920 S_GET_NAME (symbolP));
4921 ignore_rest_of_line ();
4925 if (S_GET_VALUE (symbolP))
4927 if (S_GET_VALUE (symbolP) != (valueT) temp)
4928 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4929 S_GET_NAME (symbolP),
4930 (long) S_GET_VALUE (symbolP),
4935 S_SET_VALUE (symbolP, (valueT) temp);
4936 S_SET_EXTERNAL (symbolP);
4937 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
4940 demand_empty_rest_of_line ();
4944 * implement the .section pseudo op:
4945 * .section name {, "flags"}
4947 * | +--- optional flags: 'b' for bss
4949 * +-- section name 'l' for lib
4953 * 'd' (apparently m88k for data)
4955 * But if the argument is not a quoted string, treat it as a
4956 * subsegment number.
4958 * FIXME: this is a copy of the section processing from obj-coff.c, with
4959 * additions/changes for the moto-pas assembler support. There are three
4962 * FIXME: I just noticed this. This doesn't work at all really. It it
4963 * setting bits that bfd probably neither understands or uses. The
4964 * correct approach (?) will have to incorporate extra fields attached
4965 * to the section to hold the system specific stuff. (krk)
4968 * 'a' - unknown - referred to in documentation, but no definition supplied
4969 * 'c' - section has code
4970 * 'd' - section has initialized data
4971 * 'u' - section has uninitialized data
4972 * 'i' - section contains directives (info)
4973 * 'n' - section can be discarded
4974 * 'R' - remove section at link time
4976 * Section Protection:
4977 * 'r' - section is readable
4978 * 'w' - section is writeable
4979 * 'x' - section is executable
4980 * 's' - section is sharable
4982 * Section Alignment:
4983 * '0' - align to byte boundary
4984 * '1' - align to halfword undary
4985 * '2' - align to word boundary
4986 * '3' - align to doubleword boundary
4987 * '4' - align to quadword boundary
4988 * '5' - align to 32 byte boundary
4989 * '6' - align to 64 byte boundary
4994 ppc_pe_section (int ignore ATTRIBUTE_UNUSED)
4996 /* Strip out the section name. */
5005 section_name = input_line_pointer;
5006 c = get_symbol_end ();
5008 name = xmalloc (input_line_pointer - section_name + 1);
5009 strcpy (name, section_name);
5011 *input_line_pointer = c;
5016 flags = SEC_NO_FLAGS;
5018 if (strcmp (name, ".idata$2") == 0)
5022 else if (strcmp (name, ".idata$3") == 0)
5026 else if (strcmp (name, ".idata$4") == 0)
5030 else if (strcmp (name, ".idata$5") == 0)
5034 else if (strcmp (name, ".idata$6") == 0)
5039 /* Default alignment to 16 byte boundary. */
5042 if (*input_line_pointer == ',')
5044 ++input_line_pointer;
5046 if (*input_line_pointer != '"')
5047 exp = get_absolute_expression ();
5050 ++input_line_pointer;
5051 while (*input_line_pointer != '"'
5052 && ! is_end_of_line[(unsigned char) *input_line_pointer])
5054 switch (*input_line_pointer)
5056 /* Section Contents */
5057 case 'a': /* unknown */
5058 as_bad (_("Unsupported section attribute -- 'a'"));
5060 case 'c': /* code section */
5063 case 'd': /* section has initialized data */
5066 case 'u': /* section has uninitialized data */
5067 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
5071 case 'i': /* section contains directives (info) */
5072 /* FIXME: This is IMAGE_SCN_LNK_INFO
5074 flags |= SEC_HAS_CONTENTS;
5076 case 'n': /* section can be discarded */
5079 case 'R': /* Remove section at link time */
5080 flags |= SEC_NEVER_LOAD;
5082 #if IFLICT_BRAIN_DAMAGE
5083 /* Section Protection */
5084 case 'r': /* section is readable */
5085 flags |= IMAGE_SCN_MEM_READ;
5087 case 'w': /* section is writeable */
5088 flags |= IMAGE_SCN_MEM_WRITE;
5090 case 'x': /* section is executable */
5091 flags |= IMAGE_SCN_MEM_EXECUTE;
5093 case 's': /* section is sharable */
5094 flags |= IMAGE_SCN_MEM_SHARED;
5097 /* Section Alignment */
5098 case '0': /* align to byte boundary */
5099 flags |= IMAGE_SCN_ALIGN_1BYTES;
5102 case '1': /* align to halfword boundary */
5103 flags |= IMAGE_SCN_ALIGN_2BYTES;
5106 case '2': /* align to word boundary */
5107 flags |= IMAGE_SCN_ALIGN_4BYTES;
5110 case '3': /* align to doubleword boundary */
5111 flags |= IMAGE_SCN_ALIGN_8BYTES;
5114 case '4': /* align to quadword boundary */
5115 flags |= IMAGE_SCN_ALIGN_16BYTES;
5118 case '5': /* align to 32 byte boundary */
5119 flags |= IMAGE_SCN_ALIGN_32BYTES;
5122 case '6': /* align to 64 byte boundary */
5123 flags |= IMAGE_SCN_ALIGN_64BYTES;
5128 as_bad (_("unknown section attribute '%c'"),
5129 *input_line_pointer);
5132 ++input_line_pointer;
5134 if (*input_line_pointer == '"')
5135 ++input_line_pointer;
5139 sec = subseg_new (name, (subsegT) exp);
5141 ppc_set_current_section (sec);
5143 if (flags != SEC_NO_FLAGS)
5145 if (! bfd_set_section_flags (stdoutput, sec, flags))
5146 as_bad (_("error setting flags for \"%s\": %s"),
5147 bfd_section_name (stdoutput, sec),
5148 bfd_errmsg (bfd_get_error ()));
5151 bfd_set_section_alignment (stdoutput, sec, align);
5155 ppc_pe_function (int ignore ATTRIBUTE_UNUSED)
5161 name = input_line_pointer;
5162 endc = get_symbol_end ();
5164 ext_sym = symbol_find_or_make (name);
5166 *input_line_pointer = endc;
5168 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
5169 SF_SET_FUNCTION (ext_sym);
5170 SF_SET_PROCESS (ext_sym);
5171 coff_add_linesym (ext_sym);
5173 demand_empty_rest_of_line ();
5177 ppc_pe_tocd (int ignore ATTRIBUTE_UNUSED)
5179 if (tocdata_section == 0)
5181 tocdata_section = subseg_new (".tocd", 0);
5182 /* FIXME: section flags won't work. */
5183 bfd_set_section_flags (stdoutput, tocdata_section,
5184 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
5185 | SEC_READONLY | SEC_DATA));
5187 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
5191 rdata_section = subseg_new (".tocd", 0);
5194 ppc_set_current_section (tocdata_section);
5196 demand_empty_rest_of_line ();
5199 /* Don't adjust TOC relocs to use the section symbol. */
5202 ppc_pe_fix_adjustable (fixS *fix)
5204 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
5211 /* XCOFF specific symbol and file handling. */
5213 /* Canonicalize the symbol name. We use the to force the suffix, if
5214 any, to use square brackets, and to be in upper case. */
5217 ppc_canonicalize_symbol_name (char *name)
5221 if (ppc_stab_symbol)
5224 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
5238 for (s++; *s != '\0' && *s != brac; s++)
5241 if (*s == '\0' || s[1] != '\0')
5242 as_bad (_("bad symbol suffix"));
5250 /* Set the class of a symbol based on the suffix, if any. This is
5251 called whenever a new symbol is created. */
5254 ppc_symbol_new_hook (symbolS *sym)
5256 struct ppc_tc_sy *tc;
5259 tc = symbol_get_tc (sym);
5262 tc->symbol_class = -1;
5263 tc->real_name = NULL;
5270 if (ppc_stab_symbol)
5273 s = strchr (S_GET_NAME (sym), '[');
5274 if (s == (const char *) NULL)
5276 /* There is no suffix. */
5285 if (strcmp (s, "BS]") == 0)
5286 tc->symbol_class = XMC_BS;
5289 if (strcmp (s, "DB]") == 0)
5290 tc->symbol_class = XMC_DB;
5291 else if (strcmp (s, "DS]") == 0)
5292 tc->symbol_class = XMC_DS;
5295 if (strcmp (s, "GL]") == 0)
5296 tc->symbol_class = XMC_GL;
5299 if (strcmp (s, "PR]") == 0)
5300 tc->symbol_class = XMC_PR;
5303 if (strcmp (s, "RO]") == 0)
5304 tc->symbol_class = XMC_RO;
5305 else if (strcmp (s, "RW]") == 0)
5306 tc->symbol_class = XMC_RW;
5309 if (strcmp (s, "SV]") == 0)
5310 tc->symbol_class = XMC_SV;
5313 if (strcmp (s, "TC]") == 0)
5314 tc->symbol_class = XMC_TC;
5315 else if (strcmp (s, "TI]") == 0)
5316 tc->symbol_class = XMC_TI;
5317 else if (strcmp (s, "TB]") == 0)
5318 tc->symbol_class = XMC_TB;
5319 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
5320 tc->symbol_class = XMC_TC0;
5323 if (strcmp (s, "UA]") == 0)
5324 tc->symbol_class = XMC_UA;
5325 else if (strcmp (s, "UC]") == 0)
5326 tc->symbol_class = XMC_UC;
5329 if (strcmp (s, "XO]") == 0)
5330 tc->symbol_class = XMC_XO;
5334 if (tc->symbol_class == -1)
5335 as_bad (_("Unrecognized symbol suffix"));
5338 /* Set the class of a label based on where it is defined. This
5339 handles symbols without suffixes. Also, move the symbol so that it
5340 follows the csect symbol. */
5343 ppc_frob_label (symbolS *sym)
5345 if (ppc_current_csect != (symbolS *) NULL)
5347 if (symbol_get_tc (sym)->symbol_class == -1)
5348 symbol_get_tc (sym)->symbol_class = symbol_get_tc (ppc_current_csect)->symbol_class;
5350 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5351 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
5352 &symbol_rootP, &symbol_lastP);
5353 symbol_get_tc (ppc_current_csect)->within = sym;
5357 dwarf2_emit_label (sym);
5361 /* This variable is set by ppc_frob_symbol if any absolute symbols are
5362 seen. It tells ppc_adjust_symtab whether it needs to look through
5365 static bfd_boolean ppc_saw_abs;
5367 /* Change the name of a symbol just before writing it out. Set the
5368 real name if the .rename pseudo-op was used. Otherwise, remove any
5369 class suffix. Return 1 if the symbol should not be included in the
5373 ppc_frob_symbol (symbolS *sym)
5375 static symbolS *ppc_last_function;
5376 static symbolS *set_end;
5378 /* Discard symbols that should not be included in the output symbol
5380 if (! symbol_used_in_reloc_p (sym)
5381 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
5382 || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5383 && ! symbol_get_tc (sym)->output
5384 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
5387 /* This one will disappear anyway. Don't make a csect sym for it. */
5388 if (sym == abs_section_sym)
5391 if (symbol_get_tc (sym)->real_name != (char *) NULL)
5392 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
5398 name = S_GET_NAME (sym);
5399 s = strchr (name, '[');
5400 if (s != (char *) NULL)
5406 snew = xmalloc (len + 1);
5407 memcpy (snew, name, len);
5410 S_SET_NAME (sym, snew);
5414 if (set_end != (symbolS *) NULL)
5416 SA_SET_SYM_ENDNDX (set_end, sym);
5420 if (SF_GET_FUNCTION (sym))
5422 if (ppc_last_function != (symbolS *) NULL)
5423 as_bad (_("two .function pseudo-ops with no intervening .ef"));
5424 ppc_last_function = sym;
5425 if (symbol_get_tc (sym)->u.size != (symbolS *) NULL)
5427 resolve_symbol_value (symbol_get_tc (sym)->u.size);
5428 SA_SET_SYM_FSIZE (sym,
5429 (long) S_GET_VALUE (symbol_get_tc (sym)->u.size));
5432 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
5433 && strcmp (S_GET_NAME (sym), ".ef") == 0)
5435 if (ppc_last_function == (symbolS *) NULL)
5436 as_bad (_(".ef with no preceding .function"));
5439 set_end = ppc_last_function;
5440 ppc_last_function = NULL;
5442 /* We don't have a C_EFCN symbol, but we need to force the
5443 COFF backend to believe that it has seen one. */
5444 coff_last_function = NULL;
5448 if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5449 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
5450 && S_GET_STORAGE_CLASS (sym) != C_FILE
5451 && S_GET_STORAGE_CLASS (sym) != C_FCN
5452 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
5453 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
5454 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
5455 && S_GET_STORAGE_CLASS (sym) != C_BINCL
5456 && S_GET_STORAGE_CLASS (sym) != C_EINCL
5457 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
5458 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
5460 if (S_GET_STORAGE_CLASS (sym) == C_EXT
5461 || S_GET_STORAGE_CLASS (sym) == C_AIX_WEAKEXT
5462 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
5465 union internal_auxent *a;
5467 /* Create a csect aux. */
5468 i = S_GET_NUMBER_AUXILIARY (sym);
5469 S_SET_NUMBER_AUXILIARY (sym, i + 1);
5470 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
5471 if (symbol_get_tc (sym)->symbol_class == XMC_TC0)
5473 /* This is the TOC table. */
5474 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
5475 a->x_csect.x_scnlen.l = 0;
5476 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5478 else if (symbol_get_tc (sym)->subseg != 0)
5480 /* This is a csect symbol. x_scnlen is the size of the
5482 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
5483 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5484 S_GET_SEGMENT (sym))
5485 - S_GET_VALUE (sym));
5488 resolve_symbol_value (symbol_get_tc (sym)->next);
5489 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
5490 - S_GET_VALUE (sym));
5492 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
5494 else if (S_GET_SEGMENT (sym) == bss_section)
5496 /* This is a common symbol. */
5497 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
5498 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
5499 if (S_IS_EXTERNAL (sym))
5500 symbol_get_tc (sym)->symbol_class = XMC_RW;
5502 symbol_get_tc (sym)->symbol_class = XMC_BS;
5504 else if (S_GET_SEGMENT (sym) == absolute_section)
5506 /* This is an absolute symbol. The csect will be created by
5507 ppc_adjust_symtab. */
5509 a->x_csect.x_smtyp = XTY_LD;
5510 if (symbol_get_tc (sym)->symbol_class == -1)
5511 symbol_get_tc (sym)->symbol_class = XMC_XO;
5513 else if (! S_IS_DEFINED (sym))
5515 /* This is an external symbol. */
5516 a->x_csect.x_scnlen.l = 0;
5517 a->x_csect.x_smtyp = XTY_ER;
5519 else if (symbol_get_tc (sym)->symbol_class == XMC_TC)
5523 /* This is a TOC definition. x_scnlen is the size of the
5525 next = symbol_next (sym);
5526 while (symbol_get_tc (next)->symbol_class == XMC_TC0)
5527 next = symbol_next (next);
5528 if (next == (symbolS *) NULL
5529 || symbol_get_tc (next)->symbol_class != XMC_TC)
5531 if (ppc_after_toc_frag == (fragS *) NULL)
5532 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5534 - S_GET_VALUE (sym));
5536 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
5537 - S_GET_VALUE (sym));
5541 resolve_symbol_value (next);
5542 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
5543 - S_GET_VALUE (sym));
5545 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5551 /* This is a normal symbol definition. x_scnlen is the
5552 symbol index of the containing csect. */
5553 if (S_GET_SEGMENT (sym) == text_section)
5554 csect = ppc_text_csects;
5555 else if (S_GET_SEGMENT (sym) == data_section)
5556 csect = ppc_data_csects;
5560 /* Skip the initial dummy symbol. */
5561 csect = symbol_get_tc (csect)->next;
5563 if (csect == (symbolS *) NULL)
5565 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
5566 a->x_csect.x_scnlen.l = 0;
5570 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
5572 resolve_symbol_value (symbol_get_tc (csect)->next);
5573 if (S_GET_VALUE (symbol_get_tc (csect)->next)
5574 > S_GET_VALUE (sym))
5576 csect = symbol_get_tc (csect)->next;
5579 a->x_csect.x_scnlen.p =
5580 coffsymbol (symbol_get_bfdsym (csect))->native;
5581 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
5584 a->x_csect.x_smtyp = XTY_LD;
5587 a->x_csect.x_parmhash = 0;
5588 a->x_csect.x_snhash = 0;
5589 if (symbol_get_tc (sym)->symbol_class == -1)
5590 a->x_csect.x_smclas = XMC_PR;
5592 a->x_csect.x_smclas = symbol_get_tc (sym)->symbol_class;
5593 a->x_csect.x_stab = 0;
5594 a->x_csect.x_snstab = 0;
5596 /* Don't let the COFF backend resort these symbols. */
5597 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
5599 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
5601 /* We want the value to be the symbol index of the referenced
5602 csect symbol. BFD will do that for us if we set the right
5604 asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
5605 combined_entry_type *c = coffsymbol (bsym)->native;
5607 S_SET_VALUE (sym, (valueT) (size_t) c);
5608 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
5610 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5615 block = symbol_get_tc (sym)->within;
5618 /* The value is the offset from the enclosing csect. */
5621 csect = symbol_get_tc (block)->within;
5622 resolve_symbol_value (csect);
5623 base = S_GET_VALUE (csect);
5628 S_SET_VALUE (sym, S_GET_VALUE (sym) - base);
5630 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
5631 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
5633 /* We want the value to be a file offset into the line numbers.
5634 BFD will do that for us if we set the right flags. We have
5635 already set the value correctly. */
5636 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
5642 /* Adjust the symbol table. This creates csect symbols for all
5643 absolute symbols. */
5646 ppc_adjust_symtab (void)
5653 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
5657 union internal_auxent *a;
5659 if (S_GET_SEGMENT (sym) != absolute_section)
5662 csect = symbol_create (".abs[XO]", absolute_section,
5663 S_GET_VALUE (sym), &zero_address_frag);
5664 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
5665 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
5666 i = S_GET_NUMBER_AUXILIARY (csect);
5667 S_SET_NUMBER_AUXILIARY (csect, i + 1);
5668 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
5669 a->x_csect.x_scnlen.l = 0;
5670 a->x_csect.x_smtyp = XTY_SD;
5671 a->x_csect.x_parmhash = 0;
5672 a->x_csect.x_snhash = 0;
5673 a->x_csect.x_smclas = XMC_XO;
5674 a->x_csect.x_stab = 0;
5675 a->x_csect.x_snstab = 0;
5677 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
5679 i = S_GET_NUMBER_AUXILIARY (sym);
5680 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
5681 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
5682 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
5685 ppc_saw_abs = FALSE;
5688 /* Set the VMA for a section. This is called on all the sections in
5692 ppc_frob_section (asection *sec)
5694 static bfd_vma vma = 0;
5696 /* Dwarf sections start at 0. */
5697 if (bfd_get_section_flags (NULL, sec) & SEC_DEBUGGING)
5700 vma = md_section_align (sec, vma);
5701 bfd_set_section_vma (stdoutput, sec, vma);
5702 vma += bfd_section_size (stdoutput, sec);
5705 #endif /* OBJ_XCOFF */
5708 md_atof (int type, char *litp, int *sizep)
5710 return ieee_md_atof (type, litp, sizep, target_big_endian);
5713 /* Write a value out to the object file, using the appropriate
5717 md_number_to_chars (char *buf, valueT val, int n)
5719 if (target_big_endian)
5720 number_to_chars_bigendian (buf, val, n);
5722 number_to_chars_littleendian (buf, val, n);
5725 /* Align a section (I don't know why this is machine dependent). */
5728 md_section_align (asection *seg ATTRIBUTE_UNUSED, valueT addr)
5733 int align = bfd_get_section_alignment (stdoutput, seg);
5735 return ((addr + (1 << align) - 1) & (-1 << align));
5739 /* We don't have any form of relaxing. */
5742 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
5743 asection *seg ATTRIBUTE_UNUSED)
5749 /* Convert a machine dependent frag. We never generate these. */
5752 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
5753 asection *sec ATTRIBUTE_UNUSED,
5754 fragS *fragp ATTRIBUTE_UNUSED)
5759 /* We have no need to default values of symbols. */
5762 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
5767 /* Functions concerning relocs. */
5769 /* The location from which a PC relative jump should be calculated,
5770 given a PC relative reloc. */
5773 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
5775 return fixp->fx_frag->fr_address + fixp->fx_where;
5780 /* This is called to see whether a fixup should be adjusted to use a
5781 section symbol. We take the opportunity to change a fixup against
5782 a symbol in the TOC subsegment into a reloc against the
5783 corresponding .tc symbol. */
5786 ppc_fix_adjustable (fixS *fix)
5788 valueT val = resolve_symbol_value (fix->fx_addsy);
5789 segT symseg = S_GET_SEGMENT (fix->fx_addsy);
5790 TC_SYMFIELD_TYPE *tc;
5792 if (symseg == absolute_section)
5795 /* Always adjust symbols in debugging sections. */
5796 if (bfd_get_section_flags (stdoutput, symseg) & SEC_DEBUGGING)
5799 if (ppc_toc_csect != (symbolS *) NULL
5800 && fix->fx_addsy != ppc_toc_csect
5801 && symseg == data_section
5802 && val >= ppc_toc_frag->fr_address
5803 && (ppc_after_toc_frag == (fragS *) NULL
5804 || val < ppc_after_toc_frag->fr_address))
5808 for (sy = symbol_next (ppc_toc_csect);
5809 sy != (symbolS *) NULL;
5810 sy = symbol_next (sy))
5812 TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
5814 if (sy_tc->symbol_class == XMC_TC0)
5816 if (sy_tc->symbol_class != XMC_TC)
5818 if (val == resolve_symbol_value (sy))
5821 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
5826 as_bad_where (fix->fx_file, fix->fx_line,
5827 _("symbol in .toc does not match any .tc"));
5830 /* Possibly adjust the reloc to be against the csect. */
5831 tc = symbol_get_tc (fix->fx_addsy);
5833 && tc->symbol_class != XMC_TC0
5834 && tc->symbol_class != XMC_TC
5835 && symseg != bss_section
5836 /* Don't adjust if this is a reloc in the toc section. */
5837 && (symseg != data_section
5838 || ppc_toc_csect == NULL
5839 || val < ppc_toc_frag->fr_address
5840 || (ppc_after_toc_frag != NULL
5841 && val >= ppc_after_toc_frag->fr_address)))
5844 symbolS *next_csect;
5846 if (symseg == text_section)
5847 csect = ppc_text_csects;
5848 else if (symseg == data_section)
5849 csect = ppc_data_csects;
5853 /* Skip the initial dummy symbol. */
5854 csect = symbol_get_tc (csect)->next;
5856 if (csect != (symbolS *) NULL)
5858 while ((next_csect = symbol_get_tc (csect)->next) != (symbolS *) NULL
5859 && (symbol_get_frag (next_csect)->fr_address <= val))
5861 /* If the csect address equals the symbol value, then we
5862 have to look through the full symbol table to see
5863 whether this is the csect we want. Note that we will
5864 only get here if the csect has zero length. */
5865 if (symbol_get_frag (csect)->fr_address == val
5866 && S_GET_VALUE (csect) == val)
5870 for (scan = symbol_next (csect);
5872 scan = symbol_next (scan))
5874 if (symbol_get_tc (scan)->subseg != 0)
5876 if (scan == fix->fx_addsy)
5880 /* If we found the symbol before the next csect
5881 symbol, then this is the csect we want. */
5882 if (scan == fix->fx_addsy)
5889 fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
5890 fix->fx_addsy = csect;
5895 /* Adjust a reloc against a .lcomm symbol to be against the base
5897 if (symseg == bss_section
5898 && ! S_IS_EXTERNAL (fix->fx_addsy))
5900 symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5902 fix->fx_offset += val - resolve_symbol_value (sy);
5909 /* A reloc from one csect to another must be kept. The assembler
5910 will, of course, keep relocs between sections, and it will keep
5911 absolute relocs, but we need to force it to keep PC relative relocs
5912 between two csects in the same section. */
5915 ppc_force_relocation (fixS *fix)
5917 /* At this point fix->fx_addsy should already have been converted to
5918 a csect symbol. If the csect does not include the fragment, then
5919 we need to force the relocation. */
5921 && fix->fx_addsy != NULL
5922 && symbol_get_tc (fix->fx_addsy)->subseg != 0
5923 && ((symbol_get_frag (fix->fx_addsy)->fr_address
5924 > fix->fx_frag->fr_address)
5925 || (symbol_get_tc (fix->fx_addsy)->next != NULL
5926 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5927 <= fix->fx_frag->fr_address))))
5930 return generic_force_reloc (fix);
5933 #endif /* OBJ_XCOFF */
5936 /* If this function returns non-zero, it guarantees that a relocation
5937 will be emitted for a fixup. */
5940 ppc_force_relocation (fixS *fix)
5942 /* Branch prediction relocations must force a relocation, as must
5943 the vtable description relocs. */
5944 switch (fix->fx_r_type)
5946 case BFD_RELOC_PPC_B16_BRTAKEN:
5947 case BFD_RELOC_PPC_B16_BRNTAKEN:
5948 case BFD_RELOC_PPC_BA16_BRTAKEN:
5949 case BFD_RELOC_PPC_BA16_BRNTAKEN:
5950 case BFD_RELOC_24_PLT_PCREL:
5951 case BFD_RELOC_PPC64_TOC:
5957 if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
5958 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
5961 return generic_force_reloc (fix);
5965 ppc_fix_adjustable (fixS *fix)
5967 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5968 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5969 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5970 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5971 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_DS
5972 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_LO_DS
5973 && fix->fx_r_type != BFD_RELOC_GPREL16
5974 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5975 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5976 && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
5977 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA));
5981 /* Implement HANDLE_ALIGN. This writes the NOP pattern into an
5982 rs_align_code frag. */
5985 ppc_handle_align (struct frag *fragP)
5987 valueT count = (fragP->fr_next->fr_address
5988 - (fragP->fr_address + fragP->fr_fix));
5990 if (count != 0 && (count & 3) == 0)
5992 char *dest = fragP->fr_literal + fragP->fr_fix;
5996 if (count > 4 * nop_limit && count < 0x2000000)
6000 /* Make a branch, then follow with nops. Insert another
6001 frag to handle the nops. */
6002 md_number_to_chars (dest, 0x48000000 + count, 4);
6007 rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6008 memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
6009 fragP->fr_next = rest;
6011 rest->fr_address += rest->fr_fix + 4;
6013 /* If we leave the next frag as rs_align_code we'll come here
6014 again, resulting in a bunch of branches rather than a
6015 branch followed by nops. */
6016 rest->fr_type = rs_align;
6017 dest = rest->fr_literal;
6020 md_number_to_chars (dest, 0x60000000, 4);
6022 if ((ppc_cpu & PPC_OPCODE_POWER6) != 0
6023 || (ppc_cpu & PPC_OPCODE_POWER7) != 0)
6025 /* For power6 and power7, we want the last nop to be a group
6026 terminating one. Do this by inserting an rs_fill frag immediately
6027 after this one, with its address set to the last nop location.
6028 This will automatically reduce the number of nops in the current
6032 struct frag *group_nop = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6034 memcpy (group_nop, fragP, SIZEOF_STRUCT_FRAG);
6035 group_nop->fr_address = group_nop->fr_next->fr_address - 4;
6036 group_nop->fr_fix = 0;
6037 group_nop->fr_offset = 1;
6038 group_nop->fr_type = rs_fill;
6039 fragP->fr_next = group_nop;
6040 dest = group_nop->fr_literal;
6043 if ((ppc_cpu & PPC_OPCODE_POWER7) != 0)
6044 /* power7 group terminating nop: "ori 2,2,0". */
6045 md_number_to_chars (dest, 0x60420000, 4);
6047 /* power6 group terminating nop: "ori 1,1,0". */
6048 md_number_to_chars (dest, 0x60210000, 4);
6053 /* Apply a fixup to the object code. This is called for all the
6054 fixups we generated by the call to fix_new_exp, above. In the call
6055 above we used a reloc code which was the largest legal reloc code
6056 plus the operand index. Here we undo that to recover the operand
6057 index. At this point all symbol values should be fully resolved,
6058 and we attempt to completely resolve the reloc. If we can not do
6059 that, we determine the correct reloc code and put it back in the
6063 md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
6065 valueT value = * valP;
6068 if (fixP->fx_addsy != NULL)
6070 /* Hack around bfd_install_relocation brain damage. */
6072 value += fixP->fx_frag->fr_address + fixP->fx_where;
6077 /* FIXME FIXME FIXME: The value we are passed in *valP includes
6078 the symbol values. If we are doing this relocation the code in
6079 write.c is going to call bfd_install_relocation, which is also
6080 going to use the symbol value. That means that if the reloc is
6081 fully resolved we want to use *valP since bfd_install_relocation is
6083 However, if the reloc is not fully resolved we do not want to
6084 use *valP, and must use fx_offset instead. If the relocation
6085 is PC-relative, we then need to re-apply md_pcrel_from_section
6086 to this new relocation value. */
6087 if (fixP->fx_addsy == (symbolS *) NULL)
6092 value = fixP->fx_offset;
6094 value -= md_pcrel_from_section (fixP, seg);
6098 if (fixP->fx_subsy != (symbolS *) NULL)
6100 /* We can't actually support subtracting a symbol. */
6101 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
6104 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
6107 const struct powerpc_operand *operand;
6111 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
6113 operand = &powerpc_operands[opindex];
6116 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
6117 does not generate a reloc. It uses the offset of `sym' within its
6118 csect. Other usages, such as `.long sym', generate relocs. This
6119 is the documented behaviour of non-TOC symbols. */
6120 if ((operand->flags & PPC_OPERAND_PARENS) != 0
6121 && (operand->bitm & 0xfff0) == 0xfff0
6122 && operand->shift == 0
6123 && (operand->insert == NULL || ppc_obj64)
6124 && fixP->fx_addsy != NULL
6125 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
6126 && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC
6127 && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC0
6128 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
6130 value = fixP->fx_offset;
6135 /* Fetch the instruction, insert the fully resolved operand
6136 value, and stuff the instruction back again. */
6137 where = fixP->fx_frag->fr_literal + fixP->fx_where;
6138 if (target_big_endian)
6139 insn = bfd_getb32 ((unsigned char *) where);
6141 insn = bfd_getl32 ((unsigned char *) where);
6142 insn = ppc_insert_operand (insn, operand, (offsetT) value,
6143 fixP->tc_fix_data.ppc_cpu,
6144 fixP->fx_file, fixP->fx_line);
6145 if (target_big_endian)
6146 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
6148 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
6151 /* Nothing else to do here. */
6154 gas_assert (fixP->fx_addsy != NULL);
6156 /* Determine a BFD reloc value based on the operand information.
6157 We are only prepared to turn a few of the operands into
6159 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
6160 && operand->bitm == 0x3fffffc
6161 && operand->shift == 0)
6162 fixP->fx_r_type = BFD_RELOC_PPC_B26;
6163 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
6164 && operand->bitm == 0xfffc
6165 && operand->shift == 0)
6167 fixP->fx_r_type = BFD_RELOC_PPC_B16;
6170 if (target_big_endian)
6171 fixP->fx_where += 2;
6174 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
6175 && operand->bitm == 0x3fffffc
6176 && operand->shift == 0)
6177 fixP->fx_r_type = BFD_RELOC_PPC_BA26;
6178 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
6179 && operand->bitm == 0xfffc
6180 && operand->shift == 0)
6182 fixP->fx_r_type = BFD_RELOC_PPC_BA16;
6185 if (target_big_endian)
6186 fixP->fx_where += 2;
6189 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
6190 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
6191 && (operand->bitm & 0xfff0) == 0xfff0
6192 && operand->shift == 0)
6194 if (ppc_is_toc_sym (fixP->fx_addsy))
6196 fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
6199 && (operand->flags & PPC_OPERAND_DS) != 0)
6200 fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
6205 fixP->fx_r_type = BFD_RELOC_16;
6208 && (operand->flags & PPC_OPERAND_DS) != 0)
6209 fixP->fx_r_type = BFD_RELOC_PPC64_ADDR16_DS;
6213 if (target_big_endian)
6214 fixP->fx_where += 2;
6216 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
6222 /* Use expr_symbol_where to see if this is an expression
6224 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
6225 as_bad_where (fixP->fx_file, fixP->fx_line,
6226 _("unresolved expression that must be resolved"));
6228 as_bad_where (fixP->fx_file, fixP->fx_line,
6229 _("unsupported relocation against %s"),
6230 S_GET_NAME (fixP->fx_addsy));
6238 ppc_elf_validate_fix (fixP, seg);
6240 switch (fixP->fx_r_type)
6242 case BFD_RELOC_CTOR:
6249 fixP->fx_r_type = BFD_RELOC_32_PCREL;
6253 case BFD_RELOC_32_PCREL:
6254 case BFD_RELOC_PPC_EMB_NADDR32:
6255 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6262 fixP->fx_r_type = BFD_RELOC_64_PCREL;
6265 case BFD_RELOC_64_PCREL:
6266 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6270 case BFD_RELOC_GPREL16:
6271 case BFD_RELOC_16_GOT_PCREL:
6272 case BFD_RELOC_16_GOTOFF:
6273 case BFD_RELOC_LO16_GOTOFF:
6274 case BFD_RELOC_HI16_GOTOFF:
6275 case BFD_RELOC_HI16_S_GOTOFF:
6276 case BFD_RELOC_16_BASEREL:
6277 case BFD_RELOC_LO16_BASEREL:
6278 case BFD_RELOC_HI16_BASEREL:
6279 case BFD_RELOC_HI16_S_BASEREL:
6280 case BFD_RELOC_PPC_EMB_NADDR16:
6281 case BFD_RELOC_PPC_EMB_NADDR16_LO:
6282 case BFD_RELOC_PPC_EMB_NADDR16_HI:
6283 case BFD_RELOC_PPC_EMB_NADDR16_HA:
6284 case BFD_RELOC_PPC_EMB_SDAI16:
6285 case BFD_RELOC_PPC_EMB_SDA2REL:
6286 case BFD_RELOC_PPC_EMB_SDA2I16:
6287 case BFD_RELOC_PPC_EMB_RELSEC16:
6288 case BFD_RELOC_PPC_EMB_RELST_LO:
6289 case BFD_RELOC_PPC_EMB_RELST_HI:
6290 case BFD_RELOC_PPC_EMB_RELST_HA:
6291 case BFD_RELOC_PPC_EMB_RELSDA:
6292 case BFD_RELOC_PPC_TOC16:
6294 case BFD_RELOC_PPC64_TOC16_LO:
6295 case BFD_RELOC_PPC64_TOC16_HI:
6296 case BFD_RELOC_PPC64_TOC16_HA:
6300 if (fixP->fx_addsy != NULL)
6301 as_bad_where (fixP->fx_file, fixP->fx_line,
6302 _("cannot emit PC relative %s relocation against %s"),
6303 bfd_get_reloc_code_name (fixP->fx_r_type),
6304 S_GET_NAME (fixP->fx_addsy));
6306 as_bad_where (fixP->fx_file, fixP->fx_line,
6307 _("cannot emit PC relative %s relocation"),
6308 bfd_get_reloc_code_name (fixP->fx_r_type));
6311 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6317 fixP->fx_r_type = BFD_RELOC_16_PCREL;
6320 case BFD_RELOC_16_PCREL:
6321 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6325 case BFD_RELOC_LO16:
6327 fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
6330 case BFD_RELOC_LO16_PCREL:
6331 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6335 /* This case happens when you write, for example,
6337 where L1 and L2 are defined later. */
6338 case BFD_RELOC_HI16:
6340 fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
6343 case BFD_RELOC_HI16_PCREL:
6344 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6348 case BFD_RELOC_HI16_S:
6350 fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
6353 case BFD_RELOC_HI16_S_PCREL:
6354 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6359 case BFD_RELOC_NONE:
6364 case BFD_RELOC_PPC64_HIGHER:
6367 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6368 PPC_HIGHER (value), 2);
6371 case BFD_RELOC_PPC64_HIGHER_S:
6374 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6375 PPC_HIGHERA (value), 2);
6378 case BFD_RELOC_PPC64_HIGHEST:
6381 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6382 PPC_HIGHEST (value), 2);
6385 case BFD_RELOC_PPC64_HIGHEST_S:
6388 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6389 PPC_HIGHESTA (value), 2);
6392 case BFD_RELOC_PPC64_ADDR16_DS:
6393 case BFD_RELOC_PPC64_ADDR16_LO_DS:
6394 case BFD_RELOC_PPC64_GOT16_DS:
6395 case BFD_RELOC_PPC64_GOT16_LO_DS:
6396 case BFD_RELOC_PPC64_PLT16_LO_DS:
6397 case BFD_RELOC_PPC64_SECTOFF_DS:
6398 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
6399 case BFD_RELOC_PPC64_TOC16_DS:
6400 case BFD_RELOC_PPC64_TOC16_LO_DS:
6401 case BFD_RELOC_PPC64_PLTGOT16_DS:
6402 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
6406 char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
6407 unsigned long val, mask;
6409 if (target_big_endian)
6410 val = bfd_getb32 (where - 2);
6412 val = bfd_getl32 (where);
6414 /* lq insns reserve the four lsbs. */
6415 if ((ppc_cpu & PPC_OPCODE_POWER4) != 0
6416 && (val & (0x3f << 26)) == (56u << 26))
6418 val |= value & mask;
6419 if (target_big_endian)
6420 bfd_putb16 ((bfd_vma) val, where);
6422 bfd_putl16 ((bfd_vma) val, where);
6426 case BFD_RELOC_PPC_B16_BRTAKEN:
6427 case BFD_RELOC_PPC_B16_BRNTAKEN:
6428 case BFD_RELOC_PPC_BA16_BRTAKEN:
6429 case BFD_RELOC_PPC_BA16_BRNTAKEN:
6432 case BFD_RELOC_PPC_TLS:
6433 case BFD_RELOC_PPC_TLSGD:
6434 case BFD_RELOC_PPC_TLSLD:
6437 case BFD_RELOC_PPC_DTPMOD:
6438 case BFD_RELOC_PPC_TPREL16:
6439 case BFD_RELOC_PPC_TPREL16_LO:
6440 case BFD_RELOC_PPC_TPREL16_HI:
6441 case BFD_RELOC_PPC_TPREL16_HA:
6442 case BFD_RELOC_PPC_TPREL:
6443 case BFD_RELOC_PPC_DTPREL16:
6444 case BFD_RELOC_PPC_DTPREL16_LO:
6445 case BFD_RELOC_PPC_DTPREL16_HI:
6446 case BFD_RELOC_PPC_DTPREL16_HA:
6447 case BFD_RELOC_PPC_DTPREL:
6448 case BFD_RELOC_PPC_GOT_TLSGD16:
6449 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
6450 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
6451 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
6452 case BFD_RELOC_PPC_GOT_TLSLD16:
6453 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
6454 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
6455 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
6456 case BFD_RELOC_PPC_GOT_TPREL16:
6457 case BFD_RELOC_PPC_GOT_TPREL16_LO:
6458 case BFD_RELOC_PPC_GOT_TPREL16_HI:
6459 case BFD_RELOC_PPC_GOT_TPREL16_HA:
6460 case BFD_RELOC_PPC_GOT_DTPREL16:
6461 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
6462 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
6463 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
6464 case BFD_RELOC_PPC64_TPREL16_DS:
6465 case BFD_RELOC_PPC64_TPREL16_LO_DS:
6466 case BFD_RELOC_PPC64_TPREL16_HIGHER:
6467 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
6468 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
6469 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
6470 case BFD_RELOC_PPC64_DTPREL16_DS:
6471 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
6472 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
6473 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
6474 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
6475 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
6476 S_SET_THREAD_LOCAL (fixP->fx_addsy);
6479 /* Because SDA21 modifies the register field, the size is set to 4
6480 bytes, rather than 2, so offset it here appropriately. */
6481 case BFD_RELOC_PPC_EMB_SDA21:
6485 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where
6486 + ((target_big_endian) ? 2 : 0),
6493 /* This can occur if there is a bug in the input assembler, eg:
6494 ".byte <undefined_symbol> - ." */
6496 as_bad (_("Unable to handle reference to symbol %s"),
6497 S_GET_NAME (fixP->fx_addsy));
6499 as_bad (_("Unable to resolve expression"));
6503 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6507 case BFD_RELOC_24_PLT_PCREL:
6508 case BFD_RELOC_PPC_LOCAL24PC:
6509 if (!fixP->fx_pcrel && !fixP->fx_done)
6517 /* Fetch the instruction, insert the fully resolved operand
6518 value, and stuff the instruction back again. */
6519 where = fixP->fx_frag->fr_literal + fixP->fx_where;
6520 if (target_big_endian)
6521 insn = bfd_getb32 ((unsigned char *) where);
6523 insn = bfd_getl32 ((unsigned char *) where);
6524 if ((value & 3) != 0)
6525 as_bad_where (fixP->fx_file, fixP->fx_line,
6526 _("must branch to an address a multiple of 4"));
6527 if ((offsetT) value < -0x40000000
6528 || (offsetT) value >= 0x40000000)
6529 as_bad_where (fixP->fx_file, fixP->fx_line,
6530 _("@local or @plt branch destination is too far away, %ld bytes"),
6532 insn = insn | (value & 0x03fffffc);
6533 if (target_big_endian)
6534 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
6536 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
6540 case BFD_RELOC_VTABLE_INHERIT:
6543 && !S_IS_DEFINED (fixP->fx_addsy)
6544 && !S_IS_WEAK (fixP->fx_addsy))
6545 S_SET_WEAK (fixP->fx_addsy);
6548 case BFD_RELOC_VTABLE_ENTRY:
6553 /* Generated by reference to `sym@tocbase'. The sym is
6554 ignored by the linker. */
6555 case BFD_RELOC_PPC64_TOC:
6561 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
6568 fixP->fx_addnumber = value;
6570 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6571 from the section contents. If we are going to be emitting a reloc
6572 then the section contents are immaterial, so don't warn if they
6573 happen to overflow. Leave such warnings to ld. */
6575 fixP->fx_no_overflow = 1;
6577 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
6578 fixP->fx_addnumber = 0;
6582 fixP->fx_addnumber = 0;
6584 /* We want to use the offset within the toc, not the actual VMA
6586 fixP->fx_addnumber =
6587 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy))
6588 - S_GET_VALUE (ppc_toc_csect);
6594 /* Generate a reloc for a fixup. */
6597 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
6601 reloc = (arelent *) xmalloc (sizeof (arelent));
6603 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
6604 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
6605 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6606 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6607 if (reloc->howto == (reloc_howto_type *) NULL)
6609 as_bad_where (fixp->fx_file, fixp->fx_line,
6610 _("reloc %d not supported by object file format"),
6611 (int) fixp->fx_r_type);
6614 reloc->addend = fixp->fx_addnumber;
6620 ppc_cfi_frame_initial_instructions (void)
6622 cfi_add_CFA_def_cfa (1, 0);
6626 tc_ppc_regname_to_dw2regnum (char *regname)
6628 unsigned int regnum = -1;
6632 static struct { char *name; int dw2regnum; } regnames[] =
6634 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6635 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6636 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6637 { "spe_acc", 111 }, { "spefscr", 112 }
6640 for (i = 0; i < ARRAY_SIZE (regnames); ++i)
6641 if (strcmp (regnames[i].name, regname) == 0)
6642 return regnames[i].dw2regnum;
6644 if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
6646 p = regname + 1 + (regname[1] == '.');
6647 regnum = strtoul (p, &q, 10);
6648 if (p == q || *q || regnum >= 32)
6650 if (regname[0] == 'f')
6652 else if (regname[0] == 'v')
6655 else if (regname[0] == 'c' && regname[1] == 'r')
6657 p = regname + 2 + (regname[2] == '.');
6658 if (p[0] < '0' || p[0] > '7' || p[1])
6660 regnum = p[0] - '0' + 68;