* config/tc-ppc.c (mapping): Map sectoff to BFD_RELOC_16_BASEREL.
[deliverable/binutils-gdb.git] / gas / config / tc-ppc.c
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 #include <stdio.h>
24 #include "as.h"
25 #include "safe-ctype.h"
26 #include "subsegs.h"
27
28 #include "opcode/ppc.h"
29
30 #ifdef OBJ_ELF
31 #include "elf/ppc.h"
32 #include "dwarf2dbg.h"
33 #endif
34
35 #ifdef TE_PE
36 #include "coff/pe.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 #ifdef TE_PE
50 #define TARGET_REG_NAMES_P true
51 #else
52 #define TARGET_REG_NAMES_P false
53 #endif
54 #endif
55
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
57 HIGHESTA. */
58
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
61
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
64
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
67 signed number. */
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
69
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
72
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
76
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff)
79
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
83
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
85
86 static boolean reg_names_p = TARGET_REG_NAMES_P;
87
88 static boolean register_name PARAMS ((expressionS *));
89 static void ppc_set_cpu PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
92 offsetT val, char *file, unsigned int line));
93 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
94 static void ppc_byte PARAMS ((int));
95
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
98 static void ppc_tc PARAMS ((int));
99 static void ppc_machine PARAMS ((int));
100 #endif
101
102 #ifdef OBJ_XCOFF
103 static void ppc_comm PARAMS ((int));
104 static void ppc_bb PARAMS ((int));
105 static void ppc_bc PARAMS ((int));
106 static void ppc_bf PARAMS ((int));
107 static void ppc_biei PARAMS ((int));
108 static void ppc_bs PARAMS ((int));
109 static void ppc_eb PARAMS ((int));
110 static void ppc_ec PARAMS ((int));
111 static void ppc_ef PARAMS ((int));
112 static void ppc_es PARAMS ((int));
113 static void ppc_csect PARAMS ((int));
114 static void ppc_change_csect PARAMS ((symbolS *));
115 static void ppc_function PARAMS ((int));
116 static void ppc_extern PARAMS ((int));
117 static void ppc_lglobl PARAMS ((int));
118 static void ppc_section PARAMS ((int));
119 static void ppc_named_section PARAMS ((int));
120 static void ppc_stabx PARAMS ((int));
121 static void ppc_rename PARAMS ((int));
122 static void ppc_toc PARAMS ((int));
123 static void ppc_xcoff_cons PARAMS ((int));
124 static void ppc_vbyte PARAMS ((int));
125 #endif
126
127 #ifdef OBJ_ELF
128 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
129 static void ppc_elf_cons PARAMS ((int));
130 static void ppc_elf_rdata PARAMS ((int));
131 static void ppc_elf_lcomm PARAMS ((int));
132 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
133 #endif
134
135 #ifdef TE_PE
136 static void ppc_set_current_section PARAMS ((segT));
137 static void ppc_previous PARAMS ((int));
138 static void ppc_pdata PARAMS ((int));
139 static void ppc_ydata PARAMS ((int));
140 static void ppc_reldata PARAMS ((int));
141 static void ppc_rdata PARAMS ((int));
142 static void ppc_ualong PARAMS ((int));
143 static void ppc_znop PARAMS ((int));
144 static void ppc_pe_comm PARAMS ((int));
145 static void ppc_pe_section PARAMS ((int));
146 static void ppc_pe_function PARAMS ((int));
147 static void ppc_pe_tocd PARAMS ((int));
148 #endif
149 \f
150 /* Generic assembler global variables which must be defined by all
151 targets. */
152
153 #ifdef OBJ_ELF
154 /* This string holds the chars that always start a comment. If the
155 pre-processor is disabled, these aren't very useful. The macro
156 tc_comment_chars points to this. We use this, rather than the
157 usual comment_chars, so that we can switch for Solaris conventions. */
158 static const char ppc_solaris_comment_chars[] = "#!";
159 static const char ppc_eabi_comment_chars[] = "#";
160
161 #ifdef TARGET_SOLARIS_COMMENT
162 const char *ppc_comment_chars = ppc_solaris_comment_chars;
163 #else
164 const char *ppc_comment_chars = ppc_eabi_comment_chars;
165 #endif
166 #else
167 const char comment_chars[] = "#";
168 #endif
169
170 /* Characters which start a comment at the beginning of a line. */
171 const char line_comment_chars[] = "#";
172
173 /* Characters which may be used to separate multiple commands on a
174 single line. */
175 const char line_separator_chars[] = ";";
176
177 /* Characters which are used to indicate an exponent in a floating
178 point number. */
179 const char EXP_CHARS[] = "eE";
180
181 /* Characters which mean that a number is a floating point constant,
182 as in 0d1.0. */
183 const char FLT_CHARS[] = "dD";
184 \f
185 /* The target specific pseudo-ops which we support. */
186
187 const pseudo_typeS md_pseudo_table[] =
188 {
189 /* Pseudo-ops which must be overridden. */
190 { "byte", ppc_byte, 0 },
191
192 #ifdef OBJ_XCOFF
193 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
194 legitimately belong in the obj-*.c file. However, XCOFF is based
195 on COFF, and is only implemented for the RS/6000. We just use
196 obj-coff.c, and add what we need here. */
197 { "comm", ppc_comm, 0 },
198 { "lcomm", ppc_comm, 1 },
199 { "bb", ppc_bb, 0 },
200 { "bc", ppc_bc, 0 },
201 { "bf", ppc_bf, 0 },
202 { "bi", ppc_biei, 0 },
203 { "bs", ppc_bs, 0 },
204 { "csect", ppc_csect, 0 },
205 { "data", ppc_section, 'd' },
206 { "eb", ppc_eb, 0 },
207 { "ec", ppc_ec, 0 },
208 { "ef", ppc_ef, 0 },
209 { "ei", ppc_biei, 1 },
210 { "es", ppc_es, 0 },
211 { "extern", ppc_extern, 0 },
212 { "function", ppc_function, 0 },
213 { "lglobl", ppc_lglobl, 0 },
214 { "rename", ppc_rename, 0 },
215 { "section", ppc_named_section, 0 },
216 { "stabx", ppc_stabx, 0 },
217 { "text", ppc_section, 't' },
218 { "toc", ppc_toc, 0 },
219 { "long", ppc_xcoff_cons, 2 },
220 { "llong", ppc_xcoff_cons, 3 },
221 { "word", ppc_xcoff_cons, 1 },
222 { "short", ppc_xcoff_cons, 1 },
223 { "vbyte", ppc_vbyte, 0 },
224 #endif
225
226 #ifdef OBJ_ELF
227 { "llong", ppc_elf_cons, 8 },
228 { "quad", ppc_elf_cons, 8 },
229 { "long", ppc_elf_cons, 4 },
230 { "word", ppc_elf_cons, 2 },
231 { "short", ppc_elf_cons, 2 },
232 { "rdata", ppc_elf_rdata, 0 },
233 { "rodata", ppc_elf_rdata, 0 },
234 { "lcomm", ppc_elf_lcomm, 0 },
235 { "file", dwarf2_directive_file, 0 },
236 { "loc", dwarf2_directive_loc, 0 },
237 #endif
238
239 #ifdef TE_PE
240 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
241 { "previous", ppc_previous, 0 },
242 { "pdata", ppc_pdata, 0 },
243 { "ydata", ppc_ydata, 0 },
244 { "reldata", ppc_reldata, 0 },
245 { "rdata", ppc_rdata, 0 },
246 { "ualong", ppc_ualong, 0 },
247 { "znop", ppc_znop, 0 },
248 { "comm", ppc_pe_comm, 0 },
249 { "lcomm", ppc_pe_comm, 1 },
250 { "section", ppc_pe_section, 0 },
251 { "function", ppc_pe_function,0 },
252 { "tocd", ppc_pe_tocd, 0 },
253 #endif
254
255 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
256 { "tc", ppc_tc, 0 },
257 { "machine", ppc_machine, 0 },
258 #endif
259
260 { NULL, NULL, 0 }
261 };
262
263 \f
264 /* Predefined register names if -mregnames (or default for Windows NT).
265 In general, there are lots of them, in an attempt to be compatible
266 with a number of other Windows NT assemblers. */
267
268 /* Structure to hold information about predefined registers. */
269 struct pd_reg
270 {
271 char *name;
272 int value;
273 };
274
275 /* List of registers that are pre-defined:
276
277 Each general register has predefined names of the form:
278 1. r<reg_num> which has the value <reg_num>.
279 2. r.<reg_num> which has the value <reg_num>.
280
281 Each floating point register has predefined names of the form:
282 1. f<reg_num> which has the value <reg_num>.
283 2. f.<reg_num> which has the value <reg_num>.
284
285 Each vector unit register has predefined names of the form:
286 1. v<reg_num> which has the value <reg_num>.
287 2. v.<reg_num> which has the value <reg_num>.
288
289 Each condition register has predefined names of the form:
290 1. cr<reg_num> which has the value <reg_num>.
291 2. cr.<reg_num> which has the value <reg_num>.
292
293 There are individual registers as well:
294 sp or r.sp has the value 1
295 rtoc or r.toc has the value 2
296 fpscr has the value 0
297 xer has the value 1
298 lr has the value 8
299 ctr has the value 9
300 pmr has the value 0
301 dar has the value 19
302 dsisr has the value 18
303 dec has the value 22
304 sdr1 has the value 25
305 srr0 has the value 26
306 srr1 has the value 27
307
308 The table is sorted. Suitable for searching by a binary search. */
309
310 static const struct pd_reg pre_defined_registers[] =
311 {
312 { "cr.0", 0 }, /* Condition Registers */
313 { "cr.1", 1 },
314 { "cr.2", 2 },
315 { "cr.3", 3 },
316 { "cr.4", 4 },
317 { "cr.5", 5 },
318 { "cr.6", 6 },
319 { "cr.7", 7 },
320
321 { "cr0", 0 },
322 { "cr1", 1 },
323 { "cr2", 2 },
324 { "cr3", 3 },
325 { "cr4", 4 },
326 { "cr5", 5 },
327 { "cr6", 6 },
328 { "cr7", 7 },
329
330 { "ctr", 9 },
331
332 { "dar", 19 }, /* Data Access Register */
333 { "dec", 22 }, /* Decrementer */
334 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
335
336 { "f.0", 0 }, /* Floating point registers */
337 { "f.1", 1 },
338 { "f.10", 10 },
339 { "f.11", 11 },
340 { "f.12", 12 },
341 { "f.13", 13 },
342 { "f.14", 14 },
343 { "f.15", 15 },
344 { "f.16", 16 },
345 { "f.17", 17 },
346 { "f.18", 18 },
347 { "f.19", 19 },
348 { "f.2", 2 },
349 { "f.20", 20 },
350 { "f.21", 21 },
351 { "f.22", 22 },
352 { "f.23", 23 },
353 { "f.24", 24 },
354 { "f.25", 25 },
355 { "f.26", 26 },
356 { "f.27", 27 },
357 { "f.28", 28 },
358 { "f.29", 29 },
359 { "f.3", 3 },
360 { "f.30", 30 },
361 { "f.31", 31 },
362 { "f.4", 4 },
363 { "f.5", 5 },
364 { "f.6", 6 },
365 { "f.7", 7 },
366 { "f.8", 8 },
367 { "f.9", 9 },
368
369 { "f0", 0 },
370 { "f1", 1 },
371 { "f10", 10 },
372 { "f11", 11 },
373 { "f12", 12 },
374 { "f13", 13 },
375 { "f14", 14 },
376 { "f15", 15 },
377 { "f16", 16 },
378 { "f17", 17 },
379 { "f18", 18 },
380 { "f19", 19 },
381 { "f2", 2 },
382 { "f20", 20 },
383 { "f21", 21 },
384 { "f22", 22 },
385 { "f23", 23 },
386 { "f24", 24 },
387 { "f25", 25 },
388 { "f26", 26 },
389 { "f27", 27 },
390 { "f28", 28 },
391 { "f29", 29 },
392 { "f3", 3 },
393 { "f30", 30 },
394 { "f31", 31 },
395 { "f4", 4 },
396 { "f5", 5 },
397 { "f6", 6 },
398 { "f7", 7 },
399 { "f8", 8 },
400 { "f9", 9 },
401
402 { "fpscr", 0 },
403
404 { "lr", 8 }, /* Link Register */
405
406 { "pmr", 0 },
407
408 { "r.0", 0 }, /* General Purpose Registers */
409 { "r.1", 1 },
410 { "r.10", 10 },
411 { "r.11", 11 },
412 { "r.12", 12 },
413 { "r.13", 13 },
414 { "r.14", 14 },
415 { "r.15", 15 },
416 { "r.16", 16 },
417 { "r.17", 17 },
418 { "r.18", 18 },
419 { "r.19", 19 },
420 { "r.2", 2 },
421 { "r.20", 20 },
422 { "r.21", 21 },
423 { "r.22", 22 },
424 { "r.23", 23 },
425 { "r.24", 24 },
426 { "r.25", 25 },
427 { "r.26", 26 },
428 { "r.27", 27 },
429 { "r.28", 28 },
430 { "r.29", 29 },
431 { "r.3", 3 },
432 { "r.30", 30 },
433 { "r.31", 31 },
434 { "r.4", 4 },
435 { "r.5", 5 },
436 { "r.6", 6 },
437 { "r.7", 7 },
438 { "r.8", 8 },
439 { "r.9", 9 },
440
441 { "r.sp", 1 }, /* Stack Pointer */
442
443 { "r.toc", 2 }, /* Pointer to the table of contents */
444
445 { "r0", 0 }, /* More general purpose registers */
446 { "r1", 1 },
447 { "r10", 10 },
448 { "r11", 11 },
449 { "r12", 12 },
450 { "r13", 13 },
451 { "r14", 14 },
452 { "r15", 15 },
453 { "r16", 16 },
454 { "r17", 17 },
455 { "r18", 18 },
456 { "r19", 19 },
457 { "r2", 2 },
458 { "r20", 20 },
459 { "r21", 21 },
460 { "r22", 22 },
461 { "r23", 23 },
462 { "r24", 24 },
463 { "r25", 25 },
464 { "r26", 26 },
465 { "r27", 27 },
466 { "r28", 28 },
467 { "r29", 29 },
468 { "r3", 3 },
469 { "r30", 30 },
470 { "r31", 31 },
471 { "r4", 4 },
472 { "r5", 5 },
473 { "r6", 6 },
474 { "r7", 7 },
475 { "r8", 8 },
476 { "r9", 9 },
477
478 { "rtoc", 2 }, /* Table of contents */
479
480 { "sdr1", 25 }, /* Storage Description Register 1 */
481
482 { "sp", 1 },
483
484 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
485 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
486
487 { "v.0", 0 }, /* Vector registers */
488 { "v.1", 1 },
489 { "v.10", 10 },
490 { "v.11", 11 },
491 { "v.12", 12 },
492 { "v.13", 13 },
493 { "v.14", 14 },
494 { "v.15", 15 },
495 { "v.16", 16 },
496 { "v.17", 17 },
497 { "v.18", 18 },
498 { "v.19", 19 },
499 { "v.2", 2 },
500 { "v.20", 20 },
501 { "v.21", 21 },
502 { "v.22", 22 },
503 { "v.23", 23 },
504 { "v.24", 24 },
505 { "v.25", 25 },
506 { "v.26", 26 },
507 { "v.27", 27 },
508 { "v.28", 28 },
509 { "v.29", 29 },
510 { "v.3", 3 },
511 { "v.30", 30 },
512 { "v.31", 31 },
513 { "v.4", 4 },
514 { "v.5", 5 },
515 { "v.6", 6 },
516 { "v.7", 7 },
517 { "v.8", 8 },
518 { "v.9", 9 },
519
520 { "v0", 0 },
521 { "v1", 1 },
522 { "v10", 10 },
523 { "v11", 11 },
524 { "v12", 12 },
525 { "v13", 13 },
526 { "v14", 14 },
527 { "v15", 15 },
528 { "v16", 16 },
529 { "v17", 17 },
530 { "v18", 18 },
531 { "v19", 19 },
532 { "v2", 2 },
533 { "v20", 20 },
534 { "v21", 21 },
535 { "v22", 22 },
536 { "v23", 23 },
537 { "v24", 24 },
538 { "v25", 25 },
539 { "v26", 26 },
540 { "v27", 27 },
541 { "v28", 28 },
542 { "v29", 29 },
543 { "v3", 3 },
544 { "v30", 30 },
545 { "v31", 31 },
546 { "v4", 4 },
547 { "v5", 5 },
548 { "v6", 6 },
549 { "v7", 7 },
550 { "v8", 8 },
551 { "v9", 9 },
552
553 { "xer", 1 },
554
555 };
556
557 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
558
559 /* Given NAME, find the register number associated with that name, return
560 the integer value associated with the given name or -1 on failure. */
561
562 static int reg_name_search
563 PARAMS ((const struct pd_reg *, int, const char * name));
564
565 static int
566 reg_name_search (regs, regcount, name)
567 const struct pd_reg *regs;
568 int regcount;
569 const char *name;
570 {
571 int middle, low, high;
572 int cmp;
573
574 low = 0;
575 high = regcount - 1;
576
577 do
578 {
579 middle = (low + high) / 2;
580 cmp = strcasecmp (name, regs[middle].name);
581 if (cmp < 0)
582 high = middle - 1;
583 else if (cmp > 0)
584 low = middle + 1;
585 else
586 return regs[middle].value;
587 }
588 while (low <= high);
589
590 return -1;
591 }
592
593 /*
594 * Summary of register_name.
595 *
596 * in: Input_line_pointer points to 1st char of operand.
597 *
598 * out: A expressionS.
599 * The operand may have been a register: in this case, X_op == O_register,
600 * X_add_number is set to the register number, and truth is returned.
601 * Input_line_pointer->(next non-blank) char after operand, or is in its
602 * original state.
603 */
604
605 static boolean
606 register_name (expressionP)
607 expressionS *expressionP;
608 {
609 int reg_number;
610 char *name;
611 char *start;
612 char c;
613
614 /* Find the spelling of the operand. */
615 start = name = input_line_pointer;
616 if (name[0] == '%' && ISALPHA (name[1]))
617 name = ++input_line_pointer;
618
619 else if (!reg_names_p || !ISALPHA (name[0]))
620 return false;
621
622 c = get_symbol_end ();
623 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
624
625 /* Put back the delimiting char. */
626 *input_line_pointer = c;
627
628 /* Look to see if it's in the register table. */
629 if (reg_number >= 0)
630 {
631 expressionP->X_op = O_register;
632 expressionP->X_add_number = reg_number;
633
634 /* Make the rest nice. */
635 expressionP->X_add_symbol = NULL;
636 expressionP->X_op_symbol = NULL;
637 return true;
638 }
639
640 /* Reset the line as if we had not done anything. */
641 input_line_pointer = start;
642 return false;
643 }
644 \f
645 /* This function is called for each symbol seen in an expression. It
646 handles the special parsing which PowerPC assemblers are supposed
647 to use for condition codes. */
648
649 /* Whether to do the special parsing. */
650 static boolean cr_operand;
651
652 /* Names to recognize in a condition code. This table is sorted. */
653 static const struct pd_reg cr_names[] =
654 {
655 { "cr0", 0 },
656 { "cr1", 1 },
657 { "cr2", 2 },
658 { "cr3", 3 },
659 { "cr4", 4 },
660 { "cr5", 5 },
661 { "cr6", 6 },
662 { "cr7", 7 },
663 { "eq", 2 },
664 { "gt", 1 },
665 { "lt", 0 },
666 { "so", 3 },
667 { "un", 3 }
668 };
669
670 /* Parsing function. This returns non-zero if it recognized an
671 expression. */
672
673 int
674 ppc_parse_name (name, expr)
675 const char *name;
676 expressionS *expr;
677 {
678 int val;
679
680 if (! cr_operand)
681 return 0;
682
683 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
684 name);
685 if (val < 0)
686 return 0;
687
688 expr->X_op = O_constant;
689 expr->X_add_number = val;
690
691 return 1;
692 }
693 \f
694 /* Local variables. */
695
696 /* The type of processor we are assembling for. This is one or more
697 of the PPC_OPCODE flags defined in opcode/ppc.h. */
698 static int ppc_cpu = 0;
699
700 /* The size of the processor we are assembling for. This is either
701 PPC_OPCODE_32 or PPC_OPCODE_64. */
702 static unsigned long ppc_size = (BFD_DEFAULT_TARGET_SIZE == 64
703 ? PPC_OPCODE_64
704 : PPC_OPCODE_32);
705
706 /* Whether to target xcoff64. */
707 static int ppc_xcoff64 = 0;
708
709 /* Opcode hash table. */
710 static struct hash_control *ppc_hash;
711
712 /* Macro hash table. */
713 static struct hash_control *ppc_macro_hash;
714
715 #ifdef OBJ_ELF
716 /* What type of shared library support to use. */
717 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
718
719 /* Flags to set in the elf header. */
720 static flagword ppc_flags = 0;
721
722 /* Whether this is Solaris or not. */
723 #ifdef TARGET_SOLARIS_COMMENT
724 #define SOLARIS_P true
725 #else
726 #define SOLARIS_P false
727 #endif
728
729 static boolean msolaris = SOLARIS_P;
730 #endif
731
732 #ifdef OBJ_XCOFF
733
734 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
735 using a bunch of different sections. These assembler sections,
736 however, are all encompassed within the .text or .data sections of
737 the final output file. We handle this by using different
738 subsegments within these main segments. */
739
740 /* Next subsegment to allocate within the .text segment. */
741 static subsegT ppc_text_subsegment = 2;
742
743 /* Linked list of csects in the text section. */
744 static symbolS *ppc_text_csects;
745
746 /* Next subsegment to allocate within the .data segment. */
747 static subsegT ppc_data_subsegment = 2;
748
749 /* Linked list of csects in the data section. */
750 static symbolS *ppc_data_csects;
751
752 /* The current csect. */
753 static symbolS *ppc_current_csect;
754
755 /* The RS/6000 assembler uses a TOC which holds addresses of functions
756 and variables. Symbols are put in the TOC with the .tc pseudo-op.
757 A special relocation is used when accessing TOC entries. We handle
758 the TOC as a subsegment within the .data segment. We set it up if
759 we see a .toc pseudo-op, and save the csect symbol here. */
760 static symbolS *ppc_toc_csect;
761
762 /* The first frag in the TOC subsegment. */
763 static fragS *ppc_toc_frag;
764
765 /* The first frag in the first subsegment after the TOC in the .data
766 segment. NULL if there are no subsegments after the TOC. */
767 static fragS *ppc_after_toc_frag;
768
769 /* The current static block. */
770 static symbolS *ppc_current_block;
771
772 /* The COFF debugging section; set by md_begin. This is not the
773 .debug section, but is instead the secret BFD section which will
774 cause BFD to set the section number of a symbol to N_DEBUG. */
775 static asection *ppc_coff_debug_section;
776
777 #endif /* OBJ_XCOFF */
778
779 #ifdef TE_PE
780
781 /* Various sections that we need for PE coff support. */
782 static segT ydata_section;
783 static segT pdata_section;
784 static segT reldata_section;
785 static segT rdata_section;
786 static segT tocdata_section;
787
788 /* The current section and the previous section. See ppc_previous. */
789 static segT ppc_previous_section;
790 static segT ppc_current_section;
791
792 #endif /* TE_PE */
793
794 #ifdef OBJ_ELF
795 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
796 #endif /* OBJ_ELF */
797 \f
798 #ifdef OBJ_ELF
799 const char *const md_shortopts = "b:l:usm:K:VQ:";
800 #else
801 const char *const md_shortopts = "um:";
802 #endif
803 const struct option md_longopts[] = {
804 {NULL, no_argument, NULL, 0}
805 };
806 const size_t md_longopts_size = sizeof (md_longopts);
807
808 int
809 md_parse_option (c, arg)
810 int c;
811 char *arg;
812 {
813 switch (c)
814 {
815 case 'u':
816 /* -u means that any undefined symbols should be treated as
817 external, which is the default for gas anyhow. */
818 break;
819
820 #ifdef OBJ_ELF
821 case 'l':
822 /* Solaris as takes -le (presumably for little endian). For completeness
823 sake, recognize -be also. */
824 if (strcmp (arg, "e") == 0)
825 {
826 target_big_endian = 0;
827 set_target_endian = 1;
828 }
829 else
830 return 0;
831
832 break;
833
834 case 'b':
835 if (strcmp (arg, "e") == 0)
836 {
837 target_big_endian = 1;
838 set_target_endian = 1;
839 }
840 else
841 return 0;
842
843 break;
844
845 case 'K':
846 /* Recognize -K PIC. */
847 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
848 {
849 shlib = SHLIB_PIC;
850 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
851 }
852 else
853 return 0;
854
855 break;
856 #endif
857
858 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
859 case 'a':
860 if (strcmp (arg, "64") == 0)
861 ppc_xcoff64 = 1;
862 else if (strcmp (arg, "32") == 0)
863 ppc_xcoff64 = 0;
864 else
865 return 0;
866 break;
867
868 case 'm':
869 /* Most CPU's are 32 bit. Exceptions are listed below. */
870 ppc_size = PPC_OPCODE_32;
871
872 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
873 (RIOS2). */
874 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
875 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
876 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
877 else if (strcmp (arg, "pwr") == 0)
878 ppc_cpu = PPC_OPCODE_POWER;
879 /* -m601 means to assemble for the PowerPC 601, which includes
880 instructions that are holdovers from the Power. */
881 else if (strcmp (arg, "601") == 0)
882 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
883 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
884 PowerPC 603/604. */
885 else if (strcmp (arg, "ppc") == 0
886 || strcmp (arg, "ppc32") == 0
887 || strcmp (arg, "603") == 0
888 || strcmp (arg, "604") == 0)
889 ppc_cpu = PPC_OPCODE_PPC;
890 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
891 else if (strcmp (arg, "403") == 0
892 || strcmp (arg, "405") == 0)
893 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_403;
894 else if (strcmp (arg, "7400") == 0
895 || strcmp (arg, "7410") == 0
896 || strcmp (arg, "7450") == 0
897 || strcmp (arg, "7455") == 0)
898 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
899 else if (strcmp (arg, "altivec") == 0)
900 {
901 if (ppc_cpu == 0)
902 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
903 else
904 ppc_cpu |= PPC_OPCODE_ALTIVEC;
905 }
906 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
907 620. */
908 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
909 {
910 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64;
911 ppc_size = PPC_OPCODE_64;
912 }
913 else if (strcmp (arg, "ppc64bridge") == 0)
914 {
915 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64;
916 ppc_size = PPC_OPCODE_64;
917 }
918 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
919 else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0)
920 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE;
921 /* -mbooke64 means enable 64-bit BookE support. */
922 else if (strcmp (arg, "booke64") == 0)
923 {
924 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE |
925 PPC_OPCODE_BOOKE64 | PPC_OPCODE_64;
926 ppc_size = PPC_OPCODE_64;
927 }
928 else if (strcmp (arg, "power4") == 0)
929 {
930 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64 | PPC_OPCODE_POWER4;
931 ppc_size = PPC_OPCODE_64;
932 }
933 /* -mcom means assemble for the common intersection between Power
934 and PowerPC. At present, we just allow the union, rather
935 than the intersection. */
936 else if (strcmp (arg, "com") == 0)
937 ppc_cpu = PPC_OPCODE_COMMON;
938 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
939 else if (strcmp (arg, "any") == 0)
940 ppc_cpu = PPC_OPCODE_ANY;
941
942 else if (strcmp (arg, "regnames") == 0)
943 reg_names_p = true;
944
945 else if (strcmp (arg, "no-regnames") == 0)
946 reg_names_p = false;
947
948 #ifdef OBJ_ELF
949 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
950 that require relocation. */
951 else if (strcmp (arg, "relocatable") == 0)
952 {
953 shlib = SHLIB_MRELOCATABLE;
954 ppc_flags |= EF_PPC_RELOCATABLE;
955 }
956
957 else if (strcmp (arg, "relocatable-lib") == 0)
958 {
959 shlib = SHLIB_MRELOCATABLE;
960 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
961 }
962
963 /* -memb, set embedded bit. */
964 else if (strcmp (arg, "emb") == 0)
965 ppc_flags |= EF_PPC_EMB;
966
967 /* -mlittle/-mbig set the endianess. */
968 else if (strcmp (arg, "little") == 0
969 || strcmp (arg, "little-endian") == 0)
970 {
971 target_big_endian = 0;
972 set_target_endian = 1;
973 }
974
975 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
976 {
977 target_big_endian = 1;
978 set_target_endian = 1;
979 }
980
981 else if (strcmp (arg, "solaris") == 0)
982 {
983 msolaris = true;
984 ppc_comment_chars = ppc_solaris_comment_chars;
985 }
986
987 else if (strcmp (arg, "no-solaris") == 0)
988 {
989 msolaris = false;
990 ppc_comment_chars = ppc_eabi_comment_chars;
991 }
992 #endif
993 else
994 {
995 as_bad (_("invalid switch -m%s"), arg);
996 return 0;
997 }
998 break;
999
1000 #ifdef OBJ_ELF
1001 /* -V: SVR4 argument to print version ID. */
1002 case 'V':
1003 print_version_id ();
1004 break;
1005
1006 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1007 should be emitted or not. FIXME: Not implemented. */
1008 case 'Q':
1009 break;
1010
1011 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1012 rather than .stabs.excl, which is ignored by the linker.
1013 FIXME: Not implemented. */
1014 case 's':
1015 if (arg)
1016 return 0;
1017
1018 break;
1019 #endif
1020
1021 default:
1022 return 0;
1023 }
1024
1025 return 1;
1026 }
1027
1028 void
1029 md_show_usage (stream)
1030 FILE *stream;
1031 {
1032 fprintf (stream, _("\
1033 PowerPC options:\n\
1034 -u ignored\n\
1035 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1036 -mpwr generate code for POWER (RIOS1)\n\
1037 -m601 generate code for PowerPC 601\n\
1038 -mppc, -mppc32, -m603, -m604\n\
1039 generate code for PowerPC 603/604\n\
1040 -m403, -m405 generate code for PowerPC 403/405\n\
1041 -m7400, -m7410, -m7450, -m7455\n\
1042 generate code For PowerPC 7400/7410/7450/7455\n\
1043 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1044 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1045 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1046 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1047 -mpower4 generate code for Power4 architecture\n\
1048 -maltivec generate code for AltiVec\n\
1049 -mcom generate code Power/PowerPC common instructions\n\
1050 -many generate code for any architecture (PWR/PWRX/PPC)\n\
1051 -mregnames Allow symbolic names for registers\n\
1052 -mno-regnames Do not allow symbolic names for registers\n"));
1053 #ifdef OBJ_ELF
1054 fprintf (stream, _("\
1055 -mrelocatable support for GCC's -mrelocatble option\n\
1056 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1057 -memb set PPC_EMB bit in ELF flags\n\
1058 -mlittle, -mlittle-endian\n\
1059 generate code for a little endian machine\n\
1060 -mbig, -mbig-endian generate code for a big endian machine\n\
1061 -msolaris generate code for Solaris\n\
1062 -mno-solaris do not generate code for Solaris\n\
1063 -V print assembler version number\n\
1064 -Qy, -Qn ignored\n"));
1065 #endif
1066 }
1067 \f
1068 /* Set ppc_cpu if it is not already set. */
1069
1070 static void
1071 ppc_set_cpu ()
1072 {
1073 const char *default_os = TARGET_OS;
1074 const char *default_cpu = TARGET_CPU;
1075
1076 if (ppc_cpu == 0)
1077 {
1078 if (strncmp (default_os, "aix", 3) == 0
1079 && default_os[3] >= '4' && default_os[3] <= '9')
1080 ppc_cpu = PPC_OPCODE_COMMON;
1081 else if (strncmp (default_os, "aix3", 4) == 0)
1082 ppc_cpu = PPC_OPCODE_POWER;
1083 else if (strcmp (default_cpu, "rs6000") == 0)
1084 ppc_cpu = PPC_OPCODE_POWER;
1085 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1086 ppc_cpu = PPC_OPCODE_PPC;
1087 else
1088 as_fatal (_("Unknown default cpu = %s, os = %s"),
1089 default_cpu, default_os);
1090 }
1091 }
1092
1093 /* Figure out the BFD architecture to use. */
1094
1095 enum bfd_architecture
1096 ppc_arch ()
1097 {
1098 const char *default_cpu = TARGET_CPU;
1099 ppc_set_cpu ();
1100
1101 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1102 return bfd_arch_powerpc;
1103 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1104 return bfd_arch_rs6000;
1105 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1106 {
1107 if (strcmp (default_cpu, "rs6000") == 0)
1108 return bfd_arch_rs6000;
1109 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1110 return bfd_arch_powerpc;
1111 }
1112
1113 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1114 return bfd_arch_unknown;
1115 }
1116
1117 unsigned long
1118 ppc_mach ()
1119 {
1120 return ppc_size == PPC_OPCODE_64 ? 620 : 0;
1121 }
1122
1123 #ifdef OBJ_XCOFF
1124 int
1125 ppc_subseg_align ()
1126 {
1127 return ppc_xcoff64 ? 3 : 2;
1128 }
1129 #endif
1130
1131 extern char*
1132 ppc_target_format ()
1133 {
1134 #ifdef OBJ_COFF
1135 #ifdef TE_PE
1136 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1137 #elif TE_POWERMAC
1138 return "xcoff-powermac";
1139 #else
1140 # ifdef TE_AIX5
1141 return (ppc_xcoff64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1142 # else
1143 return (ppc_xcoff64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1144 # endif
1145 #endif
1146 #endif
1147 #ifdef OBJ_ELF
1148 boolean is64 = BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64;
1149
1150 return (target_big_endian
1151 ? (is64 ? "elf64-powerpc" : "elf32-powerpc")
1152 : (is64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1153 #endif
1154 }
1155
1156 /* This function is called when the assembler starts up. It is called
1157 after the options have been parsed and the output file has been
1158 opened. */
1159
1160 void
1161 md_begin ()
1162 {
1163 register const struct powerpc_opcode *op;
1164 const struct powerpc_opcode *op_end;
1165 const struct powerpc_macro *macro;
1166 const struct powerpc_macro *macro_end;
1167 boolean dup_insn = false;
1168
1169 ppc_set_cpu ();
1170
1171 #ifdef OBJ_ELF
1172 /* Set the ELF flags if desired. */
1173 if (ppc_flags && !msolaris)
1174 bfd_set_private_flags (stdoutput, ppc_flags);
1175 #endif
1176
1177 /* Insert the opcodes into a hash table. */
1178 ppc_hash = hash_new ();
1179
1180 op_end = powerpc_opcodes + powerpc_num_opcodes;
1181 for (op = powerpc_opcodes; op < op_end; op++)
1182 {
1183 know ((op->opcode & op->mask) == op->opcode);
1184
1185 if ((op->flags & ppc_cpu) != 0
1186 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1187 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size
1188 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0)
1189 && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0
1190 || ((op->flags & PPC_OPCODE_POWER4)
1191 == (ppc_cpu & PPC_OPCODE_POWER4))))
1192 {
1193 const char *retval;
1194
1195 retval = hash_insert (ppc_hash, op->name, (PTR) op);
1196 if (retval != (const char *) NULL)
1197 {
1198 /* Ignore Power duplicates for -m601. */
1199 if ((ppc_cpu & PPC_OPCODE_601) != 0
1200 && (op->flags & PPC_OPCODE_POWER) != 0)
1201 continue;
1202
1203 as_bad (_("Internal assembler error for instruction %s"),
1204 op->name);
1205 dup_insn = true;
1206 }
1207 }
1208 }
1209
1210 /* Insert the macros into a hash table. */
1211 ppc_macro_hash = hash_new ();
1212
1213 macro_end = powerpc_macros + powerpc_num_macros;
1214 for (macro = powerpc_macros; macro < macro_end; macro++)
1215 {
1216 if ((macro->flags & ppc_cpu) != 0)
1217 {
1218 const char *retval;
1219
1220 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1221 if (retval != (const char *) NULL)
1222 {
1223 as_bad (_("Internal assembler error for macro %s"), macro->name);
1224 dup_insn = true;
1225 }
1226 }
1227 }
1228
1229 if (dup_insn)
1230 abort ();
1231
1232 /* Tell the main code what the endianness is if it is not overidden
1233 by the user. */
1234 if (!set_target_endian)
1235 {
1236 set_target_endian = 1;
1237 target_big_endian = PPC_BIG_ENDIAN;
1238 }
1239
1240 #ifdef OBJ_XCOFF
1241 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1242
1243 /* Create dummy symbols to serve as initial csects. This forces the
1244 text csects to precede the data csects. These symbols will not
1245 be output. */
1246 ppc_text_csects = symbol_make ("dummy\001");
1247 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1248 ppc_data_csects = symbol_make ("dummy\001");
1249 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1250 #endif
1251
1252 #ifdef TE_PE
1253
1254 ppc_current_section = text_section;
1255 ppc_previous_section = 0;
1256
1257 #endif
1258 }
1259
1260 /* Insert an operand value into an instruction. */
1261
1262 static unsigned long
1263 ppc_insert_operand (insn, operand, val, file, line)
1264 unsigned long insn;
1265 const struct powerpc_operand *operand;
1266 offsetT val;
1267 char *file;
1268 unsigned int line;
1269 {
1270 if (operand->bits != 32)
1271 {
1272 long min, max;
1273 offsetT test;
1274
1275 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1276 {
1277 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1278 max = (1 << operand->bits) - 1;
1279 else
1280 max = (1 << (operand->bits - 1)) - 1;
1281 min = - (1 << (operand->bits - 1));
1282
1283 if (ppc_size == PPC_OPCODE_32)
1284 {
1285 /* Some people write 32 bit hex constants with the sign
1286 extension done by hand. This shouldn't really be
1287 valid, but, to permit this code to assemble on a 64
1288 bit host, we sign extend the 32 bit value. */
1289 if (val > 0
1290 && (val & (offsetT) 0x80000000) != 0
1291 && (val & (offsetT) 0xffffffff) == val)
1292 {
1293 val -= 0x80000000;
1294 val -= 0x80000000;
1295 }
1296 }
1297 }
1298 else
1299 {
1300 max = (1 << operand->bits) - 1;
1301 min = 0;
1302 }
1303
1304 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1305 test = - val;
1306 else
1307 test = val;
1308
1309 if (test < (offsetT) min || test > (offsetT) max)
1310 {
1311 const char *err =
1312 _("operand out of range (%s not between %ld and %ld)");
1313 char buf[100];
1314
1315 sprint_value (buf, test);
1316 as_bad_where (file, line, err, buf, min, max);
1317 }
1318 }
1319
1320 if (operand->insert)
1321 {
1322 const char *errmsg;
1323
1324 errmsg = NULL;
1325 insn = (*operand->insert) (insn, (long) val, ppc_cpu | ppc_size, &errmsg);
1326 if (errmsg != (const char *) NULL)
1327 as_bad_where (file, line, errmsg);
1328 }
1329 else
1330 insn |= (((long) val & ((1 << operand->bits) - 1))
1331 << operand->shift);
1332
1333 return insn;
1334 }
1335
1336 \f
1337 #ifdef OBJ_ELF
1338 /* Parse @got, etc. and return the desired relocation. */
1339 static bfd_reloc_code_real_type
1340 ppc_elf_suffix (str_p, exp_p)
1341 char **str_p;
1342 expressionS *exp_p;
1343 {
1344 struct map_bfd {
1345 char *string;
1346 int length;
1347 int reloc;
1348 };
1349
1350 char ident[20];
1351 char *str = *str_p;
1352 char *str2;
1353 int ch;
1354 int len;
1355 const struct map_bfd *ptr;
1356
1357 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1358
1359 static const struct map_bfd mapping[] = {
1360 MAP ("l", (int) BFD_RELOC_LO16),
1361 MAP ("h", (int) BFD_RELOC_HI16),
1362 MAP ("ha", (int) BFD_RELOC_HI16_S),
1363 MAP ("brtaken", (int) BFD_RELOC_PPC_B16_BRTAKEN),
1364 MAP ("brntaken", (int) BFD_RELOC_PPC_B16_BRNTAKEN),
1365 MAP ("got", (int) BFD_RELOC_16_GOTOFF),
1366 MAP ("got@l", (int) BFD_RELOC_LO16_GOTOFF),
1367 MAP ("got@h", (int) BFD_RELOC_HI16_GOTOFF),
1368 MAP ("got@ha", (int) BFD_RELOC_HI16_S_GOTOFF),
1369 MAP ("fixup", (int) BFD_RELOC_CTOR), /* warning with -mrelocatable */
1370 MAP ("plt", (int) BFD_RELOC_24_PLT_PCREL),
1371 MAP ("pltrel24", (int) BFD_RELOC_24_PLT_PCREL),
1372 MAP ("copy", (int) BFD_RELOC_PPC_COPY),
1373 MAP ("globdat", (int) BFD_RELOC_PPC_GLOB_DAT),
1374 MAP ("local24pc", (int) BFD_RELOC_PPC_LOCAL24PC),
1375 MAP ("local", (int) BFD_RELOC_PPC_LOCAL24PC),
1376 MAP ("pltrel", (int) BFD_RELOC_32_PLT_PCREL),
1377 MAP ("plt@l", (int) BFD_RELOC_LO16_PLTOFF),
1378 MAP ("plt@h", (int) BFD_RELOC_HI16_PLTOFF),
1379 MAP ("plt@ha", (int) BFD_RELOC_HI16_S_PLTOFF),
1380 MAP ("sdarel", (int) BFD_RELOC_GPREL16),
1381 MAP ("sectoff", (int) BFD_RELOC_16_BASEREL),
1382 MAP ("sectoff@l", (int) BFD_RELOC_LO16_BASEREL),
1383 MAP ("sectoff@h", (int) BFD_RELOC_HI16_BASEREL),
1384 MAP ("sectoff@ha", (int) BFD_RELOC_HI16_S_BASEREL),
1385 MAP ("naddr", (int) BFD_RELOC_PPC_EMB_NADDR32),
1386 MAP ("naddr16", (int) BFD_RELOC_PPC_EMB_NADDR16),
1387 MAP ("naddr@l", (int) BFD_RELOC_PPC_EMB_NADDR16_LO),
1388 MAP ("naddr@h", (int) BFD_RELOC_PPC_EMB_NADDR16_HI),
1389 MAP ("naddr@ha", (int) BFD_RELOC_PPC_EMB_NADDR16_HA),
1390 MAP ("sdai16", (int) BFD_RELOC_PPC_EMB_SDAI16),
1391 MAP ("sda2rel", (int) BFD_RELOC_PPC_EMB_SDA2REL),
1392 MAP ("sda2i16", (int) BFD_RELOC_PPC_EMB_SDA2I16),
1393 MAP ("sda21", (int) BFD_RELOC_PPC_EMB_SDA21),
1394 MAP ("mrkref", (int) BFD_RELOC_PPC_EMB_MRKREF),
1395 MAP ("relsect", (int) BFD_RELOC_PPC_EMB_RELSEC16),
1396 MAP ("relsect@l", (int) BFD_RELOC_PPC_EMB_RELST_LO),
1397 MAP ("relsect@h", (int) BFD_RELOC_PPC_EMB_RELST_HI),
1398 MAP ("relsect@ha", (int) BFD_RELOC_PPC_EMB_RELST_HA),
1399 MAP ("bitfld", (int) BFD_RELOC_PPC_EMB_BIT_FLD),
1400 MAP ("relsda", (int) BFD_RELOC_PPC_EMB_RELSDA),
1401 MAP ("xgot", (int) BFD_RELOC_PPC_TOC16),
1402 #if BFD_DEFAULT_TARGET_SIZE == 64
1403 MAP ("higher", - (int) BFD_RELOC_PPC64_HIGHER),
1404 MAP ("highera", - (int) BFD_RELOC_PPC64_HIGHER_S),
1405 MAP ("highest", - (int) BFD_RELOC_PPC64_HIGHEST),
1406 MAP ("highesta", - (int) BFD_RELOC_PPC64_HIGHEST_S),
1407 MAP ("tocbase", - (int) BFD_RELOC_PPC64_TOC),
1408 MAP ("toc", - (int) BFD_RELOC_PPC_TOC16),
1409 MAP ("toc@l", - (int) BFD_RELOC_PPC64_TOC16_LO),
1410 MAP ("toc@h", - (int) BFD_RELOC_PPC64_TOC16_HI),
1411 MAP ("toc@ha", - (int) BFD_RELOC_PPC64_TOC16_HA),
1412 #endif
1413 { (char *) 0, 0, (int) BFD_RELOC_UNUSED }
1414 };
1415
1416 if (*str++ != '@')
1417 return BFD_RELOC_UNUSED;
1418
1419 for (ch = *str, str2 = ident;
1420 (str2 < ident + sizeof (ident) - 1
1421 && (ISALNUM (ch) || ch == '@'));
1422 ch = *++str)
1423 {
1424 *str2++ = TOLOWER (ch);
1425 }
1426
1427 *str2 = '\0';
1428 len = str2 - ident;
1429
1430 ch = ident[0];
1431 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1432 if (ch == ptr->string[0]
1433 && len == ptr->length
1434 && memcmp (ident, ptr->string, ptr->length) == 0)
1435 {
1436 int reloc = ptr->reloc;
1437
1438 if (BFD_DEFAULT_TARGET_SIZE == 64 && reloc < 0)
1439 {
1440 if (ppc_size != PPC_OPCODE_64)
1441 return BFD_RELOC_UNUSED;
1442 reloc = -reloc;
1443 }
1444
1445 if (exp_p->X_add_number != 0
1446 && (reloc == (int) BFD_RELOC_16_GOTOFF
1447 || reloc == (int) BFD_RELOC_LO16_GOTOFF
1448 || reloc == (int) BFD_RELOC_HI16_GOTOFF
1449 || reloc == (int) BFD_RELOC_HI16_S_GOTOFF))
1450 as_warn (_("identifier+constant@got means identifier@got+constant"));
1451
1452 /* Now check for identifier@suffix+constant. */
1453 if (*str == '-' || *str == '+')
1454 {
1455 char *orig_line = input_line_pointer;
1456 expressionS new_exp;
1457
1458 input_line_pointer = str;
1459 expression (&new_exp);
1460 if (new_exp.X_op == O_constant)
1461 {
1462 exp_p->X_add_number += new_exp.X_add_number;
1463 str = input_line_pointer;
1464 }
1465
1466 if (&input_line_pointer != str_p)
1467 input_line_pointer = orig_line;
1468 }
1469 *str_p = str;
1470
1471 if (BFD_DEFAULT_TARGET_SIZE == 64
1472 && reloc == (int) BFD_RELOC_PPC64_TOC
1473 && exp_p->X_op == O_symbol)
1474 {
1475 /* This reloc type ignores the symbol. Change the symbol
1476 so that the dummy .TOC. symbol can be omitted from the
1477 object file. */
1478 exp_p->X_add_symbol = &abs_symbol;
1479 }
1480
1481 return (bfd_reloc_code_real_type) reloc;
1482 }
1483
1484 return BFD_RELOC_UNUSED;
1485 }
1486
1487 /* Like normal .long/.short/.word, except support @got, etc.
1488 Clobbers input_line_pointer, checks end-of-line. */
1489 static void
1490 ppc_elf_cons (nbytes)
1491 register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1492 {
1493 expressionS exp;
1494 bfd_reloc_code_real_type reloc;
1495
1496 if (is_it_end_of_statement ())
1497 {
1498 demand_empty_rest_of_line ();
1499 return;
1500 }
1501
1502 do
1503 {
1504 expression (&exp);
1505 if (exp.X_op == O_symbol
1506 && *input_line_pointer == '@'
1507 && (reloc = ppc_elf_suffix (&input_line_pointer,
1508 &exp)) != BFD_RELOC_UNUSED)
1509 {
1510 reloc_howto_type *reloc_howto;
1511 int size;
1512
1513 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1514 size = bfd_get_reloc_size (reloc_howto);
1515
1516 if (size > nbytes)
1517 {
1518 as_bad (_("%s relocations do not fit in %d bytes\n"),
1519 reloc_howto->name, nbytes);
1520 }
1521 else
1522 {
1523 char *p;
1524 int offset;
1525
1526 p = frag_more (nbytes);
1527 offset = 0;
1528 if (target_big_endian)
1529 offset = nbytes - size;
1530 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1531 &exp, 0, reloc);
1532 }
1533 }
1534 else
1535 emit_expr (&exp, (unsigned int) nbytes);
1536 }
1537 while (*input_line_pointer++ == ',');
1538
1539 /* Put terminator back into stream. */
1540 input_line_pointer--;
1541 demand_empty_rest_of_line ();
1542 }
1543
1544 /* Solaris pseduo op to change to the .rodata section. */
1545 static void
1546 ppc_elf_rdata (xxx)
1547 int xxx;
1548 {
1549 char *save_line = input_line_pointer;
1550 static char section[] = ".rodata\n";
1551
1552 /* Just pretend this is .section .rodata */
1553 input_line_pointer = section;
1554 obj_elf_section (xxx);
1555
1556 input_line_pointer = save_line;
1557 }
1558
1559 /* Pseudo op to make file scope bss items. */
1560 static void
1561 ppc_elf_lcomm (xxx)
1562 int xxx ATTRIBUTE_UNUSED;
1563 {
1564 register char *name;
1565 register char c;
1566 register char *p;
1567 offsetT size;
1568 register symbolS *symbolP;
1569 offsetT align;
1570 segT old_sec;
1571 int old_subsec;
1572 char *pfrag;
1573 int align2;
1574
1575 name = input_line_pointer;
1576 c = get_symbol_end ();
1577
1578 /* just after name is now '\0'. */
1579 p = input_line_pointer;
1580 *p = c;
1581 SKIP_WHITESPACE ();
1582 if (*input_line_pointer != ',')
1583 {
1584 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1585 ignore_rest_of_line ();
1586 return;
1587 }
1588
1589 input_line_pointer++; /* skip ',' */
1590 if ((size = get_absolute_expression ()) < 0)
1591 {
1592 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1593 ignore_rest_of_line ();
1594 return;
1595 }
1596
1597 /* The third argument to .lcomm is the alignment. */
1598 if (*input_line_pointer != ',')
1599 align = 8;
1600 else
1601 {
1602 ++input_line_pointer;
1603 align = get_absolute_expression ();
1604 if (align <= 0)
1605 {
1606 as_warn (_("ignoring bad alignment"));
1607 align = 8;
1608 }
1609 }
1610
1611 *p = 0;
1612 symbolP = symbol_find_or_make (name);
1613 *p = c;
1614
1615 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1616 {
1617 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1618 S_GET_NAME (symbolP));
1619 ignore_rest_of_line ();
1620 return;
1621 }
1622
1623 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1624 {
1625 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1626 S_GET_NAME (symbolP),
1627 (long) S_GET_VALUE (symbolP),
1628 (long) size);
1629
1630 ignore_rest_of_line ();
1631 return;
1632 }
1633
1634 /* Allocate_bss. */
1635 old_sec = now_seg;
1636 old_subsec = now_subseg;
1637 if (align)
1638 {
1639 /* Convert to a power of 2 alignment. */
1640 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1641 if (align != 1)
1642 {
1643 as_bad (_("Common alignment not a power of 2"));
1644 ignore_rest_of_line ();
1645 return;
1646 }
1647 }
1648 else
1649 align2 = 0;
1650
1651 record_alignment (bss_section, align2);
1652 subseg_set (bss_section, 0);
1653 if (align2)
1654 frag_align (align2, 0, 0);
1655 if (S_GET_SEGMENT (symbolP) == bss_section)
1656 symbol_get_frag (symbolP)->fr_symbol = 0;
1657 symbol_set_frag (symbolP, frag_now);
1658 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1659 (char *) 0);
1660 *pfrag = 0;
1661 S_SET_SIZE (symbolP, size);
1662 S_SET_SEGMENT (symbolP, bss_section);
1663 subseg_set (old_sec, old_subsec);
1664 demand_empty_rest_of_line ();
1665 }
1666
1667 /* Validate any relocations emitted for -mrelocatable, possibly adding
1668 fixups for word relocations in writable segments, so we can adjust
1669 them at runtime. */
1670 static void
1671 ppc_elf_validate_fix (fixp, seg)
1672 fixS *fixp;
1673 segT seg;
1674 {
1675 if (fixp->fx_done || fixp->fx_pcrel)
1676 return;
1677
1678 switch (shlib)
1679 {
1680 case SHLIB_NONE:
1681 case SHLIB_PIC:
1682 return;
1683
1684 case SHLIB_MRELOCATABLE:
1685 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1686 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1687 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1688 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1689 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1690 && fixp->fx_r_type != BFD_RELOC_16_BASEREL
1691 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1692 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1693 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1694 && (seg->flags & SEC_LOAD) != 0
1695 && strcmp (segment_name (seg), ".got2") != 0
1696 && strcmp (segment_name (seg), ".dtors") != 0
1697 && strcmp (segment_name (seg), ".ctors") != 0
1698 && strcmp (segment_name (seg), ".fixup") != 0
1699 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1700 && strcmp (segment_name (seg), ".eh_frame") != 0
1701 && strcmp (segment_name (seg), ".ex_shared") != 0)
1702 {
1703 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1704 || fixp->fx_r_type != BFD_RELOC_CTOR)
1705 {
1706 as_bad_where (fixp->fx_file, fixp->fx_line,
1707 _("Relocation cannot be done when using -mrelocatable"));
1708 }
1709 }
1710 return;
1711 }
1712 }
1713
1714 #if BFD_DEFAULT_TARGET_SIZE == 64
1715 /* Don't emit .TOC. symbol. */
1716 int
1717 ppc_elf_frob_symbol (sym)
1718 symbolS *sym;
1719 {
1720 const char *name;
1721
1722 name = S_GET_NAME (sym);
1723 if (name != NULL && strcmp (name, ".TOC.") == 0)
1724 {
1725 S_CLEAR_EXTERNAL (sym);
1726 return 1;
1727 }
1728
1729 return 0;
1730 }
1731 #endif
1732 #endif /* OBJ_ELF */
1733 \f
1734 #ifdef TE_PE
1735
1736 /*
1737 * Summary of parse_toc_entry.
1738 *
1739 * in: Input_line_pointer points to the '[' in one of:
1740 *
1741 * [toc] [tocv] [toc32] [toc64]
1742 *
1743 * Anything else is an error of one kind or another.
1744 *
1745 * out:
1746 * return value: success or failure
1747 * toc_kind: kind of toc reference
1748 * input_line_pointer:
1749 * success: first char after the ']'
1750 * failure: unchanged
1751 *
1752 * settings:
1753 *
1754 * [toc] - rv == success, toc_kind = default_toc
1755 * [tocv] - rv == success, toc_kind = data_in_toc
1756 * [toc32] - rv == success, toc_kind = must_be_32
1757 * [toc64] - rv == success, toc_kind = must_be_64
1758 *
1759 */
1760
1761 enum toc_size_qualifier
1762 {
1763 default_toc, /* The toc cell constructed should be the system default size */
1764 data_in_toc, /* This is a direct reference to a toc cell */
1765 must_be_32, /* The toc cell constructed must be 32 bits wide */
1766 must_be_64 /* The toc cell constructed must be 64 bits wide */
1767 };
1768
1769 static int
1770 parse_toc_entry (toc_kind)
1771 enum toc_size_qualifier *toc_kind;
1772 {
1773 char *start;
1774 char *toc_spec;
1775 char c;
1776 enum toc_size_qualifier t;
1777
1778 /* Save the input_line_pointer. */
1779 start = input_line_pointer;
1780
1781 /* Skip over the '[' , and whitespace. */
1782 ++input_line_pointer;
1783 SKIP_WHITESPACE ();
1784
1785 /* Find the spelling of the operand. */
1786 toc_spec = input_line_pointer;
1787 c = get_symbol_end ();
1788
1789 if (strcmp (toc_spec, "toc") == 0)
1790 {
1791 t = default_toc;
1792 }
1793 else if (strcmp (toc_spec, "tocv") == 0)
1794 {
1795 t = data_in_toc;
1796 }
1797 else if (strcmp (toc_spec, "toc32") == 0)
1798 {
1799 t = must_be_32;
1800 }
1801 else if (strcmp (toc_spec, "toc64") == 0)
1802 {
1803 t = must_be_64;
1804 }
1805 else
1806 {
1807 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1808 *input_line_pointer = c;
1809 input_line_pointer = start;
1810 return 0;
1811 }
1812
1813 /* Now find the ']'. */
1814 *input_line_pointer = c;
1815
1816 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1817 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1818
1819 if (c != ']')
1820 {
1821 as_bad (_("syntax error: expected `]', found `%c'"), c);
1822 input_line_pointer = start;
1823 return 0;
1824 }
1825
1826 *toc_kind = t;
1827 return 1;
1828 }
1829 #endif
1830 \f
1831
1832 /* We need to keep a list of fixups. We can't simply generate them as
1833 we go, because that would require us to first create the frag, and
1834 that would screw up references to ``.''. */
1835
1836 struct ppc_fixup
1837 {
1838 expressionS exp;
1839 int opindex;
1840 bfd_reloc_code_real_type reloc;
1841 };
1842
1843 #define MAX_INSN_FIXUPS (5)
1844
1845 /* This routine is called for each instruction to be assembled. */
1846
1847 void
1848 md_assemble (str)
1849 char *str;
1850 {
1851 char *s;
1852 const struct powerpc_opcode *opcode;
1853 unsigned long insn;
1854 const unsigned char *opindex_ptr;
1855 int skip_optional;
1856 int need_paren;
1857 int next_opindex;
1858 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1859 int fc;
1860 char *f;
1861 int i;
1862 #ifdef OBJ_ELF
1863 bfd_reloc_code_real_type reloc;
1864 #endif
1865
1866 /* Get the opcode. */
1867 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1868 ;
1869 if (*s != '\0')
1870 *s++ = '\0';
1871
1872 /* Look up the opcode in the hash table. */
1873 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1874 if (opcode == (const struct powerpc_opcode *) NULL)
1875 {
1876 const struct powerpc_macro *macro;
1877
1878 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1879 if (macro == (const struct powerpc_macro *) NULL)
1880 as_bad (_("Unrecognized opcode: `%s'"), str);
1881 else
1882 ppc_macro (s, macro);
1883
1884 return;
1885 }
1886
1887 insn = opcode->opcode;
1888
1889 str = s;
1890 while (ISSPACE (*str))
1891 ++str;
1892
1893 /* PowerPC operands are just expressions. The only real issue is
1894 that a few operand types are optional. All cases which might use
1895 an optional operand separate the operands only with commas (in
1896 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1897 cases never have optional operands). There is never more than
1898 one optional operand for an instruction. So, before we start
1899 seriously parsing the operands, we check to see if we have an
1900 optional operand, and, if we do, we count the number of commas to
1901 see whether the operand should be omitted. */
1902 skip_optional = 0;
1903 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1904 {
1905 const struct powerpc_operand *operand;
1906
1907 operand = &powerpc_operands[*opindex_ptr];
1908 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1909 {
1910 unsigned int opcount;
1911
1912 /* There is an optional operand. Count the number of
1913 commas in the input line. */
1914 if (*str == '\0')
1915 opcount = 0;
1916 else
1917 {
1918 opcount = 1;
1919 s = str;
1920 while ((s = strchr (s, ',')) != (char *) NULL)
1921 {
1922 ++opcount;
1923 ++s;
1924 }
1925 }
1926
1927 /* If there are fewer operands in the line then are called
1928 for by the instruction, we want to skip the optional
1929 operand. */
1930 if (opcount < strlen (opcode->operands))
1931 skip_optional = 1;
1932
1933 break;
1934 }
1935 }
1936
1937 /* Gather the operands. */
1938 need_paren = 0;
1939 next_opindex = 0;
1940 fc = 0;
1941 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1942 {
1943 const struct powerpc_operand *operand;
1944 const char *errmsg;
1945 char *hold;
1946 expressionS ex;
1947 char endc;
1948
1949 if (next_opindex == 0)
1950 operand = &powerpc_operands[*opindex_ptr];
1951 else
1952 {
1953 operand = &powerpc_operands[next_opindex];
1954 next_opindex = 0;
1955 }
1956
1957 errmsg = NULL;
1958
1959 /* If this is a fake operand, then we do not expect anything
1960 from the input. */
1961 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1962 {
1963 insn = (*operand->insert) (insn, 0L, ppc_cpu | ppc_size, &errmsg);
1964 if (errmsg != (const char *) NULL)
1965 as_bad (errmsg);
1966 continue;
1967 }
1968
1969 /* If this is an optional operand, and we are skipping it, just
1970 insert a zero. */
1971 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1972 && skip_optional)
1973 {
1974 if (operand->insert)
1975 {
1976 insn = (*operand->insert) (insn, 0L, ppc_cpu | ppc_size, &errmsg);
1977 if (errmsg != (const char *) NULL)
1978 as_bad (errmsg);
1979 }
1980 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1981 next_opindex = *opindex_ptr + 1;
1982 continue;
1983 }
1984
1985 /* Gather the operand. */
1986 hold = input_line_pointer;
1987 input_line_pointer = str;
1988
1989 #ifdef TE_PE
1990 if (*input_line_pointer == '[')
1991 {
1992 /* We are expecting something like the second argument here:
1993 *
1994 * lwz r4,[toc].GS.0.static_int(rtoc)
1995 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1996 * The argument following the `]' must be a symbol name, and the
1997 * register must be the toc register: 'rtoc' or '2'
1998 *
1999 * The effect is to 0 as the displacement field
2000 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2001 * the appropriate variation) reloc against it based on the symbol.
2002 * The linker will build the toc, and insert the resolved toc offset.
2003 *
2004 * Note:
2005 * o The size of the toc entry is currently assumed to be
2006 * 32 bits. This should not be assumed to be a hard coded
2007 * number.
2008 * o In an effort to cope with a change from 32 to 64 bits,
2009 * there are also toc entries that are specified to be
2010 * either 32 or 64 bits:
2011 * lwz r4,[toc32].GS.0.static_int(rtoc)
2012 * lwz r4,[toc64].GS.0.static_int(rtoc)
2013 * These demand toc entries of the specified size, and the
2014 * instruction probably requires it.
2015 */
2016
2017 int valid_toc;
2018 enum toc_size_qualifier toc_kind;
2019 bfd_reloc_code_real_type toc_reloc;
2020
2021 /* Go parse off the [tocXX] part. */
2022 valid_toc = parse_toc_entry (&toc_kind);
2023
2024 if (!valid_toc)
2025 {
2026 /* Note: message has already been issued.
2027 FIXME: what sort of recovery should we do?
2028 demand_rest_of_line (); return; ? */
2029 }
2030
2031 /* Now get the symbol following the ']'. */
2032 expression (&ex);
2033
2034 switch (toc_kind)
2035 {
2036 case default_toc:
2037 /* In this case, we may not have seen the symbol yet,
2038 since it is allowed to appear on a .extern or .globl
2039 or just be a label in the .data section. */
2040 toc_reloc = BFD_RELOC_PPC_TOC16;
2041 break;
2042 case data_in_toc:
2043 /* 1. The symbol must be defined and either in the toc
2044 section, or a global.
2045 2. The reloc generated must have the TOCDEFN flag set
2046 in upper bit mess of the reloc type.
2047 FIXME: It's a little confusing what the tocv
2048 qualifier can be used for. At the very least, I've
2049 seen three uses, only one of which I'm sure I can
2050 explain. */
2051 if (ex.X_op == O_symbol)
2052 {
2053 assert (ex.X_add_symbol != NULL);
2054 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2055 != tocdata_section)
2056 {
2057 as_bad (_("[tocv] symbol is not a toc symbol"));
2058 }
2059 }
2060
2061 toc_reloc = BFD_RELOC_PPC_TOC16;
2062 break;
2063 case must_be_32:
2064 /* FIXME: these next two specifically specify 32/64 bit
2065 toc entries. We don't support them today. Is this
2066 the right way to say that? */
2067 toc_reloc = BFD_RELOC_UNUSED;
2068 as_bad (_("Unimplemented toc32 expression modifier"));
2069 break;
2070 case must_be_64:
2071 /* FIXME: see above. */
2072 toc_reloc = BFD_RELOC_UNUSED;
2073 as_bad (_("Unimplemented toc64 expression modifier"));
2074 break;
2075 default:
2076 fprintf (stderr,
2077 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2078 toc_kind);
2079 abort ();
2080 break;
2081 }
2082
2083 /* We need to generate a fixup for this expression. */
2084 if (fc >= MAX_INSN_FIXUPS)
2085 as_fatal (_("too many fixups"));
2086
2087 fixups[fc].reloc = toc_reloc;
2088 fixups[fc].exp = ex;
2089 fixups[fc].opindex = *opindex_ptr;
2090 ++fc;
2091
2092 /* Ok. We've set up the fixup for the instruction. Now make it
2093 look like the constant 0 was found here. */
2094 ex.X_unsigned = 1;
2095 ex.X_op = O_constant;
2096 ex.X_add_number = 0;
2097 ex.X_add_symbol = NULL;
2098 ex.X_op_symbol = NULL;
2099 }
2100
2101 else
2102 #endif /* TE_PE */
2103 {
2104 if (! register_name (&ex))
2105 {
2106 if ((operand->flags & PPC_OPERAND_CR) != 0)
2107 cr_operand = true;
2108 expression (&ex);
2109 cr_operand = false;
2110 }
2111 }
2112
2113 str = input_line_pointer;
2114 input_line_pointer = hold;
2115
2116 if (ex.X_op == O_illegal)
2117 as_bad (_("illegal operand"));
2118 else if (ex.X_op == O_absent)
2119 as_bad (_("missing operand"));
2120 else if (ex.X_op == O_register)
2121 {
2122 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2123 (char *) NULL, 0);
2124 }
2125 else if (ex.X_op == O_constant)
2126 {
2127 #ifdef OBJ_ELF
2128 /* Allow @HA, @L, @H on constants. */
2129 char *orig_str = str;
2130
2131 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2132 switch (reloc)
2133 {
2134 default:
2135 str = orig_str;
2136 break;
2137
2138 case BFD_RELOC_LO16:
2139 /* X_unsigned is the default, so if the user has done
2140 something which cleared it, we always produce a
2141 signed value. */
2142 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2143 ex.X_add_number &= 0xffff;
2144 else
2145 ex.X_add_number = SEX16 (ex.X_add_number);
2146 break;
2147
2148 case BFD_RELOC_HI16:
2149 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2150 ex.X_add_number = PPC_HI (ex.X_add_number);
2151 else
2152 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2153 break;
2154
2155 case BFD_RELOC_HI16_S:
2156 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2157 ex.X_add_number = PPC_HA (ex.X_add_number);
2158 else
2159 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2160 break;
2161
2162 #if BFD_DEFAULT_TARGET_SIZE == 64
2163 case BFD_RELOC_PPC64_HIGHER:
2164 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2165 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2166 else
2167 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2168 break;
2169
2170 case BFD_RELOC_PPC64_HIGHER_S:
2171 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2172 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2173 else
2174 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2175 break;
2176
2177 case BFD_RELOC_PPC64_HIGHEST:
2178 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2179 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2180 else
2181 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2182 break;
2183
2184 case BFD_RELOC_PPC64_HIGHEST_S:
2185 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2186 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2187 else
2188 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2189 break;
2190 #endif /* BFD_DEFAULT_TARGET_SIZE == 64 */
2191 }
2192 #endif /* OBJ_ELF */
2193 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2194 (char *) NULL, 0);
2195 }
2196 #ifdef OBJ_ELF
2197 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2198 {
2199 /* For the absolute forms of branches, convert the PC
2200 relative form back into the absolute. */
2201 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2202 {
2203 switch (reloc)
2204 {
2205 case BFD_RELOC_PPC_B26:
2206 reloc = BFD_RELOC_PPC_BA26;
2207 break;
2208 case BFD_RELOC_PPC_B16:
2209 reloc = BFD_RELOC_PPC_BA16;
2210 break;
2211 case BFD_RELOC_PPC_B16_BRTAKEN:
2212 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2213 break;
2214 case BFD_RELOC_PPC_B16_BRNTAKEN:
2215 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2216 break;
2217 default:
2218 break;
2219 }
2220 }
2221
2222 if (BFD_DEFAULT_TARGET_SIZE == 64
2223 && ppc_size == PPC_OPCODE_64
2224 && (operand->flags & PPC_OPERAND_DS) != 0)
2225 {
2226 switch (reloc)
2227 {
2228 case BFD_RELOC_16:
2229 reloc = BFD_RELOC_PPC64_ADDR16_DS;
2230 break;
2231 case BFD_RELOC_LO16:
2232 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2233 break;
2234 case BFD_RELOC_16_GOTOFF:
2235 reloc = BFD_RELOC_PPC64_GOT16_DS;
2236 break;
2237 case BFD_RELOC_LO16_GOTOFF:
2238 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2239 break;
2240 case BFD_RELOC_LO16_PLTOFF:
2241 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2242 break;
2243 case BFD_RELOC_16_BASEREL:
2244 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2245 break;
2246 case BFD_RELOC_LO16_BASEREL:
2247 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2248 break;
2249 case BFD_RELOC_PPC_TOC16:
2250 reloc = BFD_RELOC_PPC64_TOC16_DS;
2251 break;
2252 case BFD_RELOC_PPC64_TOC16_LO:
2253 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2254 break;
2255 case BFD_RELOC_PPC64_PLTGOT16:
2256 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2257 break;
2258 case BFD_RELOC_PPC64_PLTGOT16_LO:
2259 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2260 break;
2261 default:
2262 as_bad (_("unsupported relocation for DS offset field"));
2263 break;
2264 }
2265 }
2266
2267 /* We need to generate a fixup for this expression. */
2268 if (fc >= MAX_INSN_FIXUPS)
2269 as_fatal (_("too many fixups"));
2270 fixups[fc].exp = ex;
2271 fixups[fc].opindex = 0;
2272 fixups[fc].reloc = reloc;
2273 ++fc;
2274 }
2275 #endif /* OBJ_ELF */
2276
2277 else
2278 {
2279 /* We need to generate a fixup for this expression. */
2280 if (fc >= MAX_INSN_FIXUPS)
2281 as_fatal (_("too many fixups"));
2282 fixups[fc].exp = ex;
2283 fixups[fc].opindex = *opindex_ptr;
2284 fixups[fc].reloc = BFD_RELOC_UNUSED;
2285 ++fc;
2286 }
2287
2288 if (need_paren)
2289 {
2290 endc = ')';
2291 need_paren = 0;
2292 }
2293 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2294 {
2295 endc = '(';
2296 need_paren = 1;
2297 }
2298 else
2299 endc = ',';
2300
2301 /* The call to expression should have advanced str past any
2302 whitespace. */
2303 if (*str != endc
2304 && (endc != ',' || *str != '\0'))
2305 {
2306 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2307 break;
2308 }
2309
2310 if (*str != '\0')
2311 ++str;
2312 }
2313
2314 while (ISSPACE (*str))
2315 ++str;
2316
2317 if (*str != '\0')
2318 as_bad (_("junk at end of line: `%s'"), str);
2319
2320 /* Write out the instruction. */
2321 f = frag_more (4);
2322 md_number_to_chars (f, insn, 4);
2323
2324 #ifdef OBJ_ELF
2325 dwarf2_emit_insn (4);
2326 #endif
2327
2328 /* Create any fixups. At this point we do not use a
2329 bfd_reloc_code_real_type, but instead just use the
2330 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2331 handle fixups for any operand type, although that is admittedly
2332 not a very exciting feature. We pick a BFD reloc type in
2333 md_apply_fix3. */
2334 for (i = 0; i < fc; i++)
2335 {
2336 const struct powerpc_operand *operand;
2337
2338 operand = &powerpc_operands[fixups[i].opindex];
2339 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2340 {
2341 reloc_howto_type *reloc_howto;
2342 int size;
2343 int offset;
2344 fixS *fixP;
2345
2346 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2347 if (!reloc_howto)
2348 abort ();
2349
2350 size = bfd_get_reloc_size (reloc_howto);
2351 offset = target_big_endian ? (4 - size) : 0;
2352
2353 if (size < 1 || size > 4)
2354 abort ();
2355
2356 fixP = fix_new_exp (frag_now,
2357 f - frag_now->fr_literal + offset,
2358 size,
2359 &fixups[i].exp,
2360 reloc_howto->pc_relative,
2361 fixups[i].reloc);
2362
2363 /* Turn off complaints that the addend is too large for things like
2364 foo+100000@ha. */
2365 switch (fixups[i].reloc)
2366 {
2367 case BFD_RELOC_16_GOTOFF:
2368 case BFD_RELOC_PPC_TOC16:
2369 case BFD_RELOC_LO16:
2370 case BFD_RELOC_HI16:
2371 case BFD_RELOC_HI16_S:
2372 #ifdef OBJ_ELF
2373 #if BFD_DEFAULT_TARGET_SIZE == 64
2374 case BFD_RELOC_PPC64_HIGHER:
2375 case BFD_RELOC_PPC64_HIGHER_S:
2376 case BFD_RELOC_PPC64_HIGHEST:
2377 case BFD_RELOC_PPC64_HIGHEST_S:
2378 #endif
2379 #endif
2380 fixP->fx_no_overflow = 1;
2381 break;
2382 default:
2383 break;
2384 }
2385 }
2386 else
2387 fix_new_exp (frag_now,
2388 f - frag_now->fr_literal,
2389 4,
2390 &fixups[i].exp,
2391 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2392 ((bfd_reloc_code_real_type)
2393 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2394 }
2395 }
2396
2397 /* Handle a macro. Gather all the operands, transform them as
2398 described by the macro, and call md_assemble recursively. All the
2399 operands are separated by commas; we don't accept parentheses
2400 around operands here. */
2401
2402 static void
2403 ppc_macro (str, macro)
2404 char *str;
2405 const struct powerpc_macro *macro;
2406 {
2407 char *operands[10];
2408 unsigned int count;
2409 char *s;
2410 unsigned int len;
2411 const char *format;
2412 int arg;
2413 char *send;
2414 char *complete;
2415
2416 /* Gather the users operands into the operands array. */
2417 count = 0;
2418 s = str;
2419 while (1)
2420 {
2421 if (count >= sizeof operands / sizeof operands[0])
2422 break;
2423 operands[count++] = s;
2424 s = strchr (s, ',');
2425 if (s == (char *) NULL)
2426 break;
2427 *s++ = '\0';
2428 }
2429
2430 if (count != macro->operands)
2431 {
2432 as_bad (_("wrong number of operands"));
2433 return;
2434 }
2435
2436 /* Work out how large the string must be (the size is unbounded
2437 because it includes user input). */
2438 len = 0;
2439 format = macro->format;
2440 while (*format != '\0')
2441 {
2442 if (*format != '%')
2443 {
2444 ++len;
2445 ++format;
2446 }
2447 else
2448 {
2449 arg = strtol (format + 1, &send, 10);
2450 know (send != format && arg >= 0 && arg < count);
2451 len += strlen (operands[arg]);
2452 format = send;
2453 }
2454 }
2455
2456 /* Put the string together. */
2457 complete = s = (char *) alloca (len + 1);
2458 format = macro->format;
2459 while (*format != '\0')
2460 {
2461 if (*format != '%')
2462 *s++ = *format++;
2463 else
2464 {
2465 arg = strtol (format + 1, &send, 10);
2466 strcpy (s, operands[arg]);
2467 s += strlen (s);
2468 format = send;
2469 }
2470 }
2471 *s = '\0';
2472
2473 /* Assemble the constructed instruction. */
2474 md_assemble (complete);
2475 }
2476 \f
2477 #ifdef OBJ_ELF
2478 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2479
2480 int
2481 ppc_section_letter (letter, ptr_msg)
2482 int letter;
2483 char **ptr_msg;
2484 {
2485 if (letter == 'e')
2486 return SHF_EXCLUDE;
2487
2488 *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S in string");
2489 return 0;
2490 }
2491
2492 int
2493 ppc_section_word (str, len)
2494 char *str;
2495 size_t len;
2496 {
2497 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2498 return SHF_EXCLUDE;
2499
2500 return -1;
2501 }
2502
2503 int
2504 ppc_section_type (str, len)
2505 char *str;
2506 size_t len;
2507 {
2508 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2509 return SHT_ORDERED;
2510
2511 return -1;
2512 }
2513
2514 int
2515 ppc_section_flags (flags, attr, type)
2516 int flags;
2517 int attr;
2518 int type;
2519 {
2520 if (type == SHT_ORDERED)
2521 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2522
2523 if (attr & SHF_EXCLUDE)
2524 flags |= SEC_EXCLUDE;
2525
2526 return flags;
2527 }
2528 #endif /* OBJ_ELF */
2529
2530 \f
2531 /* Pseudo-op handling. */
2532
2533 /* The .byte pseudo-op. This is similar to the normal .byte
2534 pseudo-op, but it can also take a single ASCII string. */
2535
2536 static void
2537 ppc_byte (ignore)
2538 int ignore ATTRIBUTE_UNUSED;
2539 {
2540 if (*input_line_pointer != '\"')
2541 {
2542 cons (1);
2543 return;
2544 }
2545
2546 /* Gather characters. A real double quote is doubled. Unusual
2547 characters are not permitted. */
2548 ++input_line_pointer;
2549 while (1)
2550 {
2551 char c;
2552
2553 c = *input_line_pointer++;
2554
2555 if (c == '\"')
2556 {
2557 if (*input_line_pointer != '\"')
2558 break;
2559 ++input_line_pointer;
2560 }
2561
2562 FRAG_APPEND_1_CHAR (c);
2563 }
2564
2565 demand_empty_rest_of_line ();
2566 }
2567 \f
2568 #ifdef OBJ_XCOFF
2569
2570 /* XCOFF specific pseudo-op handling. */
2571
2572 /* This is set if we are creating a .stabx symbol, since we don't want
2573 to handle symbol suffixes for such symbols. */
2574 static boolean ppc_stab_symbol;
2575
2576 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2577 symbols in the .bss segment as though they were local common
2578 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2579 aligns .comm and .lcomm to 4 bytes. */
2580
2581 static void
2582 ppc_comm (lcomm)
2583 int lcomm;
2584 {
2585 asection *current_seg = now_seg;
2586 subsegT current_subseg = now_subseg;
2587 char *name;
2588 char endc;
2589 char *end_name;
2590 offsetT size;
2591 offsetT align;
2592 symbolS *lcomm_sym = NULL;
2593 symbolS *sym;
2594 char *pfrag;
2595
2596 name = input_line_pointer;
2597 endc = get_symbol_end ();
2598 end_name = input_line_pointer;
2599 *end_name = endc;
2600
2601 if (*input_line_pointer != ',')
2602 {
2603 as_bad (_("missing size"));
2604 ignore_rest_of_line ();
2605 return;
2606 }
2607 ++input_line_pointer;
2608
2609 size = get_absolute_expression ();
2610 if (size < 0)
2611 {
2612 as_bad (_("negative size"));
2613 ignore_rest_of_line ();
2614 return;
2615 }
2616
2617 if (! lcomm)
2618 {
2619 /* The third argument to .comm is the alignment. */
2620 if (*input_line_pointer != ',')
2621 align = 2;
2622 else
2623 {
2624 ++input_line_pointer;
2625 align = get_absolute_expression ();
2626 if (align <= 0)
2627 {
2628 as_warn (_("ignoring bad alignment"));
2629 align = 2;
2630 }
2631 }
2632 }
2633 else
2634 {
2635 char *lcomm_name;
2636 char lcomm_endc;
2637
2638 if (size <= 4)
2639 align = 2;
2640 else
2641 align = 3;
2642
2643 /* The third argument to .lcomm appears to be the real local
2644 common symbol to create. References to the symbol named in
2645 the first argument are turned into references to the third
2646 argument. */
2647 if (*input_line_pointer != ',')
2648 {
2649 as_bad (_("missing real symbol name"));
2650 ignore_rest_of_line ();
2651 return;
2652 }
2653 ++input_line_pointer;
2654
2655 lcomm_name = input_line_pointer;
2656 lcomm_endc = get_symbol_end ();
2657
2658 lcomm_sym = symbol_find_or_make (lcomm_name);
2659
2660 *input_line_pointer = lcomm_endc;
2661 }
2662
2663 *end_name = '\0';
2664 sym = symbol_find_or_make (name);
2665 *end_name = endc;
2666
2667 if (S_IS_DEFINED (sym)
2668 || S_GET_VALUE (sym) != 0)
2669 {
2670 as_bad (_("attempt to redefine symbol"));
2671 ignore_rest_of_line ();
2672 return;
2673 }
2674
2675 record_alignment (bss_section, align);
2676
2677 if (! lcomm
2678 || ! S_IS_DEFINED (lcomm_sym))
2679 {
2680 symbolS *def_sym;
2681 offsetT def_size;
2682
2683 if (! lcomm)
2684 {
2685 def_sym = sym;
2686 def_size = size;
2687 S_SET_EXTERNAL (sym);
2688 }
2689 else
2690 {
2691 symbol_get_tc (lcomm_sym)->output = 1;
2692 def_sym = lcomm_sym;
2693 def_size = 0;
2694 }
2695
2696 subseg_set (bss_section, 1);
2697 frag_align (align, 0, 0);
2698
2699 symbol_set_frag (def_sym, frag_now);
2700 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2701 def_size, (char *) NULL);
2702 *pfrag = 0;
2703 S_SET_SEGMENT (def_sym, bss_section);
2704 symbol_get_tc (def_sym)->align = align;
2705 }
2706 else if (lcomm)
2707 {
2708 /* Align the size of lcomm_sym. */
2709 symbol_get_frag (lcomm_sym)->fr_offset =
2710 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
2711 &~ ((1 << align) - 1));
2712 if (align > symbol_get_tc (lcomm_sym)->align)
2713 symbol_get_tc (lcomm_sym)->align = align;
2714 }
2715
2716 if (lcomm)
2717 {
2718 /* Make sym an offset from lcomm_sym. */
2719 S_SET_SEGMENT (sym, bss_section);
2720 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
2721 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
2722 symbol_get_frag (lcomm_sym)->fr_offset += size;
2723 }
2724
2725 subseg_set (current_seg, current_subseg);
2726
2727 demand_empty_rest_of_line ();
2728 }
2729
2730 /* The .csect pseudo-op. This switches us into a different
2731 subsegment. The first argument is a symbol whose value is the
2732 start of the .csect. In COFF, csect symbols get special aux
2733 entries defined by the x_csect field of union internal_auxent. The
2734 optional second argument is the alignment (the default is 2). */
2735
2736 static void
2737 ppc_csect (ignore)
2738 int ignore ATTRIBUTE_UNUSED;
2739 {
2740 char *name;
2741 char endc;
2742 symbolS *sym;
2743
2744 name = input_line_pointer;
2745 endc = get_symbol_end ();
2746
2747 sym = symbol_find_or_make (name);
2748
2749 *input_line_pointer = endc;
2750
2751 if (S_GET_NAME (sym)[0] == '\0')
2752 {
2753 /* An unnamed csect is assumed to be [PR]. */
2754 symbol_get_tc (sym)->class = XMC_PR;
2755 }
2756
2757 ppc_change_csect (sym);
2758
2759 if (*input_line_pointer == ',')
2760 {
2761 ++input_line_pointer;
2762 symbol_get_tc (sym)->align = get_absolute_expression ();
2763 }
2764
2765 demand_empty_rest_of_line ();
2766 }
2767
2768 /* Change to a different csect. */
2769
2770 static void
2771 ppc_change_csect (sym)
2772 symbolS *sym;
2773 {
2774 if (S_IS_DEFINED (sym))
2775 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
2776 else
2777 {
2778 symbolS **list_ptr;
2779 int after_toc;
2780 int hold_chunksize;
2781 symbolS *list;
2782
2783 /* This is a new csect. We need to look at the symbol class to
2784 figure out whether it should go in the text section or the
2785 data section. */
2786 after_toc = 0;
2787 switch (symbol_get_tc (sym)->class)
2788 {
2789 case XMC_PR:
2790 case XMC_RO:
2791 case XMC_DB:
2792 case XMC_GL:
2793 case XMC_XO:
2794 case XMC_SV:
2795 case XMC_TI:
2796 case XMC_TB:
2797 S_SET_SEGMENT (sym, text_section);
2798 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
2799 ++ppc_text_subsegment;
2800 list_ptr = &ppc_text_csects;
2801 break;
2802 case XMC_RW:
2803 case XMC_TC0:
2804 case XMC_TC:
2805 case XMC_DS:
2806 case XMC_UA:
2807 case XMC_BS:
2808 case XMC_UC:
2809 if (ppc_toc_csect != NULL
2810 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
2811 == ppc_data_subsegment))
2812 after_toc = 1;
2813 S_SET_SEGMENT (sym, data_section);
2814 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
2815 ++ppc_data_subsegment;
2816 list_ptr = &ppc_data_csects;
2817 break;
2818 default:
2819 abort ();
2820 }
2821
2822 /* We set the obstack chunk size to a small value before
2823 changing subsegments, so that we don't use a lot of memory
2824 space for what may be a small section. */
2825 hold_chunksize = chunksize;
2826 chunksize = 64;
2827
2828 subseg_new (segment_name (S_GET_SEGMENT (sym)),
2829 symbol_get_tc (sym)->subseg);
2830
2831 chunksize = hold_chunksize;
2832
2833 if (after_toc)
2834 ppc_after_toc_frag = frag_now;
2835
2836 symbol_set_frag (sym, frag_now);
2837 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2838
2839 symbol_get_tc (sym)->align = (ppc_xcoff64) ? 3 : 2;
2840 symbol_get_tc (sym)->output = 1;
2841 symbol_get_tc (sym)->within = sym;
2842
2843 for (list = *list_ptr;
2844 symbol_get_tc (list)->next != (symbolS *) NULL;
2845 list = symbol_get_tc (list)->next)
2846 ;
2847 symbol_get_tc (list)->next = sym;
2848
2849 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2850 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
2851 &symbol_lastP);
2852 }
2853
2854 ppc_current_csect = sym;
2855 }
2856
2857 /* This function handles the .text and .data pseudo-ops. These
2858 pseudo-ops aren't really used by XCOFF; we implement them for the
2859 convenience of people who aren't used to XCOFF. */
2860
2861 static void
2862 ppc_section (type)
2863 int type;
2864 {
2865 const char *name;
2866 symbolS *sym;
2867
2868 if (type == 't')
2869 name = ".text[PR]";
2870 else if (type == 'd')
2871 name = ".data[RW]";
2872 else
2873 abort ();
2874
2875 sym = symbol_find_or_make (name);
2876
2877 ppc_change_csect (sym);
2878
2879 demand_empty_rest_of_line ();
2880 }
2881
2882 /* This function handles the .section pseudo-op. This is mostly to
2883 give an error, since XCOFF only supports .text, .data and .bss, but
2884 we do permit the user to name the text or data section. */
2885
2886 static void
2887 ppc_named_section (ignore)
2888 int ignore ATTRIBUTE_UNUSED;
2889 {
2890 char *user_name;
2891 const char *real_name;
2892 char c;
2893 symbolS *sym;
2894
2895 user_name = input_line_pointer;
2896 c = get_symbol_end ();
2897
2898 if (strcmp (user_name, ".text") == 0)
2899 real_name = ".text[PR]";
2900 else if (strcmp (user_name, ".data") == 0)
2901 real_name = ".data[RW]";
2902 else
2903 {
2904 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2905 *input_line_pointer = c;
2906 ignore_rest_of_line ();
2907 return;
2908 }
2909
2910 *input_line_pointer = c;
2911
2912 sym = symbol_find_or_make (real_name);
2913
2914 ppc_change_csect (sym);
2915
2916 demand_empty_rest_of_line ();
2917 }
2918
2919 /* The .extern pseudo-op. We create an undefined symbol. */
2920
2921 static void
2922 ppc_extern (ignore)
2923 int ignore ATTRIBUTE_UNUSED;
2924 {
2925 char *name;
2926 char endc;
2927
2928 name = input_line_pointer;
2929 endc = get_symbol_end ();
2930
2931 (void) symbol_find_or_make (name);
2932
2933 *input_line_pointer = endc;
2934
2935 demand_empty_rest_of_line ();
2936 }
2937
2938 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2939
2940 static void
2941 ppc_lglobl (ignore)
2942 int ignore ATTRIBUTE_UNUSED;
2943 {
2944 char *name;
2945 char endc;
2946 symbolS *sym;
2947
2948 name = input_line_pointer;
2949 endc = get_symbol_end ();
2950
2951 sym = symbol_find_or_make (name);
2952
2953 *input_line_pointer = endc;
2954
2955 symbol_get_tc (sym)->output = 1;
2956
2957 demand_empty_rest_of_line ();
2958 }
2959
2960 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2961 although I don't know why it bothers. */
2962
2963 static void
2964 ppc_rename (ignore)
2965 int ignore ATTRIBUTE_UNUSED;
2966 {
2967 char *name;
2968 char endc;
2969 symbolS *sym;
2970 int len;
2971
2972 name = input_line_pointer;
2973 endc = get_symbol_end ();
2974
2975 sym = symbol_find_or_make (name);
2976
2977 *input_line_pointer = endc;
2978
2979 if (*input_line_pointer != ',')
2980 {
2981 as_bad (_("missing rename string"));
2982 ignore_rest_of_line ();
2983 return;
2984 }
2985 ++input_line_pointer;
2986
2987 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
2988
2989 demand_empty_rest_of_line ();
2990 }
2991
2992 /* The .stabx pseudo-op. This is similar to a normal .stabs
2993 pseudo-op, but slightly different. A sample is
2994 .stabx "main:F-1",.main,142,0
2995 The first argument is the symbol name to create. The second is the
2996 value, and the third is the storage class. The fourth seems to be
2997 always zero, and I am assuming it is the type. */
2998
2999 static void
3000 ppc_stabx (ignore)
3001 int ignore ATTRIBUTE_UNUSED;
3002 {
3003 char *name;
3004 int len;
3005 symbolS *sym;
3006 expressionS exp;
3007
3008 name = demand_copy_C_string (&len);
3009
3010 if (*input_line_pointer != ',')
3011 {
3012 as_bad (_("missing value"));
3013 return;
3014 }
3015 ++input_line_pointer;
3016
3017 ppc_stab_symbol = true;
3018 sym = symbol_make (name);
3019 ppc_stab_symbol = false;
3020
3021 symbol_get_tc (sym)->real_name = name;
3022
3023 (void) expression (&exp);
3024
3025 switch (exp.X_op)
3026 {
3027 case O_illegal:
3028 case O_absent:
3029 case O_big:
3030 as_bad (_("illegal .stabx expression; zero assumed"));
3031 exp.X_add_number = 0;
3032 /* Fall through. */
3033 case O_constant:
3034 S_SET_VALUE (sym, (valueT) exp.X_add_number);
3035 symbol_set_frag (sym, &zero_address_frag);
3036 break;
3037
3038 case O_symbol:
3039 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3040 symbol_set_value_expression (sym, &exp);
3041 else
3042 {
3043 S_SET_VALUE (sym,
3044 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3045 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3046 }
3047 break;
3048
3049 default:
3050 /* The value is some complex expression. This will probably
3051 fail at some later point, but this is probably the right
3052 thing to do here. */
3053 symbol_set_value_expression (sym, &exp);
3054 break;
3055 }
3056
3057 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3058 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3059
3060 if (*input_line_pointer != ',')
3061 {
3062 as_bad (_("missing class"));
3063 return;
3064 }
3065 ++input_line_pointer;
3066
3067 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3068
3069 if (*input_line_pointer != ',')
3070 {
3071 as_bad (_("missing type"));
3072 return;
3073 }
3074 ++input_line_pointer;
3075
3076 S_SET_DATA_TYPE (sym, get_absolute_expression ());
3077
3078 symbol_get_tc (sym)->output = 1;
3079
3080 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
3081
3082 symbol_get_tc (sym)->within = ppc_current_block;
3083
3084 /* In this case :
3085
3086 .bs name
3087 .stabx "z",arrays_,133,0
3088 .es
3089
3090 .comm arrays_,13768,3
3091
3092 resolve_symbol_value will copy the exp's "within" into sym's when the
3093 offset is 0. Since this seems to be corner case problem,
3094 only do the correction for storage class C_STSYM. A better solution
3095 would be to have the tc field updated in ppc_symbol_new_hook. */
3096
3097 if (exp.X_op == O_symbol)
3098 {
3099 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3100 }
3101 }
3102
3103 if (exp.X_op != O_symbol
3104 || ! S_IS_EXTERNAL (exp.X_add_symbol)
3105 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3106 ppc_frob_label (sym);
3107 else
3108 {
3109 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3110 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3111 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3112 symbol_get_tc (ppc_current_csect)->within = sym;
3113 }
3114
3115 demand_empty_rest_of_line ();
3116 }
3117
3118 /* The .function pseudo-op. This takes several arguments. The first
3119 argument seems to be the external name of the symbol. The second
3120 argment seems to be the label for the start of the function. gcc
3121 uses the same name for both. I have no idea what the third and
3122 fourth arguments are meant to be. The optional fifth argument is
3123 an expression for the size of the function. In COFF this symbol
3124 gets an aux entry like that used for a csect. */
3125
3126 static void
3127 ppc_function (ignore)
3128 int ignore ATTRIBUTE_UNUSED;
3129 {
3130 char *name;
3131 char endc;
3132 char *s;
3133 symbolS *ext_sym;
3134 symbolS *lab_sym;
3135
3136 name = input_line_pointer;
3137 endc = get_symbol_end ();
3138
3139 /* Ignore any [PR] suffix. */
3140 name = ppc_canonicalize_symbol_name (name);
3141 s = strchr (name, '[');
3142 if (s != (char *) NULL
3143 && strcmp (s + 1, "PR]") == 0)
3144 *s = '\0';
3145
3146 ext_sym = symbol_find_or_make (name);
3147
3148 *input_line_pointer = endc;
3149
3150 if (*input_line_pointer != ',')
3151 {
3152 as_bad (_("missing symbol name"));
3153 ignore_rest_of_line ();
3154 return;
3155 }
3156 ++input_line_pointer;
3157
3158 name = input_line_pointer;
3159 endc = get_symbol_end ();
3160
3161 lab_sym = symbol_find_or_make (name);
3162
3163 *input_line_pointer = endc;
3164
3165 if (ext_sym != lab_sym)
3166 {
3167 expressionS exp;
3168
3169 exp.X_op = O_symbol;
3170 exp.X_add_symbol = lab_sym;
3171 exp.X_op_symbol = NULL;
3172 exp.X_add_number = 0;
3173 exp.X_unsigned = 0;
3174 symbol_set_value_expression (ext_sym, &exp);
3175 }
3176
3177 if (symbol_get_tc (ext_sym)->class == -1)
3178 symbol_get_tc (ext_sym)->class = XMC_PR;
3179 symbol_get_tc (ext_sym)->output = 1;
3180
3181 if (*input_line_pointer == ',')
3182 {
3183 expressionS ignore;
3184
3185 /* Ignore the third argument. */
3186 ++input_line_pointer;
3187 expression (&ignore);
3188 if (*input_line_pointer == ',')
3189 {
3190 /* Ignore the fourth argument. */
3191 ++input_line_pointer;
3192 expression (&ignore);
3193 if (*input_line_pointer == ',')
3194 {
3195 /* The fifth argument is the function size. */
3196 ++input_line_pointer;
3197 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
3198 absolute_section,
3199 (valueT) 0,
3200 &zero_address_frag);
3201 pseudo_set (symbol_get_tc (ext_sym)->size);
3202 }
3203 }
3204 }
3205
3206 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3207 SF_SET_FUNCTION (ext_sym);
3208 SF_SET_PROCESS (ext_sym);
3209 coff_add_linesym (ext_sym);
3210
3211 demand_empty_rest_of_line ();
3212 }
3213
3214 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3215 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3216 with the correct line number */
3217
3218 static symbolS *saved_bi_sym = 0;
3219
3220 static void
3221 ppc_bf (ignore)
3222 int ignore ATTRIBUTE_UNUSED;
3223 {
3224 symbolS *sym;
3225
3226 sym = symbol_make (".bf");
3227 S_SET_SEGMENT (sym, text_section);
3228 symbol_set_frag (sym, frag_now);
3229 S_SET_VALUE (sym, frag_now_fix ());
3230 S_SET_STORAGE_CLASS (sym, C_FCN);
3231
3232 coff_line_base = get_absolute_expression ();
3233
3234 S_SET_NUMBER_AUXILIARY (sym, 1);
3235 SA_SET_SYM_LNNO (sym, coff_line_base);
3236
3237 /* Line number for bi. */
3238 if (saved_bi_sym)
3239 {
3240 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
3241 saved_bi_sym = 0;
3242 }
3243
3244
3245 symbol_get_tc (sym)->output = 1;
3246
3247 ppc_frob_label (sym);
3248
3249 demand_empty_rest_of_line ();
3250 }
3251
3252 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3253 ".ef", except that the line number is absolute, not relative to the
3254 most recent ".bf" symbol. */
3255
3256 static void
3257 ppc_ef (ignore)
3258 int ignore ATTRIBUTE_UNUSED;
3259 {
3260 symbolS *sym;
3261
3262 sym = symbol_make (".ef");
3263 S_SET_SEGMENT (sym, text_section);
3264 symbol_set_frag (sym, frag_now);
3265 S_SET_VALUE (sym, frag_now_fix ());
3266 S_SET_STORAGE_CLASS (sym, C_FCN);
3267 S_SET_NUMBER_AUXILIARY (sym, 1);
3268 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3269 symbol_get_tc (sym)->output = 1;
3270
3271 ppc_frob_label (sym);
3272
3273 demand_empty_rest_of_line ();
3274 }
3275
3276 /* The .bi and .ei pseudo-ops. These take a string argument and
3277 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3278 the symbol list. The value of .bi will be know when the next .bf
3279 is encountered. */
3280
3281 static void
3282 ppc_biei (ei)
3283 int ei;
3284 {
3285 static symbolS *last_biei;
3286
3287 char *name;
3288 int len;
3289 symbolS *sym;
3290 symbolS *look;
3291
3292 name = demand_copy_C_string (&len);
3293
3294 /* The value of these symbols is actually file offset. Here we set
3295 the value to the index into the line number entries. In
3296 ppc_frob_symbols we set the fix_line field, which will cause BFD
3297 to do the right thing. */
3298
3299 sym = symbol_make (name);
3300 /* obj-coff.c currently only handles line numbers correctly in the
3301 .text section. */
3302 S_SET_SEGMENT (sym, text_section);
3303 S_SET_VALUE (sym, coff_n_line_nos);
3304 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3305
3306 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3307 symbol_get_tc (sym)->output = 1;
3308
3309 /* Save bi. */
3310 if (ei)
3311 saved_bi_sym = 0;
3312 else
3313 saved_bi_sym = sym;
3314
3315 for (look = last_biei ? last_biei : symbol_rootP;
3316 (look != (symbolS *) NULL
3317 && (S_GET_STORAGE_CLASS (look) == C_FILE
3318 || S_GET_STORAGE_CLASS (look) == C_BINCL
3319 || S_GET_STORAGE_CLASS (look) == C_EINCL));
3320 look = symbol_next (look))
3321 ;
3322 if (look != (symbolS *) NULL)
3323 {
3324 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3325 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3326 last_biei = sym;
3327 }
3328
3329 demand_empty_rest_of_line ();
3330 }
3331
3332 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3333 There is one argument, which is a csect symbol. The value of the
3334 .bs symbol is the index of this csect symbol. */
3335
3336 static void
3337 ppc_bs (ignore)
3338 int ignore ATTRIBUTE_UNUSED;
3339 {
3340 char *name;
3341 char endc;
3342 symbolS *csect;
3343 symbolS *sym;
3344
3345 if (ppc_current_block != NULL)
3346 as_bad (_("nested .bs blocks"));
3347
3348 name = input_line_pointer;
3349 endc = get_symbol_end ();
3350
3351 csect = symbol_find_or_make (name);
3352
3353 *input_line_pointer = endc;
3354
3355 sym = symbol_make (".bs");
3356 S_SET_SEGMENT (sym, now_seg);
3357 S_SET_STORAGE_CLASS (sym, C_BSTAT);
3358 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3359 symbol_get_tc (sym)->output = 1;
3360
3361 symbol_get_tc (sym)->within = csect;
3362
3363 ppc_frob_label (sym);
3364
3365 ppc_current_block = sym;
3366
3367 demand_empty_rest_of_line ();
3368 }
3369
3370 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3371
3372 static void
3373 ppc_es (ignore)
3374 int ignore ATTRIBUTE_UNUSED;
3375 {
3376 symbolS *sym;
3377
3378 if (ppc_current_block == NULL)
3379 as_bad (_(".es without preceding .bs"));
3380
3381 sym = symbol_make (".es");
3382 S_SET_SEGMENT (sym, now_seg);
3383 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3384 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3385 symbol_get_tc (sym)->output = 1;
3386
3387 ppc_frob_label (sym);
3388
3389 ppc_current_block = NULL;
3390
3391 demand_empty_rest_of_line ();
3392 }
3393
3394 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3395 line number. */
3396
3397 static void
3398 ppc_bb (ignore)
3399 int ignore ATTRIBUTE_UNUSED;
3400 {
3401 symbolS *sym;
3402
3403 sym = symbol_make (".bb");
3404 S_SET_SEGMENT (sym, text_section);
3405 symbol_set_frag (sym, frag_now);
3406 S_SET_VALUE (sym, frag_now_fix ());
3407 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3408
3409 S_SET_NUMBER_AUXILIARY (sym, 1);
3410 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3411
3412 symbol_get_tc (sym)->output = 1;
3413
3414 SF_SET_PROCESS (sym);
3415
3416 ppc_frob_label (sym);
3417
3418 demand_empty_rest_of_line ();
3419 }
3420
3421 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3422 line number. */
3423
3424 static void
3425 ppc_eb (ignore)
3426 int ignore ATTRIBUTE_UNUSED;
3427 {
3428 symbolS *sym;
3429
3430 sym = symbol_make (".eb");
3431 S_SET_SEGMENT (sym, text_section);
3432 symbol_set_frag (sym, frag_now);
3433 S_SET_VALUE (sym, frag_now_fix ());
3434 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3435 S_SET_NUMBER_AUXILIARY (sym, 1);
3436 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3437 symbol_get_tc (sym)->output = 1;
3438
3439 SF_SET_PROCESS (sym);
3440
3441 ppc_frob_label (sym);
3442
3443 demand_empty_rest_of_line ();
3444 }
3445
3446 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3447 specified name. */
3448
3449 static void
3450 ppc_bc (ignore)
3451 int ignore ATTRIBUTE_UNUSED;
3452 {
3453 char *name;
3454 int len;
3455 symbolS *sym;
3456
3457 name = demand_copy_C_string (&len);
3458 sym = symbol_make (name);
3459 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3460 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3461 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3462 S_SET_VALUE (sym, 0);
3463 symbol_get_tc (sym)->output = 1;
3464
3465 ppc_frob_label (sym);
3466
3467 demand_empty_rest_of_line ();
3468 }
3469
3470 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3471
3472 static void
3473 ppc_ec (ignore)
3474 int ignore ATTRIBUTE_UNUSED;
3475 {
3476 symbolS *sym;
3477
3478 sym = symbol_make (".ec");
3479 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3480 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3481 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3482 S_SET_VALUE (sym, 0);
3483 symbol_get_tc (sym)->output = 1;
3484
3485 ppc_frob_label (sym);
3486
3487 demand_empty_rest_of_line ();
3488 }
3489
3490 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3491
3492 static void
3493 ppc_toc (ignore)
3494 int ignore ATTRIBUTE_UNUSED;
3495 {
3496 if (ppc_toc_csect != (symbolS *) NULL)
3497 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3498 else
3499 {
3500 subsegT subseg;
3501 symbolS *sym;
3502 symbolS *list;
3503
3504 subseg = ppc_data_subsegment;
3505 ++ppc_data_subsegment;
3506
3507 subseg_new (segment_name (data_section), subseg);
3508 ppc_toc_frag = frag_now;
3509
3510 sym = symbol_find_or_make ("TOC[TC0]");
3511 symbol_set_frag (sym, frag_now);
3512 S_SET_SEGMENT (sym, data_section);
3513 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3514 symbol_get_tc (sym)->subseg = subseg;
3515 symbol_get_tc (sym)->output = 1;
3516 symbol_get_tc (sym)->within = sym;
3517
3518 ppc_toc_csect = sym;
3519
3520 for (list = ppc_data_csects;
3521 symbol_get_tc (list)->next != (symbolS *) NULL;
3522 list = symbol_get_tc (list)->next)
3523 ;
3524 symbol_get_tc (list)->next = sym;
3525
3526 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3527 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3528 &symbol_lastP);
3529 }
3530
3531 ppc_current_csect = ppc_toc_csect;
3532
3533 demand_empty_rest_of_line ();
3534 }
3535
3536 /* The AIX assembler automatically aligns the operands of a .long or
3537 .short pseudo-op, and we want to be compatible. */
3538
3539 static void
3540 ppc_xcoff_cons (log_size)
3541 int log_size;
3542 {
3543 frag_align (log_size, 0, 0);
3544 record_alignment (now_seg, log_size);
3545 cons (1 << log_size);
3546 }
3547
3548 static void
3549 ppc_vbyte (dummy)
3550 int dummy ATTRIBUTE_UNUSED;
3551 {
3552 expressionS exp;
3553 int byte_count;
3554
3555 (void) expression (&exp);
3556
3557 if (exp.X_op != O_constant)
3558 {
3559 as_bad (_("non-constant byte count"));
3560 return;
3561 }
3562
3563 byte_count = exp.X_add_number;
3564
3565 if (*input_line_pointer != ',')
3566 {
3567 as_bad (_("missing value"));
3568 return;
3569 }
3570
3571 ++input_line_pointer;
3572 cons (byte_count);
3573 }
3574
3575 #endif /* OBJ_XCOFF */
3576 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3577 \f
3578 /* The .tc pseudo-op. This is used when generating either XCOFF or
3579 ELF. This takes two or more arguments.
3580
3581 When generating XCOFF output, the first argument is the name to
3582 give to this location in the toc; this will be a symbol with class
3583 TC. The rest of the arguments are N-byte values to actually put at
3584 this location in the TOC; often there is just one more argument, a
3585 relocateable symbol reference. The size of the value to store
3586 depends on target word size. A 32-bit target uses 4-byte values, a
3587 64-bit target uses 8-byte values.
3588
3589 When not generating XCOFF output, the arguments are the same, but
3590 the first argument is simply ignored. */
3591
3592 static void
3593 ppc_tc (ignore)
3594 int ignore ATTRIBUTE_UNUSED;
3595 {
3596 #ifdef OBJ_XCOFF
3597
3598 /* Define the TOC symbol name. */
3599 {
3600 char *name;
3601 char endc;
3602 symbolS *sym;
3603
3604 if (ppc_toc_csect == (symbolS *) NULL
3605 || ppc_toc_csect != ppc_current_csect)
3606 {
3607 as_bad (_(".tc not in .toc section"));
3608 ignore_rest_of_line ();
3609 return;
3610 }
3611
3612 name = input_line_pointer;
3613 endc = get_symbol_end ();
3614
3615 sym = symbol_find_or_make (name);
3616
3617 *input_line_pointer = endc;
3618
3619 if (S_IS_DEFINED (sym))
3620 {
3621 symbolS *label;
3622
3623 label = symbol_get_tc (ppc_current_csect)->within;
3624 if (symbol_get_tc (label)->class != XMC_TC0)
3625 {
3626 as_bad (_(".tc with no label"));
3627 ignore_rest_of_line ();
3628 return;
3629 }
3630
3631 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3632 symbol_set_frag (label, symbol_get_frag (sym));
3633 S_SET_VALUE (label, S_GET_VALUE (sym));
3634
3635 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3636 ++input_line_pointer;
3637
3638 return;
3639 }
3640
3641 S_SET_SEGMENT (sym, now_seg);
3642 symbol_set_frag (sym, frag_now);
3643 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3644 symbol_get_tc (sym)->class = XMC_TC;
3645 symbol_get_tc (sym)->output = 1;
3646
3647 ppc_frob_label (sym);
3648 }
3649
3650 #endif /* OBJ_XCOFF */
3651 #ifdef OBJ_ELF
3652 int align;
3653
3654 /* Skip the TOC symbol name. */
3655 while (is_part_of_name (*input_line_pointer)
3656 || *input_line_pointer == '['
3657 || *input_line_pointer == ']'
3658 || *input_line_pointer == '{'
3659 || *input_line_pointer == '}')
3660 ++input_line_pointer;
3661
3662 /* Align to a four/eight byte boundary. */
3663 align = BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64 ? 3 : 2;
3664 frag_align (align, 0, 0);
3665 record_alignment (now_seg, align);
3666 #endif /* OBJ_ELF */
3667
3668 if (*input_line_pointer != ',')
3669 demand_empty_rest_of_line ();
3670 else
3671 {
3672 ++input_line_pointer;
3673 cons ((ppc_size == PPC_OPCODE_64) ? 8 : 4);
3674 }
3675 }
3676
3677 /* Pseudo-op .machine. */
3678 /* FIXME: `.machine' is a nop for the moment. It would be nice to
3679 accept this directive on the first line of input and set ppc_size
3680 and the target format accordingly. Unfortunately, the target
3681 format is selected in output-file.c:output_file_create before we
3682 even get to md_begin, so it's not possible without changing
3683 as.c:main. */
3684
3685 static void
3686 ppc_machine (ignore)
3687 int ignore ATTRIBUTE_UNUSED;
3688 {
3689 discard_rest_of_line ();
3690 }
3691
3692 /* See whether a symbol is in the TOC section. */
3693
3694 static int
3695 ppc_is_toc_sym (sym)
3696 symbolS *sym;
3697 {
3698 #ifdef OBJ_XCOFF
3699 return symbol_get_tc (sym)->class == XMC_TC;
3700 #endif
3701 #ifdef OBJ_ELF
3702 const char *sname = segment_name (S_GET_SEGMENT (sym));
3703 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64)
3704 return strcmp (sname, ".toc") == 0;
3705 else
3706 return strcmp (sname, ".got") == 0;
3707 #endif
3708 }
3709 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3710 \f
3711 #ifdef TE_PE
3712
3713 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3714
3715 /* Set the current section. */
3716 static void
3717 ppc_set_current_section (new)
3718 segT new;
3719 {
3720 ppc_previous_section = ppc_current_section;
3721 ppc_current_section = new;
3722 }
3723
3724 /* pseudo-op: .previous
3725 behaviour: toggles the current section with the previous section.
3726 errors: None
3727 warnings: "No previous section" */
3728
3729 static void
3730 ppc_previous (ignore)
3731 int ignore ATTRIBUTE_UNUSED;
3732 {
3733 symbolS *tmp;
3734
3735 if (ppc_previous_section == NULL)
3736 {
3737 as_warn (_("No previous section to return to. Directive ignored."));
3738 return;
3739 }
3740
3741 subseg_set (ppc_previous_section, 0);
3742
3743 ppc_set_current_section (ppc_previous_section);
3744 }
3745
3746 /* pseudo-op: .pdata
3747 behaviour: predefined read only data section
3748 double word aligned
3749 errors: None
3750 warnings: None
3751 initial: .section .pdata "adr3"
3752 a - don't know -- maybe a misprint
3753 d - initialized data
3754 r - readable
3755 3 - double word aligned (that would be 4 byte boundary)
3756
3757 commentary:
3758 Tag index tables (also known as the function table) for exception
3759 handling, debugging, etc. */
3760
3761 static void
3762 ppc_pdata (ignore)
3763 int ignore ATTRIBUTE_UNUSED;
3764 {
3765 if (pdata_section == 0)
3766 {
3767 pdata_section = subseg_new (".pdata", 0);
3768
3769 bfd_set_section_flags (stdoutput, pdata_section,
3770 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3771 | SEC_READONLY | SEC_DATA ));
3772
3773 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3774 }
3775 else
3776 {
3777 pdata_section = subseg_new (".pdata", 0);
3778 }
3779 ppc_set_current_section (pdata_section);
3780 }
3781
3782 /* pseudo-op: .ydata
3783 behaviour: predefined read only data section
3784 double word aligned
3785 errors: None
3786 warnings: None
3787 initial: .section .ydata "drw3"
3788 a - don't know -- maybe a misprint
3789 d - initialized data
3790 r - readable
3791 3 - double word aligned (that would be 4 byte boundary)
3792 commentary:
3793 Tag tables (also known as the scope table) for exception handling,
3794 debugging, etc. */
3795
3796 static void
3797 ppc_ydata (ignore)
3798 int ignore ATTRIBUTE_UNUSED;
3799 {
3800 if (ydata_section == 0)
3801 {
3802 ydata_section = subseg_new (".ydata", 0);
3803 bfd_set_section_flags (stdoutput, ydata_section,
3804 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3805 | SEC_READONLY | SEC_DATA ));
3806
3807 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3808 }
3809 else
3810 {
3811 ydata_section = subseg_new (".ydata", 0);
3812 }
3813 ppc_set_current_section (ydata_section);
3814 }
3815
3816 /* pseudo-op: .reldata
3817 behaviour: predefined read write data section
3818 double word aligned (4-byte)
3819 FIXME: relocation is applied to it
3820 FIXME: what's the difference between this and .data?
3821 errors: None
3822 warnings: None
3823 initial: .section .reldata "drw3"
3824 d - initialized data
3825 r - readable
3826 w - writeable
3827 3 - double word aligned (that would be 8 byte boundary)
3828
3829 commentary:
3830 Like .data, but intended to hold data subject to relocation, such as
3831 function descriptors, etc. */
3832
3833 static void
3834 ppc_reldata (ignore)
3835 int ignore ATTRIBUTE_UNUSED;
3836 {
3837 if (reldata_section == 0)
3838 {
3839 reldata_section = subseg_new (".reldata", 0);
3840
3841 bfd_set_section_flags (stdoutput, reldata_section,
3842 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3843 | SEC_DATA));
3844
3845 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3846 }
3847 else
3848 {
3849 reldata_section = subseg_new (".reldata", 0);
3850 }
3851 ppc_set_current_section (reldata_section);
3852 }
3853
3854 /* pseudo-op: .rdata
3855 behaviour: predefined read only data section
3856 double word aligned
3857 errors: None
3858 warnings: None
3859 initial: .section .rdata "dr3"
3860 d - initialized data
3861 r - readable
3862 3 - double word aligned (that would be 4 byte boundary) */
3863
3864 static void
3865 ppc_rdata (ignore)
3866 int ignore ATTRIBUTE_UNUSED;
3867 {
3868 if (rdata_section == 0)
3869 {
3870 rdata_section = subseg_new (".rdata", 0);
3871 bfd_set_section_flags (stdoutput, rdata_section,
3872 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3873 | SEC_READONLY | SEC_DATA ));
3874
3875 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3876 }
3877 else
3878 {
3879 rdata_section = subseg_new (".rdata", 0);
3880 }
3881 ppc_set_current_section (rdata_section);
3882 }
3883
3884 /* pseudo-op: .ualong
3885 behaviour: much like .int, with the exception that no alignment is
3886 performed.
3887 FIXME: test the alignment statement
3888 errors: None
3889 warnings: None */
3890
3891 static void
3892 ppc_ualong (ignore)
3893 int ignore ATTRIBUTE_UNUSED;
3894 {
3895 /* Try for long. */
3896 cons (4);
3897 }
3898
3899 /* pseudo-op: .znop <symbol name>
3900 behaviour: Issue a nop instruction
3901 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3902 the supplied symbol name.
3903 errors: None
3904 warnings: Missing symbol name */
3905
3906 static void
3907 ppc_znop (ignore)
3908 int ignore ATTRIBUTE_UNUSED;
3909 {
3910 unsigned long insn;
3911 const struct powerpc_opcode *opcode;
3912 expressionS ex;
3913 char *f;
3914 symbolS *sym;
3915 char *symbol_name;
3916 char c;
3917 char *name;
3918 unsigned int exp;
3919 flagword flags;
3920 asection *sec;
3921
3922 /* Strip out the symbol name. */
3923 symbol_name = input_line_pointer;
3924 c = get_symbol_end ();
3925
3926 name = xmalloc (input_line_pointer - symbol_name + 1);
3927 strcpy (name, symbol_name);
3928
3929 sym = symbol_find_or_make (name);
3930
3931 *input_line_pointer = c;
3932
3933 SKIP_WHITESPACE ();
3934
3935 /* Look up the opcode in the hash table. */
3936 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3937
3938 /* Stick in the nop. */
3939 insn = opcode->opcode;
3940
3941 /* Write out the instruction. */
3942 f = frag_more (4);
3943 md_number_to_chars (f, insn, 4);
3944 fix_new (frag_now,
3945 f - frag_now->fr_literal,
3946 4,
3947 sym,
3948 0,
3949 0,
3950 BFD_RELOC_16_GOT_PCREL);
3951
3952 }
3953
3954 /* pseudo-op:
3955 behaviour:
3956 errors:
3957 warnings: */
3958
3959 static void
3960 ppc_pe_comm (lcomm)
3961 int lcomm;
3962 {
3963 register char *name;
3964 register char c;
3965 register char *p;
3966 offsetT temp;
3967 register symbolS *symbolP;
3968 offsetT align;
3969
3970 name = input_line_pointer;
3971 c = get_symbol_end ();
3972
3973 /* just after name is now '\0'. */
3974 p = input_line_pointer;
3975 *p = c;
3976 SKIP_WHITESPACE ();
3977 if (*input_line_pointer != ',')
3978 {
3979 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3980 ignore_rest_of_line ();
3981 return;
3982 }
3983
3984 input_line_pointer++; /* skip ',' */
3985 if ((temp = get_absolute_expression ()) < 0)
3986 {
3987 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3988 ignore_rest_of_line ();
3989 return;
3990 }
3991
3992 if (! lcomm)
3993 {
3994 /* The third argument to .comm is the alignment. */
3995 if (*input_line_pointer != ',')
3996 align = 3;
3997 else
3998 {
3999 ++input_line_pointer;
4000 align = get_absolute_expression ();
4001 if (align <= 0)
4002 {
4003 as_warn (_("ignoring bad alignment"));
4004 align = 3;
4005 }
4006 }
4007 }
4008
4009 *p = 0;
4010 symbolP = symbol_find_or_make (name);
4011
4012 *p = c;
4013 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4014 {
4015 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4016 S_GET_NAME (symbolP));
4017 ignore_rest_of_line ();
4018 return;
4019 }
4020
4021 if (S_GET_VALUE (symbolP))
4022 {
4023 if (S_GET_VALUE (symbolP) != (valueT) temp)
4024 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4025 S_GET_NAME (symbolP),
4026 (long) S_GET_VALUE (symbolP),
4027 (long) temp);
4028 }
4029 else
4030 {
4031 S_SET_VALUE (symbolP, (valueT) temp);
4032 S_SET_EXTERNAL (symbolP);
4033 }
4034
4035 demand_empty_rest_of_line ();
4036 }
4037
4038 /*
4039 * implement the .section pseudo op:
4040 * .section name {, "flags"}
4041 * ^ ^
4042 * | +--- optional flags: 'b' for bss
4043 * | 'i' for info
4044 * +-- section name 'l' for lib
4045 * 'n' for noload
4046 * 'o' for over
4047 * 'w' for data
4048 * 'd' (apparently m88k for data)
4049 * 'x' for text
4050 * But if the argument is not a quoted string, treat it as a
4051 * subsegment number.
4052 *
4053 * FIXME: this is a copy of the section processing from obj-coff.c, with
4054 * additions/changes for the moto-pas assembler support. There are three
4055 * categories:
4056 *
4057 * FIXME: I just noticed this. This doesn't work at all really. It it
4058 * setting bits that bfd probably neither understands or uses. The
4059 * correct approach (?) will have to incorporate extra fields attached
4060 * to the section to hold the system specific stuff. (krk)
4061 *
4062 * Section Contents:
4063 * 'a' - unknown - referred to in documentation, but no definition supplied
4064 * 'c' - section has code
4065 * 'd' - section has initialized data
4066 * 'u' - section has uninitialized data
4067 * 'i' - section contains directives (info)
4068 * 'n' - section can be discarded
4069 * 'R' - remove section at link time
4070 *
4071 * Section Protection:
4072 * 'r' - section is readable
4073 * 'w' - section is writeable
4074 * 'x' - section is executable
4075 * 's' - section is sharable
4076 *
4077 * Section Alignment:
4078 * '0' - align to byte boundary
4079 * '1' - align to halfword undary
4080 * '2' - align to word boundary
4081 * '3' - align to doubleword boundary
4082 * '4' - align to quadword boundary
4083 * '5' - align to 32 byte boundary
4084 * '6' - align to 64 byte boundary
4085 *
4086 */
4087
4088 void
4089 ppc_pe_section (ignore)
4090 int ignore ATTRIBUTE_UNUSED;
4091 {
4092 /* Strip out the section name. */
4093 char *section_name;
4094 char c;
4095 char *name;
4096 unsigned int exp;
4097 flagword flags;
4098 segT sec;
4099 int align;
4100
4101 section_name = input_line_pointer;
4102 c = get_symbol_end ();
4103
4104 name = xmalloc (input_line_pointer - section_name + 1);
4105 strcpy (name, section_name);
4106
4107 *input_line_pointer = c;
4108
4109 SKIP_WHITESPACE ();
4110
4111 exp = 0;
4112 flags = SEC_NO_FLAGS;
4113
4114 if (strcmp (name, ".idata$2") == 0)
4115 {
4116 align = 0;
4117 }
4118 else if (strcmp (name, ".idata$3") == 0)
4119 {
4120 align = 0;
4121 }
4122 else if (strcmp (name, ".idata$4") == 0)
4123 {
4124 align = 2;
4125 }
4126 else if (strcmp (name, ".idata$5") == 0)
4127 {
4128 align = 2;
4129 }
4130 else if (strcmp (name, ".idata$6") == 0)
4131 {
4132 align = 1;
4133 }
4134 else
4135 /* Default alignment to 16 byte boundary. */
4136 align = 4;
4137
4138 if (*input_line_pointer == ',')
4139 {
4140 ++input_line_pointer;
4141 SKIP_WHITESPACE ();
4142 if (*input_line_pointer != '"')
4143 exp = get_absolute_expression ();
4144 else
4145 {
4146 ++input_line_pointer;
4147 while (*input_line_pointer != '"'
4148 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4149 {
4150 switch (*input_line_pointer)
4151 {
4152 /* Section Contents */
4153 case 'a': /* unknown */
4154 as_bad (_("Unsupported section attribute -- 'a'"));
4155 break;
4156 case 'c': /* code section */
4157 flags |= SEC_CODE;
4158 break;
4159 case 'd': /* section has initialized data */
4160 flags |= SEC_DATA;
4161 break;
4162 case 'u': /* section has uninitialized data */
4163 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4164 in winnt.h */
4165 flags |= SEC_ROM;
4166 break;
4167 case 'i': /* section contains directives (info) */
4168 /* FIXME: This is IMAGE_SCN_LNK_INFO
4169 in winnt.h */
4170 flags |= SEC_HAS_CONTENTS;
4171 break;
4172 case 'n': /* section can be discarded */
4173 flags &=~ SEC_LOAD;
4174 break;
4175 case 'R': /* Remove section at link time */
4176 flags |= SEC_NEVER_LOAD;
4177 break;
4178
4179 /* Section Protection */
4180 case 'r': /* section is readable */
4181 flags |= IMAGE_SCN_MEM_READ;
4182 break;
4183 case 'w': /* section is writeable */
4184 flags |= IMAGE_SCN_MEM_WRITE;
4185 break;
4186 case 'x': /* section is executable */
4187 flags |= IMAGE_SCN_MEM_EXECUTE;
4188 break;
4189 case 's': /* section is sharable */
4190 flags |= IMAGE_SCN_MEM_SHARED;
4191 break;
4192
4193 /* Section Alignment */
4194 case '0': /* align to byte boundary */
4195 flags |= IMAGE_SCN_ALIGN_1BYTES;
4196 align = 0;
4197 break;
4198 case '1': /* align to halfword boundary */
4199 flags |= IMAGE_SCN_ALIGN_2BYTES;
4200 align = 1;
4201 break;
4202 case '2': /* align to word boundary */
4203 flags |= IMAGE_SCN_ALIGN_4BYTES;
4204 align = 2;
4205 break;
4206 case '3': /* align to doubleword boundary */
4207 flags |= IMAGE_SCN_ALIGN_8BYTES;
4208 align = 3;
4209 break;
4210 case '4': /* align to quadword boundary */
4211 flags |= IMAGE_SCN_ALIGN_16BYTES;
4212 align = 4;
4213 break;
4214 case '5': /* align to 32 byte boundary */
4215 flags |= IMAGE_SCN_ALIGN_32BYTES;
4216 align = 5;
4217 break;
4218 case '6': /* align to 64 byte boundary */
4219 flags |= IMAGE_SCN_ALIGN_64BYTES;
4220 align = 6;
4221 break;
4222
4223 default:
4224 as_bad (_("unknown section attribute '%c'"),
4225 *input_line_pointer);
4226 break;
4227 }
4228 ++input_line_pointer;
4229 }
4230 if (*input_line_pointer == '"')
4231 ++input_line_pointer;
4232 }
4233 }
4234
4235 sec = subseg_new (name, (subsegT) exp);
4236
4237 ppc_set_current_section (sec);
4238
4239 if (flags != SEC_NO_FLAGS)
4240 {
4241 if (! bfd_set_section_flags (stdoutput, sec, flags))
4242 as_bad (_("error setting flags for \"%s\": %s"),
4243 bfd_section_name (stdoutput, sec),
4244 bfd_errmsg (bfd_get_error ()));
4245 }
4246
4247 bfd_set_section_alignment (stdoutput, sec, align);
4248
4249 }
4250
4251 static void
4252 ppc_pe_function (ignore)
4253 int ignore ATTRIBUTE_UNUSED;
4254 {
4255 char *name;
4256 char endc;
4257 symbolS *ext_sym;
4258
4259 name = input_line_pointer;
4260 endc = get_symbol_end ();
4261
4262 ext_sym = symbol_find_or_make (name);
4263
4264 *input_line_pointer = endc;
4265
4266 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4267 SF_SET_FUNCTION (ext_sym);
4268 SF_SET_PROCESS (ext_sym);
4269 coff_add_linesym (ext_sym);
4270
4271 demand_empty_rest_of_line ();
4272 }
4273
4274 static void
4275 ppc_pe_tocd (ignore)
4276 int ignore ATTRIBUTE_UNUSED;
4277 {
4278 if (tocdata_section == 0)
4279 {
4280 tocdata_section = subseg_new (".tocd", 0);
4281 /* FIXME: section flags won't work. */
4282 bfd_set_section_flags (stdoutput, tocdata_section,
4283 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4284 | SEC_READONLY | SEC_DATA));
4285
4286 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4287 }
4288 else
4289 {
4290 rdata_section = subseg_new (".tocd", 0);
4291 }
4292
4293 ppc_set_current_section (tocdata_section);
4294
4295 demand_empty_rest_of_line ();
4296 }
4297
4298 /* Don't adjust TOC relocs to use the section symbol. */
4299
4300 int
4301 ppc_pe_fix_adjustable (fix)
4302 fixS *fix;
4303 {
4304 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4305 }
4306
4307 #endif
4308 \f
4309 #ifdef OBJ_XCOFF
4310
4311 /* XCOFF specific symbol and file handling. */
4312
4313 /* Canonicalize the symbol name. We use the to force the suffix, if
4314 any, to use square brackets, and to be in upper case. */
4315
4316 char *
4317 ppc_canonicalize_symbol_name (name)
4318 char *name;
4319 {
4320 char *s;
4321
4322 if (ppc_stab_symbol)
4323 return name;
4324
4325 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4326 ;
4327 if (*s != '\0')
4328 {
4329 char brac;
4330
4331 if (*s == '[')
4332 brac = ']';
4333 else
4334 {
4335 *s = '[';
4336 brac = '}';
4337 }
4338
4339 for (s++; *s != '\0' && *s != brac; s++)
4340 *s = TOUPPER (*s);
4341
4342 if (*s == '\0' || s[1] != '\0')
4343 as_bad (_("bad symbol suffix"));
4344
4345 *s = ']';
4346 }
4347
4348 return name;
4349 }
4350
4351 /* Set the class of a symbol based on the suffix, if any. This is
4352 called whenever a new symbol is created. */
4353
4354 void
4355 ppc_symbol_new_hook (sym)
4356 symbolS *sym;
4357 {
4358 struct ppc_tc_sy *tc;
4359 const char *s;
4360
4361 tc = symbol_get_tc (sym);
4362 tc->next = NULL;
4363 tc->output = 0;
4364 tc->class = -1;
4365 tc->real_name = NULL;
4366 tc->subseg = 0;
4367 tc->align = 0;
4368 tc->size = NULL;
4369 tc->within = NULL;
4370
4371 if (ppc_stab_symbol)
4372 return;
4373
4374 s = strchr (S_GET_NAME (sym), '[');
4375 if (s == (const char *) NULL)
4376 {
4377 /* There is no suffix. */
4378 return;
4379 }
4380
4381 ++s;
4382
4383 switch (s[0])
4384 {
4385 case 'B':
4386 if (strcmp (s, "BS]") == 0)
4387 tc->class = XMC_BS;
4388 break;
4389 case 'D':
4390 if (strcmp (s, "DB]") == 0)
4391 tc->class = XMC_DB;
4392 else if (strcmp (s, "DS]") == 0)
4393 tc->class = XMC_DS;
4394 break;
4395 case 'G':
4396 if (strcmp (s, "GL]") == 0)
4397 tc->class = XMC_GL;
4398 break;
4399 case 'P':
4400 if (strcmp (s, "PR]") == 0)
4401 tc->class = XMC_PR;
4402 break;
4403 case 'R':
4404 if (strcmp (s, "RO]") == 0)
4405 tc->class = XMC_RO;
4406 else if (strcmp (s, "RW]") == 0)
4407 tc->class = XMC_RW;
4408 break;
4409 case 'S':
4410 if (strcmp (s, "SV]") == 0)
4411 tc->class = XMC_SV;
4412 break;
4413 case 'T':
4414 if (strcmp (s, "TC]") == 0)
4415 tc->class = XMC_TC;
4416 else if (strcmp (s, "TI]") == 0)
4417 tc->class = XMC_TI;
4418 else if (strcmp (s, "TB]") == 0)
4419 tc->class = XMC_TB;
4420 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
4421 tc->class = XMC_TC0;
4422 break;
4423 case 'U':
4424 if (strcmp (s, "UA]") == 0)
4425 tc->class = XMC_UA;
4426 else if (strcmp (s, "UC]") == 0)
4427 tc->class = XMC_UC;
4428 break;
4429 case 'X':
4430 if (strcmp (s, "XO]") == 0)
4431 tc->class = XMC_XO;
4432 break;
4433 }
4434
4435 if (tc->class == -1)
4436 as_bad (_("Unrecognized symbol suffix"));
4437 }
4438
4439 /* Set the class of a label based on where it is defined. This
4440 handles symbols without suffixes. Also, move the symbol so that it
4441 follows the csect symbol. */
4442
4443 void
4444 ppc_frob_label (sym)
4445 symbolS *sym;
4446 {
4447 if (ppc_current_csect != (symbolS *) NULL)
4448 {
4449 if (symbol_get_tc (sym)->class == -1)
4450 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4451
4452 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4453 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4454 &symbol_rootP, &symbol_lastP);
4455 symbol_get_tc (ppc_current_csect)->within = sym;
4456 }
4457 }
4458
4459 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4460 seen. It tells ppc_adjust_symtab whether it needs to look through
4461 the symbols. */
4462
4463 static boolean ppc_saw_abs;
4464
4465 /* Change the name of a symbol just before writing it out. Set the
4466 real name if the .rename pseudo-op was used. Otherwise, remove any
4467 class suffix. Return 1 if the symbol should not be included in the
4468 symbol table. */
4469
4470 int
4471 ppc_frob_symbol (sym)
4472 symbolS *sym;
4473 {
4474 static symbolS *ppc_last_function;
4475 static symbolS *set_end;
4476
4477 /* Discard symbols that should not be included in the output symbol
4478 table. */
4479 if (! symbol_used_in_reloc_p (sym)
4480 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4481 || (! S_IS_EXTERNAL (sym)
4482 && ! symbol_get_tc (sym)->output
4483 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4484 return 1;
4485
4486 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4487 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4488 else
4489 {
4490 const char *name;
4491 const char *s;
4492
4493 name = S_GET_NAME (sym);
4494 s = strchr (name, '[');
4495 if (s != (char *) NULL)
4496 {
4497 unsigned int len;
4498 char *snew;
4499
4500 len = s - name;
4501 snew = xmalloc (len + 1);
4502 memcpy (snew, name, len);
4503 snew[len] = '\0';
4504
4505 S_SET_NAME (sym, snew);
4506 }
4507 }
4508
4509 if (set_end != (symbolS *) NULL)
4510 {
4511 SA_SET_SYM_ENDNDX (set_end, sym);
4512 set_end = NULL;
4513 }
4514
4515 if (SF_GET_FUNCTION (sym))
4516 {
4517 if (ppc_last_function != (symbolS *) NULL)
4518 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4519 ppc_last_function = sym;
4520 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4521 {
4522 resolve_symbol_value (symbol_get_tc (sym)->size);
4523 SA_SET_SYM_FSIZE (sym,
4524 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4525 }
4526 }
4527 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4528 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4529 {
4530 if (ppc_last_function == (symbolS *) NULL)
4531 as_bad (_(".ef with no preceding .function"));
4532 else
4533 {
4534 set_end = ppc_last_function;
4535 ppc_last_function = NULL;
4536
4537 /* We don't have a C_EFCN symbol, but we need to force the
4538 COFF backend to believe that it has seen one. */
4539 coff_last_function = NULL;
4540 }
4541 }
4542
4543 if (! S_IS_EXTERNAL (sym)
4544 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4545 && S_GET_STORAGE_CLASS (sym) != C_FILE
4546 && S_GET_STORAGE_CLASS (sym) != C_FCN
4547 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4548 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4549 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4550 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4551 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4552 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4553 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4554
4555 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4556 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4557 {
4558 int i;
4559 union internal_auxent *a;
4560
4561 /* Create a csect aux. */
4562 i = S_GET_NUMBER_AUXILIARY (sym);
4563 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4564 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4565 if (symbol_get_tc (sym)->class == XMC_TC0)
4566 {
4567 /* This is the TOC table. */
4568 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4569 a->x_csect.x_scnlen.l = 0;
4570 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4571 }
4572 else if (symbol_get_tc (sym)->subseg != 0)
4573 {
4574 /* This is a csect symbol. x_scnlen is the size of the
4575 csect. */
4576 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4577 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4578 S_GET_SEGMENT (sym))
4579 - S_GET_VALUE (sym));
4580 else
4581 {
4582 resolve_symbol_value (symbol_get_tc (sym)->next);
4583 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4584 - S_GET_VALUE (sym));
4585 }
4586 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4587 }
4588 else if (S_GET_SEGMENT (sym) == bss_section)
4589 {
4590 /* This is a common symbol. */
4591 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4592 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4593 if (S_IS_EXTERNAL (sym))
4594 symbol_get_tc (sym)->class = XMC_RW;
4595 else
4596 symbol_get_tc (sym)->class = XMC_BS;
4597 }
4598 else if (S_GET_SEGMENT (sym) == absolute_section)
4599 {
4600 /* This is an absolute symbol. The csect will be created by
4601 ppc_adjust_symtab. */
4602 ppc_saw_abs = true;
4603 a->x_csect.x_smtyp = XTY_LD;
4604 if (symbol_get_tc (sym)->class == -1)
4605 symbol_get_tc (sym)->class = XMC_XO;
4606 }
4607 else if (! S_IS_DEFINED (sym))
4608 {
4609 /* This is an external symbol. */
4610 a->x_csect.x_scnlen.l = 0;
4611 a->x_csect.x_smtyp = XTY_ER;
4612 }
4613 else if (symbol_get_tc (sym)->class == XMC_TC)
4614 {
4615 symbolS *next;
4616
4617 /* This is a TOC definition. x_scnlen is the size of the
4618 TOC entry. */
4619 next = symbol_next (sym);
4620 while (symbol_get_tc (next)->class == XMC_TC0)
4621 next = symbol_next (next);
4622 if (next == (symbolS *) NULL
4623 || symbol_get_tc (next)->class != XMC_TC)
4624 {
4625 if (ppc_after_toc_frag == (fragS *) NULL)
4626 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4627 data_section)
4628 - S_GET_VALUE (sym));
4629 else
4630 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4631 - S_GET_VALUE (sym));
4632 }
4633 else
4634 {
4635 resolve_symbol_value (next);
4636 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4637 - S_GET_VALUE (sym));
4638 }
4639 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4640 }
4641 else
4642 {
4643 symbolS *csect;
4644
4645 /* This is a normal symbol definition. x_scnlen is the
4646 symbol index of the containing csect. */
4647 if (S_GET_SEGMENT (sym) == text_section)
4648 csect = ppc_text_csects;
4649 else if (S_GET_SEGMENT (sym) == data_section)
4650 csect = ppc_data_csects;
4651 else
4652 abort ();
4653
4654 /* Skip the initial dummy symbol. */
4655 csect = symbol_get_tc (csect)->next;
4656
4657 if (csect == (symbolS *) NULL)
4658 {
4659 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4660 a->x_csect.x_scnlen.l = 0;
4661 }
4662 else
4663 {
4664 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
4665 {
4666 resolve_symbol_value (symbol_get_tc (csect)->next);
4667 if (S_GET_VALUE (symbol_get_tc (csect)->next)
4668 > S_GET_VALUE (sym))
4669 break;
4670 csect = symbol_get_tc (csect)->next;
4671 }
4672
4673 a->x_csect.x_scnlen.p =
4674 coffsymbol (symbol_get_bfdsym (csect))->native;
4675 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
4676 1;
4677 }
4678 a->x_csect.x_smtyp = XTY_LD;
4679 }
4680
4681 a->x_csect.x_parmhash = 0;
4682 a->x_csect.x_snhash = 0;
4683 if (symbol_get_tc (sym)->class == -1)
4684 a->x_csect.x_smclas = XMC_PR;
4685 else
4686 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
4687 a->x_csect.x_stab = 0;
4688 a->x_csect.x_snstab = 0;
4689
4690 /* Don't let the COFF backend resort these symbols. */
4691 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
4692 }
4693 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4694 {
4695 /* We want the value to be the symbol index of the referenced
4696 csect symbol. BFD will do that for us if we set the right
4697 flags. */
4698 S_SET_VALUE (sym,
4699 ((valueT)
4700 coffsymbol (symbol_get_bfdsym
4701 (symbol_get_tc (sym)->within))->native));
4702 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
4703 }
4704 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4705 {
4706 symbolS *block;
4707 symbolS *csect;
4708
4709 /* The value is the offset from the enclosing csect. */
4710 block = symbol_get_tc (sym)->within;
4711 csect = symbol_get_tc (block)->within;
4712 resolve_symbol_value (csect);
4713 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4714 }
4715 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4716 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4717 {
4718 /* We want the value to be a file offset into the line numbers.
4719 BFD will do that for us if we set the right flags. We have
4720 already set the value correctly. */
4721 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
4722 }
4723
4724 return 0;
4725 }
4726
4727 /* Adjust the symbol table. This creates csect symbols for all
4728 absolute symbols. */
4729
4730 void
4731 ppc_adjust_symtab ()
4732 {
4733 symbolS *sym;
4734
4735 if (! ppc_saw_abs)
4736 return;
4737
4738 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4739 {
4740 symbolS *csect;
4741 int i;
4742 union internal_auxent *a;
4743
4744 if (S_GET_SEGMENT (sym) != absolute_section)
4745 continue;
4746
4747 csect = symbol_create (".abs[XO]", absolute_section,
4748 S_GET_VALUE (sym), &zero_address_frag);
4749 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
4750 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4751 i = S_GET_NUMBER_AUXILIARY (csect);
4752 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4753 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
4754 a->x_csect.x_scnlen.l = 0;
4755 a->x_csect.x_smtyp = XTY_SD;
4756 a->x_csect.x_parmhash = 0;
4757 a->x_csect.x_snhash = 0;
4758 a->x_csect.x_smclas = XMC_XO;
4759 a->x_csect.x_stab = 0;
4760 a->x_csect.x_snstab = 0;
4761
4762 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4763
4764 i = S_GET_NUMBER_AUXILIARY (sym);
4765 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
4766 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
4767 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
4768 }
4769
4770 ppc_saw_abs = false;
4771 }
4772
4773 /* Set the VMA for a section. This is called on all the sections in
4774 turn. */
4775
4776 void
4777 ppc_frob_section (sec)
4778 asection *sec;
4779 {
4780 static bfd_size_type vma = 0;
4781
4782 bfd_set_section_vma (stdoutput, sec, vma);
4783 vma += bfd_section_size (stdoutput, sec);
4784 }
4785
4786 #endif /* OBJ_XCOFF */
4787 \f
4788 /* Turn a string in input_line_pointer into a floating point constant
4789 of type TYPE, and store the appropriate bytes in *LITP. The number
4790 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4791 returned, or NULL on OK. */
4792
4793 char *
4794 md_atof (type, litp, sizep)
4795 int type;
4796 char *litp;
4797 int *sizep;
4798 {
4799 int prec;
4800 LITTLENUM_TYPE words[4];
4801 char *t;
4802 int i;
4803
4804 switch (type)
4805 {
4806 case 'f':
4807 prec = 2;
4808 break;
4809
4810 case 'd':
4811 prec = 4;
4812 break;
4813
4814 default:
4815 *sizep = 0;
4816 return _("bad call to md_atof");
4817 }
4818
4819 t = atof_ieee (input_line_pointer, type, words);
4820 if (t)
4821 input_line_pointer = t;
4822
4823 *sizep = prec * 2;
4824
4825 if (target_big_endian)
4826 {
4827 for (i = 0; i < prec; i++)
4828 {
4829 md_number_to_chars (litp, (valueT) words[i], 2);
4830 litp += 2;
4831 }
4832 }
4833 else
4834 {
4835 for (i = prec - 1; i >= 0; i--)
4836 {
4837 md_number_to_chars (litp, (valueT) words[i], 2);
4838 litp += 2;
4839 }
4840 }
4841
4842 return NULL;
4843 }
4844
4845 /* Write a value out to the object file, using the appropriate
4846 endianness. */
4847
4848 void
4849 md_number_to_chars (buf, val, n)
4850 char *buf;
4851 valueT val;
4852 int n;
4853 {
4854 if (target_big_endian)
4855 number_to_chars_bigendian (buf, val, n);
4856 else
4857 number_to_chars_littleendian (buf, val, n);
4858 }
4859
4860 /* Align a section (I don't know why this is machine dependent). */
4861
4862 valueT
4863 md_section_align (seg, addr)
4864 asection *seg;
4865 valueT addr;
4866 {
4867 int align = bfd_get_section_alignment (stdoutput, seg);
4868
4869 return ((addr + (1 << align) - 1) & (-1 << align));
4870 }
4871
4872 /* We don't have any form of relaxing. */
4873
4874 int
4875 md_estimate_size_before_relax (fragp, seg)
4876 fragS *fragp ATTRIBUTE_UNUSED;
4877 asection *seg ATTRIBUTE_UNUSED;
4878 {
4879 abort ();
4880 return 0;
4881 }
4882
4883 /* Convert a machine dependent frag. We never generate these. */
4884
4885 void
4886 md_convert_frag (abfd, sec, fragp)
4887 bfd *abfd ATTRIBUTE_UNUSED;
4888 asection *sec ATTRIBUTE_UNUSED;
4889 fragS *fragp ATTRIBUTE_UNUSED;
4890 {
4891 abort ();
4892 }
4893
4894 /* We have no need to default values of symbols. */
4895
4896 symbolS *
4897 md_undefined_symbol (name)
4898 char *name ATTRIBUTE_UNUSED;
4899 {
4900 return 0;
4901 }
4902 \f
4903 /* Functions concerning relocs. */
4904
4905 /* The location from which a PC relative jump should be calculated,
4906 given a PC relative reloc. */
4907
4908 long
4909 md_pcrel_from_section (fixp, sec)
4910 fixS *fixp;
4911 segT sec ATTRIBUTE_UNUSED;
4912 {
4913 return fixp->fx_frag->fr_address + fixp->fx_where;
4914 }
4915
4916 #ifdef OBJ_XCOFF
4917
4918 /* This is called to see whether a fixup should be adjusted to use a
4919 section symbol. We take the opportunity to change a fixup against
4920 a symbol in the TOC subsegment into a reloc against the
4921 corresponding .tc symbol. */
4922
4923 int
4924 ppc_fix_adjustable (fix)
4925 fixS *fix;
4926 {
4927 valueT val;
4928
4929 resolve_symbol_value (fix->fx_addsy);
4930 val = S_GET_VALUE (fix->fx_addsy);
4931 if (ppc_toc_csect != (symbolS *) NULL
4932 && fix->fx_addsy != (symbolS *) NULL
4933 && fix->fx_addsy != ppc_toc_csect
4934 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4935 && val >= ppc_toc_frag->fr_address
4936 && (ppc_after_toc_frag == (fragS *) NULL
4937 || val < ppc_after_toc_frag->fr_address))
4938 {
4939 symbolS *sy;
4940
4941 for (sy = symbol_next (ppc_toc_csect);
4942 sy != (symbolS *) NULL;
4943 sy = symbol_next (sy))
4944 {
4945 if (symbol_get_tc (sy)->class == XMC_TC0)
4946 continue;
4947 if (symbol_get_tc (sy)->class != XMC_TC)
4948 break;
4949 resolve_symbol_value (sy);
4950 if (val == S_GET_VALUE (sy))
4951 {
4952 fix->fx_addsy = sy;
4953 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4954 return 0;
4955 }
4956 }
4957
4958 as_bad_where (fix->fx_file, fix->fx_line,
4959 _("symbol in .toc does not match any .tc"));
4960 }
4961
4962 /* Possibly adjust the reloc to be against the csect. */
4963 if (fix->fx_addsy != (symbolS *) NULL
4964 && symbol_get_tc (fix->fx_addsy)->subseg == 0
4965 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0
4966 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC
4967 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4968 /* Don't adjust if this is a reloc in the toc section. */
4969 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4970 || ppc_toc_csect == NULL
4971 || val < ppc_toc_frag->fr_address
4972 || (ppc_after_toc_frag != NULL
4973 && val >= ppc_after_toc_frag->fr_address)))
4974 {
4975 symbolS *csect;
4976
4977 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4978 csect = ppc_text_csects;
4979 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4980 csect = ppc_data_csects;
4981 else
4982 abort ();
4983
4984 /* Skip the initial dummy symbol. */
4985 csect = symbol_get_tc (csect)->next;
4986
4987 if (csect != (symbolS *) NULL)
4988 {
4989 while (symbol_get_tc (csect)->next != (symbolS *) NULL
4990 && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address
4991 <= val))
4992 {
4993 /* If the csect address equals the symbol value, then we
4994 have to look through the full symbol table to see
4995 whether this is the csect we want. Note that we will
4996 only get here if the csect has zero length. */
4997 if ((symbol_get_frag (csect)->fr_address == val)
4998 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4999 {
5000 symbolS *scan;
5001
5002 for (scan = symbol_next (csect);
5003 scan != NULL;
5004 scan = symbol_next (scan))
5005 {
5006 if (symbol_get_tc (scan)->subseg != 0)
5007 break;
5008 if (scan == fix->fx_addsy)
5009 break;
5010 }
5011
5012 /* If we found the symbol before the next csect
5013 symbol, then this is the csect we want. */
5014 if (scan == fix->fx_addsy)
5015 break;
5016 }
5017
5018 csect = symbol_get_tc (csect)->next;
5019 }
5020
5021 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
5022 - symbol_get_frag (csect)->fr_address);
5023 fix->fx_addsy = csect;
5024 }
5025 }
5026
5027 /* Adjust a reloc against a .lcomm symbol to be against the base
5028 .lcomm. */
5029 if (fix->fx_addsy != (symbolS *) NULL
5030 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
5031 && ! S_IS_EXTERNAL (fix->fx_addsy))
5032 {
5033 resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol);
5034 fix->fx_offset +=
5035 (S_GET_VALUE (fix->fx_addsy)
5036 - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol));
5037 fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5038 }
5039
5040 return 0;
5041 }
5042
5043 /* A reloc from one csect to another must be kept. The assembler
5044 will, of course, keep relocs between sections, and it will keep
5045 absolute relocs, but we need to force it to keep PC relative relocs
5046 between two csects in the same section. */
5047
5048 int
5049 ppc_force_relocation (fix)
5050 fixS *fix;
5051 {
5052 /* At this point fix->fx_addsy should already have been converted to
5053 a csect symbol. If the csect does not include the fragment, then
5054 we need to force the relocation. */
5055 if (fix->fx_pcrel
5056 && fix->fx_addsy != NULL
5057 && symbol_get_tc (fix->fx_addsy)->subseg != 0
5058 && ((symbol_get_frag (fix->fx_addsy)->fr_address
5059 > fix->fx_frag->fr_address)
5060 || (symbol_get_tc (fix->fx_addsy)->next != NULL
5061 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5062 <= fix->fx_frag->fr_address))))
5063 return 1;
5064
5065 return 0;
5066 }
5067
5068 #endif /* OBJ_XCOFF */
5069
5070 #ifdef OBJ_ELF
5071 int
5072 ppc_fix_adjustable (fix)
5073 fixS *fix;
5074 {
5075 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5076 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5077 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5078 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5079 && fix->fx_r_type != BFD_RELOC_GPREL16
5080 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5081 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5082 && ! S_IS_EXTERNAL (fix->fx_addsy)
5083 && ! S_IS_WEAK (fix->fx_addsy)
5084 && (fix->fx_pcrel
5085 || (fix->fx_subsy != NULL
5086 && (S_GET_SEGMENT (fix->fx_subsy)
5087 == S_GET_SEGMENT (fix->fx_addsy)))
5088 || S_IS_LOCAL (fix->fx_addsy)));
5089 }
5090 #endif
5091
5092 /* Apply a fixup to the object code. This is called for all the
5093 fixups we generated by the call to fix_new_exp, above. In the call
5094 above we used a reloc code which was the largest legal reloc code
5095 plus the operand index. Here we undo that to recover the operand
5096 index. At this point all symbol values should be fully resolved,
5097 and we attempt to completely resolve the reloc. If we can not do
5098 that, we determine the correct reloc code and put it back in the
5099 fixup. */
5100
5101 void
5102 md_apply_fix3 (fixP, valP, seg)
5103 fixS *fixP;
5104 valueT * valP;
5105 segT seg ATTRIBUTE_UNUSED;
5106 {
5107 valueT value = * valP;
5108
5109 #ifdef OBJ_ELF
5110 if (fixP->fx_addsy != NULL)
5111 {
5112 /* `*valuep' may contain the value of the symbol on which the reloc
5113 will be based; we have to remove it. */
5114 if (symbol_used_in_reloc_p (fixP->fx_addsy)
5115 && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section
5116 && S_GET_SEGMENT (fixP->fx_addsy) != undefined_section
5117 && ! bfd_is_com_section (S_GET_SEGMENT (fixP->fx_addsy)))
5118 value -= S_GET_VALUE (fixP->fx_addsy);
5119
5120 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
5121 supposed to be? I think this is related to various similar
5122 FIXMEs in tc-i386.c and tc-sparc.c. */
5123 if (fixP->fx_pcrel)
5124 value += fixP->fx_frag->fr_address + fixP->fx_where;
5125 }
5126 else
5127 fixP->fx_done = 1;
5128 #else
5129 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
5130 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5131 doing this relocation the code in write.c is going to call
5132 bfd_install_relocation, which is also going to use the symbol
5133 value. That means that if the reloc is fully resolved we want to
5134 use *valuep since bfd_install_relocation is not being used.
5135 However, if the reloc is not fully resolved we do not want to use
5136 *valuep, and must use fx_offset instead. However, if the reloc
5137 is PC relative, we do want to use *valuep since it includes the
5138 result of md_pcrel_from. This is confusing. */
5139 if (fixP->fx_addsy == (symbolS *) NULL)
5140 fixP->fx_done = 1;
5141
5142 else if (fixP->fx_pcrel)
5143 ;
5144
5145 else
5146 {
5147 value = fixP->fx_offset;
5148 if (fixP->fx_subsy != (symbolS *) NULL)
5149 {
5150 if (S_GET_SEGMENT (fixP->fx_subsy) == absolute_section)
5151 value -= S_GET_VALUE (fixP->fx_subsy);
5152 else
5153 {
5154 /* We can't actually support subtracting a symbol. */
5155 as_bad_where (fixP->fx_file, fixP->fx_line,
5156 _("expression too complex"));
5157 }
5158 }
5159 }
5160 #endif
5161
5162 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
5163 {
5164 int opindex;
5165 const struct powerpc_operand *operand;
5166 char *where;
5167 unsigned long insn;
5168
5169 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
5170
5171 operand = &powerpc_operands[opindex];
5172
5173 #ifdef OBJ_XCOFF
5174 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5175 does not generate a reloc. It uses the offset of `sym' within its
5176 csect. Other usages, such as `.long sym', generate relocs. This
5177 is the documented behaviour of non-TOC symbols. */
5178 if ((operand->flags & PPC_OPERAND_PARENS) != 0
5179 && operand->bits == 16
5180 && operand->shift == 0
5181 && (operand->insert == NULL || ppc_xcoff64)
5182 && fixP->fx_addsy != NULL
5183 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
5184 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC
5185 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC0
5186 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
5187 {
5188 value = fixP->fx_offset;
5189 fixP->fx_done = 1;
5190 }
5191 #endif
5192
5193 /* Fetch the instruction, insert the fully resolved operand
5194 value, and stuff the instruction back again. */
5195 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5196 if (target_big_endian)
5197 insn = bfd_getb32 ((unsigned char *) where);
5198 else
5199 insn = bfd_getl32 ((unsigned char *) where);
5200 insn = ppc_insert_operand (insn, operand, (offsetT) value,
5201 fixP->fx_file, fixP->fx_line);
5202 if (target_big_endian)
5203 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5204 else
5205 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5206
5207 if (fixP->fx_done)
5208 /* Nothing else to do here. */
5209 return;
5210
5211 assert (fixP->fx_addsy != NULL);
5212
5213 /* Determine a BFD reloc value based on the operand information.
5214 We are only prepared to turn a few of the operands into
5215 relocs. */
5216 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5217 && operand->bits == 26
5218 && operand->shift == 0)
5219 fixP->fx_r_type = BFD_RELOC_PPC_B26;
5220 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5221 && operand->bits == 16
5222 && operand->shift == 0)
5223 fixP->fx_r_type = BFD_RELOC_PPC_B16;
5224 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5225 && operand->bits == 26
5226 && operand->shift == 0)
5227 fixP->fx_r_type = BFD_RELOC_PPC_BA26;
5228 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5229 && operand->bits == 16
5230 && operand->shift == 0)
5231 fixP->fx_r_type = BFD_RELOC_PPC_BA16;
5232 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5233 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
5234 && operand->bits == 16
5235 && operand->shift == 0
5236 && ppc_is_toc_sym (fixP->fx_addsy))
5237 {
5238 fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
5239 #ifdef OBJ_ELF
5240 if (BFD_DEFAULT_TARGET_SIZE == 64
5241 && ppc_size == PPC_OPCODE_64
5242 && (operand->flags & PPC_OPERAND_DS) != 0)
5243 fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
5244 #endif
5245 fixP->fx_size = 2;
5246 if (target_big_endian)
5247 fixP->fx_where += 2;
5248 }
5249 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5250 else
5251 {
5252 char *sfile;
5253 unsigned int sline;
5254
5255 /* Use expr_symbol_where to see if this is an expression
5256 symbol. */
5257 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
5258 as_bad_where (fixP->fx_file, fixP->fx_line,
5259 _("unresolved expression that must be resolved"));
5260 else
5261 as_bad_where (fixP->fx_file, fixP->fx_line,
5262 _("unsupported relocation against %s"),
5263 S_GET_NAME (fixP->fx_addsy));
5264 fixP->fx_done = 1;
5265 return;
5266 }
5267 }
5268 else
5269 {
5270 #ifdef OBJ_ELF
5271 ppc_elf_validate_fix (fixP, seg);
5272 #endif
5273 switch (fixP->fx_r_type)
5274 {
5275 case BFD_RELOC_CTOR:
5276 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64)
5277 goto ctor64;
5278 /* fall through */
5279
5280 case BFD_RELOC_32:
5281 if (fixP->fx_pcrel)
5282 fixP->fx_r_type = BFD_RELOC_32_PCREL;
5283 /* fall through */
5284
5285 case BFD_RELOC_RVA:
5286 case BFD_RELOC_32_PCREL:
5287 case BFD_RELOC_PPC_EMB_NADDR32:
5288 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5289 value, 4);
5290 break;
5291
5292 case BFD_RELOC_64:
5293 ctor64:
5294 if (fixP->fx_pcrel)
5295 fixP->fx_r_type = BFD_RELOC_64_PCREL;
5296 /* fall through */
5297
5298 case BFD_RELOC_64_PCREL:
5299 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5300 value, 8);
5301 break;
5302
5303 case BFD_RELOC_LO16:
5304 case BFD_RELOC_16:
5305 case BFD_RELOC_GPREL16:
5306 case BFD_RELOC_16_GOT_PCREL:
5307 case BFD_RELOC_16_GOTOFF:
5308 case BFD_RELOC_LO16_GOTOFF:
5309 case BFD_RELOC_HI16_GOTOFF:
5310 case BFD_RELOC_HI16_S_GOTOFF:
5311 case BFD_RELOC_16_BASEREL:
5312 case BFD_RELOC_LO16_BASEREL:
5313 case BFD_RELOC_HI16_BASEREL:
5314 case BFD_RELOC_HI16_S_BASEREL:
5315 case BFD_RELOC_PPC_EMB_NADDR16:
5316 case BFD_RELOC_PPC_EMB_NADDR16_LO:
5317 case BFD_RELOC_PPC_EMB_NADDR16_HI:
5318 case BFD_RELOC_PPC_EMB_NADDR16_HA:
5319 case BFD_RELOC_PPC_EMB_SDAI16:
5320 case BFD_RELOC_PPC_EMB_SDA2REL:
5321 case BFD_RELOC_PPC_EMB_SDA2I16:
5322 case BFD_RELOC_PPC_EMB_RELSEC16:
5323 case BFD_RELOC_PPC_EMB_RELST_LO:
5324 case BFD_RELOC_PPC_EMB_RELST_HI:
5325 case BFD_RELOC_PPC_EMB_RELST_HA:
5326 case BFD_RELOC_PPC_EMB_RELSDA:
5327 case BFD_RELOC_PPC_TOC16:
5328 #ifdef OBJ_ELF
5329 #if BFD_DEFAULT_TARGET_SIZE == 64
5330 case BFD_RELOC_PPC64_TOC16_LO:
5331 case BFD_RELOC_PPC64_TOC16_HI:
5332 case BFD_RELOC_PPC64_TOC16_HA:
5333 #endif
5334 #endif
5335 if (fixP->fx_pcrel)
5336 {
5337 if (fixP->fx_addsy != NULL)
5338 as_bad_where (fixP->fx_file, fixP->fx_line,
5339 _("cannot emit PC relative %s relocation against %s"),
5340 bfd_get_reloc_code_name (fixP->fx_r_type),
5341 S_GET_NAME (fixP->fx_addsy));
5342 else
5343 as_bad_where (fixP->fx_file, fixP->fx_line,
5344 _("cannot emit PC relative %s relocation"),
5345 bfd_get_reloc_code_name (fixP->fx_r_type));
5346 }
5347
5348 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5349 value, 2);
5350 break;
5351
5352 /* This case happens when you write, for example,
5353 lis %r3,(L1-L2)@ha
5354 where L1 and L2 are defined later. */
5355 case BFD_RELOC_HI16:
5356 if (fixP->fx_pcrel)
5357 abort ();
5358 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5359 PPC_HI (value), 2);
5360 break;
5361
5362 case BFD_RELOC_HI16_S:
5363 if (fixP->fx_pcrel)
5364 abort ();
5365 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5366 PPC_HA (value), 2);
5367 break;
5368
5369 #ifdef OBJ_ELF
5370 #if BFD_DEFAULT_TARGET_SIZE == 64
5371 case BFD_RELOC_PPC64_HIGHER:
5372 if (fixP->fx_pcrel)
5373 abort ();
5374 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5375 PPC_HIGHER (value), 2);
5376 break;
5377
5378 case BFD_RELOC_PPC64_HIGHER_S:
5379 if (fixP->fx_pcrel)
5380 abort ();
5381 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5382 PPC_HIGHERA (value), 2);
5383 break;
5384
5385 case BFD_RELOC_PPC64_HIGHEST:
5386 if (fixP->fx_pcrel)
5387 abort ();
5388 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5389 PPC_HIGHEST (value), 2);
5390 break;
5391
5392 case BFD_RELOC_PPC64_HIGHEST_S:
5393 if (fixP->fx_pcrel)
5394 abort ();
5395 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5396 PPC_HIGHESTA (value), 2);
5397 break;
5398
5399 case BFD_RELOC_PPC64_ADDR16_DS:
5400 case BFD_RELOC_PPC64_ADDR16_LO_DS:
5401 case BFD_RELOC_PPC64_GOT16_DS:
5402 case BFD_RELOC_PPC64_GOT16_LO_DS:
5403 case BFD_RELOC_PPC64_PLT16_LO_DS:
5404 case BFD_RELOC_PPC64_SECTOFF_DS:
5405 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
5406 case BFD_RELOC_PPC64_TOC16_DS:
5407 case BFD_RELOC_PPC64_TOC16_LO_DS:
5408 case BFD_RELOC_PPC64_PLTGOT16_DS:
5409 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
5410 if (fixP->fx_pcrel)
5411 abort ();
5412 {
5413 unsigned char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
5414 unsigned long val;
5415
5416 if (target_big_endian)
5417 val = bfd_getb16 (where);
5418 else
5419 val = bfd_getl16 (where);
5420 val |= (value & 0xfffc);
5421 if (target_big_endian)
5422 bfd_putb16 ((bfd_vma) val, where);
5423 else
5424 bfd_putl16 ((bfd_vma) val, where);
5425 }
5426 break;
5427 #endif
5428 #endif
5429 /* Because SDA21 modifies the register field, the size is set to 4
5430 bytes, rather than 2, so offset it here appropriately. */
5431 case BFD_RELOC_PPC_EMB_SDA21:
5432 if (fixP->fx_pcrel)
5433 abort ();
5434
5435 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where
5436 + ((target_big_endian) ? 2 : 0),
5437 value, 2);
5438 break;
5439
5440 case BFD_RELOC_8:
5441 if (fixP->fx_pcrel)
5442 abort ();
5443
5444 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5445 value, 1);
5446 break;
5447
5448 case BFD_RELOC_24_PLT_PCREL:
5449 case BFD_RELOC_PPC_LOCAL24PC:
5450 if (!fixP->fx_pcrel && !fixP->fx_done)
5451 abort ();
5452
5453 if (fixP->fx_done)
5454 {
5455 char *where;
5456 unsigned long insn;
5457
5458 /* Fetch the instruction, insert the fully resolved operand
5459 value, and stuff the instruction back again. */
5460 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5461 if (target_big_endian)
5462 insn = bfd_getb32 ((unsigned char *) where);
5463 else
5464 insn = bfd_getl32 ((unsigned char *) where);
5465 if ((value & 3) != 0)
5466 as_bad_where (fixP->fx_file, fixP->fx_line,
5467 _("must branch to an address a multiple of 4"));
5468 if ((offsetT) value < -0x40000000
5469 || (offsetT) value >= 0x40000000)
5470 as_bad_where (fixP->fx_file, fixP->fx_line,
5471 _("@local or @plt branch destination is too far away, %ld bytes"),
5472 (long) value);
5473 insn = insn | (value & 0x03fffffc);
5474 if (target_big_endian)
5475 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5476 else
5477 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5478 }
5479 break;
5480
5481 case BFD_RELOC_VTABLE_INHERIT:
5482 fixP->fx_done = 0;
5483 if (fixP->fx_addsy
5484 && !S_IS_DEFINED (fixP->fx_addsy)
5485 && !S_IS_WEAK (fixP->fx_addsy))
5486 S_SET_WEAK (fixP->fx_addsy);
5487 break;
5488
5489 case BFD_RELOC_VTABLE_ENTRY:
5490 fixP->fx_done = 0;
5491 break;
5492
5493 #ifdef OBJ_ELF
5494 #if BFD_DEFAULT_TARGET_SIZE == 64
5495 /* Generated by reference to `sym@tocbase'. The sym is
5496 ignored by the linker. */
5497 case BFD_RELOC_PPC64_TOC:
5498 fixP->fx_done = 0;
5499 break;
5500 #endif
5501 #endif
5502 default:
5503 fprintf (stderr,
5504 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
5505 fflush (stderr);
5506 abort ();
5507 }
5508 }
5509
5510 #ifdef OBJ_ELF
5511 fixP->fx_addnumber = value;
5512 #else
5513 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
5514 fixP->fx_addnumber = 0;
5515 else
5516 {
5517 #ifdef TE_PE
5518 fixP->fx_addnumber = 0;
5519 #else
5520 /* We want to use the offset within the data segment of the
5521 symbol, not the actual VMA of the symbol. */
5522 fixP->fx_addnumber =
5523 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy));
5524 #endif
5525 }
5526 #endif
5527 }
5528
5529 /* Generate a reloc for a fixup. */
5530
5531 arelent *
5532 tc_gen_reloc (seg, fixp)
5533 asection *seg ATTRIBUTE_UNUSED;
5534 fixS *fixp;
5535 {
5536 arelent *reloc;
5537
5538 reloc = (arelent *) xmalloc (sizeof (arelent));
5539
5540 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
5541 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
5542 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5543 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5544 if (reloc->howto == (reloc_howto_type *) NULL)
5545 {
5546 as_bad_where (fixp->fx_file, fixp->fx_line,
5547 _("reloc %d not supported by object file format"),
5548 (int) fixp->fx_r_type);
5549 return NULL;
5550 }
5551 reloc->addend = fixp->fx_addnumber;
5552
5553 return reloc;
5554 }
This page took 0.139741 seconds and 5 git commands to generate.