]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/config/tc-ppc.c
gas: add visibility support using GNU syntax on XCOFF
[thirdparty/binutils-gdb.git] / gas / config / tc-ppc.c
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994-2022 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
4
5 This file is part of GAS, the GNU Assembler.
6
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 02110-1301, USA. */
21
22 #include "as.h"
23 #include "safe-ctype.h"
24 #include "subsegs.h"
25 #include "dw2gencfi.h"
26 #include "opcode/ppc.h"
27
28 #ifdef OBJ_ELF
29 #include "elf/ppc.h"
30 #include "elf/ppc64.h"
31 #include "dwarf2dbg.h"
32 #endif
33
34 #ifdef OBJ_XCOFF
35 #include "coff/xcoff.h"
36 #include "libxcoff.h"
37 #endif
38
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
40
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian;
43
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian = 0;
46
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
49 #define TARGET_REG_NAMES_P false
50 #endif
51
52 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
53 HIGHESTA. */
54
55 /* #lo(value) denotes the least significant 16 bits of the indicated. */
56 #define PPC_LO(v) ((v) & 0xffff)
57
58 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
59 #define PPC_HI(v) (((v) >> 16) & 0xffff)
60
61 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
62 the indicated value, compensating for #lo() being treated as a
63 signed number. */
64 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
65
66 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
67 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
68
69 /* #highera(value) denotes bits 32 through 47 of the indicated value,
70 compensating for #lo() being treated as a signed number. */
71 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
72
73 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
74 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
75
76 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
77 compensating for #lo being treated as a signed number. */
78 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
79
80 #define SEX16(val) (((val) ^ 0x8000) - 0x8000)
81
82 /* For the time being on ppc64, don't report overflow on @h and @ha
83 applied to constants. */
84 #define REPORT_OVERFLOW_HI 0
85
86 static bool reg_names_p = TARGET_REG_NAMES_P;
87
88 static void ppc_macro (char *, const struct powerpc_macro *);
89 static void ppc_byte (int);
90
91 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
92 static void ppc_tc (int);
93 static void ppc_machine (int);
94 #endif
95
96 #ifdef OBJ_XCOFF
97 static void ppc_comm (int);
98 static void ppc_bb (int);
99 static void ppc_bc (int);
100 static void ppc_bf (int);
101 static void ppc_biei (int);
102 static void ppc_bs (int);
103 static void ppc_eb (int);
104 static void ppc_ec (int);
105 static void ppc_ef (int);
106 static void ppc_es (int);
107 static void ppc_csect (int);
108 static void ppc_dwsect (int);
109 static void ppc_change_csect (symbolS *, offsetT);
110 static void ppc_file (int);
111 static void ppc_function (int);
112 static void ppc_extern (int);
113 static void ppc_globl (int);
114 static void ppc_lglobl (int);
115 static void ppc_ref (int);
116 static void ppc_section (int);
117 static void ppc_named_section (int);
118 static void ppc_stabx (int);
119 static void ppc_rename (int);
120 static void ppc_toc (int);
121 static void ppc_xcoff_cons (int);
122 static void ppc_vbyte (int);
123 static void ppc_weak (int);
124 static void ppc_GNU_visibility (int);
125 #endif
126
127 #ifdef OBJ_ELF
128 static void ppc_elf_rdata (int);
129 static void ppc_elf_lcomm (int);
130 static void ppc_elf_localentry (int);
131 static void ppc_elf_abiversion (int);
132 static void ppc_elf_gnu_attribute (int);
133 #endif
134 \f
135 /* Generic assembler global variables which must be defined by all
136 targets. */
137
138 #ifdef OBJ_ELF
139 /* This string holds the chars that always start a comment. If the
140 pre-processor is disabled, these aren't very useful. The macro
141 tc_comment_chars points to this. We use this, rather than the
142 usual comment_chars, so that we can switch for Solaris conventions. */
143 static const char ppc_solaris_comment_chars[] = "#!";
144 static const char ppc_eabi_comment_chars[] = "#";
145
146 #ifdef TARGET_SOLARIS_COMMENT
147 const char *ppc_comment_chars = ppc_solaris_comment_chars;
148 #else
149 const char *ppc_comment_chars = ppc_eabi_comment_chars;
150 #endif
151 #else
152 const char comment_chars[] = "#";
153 #endif
154
155 /* Characters which start a comment at the beginning of a line. */
156 const char line_comment_chars[] = "#";
157
158 /* Characters which may be used to separate multiple commands on a
159 single line. */
160 const char line_separator_chars[] = ";";
161
162 /* Characters which are used to indicate an exponent in a floating
163 point number. */
164 const char EXP_CHARS[] = "eE";
165
166 /* Characters which mean that a number is a floating point constant,
167 as in 0d1.0. */
168 const char FLT_CHARS[] = "dD";
169
170 /* Anything that can start an operand needs to be mentioned here,
171 to stop the input scrubber eating whitespace. */
172 const char ppc_symbol_chars[] = "%[";
173
174 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
175 int ppc_cie_data_alignment;
176
177 /* The dwarf2 minimum instruction length. */
178 int ppc_dwarf2_line_min_insn_length;
179
180 /* More than this number of nops in an alignment op gets a branch
181 instead. */
182 unsigned long nop_limit = 4;
183
184 /* The type of processor we are assembling for. This is one or more
185 of the PPC_OPCODE flags defined in opcode/ppc.h. */
186 ppc_cpu_t ppc_cpu = 0;
187 ppc_cpu_t sticky = 0;
188
189 /* Value for ELF e_flags EF_PPC64_ABI. */
190 unsigned int ppc_abiversion = 0;
191
192 #ifdef OBJ_ELF
193 /* Flags set on encountering toc relocs. */
194 static enum {
195 has_large_toc_reloc = 1,
196 has_small_toc_reloc = 2
197 } toc_reloc_types;
198 #endif
199
200 /* Warn on emitting data to code sections. */
201 int warn_476;
202 uint64_t last_insn;
203 segT last_seg;
204 subsegT last_subseg;
205 \f
206 /* The target specific pseudo-ops which we support. */
207
208 const pseudo_typeS md_pseudo_table[] =
209 {
210 /* Pseudo-ops which must be overridden. */
211 { "byte", ppc_byte, 0 },
212
213 #ifdef OBJ_XCOFF
214 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
215 legitimately belong in the obj-*.c file. However, XCOFF is based
216 on COFF, and is only implemented for the RS/6000. We just use
217 obj-coff.c, and add what we need here. */
218 { "comm", ppc_comm, 0 },
219 { "lcomm", ppc_comm, 1 },
220 { "bb", ppc_bb, 0 },
221 { "bc", ppc_bc, 0 },
222 { "bf", ppc_bf, 0 },
223 { "bi", ppc_biei, 0 },
224 { "bs", ppc_bs, 0 },
225 { "csect", ppc_csect, 0 },
226 { "dwsect", ppc_dwsect, 0 },
227 { "data", ppc_section, 'd' },
228 { "eb", ppc_eb, 0 },
229 { "ec", ppc_ec, 0 },
230 { "ef", ppc_ef, 0 },
231 { "ei", ppc_biei, 1 },
232 { "es", ppc_es, 0 },
233 { "extern", ppc_extern, 0 },
234 { "file", ppc_file, 0 },
235 { "function", ppc_function, 0 },
236 { "globl", ppc_globl, 0 },
237 { "lglobl", ppc_lglobl, 0 },
238 { "ref", ppc_ref, 0 },
239 { "rename", ppc_rename, 0 },
240 { "section", ppc_named_section, 0 },
241 { "stabx", ppc_stabx, 0 },
242 { "text", ppc_section, 't' },
243 { "toc", ppc_toc, 0 },
244 { "long", ppc_xcoff_cons, 2 },
245 { "llong", ppc_xcoff_cons, 3 },
246 { "word", ppc_xcoff_cons, 1 },
247 { "short", ppc_xcoff_cons, 1 },
248 { "vbyte", ppc_vbyte, 0 },
249 { "weak", ppc_weak, 0 },
250
251 /* Enable GNU syntax for symbol visibility. */
252 {"internal", ppc_GNU_visibility, SYM_V_INTERNAL},
253 {"hidden", ppc_GNU_visibility, SYM_V_HIDDEN},
254 {"protected", ppc_GNU_visibility, SYM_V_PROTECTED},
255 #endif
256
257 #ifdef OBJ_ELF
258 { "llong", cons, 8 },
259 { "rdata", ppc_elf_rdata, 0 },
260 { "rodata", ppc_elf_rdata, 0 },
261 { "lcomm", ppc_elf_lcomm, 0 },
262 { "localentry", ppc_elf_localentry, 0 },
263 { "abiversion", ppc_elf_abiversion, 0 },
264 { "gnu_attribute", ppc_elf_gnu_attribute, 0},
265 #endif
266
267 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
268 { "tc", ppc_tc, 0 },
269 { "machine", ppc_machine, 0 },
270 #endif
271
272 { NULL, NULL, 0 }
273 };
274
275 \f
276 /* Predefined register names if -mregnames (or default for Windows NT).
277 In general, there are lots of them, in an attempt to be compatible
278 with a number of other Windows NT assemblers. */
279
280 /* Structure to hold information about predefined registers. */
281 struct pd_reg
282 {
283 const char *name;
284 unsigned short value;
285 unsigned short flags;
286 };
287
288 /* List of registers that are pre-defined:
289
290 Each general register has predefined names of the form:
291 1. r<reg_num> which has the value <reg_num>.
292 2. r.<reg_num> which has the value <reg_num>.
293
294 Each floating point register has predefined names of the form:
295 1. f<reg_num> which has the value <reg_num>.
296 2. f.<reg_num> which has the value <reg_num>.
297
298 Each vector unit register has predefined names of the form:
299 1. v<reg_num> which has the value <reg_num>.
300 2. v.<reg_num> which has the value <reg_num>.
301
302 Each condition register has predefined names of the form:
303 1. cr<reg_num> which has the value <reg_num>.
304 2. cr.<reg_num> which has the value <reg_num>.
305
306 There are individual registers as well:
307 sp or r.sp has the value 1
308 rtoc or r.toc has the value 2
309 xer has the value 1
310 lr has the value 8
311 ctr has the value 9
312 dar has the value 19
313 dsisr has the value 18
314 dec has the value 22
315 sdr1 has the value 25
316 srr0 has the value 26
317 srr1 has the value 27
318
319 The table is sorted. Suitable for searching by a binary search. */
320
321 static const struct pd_reg pre_defined_registers[] =
322 {
323 /* VSX accumulators. */
324 { "a0", 0, PPC_OPERAND_ACC },
325 { "a1", 1, PPC_OPERAND_ACC },
326 { "a2", 2, PPC_OPERAND_ACC },
327 { "a3", 3, PPC_OPERAND_ACC },
328 { "a4", 4, PPC_OPERAND_ACC },
329 { "a5", 5, PPC_OPERAND_ACC },
330 { "a6", 6, PPC_OPERAND_ACC },
331 { "a7", 7, PPC_OPERAND_ACC },
332
333 /* Condition Registers */
334 { "cr.0", 0, PPC_OPERAND_CR_REG },
335 { "cr.1", 1, PPC_OPERAND_CR_REG },
336 { "cr.2", 2, PPC_OPERAND_CR_REG },
337 { "cr.3", 3, PPC_OPERAND_CR_REG },
338 { "cr.4", 4, PPC_OPERAND_CR_REG },
339 { "cr.5", 5, PPC_OPERAND_CR_REG },
340 { "cr.6", 6, PPC_OPERAND_CR_REG },
341 { "cr.7", 7, PPC_OPERAND_CR_REG },
342
343 { "cr0", 0, PPC_OPERAND_CR_REG },
344 { "cr1", 1, PPC_OPERAND_CR_REG },
345 { "cr2", 2, PPC_OPERAND_CR_REG },
346 { "cr3", 3, PPC_OPERAND_CR_REG },
347 { "cr4", 4, PPC_OPERAND_CR_REG },
348 { "cr5", 5, PPC_OPERAND_CR_REG },
349 { "cr6", 6, PPC_OPERAND_CR_REG },
350 { "cr7", 7, PPC_OPERAND_CR_REG },
351
352 { "ctr", 9, PPC_OPERAND_SPR },
353 { "dar", 19, PPC_OPERAND_SPR },
354 { "dec", 22, PPC_OPERAND_SPR },
355 { "dsisr", 18, PPC_OPERAND_SPR },
356
357 /* Floating point registers */
358 { "f.0", 0, PPC_OPERAND_FPR },
359 { "f.1", 1, PPC_OPERAND_FPR },
360 { "f.10", 10, PPC_OPERAND_FPR },
361 { "f.11", 11, PPC_OPERAND_FPR },
362 { "f.12", 12, PPC_OPERAND_FPR },
363 { "f.13", 13, PPC_OPERAND_FPR },
364 { "f.14", 14, PPC_OPERAND_FPR },
365 { "f.15", 15, PPC_OPERAND_FPR },
366 { "f.16", 16, PPC_OPERAND_FPR },
367 { "f.17", 17, PPC_OPERAND_FPR },
368 { "f.18", 18, PPC_OPERAND_FPR },
369 { "f.19", 19, PPC_OPERAND_FPR },
370 { "f.2", 2, PPC_OPERAND_FPR },
371 { "f.20", 20, PPC_OPERAND_FPR },
372 { "f.21", 21, PPC_OPERAND_FPR },
373 { "f.22", 22, PPC_OPERAND_FPR },
374 { "f.23", 23, PPC_OPERAND_FPR },
375 { "f.24", 24, PPC_OPERAND_FPR },
376 { "f.25", 25, PPC_OPERAND_FPR },
377 { "f.26", 26, PPC_OPERAND_FPR },
378 { "f.27", 27, PPC_OPERAND_FPR },
379 { "f.28", 28, PPC_OPERAND_FPR },
380 { "f.29", 29, PPC_OPERAND_FPR },
381 { "f.3", 3, PPC_OPERAND_FPR },
382 { "f.30", 30, PPC_OPERAND_FPR },
383 { "f.31", 31, PPC_OPERAND_FPR },
384 { "f.32", 32, PPC_OPERAND_VSR },
385 { "f.33", 33, PPC_OPERAND_VSR },
386 { "f.34", 34, PPC_OPERAND_VSR },
387 { "f.35", 35, PPC_OPERAND_VSR },
388 { "f.36", 36, PPC_OPERAND_VSR },
389 { "f.37", 37, PPC_OPERAND_VSR },
390 { "f.38", 38, PPC_OPERAND_VSR },
391 { "f.39", 39, PPC_OPERAND_VSR },
392 { "f.4", 4, PPC_OPERAND_FPR },
393 { "f.40", 40, PPC_OPERAND_VSR },
394 { "f.41", 41, PPC_OPERAND_VSR },
395 { "f.42", 42, PPC_OPERAND_VSR },
396 { "f.43", 43, PPC_OPERAND_VSR },
397 { "f.44", 44, PPC_OPERAND_VSR },
398 { "f.45", 45, PPC_OPERAND_VSR },
399 { "f.46", 46, PPC_OPERAND_VSR },
400 { "f.47", 47, PPC_OPERAND_VSR },
401 { "f.48", 48, PPC_OPERAND_VSR },
402 { "f.49", 49, PPC_OPERAND_VSR },
403 { "f.5", 5, PPC_OPERAND_FPR },
404 { "f.50", 50, PPC_OPERAND_VSR },
405 { "f.51", 51, PPC_OPERAND_VSR },
406 { "f.52", 52, PPC_OPERAND_VSR },
407 { "f.53", 53, PPC_OPERAND_VSR },
408 { "f.54", 54, PPC_OPERAND_VSR },
409 { "f.55", 55, PPC_OPERAND_VSR },
410 { "f.56", 56, PPC_OPERAND_VSR },
411 { "f.57", 57, PPC_OPERAND_VSR },
412 { "f.58", 58, PPC_OPERAND_VSR },
413 { "f.59", 59, PPC_OPERAND_VSR },
414 { "f.6", 6, PPC_OPERAND_FPR },
415 { "f.60", 60, PPC_OPERAND_VSR },
416 { "f.61", 61, PPC_OPERAND_VSR },
417 { "f.62", 62, PPC_OPERAND_VSR },
418 { "f.63", 63, PPC_OPERAND_VSR },
419 { "f.7", 7, PPC_OPERAND_FPR },
420 { "f.8", 8, PPC_OPERAND_FPR },
421 { "f.9", 9, PPC_OPERAND_FPR },
422
423 { "f0", 0, PPC_OPERAND_FPR },
424 { "f1", 1, PPC_OPERAND_FPR },
425 { "f10", 10, PPC_OPERAND_FPR },
426 { "f11", 11, PPC_OPERAND_FPR },
427 { "f12", 12, PPC_OPERAND_FPR },
428 { "f13", 13, PPC_OPERAND_FPR },
429 { "f14", 14, PPC_OPERAND_FPR },
430 { "f15", 15, PPC_OPERAND_FPR },
431 { "f16", 16, PPC_OPERAND_FPR },
432 { "f17", 17, PPC_OPERAND_FPR },
433 { "f18", 18, PPC_OPERAND_FPR },
434 { "f19", 19, PPC_OPERAND_FPR },
435 { "f2", 2, PPC_OPERAND_FPR },
436 { "f20", 20, PPC_OPERAND_FPR },
437 { "f21", 21, PPC_OPERAND_FPR },
438 { "f22", 22, PPC_OPERAND_FPR },
439 { "f23", 23, PPC_OPERAND_FPR },
440 { "f24", 24, PPC_OPERAND_FPR },
441 { "f25", 25, PPC_OPERAND_FPR },
442 { "f26", 26, PPC_OPERAND_FPR },
443 { "f27", 27, PPC_OPERAND_FPR },
444 { "f28", 28, PPC_OPERAND_FPR },
445 { "f29", 29, PPC_OPERAND_FPR },
446 { "f3", 3, PPC_OPERAND_FPR },
447 { "f30", 30, PPC_OPERAND_FPR },
448 { "f31", 31, PPC_OPERAND_FPR },
449 { "f32", 32, PPC_OPERAND_VSR },
450 { "f33", 33, PPC_OPERAND_VSR },
451 { "f34", 34, PPC_OPERAND_VSR },
452 { "f35", 35, PPC_OPERAND_VSR },
453 { "f36", 36, PPC_OPERAND_VSR },
454 { "f37", 37, PPC_OPERAND_VSR },
455 { "f38", 38, PPC_OPERAND_VSR },
456 { "f39", 39, PPC_OPERAND_VSR },
457 { "f4", 4, PPC_OPERAND_FPR },
458 { "f40", 40, PPC_OPERAND_VSR },
459 { "f41", 41, PPC_OPERAND_VSR },
460 { "f42", 42, PPC_OPERAND_VSR },
461 { "f43", 43, PPC_OPERAND_VSR },
462 { "f44", 44, PPC_OPERAND_VSR },
463 { "f45", 45, PPC_OPERAND_VSR },
464 { "f46", 46, PPC_OPERAND_VSR },
465 { "f47", 47, PPC_OPERAND_VSR },
466 { "f48", 48, PPC_OPERAND_VSR },
467 { "f49", 49, PPC_OPERAND_VSR },
468 { "f5", 5, PPC_OPERAND_FPR },
469 { "f50", 50, PPC_OPERAND_VSR },
470 { "f51", 51, PPC_OPERAND_VSR },
471 { "f52", 52, PPC_OPERAND_VSR },
472 { "f53", 53, PPC_OPERAND_VSR },
473 { "f54", 54, PPC_OPERAND_VSR },
474 { "f55", 55, PPC_OPERAND_VSR },
475 { "f56", 56, PPC_OPERAND_VSR },
476 { "f57", 57, PPC_OPERAND_VSR },
477 { "f58", 58, PPC_OPERAND_VSR },
478 { "f59", 59, PPC_OPERAND_VSR },
479 { "f6", 6, PPC_OPERAND_FPR },
480 { "f60", 60, PPC_OPERAND_VSR },
481 { "f61", 61, PPC_OPERAND_VSR },
482 { "f62", 62, PPC_OPERAND_VSR },
483 { "f63", 63, PPC_OPERAND_VSR },
484 { "f7", 7, PPC_OPERAND_FPR },
485 { "f8", 8, PPC_OPERAND_FPR },
486 { "f9", 9, PPC_OPERAND_FPR },
487
488 /* Quantization registers used with pair single instructions. */
489 { "gqr.0", 0, PPC_OPERAND_GQR },
490 { "gqr.1", 1, PPC_OPERAND_GQR },
491 { "gqr.2", 2, PPC_OPERAND_GQR },
492 { "gqr.3", 3, PPC_OPERAND_GQR },
493 { "gqr.4", 4, PPC_OPERAND_GQR },
494 { "gqr.5", 5, PPC_OPERAND_GQR },
495 { "gqr.6", 6, PPC_OPERAND_GQR },
496 { "gqr.7", 7, PPC_OPERAND_GQR },
497 { "gqr0", 0, PPC_OPERAND_GQR },
498 { "gqr1", 1, PPC_OPERAND_GQR },
499 { "gqr2", 2, PPC_OPERAND_GQR },
500 { "gqr3", 3, PPC_OPERAND_GQR },
501 { "gqr4", 4, PPC_OPERAND_GQR },
502 { "gqr5", 5, PPC_OPERAND_GQR },
503 { "gqr6", 6, PPC_OPERAND_GQR },
504 { "gqr7", 7, PPC_OPERAND_GQR },
505
506 { "lr", 8, PPC_OPERAND_SPR },
507
508 /* General Purpose Registers */
509 { "r.0", 0, PPC_OPERAND_GPR },
510 { "r.1", 1, PPC_OPERAND_GPR },
511 { "r.10", 10, PPC_OPERAND_GPR },
512 { "r.11", 11, PPC_OPERAND_GPR },
513 { "r.12", 12, PPC_OPERAND_GPR },
514 { "r.13", 13, PPC_OPERAND_GPR },
515 { "r.14", 14, PPC_OPERAND_GPR },
516 { "r.15", 15, PPC_OPERAND_GPR },
517 { "r.16", 16, PPC_OPERAND_GPR },
518 { "r.17", 17, PPC_OPERAND_GPR },
519 { "r.18", 18, PPC_OPERAND_GPR },
520 { "r.19", 19, PPC_OPERAND_GPR },
521 { "r.2", 2, PPC_OPERAND_GPR },
522 { "r.20", 20, PPC_OPERAND_GPR },
523 { "r.21", 21, PPC_OPERAND_GPR },
524 { "r.22", 22, PPC_OPERAND_GPR },
525 { "r.23", 23, PPC_OPERAND_GPR },
526 { "r.24", 24, PPC_OPERAND_GPR },
527 { "r.25", 25, PPC_OPERAND_GPR },
528 { "r.26", 26, PPC_OPERAND_GPR },
529 { "r.27", 27, PPC_OPERAND_GPR },
530 { "r.28", 28, PPC_OPERAND_GPR },
531 { "r.29", 29, PPC_OPERAND_GPR },
532 { "r.3", 3, PPC_OPERAND_GPR },
533 { "r.30", 30, PPC_OPERAND_GPR },
534 { "r.31", 31, PPC_OPERAND_GPR },
535 { "r.4", 4, PPC_OPERAND_GPR },
536 { "r.5", 5, PPC_OPERAND_GPR },
537 { "r.6", 6, PPC_OPERAND_GPR },
538 { "r.7", 7, PPC_OPERAND_GPR },
539 { "r.8", 8, PPC_OPERAND_GPR },
540 { "r.9", 9, PPC_OPERAND_GPR },
541
542 { "r.sp", 1, PPC_OPERAND_GPR },
543
544 { "r.toc", 2, PPC_OPERAND_GPR },
545
546 { "r0", 0, PPC_OPERAND_GPR },
547 { "r1", 1, PPC_OPERAND_GPR },
548 { "r10", 10, PPC_OPERAND_GPR },
549 { "r11", 11, PPC_OPERAND_GPR },
550 { "r12", 12, PPC_OPERAND_GPR },
551 { "r13", 13, PPC_OPERAND_GPR },
552 { "r14", 14, PPC_OPERAND_GPR },
553 { "r15", 15, PPC_OPERAND_GPR },
554 { "r16", 16, PPC_OPERAND_GPR },
555 { "r17", 17, PPC_OPERAND_GPR },
556 { "r18", 18, PPC_OPERAND_GPR },
557 { "r19", 19, PPC_OPERAND_GPR },
558 { "r2", 2, PPC_OPERAND_GPR },
559 { "r20", 20, PPC_OPERAND_GPR },
560 { "r21", 21, PPC_OPERAND_GPR },
561 { "r22", 22, PPC_OPERAND_GPR },
562 { "r23", 23, PPC_OPERAND_GPR },
563 { "r24", 24, PPC_OPERAND_GPR },
564 { "r25", 25, PPC_OPERAND_GPR },
565 { "r26", 26, PPC_OPERAND_GPR },
566 { "r27", 27, PPC_OPERAND_GPR },
567 { "r28", 28, PPC_OPERAND_GPR },
568 { "r29", 29, PPC_OPERAND_GPR },
569 { "r3", 3, PPC_OPERAND_GPR },
570 { "r30", 30, PPC_OPERAND_GPR },
571 { "r31", 31, PPC_OPERAND_GPR },
572 { "r4", 4, PPC_OPERAND_GPR },
573 { "r5", 5, PPC_OPERAND_GPR },
574 { "r6", 6, PPC_OPERAND_GPR },
575 { "r7", 7, PPC_OPERAND_GPR },
576 { "r8", 8, PPC_OPERAND_GPR },
577 { "r9", 9, PPC_OPERAND_GPR },
578
579 { "rtoc", 2, PPC_OPERAND_GPR },
580
581 { "sdr1", 25, PPC_OPERAND_SPR },
582
583 { "sp", 1, PPC_OPERAND_GPR },
584
585 { "srr0", 26, PPC_OPERAND_SPR },
586 { "srr1", 27, PPC_OPERAND_SPR },
587
588 /* Vector (Altivec/VMX) registers */
589 { "v.0", 0, PPC_OPERAND_VR },
590 { "v.1", 1, PPC_OPERAND_VR },
591 { "v.10", 10, PPC_OPERAND_VR },
592 { "v.11", 11, PPC_OPERAND_VR },
593 { "v.12", 12, PPC_OPERAND_VR },
594 { "v.13", 13, PPC_OPERAND_VR },
595 { "v.14", 14, PPC_OPERAND_VR },
596 { "v.15", 15, PPC_OPERAND_VR },
597 { "v.16", 16, PPC_OPERAND_VR },
598 { "v.17", 17, PPC_OPERAND_VR },
599 { "v.18", 18, PPC_OPERAND_VR },
600 { "v.19", 19, PPC_OPERAND_VR },
601 { "v.2", 2, PPC_OPERAND_VR },
602 { "v.20", 20, PPC_OPERAND_VR },
603 { "v.21", 21, PPC_OPERAND_VR },
604 { "v.22", 22, PPC_OPERAND_VR },
605 { "v.23", 23, PPC_OPERAND_VR },
606 { "v.24", 24, PPC_OPERAND_VR },
607 { "v.25", 25, PPC_OPERAND_VR },
608 { "v.26", 26, PPC_OPERAND_VR },
609 { "v.27", 27, PPC_OPERAND_VR },
610 { "v.28", 28, PPC_OPERAND_VR },
611 { "v.29", 29, PPC_OPERAND_VR },
612 { "v.3", 3, PPC_OPERAND_VR },
613 { "v.30", 30, PPC_OPERAND_VR },
614 { "v.31", 31, PPC_OPERAND_VR },
615 { "v.4", 4, PPC_OPERAND_VR },
616 { "v.5", 5, PPC_OPERAND_VR },
617 { "v.6", 6, PPC_OPERAND_VR },
618 { "v.7", 7, PPC_OPERAND_VR },
619 { "v.8", 8, PPC_OPERAND_VR },
620 { "v.9", 9, PPC_OPERAND_VR },
621
622 { "v0", 0, PPC_OPERAND_VR },
623 { "v1", 1, PPC_OPERAND_VR },
624 { "v10", 10, PPC_OPERAND_VR },
625 { "v11", 11, PPC_OPERAND_VR },
626 { "v12", 12, PPC_OPERAND_VR },
627 { "v13", 13, PPC_OPERAND_VR },
628 { "v14", 14, PPC_OPERAND_VR },
629 { "v15", 15, PPC_OPERAND_VR },
630 { "v16", 16, PPC_OPERAND_VR },
631 { "v17", 17, PPC_OPERAND_VR },
632 { "v18", 18, PPC_OPERAND_VR },
633 { "v19", 19, PPC_OPERAND_VR },
634 { "v2", 2, PPC_OPERAND_VR },
635 { "v20", 20, PPC_OPERAND_VR },
636 { "v21", 21, PPC_OPERAND_VR },
637 { "v22", 22, PPC_OPERAND_VR },
638 { "v23", 23, PPC_OPERAND_VR },
639 { "v24", 24, PPC_OPERAND_VR },
640 { "v25", 25, PPC_OPERAND_VR },
641 { "v26", 26, PPC_OPERAND_VR },
642 { "v27", 27, PPC_OPERAND_VR },
643 { "v28", 28, PPC_OPERAND_VR },
644 { "v29", 29, PPC_OPERAND_VR },
645 { "v3", 3, PPC_OPERAND_VR },
646 { "v30", 30, PPC_OPERAND_VR },
647 { "v31", 31, PPC_OPERAND_VR },
648 { "v4", 4, PPC_OPERAND_VR },
649 { "v5", 5, PPC_OPERAND_VR },
650 { "v6", 6, PPC_OPERAND_VR },
651 { "v7", 7, PPC_OPERAND_VR },
652 { "v8", 8, PPC_OPERAND_VR },
653 { "v9", 9, PPC_OPERAND_VR },
654
655 /* Vector Scalar (VSX) registers (ISA 2.06). */
656 { "vs.0", 0, PPC_OPERAND_VSR },
657 { "vs.1", 1, PPC_OPERAND_VSR },
658 { "vs.10", 10, PPC_OPERAND_VSR },
659 { "vs.11", 11, PPC_OPERAND_VSR },
660 { "vs.12", 12, PPC_OPERAND_VSR },
661 { "vs.13", 13, PPC_OPERAND_VSR },
662 { "vs.14", 14, PPC_OPERAND_VSR },
663 { "vs.15", 15, PPC_OPERAND_VSR },
664 { "vs.16", 16, PPC_OPERAND_VSR },
665 { "vs.17", 17, PPC_OPERAND_VSR },
666 { "vs.18", 18, PPC_OPERAND_VSR },
667 { "vs.19", 19, PPC_OPERAND_VSR },
668 { "vs.2", 2, PPC_OPERAND_VSR },
669 { "vs.20", 20, PPC_OPERAND_VSR },
670 { "vs.21", 21, PPC_OPERAND_VSR },
671 { "vs.22", 22, PPC_OPERAND_VSR },
672 { "vs.23", 23, PPC_OPERAND_VSR },
673 { "vs.24", 24, PPC_OPERAND_VSR },
674 { "vs.25", 25, PPC_OPERAND_VSR },
675 { "vs.26", 26, PPC_OPERAND_VSR },
676 { "vs.27", 27, PPC_OPERAND_VSR },
677 { "vs.28", 28, PPC_OPERAND_VSR },
678 { "vs.29", 29, PPC_OPERAND_VSR },
679 { "vs.3", 3, PPC_OPERAND_VSR },
680 { "vs.30", 30, PPC_OPERAND_VSR },
681 { "vs.31", 31, PPC_OPERAND_VSR },
682 { "vs.32", 32, PPC_OPERAND_VSR },
683 { "vs.33", 33, PPC_OPERAND_VSR },
684 { "vs.34", 34, PPC_OPERAND_VSR },
685 { "vs.35", 35, PPC_OPERAND_VSR },
686 { "vs.36", 36, PPC_OPERAND_VSR },
687 { "vs.37", 37, PPC_OPERAND_VSR },
688 { "vs.38", 38, PPC_OPERAND_VSR },
689 { "vs.39", 39, PPC_OPERAND_VSR },
690 { "vs.4", 4, PPC_OPERAND_VSR },
691 { "vs.40", 40, PPC_OPERAND_VSR },
692 { "vs.41", 41, PPC_OPERAND_VSR },
693 { "vs.42", 42, PPC_OPERAND_VSR },
694 { "vs.43", 43, PPC_OPERAND_VSR },
695 { "vs.44", 44, PPC_OPERAND_VSR },
696 { "vs.45", 45, PPC_OPERAND_VSR },
697 { "vs.46", 46, PPC_OPERAND_VSR },
698 { "vs.47", 47, PPC_OPERAND_VSR },
699 { "vs.48", 48, PPC_OPERAND_VSR },
700 { "vs.49", 49, PPC_OPERAND_VSR },
701 { "vs.5", 5, PPC_OPERAND_VSR },
702 { "vs.50", 50, PPC_OPERAND_VSR },
703 { "vs.51", 51, PPC_OPERAND_VSR },
704 { "vs.52", 52, PPC_OPERAND_VSR },
705 { "vs.53", 53, PPC_OPERAND_VSR },
706 { "vs.54", 54, PPC_OPERAND_VSR },
707 { "vs.55", 55, PPC_OPERAND_VSR },
708 { "vs.56", 56, PPC_OPERAND_VSR },
709 { "vs.57", 57, PPC_OPERAND_VSR },
710 { "vs.58", 58, PPC_OPERAND_VSR },
711 { "vs.59", 59, PPC_OPERAND_VSR },
712 { "vs.6", 6, PPC_OPERAND_VSR },
713 { "vs.60", 60, PPC_OPERAND_VSR },
714 { "vs.61", 61, PPC_OPERAND_VSR },
715 { "vs.62", 62, PPC_OPERAND_VSR },
716 { "vs.63", 63, PPC_OPERAND_VSR },
717 { "vs.7", 7, PPC_OPERAND_VSR },
718 { "vs.8", 8, PPC_OPERAND_VSR },
719 { "vs.9", 9, PPC_OPERAND_VSR },
720
721 { "vs0", 0, PPC_OPERAND_VSR },
722 { "vs1", 1, PPC_OPERAND_VSR },
723 { "vs10", 10, PPC_OPERAND_VSR },
724 { "vs11", 11, PPC_OPERAND_VSR },
725 { "vs12", 12, PPC_OPERAND_VSR },
726 { "vs13", 13, PPC_OPERAND_VSR },
727 { "vs14", 14, PPC_OPERAND_VSR },
728 { "vs15", 15, PPC_OPERAND_VSR },
729 { "vs16", 16, PPC_OPERAND_VSR },
730 { "vs17", 17, PPC_OPERAND_VSR },
731 { "vs18", 18, PPC_OPERAND_VSR },
732 { "vs19", 19, PPC_OPERAND_VSR },
733 { "vs2", 2, PPC_OPERAND_VSR },
734 { "vs20", 20, PPC_OPERAND_VSR },
735 { "vs21", 21, PPC_OPERAND_VSR },
736 { "vs22", 22, PPC_OPERAND_VSR },
737 { "vs23", 23, PPC_OPERAND_VSR },
738 { "vs24", 24, PPC_OPERAND_VSR },
739 { "vs25", 25, PPC_OPERAND_VSR },
740 { "vs26", 26, PPC_OPERAND_VSR },
741 { "vs27", 27, PPC_OPERAND_VSR },
742 { "vs28", 28, PPC_OPERAND_VSR },
743 { "vs29", 29, PPC_OPERAND_VSR },
744 { "vs3", 3, PPC_OPERAND_VSR },
745 { "vs30", 30, PPC_OPERAND_VSR },
746 { "vs31", 31, PPC_OPERAND_VSR },
747 { "vs32", 32, PPC_OPERAND_VSR },
748 { "vs33", 33, PPC_OPERAND_VSR },
749 { "vs34", 34, PPC_OPERAND_VSR },
750 { "vs35", 35, PPC_OPERAND_VSR },
751 { "vs36", 36, PPC_OPERAND_VSR },
752 { "vs37", 37, PPC_OPERAND_VSR },
753 { "vs38", 38, PPC_OPERAND_VSR },
754 { "vs39", 39, PPC_OPERAND_VSR },
755 { "vs4", 4, PPC_OPERAND_VSR },
756 { "vs40", 40, PPC_OPERAND_VSR },
757 { "vs41", 41, PPC_OPERAND_VSR },
758 { "vs42", 42, PPC_OPERAND_VSR },
759 { "vs43", 43, PPC_OPERAND_VSR },
760 { "vs44", 44, PPC_OPERAND_VSR },
761 { "vs45", 45, PPC_OPERAND_VSR },
762 { "vs46", 46, PPC_OPERAND_VSR },
763 { "vs47", 47, PPC_OPERAND_VSR },
764 { "vs48", 48, PPC_OPERAND_VSR },
765 { "vs49", 49, PPC_OPERAND_VSR },
766 { "vs5", 5, PPC_OPERAND_VSR },
767 { "vs50", 50, PPC_OPERAND_VSR },
768 { "vs51", 51, PPC_OPERAND_VSR },
769 { "vs52", 52, PPC_OPERAND_VSR },
770 { "vs53", 53, PPC_OPERAND_VSR },
771 { "vs54", 54, PPC_OPERAND_VSR },
772 { "vs55", 55, PPC_OPERAND_VSR },
773 { "vs56", 56, PPC_OPERAND_VSR },
774 { "vs57", 57, PPC_OPERAND_VSR },
775 { "vs58", 58, PPC_OPERAND_VSR },
776 { "vs59", 59, PPC_OPERAND_VSR },
777 { "vs6", 6, PPC_OPERAND_VSR },
778 { "vs60", 60, PPC_OPERAND_VSR },
779 { "vs61", 61, PPC_OPERAND_VSR },
780 { "vs62", 62, PPC_OPERAND_VSR },
781 { "vs63", 63, PPC_OPERAND_VSR },
782 { "vs7", 7, PPC_OPERAND_VSR },
783 { "vs8", 8, PPC_OPERAND_VSR },
784 { "vs9", 9, PPC_OPERAND_VSR },
785
786 { "xer", 1, PPC_OPERAND_SPR }
787 };
788
789 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
790
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. */
793
794 static const struct pd_reg *
795 reg_name_search (const struct pd_reg *regs, int regcount, const char *name)
796 {
797 int middle, low, high;
798 int cmp;
799
800 low = 0;
801 high = regcount - 1;
802
803 do
804 {
805 middle = (low + high) / 2;
806 cmp = strcasecmp (name, regs[middle].name);
807 if (cmp < 0)
808 high = middle - 1;
809 else if (cmp > 0)
810 low = middle + 1;
811 else
812 return &regs[middle];
813 }
814 while (low <= high);
815
816 return NULL;
817 }
818
819 /*
820 * Summary of register_name.
821 *
822 * in: Input_line_pointer points to 1st char of operand.
823 *
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
828 * original state.
829 */
830
831 static bool
832 register_name (expressionS *expressionP)
833 {
834 const struct pd_reg *reg;
835 char *name;
836 char *start;
837 char c;
838
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;
843
844 else if (!reg_names_p || !ISALPHA (name[0]))
845 return false;
846
847 c = get_symbol_name (&name);
848 reg = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
849
850 /* Put back the delimiting char. */
851 *input_line_pointer = c;
852
853 /* Look to see if it's in the register table. */
854 if (reg != NULL)
855 {
856 expressionP->X_op = O_register;
857 expressionP->X_add_number = reg->value;
858 expressionP->X_md = reg->flags;
859
860 /* Make the rest nice. */
861 expressionP->X_add_symbol = NULL;
862 expressionP->X_op_symbol = NULL;
863 return true;
864 }
865
866 /* Reset the line as if we had not done anything. */
867 input_line_pointer = start;
868 return false;
869 }
870 \f
871 /* This function is called for each symbol seen in an expression. It
872 handles the special parsing which PowerPC assemblers are supposed
873 to use for condition codes. */
874
875 /* Whether to do the special parsing. */
876 static bool cr_operand;
877
878 /* Names to recognize in a condition code. This table is sorted. */
879 static const struct pd_reg cr_names[] =
880 {
881 { "cr0", 0, PPC_OPERAND_CR_REG },
882 { "cr1", 1, PPC_OPERAND_CR_REG },
883 { "cr2", 2, PPC_OPERAND_CR_REG },
884 { "cr3", 3, PPC_OPERAND_CR_REG },
885 { "cr4", 4, PPC_OPERAND_CR_REG },
886 { "cr5", 5, PPC_OPERAND_CR_REG },
887 { "cr6", 6, PPC_OPERAND_CR_REG },
888 { "cr7", 7, PPC_OPERAND_CR_REG },
889 { "eq", 2, PPC_OPERAND_CR_BIT },
890 { "gt", 1, PPC_OPERAND_CR_BIT },
891 { "lt", 0, PPC_OPERAND_CR_BIT },
892 { "so", 3, PPC_OPERAND_CR_BIT },
893 { "un", 3, PPC_OPERAND_CR_BIT }
894 };
895
896 /* Parsing function. This returns non-zero if it recognized an
897 expression. */
898
899 int
900 ppc_parse_name (const char *name, expressionS *exp)
901 {
902 const struct pd_reg *reg;
903
904 if (! cr_operand)
905 return 0;
906
907 if (*name == '%')
908 ++name;
909 reg = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
910 name);
911 if (reg == NULL)
912 return 0;
913
914 exp->X_op = O_register;
915 exp->X_add_number = reg->value;
916 exp->X_md = reg->flags;
917
918 return 1;
919 }
920
921 /* Propagate X_md and check register expressions. This is to support
922 condition codes like 4*cr5+eq. */
923
924 int
925 ppc_optimize_expr (expressionS *left, operatorT op, expressionS *right)
926 {
927 /* Accept 4*cr<n> and cr<n>*4. */
928 if (op == O_multiply
929 && ((right->X_op == O_register
930 && right->X_md == PPC_OPERAND_CR_REG
931 && left->X_op == O_constant
932 && left->X_add_number == 4)
933 || (left->X_op == O_register
934 && left->X_md == PPC_OPERAND_CR_REG
935 && right->X_op == O_constant
936 && right->X_add_number == 4)))
937 {
938 left->X_op = O_register;
939 left->X_md = PPC_OPERAND_CR_REG | PPC_OPERAND_CR_BIT;
940 left->X_add_number *= right->X_add_number;
941 return 1;
942 }
943
944 /* Accept the above plus <cr bit>, and <cr bit> plus the above. */
945 if (right->X_op == O_register
946 && left->X_op == O_register
947 && op == O_add
948 && ((right->X_md == PPC_OPERAND_CR_BIT
949 && left->X_md == (PPC_OPERAND_CR_REG | PPC_OPERAND_CR_BIT))
950 || (right->X_md == (PPC_OPERAND_CR_REG | PPC_OPERAND_CR_BIT)
951 && left->X_md == PPC_OPERAND_CR_BIT)))
952 {
953 left->X_md = PPC_OPERAND_CR_BIT;
954 right->X_op = O_constant;
955 return 0;
956 }
957
958 /* Accept reg +/- constant. */
959 if (left->X_op == O_register
960 && !((op == O_add || op == O_subtract) && right->X_op == O_constant))
961 as_warn (_("invalid register expression"));
962
963 /* Accept constant + reg. */
964 if (right->X_op == O_register)
965 {
966 if (op == O_add && left->X_op == O_constant)
967 left->X_md = right->X_md;
968 else
969 as_warn (_("invalid register expression"));
970 }
971
972 return 0;
973 }
974 \f
975 /* Local variables. */
976
977 /* Whether to target xcoff64/elf64. */
978 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
979
980 /* Opcode hash table. */
981 static htab_t ppc_hash;
982
983 /* Macro hash table. */
984 static htab_t ppc_macro_hash;
985
986 #ifdef OBJ_ELF
987 /* What type of shared library support to use. */
988 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
989
990 /* Flags to set in the elf header. */
991 static flagword ppc_flags = 0;
992
993 /* Whether this is Solaris or not. */
994 #ifdef TARGET_SOLARIS_COMMENT
995 #define SOLARIS_P true
996 #else
997 #define SOLARIS_P false
998 #endif
999
1000 static bool msolaris = SOLARIS_P;
1001 #endif
1002
1003 #ifdef OBJ_XCOFF
1004
1005 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
1006 using a bunch of different sections. These assembler sections,
1007 however, are all encompassed within the .text, .data or .bss sections
1008 of the final output file. We handle this by using different
1009 subsegments within these main segments.
1010 .tdata and .tbss sections only have one type of csects for now,
1011 but it's better to follow the same construction like the others. */
1012
1013 struct ppc_xcoff_section ppc_xcoff_text_section;
1014 struct ppc_xcoff_section ppc_xcoff_data_section;
1015 struct ppc_xcoff_section ppc_xcoff_bss_section;
1016 struct ppc_xcoff_section ppc_xcoff_tdata_section;
1017 struct ppc_xcoff_section ppc_xcoff_tbss_section;
1018
1019 /* Return true if the ppc_xcoff_section structure is already
1020 initialized. */
1021 static bool
1022 ppc_xcoff_section_is_initialized (struct ppc_xcoff_section *section)
1023 {
1024 return section->segment != NULL;
1025 }
1026
1027 /* Initialize a ppc_xcoff_section.
1028 Dummy symbols are used to ensure the position of .text over .data
1029 and .tdata. Moreover, they allow all algorithms here to be sure that
1030 csects isn't NULL. These symbols won't be output. */
1031 static void
1032 ppc_init_xcoff_section (struct ppc_xcoff_section *s, segT seg)
1033 {
1034 s->segment = seg;
1035 s->next_subsegment = 2;
1036 s->csects = symbol_make ("dummy\001");
1037 symbol_get_tc (s->csects)->within = s->csects;
1038 }
1039
1040 /* The current csect. */
1041 static symbolS *ppc_current_csect;
1042
1043 /* The RS/6000 assembler uses a TOC which holds addresses of functions
1044 and variables. Symbols are put in the TOC with the .tc pseudo-op.
1045 A special relocation is used when accessing TOC entries. We handle
1046 the TOC as a subsegment within the .data segment. We set it up if
1047 we see a .toc pseudo-op, and save the csect symbol here. */
1048 static symbolS *ppc_toc_csect;
1049
1050 /* The first frag in the TOC subsegment. */
1051 static fragS *ppc_toc_frag;
1052
1053 /* The first frag in the first subsegment after the TOC in the .data
1054 segment. NULL if there are no subsegments after the TOC. */
1055 static fragS *ppc_after_toc_frag;
1056
1057 /* The current static block. */
1058 static symbolS *ppc_current_block;
1059
1060 /* The COFF debugging section; set by md_begin. This is not the
1061 .debug section, but is instead the secret BFD section which will
1062 cause BFD to set the section number of a symbol to N_DEBUG. */
1063 static asection *ppc_coff_debug_section;
1064
1065 /* Structure to set the length field of the dwarf sections. */
1066 struct dw_subsection {
1067 /* Subsections are simply linked. */
1068 struct dw_subsection *link;
1069
1070 /* The subsection number. */
1071 subsegT subseg;
1072
1073 /* Expression to compute the length of the section. */
1074 expressionS end_exp;
1075 };
1076
1077 static struct dw_section {
1078 /* Corresponding section. */
1079 segT sect;
1080
1081 /* Simply linked list of subsections with a label. */
1082 struct dw_subsection *list_subseg;
1083
1084 /* The anonymous subsection. */
1085 struct dw_subsection *anon_subseg;
1086 } dw_sections[XCOFF_DWSECT_NBR_NAMES];
1087 #endif /* OBJ_XCOFF */
1088
1089 #ifdef OBJ_ELF
1090 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
1091 unsigned long *ppc_apuinfo_list;
1092 unsigned int ppc_apuinfo_num;
1093 unsigned int ppc_apuinfo_num_alloc;
1094 #endif /* OBJ_ELF */
1095 \f
1096 #ifdef OBJ_ELF
1097 const char *const md_shortopts = "b:l:usm:K:VQ:";
1098 #else
1099 const char *const md_shortopts = "um:";
1100 #endif
1101 #define OPTION_NOPS (OPTION_MD_BASE + 0)
1102 const struct option md_longopts[] = {
1103 {"nops", required_argument, NULL, OPTION_NOPS},
1104 {"ppc476-workaround", no_argument, &warn_476, 1},
1105 {"no-ppc476-workaround", no_argument, &warn_476, 0},
1106 {NULL, no_argument, NULL, 0}
1107 };
1108 const size_t md_longopts_size = sizeof (md_longopts);
1109
1110 int
1111 md_parse_option (int c, const char *arg)
1112 {
1113 ppc_cpu_t new_cpu;
1114
1115 switch (c)
1116 {
1117 case 'u':
1118 /* -u means that any undefined symbols should be treated as
1119 external, which is the default for gas anyhow. */
1120 break;
1121
1122 #ifdef OBJ_ELF
1123 case 'l':
1124 /* Solaris as takes -le (presumably for little endian). For completeness
1125 sake, recognize -be also. */
1126 if (strcmp (arg, "e") == 0)
1127 {
1128 target_big_endian = 0;
1129 set_target_endian = 1;
1130 if (ppc_cpu & PPC_OPCODE_VLE)
1131 as_bad (_("the use of -mvle requires big endian."));
1132 }
1133 else
1134 return 0;
1135
1136 break;
1137
1138 case 'b':
1139 if (strcmp (arg, "e") == 0)
1140 {
1141 target_big_endian = 1;
1142 set_target_endian = 1;
1143 }
1144 else
1145 return 0;
1146
1147 break;
1148
1149 case 'K':
1150 /* Recognize -K PIC. */
1151 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
1152 {
1153 shlib = SHLIB_PIC;
1154 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1155 }
1156 else
1157 return 0;
1158
1159 break;
1160 #endif
1161
1162 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
1163 case 'a':
1164 if (strcmp (arg, "64") == 0)
1165 {
1166 #ifdef BFD64
1167 ppc_obj64 = 1;
1168 if (ppc_cpu & PPC_OPCODE_VLE)
1169 as_bad (_("the use of -mvle requires -a32."));
1170 #else
1171 as_fatal (_("%s unsupported"), "-a64");
1172 #endif
1173 }
1174 else if (strcmp (arg, "32") == 0)
1175 ppc_obj64 = 0;
1176 else
1177 return 0;
1178 break;
1179
1180 case 'm':
1181 new_cpu = ppc_parse_cpu (ppc_cpu, &sticky, arg);
1182 /* "raw" is only valid for the disassembler. */
1183 if (new_cpu != 0 && (new_cpu & PPC_OPCODE_RAW) == 0)
1184 {
1185 ppc_cpu = new_cpu;
1186 if (strcmp (arg, "vle") == 0)
1187 {
1188 if (set_target_endian && target_big_endian == 0)
1189 as_bad (_("the use of -mvle requires big endian."));
1190 if (ppc_obj64)
1191 as_bad (_("the use of -mvle requires -a32."));
1192 }
1193 }
1194
1195 else if (strcmp (arg, "no-vle") == 0)
1196 {
1197 sticky &= ~PPC_OPCODE_VLE;
1198
1199 new_cpu = ppc_parse_cpu (ppc_cpu, &sticky, "booke");
1200 new_cpu &= ~PPC_OPCODE_VLE;
1201
1202 ppc_cpu = new_cpu;
1203 }
1204
1205 else if (strcmp (arg, "regnames") == 0)
1206 reg_names_p = true;
1207
1208 else if (strcmp (arg, "no-regnames") == 0)
1209 reg_names_p = false;
1210
1211 #ifdef OBJ_ELF
1212 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1213 that require relocation. */
1214 else if (strcmp (arg, "relocatable") == 0)
1215 {
1216 shlib = SHLIB_MRELOCATABLE;
1217 ppc_flags |= EF_PPC_RELOCATABLE;
1218 }
1219
1220 else if (strcmp (arg, "relocatable-lib") == 0)
1221 {
1222 shlib = SHLIB_MRELOCATABLE;
1223 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1224 }
1225
1226 /* -memb, set embedded bit. */
1227 else if (strcmp (arg, "emb") == 0)
1228 ppc_flags |= EF_PPC_EMB;
1229
1230 /* -mlittle/-mbig set the endianness. */
1231 else if (strcmp (arg, "little") == 0
1232 || strcmp (arg, "little-endian") == 0)
1233 {
1234 target_big_endian = 0;
1235 set_target_endian = 1;
1236 if (ppc_cpu & PPC_OPCODE_VLE)
1237 as_bad (_("the use of -mvle requires big endian."));
1238 }
1239
1240 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
1241 {
1242 target_big_endian = 1;
1243 set_target_endian = 1;
1244 }
1245
1246 else if (strcmp (arg, "solaris") == 0)
1247 {
1248 msolaris = true;
1249 ppc_comment_chars = ppc_solaris_comment_chars;
1250 }
1251
1252 else if (strcmp (arg, "no-solaris") == 0)
1253 {
1254 msolaris = false;
1255 ppc_comment_chars = ppc_eabi_comment_chars;
1256 }
1257 else if (strcmp (arg, "spe2") == 0)
1258 {
1259 ppc_cpu |= PPC_OPCODE_SPE2;
1260 }
1261 #endif
1262 else
1263 {
1264 as_bad (_("invalid switch -m%s"), arg);
1265 return 0;
1266 }
1267 break;
1268
1269 #ifdef OBJ_ELF
1270 /* -V: SVR4 argument to print version ID. */
1271 case 'V':
1272 print_version_id ();
1273 break;
1274
1275 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1276 should be emitted or not. FIXME: Not implemented. */
1277 case 'Q':
1278 break;
1279
1280 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1281 rather than .stabs.excl, which is ignored by the linker.
1282 FIXME: Not implemented. */
1283 case 's':
1284 if (arg)
1285 return 0;
1286
1287 break;
1288 #endif
1289
1290 case OPTION_NOPS:
1291 {
1292 char *end;
1293 nop_limit = strtoul (optarg, &end, 0);
1294 if (*end)
1295 as_bad (_("--nops needs a numeric argument"));
1296 }
1297 break;
1298
1299 case 0:
1300 break;
1301
1302 default:
1303 return 0;
1304 }
1305
1306 return 1;
1307 }
1308
1309 static int
1310 is_ppc64_target (const bfd_target *targ, void *data ATTRIBUTE_UNUSED)
1311 {
1312 switch (targ->flavour)
1313 {
1314 #ifdef OBJ_ELF
1315 case bfd_target_elf_flavour:
1316 return startswith (targ->name, "elf64-powerpc");
1317 #endif
1318 #ifdef OBJ_XCOFF
1319 case bfd_target_xcoff_flavour:
1320 return (strcmp (targ->name, "aixcoff64-rs6000") == 0
1321 || strcmp (targ->name, "aix5coff64-rs6000") == 0);
1322 #endif
1323 default:
1324 return 0;
1325 }
1326 }
1327
1328 void
1329 md_show_usage (FILE *stream)
1330 {
1331 fprintf (stream, _("\
1332 PowerPC options:\n"));
1333 fprintf (stream, _("\
1334 -a32 generate ELF32/XCOFF32\n"));
1335 if (bfd_iterate_over_targets (is_ppc64_target, NULL))
1336 fprintf (stream, _("\
1337 -a64 generate ELF64/XCOFF64\n"));
1338 fprintf (stream, _("\
1339 -u ignored\n"));
1340 fprintf (stream, _("\
1341 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n"));
1342 fprintf (stream, _("\
1343 -mpwr generate code for POWER (RIOS1)\n"));
1344 fprintf (stream, _("\
1345 -m601 generate code for PowerPC 601\n"));
1346 fprintf (stream, _("\
1347 -mppc, -mppc32, -m603, -m604\n\
1348 generate code for PowerPC 603/604\n"));
1349 fprintf (stream, _("\
1350 -m403 generate code for PowerPC 403\n"));
1351 fprintf (stream, _("\
1352 -m405 generate code for PowerPC 405\n"));
1353 fprintf (stream, _("\
1354 -m440 generate code for PowerPC 440\n"));
1355 fprintf (stream, _("\
1356 -m464 generate code for PowerPC 464\n"));
1357 fprintf (stream, _("\
1358 -m476 generate code for PowerPC 476\n"));
1359 fprintf (stream, _("\
1360 -m7400, -m7410, -m7450, -m7455\n\
1361 generate code for PowerPC 7400/7410/7450/7455\n"));
1362 fprintf (stream, _("\
1363 -m750cl, -mgekko, -mbroadway\n\
1364 generate code for PowerPC 750cl/Gekko/Broadway\n"));
1365 fprintf (stream, _("\
1366 -m821, -m850, -m860 generate code for PowerPC 821/850/860\n"));
1367 fprintf (stream, _("\
1368 -mppc64, -m620 generate code for PowerPC 620/625/630\n"));
1369 fprintf (stream, _("\
1370 -mppc64bridge generate code for PowerPC 64, including bridge insns\n"));
1371 fprintf (stream, _("\
1372 -mbooke generate code for 32-bit PowerPC BookE\n"));
1373 fprintf (stream, _("\
1374 -ma2 generate code for A2 architecture\n"));
1375 fprintf (stream, _("\
1376 -mpower4, -mpwr4 generate code for Power4 architecture\n"));
1377 fprintf (stream, _("\
1378 -mpower5, -mpwr5, -mpwr5x\n\
1379 generate code for Power5 architecture\n"));
1380 fprintf (stream, _("\
1381 -mpower6, -mpwr6 generate code for Power6 architecture\n"));
1382 fprintf (stream, _("\
1383 -mpower7, -mpwr7 generate code for Power7 architecture\n"));
1384 fprintf (stream, _("\
1385 -mpower8, -mpwr8 generate code for Power8 architecture\n"));
1386 fprintf (stream, _("\
1387 -mpower9, -mpwr9 generate code for Power9 architecture\n"));
1388 fprintf (stream, _("\
1389 -mpower10, -mpwr10 generate code for Power10 architecture\n"));
1390 fprintf (stream, _("\
1391 -mcell generate code for Cell Broadband Engine architecture\n"));
1392 fprintf (stream, _("\
1393 -mcom generate code for Power/PowerPC common instructions\n"));
1394 fprintf (stream, _("\
1395 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1396 fprintf (stream, _("\
1397 -maltivec generate code for AltiVec\n"));
1398 fprintf (stream, _("\
1399 -mvsx generate code for Vector-Scalar (VSX) instructions\n"));
1400 fprintf (stream, _("\
1401 -me300 generate code for PowerPC e300 family\n"));
1402 fprintf (stream, _("\
1403 -me500, -me500x2 generate code for Motorola e500 core complex\n"));
1404 fprintf (stream, _("\
1405 -me500mc, generate code for Freescale e500mc core complex\n"));
1406 fprintf (stream, _("\
1407 -me500mc64, generate code for Freescale e500mc64 core complex\n"));
1408 fprintf (stream, _("\
1409 -me5500, generate code for Freescale e5500 core complex\n"));
1410 fprintf (stream, _("\
1411 -me6500, generate code for Freescale e6500 core complex\n"));
1412 fprintf (stream, _("\
1413 -mspe generate code for Motorola SPE instructions\n"));
1414 fprintf (stream, _("\
1415 -mspe2 generate code for Freescale SPE2 instructions\n"));
1416 fprintf (stream, _("\
1417 -mvle generate code for Freescale VLE instructions\n"));
1418 fprintf (stream, _("\
1419 -mtitan generate code for AppliedMicro Titan core complex\n"));
1420 fprintf (stream, _("\
1421 -mregnames Allow symbolic names for registers\n"));
1422 fprintf (stream, _("\
1423 -mno-regnames Do not allow symbolic names for registers\n"));
1424 #ifdef OBJ_ELF
1425 fprintf (stream, _("\
1426 -mrelocatable support for GCC's -mrelocatble option\n"));
1427 fprintf (stream, _("\
1428 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n"));
1429 fprintf (stream, _("\
1430 -memb set PPC_EMB bit in ELF flags\n"));
1431 fprintf (stream, _("\
1432 -mlittle, -mlittle-endian, -le\n\
1433 generate code for a little endian machine\n"));
1434 fprintf (stream, _("\
1435 -mbig, -mbig-endian, -be\n\
1436 generate code for a big endian machine\n"));
1437 fprintf (stream, _("\
1438 -msolaris generate code for Solaris\n"));
1439 fprintf (stream, _("\
1440 -mno-solaris do not generate code for Solaris\n"));
1441 fprintf (stream, _("\
1442 -K PIC set EF_PPC_RELOCATABLE_LIB in ELF flags\n"));
1443 fprintf (stream, _("\
1444 -V print assembler version number\n"));
1445 fprintf (stream, _("\
1446 -Qy, -Qn ignored\n"));
1447 #endif
1448 fprintf (stream, _("\
1449 -nops=count when aligning, more than COUNT nops uses a branch\n"));
1450 fprintf (stream, _("\
1451 -ppc476-workaround warn if emitting data to code sections\n"));
1452 }
1453 \f
1454 /* Set ppc_cpu if it is not already set. */
1455
1456 static void
1457 ppc_set_cpu (void)
1458 {
1459 const char *default_os = TARGET_OS;
1460 const char *default_cpu = TARGET_CPU;
1461
1462 if ((ppc_cpu & ~(ppc_cpu_t) PPC_OPCODE_ANY) == 0)
1463 {
1464 if (ppc_obj64)
1465 if (target_big_endian)
1466 ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_64;
1467 else
1468 /* The minimum supported cpu for 64-bit little-endian is power8. */
1469 ppc_cpu |= ppc_parse_cpu (ppc_cpu, &sticky, "power8");
1470 else if (startswith (default_os, "aix")
1471 && default_os[3] >= '4' && default_os[3] <= '9')
1472 ppc_cpu |= PPC_OPCODE_COMMON;
1473 else if (startswith (default_os, "aix3"))
1474 ppc_cpu |= PPC_OPCODE_POWER;
1475 else if (strcmp (default_cpu, "rs6000") == 0)
1476 ppc_cpu |= PPC_OPCODE_POWER;
1477 else if (startswith (default_cpu, "powerpc"))
1478 ppc_cpu |= PPC_OPCODE_PPC;
1479 else
1480 as_fatal (_("unknown default cpu = %s, os = %s"),
1481 default_cpu, default_os);
1482 }
1483 }
1484
1485 /* Figure out the BFD architecture to use. This function and ppc_mach
1486 are called well before md_begin, when the output file is opened. */
1487
1488 enum bfd_architecture
1489 ppc_arch (void)
1490 {
1491 const char *default_cpu = TARGET_CPU;
1492 ppc_set_cpu ();
1493
1494 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1495 return bfd_arch_powerpc;
1496 if ((ppc_cpu & PPC_OPCODE_VLE) != 0)
1497 return bfd_arch_powerpc;
1498 if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1499 return bfd_arch_rs6000;
1500 if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1501 {
1502 if (strcmp (default_cpu, "rs6000") == 0)
1503 return bfd_arch_rs6000;
1504 else if (startswith (default_cpu, "powerpc"))
1505 return bfd_arch_powerpc;
1506 }
1507
1508 as_fatal (_("neither Power nor PowerPC opcodes were selected."));
1509 return bfd_arch_unknown;
1510 }
1511
1512 unsigned long
1513 ppc_mach (void)
1514 {
1515 if (ppc_obj64)
1516 return bfd_mach_ppc64;
1517 else if (ppc_arch () == bfd_arch_rs6000)
1518 return bfd_mach_rs6k;
1519 else if (ppc_cpu & PPC_OPCODE_TITAN)
1520 return bfd_mach_ppc_titan;
1521 else if (ppc_cpu & PPC_OPCODE_VLE)
1522 return bfd_mach_ppc_vle;
1523 else
1524 return bfd_mach_ppc;
1525 }
1526
1527 extern const char*
1528 ppc_target_format (void)
1529 {
1530 #ifdef OBJ_COFF
1531 #if TE_POWERMAC
1532 return "xcoff-powermac";
1533 #else
1534 # ifdef TE_AIX5
1535 return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1536 # else
1537 return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1538 # endif
1539 #endif
1540 #endif
1541 #ifdef OBJ_ELF
1542 # ifdef TE_FreeBSD
1543 return (ppc_obj64 ? "elf64-powerpc-freebsd" : "elf32-powerpc-freebsd");
1544 # elif defined (TE_VXWORKS)
1545 return "elf32-powerpc-vxworks";
1546 # else
1547 return (target_big_endian
1548 ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc")
1549 : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1550 # endif
1551 #endif
1552 }
1553
1554 /* Validate one entry in powerpc_opcodes[] or vle_opcodes[].
1555 Return TRUE if there's a problem, otherwise FALSE. */
1556
1557 static bool
1558 insn_validate (const struct powerpc_opcode *op)
1559 {
1560 const unsigned char *o;
1561 uint64_t omask = op->mask;
1562
1563 /* The mask had better not trim off opcode bits. */
1564 if ((op->opcode & omask) != op->opcode)
1565 {
1566 as_bad (_("mask trims opcode bits for %s"), op->name);
1567 return true;
1568 }
1569
1570 /* The operands must not overlap the opcode or each other. */
1571 for (o = op->operands; *o; ++o)
1572 {
1573 bool optional = false;
1574 if (*o >= num_powerpc_operands)
1575 {
1576 as_bad (_("operand index error for %s"), op->name);
1577 return true;
1578 }
1579 else
1580 {
1581 uint64_t mask;
1582 const struct powerpc_operand *operand = &powerpc_operands[*o];
1583 if (operand->shift == (int) PPC_OPSHIFT_INV)
1584 {
1585 const char *errmsg;
1586 uint64_t val;
1587
1588 errmsg = NULL;
1589 val = -1;
1590 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1591 val = -val;
1592 else if ((operand->flags & PPC_OPERAND_PLUS1) != 0)
1593 val += 1;
1594 mask = (*operand->insert) (0, val, ppc_cpu, &errmsg);
1595 }
1596 else if (operand->shift >= 0)
1597 mask = operand->bitm << operand->shift;
1598 else
1599 mask = operand->bitm >> -operand->shift;
1600 if (omask & mask)
1601 {
1602 as_bad (_("operand %d overlap in %s"),
1603 (int) (o - op->operands), op->name);
1604 return true;
1605 }
1606 omask |= mask;
1607 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1608 optional = true;
1609 else if (optional)
1610 {
1611 as_bad (_("non-optional operand %d follows optional operand in %s"),
1612 (int) (o - op->operands), op->name);
1613 return true;
1614 }
1615 }
1616 }
1617 return false;
1618 }
1619
1620 /* Insert opcodes and macros into hash tables. Called at startup and
1621 for .machine pseudo. */
1622
1623 static void
1624 ppc_setup_opcodes (void)
1625 {
1626 const struct powerpc_opcode *op;
1627 const struct powerpc_opcode *op_end;
1628 const struct powerpc_macro *macro;
1629 const struct powerpc_macro *macro_end;
1630 bool bad_insn = false;
1631
1632 if (ppc_hash != NULL)
1633 htab_delete (ppc_hash);
1634 if (ppc_macro_hash != NULL)
1635 htab_delete (ppc_macro_hash);
1636
1637 /* Insert the opcodes into a hash table. */
1638 ppc_hash = str_htab_create ();
1639
1640 if (ENABLE_CHECKING)
1641 {
1642 unsigned int i;
1643
1644 /* An index into powerpc_operands is stored in struct fix
1645 fx_pcrel_adjust which is 8 bits wide. */
1646 gas_assert (num_powerpc_operands < 256);
1647
1648 /* Check operand masks. Code here and in the disassembler assumes
1649 all the 1's in the mask are contiguous. */
1650 for (i = 0; i < num_powerpc_operands; ++i)
1651 {
1652 uint64_t mask = powerpc_operands[i].bitm;
1653 uint64_t right_bit;
1654 unsigned int j;
1655
1656 right_bit = mask & -mask;
1657 mask += right_bit;
1658 right_bit = mask & -mask;
1659 if (mask != right_bit)
1660 {
1661 as_bad (_("powerpc_operands[%d].bitm invalid"), i);
1662 bad_insn = true;
1663 }
1664 for (j = i + 1; j < num_powerpc_operands; ++j)
1665 if (memcmp (&powerpc_operands[i], &powerpc_operands[j],
1666 sizeof (powerpc_operands[0])) == 0)
1667 {
1668 as_bad (_("powerpc_operands[%d] duplicates powerpc_operands[%d]"),
1669 j, i);
1670 bad_insn = true;
1671 }
1672 }
1673 }
1674
1675 op_end = powerpc_opcodes + powerpc_num_opcodes;
1676 for (op = powerpc_opcodes; op < op_end; op++)
1677 {
1678 if (ENABLE_CHECKING)
1679 {
1680 unsigned int new_opcode = PPC_OP (op[0].opcode);
1681
1682 #ifdef PRINT_OPCODE_TABLE
1683 printf ("%-14s\t#%04u\tmajor op: 0x%x\top: 0x%llx\tmask: 0x%llx\tflags: 0x%llx\n",
1684 op->name, (unsigned int) (op - powerpc_opcodes),
1685 new_opcode, (unsigned long long) op->opcode,
1686 (unsigned long long) op->mask, (unsigned long long) op->flags);
1687 #endif
1688
1689 /* The major opcodes had better be sorted. Code in the disassembler
1690 assumes the insns are sorted according to major opcode. */
1691 if (op != powerpc_opcodes
1692 && new_opcode < PPC_OP (op[-1].opcode))
1693 {
1694 as_bad (_("major opcode is not sorted for %s"), op->name);
1695 bad_insn = true;
1696 }
1697
1698 if ((op->flags & PPC_OPCODE_VLE) != 0)
1699 {
1700 as_bad (_("%s is enabled by vle flag"), op->name);
1701 bad_insn = true;
1702 }
1703 if (PPC_OP (op->opcode) != 4
1704 && PPC_OP (op->opcode) != 31
1705 && (op->deprecated & PPC_OPCODE_VLE) == 0)
1706 {
1707 as_bad (_("%s not disabled by vle flag"), op->name);
1708 bad_insn = true;
1709 }
1710 bad_insn |= insn_validate (op);
1711 }
1712
1713 if ((ppc_cpu & op->flags) != 0
1714 && !(ppc_cpu & op->deprecated)
1715 && str_hash_insert (ppc_hash, op->name, op, 0) != NULL)
1716 {
1717 as_bad (_("duplicate %s"), op->name);
1718 bad_insn = true;
1719 }
1720 }
1721
1722 if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
1723 for (op = powerpc_opcodes; op < op_end; op++)
1724 str_hash_insert (ppc_hash, op->name, op, 0);
1725
1726 op_end = prefix_opcodes + prefix_num_opcodes;
1727 for (op = prefix_opcodes; op < op_end; op++)
1728 {
1729 if (ENABLE_CHECKING)
1730 {
1731 unsigned int new_opcode = PPC_PREFIX_SEG (op[0].opcode);
1732
1733 #ifdef PRINT_OPCODE_TABLE
1734 printf ("%-14s\t#%04u\tmajor op/2: 0x%x\top: 0x%llx\tmask: 0x%llx\tflags: 0x%llx\n",
1735 op->name, (unsigned int) (op - prefix_opcodes),
1736 new_opcode, (unsigned long long) op->opcode,
1737 (unsigned long long) op->mask, (unsigned long long) op->flags);
1738 #endif
1739
1740 /* The major opcodes had better be sorted. Code in the disassembler
1741 assumes the insns are sorted according to major opcode. */
1742 if (op != prefix_opcodes
1743 && new_opcode < PPC_PREFIX_SEG (op[-1].opcode))
1744 {
1745 as_bad (_("major opcode is not sorted for %s"), op->name);
1746 bad_insn = true;
1747 }
1748 bad_insn |= insn_validate (op);
1749 }
1750
1751 if ((ppc_cpu & op->flags) != 0
1752 && !(ppc_cpu & op->deprecated)
1753 && str_hash_insert (ppc_hash, op->name, op, 0) != NULL)
1754 {
1755 as_bad (_("duplicate %s"), op->name);
1756 bad_insn = true;
1757 }
1758 }
1759
1760 if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
1761 for (op = prefix_opcodes; op < op_end; op++)
1762 str_hash_insert (ppc_hash, op->name, op, 0);
1763
1764 op_end = vle_opcodes + vle_num_opcodes;
1765 for (op = vle_opcodes; op < op_end; op++)
1766 {
1767 if (ENABLE_CHECKING)
1768 {
1769 unsigned new_seg = VLE_OP_TO_SEG (VLE_OP (op[0].opcode, op[0].mask));
1770
1771 #ifdef PRINT_OPCODE_TABLE
1772 printf ("%-14s\t#%04u\tmajor op: 0x%x\top: 0x%llx\tmask: 0x%llx\tflags: 0x%llx\n",
1773 op->name, (unsigned int) (op - vle_opcodes),
1774 (unsigned int) new_seg, (unsigned long long) op->opcode,
1775 (unsigned long long) op->mask, (unsigned long long) op->flags);
1776 #endif
1777
1778 /* The major opcodes had better be sorted. Code in the disassembler
1779 assumes the insns are sorted according to major opcode. */
1780 if (op != vle_opcodes
1781 && new_seg < VLE_OP_TO_SEG (VLE_OP (op[-1].opcode, op[-1].mask)))
1782 {
1783 as_bad (_("major opcode is not sorted for %s"), op->name);
1784 bad_insn = true;
1785 }
1786
1787 bad_insn |= insn_validate (op);
1788 }
1789
1790 if ((ppc_cpu & op->flags) != 0
1791 && !(ppc_cpu & op->deprecated)
1792 && str_hash_insert (ppc_hash, op->name, op, 0) != NULL)
1793 {
1794 as_bad (_("duplicate %s"), op->name);
1795 bad_insn = true;
1796 }
1797 }
1798
1799 /* SPE2 instructions */
1800 if ((ppc_cpu & PPC_OPCODE_SPE2) == PPC_OPCODE_SPE2)
1801 {
1802 op_end = spe2_opcodes + spe2_num_opcodes;
1803 for (op = spe2_opcodes; op < op_end; op++)
1804 {
1805 if (ENABLE_CHECKING)
1806 {
1807 if (op != spe2_opcodes)
1808 {
1809 unsigned old_seg, new_seg;
1810
1811 old_seg = VLE_OP (op[-1].opcode, op[-1].mask);
1812 old_seg = VLE_OP_TO_SEG (old_seg);
1813 new_seg = VLE_OP (op[0].opcode, op[0].mask);
1814 new_seg = VLE_OP_TO_SEG (new_seg);
1815
1816 /* The major opcodes had better be sorted. Code in the
1817 disassembler assumes the insns are sorted according to
1818 major opcode. */
1819 if (new_seg < old_seg)
1820 {
1821 as_bad (_("major opcode is not sorted for %s"), op->name);
1822 bad_insn = true;
1823 }
1824 }
1825
1826 bad_insn |= insn_validate (op);
1827 }
1828
1829 if ((ppc_cpu & op->flags) != 0
1830 && !(ppc_cpu & op->deprecated)
1831 && str_hash_insert (ppc_hash, op->name, op, 0) != NULL)
1832 {
1833 as_bad (_("duplicate %s"), op->name);
1834 bad_insn = true;
1835 }
1836 }
1837
1838 for (op = spe2_opcodes; op < op_end; op++)
1839 str_hash_insert (ppc_hash, op->name, op, 0);
1840 }
1841
1842 /* Insert the macros into a hash table. */
1843 ppc_macro_hash = str_htab_create ();
1844
1845 macro_end = powerpc_macros + powerpc_num_macros;
1846 for (macro = powerpc_macros; macro < macro_end; macro++)
1847 if (((macro->flags & ppc_cpu) != 0
1848 || (ppc_cpu & PPC_OPCODE_ANY) != 0)
1849 && str_hash_insert (ppc_macro_hash, macro->name, macro, 0) != NULL)
1850 {
1851 as_bad (_("duplicate %s"), macro->name);
1852 bad_insn = true;
1853 }
1854
1855 if (bad_insn)
1856 abort ();
1857 }
1858
1859 /* This function is called when the assembler starts up. It is called
1860 after the options have been parsed and the output file has been
1861 opened. */
1862
1863 void
1864 md_begin (void)
1865 {
1866 ppc_set_cpu ();
1867
1868 ppc_cie_data_alignment = ppc_obj64 ? -8 : -4;
1869 ppc_dwarf2_line_min_insn_length = (ppc_cpu & PPC_OPCODE_VLE) ? 2 : 4;
1870
1871 #ifdef OBJ_ELF
1872 /* Set the ELF flags if desired. */
1873 if (ppc_flags && !msolaris)
1874 bfd_set_private_flags (stdoutput, ppc_flags);
1875 #endif
1876
1877 ppc_setup_opcodes ();
1878
1879 /* Tell the main code what the endianness is if it is not overridden
1880 by the user. */
1881 if (!set_target_endian)
1882 {
1883 set_target_endian = 1;
1884 target_big_endian = PPC_BIG_ENDIAN;
1885 }
1886
1887 #ifdef OBJ_XCOFF
1888 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1889
1890 /* Create XCOFF sections with .text in first, as it's creating dummy symbols
1891 to serve as initial csects. This forces the text csects to precede the
1892 data csects. These symbols will not be output. */
1893 ppc_init_xcoff_section (&ppc_xcoff_text_section, text_section);
1894 ppc_init_xcoff_section (&ppc_xcoff_data_section, data_section);
1895 ppc_init_xcoff_section (&ppc_xcoff_bss_section, bss_section);
1896 #endif
1897 }
1898
1899 void
1900 ppc_cleanup (void)
1901 {
1902 #ifdef OBJ_ELF
1903 if (ppc_apuinfo_list == NULL)
1904 return;
1905
1906 /* Ok, so write the section info out. We have this layout:
1907
1908 byte data what
1909 ---- ---- ----
1910 0 8 length of "APUinfo\0"
1911 4 (n*4) number of APU's (4 bytes each)
1912 8 2 note type 2
1913 12 "APUinfo\0" name
1914 20 APU#1 first APU's info
1915 24 APU#2 second APU's info
1916 ... ...
1917 */
1918 {
1919 char *p;
1920 asection *seg = now_seg;
1921 subsegT subseg = now_subseg;
1922 asection *apuinfo_secp = (asection *) NULL;
1923 unsigned int i;
1924
1925 /* Create the .PPC.EMB.apuinfo section. */
1926 apuinfo_secp = subseg_new (APUINFO_SECTION_NAME, 0);
1927 bfd_set_section_flags (apuinfo_secp, SEC_HAS_CONTENTS | SEC_READONLY);
1928
1929 p = frag_more (4);
1930 md_number_to_chars (p, (valueT) 8, 4);
1931
1932 p = frag_more (4);
1933 md_number_to_chars (p, (valueT) ppc_apuinfo_num * 4, 4);
1934
1935 p = frag_more (4);
1936 md_number_to_chars (p, (valueT) 2, 4);
1937
1938 p = frag_more (8);
1939 strcpy (p, APUINFO_LABEL);
1940
1941 for (i = 0; i < ppc_apuinfo_num; i++)
1942 {
1943 p = frag_more (4);
1944 md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4);
1945 }
1946
1947 frag_align (2, 0, 0);
1948
1949 /* We probably can't restore the current segment, for there likely
1950 isn't one yet... */
1951 if (seg && subseg)
1952 subseg_set (seg, subseg);
1953 }
1954 #endif
1955 }
1956
1957 /* Insert an operand value into an instruction. */
1958
1959 static uint64_t
1960 ppc_insert_operand (uint64_t insn,
1961 const struct powerpc_operand *operand,
1962 int64_t val,
1963 ppc_cpu_t cpu,
1964 const char *file,
1965 unsigned int line)
1966 {
1967 int64_t min, max, right;
1968
1969 max = operand->bitm;
1970 right = max & -max;
1971 min = 0;
1972
1973 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1974 {
1975 /* Extend the allowed range for addis to [-32768, 65535].
1976 Similarly for cmpli and some VLE high part insns. For 64-bit
1977 it would be good to disable this for signed fields since the
1978 value is sign extended into the high 32 bits of the register.
1979 If the value is, say, an address, then we might care about
1980 the high bits. However, gcc as of 2014-06 uses unsigned
1981 values when loading the high part of 64-bit constants using
1982 lis. */
1983 min = ~(max >> 1) & -right;
1984 }
1985 else if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1986 {
1987 max = (max >> 1) & -right;
1988 min = ~max & -right;
1989 }
1990
1991 if ((operand->flags & PPC_OPERAND_PLUS1) != 0)
1992 max++;
1993
1994 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1995 {
1996 int64_t tmp = min;
1997 min = -max;
1998 max = -tmp;
1999 }
2000
2001 if (min <= max)
2002 {
2003 /* Some people write constants with the sign extension done by
2004 hand but only up to 32 bits. This shouldn't really be valid,
2005 but, to permit this code to assemble on a 64-bit host, we
2006 sign extend the 32-bit value to 64 bits if so doing makes the
2007 value valid. We only do this for operands that are 32-bits or
2008 smaller. */
2009 if (val > max
2010 && (operand->bitm & ~0xffffffffULL) == 0
2011 && (val - (1LL << 32)) >= min
2012 && (val - (1LL << 32)) <= max
2013 && ((val - (1LL << 32)) & (right - 1)) == 0)
2014 val = val - (1LL << 32);
2015
2016 /* Similarly, people write expressions like ~(1<<15), and expect
2017 this to be OK for a 32-bit unsigned value. */
2018 else if (val < min
2019 && (operand->bitm & ~0xffffffffULL) == 0
2020 && (val + (1LL << 32)) >= min
2021 && (val + (1LL << 32)) <= max
2022 && ((val + (1LL << 32)) & (right - 1)) == 0)
2023 val = val + (1LL << 32);
2024
2025 else if (val < min
2026 || val > max
2027 || (val & (right - 1)) != 0)
2028 as_bad_value_out_of_range (_("operand"), val, min, max, file, line);
2029 }
2030
2031 if (operand->insert)
2032 {
2033 const char *errmsg;
2034
2035 errmsg = NULL;
2036 insn = (*operand->insert) (insn, val, cpu, &errmsg);
2037 if (errmsg != (const char *) NULL)
2038 as_bad_where (file, line, "%s", errmsg);
2039 }
2040 else if (operand->shift >= 0)
2041 insn |= (val & operand->bitm) << operand->shift;
2042 else
2043 insn |= (val & operand->bitm) >> -operand->shift;
2044
2045 return insn;
2046 }
2047
2048 \f
2049 #ifdef OBJ_ELF
2050 /* Parse @got, etc. and return the desired relocation. */
2051 static bfd_reloc_code_real_type
2052 ppc_elf_suffix (char **str_p, expressionS *exp_p)
2053 {
2054 struct map_bfd {
2055 const char *string;
2056 unsigned int length : 8;
2057 unsigned int valid32 : 1;
2058 unsigned int valid64 : 1;
2059 unsigned int reloc;
2060 };
2061
2062 char ident[20];
2063 char *str = *str_p;
2064 char *str2;
2065 int ch;
2066 int len;
2067 const struct map_bfd *ptr;
2068
2069 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
2070 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
2071 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
2072
2073 static const struct map_bfd mapping[] = {
2074 MAP ("l", BFD_RELOC_LO16),
2075 MAP ("h", BFD_RELOC_HI16),
2076 MAP ("ha", BFD_RELOC_HI16_S),
2077 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
2078 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
2079 MAP ("got", BFD_RELOC_16_GOTOFF),
2080 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
2081 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
2082 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
2083 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
2084 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
2085 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
2086 MAP ("copy", BFD_RELOC_PPC_COPY),
2087 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
2088 MAP ("sectoff", BFD_RELOC_16_BASEREL),
2089 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
2090 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
2091 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
2092 MAP ("tls", BFD_RELOC_PPC_TLS),
2093 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD),
2094 MAP ("dtprel", BFD_RELOC_PPC_DTPREL),
2095 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO),
2096 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI),
2097 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA),
2098 MAP ("tprel", BFD_RELOC_PPC_TPREL),
2099 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO),
2100 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI),
2101 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA),
2102 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16),
2103 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO),
2104 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI),
2105 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA),
2106 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16),
2107 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO),
2108 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI),
2109 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA),
2110 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16),
2111 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO),
2112 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI),
2113 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA),
2114 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16),
2115 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO),
2116 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI),
2117 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA),
2118 MAP32 ("fixup", BFD_RELOC_CTOR),
2119 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL),
2120 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL),
2121 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
2122 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC),
2123 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL),
2124 MAP32 ("sdarel", BFD_RELOC_GPREL16),
2125 MAP32 ("sdarel@l", BFD_RELOC_PPC_VLE_SDAREL_LO16A),
2126 MAP32 ("sdarel@h", BFD_RELOC_PPC_VLE_SDAREL_HI16A),
2127 MAP32 ("sdarel@ha", BFD_RELOC_PPC_VLE_SDAREL_HA16A),
2128 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
2129 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
2130 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
2131 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
2132 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
2133 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
2134 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
2135 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
2136 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21),
2137 MAP32 ("sda21@l", BFD_RELOC_PPC_VLE_SDA21_LO),
2138 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
2139 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
2140 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
2141 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
2142 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
2143 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
2144 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
2145 MAP32 ("xgot", BFD_RELOC_PPC_TOC16),
2146 MAP64 ("high", BFD_RELOC_PPC64_ADDR16_HIGH),
2147 MAP64 ("higha", BFD_RELOC_PPC64_ADDR16_HIGHA),
2148 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER),
2149 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S),
2150 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST),
2151 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S),
2152 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC),
2153 MAP64 ("toc", BFD_RELOC_PPC_TOC16),
2154 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO),
2155 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI),
2156 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA),
2157 MAP64 ("dtprel@high", BFD_RELOC_PPC64_DTPREL16_HIGH),
2158 MAP64 ("dtprel@higha", BFD_RELOC_PPC64_DTPREL16_HIGHA),
2159 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER),
2160 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA),
2161 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST),
2162 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA),
2163 MAP64 ("localentry", BFD_RELOC_PPC64_ADDR64_LOCAL),
2164 MAP64 ("tprel@high", BFD_RELOC_PPC64_TPREL16_HIGH),
2165 MAP64 ("tprel@higha", BFD_RELOC_PPC64_TPREL16_HIGHA),
2166 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER),
2167 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA),
2168 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST),
2169 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA),
2170 MAP64 ("notoc", BFD_RELOC_PPC64_REL24_NOTOC),
2171 MAP64 ("pcrel", BFD_RELOC_PPC64_PCREL34),
2172 MAP64 ("got@pcrel", BFD_RELOC_PPC64_GOT_PCREL34),
2173 MAP64 ("plt@pcrel", BFD_RELOC_PPC64_PLT_PCREL34),
2174 MAP64 ("tls@pcrel", BFD_RELOC_PPC64_TLS_PCREL),
2175 MAP64 ("got@tlsgd@pcrel", BFD_RELOC_PPC64_GOT_TLSGD_PCREL34),
2176 MAP64 ("got@tlsld@pcrel", BFD_RELOC_PPC64_GOT_TLSLD_PCREL34),
2177 MAP64 ("got@tprel@pcrel", BFD_RELOC_PPC64_GOT_TPREL_PCREL34),
2178 MAP64 ("got@dtprel@pcrel", BFD_RELOC_PPC64_GOT_DTPREL_PCREL34),
2179 MAP64 ("higher34", BFD_RELOC_PPC64_ADDR16_HIGHER34),
2180 MAP64 ("highera34", BFD_RELOC_PPC64_ADDR16_HIGHERA34),
2181 MAP64 ("highest34", BFD_RELOC_PPC64_ADDR16_HIGHEST34),
2182 MAP64 ("highesta34", BFD_RELOC_PPC64_ADDR16_HIGHESTA34),
2183 { (char *) 0, 0, 0, 0, BFD_RELOC_NONE }
2184 };
2185
2186 if (*str++ != '@')
2187 return BFD_RELOC_NONE;
2188
2189 for (ch = *str, str2 = ident;
2190 (str2 < ident + sizeof (ident) - 1
2191 && (ISALNUM (ch) || ch == '@'));
2192 ch = *++str)
2193 {
2194 *str2++ = TOLOWER (ch);
2195 }
2196
2197 *str2 = '\0';
2198 len = str2 - ident;
2199
2200 ch = ident[0];
2201 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
2202 if (ch == ptr->string[0]
2203 && len == ptr->length
2204 && memcmp (ident, ptr->string, ptr->length) == 0
2205 && (ppc_obj64 ? ptr->valid64 : ptr->valid32))
2206 {
2207 int reloc = ptr->reloc;
2208
2209 if (!ppc_obj64 && (exp_p->X_op == O_big || exp_p->X_add_number != 0))
2210 {
2211 switch (reloc)
2212 {
2213 case BFD_RELOC_16_GOTOFF:
2214 case BFD_RELOC_LO16_GOTOFF:
2215 case BFD_RELOC_HI16_GOTOFF:
2216 case BFD_RELOC_HI16_S_GOTOFF:
2217 as_warn (_("symbol+offset@%s means symbol@%s+offset"),
2218 ptr->string, ptr->string);
2219 break;
2220
2221 case BFD_RELOC_PPC_GOT_TLSGD16:
2222 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
2223 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
2224 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
2225 case BFD_RELOC_PPC_GOT_TLSLD16:
2226 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
2227 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
2228 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
2229 case BFD_RELOC_PPC_GOT_DTPREL16:
2230 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
2231 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
2232 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
2233 case BFD_RELOC_PPC_GOT_TPREL16:
2234 case BFD_RELOC_PPC_GOT_TPREL16_LO:
2235 case BFD_RELOC_PPC_GOT_TPREL16_HI:
2236 case BFD_RELOC_PPC_GOT_TPREL16_HA:
2237 as_bad (_("symbol+offset@%s not supported"), ptr->string);
2238 break;
2239 }
2240 }
2241
2242 /* Now check for identifier@suffix+constant. */
2243 if (*str == '-' || *str == '+')
2244 {
2245 char *orig_line = input_line_pointer;
2246 expressionS new_exp;
2247
2248 input_line_pointer = str;
2249 expression (&new_exp);
2250 if (new_exp.X_op == O_constant && exp_p->X_op != O_big)
2251 {
2252 exp_p->X_add_number += new_exp.X_add_number;
2253 str = input_line_pointer;
2254 }
2255 input_line_pointer = orig_line;
2256 }
2257 *str_p = str;
2258
2259 if (reloc == (int) BFD_RELOC_PPC64_TOC
2260 && exp_p->X_op == O_symbol
2261 && strcmp (S_GET_NAME (exp_p->X_add_symbol), ".TOC.") == 0)
2262 {
2263 /* Change the symbol so that the dummy .TOC. symbol can be
2264 omitted from the object file. */
2265 exp_p->X_add_symbol = &abs_symbol;
2266 }
2267
2268 if (reloc == BFD_RELOC_PPC64_REL24_NOTOC
2269 && (ppc_cpu & PPC_OPCODE_POWER10) == 0)
2270 reloc = BFD_RELOC_PPC64_REL24_P9NOTOC;
2271
2272 return (bfd_reloc_code_real_type) reloc;
2273 }
2274
2275 return BFD_RELOC_NONE;
2276 }
2277
2278 /* Support @got, etc. on constants emitted via .short, .int etc. */
2279
2280 bfd_reloc_code_real_type
2281 ppc_elf_parse_cons (expressionS *exp, unsigned int nbytes)
2282 {
2283 expression (exp);
2284 if (nbytes >= 2 && *input_line_pointer == '@')
2285 return ppc_elf_suffix (&input_line_pointer, exp);
2286 return BFD_RELOC_NONE;
2287 }
2288
2289 /* Warn when emitting data to code sections, unless we are emitting
2290 a relocation that ld --ppc476-workaround uses to recognise data
2291 *and* there was an unconditional branch prior to the data. */
2292
2293 void
2294 ppc_elf_cons_fix_check (expressionS *exp ATTRIBUTE_UNUSED,
2295 unsigned int nbytes, fixS *fix)
2296 {
2297 if (warn_476
2298 && (now_seg->flags & SEC_CODE) != 0
2299 && (nbytes != 4
2300 || fix == NULL
2301 || !(fix->fx_r_type == BFD_RELOC_32
2302 || fix->fx_r_type == BFD_RELOC_CTOR
2303 || fix->fx_r_type == BFD_RELOC_32_PCREL)
2304 || !(last_seg == now_seg && last_subseg == now_subseg)
2305 || !((last_insn & (0x3f << 26)) == (18u << 26)
2306 || ((last_insn & (0x3f << 26)) == (16u << 26)
2307 && (last_insn & (0x14 << 21)) == (0x14 << 21))
2308 || ((last_insn & (0x3f << 26)) == (19u << 26)
2309 && (last_insn & (0x3ff << 1)) == (16u << 1)
2310 && (last_insn & (0x14 << 21)) == (0x14 << 21)))))
2311 {
2312 /* Flag that we've warned. */
2313 if (fix != NULL)
2314 fix->fx_tcbit = 1;
2315
2316 as_warn (_("data in executable section"));
2317 }
2318 }
2319
2320 /* Solaris pseduo op to change to the .rodata section. */
2321 static void
2322 ppc_elf_rdata (int xxx)
2323 {
2324 char *save_line = input_line_pointer;
2325 static char section[] = ".rodata\n";
2326
2327 /* Just pretend this is .section .rodata */
2328 input_line_pointer = section;
2329 obj_elf_section (xxx);
2330
2331 input_line_pointer = save_line;
2332 }
2333
2334 /* Pseudo op to make file scope bss items. */
2335 static void
2336 ppc_elf_lcomm (int xxx ATTRIBUTE_UNUSED)
2337 {
2338 char *name;
2339 char c;
2340 char *p;
2341 offsetT size;
2342 symbolS *symbolP;
2343 offsetT align;
2344 segT old_sec;
2345 int old_subsec;
2346 char *pfrag;
2347 int align2;
2348
2349 c = get_symbol_name (&name);
2350
2351 /* Just after name is now '\0'. */
2352 p = input_line_pointer;
2353 *p = c;
2354 SKIP_WHITESPACE_AFTER_NAME ();
2355 if (*input_line_pointer != ',')
2356 {
2357 as_bad (_("expected comma after symbol-name: rest of line ignored."));
2358 ignore_rest_of_line ();
2359 return;
2360 }
2361
2362 input_line_pointer++; /* skip ',' */
2363 if ((size = get_absolute_expression ()) < 0)
2364 {
2365 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
2366 ignore_rest_of_line ();
2367 return;
2368 }
2369
2370 /* The third argument to .lcomm is the alignment. */
2371 if (*input_line_pointer != ',')
2372 align = 8;
2373 else
2374 {
2375 ++input_line_pointer;
2376 align = get_absolute_expression ();
2377 if (align <= 0)
2378 {
2379 as_warn (_("ignoring bad alignment"));
2380 align = 8;
2381 }
2382 }
2383
2384 *p = 0;
2385 symbolP = symbol_find_or_make (name);
2386 *p = c;
2387
2388 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
2389 {
2390 as_bad (_("ignoring attempt to re-define symbol `%s'."),
2391 S_GET_NAME (symbolP));
2392 ignore_rest_of_line ();
2393 return;
2394 }
2395
2396 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
2397 {
2398 as_bad (_("length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
2399 S_GET_NAME (symbolP),
2400 (long) S_GET_VALUE (symbolP),
2401 (long) size);
2402
2403 ignore_rest_of_line ();
2404 return;
2405 }
2406
2407 /* Allocate_bss. */
2408 old_sec = now_seg;
2409 old_subsec = now_subseg;
2410 if (align)
2411 {
2412 /* Convert to a power of 2 alignment. */
2413 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
2414 if (align != 1)
2415 {
2416 as_bad (_("common alignment not a power of 2"));
2417 ignore_rest_of_line ();
2418 return;
2419 }
2420 }
2421 else
2422 align2 = 0;
2423
2424 record_alignment (bss_section, align2);
2425 subseg_set (bss_section, 1);
2426 if (align2)
2427 frag_align (align2, 0, 0);
2428 if (S_GET_SEGMENT (symbolP) == bss_section)
2429 symbol_get_frag (symbolP)->fr_symbol = 0;
2430 symbol_set_frag (symbolP, frag_now);
2431 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
2432 (char *) 0);
2433 *pfrag = 0;
2434 S_SET_SIZE (symbolP, size);
2435 S_SET_SEGMENT (symbolP, bss_section);
2436 subseg_set (old_sec, old_subsec);
2437 demand_empty_rest_of_line ();
2438 }
2439
2440 /* Pseudo op to set symbol local entry point. */
2441 static void
2442 ppc_elf_localentry (int ignore ATTRIBUTE_UNUSED)
2443 {
2444 char *name;
2445 char c = get_symbol_name (&name);
2446 char *p;
2447 expressionS exp;
2448 symbolS *sym;
2449 asymbol *bfdsym;
2450 elf_symbol_type *elfsym;
2451
2452 p = input_line_pointer;
2453 *p = c;
2454 SKIP_WHITESPACE_AFTER_NAME ();
2455 if (*input_line_pointer != ',')
2456 {
2457 *p = 0;
2458 as_bad (_("expected comma after name `%s' in .localentry directive"),
2459 name);
2460 *p = c;
2461 ignore_rest_of_line ();
2462 return;
2463 }
2464 input_line_pointer++;
2465 expression (&exp);
2466 if (exp.X_op == O_absent)
2467 {
2468 as_bad (_("missing expression in .localentry directive"));
2469 exp.X_op = O_constant;
2470 exp.X_add_number = 0;
2471 }
2472 *p = 0;
2473 sym = symbol_find_or_make (name);
2474 *p = c;
2475
2476 if (resolve_expression (&exp)
2477 && exp.X_op == O_constant)
2478 {
2479 unsigned int encoded, ok;
2480
2481 ok = 1;
2482 if (exp.X_add_number == 1 || exp.X_add_number == 7)
2483 encoded = exp.X_add_number << STO_PPC64_LOCAL_BIT;
2484 else
2485 {
2486 encoded = PPC64_SET_LOCAL_ENTRY_OFFSET (exp.X_add_number);
2487 if (exp.X_add_number != (offsetT) PPC64_LOCAL_ENTRY_OFFSET (encoded))
2488 {
2489 as_bad (_(".localentry expression for `%s' "
2490 "is not a valid power of 2"), S_GET_NAME (sym));
2491 ok = 0;
2492 }
2493 }
2494 if (ok)
2495 {
2496 bfdsym = symbol_get_bfdsym (sym);
2497 elfsym = elf_symbol_from (bfdsym);
2498 gas_assert (elfsym);
2499 elfsym->internal_elf_sym.st_other &= ~STO_PPC64_LOCAL_MASK;
2500 elfsym->internal_elf_sym.st_other |= encoded;
2501 if (ppc_abiversion == 0)
2502 ppc_abiversion = 2;
2503 }
2504 }
2505 else
2506 as_bad (_(".localentry expression for `%s' "
2507 "does not evaluate to a constant"), S_GET_NAME (sym));
2508
2509 demand_empty_rest_of_line ();
2510 }
2511
2512 /* Pseudo op to set ABI version. */
2513 static void
2514 ppc_elf_abiversion (int ignore ATTRIBUTE_UNUSED)
2515 {
2516 expressionS exp;
2517
2518 expression (&exp);
2519 if (exp.X_op == O_absent)
2520 {
2521 as_bad (_("missing expression in .abiversion directive"));
2522 exp.X_op = O_constant;
2523 exp.X_add_number = 0;
2524 }
2525
2526 if (resolve_expression (&exp)
2527 && exp.X_op == O_constant)
2528 ppc_abiversion = exp.X_add_number;
2529 else
2530 as_bad (_(".abiversion expression does not evaluate to a constant"));
2531 demand_empty_rest_of_line ();
2532 }
2533
2534 /* Parse a .gnu_attribute directive. */
2535 static void
2536 ppc_elf_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2537 {
2538 int tag = obj_elf_vendor_attribute (OBJ_ATTR_GNU);
2539
2540 /* Check validity of defined powerpc tags. */
2541 if (tag == Tag_GNU_Power_ABI_FP
2542 || tag == Tag_GNU_Power_ABI_Vector
2543 || tag == Tag_GNU_Power_ABI_Struct_Return)
2544 {
2545 unsigned int val;
2546
2547 val = bfd_elf_get_obj_attr_int (stdoutput, OBJ_ATTR_GNU, tag);
2548
2549 if ((tag == Tag_GNU_Power_ABI_FP && val > 15)
2550 || (tag == Tag_GNU_Power_ABI_Vector && val > 3)
2551 || (tag == Tag_GNU_Power_ABI_Struct_Return && val > 2))
2552 as_warn (_("unknown .gnu_attribute value"));
2553 }
2554 }
2555
2556 /* Set ABI version in output file. */
2557 void
2558 ppc_elf_end (void)
2559 {
2560 if (ppc_obj64 && ppc_abiversion != 0)
2561 {
2562 elf_elfheader (stdoutput)->e_flags &= ~EF_PPC64_ABI;
2563 elf_elfheader (stdoutput)->e_flags |= ppc_abiversion & EF_PPC64_ABI;
2564 }
2565 /* Any selection of opcodes based on ppc_cpu after gas has finished
2566 parsing the file is invalid. md_apply_fix and ppc_handle_align
2567 must select opcodes based on the machine in force at the point
2568 where the fixup or alignment frag was created, not the machine in
2569 force at the end of file. */
2570 ppc_cpu = 0;
2571 }
2572
2573 /* Validate any relocations emitted for -mrelocatable, possibly adding
2574 fixups for word relocations in writable segments, so we can adjust
2575 them at runtime. */
2576 static void
2577 ppc_elf_validate_fix (fixS *fixp, segT seg)
2578 {
2579 if (fixp->fx_done || fixp->fx_pcrel)
2580 return;
2581
2582 switch (shlib)
2583 {
2584 case SHLIB_NONE:
2585 case SHLIB_PIC:
2586 return;
2587
2588 case SHLIB_MRELOCATABLE:
2589 if (fixp->fx_r_type != BFD_RELOC_16_GOTOFF
2590 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
2591 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
2592 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
2593 && fixp->fx_r_type != BFD_RELOC_16_BASEREL
2594 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
2595 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
2596 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
2597 && (seg->flags & SEC_LOAD) != 0
2598 && strcmp (segment_name (seg), ".got2") != 0
2599 && strcmp (segment_name (seg), ".dtors") != 0
2600 && strcmp (segment_name (seg), ".ctors") != 0
2601 && strcmp (segment_name (seg), ".fixup") != 0
2602 && strcmp (segment_name (seg), ".gcc_except_table") != 0
2603 && strcmp (segment_name (seg), ".eh_frame") != 0
2604 && strcmp (segment_name (seg), ".ex_shared") != 0)
2605 {
2606 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
2607 || fixp->fx_r_type != BFD_RELOC_CTOR)
2608 {
2609 as_bad_where (fixp->fx_file, fixp->fx_line,
2610 _("relocation cannot be done when using -mrelocatable"));
2611 }
2612 }
2613 return;
2614 }
2615 }
2616
2617 /* Prevent elf_frob_file_before_adjust removing a weak undefined
2618 function descriptor sym if the corresponding code sym is used. */
2619
2620 void
2621 ppc_frob_file_before_adjust (void)
2622 {
2623 symbolS *symp;
2624 asection *toc;
2625
2626 if (!ppc_obj64)
2627 return;
2628
2629 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
2630 {
2631 const char *name;
2632 char *dotname;
2633 symbolS *dotsym;
2634
2635 name = S_GET_NAME (symp);
2636 if (name[0] == '.')
2637 continue;
2638
2639 if (! S_IS_WEAK (symp)
2640 || S_IS_DEFINED (symp))
2641 continue;
2642
2643 dotname = concat (".", name, (char *) NULL);
2644 dotsym = symbol_find_noref (dotname, 1);
2645 free (dotname);
2646 if (dotsym != NULL && (symbol_used_p (dotsym)
2647 || symbol_used_in_reloc_p (dotsym)))
2648 symbol_mark_used (symp);
2649
2650 }
2651
2652 toc = bfd_get_section_by_name (stdoutput, ".toc");
2653 if (toc != NULL
2654 && toc_reloc_types != has_large_toc_reloc
2655 && bfd_section_size (toc) > 0x10000)
2656 as_warn (_("TOC section size exceeds 64k"));
2657 }
2658
2659 /* .TOC. used in an opd entry as .TOC.@tocbase doesn't need to be
2660 emitted. Other uses of .TOC. will cause the symbol to be marked
2661 with BSF_KEEP in md_apply_fix. */
2662
2663 void
2664 ppc_elf_adjust_symtab (void)
2665 {
2666 if (ppc_obj64)
2667 {
2668 symbolS *symp;
2669 symp = symbol_find (".TOC.");
2670 if (symp != NULL)
2671 {
2672 asymbol *bsym = symbol_get_bfdsym (symp);
2673 if ((bsym->flags & BSF_KEEP) == 0)
2674 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2675 }
2676 }
2677 }
2678 #endif /* OBJ_ELF */
2679
2680 #ifdef OBJ_XCOFF
2681 /* Parse XCOFF relocations. */
2682 static bfd_reloc_code_real_type
2683 ppc_xcoff_suffix (char **str_p)
2684 {
2685 struct map_bfd {
2686 const char *string;
2687 unsigned int length : 8;
2688 unsigned int valid32 : 1;
2689 unsigned int valid64 : 1;
2690 unsigned int reloc;
2691 };
2692
2693 char ident[20];
2694 char *str = *str_p;
2695 char *str2;
2696 int ch;
2697 int len;
2698 const struct map_bfd *ptr;
2699
2700 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
2701 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
2702 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
2703
2704 static const struct map_bfd mapping[] = {
2705 MAP ("l", BFD_RELOC_PPC_TOC16_LO),
2706 MAP ("u", BFD_RELOC_PPC_TOC16_HI),
2707 MAP32 ("ie", BFD_RELOC_PPC_TLSIE),
2708 MAP32 ("ld", BFD_RELOC_PPC_TLSLD),
2709 MAP32 ("le", BFD_RELOC_PPC_TLSLE),
2710 MAP32 ("m", BFD_RELOC_PPC_TLSM),
2711 MAP32 ("ml", BFD_RELOC_PPC_TLSML),
2712 MAP64 ("ie", BFD_RELOC_PPC64_TLSIE),
2713 MAP64 ("ld", BFD_RELOC_PPC64_TLSLD),
2714 MAP64 ("le", BFD_RELOC_PPC64_TLSLE),
2715 MAP64 ("m", BFD_RELOC_PPC64_TLSM),
2716 MAP64 ("ml", BFD_RELOC_PPC64_TLSML),
2717 };
2718
2719 if (*str++ != '@')
2720 return BFD_RELOC_NONE;
2721
2722 for (ch = *str, str2 = ident;
2723 (str2 < ident + sizeof (ident) - 1
2724 && (ISALNUM (ch) || ch == '@'));
2725 ch = *++str)
2726 {
2727 *str2++ = TOLOWER (ch);
2728 }
2729
2730 *str2 = '\0';
2731 len = str2 - ident;
2732
2733 ch = ident[0];
2734 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
2735 if (ch == ptr->string[0]
2736 && len == ptr->length
2737 && memcmp (ident, ptr->string, ptr->length) == 0
2738 && (ppc_obj64 ? ptr->valid64 : ptr->valid32))
2739 {
2740 *str_p = str;
2741 return (bfd_reloc_code_real_type) ptr->reloc;
2742 }
2743
2744 return BFD_RELOC_NONE;
2745 }
2746
2747 /* Restore XCOFF addis instruction to ELF format.
2748 AIX often generates addis instructions using "addis RT,D(RA)"
2749 format instead of the ELF "addis RT,RA,SI" one.
2750 On entry RT_E is at the comma after RT, D_E is at the open
2751 parenthesis after D, and RA_E is at the close parenthesis after RA. */
2752 static void
2753 ppc_xcoff_fixup_addis (char *rt_e, char *d_e, char *ra_e)
2754 {
2755 size_t ra_size = ra_e - d_e - 1;
2756 char *save_ra = xmalloc (ra_size);
2757
2758 /* Copy RA. */
2759 memcpy (save_ra, d_e + 1, ra_size);
2760 /* Shuffle D to make room for RA, copying the comma too. */
2761 memmove (rt_e + ra_size + 1, rt_e, d_e - rt_e);
2762 /* Erase the trailing ')', keeping any rubbish for potential errors. */
2763 memmove (ra_e, ra_e + 1, strlen (ra_e));
2764 /* Write RA back. */
2765 memcpy (rt_e + 1, save_ra, ra_size);
2766 free (save_ra);
2767 }
2768
2769 /* Support @ie, etc. on constants emitted via .short, .int etc. */
2770
2771 bfd_reloc_code_real_type
2772 ppc_xcoff_parse_cons (expressionS *exp, unsigned int nbytes)
2773 {
2774 expression (exp);
2775 if (nbytes >= 2 && *input_line_pointer == '@')
2776 return ppc_xcoff_suffix (&input_line_pointer);
2777
2778 /* There isn't any @ symbol for default TLS relocations (R_TLS). */
2779 if (exp->X_add_symbol != NULL
2780 && (symbol_get_tc (exp->X_add_symbol)->symbol_class == XMC_TL
2781 || symbol_get_tc (exp->X_add_symbol)->symbol_class == XMC_UL))
2782 return (ppc_obj64 ? BFD_RELOC_PPC64_TLSGD: BFD_RELOC_PPC_TLSGD);
2783
2784 return BFD_RELOC_NONE;
2785 }
2786
2787 #endif /* OBJ_XCOFF */
2788 \f
2789 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
2790 /* See whether a symbol is in the TOC section. */
2791
2792 static int
2793 ppc_is_toc_sym (symbolS *sym)
2794 {
2795 #ifdef OBJ_XCOFF
2796 return (symbol_get_tc (sym)->symbol_class == XMC_TC
2797 || symbol_get_tc (sym)->symbol_class == XMC_TE
2798 || symbol_get_tc (sym)->symbol_class == XMC_TC0);
2799 #endif
2800 #ifdef OBJ_ELF
2801 const char *sname = segment_name (S_GET_SEGMENT (sym));
2802 if (ppc_obj64)
2803 return strcmp (sname, ".toc") == 0;
2804 else
2805 return strcmp (sname, ".got") == 0;
2806 #endif
2807 }
2808 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
2809 \f
2810
2811 #ifdef OBJ_ELF
2812 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2813 static void
2814 ppc_apuinfo_section_add (unsigned int apu, unsigned int version)
2815 {
2816 unsigned int i;
2817
2818 /* Check we don't already exist. */
2819 for (i = 0; i < ppc_apuinfo_num; i++)
2820 if (ppc_apuinfo_list[i] == APUID (apu, version))
2821 return;
2822
2823 if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2824 {
2825 if (ppc_apuinfo_num_alloc == 0)
2826 {
2827 ppc_apuinfo_num_alloc = 4;
2828 ppc_apuinfo_list = XNEWVEC (unsigned long, ppc_apuinfo_num_alloc);
2829 }
2830 else
2831 {
2832 ppc_apuinfo_num_alloc += 4;
2833 ppc_apuinfo_list = XRESIZEVEC (unsigned long, ppc_apuinfo_list,
2834 ppc_apuinfo_num_alloc);
2835 }
2836 }
2837 ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2838 }
2839 #undef APUID
2840 #endif
2841 \f
2842 /* Various frobbings of labels and their addresses. */
2843
2844 /* Symbols labelling the current insn. */
2845 struct insn_label_list
2846 {
2847 struct insn_label_list *next;
2848 symbolS *label;
2849 };
2850
2851 static struct insn_label_list *insn_labels;
2852 static struct insn_label_list *free_insn_labels;
2853
2854 static void
2855 ppc_record_label (symbolS *sym)
2856 {
2857 struct insn_label_list *l;
2858
2859 if (free_insn_labels == NULL)
2860 l = XNEW (struct insn_label_list);
2861 else
2862 {
2863 l = free_insn_labels;
2864 free_insn_labels = l->next;
2865 }
2866
2867 l->label = sym;
2868 l->next = insn_labels;
2869 insn_labels = l;
2870 }
2871
2872 static void
2873 ppc_clear_labels (void)
2874 {
2875 while (insn_labels != NULL)
2876 {
2877 struct insn_label_list *l = insn_labels;
2878 insn_labels = l->next;
2879 l->next = free_insn_labels;
2880 free_insn_labels = l;
2881 }
2882 }
2883
2884 void
2885 ppc_start_line_hook (void)
2886 {
2887 ppc_clear_labels ();
2888 }
2889
2890 void
2891 ppc_new_dot_label (symbolS *sym)
2892 {
2893 ppc_record_label (sym);
2894 #ifdef OBJ_XCOFF
2895 /* Anchor this label to the current csect for relocations. */
2896 symbol_get_tc (sym)->within = ppc_current_csect;
2897 #endif
2898 }
2899
2900 void
2901 ppc_frob_label (symbolS *sym)
2902 {
2903 ppc_record_label (sym);
2904
2905 #ifdef OBJ_XCOFF
2906 /* Set the class of a label based on where it is defined. This handles
2907 symbols without suffixes. Also, move the symbol so that it follows
2908 the csect symbol. */
2909 if (ppc_current_csect != (symbolS *) NULL)
2910 {
2911 if (symbol_get_tc (sym)->symbol_class == -1)
2912 symbol_get_tc (sym)->symbol_class = symbol_get_tc (ppc_current_csect)->symbol_class;
2913
2914 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2915 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
2916 &symbol_rootP, &symbol_lastP);
2917 /* Update last csect symbol. */
2918 symbol_get_tc (ppc_current_csect)->within = sym;
2919
2920 /* Some labels like .bs are using within differently.
2921 So avoid changing it, if it's already set. */
2922 if (symbol_get_tc (sym)->within == NULL)
2923 symbol_get_tc (sym)->within = ppc_current_csect;
2924 }
2925 #endif
2926
2927 #ifdef OBJ_ELF
2928 dwarf2_emit_label (sym);
2929 #endif
2930 }
2931
2932 /* We need to keep a list of fixups. We can't simply generate them as
2933 we go, because that would require us to first create the frag, and
2934 that would screw up references to ``.''. */
2935
2936 struct ppc_fixup
2937 {
2938 expressionS exp;
2939 int opindex;
2940 bfd_reloc_code_real_type reloc;
2941 };
2942
2943 #define MAX_INSN_FIXUPS (5)
2944
2945 /* Return the field size operated on by RELOC, and whether it is
2946 pc-relative in PC_RELATIVE. */
2947
2948 static unsigned int
2949 fixup_size (bfd_reloc_code_real_type reloc, bool *pc_relative)
2950 {
2951 unsigned int size = 0;
2952 bool pcrel = false;
2953
2954 switch (reloc)
2955 {
2956 /* This switch statement must handle all BFD_RELOC values
2957 possible in instruction fixups. As is, it handles all
2958 BFD_RELOC values used in bfd/elf64-ppc.c, bfd/elf32-ppc.c,
2959 bfd/coff-rs6000.c and bfd/coff64-rs6000.c.
2960 Overkill since data and marker relocs need not be handled
2961 here, but this way we can be sure a needed fixup reloc isn't
2962 accidentally omitted. */
2963 case BFD_RELOC_PPC_EMB_MRKREF:
2964 case BFD_RELOC_VTABLE_ENTRY:
2965 case BFD_RELOC_VTABLE_INHERIT:
2966 break;
2967
2968 case BFD_RELOC_8:
2969 size = 1;
2970 break;
2971
2972 case BFD_RELOC_16:
2973 case BFD_RELOC_16_BASEREL:
2974 case BFD_RELOC_16_GOTOFF:
2975 case BFD_RELOC_GPREL16:
2976 case BFD_RELOC_HI16:
2977 case BFD_RELOC_HI16_BASEREL:
2978 case BFD_RELOC_HI16_GOTOFF:
2979 case BFD_RELOC_HI16_PLTOFF:
2980 case BFD_RELOC_HI16_S:
2981 case BFD_RELOC_HI16_S_BASEREL:
2982 case BFD_RELOC_HI16_S_GOTOFF:
2983 case BFD_RELOC_HI16_S_PLTOFF:
2984 case BFD_RELOC_LO16:
2985 case BFD_RELOC_LO16_BASEREL:
2986 case BFD_RELOC_LO16_GOTOFF:
2987 case BFD_RELOC_LO16_PLTOFF:
2988 case BFD_RELOC_PPC64_ADDR16_DS:
2989 case BFD_RELOC_PPC64_ADDR16_HIGH:
2990 case BFD_RELOC_PPC64_ADDR16_HIGHA:
2991 case BFD_RELOC_PPC64_ADDR16_HIGHER34:
2992 case BFD_RELOC_PPC64_ADDR16_HIGHERA34:
2993 case BFD_RELOC_PPC64_ADDR16_HIGHEST34:
2994 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34:
2995 case BFD_RELOC_PPC64_ADDR16_LO_DS:
2996 case BFD_RELOC_PPC64_DTPREL16_DS:
2997 case BFD_RELOC_PPC64_DTPREL16_HIGH:
2998 case BFD_RELOC_PPC64_DTPREL16_HIGHA:
2999 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
3000 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
3001 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
3002 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
3003 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
3004 case BFD_RELOC_PPC64_GOT16_DS:
3005 case BFD_RELOC_PPC64_GOT16_LO_DS:
3006 case BFD_RELOC_PPC64_HIGHER:
3007 case BFD_RELOC_PPC64_HIGHER_S:
3008 case BFD_RELOC_PPC64_HIGHEST:
3009 case BFD_RELOC_PPC64_HIGHEST_S:
3010 case BFD_RELOC_PPC64_PLT16_LO_DS:
3011 case BFD_RELOC_PPC64_PLTGOT16:
3012 case BFD_RELOC_PPC64_PLTGOT16_DS:
3013 case BFD_RELOC_PPC64_PLTGOT16_HA:
3014 case BFD_RELOC_PPC64_PLTGOT16_HI:
3015 case BFD_RELOC_PPC64_PLTGOT16_LO:
3016 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
3017 case BFD_RELOC_PPC64_SECTOFF_DS:
3018 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
3019 case BFD_RELOC_PPC64_TOC16_DS:
3020 case BFD_RELOC_PPC64_TOC16_HA:
3021 case BFD_RELOC_PPC64_TOC16_HI:
3022 case BFD_RELOC_PPC64_TOC16_LO:
3023 case BFD_RELOC_PPC64_TOC16_LO_DS:
3024 case BFD_RELOC_PPC64_TPREL16_DS:
3025 case BFD_RELOC_PPC64_TPREL16_HIGH:
3026 case BFD_RELOC_PPC64_TPREL16_HIGHA:
3027 case BFD_RELOC_PPC64_TPREL16_HIGHER:
3028 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
3029 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
3030 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
3031 case BFD_RELOC_PPC64_TPREL16_LO_DS:
3032 #ifdef OBJ_XCOFF
3033 case BFD_RELOC_PPC_BA16:
3034 #endif
3035 case BFD_RELOC_PPC_DTPREL16:
3036 case BFD_RELOC_PPC_DTPREL16_HA:
3037 case BFD_RELOC_PPC_DTPREL16_HI:
3038 case BFD_RELOC_PPC_DTPREL16_LO:
3039 case BFD_RELOC_PPC_EMB_NADDR16:
3040 case BFD_RELOC_PPC_EMB_NADDR16_HA:
3041 case BFD_RELOC_PPC_EMB_NADDR16_HI:
3042 case BFD_RELOC_PPC_EMB_NADDR16_LO:
3043 case BFD_RELOC_PPC_EMB_RELSDA:
3044 case BFD_RELOC_PPC_EMB_RELSEC16:
3045 case BFD_RELOC_PPC_EMB_RELST_LO:
3046 case BFD_RELOC_PPC_EMB_RELST_HI:
3047 case BFD_RELOC_PPC_EMB_RELST_HA:
3048 case BFD_RELOC_PPC_EMB_SDA2I16:
3049 case BFD_RELOC_PPC_EMB_SDA2REL:
3050 case BFD_RELOC_PPC_EMB_SDAI16:
3051 case BFD_RELOC_PPC_GOT_DTPREL16:
3052 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
3053 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
3054 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
3055 case BFD_RELOC_PPC_GOT_TLSGD16:
3056 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
3057 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
3058 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
3059 case BFD_RELOC_PPC_GOT_TLSLD16:
3060 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
3061 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
3062 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
3063 case BFD_RELOC_PPC_GOT_TPREL16:
3064 case BFD_RELOC_PPC_GOT_TPREL16_HA:
3065 case BFD_RELOC_PPC_GOT_TPREL16_HI:
3066 case BFD_RELOC_PPC_GOT_TPREL16_LO:
3067 case BFD_RELOC_PPC_TOC16:
3068 case BFD_RELOC_PPC_TOC16_HI:
3069 case BFD_RELOC_PPC_TOC16_LO:
3070 case BFD_RELOC_PPC_TPREL16:
3071 case BFD_RELOC_PPC_TPREL16_HA:
3072 case BFD_RELOC_PPC_TPREL16_HI:
3073 case BFD_RELOC_PPC_TPREL16_LO:
3074 size = 2;
3075 break;
3076
3077 case BFD_RELOC_16_PCREL:
3078 case BFD_RELOC_HI16_PCREL:
3079 case BFD_RELOC_HI16_S_PCREL:
3080 case BFD_RELOC_LO16_PCREL:
3081 case BFD_RELOC_PPC64_REL16_HIGH:
3082 case BFD_RELOC_PPC64_REL16_HIGHA:
3083 case BFD_RELOC_PPC64_REL16_HIGHER:
3084 case BFD_RELOC_PPC64_REL16_HIGHER34:
3085 case BFD_RELOC_PPC64_REL16_HIGHERA:
3086 case BFD_RELOC_PPC64_REL16_HIGHERA34:
3087 case BFD_RELOC_PPC64_REL16_HIGHEST:
3088 case BFD_RELOC_PPC64_REL16_HIGHEST34:
3089 case BFD_RELOC_PPC64_REL16_HIGHESTA:
3090 case BFD_RELOC_PPC64_REL16_HIGHESTA34:
3091 #ifdef OBJ_XCOFF
3092 case BFD_RELOC_PPC_B16:
3093 #endif
3094 case BFD_RELOC_PPC_VLE_REL8:
3095 size = 2;
3096 pcrel = true;
3097 break;
3098
3099 case BFD_RELOC_32:
3100 case BFD_RELOC_32_PLTOFF:
3101 #ifdef OBJ_XCOFF
3102 case BFD_RELOC_CTOR:
3103 #endif
3104 case BFD_RELOC_PPC64_ENTRY:
3105 case BFD_RELOC_PPC_16DX_HA:
3106 #ifndef OBJ_XCOFF
3107 case BFD_RELOC_PPC_BA16:
3108 #endif
3109 case BFD_RELOC_PPC_BA16_BRNTAKEN:
3110 case BFD_RELOC_PPC_BA16_BRTAKEN:
3111 case BFD_RELOC_PPC_BA26:
3112 case BFD_RELOC_PPC_EMB_BIT_FLD:
3113 case BFD_RELOC_PPC_EMB_NADDR32:
3114 case BFD_RELOC_PPC_EMB_SDA21:
3115 case BFD_RELOC_PPC_TLS:
3116 case BFD_RELOC_PPC_TLSGD:
3117 case BFD_RELOC_PPC_TLSLD:
3118 case BFD_RELOC_PPC_TLSLE:
3119 case BFD_RELOC_PPC_TLSIE:
3120 case BFD_RELOC_PPC_TLSM:
3121 case BFD_RELOC_PPC_TLSML:
3122 case BFD_RELOC_PPC_VLE_HA16A:
3123 case BFD_RELOC_PPC_VLE_HA16D:
3124 case BFD_RELOC_PPC_VLE_HI16A:
3125 case BFD_RELOC_PPC_VLE_HI16D:
3126 case BFD_RELOC_PPC_VLE_LO16A:
3127 case BFD_RELOC_PPC_VLE_LO16D:
3128 case BFD_RELOC_PPC_VLE_SDA21:
3129 case BFD_RELOC_PPC_VLE_SDA21_LO:
3130 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
3131 case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
3132 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
3133 case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
3134 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
3135 case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
3136 case BFD_RELOC_PPC64_TLS_PCREL:
3137 case BFD_RELOC_RVA:
3138 size = 4;
3139 break;
3140
3141 case BFD_RELOC_24_PLT_PCREL:
3142 case BFD_RELOC_32_PCREL:
3143 case BFD_RELOC_32_PLT_PCREL:
3144 case BFD_RELOC_PPC64_REL24_NOTOC:
3145 case BFD_RELOC_PPC64_REL24_P9NOTOC:
3146 #ifndef OBJ_XCOFF
3147 case BFD_RELOC_PPC_B16:
3148 #endif
3149 case BFD_RELOC_PPC_B16_BRNTAKEN:
3150 case BFD_RELOC_PPC_B16_BRTAKEN:
3151 case BFD_RELOC_PPC_B26:
3152 case BFD_RELOC_PPC_LOCAL24PC:
3153 case BFD_RELOC_PPC_REL16DX_HA:
3154 case BFD_RELOC_PPC_VLE_REL15:
3155 case BFD_RELOC_PPC_VLE_REL24:
3156 size = 4;
3157 pcrel = true;
3158 break;
3159
3160 #ifndef OBJ_XCOFF
3161 case BFD_RELOC_CTOR:
3162 #endif
3163 case BFD_RELOC_PPC_COPY:
3164 case BFD_RELOC_PPC_DTPMOD:
3165 case BFD_RELOC_PPC_DTPREL:
3166 case BFD_RELOC_PPC_GLOB_DAT:
3167 case BFD_RELOC_PPC_TPREL:
3168 size = ppc_obj64 ? 8 : 4;
3169 break;
3170
3171 case BFD_RELOC_64:
3172 case BFD_RELOC_64_PLTOFF:
3173 case BFD_RELOC_PPC64_ADDR64_LOCAL:
3174 case BFD_RELOC_PPC64_D28:
3175 case BFD_RELOC_PPC64_D34:
3176 case BFD_RELOC_PPC64_D34_LO:
3177 case BFD_RELOC_PPC64_D34_HI30:
3178 case BFD_RELOC_PPC64_D34_HA30:
3179 case BFD_RELOC_PPC64_TPREL34:
3180 case BFD_RELOC_PPC64_DTPREL34:
3181 case BFD_RELOC_PPC64_TOC:
3182 case BFD_RELOC_PPC64_TLSGD:
3183 case BFD_RELOC_PPC64_TLSLD:
3184 case BFD_RELOC_PPC64_TLSLE:
3185 case BFD_RELOC_PPC64_TLSIE:
3186 case BFD_RELOC_PPC64_TLSM:
3187 case BFD_RELOC_PPC64_TLSML:
3188 size = 8;
3189 break;
3190
3191 case BFD_RELOC_64_PCREL:
3192 case BFD_RELOC_64_PLT_PCREL:
3193 case BFD_RELOC_PPC64_GOT_PCREL34:
3194 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34:
3195 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34:
3196 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34:
3197 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34:
3198 case BFD_RELOC_PPC64_PCREL28:
3199 case BFD_RELOC_PPC64_PCREL34:
3200 case BFD_RELOC_PPC64_PLT_PCREL34:
3201 size = 8;
3202 pcrel = true;
3203 break;
3204
3205 default:
3206 abort ();
3207 }
3208
3209 if (ENABLE_CHECKING)
3210 {
3211 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
3212 if (reloc_howto != NULL
3213 && (size != bfd_get_reloc_size (reloc_howto)
3214 || pcrel != reloc_howto->pc_relative))
3215 {
3216 as_bad (_("%s howto doesn't match size/pcrel in gas"),
3217 reloc_howto->name);
3218 abort ();
3219 }
3220 }
3221 *pc_relative = pcrel;
3222 return size;
3223 }
3224
3225 #ifdef OBJ_ELF
3226 /* If we have parsed a call to __tls_get_addr, parse an argument like
3227 (gd0@tlsgd). *STR is the leading parenthesis on entry. If an arg
3228 is successfully parsed, *STR is updated past the trailing
3229 parenthesis and trailing white space, and *TLS_FIX contains the
3230 reloc and arg expression. */
3231
3232 static int
3233 parse_tls_arg (char **str, const expressionS *exp, struct ppc_fixup *tls_fix)
3234 {
3235 const char *sym_name = S_GET_NAME (exp->X_add_symbol);
3236 if (sym_name[0] == '.')
3237 ++sym_name;
3238
3239 tls_fix->reloc = BFD_RELOC_NONE;
3240 if (strncasecmp (sym_name, "__tls_get_addr", 14) == 0
3241 && (sym_name[14] == 0
3242 || strcasecmp (sym_name + 14, "_desc") == 0
3243 || strcasecmp (sym_name + 14, "_opt") == 0))
3244 {
3245 char *hold = input_line_pointer;
3246 input_line_pointer = *str + 1;
3247 expression (&tls_fix->exp);
3248 if (tls_fix->exp.X_op == O_symbol)
3249 {
3250 if (strncasecmp (input_line_pointer, "@tlsgd)", 7) == 0)
3251 tls_fix->reloc = BFD_RELOC_PPC_TLSGD;
3252 else if (strncasecmp (input_line_pointer, "@tlsld)", 7) == 0)
3253 tls_fix->reloc = BFD_RELOC_PPC_TLSLD;
3254 if (tls_fix->reloc != BFD_RELOC_NONE)
3255 {
3256 input_line_pointer += 7;
3257 SKIP_WHITESPACE ();
3258 *str = input_line_pointer;
3259 }
3260 }
3261 input_line_pointer = hold;
3262 }
3263 return tls_fix->reloc != BFD_RELOC_NONE;
3264 }
3265 #endif
3266
3267 /* This routine is called for each instruction to be assembled. */
3268
3269 void
3270 md_assemble (char *str)
3271 {
3272 char *s;
3273 const struct powerpc_opcode *opcode;
3274 uint64_t insn;
3275 const unsigned char *opindex_ptr;
3276 int need_paren;
3277 int next_opindex;
3278 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
3279 int fc;
3280 char *f;
3281 int addr_mask;
3282 int i;
3283 unsigned int insn_length;
3284
3285 /* Get the opcode. */
3286 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
3287 ;
3288 if (*s != '\0')
3289 *s++ = '\0';
3290
3291 /* Look up the opcode in the hash table. */
3292 opcode = (const struct powerpc_opcode *) str_hash_find (ppc_hash, str);
3293 if (opcode == (const struct powerpc_opcode *) NULL)
3294 {
3295 const struct powerpc_macro *macro;
3296
3297 macro = (const struct powerpc_macro *) str_hash_find (ppc_macro_hash,
3298 str);
3299 if (macro == (const struct powerpc_macro *) NULL)
3300 as_bad (_("unrecognized opcode: `%s'"), str);
3301 else
3302 ppc_macro (s, macro);
3303
3304 ppc_clear_labels ();
3305 return;
3306 }
3307
3308 insn = opcode->opcode;
3309 if (!target_big_endian
3310 && ((insn & ~(1 << 26)) == 46u << 26
3311 || (insn & ~(0xc0 << 1)) == (31u << 26 | 533 << 1)))
3312 {
3313 /* lmw, stmw, lswi, lswx, stswi, stswx */
3314 as_bad (_("`%s' invalid when little-endian"), str);
3315 ppc_clear_labels ();
3316 return;
3317 }
3318
3319 str = s;
3320 while (ISSPACE (*str))
3321 ++str;
3322
3323 #ifdef OBJ_XCOFF
3324 /* AIX often generates addis instructions using "addis RT, D(RA)"
3325 format instead of the classic "addis RT, RA, SI" one.
3326 Restore it to the default format as it's the one encoded
3327 in ppc opcodes. */
3328 if (!strcmp (opcode->name, "addis"))
3329 {
3330 char *rt_e = strchr (str, ',');
3331 if (rt_e != NULL
3332 && strchr (rt_e + 1, ',') == NULL)
3333 {
3334 char *d_e = strchr (rt_e + 1, '(');
3335 if (d_e != NULL && d_e != rt_e + 1)
3336 {
3337 char *ra_e = strrchr (d_e + 1, ')');
3338 if (ra_e != NULL && ra_e != d_e + 1)
3339 ppc_xcoff_fixup_addis (rt_e, d_e, ra_e);
3340 }
3341 }
3342 }
3343 #endif
3344
3345 /* PowerPC operands are just expressions. The only real issue is
3346 that a few operand types are optional. If an instruction has
3347 multiple optional operands and one is omitted, then all optional
3348 operands past the first omitted one must also be omitted. */
3349 int num_optional_operands = 0;
3350 int num_optional_provided = 0;
3351
3352 /* Gather the operands. */
3353 need_paren = 0;
3354 next_opindex = 0;
3355 fc = 0;
3356 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
3357 {
3358 const struct powerpc_operand *operand;
3359 const char *errmsg;
3360 char *hold;
3361 expressionS ex;
3362 char endc;
3363
3364 if (next_opindex == 0)
3365 operand = &powerpc_operands[*opindex_ptr];
3366 else
3367 {
3368 operand = &powerpc_operands[next_opindex];
3369 next_opindex = 0;
3370 }
3371 errmsg = NULL;
3372
3373 /* If this is an optional operand, and we are skipping it, just
3374 insert the default value, usually a zero. */
3375 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
3376 && !((operand->flags & PPC_OPERAND_OPTIONAL32) != 0 && ppc_obj64))
3377 {
3378 if (num_optional_operands == 0)
3379 {
3380 const unsigned char *optr;
3381 int total = 0;
3382 int provided = 0;
3383 int omitted;
3384
3385 s = str;
3386 for (optr = opindex_ptr; *optr != 0; optr++)
3387 {
3388 const struct powerpc_operand *op;
3389 op = &powerpc_operands[*optr];
3390
3391 ++total;
3392
3393 if ((op->flags & PPC_OPERAND_OPTIONAL) != 0
3394 && !((op->flags & PPC_OPERAND_OPTIONAL32) != 0
3395 && ppc_obj64))
3396 ++num_optional_operands;
3397
3398 if (s != NULL && *s != '\0')
3399 {
3400 ++provided;
3401
3402 /* Look for the start of the next operand. */
3403 if ((op->flags & PPC_OPERAND_PARENS) != 0)
3404 s = strpbrk (s, "(,");
3405 else
3406 s = strchr (s, ',');
3407
3408 if (s != NULL)
3409 ++s;
3410 }
3411 }
3412 omitted = total - provided;
3413 num_optional_provided = num_optional_operands - omitted;
3414 }
3415 if (--num_optional_provided < 0)
3416 {
3417 uint64_t val = ppc_optional_operand_value (operand, insn, ppc_cpu,
3418 num_optional_provided);
3419 if (operand->insert)
3420 {
3421 insn = (*operand->insert) (insn, val, ppc_cpu, &errmsg);
3422 if (errmsg != (const char *) NULL)
3423 as_bad ("%s", errmsg);
3424 }
3425 else if (operand->shift >= 0)
3426 insn |= (val & operand->bitm) << operand->shift;
3427 else
3428 insn |= (val & operand->bitm) >> -operand->shift;
3429
3430 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
3431 next_opindex = *opindex_ptr + 1;
3432 continue;
3433 }
3434 }
3435
3436 /* Gather the operand. */
3437 hold = input_line_pointer;
3438 input_line_pointer = str;
3439
3440 if ((reg_names_p
3441 && (((operand->flags & PPC_OPERAND_CR_BIT) != 0)
3442 || ((operand->flags & PPC_OPERAND_CR_REG) != 0)))
3443 || !register_name (&ex))
3444 {
3445 char save_lex = lex_type['%'];
3446
3447 if (((operand->flags & PPC_OPERAND_CR_REG) != 0)
3448 || (operand->flags & PPC_OPERAND_CR_BIT) != 0)
3449 {
3450 cr_operand = true;
3451 lex_type['%'] |= LEX_BEGIN_NAME;
3452 }
3453 expression (&ex);
3454 cr_operand = false;
3455 lex_type['%'] = save_lex;
3456 }
3457
3458 str = input_line_pointer;
3459 input_line_pointer = hold;
3460
3461 if (ex.X_op == O_illegal)
3462 as_bad (_("illegal operand"));
3463 else if (ex.X_op == O_absent)
3464 as_bad (_("missing operand"));
3465 else if (ex.X_op == O_register)
3466 {
3467 if ((ex.X_md
3468 & ~operand->flags
3469 & (PPC_OPERAND_GPR | PPC_OPERAND_FPR | PPC_OPERAND_VR
3470 | PPC_OPERAND_VSR | PPC_OPERAND_CR_BIT | PPC_OPERAND_CR_REG
3471 | PPC_OPERAND_SPR | PPC_OPERAND_GQR | PPC_OPERAND_ACC)) != 0
3472 && !((ex.X_md & PPC_OPERAND_GPR) != 0
3473 && ex.X_add_number != 0
3474 && (operand->flags & PPC_OPERAND_GPR_0) != 0))
3475 as_warn (_("invalid register expression"));
3476 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
3477 ppc_cpu, (char *) NULL, 0);
3478 }
3479 else if (ex.X_op == O_constant
3480 || (ex.X_op == O_big && ex.X_add_number > 0))
3481 {
3482 uint64_t val;
3483 if (ex.X_op == O_constant)
3484 {
3485 val = ex.X_add_number;
3486 if (sizeof (ex.X_add_number) < sizeof (val)
3487 && (ex.X_add_number < 0) != ex.X_extrabit)
3488 val = val ^ ((addressT) -1 ^ (uint64_t) -1);
3489 }
3490 else
3491 val = generic_bignum_to_int64 ();
3492 #ifdef OBJ_ELF
3493 /* Allow @HA, @L, @H on constants. */
3494 char *orig_str = str;
3495 bfd_reloc_code_real_type reloc = ppc_elf_suffix (&str, &ex);
3496
3497 if (ex.X_op == O_constant)
3498 {
3499 val = ex.X_add_number;
3500 if (sizeof (ex.X_add_number) < sizeof (val)
3501 && (ex.X_add_number < 0) != ex.X_extrabit)
3502 val = val ^ ((addressT) -1 ^ (uint64_t) -1);
3503 }
3504 if (reloc != BFD_RELOC_NONE)
3505 switch (reloc)
3506 {
3507 default:
3508 str = orig_str;
3509 break;
3510
3511 case BFD_RELOC_LO16:
3512 val &= 0xffff;
3513 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3514 val = SEX16 (val);
3515 break;
3516
3517 case BFD_RELOC_HI16:
3518 if (REPORT_OVERFLOW_HI && ppc_obj64)
3519 {
3520 /* PowerPC64 @h is tested for overflow. */
3521 val = val >> 16;
3522 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3523 {
3524 uint64_t sign = (((uint64_t) -1 >> 16) + 1) >> 1;
3525 val = (val ^ sign) - sign;
3526 }
3527 break;
3528 }
3529 /* Fallthru */
3530
3531 case BFD_RELOC_PPC64_ADDR16_HIGH:
3532 val = PPC_HI (val);
3533 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3534 val = SEX16 (val);
3535 break;
3536
3537 case BFD_RELOC_HI16_S:
3538 if (REPORT_OVERFLOW_HI && ppc_obj64)
3539 {
3540 /* PowerPC64 @ha is tested for overflow. */
3541 val = (val + 0x8000) >> 16;
3542 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3543 {
3544 uint64_t sign = (((uint64_t) -1 >> 16) + 1) >> 1;
3545 val = (val ^ sign) - sign;
3546 }
3547 break;
3548 }
3549 /* Fallthru */
3550
3551 case BFD_RELOC_PPC64_ADDR16_HIGHA:
3552 val = PPC_HA (val);
3553 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3554 val = SEX16 (val);
3555 break;
3556
3557 case BFD_RELOC_PPC64_HIGHER:
3558 val = PPC_HIGHER (val);
3559 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3560 val = SEX16 (val);
3561 break;
3562
3563 case BFD_RELOC_PPC64_HIGHER_S:
3564 val = PPC_HIGHERA (val);
3565 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3566 val = SEX16 (val);
3567 break;
3568
3569 case BFD_RELOC_PPC64_HIGHEST:
3570 val = PPC_HIGHEST (val);
3571 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3572 val = SEX16 (val);
3573 break;
3574
3575 case BFD_RELOC_PPC64_HIGHEST_S:
3576 val = PPC_HIGHESTA (val);
3577 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
3578 val = SEX16 (val);
3579 break;
3580 }
3581 #endif /* OBJ_ELF */
3582 insn = ppc_insert_operand (insn, operand, val, ppc_cpu, NULL, 0);
3583 }
3584 else
3585 {
3586 bfd_reloc_code_real_type reloc = BFD_RELOC_NONE;
3587 #ifdef OBJ_ELF
3588 /* Look for a __tls_get_addr arg using the insane old syntax. */
3589 if (ex.X_op == O_symbol && *str == '(' && fc < MAX_INSN_FIXUPS
3590 && parse_tls_arg (&str, &ex, &fixups[fc]))
3591 {
3592 fixups[fc].opindex = *opindex_ptr;
3593 ++fc;
3594 }
3595
3596 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_NONE)
3597 {
3598 /* If VLE-mode convert LO/HI/HA relocations. */
3599 if (opcode->flags & PPC_OPCODE_VLE)
3600 {
3601 uint64_t tmp_insn = insn & opcode->mask;
3602
3603 int use_a_reloc = (tmp_insn == E_OR2I_INSN
3604 || tmp_insn == E_AND2I_DOT_INSN
3605 || tmp_insn == E_OR2IS_INSN
3606 || tmp_insn == E_LI_INSN
3607 || tmp_insn == E_LIS_INSN
3608 || tmp_insn == E_AND2IS_DOT_INSN);
3609
3610
3611 int use_d_reloc = (tmp_insn == E_ADD2I_DOT_INSN
3612 || tmp_insn == E_ADD2IS_INSN
3613 || tmp_insn == E_CMP16I_INSN
3614 || tmp_insn == E_MULL2I_INSN
3615 || tmp_insn == E_CMPL16I_INSN
3616 || tmp_insn == E_CMPH16I_INSN
3617 || tmp_insn == E_CMPHL16I_INSN);
3618
3619 switch (reloc)
3620 {
3621 default:
3622 break;
3623
3624 case BFD_RELOC_PPC_EMB_SDA21:
3625 reloc = BFD_RELOC_PPC_VLE_SDA21;
3626 break;
3627
3628 case BFD_RELOC_LO16:
3629 if (use_d_reloc)
3630 reloc = BFD_RELOC_PPC_VLE_LO16D;
3631 else if (use_a_reloc)
3632 reloc = BFD_RELOC_PPC_VLE_LO16A;
3633 break;
3634
3635 case BFD_RELOC_HI16:
3636 if (use_d_reloc)
3637 reloc = BFD_RELOC_PPC_VLE_HI16D;
3638 else if (use_a_reloc)
3639 reloc = BFD_RELOC_PPC_VLE_HI16A;
3640 break;
3641
3642 case BFD_RELOC_HI16_S:
3643 if (use_d_reloc)
3644 reloc = BFD_RELOC_PPC_VLE_HA16D;
3645 else if (use_a_reloc)
3646 reloc = BFD_RELOC_PPC_VLE_HA16A;
3647 break;
3648
3649 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
3650 if (use_d_reloc)
3651 reloc = BFD_RELOC_PPC_VLE_SDAREL_LO16D;
3652 break;
3653
3654 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
3655 if (use_d_reloc)
3656 reloc = BFD_RELOC_PPC_VLE_SDAREL_HI16D;
3657 break;
3658
3659 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
3660 if (use_d_reloc)
3661 reloc = BFD_RELOC_PPC_VLE_SDAREL_HA16D;
3662 break;
3663 }
3664 }
3665
3666 /* TLS and other tweaks. */
3667 switch (reloc)
3668 {
3669 default:
3670 break;
3671
3672 case BFD_RELOC_PPC_TLS:
3673 case BFD_RELOC_PPC64_TLS_PCREL:
3674 if (!_bfd_elf_ppc_at_tls_transform (opcode->opcode, 0))
3675 as_bad (_("@tls may not be used with \"%s\" operands"),
3676 opcode->name);
3677 else if (operand->shift != 11)
3678 as_bad (_("@tls may only be used in last operand"));
3679 else
3680 insn = ppc_insert_operand (insn, operand,
3681 ppc_obj64 ? 13 : 2,
3682 ppc_cpu, (char *) NULL, 0);
3683 break;
3684
3685 /* We'll only use the 32 (or 64) bit form of these relocations
3686 in constants. Instructions get the 16 or 34 bit form. */
3687 case BFD_RELOC_PPC_DTPREL:
3688 if (operand->bitm == 0x3ffffffffULL)
3689 reloc = BFD_RELOC_PPC64_DTPREL34;
3690 else
3691 reloc = BFD_RELOC_PPC_DTPREL16;
3692 break;
3693
3694 case BFD_RELOC_PPC_TPREL:
3695 if (operand->bitm == 0x3ffffffffULL)
3696 reloc = BFD_RELOC_PPC64_TPREL34;
3697 else
3698 reloc = BFD_RELOC_PPC_TPREL16;
3699 break;
3700
3701 case BFD_RELOC_PPC64_PCREL34:
3702 if (operand->bitm == 0xfffffffULL)
3703 {
3704 reloc = BFD_RELOC_PPC64_PCREL28;
3705 break;
3706 }
3707 /* Fall through. */
3708 case BFD_RELOC_PPC64_GOT_PCREL34:
3709 case BFD_RELOC_PPC64_PLT_PCREL34:
3710 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34:
3711 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34:
3712 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34:
3713 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34:
3714 if (operand->bitm != 0x3ffffffffULL
3715 || (operand->flags & PPC_OPERAND_NEGATIVE) != 0)
3716 as_warn (_("%s unsupported on this instruction"), "@pcrel");
3717 break;
3718
3719 case BFD_RELOC_LO16:
3720 if (operand->bitm == 0x3ffffffffULL
3721 && (operand->flags & PPC_OPERAND_NEGATIVE) == 0)
3722 reloc = BFD_RELOC_PPC64_D34_LO;
3723 else if ((operand->bitm | 0xf) != 0xffff
3724 || operand->shift != 0
3725 || (operand->flags & PPC_OPERAND_NEGATIVE) != 0)
3726 as_warn (_("%s unsupported on this instruction"), "@l");
3727 break;
3728
3729 case BFD_RELOC_HI16:
3730 if (operand->bitm == 0x3ffffffffULL
3731 && (operand->flags & PPC_OPERAND_NEGATIVE) == 0)
3732 reloc = BFD_RELOC_PPC64_D34_HI30;
3733 else if (operand->bitm != 0xffff
3734 || operand->shift != 0
3735 || (operand->flags & PPC_OPERAND_NEGATIVE) != 0)
3736 as_warn (_("%s unsupported on this instruction"), "@h");
3737 break;
3738
3739 case BFD_RELOC_HI16_S:
3740 if (operand->bitm == 0x3ffffffffULL
3741 && (operand->flags & PPC_OPERAND_NEGATIVE) == 0)
3742 reloc = BFD_RELOC_PPC64_D34_HA30;
3743 else if (operand->bitm == 0xffff
3744 && operand->shift == (int) PPC_OPSHIFT_INV
3745 && opcode->opcode == (19 << 26) + (2 << 1))
3746 /* addpcis. */
3747 reloc = BFD_RELOC_PPC_16DX_HA;
3748 else if (operand->bitm != 0xffff
3749 || operand->shift != 0
3750 || (operand->flags & PPC_OPERAND_NEGATIVE) != 0)
3751 as_warn (_("%s unsupported on this instruction"), "@ha");
3752 }
3753 }
3754 #endif /* OBJ_ELF */
3755 #ifdef OBJ_XCOFF
3756 reloc = ppc_xcoff_suffix (&str);
3757 #endif /* OBJ_XCOFF */
3758
3759 if (reloc != BFD_RELOC_NONE)
3760 ;
3761 /* Determine a BFD reloc value based on the operand information.
3762 We are only prepared to turn a few of the operands into
3763 relocs. */
3764 else if ((operand->flags & (PPC_OPERAND_RELATIVE
3765 | PPC_OPERAND_ABSOLUTE)) != 0
3766 && operand->bitm == 0x3fffffc
3767 && operand->shift == 0)
3768 reloc = BFD_RELOC_PPC_B26;
3769 else if ((operand->flags & (PPC_OPERAND_RELATIVE
3770 | PPC_OPERAND_ABSOLUTE)) != 0
3771 && operand->bitm == 0xfffc
3772 && operand->shift == 0)
3773 reloc = BFD_RELOC_PPC_B16;
3774 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3775 && operand->bitm == 0x1fe
3776 && operand->shift == -1)
3777 reloc = BFD_RELOC_PPC_VLE_REL8;
3778 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3779 && operand->bitm == 0xfffe
3780 && operand->shift == 0)
3781 reloc = BFD_RELOC_PPC_VLE_REL15;
3782 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
3783 && operand->bitm == 0x1fffffe
3784 && operand->shift == 0)
3785 reloc = BFD_RELOC_PPC_VLE_REL24;
3786 else if ((operand->flags & PPC_OPERAND_NEGATIVE) == 0
3787 && (operand->bitm & 0xfff0) == 0xfff0
3788 && operand->shift == 0)
3789 {
3790 reloc = BFD_RELOC_16;
3791 #if defined OBJ_XCOFF || defined OBJ_ELF
3792 /* Note: the symbol may be not yet defined. */
3793 if ((operand->flags & PPC_OPERAND_PARENS) != 0
3794 && ppc_is_toc_sym (ex.X_add_symbol))
3795 {
3796 reloc = BFD_RELOC_PPC_TOC16;
3797 #ifdef OBJ_ELF
3798 as_warn (_("assuming %s on symbol"),
3799 ppc_obj64 ? "@toc" : "@xgot");
3800 #endif
3801 }
3802 #endif
3803 }
3804 else if (operand->bitm == 0x3ffffffffULL)
3805 reloc = BFD_RELOC_PPC64_D34;
3806 else if (operand->bitm == 0xfffffffULL)
3807 reloc = BFD_RELOC_PPC64_D28;
3808
3809 /* For the absolute forms of branches, convert the PC
3810 relative form back into the absolute. */
3811 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
3812 {
3813 switch (reloc)
3814 {
3815 case BFD_RELOC_PPC_B26:
3816 reloc = BFD_RELOC_PPC_BA26;
3817 break;
3818 case BFD_RELOC_PPC_B16:
3819 reloc = BFD_RELOC_PPC_BA16;
3820 break;
3821 #ifdef OBJ_ELF
3822 case BFD_RELOC_PPC_B16_BRTAKEN:
3823 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
3824 break;
3825 case BFD_RELOC_PPC_B16_BRNTAKEN:
3826 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
3827 break;
3828 #endif
3829 default:
3830 break;
3831 }
3832 }
3833
3834 #ifdef OBJ_ELF
3835 switch (reloc)
3836 {
3837 case BFD_RELOC_PPC_TOC16:
3838 toc_reloc_types |= has_small_toc_reloc;
3839 break;
3840 case BFD_RELOC_PPC64_TOC16_LO:
3841 case BFD_RELOC_PPC64_TOC16_HI:
3842 case BFD_RELOC_PPC64_TOC16_HA:
3843 toc_reloc_types |= has_large_toc_reloc;
3844 break;
3845 default:
3846 break;
3847 }
3848
3849 if (ppc_obj64
3850 && (operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
3851 {
3852 switch (reloc)
3853 {
3854 case BFD_RELOC_16:
3855 reloc = BFD_RELOC_PPC64_ADDR16_DS;
3856 break;
3857
3858 case BFD_RELOC_LO16:
3859 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
3860 break;
3861
3862 case BFD_RELOC_16_GOTOFF:
3863 reloc = BFD_RELOC_PPC64_GOT16_DS;
3864 break;
3865
3866 case BFD_RELOC_LO16_GOTOFF:
3867 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
3868 break;
3869
3870 case BFD_RELOC_LO16_PLTOFF:
3871 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
3872 break;
3873
3874 case BFD_RELOC_16_BASEREL:
3875 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
3876 break;
3877
3878 case BFD_RELOC_LO16_BASEREL:
3879 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
3880 break;
3881
3882 case BFD_RELOC_PPC_TOC16:
3883 reloc = BFD_RELOC_PPC64_TOC16_DS;
3884 break;
3885
3886 case BFD_RELOC_PPC64_TOC16_LO:
3887 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
3888 break;
3889
3890 case BFD_RELOC_PPC64_PLTGOT16:
3891 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
3892 break;
3893
3894 case BFD_RELOC_PPC64_PLTGOT16_LO:
3895 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
3896 break;
3897
3898 case BFD_RELOC_PPC_DTPREL16:
3899 reloc = BFD_RELOC_PPC64_DTPREL16_DS;
3900 break;
3901
3902 case BFD_RELOC_PPC_DTPREL16_LO:
3903 reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
3904 break;
3905
3906 case BFD_RELOC_PPC_TPREL16:
3907 reloc = BFD_RELOC_PPC64_TPREL16_DS;
3908 break;
3909
3910 case BFD_RELOC_PPC_TPREL16_LO:
3911 reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
3912 break;
3913
3914 case BFD_RELOC_PPC_GOT_DTPREL16:
3915 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
3916 case BFD_RELOC_PPC_GOT_TPREL16:
3917 case BFD_RELOC_PPC_GOT_TPREL16_LO:
3918 break;
3919
3920 default:
3921 as_bad (_("unsupported relocation for DS offset field"));
3922 break;
3923 }
3924 }
3925
3926 /* Look for a __tls_get_addr arg after any __tls_get_addr
3927 modifiers like @plt. This fixup must be emitted before
3928 the usual call fixup. */
3929 if (ex.X_op == O_symbol && *str == '(' && fc < MAX_INSN_FIXUPS
3930 && parse_tls_arg (&str, &ex, &fixups[fc]))
3931 {
3932 fixups[fc].opindex = *opindex_ptr;
3933 ++fc;
3934 }
3935 #endif
3936
3937 /* We need to generate a fixup for this expression. */
3938 if (fc >= MAX_INSN_FIXUPS)
3939 as_fatal (_("too many fixups"));
3940 fixups[fc].exp = ex;
3941 fixups[fc].opindex = *opindex_ptr;
3942 fixups[fc].reloc = reloc;
3943 ++fc;
3944 }
3945
3946 if (need_paren)
3947 {
3948 endc = ')';
3949 need_paren = 0;
3950 /* If expecting more operands, then we want to see "),". */
3951 if (*str == endc && opindex_ptr[1] != 0)
3952 {
3953 do
3954 ++str;
3955 while (ISSPACE (*str));
3956 endc = ',';
3957 }
3958 }
3959 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
3960 endc = '(';
3961 else
3962 endc = ',';
3963
3964 /* The call to expression should have advanced str past any
3965 whitespace. */
3966 if (*str == endc)
3967 {
3968 ++str;
3969 if (endc == '(')
3970 need_paren = 1;
3971 }
3972 else if (*str != '\0')
3973 {
3974 as_bad (_("syntax error; found `%c', expected `%c'"), *str, endc);
3975 break;
3976 }
3977 else if (endc == ')')
3978 {
3979 as_bad (_("syntax error; end of line, expected `%c'"), endc);
3980 break;
3981 }
3982 }
3983
3984 while (ISSPACE (*str))
3985 ++str;
3986
3987 if (*str != '\0')
3988 as_bad (_("junk at end of line: `%s'"), str);
3989
3990 #ifdef OBJ_ELF
3991 /* Do we need/want an APUinfo section? */
3992 if ((ppc_cpu & (PPC_OPCODE_E500 | PPC_OPCODE_E500MC | PPC_OPCODE_VLE)) != 0
3993 && !ppc_obj64)
3994 {
3995 /* These are all version "1". */
3996 if (opcode->flags & PPC_OPCODE_SPE)
3997 ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
3998 if (opcode->flags & PPC_OPCODE_ISEL)
3999 ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
4000 if (opcode->flags & PPC_OPCODE_EFS)
4001 ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
4002 if (opcode->flags & PPC_OPCODE_BRLOCK)
4003 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
4004 if (opcode->flags & PPC_OPCODE_PMR)
4005 ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
4006 if (opcode->flags & PPC_OPCODE_CACHELCK)
4007 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
4008 if (opcode->flags & PPC_OPCODE_RFMCI)
4009 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
4010 /* Only set the VLE flag if the instruction has been pulled via
4011 the VLE instruction set. This way the flag is guaranteed to
4012 be set for VLE-only instructions or for VLE-only processors,
4013 however it'll remain clear for dual-mode instructions on
4014 dual-mode and, more importantly, standard-mode processors. */
4015 if ((ppc_cpu & opcode->flags) == PPC_OPCODE_VLE)
4016 {
4017 ppc_apuinfo_section_add (PPC_APUINFO_VLE, 1);
4018 if (elf_section_data (now_seg) != NULL)
4019 elf_section_data (now_seg)->this_hdr.sh_flags |= SHF_PPC_VLE;
4020 }
4021 }
4022 #endif
4023
4024 /* Write out the instruction. */
4025
4026 addr_mask = 3;
4027 if ((ppc_cpu & PPC_OPCODE_VLE) != 0)
4028 /* All instructions can start on a 2 byte boundary for VLE. */
4029 addr_mask = 1;
4030
4031 if (frag_now->insn_addr != addr_mask)
4032 {
4033 /* Don't emit instructions to a frag started for data, or for a
4034 CPU differing in VLE mode. Data is allowed to be misaligned,
4035 and it's possible to start a new frag in the middle of
4036 misaligned data. */
4037 frag_wane (frag_now);
4038 frag_new (0);
4039 }
4040
4041 /* Check that insns within the frag are aligned. ppc_frag_check
4042 will ensure that the frag start address is aligned. */
4043 if ((frag_now_fix () & addr_mask) != 0)
4044 as_bad (_("instruction address is not a multiple of %d"), addr_mask + 1);
4045
4046 /* Differentiate between two, four, and eight byte insns. */
4047 insn_length = 4;
4048 if ((ppc_cpu & PPC_OPCODE_VLE) != 0 && PPC_OP_SE_VLE (insn))
4049 insn_length = 2;
4050 else if ((opcode->flags & PPC_OPCODE_POWER10) != 0
4051 && PPC_PREFIX_P (insn))
4052 {
4053 struct insn_label_list *l;
4054
4055 insn_length = 8;
4056
4057 /* 8-byte prefix instructions are not allowed to cross 64-byte
4058 boundaries. */
4059 frag_align_code (6, 4);
4060 record_alignment (now_seg, 6);
4061 #ifdef OBJ_XCOFF
4062 /* Update alignment of the containing csect. */
4063 if (symbol_get_tc (ppc_current_csect)->align < 6)
4064 symbol_get_tc (ppc_current_csect)->align = 6;
4065 #endif
4066
4067 /* Update "dot" in any expressions used by this instruction, and
4068 a label attached to the instruction. By "attached" we mean
4069 on the same source line as the instruction and without any
4070 intervening semicolons. */
4071 dot_value = frag_now_fix ();
4072 dot_frag = frag_now;
4073 for (l = insn_labels; l != NULL; l = l->next)
4074 {
4075 symbol_set_frag (l->label, dot_frag);
4076 S_SET_VALUE (l->label, dot_value);
4077 }
4078 }
4079
4080 ppc_clear_labels ();
4081
4082 f = frag_more (insn_length);
4083 frag_now->insn_addr = addr_mask;
4084
4085 /* The prefix part of an 8-byte instruction always occupies the lower
4086 addressed word in a doubleword, regardless of endianness. */
4087 if (insn_length == 8
4088 && (sizeof (insn) > sizeof (valueT) || !target_big_endian))
4089 {
4090 md_number_to_chars (f, PPC_GET_PREFIX (insn), 4);
4091 md_number_to_chars (f + 4, PPC_GET_SUFFIX (insn), 4);
4092 }
4093 else
4094 md_number_to_chars (f, insn, insn_length);
4095
4096 last_insn = insn;
4097 last_seg = now_seg;
4098 last_subseg = now_subseg;
4099
4100 #ifdef OBJ_ELF
4101 dwarf2_emit_insn (insn_length);
4102 #endif
4103
4104 /* Create any fixups. */
4105 for (i = 0; i < fc; i++)
4106 {
4107 fixS *fixP;
4108 if (fixups[i].reloc != BFD_RELOC_NONE)
4109 {
4110 bool pcrel;
4111 unsigned int size = fixup_size (fixups[i].reloc, &pcrel);
4112 int offset = target_big_endian ? (insn_length - size) : 0;
4113
4114 fixP = fix_new_exp (frag_now,
4115 f - frag_now->fr_literal + offset,
4116 size,
4117 &fixups[i].exp,
4118 pcrel,
4119 fixups[i].reloc);
4120 }
4121 else
4122 {
4123 const struct powerpc_operand *operand;
4124
4125 operand = &powerpc_operands[fixups[i].opindex];
4126 fixP = fix_new_exp (frag_now,
4127 f - frag_now->fr_literal,
4128 insn_length,
4129 &fixups[i].exp,
4130 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
4131 BFD_RELOC_NONE);
4132 }
4133 fixP->fx_pcrel_adjust = fixups[i].opindex;
4134 }
4135 }
4136
4137 /* Handle a macro. Gather all the operands, transform them as
4138 described by the macro, and call md_assemble recursively. All the
4139 operands are separated by commas; we don't accept parentheses
4140 around operands here. */
4141
4142 static void
4143 ppc_macro (char *str, const struct powerpc_macro *macro)
4144 {
4145 char *operands[10];
4146 unsigned int count;
4147 char *s;
4148 unsigned int len;
4149 const char *format;
4150 unsigned int arg;
4151 char *send;
4152 char *complete;
4153
4154 /* Gather the users operands into the operands array. */
4155 count = 0;
4156 s = str;
4157 while (1)
4158 {
4159 if (count >= sizeof operands / sizeof operands[0])
4160 break;
4161 operands[count++] = s;
4162 s = strchr (s, ',');
4163 if (s == (char *) NULL)
4164 break;
4165 *s++ = '\0';
4166 }
4167
4168 if (count != macro->operands)
4169 {
4170 as_bad (_("wrong number of operands"));
4171 return;
4172 }
4173
4174 /* Work out how large the string must be (the size is unbounded
4175 because it includes user input). */
4176 len = 0;
4177 format = macro->format;
4178 while (*format != '\0')
4179 {
4180 if (*format != '%')
4181 {
4182 ++len;
4183 ++format;
4184 }
4185 else
4186 {
4187 arg = strtol (format + 1, &send, 10);
4188 know (send != format && arg < count);
4189 len += strlen (operands[arg]);
4190 format = send;
4191 }
4192 }
4193
4194 /* Put the string together. */
4195 complete = s = XNEWVEC (char, len + 1);
4196 format = macro->format;
4197 while (*format != '\0')
4198 {
4199 if (*format != '%')
4200 *s++ = *format++;
4201 else
4202 {
4203 arg = strtol (format + 1, &send, 10);
4204 strcpy (s, operands[arg]);
4205 s += strlen (s);
4206 format = send;
4207 }
4208 }
4209 *s = '\0';
4210
4211 /* Assemble the constructed instruction. */
4212 md_assemble (complete);
4213 free (complete);
4214 }
4215 \f
4216 #ifdef OBJ_ELF
4217 /* For ELF, add support for SHT_ORDERED. */
4218
4219 int
4220 ppc_section_type (char *str, size_t len)
4221 {
4222 if (len == 7 && startswith (str, "ordered"))
4223 return SHT_ORDERED;
4224
4225 return -1;
4226 }
4227
4228 int
4229 ppc_section_flags (flagword flags, bfd_vma attr ATTRIBUTE_UNUSED, int type)
4230 {
4231 if (type == SHT_ORDERED)
4232 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
4233
4234 return flags;
4235 }
4236
4237 bfd_vma
4238 ppc_elf_section_letter (int letter, const char **ptrmsg)
4239 {
4240 if (letter == 'v')
4241 return SHF_PPC_VLE;
4242
4243 *ptrmsg = _("bad .section directive: want a,e,v,w,x,M,S,G,T in string");
4244 return -1;
4245 }
4246 #endif /* OBJ_ELF */
4247
4248 \f
4249 /* Pseudo-op handling. */
4250
4251 /* The .byte pseudo-op. This is similar to the normal .byte
4252 pseudo-op, but it can also take a single ASCII string. */
4253
4254 static void
4255 ppc_byte (int ignore ATTRIBUTE_UNUSED)
4256 {
4257 int count = 0;
4258
4259 if (*input_line_pointer != '\"')
4260 {
4261 cons (1);
4262 return;
4263 }
4264
4265 /* Gather characters. A real double quote is doubled. Unusual
4266 characters are not permitted. */
4267 ++input_line_pointer;
4268 while (1)
4269 {
4270 char c;
4271
4272 c = *input_line_pointer++;
4273
4274 if (c == '\"')
4275 {
4276 if (*input_line_pointer != '\"')
4277 break;
4278 ++input_line_pointer;
4279 }
4280
4281 FRAG_APPEND_1_CHAR (c);
4282 ++count;
4283 }
4284
4285 if (warn_476 && count != 0 && (now_seg->flags & SEC_CODE) != 0)
4286 as_warn (_("data in executable section"));
4287 demand_empty_rest_of_line ();
4288 }
4289 \f
4290 #ifdef OBJ_XCOFF
4291
4292 /* XCOFF specific pseudo-op handling. */
4293
4294 /* This is set if we are creating a .stabx symbol, since we don't want
4295 to handle symbol suffixes for such symbols. */
4296 static bool ppc_stab_symbol;
4297
4298 /* Retrieve the visiblity input for pseudo-ops having ones. */
4299 static unsigned short
4300 ppc_xcoff_get_visibility (void) {
4301 SKIP_WHITESPACE();
4302
4303 if (startswith (input_line_pointer, "exported"))
4304 {
4305 input_line_pointer += 8;
4306 return SYM_V_EXPORTED;
4307 }
4308
4309 if (startswith (input_line_pointer, "hidden"))
4310 {
4311 input_line_pointer += 6;
4312 return SYM_V_HIDDEN;
4313 }
4314
4315 if (startswith (input_line_pointer, "internal"))
4316 {
4317 input_line_pointer += 8;
4318 return SYM_V_INTERNAL;
4319 }
4320
4321 if (startswith (input_line_pointer, "protected"))
4322 {
4323 input_line_pointer += 9;
4324 return SYM_V_PROTECTED;
4325 }
4326
4327 return 0;
4328 }
4329
4330 /* Retrieve visiblity using GNU syntax. */
4331 static void ppc_GNU_visibility (int visibility) {
4332 int c;
4333 char *name;
4334 symbolS *symbolP;
4335 coff_symbol_type *coffsym;
4336
4337 do
4338 {
4339 if ((name = read_symbol_name ()) == NULL)
4340 break;
4341 symbolP = symbol_find_or_make (name);
4342 coffsym = coffsymbol (symbol_get_bfdsym (symbolP));
4343
4344 coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
4345 coffsym->native->u.syment.n_type |= visibility;
4346
4347 c = *input_line_pointer;
4348 if (c == ',')
4349 {
4350 input_line_pointer ++;
4351
4352 SKIP_WHITESPACE ();
4353
4354 if (*input_line_pointer == '\n')
4355 c = '\n';
4356 }
4357 }
4358 while (c == ',');
4359
4360 demand_empty_rest_of_line ();
4361 }
4362
4363 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
4364 symbols in the .bss segment as though they were local common
4365 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
4366 aligns .comm and .lcomm to 4 bytes.
4367 Symbols having a XMC_UL storage class are uninialized thread-local
4368 data. */
4369
4370 static void
4371 ppc_comm (int lcomm)
4372 {
4373 asection *current_seg = now_seg;
4374 subsegT current_subseg = now_subseg;
4375 char *name;
4376 char endc;
4377 char *end_name;
4378 offsetT size;
4379 offsetT align;
4380 symbolS *lcomm_sym = NULL;
4381 symbolS *sym;
4382 char *pfrag;
4383 unsigned short visibility;
4384 struct ppc_xcoff_section *section;
4385
4386 endc = get_symbol_name (&name);
4387 end_name = input_line_pointer;
4388 (void) restore_line_pointer (endc);
4389
4390 if (*input_line_pointer != ',')
4391 {
4392 as_bad (_("missing size"));
4393 ignore_rest_of_line ();
4394 return;
4395 }
4396 ++input_line_pointer;
4397
4398 size = get_absolute_expression ();
4399 if (size < 0)
4400 {
4401 as_bad (_("negative size"));
4402 ignore_rest_of_line ();
4403 return;
4404 }
4405
4406 if (! lcomm)
4407 {
4408 /* The third argument to .comm is the alignment. */
4409 if (*input_line_pointer != ',')
4410 align = 2;
4411 else
4412 {
4413 ++input_line_pointer;
4414 align = get_absolute_expression ();
4415 if (align <= 0)
4416 {
4417 as_warn (_("ignoring bad alignment"));
4418 align = 2;
4419 }
4420
4421 /* The fourth argument to .comm is the visibility. */
4422 if (*input_line_pointer == ',')
4423 {
4424 input_line_pointer++;
4425 visibility = ppc_xcoff_get_visibility ();
4426 if (!visibility)
4427 {
4428 as_bad (_("Unknown visibility field in .comm"));
4429 ignore_rest_of_line ();
4430 return;
4431 }
4432 }
4433 }
4434 }
4435 else
4436 {
4437 char *lcomm_name;
4438 char lcomm_endc;
4439
4440 /* The third argument to .lcomm appears to be the real local
4441 common symbol to create. References to the symbol named in
4442 the first argument are turned into references to the third
4443 argument. */
4444 if (*input_line_pointer != ',')
4445 {
4446 as_bad (_("missing real symbol name"));
4447 ignore_rest_of_line ();
4448 return;
4449 }
4450 ++input_line_pointer;
4451
4452 lcomm_endc = get_symbol_name (&lcomm_name);
4453
4454 lcomm_sym = symbol_find_or_make (lcomm_name);
4455
4456 (void) restore_line_pointer (lcomm_endc);
4457
4458 /* The fourth argument to .lcomm is the alignment. */
4459 if (*input_line_pointer != ',')
4460 {
4461 if (size <= 4)
4462 align = 2;
4463 else
4464 align = 3;
4465 }
4466 else
4467 {
4468 ++input_line_pointer;
4469 align = get_absolute_expression ();
4470 if (align <= 0)
4471 {
4472 as_warn (_("ignoring bad alignment"));
4473 align = 2;
4474 }
4475 }
4476 }
4477
4478 *end_name = '\0';
4479 sym = symbol_find_or_make (name);
4480 *end_name = endc;
4481
4482 if (S_IS_DEFINED (sym)
4483 || S_GET_VALUE (sym) != 0)
4484 {
4485 as_bad (_("attempt to redefine symbol"));
4486 ignore_rest_of_line ();
4487 return;
4488 }
4489
4490 if (symbol_get_tc (sym)->symbol_class == XMC_UL
4491 || (lcomm && symbol_get_tc (lcomm_sym)->symbol_class == XMC_UL))
4492 {
4493 section = &ppc_xcoff_tbss_section;
4494 if (!ppc_xcoff_section_is_initialized (section))
4495 {
4496 ppc_init_xcoff_section (section, subseg_new (".tbss", 0));
4497 bfd_set_section_flags (section->segment,
4498 SEC_ALLOC | SEC_THREAD_LOCAL);
4499 seg_info (section->segment)->bss = 1;
4500 }
4501 }
4502 else
4503 section = &ppc_xcoff_bss_section;
4504
4505 record_alignment (section->segment, align);
4506
4507 if (! lcomm
4508 || ! S_IS_DEFINED (lcomm_sym))
4509 {
4510 symbolS *def_sym;
4511 offsetT def_size;
4512
4513 if (! lcomm)
4514 {
4515 def_sym = sym;
4516 def_size = size;
4517 S_SET_EXTERNAL (sym);
4518 }
4519 else
4520 {
4521 symbol_get_tc (lcomm_sym)->output = 1;
4522 def_sym = lcomm_sym;
4523 def_size = 0;
4524 }
4525
4526 subseg_set (section->segment, 1);
4527 frag_align (align, 0, 0);
4528
4529 symbol_set_frag (def_sym, frag_now);
4530 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
4531 def_size, (char *) NULL);
4532 *pfrag = 0;
4533 S_SET_SEGMENT (def_sym, section->segment);
4534 symbol_get_tc (def_sym)->align = align;
4535 }
4536 else if (lcomm)
4537 {
4538 /* Align the size of lcomm_sym. */
4539 symbol_get_frag (lcomm_sym)->fr_offset =
4540 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
4541 &~ ((1 << align) - 1));
4542 if (align > symbol_get_tc (lcomm_sym)->align)
4543 symbol_get_tc (lcomm_sym)->align = align;
4544 }
4545
4546 if (lcomm)
4547 {
4548 /* Make sym an offset from lcomm_sym. */
4549 S_SET_SEGMENT (sym, section->segment);
4550 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
4551 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
4552 symbol_get_frag (lcomm_sym)->fr_offset += size;
4553 }
4554
4555 if (!lcomm && visibility)
4556 {
4557 /* Add visibility to .comm symbol. */
4558 coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
4559 coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
4560 coffsym->native->u.syment.n_type |= visibility;
4561 }
4562
4563 subseg_set (current_seg, current_subseg);
4564
4565 demand_empty_rest_of_line ();
4566 }
4567
4568 /* The .csect pseudo-op. This switches us into a different
4569 subsegment. The first argument is a symbol whose value is the
4570 start of the .csect. In COFF, csect symbols get special aux
4571 entries defined by the x_csect field of union internal_auxent. The
4572 optional second argument is the alignment (the default is 2). */
4573
4574 static void
4575 ppc_csect (int ignore ATTRIBUTE_UNUSED)
4576 {
4577 char *name;
4578 char endc;
4579 symbolS *sym;
4580 offsetT align;
4581
4582 endc = get_symbol_name (&name);
4583
4584 sym = symbol_find_or_make (name);
4585
4586 (void) restore_line_pointer (endc);
4587
4588 if (S_GET_NAME (sym)[0] == '\0')
4589 {
4590 /* An unnamed csect is assumed to be [PR]. */
4591 symbol_get_tc (sym)->symbol_class = XMC_PR;
4592 }
4593
4594 align = 2;
4595 if (*input_line_pointer == ',')
4596 {
4597 ++input_line_pointer;
4598 align = get_absolute_expression ();
4599 }
4600
4601 ppc_change_csect (sym, align);
4602
4603 demand_empty_rest_of_line ();
4604 }
4605
4606 /* Change to a different csect. */
4607
4608 static void
4609 ppc_change_csect (symbolS *sym, offsetT align)
4610 {
4611 if (S_IS_DEFINED (sym))
4612 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
4613 else
4614 {
4615 struct ppc_xcoff_section *section;
4616 int after_toc;
4617 int hold_chunksize;
4618 symbolS *list;
4619 int is_code;
4620 segT sec;
4621
4622 /* This is a new csect. We need to look at the symbol class to
4623 figure out whether it should go in the text section or the
4624 data section. */
4625 after_toc = 0;
4626 is_code = 0;
4627 switch (symbol_get_tc (sym)->symbol_class)
4628 {
4629 case XMC_PR:
4630 case XMC_RO:
4631 case XMC_DB:
4632 case XMC_GL:
4633 case XMC_XO:
4634 case XMC_SV:
4635 case XMC_TI:
4636 case XMC_TB:
4637 section = &ppc_xcoff_text_section;
4638 is_code = 1;
4639 break;
4640 case XMC_RW:
4641 case XMC_TC0:
4642 case XMC_TC:
4643 case XMC_TE:
4644 case XMC_DS:
4645 case XMC_UA:
4646 case XMC_UC:
4647 section = &ppc_xcoff_data_section;
4648 if (ppc_toc_csect != NULL
4649 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
4650 == section->next_subsegment))
4651 after_toc = 1;
4652 break;
4653 case XMC_BS:
4654 section = &ppc_xcoff_bss_section;
4655 break;
4656 case XMC_TL:
4657 section = &ppc_xcoff_tdata_section;
4658 /* Create .tdata section if not yet done. */
4659 if (!ppc_xcoff_section_is_initialized (section))
4660 {
4661 ppc_init_xcoff_section (section, subseg_new (".tdata", 0));
4662 bfd_set_section_flags (section->segment, SEC_ALLOC
4663 | SEC_LOAD | SEC_RELOC | SEC_DATA
4664 | SEC_THREAD_LOCAL);
4665 }
4666 break;
4667 case XMC_UL:
4668 section = &ppc_xcoff_tbss_section;
4669 /* Create .tbss section if not yet done. */
4670 if (!ppc_xcoff_section_is_initialized (section))
4671 {
4672 ppc_init_xcoff_section (section, subseg_new (".tbss", 0));
4673 bfd_set_section_flags (section->segment, SEC_ALLOC |
4674 SEC_THREAD_LOCAL);
4675 seg_info (section->segment)->bss = 1;
4676 }
4677 break;
4678 default:
4679 abort ();
4680 }
4681
4682 S_SET_SEGMENT (sym, section->segment);
4683 symbol_get_tc (sym)->subseg = section->next_subsegment;
4684 ++section->next_subsegment;
4685
4686 /* We set the obstack chunk size to a small value before
4687 changing subsegments, so that we don't use a lot of memory
4688 space for what may be a small section. */
4689 hold_chunksize = chunksize;
4690 chunksize = 64;
4691
4692 sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
4693 symbol_get_tc (sym)->subseg);
4694
4695 chunksize = hold_chunksize;
4696
4697 if (after_toc)
4698 ppc_after_toc_frag = frag_now;
4699
4700 record_alignment (sec, align);
4701 if (is_code)
4702 frag_align_code (align, 0);
4703 else
4704 frag_align (align, 0, 0);
4705
4706 symbol_set_frag (sym, frag_now);
4707 S_SET_VALUE (sym, (valueT) frag_now_fix ());
4708
4709 symbol_get_tc (sym)->align = align;
4710 symbol_get_tc (sym)->output = 1;
4711 symbol_get_tc (sym)->within = sym;
4712
4713 for (list = section->csects;
4714 symbol_get_tc (list)->next != (symbolS *) NULL;
4715 list = symbol_get_tc (list)->next)
4716 ;
4717 symbol_get_tc (list)->next = sym;
4718
4719 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4720 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
4721 &symbol_lastP);
4722 }
4723
4724 ppc_current_csect = sym;
4725 }
4726
4727 static void
4728 ppc_change_debug_section (unsigned int idx, subsegT subseg)
4729 {
4730 segT sec;
4731 flagword oldflags;
4732 const struct xcoff_dwsect_name *dw = &xcoff_dwsect_names[idx];
4733
4734 sec = subseg_new (dw->xcoff_name, subseg);
4735 oldflags = bfd_section_flags (sec);
4736 if (oldflags == SEC_NO_FLAGS)
4737 {
4738 /* Just created section. */
4739 gas_assert (dw_sections[idx].sect == NULL);
4740
4741 bfd_set_section_flags (sec, SEC_DEBUGGING);
4742 bfd_set_section_alignment (sec, 0);
4743 dw_sections[idx].sect = sec;
4744 }
4745
4746 /* Not anymore in a csect. */
4747 ppc_current_csect = NULL;
4748 }
4749
4750 /* The .dwsect pseudo-op. Defines a DWARF section. Syntax is:
4751 .dwsect flag [, opt-label ]
4752 */
4753
4754 static void
4755 ppc_dwsect (int ignore ATTRIBUTE_UNUSED)
4756 {
4757 valueT flag;
4758 symbolS *opt_label;
4759 const struct xcoff_dwsect_name *dw;
4760 struct dw_subsection *subseg;
4761 struct dw_section *dws;
4762 int i;
4763
4764 /* Find section. */
4765 flag = get_absolute_expression ();
4766 dw = NULL;
4767 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
4768 if (xcoff_dwsect_names[i].flag == flag)
4769 {
4770 dw = &xcoff_dwsect_names[i];
4771 break;
4772 }
4773
4774 /* Parse opt-label. */
4775 if (*input_line_pointer == ',')
4776 {
4777 char *label;
4778 char c;
4779
4780 ++input_line_pointer;
4781
4782 c = get_symbol_name (&label);
4783 opt_label = symbol_find_or_make (label);
4784 (void) restore_line_pointer (c);
4785 }
4786 else
4787 opt_label = NULL;
4788
4789 demand_empty_rest_of_line ();
4790
4791 /* Return now in case of unknown subsection. */
4792 if (dw == NULL)
4793 {
4794 as_bad (_("no known dwarf XCOFF section for flag 0x%08x\n"),
4795 (unsigned)flag);
4796 return;
4797 }
4798
4799 /* Find the subsection. */
4800 dws = &dw_sections[i];
4801 subseg = NULL;
4802 if (opt_label != NULL && S_IS_DEFINED (opt_label))
4803 {
4804 /* Sanity check (note that in theory S_GET_SEGMENT mustn't be null). */
4805 if (dws->sect == NULL || S_GET_SEGMENT (opt_label) != dws->sect)
4806 {
4807 as_bad (_("label %s was not defined in this dwarf section"),
4808 S_GET_NAME (opt_label));
4809 subseg = dws->anon_subseg;
4810 opt_label = NULL;
4811 }
4812 else
4813 subseg = symbol_get_tc (opt_label)->u.dw;
4814 }
4815
4816 if (subseg != NULL)
4817 {
4818 /* Switch to the subsection. */
4819 ppc_change_debug_section (i, subseg->subseg);
4820 }
4821 else
4822 {
4823 /* Create a new dw subsection. */
4824 subseg = XCNEW (struct dw_subsection);
4825
4826 if (opt_label == NULL)
4827 {
4828 /* The anonymous one. */
4829 subseg->subseg = 0;
4830 subseg->link = NULL;
4831 dws->anon_subseg = subseg;
4832 }
4833 else
4834 {
4835 /* A named one. */
4836 if (dws->list_subseg != NULL)
4837 subseg->subseg = dws->list_subseg->subseg + 1;
4838 else
4839 subseg->subseg = 1;
4840
4841 subseg->link = dws->list_subseg;
4842 dws->list_subseg = subseg;
4843 symbol_get_tc (opt_label)->u.dw = subseg;
4844 }
4845
4846 ppc_change_debug_section (i, subseg->subseg);
4847
4848 if (dw->def_size)
4849 {
4850 /* Add the length field. */
4851 expressionS *exp = &subseg->end_exp;
4852 int sz;
4853
4854 if (opt_label != NULL)
4855 symbol_set_value_now (opt_label);
4856
4857 /* Add the length field. Note that according to the AIX assembler
4858 manual, the size of the length field is 4 for powerpc32 but
4859 12 for powerpc64. */
4860 if (ppc_obj64)
4861 {
4862 /* Write the 64bit marker. */
4863 md_number_to_chars (frag_more (4), -1, 4);
4864 }
4865
4866 exp->X_op = O_subtract;
4867 exp->X_op_symbol = symbol_temp_new_now ();
4868 exp->X_add_symbol = symbol_temp_make ();
4869
4870 sz = ppc_obj64 ? 8 : 4;
4871 exp->X_add_number = -sz;
4872 emit_expr (exp, sz);
4873 }
4874 }
4875 }
4876
4877 /* This function handles the .text and .data pseudo-ops. These
4878 pseudo-ops aren't really used by XCOFF; we implement them for the
4879 convenience of people who aren't used to XCOFF. */
4880
4881 static void
4882 ppc_section (int type)
4883 {
4884 const char *name;
4885 symbolS *sym;
4886
4887 if (type == 't')
4888 name = ".text[PR]";
4889 else if (type == 'd')
4890 name = ".data[RW]";
4891 else
4892 abort ();
4893
4894 sym = symbol_find_or_make (name);
4895
4896 ppc_change_csect (sym, 2);
4897
4898 demand_empty_rest_of_line ();
4899 }
4900
4901 /* This function handles the .section pseudo-op. This is mostly to
4902 give an error, since XCOFF only supports .text, .data and .bss, but
4903 we do permit the user to name the text or data section. */
4904
4905 static void
4906 ppc_named_section (int ignore ATTRIBUTE_UNUSED)
4907 {
4908 char *user_name;
4909 const char *real_name;
4910 char c;
4911 symbolS *sym;
4912
4913 c = get_symbol_name (&user_name);
4914
4915 if (strcmp (user_name, ".text") == 0)
4916 real_name = ".text[PR]";
4917 else if (strcmp (user_name, ".data") == 0)
4918 real_name = ".data[RW]";
4919 else
4920 {
4921 as_bad (_("the XCOFF file format does not support arbitrary sections"));
4922 (void) restore_line_pointer (c);
4923 ignore_rest_of_line ();
4924 return;
4925 }
4926
4927 (void) restore_line_pointer (c);
4928
4929 sym = symbol_find_or_make (real_name);
4930
4931 ppc_change_csect (sym, 2);
4932
4933 demand_empty_rest_of_line ();
4934 }
4935
4936 /* The .extern pseudo-op. We create an undefined symbol. */
4937
4938 static void
4939 ppc_extern (int ignore ATTRIBUTE_UNUSED)
4940 {
4941 char *name;
4942 symbolS *sym;
4943
4944 if ((name = read_symbol_name ()) == NULL)
4945 return;
4946
4947 sym = symbol_find_or_make (name);
4948
4949 if (*input_line_pointer == ',')
4950 {
4951 unsigned short visibility;
4952 coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
4953
4954 input_line_pointer++;
4955 visibility = ppc_xcoff_get_visibility ();
4956 if (!visibility)
4957 {
4958 as_bad (_("Unknown visibility field in .extern"));
4959 ignore_rest_of_line ();
4960 return;
4961 }
4962
4963 coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
4964 coffsym->native->u.syment.n_type |= visibility;
4965 }
4966
4967 demand_empty_rest_of_line ();
4968 }
4969
4970 /* XCOFF semantic for .globl says that the second parameter is
4971 the symbol visibility. */
4972
4973 static void
4974 ppc_globl (int ignore ATTRIBUTE_UNUSED)
4975 {
4976 char *name;
4977 symbolS *sym;
4978
4979 if ((name = read_symbol_name ()) == NULL)
4980 return;
4981
4982 sym = symbol_find_or_make (name);
4983 S_SET_EXTERNAL (sym);
4984
4985 if (*input_line_pointer == ',')
4986 {
4987 unsigned short visibility;
4988 coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
4989
4990 input_line_pointer++;
4991 visibility = ppc_xcoff_get_visibility ();
4992 if (!visibility)
4993 {
4994 as_bad (_("Unknown visibility field in .globl"));
4995 ignore_rest_of_line ();
4996 return;
4997 }
4998
4999 coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
5000 coffsym->native->u.syment.n_type |= visibility;
5001 }
5002
5003 demand_empty_rest_of_line ();
5004 }
5005
5006 /* XCOFF semantic for .weak says that the second parameter is
5007 the symbol visibility. */
5008
5009 static void
5010 ppc_weak (int ignore ATTRIBUTE_UNUSED)
5011 {
5012 char *name;
5013 symbolS *sym;
5014
5015 if ((name = read_symbol_name ()) == NULL)
5016 return;
5017
5018 sym = symbol_find_or_make (name);
5019 S_SET_WEAK (sym);
5020
5021 if (*input_line_pointer == ',')
5022 {
5023 unsigned short visibility;
5024 coff_symbol_type *coffsym = coffsymbol (symbol_get_bfdsym (sym));
5025
5026 input_line_pointer++;
5027 visibility = ppc_xcoff_get_visibility ();
5028 if (!visibility)
5029 {
5030 as_bad (_("Unknown visibility field in .weak"));
5031 ignore_rest_of_line ();
5032 return;
5033 }
5034
5035 coffsym->native->u.syment.n_type &= ~SYM_V_MASK;
5036 coffsym->native->u.syment.n_type |= visibility;
5037 }
5038
5039 demand_empty_rest_of_line ();
5040 }
5041
5042 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
5043
5044 static void
5045 ppc_lglobl (int ignore ATTRIBUTE_UNUSED)
5046 {
5047 char *name;
5048 char endc;
5049 symbolS *sym;
5050
5051 endc = get_symbol_name (&name);
5052
5053 sym = symbol_find_or_make (name);
5054
5055 (void) restore_line_pointer (endc);
5056
5057 symbol_get_tc (sym)->output = 1;
5058
5059 demand_empty_rest_of_line ();
5060 }
5061
5062 /* The .ref pseudo-op. It takes a list of symbol names and inserts R_REF
5063 relocations at the beginning of the current csect.
5064
5065 (In principle, there's no reason why the relocations _have_ to be at
5066 the beginning. Anywhere in the csect would do. However, inserting
5067 at the beginning is what the native assembler does, and it helps to
5068 deal with cases where the .ref statements follow the section contents.)
5069
5070 ??? .refs don't work for empty .csects. However, the native assembler
5071 doesn't report an error in this case, and neither yet do we. */
5072
5073 static void
5074 ppc_ref (int ignore ATTRIBUTE_UNUSED)
5075 {
5076 char *name;
5077 char c;
5078
5079 if (ppc_current_csect == NULL)
5080 {
5081 as_bad (_(".ref outside .csect"));
5082 ignore_rest_of_line ();
5083 return;
5084 }
5085
5086 do
5087 {
5088 c = get_symbol_name (&name);
5089
5090 fix_at_start (symbol_get_frag (ppc_current_csect), 0,
5091 symbol_find_or_make (name), 0, false, BFD_RELOC_NONE);
5092
5093 *input_line_pointer = c;
5094 SKIP_WHITESPACE_AFTER_NAME ();
5095 c = *input_line_pointer;
5096 if (c == ',')
5097 {
5098 input_line_pointer++;
5099 SKIP_WHITESPACE ();
5100 if (is_end_of_line[(unsigned char) *input_line_pointer])
5101 {
5102 as_bad (_("missing symbol name"));
5103 ignore_rest_of_line ();
5104 return;
5105 }
5106 }
5107 }
5108 while (c == ',');
5109
5110 demand_empty_rest_of_line ();
5111 }
5112
5113 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
5114 although I don't know why it bothers. */
5115
5116 static void
5117 ppc_rename (int ignore ATTRIBUTE_UNUSED)
5118 {
5119 char *name;
5120 char endc;
5121 symbolS *sym;
5122 int len;
5123
5124 endc = get_symbol_name (&name);
5125
5126 sym = symbol_find_or_make (name);
5127
5128 (void) restore_line_pointer (endc);
5129
5130 if (*input_line_pointer != ',')
5131 {
5132 as_bad (_("missing rename string"));
5133 ignore_rest_of_line ();
5134 return;
5135 }
5136 ++input_line_pointer;
5137
5138 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
5139
5140 demand_empty_rest_of_line ();
5141 }
5142
5143 /* The .stabx pseudo-op. This is similar to a normal .stabs
5144 pseudo-op, but slightly different. A sample is
5145 .stabx "main:F-1",.main,142,0
5146 The first argument is the symbol name to create. The second is the
5147 value, and the third is the storage class. The fourth seems to be
5148 always zero, and I am assuming it is the type. */
5149
5150 static void
5151 ppc_stabx (int ignore ATTRIBUTE_UNUSED)
5152 {
5153 char *name;
5154 int len;
5155 symbolS *sym;
5156 expressionS exp;
5157
5158 name = demand_copy_C_string (&len);
5159
5160 if (*input_line_pointer != ',')
5161 {
5162 as_bad (_("missing value"));
5163 return;
5164 }
5165 ++input_line_pointer;
5166
5167 ppc_stab_symbol = true;
5168 sym = symbol_make (name);
5169 ppc_stab_symbol = false;
5170
5171 symbol_get_tc (sym)->real_name = name;
5172
5173 (void) expression (&exp);
5174
5175 switch (exp.X_op)
5176 {
5177 case O_illegal:
5178 case O_absent:
5179 case O_big:
5180 as_bad (_("illegal .stabx expression; zero assumed"));
5181 exp.X_add_number = 0;
5182 /* Fall through. */
5183 case O_constant:
5184 S_SET_VALUE (sym, (valueT) exp.X_add_number);
5185 symbol_set_frag (sym, &zero_address_frag);
5186 break;
5187
5188 case O_symbol:
5189 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
5190 symbol_set_value_expression (sym, &exp);
5191 else
5192 {
5193 S_SET_VALUE (sym,
5194 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
5195 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
5196 }
5197 break;
5198
5199 default:
5200 /* The value is some complex expression. This will probably
5201 fail at some later point, but this is probably the right
5202 thing to do here. */
5203 symbol_set_value_expression (sym, &exp);
5204 break;
5205 }
5206
5207 S_SET_SEGMENT (sym, ppc_coff_debug_section);
5208 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5209
5210 if (*input_line_pointer != ',')
5211 {
5212 as_bad (_("missing class"));
5213 return;
5214 }
5215 ++input_line_pointer;
5216
5217 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
5218
5219 if (*input_line_pointer != ',')
5220 {
5221 as_bad (_("missing type"));
5222 return;
5223 }
5224 ++input_line_pointer;
5225
5226 S_SET_DATA_TYPE (sym, get_absolute_expression ());
5227
5228 symbol_get_tc (sym)->output = 1;
5229
5230 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5231 {
5232 /* In this case :
5233
5234 .bs name
5235 .stabx "z",arrays_,133,0
5236 .es
5237
5238 .comm arrays_,13768,3
5239
5240 resolve_symbol_value will copy the exp's "within" into sym's when the
5241 offset is 0. Since this seems to be corner case problem,
5242 only do the correction for storage class C_STSYM. A better solution
5243 would be to have the tc field updated in ppc_symbol_new_hook. */
5244
5245 if (exp.X_op == O_symbol)
5246 {
5247 if (ppc_current_block == NULL)
5248 as_bad (_(".stabx of storage class stsym must be within .bs/.es"));
5249
5250 symbol_get_tc (sym)->within = ppc_current_block;
5251 }
5252 }
5253
5254 if (exp.X_op != O_symbol
5255 || ! S_IS_EXTERNAL (exp.X_add_symbol)
5256 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
5257 ppc_frob_label (sym);
5258 else
5259 {
5260 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5261 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
5262 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
5263 symbol_get_tc (ppc_current_csect)->within = sym;
5264 }
5265
5266 demand_empty_rest_of_line ();
5267 }
5268
5269 /* The .file pseudo-op. On XCOFF, .file can have several parameters
5270 which are being added to the symbol table to provide additional
5271 information. */
5272
5273 static void
5274 ppc_file (int ignore ATTRIBUTE_UNUSED)
5275 {
5276 char *sfname, *s1 = NULL, *s2 = NULL, *s3 = NULL;
5277 int length, auxnb = 1;
5278
5279 /* Some assemblers tolerate immediately following '"'. */
5280 if ((sfname = demand_copy_string (&length)) != 0)
5281 {
5282 coff_symbol_type *coffsym;
5283 if (*input_line_pointer == ',')
5284 {
5285 ++input_line_pointer;
5286 s1 = demand_copy_string (&length);
5287 auxnb++;
5288
5289 if (*input_line_pointer == ',')
5290 {
5291 ++input_line_pointer;
5292 s2 = demand_copy_string (&length);
5293 auxnb++;
5294
5295 if (*input_line_pointer == ',')
5296 {
5297 ++input_line_pointer;
5298 s3 = demand_copy_string (&length);
5299 auxnb++;
5300 }
5301 }
5302 }
5303
5304 /* Use coff dot_file creation and adjust auxiliary entries. */
5305 c_dot_file_symbol (sfname, 0);
5306 S_SET_NUMBER_AUXILIARY (symbol_rootP, auxnb);
5307 coffsym = coffsymbol (symbol_get_bfdsym (symbol_rootP));
5308 coffsym->native[1].u.auxent.x_file.x_ftype = XFT_FN;
5309
5310 if (s1)
5311 {
5312 coffsym->native[2].u.auxent.x_file.x_ftype = XFT_CT;
5313 coffsym->native[2].extrap = s1;
5314 }
5315 if (s2)
5316 {
5317 coffsym->native[3].u.auxent.x_file.x_ftype = XFT_CV;
5318 coffsym->native[3].extrap = s2;
5319 }
5320 if (s3)
5321 {
5322 coffsym->native[4].u.auxent.x_file.x_ftype = XFT_CD;
5323 coffsym->native[4].extrap = s3;
5324 }
5325
5326 demand_empty_rest_of_line ();
5327 }
5328 }
5329
5330 /* The .function pseudo-op. This takes several arguments. The first
5331 argument seems to be the external name of the symbol. The second
5332 argument seems to be the label for the start of the function. gcc
5333 uses the same name for both. I have no idea what the third and
5334 fourth arguments are meant to be. The optional fifth argument is
5335 an expression for the size of the function. In COFF this symbol
5336 gets an aux entry like that used for a csect. */
5337
5338 static void
5339 ppc_function (int ignore ATTRIBUTE_UNUSED)
5340 {
5341 char *name;
5342 char endc;
5343 char *s;
5344 symbolS *ext_sym;
5345 symbolS *lab_sym;
5346
5347 endc = get_symbol_name (&name);
5348
5349 /* Ignore any [PR] suffix. */
5350 name = ppc_canonicalize_symbol_name (name);
5351 s = strchr (name, '[');
5352 if (s != (char *) NULL
5353 && strcmp (s + 1, "PR]") == 0)
5354 *s = '\0';
5355
5356 ext_sym = symbol_find_or_make (name);
5357
5358 (void) restore_line_pointer (endc);
5359
5360 if (*input_line_pointer != ',')
5361 {
5362 as_bad (_("missing symbol name"));
5363 ignore_rest_of_line ();
5364 return;
5365 }
5366 ++input_line_pointer;
5367
5368 endc = get_symbol_name (&name);
5369
5370 lab_sym = symbol_find_or_make (name);
5371
5372 (void) restore_line_pointer (endc);
5373
5374 if (ext_sym != lab_sym)
5375 {
5376 expressionS exp;
5377
5378 exp.X_op = O_symbol;
5379 exp.X_add_symbol = lab_sym;
5380 exp.X_op_symbol = NULL;
5381 exp.X_add_number = 0;
5382 exp.X_unsigned = 0;
5383 symbol_set_value_expression (ext_sym, &exp);
5384 }
5385
5386 if (symbol_get_tc (ext_sym)->symbol_class == -1)
5387 symbol_get_tc (ext_sym)->symbol_class = XMC_PR;
5388 symbol_get_tc (ext_sym)->output = 1;
5389
5390 if (*input_line_pointer == ',')
5391 {
5392 expressionS exp;
5393
5394 /* Ignore the third argument. */
5395 ++input_line_pointer;
5396 expression (& exp);
5397 if (*input_line_pointer == ',')
5398 {
5399 /* Ignore the fourth argument. */
5400 ++input_line_pointer;
5401 expression (& exp);
5402 if (*input_line_pointer == ',')
5403 {
5404 /* The fifth argument is the function size.
5405 If it's omitted, the size will be the containing csect.
5406 This will be donce during ppc_frob_symtab. */
5407 ++input_line_pointer;
5408 symbol_get_tc (ext_sym)->u.size
5409 = symbol_new ("L0\001", absolute_section,
5410 &zero_address_frag, 0);
5411 pseudo_set (symbol_get_tc (ext_sym)->u.size);
5412 }
5413 }
5414 }
5415
5416 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
5417 SF_SET_FUNCTION (ext_sym);
5418 SF_SET_PROCESS (ext_sym);
5419 coff_add_linesym (ext_sym);
5420
5421 demand_empty_rest_of_line ();
5422 }
5423
5424 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
5425 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
5426 with the correct line number */
5427
5428 static symbolS *saved_bi_sym = 0;
5429
5430 static void
5431 ppc_bf (int ignore ATTRIBUTE_UNUSED)
5432 {
5433 symbolS *sym;
5434
5435 sym = symbol_make (".bf");
5436 S_SET_SEGMENT (sym, text_section);
5437 symbol_set_frag (sym, frag_now);
5438 S_SET_VALUE (sym, frag_now_fix ());
5439 S_SET_STORAGE_CLASS (sym, C_FCN);
5440
5441 coff_line_base = get_absolute_expression ();
5442
5443 S_SET_NUMBER_AUXILIARY (sym, 1);
5444 SA_SET_SYM_LNNO (sym, coff_line_base);
5445
5446 /* Line number for bi. */
5447 if (saved_bi_sym)
5448 {
5449 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
5450 saved_bi_sym = 0;
5451 }
5452
5453
5454 symbol_get_tc (sym)->output = 1;
5455
5456 ppc_frob_label (sym);
5457
5458 demand_empty_rest_of_line ();
5459 }
5460
5461 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
5462 ".ef", except that the line number is absolute, not relative to the
5463 most recent ".bf" symbol. */
5464
5465 static void
5466 ppc_ef (int ignore ATTRIBUTE_UNUSED)
5467 {
5468 symbolS *sym;
5469
5470 sym = symbol_make (".ef");
5471 S_SET_SEGMENT (sym, text_section);
5472 symbol_set_frag (sym, frag_now);
5473 S_SET_VALUE (sym, frag_now_fix ());
5474 S_SET_STORAGE_CLASS (sym, C_FCN);
5475 S_SET_NUMBER_AUXILIARY (sym, 1);
5476 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
5477 symbol_get_tc (sym)->output = 1;
5478
5479 ppc_frob_label (sym);
5480
5481 demand_empty_rest_of_line ();
5482 }
5483
5484 /* The .bi and .ei pseudo-ops. These take a string argument and
5485 generates a C_BINCL or C_EINCL symbol, which goes at the start of
5486 the symbol list. The value of .bi will be know when the next .bf
5487 is encountered. */
5488
5489 static void
5490 ppc_biei (int ei)
5491 {
5492 static symbolS *last_biei;
5493
5494 char *name;
5495 int len;
5496 symbolS *sym;
5497 symbolS *look;
5498
5499 name = demand_copy_C_string (&len);
5500
5501 /* The value of these symbols is actually file offset. Here we set
5502 the value to the index into the line number entries. In
5503 ppc_frob_symbols we set the fix_line field, which will cause BFD
5504 to do the right thing. */
5505
5506 sym = symbol_make (name);
5507 /* obj-coff.c currently only handles line numbers correctly in the
5508 .text section. */
5509 S_SET_SEGMENT (sym, text_section);
5510 S_SET_VALUE (sym, coff_n_line_nos);
5511 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5512
5513 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
5514 symbol_get_tc (sym)->output = 1;
5515
5516 /* Save bi. */
5517 if (ei)
5518 saved_bi_sym = 0;
5519 else
5520 saved_bi_sym = sym;
5521
5522 for (look = last_biei ? last_biei : symbol_rootP;
5523 (look != (symbolS *) NULL
5524 && (S_GET_STORAGE_CLASS (look) == C_FILE
5525 || S_GET_STORAGE_CLASS (look) == C_BINCL
5526 || S_GET_STORAGE_CLASS (look) == C_EINCL));
5527 look = symbol_next (look))
5528 ;
5529 if (look != (symbolS *) NULL)
5530 {
5531 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5532 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
5533 last_biei = sym;
5534 }
5535
5536 demand_empty_rest_of_line ();
5537 }
5538
5539 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
5540 There is one argument, which is a csect symbol. The value of the
5541 .bs symbol is the index of this csect symbol. */
5542
5543 static void
5544 ppc_bs (int ignore ATTRIBUTE_UNUSED)
5545 {
5546 char *name;
5547 char endc;
5548 symbolS *csect;
5549 symbolS *sym;
5550
5551 if (ppc_current_block != NULL)
5552 as_bad (_("nested .bs blocks"));
5553
5554 endc = get_symbol_name (&name);
5555
5556 csect = symbol_find_or_make (name);
5557
5558 (void) restore_line_pointer (endc);
5559
5560 sym = symbol_make (".bs");
5561 S_SET_SEGMENT (sym, now_seg);
5562 S_SET_STORAGE_CLASS (sym, C_BSTAT);
5563 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5564 symbol_get_tc (sym)->output = 1;
5565
5566 symbol_get_tc (sym)->within = csect;
5567
5568 ppc_frob_label (sym);
5569
5570 ppc_current_block = sym;
5571
5572 demand_empty_rest_of_line ();
5573 }
5574
5575 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
5576
5577 static void
5578 ppc_es (int ignore ATTRIBUTE_UNUSED)
5579 {
5580 symbolS *sym;
5581
5582 if (ppc_current_block == NULL)
5583 as_bad (_(".es without preceding .bs"));
5584
5585 sym = symbol_make (".es");
5586 S_SET_SEGMENT (sym, now_seg);
5587 S_SET_STORAGE_CLASS (sym, C_ESTAT);
5588 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5589 symbol_get_tc (sym)->output = 1;
5590
5591 ppc_frob_label (sym);
5592
5593 ppc_current_block = NULL;
5594
5595 demand_empty_rest_of_line ();
5596 }
5597
5598 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
5599 line number. */
5600
5601 static void
5602 ppc_bb (int ignore ATTRIBUTE_UNUSED)
5603 {
5604 symbolS *sym;
5605
5606 sym = symbol_make (".bb");
5607 S_SET_SEGMENT (sym, text_section);
5608 symbol_set_frag (sym, frag_now);
5609 S_SET_VALUE (sym, frag_now_fix ());
5610 S_SET_STORAGE_CLASS (sym, C_BLOCK);
5611
5612 S_SET_NUMBER_AUXILIARY (sym, 1);
5613 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
5614
5615 symbol_get_tc (sym)->output = 1;
5616
5617 SF_SET_PROCESS (sym);
5618
5619 ppc_frob_label (sym);
5620
5621 demand_empty_rest_of_line ();
5622 }
5623
5624 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
5625 line number. */
5626
5627 static void
5628 ppc_eb (int ignore ATTRIBUTE_UNUSED)
5629 {
5630 symbolS *sym;
5631
5632 sym = symbol_make (".eb");
5633 S_SET_SEGMENT (sym, text_section);
5634 symbol_set_frag (sym, frag_now);
5635 S_SET_VALUE (sym, frag_now_fix ());
5636 S_SET_STORAGE_CLASS (sym, C_BLOCK);
5637 S_SET_NUMBER_AUXILIARY (sym, 1);
5638 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
5639 symbol_get_tc (sym)->output = 1;
5640
5641 SF_SET_PROCESS (sym);
5642
5643 ppc_frob_label (sym);
5644
5645 demand_empty_rest_of_line ();
5646 }
5647
5648 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
5649 specified name. */
5650
5651 static void
5652 ppc_bc (int ignore ATTRIBUTE_UNUSED)
5653 {
5654 char *name;
5655 int len;
5656 symbolS *sym;
5657
5658 name = demand_copy_C_string (&len);
5659 sym = symbol_make (name);
5660 S_SET_SEGMENT (sym, ppc_coff_debug_section);
5661 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5662 S_SET_STORAGE_CLASS (sym, C_BCOMM);
5663 S_SET_VALUE (sym, 0);
5664 symbol_get_tc (sym)->output = 1;
5665
5666 ppc_frob_label (sym);
5667
5668 demand_empty_rest_of_line ();
5669 }
5670
5671 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
5672
5673 static void
5674 ppc_ec (int ignore ATTRIBUTE_UNUSED)
5675 {
5676 symbolS *sym;
5677
5678 sym = symbol_make (".ec");
5679 S_SET_SEGMENT (sym, ppc_coff_debug_section);
5680 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
5681 S_SET_STORAGE_CLASS (sym, C_ECOMM);
5682 S_SET_VALUE (sym, 0);
5683 symbol_get_tc (sym)->output = 1;
5684
5685 ppc_frob_label (sym);
5686
5687 demand_empty_rest_of_line ();
5688 }
5689
5690 /* The .toc pseudo-op. Switch to the .toc subsegment. */
5691
5692 static void
5693 ppc_toc (int ignore ATTRIBUTE_UNUSED)
5694 {
5695 if (ppc_toc_csect != (symbolS *) NULL)
5696 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
5697 else
5698 {
5699 subsegT subseg;
5700 symbolS *sym;
5701 symbolS *list;
5702
5703 subseg = ppc_xcoff_data_section.next_subsegment;
5704 ++ppc_xcoff_data_section.next_subsegment;
5705
5706 subseg_new (segment_name (data_section), subseg);
5707 ppc_toc_frag = frag_now;
5708
5709 sym = symbol_find_or_make ("TOC[TC0]");
5710 symbol_set_frag (sym, frag_now);
5711 S_SET_SEGMENT (sym, data_section);
5712 S_SET_VALUE (sym, (valueT) frag_now_fix ());
5713 symbol_get_tc (sym)->subseg = subseg;
5714 symbol_get_tc (sym)->output = 1;
5715 symbol_get_tc (sym)->within = sym;
5716
5717 ppc_toc_csect = sym;
5718
5719 for (list = ppc_xcoff_data_section.csects;
5720 symbol_get_tc (list)->next != (symbolS *) NULL;
5721 list = symbol_get_tc (list)->next)
5722 ;
5723 symbol_get_tc (list)->next = sym;
5724
5725 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5726 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
5727 &symbol_lastP);
5728 }
5729
5730 ppc_current_csect = ppc_toc_csect;
5731
5732 demand_empty_rest_of_line ();
5733 }
5734
5735 /* The AIX assembler automatically aligns the operands of a .long or
5736 .short pseudo-op, and we want to be compatible. */
5737
5738 static void
5739 ppc_xcoff_cons (int log_size)
5740 {
5741 frag_align (log_size, 0, 0);
5742 record_alignment (now_seg, log_size);
5743 cons (1 << log_size);
5744 }
5745
5746 static void
5747 ppc_vbyte (int dummy ATTRIBUTE_UNUSED)
5748 {
5749 expressionS exp;
5750 int byte_count;
5751
5752 (void) expression (&exp);
5753
5754 if (exp.X_op != O_constant)
5755 {
5756 as_bad (_("non-constant byte count"));
5757 return;
5758 }
5759
5760 byte_count = exp.X_add_number;
5761
5762 if (*input_line_pointer != ',')
5763 {
5764 as_bad (_("missing value"));
5765 return;
5766 }
5767
5768 ++input_line_pointer;
5769 cons (byte_count);
5770 }
5771
5772 void
5773 ppc_xcoff_end (void)
5774 {
5775 int i;
5776
5777 for (i = 0; i < XCOFF_DWSECT_NBR_NAMES; i++)
5778 {
5779 struct dw_section *dws = &dw_sections[i];
5780 struct dw_subsection *dwss;
5781
5782 if (dws->anon_subseg)
5783 {
5784 dwss = dws->anon_subseg;
5785 dwss->link = dws->list_subseg;
5786 }
5787 else
5788 dwss = dws->list_subseg;
5789
5790 for (; dwss != NULL; dwss = dwss->link)
5791 if (dwss->end_exp.X_add_symbol != NULL)
5792 {
5793 subseg_set (dws->sect, dwss->subseg);
5794 symbol_set_value_now (dwss->end_exp.X_add_symbol);
5795 }
5796 }
5797 ppc_cpu = 0;
5798 }
5799
5800 #endif /* OBJ_XCOFF */
5801 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5802 \f
5803 /* The .tc pseudo-op. This is used when generating either XCOFF or
5804 ELF. This takes two or more arguments.
5805
5806 When generating XCOFF output, the first argument is the name to
5807 give to this location in the toc; this will be a symbol with class
5808 TC. The rest of the arguments are N-byte values to actually put at
5809 this location in the TOC; often there is just one more argument, a
5810 relocatable symbol reference. The size of the value to store
5811 depends on target word size. A 32-bit target uses 4-byte values, a
5812 64-bit target uses 8-byte values.
5813
5814 When not generating XCOFF output, the arguments are the same, but
5815 the first argument is simply ignored. */
5816
5817 static void
5818 ppc_tc (int ignore ATTRIBUTE_UNUSED)
5819 {
5820 #ifdef OBJ_XCOFF
5821
5822 /* Define the TOC symbol name. */
5823 {
5824 char *name;
5825 char endc;
5826 symbolS *sym;
5827
5828 if (ppc_toc_csect == (symbolS *) NULL
5829 || ppc_toc_csect != ppc_current_csect)
5830 {
5831 as_bad (_(".tc not in .toc section"));
5832 ignore_rest_of_line ();
5833 return;
5834 }
5835
5836 endc = get_symbol_name (&name);
5837
5838 sym = symbol_find_or_make (name);
5839
5840 (void) restore_line_pointer (endc);
5841
5842 if (S_IS_DEFINED (sym))
5843 {
5844 symbolS *label;
5845
5846 label = symbol_get_tc (ppc_current_csect)->within;
5847 if (symbol_get_tc (label)->symbol_class != XMC_TC0)
5848 {
5849 as_bad (_(".tc with no label"));
5850 ignore_rest_of_line ();
5851 return;
5852 }
5853
5854 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
5855 symbol_set_frag (label, symbol_get_frag (sym));
5856 S_SET_VALUE (label, S_GET_VALUE (sym));
5857
5858 while (! is_end_of_line[(unsigned char) *input_line_pointer])
5859 ++input_line_pointer;
5860
5861 return;
5862 }
5863
5864 S_SET_SEGMENT (sym, now_seg);
5865 symbol_set_frag (sym, frag_now);
5866 S_SET_VALUE (sym, (valueT) frag_now_fix ());
5867
5868 /* AIX assembler seems to allow any storage class to be set in .tc.
5869 But for now, only XMC_TC and XMC_TE are supported by us. */
5870 switch (symbol_get_tc (sym)->symbol_class)
5871 {
5872 case XMC_TC:
5873 case XMC_TE:
5874 break;
5875
5876 default:
5877 as_bad (_(".tc with storage class %d not yet supported"),
5878 symbol_get_tc (sym)->symbol_class);
5879 ignore_rest_of_line ();
5880 return;
5881 }
5882 symbol_get_tc (sym)->output = 1;
5883
5884 ppc_frob_label (sym);
5885 }
5886
5887 #endif /* OBJ_XCOFF */
5888 #ifdef OBJ_ELF
5889 int align;
5890
5891 /* Skip the TOC symbol name. */
5892 while (is_part_of_name (*input_line_pointer)
5893 || *input_line_pointer == ' '
5894 || *input_line_pointer == '['
5895 || *input_line_pointer == ']'
5896 || *input_line_pointer == '{'
5897 || *input_line_pointer == '}')
5898 ++input_line_pointer;
5899
5900 /* Align to a four/eight byte boundary. */
5901 align = ppc_obj64 ? 3 : 2;
5902 frag_align (align, 0, 0);
5903 record_alignment (now_seg, align);
5904 #endif /* OBJ_ELF */
5905
5906 if (*input_line_pointer != ',')
5907 demand_empty_rest_of_line ();
5908 else
5909 {
5910 ++input_line_pointer;
5911 cons (ppc_obj64 ? 8 : 4);
5912 }
5913 }
5914
5915 /* Pseudo-op .machine. */
5916
5917 static void
5918 ppc_machine (int ignore ATTRIBUTE_UNUSED)
5919 {
5920 char c;
5921 char *cpu_string;
5922 #define MAX_HISTORY 100
5923 static ppc_cpu_t *cpu_history;
5924 static int curr_hist;
5925
5926 SKIP_WHITESPACE ();
5927
5928 c = get_symbol_name (&cpu_string);
5929 cpu_string = xstrdup (cpu_string);
5930 (void) restore_line_pointer (c);
5931
5932 if (cpu_string != NULL)
5933 {
5934 ppc_cpu_t old_cpu = ppc_cpu;
5935 char *p;
5936
5937 for (p = cpu_string; *p != 0; p++)
5938 *p = TOLOWER (*p);
5939
5940 if (strcmp (cpu_string, "push") == 0)
5941 {
5942 if (cpu_history == NULL)
5943 cpu_history = XNEWVEC (ppc_cpu_t, MAX_HISTORY);
5944
5945 if (curr_hist >= MAX_HISTORY)
5946 as_bad (_(".machine stack overflow"));
5947 else
5948 cpu_history[curr_hist++] = ppc_cpu;
5949 }
5950 else if (strcmp (cpu_string, "pop") == 0)
5951 {
5952 if (curr_hist <= 0)
5953 as_bad (_(".machine stack underflow"));
5954 else
5955 ppc_cpu = cpu_history[--curr_hist];
5956 }
5957 else
5958 {
5959 ppc_cpu_t new_cpu;
5960 /* Not using the global "sticky" variable here results in
5961 none of the extra functional unit command line options,
5962 -many, -maltivec, -mspe, -mspe2, -mvle, -mvsx, being in
5963 force after selecting a new cpu with .machine.
5964 ".machine altivec" and other extra functional unit
5965 options do not count as a new machine, instead they add
5966 to currently selected opcodes. */
5967 ppc_cpu_t machine_sticky = 0;
5968 new_cpu = ppc_parse_cpu (ppc_cpu, &machine_sticky, cpu_string);
5969 if (new_cpu != 0)
5970 ppc_cpu = new_cpu;
5971 else
5972 as_bad (_("invalid machine `%s'"), cpu_string);
5973 }
5974
5975 if (ppc_cpu != old_cpu)
5976 ppc_setup_opcodes ();
5977 }
5978
5979 demand_empty_rest_of_line ();
5980 }
5981 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5982 \f
5983 #ifdef OBJ_XCOFF
5984
5985 /* XCOFF specific symbol and file handling. */
5986
5987 /* Canonicalize the symbol name. We use the to force the suffix, if
5988 any, to use square brackets, and to be in upper case. */
5989
5990 char *
5991 ppc_canonicalize_symbol_name (char *name)
5992 {
5993 char *s;
5994
5995 if (ppc_stab_symbol)
5996 return name;
5997
5998 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
5999 ;
6000 if (*s != '\0')
6001 {
6002 char brac;
6003
6004 if (*s == '[')
6005 brac = ']';
6006 else
6007 {
6008 *s = '[';
6009 brac = '}';
6010 }
6011
6012 for (s++; *s != '\0' && *s != brac; s++)
6013 *s = TOUPPER (*s);
6014
6015 if (*s == '\0' || s[1] != '\0')
6016 as_bad (_("bad symbol suffix"));
6017
6018 *s = ']';
6019 }
6020
6021 return name;
6022 }
6023
6024 /* Set the class of a symbol based on the suffix, if any. This is
6025 called whenever a new symbol is created. */
6026
6027 void
6028 ppc_symbol_new_hook (symbolS *sym)
6029 {
6030 struct ppc_tc_sy *tc;
6031 const char *s;
6032
6033 tc = symbol_get_tc (sym);
6034 tc->next = NULL;
6035 tc->output = 0;
6036 tc->symbol_class = -1;
6037 tc->real_name = NULL;
6038 tc->subseg = 0;
6039 tc->align = 0;
6040 tc->u.size = NULL;
6041 tc->u.dw = NULL;
6042 tc->within = NULL;
6043
6044 if (ppc_stab_symbol)
6045 return;
6046
6047 s = strchr (S_GET_NAME (sym), '[');
6048 if (s == (const char *) NULL)
6049 {
6050 /* There is no suffix. */
6051 return;
6052 }
6053
6054 ++s;
6055
6056 switch (s[0])
6057 {
6058 case 'B':
6059 if (strcmp (s, "BS]") == 0)
6060 tc->symbol_class = XMC_BS;
6061 break;
6062 case 'D':
6063 if (strcmp (s, "DB]") == 0)
6064 tc->symbol_class = XMC_DB;
6065 else if (strcmp (s, "DS]") == 0)
6066 tc->symbol_class = XMC_DS;
6067 break;
6068 case 'G':
6069 if (strcmp (s, "GL]") == 0)
6070 tc->symbol_class = XMC_GL;
6071 break;
6072 case 'P':
6073 if (strcmp (s, "PR]") == 0)
6074 tc->symbol_class = XMC_PR;
6075 break;
6076 case 'R':
6077 if (strcmp (s, "RO]") == 0)
6078 tc->symbol_class = XMC_RO;
6079 else if (strcmp (s, "RW]") == 0)
6080 tc->symbol_class = XMC_RW;
6081 break;
6082 case 'S':
6083 if (strcmp (s, "SV]") == 0)
6084 tc->symbol_class = XMC_SV;
6085 break;
6086 case 'T':
6087 if (strcmp (s, "TC]") == 0)
6088 tc->symbol_class = XMC_TC;
6089 else if (strcmp (s, "TI]") == 0)
6090 tc->symbol_class = XMC_TI;
6091 else if (strcmp (s, "TB]") == 0)
6092 tc->symbol_class = XMC_TB;
6093 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
6094 tc->symbol_class = XMC_TC0;
6095 else if (strcmp (s, "TE]") == 0)
6096 tc->symbol_class = XMC_TE;
6097 else if (strcmp (s, "TL]") == 0)
6098 tc->symbol_class = XMC_TL;
6099 break;
6100 case 'U':
6101 if (strcmp (s, "UA]") == 0)
6102 tc->symbol_class = XMC_UA;
6103 else if (strcmp (s, "UC]") == 0)
6104 tc->symbol_class = XMC_UC;
6105 else if (strcmp (s, "UL]") == 0)
6106 tc->symbol_class = XMC_UL;
6107 break;
6108 case 'X':
6109 if (strcmp (s, "XO]") == 0)
6110 tc->symbol_class = XMC_XO;
6111 break;
6112 }
6113
6114 if (tc->symbol_class == -1)
6115 as_bad (_("unrecognized symbol suffix"));
6116 }
6117
6118 /* This variable is set by ppc_frob_symbol if any absolute symbols are
6119 seen. It tells ppc_adjust_symtab whether it needs to look through
6120 the symbols. */
6121
6122 static bool ppc_saw_abs;
6123
6124 /* Change the name of a symbol just before writing it out. Set the
6125 real name if the .rename pseudo-op was used. Otherwise, remove any
6126 class suffix. Return 1 if the symbol should not be included in the
6127 symbol table. */
6128
6129 int
6130 ppc_frob_symbol (symbolS *sym)
6131 {
6132 static symbolS *ppc_last_function;
6133 static symbolS *set_end;
6134
6135 /* Discard symbols that should not be included in the output symbol
6136 table. */
6137 if (! symbol_used_in_reloc_p (sym)
6138 && S_GET_STORAGE_CLASS (sym) != C_DWARF
6139 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
6140 || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
6141 && ! symbol_get_tc (sym)->output
6142 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
6143 return 1;
6144
6145 /* This one will disappear anyway. Don't make a csect sym for it. */
6146 if (sym == abs_section_sym)
6147 return 1;
6148
6149 if (symbol_get_tc (sym)->real_name != (char *) NULL)
6150 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
6151 else
6152 {
6153 const char *name;
6154 const char *s;
6155
6156 name = S_GET_NAME (sym);
6157 s = strchr (name, '[');
6158 if (s != (char *) NULL)
6159 {
6160 unsigned int len;
6161 char *snew;
6162
6163 len = s - name;
6164 snew = xstrndup (name, len);
6165
6166 S_SET_NAME (sym, snew);
6167 }
6168 }
6169
6170 if (set_end != (symbolS *) NULL)
6171 {
6172 SA_SET_SYM_ENDNDX (set_end, sym);
6173 set_end = NULL;
6174 }
6175
6176 if (SF_GET_FUNCTION (sym))
6177 {
6178 /* Make sure coff_last_function is reset. Otherwise, we won't create
6179 the auxent for the next function. */
6180 coff_last_function = 0;
6181 ppc_last_function = sym;
6182 if (symbol_get_tc (sym)->u.size != (symbolS *) NULL)
6183 {
6184 resolve_symbol_value (symbol_get_tc (sym)->u.size);
6185 SA_SET_SYM_FSIZE (sym,
6186 (long) S_GET_VALUE (symbol_get_tc (sym)->u.size));
6187 }
6188 else
6189 {
6190 /* Size of containing csect. */
6191 symbolS* within = symbol_get_tc (sym)->within;
6192 union internal_auxent *csectaux;
6193 csectaux = &coffsymbol (symbol_get_bfdsym (within))
6194 ->native[S_GET_NUMBER_AUXILIARY(within)].u.auxent;
6195
6196 SA_SET_SYM_FSIZE (sym, csectaux->x_csect.x_scnlen.l);
6197 }
6198 }
6199 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
6200 && strcmp (S_GET_NAME (sym), ".ef") == 0)
6201 {
6202 if (ppc_last_function == (symbolS *) NULL)
6203 as_bad (_(".ef with no preceding .function"));
6204 else
6205 {
6206 set_end = ppc_last_function;
6207 ppc_last_function = NULL;
6208
6209 /* We don't have a C_EFCN symbol, but we need to force the
6210 COFF backend to believe that it has seen one. */
6211 coff_last_function = NULL;
6212 }
6213 }
6214
6215 if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
6216 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
6217 && S_GET_STORAGE_CLASS (sym) != C_FILE
6218 && S_GET_STORAGE_CLASS (sym) != C_FCN
6219 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
6220 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
6221 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
6222 && S_GET_STORAGE_CLASS (sym) != C_BINCL
6223 && S_GET_STORAGE_CLASS (sym) != C_EINCL
6224 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
6225 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
6226
6227 if (S_GET_STORAGE_CLASS (sym) == C_EXT
6228 || S_GET_STORAGE_CLASS (sym) == C_AIX_WEAKEXT
6229 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
6230 {
6231 int i;
6232 union internal_auxent *a;
6233
6234 /* Create a csect aux. */
6235 i = S_GET_NUMBER_AUXILIARY (sym);
6236 S_SET_NUMBER_AUXILIARY (sym, i + 1);
6237 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
6238 if (symbol_get_tc (sym)->symbol_class == XMC_TC0)
6239 {
6240 /* This is the TOC table. */
6241 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
6242 a->x_csect.x_scnlen.l = 0;
6243 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
6244 }
6245 else if (symbol_get_tc (sym)->subseg != 0)
6246 {
6247 /* This is a csect symbol. x_scnlen is the size of the
6248 csect. */
6249 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
6250 a->x_csect.x_scnlen.l = (bfd_section_size (S_GET_SEGMENT (sym))
6251 - S_GET_VALUE (sym));
6252 else
6253 {
6254 resolve_symbol_value (symbol_get_tc (sym)->next);
6255 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
6256 - S_GET_VALUE (sym));
6257 }
6258 if (symbol_get_tc (sym)->symbol_class == XMC_BS
6259 || symbol_get_tc (sym)->symbol_class == XMC_UL)
6260 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
6261 else
6262 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
6263 }
6264 else if (S_GET_SEGMENT (sym) == bss_section
6265 || S_GET_SEGMENT (sym) == ppc_xcoff_tbss_section.segment)
6266 {
6267 /* This is a common symbol. */
6268 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
6269 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
6270 if (S_GET_SEGMENT (sym) == ppc_xcoff_tbss_section.segment)
6271 symbol_get_tc (sym)->symbol_class = XMC_UL;
6272 else if (S_IS_EXTERNAL (sym))
6273 symbol_get_tc (sym)->symbol_class = XMC_RW;
6274 else
6275 symbol_get_tc (sym)->symbol_class = XMC_BS;
6276 }
6277 else if (S_GET_SEGMENT (sym) == absolute_section)
6278 {
6279 /* This is an absolute symbol. The csect will be created by
6280 ppc_adjust_symtab. */
6281 ppc_saw_abs = true;
6282 a->x_csect.x_smtyp = XTY_LD;
6283 if (symbol_get_tc (sym)->symbol_class == -1)
6284 symbol_get_tc (sym)->symbol_class = XMC_XO;
6285 }
6286 else if (! S_IS_DEFINED (sym))
6287 {
6288 /* This is an external symbol. */
6289 a->x_csect.x_scnlen.l = 0;
6290 a->x_csect.x_smtyp = XTY_ER;
6291 }
6292 else if (ppc_is_toc_sym (sym))
6293 {
6294 symbolS *next;
6295
6296 /* This is a TOC definition. x_scnlen is the size of the
6297 TOC entry. */
6298 next = symbol_next (sym);
6299 while (symbol_get_tc (next)->symbol_class == XMC_TC0)
6300 next = symbol_next (next);
6301 if (next == (symbolS *) NULL
6302 || (!ppc_is_toc_sym (next)))
6303 {
6304 if (ppc_after_toc_frag == (fragS *) NULL)
6305 a->x_csect.x_scnlen.l = (bfd_section_size (data_section)
6306 - S_GET_VALUE (sym));
6307 else
6308 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
6309 - S_GET_VALUE (sym));
6310 }
6311 else
6312 {
6313 resolve_symbol_value (next);
6314 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
6315 - S_GET_VALUE (sym));
6316 }
6317 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
6318 }
6319 else
6320 {
6321 symbolS *csect;
6322
6323 /* This is a normal symbol definition. x_scnlen is the
6324 symbol index of the containing csect. */
6325 if (S_GET_SEGMENT (sym) == text_section)
6326 csect = ppc_xcoff_text_section.csects;
6327 else if (S_GET_SEGMENT (sym) == data_section)
6328 csect = ppc_xcoff_data_section.csects;
6329 else if (S_GET_SEGMENT (sym) == ppc_xcoff_tdata_section.segment)
6330 csect = ppc_xcoff_tdata_section.csects;
6331 else
6332 abort ();
6333
6334 /* Skip the initial dummy symbol. */
6335 csect = symbol_get_tc (csect)->next;
6336
6337 if (csect == (symbolS *) NULL)
6338 {
6339 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
6340 a->x_csect.x_scnlen.l = 0;
6341 }
6342 else
6343 {
6344 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
6345 {
6346 resolve_symbol_value (symbol_get_tc (csect)->next);
6347 if (S_GET_VALUE (symbol_get_tc (csect)->next)
6348 > S_GET_VALUE (sym))
6349 break;
6350 csect = symbol_get_tc (csect)->next;
6351 }
6352
6353 a->x_csect.x_scnlen.p =
6354 coffsymbol (symbol_get_bfdsym (csect))->native;
6355 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
6356 1;
6357 }
6358 a->x_csect.x_smtyp = XTY_LD;
6359 }
6360
6361 a->x_csect.x_parmhash = 0;
6362 a->x_csect.x_snhash = 0;
6363 if (symbol_get_tc (sym)->symbol_class == -1)
6364 a->x_csect.x_smclas = XMC_PR;
6365 else
6366 a->x_csect.x_smclas = symbol_get_tc (sym)->symbol_class;
6367 a->x_csect.x_stab = 0;
6368 a->x_csect.x_snstab = 0;
6369
6370 /* Don't let the COFF backend resort these symbols. */
6371 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
6372 }
6373 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
6374 {
6375 /* We want the value to be the symbol index of the referenced
6376 csect symbol. BFD will do that for us if we set the right
6377 flags. */
6378 asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
6379 combined_entry_type *c = coffsymbol (bsym)->native;
6380
6381 S_SET_VALUE (sym, (valueT) (size_t) c);
6382 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
6383 }
6384 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
6385 {
6386 symbolS *block;
6387 valueT base;
6388
6389 block = symbol_get_tc (sym)->within;
6390 if (block)
6391 {
6392 /* The value is the offset from the enclosing csect. */
6393 symbolS *csect;
6394
6395 csect = symbol_get_tc (block)->within;
6396 resolve_symbol_value (csect);
6397 base = S_GET_VALUE (csect);
6398 }
6399 else
6400 base = 0;
6401
6402 S_SET_VALUE (sym, S_GET_VALUE (sym) - base);
6403 }
6404 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
6405 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
6406 {
6407 /* We want the value to be a file offset into the line numbers.
6408 BFD will do that for us if we set the right flags. We have
6409 already set the value correctly. */
6410 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
6411 }
6412
6413 return 0;
6414 }
6415
6416 /* Adjust the symbol table. */
6417
6418 void
6419 ppc_adjust_symtab (void)
6420 {
6421 symbolS *sym;
6422 symbolS *anchorSym;
6423
6424 /* Make sure C_DWARF symbols come right after C_FILE.
6425 As the C_FILE might not be defined yet and as C_DWARF
6426 might already be ordered, we insert them before the
6427 first symbol which isn't a C_FILE or a C_DWARF. */
6428 for (anchorSym = symbol_rootP; anchorSym != NULL;
6429 anchorSym = symbol_next (anchorSym))
6430 {
6431 if (S_GET_STORAGE_CLASS (anchorSym) != C_FILE
6432 && S_GET_STORAGE_CLASS (anchorSym) != C_DWARF)
6433 break;
6434 }
6435
6436 sym = anchorSym;
6437 while (sym != NULL)
6438 {
6439 if (S_GET_STORAGE_CLASS (sym) != C_DWARF)
6440 {
6441 sym = symbol_next (sym);
6442 continue;
6443 }
6444
6445 symbolS* tsym = sym;
6446 sym = symbol_next (sym);
6447
6448 symbol_remove (tsym, &symbol_rootP, &symbol_lastP);
6449 symbol_insert (tsym, anchorSym, &symbol_rootP, &symbol_lastP);
6450 }
6451
6452 /* Create csect symbols for all absolute symbols. */
6453
6454 if (! ppc_saw_abs)
6455 return;
6456
6457 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
6458 {
6459 symbolS *csect;
6460 int i;
6461 union internal_auxent *a;
6462
6463 if (S_GET_SEGMENT (sym) != absolute_section)
6464 continue;
6465
6466 csect = symbol_create (".abs[XO]", absolute_section,
6467 &zero_address_frag, S_GET_VALUE (sym));
6468 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
6469 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
6470 i = S_GET_NUMBER_AUXILIARY (csect);
6471 S_SET_NUMBER_AUXILIARY (csect, i + 1);
6472 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
6473 a->x_csect.x_scnlen.l = 0;
6474 a->x_csect.x_smtyp = XTY_SD;
6475 a->x_csect.x_parmhash = 0;
6476 a->x_csect.x_snhash = 0;
6477 a->x_csect.x_smclas = XMC_XO;
6478 a->x_csect.x_stab = 0;
6479 a->x_csect.x_snstab = 0;
6480
6481 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
6482
6483 i = S_GET_NUMBER_AUXILIARY (sym);
6484 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
6485 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
6486 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
6487 }
6488
6489 ppc_saw_abs = false;
6490 }
6491
6492 /* Set the VMA for a section. This is called on all the sections in
6493 turn. */
6494
6495 void
6496 ppc_frob_section (asection *sec)
6497 {
6498 static bfd_vma vma = 0;
6499
6500 /* Dwarf sections start at 0. */
6501 if (bfd_section_flags (sec) & SEC_DEBUGGING)
6502 return;
6503
6504 vma = md_section_align (sec, vma);
6505 bfd_set_section_vma (sec, vma);
6506 vma += bfd_section_size (sec);
6507 }
6508
6509 #endif /* OBJ_XCOFF */
6510 \f
6511 const char *
6512 md_atof (int type, char *litp, int *sizep)
6513 {
6514 return ieee_md_atof (type, litp, sizep, target_big_endian);
6515 }
6516
6517 /* Write a value out to the object file, using the appropriate
6518 endianness. */
6519
6520 void
6521 md_number_to_chars (char *buf, valueT val, int n)
6522 {
6523 if (target_big_endian)
6524 number_to_chars_bigendian (buf, val, n);
6525 else
6526 number_to_chars_littleendian (buf, val, n);
6527 }
6528
6529 /* Align a section (I don't know why this is machine dependent). */
6530
6531 valueT
6532 md_section_align (asection *seg ATTRIBUTE_UNUSED, valueT addr)
6533 {
6534 #ifdef OBJ_ELF
6535 return addr;
6536 #else
6537 int align = bfd_section_alignment (seg);
6538
6539 return ((addr + (1 << align) - 1) & -(1 << align));
6540 #endif
6541 }
6542
6543 /* We don't have any form of relaxing. */
6544
6545 int
6546 md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
6547 asection *seg ATTRIBUTE_UNUSED)
6548 {
6549 abort ();
6550 return 0;
6551 }
6552
6553 /* Convert a machine dependent frag. We never generate these. */
6554
6555 void
6556 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
6557 asection *sec ATTRIBUTE_UNUSED,
6558 fragS *fragp ATTRIBUTE_UNUSED)
6559 {
6560 abort ();
6561 }
6562
6563 /* We have no need to default values of symbols. */
6564
6565 symbolS *
6566 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
6567 {
6568 return 0;
6569 }
6570 \f
6571 /* Functions concerning relocs. */
6572
6573 /* The location from which a PC relative jump should be calculated,
6574 given a PC relative reloc. */
6575
6576 long
6577 md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
6578 {
6579 return fixp->fx_frag->fr_address + fixp->fx_where;
6580 }
6581
6582 #ifdef OBJ_XCOFF
6583
6584 /* Return the surrending csect for sym when possible. */
6585
6586 static symbolS*
6587 ppc_get_csect_to_adjust (symbolS *sym)
6588 {
6589 if (sym == NULL)
6590 return NULL;
6591
6592 valueT val = resolve_symbol_value (sym);
6593 TC_SYMFIELD_TYPE *tc = symbol_get_tc (sym);
6594 segT symseg = S_GET_SEGMENT (sym);
6595
6596 if (tc->subseg == 0
6597 && tc->symbol_class != XMC_TC0
6598 && tc->symbol_class != XMC_TC
6599 && tc->symbol_class != XMC_TE
6600 && symseg != bss_section
6601 && symseg != ppc_xcoff_tbss_section.segment
6602 /* Don't adjust if this is a reloc in the toc section. */
6603 && (symseg != data_section
6604 || ppc_toc_csect == NULL
6605 || val < ppc_toc_frag->fr_address
6606 || (ppc_after_toc_frag != NULL
6607 && val >= ppc_after_toc_frag->fr_address)))
6608 {
6609 symbolS* csect = tc->within;
6610
6611 /* If the symbol was not declared by a label (eg: a section symbol),
6612 use the section instead of the csect. This doesn't happen in
6613 normal AIX assembly code. */
6614 if (csect == NULL)
6615 csect = seg_info (symseg)->sym;
6616
6617 return csect;
6618 }
6619
6620 return NULL;
6621 }
6622
6623 /* This is called to see whether a fixup should be adjusted to use a
6624 section symbol. We take the opportunity to change a fixup against
6625 a symbol in the TOC subsegment into a reloc against the
6626 corresponding .tc symbol. */
6627
6628 int
6629 ppc_fix_adjustable (fixS *fix)
6630 {
6631 valueT val = resolve_symbol_value (fix->fx_addsy);
6632 segT symseg = S_GET_SEGMENT (fix->fx_addsy);
6633 symbolS* csect;
6634
6635 if (symseg == absolute_section)
6636 return 0;
6637
6638 /* Always adjust symbols in debugging sections. */
6639 if (bfd_section_flags (symseg) & SEC_DEBUGGING)
6640 return 1;
6641
6642 if (ppc_toc_csect != (symbolS *) NULL
6643 && fix->fx_addsy != ppc_toc_csect
6644 && symseg == data_section
6645 && val >= ppc_toc_frag->fr_address
6646 && (ppc_after_toc_frag == (fragS *) NULL
6647 || val < ppc_after_toc_frag->fr_address))
6648 {
6649 symbolS *sy;
6650
6651 for (sy = symbol_next (ppc_toc_csect);
6652 sy != (symbolS *) NULL;
6653 sy = symbol_next (sy))
6654 {
6655 TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
6656
6657 if (sy_tc->symbol_class == XMC_TC0)
6658 continue;
6659 if (sy_tc->symbol_class != XMC_TC
6660 && sy_tc->symbol_class != XMC_TE)
6661 break;
6662 if (val == resolve_symbol_value (sy))
6663 {
6664 fix->fx_addsy = sy;
6665 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
6666 return 0;
6667 }
6668 }
6669
6670 as_bad_where (fix->fx_file, fix->fx_line,
6671 _("symbol in .toc does not match any .tc"));
6672 }
6673
6674 /* Possibly adjust the reloc to be against the csect. */
6675 if ((csect = ppc_get_csect_to_adjust (fix->fx_addsy)) != NULL)
6676 {
6677 fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
6678 fix->fx_addsy = csect;
6679 }
6680
6681 if ((csect = ppc_get_csect_to_adjust (fix->fx_subsy)) != NULL)
6682 {
6683 fix->fx_offset -= resolve_symbol_value (fix->fx_subsy)
6684 - symbol_get_frag (csect)->fr_address;
6685 fix->fx_subsy = csect;
6686 }
6687
6688 /* Adjust a reloc against a .lcomm symbol to be against the base
6689 .lcomm. */
6690 if (symseg == bss_section
6691 && ! S_IS_EXTERNAL (fix->fx_addsy)
6692 && symbol_get_tc (fix->fx_addsy)->subseg == 0)
6693 {
6694 symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
6695
6696 fix->fx_offset += val - resolve_symbol_value (sy);
6697 fix->fx_addsy = sy;
6698 }
6699
6700 return 0;
6701 }
6702
6703 /* A reloc from one csect to another must be kept. The assembler
6704 will, of course, keep relocs between sections, and it will keep
6705 absolute relocs, but we need to force it to keep PC relative relocs
6706 between two csects in the same section. */
6707
6708 int
6709 ppc_force_relocation (fixS *fix)
6710 {
6711 /* At this point fix->fx_addsy should already have been converted to
6712 a csect symbol. If the csect does not include the fragment, then
6713 we need to force the relocation. */
6714 if (fix->fx_pcrel
6715 && fix->fx_addsy != NULL
6716 && symbol_get_tc (fix->fx_addsy)->subseg != 0
6717 && ((symbol_get_frag (fix->fx_addsy)->fr_address
6718 > fix->fx_frag->fr_address)
6719 || (symbol_get_tc (fix->fx_addsy)->next != NULL
6720 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
6721 <= fix->fx_frag->fr_address))))
6722 return 1;
6723
6724 return generic_force_reloc (fix);
6725 }
6726 #endif /* OBJ_XCOFF */
6727
6728 #ifdef OBJ_ELF
6729 /* If this function returns non-zero, it guarantees that a relocation
6730 will be emitted for a fixup. */
6731
6732 int
6733 ppc_force_relocation (fixS *fix)
6734 {
6735 /* Branch prediction relocations must force a relocation, as must
6736 the vtable description relocs. */
6737 switch (fix->fx_r_type)
6738 {
6739 case BFD_RELOC_PPC_B16_BRTAKEN:
6740 case BFD_RELOC_PPC_B16_BRNTAKEN:
6741 case BFD_RELOC_PPC_BA16_BRTAKEN:
6742 case BFD_RELOC_PPC_BA16_BRNTAKEN:
6743 case BFD_RELOC_24_PLT_PCREL:
6744 case BFD_RELOC_PPC64_TOC:
6745 return 1;
6746 case BFD_RELOC_PPC_B26:
6747 case BFD_RELOC_PPC_BA26:
6748 case BFD_RELOC_PPC_B16:
6749 case BFD_RELOC_PPC_BA16:
6750 case BFD_RELOC_PPC64_REL24_NOTOC:
6751 case BFD_RELOC_PPC64_REL24_P9NOTOC:
6752 /* All branch fixups targeting a localentry symbol must
6753 force a relocation. */
6754 if (fix->fx_addsy)
6755 {
6756 asymbol *bfdsym = symbol_get_bfdsym (fix->fx_addsy);
6757 elf_symbol_type *elfsym = elf_symbol_from (bfdsym);
6758 gas_assert (elfsym);
6759 if ((STO_PPC64_LOCAL_MASK & elfsym->internal_elf_sym.st_other) != 0)
6760 return 1;
6761 }
6762 break;
6763 default:
6764 break;
6765 }
6766
6767 if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
6768 && fix->fx_r_type <= BFD_RELOC_PPC64_TLS_PCREL)
6769 return 1;
6770
6771 return generic_force_reloc (fix);
6772 }
6773
6774 int
6775 ppc_fix_adjustable (fixS *fix)
6776 {
6777 switch (fix->fx_r_type)
6778 {
6779 /* All branch fixups targeting a localentry symbol must
6780 continue using the symbol. */
6781 case BFD_RELOC_PPC_B26:
6782 case BFD_RELOC_PPC_BA26:
6783 case BFD_RELOC_PPC_B16:
6784 case BFD_RELOC_PPC_BA16:
6785 case BFD_RELOC_PPC_B16_BRTAKEN:
6786 case BFD_RELOC_PPC_B16_BRNTAKEN:
6787 case BFD_RELOC_PPC_BA16_BRTAKEN:
6788 case BFD_RELOC_PPC_BA16_BRNTAKEN:
6789 case BFD_RELOC_PPC64_REL24_NOTOC:
6790 case BFD_RELOC_PPC64_REL24_P9NOTOC:
6791 if (fix->fx_addsy)
6792 {
6793 asymbol *bfdsym = symbol_get_bfdsym (fix->fx_addsy);
6794 elf_symbol_type *elfsym = elf_symbol_from (bfdsym);
6795 gas_assert (elfsym);
6796 if ((STO_PPC64_LOCAL_MASK & elfsym->internal_elf_sym.st_other) != 0)
6797 return 0;
6798 }
6799 break;
6800 default:
6801 break;
6802 }
6803
6804 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
6805 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
6806 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
6807 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
6808 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_DS
6809 && fix->fx_r_type != BFD_RELOC_PPC64_GOT16_LO_DS
6810 && fix->fx_r_type != BFD_RELOC_PPC64_GOT_PCREL34
6811 && fix->fx_r_type != BFD_RELOC_24_PLT_PCREL
6812 && fix->fx_r_type != BFD_RELOC_32_PLTOFF
6813 && fix->fx_r_type != BFD_RELOC_32_PLT_PCREL
6814 && fix->fx_r_type != BFD_RELOC_LO16_PLTOFF
6815 && fix->fx_r_type != BFD_RELOC_HI16_PLTOFF
6816 && fix->fx_r_type != BFD_RELOC_HI16_S_PLTOFF
6817 && fix->fx_r_type != BFD_RELOC_64_PLTOFF
6818 && fix->fx_r_type != BFD_RELOC_64_PLT_PCREL
6819 && fix->fx_r_type != BFD_RELOC_PPC64_PLT16_LO_DS
6820 && fix->fx_r_type != BFD_RELOC_PPC64_PLT_PCREL34
6821 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16
6822 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16_LO
6823 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16_HI
6824 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16_HA
6825 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16_DS
6826 && fix->fx_r_type != BFD_RELOC_PPC64_PLTGOT16_LO_DS
6827 && fix->fx_r_type != BFD_RELOC_GPREL16
6828 && fix->fx_r_type != BFD_RELOC_PPC_VLE_SDAREL_LO16A
6829 && fix->fx_r_type != BFD_RELOC_PPC_VLE_SDAREL_HI16A
6830 && fix->fx_r_type != BFD_RELOC_PPC_VLE_SDAREL_HA16A
6831 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
6832 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
6833 && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
6834 && fix->fx_r_type <= BFD_RELOC_PPC64_TLS_PCREL));
6835 }
6836 #endif
6837
6838 void
6839 ppc_frag_check (struct frag *fragP)
6840 {
6841 if ((fragP->fr_address & fragP->insn_addr) != 0)
6842 as_bad_where (fragP->fr_file, fragP->fr_line,
6843 _("instruction address is not a multiple of %d"),
6844 fragP->insn_addr + 1);
6845 }
6846
6847 /* rs_align_code frag handling. */
6848
6849 enum ppc_nop_encoding_for_rs_align_code
6850 {
6851 PPC_NOP_VANILLA,
6852 PPC_NOP_VLE,
6853 PPC_NOP_GROUP_P6,
6854 PPC_NOP_GROUP_P7
6855 };
6856
6857 unsigned int
6858 ppc_nop_select (void)
6859 {
6860 if ((ppc_cpu & PPC_OPCODE_VLE) != 0)
6861 return PPC_NOP_VLE;
6862 if ((ppc_cpu & (PPC_OPCODE_POWER9 | PPC_OPCODE_E500MC)) == 0)
6863 {
6864 if ((ppc_cpu & PPC_OPCODE_POWER7) != 0)
6865 return PPC_NOP_GROUP_P7;
6866 if ((ppc_cpu & PPC_OPCODE_POWER6) != 0)
6867 return PPC_NOP_GROUP_P6;
6868 }
6869 return PPC_NOP_VANILLA;
6870 }
6871
6872 void
6873 ppc_handle_align (struct frag *fragP)
6874 {
6875 valueT count = (fragP->fr_next->fr_address
6876 - (fragP->fr_address + fragP->fr_fix));
6877 char *dest = fragP->fr_literal + fragP->fr_fix;
6878 enum ppc_nop_encoding_for_rs_align_code nop_select = *dest & 0xff;
6879
6880 /* Pad with zeros if not inserting a whole number of instructions.
6881 We could pad with zeros up to an instruction boundary then follow
6882 with nops but odd counts indicate data in an executable section
6883 so padding with zeros is most appropriate. */
6884 if (count == 0
6885 || (nop_select == PPC_NOP_VLE ? (count & 1) != 0 : (count & 3) != 0))
6886 {
6887 *dest = 0;
6888 return;
6889 }
6890
6891 if (nop_select == PPC_NOP_VLE)
6892 {
6893
6894 fragP->fr_var = 2;
6895 md_number_to_chars (dest, 0x4400, 2);
6896 }
6897 else
6898 {
6899 fragP->fr_var = 4;
6900
6901 if (count > 4 * nop_limit && count < 0x2000000)
6902 {
6903 struct frag *rest;
6904
6905 /* Make a branch, then follow with nops. Insert another
6906 frag to handle the nops. */
6907 md_number_to_chars (dest, 0x48000000 + count, 4);
6908 count -= 4;
6909 if (count == 0)
6910 return;
6911
6912 rest = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6913 memcpy (rest, fragP, SIZEOF_STRUCT_FRAG);
6914 fragP->fr_next = rest;
6915 fragP = rest;
6916 rest->fr_address += rest->fr_fix + 4;
6917 rest->fr_fix = 0;
6918 /* If we leave the next frag as rs_align_code we'll come here
6919 again, resulting in a bunch of branches rather than a
6920 branch followed by nops. */
6921 rest->fr_type = rs_align;
6922 dest = rest->fr_literal;
6923 }
6924
6925 md_number_to_chars (dest, 0x60000000, 4);
6926
6927 if (nop_select >= PPC_NOP_GROUP_P6)
6928 {
6929 /* For power6, power7, and power8, we want the last nop to
6930 be a group terminating one. Do this by inserting an
6931 rs_fill frag immediately after this one, with its address
6932 set to the last nop location. This will automatically
6933 reduce the number of nops in the current frag by one. */
6934 if (count > 4)
6935 {
6936 struct frag *group_nop = xmalloc (SIZEOF_STRUCT_FRAG + 4);
6937
6938 memcpy (group_nop, fragP, SIZEOF_STRUCT_FRAG);
6939 group_nop->fr_address = group_nop->fr_next->fr_address - 4;
6940 group_nop->fr_fix = 0;
6941 group_nop->fr_offset = 1;
6942 group_nop->fr_type = rs_fill;
6943 fragP->fr_next = group_nop;
6944 dest = group_nop->fr_literal;
6945 }
6946
6947 if (nop_select == PPC_NOP_GROUP_P6)
6948 /* power6 group terminating nop: "ori 1,1,0". */
6949 md_number_to_chars (dest, 0x60210000, 4);
6950 else
6951 /* power7/power8 group terminating nop: "ori 2,2,0". */
6952 md_number_to_chars (dest, 0x60420000, 4);
6953 }
6954 }
6955 }
6956
6957 /* Apply a fixup to the object code. This is called for all the
6958 fixups we generated by the calls to fix_new_exp, above. */
6959
6960 void
6961 md_apply_fix (fixS *fixP, valueT *valP, segT seg)
6962 {
6963 valueT value = * valP;
6964 offsetT fieldval;
6965 const struct powerpc_operand *operand;
6966
6967 #ifdef OBJ_ELF
6968 if (fixP->fx_addsy != NULL)
6969 {
6970 /* Hack around bfd_install_relocation brain damage. */
6971 if (fixP->fx_pcrel)
6972 value += fixP->fx_frag->fr_address + fixP->fx_where;
6973
6974 if (fixP->fx_addsy == abs_section_sym)
6975 fixP->fx_done = 1;
6976 }
6977 else
6978 fixP->fx_done = 1;
6979 #else
6980 /* FIXME FIXME FIXME: The value we are passed in *valP includes
6981 the symbol values. If we are doing this relocation the code in
6982 write.c is going to call bfd_install_relocation, which is also
6983 going to use the symbol value. That means that if the reloc is
6984 fully resolved we want to use *valP since bfd_install_relocation is
6985 not being used.
6986 However, if the reloc is not fully resolved we do not want to
6987 use *valP, and must use fx_offset instead. If the relocation
6988 is PC-relative, we then need to re-apply md_pcrel_from_section
6989 to this new relocation value. */
6990 if (fixP->fx_addsy == (symbolS *) NULL)
6991 fixP->fx_done = 1;
6992
6993 else
6994 {
6995 value = fixP->fx_offset;
6996 if (fixP->fx_pcrel)
6997 value -= md_pcrel_from_section (fixP, seg);
6998 }
6999 #endif
7000
7001 /* We are only able to convert some relocs to pc-relative. */
7002 if (fixP->fx_pcrel)
7003 {
7004 switch (fixP->fx_r_type)
7005 {
7006 case BFD_RELOC_64:
7007 fixP->fx_r_type = BFD_RELOC_64_PCREL;
7008 break;
7009
7010 case BFD_RELOC_32:
7011 fixP->fx_r_type = BFD_RELOC_32_PCREL;
7012 break;
7013
7014 case BFD_RELOC_16:
7015 fixP->fx_r_type = BFD_RELOC_16_PCREL;
7016 break;
7017
7018 case BFD_RELOC_LO16:
7019 fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
7020 break;
7021
7022 case BFD_RELOC_HI16:
7023 fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
7024 break;
7025
7026 case BFD_RELOC_HI16_S:
7027 fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
7028 break;
7029
7030 case BFD_RELOC_PPC64_ADDR16_HIGH:
7031 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGH;
7032 break;
7033
7034 case BFD_RELOC_PPC64_ADDR16_HIGHA:
7035 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHA;
7036 break;
7037
7038 case BFD_RELOC_PPC64_HIGHER:
7039 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHER;
7040 break;
7041
7042 case BFD_RELOC_PPC64_HIGHER_S:
7043 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHERA;
7044 break;
7045
7046 case BFD_RELOC_PPC64_HIGHEST:
7047 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHEST;
7048 break;
7049
7050 case BFD_RELOC_PPC64_HIGHEST_S:
7051 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHESTA;
7052 break;
7053
7054 case BFD_RELOC_PPC64_ADDR16_HIGHER34:
7055 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHER34;
7056 break;
7057
7058 case BFD_RELOC_PPC64_ADDR16_HIGHERA34:
7059 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHERA34;
7060 break;
7061
7062 case BFD_RELOC_PPC64_ADDR16_HIGHEST34:
7063 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHEST34;
7064 break;
7065
7066 case BFD_RELOC_PPC64_ADDR16_HIGHESTA34:
7067 fixP->fx_r_type = BFD_RELOC_PPC64_REL16_HIGHESTA34;
7068 break;
7069
7070 case BFD_RELOC_PPC_16DX_HA:
7071 fixP->fx_r_type = BFD_RELOC_PPC_REL16DX_HA;
7072 break;
7073
7074 case BFD_RELOC_PPC64_D34:
7075 fixP->fx_r_type = BFD_RELOC_PPC64_PCREL34;
7076 break;
7077
7078 case BFD_RELOC_PPC64_D28:
7079 fixP->fx_r_type = BFD_RELOC_PPC64_PCREL28;
7080 break;
7081
7082 default:
7083 break;
7084 }
7085 }
7086 else if (!fixP->fx_done
7087 && fixP->fx_r_type == BFD_RELOC_PPC_16DX_HA)
7088 {
7089 /* addpcis is relative to next insn address. */
7090 value -= 4;
7091 fixP->fx_r_type = BFD_RELOC_PPC_REL16DX_HA;
7092 fixP->fx_pcrel = 1;
7093 }
7094
7095 operand = NULL;
7096 if (fixP->fx_pcrel_adjust != 0)
7097 {
7098 /* This is a fixup on an instruction. */
7099 int opindex = fixP->fx_pcrel_adjust & 0xff;
7100
7101 operand = &powerpc_operands[opindex];
7102 #ifdef OBJ_XCOFF
7103 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
7104 does not generate a reloc. It uses the offset of `sym' within its
7105 csect. Other usages, such as `.long sym', generate relocs. This
7106 is the documented behaviour of non-TOC symbols. */
7107 if ((operand->flags & PPC_OPERAND_PARENS) != 0
7108 && (operand->bitm & 0xfff0) == 0xfff0
7109 && operand->shift == 0
7110 && (operand->insert == NULL || ppc_obj64)
7111 && fixP->fx_addsy != NULL
7112 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
7113 && !ppc_is_toc_sym (fixP->fx_addsy)
7114 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
7115 {
7116 value = fixP->fx_offset;
7117 fixP->fx_done = 1;
7118 }
7119
7120 /* During parsing of instructions, a TOC16 reloc is generated for
7121 instructions such as 'lwz RT,SYM(RB)' if SYM is a symbol defined
7122 in the toc. But at parse time, SYM may be not yet defined, so
7123 check again here. */
7124 if (fixP->fx_r_type == BFD_RELOC_16
7125 && fixP->fx_addsy != NULL
7126 && ppc_is_toc_sym (fixP->fx_addsy))
7127 fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
7128 #endif
7129 }
7130
7131 /* Calculate value to be stored in field. */
7132 fieldval = value;
7133 switch (fixP->fx_r_type)
7134 {
7135 #ifdef OBJ_ELF
7136 case BFD_RELOC_PPC64_ADDR16_LO_DS:
7137 case BFD_RELOC_PPC_VLE_LO16A:
7138 case BFD_RELOC_PPC_VLE_LO16D:
7139 #endif
7140 case BFD_RELOC_LO16:
7141 case BFD_RELOC_LO16_PCREL:
7142 fieldval = value & 0xffff;
7143 sign_extend_16:
7144 if (operand != NULL && (operand->flags & PPC_OPERAND_SIGNED) != 0)
7145 fieldval = SEX16 (fieldval);
7146 fixP->fx_no_overflow = 1;
7147 break;
7148
7149 case BFD_RELOC_HI16:
7150 case BFD_RELOC_HI16_PCREL:
7151 #ifdef OBJ_ELF
7152 if (REPORT_OVERFLOW_HI && ppc_obj64)
7153 {
7154 fieldval = value >> 16;
7155 if (operand != NULL && (operand->flags & PPC_OPERAND_SIGNED) != 0)
7156 {
7157 valueT sign = (((valueT) -1 >> 16) + 1) >> 1;
7158 fieldval = ((valueT) fieldval ^ sign) - sign;
7159 }
7160 break;
7161 }
7162 /* Fallthru */
7163
7164 case BFD_RELOC_PPC_VLE_HI16A:
7165 case BFD_RELOC_PPC_VLE_HI16D:
7166 case BFD_RELOC_PPC64_ADDR16_HIGH:
7167 #endif
7168 fieldval = PPC_HI (value);
7169 goto sign_extend_16;
7170
7171 case BFD_RELOC_HI16_S:
7172 case BFD_RELOC_HI16_S_PCREL:
7173 case BFD_RELOC_PPC_16DX_HA:
7174 case BFD_RELOC_PPC_REL16DX_HA:
7175 #ifdef OBJ_ELF
7176 if (REPORT_OVERFLOW_HI && ppc_obj64)
7177 {
7178 fieldval = (value + 0x8000) >> 16;
7179 if (operand != NULL && (operand->flags & PPC_OPERAND_SIGNED) != 0)
7180 {
7181 valueT sign = (((valueT) -1 >> 16) + 1) >> 1;
7182 fieldval = ((valueT) fieldval ^ sign) - sign;
7183 }
7184 break;
7185 }
7186 /* Fallthru */
7187
7188 case BFD_RELOC_PPC_VLE_HA16A:
7189 case BFD_RELOC_PPC_VLE_HA16D:
7190 case BFD_RELOC_PPC64_ADDR16_HIGHA:
7191 #endif
7192 fieldval = PPC_HA (value);
7193 goto sign_extend_16;
7194
7195 #ifdef OBJ_ELF
7196 case BFD_RELOC_PPC64_HIGHER:
7197 fieldval = PPC_HIGHER (value);
7198 goto sign_extend_16;
7199
7200 case BFD_RELOC_PPC64_HIGHER_S:
7201 fieldval = PPC_HIGHERA (value);
7202 goto sign_extend_16;
7203
7204 case BFD_RELOC_PPC64_HIGHEST:
7205 fieldval = PPC_HIGHEST (value);
7206 goto sign_extend_16;
7207
7208 case BFD_RELOC_PPC64_HIGHEST_S:
7209 fieldval = PPC_HIGHESTA (value);
7210 goto sign_extend_16;
7211 #endif
7212
7213 default:
7214 break;
7215 }
7216
7217 if (operand != NULL)
7218 {
7219 /* Handle relocs in an insn. */
7220 switch (fixP->fx_r_type)
7221 {
7222 #ifdef OBJ_ELF
7223 /* The following relocs can't be calculated by the assembler.
7224 Leave the field zero. */
7225 case BFD_RELOC_PPC_TPREL16:
7226 case BFD_RELOC_PPC_TPREL16_LO:
7227 case BFD_RELOC_PPC_TPREL16_HI:
7228 case BFD_RELOC_PPC_TPREL16_HA:
7229 case BFD_RELOC_PPC_DTPREL16:
7230 case BFD_RELOC_PPC_DTPREL16_LO:
7231 case BFD_RELOC_PPC_DTPREL16_HI:
7232 case BFD_RELOC_PPC_DTPREL16_HA:
7233 case BFD_RELOC_PPC_GOT_TLSGD16:
7234 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
7235 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
7236 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
7237 case BFD_RELOC_PPC_GOT_TLSLD16:
7238 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
7239 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
7240 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
7241 case BFD_RELOC_PPC_GOT_TPREL16:
7242 case BFD_RELOC_PPC_GOT_TPREL16_LO:
7243 case BFD_RELOC_PPC_GOT_TPREL16_HI:
7244 case BFD_RELOC_PPC_GOT_TPREL16_HA:
7245 case BFD_RELOC_PPC_GOT_DTPREL16:
7246 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
7247 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
7248 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
7249 case BFD_RELOC_PPC64_TPREL16_DS:
7250 case BFD_RELOC_PPC64_TPREL16_LO_DS:
7251 case BFD_RELOC_PPC64_TPREL16_HIGH:
7252 case BFD_RELOC_PPC64_TPREL16_HIGHA:
7253 case BFD_RELOC_PPC64_TPREL16_HIGHER:
7254 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
7255 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
7256 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
7257 case BFD_RELOC_PPC64_DTPREL16_HIGH:
7258 case BFD_RELOC_PPC64_DTPREL16_HIGHA:
7259 case BFD_RELOC_PPC64_DTPREL16_DS:
7260 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
7261 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
7262 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
7263 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
7264 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
7265 case BFD_RELOC_PPC64_TPREL34:
7266 case BFD_RELOC_PPC64_DTPREL34:
7267 case BFD_RELOC_PPC64_GOT_TLSGD_PCREL34:
7268 case BFD_RELOC_PPC64_GOT_TLSLD_PCREL34:
7269 case BFD_RELOC_PPC64_GOT_TPREL_PCREL34:
7270 case BFD_RELOC_PPC64_GOT_DTPREL_PCREL34:
7271 gas_assert (fixP->fx_addsy != NULL);
7272 S_SET_THREAD_LOCAL (fixP->fx_addsy);
7273 fieldval = 0;
7274 break;
7275
7276 /* These also should leave the field zero for the same
7277 reason. Note that older versions of gas wrote values
7278 here. If we want to go back to the old behaviour, then
7279 all _LO and _LO_DS cases will need to be treated like
7280 BFD_RELOC_LO16_PCREL above. Similarly for _HI etc. */
7281 case BFD_RELOC_16_GOTOFF:
7282 case BFD_RELOC_LO16_GOTOFF:
7283 case BFD_RELOC_HI16_GOTOFF:
7284 case BFD_RELOC_HI16_S_GOTOFF:
7285 case BFD_RELOC_LO16_PLTOFF:
7286 case BFD_RELOC_HI16_PLTOFF:
7287 case BFD_RELOC_HI16_S_PLTOFF:
7288 case BFD_RELOC_GPREL16:
7289 case BFD_RELOC_16_BASEREL:
7290 case BFD_RELOC_LO16_BASEREL:
7291 case BFD_RELOC_HI16_BASEREL:
7292 case BFD_RELOC_HI16_S_BASEREL:
7293 case BFD_RELOC_PPC_TOC16:
7294 case BFD_RELOC_PPC64_TOC16_LO:
7295 case BFD_RELOC_PPC64_TOC16_HI:
7296 case BFD_RELOC_PPC64_TOC16_HA:
7297 case BFD_RELOC_PPC64_PLTGOT16:
7298 case BFD_RELOC_PPC64_PLTGOT16_LO:
7299 case BFD_RELOC_PPC64_PLTGOT16_HI:
7300 case BFD_RELOC_PPC64_PLTGOT16_HA:
7301 case BFD_RELOC_PPC64_GOT16_DS:
7302 case BFD_RELOC_PPC64_GOT16_LO_DS:
7303 case BFD_RELOC_PPC64_PLT16_LO_DS:
7304 case BFD_RELOC_PPC64_SECTOFF_DS:
7305 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
7306 case BFD_RELOC_PPC64_TOC16_DS:
7307 case BFD_RELOC_PPC64_TOC16_LO_DS:
7308 case BFD_RELOC_PPC64_PLTGOT16_DS:
7309 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
7310 case BFD_RELOC_PPC_EMB_NADDR16:
7311 case BFD_RELOC_PPC_EMB_NADDR16_LO:
7312 case BFD_RELOC_PPC_EMB_NADDR16_HI:
7313 case BFD_RELOC_PPC_EMB_NADDR16_HA:
7314 case BFD_RELOC_PPC_EMB_SDAI16:
7315 case BFD_RELOC_PPC_EMB_SDA2I16:
7316 case BFD_RELOC_PPC_EMB_SDA2REL:
7317 case BFD_RELOC_PPC_EMB_SDA21:
7318 case BFD_RELOC_PPC_EMB_MRKREF:
7319 case BFD_RELOC_PPC_EMB_RELSEC16:
7320 case BFD_RELOC_PPC_EMB_RELST_LO:
7321 case BFD_RELOC_PPC_EMB_RELST_HI:
7322 case BFD_RELOC_PPC_EMB_RELST_HA:
7323 case BFD_RELOC_PPC_EMB_BIT_FLD:
7324 case BFD_RELOC_PPC_EMB_RELSDA:
7325 case BFD_RELOC_PPC_VLE_SDA21:
7326 case BFD_RELOC_PPC_VLE_SDA21_LO:
7327 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
7328 case BFD_RELOC_PPC_VLE_SDAREL_LO16D:
7329 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
7330 case BFD_RELOC_PPC_VLE_SDAREL_HI16D:
7331 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
7332 case BFD_RELOC_PPC_VLE_SDAREL_HA16D:
7333 case BFD_RELOC_PPC64_GOT_PCREL34:
7334 case BFD_RELOC_PPC64_PLT_PCREL34:
7335 gas_assert (fixP->fx_addsy != NULL);
7336 /* Fallthru */
7337
7338 case BFD_RELOC_PPC_TLS:
7339 case BFD_RELOC_PPC_TLSGD:
7340 case BFD_RELOC_PPC_TLSLD:
7341 case BFD_RELOC_PPC64_TLS_PCREL:
7342 fieldval = 0;
7343 break;
7344 #endif
7345
7346 #ifdef OBJ_XCOFF
7347 case BFD_RELOC_PPC_B16:
7348 /* Adjust the offset to the instruction boundary. */
7349 fieldval += 2;
7350 break;
7351 #endif
7352
7353 case BFD_RELOC_VTABLE_INHERIT:
7354 case BFD_RELOC_VTABLE_ENTRY:
7355 case BFD_RELOC_PPC_DTPMOD:
7356 case BFD_RELOC_PPC_TPREL:
7357 case BFD_RELOC_PPC_DTPREL:
7358 case BFD_RELOC_PPC_COPY:
7359 case BFD_RELOC_PPC_GLOB_DAT:
7360 case BFD_RELOC_32_PLT_PCREL:
7361 case BFD_RELOC_PPC_EMB_NADDR32:
7362 case BFD_RELOC_PPC64_TOC:
7363 case BFD_RELOC_CTOR:
7364 case BFD_RELOC_32:
7365 case BFD_RELOC_32_PCREL:
7366 case BFD_RELOC_RVA:
7367 case BFD_RELOC_64:
7368 case BFD_RELOC_64_PCREL:
7369 case BFD_RELOC_PPC64_ADDR64_LOCAL:
7370 as_bad_where (fixP->fx_file, fixP->fx_line,
7371 _("%s unsupported as instruction fixup"),
7372 bfd_get_reloc_code_name (fixP->fx_r_type));
7373 fixP->fx_done = 1;
7374 return;
7375
7376 default:
7377 break;
7378 }
7379
7380 #ifdef OBJ_ELF
7381 /* powerpc uses RELA style relocs, so if emitting a reloc the field
7382 contents can stay at zero. */
7383 #define APPLY_RELOC fixP->fx_done
7384 #else
7385 #define APPLY_RELOC 1
7386 #endif
7387 /* We need to call the insert function even when fieldval is
7388 zero if the insert function would translate that zero to a
7389 bit pattern other than all zeros. */
7390 if ((fieldval != 0 && APPLY_RELOC) || operand->insert != NULL)
7391 {
7392 uint64_t insn;
7393 unsigned char *where;
7394
7395 /* Fetch the instruction, insert the fully resolved operand
7396 value, and stuff the instruction back again. */
7397 where = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
7398 if (target_big_endian)
7399 {
7400 if (fixP->fx_size < 4)
7401 insn = bfd_getb16 (where);
7402 else
7403 {
7404 insn = bfd_getb32 (where);
7405 if (fixP->fx_size > 4)
7406 insn = insn << 32 | bfd_getb32 (where + 4);
7407 }
7408 }
7409 else
7410 {
7411 if (fixP->fx_size < 4)
7412 insn = bfd_getl16 (where);
7413 else
7414 {
7415 insn = bfd_getl32 (where);
7416 if (fixP->fx_size > 4)
7417 insn = insn << 32 | bfd_getl32 (where + 4);
7418 }
7419 }
7420 insn = ppc_insert_operand (insn, operand, fieldval,
7421 fixP->tc_fix_data.ppc_cpu,
7422 fixP->fx_file, fixP->fx_line);
7423 if (target_big_endian)
7424 {
7425 if (fixP->fx_size < 4)
7426 bfd_putb16 (insn, where);
7427 else
7428 {
7429 if (fixP->fx_size > 4)
7430 {
7431 bfd_putb32 (insn, where + 4);
7432 insn >>= 32;
7433 }
7434 bfd_putb32 (insn, where);
7435 }
7436 }
7437 else
7438 {
7439 if (fixP->fx_size < 4)
7440 bfd_putl16 (insn, where);
7441 else
7442 {
7443 if (fixP->fx_size > 4)
7444 {
7445 bfd_putl32 (insn, where + 4);
7446 insn >>= 32;
7447 }
7448 bfd_putl32 (insn, where);
7449 }
7450 }
7451 }
7452
7453 if (fixP->fx_done)
7454 /* Nothing else to do here. */
7455 return;
7456
7457 gas_assert (fixP->fx_addsy != NULL);
7458 if (fixP->fx_r_type == BFD_RELOC_NONE)
7459 {
7460 const char *sfile;
7461 unsigned int sline;
7462
7463 /* Use expr_symbol_where to see if this is an expression
7464 symbol. */
7465 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
7466 as_bad_where (fixP->fx_file, fixP->fx_line,
7467 _("unresolved expression that must be resolved"));
7468 else
7469 as_bad_where (fixP->fx_file, fixP->fx_line,
7470 _("unsupported relocation against %s"),
7471 S_GET_NAME (fixP->fx_addsy));
7472 fixP->fx_done = 1;
7473 return;
7474 }
7475 }
7476 else
7477 {
7478 /* Handle relocs in data. */
7479 switch (fixP->fx_r_type)
7480 {
7481 case BFD_RELOC_VTABLE_INHERIT:
7482 if (fixP->fx_addsy
7483 && !S_IS_DEFINED (fixP->fx_addsy)
7484 && !S_IS_WEAK (fixP->fx_addsy))
7485 S_SET_WEAK (fixP->fx_addsy);
7486 /* Fallthru */
7487
7488 case BFD_RELOC_VTABLE_ENTRY:
7489 fixP->fx_done = 0;
7490 break;
7491
7492 #ifdef OBJ_ELF
7493 /* These can appear with @l etc. in data. */
7494 case BFD_RELOC_LO16:
7495 case BFD_RELOC_LO16_PCREL:
7496 case BFD_RELOC_HI16:
7497 case BFD_RELOC_HI16_PCREL:
7498 case BFD_RELOC_HI16_S:
7499 case BFD_RELOC_HI16_S_PCREL:
7500 case BFD_RELOC_PPC64_HIGHER:
7501 case BFD_RELOC_PPC64_HIGHER_S:
7502 case BFD_RELOC_PPC64_HIGHEST:
7503 case BFD_RELOC_PPC64_HIGHEST_S:
7504 case BFD_RELOC_PPC64_ADDR16_HIGH:
7505 case BFD_RELOC_PPC64_ADDR16_HIGHA:
7506 case BFD_RELOC_PPC64_ADDR64_LOCAL:
7507 break;
7508
7509 case BFD_RELOC_PPC_DTPMOD:
7510 case BFD_RELOC_PPC_TPREL:
7511 case BFD_RELOC_PPC_DTPREL:
7512 S_SET_THREAD_LOCAL (fixP->fx_addsy);
7513 break;
7514
7515 /* Just punt all of these to the linker. */
7516 case BFD_RELOC_PPC_B16_BRTAKEN:
7517 case BFD_RELOC_PPC_B16_BRNTAKEN:
7518 case BFD_RELOC_16_GOTOFF:
7519 case BFD_RELOC_LO16_GOTOFF:
7520 case BFD_RELOC_HI16_GOTOFF:
7521 case BFD_RELOC_HI16_S_GOTOFF:
7522 case BFD_RELOC_LO16_PLTOFF:
7523 case BFD_RELOC_HI16_PLTOFF:
7524 case BFD_RELOC_HI16_S_PLTOFF:
7525 case BFD_RELOC_PPC_COPY:
7526 case BFD_RELOC_PPC_GLOB_DAT:
7527 case BFD_RELOC_16_BASEREL:
7528 case BFD_RELOC_LO16_BASEREL:
7529 case BFD_RELOC_HI16_BASEREL:
7530 case BFD_RELOC_HI16_S_BASEREL:
7531 case BFD_RELOC_PPC_TLS:
7532 case BFD_RELOC_PPC_DTPREL16_LO:
7533 case BFD_RELOC_PPC_DTPREL16_HI:
7534 case BFD_RELOC_PPC_DTPREL16_HA:
7535 case BFD_RELOC_PPC_TPREL16_LO:
7536 case BFD_RELOC_PPC_TPREL16_HI:
7537 case BFD_RELOC_PPC_TPREL16_HA:
7538 case BFD_RELOC_PPC_GOT_TLSGD16:
7539 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
7540 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
7541 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
7542 case BFD_RELOC_PPC_GOT_TLSLD16:
7543 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
7544 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
7545 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
7546 case BFD_RELOC_PPC_GOT_DTPREL16:
7547 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
7548 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
7549 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
7550 case BFD_RELOC_PPC_GOT_TPREL16:
7551 case BFD_RELOC_PPC_GOT_TPREL16_LO:
7552 case BFD_RELOC_PPC_GOT_TPREL16_HI:
7553 case BFD_RELOC_PPC_GOT_TPREL16_HA:
7554 case BFD_RELOC_24_PLT_PCREL:
7555 case BFD_RELOC_PPC_LOCAL24PC:
7556 case BFD_RELOC_32_PLT_PCREL:
7557 case BFD_RELOC_GPREL16:
7558 case BFD_RELOC_PPC_VLE_SDAREL_LO16A:
7559 case BFD_RELOC_PPC_VLE_SDAREL_HI16A:
7560 case BFD_RELOC_PPC_VLE_SDAREL_HA16A:
7561 case BFD_RELOC_PPC_EMB_NADDR32:
7562 case BFD_RELOC_PPC_EMB_NADDR16:
7563 case BFD_RELOC_PPC_EMB_NADDR16_LO:
7564 case BFD_RELOC_PPC_EMB_NADDR16_HI:
7565 case BFD_RELOC_PPC_EMB_NADDR16_HA:
7566 case BFD_RELOC_PPC_EMB_SDAI16:
7567 case BFD_RELOC_PPC_EMB_SDA2REL:
7568 case BFD_RELOC_PPC_EMB_SDA2I16:
7569 case BFD_RELOC_PPC_EMB_SDA21:
7570 case BFD_RELOC_PPC_VLE_SDA21_LO:
7571 case BFD_RELOC_PPC_EMB_MRKREF:
7572 case BFD_RELOC_PPC_EMB_RELSEC16:
7573 case BFD_RELOC_PPC_EMB_RELST_LO:
7574 case BFD_RELOC_PPC_EMB_RELST_HI:
7575 case BFD_RELOC_PPC_EMB_RELST_HA:
7576 case BFD_RELOC_PPC_EMB_BIT_FLD:
7577 case BFD_RELOC_PPC_EMB_RELSDA:
7578 case BFD_RELOC_PPC64_TOC:
7579 case BFD_RELOC_PPC_TOC16:
7580 case BFD_RELOC_PPC_TOC16_LO:
7581 case BFD_RELOC_PPC_TOC16_HI:
7582 case BFD_RELOC_PPC64_TOC16_LO:
7583 case BFD_RELOC_PPC64_TOC16_HI:
7584 case BFD_RELOC_PPC64_TOC16_HA:
7585 case BFD_RELOC_PPC64_DTPREL16_HIGH:
7586 case BFD_RELOC_PPC64_DTPREL16_HIGHA:
7587 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
7588 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
7589 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
7590 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
7591 case BFD_RELOC_PPC64_TPREL16_HIGH:
7592 case BFD_RELOC_PPC64_TPREL16_HIGHA:
7593 case BFD_RELOC_PPC64_TPREL16_HIGHER:
7594 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
7595 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
7596 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
7597 case BFD_RELOC_PPC64_TLS_PCREL:
7598 fixP->fx_done = 0;
7599 break;
7600 #endif
7601
7602 #ifdef OBJ_XCOFF
7603 case BFD_RELOC_PPC_TLSGD:
7604 case BFD_RELOC_PPC_TLSLD:
7605 case BFD_RELOC_PPC_TLSLE:
7606 case BFD_RELOC_PPC_TLSIE:
7607 case BFD_RELOC_PPC_TLSM:
7608 case BFD_RELOC_PPC64_TLSGD:
7609 case BFD_RELOC_PPC64_TLSLD:
7610 case BFD_RELOC_PPC64_TLSLE:
7611 case BFD_RELOC_PPC64_TLSIE:
7612 case BFD_RELOC_PPC64_TLSM:
7613 gas_assert (fixP->fx_addsy != NULL);
7614 S_SET_THREAD_LOCAL (fixP->fx_addsy);
7615 break;
7616
7617 /* Officially, R_TLSML relocations must be from a TOC entry
7618 targeting itself. In practice, this TOC entry is always
7619 named (or .rename) "_$TLSML".
7620 Thus, as it doesn't seem possible to retrieve the symbol
7621 being relocated here, we simply check that the symbol
7622 targeted by R_TLSML is indeed a TOC entry named "_$TLSML".
7623 FIXME: Find a way to correctly check R_TLSML relocations
7624 as described above. */
7625 case BFD_RELOC_PPC_TLSML:
7626 case BFD_RELOC_PPC64_TLSML:
7627 gas_assert (fixP->fx_addsy != NULL);
7628 if ((symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC
7629 || symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TE)
7630 && strcmp (symbol_get_tc (fixP->fx_addsy)->real_name, "_$TLSML") != 0)
7631 as_bad_where (fixP->fx_file, fixP->fx_line,
7632 _("R_TLSML relocation doesn't target a "
7633 "TOC entry named \"_$TLSML\": %s"), S_GET_NAME(fixP->fx_addsy));
7634 fieldval = 0;
7635 break;
7636
7637 case BFD_RELOC_NONE:
7638 #endif
7639 case BFD_RELOC_CTOR:
7640 case BFD_RELOC_32:
7641 case BFD_RELOC_32_PCREL:
7642 case BFD_RELOC_RVA:
7643 case BFD_RELOC_64:
7644 case BFD_RELOC_64_PCREL:
7645 case BFD_RELOC_16:
7646 case BFD_RELOC_16_PCREL:
7647 case BFD_RELOC_8:
7648 break;
7649
7650 default:
7651 fprintf (stderr,
7652 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
7653 fflush (stderr);
7654 abort ();
7655 }
7656
7657 if (fixP->fx_size && APPLY_RELOC)
7658 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
7659 fieldval, fixP->fx_size);
7660 if (warn_476
7661 && (seg->flags & SEC_CODE) != 0
7662 && fixP->fx_size == 4
7663 && fixP->fx_done
7664 && !fixP->fx_tcbit
7665 && (fixP->fx_r_type == BFD_RELOC_32
7666 || fixP->fx_r_type == BFD_RELOC_CTOR
7667 || fixP->fx_r_type == BFD_RELOC_32_PCREL))
7668 as_warn_where (fixP->fx_file, fixP->fx_line,
7669 _("data in executable section"));
7670 }
7671
7672 #ifdef OBJ_ELF
7673 ppc_elf_validate_fix (fixP, seg);
7674 fixP->fx_addnumber = value;
7675
7676 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
7677 from the section contents. If we are going to be emitting a reloc
7678 then the section contents are immaterial, so don't warn if they
7679 happen to overflow. Leave such warnings to ld. */
7680 if (!fixP->fx_done)
7681 {
7682 fixP->fx_no_overflow = 1;
7683
7684 /* Arrange to emit .TOC. as a normal symbol if used in anything
7685 but .TOC.@tocbase. */
7686 if (ppc_obj64
7687 && fixP->fx_r_type != BFD_RELOC_PPC64_TOC
7688 && fixP->fx_addsy != NULL
7689 && strcmp (S_GET_NAME (fixP->fx_addsy), ".TOC.") == 0)
7690 symbol_get_bfdsym (fixP->fx_addsy)->flags |= BSF_KEEP;
7691 }
7692 #else
7693 if (fixP->fx_r_type == BFD_RELOC_PPC_TOC16
7694 || fixP->fx_r_type == BFD_RELOC_PPC_TOC16_HI
7695 || fixP->fx_r_type == BFD_RELOC_PPC_TOC16_LO)
7696 {
7697 /* We want to use the offset within the toc, not the actual VMA
7698 of the symbol. */
7699 fixP->fx_addnumber = (- bfd_section_vma (S_GET_SEGMENT (fixP->fx_addsy))
7700 - S_GET_VALUE (ppc_toc_csect));
7701
7702 /* The high bits must be adjusted for the low bits being signed. */
7703 if (fixP->fx_r_type == BFD_RELOC_PPC_TOC16_HI) {
7704 fixP->fx_addnumber += 0x8000;
7705 }
7706
7707 /* Set *valP to avoid errors. */
7708 *valP = value;
7709 }
7710 else if (fixP->fx_r_type == BFD_RELOC_PPC_TLSM
7711 || fixP->fx_r_type == BFD_RELOC_PPC64_TLSM
7712 || fixP->fx_r_type == BFD_RELOC_PPC_TLSML
7713 || fixP->fx_r_type == BFD_RELOC_PPC64_TLSML)
7714 /* AIX ld expects the section contents for these relocations
7715 to be zero. Arrange for that to occur when
7716 bfd_install_relocation is called. */
7717 fixP->fx_addnumber = (- bfd_section_vma (S_GET_SEGMENT (fixP->fx_addsy))
7718 - S_GET_VALUE (fixP->fx_addsy)
7719 - fieldval);
7720 else
7721 fixP->fx_addnumber = 0;
7722 #endif
7723 }
7724
7725 /* Generate a reloc for a fixup. */
7726
7727 arelent **
7728 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
7729 {
7730 static arelent *relocs[3];
7731 arelent *reloc;
7732
7733 relocs[0] = reloc = XNEW (arelent);
7734 relocs[1] = NULL;
7735
7736 reloc->sym_ptr_ptr = XNEW (asymbol *);
7737 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
7738 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
7739 /* BFD_RELOC_PPC64_TLS_PCREL generates R_PPC64_TLS with an odd r_offset. */
7740 if (fixp->fx_r_type == BFD_RELOC_PPC64_TLS_PCREL)
7741 reloc->address++;
7742 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
7743 if (reloc->howto == (reloc_howto_type *) NULL)
7744 {
7745 as_bad_where (fixp->fx_file, fixp->fx_line,
7746 _("reloc %d not supported by object file format"),
7747 (int) fixp->fx_r_type);
7748 relocs[0] = NULL;
7749 }
7750 reloc->addend = fixp->fx_addnumber;
7751
7752 if (fixp->fx_subsy != NULL)
7753 {
7754 relocs[1] = reloc = XNEW (arelent);
7755 relocs[2] = NULL;
7756
7757 reloc->sym_ptr_ptr = XNEW (asymbol *);
7758 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
7759 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
7760
7761 reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_PPC_NEG);
7762 reloc->addend = fixp->fx_addnumber;
7763
7764 if (reloc->howto == (reloc_howto_type *) NULL)
7765 {
7766 as_bad_subtract (fixp);
7767 free (relocs[1]->sym_ptr_ptr);
7768 free (relocs[1]);
7769 free (relocs[0]->sym_ptr_ptr);
7770 free (relocs[0]);
7771 relocs[0] = NULL;
7772 }
7773 }
7774
7775
7776 return relocs;
7777 }
7778
7779 void
7780 ppc_cfi_frame_initial_instructions (void)
7781 {
7782 cfi_add_CFA_def_cfa (1, 0);
7783 }
7784
7785 int
7786 tc_ppc_regname_to_dw2regnum (char *regname)
7787 {
7788 unsigned int regnum = -1;
7789 unsigned int i;
7790 const char *p;
7791 char *q;
7792 static struct { const char *name; int dw2regnum; } regnames[] =
7793 {
7794 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
7795 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
7796 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
7797 { "spe_acc", 111 }, { "spefscr", 112 }
7798 };
7799
7800 for (i = 0; i < ARRAY_SIZE (regnames); ++i)
7801 if (strcmp (regnames[i].name, regname) == 0)
7802 return regnames[i].dw2regnum;
7803
7804 if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
7805 {
7806 p = regname + 1 + (regname[1] == '.');
7807 regnum = strtoul (p, &q, 10);
7808 if (p == q || *q || regnum >= 32)
7809 return -1;
7810 if (regname[0] == 'f')
7811 regnum += 32;
7812 else if (regname[0] == 'v')
7813 regnum += 77;
7814 }
7815 else if (regname[0] == 'c' && regname[1] == 'r')
7816 {
7817 p = regname + 2 + (regname[2] == '.');
7818 if (p[0] < '0' || p[0] > '7' || p[1])
7819 return -1;
7820 regnum = p[0] - '0' + 68;
7821 }
7822 return regnum;
7823 }